:root {
  --bg: #fbf6ef; --fg: #3b2f2a; --muted: #75665c; --accent: #a8442b; --accent-soft: #e07a5f; --accent-2: #81b29a;
  --card: #ffffff; --line: #e6d9cb; --soft: #f4ebe1; --panel: rgba(255, 252, 247, 0.98);
  --ok: #3f8a64; --todo: #c9b8a8; --note: #fff4e6; --focus: #2f6fb5;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--fg); font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif; }
body.live { overflow: hidden; height: 100%; }
a { color: var(--accent); }
button { font-weight: 700; font-size: 15px; font-family: inherit; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card); color: var(--fg); padding: 10px 18px; cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { background: none; border: 0; padding: 4px 6px; color: var(--accent); text-decoration: underline; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; max-width: 1040px; margin: 0 auto; padding: 14px 16px 0; }
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 18px; text-decoration: none; color: var(--fg); }
.topbar nav { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a, .topbar nav button { font-weight: 700; font-size: 14px; padding: 8px 12px; border-radius: 999px; text-decoration: none; color: var(--fg); background: none; border: 0; }
.topbar nav a:hover, .topbar nav button:hover { background: var(--soft); }

/* ---------- home ---------- */
#home { max-width: 1040px; margin: 0 auto; padding: 18px 16px 40px; }
#home header { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
#home h1 { margin: 0; font-size: 34px; letter-spacing: -0.01em; }
.lede { color: var(--muted); max-width: 660px; line-height: 1.55; margin: 8px 0 0; }
.callout { background: var(--note); border: 1.5px solid #f1dcc0; border-radius: 16px; padding: 12px 14px; line-height: 1.5; margin: 16px 0 0; font-size: 15px; }
.bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 20px 0 6px; }
.progress { flex: 1; min-width: 200px; display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 700; }
.progress .track { flex: 1; height: 10px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.progress .fill { height: 100%; background: var(--accent-2); border-radius: 999px; transition: width .4s; }
footer.site { max-width: 1040px; margin: 0 auto; padding: 8px 16px 40px; color: var(--muted); font-size: 14px; line-height: 1.55; border-top: 1.5px solid var(--line); }
footer.site p { margin: 10px 0; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 22px; padding: 0; max-width: min(620px, calc(100% - 32px)); width: 100%; color: var(--fg); background: var(--bg); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(43, 35, 31, .55); }
dialog .inner { padding: 22px 22px 18px; max-height: calc(100vh - 64px); overflow-y: auto; }
dialog h2 { margin: 0 0 8px; font-size: 24px; }
dialog ul { padding-left: 20px; line-height: 1.55; margin: 8px 0; }
dialog li { margin: 6px 0; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1.5px solid var(--line); }
.setting small { display: block; color: var(--muted); }
/* Offline proof panel */
.proof-panel { position: fixed; inset: auto 12px 12px auto; width: min(480px, calc(100vw - 24px)); max-height: min(640px, calc(100vh - 24px)); overflow-y: auto; z-index: 60; background: #fff; border: 1px solid #ddd7cc; border-radius: 12px; padding: 14px; box-shadow: 0 8px 32px rgba(0,0,0,.25); color: #23211d; }
.proof-panel h2 { font-size: 14px; margin: 14px 0 6px; }
.proof-panel h2:first-child { margin-top: 0; }
.proof-panel .muted { color: #6e6960; font-size: 13px; line-height: 1.5; }
.proof-panel .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.proof-panel .note { background: #fff4e3; border: 1px solid #f0d9b5; border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.5; margin: 8px 0; }
.proof-panel code { font: 12px ui-monospace, Menlo, monospace; background: #efebe4; padding: 1px 4px; border-radius: 4px; }
#proofLog { font: 11px ui-monospace, Menlo, monospace; max-height: 180px; overflow-y: auto; background: #f7f5f1; border-radius: 8px; padding: 6px 8px; margin: 6px 0; list-style: none; }
#proofLog li { padding: 3px 0; border-bottom: 1px solid #ddd7cc; overflow-wrap: anywhere; }
.proof-origin { font-weight: 700; color: #2f7d5b; }
.proof-origin.remote { color: #c0392b; }
#proofStore ul { font-size: 13px; padding-left: 18px; }

/* ---------- rhythm tutor ---------- */
#home h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 6px; }
#home .metro h2 { margin-top: 0; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dashboard { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 12px 14px; margin: 16px 0 0; }
.dash-line { font-weight: 800; }
.stats { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; color: var(--muted); font-size: 14px; }
.stats b { color: var(--fg); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge { background: var(--note); border: 1px solid #f1dcc0; border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 700; }
.input-mode { border: 1.5px solid var(--line); border-radius: 16px; padding: 10px 14px; margin: 14px 0 0; background: var(--card); display: grid; gap: 6px; }
.input-mode legend { font-weight: 800; padding: 0 6px; }
.input-mode label { display: flex; gap: 8px; align-items: center; line-height: 1.4; }
.metro { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 12px 14px; margin: 16px 0 0; }
.metro-row, .lesson-controls { display: grid; gap: 8px; }
.bpm-label { font-weight: 800; }
.bpm-label output { font-size: 22px; color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.sig-label { font-weight: 700; display: flex; gap: 6px; align-items: center; }
select { font: inherit; padding: 8px 10px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); color: var(--fg); }
.lights, .beat-lights { display: flex; gap: 8px; margin-top: 10px; }
.light { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--soft); color: var(--muted); font-weight: 800; border: 2px solid var(--line); transition: background .05s; }
.light.accent { border-color: var(--accent-soft); }
.light.lit { background: var(--accent-2); color: #fff; }
.light.accent.lit { background: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.card { position: relative; text-align: left; border-radius: 18px; padding: 12px; width: 100%; }
.card:hover:not(:disabled) { border-color: var(--accent-soft); }
.card .w { font-weight: 800; font-size: 17px; }
.card .sig { color: var(--muted); font-size: 13px; font-weight: 700; margin: 2px 0 6px; }
.card .times { color: var(--muted); font-size: 13px; font-weight: 700; margin-top: 6px; }
.card .done { position: absolute; top: 8px; right: 12px; color: var(--ok); font-weight: 900; }
.mini { display: flex; gap: 2px; }
.mini .slot { flex: 1; height: 12px; border-radius: 3px; background: var(--soft); }
.mini .slot.beat { box-shadow: inset 2px 0 0 var(--todo); }
.mini .slot.note { background: var(--accent); }

/* lesson view */
#lesson { display: none; }
body.live #lesson { display: block; }
body.live #home, body.live footer.site { display: none; }
.lesson-inner { max-width: 860px; margin: 0 auto; padding: 14px 16px 60px; }
.lesson-inner .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grp { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; }
#patName { font-size: 30px; margin: 12px 0 0; }
.meta-line { color: var(--muted); font-weight: 700; margin: 2px 0 8px; }
.lesson-inner h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px; }
#notation { display: grid; grid-template-columns: repeat(var(--slots), 1fr); gap: 3px; background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 10px; }
.nslot { display: grid; justify-items: center; gap: 4px; padding: 6px 0; border-radius: 8px; background: var(--soft); }
.nslot.beat { box-shadow: inset 3px 0 0 var(--todo); }
.nslot .ndot { width: 18px; height: 18px; border-radius: 50%; border: 2px dashed var(--todo); }
.nslot.note .ndot { background: var(--accent); border: 2px solid var(--accent); }
.nslot small { font-weight: 800; color: var(--muted); font-size: 12px; }
.nslot.note small { color: var(--fg); }
.count { font-weight: 800; font-size: 18px; margin: 8px 0 4px; }
.tip { background: var(--note); border-radius: 14px; padding: 10px 12px; line-height: 1.45; font-size: 14px; margin: 6px 0 0; }
.lesson-controls { margin: 16px 0 6px; }
.coach { background: #2b231f; color: #fff; border-radius: 16px; padding: 12px 16px; font-weight: 800; font-size: 18px; margin: 12px 0 8px; min-height: 52px; }
.beat-lights { margin: 0 0 8px; }
#timeline { position: relative; height: 76px; background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; margin: 6px 0 12px; overflow: visible; }
#timeline .tick { position: absolute; top: 10px; bottom: 10px; width: 1px; background: var(--line); }
#timeline .tick.bar { width: 2px; background: var(--todo); }
#timeline .exp { position: absolute; top: 30px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; border: 2px solid var(--accent); background: var(--bg); }
#timeline .hit { position: absolute; top: 6px; width: 4px; height: 64px; margin-left: -2px; border-radius: 2px; }
#timeline .hit small { position: absolute; top: -2px; left: 6px; font-size: 11px; font-weight: 800; white-space: nowrap; }
#timeline .hit.on { background: var(--ok); }
#timeline .hit.early, #timeline .hit.late { background: #c46a00; }
#timeline .hit.between { background: #b3261e; }
#timeline .hit.missed { background: repeating-linear-gradient(#b3261e 0 4px, transparent 4px 8px); }
#timeline .playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--focus); }
#timeline .playhead[hidden] { display: none; }
#tapPad { display: block; width: 100%; min-height: 120px; border-radius: 24px; font-size: 30px; font-weight: 900; letter-spacing: .1em; background: var(--soft); border: 2px dashed var(--todo); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#tapPad small { display: block; font-size: 13px; letter-spacing: 0; color: var(--muted); font-weight: 700; }
#tapPad.armed { border-style: solid; border-color: var(--accent); background: #fff; }
#tapPad.flash { animation: tapflash .15s ease-out; }
@keyframes tapflash { from { background: var(--accent-2); } to { background: #fff; } }
.summary { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 12px 14px; margin: 12px 0 0; line-height: 1.5; }
.summary.pass { border-color: #bfe0cd; background: #f1faf4; }
.summary .big { font-weight: 900; font-size: 18px; margin: 0 0 4px; }
.summary p { margin: 4px 0 10px; }
.hit-list { padding-left: 22px; line-height: 1.6; margin: 0; }
.hit-list li.on { color: var(--ok); }
.hit-list li.early, .hit-list li.late { color: #8a4b00; }
.hit-list li.between, .hit-list li.missed { color: #a3221b; }
.nav { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.quizbar { display: flex; justify-content: space-between; font-weight: 800; color: var(--muted); margin-top: 8px; }
#micchip { display: inline-flex; gap: 8px; align-items: center; background: #2b231f; color: #fff; padding: 6px 8px 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; margin-top: 10px; }
#micchip .dot { width: 9px; height: 9px; border-radius: 50%; background: #5fd38d; }
#micchip button { padding: 4px 10px; font-size: 13px; }
#micchip[hidden] { display: none; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }
#celebrate { position: fixed; inset: 0; z-index: 41; display: none; align-items: center; justify-content: center; pointer-events: none; }
#celebrate div { background: rgba(255, 252, 247, 0.97); padding: 18px 28px; border-radius: 28px; font-size: 30px; font-weight: 900; box-shadow: 0 10px 40px rgba(0,0,0,.25); text-align: center; pointer-events: auto; cursor: pointer; }
#celebrate small { display: block; font-size: 15px; color: var(--muted); font-weight: 700; margin-top: 4px; }
#celebrate.show { display: flex; animation: pop .35s ease-out; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
dialog .actions .link { align-self: center; }
@media (max-width: 600px) {
  #home h1 { font-size: 27px; }
  .nslot small { font-size: 10px; }
  .nslot .ndot { width: 12px; height: 12px; }
  #notation { gap: 2px; padding: 6px; }
  .light { width: 32px; height: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- morse tutor ---------- */
.code-chart { background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 10px 14px; font-weight: 800; font-size: 20px; letter-spacing: .06em; margin: 8px 0 0; }
.readout { background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 14px; font-weight: 800; font-size: 18px; margin: 12px 0; min-height: 48px; }
.copy-label { display: block; font-weight: 800; margin: 14px 0 6px; }
#copyInput { width: 100%; font: inherit; font-size: 22px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); color: var(--fg); }
#copyInput:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
