:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1d1d1f;
  --muted: #6b6b72;
  --border: #e2e0da;
  --accent: #4f4fd1;
  --accent-text: #ffffff;
  --lh: #2f6fde;
  --lh-soft: #e2ecfd;
  --rh: #e1700a;
  --rh-soft: #fdebd9;
  --good: #1c8f4e;
  --good-soft: #dcf3e5;
  --bad: #cf3f3f;
  --bad-soft: #fbe2e2;
  --pick: #7656d6;
  --key-white: #ffffff;
  --key-edge: #c9c7c1;
  --key-black: #222226;
  --key-hint: #9d9da4;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.05), 0 6px 20px rgba(20, 20, 30, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111113;
    --surface: #1b1b1f;
    --surface-2: #26262b;
    --text: #ececf0;
    --muted: #9c9ca6;
    --border: #303036;
    --accent: #8d8df5;
    --accent-text: #15152b;
    --lh: #4f8fff;
    --lh-soft: #1b2944;
    --rh: #ff9a3c;
    --rh-soft: #3b2814;
    --good: #43c47b;
    --good-soft: #163324;
    --bad: #f06a6a;
    --bad-soft: #3a1b1b;
    --pick: #a58cff;
    --key-white: #ececef;
    --key-edge: #7d7d85;
    --key-black: #0b0b0d;
    --key-hint: #8a8a92;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111113;
  --surface: #1b1b1f;
  --surface-2: #26262b;
  --text: #ececf0;
  --muted: #9c9ca6;
  --border: #303036;
  --accent: #8d8df5;
  --accent-text: #15152b;
  --lh: #4f8fff;
  --lh-soft: #1b2944;
  --rh: #ff9a3c;
  --rh-soft: #3b2814;
  --good: #43c47b;
  --good-soft: #163324;
  --bad: #f06a6a;
  --bad-soft: #3a1b1b;
  --pick: #a58cff;
  --key-white: #ececef;
  --key-edge: #7d7d85;
  --key-black: #0b0b0d;
  --key-hint: #8a8a92;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 18px; letter-spacing: -0.01em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
code { font: 14px ui-monospace, "SF Mono", Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }

/* ---------- Header & tabs ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  max-width: 1100px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 8px; }
.legend-inline { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.legend-inline .dot.rh { margin-left: 8px; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.lh { background: var(--lh); }
.dot.rh { background: var(--rh); }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabs button {
  flex: 1;
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 8px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font: 600 11px/1.2 inherit;
  cursor: pointer;
}
.tabs svg { width: 26px; height: 26px; }
.tabs button[aria-current] { color: var(--accent); }

@media (min-width: 900px) {
  body { padding-bottom: 32px; }
  .tabs {
    position: static;
    background: none;
    backdrop-filter: none;
    border: 0;
    padding: 0;
    gap: 4px;
  }
  .tabs button {
    flex: none;
    flex-direction: row;
    gap: 8px;
    font-size: 15px;
    padding: 8px 14px;
    border-radius: 10px;
  }
  .tabs svg { width: 20px; height: 20px; }
  .tabs button:hover { background: var(--surface-2); }
  .tabs button[aria-current] { background: var(--surface); box-shadow: var(--shadow); color: var(--text); }
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 4px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
}

.style-bar { max-width: 1100px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); display: grid; gap: 6px; }
.style-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.style-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.style-blurb { margin: 0; font-size: 13px; color: var(--muted); }
.view { display: grid; gap: 14px; }
/* Grid tracks must be allowed to shrink below their content, or wide rows push the page sideways on phones. */
.view, .result, .board, .panels, .player, .player-top, .now, .quiz-stage, .editor, .preview, .feedback { grid-template-columns: minmax(0, 1fr); }
.view > *, .result > * { min-width: 0; }
.view[hidden] { display: none; }

/* ---------- Controls ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 16px;
  min-height: 44px;
  font: 600 15px/1.2 inherit;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.icon { min-width: 40px; min-height: 40px; padding: 0; border-radius: 50%; font-size: 13px; }
.btn.danger { color: var(--bad); justify-self: start; }
.btn.good-btn { background: var(--good); color: #fff; border-color: transparent; }
.btn.bad-btn { background: var(--bad); color: #fff; border-color: transparent; }

.input {
  width: 100%;
  font: 17px/1.4 inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.input.mono { font: 15px/1.5 ui-monospace, "SF Mono", Menlo, monospace; resize: vertical; }
.search { font-size: 18px; padding: 14px 16px; }
.search-msg { margin: -6px 0 0; min-height: 0; color: var(--muted); font-size: 14px; }
.search-msg:empty { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  min-width: 44px;
  min-height: 38px;
  font: 600 15px/1.2 inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.chip:hover { border-color: var(--muted); }
.chip.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chip.static { cursor: default; min-height: 32px; padding: 5px 11px; font-size: 14px; }
.chips.types .chip { font-size: 14px; }
.chip-sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 4px; }

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 12px;
}
.seg button {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  border-radius: 9px;
  padding: 8px 12px;
  min-height: 36px;
  font: 600 14px/1.2 inherit;
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.toggle { display: inline-flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; min-height: 36px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .switch {
  width: 40px;
  height: 24px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  flex: none;
  transition: background 0.15s;
}
.toggle .switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.toggle input:checked + .switch { background: var(--accent); border-color: transparent; }
.toggle input:checked + .switch::after { transform: translateX(16px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Chord result ---------- */

.result { display: grid; gap: 12px; }
.result-head { display: flex; align-items: center; gap: 14px; min-width: 0; }
.symbol { font-size: 44px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.symbol.big { font-size: 56px; }
.long { font-size: 17px; font-weight: 600; }

.hands { display: grid; gap: 8px; }
@media (min-width: 640px) { .hands { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.hand { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 12px; min-width: 0; }
.hand.lh { background: var(--lh-soft); }
.hand.rh { background: var(--rh-soft); }
.hand-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; min-width: 50px; }
.hand.lh .hand-title { color: var(--lh); }
.hand.rh .hand-title { color: var(--rh); }
.hand-notes { flex: 1; font-size: 19px; font-weight: 700; min-width: 0; }
.hand .btn.icon { background: var(--surface); border-color: transparent; }
.hands.compact .hand-notes { font-size: 17px; }

.inv { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hint-note { margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: 14px; }

/* ---------- Keyboard ---------- */

.board { display: grid; gap: 10px; }
.board.swipe { touch-action: pan-y; }
.panels { display: grid; gap: 10px; }
@media (min-width: 760px) {
  .panels { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; }
  .panel + .panel .kb-box { margin-left: -1px; }
}
.panel-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.kb-box { border-radius: 10px; overflow: hidden; background: var(--key-edge); }

.kb { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.key { cursor: pointer; }
.key rect { stroke: var(--key-edge); stroke-width: 1.2; transition: fill 0.12s; }
.key.white rect { fill: var(--key-white); }
.key.black rect { fill: var(--key-black); stroke: var(--key-black); }
.key.lh rect { fill: var(--lh); }
.key.rh rect { fill: var(--rh); }
.key.pick rect { fill: var(--pick); }
.key.right rect { fill: var(--good); }
.key.wrong rect { fill: var(--bad); }
.key.black.marked rect { stroke: color-mix(in srgb, var(--key-black) 60%, transparent); stroke-width: 2.5; }
.key.ghost rect { stroke: var(--accent); stroke-width: 3; stroke-dasharray: 7 5; }
.key.white.ghost rect { fill: color-mix(in srgb, var(--accent) 12%, var(--key-white)); }
.key.black.ghost rect { fill: color-mix(in srgb, var(--accent) 35%, var(--key-black)); }
.key.pressed rect { filter: brightness(0.8); }
.key text { font: 700 21px -apple-system, BlinkMacSystemFont, system-ui, sans-serif; text-anchor: middle; pointer-events: none; fill: #26262b; }
.key.black text { font-size: 16px; fill: #fff; }
.key.marked text { fill: #fff; }
.key text.hint { font-size: 15px; font-weight: 600; fill: var(--key-hint); }
.key.black text.hint { fill: #9a9aa2; font-size: 13px; }

.kb.mini .key { cursor: default; }
.overview { display: grid; gap: 4px; }
.overview .kb { border-radius: 6px; overflow: hidden; background: var(--key-edge); }
.overview p { margin: 0; }

/* ---------- Cheat sheet ---------- */

.cheat summary, .help summary { cursor: pointer; font-weight: 700; }
.table-wrap { overflow-x: auto; margin-top: 12px; }
.cheat table { width: 100%; border-collapse: collapse; font-size: 15px; }
.cheat th, .cheat td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.cheat thead th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.cheat tbody tr { cursor: pointer; }
.cheat tbody tr:hover, .cheat tbody tr:focus-visible { background: var(--surface-2); outline: none; }
.cheat tbody th { font-weight: 600; }
.lh-text { color: var(--lh); font-weight: 600; }
.rh-text { color: var(--rh); font-weight: 600; }

/* ---------- Songs ---------- */

.song-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
@media (min-width: 760px) { .song-list { grid-template-columns: 1fr 1fr; } }
.song-item { width: 100%; text-align: left; display: grid; gap: 4px; cursor: pointer; font: inherit; color: inherit; }
.song-item:hover { border-color: var(--muted); }
.song-title { font-weight: 700; font-size: 17px; }
.song-preview { font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 24px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

.editor { display: grid; gap: 12px; }
.preview { display: grid; gap: 8px; }
.warn { margin: 0; color: var(--bad); font-size: 14px; }
.help ul { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; }

.player { display: grid; gap: 12px; }
.player-head { flex-wrap: wrap; }
.source-line { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.badge { display: inline-block; margin-left: 8px; padding: 1px 6px; border-radius: 6px; font-size: 11px; font-weight: 700; vertical-align: 2px; background: var(--surface-2); color: var(--muted); }
.ug-panel summary { cursor: pointer; font-weight: 700; }
.steps { margin: 12px 0 0; padding-left: 22px; display: grid; gap: 14px; }
.steps li::marker { font-weight: 700; color: var(--accent); }
.step-body { display: grid; gap: 8px; margin-top: 6px; justify-items: start; }
.step-body p { margin: 0; }
.step-body .row { width: 100%; }
.step-body .row .input { flex: 1; min-width: 0; }
.bookmarklet { cursor: grab; text-decoration: none; display: inline-flex; align-items: center; }
.player-head h2 { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.player-top { display: grid; gap: 10px; background: var(--bg); padding: 4px 0 10px; }
@media (min-height: 700px) {
  .player-top { position: sticky; top: 0; z-index: 5; padding-top: calc(env(safe-area-inset-top) + 6px); }
}
.now { display: grid; gap: 8px; }
.now .symbol { font-size: 48px; }
.next { margin-left: auto; text-align: right; display: grid; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.next strong { font-size: 22px; color: var(--text); text-transform: none; letter-spacing: 0; }
.controls .counter { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
.controls .btn { flex: 1; max-width: 160px; }
.tip { margin: 0; }
.song-chips { display: flex; flex-wrap: wrap; gap: 8px; touch-action: pan-y; }
.song-chips .chip { font-size: 17px; min-width: 58px; min-height: 46px; padding: 10px 14px; }
.section-label { flex-basis: 100%; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-top: 6px; }
.practice { display: grid; gap: 12px; }
.suggestion { display: grid; gap: 8px; justify-items: start; }
.suggestion p { margin: 0; }
.suggest-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; line-height: 1.45; }
.tempo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tempo-row input[type=range] { flex: 1; min-width: 120px; accent-color: var(--accent); }
.tempo-label { min-width: 64px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pulses { display: flex; gap: 6px; flex-wrap: wrap; }
.pulse { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; background: var(--surface-2); color: var(--muted); border: 2px solid transparent; transition: background 0.05s; }
.pulse.main { color: var(--text); border-color: var(--border); }
.pulse.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.practice-status { margin: 0; min-height: 1.3em; }
.hand-note { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.settings-row { display: flex; flex-wrap: wrap; gap: 4px 20px; padding-top: 6px; border-top: 1px solid var(--border); }

/* ---------- Quiz ---------- */

.quiz-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.quiz-stats { margin: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; color: var(--muted); font-weight: 600; }
.quiz-stage { display: grid; gap: 14px; }
.prompt { text-align: center; display: grid; gap: 4px; }
.feedback { display: grid; gap: 12px; }
.feedback:empty { display: none; }
.feedback p { margin: 0; font-weight: 700; font-size: 17px; padding: 10px 14px; border-radius: 12px; }
.good { color: var(--good); background: var(--good-soft); }
.bad { color: var(--bad); background: var(--bad-soft); }
.quiz-stage .row { justify-content: center; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.options .btn { font-size: 20px; min-height: 54px; display: grid; place-items: center; gap: 0; line-height: 1.15; padding: 8px; }
.opt-sub { font-size: 12px; font-weight: 500; opacity: 0.7; }
.mark-hint { margin: 0; text-align: center; }
.sheet-box { display: grid; gap: 6px; justify-items: center; }
.sheet-box:empty { display: none; }
.sheet-box p { margin: 0; text-align: center; }
.brushes { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.brushes[hidden] { display: none; }
.brush { appearance: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 16px; border-radius: 999px; border: 2px solid var(--border); background: var(--surface); color: var(--text); font: 700 15px/1.2 inherit; cursor: pointer; touch-action: manipulation; }
.brush.lh.active { border-color: var(--lh); background: var(--lh-soft); }
.brush.rh.active { border-color: var(--rh); background: var(--rh-soft); }
.kb-scroll { overflow-x: auto; border-radius: 10px; background: var(--key-edge); -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.kb-scroll .kb { min-width: 920px; }
.strikes { display: flex; align-items: center; justify-content: center; gap: 8px; }
.strike { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; }
.strike.used { background: var(--bad); border-color: var(--bad); }
.sheet-fig { margin: 0; display: grid; gap: 6px; }
.sheet-fig figcaption { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 8px; font-size: 12px; color: var(--muted); }
.sheet-fig figcaption .dot + .dot, .sheet-fig figcaption .dot:not(:first-child) { margin-left: 10px; }
.sheet { display: block; width: 100%; max-width: 520px; height: auto; margin: 0 auto; }
.sheet .line { stroke: var(--muted); stroke-width: 1.1; opacity: 0.8; }
.sheet .ledger { stroke: var(--muted); stroke-width: 1.6; }
.sheet .bar { stroke: var(--muted); stroke-width: 1.2; }
.sheet .bar.thick { stroke: var(--text); stroke-width: 2.4; }
.sheet .clef { font: 62px "Apple Symbols", "Noto Music", "Segoe UI Symbol", "Bravura Text", serif; fill: var(--text); }
.sheet .clef.bass { font-size: 42px; }
.sheet .time { font: 800 22px -apple-system, BlinkMacSystemFont, system-ui, sans-serif; text-anchor: middle; fill: var(--text); }
.sheet .chord-symbol { font: 800 24px -apple-system, BlinkMacSystemFont, system-ui, sans-serif; fill: var(--text); }
.sheet .head { stroke: none; }
.sheet .head.open { fill: var(--surface); stroke-width: 2.2; }
.sheet .beam { stroke-width: 3; stroke-linecap: butt; }
.sheet .accent { font: 800 9px -apple-system, BlinkMacSystemFont, system-ui, sans-serif; text-anchor: middle; }
.sheet .stem { stroke-width: 1.8; stroke-linecap: round; }
.sheet .gl { font: 700 8.5px -apple-system, BlinkMacSystemFont, system-ui, sans-serif; text-anchor: end; fill: var(--muted); }
.sheet .gl.space { font-weight: 500; font-size: 8px; opacity: 0.85; }
.sheet .gl.used { font-size: 9.5px; font-weight: 800; opacity: 1; }
.sheet-guide { margin: 0; text-align: center; font-size: 12px; line-height: 1.4; color: var(--muted); }
.sheet .acc { font: 700 18px "Apple Symbols", "Noto Music", "Segoe UI Symbol", system-ui, sans-serif; text-anchor: end; }
.ear-icon { font-size: 48px; line-height: 1.2; }
.ear-tip { margin: 0; text-align: center; }

.mastery {
  display: grid;
  grid-template-columns: auto repeat(var(--cols), minmax(0, 1fr));
  gap: 3px;
  margin-top: 12px;
  font-size: 11px;
  align-items: center;
}
.mh { text-align: center; color: var(--muted); font-weight: 600; overflow: hidden; }
.mh.row-h { text-align: right; padding-right: 6px; }
.cell { display: block; aspect-ratio: 1; border-radius: 5px; background: var(--surface-2); }
.cell.b1 { background: color-mix(in srgb, var(--bad) 55%, var(--surface)); }
.cell.b2 { background: color-mix(in srgb, var(--rh) 55%, var(--surface)); }
.cell.b3 { background: color-mix(in srgb, var(--good) 35%, var(--surface)); }
.cell.b4 { background: color-mix(in srgb, var(--good) 65%, var(--surface)); }
.cell.b5 { background: var(--good); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .cell { width: 12px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
