/* ==========================================================================
   Music Playground — styling
   For iPads, Chromebooks and the classroom projector.

   One idea carries the look: tone bars (Boomwhacker / xylophone bars). The
   seven note colours below are the palette, used flat. They appear on the
   home screen's activity bars, the bells and the Song Maker grid. Everything
   else stays quiet: white like a whiteboard, ink text, thin rules, plain
   buttons. The only drawing is five faint staff lines behind the home title.

   Rules worth keeping:
   - No gradients, glows or blurred glass. Colour is flat.
   - Words on a coloured fill: dark ink on C-yellow, D-orange and F-green;
     white on red, teal, purple and magenta. Every pairing here passes
     WCAG AA (measured, see the commit that introduced it).
   - Touch targets are at least 48px.
   - Fonts are system stacks, so the app looks the same with no network.
   ========================================================================== */

:root {
  /* ---- Note colours (Boomwhacker order), flat fills --------------------- */
  --note-c: #d7263d;   /* red     — white text 4.96:1 */
  --note-d: #f28c28;   /* orange  — ink text 6.6:1   */
  --note-e: #ffd23f;   /* yellow  — ink text 11.3:1  */
  --note-f: #4caf50;   /* green   — ink text 5.9:1   */
  --note-g: #0b7d70;   /* teal    — white text 5.0:1 */
  --note-a: #7b3fb8;   /* purple  — white text 6.5:1 */
  --note-b: #c2257a;   /* magenta — white text 5.5:1 */

  /* ---- Text-safe shades for coloured words on white (>= 4.5:1) ---------- */
  --pink-strong:   #b01f6d;
  --orange-strong: #b34700;
  --green-strong:  #1d6b31;
  --teal-strong:   #0a6b63;
  --sky-strong:    #0866a3;
  --blue-strong:   #3a4fd0;
  --purple-strong: #6a2fa8;
  --grape-strong:  #6a2fa8;
  --red-strong:    #c8202f;

  /* Older names still used by a few rules and inline styles. */
  --pink: var(--note-b);
  --coral: var(--note-c);
  --orange: var(--note-d);
  --yellow: var(--note-e);
  --lime: var(--note-f);
  --teal: var(--note-g);
  --sky: #2f8fd8;
  --blue: #3a4fd0;
  --purple: var(--note-a);
  --grape: var(--note-a);

  /* ---- Neutrals ---------------------------------------------------------- */
  --ink:       #1f1a33;
  --ink-soft:  #55506a;   /* 7.6:1 on white */
  --line:      #e4e1ea;
  --line-strong: #c9c4d6;
  --surface:   #ffffff;
  --page:      #ffffff;
  --tint:      #f6f5f9;   /* quiet panels, empty cells */
  --cream:     #f6f5f9;
  --track:     #e9e6ef;
  --focus:     #3a4fd0;

  /* ---- Spacing ------------------------------------------------------------ */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;
  --gutter: clamp(16px, 3.2vw, 40px);

  /* ---- Radius: small and varied on purpose ------------------------------- */
  --radius-bar: 6px;     /* tone bars */
  --radius-sm: 8px;      /* buttons, chips */
  --radius: 10px;        /* panels */
  --radius-pill: 999px;  /* only for round things: dots, rivets */

  /* ---- Type --------------------------------------------------------------- */
  --font-round: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Varela Round",
                system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-body:  system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-xs:  0.8125rem;
  --text-sm:  0.9375rem;
  --text-md:  1.0625rem;
  --text-lg:  clamp(1.125rem, 1rem + 0.5vw, 1.3125rem);
  --text-xl:  clamp(1.3125rem, 1.1rem + 0.9vw, 1.625rem);
  --text-2xl: clamp(1.75rem, 1.3rem + 2vw, 2.5rem);
  --text-3xl: clamp(2.5rem, 1.6rem + 4.4vw, 4.5rem);

  --tap: 48px;

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
* { -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: none;
  overflow-x: hidden;
}

h1, h2, h3 { font-family: var(--font-round); font-weight: 800; line-height: 1.15; }
img, svg, canvas { max-width: 100%; }

button, a, input, select, label { touch-action: manipulation; }
button { font: inherit; color: inherit; }

/* One clear focus ring for keyboard and switch users; :focus-visible keeps
   it off finger taps. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* ------------------------------- Header ---------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--gutter);
  padding-top: max(var(--space-2), env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.home-btn {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  border: none;
  background: transparent;
  font-family: var(--font-round);
  font-weight: 800;
  font-size: var(--text-lg);
  color: var(--ink);
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
  min-width: 0;
}
.home-btn__text { overflow: hidden; text-overflow: ellipsis; }
/* The home screen already has the big title, so the header doesn't repeat it. */
body[data-view="home"] .home-btn { visibility: hidden; }
body[data-view="home"] .app-header { border-bottom-color: transparent; }
.header-spacer { flex: 1; }

.ghost-btn {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 20px;
  cursor: pointer;
  color: var(--ink);
}

/* ------------------------------- Layout ---------------------------------- */
.view {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--space-6) var(--gutter) var(--space-8);
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0 var(--space-5);
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  color: var(--ink-soft);
  font-size: var(--text-xs);
  padding: var(--space-3) var(--gutter) max(var(--space-4), env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.app-footer a {
  color: var(--ink);
  font-weight: 700;
  text-underline-offset: 3px;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}

/* ------------------------------- Home ------------------------------------ */
body[data-view="home"] .view {
  display: grid;
  grid-template-columns: 1fr;
  column-gap: clamp(32px, 5vw, 72px);
  row-gap: var(--space-7);
  align-items: start;
}
@media (min-width: 900px) {
  body[data-view="home"] .view { grid-template-columns: 1fr 1fr; }
}
.hero, .more-apps { grid-column: 1 / -1; }

.hero {
  position: relative;
  padding: var(--space-4) 0 0;
}
/* The five-line staff sits behind the title like ruled paper on the board. */
.hero__staff {
  position: absolute;
  left: 0; right: 0;
  top: var(--space-2);
  width: 100%;
  height: calc(var(--text-3xl) * 1.35);
  z-index: 0;
  overflow: visible;
}
.hero__staff line { stroke: #d4d0de; stroke-width: 1.5; }
/* On a phone the title fills the width, so only a stray top line would show. */
@media (max-width: 599px) { .hero__staff { display: none; } }
.hero h1 {
  position: relative;
  z-index: 1;
  display: inline-block;
  background: var(--page);
  padding-right: var(--space-4);
  font-size: var(--text-3xl);
  line-height: 1.1;
  margin: 0 0 var(--space-5);
  padding-top: calc(var(--text-3xl) * 0.06);
  color: var(--ink);
  letter-spacing: -0.02em;
}
.hero p {
  position: relative;
  display: block;
  font-size: var(--text-lg);
  color: var(--ink-soft);
  margin: 0;
  max-width: 46ch;
}

.bar-group h2 {
  font-size: var(--text-xl);
  margin: 0 0 var(--space-3);
}
.bar-set {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-3);
}
.bar-set li { display: flex; }
.bar-set { --bar-step: 4%; }
@media (min-width: 600px) { .bar-set { --bar-step: 8%; } }

/* A tone bar: flat colour, a darker lower edge for thickness, and a rivet
   near each end where the bar would sit on the frame. Bars in a group get
   shorter one by one (--len, set in app.js), like a xylophone. */
.bar {
  --bar-ink: #fff;
  position: relative;
  width: calc(100% - var(--i, 0) * var(--bar-step));
  min-width: min(100%, 16.5rem);
  min-height: 88px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  border: 0;
  border-radius: var(--radius-bar);
  padding: var(--space-3) 52px var(--space-4) 46px;
  color: var(--bar-ink);
  cursor: pointer;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .16);
}
.bar::before, .bar::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 12px; height: 12px;
  margin-top: -9px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .28);
  box-shadow: inset 0 -2px 0 rgba(255, 255, 255, .35);
}
.bar::before { left: 18px; }
.bar::after { right: 18px; }
.bar__title {
  font-family: var(--font-round);
  font-weight: 800;
  font-size: var(--text-xl);
  line-height: 1.15;
}
.bar__desc { font-size: var(--text-sm); font-weight: 500; line-height: 1.35; }
.bar:active { transform: translateY(2px); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .16); }

.bar--c { background: var(--note-c); }
.bar--d { background: var(--note-d); --bar-ink: var(--ink); }
.bar--e { background: var(--note-e); --bar-ink: var(--ink); }
.bar--f { background: var(--note-f); --bar-ink: var(--ink); }
.bar--g { background: var(--note-g); }
.bar--a { background: var(--note-a); }
.bar--b { background: var(--note-b); }

.more-apps {
  border-top: 1px solid var(--line);
  padding-top: var(--space-5);
}
.more-apps h2 { font-size: var(--text-lg); margin: 0 0 var(--space-2); }
.more-apps ul { list-style: none; margin: 0; padding: 0; }
.more-apps li { color: var(--ink-soft); font-size: var(--text-sm); }
.more-apps a {
  display: inline-flex; align-items: center; min-height: var(--tap);
  color: var(--ink); font-weight: 800; font-size: var(--text-md); text-underline-offset: 3px;
}

/* ---------------------------- Activity pages ----------------------------- */
.page-head { margin-bottom: var(--space-6); max-width: 60rem; }
.page-head h2 { font-size: var(--text-2xl); margin: var(--space-3) 0 var(--space-2); }
.page-head p { margin: 0; color: var(--ink-soft); font-size: var(--text-md); max-width: 60ch; }
/* A short tone bar in the colour of the bar that opened this page. */
.page-head__bar {
  display: block;
  position: relative;
  width: 76px; height: 16px;
  margin-top: var(--space-4);
  border-radius: 4px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .16);
}
.page-head__bar::before, .page-head__bar::after {
  content: ""; position: absolute; top: 4px;
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(0, 0, 0, .28);
}
.page-head__bar::before { left: 7px; }
.page-head__bar::after { right: 7px; }

.back-btn {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0;
  border: none;
  background: none;
  font-weight: 700;
  font-size: var(--text-md);
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(16px, 3vw, 24px);
  margin-bottom: var(--space-5);
}
.card h3 { margin: 0 0 var(--space-2); font-size: var(--text-xl); }
.card p { margin: 0 0 var(--space-2); }

/* ---- Buttons --------------------------------------------------------------
   Primary actions (Play, Strum, Next) are flat colour blocks. Secondary ones
   (Clear, Undo, copy a link, download) are plain underlined text buttons, so
   the thing to press first is obvious. */
.btn {
  /* inline-block, not flex: some buttons mix text with <b>/<span>, and flex
     would turn each run into its own item and eat the spaces between them. */
  display: inline-block;
  vertical-align: middle;
  border: none;
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-6);
  font-family: var(--font-round);
  font-weight: 800;
  font-size: var(--text-lg);
  line-height: 1.2;
  color: #fff;
  background: var(--ink);
  cursor: pointer;
  min-height: 52px;
  text-align: center;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18);
}
.btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18); }
.btn:disabled { cursor: default; opacity: .6; }
.btn--play  { background: var(--note-f); color: var(--ink); }
.btn--stop  { background: var(--note-c); }
.btn--blue  { background: var(--note-g); }
.btn--pink  { background: var(--note-b); }
.btn--purple{ background: var(--note-a); }
.btn--sun   { background: var(--note-e); color: var(--ink); }
.btn--ghost { background: var(--surface); color: var(--ink); border: 2px solid var(--line-strong); box-shadow: none; }
.btn--sm    { min-height: var(--tap); padding: var(--space-2) var(--space-5); font-size: var(--text-sm); }
.btn--text, .btn--link {
  background: none; color: var(--ink); box-shadow: none;
  min-height: var(--tap); padding: 0 var(--space-2);
  font-family: var(--font-body); font-weight: 700; font-size: var(--text-md);
  text-decoration: underline; text-underline-offset: 4px;
}
.btn--text:active, .btn--link:active { transform: none; box-shadow: none; color: var(--ink-soft); }
.btn__sub { display: block; font-size: var(--text-sm); font-weight: 600; }

/* Big main surfaces: Major/Minor "Play the sound", Steady Beat "Tap". */
.big-pad {
  width: 100%;
  min-height: 160px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: #fff;
  font-family: var(--font-round);
  font-weight: 800;
  font-size: var(--text-2xl);
  line-height: 1.2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-1);
  padding: var(--space-5);
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, .16);
}
.big-pad:active { transform: translateY(3px); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .16); }
.big-pad__sub { font-family: var(--font-body); font-size: var(--text-md); font-weight: 600; }
.big-pad--listen { background: var(--note-a); }
.big-pad--tap    { min-height: 220px; background: var(--note-f); color: var(--ink); font-size: var(--text-3xl); }

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.pill-group { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  border: 2px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-4);
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--ink);
  cursor: pointer;
}
.pill.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }

label.slider {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  font-weight: 700;
  font-size: var(--text-md);
  color: var(--ink);
}

/* Range inputs: a 48px-tall hit area around a slim flat track. */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: var(--tap);
  width: min(280px, 100%);
  background: transparent;
  cursor: pointer;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: var(--line-strong); }
input[type="range"]::-moz-range-track { height: 8px; border-radius: 4px; background: var(--line-strong); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 30px; height: 30px;
  margin-top: -11px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--ink);
}
input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--ink);
}

/* ---------------------------- Beat Boxes --------------------------------- */
.beat-row {
  display: flex;
  gap: clamp(8px, 1.6vw, 16px);
  justify-content: center;
  flex-wrap: wrap;
  margin: var(--space-2) 0;
}
.beat-box {
  position: relative;
  flex: 1 1 0;
  min-width: 88px;
  max-width: 180px;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  border: 3px solid var(--line-strong);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  user-select: none;
}
.beat-box:active { transform: scale(0.97); }
.beat-box.flash { animation: boxflash .28s ease; }
@keyframes boxflash {
  0% { background: #fff; }
  40% { background: var(--note-e); border-color: var(--note-d); }
  100% { background: #fff; }
}
.beat-box .fruits { font-size: clamp(26px, 6vw, 52px); line-height: 1; letter-spacing: -2px; }
.beat-box .syllable {
  font-family: var(--font-round);
  font-weight: 800;
  color: var(--ink-soft);
  font-size: clamp(14px, 2.4vw, 18px);
}
.beat-box .count {
  position: absolute;
  top: 6px; left: 10px;
  font-weight: 800;
  color: var(--ink-soft);
  font-size: var(--text-sm);
}
.legend {
  display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5);
  margin-top: var(--space-4); color: var(--ink-soft); font-size: var(--text-sm);
}
.legend span b { color: var(--ink); }

/* ------------------------------ Staff ------------------------------------ */
.staff-wrap { overflow-x: auto; padding: var(--space-2) 0; }
.staff-svg { display: block; margin: 0 auto; max-width: 100%; height: auto; touch-action: manipulation; }
.note-readout {
  text-align: center;
  font-family: var(--font-round);
  font-weight: 800;
  font-size: var(--text-2xl);
  line-height: 1.2;
  min-height: 1.2em;
  margin: var(--space-3) 0;
}
.note-readout small { display: block; font-family: var(--font-body); font-weight: 600; font-size: var(--text-sm); color: var(--ink-soft); margin-top: var(--space-1); }
.letter-btn {
  border: none;
  width: 60px; height: 60px;
  border-radius: var(--radius-sm);
  font-family: var(--font-round);
  font-weight: 800;
  font-size: 26px;
  color: #fff;
  cursor: pointer;
  background: var(--ink);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .3);
}
.letter-btn:active { transform: translateY(2px); }

.txt-line  { color: var(--blue-strong); }
.txt-space { color: var(--pink-strong); }
.txt-good  { color: var(--green-strong); }
.txt-bad   { color: var(--red-strong); }

/* ---------------------------- Clef Draw ---------------------------------- */
.draw-stage {
  position: relative;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  border: 2px solid var(--line-strong);
  touch-action: none;
}
.draw-stage canvas { display: block; width: 100%; height: auto; touch-action: none; }
.swatches { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.swatch {
  width: var(--tap); height: var(--tap); border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line-strong); cursor: pointer;
}
.swatch.is-active { outline: 3px solid var(--ink); outline-offset: 2px; }

/* --------------------------- Song Library -------------------------------- */
.search-bar {
  display: flex; align-items: center;
  margin-bottom: var(--space-4);
}
.search-bar input {
  width: 100%;
  min-height: 52px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-4);
  font-family: var(--font-body); font-size: var(--text-md); color: var(--ink);
  background: var(--surface);
}
.search-bar input:focus { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--ink); }
.search-bar input::placeholder { color: var(--ink-soft); opacity: 1; }

.filter-row { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }

.song-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: var(--space-4);
}
.song-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 6px solid var(--sky);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.song-card h3 { font-size: var(--text-xl); margin: 0; }
.song-card .tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: var(--text-xs); font-weight: 700;
  padding: 2px 8px; border-radius: 4px; color: var(--ink); background: var(--tint); border: 1px solid var(--line);
}
.song-card .focus { font-size: var(--text-sm); color: var(--ink-soft); }
.song-card .focus b { color: var(--ink); }
.song-card .game {
  border-left: 4px solid var(--line-strong);
  padding: var(--space-1) 0 var(--space-1) var(--space-3);
  font-size: var(--text-sm); line-height: 1.5;
}
.song-card .game b { color: var(--ink); }
.song-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); margin-top: auto; }
.mini-btn {
  border: none;
  border-radius: var(--radius-sm);
  min-height: var(--tap);
  padding: 0 var(--space-4);
  font-weight: 800;
  font-size: var(--text-sm);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.mini-btn:active { transform: translateY(2px); }
.mini-btn--play { background: var(--note-f); color: var(--ink); box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.mini-btn--link { background: none; color: var(--ink); padding: 0; text-decoration: underline; text-underline-offset: 4px; font-weight: 700; }
.empty-note { text-align: center; color: var(--ink-soft); font-weight: 700; padding: var(--space-8) var(--space-3); grid-column: 1 / -1; }

/* ------------------------------ Utility ---------------------------------- */
.big-emoji-badge { font-size: 32px; }
.hint { color: var(--ink-soft); font-weight: 600; font-size: var(--text-sm); }
.spacer-sm { height: var(--space-3); }
.row-wrap { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }

/* ------------------------------ Piano ------------------------------------ */
.piano-wrap { overflow-x: auto; padding: var(--space-1) 2px var(--space-3); }
.piano {
  position: relative; display: flex; height: 240px; min-width: 680px;
  user-select: none; touch-action: manipulation;
}
.pkey-white {
  position: relative; flex: 1; background: #fff;
  border: 2px solid var(--ink); border-radius: 0 0 8px 8px;
  margin-right: -2px; cursor: pointer;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 12px;
}
.pkey-white:active, .pkey-white.active { background: var(--note-e); }
.pkey-white .lbl { font-weight: 800; color: var(--ink-soft); font-size: var(--text-sm); }
.pkey-black {
  position: absolute; top: 0; height: 60%; background: var(--ink);
  border-radius: 0 0 6px 6px; z-index: 2; cursor: pointer;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px;
}
.pkey-black:active, .pkey-black.active { background: var(--note-a); }
.pkey-black .lbl { color: #fff; font-weight: 800; font-size: 11px; }

/* -------------------------- Rhythm Flashcards ---------------------------- */
.rhythm-card { text-align: center; }
.rhythm-beats { display: flex; justify-content: center; gap: var(--space-1); flex-wrap: wrap; margin: var(--space-2) 0 var(--space-1); }
.rbeat { min-width: 84px; padding: 6px 4px; border-radius: var(--radius-sm); }
.rbeat.hit { background: var(--note-e); }
.rbeat.miss { background: #ffd3d3; }
.rbeat .glyph { display: flex; align-items: flex-end; justify-content: center; min-height: clamp(40px, 10vw, 64px); }
.rbeat .glyph .rnote-svg { height: clamp(40px, 10vw, 64px); width: auto; display: block; }
.rbeat .syl { font-weight: 800; color: var(--ink-soft); font-size: var(--text-sm); }
.barline { width: 4px; align-self: stretch; background: var(--ink); border-radius: 2px; margin: 0 4px; }

/* ---------------------------- Ukulele Chords ----------------------------- */
.uke-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); gap: var(--space-3); }
.uke-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--space-4) var(--space-3); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
}
.uke-card h3 { margin: 0; font-size: 1.875rem; }
.uke-diagram { width: 100%; max-width: 160px; height: auto; }
.uke-tip { margin: 0; font-size: var(--text-xs); color: var(--ink-soft); line-height: 1.4; min-height: 2.8em; }

/* ----------------------------- Musical Terms ----------------------------- */
.term-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 0 var(--space-6); margin-top: var(--space-4); }
/* Terms read like a word list on the board: rules between entries, not boxes. */
.term-card {
  border-top: 1px solid var(--line);
  padding: var(--space-4) 0 var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-start;
}
.term-cat-tag { font-size: var(--text-xs); font-weight: 700; color: var(--ink-soft); }
.term-card h3 { margin: 0; font-size: var(--text-xl); }
.term-abbr { font-family: Georgia, "Times New Roman", serif; font-style: italic; font-weight: 700; color: var(--pink-strong); font-size: var(--text-lg); }
.term-card p { margin: 0; color: var(--ink-soft); font-size: var(--text-sm); line-height: 1.45; }

/* ------------------------- Orchestra Instruments ------------------------- */
.orch-section-head {
  display: flex; align-items: center; gap: var(--space-3); margin: var(--space-6) 0 var(--space-3);
}
.orch-section-head:first-of-type { margin-top: var(--space-2); }
.orch-section-emoji {
  width: 40px; height: 40px; border-radius: var(--radius-sm); flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--sc, var(--sky));
}
.orch-section-emoji .orch-svg { width: 22px; height: 22px; }
/* Section colours are bright fills; the heading text is mixed toward ink so
   it passes AA. Browsers without color-mix() keep plain ink. */
.orch-section-head h3 {
  margin: 0; font-size: var(--text-xl);
  color: var(--ink);
  color: color-mix(in srgb, var(--sc, var(--ink)) 45%, #1a1033);
}
.orch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); gap: var(--space-3); }
.orch-card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-4) var(--space-3); cursor: pointer;
  background: var(--surface); border-bottom: 5px solid var(--sc, var(--sky));
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.orch-card:active { transform: translateY(2px); }
.orch-card.flash { animation: orchflash .3s ease; }
@keyframes orchflash { 40% { background: var(--tint); } }
.orch-icon { display: flex; align-items: flex-end; justify-content: center; height: 56px; }
.orch-icon .orch-svg { height: 100%; width: auto; max-width: 64px; }
.orch-name { font-weight: 800; font-size: var(--text-sm); color: var(--ink); text-align: center; }
.orch-credit { text-align: center; color: var(--ink-soft); font-size: var(--text-xs); margin-top: var(--space-5); }
.orch-credit a { color: var(--ink); }

/* --------------------------- Composer Spotlight --------------------------- */
.composer-timeline { padding: var(--space-3) var(--space-1) 0; }
.timeline-scroll { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; touch-action: pan-x; padding-top: 110px; }
.timeline-bar { position: relative; height: 4px; min-width: 100%; background: var(--line-strong); border-radius: 2px; margin: 0 10px 22px; }
.timeline-zoom-controls { display: flex; align-items: center; justify-content: center; gap: var(--space-2); margin-top: -6px; }
.timeline-zoom-btn {
  border: 2px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
  font-weight: 800; color: var(--ink);
  width: var(--tap); height: var(--tap); font-size: 20px; display: flex; align-items: center; justify-content: center;
}
.timeline-zoom-label { width: auto; padding: 0 var(--space-4); font-size: var(--text-sm); color: var(--ink-soft); }
.timeline-dot {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 16px; height: 16px; border-radius: 50%; background: var(--dc, var(--pink));
  border: 3px solid #fff;
}
.timeline-dot-label {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-weight: 800; font-size: var(--text-xs);
  color: var(--ink);
  color: color-mix(in srgb, var(--dc, var(--ink)) 50%, #1a1033);
  white-space: nowrap;
}
.composer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: var(--space-4); }
.composer-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--space-5); display: flex; gap: var(--space-4);
}
.composer-avatar {
  flex: none; width: 56px; height: 56px; border-radius: 50%;
  background: var(--ink);
  background: color-mix(in srgb, var(--ac, var(--purple)) 62%, #1a1033);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-round); font-weight: 800; font-size: 26px;
}
.composer-info { min-width: 0; }
.composer-info h3 { margin: 0 0 2px; font-size: var(--text-xl); }
.composer-meta { font-size: var(--text-sm); color: var(--ink-soft); margin-bottom: var(--space-2); }
.composer-facts { margin: 0 0 var(--space-3); padding-left: 20px; }
.composer-facts li { font-size: var(--text-sm); line-height: 1.45; margin-bottom: 6px; }
.composer-works { font-size: var(--text-sm); color: var(--ink-soft); margin: 0 0 var(--space-3); line-height: 1.45; }
@media (max-width: 420px) {
  .composer-card { flex-direction: column; }
}

/* ------------------------------ Song Maker ------------------------------- */
.sm-gridwrap { overflow-x: auto; padding: var(--space-1) 2px var(--space-2); }
.sm-grid { display: inline-flex; flex-direction: column; gap: 4px; min-width: 100%; }
.sm-row { display: flex; align-items: center; gap: 4px; }
.sm-rowlabel {
  width: 22px; flex: none; font-weight: 800; font-size: var(--text-sm); text-align: center;
  color: var(--ink);
  color: color-mix(in srgb, var(--cc, var(--ink)) 50%, #1a1033);
}
.sm-cell {
  width: 34px; height: 32px; flex: none; border-radius: 4px;
  background: var(--track); cursor: pointer;
}
.sm-cell.beatstart { margin-left: 8px; }
.sm-cell.on { background: var(--cc); box-shadow: inset 0 -3px 0 rgba(0,0,0,.16); }
.sm-cell.col-playing:not(.on) { background: #d8d4e2; }
.sm-cell.on.col-playing { filter: brightness(1.15); transform: scale(1.08); }

/* ------------------------------ Beat Maker ------------------------------- */
.bm-board { overflow-x: auto; padding: var(--space-1) 2px; }
.bm-row { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.bm-char {
  width: 78px; flex: none; border-radius: var(--radius-sm); padding: 6px 4px;
  background: var(--ic, #eee); color: var(--ink); text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.bm-char-emoji { font-size: 34px; line-height: 1; }
/* The name sits on a white chip: white text on the bright kit colours
   measured under 2:1. */
.bm-char-name {
  font-weight: 800; font-size: 12px; color: var(--ink);
  background: #fff; border-radius: 4px; padding: 0 6px; margin-top: 4px;
}
.bm-char.hit { animation: bmhit .22s ease; }
@keyframes bmhit {
  0% { transform: translateY(0) scale(1) rotate(0); }
  35% { transform: translateY(-10px) scale(1.16) rotate(-6deg); }
  100% { transform: translateY(0) scale(1) rotate(0); }
}
.bm-steps { display: flex; gap: 4px; }
.bm-step { width: 32px; height: 44px; flex: none; border-radius: 4px; background: var(--track); cursor: pointer; }
.bm-step.beatstart { margin-left: 8px; }
.bm-step.on { background: var(--ic); box-shadow: inset 0 -3px 0 rgba(0,0,0,.16); }
.bm-step.col-playing:not(.on) { background: #d8d4e2; }
.bm-step.on.col-playing { filter: brightness(1.15); transform: scale(1.08); }

/* --------------------------------- Bells --------------------------------- */
.bells-stage { display: flex; justify-content: center; }
.bells-wrap { display: flex; align-items: flex-start; gap: clamp(4px, 1.4vw, 12px); height: 260px; width: 100%; max-width: 760px; }
.bell-bar {
  flex: 1 1 0; min-width: 0; max-width: 90px;
  border: none; border-radius: 0 0 var(--radius-bar) var(--radius-bar); cursor: pointer;
  background: var(--bc);
  box-shadow: inset -5px 0 0 rgba(0,0,0,.14);
  display: flex; align-items: flex-end; justify-content: center; padding: 0 0 10px;
}
.bell-bar:active { transform: translateY(3px); }
.bell-bar.ring { animation: bellring .24s ease; }
@keyframes bellring { 40% { filter: brightness(1.25); } }
/* Letter on a white disc: white text on the yellow/green bars was ~1.4:1. */
.bell-label {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: #fff; color: var(--ink);
  font-weight: 800; font-size: 17px;
}
.bell-dots { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 6px 0; }
.bell-dot {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--ink); font-size: 14px;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.6); opacity: .85;
}
.bell-dot.now { outline: 3px solid var(--ink); outline-offset: 2px; transform: scale(1.15); opacity: 1; }

/* ----------------------------- Magic Link -------------------------------- */
.share-box {
  margin-top: var(--space-3); border-left: 4px solid var(--note-g);
  padding: var(--space-2) 0 var(--space-2) var(--space-4);
}
.share-msg { color: var(--ink); font-size: var(--text-sm); margin-bottom: var(--space-2); line-height: 1.45; }
.share-input {
  width: 100%; min-height: var(--tap); border: 2px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 0 var(--space-3); font-family: var(--font-body); font-size: var(--text-sm);
  color: var(--ink); background: #fff;
}

/* --------------------------- Install banner ------------------------------ */
.install-banner {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  width: min(560px, calc(100vw - 24px));
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.install-banner__text { flex: 1; font-size: var(--text-sm); color: var(--ink-soft); line-height: 1.4; min-width: 0; }
.install-banner__text b { display: block; font-size: var(--text-md); color: var(--ink); }
.install-banner__btn {
  flex: none; border: none; border-radius: var(--radius-sm); min-height: var(--tap); padding: 0 var(--space-5);
  font-weight: 800; font-size: var(--text-sm); color: #fff;
  background: var(--ink); cursor: pointer;
}
.install-banner__close {
  flex: none; border: none; background: transparent; color: var(--ink-soft);
  width: var(--tap); height: var(--tap);
  font-size: 18px; font-weight: 800; cursor: pointer;
}

/* ------------------------------- Quiz Mode -------------------------------- */
.quiz-menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: var(--space-4); }
.quiz-cat-card { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: 0; }
.quiz-cat-head { display: flex; align-items: center; gap: var(--space-2); }
.quiz-cat-head h3 { margin: 0; font-size: var(--text-xl); }

.quiz-progress-track { height: 8px; background: var(--track); border-radius: 4px; margin: var(--space-3) 0 var(--space-4); overflow: hidden; }
.quiz-progress-fill { height: 100%; background: var(--note-g); transition: width .25s ease; }

.quiz-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: var(--space-3); margin-top: var(--space-4); }
.quiz-option-btn {
  border: 2px solid var(--line-strong); border-radius: var(--radius-sm); padding: var(--space-4) var(--space-3); cursor: pointer;
  min-height: 56px;
  font-family: var(--font-round); font-weight: 800; font-size: var(--text-md); color: var(--ink);
  background: var(--surface);
}
.quiz-option-btn:active { transform: translateY(2px); }
.quiz-option-btn.is-correct { background: var(--green-strong); border-color: var(--green-strong); color: #fff; }
.quiz-option-btn.is-wrong { background: var(--red-strong); border-color: var(--red-strong); color: #fff; }
.quiz-option-btn.is-disabled { opacity: 0.55; cursor: default; }

.quiz-sheet { text-align: left; }
.quiz-score-big { font-family: var(--font-round); font-size: var(--text-2xl); font-weight: 800; margin-top: 6px; }
.quiz-grade { font-family: var(--font-round); font-weight: 800; font-size: var(--text-lg); color: var(--ink-soft); margin-bottom: var(--space-3); }
.quiz-review-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; }
.quiz-review-list li { padding: var(--space-2) 0; border-top: 1px solid var(--line); font-weight: 700; font-size: var(--text-sm); }
.quiz-review-list li:first-child { border-top: none; }
.quiz-review-list li.is-wrong { color: var(--red-strong); }
.quiz-review-detail { display: block; font-weight: 500; color: var(--ink-soft); font-size: var(--text-xs); margin-top: 2px; }

/* ---------------------------- Small screens ------------------------------ */
@media (max-width: 380px) {
  .card { padding: var(--space-4); }
  .btn { padding: var(--space-3) var(--space-5); }
  .bar { padding-left: 40px; padding-right: 40px; }
  .bar::before { left: 14px; }
  .bar::after { right: 14px; }
}

/* ---------------------------- Reduced motion ----------------------------- */
/* Feedback still happens (colour changes, the .hit/.ring classes), it just
   doesn't bounce. Durations go to ~0 rather than "none" so any code waiting
   for animationend still gets it. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------ Print ------------------------------------ */
@media print {
  .app-header, .app-footer, .install-banner, .back-btn { display: none !important; }
}
