/* The shell's look. Dark ground, hot accents — the phonk end of the crayon box.
   Everything here is in service of one thing: nothing on screen may compete
   with the four keys and the blocks falling into them. */

:root {
  --bg: #0d0a14;
  --ink: #f4eefc;
  --hot: #ff3d7f;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 500 16px/1.4 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;

  /* A rhythm game and a browser want the same gestures. The browser loses. */
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* Keep the keys clear of the notch, which in landscape is on a long edge. */
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

/* --- the layer strip: the only navigation in the game --------------------- */

.strip {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: calc(12px + var(--safe-r));
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 5;
}

.rounds { display: flex; gap: 6px; }

/* --- what she is playing, and how fast ----------------------------------- */

.status {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: calc(12px + var(--safe-l));
  z-index: 5;
  pointer-events: none;
}
.round { font-size: 15px; font-weight: 600; }
.under { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.bpm { font-size: 12px; opacity: 0.45; }

/* The only tappable thing in the status corner, so it has to look tappable
   without shouting — it is set once per round and then left alone. */
.length {
  appearance: none;
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(244, 238, 252, 0.8);
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.length:active { background: var(--hot); border-color: var(--hot); color: #14060d; }
/* A locked rhythm is a statement, not a control. It still says what it is —
   she should be able to see why her taps land where they do — but it does not
   look like something that will change if she presses it. */
.length[data-locked="true"] {
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.3);
  background: transparent;
}
/* The chord is the one chip that changes the MUSIC rather than the grid, so it
   carries the accent — and it is the only thing on this screen she can press
   that alters what the notes she already played will sound like. */
.chord { border-color: var(--hot); color: var(--hot); }
.chord:active { background: var(--hot); border-color: var(--hot); color: #14060d; }

.length[data-locked="true"]:active { background: transparent; border-color: rgba(255, 255, 255, 0.3); color: rgba(244, 238, 252, 0.8); }

/* --- the transport, down the empty middle -------------------------------- */

.transport {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 6;
}

.go {
  appearance: none;
  border: 2px solid var(--hot);
  background: var(--hot);
  color: #14060d;
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.04em;
  min-width: 128px;
  padding: 16px 22px;
  border-radius: 999px;
  cursor: pointer;
}
/* While recording it is a stop button, so it stops looking like a go button. */
.go[data-state="recording"] {
  background: transparent;
  color: var(--hot);
  animation: throb 1.1s ease-in-out infinite;
}
.go[data-state="counting"], .go[data-state="done"] {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.25);
  color: rgba(244, 238, 252, 0.6);
}
@keyframes throb { 50% { opacity: 0.55; } }

/* Words, not an icon — and quieter than the transport, because it is the
   button she reaches for when something has gone wrong rather than the one
   she uses to play. */
.reset {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: transparent;
  color: rgba(244, 238, 252, 0.75);
  font: inherit;
  font-size: 14px;
  padding: 15px 18px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.reset:active { background: rgba(255, 255, 255, 0.28); color: var(--ink); }

.share, .clear {
  appearance: none;
  border: 1px solid var(--hot);
  background: transparent;
  color: var(--hot);
  font: inherit;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.share { margin-left: 6px; }
.share:active, .clear:active { background: var(--hot); color: #14060d; }

/* Deliberately quieter than send. It is the button she reaches for when a
   layer has got away from her, not one she should hit by accident. */
.clear {
  margin-left: 10px;
  border-color: rgba(255, 255, 255, 0.28);
  color: rgba(244, 238, 252, 0.75);
}
.clear:active { background: rgba(255, 255, 255, 0.28); color: var(--ink); }

/* Quieter than anything else on the screen, on purpose (dec:idea-midi-out).
   This is an adult's button on a child's game: whoever wants it will find it,
   and it must never pull her eye away from "send". No border, small, dim. */
.midi {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(244, 238, 252, 0.4);
  font: inherit;
  font-size: 12px;
  padding: 7px 8px;
  cursor: pointer;
}
.midi:active { color: var(--ink); }

.chip {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
/* Kept rounds get a tick, so what is finished is visible at a glance. */
.chip.kept::before { content: "✓ "; opacity: 0.7; }

/* The add-a-section chip (dec:a-segment-is-a-whole-track). Deliberately quieter
   than a round chip: it is an occasional act, not one of the four things she is
   choosing between, and it appears only once a segment is finished. */
.chip.section {
  border-style: dashed;
  opacity: 0.72;
}
.chip.section:active { opacity: 1; }

/* A silenced round has to look silenced from across the room — dimmed AND
   struck through, because dimming alone reads as "disabled" and she needs to
   know it is still hers and coming back. */
.chip.muted {
  opacity: 0.4;
  text-decoration: line-through;
}
.chip.muted::before { content: "○ "; }
.chip[aria-current="true"] {
  background: var(--hot);
  border-color: var(--hot);
  color: #14060d;
}
.chip:disabled { opacity: 0.25; cursor: default; }

/* --- a nudge from the coach ---------------------------------------------- */

.nudge {
  position: fixed;
  top: calc(52px + env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  text-align: center;
  font-size: 15px;
  color: var(--hot);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 5;
}
.nudge.show { opacity: 1; transform: none; }

/* --- the first-tap gate --------------------------------------------------- */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  text-align: center;
  z-index: 20;
  transition: opacity 0.35s;
}
.gate.gone { opacity: 0; pointer-events: none; }

.gate h1 {
  margin: 0 0 6px;
  font-size: clamp(30px, 8vw, 54px);
  letter-spacing: -0.02em;
  color: var(--hot);
}
.gate-label { margin: 0; font-size: 17px; opacity: 0.85; }
.gate.loaded .gate-label { animation: pulse 1.7s ease-in-out infinite; }

.hint {
  margin: 26px 20px 0;
  font-size: 13px;
  opacity: 0.42;
  max-width: 22em;
}

@keyframes pulse { 50% { opacity: 0.45; } }

/* --- portrait: ask her to turn it ---------------------------------------- */

.rotate {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: var(--bg);
  text-align: center;
  z-index: 30;
}
body.portrait .rotate { display: grid; }

.rotate-icon {
  font-size: 64px;
  color: var(--hot);
  animation: tip 2s ease-in-out infinite;
}
@keyframes tip {
  0%, 45% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(90deg); }
}

@media (prefers-reduced-motion: reduce) {
  .gate.loaded .gate-label, .rotate-icon { animation: none; }
}

/* --- "no sound?" and the panel behind it --------------------------------- */

/* Sits with the status, top-left. It USED to sit bottom-left, which on a
   landscape phone is inside the left key — so every reach for the kick opened
   the help screen. A help button must never live in a thumb's play area. */
.help {
  appearance: none;
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  color: rgba(244, 238, 252, 0.45);
  font: inherit;
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
}
.help:active { background: rgba(255, 255, 255, 0.2); color: var(--ink); }

.panel {
  /* Shown by a CLASS, not by the hidden attribute. `hidden` depends on the user
     agent stylesheet's display:none, which any author display rule silently
     beats — too fragile for the one screen she must always be able to leave. */
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6, 4, 10, 0.96);
  z-index: 40;
  /* The body blocks touch scrolling, so the panel has to allow it back or a
     phone in landscape cannot reach anything below the fold. */
  touch-action: pan-y;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.panel.open { display: block; }

/* Top-aligned, never centred. Centring a panel taller than the viewport pushes
   its head off the top, where no amount of scrolling reaches it. */
.panel-inner {
  max-width: 40em;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 24px calc(24px + var(--safe-b));
  font-size: 13px;
  line-height: 1.5;
}
.panel h2 { margin: 10px 0 8px; font-size: 18px; color: var(--hot); }
.panel ol { margin: 0; padding-left: 1.2em; }
.panel li { margin-bottom: 7px; }
.panel i { opacity: 0.75; }
.panel-actions { margin: 14px 0 0; }

/* The way out, FIRST and full width. It was a small button at the bottom of a
   panel taller than the screen, on a page where scrolling is disabled — which
   is how a nine-year-old got stuck on a help screen she never meant to open. */
.closepanel {
  appearance: none;
  display: block;
  width: 100%;
  border: 1px solid var(--hot);
  background: var(--hot);
  color: #14060d;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  padding: 13px;
  border-radius: 999px;
  cursor: pointer;
}

.retry {
  appearance: none;
  border: 1px solid var(--hot);
  background: transparent;
  color: var(--hot);
  font: inherit;
  font-size: 13px;
  padding: 9px 15px;
  border-radius: 999px;
  cursor: pointer;
}
.retry:active { background: var(--hot); color: #14060d; }

/* For a grown-up working out what went wrong, not for her. */
.diag {
  margin: 14px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  opacity: 0.5;
  word-break: break-word;
}

/* The off switch. Quieter than the transport, because it is not how she plays —
   it is how she gets a moment's peace. */
.playpause {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: transparent;
  color: rgba(244, 238, 252, 0.8);
  font: inherit;
  font-size: 14px;
  padding: 15px 18px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.playpause[data-state="play"] { border-color: var(--hot); color: var(--hot); }
/* LISTEN is the one she reaches for mid-take, so it reads as available rather
   than as a warning. STOP stays quiet — it ends everything, and a button that
   ends everything should not invite a stray thumb. */
.playpause[data-state="listen"] { border-color: rgba(255, 255, 255, 0.55); color: var(--ink); }
.playpause:active { background: rgba(255, 255, 255, 0.28); color: var(--ink); }
