/* The shared chrome (top bar, buttons, dialogs, stats grid, week strip, toast) is in
   hub/game.css, linked before this file. This sets the tokens it uses, Tune's board, the marked
   rows and the piano. */
:root {
  color-scheme: light dark;
  --bg: #f7f1f8;
  --bg-2: #ecdfef;
  --panel: rgba(255, 255, 255, 0.8);
  --panel-solid: #ffffff;
  --ink: #2a1730;
  --muted: #6a5870;
  --line: rgba(42, 23, 48, 0.13);
  --accent: #8e3b8f; /* white button text on it is 6.6:1 */
  --accent-deep: #73287a;
  --accent-ink: #ffffff;
  --good: #2b8a55;
  --bad: #c43d3d;
  --up: #f0b23e; /* the real note is higher: dark ink on it */
  --up-ink: #2a1a00;
  --down: #3d6fd1; /* lower: white on it */
  --down-ink: #ffffff;
  --key: #fffdfb;
  --key-2: #efe6ef;
  --key-ink: #2a1730;
  --shadow: rgba(90, 30, 100, 0.18);
  --display: Fredoka, 'Arial Rounded MT Bold', system-ui, sans-serif;
  --text: Nunito, system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #170f1b;
    --bg-2: #211526;
    --panel: rgba(52, 34, 60, 0.72);
    --panel-solid: #2b1d32;
    --ink: #f4eaf6;
    --muted: #bba9c1;
    --line: rgba(244, 234, 246, 0.13);
    --accent: #d68ad7;
    --accent-deep: #c070c2;
    --accent-ink: #2a0d2c;
    --good: #4fc282;
    --bad: #ff7a72;
    --up: #f5c060;
    --down: #6f9bf0;
    --down-ink: #0d1733;
    --key: #ece4ee;
    --key-2: #cfc2d4;
    --shadow: rgba(0, 0, 0, 0.45);
  }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font: 600 16px/1.4 var(--text);
  -webkit-font-smoothing: antialiased;
  background: linear-gradient(180deg, var(--bg), var(--bg-2)) fixed;
}
button { -webkit-tap-highlight-color: transparent; }

.app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------------------------------------------------------------- header */
.logo { margin: 0; font: 700 2.1rem/1 var(--display); color: var(--accent-deep); }
@media (prefers-color-scheme: dark) { .logo { color: var(--accent); } }
.day { margin: 4px 0 0; font-size: 0.78rem; color: var(--muted); }

/* ---------------------------------------------------------------- board */
.play { display: flex; flex-direction: column; gap: 12px; }
.board, .deck { padding: 12px; border-radius: 22px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 14px 40px -24px var(--shadow); }
.listen { display: flex; align-items: center; gap: 14px; justify-content: center; }
.play-btn {
  flex: none;
  width: 54px; height: 54px;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 8px 20px -8px var(--accent);
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform 0.12s;
}
.play-btn svg { width: 28px; height: 28px; fill: currentColor; margin-left: 3px; }
.play-btn:active { transform: scale(0.94); }
.listen-text { min-width: 0; }
.ramp { margin: 0 0 7px; font: 600 1rem/1.25 var(--display); }
.sub { display: flex; align-items: center; gap: 12px; }
.dots { display: flex; gap: 7px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; background: var(--line); transition: background 0.1s, transform 0.1s; }
.dots i.lit { background: var(--accent); transform: scale(1.3); }
.hint { margin: 8px 0 0; font-size: 0.78rem; color: var(--muted); text-align: center; }
.rows { display: grid; gap: 5px; margin-top: 12px; justify-content: center; }
.row { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 48px)) 32px; gap: 5px; align-items: center; }
.cell {
  height: 42px;
  border: 2px solid var(--line);
  border-radius: 11px;
  background: var(--panel-solid);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font: 600 1.15rem/1 var(--display);
  position: relative;
}
.cell sub, .pk sub, .answer sub, .res-tune sub { font-size: 0.6em; vertical-align: baseline; position: relative; top: 0.2em; }
.cell i { font-style: normal; font-size: 0.72rem; line-height: 1; margin-top: 2px; min-height: 0.72rem; }
.cell.typed { border-color: var(--accent); }
.cell.caret { border-style: dashed; border-color: var(--accent); }
.cell.ghost { color: var(--muted); opacity: 0.6; }
.cell.pending { border-color: var(--accent); }
.cell.r { background: var(--good); border-color: transparent; color: #fff; }
.cell.u { background: var(--up); border-color: transparent; color: var(--up-ink); }
.cell.d { background: var(--down); border-color: transparent; color: var(--down-ink); }
.cell.lit { transform: scale(1.1); box-shadow: 0 0 0 3px var(--accent); }
.cell.flip { animation: flip 0.32s ease-out; }
@keyframes flip { from { transform: rotateX(90deg); } }
.row.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.row-play, .row-play-gap { width: 32px; height: 32px; }
.row-play { border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--muted); display: grid; place-items: center; padding: 0; cursor: pointer; }
.row-play svg { width: 14px; height: 14px; fill: currentColor; margin-left: 2px; }
.row-play:hover { color: var(--accent); border-color: var(--accent); }
.left { margin: 0; color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.answer { margin: 6px 0 0; text-align: center; color: var(--muted); }
.answer b { color: var(--ink); font: 600 1.2rem/1 var(--display); letter-spacing: 0.04em; }

/* ---------------------------------------------------------------- piano */
.deck { display: flex; flex-direction: column; gap: 10px; }
.piano { display: grid; grid-template-columns: repeat(var(--k), 1fr); gap: 4px; height: 116px; }
.pk {
  border: 1px solid rgba(42, 23, 48, 0.22);
  border-radius: 4px 4px 12px 12px;
  background: linear-gradient(180deg, var(--key-2), var(--key) 18%);
  box-shadow: inset 0 -7px 0 rgba(42, 23, 48, 0.1), 0 2px 4px -2px var(--shadow);
  color: var(--key-ink);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 8px 0 12px;
  font: 600 1.15rem/1 var(--display);
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s;
}
.pk kbd { font: 700 0.68rem/1 var(--text); color: #8a7890; }
.pk:active, .pk.hit { animation: press 0.18s; }
@keyframes press { 40% { transform: translateY(2px); box-shadow: inset 0 -3px 0 rgba(42, 23, 48, 0.1); background: var(--key-2); } }
.pk.out { opacity: 0.4; }
.controls { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px; }
.ctl { min-height: 44px; }
#btnBack { padding: 0 16px; }
#btnBack svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; display: block; }
.foot { display: flex; justify-content: flex-end; gap: 8px; }
.foot:has(> [hidden]:only-child) { display: none; }

/* ---------------------------------------------------------------- help */
.help-marks { display: grid; gap: 6px; margin: 12px 0; }
.rule-note { margin: 10px 0 0; }
.help-marks p { margin: 0; display: flex; align-items: center; gap: 10px; }
.cell.demo { width: 40px; height: 40px; flex: none; }
kbd { font: 700 0.85em/1 var(--text); }
.rule-note kbd { padding: 1px 5px; border: 1px solid var(--line); border-radius: 5px; }

/* ---------------------------------------------------------------- buttons */
.btn.wide { margin-top: 16px; }

/* ---------------------------------------------------------------- dialogs and results */
@keyframes pop { from { opacity: 0; transform: scale(0.95); } }
.kicker { color: var(--muted); }
.res-line { margin: 0 0 8px; font-size: 1.05rem; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px 10px; }
.res-tune { font: 600 1.15rem/1 var(--display); letter-spacing: 0.04em; }
.res-grid { margin: 0 0 12px; text-align: center; font-size: 1.15rem; line-height: 1.3; letter-spacing: 0.05em; }
.wd.today i { outline: 2px dashed var(--accent); outline-offset: -2px; }
.wd.won i { background: var(--good); color: #fff; }
.wd.lost i { color: var(--bad); }

.toast { z-index: 10; }

@media (max-width: 380px) {
  .app { padding-left: 10px; padding-right: 10px; }
  .board, .deck { padding: 12px 8px; }
  .row { gap: 4px; grid-template-columns: repeat(var(--n), minmax(0, 44px)) 28px; }
  .row-play, .row-play-gap { width: 28px; height: 28px; }
  .cell { font-size: 1.05rem; }
  .piano { gap: 3px; }
  .pk { font-size: 1rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
/* the same for the site-wide Reduce motion setting (hub/prefs.js) */
@media (prefers-reduced-motion: reduce) {
  .cell.flip, .row.shake, .pk.hit, .pk:active { animation: none; }
}
.reduce-motion .cell.flip, .reduce-motion .row.shake, .reduce-motion .pk.hit, .reduce-motion .pk:active { animation: none; }

/* Short screens (a phone with its browser bars): keep the keys on screen under the rows. */
@media (max-height: 760px) {
  .app { gap: 8px; }
  .cell { height: 36px; }
  .cell i { font-size: 0.62rem; min-height: 0.62rem; margin-top: 0; }
  .rows { gap: 4px; margin-top: 10px; }
  .piano { height: 98px; }
  .ctl { min-height: 40px; }
  .play-btn { width: 48px; height: 48px; }
}
@media (max-height: 640px) {
  .logo { font-size: 1.7rem; }
  .board, .deck { padding: 10px 8px; }
  .cell { height: 33px; font-size: 0.98rem; }
  .hint { font-size: 0.7rem; margin-top: 6px; }
  .piano { height: 86px; }
  .pk { padding: 5px 0 9px; }
  .deck { gap: 8px; }
}
