/* ---------- tokens ---------- */
:root {
  color-scheme: light dark;
  --bg: #f4efe6;
  --bg-glow: rgba(214, 150, 60, 0.16);
  --surface: #fffcf7;
  --surface-2: #f6f1e7;
  --line: #e6ddce;
  --ink: #1f1b16;
  --ink-2: #5d5549;
  --ink-3: #8e8577;
  --accent: #b46e17;
  --accent-ink: #fffaf2;
  --accent-soft: #f5e4c8;
  --good: #23824f;
  --good-soft: #dcf0e3;
  --bad: #c2412f;
  --bad-soft: #f8dfda;
  --brand-ink: #fffaf2;
  --key-white: #fffdf8;
  --key-white-2: #ece4d5;
  --key-black: #221e1a;
  --key-black-2: #3d3730;
  --key-edge: #d8cebd;
  --shadow: 0 1px 2px rgba(60, 40, 10, 0.05), 0 10px 32px -8px rgba(60, 40, 10, 0.12);
  --radius: 20px;
  --serif: 'Instrument Serif', 'Iowan Old Style', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1013;
    --bg-glow: rgba(227, 166, 79, 0.10);
    --surface: #17181c;
    --surface-2: #1f2025;
    --line: #2b2c32;
    --ink: #f1ebe0;
    --ink-2: #b7afa2;
    --ink-3: #7f786d;
    --accent: #e6a955;
    --accent-ink: #1c1408;
    --accent-soft: rgba(230, 169, 85, 0.14);
    --good: #5fcb8f;
    --good-soft: rgba(95, 203, 143, 0.15);
    --bad: #f0806e;
    --bad-soft: rgba(240, 128, 110, 0.15);
    --brand-ink: #1c1408;
    --key-white: #efe9de;
    --key-white-2: #cfc7b8;
    --key-black: #0b0b0d;
    --key-black-2: #2a2a2f;
    --key-edge: #3a3a40;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 36px -10px rgba(0, 0, 0, 0.55);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.5 var(--sans);
  color: var(--ink);
  background: radial-gradient(1100px 520px at 50% -180px, var(--bg-glow), transparent 70%), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--accent); }
h1, h2 { font-family: var(--serif); font-weight: 400; letter-spacing: -0.01em; margin: 0; }
.muted { color: var(--ink-2); }
kbd {
  font: 500 11px/1 var(--sans);
  padding: 3px 5px;
  border-radius: 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  background: var(--surface);
  color: var(--ink-2);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font: 26px/1 var(--serif);
}
.brand svg { width: 32px; height: 32px; color: var(--accent); }
.brand em { color: var(--accent); }
.tabs {
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected='true'] { background: var(--ink); color: var(--bg); }
.tab-stats { margin-left: 6px; position: relative; }
.tab-stats::before {
  content: '';
  position: absolute;
  left: -5px; top: 9px; bottom: 9px;
  width: 1px;
  background: var(--line);
}

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stage { padding: 28px 28px 22px; }
.stage-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.stage-head h1 { font-size: 44px; line-height: 1; }
.stage-head p { margin: 8px 0 0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}
.icon-btn:hover, .icon-btn[aria-expanded='true'] { color: var(--ink); border-color: var(--ink-3); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* ---------- prompt ---------- */
.prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 30px 0 26px;
}
.play-btn {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px -6px color-mix(in srgb, var(--accent) 60%, transparent);
  transition: transform 0.15s ease;
}
.play-btn:hover { transform: scale(1.04); }
.play-btn:active { transform: scale(0.97); }
.play-btn svg { width: 34px; height: 34px; }
.i-play { fill: currentColor; margin-left: 4px; }
.i-replay { display: none; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; width: 30px !important; }
.play-btn.is-replay .i-play { display: none; }
.play-btn.is-replay .i-replay { display: block; }
.play-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  pointer-events: none;
}
.play-btn.is-pulsing::after { animation: ring 1.1s ease-out; }
@keyframes ring {
  from { transform: scale(1); opacity: 0.7; }
  to { transform: scale(1.6); opacity: 0; }
}

.status { font-weight: 500; color: var(--ink-2); min-height: 22px; text-align: center; }
.status-good { color: var(--good); }
.status-bad { color: var(--bad); }
.status-asking { color: var(--ink); }
.timer {
  font: 400 28px/1 var(--serif);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.timer span { font-size: 18px; margin-left: 2px; }

/* ---------- answer buttons ---------- */
.answers-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 8px;
}
.answer {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px 11px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  text-align: left;
  touch-action: manipulation;
  user-select: none;
  transition: border-color 0.12s, background 0.12s, transform 0.08s;
}
.answer:hover { border-color: var(--ink-3); }
.answer:active { transform: scale(0.98); }
.answer-label { font: 26px/1.05 var(--serif); }
.answer-name { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.answer kbd { position: absolute; top: 9px; right: 9px; opacity: 0.7; }
.answer.is-correct { background: var(--good-soft); border-color: var(--good); }
.answer.is-correct .answer-label { color: var(--good); }
.answer.is-wrong { background: var(--bad-soft); border-color: var(--bad); }
.answer.is-wrong .answer-label { color: var(--bad); }

/* ---------- piano ---------- */
.kb {
  --kb-h: 190px;
  position: relative;
  display: flex;
  height: var(--kb-h);
  user-select: none;
  touch-action: manipulation;
}
.answers-keyboard { max-width: 620px; margin: 0 auto; }
.key { position: relative; border: 0; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.key-white {
  flex: 1;
  margin: 0 2px;
  border-radius: 0 0 10px 10px;
  background: linear-gradient(to bottom, var(--key-white-2), var(--key-white) 14%);
  box-shadow: inset 0 -5px 0 var(--key-white-2), 0 0 0 1px var(--key-edge);
  color: #6e665a;
  padding-bottom: 14px;
}
.key-white:first-child { margin-left: 0; }
.key-white:last-of-type { margin-right: 0; }
.key-black {
  position: absolute;
  top: 0;
  width: var(--bk-w);
  height: 62%;
  z-index: 2;
  border-radius: 0 0 7px 7px;
  background: linear-gradient(to bottom, var(--key-black-2), var(--key-black) 70%);
  box-shadow: inset 0 -4px 0 rgba(255, 255, 255, 0.07), 0 3px 6px rgba(0, 0, 0, 0.25);
  color: #bdb4a6;
  padding-bottom: 10px;
}
.key-name { display: flex; flex-direction: column; align-items: center; font-weight: 600; font-size: 14px; line-height: 1.2; }
.key-black .key-name { font-size: 10px; font-weight: 500; }
.key-hint { position: absolute; top: auto; bottom: 44px; opacity: 0.55; background: transparent; border-color: currentColor; color: inherit; font-size: 10px; }
.key-black .key-hint { bottom: 40px; }
.kb-nolabels .key-name { visibility: hidden; }

.kb-live .key { cursor: pointer; transition: transform 0.06s, filter 0.12s; transform-origin: top; }
.kb-live .key-white:hover { filter: brightness(0.97); }
.kb-live .key-black:hover { filter: brightness(1.25); }
.key.is-down { transform: scaleY(0.985); filter: brightness(0.92); }
.key.is-off { opacity: 0.45; }
.key.is-correct { background: var(--good) !important; color: #fff; box-shadow: 0 0 0 1px var(--good), 0 0 24px -4px var(--good); }
.key.is-wrong { background: var(--bad) !important; color: #fff; box-shadow: 0 0 0 1px var(--bad), 0 0 24px -4px var(--bad); }

.kb-compact { --kb-h: 74px; }
.kb-compact .key-white { margin: 0 1px; border-radius: 0 0 5px 5px; padding-bottom: 6px; box-shadow: inset 0 -3px 0 var(--key-white-2), 0 0 0 1px var(--key-edge); }
.kb-compact .key-black { border-radius: 0 0 4px 4px; height: 60%; padding-bottom: 4px; }
.kb-compact .key-name { display: none; }
.kb-compact .key.is-lit .key-name { display: flex; font-size: 10px; }
.kb-compact .key-black.is-lit .key-name span:first-child:not(:last-child) { display: none; }
.key.is-lit { background: var(--accent) !important; color: var(--accent-ink); }
.key.is-tonic::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 8px;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  border-radius: 50%;
  background: var(--accent);
}
.key-black.is-tonic::before { background: var(--accent); }
.key.is-lit.is-tonic::before { background: var(--accent-ink); }

/* ---------- reveal ---------- */
.reveal {
  min-height: 0;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s, transform 0.2s;
}
.reveal.show {
  opacity: 1;
  transform: none;
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.reveal.good { border-left: 3px solid var(--good); }
.reveal.bad { border-left: 3px solid var(--bad); }
.reveal-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.reveal-text strong { font: 400 26px/1.1 var(--serif); }
.reveal-text span { color: var(--ink-2); }
.reveal-yours { color: var(--bad) !important; font-weight: 500; }
.reveal-kb:not(:empty) { margin-top: 12px; max-width: 420px; }
.reveal-tip { margin: 10px 0 0; font-size: 12.5px; color: var(--ink-3); }

/* ---------- actions ---------- */
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 500;
  font-size: 14px;
}
.btn:hover:not(:disabled) { border-color: var(--ink-3); }
.btn:disabled { opacity: 0.45; }
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-primary kbd { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--bg) 40%, transparent); }

/* ---------- customize ---------- */
.customize {
  margin-top: 20px;
  padding: 18px 20px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid;
  gap: 14px;
}
.cust-head { display: flex; justify-content: space-between; align-items: baseline; }
.cust-head h2 { font-size: 24px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: 13px; font-weight: 500; }
.link:hover { text-decoration: underline; }
.opt { display: grid; grid-template-columns: 170px 1fr; align-items: center; gap: 12px; }
.opt-items { align-items: start; }
.opt-k { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.opt-items .opt-k { padding-top: 4px; }
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  justify-self: start;
}
.seg button {
  border: 0;
  background: none;
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--ink-2);
}
.seg button[aria-checked='true'] { background: var(--ink); color: var(--bg); }
.groups { display: grid; gap: 10px; }
.group-name {
  border: 0; background: none; padding: 0;
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); font-weight: 600;
  margin-bottom: 6px;
}
.group-name:hover { color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 500;
}
.chip[aria-pressed='true'] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }

/* ---------- session tiles ---------- */
.session {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}
.tile {
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.tile-k { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.tile-v { font: 400 32px/1.15 var(--serif); font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12px; color: var(--ink-3); }

/* ---------- stats page ---------- */
.stats { display: grid; gap: 14px; }
.stats-hero { padding: 26px 28px; display: grid; gap: 20px; }
.stats-hero h1 { font-size: 40px; line-height: 1.05; }
.stats-hero p { margin: 8px 0 0; max-width: 560px; font-size: 14px; }
.hero-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.hero-tiles .tile { background: var(--surface-2); }
.activity { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.day-bar {
  width: 100%;
  height: 56px;
  display: flex;
  align-items: flex-end;
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
}
.day-bar span { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; }
.day:hover .day-bar span { filter: brightness(1.1); }
.day-k { font-size: 11px; color: var(--ink-3); }
.day.today .day-k { color: var(--ink); font-weight: 600; }

.mode-stats { padding: 22px 26px; }
.mode-stats header { display: flex; justify-content: space-between; align-items: baseline; }
.mode-stats h2 { font-size: 30px; }
.mini-tiles {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 14px 0 6px;
}
.mini-tiles div { display: flex; flex-direction: column; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.mini-tiles span { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.mini-tiles b { font: 400 22px/1.2 var(--serif); font-variant-numeric: tabular-nums; }
.items { margin-top: 12px; }
.item-row {
  display: grid;
  grid-template-columns: minmax(110px, 180px) 1fr 52px 64px;
  align-items: center;
  gap: 14px;
  padding: 7px 4px;
  border-top: 1px solid var(--line);
  font-size: 13.5px;
}
.item-row:hover:not(.item-head) { background: var(--surface-2); }
.item-head { border-top: 0; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 600; }
.item-label { font: 20px/1.1 var(--serif); display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.item-label small { font: 12px var(--sans); color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { position: relative; height: 22px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.bar span { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 0 4px 4px 0; opacity: 0.85; }
.bar em { position: absolute; right: 8px; top: 0; line-height: 22px; font-style: normal; font-size: 12px; font-weight: 600; color: var(--ink); }
.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.empty { color: var(--ink-3); margin: 14px 0 4px; }

/* ---------- footer & toast ---------- */
.foot { margin-top: 24px; text-align: center; font-size: 12.5px; color: var(--ink-3); }
.foot kbd { font-size: 10.5px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 500;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}
.toast.show { animation: toast 2.8s ease forwards; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 20px); }
  10%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .app { padding-top: 14px; }
  .top { margin-bottom: 14px; }
  .tabs { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); border-radius: 18px; }
  .tab { padding: 7px 6px; text-align: center; border-radius: 14px; }
  .tab-stats { margin-left: 0; }
  .tab-stats::before { display: none; }
  .stage { padding: 20px 16px 16px; }
  .stage-head h1 { font-size: 36px; }
  .icon-btn span { display: none; }
  .prompt { padding: 22px 0 20px; }
  .kb { --kb-h: 160px; }
  .key-hint { display: none; }
  .answers-buttons { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .answer { padding: 10px 11px 9px; }
  .answer kbd { display: none; }
  .answer-label { font-size: 23px; }
  .session { grid-template-columns: repeat(2, 1fr); }
  .opt { grid-template-columns: 1fr; gap: 6px; }
  .actions .btn kbd { display: none; }
  .hero-tiles { grid-template-columns: 1fr; }
  .stats-hero, .mode-stats { padding: 20px 16px; }
  .mini-tiles { grid-template-columns: repeat(3, 1fr); }
  .item-row { grid-template-columns: 74px 1fr 34px 50px; gap: 8px; }
  .item-label small { display: none; }
  .foot { display: none; }
}

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