/* ------------------------------------------------------------------ tokens */
:root {
  --base: #070d16;
  --mesh-1: #0a6ac4;
  --mesh-2: #08407f;
  --mesh-3: #14315f;
  --mesh-4: #1b86d8;
  --accent: #0490ff;
  --accent-2: #5fd2ff;
  --text: #e8f2fd;
  --dim: #93aac4;

  --font-stack: 'Inter', 'Segoe UI Variable', 'Segoe UI', system-ui, sans-serif;
  --word-size: 34px;
  --word-track: 0px;
  --word-leading: 1.85;

  --glass: color-mix(in srgb, var(--base) 62%, transparent);
  --glass-line: color-mix(in srgb, var(--text) 13%, transparent);
  --glass-hi: color-mix(in srgb, var(--text) 8%, transparent);

  --titlebar: 40px;
  --radius: 18px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --drift: cubic-bezier(0.45, 0, 0.55, 1);
}

* { box-sizing: border-box; }

/* The `hidden` attribute must beat any author `display` rule. Without this,
   .btn/.live's own `display: inline-flex` silently overrides it and the
   element stays on screen. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--base);
  color: var(--text);
  font-family: var(--font-stack);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  cursor: default;
}

button { font: inherit; color: inherit; }

svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

/* ------------------------------------------------------------- background */
/* No filter here on purpose. A blur() on this element forced Chromium to
   re-render the whole subtree into an offscreen surface the size of the window
   plus the blur outset, every single frame, because the children animate. The
   blobs are painted soft instead — a radial falloff is what a blurred disc
   looks like anyway — so each one rasterises once and the compositor just moves
   it. Free on Apple Silicon, but on an integrated GPU sharing system memory
   that per-frame surface was the whole frame budget. */
.mesh {
  position: fixed;
  inset: -12%;
  z-index: 0;
  pointer-events: none;
  /* The old blur smeared colour into every corner. The blobs alone leave the
     corners bare, so a cheap static wash stands in for that — it rasterises
     once and never changes. */
  background:
    radial-gradient(120% 90% at 12% 8%, color-mix(in srgb, var(--mesh-1) 55%, transparent) 0%, transparent 60%),
    radial-gradient(110% 100% at 88% 82%, color-mix(in srgb, var(--mesh-4) 50%, transparent) 0%, transparent 62%);
}

.blob {
  position: absolute;
  display: block;
  opacity: 0.85;
  will-change: transform, opacity;
}
/* Durations are short enough that the motion is legible within a few seconds
   (the old 28-40s drift read as a still image), but the paths are long and
   out of phase so it never resolves into an obvious loop. */
.b1 { width: 110vw; height: 110vw; background: radial-gradient(circle closest-side, var(--mesh-1) 0%, color-mix(in srgb, var(--mesh-1) 82%, transparent) 34%, color-mix(in srgb, var(--mesh-1) 42%, transparent) 62%, transparent 86%); top: -34%; left: -26%; opacity: 0.9; animation: drift1 17s var(--drift) infinite alternate; }
.b2 { width: 104vw; height: 104vw; background: radial-gradient(circle closest-side, var(--mesh-2) 0%, color-mix(in srgb, var(--mesh-2) 82%, transparent) 34%, color-mix(in srgb, var(--mesh-2) 42%, transparent) 62%, transparent 86%); top: -10%; right: -30%; opacity: 0.9; animation: drift2 13s var(--drift) infinite alternate; }
.b3 { width: 120vw; height: 120vw; background: radial-gradient(circle closest-side, var(--mesh-3) 0%, color-mix(in srgb, var(--mesh-3) 82%, transparent) 34%, color-mix(in srgb, var(--mesh-3) 42%, transparent) 62%, transparent 86%); bottom: -44%; left: -10%; opacity: 0.95; animation: drift3 21s var(--drift) infinite alternate; }
.b4 { width: 92vw; height: 92vw; background: radial-gradient(circle closest-side, var(--mesh-4) 0%, color-mix(in srgb, var(--mesh-4) 82%, transparent) 34%, color-mix(in srgb, var(--mesh-4) 42%, transparent) 62%, transparent 86%); bottom: -26%; right: -16%; opacity: 0.9; animation: drift4 15s var(--drift) infinite alternate; }
.b5 { width: 80vw; height: 80vw; background: radial-gradient(circle closest-side, var(--mesh-2) 0%, color-mix(in srgb, var(--mesh-2) 82%, transparent) 34%, color-mix(in srgb, var(--mesh-2) 42%, transparent) 62%, transparent 86%); top: 16%; left: 14%; opacity: 0.6; animation: drift5 19s var(--drift) infinite alternate; }

@keyframes drift1 {
  0%   { transform: translate3d(0, 0, 0) scale(1); opacity: 0.85; }
  50%  { transform: translate3d(14vw, 12vh, 0) scale(1.22); opacity: 0.7; }
  100% { transform: translate3d(4vw, 22vh, 0) scale(0.95); opacity: 0.9; }
}
@keyframes drift2 {
  0%   { transform: translate3d(0, 0, 0) scale(1); opacity: 0.8; }
  50%  { transform: translate3d(-18vw, 9vh, 0) scale(0.84); opacity: 0.95; }
  100% { transform: translate3d(-6vw, 24vh, 0) scale(1.16); opacity: 0.75; }
}
@keyframes drift3 {
  0%   { transform: translate3d(0, 0, 0) scale(1); opacity: 0.85; }
  50%  { transform: translate3d(16vw, -14vh, 0) scale(1.18); opacity: 0.7; }
  100% { transform: translate3d(-8vw, -24vh, 0) scale(1.02); opacity: 0.9; }
}
@keyframes drift4 {
  0%   { transform: translate3d(0, 0, 0) scale(1); opacity: 0.8; }
  50%  { transform: translate3d(-14vw, -11vh, 0) scale(1.3); opacity: 0.95; }
  100% { transform: translate3d(-22vw, 4vh, 0) scale(1.05); opacity: 0.7; }
}
@keyframes drift5 {
  0%   { transform: translate3d(0, 0, 0) scale(0.9); opacity: 0.4; }
  50%  { transform: translate3d(-16vw, -16vh, 0) scale(1.25); opacity: 0.65; }
  100% { transform: translate3d(12vw, -6vh, 0) scale(1); opacity: 0.35; }
}

html[data-motion="off"] .blob { animation: none; }

/* ------------------------------------------------------------------ chrome */
.drag-strip {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--titlebar);
  z-index: 40;
  -webkit-app-region: drag;
}

.shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: calc(var(--titlebar) + 4px) 28px 18px;
  gap: 14px;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}
.topbar .pill-group:first-of-type { justify-self: start; }
.topbar .pill-group:last-child { justify-self: end; }

.pill-group {
  display: inline-flex;
  gap: 2px;
  padding: 6px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  backdrop-filter: blur(22px) saturate(140%);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.22);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px; height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease), transform .12s var(--ease);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { background: var(--glass-hi); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.ghost { background: transparent; }

/* -------------------------------------------------------------------- chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 17px;
  border-radius: 999px;
  border: 1px solid var(--glass-line);
  background: var(--glass);
  color: var(--text);
  font-size: 14px;
  font-weight: 560;
  cursor: pointer;
  backdrop-filter: blur(18px) saturate(140%);
  transition: background .18s var(--ease), transform .12s var(--ease), border-color .18s var(--ease);
  white-space: nowrap;
}
.chip:hover { background: color-mix(in srgb, var(--base) 48%, transparent); border-color: color-mix(in srgb, var(--text) 22%, transparent); }
.chip:active { transform: scale(0.97); }
.chip-ico { width: 15px; height: 15px; color: var(--accent); flex: 0 0 auto; }
.chip-sm { padding: 7px 14px; font-size: 13px; }
.chip-lang { color: var(--accent); }
.chip-lang .chip-ico { color: inherit; }

.lang-row { display: flex; justify-content: center; flex: 0 0 auto; }

/* ------------------------------------------------------------------- stage */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  outline: none;
}

.words-viewport {
  position: relative;
  width: 100%;
  max-height: 100%;
  overflow: hidden;
  /* Fixed px, not percentages: the fade is there to soften the scroll edge, so
     it must stay the same depth whether the viewport shows two lines or eight.
     At 6% a tall viewport ate most of the last line. */
  mask-image: linear-gradient(180deg,
    transparent 0, #000 10px, #000 calc(100% - 10px), transparent 100%);
}

.words {
  position: relative;
  font-size: var(--word-size);
  line-height: var(--word-leading);
  letter-spacing: var(--word-track);
  font-weight: 500;
  transition: transform .28s var(--ease);
  will-change: transform;
}

.word {
  display: inline-block;
  margin-right: 0.42em;
  white-space: nowrap;
  transition: box-shadow .2s var(--ease);
}
/* An inset shadow, not a border. A border on an inline-block joins its margin
   box and makes every line box 2px taller than line-height, which is enough to
   throw the scroll maths off by a whole line a dozen lines in. */
.word.flagged {
  box-shadow: inset 0 -2px 0 0 color-mix(in srgb, var(--accent-2) 65%, transparent);
}

.ch {
  color: color-mix(in srgb, var(--text) 32%, transparent);
  transition: color .09s linear;
}
.ch.correct { color: var(--text); }
.ch.wrong   { color: var(--accent-2); }
.ch.extra   { color: color-mix(in srgb, var(--accent-2) 62%, transparent); text-decoration: underline wavy; text-underline-offset: 6px; }

.caret {
  position: absolute;
  top: 0; left: 0;
  width: 2.5px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 70%, transparent);
  pointer-events: none;
  opacity: 0;
}
.caret.on { opacity: 1; }
.caret.smooth { transition: transform .085s var(--ease), height .12s var(--ease); }
.caret.blink { animation: blink 1.05s steps(1, end) infinite; }
.caret.block { width: 0.58em; background: color-mix(in srgb, var(--accent) 45%, transparent); box-shadow: none; }
.caret.under { width: 0.58em; height: 3px !important; transform-origin: bottom; }
@keyframes blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0.12; } }

.focus-veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  backdrop-filter: blur(5px);
  background: color-mix(in srgb, var(--base) 22%, transparent);
  font-size: 15px;
  color: var(--dim);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s var(--ease);
}
.stage.unfocused .focus-veil { opacity: 1; }

/* --------------------------------------------------------------- statusbar */
.statusbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}
.statusbar > :first-child { justify-self: start; }
.statusbar > :last-child { justify-self: end; }

.status-center { display: grid; grid-auto-flow: column; place-items: center; gap: 14px; min-height: 34px; }

/* Shown while Caps Lock is on (app.js noteCapsLock): every letter would come
   out as a capital and count as wrong. Empty, it takes no room but stays in
   the page as a live region, so screen readers hear it appear. */
.caps-warn { display: none; }
.caps-warn.on {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--base);
  background: var(--accent);
}
.status-idle { font-size: 13.5px; color: var(--dim); }

.live { display: inline-flex; align-items: center; gap: 14px; }
.live-metric { display: inline-flex; align-items: baseline; gap: 4px; }
.live-metric b { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.live-metric i { font-style: normal; font-size: 12px; color: var(--dim); }
.live-sep { width: 1px; height: 14px; background: var(--glass-line); }
.live-progress b { color: var(--text); }

/* ------------------------------------------------------------------ keymap */
.keymap-wrap { flex: 0 0 auto; display: flex; justify-content: center; }
.keymap-wrap[hidden] { display: none; }

.keymap-stack {
  position: relative;
  width: min(100%, 760px);
  padding: 10px;
  border-radius: 20px;
}

.keymap { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 5px; }
.keymap-row { display: flex; gap: 5px; }

.keycap {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  /* No backdrop-filter here. There are 58 keycaps on screen and each one was a
     separate compositing pass that read back the backdrop; measured, they cost
     as much as every other blurred surface in the app combined and doubled the
     frame time. A more opaque fill reads the same at this size. */
  background: color-mix(in srgb, var(--base) 82%, transparent);
  font-size: 11.5px;
  font-weight: 600;
  color: color-mix(in srgb, var(--text) 62%, transparent);
  transition: background .1s linear, color .1s linear, border-color .1s linear, transform .07s var(--ease);
  overflow: hidden;
}
.keycap-main { line-height: 1; }
.keycap-shift {
  position: absolute;
  top: 3px; left: 6px;
  font-size: 8.5px;
  opacity: 0.55;
  line-height: 1;
}
.keycap:has(.keycap-shift) .keycap-main { position: absolute; bottom: 5px; left: 6px; }
.keycap-wide { font-size: 10px; }
.keycap-space { flex-grow: 7; }

.keycap.next {
  border-color: var(--accent);
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 24%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent),
              0 4px 18px color-mix(in srgb, var(--accent) 26%, transparent);
}
.keycap.down {
  transform: translateY(1.5px) scale(0.97);
  background: color-mix(in srgb, var(--accent) 46%, transparent);
  color: var(--base);
  border-color: transparent;
}
.keycap.miss {
  background: color-mix(in srgb, var(--accent-2) 48%, transparent);
  border-color: transparent;
  color: var(--text);
}

/* ------------------------------------------------------------------ footer */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 0 0 auto;
}

/* ----------------------------------------------------------------- overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, #000 52%, transparent);
  backdrop-filter: blur(14px);
  animation: fade .18s var(--ease);
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }

/* ----------------------------------------------------------------- results */
.results {
  width: min(760px, calc(100vw - 56px));
  max-height: calc(100vh - 72px);
  overflow: auto;
  padding: 26px 28px 24px;
  border-radius: 26px;
  background: color-mix(in srgb, var(--base) 88%, transparent);
  border: 1px solid var(--glass-line);
  box-shadow: 0 30px 90px rgb(0 0 0 / 0.5);
  animation: rise .26s var(--ease);
}
@keyframes rise { from { transform: translateY(14px) scale(0.985); opacity: 0; } }

.results-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.result-hero { display: flex; gap: 40px; align-items: flex-end; }
.hero-metric { display: flex; flex-direction: column; }
.hero-value {
  font-size: 58px;
  font-weight: 750;
  line-height: 1;
  letter-spacing: -1.5px;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-value i { font-size: 30px; font-style: normal; }
.hero-label { font-size: 12.5px; color: var(--dim); margin-top: 4px; letter-spacing: 0.4px; }

.chart-card {
  margin-top: 20px;
  padding: 14px 8px 8px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--text) 4%, transparent);
  border: 1px solid var(--glass-line);
}
#chart { width: 100%; height: 190px; display: block; }
#chart .grid { stroke: color-mix(in srgb, var(--text) 10%, transparent); stroke-width: 1; }
#chart .axis-label { fill: var(--dim); stroke: none; font-size: 10px; font-family: var(--font-stack); }
#chart .line-wpm { stroke: var(--accent); stroke-width: 2.4; }
#chart .line-raw { stroke: color-mix(in srgb, var(--text) 40%, transparent); stroke-width: 1.6; stroke-dasharray: 4 4; }
#chart .area-wpm { fill: color-mix(in srgb, var(--accent) 16%, transparent); stroke: none; }
#chart .err { fill: var(--accent-2); stroke: none; }

.chart-legend { display: flex; gap: 16px; justify-content: center; padding: 6px 0 2px; font-size: 11.5px; color: var(--dim); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.sw-wpm { background: var(--accent); }
.sw-raw { background: color-mix(in srgb, var(--text) 40%, transparent); }
.sw-err { background: var(--accent-2); border-radius: 50%; height: 7px; width: 7px; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.stat {
  padding: 12px 14px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--text) 4%, transparent);
  border: 1px solid var(--glass-line);
}
.stat-k { font-size: 11px; color: var(--dim); letter-spacing: 0.3px; }
.stat-v { font-size: 21px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat-v small { font-size: 12px; font-weight: 500; color: var(--dim); margin-left: 2px; }

.problem-keys { margin-top: 16px; }
.problem-keys:empty { display: none; }
.pk-title { font-size: 12px; color: var(--dim); margin-bottom: 8px; letter-spacing: 0.3px; }
.pk-list { display: flex; flex-wrap: wrap; gap: 8px; }
.pk {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent-2) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent-2) 26%, transparent);
  font-size: 12.5px;
}
.pk b { font-family: 'Cascadia Code', Consolas, ui-monospace, monospace; font-size: 13.5px; }
.pk i { font-style: normal; color: var(--dim); font-size: 11.5px; }

.results-actions { display: flex; gap: 10px; margin-top: 22px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 12px;
  border: 1px solid var(--glass-line);
  background: color-mix(in srgb, var(--text) 5%, transparent);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background .16s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: color-mix(in srgb, var(--text) 10%, transparent); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--base);
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-count {
  margin-left: 2px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, #000 26%, transparent);
}

kbd {
  font: inherit;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 5px;
  background: color-mix(in srgb, #000 22%, transparent);
  border: 1px solid color-mix(in srgb, #000 30%, transparent);
}

/* ------------------------------------------------------------------ panels */
.panel-overlay { place-items: stretch; justify-items: end; }
.panel {
  width: min(430px, 100vw);
  height: 100%;
  overflow: auto;
  padding: 0 0 28px;
  background: color-mix(in srgb, var(--base) 92%, transparent);
  border-left: 1px solid var(--glass-line);
  box-shadow: -30px 0 90px rgb(0 0 0 / 0.45);
  animation: slide .26s var(--ease);
}
@keyframes slide { from { transform: translateX(26px); opacity: 0; } }

.panel-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  background: color-mix(in srgb, var(--base) 92%, transparent);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-line);
}
.panel-head h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: 0.1px; }
.panel-body { padding: 16px 20px 0; }

.group { margin-bottom: 26px; }
.group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--dim);
  margin-bottom: 10px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--text) 7%, transparent);
  font-size: 14px;
}
.row:last-child { border-bottom: 0; }
.row-label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-label small { color: var(--dim); font-size: 11.5px; }

select, input[type="range"], input[type="number"] {
  font: inherit;
  color: var(--text);
  background: color-mix(in srgb, var(--text) 7%, transparent);
  border: 1px solid var(--glass-line);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}
select option { background: #1b1418; color: var(--text); }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  padding: 0;
  width: 132px;
  height: 4px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 16%, transparent);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 50%, transparent);
  cursor: grab;
}

.switch {
  position: relative;
  width: 42px; height: 24px;
  border-radius: 999px;
  border: 0;
  background: color-mix(in srgb, var(--text) 16%, transparent);
  cursor: pointer;
  transition: background .2s var(--ease);
  flex: 0 0 auto;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--text);
  transition: transform .22s var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(18px); background: var(--base); }

.seg-choice { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-choice button {
  border: 1px solid var(--glass-line);
  background: color-mix(in srgb, var(--text) 5%, transparent);
  color: var(--dim);
  border-radius: 9px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .16s var(--ease);
}
.seg-choice button:hover { color: var(--text); }
.seg-choice button[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--base);
  border-color: transparent;
}

.pack-list { display: grid; gap: 8px; }
.pack {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border-radius: 13px;
  border: 1px solid var(--glass-line);
  background: color-mix(in srgb, var(--text) 4%, transparent);
  cursor: pointer;
  text-align: left;
  transition: all .16s var(--ease);
}
.pack:hover { background: color-mix(in srgb, var(--text) 9%, transparent); }
.pack[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.pack-body { flex: 1 1 auto; min-width: 0; }
.pack-name { font-size: 14px; font-weight: 650; }
.pack-desc { font-size: 11.5px; color: var(--dim); margin-top: 2px; }
.pack-fam {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 10%, transparent);
  color: var(--dim);
  letter-spacing: 0.4px;
  flex: 0 0 auto;
}
.pack-play {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--glass-line);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}
.pack-play svg { width: 13px; height: 13px; }

/* --------------------------------------------------------------- data lists */
.hist { display: grid; gap: 7px; }
.hist-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 13px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--text) 4%, transparent);
  border: 1px solid var(--glass-line);
  font-size: 13px;
}
.hist-when { color: var(--dim); font-size: 11.5px; }
.hist-meta { color: var(--dim); font-size: 11.5px; }
.hist-wpm { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.hist-acc { font-variant-numeric: tabular-nums; color: var(--dim); }

.empty { padding: 34px 10px; text-align: center; color: var(--dim); font-size: 13.5px; }

.spark { width: 100%; height: 76px; display: block; margin: 6px 0 14px; }
.spark path.l { stroke: var(--accent); stroke-width: 2; fill: none; }
.spark path.a { fill: color-mix(in srgb, var(--accent) 15%, transparent); stroke: none; }

/* ------------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 90;
  padding: 10px 18px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--base) 90%, transparent);
  border: 1px solid var(--glass-line);
  backdrop-filter: blur(18px);
  font-size: 13px;
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.4);
  animation: toastIn .22s var(--ease);
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { transform: translate(-50%, 10px); opacity: 0; } }

/* ------------------------------------------------------------ scroll + a11y */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text) 16%, transparent);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.stage:focus,
.stage:focus-visible { outline: none; }

@media (prefers-reduced-motion: reduce) {
  .blob { animation: none; }
  * { transition-duration: .01ms !important; }
  /* Layers fade in without sliding; modules/layers.js fades them out. */
  .panel, .results, .name-card, .custom-card, .toast { animation-name: fade; }
}

@media (max-width: 960px) {
  .shell { padding-left: 18px; padding-right: 18px; }
  .seg { padding: 8px 14px; font-size: 13.5px; }
  .hero-value { font-size: 46px; }
}

/* ------------------------------------------------------------ player chip */
.chip-player { justify-self: center; font-weight: 640; }
.chip-player .chip-ico { color: var(--accent); }

/* ------------------------------------------------------------- name modal */
.name-card {
  width: min(430px, calc(100vw - 48px));
  padding: 28px 28px 24px;
  border-radius: 24px;
  background: color-mix(in srgb, var(--base) 92%, transparent);
  border: 1px solid var(--glass-line);
  box-shadow: 0 30px 90px rgb(0 0 0 / 0.5);
  animation: rise .26s var(--ease);
}
.name-card h2 { margin: 0 0 6px; font-size: 22px; font-weight: 720; letter-spacing: -0.2px; }
.name-sub { margin: 0 0 18px; font-size: 13.5px; color: var(--dim); line-height: 1.5; }

#nameInput {
  width: 100%;
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 560;
  color: var(--text);
  background: color-mix(in srgb, var(--text) 7%, transparent);
  border: 1px solid var(--glass-line);
  border-radius: 13px;
  outline: none;
  user-select: text;
  cursor: text;
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
#nameInput::placeholder { color: color-mix(in srgb, var(--dim) 70%, transparent); font-weight: 450; }
#nameInput:focus {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--text) 10%, transparent);
}

.name-error {
  margin-top: 9px;
  font-size: 12.5px;
  color: var(--accent-2);
}
.name-error[hidden] { display: none; }

.name-known { margin-top: 20px; }
.name-known[hidden] { display: none; }
.name-known-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--dim);
  margin-bottom: 9px;
}
.name-known-list { display: flex; flex-wrap: wrap; gap: 7px; }
.name-pill {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--glass-line);
  background: color-mix(in srgb, var(--text) 5%, transparent);
  color: var(--dim);
  font-size: 13px;
  font-weight: 560;
  cursor: pointer;
  transition: all .16s var(--ease);
}
.name-pill:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.name-actions { display: flex; gap: 9px; margin-top: 22px; }

/* ------------------------------------------------------------- leaderboard */
.board { display: grid; gap: 7px; margin-top: 12px; }

.board-row {
  display: grid;
  grid-template-columns: 30px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 11px 13px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--text) 4%, transparent);
  border: 1px solid var(--glass-line);
}
.board-row.me {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 11%, transparent);
}

.board-rank {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  background: color-mix(in srgb, var(--text) 8%, transparent);
}
.medal-1 .board-rank { background: linear-gradient(135deg, #f2c14a, #d99a2b); color: #2a1c05; }
.medal-2 .board-rank { background: linear-gradient(135deg, #d6dae0, #a8b0ba); color: #1d2126; }
.medal-3 .board-rank { background: linear-gradient(135deg, #d29464, #ab6f43); color: #241407; }

.board-who { min-width: 0; }
.board-name {
  font-size: 14px;
  font-weight: 640;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-sub { font-size: 11.5px; color: var(--dim); margin-top: 2px; }
.board-acc { font-size: 12.5px; color: var(--dim); font-variant-numeric: tabular-nums; }
.board-wpm {
  font-size: 19px;
  font-weight: 750;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.board-wpm i { font-size: 10.5px; font-style: normal; color: var(--dim); margin-left: 3px; font-weight: 500; }

/* ------------------------------------------------------------------- home */
.home {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* `safe` keeps the top reachable when the content is taller than the window;
     plain `center` would push the overflow above the scroll origin. */
  justify-content: safe center;
  height: 100%;
  padding: calc(var(--titlebar) + 12px) 28px 32px;
  gap: 22px;
  overflow: auto;
}

/* The first screen: brand, board, Start now. It is exactly one window tall so
   the board keeps scrolling inside itself, and anything the web build adds
   below (.home-extra) starts under the fold instead of squeezing it. */
.home-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 22px;
  width: 100%;
  flex: 0 0 100%;
  height: 100%;
  min-height: 0;
}

/* Only a touch-first device gets the keyboard notice. */
.touch-note { display: none; margin: 0; max-width: 420px; text-align: center; color: var(--dim); font-size: 13.5px; line-height: 1.5; }
@media (pointer: coarse) { .touch-note { display: block; } }

.board-caption { text-align: center; color: var(--dim); font-size: 12.5px; margin: 0 0 10px; }

.home-chrome {
  position: absolute;
  top: calc(var(--titlebar) + 4px);
  right: 28px;
}

.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  text-align: center;
}

.home-logo {
  width: min(260px, 52vw);
  height: auto;
  /* The brand mark keeps its own colour; the glow just lifts it off the dark. */
  filter: drop-shadow(0 8px 30px rgb(0 0 0 / 0.45))
          drop-shadow(0 0 46px color-mix(in srgb, #ffffff 22%, transparent));
}

.home-title {
  margin: 0;
  font-size: clamp(30px, 4.4vw, 46px);
  font-weight: 760;
  letter-spacing: -1px;
  /* background-clip: text crops to the line box, so line-height: 1 sliced the
     descender off the "g". Give the box room for it. */
  line-height: 1.2;
  padding-bottom: 0.06em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.home-board {
  width: min(560px, 100%);
  flex: 0 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--base) 66%, transparent);
  border: 1px solid var(--glass-line);
  backdrop-filter: blur(22px) saturate(140%);
  box-shadow: 0 16px 50px rgb(0 0 0 / 0.3);
}
.home-board .empty { padding: 22px 8px; }
.home-board .group { margin-bottom: 0; }

.board-picker { display: flex; justify-content: center; margin-bottom: 12px; }
.board-picker .seg-choice { justify-content: center; }

.btn-xl {
  flex: 0 0 auto;
  padding: 15px 42px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 14px;
  letter-spacing: 0.2px;
  box-shadow: 0 10px 34px color-mix(in srgb, var(--accent) 34%, transparent);
}

@media (max-height: 720px) {
  .home, .home-main { gap: 14px; }
  .home { padding-top: calc(var(--titlebar) + 6px); }
  .home-logo { width: min(180px, 42vw); }
  .home-title { font-size: clamp(24px, 3.6vw, 34px); }
}
