/* Theorywise (th-*). Colours only from the tokens in shared/css/style.css, so light and dark both work.
   Mobile first: wide things (staves, tables, grids) scroll inside their own box, never the page. */

/* ---------- staff (rendered by piano/js/staff.js, which uses pn-st-* class names) ---------- */
.th-staff { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.th-staff .pn-staff { display: block; height: auto; max-width: none; }
.th-staff.center .pn-staff { margin: 0 auto; }
.th-staff .pn-st-line, .th-staff .pn-st-ledger { stroke: var(--muted); stroke-width: 1; }
.th-staff .pn-st-bar { stroke: var(--muted); stroke-width: 1.2; }
.th-staff .pn-st-final { stroke: var(--fg); stroke-width: 3.2; }
.th-staff .pn-st-brace { fill: none; stroke: var(--fg); stroke-width: 2; }
.th-staff .pn-st-clef path { fill: none; stroke: var(--fg); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.th-staff .pn-st-clef circle { fill: var(--fg); }
.th-staff .pn-st-time { font: 800 22px var(--font-display); fill: var(--fg); }
.th-staff .pn-st-acc { fill: none; stroke: var(--fg); stroke-width: 1.2; stroke-linecap: round; }
.th-staff .pn-st-acc.pn-st-thick { stroke-width: 2.4; stroke-linecap: butt; }
.th-staff .pn-st-head, .th-staff .pn-st-dot, .th-staff .pn-st-flag, .th-staff .pn-st-rest { fill: var(--fg); }
.th-staff .pn-st-head.pn-st-open { fill: none; stroke: var(--fg); stroke-width: 1.9; }
.th-staff .pn-st-stem { stroke: var(--fg); stroke-width: 1.3; }
.th-staff .pn-st-rest-q, .th-staff .pn-st-rest-line { fill: none; stroke: var(--fg); stroke-width: 2.4; stroke-linejoin: round; }
.th-staff .pn-st-label { font: 600 11px var(--font-mono); fill: var(--muted); }
.th-staff .pn-st-accent .pn-st-head, .th-staff .pn-st-accent .pn-st-dot { fill: var(--cool); }
.th-staff .pn-st-accent .pn-st-head.pn-st-open { fill: none; stroke: var(--cool); }
.th-staff .pn-st-accent .pn-st-stem, .th-staff .pn-st-accent .pn-st-acc { stroke: var(--cool); }
.th-staff .pn-st-accent .pn-st-label { fill: var(--cool); }
.th-staff .pn-st-now .pn-st-head { fill: var(--accent); }
.th-staff .pn-st-now .pn-st-head.pn-st-open { fill: none; stroke: var(--accent); }
.th-staff .pn-st-now .pn-st-stem { stroke: var(--accent); }

/* ---------- lessons ---------- */
.th-ln-meta { gap: 8px 12px; margin-top: -8px; }
.th-ln-lesson { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.th-ln-lesson > .prose:first-child h2:first-child { margin-top: 0; }
.th-figure { max-width: 100%; min-width: 0; }
.th-callout-body { display: flex; flex-direction: column; gap: 6px; }
.th-practise { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 18px; }
.th-practise h2 { font-size: 22px; }
.th-ln-complete {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.th-ln-complete .btn.primary { max-width: 100%; white-space: normal; text-align: left; }
.th-device { gap: 10px; }
.th-device > h2 { margin-top: 6px; }
.th-device .prose { gap: 8px; }
.btn { max-width: 100%; }
.row .btn.small { white-space: normal; text-align: center; }

/* tables and word lists */
.th-table-wrap { max-width: 100%; -webkit-overflow-scrolling: touch; }
.th-table { min-width: 100%; }
.th-table td { vertical-align: top; line-height: 1.45; }
.th-table td .btn { white-space: nowrap; }
.th-terms { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 8px 18px; margin: 0; max-width: 72ch; }
.th-terms dt { font-weight: 700; color: var(--fg); overflow-wrap: anywhere; }
.th-terms dd { margin: 0; color: var(--muted); line-height: 1.5; }
@media (max-width: 560px) {
  .th-terms { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .th-terms dd { margin-bottom: 10px; }
}
.th-list { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 6px; }
.th-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* elements of music */
.th-elements { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 10px; }
.th-element { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.th-element b { font: 700 17px var(--font-display); }
.th-element-letter { color: var(--accent); font-size: 1.3em; }
.th-element p { color: var(--muted); font-size: 14.5px; line-height: 1.5; }

/* structure letters */
.th-form { display: flex; flex-wrap: wrap; gap: 6px; }
.th-form-box {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 44px; min-height: 40px;
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); font: 700 15px var(--font-display);
}
.th-form-box small { font: 500 11px var(--font-body); color: var(--muted); }
.th-form-A { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.th-form-B { background: var(--cool-soft); border-color: var(--cool); color: var(--cool); }
.th-form-C { background: var(--good-soft); border-color: var(--good); color: var(--good); }

/* chords */
.th-chord-row { display: grid; grid-template-columns: repeat(7, minmax(64px, 1fr)); gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.th-chord-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; min-height: 56px; cursor: pointer;
  background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 10px; font: inherit;
}
.th-chord-btn:hover { border-color: var(--accent); }
.th-chord-btn b { font: 800 18px var(--font-display); }
.th-chord-btn span { font: 600 12px var(--font-mono); color: var(--muted); }
.th-cadences, .th-ornaments, .th-textures { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 12px; }
.th-cadence, .th-ornament, .th-texture {
  display: flex; flex-direction: column; gap: 8px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.th-cadence p, .th-ornament p, .th-texture p { color: var(--muted); font-size: 15px; line-height: 1.5; }
.th-cad-chords { color: var(--accent); }
.th-blues { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; max-width: 420px; }
.th-blues-bar { position: relative; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 16px 6px 8px; text-align: center; }
.th-blues-bar small { position: absolute; top: 2px; left: 6px; font: 500 10px var(--font-mono); color: var(--muted); }
.th-blues-bar b { font: 700 16px var(--font-mono); }

/* circle of fifths */
.th-circle-wrap { max-width: 360px; width: 100%; margin: 0 auto; }
.th-circle { display: block; width: 100%; height: auto; }
.th-circle-ring { fill: none; stroke: var(--line); stroke-width: 1; }
.th-circle-hub { fill: var(--surface-2); }
.th-circle-hubtext { font: 500 10px var(--font-body); fill: var(--muted); }
.th-circle-key { cursor: pointer; outline: none; }
.th-circle-dot { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; }
.th-circle-major { font: 700 13px var(--font-body); fill: var(--fg); }
.th-circle-minor { font: 500 11px var(--font-body); fill: var(--muted); }
.th-circle-key:hover .th-circle-dot, .th-circle-key:focus-visible .th-circle-dot { stroke: var(--accent); }
.th-circle-key.on .th-circle-dot { fill: var(--accent); stroke: var(--accent); }
.th-circle-key.on .th-circle-major { fill: var(--accent-ink); }
.th-circle-key.on .th-circle-minor { fill: var(--accent); font-weight: 700; }
.th-circle-info { font-weight: 600; color: var(--accent); min-height: 1.5em; text-align: center; }

/* anchor songs */
.th-anchor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 12px; }
.th-anchor {
  display: flex; flex-direction: column; gap: 8px; min-width: 0;
  background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius-lg); padding: 16px;
  box-shadow: inset 4px 0 0 var(--accent);
}
.th-anchor h3 { font: 700 20px/1.2 var(--font-display); }
.th-anchor p { color: var(--muted); font-size: 15px; line-height: 1.5; }
.th-anchor-iv { font: 600 12px var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.th-anchor-text { color: var(--accent); }

/* ---------- practice ---------- */
.th-pr-stage { gap: 16px; }
.th-pr-stage .prompt { overflow-wrap: anywhere; }
.th-pr-head { align-items: flex-start; flex-wrap: nowrap; }
.th-pr-head .prompt { flex: 1; min-width: 0; }
@media (max-width: 480px) { .th-pr-head { flex-wrap: wrap; } }
.th-pr-hints { line-height: 2; }
@media (hover: none) { .th-pr-hints { display: none; } }
.th-pr-start { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; padding: 18px 0; }
.th-pr-visual:empty { display: none; }
.th-pr-visual { display: flex; justify-content: center; min-width: 0; }
.th-pr-answers .th-pr-ans { position: relative; flex-direction: column; gap: 0; line-height: 1.25; padding: 8px 14px; text-align: center; min-width: 0; overflow-wrap: anywhere; }
.th-pr-ans-label { font-weight: 600; }
.th-pr-sub { font: 500 12px var(--font-mono); color: var(--muted); }
.th-pr-ans.good .th-pr-sub, .th-pr-ans.bad .th-pr-sub { color: inherit; }
.th-pr-key { position: absolute; top: 3px; right: 4px; font-size: 10px; padding: 0 3px; line-height: 1.3; opacity: 0.55; border-bottom-width: 1px; }
@media (hover: none) { .th-pr-key { display: none; } }
.th-pr-answers.th-pr-letters { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.th-pr-answers.th-pr-letters .th-pr-ans { padding: 8px 2px; font-size: 18px; }
.th-pr-answers.th-pr-keys { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
.th-pr-answers.th-pr-wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.th-pr-answers.th-pr-text { grid-template-columns: minmax(0, 1fr); }
.th-pr-answers.th-pr-text .th-pr-ans { align-items: flex-start; text-align: left; padding-right: 28px; }
.th-pr-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.th-pr-chip {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  padding: 4px 10px 4px 7px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--fg); font: 500 13px var(--font-body); text-transform: none; letter-spacing: 0;
}
.th-pr-chip input { width: 15px; height: 15px; margin: 0; }
.th-pr-chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.th-pr-chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.th-pr-info:empty { display: none; }
.th-songbox p { margin: 0; }

/* flashcards */
.th-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 200px; width: 100%;
  padding: 24px 16px; border-radius: var(--radius-lg); border: 2px dashed var(--line); background: var(--surface-2);
  color: var(--fg); font: inherit; cursor: pointer; text-align: center;
}
.th-card.flipped { border-style: solid; border-color: var(--cool); background: var(--cool-soft); }
.th-card-term { margin: 0; }
.th-card-meaning { font-size: 19px; font-weight: 600; color: var(--cool); min-height: 1.4em; max-width: 40ch; }

/* exam quiz round summary */
.th-round-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); gap: 4px 16px; }
.th-round-list li { font-weight: 600; }
.th-round-list li.good { color: var(--good); }
.th-round-list li.bad { color: var(--bad); }

/* ---------- songs ---------- */
.th-iv-list { display: flex; flex-direction: column; gap: 10px; }
.th-iv-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.th-iv-item.anchor { border-color: var(--accent); }
.th-iv-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.th-iv-head b { font: 700 18px var(--font-display); }
.th-iv-song { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); min-width: 0; }
.th-iv-song p { overflow-wrap: anywhere; }
.th-spotify { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: var(--radius); background: var(--surface-2); min-width: 0; }
.th-spotify-frame { display: block; width: 100%; height: 152px; border: 0; border-radius: 12px; }
.th-spotify-others { gap: 6px; align-items: flex-start; }
.th-spotify-pick { text-align: left; justify-content: flex-start; }

/* ---------- genres ---------- */
.th-gcse .th-terms { max-width: none; }

/* ---------- exam ---------- */
.th-setworks .table-wrap { margin-top: 4px; }
.th-glossary { max-width: none; }
.th-gl-cat { margin-left: 8px; font-weight: 500; vertical-align: 1px; }
.th-checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 18px 24px; }
.th-check-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.th-check-list li { display: flex; align-items: center; gap: 10px; }
.th-check { flex: none; width: 22px; height: 22px; border-radius: 6px; border: 1.5px solid var(--line); display: grid; place-items: center; font: 700 13px var(--font-body); color: var(--good); }
.th-check-list li.done .th-check { border-color: var(--good); background: var(--good-soft); }

/* ---------- tips ---------- */
.th-tip { display: flex; flex-direction: column; gap: 8px; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.th-tip p { color: var(--muted); font-size: 15px; line-height: 1.5; }
.th-tip-link { margin-top: auto; font-size: 14px; font-weight: 600; text-decoration: none; color: var(--accent); }
.th-tip-link:hover { text-decoration: underline; }
.th-tip-featured { border-color: var(--accent); }
.th-tip-featured h2 { font-size: clamp(24px, 5vw, 32px); }
.th-tip-featured p { color: var(--fg); font-size: 17px; max-width: 62ch; }
.th-tip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 12px; }
.th-tips-empty { grid-column: 1 / -1; padding: 24px 0; text-align: center; }
.th-tips-filters { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: end; }
.th-tips-search { flex: 1 1 240px; min-width: 0; }
.th-tips-search input, .controls .grow input { width: 100%; }
.th-chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.th-chip-btn {
  font: 500 13px var(--font-body); padding: 6px 12px; border-radius: 999px; cursor: pointer; min-height: 34px;
  background: var(--surface-2); color: var(--muted); border: 1px solid transparent;
}
.th-chip-btn:hover { color: var(--fg); border-color: var(--line); }
.th-chip-btn.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- home ---------- */
.th-home-figure { gap: 12px; }
.th-home-now { font: 700 clamp(18px, 3vw, 22px)/1.25 var(--font-display); color: var(--accent); min-height: 2.5em; }
.th-home-anchors { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 8px; }
.th-home-anchor {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; cursor: pointer; min-height: 60px;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg); font: inherit;
}
.th-home-anchor:hover, .th-home-anchor:focus-visible { border-color: var(--accent); }
.th-home-anchor b { font: 700 15px var(--font-display); color: var(--accent); }
.th-home-anchor span { font-size: 13.5px; color: var(--muted); }
