/* ==========================================================================
   /keyboard-typing-test/ — page-specific rules only.
   Everything else comes from /assets/css/design-system.css.
   The typing surface (a scrolling per-character text field with a caret) has
   no equivalent in the shared system, so it is defined here.
   ========================================================================== */

/* --------------------------------------------------------------- controls */

/* The length/mode selector is a segmented control and now uses the shared
   .seg / .seg__btn component (design-system.css §10.1) rather than a local
   pressed state on .btn. The previous rule here made "selected" mean an
   outlined button with an accent underline, while the same state on the
   homepage meant a filled accent plate — one interaction, two answers, on the
   two controls a visitor is most likely to meet in the same session.
   Markup: <div class="seg" role="group" aria-label="Test length">
             <button class="seg__btn" aria-pressed="true" data-mode="15">15 seconds</button> … */

.tt-card > * + * { margin-block-start: var(--space); }

.tt-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  justify-content: space-between;
}

.tt-toolbar__right {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
}

.tt-check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-block-size: 44px;
  font-size: 0.875rem;
  color: var(--text-2);
  cursor: pointer;
}

.tt-check input {
  inline-size: 18px;
  block-size: 18px;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}

.tt-check:hover { color: var(--text); }

/* Fixed-passage mode: the passages already carry punctuation, so the toggle
   does not apply. Explained in the help text as well, never colour alone. */
.tt-check.is-disabled { color: var(--text-3); cursor: not-allowed; }
.tt-check.is-disabled input { cursor: not-allowed; }

/* Live tiles are smaller than the result tiles: they are glanced at, not read. */
.tt-live .metric__value { font-size: clamp(1.25rem, 1rem + 1.2vw, 1.75rem); }

/* ----------------------------------------------------------- typing field */

.tt-field {
  --tt-lh: 1.9;
  position: relative;
  border: 1px solid var(--border-ui);
  border-radius: var(--r);
  background: var(--bg-2);
  padding: clamp(0.75rem, 2.2vw, 1.15rem);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tt-field.is-focused {
  border-color: var(--accent);
  box-shadow: var(--ring);
}

/* Run state is always paired with the wording in .tt-status, never colour alone. */
.tt-field.is-running { background: color-mix(in srgb, var(--accent) 4%, var(--bg-2)); }
.tt-field.is-paused { border-color: var(--warn); }
.tt-field.is-done { border-color: var(--good); }

/* Three visible lines of text; the caret line is kept as the second one. */
.tt-text {
  position: relative;
  block-size: calc(var(--tt-lh) * 3em);
  overflow: hidden;
  font-family: var(--mono);
  font-size: clamp(1rem, 0.92rem + 0.62vw, 1.375rem);
  line-height: var(--tt-lh);
  color: var(--text-2);
  scroll-behavior: auto;
  /* Words are inline-blocks, so breaks happen at the space spans between them. */
  word-break: normal;
  overflow-wrap: normal;
}

.tt-w { display: inline-block; white-space: pre; }

.ch {
  position: relative;
  white-space: pre;
  color: var(--text-2);
  font-weight: 400;
  text-decoration: none;
}

/* Correct / wrong / pending are separable without colour:
   pending = normal weight, correct = bold, wrong = bold + wavy underline.
   The face is monospaced, so a weight change never shifts later characters. */
.ch--correct {
  color: var(--good);
  font-weight: 700;
}

.ch--wrong {
  color: var(--bad);
  font-weight: 700;
  text-decoration: underline wavy;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.ch--pending {
  color: var(--text-2);
  font-weight: 400;
}

/* A mistyped space has no glyph to mark, so give it a body. */
.ch--space.ch--wrong {
  background: color-mix(in srgb, var(--bad) 32%, transparent);
  border-radius: 2px;
}

.ch--space.ch--correct { background: none; }

/* Caret: a bar drawn on the leading edge of the next character to type. */
.ch--caret::before,
.ch--caret-end::after {
  content: "";
  position: absolute;
  inset-block: -0.08em;
  inline-size: 2px;
  background: var(--accent);
  border-radius: 1px;
  animation: tt-blink 1.05s steps(1, end) infinite;
}

.ch--caret::before { inset-inline-start: -1px; }
.ch--caret-end::after { inset-inline-end: -1px; }

@keyframes tt-blink {
  0%, 55% { opacity: 1; }
  56%, 100% { opacity: 0.15; }
}

/* The real input. Transparent and stretched over the text so a tap anywhere
   focuses it (and summons a touchscreen keyboard). It is never allowed to
   hold text: tool.js cancels every insertion and clears the value. */
.tt-capture {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  min-block-size: 0;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: transparent;
  caret-color: transparent;
  -webkit-text-fill-color: transparent;
  /* 16px stops iOS Safari zooming the page when the field takes focus. */
  font-size: 16px;
  line-height: 1;
  resize: none;
  overflow: hidden;
  cursor: text;
  z-index: 2;
}

/* The field carries the ring via .is-focused, so the bare textarea outline
   would double it up. Focus is never hidden — it moves to the wrapper. */
.tt-capture:focus,
.tt-capture:focus-visible { outline: none; }

.tt-capture::selection { background: transparent; }

.tt-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 1rem;
  margin: 0;
  text-align: center;
  border-radius: var(--r);
  background: color-mix(in srgb, var(--bg-2) 78%, transparent);
  backdrop-filter: blur(1px);
  color: var(--text-2);
  font-size: 0.9375rem;
  pointer-events: none;
}

.tt-overlay span {
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border-ui);
  border-radius: 999px;
  background: var(--surface);
}

/* ------------------------------------------------------------ legend/status */

.tt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--text-2);
}

.tt-legend__item { display: inline-flex; align-items: center; gap: 0.35rem; }

.tt-legend__caret {
  display: inline-block;
  inline-size: 2px;
  block-size: 1em;
  background: var(--accent);
  border-radius: 1px;
  vertical-align: text-bottom;
}

.tt-status {
  font-size: 0.875rem;
  color: var(--text-2);
  min-block-size: 1.4em;
  margin: 0;
}

.tt-status[data-state="running"] { color: var(--accent); }
.tt-status[data-state="paused"] { color: var(--warn); }
.tt-status[data-state="done"] { color: var(--good); }
.tt-status[data-state="blocked"] { color: var(--bad); }

.tt-mobile-note { margin-block-start: var(--space); }

.tt-quality {
  font-size: 0.9375rem;
  color: var(--text-2);
  margin-block-start: var(--space);
}

.tt-quality b { color: var(--text); }

/* ----------------------------------------------------------------- charts */

.tt-charts {
  display: grid;
  gap: var(--space);
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  .tt-charts { grid-template-columns: 1fr 1fr; }
}

/* ---------------------------------------------------------------- per-key */

.tt-perkey-note {
  color: var(--text-2);
  max-inline-size: var(--maxw-prose);
  margin-block-end: var(--space);
}

.tbl tbody tr.is-slow th,
.tbl tbody tr.is-slow td { background: color-mix(in srgb, var(--amber) 9%, transparent); }

.tt-key-glyph {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--text);
}

.tt-variant { max-inline-size: 16rem; margin-block-end: 0.85rem; }

.tt-map { margin-block-end: 0.6rem; }

.tt-swatch {
  display: inline-block;
  inline-size: 12px;
  block-size: 12px;
  border-radius: 3px;
  vertical-align: -1px;
  margin-inline-end: 0.15rem;
  border: 1px solid var(--border-ui);
}

.tt-swatch--slow { background: color-mix(in srgb, var(--amber) 40%, var(--surface-2)); border-color: var(--amber); }
.tt-swatch--typo { background: color-mix(in srgb, var(--bad) 32%, var(--surface-2)); border-color: var(--bad); }

/* Marks applied to the shared keyboard map by tool.js. Each carries a printed
   label (SLOW / ERR) as well as a colour, so neither state is colour-only. */
.kbd-key--slow {
  background: color-mix(in srgb, var(--amber) 26%, var(--surface-2));
  border-color: var(--amber);
  color: var(--text);
}

.kbd-key--typo {
  background: color-mix(in srgb, var(--bad) 24%, var(--surface-2));
  border-color: var(--bad);
  color: var(--text);
}

/* Slow + mistyped: keep the amber body, add a hatched edge for the error. */
.kbd-key--slow.kbd-key--typo {
  background-image: repeating-linear-gradient(
    -45deg,
    color-mix(in srgb, var(--bad) 34%, transparent) 0 3px,
    transparent 3px 7px
  );
}

.kbd-key--slow .kbd-key__stat,
.kbd-key--typo .kbd-key__stat { color: var(--text); font-weight: 700; }

/* --------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  .ch--caret::before,
  .ch--caret-end::after { animation: none; }
  .tt-field { transition: none; }
}
