/* type.hjorth.dev — layout, type and components. Colour tokens live in themes.css. */

@font-face { font-family: "Xanh Mono"; src: url("../fonts/xanh-mono-400.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Familjen Grotesk"; src: url("../fonts/familjen-grotesk-var.woff2") format("woff2"); font-weight: 400 700; font-style: normal; font-display: swap; }

:root {
  --serif-mono: "Xanh Mono", "Iosevka", ui-monospace, "Courier New", monospace;
  --sans: "Familjen Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --type-size: var(--type-size-user, 2rem); /* --type-size-user comes from settings */
  --type-lh: 1.62;
  --type-ls: 0em;
  --type-font: var(--serif-mono);
  --lines: 3;
  --col: 60rem;
  --rail: 11.5rem;
  --gutter: clamp(1rem, 4vw, 3rem);
  --big: clamp(4.25rem, 8.5vw, 6.75rem); /* the stationary scoreboard / result number */
  --dim: color-mix(in srgb, var(--text) 24%, var(--bg));
  --dim-run: color-mix(in srgb, var(--text) 42%, var(--bg));
  --ease: cubic-bezier(.2, .7, .2, 1);
  --caret-ms: 95ms;
  --radius: 6px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--sub);
  font: 400 0.9375rem/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  transition: background-color .22s var(--ease), color .22s var(--ease);
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
kbd {
  display: inline-block;
  font: 500 .76em/1.35 var(--sans);
  color: var(--sub);
  padding: 0 .38em;
  min-width: 1.5em;
  text-align: center;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  white-space: nowrap;
  vertical-align: .06em;
}
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--main); outline-offset: 3px; border-radius: 4px; }
[tabindex="-1"]:focus-visible { outline: none; }
::selection { background: var(--main); color: var(--on-main); }

.sr-only, .skip:not(:focus) {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip {
  position: fixed; top: .75rem; left: .75rem; z-index: 50;
  background: var(--main); color: var(--on-main); padding: .4rem .75rem; border-radius: var(--radius);
}

/* ---------- page frame: centered default ---------- */
.page {
  min-height: 100dvh;
  max-width: calc(var(--col) + 2 * var(--gutter));
  margin: 0 auto;
  padding: clamp(1.25rem, 4vh, 2.5rem) var(--gutter) 1.35rem;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  row-gap: clamp(.9rem, 2.5vh, 1.5rem);
}
.chrome { transition: opacity .35s var(--ease); }
body.focus .chrome { opacity: 0; pointer-events: none; }
body.focus { cursor: none; }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.wordmark {
  font: 400 1.55rem/1 var(--serif-mono); color: var(--text); text-decoration: none; letter-spacing: -.01em;
}
.wordmark span { color: var(--sub); }
.top-actions { display: flex; align-items: baseline; gap: 1.35rem; }
.link { color: var(--sub); padding: .25rem 0; transition: color .14s; }
.link:hover, .link[aria-pressed="true"] { color: var(--text); }
.link kbd { margin-left: .4rem; }

/* ---------- mode + options bar (shape + colour) ---------- */
.config { display: flex; flex-direction: column; gap: .45rem; }
.modes, .options { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: .95rem; row-gap: .35rem; }
.modes { font-size: 1.0625rem; }
.options { min-height: 1.75rem; font-size: .9375rem; }
.chip {
  position: relative; padding: .2rem 0; color: var(--sub); transition: color .14s; text-align: left;
}
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { color: var(--text); }

/* active mode gets a crisp accent underline (shape + colour) */
.modes .chip::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: var(--main); transform: scaleX(0); transform-origin: left;
  transition: transform .16s var(--ease);
}
.modes .chip[aria-pressed="true"] { font-weight: 500; }
.modes .chip[aria-pressed="true"]::after { transform: none; }

/* active numeric/quote presets get an accent underline */
.options .chip[data-action="time"][aria-pressed="true"],
.options .chip[data-action="words"][aria-pressed="true"],
.options .chip[data-action="quote"][aria-pressed="true"],
.options .chip[data-action="custom"][aria-pressed="true"] {
  color: var(--main);
  text-decoration: underline 2px var(--main);
  text-underline-offset: .32em;
}

/* boolean toggles and active modifiers get geometric square state markers */
.options .chip[data-action="toggle"]::before,
.options .chip[data-action="open"][aria-pressed="true"]::before {
  content: ""; display: inline-block; width: .6em; height: .6em; margin-right: .45em;
  border: 1.5px solid currentColor; border-radius: 1.5px; vertical-align: -.02em; opacity: .78;
  transition: background-color .14s, border-color .14s, opacity .14s;
}
.options .chip[data-action="toggle"][aria-pressed="true"]::before,
.options .chip[data-action="open"][aria-pressed="true"]::before {
  background: var(--main); border-color: var(--main); opacity: 1;
}

.sep { width: .85rem; flex: none; }
.note .keys { font-family: var(--serif-mono); font-size: 1.15em; color: var(--main); letter-spacing: .12em; }

/* ---------- optional persistent left rail layout (from Design B) ---------- */
[data-layout="rail"] .page {
  max-width: calc(var(--rail) + var(--col) + 5rem + 2 * var(--gutter));
  grid-template-columns: var(--rail) minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  column-gap: clamp(2.25rem, 5.5vw, 5rem);
  row-gap: 2.25rem;
}
[data-layout="rail"] .top { display: contents; }
[data-layout="rail"] .wordmark { grid-column: 1; grid-row: 1; align-self: start; }
[data-layout="rail"] .config { grid-column: 1; grid-row: 2; gap: 1.6rem; align-self: start; }
[data-layout="rail"] .top-actions {
  grid-column: 1; grid-row: 3; align-self: end;
  flex-direction: column; gap: .2rem;
}
[data-layout="rail"] .modes { flex-direction: column; align-items: flex-start; row-gap: .15rem; }
[data-layout="rail"] .modes .chip::after {
  left: -.95rem; right: auto; top: .45em; bottom: .45em; width: 3px; height: auto;
  transform: scaleY(0); transform-origin: center;
}
[data-layout="rail"] .modes .chip[aria-pressed="true"]::after { transform: none; }
[data-layout="rail"] .modes .sep { width: auto; height: .6rem; }
[data-layout="rail"] .options { column-gap: .8rem; row-gap: .15rem; }
[data-layout="rail"] .options .sep { flex-basis: 100%; width: auto; height: .55rem; }
[data-layout="rail"] .options .chip[data-action="toggle"],
[data-layout="rail"] .options .chip[data-action="open"] { flex-basis: 100%; }
[data-layout="rail"] .stage {
  grid-column: 2; grid-row: 1 / 3;
  padding-top: 3.85rem;
}
[data-layout="rail"] .foot { grid-column: 2; grid-row: 3; max-width: var(--col); align-self: end; }

/* ---------- stage: steady top anchor so scoreboard and result share one spot ---------- */
.stage {
  display: flex; flex-direction: column; justify-content: flex-start; min-height: 0; min-width: 0;
  padding: clamp(1.5rem, 6vh, 4rem) 0 clamp(2rem, 5vh, 3.5rem);
}
.test, .results { width: 100%; max-width: var(--col); }
.test[hidden], .results[hidden] { display: none; }

/* the one bold thing: the stationary scoreboard numeral */
.live {
  display: flex; align-items: flex-end; flex-wrap: wrap; column-gap: 1.4rem; row-gap: .35rem;
  min-height: calc(var(--big) * .88);
  margin-bottom: 1.15rem;
}
.live-main {
  font: 400 var(--big)/.88 var(--serif-mono);
  color: var(--dim);
  letter-spacing: -.03em;
  margin-left: -.04em;
  transition: color .3s var(--ease);
}
.test.running .live-main { color: var(--dim-run); }
.live-sub {
  font-size: 1.0625rem; color: var(--sub); padding-bottom: .55rem;
  font-variant-numeric: tabular-nums;
  opacity: 0; transition: opacity .3s var(--ease);
}
.test.running .live-sub { opacity: 1; }
.live-sub:empty { display: none; }
.live-sub .ahead { color: var(--main); }

.progress { height: 2px; background: var(--line); border-radius: 2px; margin: -.45rem 0 1.05rem; opacity: 0; overflow: hidden; }
.progress i { display: block; height: 100%; width: 100%; background: var(--main); transform-origin: left; transform: scaleX(0); transition: transform .2s linear; }
.test.show-progress.running .progress { opacity: 1; }

/* ---------- typing area: lit line + lamp caret + shape-coded errors ---------- */
.typing { position: relative; font-size: var(--type-size); }
.ghost-input {
  position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0;
  border: 0; padding: 0; margin: 0; pointer-events: none; caret-color: transparent;
}
.words-window {
  --lh: calc(var(--type-size) * var(--type-lh));
  height: calc(var(--lh) * var(--lines));
  overflow: hidden;
  position: relative;
  cursor: text;
  transition: filter .12s var(--ease), opacity .12s var(--ease);
  /* the lit line: scrolled-past and upcoming rows sit in softer light */
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,var(--top-fade, 1)) 0, #000 var(--lh), #000 calc(var(--lh) * 2), rgba(0,0,0,.58) 100%);
          mask-image: linear-gradient(to bottom, rgba(0,0,0,var(--top-fade, 1)) 0, #000 var(--lh), #000 calc(var(--lh) * 2), rgba(0,0,0,.58) 100%);
}
.words-window.scrolled { --top-fade: .48; }
.words-window[data-lines="2"] {
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 var(--lh), rgba(0,0,0,.58) 100%);
          mask-image: linear-gradient(to bottom, #000 0, #000 var(--lh), rgba(0,0,0,.58) 100%);
}
.words {
  position: relative;
  display: flex; flex-wrap: wrap; align-content: flex-start;
  font-family: var(--type-font);
  line-height: var(--type-lh);
  letter-spacing: var(--type-ls);
  color: var(--sub);
  transition: transform .18s var(--ease);
  will-change: transform;
}
.word {
  display: flex; align-items: center; height: var(--lh);
  margin-right: var(--word-gap, .56em); position: relative; white-space: pre;
}
.word.empty { min-width: .5em; }
.word.err::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: .08em; height: 1.5px;
  background: var(--error); opacity: .65; border-radius: 1px;
}
.word > span { display: block; line-height: 1.22; }
.c { color: var(--text); }
/* shape-coded errors (accessible beyond colour, crisp in every typeface) */
.x {
  color: var(--error);
  background: color-mix(in srgb, var(--error) 17%, transparent);
  border-radius: 2px;
}
.e {
  color: var(--extra);
  text-decoration: line-through .08em var(--error);
}
.m {
  color: var(--sub);
  text-decoration: underline dotted .075em var(--error);
  text-underline-offset: .13em;
}
.blind .x, .blind .e { color: var(--text); background: none; text-decoration: none; }
.blind .m { text-decoration: none; }
.blind .word.err::after { display: none; }

.caret {
  position: absolute; left: 0; top: 0; pointer-events: none; z-index: 2;
  width: .09em; height: 1.18em; margin-top: calc((var(--lh) - 1.18em) / 2);
  border-radius: .04em;
  background: var(--main);
  box-shadow: 0 0 .45em color-mix(in srgb, var(--main) 55%, transparent);
  transform: translate3d(var(--cx, 0), var(--cy, 0), 0);
}
.caret.smooth { transition: transform var(--caret-ms) var(--ease); }
.no-glow .caret { box-shadow: none; }
.typing.flash .caret:not(.ghost) {
  background: var(--error);
  box-shadow: 0 0 .5em color-mix(in srgb, var(--error) 60%, transparent);
  transition: none;
}
.typing.flash .caret[data-style="outline"]:not(.ghost) {
  background: transparent; box-shadow: inset 0 0 0 1.5px var(--error);
}
.caret.blink { animation: blink 1.05s steps(1, end) infinite; }
.caret[data-style="block"] { width: .5em; opacity: .48; box-shadow: none; }
.caret[data-style="block"].blink { animation-name: blink-half; }
.caret[data-style="outline"] { width: .5em; background: transparent; box-shadow: inset 0 0 0 1.5px var(--main); }
.caret[data-style="underline"] { width: .5em; height: .09em; margin-top: calc((var(--lh) + 1em) / 2); }
.caret.ghost {
  z-index: 1; width: .09em; height: 1.18em; background: var(--sub); opacity: .55; box-shadow: none;
  margin-top: calc((var(--lh) - 1.18em) / 2); transition: transform .12s linear;
}
.caret.ghost[hidden] { display: none; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes blink-half { 0%, 100% { opacity: .48; } 50% { opacity: 0; } }

.refocus {
  position: absolute; inset: 0; display: grid; place-items: center start;
  font-size: 1rem; font-family: var(--sans); color: var(--text);
  opacity: 0; pointer-events: none; transition: opacity .12s var(--ease);
}
.typing.blurred .refocus { opacity: 1; pointer-events: auto; cursor: pointer; transition: opacity .2s var(--ease) .25s; }
.typing.blurred .words-window { filter: blur(5px); opacity: .42; transition: filter .2s var(--ease) .25s, opacity .2s var(--ease) .25s; }
.typing.blurred .caret { opacity: 0; }
/* while a drawer is open, keep the stage sharp so theme previews show the real text */
body:has(.overlay:not([hidden])) .typing.blurred .words-window { filter: none; opacity: 1; transition: none; }
body:has(.overlay:not([hidden])) .typing.blurred .refocus { opacity: 0; pointer-events: none; }

.under { display: flex; align-items: center; gap: .9rem; margin-top: 1.35rem; min-height: 2.25rem; }
.icon-btn { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; margin-left: -.45rem; border-radius: 50%; color: var(--sub); transition: color .14s; }
.icon-btn:hover { color: var(--text); }
.icon-btn:focus-visible { color: var(--main); outline-offset: 0; border-radius: 50%; }
.note { margin: 0; color: var(--sub); font-size: .9rem; }
.test.running .under { opacity: 0; transition: opacity .3s; }
.test.running .under:focus-within { opacity: 1; }

/* ---------- results: the number lights up in the exact spot the scoreboard held ---------- */
.results { outline: none; }
.r-head { display: flex; flex-wrap: wrap; align-items: flex-end; column-gap: clamp(2rem, 6vw, 4.25rem); row-gap: 1rem; }
.r-big { display: flex; flex-direction: column; }
.r-big .num {
  font: 400 var(--big)/.88 var(--serif-mono);
  color: var(--main);
  letter-spacing: -.03em;
  margin-left: -.04em;
  position: relative;
}
.r-big.second .num { font-size: calc(var(--big) * .54); color: var(--text); margin-left: 0; }
.r-big .lbl { margin-top: .55rem; font-size: .9375rem; }
.pb-line { margin: 1.1rem 0 0; color: var(--text); max-width: 42rem; }
.pb .num::after {
  content: ""; position: absolute; left: .04em; right: 0; bottom: -.12em; height: 3px; border-radius: 2px;
  background: var(--main); transform-origin: left; animation: draw .85s var(--ease) .12s both;
}
@keyframes draw { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.r-fail {
  margin: 0 0 1.4rem; color: var(--text); font-size: 1.0625rem;
  padding-left: .85rem; border-left: 3px solid var(--error);
}
.r-fail span { color: var(--sub); }

.chart { margin: 1.85rem 0 1.15rem; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--sub); font: 12px var(--sans); }
.chart .l-wpm { fill: none; stroke: var(--main); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .l-raw { fill: none; stroke: var(--sub); stroke-width: 1.4; stroke-dasharray: 3 4; stroke-linecap: round; }
.chart .area { fill: color-mix(in srgb, var(--main) 6%, transparent); }
.chart .errs path { stroke: var(--error); stroke-width: 1.85; stroke-linecap: round; }
.chart .guide { stroke: var(--sub); stroke-width: 1; opacity: 0; }
.chart .dot { fill: var(--main); opacity: 0; }
.chart.hover .guide, .chart.hover .dot { opacity: 1; }
.chart-tip {
  position: absolute; top: 0; pointer-events: none; transform: translateX(-50%);
  background: var(--surface); color: var(--text); font-size: .8125rem; padding: .3rem .55rem; border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px var(--line); white-space: nowrap; opacity: 0;
}
.chart.hover .chart-tip { opacity: 1; }
.legend { display: flex; gap: 1.35rem; font-size: .8125rem; margin-top: .45rem; }
.legend i { display: inline-block; width: 1rem; height: 0; border-top: 2px solid var(--main); vertical-align: middle; margin-right: .4rem; }
.legend .raw i { border-top: 2px dashed var(--sub); }
.legend .er i { width: .6rem; border-color: var(--error); }

.facts { display: flex; flex-wrap: wrap; gap: 1.15rem clamp(1.5rem, 4vw, 3rem); margin: 1.6rem 0 0; }
.facts div { display: flex; flex-direction: column; }
.facts dt { font-size: .8125rem; order: 2; margin-top: .2rem; }
.facts dd { margin: 0; font: 400 1.65rem/1.15 var(--serif-mono); color: var(--text); }
.facts dd .slash { color: var(--sub); }
.facts dd.lbl-test { font: 400 1rem/1.35 var(--sans); padding-top: .4rem; max-width: 22rem; }

.r-bottom { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1.5rem; margin-top: 2rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem 1.6rem; }
.action { color: var(--text); padding: .3rem 0; font-weight: 500; transition: color .14s; }
.action kbd { margin-left: .45rem; font-weight: 500; }
.action:hover { color: var(--main); }

/* mini keyboard heatmap */
.kb { display: inline-flex; flex-direction: column; gap: 3px; font-family: var(--serif-mono); }
.kb-row { display: flex; gap: 3px; }
.kb-row:nth-child(2) { padding-left: .55rem; }
.kb-row:nth-child(3) { padding-left: 1.4rem; }
.kb-key {
  width: 1.55rem; height: 1.55rem; display: grid; place-items: center; border-radius: 3px; font-size: .92rem;
  color: var(--sub); background: color-mix(in srgb, var(--error) calc(var(--heat, 0) * 70%), var(--surface));
}
.kb-key.hot { color: var(--text); }
.kb-key.none { background: transparent; box-shadow: inset 0 0 0 1px var(--line); opacity: .65; }
.kb-cap { font-size: .8125rem; margin: 0 0 .5rem; }

/* ---------- footer ---------- */
.foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .5rem 2rem; font-size: .8125rem; }
.hints { margin: 0; display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; }
.hints span kbd { margin-right: .32rem; }
.fine { margin: 0; }

/* ---------- drawers: right slide-in over sharp stage for honest previews ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; justify-content: flex-end; align-items: stretch;
  padding: 0;
  background: color-mix(in srgb, var(--bg) 16%, transparent);
  animation: fade .12s var(--ease);
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.palette, .sheet {
  width: min(23rem, 100%); height: 100dvh; background: var(--surface); color: var(--text);
  border-left: 1px solid var(--line);
  box-shadow: -14px 0 38px -20px rgba(0, 0, 0, .35);
  animation: slide-in .16s var(--ease);
}
@keyframes slide-in { from { transform: translateX(1.25rem); opacity: 0; } }
.palette { display: flex; flex-direction: column; }
.palette-head {
  display: flex; align-items: baseline; gap: .55rem;
  padding: clamp(1.35rem, 4.5vh, 2.5rem) 1.5rem 1rem;
  border-bottom: 1px solid var(--line);
}
.crumb { color: var(--main); white-space: nowrap; font-size: 1.125rem; font-weight: 500; }
.crumb:empty { display: none; }
#palette-input { flex: 1; min-width: 0; background: none; border: 0; font-size: 1.125rem; color: var(--text); padding: 0; }
#palette-input::placeholder { color: var(--sub); }
#palette-input:focus-visible { outline: none; }
.palette-list { flex: 1; list-style: none; margin: 0; padding: .5rem 0; overflow-y: auto; scrollbar-width: thin; }
.palette-list li {
  position: relative; display: flex; align-items: center; gap: .7rem;
  padding: .52rem 1.5rem; cursor: pointer; color: var(--sub);
}
.palette-list li[aria-selected="true"] {
  background: color-mix(in srgb, var(--bg) 58%, var(--surface)); color: var(--text);
}
.palette-list li[aria-selected="true"]::before {
  content: ""; position: absolute; left: 0; top: .42rem; bottom: .42rem; width: 3px; background: var(--main);
}
.palette-list li .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-list li .lbl .path { color: var(--sub); }
.palette-list li .lbl mark { background: none; color: var(--main); font-weight: 500; }
.palette-list li .val { font-size: .8125rem; color: var(--sub); white-space: nowrap; }
.palette-list li .chk { width: .85rem; color: var(--main); flex: none; text-align: center; }
.palette-list li .more { color: var(--sub); }
.palette-list li .sw { display: inline-flex; }
.palette-list li .sw i {
  width: .65rem; height: .85rem;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 14%, transparent);
}
.palette-list .empty { color: var(--sub); cursor: default; }
.palette-foot {
  margin: 0; padding: .85rem 1.5rem 1.15rem; border-top: 1px solid var(--line);
  font-size: .78rem; color: var(--sub); display: flex; flex-wrap: wrap; gap: .3rem; align-items: center;
}
.palette-foot kbd:not(:first-child) { margin-left: .25rem; }
.palette-foot kbd + kbd { margin-left: 0; }

.sheet { padding: clamp(1.25rem, 3.8vh, 2rem) 1.5rem 1.35rem; overflow-y: auto; }
.sheet h2 { margin: 0 0 1rem; font: 600 1.3rem/1.2 var(--sans); letter-spacing: -.01em; }
.sheet dl { display: grid; grid-template-columns: 7.25rem 1fr; gap: .48rem .95rem; margin: 0; font-size: .9rem; }
.sheet dt { color: var(--text); }
.sheet dd { margin: 0; color: var(--sub); }
.sheet h3 { font: 600 .92rem var(--sans); color: var(--text); margin: 1.25rem 0 .55rem; }
.sheet .close { margin-top: 1.25rem; color: var(--sub); font-size: .875rem; }

/* ---------- stats view ---------- */
.statsview {
  position: fixed; inset: 0; z-index: 15; overflow-y: auto; background: var(--bg); color: var(--sub);
  padding: clamp(1.25rem, 4vh, 2.5rem) var(--gutter) 3rem;
}
.statsview[hidden] { display: none; }
.sv { max-width: 60rem; margin: 0 auto; }
.sv-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 2.25rem; gap: 1rem; }
.sv h2 { font: 600 1.75rem/1.1 var(--sans); letter-spacing: -.015em; color: var(--text); margin: 0; }
.sv h3 { font: 600 1rem var(--sans); color: var(--text); margin: 2.5rem 0 .95rem; }
.sv .facts dd { font-size: clamp(1.9rem, 3.8vw, 2.5rem); }
.sv .facts div:nth-child(3) dd { color: var(--main); }
.sv table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.sv th { font-weight: 500; text-align: left; color: var(--sub); padding: .45rem .85rem .45rem 0; border-bottom: 1px solid var(--line); }
.sv td { padding: .5rem .85rem .5rem 0; color: var(--text); border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent); }
.sv td.n { font-family: var(--serif-mono); font-size: 1.15rem; }
.sv td.d { color: var(--sub); }
.sv .table-wrap { overflow-x: auto; }
.sv .spark svg { width: 100%; height: auto; display: block; overflow: visible; }
.sv .spark .grid line { stroke: var(--line); }
.sv .spark .l-wpm { fill: none; stroke: var(--main); stroke-width: 2; }
.sv .spark .l-avg { fill: none; stroke: var(--sub); stroke-width: 1.25; stroke-dasharray: 2 4; }
.sv .spark text { fill: var(--sub); font: 12px var(--sans); }
.sv .data-actions { display: flex; flex-wrap: wrap; gap: .75rem 1.75rem; }
.sv .data-actions button { color: var(--text); font-weight: 500; padding: .2rem 0; }
.sv .data-actions button:hover { color: var(--main); }
.sv .data-actions .danger { color: var(--error); }
.sv .msg { margin-top: .75rem; color: var(--text); min-height: 1.5em; }
.sv .empty-state { color: var(--sub); }

/* ---------- settings view ---------- */
.st { max-width: 60rem; margin: 0 auto; display: grid; grid-template-columns: 9.5rem minmax(0, 1fr); column-gap: clamp(2rem, 5vw, 4rem); }
.st-top { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 2rem; }
.st-top h2 { font: 600 1.75rem/1.1 var(--sans); letter-spacing: -.015em; color: var(--text); margin: 0; }
.st-rail { position: sticky; top: 1.5rem; align-self: start; display: flex; flex-direction: column; }
.st-rail a {
  color: var(--sub); text-decoration: none; padding: .35rem 0 .35rem .9rem;
  border-left: 2px solid var(--line); transition: color .14s, border-color .14s;
}
.st-rail a:hover, .st-rail a.on { color: var(--text); }
.st-rail a.on { border-left-color: var(--main); font-weight: 500; }
.st-main { min-width: 0; }
.st-intro { margin: 0 0 1.85rem; }
.st-sec { padding-bottom: 2.5rem; scroll-margin-top: 1.5rem; }
.st-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .5rem; }
.st-head h3 { font: 600 1.25rem var(--sans); color: var(--text); margin: 0; scroll-margin-top: 1.5rem; }
.st-reset { font-size: .8125rem; }
.st-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .6rem 2.25rem;
  padding: .95rem 0; border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  transition: opacity .2s;
}
.st-row.wide { grid-template-columns: 1fr; }
.st-row.muted { opacity: .48; }
.st-label { color: var(--text); font-weight: 500; }
.st-desc { margin: .15rem 0 0; font-size: .875rem; max-width: 34rem; }
.st-ctl { justify-self: end; min-width: 0; }
.st-row.wide .st-ctl { justify-self: stretch; }
.st-actions { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; justify-content: flex-end; }
.link.strong { color: var(--text); font-weight: 500; }
.link.strong:hover { color: var(--main); }
.link.danger { color: var(--error); font-weight: 500; }
.confirm { display: inline-flex; gap: 1.25rem; }
.st-msg { color: var(--text); min-height: 1.5em; margin: .75rem 0 0; }

.seg { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: .2rem; }
.seg button { padding: .3rem .6rem; border-radius: 5px; color: var(--sub); white-space: nowrap; transition: color .14s, background-color .14s; }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] {
  color: var(--main); font-weight: 500;
  background: color-mix(in srgb, var(--main) 14%, transparent);
}

.switch { display: inline-flex; align-items: center; gap: .6rem; color: var(--sub); padding: .25rem 0; }
.switch .sw-txt { min-width: 1.6rem; text-align: right; font-size: .875rem; }
.switch .track { width: 2.3rem; height: 1.3rem; border-radius: 1rem; background: var(--line); position: relative; transition: background .18s var(--ease); }
.switch .knob { position: absolute; top: .2rem; left: .2rem; width: .9rem; height: .9rem; border-radius: 50%; background: var(--sub); transition: transform .18s var(--ease), background .18s; }
.switch[aria-checked="true"] { color: var(--text); }
.switch[aria-checked="true"] .track { background: var(--main); }
.switch[aria-checked="true"] .knob { transform: translateX(1rem); background: var(--on-main); }

.range { display: inline-flex; align-items: center; gap: .9rem; }
.range input { width: 11rem; accent-color: var(--main); margin: 0; }
.range output { min-width: 4.5rem; text-align: right; color: var(--text); font: 400 1.05rem var(--serif-mono); }

.st-preview {
  margin: .5rem 0 1.25rem; color: var(--sub); max-width: var(--col);
  font-family: var(--type-font); font-size: min(var(--type-size), 2.15rem); line-height: var(--type-lh); letter-spacing: var(--type-ls);
}
.pcaret {
  display: inline-block; width: .09em; height: 1.15em; margin: 0 -.045em; vertical-align: -.22em;
  background: var(--main); border-radius: .04em;
  box-shadow: 0 0 .45em color-mix(in srgb, var(--main) 55%, transparent);
}
.no-glow .pcaret { box-shadow: none; }
.pcaret[data-style="block"] { width: .5em; margin-right: -.5em; opacity: .48; box-shadow: none; }
.pcaret[data-style="outline"] { width: .5em; margin-right: -.5em; background: transparent; box-shadow: inset 0 0 0 1.5px var(--main); }
.pcaret[data-style="underline"] { width: .5em; height: .09em; margin-right: -.5em; vertical-align: -.2em; }

.themes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .65rem; margin-top: .6rem; }
.tile {
  display: flex; flex-direction: column; gap: .55rem; text-align: left; padding: .8rem .85rem .65rem; border-radius: 7px;
  background: var(--bg); color: var(--sub); box-shadow: inset 0 0 0 1px var(--line);
  transition: box-shadow .14s;
}
.tile .t-sample { font: 400 1.25rem/1.2 var(--serif-mono); white-space: nowrap; }
.tile .t-name { display: flex; justify-content: space-between; font-size: .8125rem; }
.tile .t-on { color: var(--main); }
.tile[aria-checked="true"] { box-shadow: inset 0 0 0 2px var(--main); }
.tile:hover { box-shadow: inset 0 0 0 1px var(--sub); }
.tile[aria-checked="true"]:hover { box-shadow: inset 0 0 0 2px var(--main); }

/* ---------- narrow / mobile screens (responsive down to 390px, zero horizontal scroll) ---------- */
@media (max-width: 760px) {
  :root {
    --type-size: min(var(--type-size-user, 2rem), 1.55rem);
    --big: clamp(3.5rem, 16vw, 5rem);
  }
  /* collapse optional rail layout back to stacked rows */
  [data-layout="rail"] .page {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto 1fr auto;
    column-gap: 0;
    row-gap: 1.15rem;
  }
  [data-layout="rail"] .top { display: flex; }
  [data-layout="rail"] .wordmark,
  [data-layout="rail"] .config,
  [data-layout="rail"] .top-actions,
  [data-layout="rail"] .stage,
  [data-layout="rail"] .foot { grid-column: auto; grid-row: auto; }
  [data-layout="rail"] .top-actions { flex-direction: row; align-self: auto; gap: 1rem; }
  [data-layout="rail"] .config { gap: .45rem; }
  [data-layout="rail"] .modes { flex-direction: row; flex-wrap: wrap; column-gap: .95rem; }
  [data-layout="rail"] .modes .chip::after {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 2px;
    transform: scaleX(0); transform-origin: left;
  }
  [data-layout="rail"] .modes .chip[aria-pressed="true"]::after { transform: none; }
  [data-layout="rail"] .modes .sep { width: .5rem; height: auto; }
  [data-layout="rail"] .options .sep { flex-basis: auto; width: .5rem; height: auto; }
  [data-layout="rail"] .options .chip[data-action="toggle"],
  [data-layout="rail"] .options .chip[data-action="open"] { flex-basis: auto; }
  [data-layout="rail"] .stage { padding-top: 1.5rem; }

  .st { grid-template-columns: minmax(0, 1fr); }
  .st-rail { display: none; }
  .st-row { grid-template-columns: minmax(0, 1fr); gap: .55rem; }
  .st-ctl { justify-self: start; }
  .switch .sw-txt { order: 2; text-align: left; }
  .seg, .st-actions { justify-content: flex-start; }
  .range input { width: min(11rem, 52vw); }
  .themes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .palette, .sheet { width: 100%; border-left: 0; }
  .sheet dl { grid-template-columns: 1fr; gap: .1rem; }
  .sheet dd { margin-bottom: .6rem; }
}

@media (max-width: 640px) {
  .wordmark { font-size: 1.25rem; }
  .top-actions { gap: .85rem; font-size: .875rem; }
  .top-actions .link kbd { display: none; }
  .modes { font-size: 1rem; column-gap: .8rem; }
  .options { column-gap: .75rem; }
  .sep { width: .35rem; }
  .stage { padding-top: 1.5rem; }
  .facts dd { font-size: 1.35rem; }
  .hints { display: none; }
}

/* reduced motion: follows the system unless overridden in settings (class set from JS) */
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
  transition-delay: 0s !important;
  scroll-behavior: auto !important;
}
.reduce-motion .caret.blink { animation: none; }
body.no-hints .hints { display: none; }
