:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1d2330; --muted: #6b7385; --line: #e2e5ec;
  --precision-gray: #e5e7eb; --accent: #2f6fdb; --ok: #1f9d55; --bad: #d64545; --pending: #a3aab8; --locked: #e9ecf2; --locked-text: #b5bcc9;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --precision-gray: #374151; --bg: #12151b; --surface: #1a1f28; --text: #e6e9ef; --muted: #8d95a7; --line: #2a313d;
    --accent: #6c9cf0; --ok: #43c47a; --bad: #f06a6a; --pending: #5b6475; --locked: #222833; --locked-text: #4a5262;
  }
}
:root[data-theme="dark"] {
  --precision-gray: #374151; --bg: #12151b; --surface: #1a1f28; --text: #e6e9ef; --muted: #8d95a7; --line: #2a313d;
  --accent: #6c9cf0; --ok: #43c47a; --bad: #f06a6a; --pending: #5b6475; --locked: #222833; --locked-text: #4a5262;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
main { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 16px; flex: 1; }
.top { width: 100%; max-width: 960px; margin: 0 auto; padding: 18px 16px; display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 700; font-size: 22px; letter-spacing: -0.02em; }
.brand .dot { color: var(--accent); }
.who { display: flex; gap: 10px; align-items: baseline; color: var(--muted); font-size: 14px; }
.who b { color: var(--text); }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; background: var(--accent); color: #fff; padding: 10px 18px; font-weight: 600; }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 500; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.login { max-width: 480px; margin: 8vh auto 0; }
.login h1 { margin: 0 0 8px; font-size: 24px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.login label { display: block; font-weight: 600; margin-bottom: 6px; }
.login .row { display: flex; gap: 8px; }
.login input { flex: 1; min-width: 0; font: inherit; font-size: 20px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-family: var(--mono); }
.login small { display: block; margin-top: 10px; color: var(--muted); }

.letters { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin: 8px 0 18px; }
.letter {
  width: 30px; height: 36px; padding: 0; border-radius: 7px; display: grid; place-items: center;
  font: 600 16px var(--mono); background: var(--locked); color: var(--locked-text); position: relative;
}
.letter.unseen { color: var(--text); background: var(--precision-gray); border: 1px dashed var(--pending); }
.letter.practice { color: #1d2330; background: #facc15; }
.letter.ready { color: #1d2330; background: #86efac; }
.letter.strong { color: #fff; background: #15803d; }
.letter.focus { background: #7c3aed !important; color: #fff; border-color: #7c3aed; outline: 2.5px solid #a78bfa; outline-offset: 2px; }
.letter .bar { position: absolute; left: 3px; right: 3px; bottom: 3px; height: 3px; border-radius: 2px; background: color-mix(in srgb, currentColor 20%, transparent); overflow: hidden; }
.letter .bar i { display: block; height: 100%; background: currentColor; }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.metrics > div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; }
.metrics .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.metrics .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metrics .v.focus { font-family: var(--mono); color: var(--accent); }
.metrics .d { font-size: 13px; color: var(--muted); min-height: 1.2em; font-variant-numeric: tabular-nums; }
.metrics .d.up { color: var(--ok); } .metrics .d.down { color: var(--bad); }

.board {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 24px; min-height: 150px; cursor: text; outline: none;
}
.board.active { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.text { font: 28px/1.7 var(--mono); letter-spacing: .01em; word-break: break-word; user-select: none; }
.text .word { display: inline-block; white-space: pre; }
.text .char.space { position: relative; }
.text .char { color: var(--pending); border-radius: 3px; }
.text .char.done { color: var(--text); }
.text .char.err { color: var(--bad); }
.text .char.done.err { color: var(--bad); text-decoration: underline; text-decoration-thickness: 2px; }
.text .char.cur { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--text); box-shadow: inset 0 -3px 0 var(--accent); }
.text .char.cur.err { background: color-mix(in srgb, var(--bad) 25%, transparent); box-shadow: inset 0 -3px 0 var(--bad); }
.text .char.space.cur::after { content: "␣"; color: var(--text); position: absolute; inset: 0; display: grid; place-items: center; line-height: 1; opacity: .8; }
.hint { position: absolute; inset: auto 0 10px 0; text-align: center; color: var(--muted); font-size: 13px; }
.board.active .hint { visibility: hidden; }
#sink { position: absolute; opacity: 0; left: 0; top: 0; width: 1px; height: 1px; border: 0; padding: 0; resize: none; }

/* A single action, positioned outside layout flow so the exercise never shifts. */
.key-menu { position: fixed; z-index: 50; max-width: calc(100vw - 16px); padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.16); }
.key-menu button { display: block; width: 100%; padding: 8px 12px; text-align: left; white-space: nowrap; background: transparent; color: var(--text); font-size: 14px; font-weight: 500; }
.key-menu button:hover, .key-menu button:focus-visible { background: var(--locked); outline: none; }

.chart-card { margin: 16px 0 24px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head h2 { margin: 0; font-size: 17px; }
.target { font-size: 14px; color: var(--muted); }
.target input { width: 5em; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
#chart { width: 100%; display: block; }
.muted { color: var(--muted); } .small { font-size: 13px; margin: 6px 0 0; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }
footer a { color: inherit; }

@media (max-width: 640px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .text { font-size: 21px; }
  .board { padding: 20px 14px 30px; }
  .letter { width: 25px; height: 32px; font-size: 14px; }
}

/* ---------- tools + finger keyboard ---------- */
:root { --f-lp: #e98bbf; --f-lr: #7fb0ee; --f-lm: #7ccf98; --f-li: #f5b45a; --f-ri: #f2d758; --f-rm: #7ccf98; --f-rr: #7fb0ee; --f-rp: #e98bbf; --f-th: #c3bfd2; --key-text: #1d2330; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --f-lp: #c86f9f; --f-lr: #5f8fcc; --f-lm: #5aae78; --f-li: #d4943d; --f-ri: #cdb43f; --f-rm: #5aae78; --f-rr: #5f8fcc; --f-rp: #c86f9f; --f-th: #8f8aa3; --key-text: #12151b; }
}
:root[data-theme="dark"] { --f-lp: #c86f9f; --f-lr: #5f8fcc; --f-lm: #5aae78; --f-li: #d4943d; --f-ri: #cdb43f; --f-rm: #5aae78; --f-rr: #5f8fcc; --f-rp: #c86f9f; --f-th: #8f8aa3; --key-text: #12151b; }
.tools { display: flex; justify-content: flex-end; margin-bottom: 8px; }
button.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--line); padding: 6px 12px; font-weight: 500; font-size: 14px; }
button.ghost.on { border-color: var(--accent); color: var(--accent); }
.kb-panel { margin-top: 16px; }
.kb { --u: min(46px, calc((100vw - 80px) / 15.3)); display: flex; flex-direction: column; gap: calc(var(--u) * .08); align-items: center; }
.kb-row { display: flex; gap: calc(var(--u) * .08); }
.key {
  width: var(--u); height: var(--u); border-radius: calc(var(--u) * .16); display: grid; place-items: center;
  font: 600 calc(var(--u) * .36) var(--mono); color: var(--key-text); position: relative;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.15); transition: transform .08s, opacity .15s;
}
.key.w125 { width: calc(var(--u) * 1.25); } .key.w15 { width: calc(var(--u) * 1.5); } .key.w175 { width: calc(var(--u) * 1.75); }
.key.w2 { width: calc(var(--u) * 2); } .key.w275 { width: calc(var(--u) * 2.75); }
.key.space { width: calc(var(--u) * 6.5); font: 500 calc(var(--u) * .28) system-ui, sans-serif; }
.key.home::after { content: ""; position: absolute; bottom: 18%; width: 28%; height: 2px; border-radius: 1px; background: var(--key-text); opacity: .6; }
.f-lp { background: var(--f-lp); } .f-lr { background: var(--f-lr); } .f-lm { background: var(--f-lm); } .f-li { background: var(--f-li); }
.f-ri { background: var(--f-ri); } .f-rm { background: var(--f-rm); } .f-rr { background: var(--f-rr); } .f-rp { background: var(--f-rp); } .f-th { background: var(--f-th); }
.key.locked { opacity: .35; }
.key.focus { outline: 2px dashed var(--text); outline-offset: 1px; }
.key.next { outline: 3px solid var(--text); outline-offset: 2px; transform: translateY(-2px); opacity: 1; z-index: 1; }
.kb-hands { display: flex; justify-content: center; align-items: flex-end; gap: clamp(16px, 5vw, 44px); margin-top: 16px; }
.kb-hands figure { margin: 0; text-align: center; }
.kb-hands svg { display: block; width: clamp(104px, 20vw, 136px); height: auto; overflow: visible; }
.hand-palm { fill: var(--locked); stroke: var(--line); stroke-width: 2; stroke-linejoin: round; }
.hand-finger { stroke: var(--surface); stroke-width: 2; stroke-linejoin: round; }
.kb-hands figcaption { margin-top: 3px; color: var(--muted); font-size: 12px; }


/* ---------- v3: modes, dictionaries, layouts ---------- */
.top { gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--locked); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.small-seg button { padding: 4px 10px; font-size: 13px; }
.tools { gap: 8px; flex-wrap: wrap; }
#dictBtn { display: inline-flex; align-items: center; gap: 9px; }
#dictBtn::before { content: ""; width: 12px; height: 12px; flex: 0 0 12px; background: currentColor; clip-path: polygon(0 0, 100% 50%, 0 100%); }
#dictBtn[aria-expanded="true"]::before { transform: rotate(180deg); }
.dict-wrap { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; min-width: 0; }
.dict-panel { display: flex; flex-direction: column; min-width: 0; }
.dict-choices { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.dict-choices label { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background: var(--surface); cursor: pointer; }
.dict-choices label.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.dict-choices input { margin: 0; width: 16px; height: 16px; accent-color: var(--accent); }
button:disabled, input:disabled { cursor: wait; opacity: .6; }
button:focus-visible, .dict-choices label:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
body.free .letters, body.free .card-focus { display: none; }
body.free .metrics { grid-template-columns: repeat(3, 1fr); }
.kb-head { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-bottom: 12px; }
.key .main { line-height: 1; }
.key .sh { position: absolute; top: 8%; left: 12%; font-size: calc(var(--u) * .22); opacity: .75; }
.key .ag { position: absolute; bottom: 8%; right: 12%; font-size: calc(var(--u) * .22); opacity: .75; }
.key.mod .main { font: 500 calc(var(--u) * .24) system-ui, sans-serif; }
.key.w225 { width: calc(var(--u) * 2.25); }
@media (max-width: 640px) {
  .top { justify-content: space-between; }
  .modes { order: 3; width: 100%; } .modes button { flex: 1; }
  body.free .metrics { grid-template-columns: repeat(2, 1fr); }
  .dict-wrap { display: contents; }
  .dict-panel { flex: 1 1 100%; }
  .dict-choices { justify-content: flex-start; }
}
