:root {
  --bg: #0b0f14;
  --bg-soft: #111823;
  --panel: #131b26;
  --panel-2: #0f1620;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.3);
  --text: #e6edf5;
  --muted: #8b9bb0;
  --faint: #61708a;
  --accent: #2dd4bf;
  --accent-soft: rgba(45, 212, 191, 0.14);
  --blue: #38bdf8;
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, 0.16);
  --good: #7ee2c4;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 12% -12%, rgba(45, 212, 191, 0.1), transparent 62%),
    radial-gradient(900px 520px at 96% 0%, rgba(56, 189, 248, 0.08), transparent 58%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1220px;
  margin: 0 auto;
  padding: 26px 22px 40px;
}

/* ---------------- topbar ---------------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-end;
  justify-content: space-between;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; gap: 12px; align-items: center; }

.logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 22px;
  color: var(--accent);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--panel);
}

.brand h1 {
  margin: 0;
  font-size: 1.28rem;
  letter-spacing: -0.015em;
  font-weight: 650;
}

.brand .sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-left: auto;
}

.user-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.btn-settings,
.btn-drills {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.btn-drills span { color: var(--accent); font-size: 0.95rem; line-height: 1; }

.btn-drills.is-active {
  color: var(--accent);
  border-color: rgba(45, 212, 191, 0.55);
  background: var(--accent-soft);
}

.btn-settings span {
  color: var(--accent);
  font-size: 0.95rem;
  line-height: 1;
}

.field { display: flex; flex-direction: column; gap: 5px; }

.field-layout { position: relative; }
.layout-row { display: flex; align-items: center; gap: 6px; }


.kb-settings {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  width: 288px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 13px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--panel-2);
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.5);
}

.kb-settings[hidden] { display: none; }

.kb-settings-title {
  margin: 0;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

.kb-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.kb-row .field-label { font-size: 0.6rem; letter-spacing: 0.08em; }
.kb-row select { width: 174px; min-width: 0; font-size: 0.72rem; padding: 6px 8px; }
.kb-row input { width: 84px; }

.kb-row input.is-off { opacity: 0.4; }

.kb-note {
  margin: 0;
  font-size: 0.64rem;
  line-height: 1.55;
  color: var(--faint);
}
.inline-field { display: flex; align-items: center; gap: 8px; }

.field-label {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}

input[type="text"], input#userName, select, button, .btn {
  font-family: inherit;
}

input#userName,
select {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 8px 10px;
  min-width: 140px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input#userName:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select { min-width: 118px; cursor: pointer; }

.xlate {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  color: var(--faint);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  white-space: nowrap;
  margin-bottom: 8px;
}

.badge {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(45, 212, 191, 0.32);
  border-radius: 999px;
  padding: 7px 12px;
  white-space: nowrap;
}

/* ---------------- layout ---------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin-top: 18px;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  min-width: 0;
}

.stage-panel { grid-column: 1 / -1; }

.chart-panel { grid-column: 1; }

.history-panel { grid-column: 1 / -1; }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 12px;
}

.panel-head-tight { margin-top: 18px; }

/* chart header: metric + line mode + the perfect-only filter */
.chart-controls {
  display: flex;
  align-items: center;
  gap: 10px 16px;
  flex-wrap: wrap;
}

.chart-controls .check.check-inline {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.76rem;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.chart-controls .check-inline input { accent-color: var(--accent); }

.panel-head h2 {
  margin: 0;
  white-space: nowrap;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}

.stage-flags { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.pangram-picker {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 11, 16, 0.4);
}

.pangram-picker .pg {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: var(--faint);
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

.pangram-picker .pg:hover { color: var(--text); }

.pangram-picker .pg.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.pangram-picker .pg:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

.pangram-id,
.state-pill {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--faint);
  white-space: nowrap;
}

.state-pill.is-running { color: var(--accent); border-color: rgba(45, 212, 191, 0.4); background: var(--accent-soft); }
.state-pill.is-done { color: var(--good); border-color: rgba(126, 226, 196, 0.4); background: rgba(126, 226, 196, 0.1); }
.state-pill.is-fix { color: #fbbf24; border-color: rgba(251, 191, 36, 0.42); background: rgba(251, 191, 36, 0.1); }

/* ---------------- drill bar ---------------- */

.drill-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid rgba(45, 212, 191, 0.28);
  border-radius: 11px;
  background: linear-gradient(120deg, rgba(45, 212, 191, 0.08), rgba(56, 189, 248, 0.04));
}

.drill-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1 1 320px;
}

.word-chip {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  background: rgba(7, 11, 16, 0.5);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.word-chip:hover { color: var(--text); border-color: var(--line-strong); }

.word-chip.is-active {
  color: var(--accent);
  border-color: rgba(45, 212, 191, 0.5);
  background: var(--accent-soft);
}

.word-chip:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

.drill-opts { display: flex; align-items: flex-end; gap: 14px; }

.drill-field { display: flex; flex-direction: column; gap: 4px; }

input#drillCount {
  width: 64px;
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 6px 8px;
  outline: none;
}

input#drillCount:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.drill-auto {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-bottom: 7px;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
}

.drill-auto input { width: 14px; height: 14px; accent-color: var(--accent); }

.drill-note { flex-basis: 100%; margin: 0; font-size: 0.72rem; color: var(--faint); }
.drill-note kbd { font-size: 0.66rem; }

/* ---------------- textbox ---------------- */

.textbox {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(7, 11, 16, 0.62);
  padding: 22px 22px;
  cursor: text;
  transition: border-color 0.15s, box-shadow 0.15s;
  overflow: hidden;
}

.textbox:focus {
  border-color: rgba(45, 212, 191, 0.55);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.textbox.is-drill { border-color: rgba(45, 212, 191, 0.35); }

.textbox.is-err { animation: shake 0.16s linear; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

.text-display {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(1.15rem, 2.1vw, 1.6rem);
  line-height: 1.85;
  letter-spacing: 0.012em;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--faint);
}

.text-display .ch { transition: color 0.08s linear; }
.text-display .ch.ok { color: var(--text); }
.text-display .ch.bad {
  color: #fff;
  background: var(--bad-soft);
  box-shadow: inset 0 -2px 0 var(--bad);
  border-radius: 2px;
}
.text-display .ch.cur {
  color: var(--text);
  background: rgba(45, 212, 191, 0.26);
  box-shadow: inset 0 -2px 0 var(--accent);
  border-radius: 3px;
}
.text-display .ch.cur.is-space { background: rgba(45, 212, 191, 0.36); }

/* ---------------- virtual keyboard ---------------- */

.vkeyboard {
  --key: clamp(25px, 3vw, 36px);
  --gap: 5px;
  --split: 28px;

  display: flex;
  flex-direction: column;
  gap: var(--gap);
  align-items: center;
  margin: 14px auto 0;
  width: fit-content;
  max-width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(7, 11, 16, 0.28);
  overflow-x: auto;
}

.vk-row {
  display: flex;
  gap: var(--split);
  flex: 0 0 auto;
}

/* left / right hand blocks, with the split padding between them */
.vk-half {
  display: flex;
  gap: var(--gap);
  flex: 0 0 auto;
}

.vk-caption {
  width: 100%;
  margin: 0 0 2px;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.vk-key {
  position: relative;
  width: var(--key);
  height: var(--key);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1;
  text-transform: uppercase;
  color: var(--text);
  background: rgba(148, 163, 184, 0.055);
  border: 1px solid var(--line);
  border-radius: 6px;
  transition: color 0.1s, background 0.1s, border-color 0.1s;
}

/* finger tint: index 1, middle 2, ring 3, pinky 4 */
.vk-key[data-finger] {
  background: var(--finger-bg);
  border-color: var(--finger-line);
}

.vk-letter { line-height: 1; }

.vk-finger {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 7px;
  line-height: 1;
  letter-spacing: 0;
  color: var(--finger);
  opacity: 0.95;
}

.vk-key.is-next .vk-finger,
.vk-key.is-next.is-fix-key .vk-finger { color: rgba(6, 26, 23, 0.75); }

.vk-key.is-next {
  color: #04201c;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.16);
}

.vk-key.is-next.is-fix-key {
  color: #241a02;
  background: #fbbf24;
  border-color: #fbbf24;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.18);
}

/* split between the index finger's two columns and the middle finger */
.vk-key.vk-index-gap {
  margin-left: var(--split);
}

/* the correct key, shown green after a wrong press */
.vk-key.is-good {
  color: #042011;
  background: #4ade80;
  border-color: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.16);
}

.vk-key.is-good .vk-finger { color: rgba(4, 32, 17, 0.7); }

.vk-space.is-good {
  background: rgba(74, 222, 128, 0.3);
  border-color: #4ade80;
  box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.55);
}

/*
 * Hint fade-in. Nothing is applied to the key until the highlight starts, so
 * it sits there in its own finger colours; then these transitions carry it
 * from that look to the highlight over --hint-dur.
 */
.vk-key.hint-anim {
  transition:
    color var(--hint-dur, 0.5s) ease-out,
    background var(--hint-dur, 0.5s) ease-out,
    border-color var(--hint-dur, 0.5s) ease-out,
    box-shadow var(--hint-dur, 0.5s) ease-out;
}

.vk-key.hint-anim .vk-finger {
  transition: color var(--hint-dur, 0.5s) ease-out;
}

.vk-key.is-err {
  color: #fff;
  background: var(--bad);
  border-color: var(--bad);
}

.vk-space {
  width: calc(5 * var(--key) + 4 * var(--gap) + var(--split));
  height: calc(var(--key) * 0.7);
  border-radius: 6px;
}

/* index-finger homing bar, like the raised line on F and J */
.vk-key.has-homing::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 22%;
  width: 38%;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.55;
  transform: translateX(-50%);
}

.vk-space.is-next {
  background: rgba(45, 212, 191, 0.3);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.55);
}

.vk-space.is-next.is-fix-key {
  background: rgba(251, 191, 36, 0.3);
  border-color: #fbbf24;
  box-shadow: inset 0 0 0 1px rgba(251, 191, 36, 0.55);
}

/* ---------------- live stats ---------------- */

.live-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
  margin-top: 14px;
}

.stat { display: flex; flex-direction: column; min-width: 62px; }

.stat-value {
  font-family: var(--mono);
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.stat-label {
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.live-stats .btn { margin-left: auto; }

.hints {
  margin: 12px 0 0;
  font-size: 0.78rem;
  color: var(--faint);
  line-height: 1.7;
}

kbd {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  background: var(--panel-2);
  color: var(--muted);
}

/* ---------------- result ---------------- */

.result-card {
  margin-top: 16px;
  padding: 16px 18px;
  border-radius: 12px;
  border: 1px solid rgba(45, 212, 191, 0.32);
  background: linear-gradient(120deg, rgba(45, 212, 191, 0.12), rgba(56, 189, 248, 0.06));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 28px;
  animation: rise 0.22s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-main { display: flex; align-items: baseline; gap: 8px; }

.result-wpm {
  font-family: var(--mono);
  font-size: 2.5rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: -0.03em;
}

.result-unit {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.result-badge.is-drill {
  color: var(--accent);
  background: rgba(45, 212, 191, 0.2);
  border: 1px solid rgba(45, 212, 191, 0.42);
}

.result-badge {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #04201c;
  background: var(--accent);
  border-radius: 999px;
  padding: 3px 9px;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 26px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.result-meta li { display: flex; flex-direction: column; }
.result-meta b {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.result-meta span {
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.result-note {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted);
}

/* ---------------- chart ---------------- */

.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.tab {
  font-size: 0.76rem;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.tab:hover { color: var(--text); border-color: var(--line-strong); }

.tab.is-active {
  color: var(--accent);
  border-color: rgba(45, 212, 191, 0.45);
  background: var(--accent-soft);
}

.tab-sub {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--faint);
}

.chart-panel .inline-field select {
  min-width: 106px;
  font-size: 0.8rem;
  padding: 6px 9px;
}

.depth-preview {
  margin: 2px 0 10px;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
  letter-spacing: 0.02em;
  white-space: pre-wrap;
  word-break: break-word;
}

.depth-preview[hidden] { display: none; }
.depth-preview .dp-lit { color: var(--text); }
.depth-preview .dp-dim { color: var(--faint); opacity: 0.45; }

.chart-wrap { position: relative; height: 320px; min-width: 0; }

#chart { display: block; width: 100%; height: 100%; }

.chart-tip {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: rgba(9, 14, 20, 0.96);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--text);
  white-space: nowrap;
  transform: translate(-50%, -100%);
}

.chart-tip .tip-muted { color: var(--faint); }

.chart-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.cs { display: flex; flex-direction: column; gap: 2px; }
.cs b {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.cs span {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.legend {
  margin: 10px 0 0;
  font-size: 0.7rem;
  color: var(--faint);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
}

.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-sep { opacity: 0.5; }

.legend .dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}

.legend .line {
  width: 14px; height: 2px; border-radius: 2px;
  display: inline-block;
}

/* ---------------- settings ---------------- */

.settings { display: grid; gap: 10px; }

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(7, 11, 16, 0.35);
  cursor: pointer;
}

.check input {
  margin: 3px 0 0;
  accent-color: var(--accent);
  width: 15px; height: 15px;
  flex: 0 0 auto;
}

.check strong { display: block; font-size: 0.84rem; font-weight: 550; }

.check-line {
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.check-line select { min-width: 130px; }

.check-line .check-note {
  flex-basis: 100%;
  font-size: 0.72rem;
  color: var(--faint);
  line-height: 1.5;
}
.check small { display: block; margin-top: 2px; font-size: 0.73rem; color: var(--faint); line-height: 1.5; }

.user-list { display: grid; gap: 6px; }

.layout-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.layout-chip { font-weight: 500; }

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(7, 11, 16, 0.35);
}

.user-row.is-current { border-color: rgba(45, 212, 191, 0.42); background: var(--accent-soft); }

.user-row .uname {
  font-family: var(--mono);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-row .umeta {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--faint);
  white-space: nowrap;
}

.icon-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--faint);
  border-radius: 7px;
  font-size: 0.68rem;
  padding: 4px 7px;
  cursor: pointer;
  line-height: 1.3;
}

.icon-btn:hover { color: var(--bad); border-color: rgba(248, 113, 113, 0.45); }

/* the keyboard-hints gear keeps the accent colour, open or hovered */
.icon-btn.kb-gear { padding: 7px 8px; display: grid; place-items: center; }
.icon-btn.kb-gear svg { display: block; }
.icon-btn.kb-gear:hover,
.icon-btn.kb-gear[aria-expanded="true"] {
  color: var(--accent);
  border-color: rgba(45, 212, 191, 0.55);
}

.data-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  font-size: 0.8rem;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }

.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-ghost:hover { color: var(--accent); border-color: rgba(45, 212, 191, 0.45); }

.fineprint { margin: 10px 0 0; font-size: 0.72rem; color: var(--faint); }

/* ---------------- history ---------------- */

.table-wrap { overflow: auto; max-height: 430px; }

.history-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #131b26;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.history-table th {
  text-align: left;
  font-size: 0.64rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.history-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.history-table tbody tr:hover td { background: rgba(148, 163, 184, 0.05); }
.history-table .num { text-align: right; font-family: var(--mono); }
.history-table td.num { font-family: var(--mono); }
.history-table td.when { color: var(--muted); }
.history-table td.text { color: var(--muted); }
.history-table td.wpm { color: var(--accent); font-family: var(--mono); }

.tag {
  font-family: var(--mono);
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.empty {
  padding: 18px 10px;
  color: var(--faint);
  font-size: 0.84rem;
  text-align: center;
}

.footer {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--faint);
}

.dot-sep { opacity: 0.6; }

/* ---------------- settings modal ---------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px 24px;
  background: rgba(4, 7, 10, 0.72);
  backdrop-filter: blur(3px);
  overflow-y: auto;
}

.modal {
  width: min(560px, 100%);
  background: linear-gradient(180deg, #151d29, #0f1620);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: rise 0.18s ease-out;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}

.modal-head p {
  margin: 3px 0 0;
  font-size: 0.76rem;
  color: var(--faint);
}

.modal-close {
  font-size: 0.78rem;
  padding: 6px 9px;
  color: var(--muted);
}

.modal-close:hover { color: var(--text); border-color: var(--line-strong); }

.modal-body { padding: 4px 20px 20px; }

.modal-section { padding-top: 16px; }

.modal-section h3 {
  margin: 0 0 10px;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}

body.modal-open { overflow: hidden; }

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(9, 14, 20, 0.96);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 0.82rem;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  z-index: 20;
  max-width: min(90vw, 460px);
}

.hidden { display: none !important; }

/* ---------------- responsive ---------------- */

@media (max-width: 940px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .chart-panel, .history-panel, .stage-panel { grid-column: 1; }
  .chart-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .app { padding: 18px 14px 32px; }
  .topbar { align-items: flex-start; }
  .user-bar { width: 100%; }
  .field { flex: 1 1 140px; }
  input#userName, select { width: 100%; min-width: 0; }
  .live-stats .btn { margin-left: 0; }
  .depth-preview {
  margin: 2px 0 10px;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
  letter-spacing: 0.02em;
  white-space: pre-wrap;
  word-break: break-word;
}

.depth-preview[hidden] { display: none; }
.depth-preview .dp-lit { color: var(--text); }
.depth-preview .dp-dim { color: var(--faint); opacity: 0.45; }

.chart-wrap { height: 220px; }
  .stage-flags { width: 100%; justify-content: flex-start; }
  .pangram-picker .pg { padding: 4px 8px; font-size: 0.64rem; }
  .vkeyboard { padding: 8px 8px; --key: 22px; --gap: 3px; --split: 16px; }
  .vk-key { font-size: 0.62rem; }
}

@media (max-width: 680px) {
  .history-table .col-text,
  .history-table td.text { display: none; }
  .history-table th, .history-table td { padding-left: 6px; padding-right: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
