/* Fast On Paper — mobile-first styling */

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Night mode: the same squared paper after dark — chalk ink on dusk
   sheets. Toggled by main.js (moon button; system preference default). */
body.dark {
  --bg: #23261e;
  --panel: #2c3026;
  --card: #343930;
  --text: #ddd6c4;
  --text-dim: #a49c88;
  --accent: #2e9e44;
  --accent-dark: #237735;
  --paper: #2c3026;
  --ink: #d8d2c0;
  --ink-dim: #a49c88;
  --ink-soft: rgba(216, 210, 192, 0.4);
  --field: #1d201a;
  background-image:
    linear-gradient(rgba(150, 180, 210, 0.10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(150, 180, 210, 0.10) 1px, transparent 1px);
}

body.dark #splash-screen {
  background: var(--bg);
  background-image:
    linear-gradient(rgba(150, 180, 210, 0.10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(150, 180, 210, 0.10) 1px, transparent 1px);
  background-size: 26px 26px;
}

/* Patrick Hand (SIL Open Font License), self-hosted — the handwriting
   used by the in-game HUD to match the doodled map. */
@font-face {
  font-family: 'Patrick Hand';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/patrick-hand.woff2') format('woff2');
}

:root {
  /* The whole app lives on the same squared paper as the racing map:
     paper surfaces, pen-ink text, handwriting throughout. */
  --bg: #f0ead8;
  --panel: #fcf9ee;
  --card: #f3ecd8;
  --text: #4a4438;
  --text-dim: #7a7260;
  --accent: #2e9e44;
  --accent-dark: #237735;
  --paper: #faf7ef;
  --ink: #4a4438;
  --ink-dim: #7a7260;
  --ink-soft: rgba(74, 68, 56, 0.4);
  --field: #ffffff;
  --hand: "Patrick Hand", "Comic Sans MS", "Comic Sans", "Chalkboard SE",
    "Segoe Print", "Bradley Hand", "Marker Felt", cursive;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--hand);
  background-color: var(--bg);
  /* the printed squared-paper grid */
  background-image:
    linear-gradient(rgba(96, 128, 170, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(96, 128, 170, 0.16) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--text);
}

.hidden { display: none !important; }

/* Inline hand-drawn SVG icons sit on the text baseline. */
.doodle-icon { vertical-align: -0.18em; }

.bot-icon { display: flex; align-items: center; flex: none; }

.screen {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- Menu ---------- */

#menu-screen {
  align-items: center;
  padding: 24px 16px 48px;
  gap: 24px;
}

/* ---------- Splash ---------- */

#splash-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  background: var(--bg);
  background-image:
    linear-gradient(rgba(96, 128, 170, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(96, 128, 170, 0.16) 1px, transparent 1px);
  background-size: 26px 26px;
}

.splash-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 26px 18px;
  width: min(100%, 560px);
}

.splash-art {
  width: 100%;
  max-height: 56vh;
  object-fit: contain;
  filter: drop-shadow(0 4px 0 rgba(74, 68, 56, 0.14));
}

/* The id outranks .btn-big's later width/font caps. */
#splash-start {
  width: 100%; /* the art spans the wrap, and so does the button */
  font-size: 2.5rem;
}

.menu-header { text-align: center; }

.menu-header h1 {
  font-size: 2.2rem;
  letter-spacing: 1px;
}

.tagline { color: var(--text-dim); margin-top: 4px; }

/* ---------- Garage ---------- */

.garage {
  background: var(--panel);
  border: 2.5px solid var(--ink);
  border-radius: 22px 16px 20px 15px / 16px 22px 15px 20px;
  box-shadow: 0 3px 0 rgba(74, 68, 56, 0.16);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  width: min(100%, 560px);
}

.garage h2, .section-title { font-size: 1.1rem; }

/* The chosen car takes the stage; the four styles wait underneath. */
.car-hero {
  width: min(100%, 380px);
  filter: drop-shadow(0 3px 0 rgba(74, 68, 56, 0.14));
}

.style-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 100px));
  gap: 8px;
  justify-content: center;
}

.style-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--card);
  border: 2px solid var(--ink-soft);
  border-radius: 14px 10px 13px 9px / 10px 14px 9px 13px;
  padding: 6px 6px 4px;
  cursor: pointer;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.72rem;
  -webkit-tap-highlight-color: transparent;
}

.style-btn canvas { display: block; max-width: 100%; }

.style-btn.selected {
  border-color: var(--accent);
  border-width: 2.5px;
  color: var(--text);
  background: #e8f0da;
}

.color-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.color-btn {
  width: 34px;
  height: 34px;
  border-radius: 46% 54% 50% 50% / 55% 48% 52% 45%;
  border: 2px solid var(--ink-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.color-btn:nth-child(2n) {
  border-radius: 53% 47% 45% 55% / 47% 55% 45% 53%;
  transform: rotate(7deg);
}

.color-btn.selected {
  border: 2.5px solid var(--ink);
  box-shadow: 0 0 0 2.5px rgba(252, 249, 238, 0.9), 0 0 0 4.5px var(--ink);
}

/* ---------- Menu wizard ---------- */

.wizard-nav {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.wiz-chip {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  width: 118px;
  text-align: center;
  color: var(--text-dim);
  background: var(--panel);
  border: 2px solid var(--ink-soft);
  border-radius: 22px 18px 24px 16px / 18px 24px 16px 22px;
  padding: 10px 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.wiz-chip.active {
  color: #ffffff;
  border-color: var(--ink);
  background: var(--accent);
  transform: rotate(-2deg);
}

.wiz-chip.done { color: var(--text); border-color: var(--ink); }

.wizard-step {
  background: var(--panel);
  border: 2.5px solid var(--ink);
  border-radius: 20px 24px 18px 26px / 24px 18px 26px 20px;
  box-shadow: 0 3px 0 rgba(74, 68, 56, 0.16);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  width: min(100%, 620px);
}

.wizard-step h2 { font-size: 1.15rem; }

.wizard-step input, .wizard-step select {
  font: inherit;
  color: var(--text);
  background: var(--field);
  border: 2px solid var(--ink);
  border-radius: 12px 9px 13px 8px / 9px 13px 8px 12px;
  padding: 11px 12px;
}

.wizard-step input:focus, .wizard-step select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.name-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* The two color dropdowns side by side; the race number on its own row. */
.garage-extra {
  display: flex;
  gap: 22px;
  align-items: flex-end;
  justify-content: center;
  flex-wrap: wrap;
}

.garage-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.garage-label { color: var(--text-dim); font-size: 0.85rem; }

.color-dd { position: relative; }

.dd-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--field);
  border: 2px solid var(--ink);
  border-radius: 10px 8px 11px 7px / 8px 11px 7px 10px;
  padding: 6px 10px;
  cursor: pointer;
  min-width: 168px;
  -webkit-tap-highlight-color: transparent;
}

.dd-chip {
  width: 18px;
  height: 18px;
  border-radius: 46% 54% 50% 50% / 55% 48% 52% 45%;
  border: 1.5px solid var(--ink-soft);
  flex: none;
}

.dd-name { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dd-caret { color: var(--text-dim); }

.dd-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  grid-template-columns: repeat(5, 34px);
  gap: 8px;
  padding: 12px;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 14px 11px 15px 10px / 11px 15px 10px 14px;
  box-shadow: 0 4px 0 rgba(74, 68, 56, 0.18);
}

.color-dd.open .dd-menu { display: grid; }

.num-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

#car-num {
  font: inherit;
  font-weight: 700;
  font-size: 1.15rem;
  width: 58px;
  text-align: center;
  color: var(--text);
  background: var(--field);
  border: 2px solid var(--ink);
  border-radius: 10px 8px 11px 7px / 8px 11px 7px 10px;
  padding: 5px 6px;
}

#mp-name { width: 170px; font-size: 1.05rem; }

.btn-big {
  font-size: 1.1rem;
  padding: 14px 26px;
  border-radius: 12px;
  width: min(100%, 320px);
}

.mode-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.mode-btn {
  flex: 1 1 180px;
  max-width: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--ink-soft);
  border-radius: 18px 14px 20px 13px / 14px 20px 13px 18px;
  padding: 18px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mode-btn.selected {
  border: 2.5px solid var(--accent);
  background: #e8f0da;
}

.mode-icon { line-height: 1; display: flex; justify-content: center; }

.mode-sub {
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--text-dim);
}

.race-config {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  width: 100%;
}

.cfg-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.cfg-label { color: var(--text-dim); font-size: 0.95rem; }

.cfg-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.opp-row { display: flex; gap: 8px; }

.opp-btn {
  width: 58px;
  padding: 9px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border-radius: 14px 10px 15px 9px / 10px 15px 9px 14px;
  border: 2px solid var(--ink-soft);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.opp-btn .opp-icon {
  font-size: 1.35rem;
  line-height: 1.2;
  min-height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.opp-btn.off {
  background: transparent;
  border-style: dashed;
  border-color: var(--ink-soft);
  color: var(--text-dim);
}

.opp-btn.human { border-color: #4d8fd1; }
.opp-btn.ai { border-color: var(--accent); }

.options-toggle { font-size: 0.95rem; }

.race-config .lobby-rules { width: 100%; }

.start-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  width: 100%;
}

.open-lobby-choice {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: flex-start;
}

.open-lobby-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  font-family: var(--hand);
  color: var(--text-dim);
  font-size: 0.95rem;
  cursor: pointer;
}

.open-lobby-row input { accent-color: #2e9e44; width: 17px; height: 17px; }

.go-practice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.go-note { font-family: var(--hand); color: var(--text-dim); }

.join-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.ol-empty {
  padding: 12px;
  border: 2px dashed var(--ink-soft);
  border-radius: 14px 10px 15px 9px / 10px 14px 9px 15px;
  font-family: var(--hand);
  color: var(--text-dim);
  text-align: center;
}

/* The open-race board: little track sheets taped to the page, same
   language as the track picker. */
.ol-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 30px 26px;
  width: 100%;
  padding: 10px 6px 4px;
}

.ol-grid .ol-empty { grid-column: 1 / -1; }

.ol-card:disabled { opacity: 0.55; cursor: default; }

.ol-meta {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.lobby-countdown {
  font-family: var(--hand);
  color: var(--ink);
  font-size: 1.05rem;
  margin: 2px 0 4px;
}

.lobby-countdown svg { vertical-align: -2px; }

#mp-code {
  width: 110px;
  text-transform: lowercase;
  letter-spacing: 4px;
  font-weight: 700;
  text-align: center;
}

/* ---------- Lobby ---------- */

#lobby-screen,
#invite-screen {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lobby-card {
  background: var(--panel);
  border: 2.5px solid var(--ink);
  border-radius: 24px 18px 26px 16px / 18px 26px 16px 24px;
  box-shadow: 0 3px 0 rgba(74, 68, 56, 0.16);
  padding: 26px 24px;
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.lobby-code-row {
  color: var(--text-dim);
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
}

.lobby-code-row .lobby-code { display: inline-flex; align-items: center; }

.lobby-code {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--ink);
  background: var(--field);
  border: 2px solid var(--ink);
  border-radius: 12px 9px 13px 8px / 9px 13px 8px 12px;
  padding: 2px 12px;
  margin-left: 6px;
}

.lobby-info { color: var(--text-dim); font-size: 0.9rem; }

/* A dashed pen stroke separating the code block from the rest. */
.lobby-divider {
  border: none;
  border-top: 2px dashed var(--ink-soft);
  width: 100%;
  margin: 4px 0;
}

/* Track thumbnail, big and centered, its name below — in the lobby and
   on invite pages. */
.lobby-track {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#lobby-track-name { font-size: 1.05rem; }

.lobby-thumb {
  width: min(100%, 220px);
  border: 2px solid var(--ink-soft);
  border-radius: 10px 8px 11px 7px / 8px 11px 7px 10px;
  background: var(--card);
  flex: none;
}

.lobby-track-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
}

.lobby-share { font-size: 1.05rem; padding: 8px 18px; align-self: center; }

/* The open seat's Invite matches the AI rows' skill dropdown exactly. */
.row-invite {
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--field);
  border: 1.5px solid var(--ink);
  border-radius: 9px 7px 10px 6px / 7px 10px 6px 9px;
  padding: 4px 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* The invite landing page: welcome, track, and one obvious code box. */
.invite-card { align-items: stretch; }

/* The form stacks like the card it sits in (it's a wrapper so a dead
   invite can hide the whole thing at once). */
.invite-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.invite-card .btn { width: 100%; }

.invite-msg { color: var(--text-dim); }

.invite-label {
  color: var(--text-dim);
  font-size: 0.82rem;
  text-align: left;
  margin-bottom: -8px;
}

.invite-card input {
  font: inherit;
  color: var(--text);
  background: var(--field);
  border: 2px solid var(--ink);
  border-radius: 12px 9px 13px 8px / 9px 13px 8px 12px;
  padding: 8px 12px;
}

.invite-card .invite-code {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: 10px;
  text-align: center;
  text-transform: lowercase;
}

.lobby-players {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 6px 0;
}

.lobby-players li {
  display: flex;
  align-items: center;
  gap: 8px 10px;
  background: var(--card);
  border: 2px solid var(--ink-soft);
  border-radius: 12px 9px 13px 8px / 9px 13px 8px 12px;
  padding: 8px 12px;
  text-align: left;
  flex-wrap: wrap;
}

/* Chip + name stay glued together; pickers sit to the right and the
   color palette wraps to its own line when the row runs out of room
   (phones), instead of crushing the name. */
.lobby-row-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.lobby-row-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.player-chip {
  width: 16px;
  height: 16px;
  border-radius: 46% 54% 50% 50% / 55% 48% 52% 45%;
  border: 2px solid var(--ink);
  flex: none;
}

.lobby-car { width: 66px; height: 34px; flex: none; }

.player-name {
  flex: 1;
  min-width: 84px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lobby-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
  justify-content: flex-end;
  max-width: 100%;
}

.lobby-add-row {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.lobby-swatch {
  width: 17px;
  height: 17px;
  border-radius: 46% 54% 50% 50% / 55% 48% 52% 45%;
  border: 1.5px solid var(--ink-soft);
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.lobby-swatch.selected {
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 2px rgba(252, 249, 238, 0.9), 0 0 0 3.5px var(--ink);
}

.lobby-swatch.taken {
  opacity: 0.25;
  cursor: default;
}

.bot-diff {
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--field);
  border: 1.5px solid var(--ink);
  border-radius: 9px 7px 10px 6px / 7px 10px 6px 9px;
  padding: 4px 6px;
}

.bot-remove {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text-dim);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  -webkit-tap-highlight-color: transparent;
}

.bot-remove:hover { color: #d64545; background: rgba(74, 68, 56, 0.08); }


/* Placeholder rows for human seats not yet taken. */
.waiting-row { opacity: 0.75; }

.waiting-chip {
  background: transparent !important;
  border: 2px dashed var(--ink-soft);
  box-shadow: none;
}

.waiting-name {
  color: var(--text-dim);
  font-style: italic;
  animation: waiting-pulse 1.6s ease-in-out infinite;
}

@keyframes waiting-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.lobby-rules {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(74, 68, 56, 0.07);
  border: 2px dashed var(--ink-soft);
  border-radius: 14px 11px 15px 10px / 11px 15px 10px 14px;
  padding: 12px 14px;
  text-align: left;
}

/* The Options screen lists the rules bare — the wizard section is frame
   enough; the dashed box stays for the in-lobby settings panel. */
#race-options {
  background: none;
  border: none;
  border-radius: 0;
  padding: 4px 2px;
}

.rule-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.rule-row label {
  color: var(--text-dim);
  font-size: 0.88rem;
}

.rule-row select {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--field);
  border: 1.5px solid var(--ink);
  border-radius: 9px 7px 10px 6px / 7px 10px 6px 9px;
  padding: 5px 8px;
  max-width: 62%;
}

.rule-row select:disabled,
.rule-row input:disabled {
  opacity: 0.6;
}

.rule-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex: none;
}

.rule-note {
  display: block;
  font-size: 0.75rem;
  opacity: 0.8;
}



.lobby-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 4px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------- Turn banner ---------- */

.turn-banner {
  color: var(--ink-dim);
  font-size: 0.82rem;
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
}

.turn-banner.my-turn { color: #2e7d3f; }

/* Collision-state sign inside the status bar. */
.collision-sign {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  border-radius: 999px;
  padding: 1px 10px;
}

.collision-sign.coll-off {
  color: #8a6a00;
  background: rgba(224, 168, 0, 0.2);
}

.collision-sign.coll-on {
  color: #b23327;
  background: rgba(214, 69, 69, 0.16);
  animation: coll-pulse 0.9s ease-in-out 4;
}

@keyframes coll-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* Narrow screens: compact status strip. */
@media (max-width: 560px) {
  .race-status { padding: 5px 10px 7px; gap: 3px; }
  .rs-strip { gap: 6px; height: 32px; }
  .rs-cell { width: 30px; height: 30px; }
  .rs-cell .rs-dot { inset: 4px; }
  .rs-cell.active .rs-dot { font-size: 0.78rem; }
  .turn-banner { font-size: 0.74rem; }
}

/* ---------- Race status: round number + turn strip (top center) ----------
   Drawn to match the map: a strip of the same paper with an inky edge,
   handwritten lettering and wobbly hand-drawn player dots. */

.race-status {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-family: var(--hand);
  background: rgba(252, 249, 238, 0.93);
  border-bottom: 3px solid var(--ink);
  /* uneven corners, like a torn strip of paper */
  border-radius: 0 0 22px 14px / 0 0 14px 20px;
  box-shadow: 0 3px 0 rgba(74, 68, 56, 0.16);
  padding: 7px 16px 9px;
  pointer-events: none;
  z-index: 2;
}

.rs-round {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.rs-round span {
  color: var(--ink);
  font-size: 1rem;
  margin-left: 3px;
}

.rs-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
}

.rs-cell {
  position: relative;
  width: 36px;
  height: 36px;
  flex: none;
}

/* Hand-drawn dots: lumpy outlines with a pen stroke, each a little
   different, some tilted — nothing perfectly round on this paper. */
.rs-dot {
  position: absolute;
  inset: 5px;
  border-radius: 46% 54% 50% 50% / 55% 48% 52% 45%;
  border: 2px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #fff;
  font-weight: 700;
}

.rs-cell:nth-child(2n) .rs-dot {
  border-radius: 53% 47% 45% 55% / 47% 55% 45% 53%;
  transform: rotate(8deg);
}

.rs-cell:nth-child(3n) .rs-dot {
  border-radius: 50% 50% 56% 44% / 44% 52% 48% 56%;
  transform: rotate(-7deg);
}

.rs-cell.me .rs-dot {
  box-shadow: 0 0 0 2.5px rgba(252, 249, 238, 0.9), 0 0 0 4.5px var(--ink);
}

.rs-cell.done .rs-dot { opacity: 0.45; }

.rs-cell.active .rs-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(74, 68, 56, 0.18);
}

.rs-cell.active .rs-dot { font-size: 0.85rem; }

/* Race mode hides the solo HUD. */
.race-mode .solo-hud {
  display: none;
}

/* ---------- Track list ---------- */

/* Each track is a little sheet of paper taped to the page: no boxes,
   just the drawing itself with a shadow, a bit of tape and a tilt. */
.track-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 30px 26px;
  width: 100%;
  padding: 10px 6px 4px;
}

.track-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transform: rotate(-1.3deg);
  transition: transform 0.15s ease;
}

.track-card:nth-of-type(2n) { transform: rotate(1.2deg); }
.track-card:nth-of-type(3n) { transform: rotate(-0.7deg); }

/* Hovering highlights the sheet — the paper stays taped down. */
.track-card:hover, .track-card:focus-visible { outline: none; }

.track-card:hover .track-preview,
.track-card:focus-visible .track-preview {
  outline: 3.5px solid var(--accent);
  outline-offset: 2px;
}

.track-card:hover .track-card-name,
.track-card:focus-visible .track-card-name {
  color: var(--accent-dark);
}

/* Subtle length-group labels spanning the sheet grid. */
.track-section {
  grid-column: 1 / -1;
  text-align: left;
  color: var(--text-dim);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  border-bottom: 2px dashed var(--ink-soft);
  padding-bottom: 3px;
  margin-top: 6px;
}

.track-section:first-child { margin-top: 0; }

/* a strip of tape holding the sheet down */
.track-card::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%;
  width: 60px;
  height: 17px;
  transform: translateX(-50%) rotate(-2.5deg);
  background: rgba(233, 220, 176, 0.8);
  border: 1px solid rgba(74, 68, 56, 0.16);
  z-index: 1;
}

.track-preview {
  width: 100%;
  height: auto;
  border: none;
  border-radius: 2px;
  background: var(--paper);
  box-shadow: 0 2px 0 rgba(74, 68, 56, 0.14), 0 7px 16px rgba(74, 68, 56, 0.22);
}


.track-info {
  display: flex;
  flex-direction: column;
  gap: 0;
  text-align: center;
}

.track-card-name { font-weight: 700; font-size: 1.02rem; }

/* ---------- Tutorial ---------- */

#tutorial-screen {
  align-items: center;
  padding: 28px 16px 48px;
}

.tutorial-wrap {
  background: var(--panel);
  border: 2.5px solid var(--ink);
  border-radius: 24px 18px 26px 16px / 18px 26px 16px 24px;
  box-shadow: 0 3px 0 rgba(74, 68, 56, 0.16);
  padding: 22px 20px 24px;
  width: min(100%, 620px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.tutorial-wrap h2 { font-size: 1.2rem; }

/* One card at a time: the stage keeps a steady height while the pager
   deals steps, with the features card as the final hand. */
.tut-stage {
  width: 100%;
  min-height: 330px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.tut-steps {
  list-style: none;
  display: contents;
}

.tut-step {
  display: none;
  gap: 16px;
  flex-direction: column;
  align-items: center;
}

.tut-step.active { display: flex; }

.tut-box { display: none; }

.tut-box.active { display: block; }

.tut-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.tut-dot {
  width: 12px;
  height: 12px;
  padding: 0;
  border-radius: 46% 54% 50% 50% / 55% 48% 52% 45%;
  border: 1.5px solid var(--ink);
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tut-dot.active { background: var(--accent); }

.tut-nav {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.tut-canvas {
  flex: none;
  width: min(100%, 330px);
  border-radius: 2px;
  box-shadow: 0 2px 0 rgba(74, 68, 56, 0.14), 0 6px 14px rgba(74, 68, 56, 0.2);
  transform: rotate(-1deg);
}

.tut-step:nth-child(2n) .tut-canvas { transform: rotate(1deg); }

.tut-text {
  max-width: 320px;
  text-align: center;
}

.tut-text b { font-size: 1.02rem; }

.tut-text p {
  color: var(--text-dim);
  font-size: 0.92rem;
  line-height: 1.45;
  margin-top: 2px;
}

.tut-features {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  font-size: 0.95rem;
  line-height: 1.4;
}

.tut-features li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.tut-features li > span:first-child { flex: none; margin-top: 1px; }
.tut-features b { color: var(--text); }
.tut-features li > span:last-child { color: var(--text-dim); }

kbd {
  background: var(--field);
  border: 1.5px solid var(--ink);
  border-radius: 6px 4px 7px 4px / 4px 7px 4px 6px;
  padding: 1px 5px;
  font-size: 0.8em;
}

/* ---------- Game ---------- */

#game-screen {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

#canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}

#game-canvas {
  display: block;
  touch-action: none;
  cursor: pointer;
}

/* Floating chrome over the map — same pen-on-paper hand as the map. */
.float-btn {
  position: absolute;
  width: 42px;
  height: 42px;
  border-radius: 47% 53% 50% 50% / 52% 46% 54% 48%;
  border: 2.5px solid var(--ink);
  background: rgba(252, 249, 238, 0.95);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 rgba(74, 68, 56, 0.2);
  transform: rotate(-4deg);
  -webkit-tap-highlight-color: transparent;
}

.float-btn:active { background: #efe6d0; }

/* Bottom-left cluster: exit button + standings (races) / undo-restart (solo). */
.corner-hud {
  position: absolute;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 10px;
  z-index: 2;
}

.corner-hud .float-btn { position: static; }

.solo-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 12px;
  font-family: var(--hand);
  background: rgba(252, 249, 238, 0.93);
  border: 2px solid var(--ink);
  border-radius: 20px 16px 22px 15px / 16px 20px 15px 22px;
  padding: 7px 15px;
  font-size: 0.82rem;
  color: var(--ink-dim);
  pointer-events: none;
}

.solo-hud b { color: var(--ink); font-size: 0.92rem; }

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 16px 12px 18px 11px / 12px 18px 11px 16px;
  box-shadow: 0 2px 0 rgba(74, 68, 56, 0.25);
  padding: 12px 22px;
  cursor: pointer;
  transition: background 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: #ece4cd; }
.btn:active { background: #e2d8bd; box-shadow: none; transform: translateY(2px); }

.btn-small { padding: 8px 14px; font-size: 0.9rem; }

.btn-primary { background: var(--accent); color: #ffffff; }
.btn-primary:hover { background: var(--accent-dark); }

/* ---------- Move pad: 9 big dots mirroring the on-track options ---------- */

.move-pad {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 7px;
  padding: 9px;
  background: rgba(252, 249, 238, 0.92);
  border: 2.5px solid var(--ink);
  border-radius: 22px 16px 20px 15px / 16px 22px 15px 20px;
  box-shadow: 0 3px 0 rgba(74, 68, 56, 0.16);
}

/* Hand-drawn option dots: inky lumpy circles, each one different. */
.pad-dot {
  width: 46px;
  height: 46px;
  border-radius: 46% 54% 50% 50% / 55% 48% 52% 45%;
  border: 2.5px solid var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-family: var(--hand);
  font-size: 1.2rem;
  font-weight: 700;
  padding: 0;
}

.pad-dot:nth-child(2n) {
  border-radius: 53% 47% 45% 55% / 47% 55% 45% 53%;
  transform: rotate(6deg);
}

.pad-dot:nth-child(3n) {
  border-radius: 50% 50% 56% 44% / 44% 52% 48% 56%;
  transform: rotate(-5deg);
}

.pad-dot.safe { background: #2e9e44; }
.pad-dot.crash { background: #d64545; opacity: 0.62; }
.pad-dot.win { background: #e0a800; }
.pad-dot.off { visibility: hidden; }
.pad-dot.idle {
  background: rgba(74, 68, 56, 0.1);
  border-color: rgba(74, 68, 56, 0.5);
  border-style: dashed;
  cursor: default;
}
.pad-dot:not(:disabled):active { filter: brightness(1.15); }

@media (max-width: 480px) {
  .pad-dot { width: 40px; height: 40px; font-size: 1rem; }
  .move-pad { gap: 6px; padding: 7px; }
}

/* ---------- Toast ---------- */

/* Toasts sit just below the race-status bar, in the same paper-and-ink
   hand as the rest of the page. */
.toast {
  position: fixed;
  top: 118px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 65; /* above every screen, below the splash */
  font-family: var(--hand);
  background: rgba(252, 249, 238, 0.95);
  color: #4a4438;
  border: 2px solid #4a4438;
  padding: 7px 16px;
  border-radius: 22px 18px 24px 16px / 18px 24px 16px 22px;
  font-size: 0.92rem;
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* After dark the note flips to chalk on a dusk card. */
body.dark .toast {
  background: rgba(44, 48, 38, 0.95);
  color: var(--text);
  border-color: var(--ink);
}

/* ---------- Win overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 52, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.overlay-card {
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 26px 20px 28px 18px / 20px 28px 18px 26px;
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 10px 30px rgba(58, 52, 40, 0.35);
}

.overlay-card h2 { font-size: 1.5rem; }

.overlay-card p { color: var(--text-dim); line-height: 1.5; white-space: pre-line; }

.win-record {
  color: #e0a800 !important;
  font-weight: 700;
}

/* Race results: a podium for the top three, the rest in a list. */
.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

.pod {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 96px;
  min-width: 0;
}

.pod-medal { font-size: 1.25rem; line-height: 1.2; }
.pod-car { display: block; }

.pod-name {
  font-weight: 700;
  font-size: 0.85rem;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pod-me .pod-name { color: #e0a800; }
.pod-stat { font-size: 0.7rem; color: var(--text-dim); }

.pod-block {
  width: 100%;
  margin-top: 5px;
  border: 2px solid var(--ink);
  border-bottom: none;
  border-radius: 10px 8px 0 0 / 8px 10px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.15rem;
  color: rgba(40, 35, 22, 0.65);
}

.pod-1 .pod-block { height: 62px; background: linear-gradient(#f2cf63, #cf9c1c); }
.pod-2 .pod-block { height: 44px; background: linear-gradient(#e4e7ea, #aeb6c0); }
.pod-3 .pod-block { height: 32px; background: linear-gradient(#dfa878, #b0793f); }

.podium-rest {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.podium-rest li {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.podium-rest .pod-me { color: var(--text); font-weight: 600; }

.pod-dot {
  width: 10px;
  height: 10px;
  border-radius: 46% 54% 50% 50% / 55% 48% 52% 45%;
  border: 1.5px solid var(--ink);
  flex: none;
}

.rest-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rest-stat { white-space: nowrap; font-size: 0.75rem; }

.overlay-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 6px;
}

@media (max-width: 480px) {
  .menu-header h1 { font-size: 1.7rem; }
  .solo-hud { font-size: 0.72rem; gap: 9px; padding: 7px 12px; }
}

/* Narrow screens: the status strip owns the top — toasts slide in
   underneath it. (Kept last so it wins the cascade.) */
@media (max-width: 560px) {
  .toast { top: 126px; }
}


.menu-extras { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ---------- Night-mode component touches ---------- */

body.dark .style-btn.selected,
body.dark .mode-btn.selected { background: #35422c; }
body.dark .color-btn.selected,
body.dark .rs-cell.me .rs-dot {
  box-shadow: 0 0 0 2.5px rgba(44, 48, 38, 0.9), 0 0 0 4.5px var(--ink);
}
body.dark .lobby-swatch.selected {
  box-shadow: 0 0 0 2px rgba(44, 48, 38, 0.9), 0 0 0 3.5px var(--ink);
}
body.dark .race-status,
body.dark .move-pad,
body.dark .float-btn,
body.dark .solo-hud { background: rgba(44, 48, 38, 0.93); }
body.dark .float-btn:active { background: #23261e; }
body.dark .btn:hover { background: #3b4034; }
body.dark .btn:active { background: #2f342a; }
body.dark .btn-primary:hover { background: var(--accent-dark); }
body.dark .track-preview,
body.dark .tut-canvas { box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
