/* Note Time: flat pastel tiles on soft grey, one idea per screen, a big staff at the piano. */
:root {
  --bg: #E4E3E6;
  --card: #FFFFFF;
  --ink: #1B1A1F;
  --ink-2: #5C5A62;
  --ink-3: #8D8B93;
  --line: #1B1A1F;
  --soft: #EFEEF2;
  --border: rgba(27, 26, 31, 0.09);

  --coral: #E8846E;
  --purple: #C566F2;
  --mint: #7EDFC8;
  --yellow: #F8DC5E;
  --pink: #F28DB8;
  --sky: #8EC5F5;
  --on-coral: #FFFFFF;
  --on-purple: #FFFFFF;
  --on-mint: #163A32;
  --on-yellow: #3B3105;
  --on-pink: #4A1529;
  --on-sky: #0D2E4F;
  --coral-soft: #FBE3DC;
  --purple-soft: #F2E0FC;
  --mint-soft: #DDF6EF;
  --yellow-soft: #FDF4CF;
  --pink-soft: #FCE2EE;
  --sky-soft: #E1EEFC;

  --good: #27AE8A;
  --bad: #E2674C;

  --font: 'Jost', 'Avenir Next', 'Futura', 'Century Gothic', system-ui, sans-serif;
  --music: 'Noto Music', 'Apple Symbols', serif;
  --r-lg: 24px;
  --r-md: 16px;
  --r-sm: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161B;
    --card: #24232A;
    --ink: #F3F2F6;
    --ink-2: #B7B5BE;
    --ink-3: #7F7D87;
    --line: #ECEBF0;
    --soft: #2E2D35;
    --border: rgba(255, 255, 255, 0.09);
    --coral-soft: #3B2823;
    --purple-soft: #33243D;
    --mint-soft: #1C3530;
    --yellow-soft: #38321B;
    --pink-soft: #3B2231;
    --sky-soft: #1E2C3B;
    --good: #4FD1AB;
    --bad: #F08A72;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
#app { min-height: 100%; display: flex; flex-direction: column; }
#app > .screen { flex: 1 0 auto; width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.15; text-wrap: balance; }
h1 { font-size: 30px; font-weight: 600; }
h2 { font-size: 21px; font-weight: 600; }
h3 { font-size: 17px; font-weight: 600; margin-top: 8px; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
.loading { padding: 40px; text-align: center; font-weight: 600; color: var(--ink-3); }

.screen {
  min-height: 100%;
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-block: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.label { font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.small { font-size: 14px; color: var(--ink-2); }
.error { color: var(--bad); font-weight: 500; min-height: 1px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* Buttons */
.btn {
  appearance: none;
  border: 0;
  border-radius: var(--r-md);
  padding: 12px 20px;
  font-weight: 600;
  font-size: 17px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .pill-btn:focus-visible, .icon-btn:focus-visible, .stop-dot:focus-visible {
  outline: 3px solid var(--purple);
  outline-offset: 2px;
}
.btn.primary { background: var(--yellow); color: var(--on-yellow); }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--border); }
.btn.big { font-size: 22px; padding: 16px 32px; border-radius: var(--r-lg); }
.btn.small { font-size: 15px; padding: 8px 14px; }
.btn.danger { background: var(--bad); color: #fff; }
.pill-btn {
  appearance: none;
  border: 0;
  background: var(--card);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.icon-btn {
  appearance: none;
  border: 0;
  background: var(--card);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* Colour tiles */
.c-coral { background: var(--coral); color: var(--on-coral); }
.c-purple { background: var(--purple); color: var(--on-purple); }
.c-mint { background: var(--mint); color: var(--on-mint); }
.c-yellow { background: var(--yellow); color: var(--on-yellow); }
.c-pink { background: var(--pink); color: var(--on-pink); }
.c-sky { background: var(--sky); color: var(--on-sky); }
.c-coral-soft { background: var(--coral-soft); }
.c-purple-soft { background: var(--purple-soft); }
.c-mint-soft { background: var(--mint-soft); }
.c-yellow-soft { background: var(--yellow-soft); }
.c-pink-soft { background: var(--pink-soft); }
.c-sky-soft { background: var(--sky-soft); }
.tag { display: inline-block; align-self: flex-start; border-radius: 8px; padding: 2px 10px; font-size: 13px; font-weight: 700; letter-spacing: 0.02em; }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: 0.01em; }
.week { display: flex; gap: 6px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--ink-3); }
.day i { width: 14px; height: 14px; border-radius: 50%; background: var(--card); }
.day.played i { background: var(--coral); }
.day.today { color: var(--ink); }
.day.today i { box-shadow: 0 0 0 2px var(--ink); }

/* Mascot and speech bubble */
.mascot { width: 104px; height: auto; flex: none; }
.mascot .m-head { fill: var(--coral); }
.mascot .m-stem, .mascot .m-fill { fill: var(--ink); }
.mascot .m-line { fill: none; stroke: var(--ink); stroke-width: 4; stroke-linecap: round; }
.bob { animation: bob 3.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px) rotate(-2deg); } }
.hello { display: flex; align-items: center; gap: 14px; }
.bubble {
  position: relative;
  background: var(--card);
  border-radius: 28px;
  padding: 14px 20px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
}
.bubble::before {
  content: '';
  position: absolute;
  left: -10px;
  bottom: 18px;
  border: 10px solid transparent;
  border-right-color: var(--card);
  border-left: 0;
}
.bubble small { display: block; margin-top: 4px; font-size: 14px; font-weight: 500; color: var(--ink-2); }
.hello.big .mascot { width: 140px; }
.hello.big .bubble { font-size: 24px; }

/* Home: path of stops */
.trip { display: flex; flex-direction: column; gap: 10px; }
.path { list-style: none; margin: 0; padding: 0; display: flex; justify-content: space-between; position: relative; }
.path::before { content: ''; position: absolute; left: 22px; right: 22px; top: 21px; height: 4px; border-radius: 2px; background: var(--card); }
.stop { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1 1 0; min-width: 0; }
.stop-dot {
  appearance: none;
  border: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
}
.stop.locked .stop-dot { background: var(--card); color: var(--ink-3); cursor: default; }
.stop.here .stop-dot { box-shadow: 0 0 0 4px var(--bg), 0 0 0 7px var(--ink); }
.stop-name { font-size: 12px; font-weight: 600; text-align: center; line-height: 1.15; color: var(--ink-2); }
.stop.here .stop-name { color: var(--ink); }
.stop.locked .stop-name { color: var(--ink-3); }
.stop-card {
  border-radius: var(--r-lg);
  padding: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}
.stop-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.stop-info > p:first-of-type { font-size: 18px; color: var(--ink-2); }
.stop-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.stars { display: inline-flex; gap: 4px; }
.star { width: 26px; height: 26px; }
.star path { fill: var(--card); stroke: var(--ink-3); stroke-width: 1.2; stroke-linejoin: round; }
.star.on path { fill: var(--yellow); stroke: #C9A91F; }
.toast { min-height: 1.4em; text-align: center; font-weight: 600; color: var(--ink-2); }

/* Lesson cards */
.lesson { gap: 14px; }
.dots { display: flex; gap: 6px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--card); }
.dots i.on { background: var(--ink); }
.lesson-card { flex: 1; display: flex; flex-direction: column; gap: 16px; }
.lesson-art {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 16px;
  display: grid;
  place-items: center;
  min-height: 0;
}
.lesson-art svg { width: 100%; max-height: 46vh; }
.lesson-text { display: flex; flex-direction: column; gap: 10px; max-width: 34em; }
.lesson-text p { font-size: 21px; line-height: 1.4; }
.lesson-nav { display: flex; gap: 10px; margin-top: 6px; }

/* Staff drawing */
.staff .st-line, .staff .ledger, .staff .stem { stroke: var(--line); stroke-width: 1.6; }
.staff .ledger { stroke-width: 2.2; }
.staff .stem { stroke-width: 2.2; }
.staff .brace { fill: none; stroke: var(--line); stroke-width: 3.5; stroke-linecap: round; }
.staff .clef { font-family: var(--music); fill: var(--ink); }
.staff .clef.accent { fill: var(--purple); }
.staff .head { fill: var(--ink); }
.staff .note { transform-box: fill-box; transform-origin: center; }
.staff .note.accent .head { fill: var(--purple); }
.staff .note.accent .stem, .staff .ledger.accent { stroke: var(--purple); }
.staff .ledger.accent { stroke-width: 4; }
.staff .nlabel { font-family: var(--font); font-weight: 600; font-size: 22px; fill: var(--ink); }
.staff .note.ready .head { animation: breathe 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.staff .note.enter { animation: slidein 0.22s ease-out; }
.staff .note.ok .head { fill: var(--good); }
.staff .note.ok .stem, .staff .note.ok .ledger { stroke: var(--good); }
.staff .note.ok { animation: pop 0.35s ease-out; }
.staff .note.bad .head { fill: var(--bad); }
.staff .note.bad .stem, .staff .note.bad .ledger { stroke: var(--bad); }
.staff .note.bad { animation: shake 0.4s ease-in-out; }
.staff .bubble circle { fill: var(--mint); }
.staff .bubble text { font-family: var(--font); font-weight: 700; font-size: 28px; fill: var(--on-mint); }
.staff .bubble .sub { font-size: 16px; }
.staff .bubble { transform-box: fill-box; transform-origin: center; animation: pop 0.3s ease-out; }
@keyframes pop { 40% { transform: scale(1.22); } }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes slidein { from { transform: translateX(26px); opacity: 0; } }
@keyframes breathe { 50% { transform: scale(1.12); } }

/* Keyboards */
.keys .wk { fill: #FFFFFF; stroke: #1B1A1F; stroke-width: 1.2; }
.keys .bk { fill: #1B1A1F; }
.keys .kdot { stroke: #1B1A1F; stroke-width: 1; }
.keys .kdot.coral { fill: var(--coral); }
.keys .kdot.mint { fill: var(--mint); }
.keys .kdot.purple { fill: var(--purple); }
.keys .klabel { font-family: var(--font); font-weight: 700; font-size: 15px; fill: var(--ink); }

/* Play screen */
.screen.play { height: 100%; min-height: 0; gap: 10px; }
html:has(#app[data-screen="sprint"]), html:has(#app[data-screen="sprint"]) body { height: 100%; overflow: hidden; }
#app[data-screen="sprint"] { height: 100%; }
.play-bar { display: flex; align-items: center; gap: 12px; }
.clock { font-weight: 700; font-size: 22px; font-variant-numeric: tabular-nums; min-width: 3.2ch; }
.clock.hurry { color: var(--bad); }
.timebar { flex: 1; height: 12px; border-radius: 6px; background: var(--card); overflow: hidden; }
.timebar i { display: block; height: 100%; background: var(--coral); border-radius: 6px; transform-origin: left; transform: scaleX(1); }
.score { font-weight: 700; font-size: 38px; line-height: 1; min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }
.score.bump { animation: pop 0.3s ease-out; }
.staff-card {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.staff-card svg { width: 100%; height: 100%; max-height: 100%; }
.play-foot { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.status { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 600; flex: 1; min-width: 0; }
.mic-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--ink-3); flex: none; transition: transform 0.06s linear; }
.mic-dot.live { background: var(--purple); }
.tap-mode .mic-dot { display: none; }
.hint-keys { flex: 0 1 46%; min-width: 0; }
.hint-keys:empty { display: none; }
.hint-keys svg { width: 100%; max-height: 52px; display: block; }
.tap-keys { background: var(--card); border-radius: var(--r-md); padding: 8px; }
.tap-keys svg { width: 100%; max-height: 110px; display: block; }
.tap-keys .wk, .tap-keys .bk { cursor: pointer; }
.tap-keys .wk:active { fill: var(--mint); }
.tap-keys .bk:active { fill: var(--purple); }
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 22, 27, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 10;
}
.overlay[hidden] { display: none; }
.overlay-card { background: var(--card); border-radius: var(--r-lg); padding: 24px; max-width: 420px; display: flex; flex-direction: column; gap: 16px; font-size: 19px; font-weight: 500; }
.overlay-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Results */
.result-top { display: flex; gap: 18px; align-items: flex-start; }
.result-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.big-score { font-size: 22px; font-weight: 500; }
.big-score strong { font-size: 64px; font-weight: 700; line-height: 1; margin-right: 4px; }
.stars.pop-in .star { width: 40px; height: 40px; animation: pop 0.4s ease-out backwards; }
.stars.pop-in .star:nth-child(2) { animation-delay: 0.15s; }
.stars.pop-in .star:nth-child(3) { animation-delay: 0.3s; }
.unlock { border-radius: var(--r-md); padding: 14px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 4px; }
.unlock strong { font-size: 22px; }
.unlock .tag { background: rgba(255, 255, 255, 0.35); }
.tricky-row { display: flex; flex-direction: column; gap: 10px; }
.tricky-list { display: flex; gap: 12px; flex-wrap: wrap; }
.tricky { margin: 0; background: var(--card); border-radius: var(--r-md); padding: 8px 10px 6px; width: 150px; text-align: center; }
.tricky svg { width: 100%; height: auto; }
.tricky figcaption { font-weight: 700; font-size: 20px; }
.result-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* Setup and grown-ups */
.panel { background: var(--card); border-radius: var(--r-lg); padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.panel h1 { font-size: 26px; }
.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 8px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 600; padding: 0; }
.field em { font-style: normal; font-weight: 400; color: var(--ink-2); }
.field input[type="text"], .field select {
  border: 0;
  border-radius: var(--r-sm);
  background: var(--card);
  padding: 12px 14px;
  font-size: 18px;
  box-shadow: inset 0 0 0 2px var(--border);
  max-width: 420px;
}
.panel .field input[type="text"], .panel .field select { background: var(--soft); }
.choice { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border-radius: var(--r-md); padding: 12px 14px; cursor: pointer; }
.choice input { margin-top: 5px; accent-color: var(--purple); width: 18px; height: 18px; }
.choice strong { display: block; }
.choice span { display: flex; flex-direction: column; color: var(--ink-2); }
.choice strong { color: var(--ink); }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-block; padding: 10px 16px; border-radius: var(--r-sm); background: var(--card); font-weight: 600; box-shadow: inset 0 0 0 2px var(--border); }
.panel .seg span { background: var(--soft); }
.seg input:checked + span { background: var(--purple); color: var(--on-purple); box-shadow: none; }
.seg input:focus-visible + span { outline: 3px solid var(--purple); outline-offset: 2px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--purple); }

.mic-check { display: flex; flex-direction: column; gap: 10px; background: var(--soft); border-radius: var(--r-md); padding: 16px; }
.heard { display: flex; align-items: baseline; gap: 16px; }
.heard-letter { font-size: 72px; font-weight: 700; line-height: 1; min-width: 1.2ch; color: var(--purple); display: inline-block; }
.heard-letter.pop { animation: pop 0.3s ease-out; }
.heard-sub { font-size: 18px; font-weight: 600; color: var(--ink-2); }
.meter { height: 8px; border-radius: 4px; background: var(--card); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--mint); transform-origin: left; transform: scaleX(0); }

.table-wrap { overflow-x: auto; }
.stats { border-collapse: collapse; width: 100%; font-size: 15px; font-variant-numeric: tabular-nums; }
.stats th, .stats td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.stats th { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.stats tr.weak td:first-child { color: var(--bad); font-weight: 700; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.history li { display: grid; grid-template-columns: 6.5em 1fr auto 4em; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 15px; font-variant-numeric: tabular-nums; }
.history li span:last-child { color: #C9A91F; letter-spacing: 0.05em; }
.book-map { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 4px; }
.welcome { justify-content: center; align-items: center; gap: 36px; }

/* Wider screens and phones lying sideways */
@media (max-width: 420px) {
  .stop-dot { width: 36px; height: 36px; font-size: 15px; }
  .stop-dot .ico { width: 18px; height: 18px; }
  .path::before { top: 16px; left: 18px; right: 18px; }
  .stop-name { font-size: 11px; }
  .week { gap: 4px; }
  .day i { width: 12px; height: 12px; }
}
@media (min-width: 720px) {
  .stop-name { font-size: 13px; }
  .stop-actions { flex-direction: row; }
}
@media (orientation: landscape) and (max-height: 560px) {
  .screen { gap: 10px; padding-block: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-bottom)); }
  .screen.home {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto 1fr auto;
    column-gap: 20px;
  }
  .home .topbar { grid-column: 1 / -1; }
  .home .hello { grid-column: 1; }
  .home .trip { grid-column: 1; }
  .home .stop-card { grid-column: 2; grid-row: 2 / span 2; align-self: stretch; flex-direction: column; align-items: stretch; }
  .home .toast { grid-column: 1 / -1; }
  .mascot { width: 84px; }
  .bubble { font-size: 18px; }
  h1 { font-size: 26px; }
  .lesson-card { flex-direction: row; align-items: stretch; }
  .lesson-art { flex: 1 1 55%; }
  .lesson-art svg { max-height: 70vh; }
  .lesson-text { flex: 1 1 45%; justify-content: center; }
  .lesson-text p { font-size: 19px; }
  .play-bar .score { font-size: 32px; }
  .play-foot { min-height: 40px; }
  .tap-keys svg { max-height: 80px; }
  .result-top .mascot { width: 72px; }
  .big-score strong { font-size: 52px; }
  .screen.results {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    column-gap: 20px;
    align-content: start;
  }
  .results .result-top { grid-column: 1; grid-row: 1 / span 2; }
  .results .tricky-row { grid-column: 2; grid-row: 1; }
  .results .result-actions { grid-column: 2; grid-row: 2; align-self: end; }
  .tricky { width: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
