:root {
  --bg: #0f1012;
  --panel: #16171a;
  --panel2: #1c1d21;
  --line: #25262b;
  --text: #e8e5de;
  --dim: #6c6e76;
  --faint: #3b3d44;
  --accent: #f0b450;
  --err: #ef6b73;
  --good: #7fcf9f;
  --cap: #1d1e22;
  --cap-mod: #17181b;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
code { font-family: var(--mono); font-size: .92em; color: var(--text); background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--faint); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }
.dim { color: var(--dim); }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; gap: 28px;
  max-width: 1000px; margin: 0 auto; padding: 22px 24px 10px;
}
.brand { font-family: var(--mono); font-weight: 500; font-size: 17px; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.logo { width: 18px; height: 12px; border: 2px solid var(--accent); border-radius: 3px; position: relative; }
.logo::after { content: ''; position: absolute; left: 3px; right: 3px; bottom: 2px; height: 2px; background: var(--accent); border-radius: 1px; }
nav { display: flex; gap: 2px; }
nav button {
  background: none; border: 0; padding: 6px 12px; border-radius: 6px; color: var(--dim);
  transition: color .15s, background .15s;
}
nav button:hover { color: var(--text); }
nav button.active { color: var(--text); background: var(--panel2); }
.save { margin-left: auto; font-size: 12px; color: var(--dim); }
.back {
  color: var(--dim); text-decoration: none; font-size: 13px; padding: 6px 12px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel2); white-space: nowrap; transition: color .15s, border-color .15s;
}
.back:hover { color: var(--text); border-color: var(--faint); }
.foot { text-align: center; color: var(--faint); font-size: 12px; padding: 0 24px 28px; }
.foot a { color: inherit; text-decoration: none; }
.foot a:hover { color: var(--dim); }

main { max-width: 1000px; margin: 0 auto; padding: 8px 24px 60px; }
.view { display: none; }
.view.active { display: block; }

/* ---------- letters strip ---------- */
.letters { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin: 18px 0 8px; }
.lt {
  width: 26px; padding: 4px 0 5px; text-align: center; font-family: var(--mono); font-size: 14px;
  border-radius: 5px; background: var(--panel); position: relative; color: var(--text);
  border: 1px solid transparent;
}
.lt i { position: absolute; left: 4px; right: 4px; bottom: 3px; height: 2px; border-radius: 1px; background: var(--faint); overflow: hidden; }
.lt i b { display: block; height: 100%; background: var(--c, var(--accent)); }
.lt.locked { color: var(--faint); background: transparent; }
.lt.locked i { display: none; }
.lt.focus { border-color: var(--accent); }
.lt.new { animation: pop .6s ease; }
@keyframes pop { 0% { transform: scale(1.5); background: var(--accent); color: var(--bg); } 100% { transform: scale(1); } }

/* ---------- story bar ---------- */
.storybar { display: flex; align-items: center; gap: 14px; margin: 18px 0 8px; }
.storytitle { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.storyprog { flex: 1; height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; min-width: 60px; }
.storyprog div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }

/* ---------- live metrics ---------- */
.live { display: flex; gap: 28px; align-items: baseline; margin: 26px 4px 10px; font-family: var(--mono); }
.live b { font-size: 22px; font-weight: 500; color: var(--accent); }
.live span { color: var(--dim); margin-left: 6px; font-size: 12px; }
.live b { transition: opacity .2s; }
.live.prev b { opacity: .55; }
.live .last { margin-left: auto; font-size: 12px; color: var(--dim); }
.live .last em { font-style: normal; color: var(--text); }
.live .last .up { color: var(--good); }

/* ---------- text ---------- */
.textbox {
  background: var(--panel); border-radius: 12px; padding: 26px 30px; min-height: 150px;
  display: flex; align-items: center; position: relative; overflow: hidden;
}
.textbox .text { transition: filter .2s, opacity .2s; }
.textbox.is-paused .text { filter: blur(5px); opacity: .35; }
.paused {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--dim); font-size: 13px; cursor: pointer; animation: fadein .15s ease;
}
.paused kbd { color: var(--text); }
.play {
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--bg);
  display: grid; place-items: center; box-shadow: 0 6px 24px rgba(240, 180, 80, .25); transition: transform .12s;
}
.play svg { width: 26px; height: 26px; fill: currentColor; margin-left: 3px; }
.paused:hover .play { transform: scale(1.06); }
@keyframes fadein { from { opacity: 0; } }
.pausebtn {
  align-self: center; width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--dim); display: grid; place-items: center; padding: 0;
}
.pausebtn:hover { color: var(--text); border-color: var(--faint); }
.pausebtn svg { width: 12px; height: 12px; fill: currentColor; }
.text {
  font-family: var(--mono); font-size: 25px; line-height: 1.75; white-space: pre-wrap; word-break: normal;
  color: var(--dim); width: 100%;
}
.text span { border-radius: 3px; transition: color .08s; }
.text .ok { color: var(--text); }
.text .fixed { color: var(--accent); }
.text .bad { color: var(--err); background: rgba(239, 107, 115, .12); }
.text .cur { box-shadow: inset 0 -2px 0 var(--accent); }
.text .cur.err { background: rgba(239, 107, 115, .25); box-shadow: inset 0 -2px 0 var(--err); }
.text.flash .cur { animation: shake .18s; }
@keyframes shake { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
.text .done-msg { color: var(--good); }
.hint { text-align: center; color: var(--faint); font-size: 12px; margin: 10px 0 0; }
.hint kbd { color: var(--dim); }

/* ---------- keyboard ---------- */
.kbwrap { margin: 30px auto 0; max-width: 900px; padding: 14px; background: #121316; border-radius: 14px; border: 1px solid var(--line); }
.kb { position: relative; width: 100%; aspect-ratio: var(--ratio); container-type: inline-size; }
.key { position: absolute; }
.cap {
  position: absolute; inset: 2.5px; border-radius: 5px;
  background: var(--cap); box-shadow: inset 0 -2px 0 rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.03);
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  font-family: var(--mono); font-size: 1.55cqw; color: #a9a7a1; line-height: 1.05;
  transition: background .12s, transform .06s, box-shadow .12s, color .12s;
  overflow: hidden;
}
.key.mod .cap { background: var(--cap-mod); color: var(--dim); font-size: 1.15cqw; }
.key.num .cap { background: var(--cap-mod); color: var(--faint); }
.key.iso .cap { clip-path: polygon(0 0, 100% 0, 100% 100%, 17% 100%, 17% 50%, 0 50%); align-items: flex-end; padding-right: 14%; justify-content: flex-start; padding-top: 6%; }
.cap .main { font-size: 1.1em; }
.cap .ks, .cap .kb2 { font-size: .82em; line-height: 1.15; }
.cap .ks { color: var(--dim); }
.cap .alt { position: absolute; right: 12%; bottom: 8%; font-size: .7em; color: var(--faint); }
.cap .bump { position: absolute; bottom: 14%; width: 22%; height: 2px; border-radius: 1px; background: currentColor; opacity: .55; }
.cap .heat { position: absolute; inset: 0; background: var(--h, transparent); pointer-events: none; mix-blend-mode: normal; z-index: 0; }
.cap > span:not(.alt) { position: relative; z-index: 1; }
.cap > .alt, .cap > .bump { z-index: 1; }

/* finger tints */
.fingers .key[data-finger] .cap { background: color-mix(in srgb, var(--f) 13%, var(--cap)); }
.key[data-finger=lp], .key[data-finger=rp] { --f: #c678dd; }
.key[data-finger=lr], .key[data-finger=rr] { --f: #61afef; }
.key[data-finger=lm], .key[data-finger=rm] { --f: #56c2a6; }
.key[data-finger=li] { --f: #e5c07b; }
.key[data-finger=ri] { --f: #e09c6b; }
.key[data-finger=th] { --f: #8a8d96; }

.key.next .cap { background: color-mix(in srgb, var(--accent) 22%, var(--cap)) !important; color: var(--text); box-shadow: 0 0 0 1.5px var(--accent), 0 0 14px rgba(240,180,80,.25); }
.key.down .cap { transform: translateY(1px); background: #2b2c31 !important; color: var(--text); box-shadow: inset 0 1px 0 rgba(0,0,0,.4); }
.key.miss .cap { background: color-mix(in srgb, var(--err) 40%, var(--cap)) !important; }

/* stats keyboard: no finger tints, heat instead */
#kbStats .cap { color: #c9c6bf; }
#kbStats .key.mod .cap, #kbStats .key.num .cap { opacity: .4; }

/* ---------- generic panels ---------- */
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin: 22px 0 18px; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.01em; }
.head p { margin: 0; }
.panel { background: var(--panel); border-radius: 12px; padding: 18px 20px; margin-bottom: 14px; }
.ptitle { font-weight: 500; margin-bottom: 14px; display: flex; align-items: center; gap: 10px; }
.ptitle .dim { font-weight: 400; font-size: 12px; }
button.ghost { background: var(--panel2); border: 1px solid var(--line); padding: 7px 14px; border-radius: 7px; color: var(--text); }
button.ghost:hover { border-color: var(--faint); }
button.ghost.red { color: var(--err); }

/* stories */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid transparent; border-radius: 12px; padding: 16px 18px; text-align: left;
  display: flex; flex-direction: column; gap: 8px; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--faint); transform: translateY(-1px); }
.card h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card p { margin: 0; color: var(--dim); font-size: 13px; line-height: 1.45; flex: 1; }
.card .meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--dim); font-family: var(--mono); }
.card .bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.card .bar div { height: 100%; background: var(--accent); }
.empty { color: var(--dim); padding: 40px; text-align: center; background: var(--panel); border-radius: 12px; }

/* stats */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--panel); border-radius: 12px; padding: 14px 18px; }
.tile b { display: block; font-family: var(--mono); font-size: 24px; font-weight: 500; }
.tile span { color: var(--dim); font-size: 12px; }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart svg { width: 100%; height: 150px; display: block; overflow: visible; }
.chart .grid line { stroke: var(--line); }
.chart .grid text { fill: var(--dim); font: 10px var(--mono); }
.chart .area { opacity: .12; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .target { stroke: var(--faint); stroke-dasharray: 4 4; }
.chart .nodata { fill: var(--dim); font: 12px var(--ui); }
.seg { margin-left: auto; display: flex; background: var(--panel2); border-radius: 7px; padding: 2px; }
.seg button { background: none; border: 0; padding: 4px 10px; border-radius: 5px; color: var(--dim); font-size: 12px; }
.seg button.active { background: var(--line); color: var(--text); }
.legend { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 12px; font-size: 12px; color: var(--dim); }
.legend .grad { width: 160px; height: 6px; border-radius: 3px; }
.lettergrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
.lg { background: var(--panel2); border-radius: 8px; padding: 8px 10px; font-family: var(--mono); }
.lg b { font-size: 18px; font-weight: 500; }
.lg div { font-size: 11px; color: var(--dim); }
.lg.locked { opacity: .35; }

/* settings */
.form label { display: flex; justify-content: space-between; align-items: center; gap: 30px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.form label:last-child { border-bottom: 0; }
.form small { display: block; color: var(--dim); font-size: 12px; margin-top: 2px; max-width: 520px; }
.form input[type=number] { width: 72px; background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 6px 8px; font: 14px var(--mono); }
.form input[type=checkbox] { appearance: none; width: 36px; height: 20px; border-radius: 10px; background: var(--faint); position: relative; cursor: pointer; transition: background .15s; flex-shrink: 0; }
.form input[type=checkbox]::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.form input[type=checkbox]:checked { background: var(--accent); }
.form input[type=checkbox]:checked::after { transform: translateX(16px); background: var(--bg); }
.inline { display: flex; align-items: center; gap: 8px; color: var(--dim); }

@media (max-width: 720px) {
  .top { flex-wrap: wrap; gap: 12px; padding: 16px; }
  main { padding: 8px 16px 40px; }
  .text { font-size: 19px; }
  .textbox { padding: 18px; }
  .charts { grid-template-columns: 1fr; }
  .live { gap: 16px; flex-wrap: wrap; }
}
