:root {
  color-scheme: dark;
  --bg: #080706;
  --panel: #17110d;
  --panel-strong: #241b12;
  --stone: #31312d;
  --stone-dark: #11100e;
  --line: #6c5b34;
  --line-bright: #c99a3a;
  --text: #f4e8c0;
  --muted: #b9aa78;
  --accent: #c99735;
  --accent-strong: #f0c45c;
  --danger: #a33d2f;
  --green: #4ca055;
  --blue: #4b8cab;
  --slot: #070605;
  font-family: Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 7px),
    linear-gradient(45deg, rgba(0, 0, 0, 0.28) 0 2px, transparent 2px 10px),
    linear-gradient(135deg, #070604 0%, #17120d 48%, #090a08 100%);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  min-height: 100vh;
  gap: 10px;
  padding: 10px;
}

.stage {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  border: 3px solid var(--stone);
  border-top-color: #5d5a4d;
  border-left-color: #5d5a4d;
  border-right-color: #090806;
  border-bottom-color: #090806;
  box-shadow:
    inset 0 0 0 2px #090806,
    inset 0 0 0 3px rgba(201, 154, 58, 0.45),
    0 0 0 1px rgba(0, 0, 0, 0.85),
    0 22px 60px rgba(0, 0, 0, 0.36);
}

#modelCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 20px);
  background:
    linear-gradient(180deg, rgba(7, 6, 5, 0.08), rgba(5, 5, 4, 0.76)),
    repeating-linear-gradient(90deg, rgba(201, 154, 58, 0.045) 0 1px, transparent 1px 56px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 56px),
    #0a0d09;
  cursor: grab;
  touch-action: none;
}

.stage.is-dragging #modelCanvas {
  cursor: grabbing;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 32px;
  pointer-events: none;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.9);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(3rem, 8vw, 7rem);
  line-height: 0.88;
  color: #fff0b8;
  text-shadow:
    0 2px 0 #2b1707,
    0 0 18px rgba(201, 154, 58, 0.28),
    0 6px 18px rgba(0, 0, 0, 0.9);
}

h2 {
  margin-bottom: 0;
  font-size: 1.6rem;
  line-height: 1.1;
  color: #ffe5a5;
  text-shadow: 0 2px 0 #150d06;
}

h3 {
  margin-bottom: 10px;
  font-size: 0.95rem;
  color: var(--muted);
}

.status-pill,
.version {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: 3px;
  background:
    linear-gradient(180deg, rgba(255, 236, 158, 0.12), transparent 46%),
    linear-gradient(180deg, #19130c, #070605);
  color: #e0c979;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px #070605, 0 2px 0 rgba(0, 0, 0, 0.6);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  border: 3px solid var(--stone);
  border-top-color: #5d5a4d;
  border-left-color: #5d5a4d;
  border-right-color: #090806;
  border-bottom-color: #090806;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 9px),
    linear-gradient(180deg, rgba(46, 40, 31, 0.96), rgba(14, 10, 7, 0.99)),
    var(--panel);
  box-shadow:
    inset 0 0 0 2px #090806,
    inset 0 0 0 3px rgba(201, 154, 58, 0.34),
    0 18px 50px rgba(0, 0, 0, 0.42);
}

.panel-header,
.primary-actions,
.toggle-row {
  display: flex;
  align-items: center;
}

.panel-header {
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid rgba(201, 154, 58, 0.36);
}



.unit-picker {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 3px;
  background:
    linear-gradient(180deg, rgba(255, 236, 158, 0.07), transparent 42%),
    linear-gradient(180deg, #1b150e, #0a0705);
  box-shadow: inset 0 0 0 1px #050403, inset 0 0 18px rgba(0, 0, 0, 0.72);
}

.unit-picker label {
  color: #d0ba78;
  font-size: 0.82rem;
  font-weight: 800;
  text-shadow: 0 1px 0 #000;
}

.unit-picker select {
  width: 100%;
  min-height: 42px;
  border: 2px solid #4c3c20;
  border-radius: 3px;
  padding: 0 12px;
  color: var(--text);
  background:
    linear-gradient(180deg, #21170d, #080604);
  box-shadow: inset 0 0 0 1px #070504;
}

.talk-button:disabled,
.toggle-row:has(input:disabled) {
  opacity: 0.55;
  cursor: not-allowed;
}
.portrait-panel {
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 3px;
  background: var(--slot);
}

.portrait-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  padding: 0 12px;
  border-bottom: 1px solid rgba(244, 239, 225, 0.1);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

#portraitCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  background:
    linear-gradient(180deg, rgba(15, 20, 17, 0.2), rgba(15, 20, 17, 0.86)),
    repeating-linear-gradient(90deg, rgba(244, 239, 225, 0.035) 0 1px, transparent 1px 46px),
    repeating-linear-gradient(0deg, rgba(244, 239, 225, 0.03) 0 1px, transparent 1px 46px);
}

.tuning-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 3px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 8px),
    linear-gradient(180deg, #1b150e, #090604);
  box-shadow: inset 0 0 0 1px #050403, inset 0 0 26px rgba(0, 0, 0, 0.7);
}

.tuning-header,
.tuning-row,
.tuning-row-label {
  display: flex;
  align-items: center;
}

.tuning-header {
  justify-content: space-between;
  gap: 12px;
}

.tuning-header h3,
.tuning-group h3 {
  margin: 0;
}

.copy-config-button,
.close-drawer-button,
.secondary-button {
  min-height: 32px;
  padding: 0 10px;
  border: 2px solid #584522;
  border-radius: 3px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 226, 128, 0.14), transparent 48%),
    linear-gradient(180deg, #23170c, #080504);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px #050403, 0 2px 0 rgba(0, 0, 0, 0.72);
  text-shadow: 0 1px 0 #000;
}

.tuning-controls {
  display: grid;
  gap: 12px;
}

.tuning-group {
  display: grid;
  gap: 8px;
}

.tuning-grid {
  display: grid;
  gap: 8px;
}

.tuning-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 54px;
  gap: 9px;
}

.tuning-row-label {
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.tuning-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.tuning-value {
  color: var(--accent-strong);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.76rem;
  text-align: right;
}

#configOutput {
  min-height: 108px;
  resize: vertical;
  border: 2px solid #47381d;
  border-radius: 3px;
  padding: 10px;
  color: #c8bb8c;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 40%),
    #050403;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.74rem;
  line-height: 1.45;
}

.tuning-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.secondary-button {
  min-height: 48px;
  border-radius: 8px;
  color: var(--text);
}

.close-drawer-button {
  min-height: 32px;
}

.tuning-drawer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  padding: 0 16px 16px;
  color: var(--text);
  pointer-events: none;
  transform: translateY(calc(100% + 20px));
  transition: transform 180ms ease;
}

.tuning-drawer.is-open {
  pointer-events: auto;
  transform: translateY(0);
}

.tuning-drawer .tuning-panel {
  width: min(920px, calc(100vw - 32px));
  max-height: min(58vh, 640px);
  margin: 0 auto;
  overflow: auto;
  border-color: var(--line-bright);
  border-radius: 3px 3px 0 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 9px),
    linear-gradient(180deg, #241b12, #080604);
  box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.48);
}
.primary-actions {
  flex-wrap: wrap;
  gap: 12px;
}

.talk-button,
.line-button {
  border: 2px solid #352815;
  color: #160f07;
  background:
    linear-gradient(180deg, #f3cf66, #b87c23 58%, #744412);
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 188, 0.58),
    inset 0 -3px 0 rgba(62, 32, 8, 0.85),
    0 2px 0 rgba(0, 0, 0, 0.7);
  text-shadow: 0 1px 0 rgba(255, 238, 178, 0.36);
}

.talk-button:hover,
.line-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.12);
}

.talk-button:active,
.line-button:active {
  transform: translateY(0);
}

.talk-button {
  min-height: 48px;
  flex: 1;
  border-radius: 4px;
  font-weight: 800;
}

.toggle-row {
  gap: 9px;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  white-space: nowrap;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.meter {
  height: 8px;
  overflow: hidden;
  border: 1px solid #4c3c20;
  border-radius: 2px;
  background: #050403;
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.78);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--accent-strong), var(--danger));
  transition: width 120ms linear;
}

.animation-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 3px;
  background:
    linear-gradient(180deg, rgba(255, 236, 158, 0.06), transparent 44%),
    linear-gradient(180deg, #17110b, #070504);
  box-shadow: inset 0 0 0 1px #050403, inset 0 0 18px rgba(0, 0, 0, 0.72);
}

.animation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.animation-header h3 {
  margin: 0;
  font-size: 0.9rem;
}

.animation-header span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.sound-group {
  padding-top: 2px;
  padding: 12px;
  border: 2px solid #4f4229;
  border-radius: 3px;
  background:
    linear-gradient(180deg, rgba(255, 236, 158, 0.045), transparent 44%),
    linear-gradient(180deg, #15100b, #070504);
  box-shadow: inset 0 0 0 1px #050403, inset 0 0 18px rgba(0, 0, 0, 0.72);
}

.sound-group h3 {
  color: #d0ba78;
  text-shadow: 0 1px 0 #000;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.line-button {
  min-height: 44px;
  padding: 0 10px;
  border-radius: 2px;
  background:
    linear-gradient(180deg, rgba(255, 236, 158, 0.08), transparent 44%),
    linear-gradient(180deg, #15100b, #050403);
  border-color: #352815;
  color: #e7d49b;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 0 #000;
}

.line-button:hover {
  background:
    linear-gradient(180deg, rgba(240, 196, 92, 0.2), transparent 48%),
    linear-gradient(180deg, #23170c, #090604);
  border-color: var(--line-bright);
  color: var(--text);
}

.line-button.is-playing {
  background:
    linear-gradient(180deg, #f3cf66, #b87c23 58%, #744412);
  border-color: #f0c45c;
  color: #160f07;
  text-shadow: 0 1px 0 rgba(255, 238, 178, 0.38);
}

.stage.is-speaking #modelCanvas {
  filter: saturate(1.1) brightness(1.08);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .stage {
    min-height: 54vh;
    border-right: 0;
    border-bottom: 1px solid rgba(244, 239, 225, 0.1);
  }

  #modelCanvas {
    min-height: 54vh;
  }

  .stage-overlay {
    padding: 22px;
  }

  .control-panel {
    padding: 22px;
  }
}

@media (max-width: 520px) {
  .primary-actions,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .version {
    align-self: flex-start;
  }

  .button-grid {
    grid-template-columns: 1fr;
  }
}
