:root, [data-theme="midnight"] {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a; --text: #e8eaf0; --muted: #8b93a7; --faint: #5b6273;
  --accent: #5aa9ff; --accent-soft: rgba(90,169,255,.14); --ok: #e8eaf0; --untyped: #5b6273; --bad: #ff5f6d; --bad-soft: rgba(255,95,109,.15);
  --good: #3ecf8e; --warn: #f0b429; --caret: #5aa9ff;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #2e9e2e; --s7: #9085e9; --s8: #e66767;
  --c0: #1f232c; --c1: #184f95; --c2: #256abf; --c3: #3987e5; --c4: #86b6ef;
  color-scheme: dark;
}
[data-theme="paper"] {
  --bg: #f6f5f1; --panel: #ffffff; --panel2: #f0efea; --line: #e2e0d8; --text: #1d1d1b; --muted: #6b6a64; --faint: #a7a59c;
  --accent: #2a78d6; --accent-soft: rgba(42,120,214,.1); --ok: #1d1d1b; --untyped: #a7a59c; --bad: #d23a3a; --bad-soft: rgba(210,58,58,.1);
  --good: #13885b; --warn: #b07800; --caret: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --c0: #ebe9e2; --c1: #cde2fb; --c2: #86b6ef; --c3: #3987e5; --c4: #1c5cab;
  color-scheme: light;
}
[data-theme="nord"] { --bg: #2e3440; --panel: #353c4a; --panel2: #3b4252; --line: #434c5e; --text: #eceff4; --muted: #a3acbf; --faint: #6b7489; --accent: #88c0d0; --accent-soft: rgba(136,192,208,.15); --ok: #eceff4; --untyped: #6b7489; --caret: #88c0d0; --bad: #bf616a; --good: #a3be8c; --c0: #3b4252; }
[data-theme="serika"] { --bg: #323437; --panel: #2c2e31; --panel2: #3a3c40; --line: #46484c; --text: #d1d0c5; --muted: #8f9094; --faint: #646669; --accent: #e2b714; --accent-soft: rgba(226,183,20,.14); --ok: #d1d0c5; --untyped: #646669; --caret: #e2b714; --bad: #ca4754; --c0: #2c2e31; }
[data-theme="grape"] { --bg: #1b1526; --panel: #241c33; --panel2: #2d2340; --line: #3a2e52; --text: #efe7ff; --muted: #a596c2; --faint: #6c5d8a; --accent: #c792ea; --accent-soft: rgba(199,146,234,.15); --ok: #efe7ff; --untyped: #6c5d8a; --caret: #c792ea; --bad: #ff6b8b; --c0: #2d2340; }
[data-theme="forest"] { --bg: #101a14; --panel: #15231b; --panel2: #1b2c22; --line: #263b2e; --text: #e3f0e6; --muted: #8fae99; --faint: #557060; --accent: #5fd38d; --accent-soft: rgba(95,211,141,.14); --ok: #e3f0e6; --untyped: #557060; --caret: #5fd38d; --bad: #ff7a6b; --c0: #1b2c22; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Inter, sans-serif; display: flex; overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #0b0d12; border-color: var(--accent); font-weight: 600; }
button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
select, input[type=text], input[type=number], textarea { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
textarea { width: 100%; min-height: 120px; resize: vertical; }
a { color: var(--accent); }
kbd { font: 12px ui-monospace, monospace; background: var(--panel2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; }
h1, h2, h3 { margin: 0 0 10px; font-weight: 650; }
h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); fill: var(--muted); }
.small { font-size: 13px; }

/* nav */
nav { width: 210px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 10px; gap: 2px; }
.brand { font-weight: 800; font-size: 20px; padding: 4px 10px 14px; letter-spacing: -.02em; }
.brand span { color: var(--accent); }
nav button { background: none; border: none; text-align: left; padding: 9px 12px; border-radius: 8px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
nav button:hover { color: var(--text); background: var(--panel2); }
nav button.active { color: var(--text); background: var(--accent-soft); }
nav button svg { width: 18px; height: 18px; flex: none; }
.navfoot { margin-top: auto; padding: 10px; font-size: 13px; color: var(--muted); }
.goal { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.goal svg { width: 40px; height: 40px; }
.camdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); margin-right: 6px; }
.camdot.on { background: var(--good); box-shadow: 0 0 8px var(--good); }

main { flex: 1; overflow-y: auto; padding: 22px 28px 40px; }
.page { display: none; max-width: 1180px; margin: 0 auto; }
.page.active { display: block; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1000px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* practice header */
.modebar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.modebtn { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.opts { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.opts .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.chip { padding: 4px 11px; border-radius: 99px; font-size: 13px; }
.note { color: var(--muted); font-size: 13px; margin: 4px 0 0; min-height: 20px; }

.livebar { display: flex; gap: 22px; align-items: baseline; font-variant-numeric: tabular-nums; margin: 6px 0 8px; min-height: 34px; }
.livebar .big { font-size: 26px; font-weight: 700; color: var(--accent); }
.livebar span { color: var(--muted); }
.livebar b { color: var(--text); }

.typebox-wrap { position: relative; }
.typebox { position: relative; font-family: var(--tfont, ui-monospace, "JetBrains Mono", "Fira Code", monospace); font-size: var(--tsize, 28px); line-height: 1.6; height: calc(var(--tsize, 28px) * 1.6 * 3); overflow: hidden; color: var(--untyped); outline: none; word-break: normal; padding: 0 2px; }
.typebox.code { height: calc(var(--tsize, 28px) * 1.6 * 6); white-space: pre; }
.typebox .word { white-space: pre; display: inline-block; }
.typebox.code .word { white-space: pre; display: inline; }
.typebox .ch { position: relative; transition: color .05s; }
.typebox .ch.ok { color: var(--ok); }
.typebox .ch.bad { color: var(--bad); background: var(--bad-soft); border-radius: 3px; }
.typebox .ch.sp.bad { background: var(--bad-soft); }
.typebox .ch.nl { opacity: .45; font-size: .7em; }
.typebox .ch.auto { color: var(--faint); }
.typebox.blind .ch.bad { color: var(--ok); background: none; }
.typebox .ch.shake { animation: shake .18s; color: var(--bad); }
@keyframes shake { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
.caret { position: absolute; left: 0; top: 0; width: 2.5px; background: var(--caret); border-radius: 2px; transition: transform .08s linear; pointer-events: none; animation: blink 1s step-end infinite; }
.typing .caret { animation: none; }
.caret.underline { height: 3px !important; margin-top: calc(var(--tsize, 28px) * 1.35); width: .6em; }
.caret.block { opacity: .35; }
@keyframes blink { 50% { opacity: 0; } }
.focus-hint { position: absolute; inset: 0; display: none; place-items: center; backdrop-filter: blur(4px); color: var(--text); cursor: pointer; font-size: 16px; z-index: 2; }
.unfocused .focus-hint { display: grid; }
.source { color: var(--muted); font-style: italic; margin-top: 4px; min-height: 22px; }
.actions { display: flex; gap: 8px; justify-content: center; margin: 14px 0 6px; }
.hint { text-align: center; color: var(--faint); font-size: 12.5px; }

.nudge { position: absolute; right: 0; top: -44px; background: var(--warn); color: #111; font-weight: 700; padding: 6px 12px; border-radius: 99px; display: none; }
.nudge.show { display: block; animation: pop .2s; }
@keyframes pop { from { transform: scale(.8); } }

.practice-grid { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start; }
.mini-cam { width: 240px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #000; position: relative; }
.mini-cam canvas { width: 100%; display: block; transform: var(--mirror, none); }
.mini-cam .lbl { position: absolute; left: 8px; bottom: 6px; font-size: 12px; color: #fff; text-shadow: 0 1px 3px #000; }
.mini-cam.rec { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }

/* virtual keyboard */
.kbd { display: flex; flex-direction: column; gap: 5px; align-items: center; margin-top: 14px; user-select: none; }
.kbd .krow { display: flex; gap: 5px; }
.kbd .key { width: 44px; height: 42px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; font: 14px ui-monospace, monospace; color: var(--muted); position: relative; transition: background .08s; }
.kbd .key.wide { width: 70px; } .kbd .key.space { width: 290px; } .kbd .key.wider { width: 92px; }
.kbd .key.home::after { content: ""; position: absolute; bottom: 5px; width: 10px; height: 2px; border-radius: 1px; background: var(--faint); }
.kbd .key[data-f] { border-bottom: 3px solid var(--fc); }
.kbd.nofingers .key[data-f] { border-bottom: 1px solid var(--line); }
.kbd .key.next { background: var(--fc, var(--accent)); color: #0b0d12; font-weight: 700; }
.kbd .key.down { background: var(--accent); color: #0b0d12; }
.kbd .key.was { background: var(--accent-soft); color: var(--text); }
.kbd .key .cnt { position: absolute; bottom: 1px; right: 4px; font-size: 10px; }
.finger-hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 8px; min-height: 20px; }
.finger-hint b { color: var(--fc, var(--text)); }
[data-f="LP"], [data-f="RP"] { --fc: var(--s5); } [data-f="LR"], [data-f="RR"] { --fc: var(--s4); }
[data-f="LM"], [data-f="RM"] { --fc: var(--s3); } [data-f="LI"], [data-f="RI"] { --fc: var(--s1); }
[data-f="LT"], [data-f="RT"] { --fc: var(--s7); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; place-items: center; z-index: 50; }
.modal.open { display: grid; }
.modal .box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(1000px, 94vw); max-height: 88vh; overflow-y: auto; }
.modegroup { margin-bottom: 16px; }
.modegroup h3 { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.modegrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.modecard { text-align: left; padding: 11px 13px; background: var(--panel2); }
.modecard b { display: block; }
.modecard span { font-size: 12.5px; color: var(--muted); }
.badge { font-size: 10px; background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 1px 7px; margin-left: 6px; vertical-align: 2px; }

/* results */
.results { display: none; }
.results.show { display: block; }
.res-top { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: center; }
.res-main .big { font-size: 64px; font-weight: 800; line-height: 1; color: var(--accent); }
.res-main .lab { color: var(--muted); }
.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--panel2); border-radius: 10px; padding: 10px 12px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); }
.tips { display: flex; flex-direction: column; gap: 8px; }
.tip { border: 1px solid var(--line); border-left: 4px solid var(--faint); border-radius: 10px; padding: 10px 14px; background: var(--panel2); }
.tip.bad { border-left-color: var(--bad); } .tip.good { border-left-color: var(--good); } .tip.info { border-left-color: var(--accent); }
.tip h4 { margin: 0 0 3px; font-size: 14.5px; display: flex; gap: 8px; align-items: center; }
.tip p { margin: 0; color: var(--muted); font-size: 13.5px; }
.tip .tag { font-size: 10px; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.tip button { margin-top: 8px; font-size: 12.5px; padding: 4px 10px; }
.seqs { display: flex; gap: 6px; flex-wrap: wrap; }
.seq { font-family: ui-monospace, monospace; background: var(--bad-soft); color: var(--bad); border: 1px solid transparent; }
.seq:hover { border-color: var(--bad); }
.wordlist { display: flex; gap: 6px; flex-wrap: wrap; font-family: ui-monospace, monospace; font-size: 13px; }
.wordlist span { background: var(--panel2); border-radius: 6px; padding: 2px 8px; }

/* charts */
.chart { display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--panel); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .mark { stroke: var(--bad); stroke-width: 1; opacity: .5; }
.chart .dlabel { fill: var(--text); font-size: 12px; }
.chart .bar { stroke: var(--panel); stroke-width: 2; }
.chart .bar.hover { filter: brightness(1.2); }
.ln.s1 { stroke: var(--s1); } .dot.s1, .bar.s1, .sw.s1 { fill: var(--s1); background: var(--s1); }
.ln.s2 { stroke: var(--s2); } .dot.s2, .bar.s2, .sw.s2 { fill: var(--s2); background: var(--s2); }
.ln.s3 { stroke: var(--s3); } .dot.s3, .bar.s3, .sw.s3 { fill: var(--s3); background: var(--s3); }
.ln.s4 { stroke: var(--s4); } .dot.s4, .bar.s4, .sw.s4 { fill: var(--s4); background: var(--s4); }
.ln.s5 { stroke: var(--s5); } .dot.s5, .bar.s5, .sw.s5 { fill: var(--s5); background: var(--s5); }
.ln.s7 { stroke: var(--s7); } .dot.s7, .bar.s7, .sw.s7 { fill: var(--s7); background: var(--s7); }
.bar.bad { fill: var(--bad); }
.cal rect.c0 { fill: var(--c0); } .cal rect.c1 { fill: var(--c1); } .cal rect.c2 { fill: var(--c2); } .cal rect.c3 { fill: var(--c3); } .cal rect.c4 { fill: var(--c4); }
.cal rect:hover { stroke: var(--text); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart-tip { position: fixed; pointer-events: none; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; opacity: 0; transition: opacity .1s; z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.chart-tip .tt { color: var(--muted); margin-bottom: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 6px 8px; }
td { border-bottom: 1px solid var(--line); padding: 6px 8px; }
tr:hover td { background: var(--panel2); }

.heat .key { color: var(--text); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }

/* camera page */
.campage { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .campage { grid-template-columns: 1fr; } }
.bigcam { background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 16/9; display: grid; place-items: center; color: #888; }
.bigcam canvas { width: 100%; display: block; transform: var(--mirror, none); }
.camstatus { font-size: 13.5px; color: var(--muted); margin: 10px 0; }
.camstatus.err { color: var(--bad); }
.readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.calib-count { font-size: 48px; font-weight: 800; color: var(--accent); text-align: center; }

/* settings */
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setrow:last-child { border: none; }
.setrow .d { color: var(--muted); font-size: 13px; }

/* tools */
.toolbox { min-height: 300px; }
.bigread { font-size: 46px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.pad { border: 2px dashed var(--line); border-radius: 12px; height: 220px; display: grid; place-items: center; color: var(--muted); }

/* replay */
.replay-text { font-family: ui-monospace, monospace; font-size: 20px; line-height: 1.6; white-space: pre-wrap; color: var(--untyped); min-height: 120px; }
.replay-text .ok { color: var(--ok); } .replay-text .bad { color: var(--bad); background: var(--bad-soft); }
.replay-text .cur { box-shadow: -2px 0 0 var(--caret); }
.timeline { height: 60px; display: flex; align-items: flex-end; gap: 1px; margin: 12px 0; cursor: pointer; }
.timeline i { flex: 1; background: var(--s1); min-width: 1px; border-radius: 1px 1px 0 0; }
.timeline i.slow { background: var(--warn); } .timeline i.err { background: var(--bad); } .timeline i.past { opacity: .4; }
.practice-grid > div { min-width: 0; }

/* accounts */
.navuser { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.navuser button { padding: 3px 9px; font-size: 12px; }
#authScreen { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 200; padding: 16px; }
#authScreen[hidden] { display: none; }
.authbox { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px; display: flex; flex-direction: column; gap: 12px; }
.authbox label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.authbox input { font-size: 15px; color: var(--text); }
.autherr { color: var(--bad); font-size: 13px; margin: 0; min-height: 18px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 16px; opacity: 0; transition: .2s; z-index: 300; pointer-events: none; font-size: 14px; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { border-color: var(--bad); }
input[type=password] { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }

/* intro video + tour */
.introbox { width: min(900px, 94vw); }
.introvid { position: relative; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 16/9; }
.introvid video { width: 100%; height: 100%; display: block; }
.introplay { position: absolute; inset: 0; margin: auto; width: 84px; height: 84px; border-radius: 50%; font-size: 30px; background: var(--accent); color: #0b0d12; border: none; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.introplay:hover { transform: scale(1.06); }
.introplay[hidden] { display: none; }
#tour { position: fixed; inset: 0; z-index: 150; }
#tour[hidden] { display: none; }
#tourSpot { position: fixed; border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.72); border: 2px solid var(--accent); transition: all .25s ease; pointer-events: none; }
#tourCard { position: fixed; width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; box-shadow: 0 12px 40px rgba(0,0,0,.45); transition: left .25s ease, top .25s ease; }
#tourCard p { color: var(--muted); font-size: 14px; margin: 8px 0 12px; }
#tourTitle { font-size: 16px; }
