/* ==========================================================================
   Touch Type Racer - theme
   Fuses play.typeracer.com (racing blue, car tracks, results table) with
   KTouch (clean panel layout, colourful finger-coded keyboard, lesson tree).
   ========================================================================== */

:root {
  /* TypeRacer-inspired racing palette */
  --ttr-blue: #2f6fed;
  --ttr-blue-dark: #1b4bb8;
  --ttr-blue-soft: #e8f0ff;
  --ttr-accent: #ffcc33;
  --ttr-green: #2fae6b;
  --ttr-red: #e5484d;

  /* KTouch-inspired neutral surfaces */
  --bg: #eef1f6;
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --ink: #1d2433;
  --ink-soft: #5b6577;
  --line: #d8dee9;
  --line-soft: #eaeef4;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(29, 36, 51, 0.08);
  --shadow-sm: 0 2px 8px rgba(29, 36, 51, 0.06);
  --mono: 'DejaVu Sans Mono', 'Cascadia Mono', 'Consolas', 'Menlo', monospace;
  --sans: 'Segoe UI', system-ui, -apple-system, 'Roboto', 'Helvetica Neue', sans-serif;

  /*
   * The header's geometry, named. The page below the header is narrower than it and
   * has to line up with the menu, so the arithmetic lives in one place instead of
   * being guessed at in two:
   *
   *   the menu's left edge = bar padding + brand + gap + the menu's own offset
   *   the page's left edge = that, less the page's own padding
   *
   * Change any of the first four values and --shell-inset follows.
   */
  --topbar-pad: 20px;
  --brand-w: 240px;
  --topbar-gap: 18px;
  --nav-offset: 8px;
  --page-pad: 20px;
  --shell-inset: calc(
    var(--topbar-pad) + var(--brand-w) + var(--topbar-gap) + var(--nav-offset) - var(--page-pad)
  );
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--ttr-blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0 0 0.4em;
  line-height: 1.2;
}

button {
  font-family: inherit;
}

/* ------------------------------------------------------------------ layout */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  /*
   * Page backdrop: a faint diagonal "tarmac weave" painted from an inline SVG
   * background-image. Keeping the texture in the CSS means no extra asset
   * requests, no broken images behind a CDN, and it tiles at any zoom level.
   */
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64'%3E%3Cg fill='none' stroke='%23dde4f0' stroke-width='1'%3E%3Cpath d='M0 64L64 0'/%3E%3Cpath d='M-16 16L16-16M48 80L80 48'/%3E%3C/g%3E%3C/svg%3E");
  background-attachment: fixed;
}

/*
 * The page below the header is capped at three quarters of the screen, while the
 * header itself keeps the full width. Above the aligned breakpoint it also starts
 * exactly where the menu starts, so the home page's first card sits under the
 * "Home" link instead of floating in the middle of the screen (see --shell-inset).
 *
 * Below the first breakpoint there is nothing to cap - three quarters of a phone
 * is not a layout - so the page fills the width with its own padding, which is
 * what the responsive block at the end of this file assumes.
 */
.container {
  width: 100%;
  margin: 0 auto;
  padding: 24px var(--page-pad) 56px;
}

@media (min-width: 960px) {
  .container {
    max-width: 75%;
  }
}

@media (min-width: 1200px) {
  /* A fixed brand width is what makes the menu's left edge predictable enough for
     the page below to line up with it. */
  .brand {
    width: var(--brand-w);
  }

  .container {
    margin-left: var(--shell-inset);
    margin-right: auto;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.panel + .panel {
  margin-top: 18px;
}

/* Keyword-bearing page heading (Learn to Type) - real <h1> for search engines. */
.page-intro h1,
.page-title {
  font-size: 1.55rem;
  margin-bottom: 6px;
}

.page-title {
  margin-bottom: 14px;
}

.panel-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.grid {
  display: grid;
  gap: 18px;
}

/*
 * Grid items default to min-width: auto, which lets one wide child (a table, a
 * long word) push the whole track wider than the screen and give the page a
 * horizontal scrollbar. Every panel may shrink; the few children that can really
 * be too wide - the tables - scroll inside themselves instead.
 */
.grid > * {
  min-width: 0;
}

.grid.two {
  grid-template-columns: 2fr 1fr;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 880px) {
  .grid.two,
  .grid.cols-2,
  .grid.cols-3 {
    grid-template-columns: 1fr;
  }

  /* Four features side by side would be unreadable: two is the tablet shape. */
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .grid.cols-4 {
    grid-template-columns: 1fr;
  }
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.muted {
  color: var(--ink-soft);
}

.small {
  font-size: 0.85rem;
}

.center {
  text-align: center;
}

/* ------------------------------------------------------------------ header */

.topbar {
  background: linear-gradient(180deg, #2f6fed 0%, #245ad0 100%);
  color: #fff;
  border-bottom: 3px solid var(--ttr-accent);
  box-shadow: var(--shadow-sm);
}

/*
 * The header spans the full width, with the menu between the brand and the
 * player's name and speed. Its items are never squeezed: on a narrow screen the
 * whole menu moves into a drawer instead (see the media query at the end of this
 * section), so neither the menu nor a long player name has to give way.
 */
.topbar-inner {
  width: 100%;
  margin: 0 auto;
  padding: 12px var(--topbar-pad);
  display: flex;
  align-items: center;
  gap: var(--topbar-gap);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: 0.2px;
  color: #fff;
  /* The wordmark stays on one line: above the aligned breakpoint the brand holds a
     fixed width, so the page below can line up with the menu. */
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
}

.brand .logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--ttr-accent);
  color: #245ad0;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  font-weight: 900;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: var(--nav-offset);
  flex: 1 1 auto;
  min-width: 0;
}

/*
 * A menu item is never squeezed. It keeps its own width and, when the bar runs
 * out of room, wraps onto the next line as a whole word - never mid-label, which
 * is what made "Typing Race" and "Leaderboard" read as one jumbled run.
 */
.nav a {
  color: #e8f0ff;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  flex: 0 0 auto;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.14);
  text-decoration: none;
}

.nav a.active {
  background: #fff;
  color: var(--ttr-blue-dark);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  /* The player side keeps its own shape as well; a long name is cut short by
     the rule below instead of pushing the menu around. */
  flex: 0 0 auto;
  min-width: 0;
}

.pill {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 5px 12px;
  font-weight: 600;
}

/*
 * The top-bar name and speed are one hoverable group. It sits at the right edge
 * of the bar, so its summary card opens leftwards and stays on screen.
 */
.topbar-stats {
  gap: 8px;
}

/*
 * The player's name can be long. It is cut with an ellipsis rather than taking
 * room from the menu: the name and the speed share the right-hand edge of the
 * bar, and the name is the one that gives way.
 */
.topbar-stats > .pill:first-child {
  display: inline-block;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.topbar-stats .player-card {
  left: auto;
  right: 0;
}

/*
 * ------------------------------------------------------------------ the menu
 *
 * Above the breakpoint the menu is a row in the top bar. Below it, the same
 * markup becomes a drawer that slides in over the page. The stylesheet only ever
 * hides the row under the "js" class the layout sets on <html>, so a browser with
 * no JavaScript keeps a plain wrapping row of links and the menu can never become
 * unreachable.
 *
 * Five menu items plus a brand and a player's name simply do not fit a phone, so
 * the drawer - not a squeezed row - is what makes the header usable there.
 */

.nav-toggle,
.nav-close,
.nav-backdrop {
  display: none;
}

@media (max-width: 1000px) {
  /*
   * The bar keeps the brand, the player and the menu handle. It is deliberately
   * allowed to wrap: if a long name and its speed still cannot share one line, the
   * player block drops to a second row rather than pushing the handle off screen.
   */
  .js .brand {
    order: 1;
  }

  .js .topbar-user {
    order: 2;
    margin-left: auto;
  }

  /* A phone-sized bar wants a shorter name than a desktop one. */
  .topbar-stats > .pill:first-child {
    max-width: 150px;
  }

  .js .nav-toggle {
    order: 3;
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 38px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.38);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.14);
    cursor: pointer;
  }

  .js .nav-toggle:hover {
    background: rgba(255, 255, 255, 0.26);
  }

  /* Three bars, painted in CSS: no icon font and no extra request. */
  .js .nav-toggle-bar,
  .js .nav-toggle-bar::before,
  .js .nav-toggle-bar::after {
    display: block;
    width: 19px;
    height: 2px;
    border-radius: 2px;
    background: #fff;
    content: '';
  }

  .js .nav-toggle-bar {
    position: relative;
  }

  .js .nav-toggle-bar::before {
    position: absolute;
    top: -6px;
  }

  .js .nav-toggle-bar::after {
    position: absolute;
    top: 6px;
  }

  .js .nav {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 70;
    width: min(320px, 86vw);
    margin: 0;
    padding: 12px;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 2px;
    overflow-y: auto;
    background: #fff;
    border-left: 1px solid var(--line);
    box-shadow: -20px 0 48px rgba(15, 23, 42, 0.32);
    transform: translateX(105%);
    transition: transform 0.22s ease;
  }

  .js .nav.is-open {
    transform: none;
  }

  .js .nav-close {
    display: grid;
    place-items: center;
    align-self: flex-end;
    width: 36px;
    height: 36px;
    margin-bottom: 6px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    color: var(--ink);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
  }

  /* The drawer is a white panel, so the links use the page palette, not the
     top bar's white-on-blue. */
  .js .nav a {
    flex: none;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    color: var(--ink);
    font-size: 1rem;
  }

  .js .nav a:hover {
    background: var(--panel-2);
    text-decoration: none;
  }

  .js .nav a.active {
    background: var(--ttr-blue-soft);
    color: var(--ttr-blue-dark);
  }

  .js .nav-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(15, 23, 42, 0.5);
  }

  /* An open drawer owns the screen: the page behind it must not scroll away. */
  body.menu-open {
    overflow: hidden;
  }
}

/* ----------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:hover:not(:disabled) {
  box-shadow: var(--shadow-sm);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--ttr-blue);
  border-color: var(--ttr-blue);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--ttr-blue-dark);
}

.btn.gold {
  background: var(--ttr-accent);
  border-color: #e6b800;
  color: #3a2f00;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--panel-2);
}

.btn.danger {
  background: var(--ttr-red);
  border-color: var(--ttr-red);
  color: #fff;
}

.btn.lg {
  padding: 13px 22px;
  font-size: 1rem;
}

.btn.sm {
  padding: 6px 11px;
  font-size: 0.82rem;
}

/* ------------------------------------------------------------------ forms */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.input,
select.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}

.input:focus {
  outline: none;
  border-color: var(--ttr-blue);
  box-shadow: 0 0 0 3px var(--ttr-blue-soft);
}

.input.code {
  font-family: var(--mono);
  letter-spacing: 3px;
  text-transform: uppercase;
  text-align: center;
  font-size: 1.1rem;
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.alert.error {
  background: #fde8e8;
  color: #a1262a;
  border: 1px solid #f6c6c8;
}

.alert.ok {
  background: #e6f6ed;
  color: #1c6b45;
  border: 1px solid #bfe6d1;
}

.alert.info {
  background: var(--ttr-blue-soft);
  color: var(--ttr-blue-dark);
  border: 1px solid #cfe0ff;
}

/* ----------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

.badge.guest {
  background: #fff4e0;
  border-color: #ffdca3;
  color: #8a5a00;
}

.badge.member {
  background: var(--ttr-blue-soft);
  border-color: #cfe0ff;
  color: var(--ttr-blue-dark);
}

.badge.live {
  background: #e6f6ed;
  border-color: #bfe6d1;
  color: #1c6b45;
}

.badge.gold {
  background: #fff6d6;
  border-color: #ffe58a;
  color: #7a5c00;
}

/* Robot opponent - never mistakable for a person. */
.badge.bot {
  background: #ece7ff;
  border-color: #d3c8ff;
  color: #4b3ba8;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ttr-green);
  display: inline-block;
}

/* ------------------------------------------------------- KTouch keyboard */

/*
 * KTouch's keyboard: coloured keys on a dark strip. Every key carries its
 * finger's colour, white bold labels, the shifted symbol in the top-left
 * corner, and the next key to press is boxed in light cyan.
 */
/*
 * The key size is a variable, so a narrow screen can scale the whole board down
 * (see the responsive block at the end of this file). A full keyboard is wider
 * than any phone, so it also scrolls sideways rather than spilling out of its
 * panel and dragging the whole page with it.
 */
.keyboard {
  --key-size: 38px;
  --key-height: 40px;
  background: #4b4b4b;
  border: 1px solid #3a3a3a;
  border-radius: 5px;
  padding: 6px;
  user-select: none;
  overflow-x: auto;
}

.kb-row {
  display: flex;
  gap: 4px;
  margin-bottom: 3px;
}

.kb-row:last-child {
  margin-bottom: 0;
}

.kb-key {
  --keyw: 1;
  flex: 0 0 auto;
  width: calc(var(--keyw) * var(--key-size));
  height: var(--key-height);
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.35);
  background: #6f6f6f;
  display: grid;
  place-items: center;
  font-family: var(--sans);
  font-size: 1.02rem;
  font-weight: 700;
  color: #fff;
  position: relative;
  overflow: hidden;
  transition: transform 0.04s ease, box-shadow 0.1s ease, background 0.1s ease;
}

.kb-key.mod {
  background: #3c3c3c;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  color: #e8e8e8;
}

/* Finger tint - the signature KTouch look. */
.kb-key.tinted {
  color: #fff;
  border-color: rgba(0, 0, 0, 0.35);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}

/*
 * KTouch only colours the keys the course has taught so far: everything the
 * student has not learned yet is dark and inert, and lights up as the lessons
 * progress. (Free practice has no lesson, so nothing is dimmed there.)
 */
.kb-key.unlearned {
  background: #454545 !important;
  color: #8a8a8a !important;
  border-color: rgba(0, 0, 0, 0.3) !important;
  text-shadow: none;
}

.kb-key.unlearned .shift-hint {
  color: rgba(255, 255, 255, 0.3);
}

/* The keys this very lesson introduces get a golden ring, like KTouch's. */
.kb-key.new-key {
  box-shadow: 0 0 0 2px #ffd54a;
}

/* The key to press next, boxed in light cyan exactly like KTouch. */
.kb-key.next {
  background: #bfe6f5 !important;
  color: #0b3c52 !important;
  text-shadow: none;
  box-shadow: 0 0 0 2px #2b7fb8;
  z-index: 2;
}

.kb-key.hit {
  background: var(--ttr-green) !important;
  color: #fff !important;
  transform: translateY(1px);
}

.kb-key.miss {
  background: var(--ttr-red) !important;
  color: #fff !important;
}

/* The shifted symbol, printed small in the key's top-left corner. */
.kb-key .shift-hint {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 0.6rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1;
}

.kb-key.next .shift-hint {
  color: #0b3c52;
}

.kb-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.kb-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: #e2e2e2;
}

.kb-swatch {
  width: 13px;
  height: 13px;
  border-radius: 4px;
}

/* ------------------------------------------------------------- typing area */

/*
 * KTouch's training screen: a white, fixed-height window onto the passage. The
 * words start at the top and scroll up line by line as the typist advances,
 * while the keyboard underneath lights the next key to press.
 */
.ktouch-view {
  margin-top: 10px;
  padding: 0;
  border-radius: 5px;
  background: #fff;
  border: 1px solid #c9c9c9;
}

.ktouch-view-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-bottom: 1px solid #e4e4e4;
  background: #f7f7f7;
}

.ktouch-view .text-display {
  /* Exactly three lines, so nothing is ever sliced in half and the keyboard
     below stays on screen. */
  height: 198px;
  min-height: 0;
  overflow: hidden;
  padding: 18px 70px;
  font-size: 1.7rem;
  line-height: 54px;
  background: #fff;
  border: 0;
  border-radius: 0;
  color: #000;
}

/* KTouch keeps the training text plain: no box on the current character. */
.ktouch-view .ch.word {
  background: none;
  border-bottom: 0;
}

.ktouch-view .ch.current {
  background: none;
  color: inherit;
}

/*
 * KTouch's reveal: the words ahead are greyed out but readable, a correctly
 * typed character turns deep black, and a wrong one turns red.
 */
.ktouch-view .ch.pending {
  color: #b0b0b0;
}

.ktouch-view .ch.correct {
  color: #000;
}

.ktouch-view .ch.incorrect {
  color: #d6301d;
  background: rgba(214, 48, 29, 0.12);
  box-shadow: none;
}

.ktouch-view .ch.current.incorrect {
  background: rgba(214, 48, 29, 0.12);
}

/* The slim KTouch insertion mark, on the character about to be typed. */
.ktouch-view .typing-wrap.is-live .ch.current::after {
  left: -1px;
  width: 2px;
  background: #000;
}

.typing-wrap {
  position: relative;
}

.typing-hidden-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.text-display {
  font-family: var(--mono);
  font-size: 1.5rem;
  line-height: 2.1;
  letter-spacing: 0.5px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  /* Wrap on word boundaries only: a whole word always moves to the next line
     instead of being split in half. overflow-wrap is the last-resort escape
     hatch for a single word longer than a whole line. */
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
  cursor: text;
  min-height: 120px;
}

.text-display:focus-within {
  border-color: var(--ttr-blue);
  box-shadow: 0 0 0 3px var(--ttr-blue-soft);
}

.ch {
  position: relative;
  border-radius: 3px;
  /* Preserve the character inside its own span (matters for the space). */
  white-space: pre;
}

/*
 * A word - and the space that trails it - is one atomic inline block, so the
 * browser can only wrap between words: no word is ever split across two lines
 * and no line ever starts with a space.
 */
.text-display .word-box {
  display: inline-block;
}

.ch.correct {
  /* KTouch's reveal: a correctly typed character is deep black. */
  color: #000;
}

.ch.incorrect {
  color: #d6301d;
  background: rgba(214, 48, 29, 0.14);
  box-shadow: 0 2px 0 0 #d6301d;
}

.ch.pending {
  /* The words ahead are greyed out but stay readable - type over them. */
  color: #b0b0b0;
}

/* TypeRacer highlights and underlines the word the caret is in. */
.ch.word {
  background: #e7ecf5;
  border-bottom: 2px solid #93aede;
  border-radius: 0;
}

.ch.current {
  background: var(--ttr-accent);
  color: #1d2433;
  border-bottom-color: var(--ttr-accent);
}

.ch.current.correct,
.ch.current.incorrect {
  background: var(--ttr-accent);
  color: #1d2433;
}

/*
 * The blinking caret. It only shows while typing is live, so the moment the
 * countdown hits zero - or a lesson page paints - a visible cursor blinks on
 * the next character, telling the typist they are clear to type.
 *
 * It is positioned absolutely on purpose: an inline caret would sit in the text
 * flow and shift the rest of the line by a couple of pixels on every keystroke,
 * which made the whole passage jitter while typing fast.
 */
.typing-wrap.is-live .ch.current::after {
  content: '';
  position: absolute;
  left: -1px;
  top: 0.12em;
  bottom: 0.12em;
  width: 2px;
  background: #1d2433;
  animation: caret-blink 1s steps(2, start) infinite;
}

@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

.text-overlay-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.82);
  border-radius: var(--radius);
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 1rem;
  pointer-events: none;
}

/* ------------------------------------------------------------------ stats */

/*
 * KTouch's stat cards: a white rounded card with a dial on the left, a small
 * grey label, a big number, and a green delta underneath.
 */
.kt-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 4px;
}

@media (max-width: 720px) {
  .kt-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.kt-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid #c9c9c9;
  border-radius: 5px;
  padding: 8px 10px;
  min-height: 74px;
}

.kt-dial {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
}

.kt-dial-track {
  fill: #fbfbfb;
  stroke: #cfcfcf;
  stroke-width: 3;
}

.kt-dial-arc {
  fill: none;
  stroke: #2fae6b;
  stroke-width: 4;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.kt-dial-tick {
  stroke: #9a9a9a;
  stroke-width: 2;
}

.kt-needle {
  stroke: #d6301d;
  stroke-width: 3;
  stroke-linecap: round;
}

.kt-hub {
  fill: #d6301d;
}

.kt-body {
  min-width: 0;
  flex: 1;
}

.kt-label {
  font-size: 0.82rem;
  color: #4a4a4a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kt-value {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.15;
  color: #101010;
  font-variant-numeric: tabular-nums;
}

.kt-delta {
  font-size: 0.85rem;
  font-weight: 700;
  color: #1d9a4e;
  min-height: 1.1em;
}

.kt-delta.negative {
  color: #d6301d;
}

/* ------------------------------------------------- rank badges & racer card */

/*
 * A racer's rank chip, TypeRacer-style: the skill level next to the name, tinted
 * by the band the racer's speed falls in.
 */
.rank-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--rank-color, #8a94a6);
  vertical-align: 1px;
  white-space: nowrap;
}

/* A hoverable name: the card lives inside it and appears on hover or focus. */
.name-hover {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: help;
  outline: none;
}

.name-hover:hover,
.name-hover:focus-within {
  z-index: 30;
}

.player-card {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 40;
  width: 320px;
  /* A 320px card would hang off the edge of a phone. */
  max-width: calc(100vw - 24px);
  padding: 12px 14px 14px;
  text-align: left;
  background: #fff;
  border: 1px solid #cbd6e8;
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 34px rgba(29, 36, 51, 0.22);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink);
  cursor: default;
  white-space: normal;
}

/* Keep the card on screen when the name sits near the right edge. */
.lane-driver .player-card {
  left: auto;
  right: 0;
}

.name-hover:hover .player-card,
.name-hover:focus .player-card,
.name-hover:focus-within .player-card {
  display: block;
}

.player-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.player-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--ttr-blue-dark);
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
}

.player-card-id strong {
  display: block;
  font-size: 1rem;
  font-weight: 800;
}

.player-card-id em {
  display: block;
  font-style: italic;
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.player-card-rows {
  display: block;
  border-top: 1px solid var(--line-soft);
  padding-top: 8px;
}

.player-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
  white-space: nowrap;
}

.player-row .key {
  color: var(--ink-soft);
}

.player-row .val {
  font-weight: 800;
  color: var(--ttr-blue-dark);
  font-variant-numeric: tabular-nums;
}

.player-row.muted .key,
.player-row.muted .val {
  color: var(--ink-soft);
  font-weight: 600;
}

.stats-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.stat {
  flex: 1;
  min-width: 96px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.stat .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-soft);
  font-weight: 700;
}

.stat .value {
  font-size: 1.5rem;
  font-weight: 800;
  font-family: var(--mono);
  line-height: 1.2;
}

.stat .value.wpm {
  color: var(--ttr-blue);
}

.stat .value.acc {
  color: var(--ttr-green);
}

.stat .value.err {
  color: var(--ttr-red);
}

/* ------------------------------------------------- TypeRacer car track */

/* The room's action buttons (start / race again / copy invite / leave), kept a
   clear step away from the track so the controls never crowd the cars. */
.race-actions {
  gap: 10px;
  margin: 14px 0 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.race-track {
  margin-top: 4px;
  position: relative;
  overflow: hidden;
  border: 1px solid #c3d0e8;
  border-radius: var(--radius);
  background: #eef3fb;
  box-shadow: var(--shadow);
}

/*
 * Stadium backdrop. Everything here is original CSS artwork (gradients + dots),
 * inspired by TypeRacer's racetrack: sky, sun, clouds, hills, a crowd strip and
 * a banner over the start line - kept in the site's bright, jolly palette.
 */
.track-scenery {
  position: relative;
  height: 76px;
  overflow: hidden;
  background: linear-gradient(180deg, #9ed2ff 0%, #d3ecff 62%, #eaf6ff 100%);
}

.track-sun {
  position: absolute;
  right: 14%;
  top: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3cf, #f7b733);
  box-shadow: 0 0 26px rgba(255, 214, 106, 0.7);
}

.track-cloud {
  position: absolute;
  height: 14px;
  border-radius: 40px;
  background: rgba(255, 255, 255, 0.92);
}

.track-cloud.one {
  left: 10%;
  top: 16px;
  width: 68px;
  box-shadow: 20px -8px 0 -3px rgba(255, 255, 255, 0.85), -18px 3px 0 -5px rgba(255, 255, 255, 0.8);
}

.track-cloud.two {
  left: 52%;
  top: 32px;
  width: 48px;
  opacity: 0.75;
}

.track-hills {
  position: absolute;
  left: -6%;
  right: -6%;
  bottom: 12px;
  height: 38px;
  background:
    radial-gradient(70px 34px at 22% 100%, #6fd69b 0 58%, transparent 59%),
    radial-gradient(96px 42px at 58% 100%, #57c98a 0 58%, transparent 59%),
    linear-gradient(#63cf95, #46b97a);
}

.track-banner {
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translateX(-50%);
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(230, 184, 0, 0.6);
  color: var(--ttr-blue-dark);
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  box-shadow: 0 2px 6px rgba(27, 75, 184, 0.12);
}

/* Crowd: a strip of tiled dots, like packed grandstands along the straight. */
.track-stand {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12px;
  background:
    radial-gradient(circle at 3px 5px, #ffffff 1.7px, transparent 2.2px) 0 0 / 7px 7px repeat-x,
    radial-gradient(circle at 6px 8px, #ffb703 1.5px, transparent 2px) 0 0 / 9px 9px repeat-x,
    linear-gradient(#bfe0ff, #a3ccf7);
}

/* The asphalt itself, with red/white kerbs along both edges. */
.track-road {
  position: relative;
  padding: 11px 12px 13px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.35)),
    repeating-linear-gradient(90deg, #e5ebf6 0 34px, #dde5f3 34px 68px);
}

.track-kerb {
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  background: repeating-linear-gradient(90deg, #e0503c 0 12px, #f7f9fc 12px 24px);
}

.track-kerb.top {
  top: 0;
}

.track-kerb.bottom {
  bottom: 0;
}

/* While the race runs the tarmac picks up a warm sheen from the lights. */
.race-track.racing .track-road {
  box-shadow: inset 0 0 44px rgba(255, 204, 51, 0.1);
}

/* A car that crossed the line sits at the finish with a winner's glow. */
.lane.finished .lane-car .car {
  filter: drop-shadow(0 0 9px rgba(255, 204, 51, 0.85));
}

/* A lane is one racer's row: name beside their car, place and speed on the
   right, and a dashed racing line instead of a boxed road. */
.lane {
  display: grid;
  grid-template-columns: 150px 1fr 116px;
  align-items: center;
  gap: 14px;
  padding: 8px 4px;
}

/* Your own lane gets a warm highlight, like TypeRacer's highlighted "You" row. */
.lane.me {
  background: linear-gradient(90deg, rgba(255, 204, 51, 0.32), rgba(255, 204, 51, 0));
  border-radius: var(--radius-sm);
}

/* The name, right up against the car, with "you" (or host/guest) underneath. */
.lane-driver {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  min-width: 0;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
  text-align: right;
}

.lane-driver .name {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.lane-tag {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.lane.me .lane-driver .name,
.lane.me .lane-tag {
  color: var(--ttr-blue-dark);
}

/* Road: a dashed line with the car riding on it and the finish flags at the end. */
.lane-road {
  position: relative;
  height: 34px;
  border: 0;
  border-radius: 0;
  border-bottom: 2px dashed #d9c46a;
  background: none;
}

.lane-dash,
.lane-road .start-line {
  display: none;
}

.lane-road .finish-line {
  position: absolute;
  right: 0;
  top: 2px;
  bottom: 2px;
  width: 12px;
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #3b4658 25%, transparent 25%, transparent 75%, #3b4658 75%),
    linear-gradient(45deg, #3b4658 25%, transparent 25%, transparent 75%, #3b4658 75%);
  background-size: 8px 8px;
  background-position: 0 0, 4px 4px;
  border-radius: 2px;
}

/* Cars are drawn from divs, so they stay pin sharp at any size. */
.lane-car {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translate(-50%, -50%);
  width: 54px;
  height: 26px;
  transition: left 0.3s cubic-bezier(0.22, 0.8, 0.3, 1);
}

.car {
  position: absolute;
  inset: 0;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.car-body {
  position: absolute;
  left: 0;
  right: 0;
  top: 11px;
  height: 11px;
  border-radius: 3px 9px 4px 4px;
  background: var(--car);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
}

.car-roof {
  position: absolute;
  left: 12px;
  top: 4px;
  width: 24px;
  height: 9px;
  border-radius: 7px 9px 0 0;
  background: var(--car);
  filter: brightness(0.88);
}

.car-window {
  position: absolute;
  left: 15px;
  top: 6px;
  width: 18px;
  height: 6px;
  border-radius: 4px 6px 1px 1px;
  background: linear-gradient(180deg, #eef5ff, #9dc0ea);
}

.car-wheel {
  position: absolute;
  top: 20px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #121826;
  border: 2px solid #5b6577;
}

.car-wheel.rear {
  left: 8px;
}

.car-wheel.front {
  right: 9px;
}

.car-light {
  position: absolute;
  right: -1px;
  top: 14px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #ffe9a8;
  box-shadow: 0 0 7px #ffd76a;
}

.lane.me .car-light {
  box-shadow: 0 0 12px 2px #ffe9a8;
}

.car-crash {
  position: absolute;
  left: 6px;
  top: -4px;
  font-size: 1.05rem;
}

/* Live speed and place on the right of each lane, stacked like TypeRacer's. */
.lane-speed {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.82rem;
  text-align: right;
  color: var(--ink-soft);
  line-height: 1.35;
}

.lane-place {
  display: block;
  color: var(--ttr-blue-dark);
}

.lane-speed small {
  display: block;
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--ink);
}

.lane.finished .lane-place {
  color: #15813f;
}

.lane.finished .lane-speed small {
  color: #15813f;
}

/* The quote's credit line, printed under the track while a race runs. */
.track-credit {
  padding: 8px 14px 12px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.track-credit strong {
  color: var(--ink);
}

.lane.dnf .lane-driver,
.lane.dnf .lane-speed {
  opacity: 0.45;
  text-decoration: line-through;
}

/* Empty seats stay on the grid, so the open lane is always obvious. */
.lane.empty .lane-driver,
.lane.empty .lane-speed {
  opacity: 0.45;
}

.lane.empty .lane-road {
  background: repeating-linear-gradient(135deg, #eef2f9 0 9px, #e4eaf5 9px 18px);
  opacity: 0.85;
}

/* ------------------------------------------------------------- countdown */

.countdown {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 60;
  background: radial-gradient(120% 120% at 50% 0%, rgba(240, 246, 255, 0.86), rgba(206, 226, 252, 0.93));
  backdrop-filter: blur(3px);
}

.countdown-card {
  padding: 26px 56px 30px;
  border-radius: 20px;
  text-align: center;
  /* TypeRacer's gray countdown panel over the dark overlay. */
  background: #e9ecf2;
  border: 2px solid #c3ccda;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.55);
}

.countdown-label {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #5b6577;
}

.countdown .num {
  font-size: 6.5rem;
  font-weight: 900;
  line-height: 1;
  color: #d6301d;
  text-shadow: none;
  animation: pop 0.9s ease-out;
  font-family: var(--mono);
  margin-top: 4px;
}

.countdown .go {
  color: #1d9a4e;
}

/* TypeRacer's depleting time strip under the digit. */
.countdown-strip {
  width: 220px;
  height: 10px;
  margin: 14px auto 0;
  border-radius: 999px;
  background: #c3ccda;
  overflow: hidden;
}

.strip-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--ttr-blue);
  transition: width 0.15s linear;
}

.strip-fill.go {
  background: var(--ttr-green);
}

.countdown-hint {
  margin: 12px 0 0;
  color: #5b6577;
  font-size: 0.85rem;
}

/* ------------------------------------------------------------ waiting room */

/* Who is on the grid, and how long until bots fill the empty lanes. */
.waiting-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px dashed var(--line);
}

.waiting-title {
  font-size: 0.95rem;
  color: var(--ttr-blue-dark);
}

.waiting-timer {
  flex: none;
  min-width: 96px;
  text-align: center;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: #fff;
  border: 1px solid var(--line);
}

.waiting-seconds {
  display: block;
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--ttr-blue-dark);
}

@keyframes pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  40% {
    transform: scale(1.15);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

/* -------------------------------------------------------------- tables */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line-soft);
}

.table th {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-soft);
  border-bottom: 2px solid var(--line);
}

.table tbody tr:hover {
  background: var(--panel-2);
}

.table .num {
  font-family: var(--mono);
  text-align: right;
}

.table tr.me-row {
  background: var(--ttr-blue-soft);
}

/*
 * Tables are the one thing that cannot fold into a phone: six or seven columns of
 * numbers have a minimum sensible width. Below the tablet breakpoint a table
 * becomes a scroll container of its own, so its columns keep their natural width
 * and the panel scrolls - the page itself never gains a horizontal scrollbar.
 * (Desktop tables are untouched: they stay full-width tables with 100% width.)
 */
@media (max-width: 880px) {
  .table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
  }
}

.place-1 {
  color: #b8860b;
  font-weight: 800;
}

.place-2 {
  color: #7a8794;
  font-weight: 700;
}

.place-3 {
  color: #a5673f;
  font-weight: 700;
}

/* --------------------------------------------------- KTouch lesson tree */

/*
 * The race page runs wide - racing is the whole page, so there is no sidebar
 * squeezing the track or the passage - and, like every other page, it has no
 * width cap.
 */
.race-page > .panel {
  margin-top: 18px;
}

.race-details {
  margin-top: 18px;
}

/*
 * TypeRacer's typing surface: the word being typed is underlined so it is clear
 * which word is live, and the blinking cursor sits exactly where the typist is -
 * type over the grey words and they turn black, or red when you slip.
 */
.typeracer-view .ch.word {
  background: none;
  border-bottom: 3px solid #8fb2e8;
  border-radius: 2px 2px 0 0;
}

.typeracer-view .typing-wrap.is-live .ch.current::after {
  left: -2px;
  width: 2px;
  background: #1b4bb8;
}

.typeracer-view .text-display {
  font-size: 1.6rem;
  line-height: 50px;
  padding: 26px 28px;
  /* A fixed window (four lines), so a vanished word never resizes the panel. */
  height: 252px;
  min-height: 0;
  overflow: hidden;
}

/*
 * Vanishing text on the race page: once a word is typed correctly it leaves the
 * passage and the remaining words flow up into the space, so the whole passage
 * can be raced without the page ever scrolling.
 */
.typeracer-view .word-box.done {
  display: none;
}

/*
 * The KTouch keyboard under the race typing area. The board itself scrolls
 * sideways when a screen is too narrow for it (see .keyboard), so this only has
 * to hold it a clear step below the passage.
 */
.race-keyboard {
  margin-top: 12px;
}

/*
 * Learn page layout, after KTouch: the typing area and its stats own the bulk
 * of the screen; the course tree is squeezed into a narrow sidebar on the far
 * right, and the keyboard runs along the bottom of the page.
 */
.grid.two.learn-grid {
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: start;
}

.learn-grid .course {
  margin-bottom: 8px;
}

.learn-grid .course-head {
  padding: 8px 10px;
  font-size: 0.85rem;
}

.learn-grid .course-head .blurb {
  font-size: 0.72rem;
}

.learn-grid .level {
  padding: 6px 10px;
  gap: 8px;
}

.learn-grid .level .idx {
  width: 20px;
  height: 20px;
  font-size: 0.65rem;
}

.learn-grid .level .title {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.learn-grid .level .targets {
  font-size: 0.68rem;
}

.learn-grid .level-list {
  max-height: 40vh;
  overflow-y: auto;
}

@media (max-width: 880px) {
  .grid.two.learn-grid {
    grid-template-columns: 1fr;
  }

  .learn-grid .level-list {
    max-height: none;
  }
}

.course {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 12px;
}

.course-head {
  background: var(--panel-2);
  padding: 12px 14px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.course-head .blurb {
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.level-list {
  display: flex;
  flex-direction: column;
}

.level {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--line-soft);
  cursor: pointer;
}

.level:hover {
  background: var(--panel-2);
}

.level.active {
  background: var(--ttr-blue-soft);
  box-shadow: inset 3px 0 0 var(--ttr-blue);
}

.level .idx {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink-soft);
  flex: 0 0 auto;
}

.level.passed .idx {
  background: var(--ttr-green);
  border-color: var(--ttr-green);
  color: #fff;
}

.level .title {
  font-weight: 600;
  font-size: 0.92rem;
}

.level .targets {
  margin-left: auto;
  font-size: 0.76rem;
  color: var(--ink-soft);
  font-family: var(--mono);
}

.progress {
  height: 8px;
  background: var(--line-soft);
  border-radius: 999px;
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--ttr-blue);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress.green > span {
  background: var(--ttr-green);
}

/* -------------------------------------------------------------- lobby */

.lobby-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lobby-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}

.lobby-row .slots {
  display: flex;
  gap: 4px;
}

.slot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
}

.slot.filled {
  background: var(--ttr-blue);
  border-color: var(--ttr-blue);
}

.code-chip {
  font-family: var(--mono);
  font-weight: 800;
  letter-spacing: 2px;
  background: #fff6d6;
  border: 1px dashed #e6b800;
  color: #7a5c00;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
}

/* --------------------------------------------------------------- home */

.hero {
  background: linear-gradient(135deg, #2f6fed 0%, #1b4bb8 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 34px 30px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.hero h1 {
  font-size: 2.1rem;
  margin-bottom: 8px;
}

.hero p {
  max-width: 620px;
  color: #dce7ff;
  font-size: 1.02rem;
  line-height: 1.6;
}

.hero .cta {
  margin-top: 20px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-cars {
  position: absolute;
  right: 20px;
  bottom: 14px;
  font-size: 2.4rem;
  opacity: 0.35;
}

.feature {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.feature .icon {
  font-size: 1.6rem;
  flex: 0 0 auto;
}

.feature h3 {
  font-size: 1rem;
  margin-bottom: 3px;
}

.feature p {
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin: 0;
}

/* ------------------------------------------------------------- footer */

.footer {
  margin-top: auto;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 18px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.84rem;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--ttr-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 30px auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------------------------------------- results */

/* TypeRacer's headline: "You finished 1st!". */
.results-title {
  margin: 4px 0 16px;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--ttr-blue-dark);
}

/*
 * The quote card: a blue header naming what was typed, the work and its author,
 * then the run's numbers in rows - the way TypeRacer credits a quote.
 */
.quote-panel {
  margin-bottom: 18px;
  border: 1px solid #c3d0e8;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #f6f9fe;
}

.quote-head {
  padding: 10px 14px;
  background: var(--ttr-blue-dark);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  text-transform: capitalize;
}

.quote-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  background: #fff;
  border-bottom: 1px solid #e2e9f5;
}

.quote-title {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--ink);
}

.quote-source {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.quote-stats {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.92rem;
}

.stat-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ttr-blue-soft);
  font-size: 0.8rem;
  flex: 0 0 auto;
}

.stat-key {
  color: var(--ink-soft);
}

.stat-val {
  font-weight: 800;
  color: var(--ink);
}

/* ==========================================================================
   Responsive layout

   The site is used on a phone as often as on a laptop, so every layout above has
   a narrow shape of its own. The blocks run from the widest screen to the
   narrowest, so a rule written for a phone always wins when both match.
   ========================================================================== */

/* --------------------------------------------------------------- tablets */

@media (max-width: 880px) {
  .container {
    padding: 18px 16px 44px;
  }

  .panel {
    padding: 16px;
  }

  .hero {
    padding: 24px 20px;
  }

  .hero h1 {
    font-size: 1.65rem;
  }

  .results-title {
    font-size: 1.25rem;
  }

  /* Whatever is in these rows can wrap instead of pushing the panel wider. */
  .quote-body,
  .lobby-row,
  .waiting-panel,
  .ktouch-view-head {
    flex-wrap: wrap;
  }

  /* The whole 15-unit keyboard scales down; it still scrolls when it must. */
  .keyboard {
    --key-size: 30px;
    --key-height: 34px;
  }

  .kb-key {
    font-size: 0.85rem;
  }

  .kb-key.mod {
    font-size: 0.62rem;
  }
}

/* ---------------------------------------------------------------- phones */

@media (max-width: 720px) {
  /*
   * The typing surfaces. Both were sized around a desktop line: KTouch's window
   * is a fixed height, and its line height and side padding left a phone with
   * about three words per line. Each height below is exactly the padding plus
   * three whole lines, so the window still shows complete lines and never slices
   * one in half.
   */
  .ktouch-view .text-display {
    font-size: 1.1rem;
    line-height: 38px;
    height: 134px;
    padding: 10px 12px;
  }

  .typeracer-view .text-display {
    font-size: 1.1rem;
    line-height: 36px;
    height: 172px;
    padding: 14px;
  }

  /*
   * TypeRacer's three-column lane does not fit a phone: the name and the readout
   * share one line, and the road takes the whole width underneath it.
   */
  .lane {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      'driver speed'
      'road road';
    gap: 4px 10px;
    padding: 8px 2px;
  }

  .lane-driver {
    grid-area: driver;
    align-items: flex-start;
    text-align: left;
  }

  .lane-speed {
    grid-area: speed;
  }

  .lane-road {
    grid-area: road;
  }

  .track-road {
    padding: 8px 8px 10px;
  }

  .track-scenery {
    height: 56px;
  }

  .track-sun {
    top: 8px;
    width: 24px;
    height: 24px;
  }

  .track-banner {
    font-size: 0.52rem;
  }

  .countdown .num {
    font-size: 4.6rem;
  }

  .countdown-card {
    padding: 20px 30px 24px;
  }

  .countdown-strip {
    width: 170px;
  }

  .hero p {
    font-size: 0.95rem;
  }

  .hero-cars {
    font-size: 1.7rem;
  }
}

@media (max-width: 640px) {
  .topbar-inner {
    gap: 10px;
    padding: 10px 12px;
  }

  .brand {
    font-size: 1.05rem;
    gap: 8px;
  }

  .brand .logo {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    font-size: 0.95rem;
  }

  /* On a phone the name is cut right down and the speed chip waits for a wider
     screen: the header keeps the brand, the player and the menu handle. */
  .topbar-stats > .pill:first-child {
    max-width: 104px;
  }

  .topbar-stats .pill.wpm {
    display: none;
  }

  .container {
    padding: 14px 12px 36px;
  }

  .panel {
    padding: 14px;
  }

  .footer {
    padding: 14px 12px;
  }
}

@media (max-width: 520px) {
  /* A stack of full-width buttons beats a row of ragged ones on a small screen. */
  .hero .cta {
    flex-direction: column;
    align-items: stretch;
  }

  .hero .cta .btn {
    width: 100%;
  }

  .stats-bar .stat {
    min-width: 78px;
    padding: 8px 10px;
  }

  .stat .value {
    font-size: 1.25rem;
  }
}




