:root {
  color-scheme: light;
  --ink: #1d2540;
  --paper: #fffaf0;
  --cream: #f5eddf;
  --line: #d8cdbc;
  --coral: #f45d48;
  --coral-dark: #cb3e2d;
  --yellow: #f9c96a;
  --blue: #27345c;
  --muted: #79766f;
  --skin: #ffd7b5;
}

body[data-theme="ocean"] { --coral: #168f99; --coral-dark: #08727c; --yellow: #f2ce68; --blue: #163753; --cream: #e7f1ec; --line: #bed2cd; }
body[data-theme="plum"] { --coral: #9b4f96; --coral-dark: #71366f; --yellow: #f2a7b8; --blue: #34224f; --cream: #f1e7ef; --line: #d6c2d3; }
body[data-theme="sunset"] { --coral: #ef704c; --coral-dark: #cb4e31; --yellow: #ffd166; --blue: #49304c; --cream: #f7e6d6; --line: #dfc6b3; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-width: 320px; min-height: 100%; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--cream);
  color: var(--ink);
  font-family: "Arial Narrow", "Aptos Narrow", Inter, ui-sans-serif, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input { color: inherit; font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.masthead {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px clamp(16px, 4vw, 48px);
  border-bottom: 2px solid var(--ink);
  background: var(--paper);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-size: clamp(.96rem, 2.6vw, 1.22rem);
  font-weight: 1000;
  letter-spacing: .06em;
  text-decoration: none;
}

.wordmark small { display: block; margin-top: 1px; color: var(--coral); font-size: .5em; letter-spacing: .23em; }
.wordmark-mark { display: grid; width: 37px; height: 37px; place-items: center; border-radius: 50% 50% 46% 54%; background: var(--ink); color: var(--paper); font-family: Georgia, serif; font-size: 1.28rem; font-style: italic; }

.quiet-button,
.music-form button {
  min-height: 38px;
  border: 2px solid var(--ink);
  border-radius: 99px;
  background: transparent;
  padding: 0 15px;
  font-size: .73rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.quiet-button:hover, .quiet-button[aria-expanded="true"] { background: var(--ink); color: var(--paper); }

.music-panel {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(300px, 520px);
  gap: 22px;
  padding: 16px clamp(16px, 4vw, 48px);
  border-bottom: 2px solid var(--ink);
  background: var(--yellow);
}

.music-form label { display: block; margin-bottom: 7px; font-size: .66rem; font-weight: 1000; letter-spacing: .14em; text-transform: uppercase; }
.music-input-row { display: flex; gap: 8px; }
.music-input-row input { width: 100%; min-width: 0; border: 2px solid var(--ink); border-radius: 7px; background: var(--paper); padding: 10px 12px; outline: none; }
.music-input-row input:focus { box-shadow: 0 0 0 3px #fff8; }
.music-form button { flex: 0 0 auto; border-radius: 7px; background: var(--ink); color: var(--paper); }
.music-form p { margin: 7px 0 0; font-size: .75rem; }
.video-frame { aspect-ratio: 16 / 9; overflow: hidden; border: 2px solid var(--ink); border-radius: 8px; background: #000; }
.video-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

.studio-grid {
  width: min(1180px, 100%);
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(310px, .85fr);
  gap: 0;
  border-inline: 2px solid var(--ink);
  background: var(--paper);
}

.stage-card { min-width: 0; display: grid; grid-template-rows: auto minmax(440px, 1fr) 12px; border-right: 2px solid var(--ink); }

.stage-topline {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 17px;
  border-bottom: 1px solid var(--line);
}

.stage-topline > div:first-child { display: grid; gap: 1px; }
.stage-kicker { color: var(--muted); font-size: .55rem; font-weight: 900; letter-spacing: .16em; }
#active-part-label { color: var(--coral); font-size: 1.04rem; letter-spacing: .05em; }
.loop-readout { display: flex; align-items: center; gap: 12px; font-size: .72rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.loop-readout button { border: 0; background: transparent; color: var(--muted); padding: 7px 0; font-size: .64rem; font-weight: 900; letter-spacing: .1em; }
.loop-readout button:hover { color: var(--coral); }

.stage-wrap { position: relative; min-height: 0; overflow: hidden; background: var(--paper); }
#puppet {
  width: 100%;
  height: 100%;
  min-height: 440px;
  display: block;
  --coat: var(--coral);
  --outline: var(--ink);
  --trim: var(--yellow);
  --skin-tone: var(--skin);
  --shoe: var(--blue);
  --sole: var(--paper);
}
.stage-art { pointer-events: none; }
.floor-shadow { fill: #1d254026; filter: url(#soft-shadow); transform-origin: center; }
.bone { stroke: var(--coat); stroke-width: 25; stroke-linecap: round; }
.leg .bone { stroke: var(--blue); stroke-width: 28; }
.bone-front { stroke: var(--yellow); stroke-width: 8; }
.leg .bone-front { stroke: #52618b; stroke-width: 8; }
.joint { fill: var(--paper); stroke: var(--ink); stroke-width: 6; }
.neck-line { stroke: var(--ink); stroke-width: 22; stroke-linecap: round; }
#torso-art, #head-art, [data-part] { transform-box: fill-box; transform-origin: center; }
.face-eyes circle { fill: var(--ink); transform-box: fill-box; transform-origin: center; }
.face-eyes.blink circle { transform: scaleY(.12); }
.face-mouth { fill: none; stroke: var(--ink); stroke-width: 4; stroke-linecap: round; }
.recording-halo { opacity: 0; pointer-events: none; }
.recording-halo circle { fill: none; stroke: var(--coral); stroke-width: 5; stroke-dasharray: 7 13; transform-origin: center; }
.recording .recording-halo { opacity: .7; }
.recording .recording-halo circle { animation: halo-spin 7s linear infinite; }
@keyframes halo-spin { to { transform: rotate(360deg); } }

.stage-toast {
  position: absolute;
  z-index: 3;
  top: 22px;
  left: 50%;
  translate: -50% -8px;
  opacity: 0;
  pointer-events: none;
  border: 2px solid var(--ink);
  border-radius: 99px;
  background: var(--yellow);
  padding: 9px 15px;
  font-size: .66rem;
  font-weight: 1000;
  letter-spacing: .12em;
  text-align: center;
  text-transform: uppercase;
  transition: opacity 150ms ease, translate 150ms ease;
}
.stage-toast.show { opacity: 1; translate: -50% 0; }
.stage-toast.recording-toast { background: var(--coral); color: white; }
.first-tip { position: absolute; left: 18px; bottom: 18px; max-width: 220px; border-left: 4px solid var(--coral); background: #fffaf0dd; padding: 8px 11px; font-size: .72rem; line-height: 1.35; transition: opacity 250ms ease; }
.first-tip.hidden { opacity: 0; pointer-events: none; }

.timeline { position: relative; overflow: hidden; border-top: 2px solid var(--ink); background: var(--line); }
.timeline i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--coral); }
.timeline span { position: absolute; top: 0; bottom: 0; width: 1px; background: #fff8; }
.timeline span:nth-of-type(1) { left: 25%; }
.timeline span:nth-of-type(2) { left: 50%; }
.timeline span:nth-of-type(3) { left: 75%; }

.control-card { min-width: 0; display: grid; align-content: start; grid-template-rows: auto auto auto auto auto 1fr; background: var(--cream); }
.part-grid { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 2px solid var(--ink); }
.part-grid button { position: relative; min-height: 66px; display: grid; place-items: center; gap: 4px; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--paper); padding: 8px 3px; font-size: .63rem; font-weight: 900; }
.part-grid button:nth-child(3n) { border-right: 0; }
.part-grid button:nth-child(n+4) { border-bottom: 0; }
.part-grid button i { width: 10px; height: 10px; border: 2px solid var(--ink); border-radius: 50%; background: transparent; }
.part-grid button.has-track i { background: var(--yellow); }
.part-grid button.muted i { background: var(--line); }
.part-grid button.active { background: var(--coral); color: white; }
.part-grid button.active i { border-color: white; }
.part-grid button.recording-part::after { content: "REC"; position: absolute; top: 4px; right: 5px; color: var(--coral); font-size: .45rem; font-weight: 1000; letter-spacing: .08em; }
.part-grid button.active.recording-part::after { color: white; }

.joystick-zone { display: grid; justify-items: center; gap: 12px; padding: 20px 16px 18px; }
.joystick-copy { width: 100%; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .58rem; font-weight: 900; letter-spacing: .1em; }
.joystick-copy b { color: var(--ink); }
.joystick-copy small { font-size: .5rem; }
.joystick {
  position: relative;
  width: min(210px, 58vw);
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: inset 0 0 0 12px var(--cream), inset 0 0 0 14px var(--line);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  outline: none;
}
.joystick:focus-visible { box-shadow: 0 0 0 4px var(--yellow), inset 0 0 0 12px var(--cream), inset 0 0 0 14px var(--line); }
.joystick.dragging { cursor: grabbing; }
.joystick-rings::before, .joystick-rings::after { content: ""; position: absolute; background: var(--line); pointer-events: none; }
.joystick-rings::before { width: 1px; top: 17px; bottom: 17px; left: 50%; }
.joystick-rings::after { height: 1px; left: 17px; right: 17px; top: 50%; }
.joystick-knob { position: absolute; left: 50%; top: 50%; width: 74px; height: 74px; translate: -50% -50%; display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 50%; background: var(--coral); box-shadow: 0 7px 0 var(--coral-dark); will-change: transform; }
.joystick-knob span { width: 20px; height: 20px; border: 3px solid white; border-radius: 50%; }

.track-actions { padding: 0 16px 16px; }
.record-button { width: 100%; min-height: 52px; border: 2px solid var(--ink); border-radius: 7px; background: var(--ink); color: white; font-size: .78rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.record-button b { color: var(--yellow); font-weight: inherit; }
.record-button.recording { background: var(--coral); }
.record-dot { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%; background: currentColor; }
.record-button.recording .record-dot { animation: record-pulse .7s ease infinite alternate; }
@keyframes record-pulse { to { transform: scale(1.45); opacity: .45; } }
.small-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.small-actions button, .transport button { min-height: 38px; border: 1px solid var(--ink); border-radius: 6px; background: transparent; font-size: .62rem; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; }
.small-actions button:disabled { opacity: .35; cursor: default; }
.small-actions button:hover:not(:disabled), .transport button:hover { background: var(--yellow); }

.transport { display: grid; grid-template-columns: 1.2fr 1fr .8fr; gap: 7px; padding: 13px 16px; border-block: 1px solid var(--line); }
.transport .play-button { display: flex; align-items: center; justify-content: center; gap: 7px; background: var(--paper); }
.play-button span { font-size: 1rem; line-height: 1; }
.character-options { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--paper); }
.character-options label { display: grid; gap: 5px; }
.character-options label > span, .character-options legend { color: var(--muted); font-size: .52rem; font-weight: 1000; letter-spacing: .12em; text-transform: uppercase; }
.character-options select { min-width: 116px; height: 34px; border: 1px solid var(--ink); border-radius: 5px; background: var(--cream); padding: 0 8px; font-size: .68rem; font-weight: 900; }
.character-options fieldset { display: flex; gap: 7px; margin: 0; border: 0; padding: 0; }
.character-options legend { margin-bottom: 5px; padding: 0; }
.theme-swatch { width: 27px; height: 27px; border: 2px solid var(--paper); border-radius: 50%; outline: 1px solid var(--line); padding: 0; }
.theme-swatch.active { outline: 3px solid var(--ink); }
.theme-swatch[data-theme="classic"] { background: linear-gradient(135deg, #f45d48 50%, #27345c 50%); }
.theme-swatch[data-theme="ocean"] { background: linear-gradient(135deg, #168f99 50%, #163753 50%); }
.theme-swatch[data-theme="plum"] { background: linear-gradient(135deg, #9b4f96 50%, #34224f 50%); }
.theme-swatch[data-theme="sunset"] { background: linear-gradient(135deg, #ef704c 50%, #49304c 50%); }
.status-line { align-self: end; margin: 0; padding: 13px 16px; color: var(--muted); font-size: .68rem; line-height: 1.45; }

@media (max-width: 800px) {
  .studio-grid { grid-template-columns: 1fr; border-inline: 0; }
  .stage-card { min-height: 60svh; border-right: 0; border-bottom: 2px solid var(--ink); }
  .control-card { grid-template-columns: minmax(0, 1fr) minmax(240px, 1fr); grid-template-rows: auto auto auto; }
  .part-grid { grid-column: 1 / -1; }
  .joystick-zone { grid-row: 2 / 4; }
  .track-actions { padding-top: 18px; }
  .transport { align-self: start; border-bottom: 0; }
  .character-options { grid-column: 1 / -1; align-self: start; }
  .status-line { display: none; }
  .music-panel { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .masthead { min-height: 58px; padding: 9px 12px; }
  .wordmark-mark { width: 32px; height: 32px; }
  .quiet-button { padding: 0 10px; font-size: .6rem; }
  .studio-grid { display: block; }
  .stage-card { min-height: 0; grid-template-rows: auto auto 10px; }
  .stage-wrap { height: min(58svh, 500px); min-height: 375px; }
  #puppet { min-height: 375px; }
  .stage-topline { min-height: 51px; padding: 7px 12px; }
  .control-card { display: block; }
  .part-grid button { min-height: 55px; }
  .joystick-zone { padding: 16px 12px 14px; }
  .joystick { width: min(184px, 52vw); }
  .joystick-knob { width: 65px; height: 65px; }
  .track-actions { padding: 0 12px 12px; }
  .transport { padding: 10px 12px max(12px, env(safe-area-inset-bottom)); }
  .first-tip { left: 10px; bottom: 10px; }
  .music-panel { padding: 13px 12px; }
  .music-input-row { align-items: stretch; }
  .music-form button { padding-inline: 10px; font-size: .62rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
