/* ============================================
   RHYTHM KIT — the Rhythm Lab (bar + counting grid) and the Rhythm Tree. Uses the lesson tokens
   (--ink --muted --line --card --accent --accent-dark --accent-soft --frame) so it follows dark mode.
   The Lab is the one full-width interactive on a counting guide (owner ruling, 2026-11-28).
   ============================================ */
.rk-lab, .rk-tree { --ph: -10%; position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
    padding: 14px 16px 12px; margin: 22px 0 26px; clear: both; font-family: var(--sans); }
.rk-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.rk-pill { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-dark);
    background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 99px; padding: 2px 9px; }
.rk-title { font-family: var(--display); font-size: 1.2rem; font-weight: 700; }
.rk-hint { margin: 0 0 6px; color: var(--muted); font-size: .92rem; }

/* counting-system switch */
.rk-sysrow { margin: 2px 0 6px; }
.rk-systems { display: inline-flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.rk-systems button { font: 600 14px var(--sans); padding: 7px 14px; border: 0; border-right: 1px solid var(--line);
    background: var(--card); color: var(--ink); cursor: pointer; }
.rk-systems button:last-child { border-right: 0; }
.rk-systems button[aria-pressed="true"] { background: var(--accent); color: #fff; }
body.dark-mode .rk-systems button[aria-pressed="true"] { color: #0b1f1c; }

/* the bar and its grid; the playhead line runs through both */
.rk-stage { position: relative; }
.rk-stage::after { content: ''; position: absolute; top: 18px; bottom: 6px; left: var(--ph); width: 3px; margin-left: -1px;
    background: var(--accent); border-radius: 2px; opacity: 0; pointer-events: none; }
.rk-playing .rk-stage::after, .rk-video .rk-stage::after { opacity: .55; }
.rk-score svg { display: block; width: 100%; height: auto; }
body.dark-mode .rk-score svg, body.dark-mode .rk-rscore svg { filter: invert(.92) hue-rotate(180deg); }
.rk-grid { display: flex; gap: 6px; }
.rk-beat { flex: 1 1 0; display: flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--frame); }
.rk-cell { flex: 1 1 0; min-width: 0; height: 46px; padding: 0; border: 1px solid transparent; border-radius: 6px; background: transparent;
    color: var(--muted); font: 700 15px var(--sans); cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background-color .08s, transform .08s; }
.rk-cell span { pointer-events: none; white-space: nowrap; }
/* a long Kodály name (ta-a-a-a) runs on over the cells the note is held for */
.rk-cell.rk-long { justify-content: flex-start; padding-left: 6px; overflow: visible; position: relative; z-index: 1; }
.rk-cell.rk-on-beat { color: var(--ink); }
.rk-cell.on { background: var(--accent); border-color: var(--accent); color: #fff; }
body.dark-mode .rk-cell.on { color: #0b1f1c; }
.rk-cell.hold { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent-dark); }
.rk-cell.rest, .rk-cell.quiet { background: repeating-linear-gradient(135deg, transparent 0 5px, var(--line) 5px 7px); color: var(--muted); }
.rk-cell.rest { border-color: var(--line); }
.rk-cell.rk-dim span { opacity: .28; }
.rk-cell.on.rk-dim span { opacity: 1; }
.rk-cell.now { outline: 3px solid var(--amber); outline-offset: -1px; }
.rk-cell.hit { transform: scale(1.12); }
.rk-compact .rk-cell, .rk-video .rk-cell { cursor: default; }
.rk-cell:focus-visible, .rk-controls button:focus-visible, .rk-systems button:focus-visible, .rk-row:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.rk-say { margin: 10px 2px 2px; font-family: var(--display); font-size: 1.15rem; font-weight: 600; min-height: 1.6em; }
.rk-countin { position: absolute; right: 10px; top: 0; font: 800 44px/1 var(--display); color: var(--amber); pointer-events: none; }
.rk-countin:not(:empty)::before { content: 'Count-in '; font: 700 13px var(--sans); letter-spacing: .06em; text-transform: uppercase; vertical-align: middle; margin-right: 6px; }
/* no playhead until beat 1; the count-in lights the beat numbers instead */
.rk-counting-in .rk-stage::after { opacity: 0 !important; }
.rk-cell.ci { background: var(--amber); border-color: var(--amber); color: #fff; }
.rk-cell.ci span { opacity: 1 !important; }

/* controls */
.rk-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line);
    font-size: 14px; color: var(--muted); }
.rk-controls button, .rk-controls select { font: 600 14px var(--sans); border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px;
    background: var(--card); color: var(--ink); cursor: pointer; }
.rk-controls .rk-play { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 88px; }
body.dark-mode .rk-controls .rk-play { color: #0b1f1c; }
.rk-tempo { display: inline-flex; align-items: center; gap: 6px; }
.rk-tempo input { width: 110px; accent-color: var(--accent); }
.rk-tempo b { color: var(--ink); min-width: 2.2em; font-variant-numeric: tabular-nums; }
.rk-build { display: inline-flex; align-items: center; gap: 4px; }
.rk-build button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.rk-all { display: inline-flex; align-items: center; gap: 5px; }
.rk-all input { accent-color: var(--accent); }
.rk-note { margin: 8px 2px 0; font-size: .9rem; color: var(--muted); }

/* compact labs float beside the text like any example */
.rk-lab.rk-compact { padding: 10px 12px; margin: 4px 0 14px 22px; }
.rk-compact .rk-cell { height: 36px; font-size: 13px; }
.rk-compact .rk-controls { margin-top: 6px; padding-top: 6px; }
.rk-compact .rk-say { font-size: 1rem; }

/* ---------- the tree ---------- */
.rk-rows { display: flex; flex-direction: column; gap: 4px; position: relative; z-index: 1; }
.rk-row { display: grid; grid-template-columns: 9.5em 1fr; grid-template-rows: auto auto; align-items: center; text-align: left;
    background: transparent; border: 1px solid transparent; border-radius: 10px; padding: 2px 6px; cursor: pointer; color: var(--ink); font: inherit; }
.rk-row:hover { border-color: var(--line); }
.rk-row.playing { border-color: var(--accent); background: var(--accent-soft); }
.rk-rname { grid-row: 1 / span 2; font-weight: 700; font-size: .95rem; }
.rk-rscore { display: block; min-width: 0; }
.rk-rscore svg { display: block; width: 100%; height: auto; margin: -14px 0 -22px; }
.rk-rscore svg.rk-noclef .vf-clef, .rk-rscore svg.rk-noclef .vf-timesignature { opacity: 0; }
.rk-rsay { position: relative; display: block; height: 1.3em; font-size: .85rem; color: var(--accent-dark); font-weight: 700; margin: 0 0 6px; }
.rk-rsay span { position: absolute; top: 0; transform: translateX(-30%); white-space: nowrap; }
.rk-links { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.rk-links line { stroke: var(--accent); stroke-width: 1.2; opacity: .35; }
.rk-tree .vf-stavenote.rk-lit path, .rk-tree .vf-stavenote.rk-lit rect { fill: var(--accent) !important; stroke: var(--accent); }

@media (max-width: 640px) {
    .rk-lab, .rk-tree { padding: 10px; }
    .rk-cell { height: 38px; font-size: 12px; border-radius: 4px; }
    .rk-grid { gap: 3px; } .rk-beat { padding: 2px; gap: 1px; }
    .rk-systems button { padding: 6px 10px; font-size: 13px; }
    .rk-row { grid-template-columns: 1fr; }
    .rk-rname { grid-row: auto; font-size: .85rem; margin-top: 4px; }
    .rk-lab.rk-compact { margin: 4px 0 14px; }
    .rk-say { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) { .rk-cell { transition: none; } .rk-cell.hit { transform: none; } }

/* tree: notes or rests */
.rk-treebar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin: 0 0 6px; }
.rk-treebar .rk-hint { margin: 0; }
.rk-nr { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.rk-nr button { font: 600 13px var(--sans); padding: 5px 12px; border: 0; background: var(--card); color: var(--ink); cursor: pointer; }
.rk-nr button + button { border-left: 1px solid var(--line); }
.rk-nr button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-dark); }

/* on the guide pages */
.rk-compact .rk-note { display: none; }
.rk-float.rk-tree, .rk-float.rk-lab { padding: 10px 12px; }
.rk-sys-inline { margin: 4px 0 12px; }
.rk-hear { font-size: 12px; width: 30px; height: 28px; border-radius: 7px; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent-dark); cursor: pointer; }
.rk-hear:hover { background: var(--accent); color: #fff; }
.rk-varies { color: var(--muted); font-size: .85em; }
.rk-compare td:not(:first-child) { white-space: nowrap; font-weight: 600; }
.rk-pair .rk-lab { margin: 0 0 8px; }
.rk-hear-wide { width: auto; padding: 0 12px; font-size: 14px; font-weight: 600; }
.rk-tight .rk-cell.rk-dim span { visibility: hidden; }
.rk-tight .rk-cell { font-size: 12px; }
.rk-tight { gap: 3px; }
.rk-tight .rk-beat { padding: 2px; gap: 1px; }

/* each box's own options */
.rk-opt { display: inline-flex; align-items: center; gap: 5px; }
.rk-opt input { accent-color: var(--accent); }
.rk-compact .rk-sysrow { margin: 0 0 4px; }
.rk-compact .rk-systems button { padding: 4px 9px; font-size: 12px; }
.rk-compact .rk-controls { gap: 6px 10px; font-size: 13px; }
.rk-compact .rk-tempo input { width: 80px; }
.rk-sys-slot .rk-systems button { padding: 4px 9px; font-size: 12px; }

/* small box grids in the pattern tables: one box per sixteenth (or per sixth of a compound beat) */
.rk-mini { display: inline-flex; gap: 2px; vertical-align: middle; }
.rk-mini i { width: 16px; height: 16px; border-radius: 3px; border: 1px solid var(--line); background: var(--card); }
.rk-mini i.on { background: var(--accent); border-color: var(--accent); }
.rk-mini i.hold { background: var(--accent); border-color: var(--accent); opacity: .38; }
.rk-mini i.rest { background: repeating-linear-gradient(135deg, transparent 0 3px, var(--line) 3px 5px); }

/* ---------- the three rows: Count / Say / Write ---------- */
.rk-line { display: flex; align-items: center; }
.rk-l-count { margin-top: -10px; }
.rk-rowlab { flex: none; box-sizing: border-box; padding-right: 10px; text-align: right; font: 800 10.5px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.rk-srow, .rk-wrow { display: flex; gap: 6px; flex: none; }
.rk-srow .rk-beat, .rk-wrow .rk-beat { background: none; padding: 0 3px; gap: 2px; }
.rk-sc, .rk-wc { flex: 1 1 0; min-width: 0; height: 30px; display: flex; align-items: center; position: relative; white-space: nowrap; }
/* Say: the syllable, then a bar for as long as the note lasts; silence is hatched */
.rk-sc.sa-on { font: 700 15px var(--sans); color: var(--ink); justify-content: flex-start; padding-left: 4px; z-index: 1; overflow: visible; }
.rk-sc.sa-on b { font-weight: 800; background: var(--card); padding-right: 3px; position: relative; z-index: 1; }
.rk-sc.sa-on::after, .rk-sc.sa-hold::after { content: ''; position: absolute; left: 0; right: -2px; top: 50%; height: 4px; margin-top: -2px; background: var(--accent); opacity: .35; border-radius: 2px; }
.rk-sc.sa-on::after { left: 4px; }
.rk-sc.sa-rest::after { content: ''; position: absolute; left: 1px; right: 1px; top: 50%; height: 8px; margin-top: -4px; background: repeating-linear-gradient(135deg, transparent 0 3px, var(--line) 3px 5px); border-radius: 2px; }
.rk-sc.now.sa-on b, .rk-sc.now.sa-on { color: var(--accent-dark); }
.rk-sc.now::after { opacity: .9; }
/* Write: pencil-style counts under the notes; the beats nothing starts on in parentheses */
.rk-wc { justify-content: flex-start; padding-left: 4px; font: 600 16px var(--display); font-style: italic; color: var(--ink); overflow: visible; }
.rk-wc.rk-paren { color: var(--muted); }
.rk-l-write { border-top: 1px dashed var(--line); margin-top: 2px; }
.rk-tight .rk-sc.sa-on, .rk-tight .rk-wc { font-size: 12px; padding-left: 1px; }
.rk-compact .rk-sc, .rk-compact .rk-wc { height: 26px; }
.rk-compact .rk-rowlab { font-size: 9.5px; padding-right: 6px; }

/* Notes: Piano | Voice */
.rk-sound { display: inline-flex; align-items: center; gap: 4px; }
.rk-sound button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }

/* a table row playing its own figure */
tr.rk-row-playing td { background: var(--accent-soft); }
tr.rk-row-countin .rk-mini i { border-color: var(--amber); }
.rk-mini i.now { outline: 2px solid var(--amber); outline-offset: 0; }
.rk-hear.playing { background: var(--accent); color: #fff; }

/* ---------- the pattern card ---------- */
.rk-figbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.rk-figbar .rk-sound button { font: 600 13px var(--sans); border: 1px solid var(--line); border-radius: 8px; padding: 5px 11px; background: var(--card); color: var(--ink); cursor: pointer; }
.rk-figbar .rk-sound button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.rk-figbar .rk-hint { margin: 0; }
.rk-figlist { display: flex; flex-direction: column; }
.rk-fig { display: grid; grid-template-columns: 40px minmax(150px, 1.2fr) 104px minmax(170px, 1fr); align-items: center; gap: 12px;
    padding: 6px 4px; border-top: 1px solid var(--line); border-radius: 8px; }
.rk-fig:first-child { border-top: 0; }
.rk-fig.playing { background: var(--accent-soft); }
.rk-figplay { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--accent); background: var(--card); color: var(--accent-dark); font-size: 12px; cursor: pointer; }
.rk-fig.playing .rk-figplay { background: var(--accent); color: #fff; }
body.dark-mode .rk-fig.playing .rk-figplay { color: #0b1f1c; }
.rk-figname b { display: block; font-size: 15px; }
.rk-figname small { display: block; color: var(--muted); font-size: 13px; }
.rk-fignote svg { display: block; width: 104px; height: auto; }
body.dark-mode .rk-fignote svg { filter: invert(.92) hue-rotate(180deg); }
.rk-figgrid .rk-beat { display: flex; }
.rk-figgrid .rk-cell { height: 34px; cursor: default; font-size: 14px; }
.rk-fig.counting .rk-figgrid .rk-cell.rk-on-beat { outline: 2px solid var(--amber); outline-offset: -2px; }
.rk-figsay { font: 700 15px var(--display); color: var(--accent-dark); white-space: nowrap; }
@media (max-width: 640px) {
    .rk-fig { grid-template-columns: 36px 1fr 96px; grid-template-areas: "p n s" "p g g"; row-gap: 4px; }
    .rk-figplay { grid-area: p; } .rk-figname { grid-area: n; } .rk-fignote { grid-area: s; } .rk-figgrid { grid-area: g; } .rk-figsay { display: none; }
    .rk-fignote svg { width: 96px; }
}

/* "Count this bar": the rows wait behind Show answer */
.rk-quiz:not(.rk-revealed) .rk-line { visibility: hidden; }
.rk-quiz:not(.rk-revealed) .rk-stage { position: relative; }
.rk-quiz:not(.rk-revealed) .rk-stage::before { content: 'Count it out loud, then press Show answer.'; position: absolute; left: 0; right: 0; top: 150px; text-align: center; font: 600 15px var(--sans); color: var(--muted); }
.rk-quiz .rk-reveal { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.rk-quiz .rk-cell { cursor: default; }
/* a lab inside a figure: the figure does the floating */
figure.rk-fig-wrap { margin-top: 4px; }
figure.rk-fig-wrap .rk-lab { margin: 0 0 6px; }
