/* keypot personal prefs: visual effects on the game DOM, then the settings page.
   prefs.js writes the data-* attributes and --type-font / --type-scale on <html>. */

:root {
  --type-font: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --type-scale: 1;
  --type-px: 25px;
  --c-untyped: var(--sub);
  --c-typed: var(--text);
  --c-caret: var(--accent);
}
@media (max-width: 820px) { :root { --type-px: 20px; } }

/* ---------- type font + size ---------- */
.words, .typed, .rocket .word, .caret { font-family: var(--type-font); }
.words, .caret { font-size: calc(var(--type-px) * var(--type-scale, 1)); }
.words { height: calc(var(--type-px) * var(--type-scale, 1) * 1.6 * 3); color: var(--c-untyped); }
@media (max-width: 820px) {
  .words { height: calc(var(--type-px) * var(--type-scale, 1) * 1.6 * 3); }
}
[data-show-all-lines] .words:not(.tape) { height: auto; max-height: none; }
[data-no-smooth-scroll] .words #inner { transition: none !important; }

/* ---------- colours: flip + colorful ---------- */
.words .c.ok, .words .c.done { color: var(--c-typed); }
[data-flip] { --c-untyped: var(--text); --c-typed: var(--sub); }
[data-colorful] {
  --c-typed: var(--accent);
  --c-untyped: color-mix(in srgb, var(--accent) 30%, var(--sub));
}
[data-flip][data-colorful] {
  --c-untyped: var(--accent);
  --c-typed: color-mix(in srgb, var(--accent) 40%, var(--sub));
}
[data-colorful] .words .c.extra { color: color-mix(in srgb, var(--err) 70%, var(--bg)); }

/* ---------- highlight: word ---------- */
/* the active word is .w.active (fallback: the word that has typed letters but is not committed) */
[data-highlight='word'] .words .w.active,
[data-highlight='word'] .words .w:has(> .c.ok, > .c.bad):not(:has(> .c.done)) {
  color: var(--c-typed);
}
[data-highlight='word'] .words .w.active .c,
[data-highlight='word'] .words .w:has(> .c.ok, > .c.bad):not(:has(> .c.done)) .c:not(.bad):not(.extra) {
  color: var(--c-typed);
}
[data-highlight='word'] .words .w.active::before,
[data-highlight='word'] .words .w:has(> .c.ok, > .c.bad):not(:has(> .c.done))::before {
  content: '';
  position: absolute;
  inset: 0.18em -0.22em 0.12em;
  border-radius: 0.2em;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  z-index: -1;
}
[data-highlight='word'] .words #inner { isolation: isolate; }

/* ---------- caret ---------- */
.caret { background: var(--c-caret); }
[data-smooth-caret='off'] .caret { transition: none; }
[data-smooth-caret='slow'] .caret { transition: left 0.2s ease, top 0.2s ease; }
[data-smooth-caret='medium'] .caret { transition: left 0.1s ease, top 0.1s ease; }
[data-smooth-caret='fast'] .caret { transition: left 0.05s ease, top 0.05s ease; }

/* JS puts left at the letter's left edge; the box styles cover the whole letter */
[data-caret='block'] .caret,
[data-caret='outline'] .caret,
[data-caret='underline'] .caret { width: 1ch; border-radius: 0.12em; }
/* the pace ghost follows your caret style, in --sub */
.caret.pace { --c-caret: var(--sub); }
.caret.pace[hidden] { display: none; }
[data-caret='block'] .caret { background: color-mix(in srgb, var(--c-caret) 32%, transparent); }
[data-caret='outline'] .caret { background: transparent; box-shadow: inset 0 0 0 2px var(--c-caret); }
[data-caret='underline'] .caret { background: transparent; }
[data-caret='underline'] .caret::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; border-radius: 2px; background: var(--c-caret);
}
[data-caret='off'] .caret { visibility: hidden; }

/* ---------- input feedback ---------- */
/* hidden extras keep a zero-width box so the caret still lands right after the word */
[data-hide-extra] .words .c.extra { color: transparent; letter-spacing: -1ch; }

/* typos: <span class="c bad" data-typed="x">expected</span> */
[data-typos='below'] .words .c.bad[data-typed] { position: relative; }
[data-typos='below'] .words .w.err-word { text-decoration: none; }
[data-typos='below'] .words .c.bad[data-typed]::after {
  content: attr(data-typed);
  position: absolute; left: -0.5em; right: -0.5em; top: calc(100% - 0.14em);
  font-size: 0.5em; line-height: 1; text-align: center;
  color: var(--err); opacity: 0.85; pointer-events: none;
}
[data-typos='replace'] .words .c.bad[data-typed] { position: relative; color: transparent; }
[data-typos='replace'] .words .c.bad[data-typed]::after {
  content: attr(data-typed);
  position: absolute; left: 0; top: 0; line-height: normal;
  color: var(--err); pointer-events: none;
}

/* blind mode goes last so it beats colours and typo hints */
html[data-blind] .words .c.bad, html[data-blind] .words .c.bad[data-typed] { color: var(--c-typed); }
html[data-blind] .words .c.bad::after { content: none; }
html[data-blind] .words .c.extra { color: transparent; letter-spacing: -1ch; }
[data-blind] .words .w.err-word { text-decoration: none; }

/* ---------- hide elements ---------- */
[data-hide-wpm] .hud-wpm,
[data-hide-acc] .hud-acc,
[data-hide-timer] .hud-time,
[data-hide-streak] .hud-streak,
[data-hide-rivals] .rival-gap,
[data-hide-keytips] .ohint,
[data-hide-keytips] .cta kbd,
[data-hide-keytips] .ghost kbd,
[data-hide-keytips] .foot span:has(> kbd),
[data-hide-keytips] .key-tip { display: none !important; }

/* ================= settings page ================= */
.st { display: grid; gap: 26px; min-width: 0; }
.st > *, .st-layout > *, .st-main > * { min-width: 0; }
.st-head { display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap; }
.st-head h2 { font-size: 34px; font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.st-head p { color: var(--sub); font-size: 12.5px; display: flex; align-items: center; gap: 8px; margin-left: auto; }
.st-head p .ic { color: var(--accent); }

.st-layout { display: grid; grid-template-columns: 188px minmax(0, 1fr); gap: 40px; align-items: start; }

/* left rail: search + quick nav */
.st-rail { position: sticky; top: 20px; display: grid; gap: 14px; min-width: 0; }
.st-search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 12px; background: var(--bg-2); color: var(--sub); transition: box-shadow 0.15s; }
.st-search:focus-within { box-shadow: 0 0 0 1.5px var(--accent); color: var(--text); }
.st-search input { flex: 1; width: 100%; min-width: 0; background: none; border: 0; outline: 0; font-size: 13px; color: var(--text); }
.st-search input::placeholder { color: var(--sub); }
.st-search kbd { font-size: 10px; padding: 0 5px; }
.st-nav { display: grid; gap: 2px; }
.st-nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; color: var(--sub); font-size: 13px; transition: color 0.15s, background 0.15s; white-space: nowrap; }
.st-nav a:hover { color: var(--text); }
.st-nav a.on { color: var(--text); background: var(--bg-2); }
.st-nav a.on .ic { color: var(--accent); }
.st-nav a.dim { opacity: 0.35; }
.st-nav a.danger.on .ic { color: var(--err); }

/* live preview strip */
.st-preview { position: sticky; top: 12px; z-index: 4; background: var(--bg-2); border-radius: 18px; padding: 14px 20px 16px; box-shadow: 0 0 0 8px var(--bg); display: grid; gap: 10px; }
.st-preview .bar { display: flex; align-items: center; gap: 22px; min-height: 30px; }
.st-preview .hud { gap: 22px; min-height: 0; }
.st-preview .hud .big { font-size: 20px; }
.st-preview .hud .lbl { font-size: 9.5px; }
.st-preview .hud .hud-streak { display: flex; align-items: flex-end; gap: 6px; }
.st-preview .hud .rival-gap .big { color: var(--ok); }
.st-preview .tag { margin-left: auto; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--sub); display: flex; align-items: center; gap: 6px; }
.st-preview .tag i { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.st-preview .words-wrap { padding: 0; overflow: hidden; }
.st-preview .words { height: calc(var(--type-px) * var(--type-scale, 1) * 1.6 * 2); }
.st-preview .words #inner { display: flex; flex-wrap: wrap; }
[data-tape]:not([data-tape='off']) .st-preview .words #inner { flex-wrap: nowrap; }
.st-preview .hint { font-size: 11.5px; color: var(--sub); display: flex; gap: 14px; flex-wrap: wrap; }
.st-preview .hint b { color: var(--text); font-weight: 500; }

/* sections */
.st-main { display: grid; gap: 8px; min-width: 0; }
.st-sec { display: grid; scroll-margin-top: 210px; padding-top: 22px; }
.st-sec > h3 { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; letter-spacing: -0.03em; color: var(--sub); padding: 0 0 10px; }
.st-sec > h3 .ic { color: var(--sub); }
.st-sec[hidden] { display: none; }

.st-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 10px 32px; align-items: center; padding: 14px 0; border-top: 1px solid color-mix(in srgb, var(--line) 55%, transparent); }
.st-row:first-of-type { border-top: 0; }
.st-row[hidden] { display: none; }
.st-row.full, .st-row.wide { grid-template-columns: 1fr; }
.st-row.full .ctl, .st-row.wide .ctl { display: block; }
.st-row.wide .st-btns { display: grid; grid-template-columns: repeat(var(--cols, var(--n, 4)), minmax(0, 1fr)); width: 100%; }
.st-row.wide .st-btns.fonts { --cols: 4; }
.st-row.wide .st-btns button { max-width: none; }
.st-row .t { font-size: 14px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; }
.st-row .t .badge { font-size: 9.5px; font-weight: 500; letter-spacing: 0.08em; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); text-transform: uppercase; }
.st-row .d { font-size: 12.5px; color: var(--sub); margin-top: 2px; line-height: 1.45; }
.st-row .ctl { display: flex; justify-content: flex-end; align-items: center; min-width: 0; }
.st-row.off { opacity: 0.4; }
.st-row.off .ctl { pointer-events: none; }
.st-row mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; }

/* button group */
.st-btns { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.st-btns button {
  height: 34px; padding: 0 14px; border-radius: 10px; background: var(--bg-2); color: var(--sub); font-size: 13px;
  transition: color 0.12s, background 0.12s, transform 0.08s; flex: 1 1 auto; min-width: 54px; max-width: 160px; white-space: nowrap;
}
.st-btns button:hover { color: var(--text); background: var(--surface); }
.st-btns button:active { transform: scale(0.96); }
.st-btns button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.st-btns button:focus-visible, .st-switch:focus-visible, .st-theme:focus-visible, .st-act:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.st-btns.fonts button { font-size: 13.5px; }

/* switch */
.st-switch { display: inline-flex; align-items: center; gap: 10px; font-size: 12px; color: var(--sub); }
.st-switch .track { position: relative; width: 44px; height: 24px; border-radius: 999px; background: var(--bg-2); box-shadow: inset 0 0 0 1px var(--line); transition: background 0.18s, box-shadow 0.18s; }
.st-switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--sub); transition: transform 0.2s cubic-bezier(.3,1.4,.5,1), background 0.18s; }
.st-switch[aria-checked='true'] { color: var(--text); }
.st-switch[aria-checked='true'] .track { background: var(--accent); box-shadow: none; }
.st-switch[aria-checked='true'] .track::after { transform: translateX(20px); background: var(--accent-ink); }

/* volume slider */
.st-range { display: flex; align-items: center; gap: 12px; width: min(100%, 340px); }
.st-range .ic { color: var(--sub); cursor: pointer; }
.st-range output { width: 42px; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text); }
.st-range input { flex: 1; min-width: 0; appearance: none; -webkit-appearance: none; height: 6px; border-radius: 6px; outline: 0; cursor: pointer;
  background: linear-gradient(var(--accent), var(--accent)) 0 / var(--pct, 50%) 100% no-repeat, var(--bg-2); }
.st-range input::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--text); border: 4px solid var(--bg); box-shadow: 0 0 0 1.5px var(--accent); }
.st-range input::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--text); border: 4px solid var(--bg); box-shadow: 0 0 0 1.5px var(--accent); }
.st-range input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent); }

/* number stepper */
.st-num { display: inline-flex; align-items: center; background: var(--bg-2); border-radius: 10px; height: 34px; }
.st-num button { width: 34px; height: 34px; display: grid; place-items: center; color: var(--sub); border-radius: 10px; }
.st-num button:hover { color: var(--text); }
.st-num input { width: 56px; text-align: center; background: none; border: 0; outline: 0; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.st-num input::-webkit-outer-spin-button, .st-num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.st-num span { font-size: 11px; color: var(--sub); padding-right: 12px; }

/* theme grid */
.st-themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.st-theme {
  --tb: #000; --ts: #888; --tt: #fff; --ta: #fc0;
  position: relative; display: grid; gap: 10px; text-align: left; padding: 12px 14px 12px; border-radius: 14px; background: var(--tb); color: var(--tt);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tt) 10%, transparent); transition: transform 0.12s, box-shadow 0.15s;
}
.st-theme:hover { transform: translateY(-2px); }
.st-theme.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.st-theme .nm { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 700; }
.st-theme .nm .ic { color: var(--ta); }
.st-theme .sample { font-size: 12px; letter-spacing: 0.01em; white-space: nowrap; overflow: hidden; color: var(--ts); }
.st-theme .sample b { font-weight: 500; color: var(--tt); }
.st-theme .sample i { display: inline-block; width: 2px; height: 1.1em; vertical-align: -0.2em; background: var(--ta); border-radius: 1px; margin: 0 1px; }
.st-theme .dots { display: flex; gap: 5px; }
.st-theme .dots span { width: 12px; height: 12px; border-radius: 50%; }

/* danger zone */
.st-danger { display: grid; gap: 10px; }
.st-acts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.st-act { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 10px; background: var(--bg-2); color: var(--text); font-size: 13px; transition: background 0.12s, color 0.12s; }
.st-act:hover { background: var(--surface); }
.st-act .ic { color: var(--sub); }
.st-act.warn { color: var(--err); }
.st-act.warn .ic { color: var(--err); }
.st-act.warn.armed { background: var(--err); color: var(--bg); }
.st-act.warn.armed .ic { color: var(--bg); }
.st-act.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.st-act.primary .ic { color: var(--accent-ink); }
.st-import { display: grid; gap: 8px; grid-column: 1 / -1; }
.st-import[hidden] { display: none; }
.st-import textarea { width: 100%; min-height: 120px; resize: vertical; background: var(--bg-2); color: var(--text); border: 0; outline: 0; border-radius: 12px; padding: 12px 14px; font: 12px/1.5 'JetBrains Mono', ui-monospace, monospace; box-shadow: inset 0 0 0 1px var(--line); }
.st-import textarea:focus { box-shadow: inset 0 0 0 1.5px var(--accent); }
.st-import .st-acts { justify-content: flex-start; }

.st-empty { color: var(--sub); font-size: 13px; display: grid; justify-items: center; gap: 10px; padding: 50px 0; text-align: center; }
.st-empty .ic { color: var(--sub-2); }
.st-empty[hidden] { display: none; }

@media (max-width: 960px) {
  .st-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .st-rail { position: sticky; top: 0; z-index: 6; background: var(--bg); padding: 8px 0; margin: -8px 0 0; }
  .st-nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; mask-image: linear-gradient(90deg, #000 85%, transparent); }
  .st-nav::-webkit-scrollbar { display: none; }
  .st-nav a { padding: 6px 10px; font-size: 12px; }
  .st-preview { position: static; box-shadow: none; }
  .st-sec { scroll-margin-top: 110px; }
}
@media (max-width: 640px) {
  .st-head h2 { font-size: 28px; }
  .st-head p { margin-left: 0; }
  .st-row { grid-template-columns: 1fr; gap: 10px; }
  .st-row .ctl { justify-content: flex-start; }
  .st-btns { justify-content: flex-start; width: 100%; }
  .st-btns button { padding: 0 10px; min-width: 0; max-width: none; }
  .st-themes { grid-template-columns: repeat(2, 1fr); }
  .st-row.wide .st-btns { --cols: 4; }
  .st-row.wide .st-btns.fonts { --cols: 2; }
  .st-preview { padding: 12px 14px 14px; }
  .st-preview .hud { gap: 14px; }
  .st-preview .tag { display: none; }
  .st-acts { justify-content: flex-start; }
}
