/* ─── e-Orch KeyPro · Kids ─────────────────────────────────────────
   Its own stylesheet. It shares nothing with the main app's style.css,
   which is a dark Courier instrument — opposite in every respect.
   Nothing here is scoped to the other UI, and nothing there reaches in. */

:root {
  --cream:    #fdeedd;
  --ink:      #0f3046;
  --ink-soft: #4a6b80;
  --card:     #ffffff;
  --yellow:   #f7c948;
  --yellow-d: #e0a800;
  --teal:     #17a2b8;
  --coral:    #ef7d7d;

  /* Key colours, in order. Six is the default; the sequence repeats. */
  --k1: #f8dd82;
  --k2: #f4aab0;
  --k3: #a9ded3;
  --k4: #a9bdec;
  --k5: #f7bd8f;
  --k6: #f8dd82;

  --shadow: 0 4px 0 var(--ink);
  --radius: 18px;
  /* Light theme: the e-Orch mark takes the same ink as "KeyPro" (see .brand-mark).
     Dark themes show the gold with a soft glow instead. */
  --logo-filter: none;
  --logo-ink: 1;
}

:root[data-kids-theme="dark"] {
  --cream:    #15202b;
  --ink:      #eaf3f8;
  --ink-soft: #9fb6c4;
  --card:     #1e2d3a;
  --shadow: 0 4px 0 #000;
  --logo-filter: drop-shadow(0 0 14px rgba(212, 175, 55, 0.3));
  --logo-ink: 0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-kids-theme="light"]) {
    --cream:    #15202b;
    --ink:      #eaf3f8;
    --ink-soft: #9fb6c4;
    --card:     #1e2d3a;
    --shadow: 0 4px 0 #000;
    --logo-filter: drop-shadow(0 0 14px rgba(212, 175, 55, 0.3));
    --logo-ink: 0;
  }
}

/* Self-hosted: Google Fonts is slow or blocked in some regions. */
@font-face {
  font-family: 'Quicksand';
  src: url('../vendor/quicksand-latin.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  color: var(--ink);
  /* A rounded sans for Latin, with CJK faces behind it. Quicksand and
     Baloo render the playful look of the designs; the system stack takes
     over for Han characters, which those fonts do not cover. */
  font-family: 'Quicksand', 'Varela Round', 'Noto Sans TC', 'PingFang TC',
               'Microsoft JhengHei', 'Hiragino Sans', system-ui, sans-serif;
  font-weight: 700;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* ─── Screens ───────────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.on { display: flex; }

/* ─── Generic pieces ────────────────────────────────────────────── */
.pill, .btn {
  font: inherit;
  /* Han characters will happily break one-per-line when a flex item is
     squeezed, which turned 家長專區 into a vertical column on a phone. */
  white-space: nowrap;
  color: var(--ink);
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 10px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  line-height: 1;
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active, .pill:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn--go {
  background: var(--yellow);
  font-size: 1.35rem;
  padding: 16px 34px;
  border-radius: 999px;
}
.btn--rec { background: var(--card); }
.btn--rec .dot { width: 16px; height: 16px; border-radius: 50%; background: #e23b3b; }
.btn--on { background: var(--yellow); }
.btn--teal { background: var(--teal); color: #fff; }
.icon-btn { width: 52px; height: 52px; padding: 0; justify-content: center; border-radius: 50%; }

/* ─── Gate ──────────────────────────────────────────────────────── */
#gate { align-items: center; justify-content: center; text-align: center; gap: 4px; }
.gate-top { position: absolute; top: 18px; left: 18px; right: 18px; display: flex; align-items: center; gap: 8px; }
.gate-top .pill { flex-shrink: 0; }
@media (max-width: 430px) {
  .gate-top .pill { padding: 8px 12px; font-size: 0.85rem; }
}
/* The e-Orch mark is the brand's gold image; "KeyPro Kids" is live text so it takes
   the theme's ink (keyprologo.png bakes it in grey, which vanishes on dark).
   The size keeps the whole name on one line down to a 320px phone. */
.brand { display: inline-flex; align-items: center; justify-content: center; gap: 0.28em; white-space: nowrap;
         font-size: clamp(1.9rem, min(8.4vw, 11vh), 4.6rem); font-weight: 700; letter-spacing: -0.02em;
         line-height: 1; color: var(--ink); margin: 14px 0 4px; }
/* The image always sets the size. In light mode it is used only as a mask over
   a fill of the text colour, so the mark matches "KeyPro" exactly; in dark mode
   the gold image itself shows. */
.brand-mark { display: block; position: relative; }
.brand-mark img { height: 0.92em; width: auto; display: block; filter: var(--logo-filter); }
.brand-mark::after {
  content: ''; position: absolute; inset: 0; background: currentColor;
  -webkit-mask: url(../logo1.png) center / contain no-repeat;
          mask: url(../logo1.png) center / contain no-repeat;
  opacity: var(--logo-ink);
}
:root:not([data-kids-theme="dark"]) .brand-mark img { opacity: calc(1 - var(--logo-ink)); }

/* Pastel fills stay pastel in both themes, so text on them keeps the light
   theme's dark ink; the dark theme's near-white ink washes out on them. */
.note-bubble, .btn--go, .btn--on, .star,
.row-toggle[aria-pressed="true"], .chip[aria-pressed="true"] { color: #0f3046; }
.tagline { font-size: clamp(0.95rem, 3.4vw, 1.4rem); margin: 6px 16px 18px; }
.notes { display: flex; gap: clamp(6px, 2vw, 16px); margin-bottom: 26px; flex-wrap: wrap; justify-content: center; }
.note-bubble {
  width: clamp(48px, 11vw, 86px); aspect-ratio: 1; border-radius: 50%;
  border: 2.5px solid var(--ink); box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: clamp(0.8rem, 2.4vw, 1.3rem);
}

.build {
  position: absolute;
  bottom: calc(8px + env(safe-area-inset-bottom));
  left: 0; right: 0;
  margin: 0;
  text-align: center;
  font-size: 0.58rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  opacity: 0.6;
}

/* ─── Play surface ──────────────────────────────────────────────── */
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.oct-group { display: flex; align-items: center; gap: 8px; }
.oct-dots { display: flex; gap: 5px; }
.oct-dots i { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--ink); display: block; }
.oct-dots i.on { background: var(--ink); }
.oct-dots i.off { opacity: 0.3; }   /* the instrument can't play every key here (violin below G3) */
#octDown[disabled], #octUp[disabled] { opacity: 0.4; cursor: not-allowed; }
/* A key the instrument cannot play (a violin below G3): dimmed, and taps pass through. */
.key.key--out { opacity: 0.3; filter: grayscale(1); pointer-events: none; }

#keys {
  flex: 1;
  display: grid;
  gap: clamp(5px, 1.2vw, 12px);
  padding: 0 clamp(8px, 1.6vw, 16px) 6px;
  min-height: 0;
}
.key {
  position: relative;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 14px 4px 18px;
  touch-action: none;
  overflow: hidden;
  transition: transform 0.05s;
}
/* Keys stay pastel in both themes, so their labels always use the light theme's
   dark ink; the page ink turns near-white in dark mode and washes out on them. */
.key, .preview-key { --key-ink: #0f3046; --key-ink-soft: #4a6b80; color: var(--key-ink); }
.key .note, .key .freq, .preview-key .note, .preview-key .freq { color: var(--key-ink-soft) !important; }
.key .spk { position: absolute; top: 12px; left: 0; right: 0; text-align: center; font-size: 1.1rem; opacity: 0.45; }
.key .solfege { font-size: clamp(1.1rem, 3.4vw, 2.1rem); }
.key .note { font-size: clamp(0.65rem, 1.7vw, 1rem); color: var(--ink-soft); margin-top: 2px; }
.key .freq { font-size: clamp(0.6rem, 1.5vw, 0.9rem); color: var(--ink-soft); margin-top: 1px; }
/* --vel is the tap's loudness (0.12 soft … 1 loud): soft taps wash the key out lighter,
   loud taps deepen and saturate it, so the colour shows how hard the note was played. */
.key.down { transform: translateY(3px);
            filter: brightness(calc(1.35 - 0.5 * var(--vel, 0.5))) saturate(calc(0.8 + 0.5 * var(--vel, 0.5))); }
.key.lit  { filter: brightness(1.2); }
#keys.bare .spk, #keys.bare .note { display: none; }

/* Guidance, not controls. These used to carry the pill/shadow treatment and
   read as tappable; they are plain captions now. */
.instruct {
  display: flex; gap: clamp(14px, 4vw, 34px); justify-content: center; flex-wrap: wrap;
  margin: 0; padding: 2px 10px 12px;
  font-size: clamp(0.62rem, 1.9vw, 0.85rem); font-weight: 500;
  color: var(--ink-soft);
}
.instruct span { display: inline-flex; align-items: center; gap: 6px; }
.instruct b { font-size: 1.1em; color: var(--ink); }

/* Portrait nudge — informative, never blocking. */
#rotate {
  display: none; position: fixed; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--cream);
  border-radius: 999px; padding: 9px 18px; font-size: 0.8rem; white-space: nowrap;
}
@media (orientation: portrait) { #play.on #rotate { display: block; } }

/* ─── Instrument picker ─────────────────────────────────────────── */
.sheet { flex: 1; overflow-y: auto; padding: 0 16px 16px; -webkit-overflow-scrolling: touch; }
.title-pill {
  border: 2.5px solid var(--teal); background: var(--card); border-radius: 999px;
  padding: 9px 30px; font-size: 1.15rem; box-shadow: var(--shadow);
}
.grid-instr {
  display: grid; gap: 12px; padding-top: 6px;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
}
.instr {
  position: relative; background: var(--card); border: 2.5px solid var(--ink);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 6px 12px; text-align: center; cursor: pointer; font: inherit; color: inherit;
}
.instr .bubble {
  width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 8px;
  display: grid; place-items: center; font-size: 1.6rem; border: 2px solid var(--ink);
}
.instr .cn { font-size: 1rem; }
.instr .en { font-size: 0.68rem; color: var(--ink-soft); letter-spacing: 0.06em; }
.instr[aria-pressed="true"] { border-color: var(--coral); box-shadow: 0 4px 0 var(--coral); }
.instr[aria-pressed="true"]::after {
  content: '✓'; position: absolute; top: -10px; right: -10px;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 0.9rem;
}
.picker-foot { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 16px; flex-wrap: wrap; }
.seg { display: inline-flex; gap: 8px; align-items: center; background: var(--card);
       border: 2.5px solid var(--ink); border-radius: 999px; padding: 7px 10px; box-shadow: var(--shadow); }
.seg .btn { box-shadow: none; padding: 7px 16px; }

/* ─── Finished ──────────────────────────────────────────────────── */
#done { align-items: center; justify-content: center; padding: 16px; }
.card {
  background: var(--card); border: 2.5px solid var(--ink); border-radius: 22px;
  box-shadow: 0 6px 0 var(--coral);
  padding: 22px 20px; width: min(560px, 100%); max-height: 100%; overflow-y: auto; text-align: center;
}
.star { width: 64px; height: 64px; border-radius: 50%; background: var(--yellow);
        border: 2.5px solid var(--ink); display: grid; place-items: center; font-size: 1.8rem; margin: 0 auto 10px; }
.bravo { font-size: 1.9rem; margin: 4px 0 16px; }
/* Shared song: listen-only. Naming and re-sharing belong to the child who made it. */
.shared-title { font-size: 1.25rem; font-weight: 700; margin: -8px 0 16px; overflow-wrap: anywhere; }
#done.shared .field-label, #done.shared #title, #done.shared .ideas,
#done.shared #copyBtn, #done.shared #shareBtn, #done.shared .share-note,
#done.shared #saveBtn { display: none; }
/* A song from 我的作品: already named and saved, but still the family's to share. */
#done.saved .field-label, #done.saved #title, #done.saved .ideas, #done.saved #saveBtn { display: none; }
#done.shared #replayBtn { animation: invite 1.6s ease-in-out infinite; }
@keyframes invite { 50% { transform: scale(1.12); } }
@media (prefers-reduced-motion: reduce) { #done.shared #replayBtn { animation: none; } }
#done.shared .link-back { font-size: 1.05rem; }
.player { display: flex; align-items: center; gap: 12px; background: var(--cream);
          border: 2.5px solid var(--ink); border-radius: 999px; padding: 8px 16px 8px 8px; }
.player canvas { flex: 1; height: 34px; min-width: 0; }
.player .dur { font-size: 0.85rem; }
.field-label { text-align: left; font-size: 0.9rem; margin: 18px 0 6px; }
#title {
  width: 100%; font: inherit; font-size: 1.1rem; color: var(--ink);
  background: var(--card); border: 2.5px solid var(--ink); border-radius: 14px; padding: 12px 14px;
  -webkit-user-select: text; user-select: text;
}
.ideas { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: 0.78rem; }
.ideas .btn { padding: 7px 14px; font-size: 0.78rem; }
.idea-list { display: contents; }
.ideas .idea-more { background: transparent; }
.done-actions { display: flex; gap: 12px; margin-top: 18px; }
.done-actions .btn { flex: 1; justify-content: center; font-size: 1rem; padding: 14px; }
.done-actions { flex-wrap: wrap; }
.share-note { font-size: 0.78rem; color: var(--ink-soft); margin-top: 14px; line-height: 1.5; }
.link-back { display: inline-block; margin-top: 10px; color: var(--ink); font-size: 0.9rem; }

/* ─── Parents ───────────────────────────────────────────────────── */
.panels { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.panel { background: var(--card); border: 2.5px solid var(--ink); border-radius: var(--radius);
         box-shadow: var(--shadow); padding: 16px; }
.panel h2 { font-size: 1.1rem; margin: 0 0 12px; display: flex; align-items: baseline; gap: 8px; }
.panel h2 small { font-size: 0.62rem; color: var(--ink-soft); letter-spacing: 0.14em; font-weight: 700; }
/* The English caption is a helper beside the Chinese heading; in English it would just repeat it. */
html:lang(en) .panel h2 small { display: none; }
.stepper { display: flex; align-items: center; gap: 14px; }
.stepper .num { font-size: 2rem; min-width: 1.6em; text-align: center; }
/* Miniature of the play-screen keyboard: same grid and .key markup, scaled down. */
.keys-preview { display: grid; gap: 4px; height: 92px; margin-top: 12px; pointer-events: none; }
.keys-preview .key { border-width: 2px; border-radius: 8px; box-shadow: var(--shadow);
                     padding: 2px 1px 6px; min-width: 0; }
.keys-preview .key .solfege { font-size: 0.8rem; }
.keys-preview .key .note    { font-size: 0.6rem; margin-top: 0; }
.keys-preview .key .freq    { font-size: 0.55rem; margin-top: 0; }
/* Two rows: each row gets the single row's height, so three labels still fit. */
.keys-preview.two-rows { height: 176px; }
.keys-preview .key > span { max-width: 100%; overflow: hidden; white-space: nowrap; }
.keys-preview .key .solfege { font-size: clamp(0.6rem, 2.6vw, 0.8rem); }
.keys-preview .key .note    { font-size: clamp(0.5rem, 2vw, 0.6rem); }
/* "1047 Hz" can't fit a narrow key on one line, so the unit drops below. */
.keys-preview .key .freq    { font-size: clamp(0.48rem, 1.8vw, 0.55rem); white-space: normal; line-height: 1.1; text-align: center; }
.panel .note-line { font-size: 0.78rem; color: var(--ink-soft); margin: 12px 0 0; line-height: 1.5; }
.rows { display: grid; gap: 8px; }
.row-toggle { display: flex; justify-content: space-between; align-items: center; gap: 10px;
              border: 2.5px solid var(--ink); border-radius: 999px; padding: 9px 16px;
              background: var(--card); font: inherit; color: inherit; cursor: pointer; }
.row-toggle[aria-pressed="true"] { background: var(--yellow); }
.preview-key { width: 92px; border: 2.5px solid var(--ink); border-radius: 12px; background: var(--k1);
               display: flex; flex-direction: column; align-items: center; justify-content: center;
               text-align: center; cursor: default; }
.preview-key .solfege { font-size: 1.5rem; }
.preview-key .note { font-size: 0.85rem; color: var(--ink-soft); }
.preview-key .freq { font-size: 0.75rem; color: var(--ink-soft); }
.labels-wrap { display: flex; gap: 14px; align-items: stretch; }
.labels-wrap .rows { flex: 1; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips--sm { gap: 6px; }
.chips--sm .chip { padding: 6px 10px; min-width: 2.6em; white-space: nowrap; text-align: center; font-size: 0.85rem; }
.setting-line.setting-line--stack { flex-direction: column; align-items: flex-start; gap: 8px; }
.chip { font: inherit; color: inherit; background: var(--card); border: 2.5px solid var(--ink);
        border-radius: 999px; padding: 9px 16px; cursor: pointer; font-size: 0.9rem; }
.chip[aria-pressed="true"] { background: var(--k3); }
.tip { display: flex; gap: 8px; align-items: flex-start; background: var(--cream);
       border-radius: 12px; padding: 10px 12px; margin-top: 12px; font-size: 0.78rem; line-height: 1.5; }
.tip b { background: var(--coral); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 0.68rem; white-space: nowrap; }
.switch { width: 58px; height: 32px; border-radius: 999px; border: 2.5px solid var(--ink);
          background: var(--card); position: relative; cursor: pointer; flex-shrink: 0; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px;
                 border-radius: 50%; background: var(--ink); transition: left 0.14s; }
.switch[aria-pressed="true"] { background: var(--teal); }
.switch[aria-pressed="true"]::after { left: 28px; background: #fff; }
.setting-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; }
.setting-line + .setting-line { border-top: 2px solid var(--cream); }
.setting-line .sub { font-size: 0.66rem; color: var(--ink-soft); letter-spacing: 0.04em; }
.credits { margin: 0; font-size: 0.72rem; line-height: 1.6; color: var(--ink-soft); }
.credits a { color: inherit; white-space: nowrap; }

/* ─── Walkthrough ───────────────────────────────────────────────── */
/* The spot's shadow dims the page without catching taps, so the keys can be
   tried through it. Everything that must not be pressed is switched off here. */
#tour { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
#tour[hidden] { display: none; }
#play.touring .topbar,
#play.touring:not(.touring-keys) #keys { pointer-events: none; }
#tourSpot {
  position: fixed; border: 3px solid var(--yellow); border-radius: 16px;
  box-shadow: 0 0 0 200vmax rgba(15, 48, 70, 0.62);
}
#tourCard {
  position: fixed; pointer-events: auto;
  width: min(calc(100vw - 24px), 340px);
  background: var(--card); color: var(--ink);
  border: 2.5px solid var(--ink); border-radius: 18px; box-shadow: var(--shadow);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 5px;
}
#tourCount { font-size: 0.72rem; color: var(--ink-soft); }
#tourTitle { font-size: 1.1rem; font-weight: 700; }
#tourBody  { font-size: 0.95rem; line-height: 1.4; }
.tour-actions { display: flex; gap: 6px; margin-top: 5px; }
.tour-actions .btn {
  flex: 1; padding: 7px 4px; font-size: 0.85rem; min-width: 0; white-space: nowrap;
  justify-content: center; text-align: center;
}
.tour-actions .btn[hidden] { display: none; }
.tour-tag {
  position: fixed; transform: translateX(-50%); white-space: nowrap;
  background: var(--ink); color: var(--card); border-radius: 999px;
  padding: 2px 8px; font-size: 0.78rem; font-weight: 700;
}
.tour-tag[hidden] { display: none; }
@media (orientation: landscape) { #tourCard { width: min(42vw, 340px); } }
@media (min-width: 600px) and (min-height: 600px) {
  #tourCard { width: 420px; padding: 16px 20px; gap: 7px; }
  #tourTitle { font-size: 1.35rem; }
  #tourBody { font-size: 1.1rem; }
  .tour-actions .btn { font-size: 1rem; padding: 10px 6px; }
  .tour-tag { font-size: 0.95rem; padding: 4px 12px; }
}
#play.touring #rotate { display: none; }

/* Start-of-session volume reminder: shows, holds, fades. Never catches a tap. */
#volHint {
  position: fixed; left: 50%; top: 50%; z-index: 55; pointer-events: none;
  transform: translate(-50%, -50%); width: max-content; max-width: min(90vw, 460px); text-align: center;
  background: var(--ink); color: var(--card); border-radius: 22px;
  padding: 12px 22px; font-size: 1.05rem; font-weight: 700; line-height: 1.4; opacity: 0;
}
#volHint[hidden] { display: none; }
#volHint.show { animation: vol-hint 4s ease forwards; }
@keyframes vol-hint { 0% { opacity: 0; } 10%, 75% { opacity: 1; } 100% { opacity: 0; } }

/* Velocity off: every tap is full volume, so the loud/soft captions go. */
body.no-vel .instruct { display: none; }

/* ─── Grown-up check ────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 48, 70, 0.55);
  display: grid; place-items: center; padding: 20px;
}
.overlay[hidden] { display: none; }
.quiz-box {
  background: var(--card); border: 2.5px solid var(--ink); border-radius: 22px;
  box-shadow: 0 6px 0 var(--coral); padding: 24px 22px; width: min(360px, 100%); text-align: center;
}
.quiz-ask { margin: 0; font-size: 0.85rem; color: var(--ink-soft); font-weight: 500; }
.quiz-sum { margin: 10px 0 16px; font-size: 2rem; letter-spacing: 0.04em; }
#quizAnswer {
  width: 100%; font: inherit; font-size: 1.6rem; text-align: center; color: var(--ink);
  background: var(--cream); border: 2.5px solid var(--ink); border-radius: 14px; padding: 10px;
  -webkit-user-select: text; user-select: text;
}
.quiz-wrong { color: var(--coral); font-size: 0.85rem; margin: 10px 0 0; }
.quiz-wrong[hidden] { display: none; }
.quiz-actions { display: flex; gap: 10px; margin-top: 16px; }
.quiz-actions .btn { flex: 1; justify-content: center; }
.quiz-box.shake { animation: shake 0.3s; }
@keyframes shake {
  25% { transform: translateX(-7px); } 75% { transform: translateX(7px); }
}
@media (prefers-reduced-motion: reduce) { .quiz-box.shake { animation: none; } }

/* Landscape phones: the landing page has to fit in about 390px of height. */
@media (max-height: 480px) {
  .note-bubble { width: 46px; font-size: 0.8rem; }
  .notes { margin-bottom: 12px; }
  .tagline { margin-bottom: 10px; }
  .gate-login { margin-top: 10px; }
  .login-note, .build { display: none; }
}

/* ─── Melody tutor ────────────────────────────────────────────────── */
/* e-Orch AI button: a band of colour flowing round its edge. A square of colour
   spins behind a card-coloured centre, leaving only the rim showing. Spinning
   an element rather than animating a gradient stays on the compositor, so it
   never competes with taps on the keys. overflow clips at the padding edge,
   hence no real border: the padding adds the 2.5px back. */
#ideaBtn {
  position: relative; overflow: hidden; isolation: isolate;
  border: 0; padding: 12.5px 20.5px; background: transparent;
  box-shadow: var(--shadow), 0 0 12px rgba(175, 82, 222, 0.45);
}
#ideaBtn:active { box-shadow: 0 1px 0 var(--ink), 0 0 12px rgba(175, 82, 222, 0.45); }
#ideaBtn::before {
  content: ''; position: absolute; z-index: -2; top: 50%; left: 50%;
  width: 220%; aspect-ratio: 1; transform: translate(-50%, -50%);
  background: conic-gradient(#5ac8fa, #5e5ce6, #bf5af2, #ff375f, #ff9f0a, #5ac8fa);
  animation: ai-spin 4s linear infinite;
}
#ideaBtn::after {
  content: ''; position: absolute; z-index: -1; inset: 2.5px;
  background: var(--card); border-radius: 999px;
}
@keyframes ai-spin { to { transform: translate(-50%, -50%) rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #ideaBtn::before { animation: none; } }

.key.tutor-lit { filter: brightness(1.12) saturate(1.2); transform: translateY(3px);
                 outline: 4px solid var(--coral); outline-offset: -4px; }
#ideaBubble { display: flex; align-items: center; gap: 8px; margin: 0 clamp(8px, 1.6vw, 16px) 8px;
              padding: 8px 10px 8px 14px; background: var(--card); border: 2px solid var(--ink); border-radius: 16px; }
#ideaBubble[hidden] { display: none; }
#ideaText { flex: 1; min-width: 0; font-size: 0.9rem; line-height: 1.4; }
#ideaBubble .pill { flex-shrink: 0; padding: 6px 12px; font-size: 0.82rem; }
#ideaBubble .icon-btn { width: 36px; height: 36px; padding: 0; }
.done-actions #tutorBtn { flex-basis: 100%; }
#done.shared #tutorBtn { display: none; }
.quiz-box.tutor-box { width: min(420px, 100%); text-align: left; }
.tutor-row { display: flex; gap: 10px; margin: 0 0 12px; font-size: 1rem; line-height: 1.5; }
.quiz-actions .btn[hidden] { display: none; }

/* Phones, either way up: the labels on the octave and record buttons are hidden
   from sight only, so screen readers still announce them; ▼ ▲ and the red dot
   carry the meaning. */
@media (max-width: 600px), (orientation: landscape) and (max-height: 480px) {
  #play .topbar { gap: 8px; row-gap: 4px; }
  #toPicker { min-width: 0; padding: 0 12px; height: 44px; justify-content: center; }
  #instrName { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  #play .oct-group { flex-shrink: 0; gap: 6px; }
  #ideaBtn { justify-content: center; height: 44px; padding-top: 0; padding-bottom: 0; white-space: nowrap; }
  #play .topbar .icon-btn, #octDown, #octUp, #recBtn, #velBtn, #jamBtn:not(.btn--on) {
    width: 44px; height: 44px; padding: 0; justify-content: center; flex-shrink: 0;
  }
  #octDown span, #octUp span, #recBtn span:not(.dot), #velBtn span, #jamBtn:not(.btn--on) #jamLabel {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
  }
}

/* Upright phones: two full rows instead of three part-empty ones. */
@media (max-width: 600px) and (orientation: portrait) {
  #toGate { order: 1; }
  #toPicker { order: 2; flex: 1 1 0; }
  #play .oct-group { order: 3; }
  #play .topbar .spacer { order: 4; flex: 0 0 100%; height: 0; }     /* forces the second row */
  #velBtn { order: 2; }                                             /* beside the instrument */
  #ideaBtn { order: 5; flex: 1 1 auto; }
  #jamBtn { order: 6; }                                             /* beside record */
  #recBtn { order: 6; }
  #toParentsPlay { order: 7; }
}

/* Sideways phones are short, so every control shares one row and the AI idea
   is a slim strip below it. The keys keep the height. */
@media (orientation: landscape) and (max-width: 600px), (orientation: landscape) and (max-height: 480px) {
  #play .topbar { flex-wrap: nowrap; padding: 6px 12px; }
  #toPicker { flex: 0 1 auto; }
  #ideaBtn { flex-shrink: 0; }
  #ideaBubble { margin-bottom: 6px; padding: 3px 4px 3px 12px; }
  #ideaText { font-size: 0.82rem; line-height: 1.25; }
  #ideaBubble .pill { padding: 3px 10px; }
  #ideaBubble .icon-btn { width: 32px; height: 32px; padding: 0; }
  #play .instruct { padding-bottom: 6px; }
}

/* ─── Release notes ───────────────────────────────────────────────── */
.quiz-box.release-box { width: min(460px, 100%); max-height: 86dvh; display: flex; flex-direction: column; text-align: left; }
.release-title { margin: 0 0 10px; font-size: 1.2rem; text-align: center; }
.release-body { overflow-y: auto; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
.release-body h3 { margin: 14px 0 6px; font-size: 0.85rem; color: var(--ink-soft); }
.release-body h3:first-child { margin-top: 0; }
.release-body ul { margin: 0; padding-left: 20px; }
.release-body li { margin-bottom: 6px; font-size: 0.85rem; font-weight: 500; line-height: 1.5; }

/* The suggested preset name is long, so on phones it gets the full width. */
@media (max-width: 430px) {
  #presetPanel .setup-link, #classPanel .setup-link { flex-direction: column; }
  #presetPanel .setup-link input, #classPanel .setup-link input { width: 100%; flex: none; }
  #presetPanel .setup-link .btn, #classPanel .setup-link .btn { justify-content: center; }
}

/* ─── Google sign-in and 我的作品 ─────────────────────────────────── */
.gate-login { width: min(340px, 100%); margin-top: 18px; }
.gate-signed { margin: 14px 0 0; font-size: 0.85rem; color: var(--ink-soft); }
.login-note { margin: 8px 0 0; font-size: 0.78rem; color: var(--ink-soft); }
.login-status { margin: 6px 0 0; font-size: 0.78rem; color: var(--coral); }
.login-status:empty { display: none; }
.oauth-row { display: flex; flex-direction: column; align-items: center; width: 100%; }
.gsi-slot { display: flex; justify-content: center; min-height: 44px; }
.oauth-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid #747775; background: #fff; color: #1f1f1f;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 0.95rem; font-weight: 500; cursor: pointer;
}
.oauth-btn.hidden { display: none; }
.oauth-btn:disabled { opacity: 0.6; cursor: default; }
.oauth-logo { width: 1.15em; height: 1.15em; flex: none; }
:root[data-kids-theme="dark"] .oauth-btn { background: #131314; color: #e3e3e3; border-color: #8e918f; }
@media (prefers-color-scheme: dark) {
  :root:not([data-kids-theme="light"]) .oauth-btn { background: #131314; color: #e3e3e3; border-color: #8e918f; }
}
.panel--wide { grid-column: 1 / -1; }
.panel[hidden], #accountOut[hidden], #accountIn[hidden], .gate-login[hidden], .gate-signed[hidden] { display: none; }
.note-line--top { margin: 0 0 12px; }
#parentsOAuthRow { align-items: flex-start; max-width: 340px; }
.works { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 6px; }
.work { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px;
        border: 2.5px solid var(--ink); border-radius: 999px; background: var(--cream); }
.work-title { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.work-date { font-size: 0.75rem; color: var(--ink-soft); white-space: nowrap; }
/* Three actions per row: compact round buttons so a phone-width row still fits. */
.work { gap: 6px; }
.work .icon-btn { width: 38px; height: 38px; min-width: 38px; padding: 0; font-size: 0.9rem;
                  flex-shrink: 0; display: grid; place-items: center; box-shadow: 0 2px 0 var(--ink); }
.work .work-action { height: 38px; padding: 0 14px; font-size: 0.85rem; flex-shrink: 0;
                     white-space: nowrap; box-shadow: 0 2px 0 var(--ink); }
.work-rename { flex: 1; min-width: 0; width: 0; font: inherit; font-weight: 700; color: var(--ink);
               background: var(--card); border: 2px solid var(--ink); border-radius: 10px; padding: 6px 10px;
               -webkit-user-select: text; user-select: text; }
.done-actions .btn[hidden] { display: none; }
.login-ask-text { font-size: 0.85rem; color: var(--ink-soft); margin: 0 0 14px; line-height: 1.5; }
#loginAsk .oauth-row { margin: 0 auto; max-width: 300px; }
/* Grown-ups screen: signed-in name and sign-out in the top-right corner. */
.account-corner { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.account-corner[hidden] { display: none; }
.account-corner .who { font-size: 0.75rem; font-weight: 500; color: var(--ink-soft);
                         overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.chip--sm { padding: 6px 14px; font-size: 0.8rem; }
/* Phones: keep sign-out on the first row, top-right; the subtitle drops below. */
@media (max-width: 600px) {
  #parents .topbar > [data-k="parentsSub"] { order: 10; flex-basis: 100%; }
}

/* Han characters differ in shape between 繁體, 简体 and Japanese, so each
   language puts its own system fonts first after the rounded Latin faces. */
html:lang(zh-Hans) body {
  font-family: 'Quicksand', 'Varela Round', 'PingFang SC', 'Noto Sans SC',
               'Microsoft YaHei', 'Hiragino Sans GB', system-ui, sans-serif;
}
html:lang(ja) body {
  font-family: 'Quicksand', 'Varela Round', 'Hiragino Maru Gothic ProN', 'Hiragino Sans',
               'Noto Sans JP', 'Yu Gothic', 'Meiryo', system-ui, sans-serif;
}

/* Teacher mode: the settings screen plus the class-setup panel. */
#parents:not(.teacher) .teacher-only { display: none; }
/* The banner repeats the subtitle's job in teacher mode. */
#parents.teacher .topbar > [data-k="parentsSub"] { display: none; }
.teacher-banner { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px;
                  background: var(--cream); border: 1.5px solid var(--ink-soft); border-radius: var(--radius); }
.teacher-banner svg { width: 22px; height: 22px; flex: none; margin-top: 1px; color: var(--ink-soft); }
.teacher-banner p { margin: 0; }
.teacher-banner-title { font-size: 1rem; }
.teacher-banner-text { font-size: 0.82rem; font-weight: 500; color: var(--ink-soft); line-height: 1.55; margin-top: 4px !important; }
.setup-link { display: flex; gap: 8px; align-items: stretch; margin-top: 14px; }
.setup-link input { flex: 1; min-width: 0; width: 0; font: inherit; font-size: 0.85rem; font-weight: 500; color: var(--ink);
                    background: var(--cream); border: 2px solid var(--ink); border-radius: 12px; padding: 10px 12px;
                    -webkit-user-select: text; user-select: text; }
.setup-link .btn { flex: none; font-size: 0.9rem; padding: 10px 14px; white-space: nowrap; }
#presetPanel .setup-link { margin: 0 0 12px; }
.work.work--on { background: var(--k3); }
.work.work--on .work-title, .work.work--on .work-date { color: #0f3046; }
.setup-row { display: grid; gap: 8px; padding: 10px 0; }
#setupInstruments .chip, #setupOctaves .chip { padding: 6px 12px; min-width: 0; }
.setup-qr { display: block; width: min(300px, 100%); height: auto; margin: 16px auto 0;
            border: 2.5px solid var(--ink); border-radius: 14px; }
.setup-qr[hidden] { display: none; }
/* The hold that opens teacher mode must not select text or raise the iOS callout. */
#toParents, #toParentsPlay { -webkit-touch-callout: none; touch-action: manipulation; }
/* Teacher mode's longer title: on phones drop the name so sign-out stays top-right. */
@media (max-width: 430px) {
  #parents.teacher .account-corner .who { display: none; }
  #parents.teacher .account-corner .pill { padding: 8px 12px; font-size: 0.85rem; }
  #parents.teacher .title-pill { padding-left: 14px; padding-right: 14px; font-size: 0.95rem; white-space: nowrap; }
}

/* ─── Class: join box, student songs, teacher's classes ───────────── */
.class-bar { max-width: min(46vw, 320px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.class-bar[hidden], #classJoinBtn[hidden], #doneSubmitBtn[hidden] { display: none; }
.class-field { display: grid; gap: 6px; margin-top: 14px; text-align: left; font-size: 0.85rem; color: var(--ink-soft); }
.class-field input {
  width: 100%; font: inherit; font-size: 1.2rem; color: var(--ink);
  background: var(--cream); border: 2.5px solid var(--ink); border-radius: 14px; padding: 9px 12px;
  -webkit-user-select: text; user-select: text;
}
#classCodeInput { letter-spacing: 0.3em; text-align: center; }
#classCodeInput::placeholder { letter-spacing: normal; }
.class-note { margin: 10px 0 0; font-size: 0.75rem; color: var(--ink-soft); text-align: left; line-height: 1.45; }
#classJoinMsg:empty { display: none; }
.class-who { font-size: 0.85rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.work .work-submitted { background: var(--k3); color: #0f3046; opacity: 1; }
.work .work-action:disabled { cursor: default; }
/* Narrow: the title gets its own line, so Submit never squeezes it to "So…". */
@media (max-width: 480px) {
  .class-works .work { flex-wrap: wrap; padding: 10px 12px; border-radius: 18px; }
  .class-works .work-title { flex-basis: 100%; padding-left: 4px; }
  .class-works .work-date { display: none; }
}

.class-list { display: grid; gap: 12px; }
.class-card { border: 2.5px solid var(--ink); border-radius: 16px; padding: 12px 14px; display: grid; gap: 10px; }
.class-card--paused { opacity: 0.7; }
.class-head { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.class-toggle {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: 1 1 260px; min-width: 0;
  background: none; border: 0; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.class-chevron { display: inline-block; font-size: 0.9rem; transition: transform 0.15s; }
.class-toggle[aria-expanded="true"] .class-chevron { transform: rotate(90deg); }
/* QR, link, pause and delete: beside the code, so they're there even with the card closed. */
.class-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.class-tools .pill { font-size: 0.8rem; padding: 6px 11px; white-space: nowrap; }
.class-tools .icon-btn { width: 34px; height: 34px; min-width: 34px; padding: 0; }
.class-count { font-size: 0.85rem; font-weight: 700; padding: 3px 10px; border-radius: 999px;
               background: var(--k3); color: #0f3046; white-space: nowrap; }
.class-body { display: grid; gap: 10px; }
.class-body[hidden] { display: none; }
.class-name { font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.class-code { font-size: 1.5rem; font-weight: 700; letter-spacing: 0.12em; }
.class-state { font-size: 0.75rem; color: var(--coral); font-weight: 700; }
.class-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.class-actions .pill { font-size: 0.85rem; padding: 7px 12px; }
.class-actions .icon-btn { width: 36px; height: 36px; min-width: 36px; padding: 0; }
/* A busy class scrolls inside its card instead of running the panel off the page. */
.class-subs { margin-top: 0; max-height: 360px; overflow-y: auto; }

/* Teacher changed the class settings: a strip at the foot of the screen. Hidden
   while recording, so the keys never change under a child mid-song. */
#classUpdate {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 90;
  transform: translateX(-50%); width: max-content; max-width: calc(100vw - 24px);
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px;
  background: var(--card); color: var(--ink); border: 2.5px solid var(--ink); border-radius: 999px;
  box-shadow: var(--shadow); font-weight: 700; font-size: 0.95rem;
}
#classUpdate[hidden], body:has(#rec.on) #classUpdate { display: none; }
#classUpdate .pill { padding: 7px 14px; font-size: 0.9rem; white-space: nowrap; }
#classUpdateCount { font-variant-numeric: tabular-nums; }

/* ─── Playback on the keys ───────────────────────────────────────── */
.watch-btn { margin: 4px auto 14px; display: flex; justify-content: center; }
#watchKeys {
  flex: 1; display: grid; min-height: 0; pointer-events: none;
  gap: clamp(5px, 1.2vw, 12px); padding: 0 clamp(8px, 1.6vw, 16px) 12px;
}
.watch-progress { height: 6px; margin: 0 clamp(8px, 1.6vw, 16px) 10px; border-radius: 3px; background: var(--card); overflow: hidden; }
#watchBar { width: 0; height: 100%; background: var(--yellow); }
.watch-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Beat mode ─────────────────────────────────────────────────────
   Recording with a metronome. Meter and tempo show while getting ready
   (#rec[data-phase="ready"]); the dots follow the click throughout. */
#beatGo[hidden], #recLive[hidden], #recDone[hidden], #tidyBtn[hidden] { display: none; }
/* Where 完成 will be. It looks like the play screen's 錄音 (white, red dot)
   and only turns into the red 完成 once tapped. */
#beatGo { box-shadow: 0 4px 0 var(--coral); }
/* Free recording counts 3, 2, 1 first: the keys wait, so nothing is played and lost. */
#rec[data-phase="free-count"] #keys { pointer-events: none; }
/* The question when 錄音 is tapped: two big choices. */
.quiz-box.rec-ask-box { width: min(400px, 100%); display: flex; flex-direction: column; gap: 12px; }
.rec-ask-choice { width: 100%; justify-content: flex-start; gap: 14px; padding: 14px 18px; border-radius: var(--radius);
                  white-space: normal; text-align: left; line-height: 1.3; }
.rec-ask-choice b { display: block; font-size: 1.1rem; }
.rec-ask-choice small { display: block; font-size: 0.8rem; font-weight: 500; opacity: 0.72; margin-top: 2px; }
.rec-ask-icon { font-size: 2rem; line-height: 1; }
.rec-ask-box .quiz-actions { margin-top: 4px; }
/* In the top bar, between 取消 and 開始錄音 / 完成. Its height never changes
   between phases, so the keys stay put when the count-in starts. */
.beat-bar { display: flex; align-items: center; justify-content: center; flex-wrap: nowrap;
            gap: 10px 16px; min-height: 44px; }
.beat-bar[hidden] { display: none; }
.beat-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; }
#rec .beat-controls { flex-wrap: nowrap; }      /* one line in the recording top bar */
#rec:not([data-phase="ready"]) .beat-controls { display: none; }
/* The play screen's loud/soft captions hide with velocity off; with the metronome
   the hint stays, from getting ready to the end, so the keys never change size. */
body.no-vel #rec:is([data-phase="ready"], [data-phase="count"], [data-phase="rec"]) .instruct { display: flex; }
.beat-meters .chip { min-width: 3.2em; }
.beat-tempo { gap: 8px; }
.beat-tempo .icon-btn { width: 42px; height: 42px; font-size: 1.2rem; }
.beat-tempo .icon-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.tempo-num { display: inline-flex; align-items: baseline; justify-content: center; gap: 4px; min-width: 5.6em;
             font-size: 1.35rem; }
.tempo-emoji { font-size: 1.2rem; margin-right: 2px; }
.tempo-mark { font-size: 0.8rem; color: var(--ink-soft); }
.beat-dots { display: flex; align-items: center; gap: 10px; min-height: 26px; }
.beat-dots i { display: block; width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid var(--ink);
               transition: transform 0.05s; }
.beat-dots i.strong { width: 24px; height: 24px; }
.beat-dots i.mid { width: 20px; height: 20px; }
.beat-dots i.gap { margin-left: 12px; }                 /* 6/8: two groups of three */
.beat-dots i.on { background: var(--coral); transform: scale(1.18); }
.beat-dots i.strong.on { background: #e23b3b; }
/* The count-in: one big number per click over the keys. Never catches a tap. */
.beat-count { position: fixed; inset: 0; z-index: 45; display: grid; place-items: center; pointer-events: none; }
.beat-count[hidden] { display: none; }
.beat-count span { display: grid; place-items: center; width: 1.5em; height: 1.5em; border-radius: 50%;
                   font-size: clamp(4rem, 20vmin, 9rem); font-weight: 700; line-height: 1;
                   background: var(--card); color: var(--ink); border: 3px solid var(--ink); box-shadow: var(--shadow); }
.beat-count span:empty { display: none; }
/* The circle holds still; only the number changes, with a quick fade. */
.beat-count span.pop { animation: beat-fade 0.18s ease-out; }
@keyframes beat-fade { from { color: transparent; } to { color: var(--ink); } }
@media (prefers-reduced-motion: reduce) { .beat-count span.pop { animation: none; } }
/* 在琴鍵上播放 and 對齊拍子 share one row under the player; they wrap only when there is no room. */
.take-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 4px 0 14px; }
.take-actions .watch-btn, .take-actions .tidy-btn { margin: 0; }
/* Short screens (phones on their side): a slimmer bar so the keys keep their height. */
@media (max-height: 480px) {
  #rec .topbar { gap: 8px; }
  .beat-bar, .beat-controls { gap: 6px 10px; }
  .tempo-num { min-width: 4.4em; font-size: 1.15rem; }
  .beat-dots { gap: 7px; }
  .beat-dots i { width: 14px; height: 14px; }
  .beat-dots i.strong { width: 20px; height: 20px; }
  .beat-dots i.mid { width: 17px; height: 17px; }
  .beat-dots i.gap { margin-left: 8px; }
  .beat-tempo .icon-btn { width: 36px; height: 36px; }
  .beat-meters .chip { padding: 4px 0; }
}
.rec-ask-box .quiz-ask { font-size: 1.25rem; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.whats-new-box { width: min(420px, 100%); }
.whats-new-star { font-size: 2.2rem; text-align: center; line-height: 1; margin-bottom: 4px; }
/* Phones, when both show: they split the row evenly, like the two-column buttons below.
   On its own (free takes, shared songs) 在琴鍵上播放 keeps its usual size. */
@media (max-width: 480px) {
  .take-actions:has(#tidyBtn:not([hidden])) { flex-wrap: nowrap; }
  .take-actions:has(#tidyBtn:not([hidden])) .btn { flex: 1 1 0; min-width: 0; justify-content: center; gap: 5px;
                                                   padding: 10px 8px; font-size: 0.85rem; }
}
/* Not enough width for one row: the metronome takes a second row of its own,
   still a fixed height so nothing moves when recording starts. Sideways phones
   are short, so they keep one row (tightened below) down to 800px wide. */
@media (max-width: 900px) and (min-height: 481px), (max-width: 799px) {
  #rec .beat-bar { order: 5; flex: 0 0 100%; flex-wrap: wrap; }
  /* 取消, the clock and 完成 spread across the first row instead of wrapping. */
  #rec .topbar { justify-content: space-between; }
  #rec .topbar .spacer { display: none; }
  #rec .beat-controls { flex-wrap: wrap; justify-content: center; }
  /* Recording: the controls keep their space, so the keys below don't move up. */
  #rec:not([data-phase="ready"]) .beat-controls { display: flex; visibility: hidden; }
}

/* ─── Teacher Mode: sorting what came in ─────────────────────────── */
.class-sort { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 -4px;
              font-size: 0.85rem; color: var(--ink-soft); }
.class-actions .pill[disabled] { opacity: 0.4; cursor: not-allowed; }
/* Phones: the date gives way so the song's name keeps room beside 🔗 and ▶. */
@media (max-width: 480px) {
  .class-subs .work-date { display: none; }
}

/* ─── Jam mode (hidden) ─────────────────────────────────────────────── */
#jamBtn[hidden] { display: none; }
#jamBtn.btn--on { min-width: 5.2em; justify-content: center; font-variant-numeric: tabular-nums; }
.quiz-box.jam-box { width: min(440px, 100%); text-align: left; }
.jam-box .quiz-ask { font-size: 1.15rem; font-weight: 700; color: var(--ink); text-align: center; margin-bottom: 6px; }
/* The logo takes a long press without the browser's image menu or drag. */
#gate .brand-mark { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
#gate .brand-mark img { -webkit-user-drag: none; pointer-events: none; }

/* ─── Computer keyboard (desktop only, see bindComputerKeyboard) ─── */
.key .kbd {
  position: absolute; top: 7px; left: 9px; pointer-events: none;
  min-width: 1.5em; padding: 1px 5px; border: 1.5px solid currentColor; border-radius: 6px;
  font-size: clamp(0.6rem, 1.2vw, 0.8rem); font-weight: 700; line-height: 1.3; text-align: center;
  color: var(--key-ink-soft); opacity: 0.75;
}
#keys.two-rows .key .kbd { top: 5px; left: 7px; }

/* ─── Classroom control: the freeze cover and the status pill ────── */
#hushCover {
  position: fixed; inset: 0; z-index: 300;
  display: grid; place-content: center; justify-items: center; gap: 6px; padding: 24px; text-align: center;
  background: var(--cream); color: var(--ink);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#hushCover[hidden] { display: none; }
.hush-eyes { font-size: clamp(5rem, 22vmin, 10rem); line-height: 1; animation: hush-look 3.2s ease-in-out infinite; }
.hush-title { margin: 10px 0 0; font-size: clamp(2rem, 7vmin, 3.4rem); font-weight: 700; }
.hush-text { margin: 0; max-width: 28em; font-size: clamp(1rem, 3vmin, 1.3rem); color: var(--ink-soft); font-weight: 600; }
@keyframes hush-look { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-6%); } 60% { transform: translateX(6%); } }
@media (prefers-reduced-motion: reduce) { .hush-eyes { animation: none; } }

#hushBar {
  position: fixed; left: calc(12px + env(safe-area-inset-left)); bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 95; pointer-events: none; max-width: calc(100vw - 24px);
  padding: 7px 14px; border: 2.5px solid var(--ink); border-radius: 999px; box-shadow: var(--shadow);
  background: var(--card); color: var(--ink); font-weight: 700; font-size: 0.95rem; font-variant-numeric: tabular-nums;
}
#hushBar[hidden] { display: none; }
#hushBar.urgent { background: var(--coral); color: #fff; animation: hush-pulse 1s ease-in-out infinite; }
@keyframes hush-pulse { 50% { transform: scale(1.06); } }

/* Teacher: the classroom strip on each class card. */
.class-hush { display: grid; gap: 8px; padding: 10px 12px; border: 2px dashed var(--ink-soft); border-radius: 14px; }
.class-hush-title { font-weight: 700; font-size: 0.9rem; }
.class-hush-modes .chip, .class-hush-timer .chip { padding: 6px 12px; min-width: 0; }
.class-hush-modes .chip[data-hush="mute"][aria-pressed="true"] { background: var(--k5); }
.class-hush-modes .chip[data-hush="freeze"][aria-pressed="true"] { background: var(--k4); }
.class-hush-timer { align-items: center; }
.class-hush-unit { font-size: 0.85rem; color: var(--ink-soft); font-weight: 600; }
.class-hush-timer .class-hush-start { background: var(--yellow); color: #0f3046; }
.class-hush-left { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.class-hush-hint { margin: 0; font-size: 0.78rem; }
.class-hush-badge { font-size: 0.85rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Teacher: a class's join QR, for the projector. Always dark on white, so it scans. */
#classQr { z-index: 150; background: rgba(15, 48, 70, 0.85); }
#classQr:fullscreen { background: #fff; }
.class-qr-box {
  position: relative; display: grid; justify-items: center; gap: 4px;
  width: min(92vw, 720px); max-height: 100%; padding: 22px 22px 16px;
  background: #fff; color: #0f3046; border-radius: 22px; text-align: center;
}
#classQr:fullscreen .class-qr-box { width: min(96vw, 900px); }
.class-qr-close { position: absolute; top: 10px; right: 10px; background: #fff; color: #0f3046; }
.class-qr-name { margin: 0; font-size: clamp(1.1rem, 3.5vmin, 1.8rem); font-weight: 700; }
.class-qr-code { margin: 0; font-size: clamp(2.6rem, 11vmin, 6rem); font-weight: 700; letter-spacing: 0.14em; line-height: 1.1; font-variant-numeric: tabular-nums; }
#classQrCanvas { width: auto; height: auto; max-width: 100%; max-height: calc(100vh - clamp(15rem, 36vmin, 22rem)); aspect-ratio: 1; image-rendering: pixelated; }
.class-qr-scan { margin: 4px 0 0; font-size: clamp(0.95rem, 2.6vmin, 1.3rem); font-weight: 700; }
.class-qr-link { margin: 0; font-size: clamp(0.8rem, 2vmin, 1rem); color: #4a6b80; word-break: break-all; }
