/* ============================================================ Typerider · CSS */

:root {
  /* The navbar is pure white; the page sits on a lighter, airier tint so the
     bar reads as a distinct surface floating above it. */
  --bg: #F4F6FB;
  --bg-soft: #EDF1FA;
  --surface: #FFFFFF;
  --ink: #0E1524;
  --ink-soft: #3A4358;
  --muted: #6B7488;
  --line: #E3E8F3;
  --brand: #4F46E5;
  --brand-dark: #3D35C4;
  --brand-soft: #EEF0FE;
  --good: #15A34A;
  --bad: #E11D48;
  --gold: #E9A100;

  --radius: 14px;
  --radius-lg: 22px;
  --shadow-nav: 0 1px 0 rgba(14, 21, 36, .05), 0 10px 24px -18px rgba(14, 21, 36, .55);
  --shadow-card: 0 1px 2px rgba(14, 21, 36, .04), 0 12px 32px -24px rgba(14, 21, 36, .5);

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }

h1, h2, h3 { line-height: 1.15; letter-spacing: -.02em; margin: 0; }

.wrap { width: min(1080px, 100% - 2.5rem); margin-inline: auto; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------- navbar */

.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  box-shadow: var(--shadow-nav);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 68px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
  font-size: 1.12rem;
  letter-spacing: -.025em;
  color: var(--ink);
  text-decoration: none;
}

.brand .mark {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-family: var(--mono);
  font-size: .95rem;
  font-weight: 700;
  box-shadow: 0 6px 14px -8px var(--brand);
}

.brand .mark::after { content: "_"; animation: blink 1.1s steps(1) infinite; }

@keyframes blink { 50% { opacity: 0; } }

.nav-links { display: flex; align-items: center; gap: 1.4rem; }

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: .93rem;
  font-weight: 500;
}
.nav-link:hover { color: var(--ink); }

/* the one and only play button on the site */
.btn-play {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: var(--brand);
  color: #fff;
  font-weight: 650;
  font-size: .93rem;
  letter-spacing: .01em;
  text-decoration: none;
  padding: .68rem 1.15rem;
  border-radius: 999px;
  border: 0;
  cursor: pointer;
  box-shadow: 0 10px 20px -12px var(--brand);
  transition: transform .12s ease, background .12s ease, box-shadow .12s ease;
}
.btn-play:hover { background: var(--brand-dark); transform: translateY(-1px); box-shadow: 0 14px 24px -12px var(--brand); }
.btn-play:active { transform: translateY(0); }
.btn-play .arrow { transition: transform .12s ease; }
.btn-play:hover .arrow { transform: translateX(2px); }

/* --------------------------------------------------------------------- hero */

.hero { padding: clamp(3rem, 8vw, 5.5rem) 0 clamp(2rem, 5vw, 3rem); }

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: clamp(2rem, 5vw, 4rem);
  align-items: center;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: .78rem;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: .35rem .7rem;
  border-radius: 999px;
  margin-bottom: 1.1rem;
}

.hero h1 { font-size: clamp(2.3rem, 5.5vw, 3.5rem); font-weight: 750; }
.hero h1 em { font-style: normal; color: var(--brand); }

.lede {
  color: var(--ink-soft);
  font-size: clamp(1.02rem, 1.6vw, 1.14rem);
  max-width: 46ch;
  margin: 1.1rem 0 1.6rem;
}

.hero-note {
  display: inline-flex;
  align-items: flex-start;
  gap: .55rem;
  color: var(--muted);
  font-size: .92rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .5rem .95rem;
}
.hero-note b { color: var(--ink); font-weight: 650; }

.facts { display: flex; gap: 2rem; margin-top: 2rem; flex-wrap: wrap; }
.fact strong { display: block; font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.fact span { color: var(--muted); font-size: .85rem; }

/* demo card in the hero */
.demo {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--line);
  padding: 1.5rem;
}
.demo-head {
  display: flex; align-items: center; justify-content: space-between;
  color: var(--muted); font-size: .8rem; margin-bottom: 1rem;
}
.dots { display: flex; gap: .35rem; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); display: block; }
.demo-line {
  font-family: var(--mono);
  font-size: clamp(.95rem, 2.1vw, 1.08rem);
  line-height: 1.9;
  word-break: break-word;
}
.demo-line .ok { color: var(--good); }
.demo-line .rest { color: var(--muted); opacity: .65; }
.demo-line .caret {
  display: inline-block; width: 2px; height: 1.15em; vertical-align: -.2em;
  background: var(--brand); animation: blink 1.1s steps(1) infinite;
}
.demo-foot {
  display: flex; gap: 1.4rem; margin-top: 1.2rem; padding-top: 1rem;
  border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem;
}
.demo-foot b { color: var(--ink); font-family: var(--mono); }

/* ----------------------------------------------------------------- sections */

.section { padding: clamp(2.5rem, 6vw, 4rem) 0; }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.6rem; flex-wrap: wrap; }
.section-head h2 { font-size: clamp(1.5rem, 3vw, 1.9rem); font-weight: 700; }
.section-head p { color: var(--muted); margin: .4rem 0 0; font-size: .95rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

/* ------------------------------------------------------------- leaderboard */

.board { overflow: hidden; }

.board-champion {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  background: linear-gradient(100deg, #FFF9EC, var(--surface) 65%);
  border-bottom: 1px solid var(--line);
}
.champion-medal {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  background: #FDF0CE; color: var(--gold); font-size: 1.3rem;
  flex: none;
}
.champion-body { min-width: 0; flex: 1; }
.champion-body .label { font-size: .74rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.champion-body .who { font-size: 1.2rem; font-weight: 700; letter-spacing: -.015em; overflow-wrap: anywhere; }
.champion-score { text-align: right; flex: none; }
.champion-score b { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; }
.champion-score span { display: block; color: var(--muted); font-size: .78rem; }

table.rows { width: 100%; border-collapse: collapse; }
table.rows th {
  text-align: left; font-size: .74rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); font-weight: 650; padding: .8rem 1.5rem; border-bottom: 1px solid var(--line);
}
table.rows td { padding: .8rem 1.5rem; border-bottom: 1px solid var(--line); font-size: .95rem; }
table.rows tr:last-child td { border-bottom: 0; }
table.rows tr.is-you td { background: var(--brand-soft); }
.col-rank { width: 3.5rem; color: var(--muted); font-family: var(--mono); }
.col-num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.col-num b { font-weight: 700; }
.name-cell { font-weight: 600; overflow-wrap: anywhere; }
.track-pill {
  display: inline-block; font-size: .74rem; color: var(--muted);
  background: var(--bg-soft); border-radius: 999px; padding: .15rem .55rem;
}
.board-empty { padding: 2.5rem 1.5rem; text-align: center; color: var(--muted); }
.board-meta {
  padding: .7rem 1.5rem;
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
  text-align: right;
  color: var(--muted);
  font-size: .78rem;
}

/* ---------------------------------------------------------------- variations */

.tracks { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.track-card { padding: 1.4rem; display: flex; flex-direction: column; gap: .5rem; }
.track-card .lang {
  align-self: flex-start; font-size: .72rem; font-weight: 650; letter-spacing: .07em;
  text-transform: uppercase; color: var(--brand-dark); background: var(--brand-soft);
  padding: .2rem .55rem; border-radius: 999px;
}
.track-card h3 { font-size: 1.12rem; font-weight: 700; margin-top: .2rem; }
.track-card p { margin: 0; color: var(--muted); font-size: .92rem; }
.track-card .count { margin-top: auto; padding-top: .8rem; color: var(--muted); font-size: .82rem; font-family: var(--mono); }

/* ----------------------------------------------------------------- how / faq */

.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; }
.step { padding: 1.3rem; }
.step .n {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--ink); color: #fff; font-size: .82rem; font-weight: 700; margin-bottom: .8rem;
}
.step h3 { font-size: 1rem; font-weight: 680; margin-bottom: .25rem; }
.step p { margin: 0; color: var(--muted); font-size: .9rem; }

/* -------------------------------------------------------------------- footer */

.footer {
  border-top: 1px solid var(--line);
  margin-top: 2rem;
  padding: 2rem 0;
  color: var(--muted);
  font-size: .87rem;
}
.footer-inner { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* ================================================================ play page */

.play-main { padding: clamp(1.5rem, 4vw, 3rem) 0 3rem; }

.stage { display: none; }
.stage.is-active { display: block; }
#stage-game.is-active, #stage-result.is-active { padding-top: clamp(0rem, 4vh, 3rem); }

.panel {
  max-width: 640px; margin-inline: auto; padding: clamp(1.4rem, 4vw, 2.2rem);
}
.panel h1 { font-size: clamp(1.5rem, 4vw, 2rem); font-weight: 730; }
.panel > p.sub { color: var(--muted); margin: .5rem 0 1.6rem; }

.field label { display: block; font-size: .82rem; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: .45rem; }
.field input[type="text"] {
  width: 100%; font: inherit; font-size: 1.05rem; padding: .85rem 1rem;
  border: 1.5px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink);
}
.field input[type="text"]:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

.suggestions { display: flex; gap: .5rem; margin-top: .7rem; flex-wrap: wrap; }
.suggestions .hint { flex-basis: 100%; color: var(--muted); font-size: .82rem; margin-bottom: .1rem; }
.chip {
  flex: 1 1 0; min-width: 0; font: inherit; font-size: .9rem; font-weight: 600;
  padding: .55rem .5rem; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink-soft); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.chip:hover { border-color: var(--brand); color: var(--brand-dark); background: var(--brand-soft); }

.btn {
  font: inherit; font-weight: 650; cursor: pointer; border-radius: var(--radius);
  padding: .85rem 1.3rem; border: 1.5px solid transparent; background: var(--brand); color: #fff;
  transition: background .12s ease, transform .12s ease;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--ink); }
.btn-row { display: flex; gap: .7rem; margin-top: 1.4rem; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

.error { color: var(--bad); font-size: .88rem; margin-top: .6rem; min-height: 1.2em; }

/* track picker */
.picker { display: grid; gap: .8rem; margin-top: 1.2rem; }
.pick {
  display: flex; align-items: center; gap: 1rem; width: 100%; text-align: left;
  font: inherit; cursor: pointer; padding: 1.1rem 1.2rem;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
  transition: border-color .12s ease, transform .12s ease, box-shadow .12s ease;
}
.pick:hover { border-color: var(--brand); transform: translateY(-1px); box-shadow: var(--shadow-card); }
.pick .idx {
  display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 11px;
  background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; font-family: var(--mono);
}
.pick .body { min-width: 0; flex: 1; }
.pick .body strong { display: block; font-size: 1.02rem; font-weight: 680; }
.pick .body span { color: var(--muted); font-size: .88rem; }
.pick .meta { flex: none; color: var(--muted); font-size: .78rem; text-align: right; font-family: var(--mono); }

/* ------------------------------------------------------------------ the game */

.game-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-bottom: 1rem; flex-wrap: wrap;
}
.game-title { font-weight: 700; letter-spacing: -.015em; }
.game-title span { display: block; color: var(--muted); font-size: .82rem; font-weight: 500; letter-spacing: 0; }
.live { display: flex; gap: 1.4rem; }
.live div { text-align: right; }
.live b { display: block; font-family: var(--mono); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.live span { color: var(--muted); font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; }

.progress { display: flex; gap: .3rem; margin-bottom: 1rem; }
.progress i {
  flex: 1; height: 5px; border-radius: 999px; background: var(--line); display: block;
  transition: background .2s ease;
}
.progress i.done { background: var(--brand); }
.progress i.current { background: var(--brand); opacity: .45; }

.type-card { padding: clamp(1.3rem, 4vw, 2rem); }

.prompt-line {
  font-family: var(--mono);
  font-size: clamp(1.05rem, 3.4vw, 1.45rem);
  line-height: 1.95;
  letter-spacing: .01em;
  word-break: break-word;
  min-height: 2.6em;
}
.prompt-line .ch { color: var(--muted); opacity: .55; transition: color .05s linear; }
.prompt-line .ch.ok { color: var(--ink); opacity: 1; }
.prompt-line .ch.bad { color: var(--bad); opacity: 1; background: rgba(225, 29, 72, .1); border-radius: 3px; }
.prompt-line .ch.at { box-shadow: inset 2px 0 0 var(--brand); border-radius: 1px; }
.prompt-line .ch.space.bad { background: rgba(225, 29, 72, .22); }

.typing-input {
  width: 100%; font-family: var(--mono);
  font-size: clamp(1rem, 3vw, 1.15rem);
  margin-top: 1.2rem; padding: .8rem 1rem;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--ink);
}
.typing-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); background: #fff; }

.type-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-top: 1rem; color: var(--muted); font-size: .86rem; flex-wrap: wrap;
}
.kbd {
  font-family: var(--mono); font-size: .78rem; background: var(--bg-soft);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: .1rem .4rem; color: var(--ink-soft);
}
.next-btn { display: none; }

/* ------------------------------------------------------------------- result */

.result-hero { text-align: center; padding: 2rem 1.5rem 1.5rem; }
.result-hero .who { color: var(--muted); font-size: .95rem; }
.result-wpm { font-family: var(--mono); font-size: clamp(3rem, 12vw, 4.5rem); font-weight: 700; line-height: 1; letter-spacing: -.04em; }
.result-wpm small { font-size: .28em; letter-spacing: .1em; color: var(--muted); margin-left: .4rem; }
.result-stats { display: flex; justify-content: center; gap: 2.2rem; margin-top: 1.4rem; flex-wrap: wrap; }
.result-stats div { text-align: center; }
.result-stats b { display: block; font-family: var(--mono); font-size: 1.25rem; }
.result-stats span { color: var(--muted); font-size: .78rem; letter-spacing: .05em; text-transform: uppercase; }
/* Where the missing accuracy went. Green when there is nothing to confess. */
.result-mistakes {
  margin-top: .9rem; font-size: .85rem; color: var(--bad); line-height: 1.5;
}
.result-mistakes.is-clean { color: var(--muted); }

.result-badge {
  display: inline-block; margin-top: 1.2rem; padding: .45rem .9rem; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-dark); font-weight: 650; font-size: .88rem;
}
.result-badge.is-error { background: #FDE9EE; color: var(--bad); }
.result-actions { display: flex; gap: .7rem; justify-content: center; padding: 0 1.5rem 1.8rem; flex-wrap: wrap; }

/* ------------------------------------------------------------------ mobile */

@media (max-width: 860px) {
  .hero-grid { grid-template-columns: 1fr; }
  .nav-links .nav-link { display: none; }
  .facts { gap: 1.4rem; }
  table.rows th:nth-child(4), table.rows td:nth-child(4) { display: none; }
  table.rows th, table.rows td { padding-inline: 1rem; }
  .board-champion { padding-inline: 1rem; }
}

@media (max-width: 560px) {
  .wrap { width: calc(100% - 1.8rem); }
  .nav-inner { height: 60px; }
  .brand span.word { display: none; }
  .live { gap: 1rem; }
  .live b { font-size: 1rem; }
  .result-stats { gap: 1.4rem; }
  /* Drop the story column too: rider names need the room more than it does. */
  table.rows th:nth-child(3), table.rows td:nth-child(3) { display: none; }
  .hero-note { align-items: flex-start; line-height: 1.5; }
  .pick { padding: .9rem 1rem; gap: .75rem; }
  .pick .meta { font-size: .72rem; }
}

/* Touch devices get an explicit "next line" button, because a soft keyboard's
   return key is easy to miss and on some of them does not fire at all. */
@media (hover: none) and (pointer: coarse) {
  .next-btn { display: inline-flex; }
  .type-foot .enter-hint { display: none; }
}

/* Installed as an app: no browser chrome, so the nav needs the safe-area pad
   and the game gets the full screen. */
@media (display-mode: standalone) {
  .nav { padding-top: env(safe-area-inset-top); }
  .install-hint { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

.hint-msg { color: var(--bad); font-size: .86rem; min-height: 1.2em; }
