/* Music theory. Colors are tokens: light by default, dark from the system or the switch. */
:root {
  --bg: #f7f5f0;
  --panel: #ffffff;
  --panel-2: #f1eee7;
  --line: #e1dbcf;
  --text: #1f1c17;
  --muted: #6a6358;
  --accent: #5b3cc4;
  --accent-text: #ffffff;
  --accent-soft: #ece6fb;
  --tone: #8b6fe0;
  --ok: #1d7f47;
  --ok-soft: #dff3e7;
  --bad: #b8322a;
  --bad-soft: #fbe3e0;
  --key-white: #fffdf9;
  --key-white-edge: #cfc8bb;
  --key-black: #25211c;
  --key-down: #e6e0d4;
  --fret-bg: #efe4d2;
  --fret-line: #b9a98f;
  --string: #8c7b62;
  --shadow: 0 1px 3px rgba(40, 30, 10, 0.07);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16141c; --panel: #1f1c27; --panel-2: #272333; --line: #353044; --text: #ebe7f2; --muted: #a29bb2;
    --accent: #a98cff; --accent-text: #16141c; --accent-soft: #2f2747; --tone: #7f68c9;
    --ok: #63d394; --ok-soft: #173326; --bad: #ff8a7d; --bad-soft: #3d1d1b;
    --key-white: #e9e5dc; --key-white-edge: #8f897d; --key-black: #0b0a0e; --key-down: #c9c3b6;
    --fret-bg: #2c2620; --fret-line: #6b5d49; --string: #a8987f; --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16141c; --panel: #1f1c27; --panel-2: #272333; --line: #353044; --text: #ebe7f2; --muted: #a29bb2;
  --accent: #a98cff; --accent-text: #16141c; --accent-soft: #2f2747; --tone: #7f68c9;
  --ok: #63d394; --ok-soft: #173326; --bad: #ff8a7d; --bad-soft: #3d1d1b;
  --key-white: #e9e5dc; --key-white-edge: #8f897d; --key-black: #0b0a0e; --key-down: #c9c3b6;
  --fret-bg: #2c2620; --fret-line: #6b5d49; --string: #a8987f; --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden]:not(.hub-link) { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.7rem; line-height: 1.2; margin: .4rem 0 .5rem; }
h2 { font-size: 1.25rem; margin: 2rem 0 .6rem; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .4rem; }
p { margin: .5rem 0; }
.muted, .note { color: var(--muted); }
.note { font-size: .9rem; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 46rem; }
main { max-width: 1000px; margin: 0 auto; padding: .5rem 16px 3rem; }

/* ---- header ---- */
.top { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1000px; margin: 0 auto; padding: 0 8px 0 12px; display: flex; gap: .2rem; align-items: center; }
.top nav { flex: 1; min-width: 0; padding: .45rem 0; display: flex; gap: .15rem; align-items: center; overflow-x: auto; scrollbar-width: none; }
.top nav::-webkit-scrollbar { display: none; }
.top nav a { text-decoration: none; color: var(--muted); padding: .35rem .6rem; border-radius: 8px; white-space: nowrap; font-size: .95rem; }
.top nav a:hover { background: var(--panel-2); color: var(--text); }
.top nav a.on { color: var(--text); background: var(--panel); box-shadow: var(--shadow); font-weight: 600; outline: 1px solid var(--line); }
.top .brand { font-weight: 700; color: var(--text); margin-right: .3rem; display: flex; align-items: center; gap: .35rem; padding-left: .2rem; }
.brand-mark { width: 1.2rem; height: 1.2rem; color: var(--accent); }
.top .hub-link { margin-left: auto; font-size: .85rem; }
.top .hub-link::before { content: "← "; }
html.hosted:not(.installed) .top .hub-link[hidden] { display: inline-block; }

.vol { position: relative; flex: none; }
.vol summary { list-style: none; display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: 50%; color: var(--muted); cursor: pointer; border: 1px solid transparent; }
.vol summary::-webkit-details-marker { display: none; }
.vol summary:hover, .vol[open] summary { color: var(--text); border-color: var(--line); }
.vol summary:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.vol summary svg { width: 1.15rem; height: 1.15rem; }
.vol-pop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .15); display: flex; align-items: center; gap: .6rem; white-space: nowrap; font-size: .9rem; }
.vol-pop label { display: flex; align-items: center; gap: .5rem; }
.vol-pop input { width: 9rem; accent-color: var(--accent); }
.vol-val { width: 2ch; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---- cards, buttons, form bits ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 14px; }
button, .btn {
  font: inherit; font-size: .95rem; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: .45rem .85rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem;
  touch-action: manipulation;
}
button:hover, .btn:hover { border-color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: default; }
button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
select, input[type="number"] {
  font: inherit; font-size: .95rem; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: .4rem .5rem; min-width: 0; max-width: 100%;
}
label.field { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--muted); min-width: 0; }
label.check { display: inline-flex; align-items: center; gap: .4rem; font-size: .95rem; cursor: pointer; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.row.center { align-items: center; }
.seg { display: inline-flex; flex-wrap: wrap; gap: .3rem; }
.spacer { flex: 1; }
#pwa-install { margin-top: .6rem; }

/* explorer readout */
.readout { margin: .8rem 0 .4rem; }
.readout .big { font-size: 1.5rem; font-weight: 700; line-height: 1.25; }
.readout .notes { font-size: 1.15rem; letter-spacing: .02em; }
.pills { display: flex; flex-wrap: wrap; gap: .35rem; margin: .4rem 0; padding: 0; list-style: none; }
.pills li, .pill { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: .1rem .6rem; font-size: .9rem; }
.pills li:has(> button) { background: none; border: 0; padding: 0; }
.pills button { border-radius: 999px; padding: .2rem .75rem; }
.warn { color: var(--bad); }

/* tables */
.table-wrap { overflow-x: auto; margin: .6rem 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { text-align: left; padding: .45rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; background: var(--panel-2); }
tbody tr.pick { cursor: pointer; }
tbody tr.pick:hover td { background: var(--accent-soft); }
td.num { font-variant-numeric: tabular-nums; }

/* ---- piano keyboard ---- */
.kb { overflow-x: auto; overflow-y: hidden; padding: 4px 2px 8px; margin: .6rem 0; overscroll-behavior-x: contain; }
.kb-keys {
  --kh: 150px; --bw: calc(100% / var(--whites) * .62);
  position: relative; display: flex; height: var(--kh); min-width: calc(var(--whites) * 30px);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.k { position: relative; padding: 0; border-radius: 0 0 6px 6px; cursor: pointer; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.k.w { flex: 1 1 0; min-width: 0; background: var(--key-white); border: 1px solid var(--key-white-edge); border-top: 0; margin-left: -1px; padding-bottom: 6px; }
.k.w:first-child { margin-left: 0; }
.k.b { position: absolute; top: 0; width: var(--bw); height: 62%; background: var(--key-black); border: 1px solid var(--key-black); z-index: 2; padding-bottom: 5px; border-radius: 0 0 4px 4px; }
.k:hover { border-color: var(--key-white-edge); }
.k.w.down { background: var(--key-down); }
.k.b.down { background: #4a443b; }
.k .lab { font-size: .8rem; font-weight: 700; line-height: 1; border-radius: 999px; padding: 0; min-width: 0; }
.k.b .lab { font-size: .72rem; }
.k.root .lab, .k.tone .lab, .k.ok .lab, .k.bad .lab { padding: .28rem .32rem; min-width: 1.7rem; color: #fff; }
.k.root .lab { background: var(--accent); color: var(--accent-text); box-shadow: 0 0 0 2px var(--key-white), 0 0 0 4px var(--accent); }
.k.tone .lab { background: var(--tone); }
.k.ok .lab { background: var(--ok); color: var(--bg); }
.k.bad .lab { background: var(--bad); color: var(--bg); }
.k.root .lab:empty, .k.tone .lab:empty, .k.ok .lab:empty, .k.bad .lab:empty { min-width: 1rem; min-height: 1rem; padding: 0; }
.k.w.root, .k.w.tone { background: color-mix(in srgb, var(--key-white) 82%, var(--accent)); }
.k.w.ok { background: color-mix(in srgb, var(--key-white) 70%, var(--ok)); }
.k.w.bad { background: color-mix(in srgb, var(--key-white) 70%, var(--bad)); }
.k .hk { position: absolute; bottom: 2.15rem; font: 600 .6rem/1 ui-monospace, monospace; color: #9a9285; pointer-events: none; }
.k.b .hk { bottom: 1.9rem; color: #8d877c; }
.k.w .hk:not(:empty) ~ .c-mark { bottom: 3rem; }
.kb-help { margin: -.2rem 0 .4rem; font-size: .8rem; }
@media (hover: none) and (pointer: coarse) { .k .hk, .kb-help { display: none; } }
.k .c-mark { position: absolute; bottom: 2.1rem; font-size: .62rem; color: #9a9285; pointer-events: none; }
.k.root .c-mark, .k.tone .c-mark { display: none; }
.k:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

/* ---- guitar fretboard ---- */
.fb { overflow-x: auto; margin: .6rem 0; padding-bottom: 4px; }
.fb-grid {
  display: grid; grid-template-columns: 2.2rem repeat(calc(var(--frets) - 1), minmax(2.4rem, 1fr));
  min-width: calc(var(--frets) * 2.4rem); background: var(--fret-bg); border-radius: 8px; overflow: hidden;
}
.fc {
  position: relative; height: 1.9rem; padding: 0; border: 0; border-radius: 0; background: transparent;
  border-right: 2px solid var(--fret-line); display: grid; place-items: center; cursor: pointer; touch-action: manipulation;
}
.fc::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1.5px; background: var(--string); }
.fc.open { border-right: 5px solid var(--fret-line); background: var(--panel-2); }
.fc:hover { border-color: var(--fret-line); background: color-mix(in srgb, var(--fret-bg) 80%, var(--accent)); }
.fc.down { background: color-mix(in srgb, var(--fret-bg) 60%, var(--accent)); }
.fc .lab { position: relative; z-index: 1; font-size: .7rem; font-weight: 700; line-height: 1; }
.fc.on .lab { background: var(--tone); color: #fff; border-radius: 999px; padding: .22rem .26rem; min-width: 1.45rem; }
.fc.root .lab { background: var(--accent); color: var(--accent-text); }
.fnum { font-size: .7rem; color: var(--muted); text-align: center; padding: .1rem 0; background: var(--panel); }
.fnum.dot { font-weight: 700; color: var(--text); }

/* ---- circle of fifths ---- */
.circle-layout { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 18px; align-items: start; }
.circle svg { width: 100%; height: auto; display: block; touch-action: manipulation; }
.circle .slot { cursor: pointer; }
.circle .slot path { fill: var(--panel-2); stroke: var(--line); stroke-width: 1.5; }
.circle .slot path.inner { fill: var(--panel); }
.circle .slot:hover path { fill: var(--accent-soft); }
.circle .slot.sel path { fill: var(--accent); }
.circle .slot.sel path.inner { fill: var(--tone); }
.circle .slot.near path.outer { fill: var(--accent-soft); }
.circle text { fill: var(--text); font: 600 15px system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.circle text.min { font-size: 12.5px; font-weight: 500; }
.circle text.sig { font-size: 10.5px; fill: var(--muted); font-weight: 500; }
.circle .slot.sel text { fill: var(--accent-text); }
.circle .slot.sel text.min, .circle .slot.sel text.sig { fill: #fff; }
.circle .hub { fill: var(--panel); stroke: var(--line); }
.circle .hub-text { font-size: 13px; fill: var(--muted); font-weight: 500; }
.circle .slot:focus-visible { outline: none; }
.circle .slot:focus-visible path.outer { stroke: var(--accent); stroke-width: 3; }

/* ---- practice ---- */
.drills { display: flex; flex-wrap: wrap; gap: .35rem; padding: .2rem 0 .7rem; }
.drills button { flex: none; }
.q-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; justify-content: space-between; }
.prompt { font-size: 1.35rem; font-weight: 700; margin: .2rem 0; }
.scorebar { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.scorebar b { color: var(--text); }
.answers { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.2rem, 1fr)); gap: .45rem; margin: .8rem 0 .4rem; }
.answers button { justify-content: center; text-align: center; min-height: 2.75rem; padding: .4rem .5rem; line-height: 1.2; }
.answers button.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--text); font-weight: 700; }
.answers button.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--text); text-decoration: line-through; }
.answers button:disabled { opacity: 1; }
.answers button:disabled:not(.ok):not(.bad) { opacity: .55; }
.feedback { min-height: 3.2rem; margin: .3rem 0; padding: .55rem .8rem; border-radius: 10px; background: var(--panel-2); }
.feedback.ok { background: var(--ok-soft); }
.feedback.bad { background: var(--bad-soft); }
.feedback .verdict { font-weight: 700; }
.feedback.ok .verdict { color: var(--ok); }
.feedback.bad .verdict { color: var(--bad); }
.options { display: flex; flex-wrap: wrap; gap: .5rem 1.1rem; align-items: center; margin: .5rem 0; }
.options .group { display: flex; flex-wrap: wrap; gap: .3rem .8rem; align-items: center; }
.options .group-label { font-size: .85rem; color: var(--muted); }
kbd { font: .8rem ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 .3rem; background: var(--panel); }

/* ---- progress ---- */
.bar { position: relative; height: .5rem; border-radius: 999px; background: var(--panel-2); overflow: hidden; min-width: 4rem; margin-top: .45rem; }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--ok); border-radius: 999px; }
.bar.low i { background: var(--bad); }
.weak { display: flex; flex-wrap: wrap; gap: .3rem; }
.weak span { font-size: .85rem; border-radius: 999px; padding: .05rem .55rem; background: var(--bad-soft); }
.box-dots { letter-spacing: .1em; color: var(--accent); white-space: nowrap; }

/* ---- home ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 12px; margin: 1rem 0; }
.tile { display: block; text-decoration: none; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent); }
.tile b { display: block; font-size: 1.05rem; margin-bottom: .2rem; }
.tile span { color: var(--muted); font-size: .92rem; }
.played { font-size: 1.3rem; font-weight: 700; min-height: 2rem; }

.pwa-toast {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 60;
  display: flex; gap: .8rem; align-items: center; max-width: calc(100% - 2rem);
  padding: .6rem .7rem .6rem 1rem; border-radius: 12px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
footer { max-width: 1000px; margin: 0 auto; padding: 0 16px 2rem; color: var(--muted); font-size: .85rem; }

@media (max-width: 760px) {
  .circle-layout { grid-template-columns: minmax(0, 1fr); }
  .circle { max-width: 420px; margin: 0 auto; width: 100%; }
}
@media (max-width: 520px) {
  h1 { font-size: 1.45rem; }
  .kb-keys { --kh: 130px; }
  .answers { grid-template-columns: repeat(auto-fill, minmax(6.8rem, 1fr)); }
  .card { padding: 12px; }
  .top nav a { padding: .35rem .5rem; }
}
