:root {
  --f1-red: #e10600;
  --panel: rgba(12, 14, 18, 0.82);
  --panel-solid: #111418;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f4f5f7;
  --muted: rgba(244, 245, 247, 0.58);
  --green: #22c55e;
  --purple: #a855f7;
  --yellow: #facc15;
  --font: 'Titillium Web', 'Segoe UI', Arial, sans-serif;
  --ink: #16161d;
  --paper: #fffaf0;
  --paper-2: #f3ecdc;
  --sun: #ffd21f;
  --red: #e10600;
  --logo: 'Lilita One', 'Titillium Web', 'Segoe UI', sans-serif;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #121a33;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  font-family: var(--font);
  color: var(--text);
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

input, textarea { -webkit-user-select: auto; user-select: auto; }

canvas.game-canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* ------------------------------------------------------------------ Shared buttons (menu + pause) */
.laps-buttons, .seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
}

.lap-opt, .seg button {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  padding: 8px 6px;
  border-radius: 8px;
  font: 700 14px var(--font);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}

.lap-opt:hover, .seg button:hover { background: rgba(255, 255, 255, 0.13); }

.lap-opt.active, .seg button.active {
  background: var(--f1-red);
  border-color: #ff4d47;
  box-shadow: 0 0 12px rgba(225, 6, 0, 0.35);
}

.tyre-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 3px solid currentColor;
  background: #111;
  display: inline-block;
}
.tyre-dot.soft { color: #e10600; }
.tyre-dot.medium { color: #ffd21f; }
.tyre-dot.hard { color: #f2f2f2; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip { cursor: pointer; }
.chip input { display: none; }
.chip span {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}
.chip input:checked + span {
  color: #fff;
  border-color: rgba(34, 197, 94, 0.7);
  background: rgba(34, 197, 94, 0.18);
}

kbd {
  display: inline-block;
  min-width: 1.2em;
  padding: 0 5px;
  margin: 0 1px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  font: 600 10px var(--font);
  color: rgba(255, 255, 255, 0.9);
}

/* ------------------------------------------------------------------ Game */
.game-screen {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #07080a;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.1em;
  z-index: 50;
}

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  font-family: var(--font);
}

/* Timing tower */
.tower {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 200px;
  background: var(--panel);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  contain: layout paint;
}

.tower-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.45);
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 0.06em;
}

.tower-badge {
  background: var(--f1-red);
  color: #fff;
  font-weight: 900;
  font-style: italic;
  padding: 0 6px;
  border-radius: 3px;
  font-size: 13px;
}

.tower-list { list-style: none; margin: 0; padding: 2px 0; }

.tower-list li {
  display: grid;
  grid-template-columns: 22px 4px 1fr auto 14px;
  align-items: center;
  gap: 6px;
  height: 21px;
  padding: 0 8px;
  font-size: 13px;
  font-weight: 700;
}

.tower-list li.is-player { background: rgba(255, 255, 255, 0.92); color: #0b0d10; }
.tower-list li.is-player .t-gap { color: #0b0d10; }
.tower-list li.hidden-row { display: none; }

.t-pos { text-align: right; opacity: 0.85; }
.t-bar { height: 13px; border-radius: 1px; }
.t-code { letter-spacing: 0.04em; }
.t-gap { font-size: 12px; color: rgba(255, 255, 255, 0.78); font-variant-numeric: tabular-nums; text-align: right; }
.t-gap.purple { color: var(--purple); }
.t-tyre {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2.5px solid #ffd21f;
  background: #111;
}

/* Banner / flags */
.top-center {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(560px, 70vw);
}

.banner, .flag {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s, transform 0.25s;
  padding: 8px 18px;
  border-radius: 6px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-align: center;
  background: var(--panel);
  border-left: 4px solid var(--f1-red);
  font-size: 18px;
}

.banner.show, .flag.show { opacity: 1; transform: none; }
.banner.big { font-size: clamp(26px, 4vw, 44px); font-style: italic; }
.flag.yellow { border-left-color: var(--yellow); }
.flag.blackwhite { border-left: 10px solid; border-image: linear-gradient(135deg, #000 50%, #fff 50%) 1; }
.flag.chequered { border-left: 10px solid; border-image: repeating-linear-gradient(45deg, #000 0 6px, #fff 6px 12px) 1; }
.flag.green { border-left-color: var(--green); }
.flag.purple { border-left-color: var(--purple); }

/* Team radio */
.radio {
  position: absolute;
  top: 110px;
  left: 50%;
  transform: translate(-50%, -6px);
  min-width: 260px;
  max-width: min(520px, 80vw);
  background: rgba(12, 14, 18, 0.9);
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 8px 14px 10px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
}
.radio.show { opacity: 1; transform: translate(-50%, 0); }
.radio-head { font-size: 11px; font-weight: 900; letter-spacing: 0.14em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.radio-wave { width: 18px; height: 10px; background: repeating-linear-gradient(90deg, var(--f1-red) 0 2px, transparent 2px 4px); animation: wave 0.5s infinite alternate; }
@keyframes wave { from { transform: scaleY(0.4); } to { transform: scaleY(1); } }
.radio-text { font-size: 16px; font-weight: 700; margin-top: 2px; }

/* Minimap */
.map-container {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 190px;
  height: 190px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
#minimap { width: 100%; height: 100%; display: block; }

/* Lap timing */
.timing {
  position: absolute;
  top: 212px;
  right: 12px;
  width: 190px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-variant-numeric: tabular-nums;
}
.timing-row { display: flex; justify-content: space-between; font-size: 14px; font-weight: 700; line-height: 1.5; }
.timing-row.big { font-size: 20px; font-weight: 900; }
.timing-row.small { font-size: 12px; opacity: 0.8; }
.t-label { color: var(--muted); font-size: 11px; letter-spacing: 0.1em; align-self: center; }
.delta.ahead { color: var(--green); }
.delta.behind { color: #ff5a52; }
.sectors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 4px 0; }
.sector {
  text-align: center;
  font-size: 11px;
  font-weight: 900;
  padding: 2px 0;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}
.sector.purple { background: var(--purple); color: #fff; }
.sector.green { background: var(--green); color: #04130a; }
.sector.yellow { background: var(--yellow); color: #1a1500; }

/* Dashboard */
.dash {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 14px 8px;
}

.revlights { display: grid; grid-template-columns: repeat(15, 1fr); gap: 4px; margin-bottom: 6px; }
.revlights i {
  height: 9px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  transition: background 0.04s;
}
.revlights i.g.on { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.revlights i.r.on { background: #ef4444; box-shadow: 0 0 8px #ef4444; }
.revlights i.b.on { background: #6366f1; box-shadow: 0 0 8px #818cf8; }
.revlights.flash i { background: #6366f1; box-shadow: 0 0 10px #818cf8; }

.dash-main { display: grid; grid-template-columns: 1fr 70px 1.25fr; align-items: center; gap: 8px; }
.dash-block { display: flex; flex-direction: column; align-items: flex-end; }
.dash-block.left { align-items: stretch; gap: 6px; }
.speed-number { font-size: 40px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.dash-unit { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: 0.12em; }

.gear-display {
  font-size: 48px;
  font-weight: 900;
  text-align: center;
  line-height: 1;
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 4px 0;
}

.meter { display: grid; grid-template-columns: 30px 1fr 34px; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.m-label { color: var(--muted); font-size: 11px; letter-spacing: 0.08em; }
.meter > span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; transform-origin: left center; background: linear-gradient(90deg, #facc15, #22c55e); }
.bar.tyre i { background: linear-gradient(90deg, #ef4444, #facc15 40%, #22c55e); }
#ers-bar.boost { background: linear-gradient(90deg, #a855f7, #ec4899); }

.dash-modes { display: flex; justify-content: center; gap: 6px; margin-top: 6px; min-height: 18px; }
.mode {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.1em;
  padding: 1px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.28);
}
.mode.on { background: #0ea5e9; color: #fff; }
.mode.ovt.ready { background: rgba(168, 85, 247, 0.35); color: #fff; }
.mode.ovt.on { background: #a855f7; color: #fff; }
.mode.drs.ready { background: rgba(34, 197, 94, 0.25); color: #bbf7d0; box-shadow: inset 0 0 0 1px #22c55e; }
.mode.drs.on { background: #22c55e; color: #052e14; }
.mode.brk { display: none; }
.mode.brk.on { display: inline-block; background: #22c55e; color: #052e14; }
.mode.dmg { display: none; }
.mode.dmg.on { display: inline-block; background: #f97316; color: #fff; }

.reaction {
  position: absolute;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 15px;
  font-weight: 700;
  background: var(--panel);
  padding: 4px 12px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.3s;
}
.reaction.show { opacity: 1; }

.key-hints {
  position: absolute;
  bottom: 6px;
  left: 12px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.45);
  text-shadow: 0 1px 2px #000;
}

/* ------------------------------------------------------------------ Podium ceremony */
.podium-overlay { display: none; position: absolute; inset: 0; z-index: 4000; pointer-events: none; }
body.podium-on .podium-overlay { display: block; }
body.podium-on #hud, body.podium-on .mobile-controls { display: none !important; }
.podium-title {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%) rotate(-2deg);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.podium-title span {
  font: 400 54px / 1 var(--logo);
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
  letter-spacing: 2px;
}
.podium-title em {
  font-style: normal; font-weight: 800; font-size: 15px; color: var(--ink);
  background: var(--sun); border: 3px solid var(--ink); border-radius: 999px; padding: 2px 14px; box-shadow: 0 3px 0 var(--ink);
}
.podium-cards {
  position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: flex-end; gap: 10px;
}
.podium-card {
  width: 170px; padding: 8px 10px 10px;
  background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 5px 0 var(--ink);
  animation: panel-pop 0.4s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}
.podium-card.p1 { width: 200px; transform: translateY(-14px); }
.podium-card .pc-pos { font: 400 26px / 1 var(--logo); }
.podium-card.p1 .pc-pos { color: #d9a400; }
.podium-card .pc-name { font-weight: 900; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.podium-card .pc-team { font-size: 12px; font-weight: 700; color: #5b5d66; display: flex; align-items: center; gap: 6px; }
.podium-card .pc-team i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); }
.podium-skip {
  pointer-events: auto; position: absolute; right: 18px; bottom: 22px;
  font: 400 20px / 1 var(--logo); color: #fff; padding: 10px 16px 11px;
  background: linear-gradient(180deg, #ff3b2f, var(--red)); border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: 0 5px 0 var(--ink); cursor: pointer; -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill;
}
.podium-skip:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
@media (max-width: 700px) {
  .podium-title span { font-size: 38px; }
  .podium-cards { gap: 6px; bottom: 80px; }
  .podium-card { width: 104px; padding: 6px; }
  .podium-card.p1 { width: 118px; }
  .podium-card .pc-name { font-size: 12px; }
  .podium-skip { bottom: 18px; right: 50%; transform: translateX(50%); }
}

/* ------------------------------------------------------------------ Pause / results (cartoon, like the menu) */
.pause-menu, .results {
  position: absolute;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(22, 22, 29, 0.25), rgba(22, 22, 29, 0.72)),
    rgba(63, 167, 239, 0.18);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.pause-panel, .results-panel {
  position: relative;
  width: min(390px, 94vw);
  max-height: 94dvh;
  overflow-y: auto;
  padding: 22px 22px 24px;
  text-align: center;
  color: var(--ink);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 26px;
  box-shadow: 0 9px 0 var(--ink), 0 24px 60px rgba(0, 0, 0, 0.35);
  animation: panel-pop 0.28s cubic-bezier(0.3, 1.6, 0.5, 1);
}
/* Chequered tab on top of the card */
.pause-panel::before, .results-panel::before {
  content: '';
  display: block;
  width: 64px;
  height: 22px;
  margin: -4px auto 10px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  background: conic-gradient(#fff 0 25%, var(--ink) 0 50%, #fff 0 75%, var(--ink) 0) 0 0 / 14px 11px;
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(-3deg);
}
@keyframes panel-pop {
  from { transform: scale(0.85) translateY(14px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.pause-panel h2, .results-head h2 {
  margin: 0 0 8px;
  font: 400 44px / 1 var(--logo);
  letter-spacing: 1px;
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
  transform: rotate(-2deg);
}
.pause-sub {
  display: inline-block;
  margin: 2px 0 16px;
  padding: 3px 14px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
}
.pause-sub:empty { display: none; }
.laps-label {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5b5d66;
}
.pause-panel .laps-picker { margin-bottom: 8px; }

.pause-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 11px 16px 12px;
  font: 400 21px / 1 var(--logo);
  letter-spacing: 0.5px;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s, box-shadow 0.08s, background 0.12s, filter 0.12s;
}
.pause-btn:hover { background: #fff4c7; }
.pause-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.pause-btn-primary, .pause-btn-danger { color: #fff; }
.pause-btn-primary {
  font-size: 25px;
  background: linear-gradient(180deg, #ff3b2f, var(--red));
  box-shadow: 0 6px 0 var(--ink), inset 0 -5px 0 rgba(0, 0, 0, 0.18), inset 0 3px 0 rgba(255, 255, 255, 0.25);
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 2px 0 var(--ink);
}
.pause-btn-primary:hover { background: linear-gradient(180deg, #ff5246, #f01208); }
.pause-btn-danger { background: #3b4250; }
.pause-btn-danger:hover { background: #4a5262; }

.results-panel { width: min(660px, 96vw); text-align: left; padding: 18px 20px 0; }
.results-panel::before { margin-top: 0; }
.results-head { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 10px; text-align: center; }
.results-head h2 { font-size: 34px; margin-bottom: 6px; }
.results-head .pause-sub { margin-bottom: 4px; }
.results-head .tower-badge {
  padding: 4px 10px;
  font: 400 20px var(--logo);
  font-style: normal;
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(-4deg);
}

.results-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  overflow: hidden;
}
.results-table th {
  text-align: left;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--ink);
}
.results-table td { padding: 3px 8px; font-weight: 700; font-size: 13px; color: var(--ink); border-top: 1.5px solid #ece6d6; }
.results-table tbody tr:nth-child(even) td { background: #fbf7ec; }
.results-table tr.is-player td { background: var(--sun); color: var(--ink); font-weight: 900; }
.results-table .team-dot { display: inline-block; width: 6px; height: 14px; margin-right: 6px; vertical-align: -2px; border-radius: 3px; border: 1.5px solid var(--ink); }
.results-table .fl { color: #8b2fd6; font-weight: 900; }
.results-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 6px -20px 0;
  position: sticky;
  bottom: 0;
  padding: 8px 20px 18px;
  background: linear-gradient(180deg, rgba(255, 250, 240, 0), var(--paper) 30%);
}
.results-actions .pause-btn { margin-top: 0; font-size: 18px; }
.results-head { position: relative; }
.share-btn {
  display: inline-block;
  white-space: nowrap;
  vertical-align: top;
  margin: 2px 0 4px 8px;
  padding: 6px 12px 7px;
  font: 400 16px / 1 var(--logo);
  color: var(--ink);
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  transform: rotate(3deg);
}
.share-btn:active { transform: rotate(3deg) translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.share-btn:disabled { opacity: 0.6; cursor: wait; }
@media (max-width: 560px) { .share-btn { margin: 4px 0 6px; } }
.challenge-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(440px, 100%);
  padding: 10px 12px 10px 14px;
  color: var(--ink);
  background: #fff;
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 6px 0 var(--ink);
  animation: nav-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.challenge-card[hidden] { display: none; }
.challenge-card p { margin: 0; flex: 1; font-weight: 800; font-size: 14px; line-height: 1.25; }
.challenge-card p b { font: 400 20px / 1 var(--logo); }
.ch-tag {
  position: absolute;
  top: -14px;
  left: 12px;
  padding: 2px 10px;
  font: 400 14px / 1.2 var(--logo);
  color: #fff;
  background: var(--red);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  transform: rotate(-3deg);
}
.ch-go {
  flex-shrink: 0;
  padding: 8px 14px 9px;
  font: 400 18px / 1 var(--logo);
  color: #fff;
  background: linear-gradient(180deg, #ff3b2f, var(--red));
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  -webkit-text-stroke: 1px var(--ink);
  paint-order: stroke fill;
}
.hud .target-row[hidden] { display: none; }
.hud .target-row span:last-child { color: #dc2626; font-weight: 900; }
.hud .target-row.beaten span:last-child { color: #15803d; }
.results-actions .pause-btn[hidden] { display: none; }
.results-actions.four { grid-template-columns: repeat(4, 1fr); }
.results-actions .pause-btn-primary { font-size: 20px; }

/* Phones: the team column shrinks to its colour dot, names stay on one line */
@media (max-width: 560px) {
  .results-panel { padding: 14px 12px 0; }
  .results-head { gap: 8px; }
  .results-head h2 { font-size: 28px; }
  .results-head .tower-badge { font-size: 16px; }
  .results-table th, .results-table td { padding: 3px 5px; font-size: 12px; }
  .results-table th:nth-child(3), .results-table td:nth-child(3) { font-size: 0; padding: 3px 2px; }
  .results-table td:nth-child(2) { max-width: 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .results-table .team-dot { margin-right: 0; }
  .results-actions { margin: 6px -12px 0; padding: 8px 12px 14px; gap: 7px; }
  .results-actions .pause-btn, .results-actions .pause-btn-primary { font-size: 16px; padding: 10px 6px 11px; }
}

.vibe-jam-badge {
  font-family: system-ui, sans-serif;
  position: fixed;
  bottom: -1px;
  right: -1px;
  padding: 7px;
  font-size: 14px;
  font-weight: bold;
  background: #fff;
  color: #000;
  text-decoration: none;
  z-index: 10000;
  border-top-left-radius: 12px;
  border: 1px solid #fff;
}


/* ------------------------------------------------------------------ Mobile */
.mobile-controls { display: none; }

@media (max-width: 768px), (pointer: coarse) and (max-height: 520px) {
  .tower { width: 150px; top: 6px; left: 6px; }
  .tower-list li { height: 17px; font-size: 11px; grid-template-columns: 18px 3px 1fr auto 10px; gap: 4px; padding: 0 5px; }
  .tower-list li.far-row { display: none; }
  .t-gap { font-size: 10px; }
  .t-tyre { width: 10px; height: 10px; border-width: 2px; }

  .map-container { width: 120px; height: 120px; top: 6px; right: 6px; }
  .timing { top: 132px; right: 6px; width: 130px; padding: 5px 8px; }
  .timing-row { font-size: 11px; }
  .timing-row.big { font-size: 14px; }

  .dash { bottom: 8px; width: 250px; padding: 5px 8px; border-radius: 10px; }
  .game-active .vibe-jam-badge { display: none; }
  .speed-number { font-size: 26px; }
  .gear-display { font-size: 30px; }
  .dash-main { grid-template-columns: 1fr 46px 1.2fr; }
  .meter { grid-template-columns: 24px 1fr 28px; font-size: 10px; }

  .radio { top: 96px; }
  .banner { font-size: 14px; }
  .banner.big { font-size: 24px; }
  .key-hints { display: none; }
  .reaction { bottom: 130px; }

  .mobile-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 12px;
    z-index: 100;
    pointer-events: none;
  }
  .mobile-controls button {
    pointer-events: auto;
    touch-action: none;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    font: 900 14px var(--font);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .mobile-controls button:active { transform: scale(0.94); filter: brightness(1.25); }
  .left-controls, .right-controls { display: flex; gap: 12px; align-items: flex-end; }
  .btn-left, .btn-right {
    width: 84px;
    height: 84px;
    border-radius: 50%;
    font-size: 32px !important;
    background: rgba(255, 255, 255, 0.18);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25) inset;
  }
  .btn-accelerate { width: 92px; height: 120px; border-radius: 14px; background: rgba(34, 197, 94, 0.55); }
  .btn-brake { width: 84px; height: 96px; border-radius: 14px; background: rgba(239, 68, 68, 0.55); }
  .btn-boost { width: 54px; height: 54px; border-radius: 50%; background: rgba(168, 85, 247, 0.6); font-size: 12px !important; }
}

/* Phones held upright: stack dash above the controls, radio above the dash */
@media (orientation: portrait) and (max-width: 600px) {
  .dash { bottom: 150px; width: min(340px, 92vw); }
  .radio { top: auto; bottom: 252px; }
  .reaction { bottom: 250px; }
  .left-controls, .right-controls { gap: 8px; }
  .btn-left, .btn-right { width: 64px; height: 64px; font-size: 26px !important; }
  .btn-accelerate { width: 74px; height: 110px; }
  .btn-brake { width: 66px; height: 88px; }
  .btn-boost { width: 46px; height: 46px; }
  .mobile-controls { padding: 0 8px; }
}

/* ------------------------------------------------------------------ Cartoon extras, weather & pit */
.seg.five { grid-template-columns: repeat(5, 1fr); }
.seg.two { grid-template-columns: repeat(2, 1fr); }
.tyre-dot.inter { color: #2fd14a; }
.tyre-dot.wet { color: #2b8cff; }

.banner.big {
  -webkit-text-stroke: 1.5px #0b0d10;
  text-shadow: 3px 3px 0 #0b0d10;
  transform-origin: center;
}
.banner.big.show { animation: pop 0.35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(0.6); } to { transform: none; } }

.weather-chip {
  margin-top: 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  padding: 3px 0;
  border-radius: 6px;
  background: rgba(250, 204, 21, 0.18);
  color: #fde68a;
}
.weather-chip.wet { background: rgba(59, 130, 246, 0.28); color: #bfdbfe; }

.mode.pit { display: none; border: 2px solid #ffd21f; }
.mode.pit.on { display: inline-block; background: #111; color: #fff; animation: blink 0.8s infinite alternate; }
@keyframes blink { to { filter: brightness(1.6); } }

.speedlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  background: repeating-conic-gradient(from 0deg at 50% 55%, rgba(255, 255, 255, 0.0) 0deg 4deg, rgba(255, 255, 255, 0.22) 4.4deg 4.8deg, rgba(255, 255, 255, 0) 5.2deg 9deg);
  -webkit-mask: radial-gradient(circle at 50% 55%, transparent 0 32%, #000 70%);
  mask: radial-gradient(circle at 50% 55%, transparent 0 32%, #000 70%);
}

.popups { position: absolute; left: 50%; bottom: 190px; transform: translateX(-50%); width: 0; height: 0; }
.popup {
  position: absolute;
  left: -60px;
  width: 120px;
  text-align: center;
  font-size: 46px;
  font-weight: 900;
  font-style: italic;
  -webkit-text-stroke: 2px #0b0d10;
  text-shadow: 4px 4px 0 #0b0d10;
  animation: rise 1.25s ease-out forwards;
}
.popup.good { color: #4ade80; }
.popup.bad { color: #f87171; }
@keyframes rise {
  0% { transform: translateY(20px) scale(0.5); opacity: 0; }
  20% { transform: translateY(0) scale(1.15); opacity: 1; }
  100% { transform: translateY(-90px) scale(1); opacity: 0; }
}

.pit-panel {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%) scale(0.8);
  min-width: 300px;
  padding: 14px 22px 16px;
  text-align: center;
  border-radius: 18px;
  background: rgba(12, 14, 18, 0.9);
  border: 3px solid #ffd21f;
  box-shadow: 6px 6px 0 #0b0d10;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}
.pit-panel.show { opacity: 1; transform: translate(-50%, -50%); }
.pit-panel.go { border-color: #22c55e; animation: shake 0.3s infinite; }
@keyframes shake { 50% { transform: translate(-50%, -50%) rotate(-1.5deg) scale(1.03); } }
.pit-title { font-size: 20px; font-weight: 900; letter-spacing: 0.08em; }
.pit-panel.go .pit-title { color: #4ade80; font-size: 30px; }
.pit-time { font-size: 38px; font-weight: 900; font-variant-numeric: tabular-nums; }
.pit-bar { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.12); overflow: hidden; margin: 6px 0; }
.pit-bar i { display: block; height: 100%; transform-origin: left; transform: scaleX(0); background: linear-gradient(90deg, #ffd21f, #22c55e); }
.pit-hint { font-size: 13px; color: var(--muted); font-weight: 700; }

.btn-pit, .btn-drs, .btn-look, .btn-assist { display: none; }
.mode.vscm { display: none; }
.hud .mode.vscm.on { display: inline-block; background: var(--sun); color: var(--ink); animation: blink 0.6s infinite alternate; }
.hud .flag.vsc { background: var(--sun); }
.hud .flag.vsc::before { content: "VSC"; margin-right: 8px; padding: 0 6px; border: 2px solid var(--ink); border-radius: 6px; background: #fff; }
.hud .flag.blue { background: #3b82f6; color: #fff; -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; }
.stack-controls { display: flex; flex-direction: column; gap: 8px; align-items: center; }
@media (max-width: 768px), (pointer: coarse) and (max-height: 520px) {
  .btn-pit { display: flex; width: 54px; height: 54px; border-radius: 50%; background: rgba(255, 210, 31, 0.75); color: #111 !important; font-size: 12px !important; }
  .btn-drs { display: flex; width: 54px; height: 44px; border-radius: 12px; background: rgba(34, 197, 94, 0.7); color: #052e14 !important; font-size: 12px !important; }
  .pit-panel { top: 40%; min-width: 220px; padding: 8px 14px; }
  .timing .sectors, .timing .timing-row.small { display: none; }
  .weather-chip { margin-top: 3px; font-size: 10px; padding: 1px 0; }
  .pit-time { font-size: 26px; }
  .popups { bottom: 160px; }
}
@media (orientation: portrait) and (max-width: 600px) {
  .btn-pit { width: 44px; height: 44px; }
}

/* ------------------------------------------------------------------ Menu (cartoon garage) */
.menu-screen {
  --sky-top: #3fa7ef;
  --sky-low: #bfe6ff;
  position: absolute;
  inset: 0;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: safe center;
  z-index: 200;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-top) 0%, #7cc8f7 45%, var(--sky-low) 72%);
  color: var(--ink);
}

/* --- Sky, hills and a strip of race track drawn in CSS */
.menu-sky, .menu-sky i { position: absolute; display: block; pointer-events: none; }
.menu-sky { inset: 0; overflow: hidden; }
.menu-sky .sun {
  width: 120px; height: 120px; top: 6%; right: 9%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 38%, #fff6b8, var(--sun) 60%);
  border: 4px solid var(--ink);
  box-shadow: 0 0 0 14px rgba(255, 233, 120, 0.35), 0 0 0 30px rgba(255, 233, 120, 0.16);
}
.menu-sky .cloud {
  width: 150px; height: 44px;
  border-radius: 40px;
  background: #fff;
  border: 4px solid var(--ink);
  box-shadow: inset 0 -8px 0 #dbeefa;
  animation: cloud-drift 70s linear infinite;
}
.menu-sky .cloud::before, .menu-sky .cloud::after {
  content: '';
  position: absolute;
  background: #fff;
  border: 4px solid var(--ink);
  border-bottom: none;
  border-radius: 50% 50% 0 0;
}
.menu-sky .cloud::before { width: 62px; height: 46px; left: 20px; bottom: 26px; }
.menu-sky .cloud::after { width: 48px; height: 34px; left: 70px; bottom: 26px; }
.menu-sky .c1 { top: 9%; left: -10%; animation-duration: 80s; }
.menu-sky .c2 { top: 22%; left: 30%; transform: scale(0.7); animation-duration: 105s; animation-delay: -40s; }
.menu-sky .c3 { top: 5%; left: 60%; transform: scale(0.85); animation-duration: 95s; animation-delay: -70s; }
.menu-sky .c4 { top: 30%; left: 80%; transform: scale(0.55); animation-duration: 120s; animation-delay: -20s; }
@keyframes cloud-drift {
  from { translate: -30vw 0; }
  to { translate: 130vw 0; }
}

.menu-sky .hills { left: -10%; right: -10%; border-top: 4px solid var(--ink); }
.menu-sky .hills.back {
  bottom: 70px; height: 34vh;
  background: #8fd16a;
  border-radius: 50% 60% 0 0 / 100% 100% 0 0;
  box-shadow: inset 0 14px 0 #a6dd84;
}
.menu-sky .hills.front {
  bottom: 60px; height: 20vh; left: 30%; right: -20%;
  background: #6cc24a;
  border-radius: 60% 40% 0 0 / 100% 100% 0 0;
  box-shadow: inset 0 12px 0 #84d062;
}
.menu-sky .road {
  left: 0; right: 0; bottom: 0; height: 64px;
  background:
    repeating-linear-gradient(90deg, #fff 0 34px, transparent 34px 80px) 0 31px / 100% 4px no-repeat,
    #3b4250;
  border-top: 4px solid var(--ink);
  animation: road-run 0.9s linear infinite;
}
.menu-sky .road::before {
  content: '';
  position: absolute; left: 0; right: 0; top: -14px; height: 12px;
  background: repeating-linear-gradient(90deg, var(--red) 0 28px, #fff 28px 56px);
  border-top: 3px solid var(--ink);
  animation: kerb-run 0.9s linear infinite;
}
@keyframes kerb-run {
  from { background-position: 0 0; }
  to { background-position: -56px 0; }
}
@keyframes road-run {
  from { background-position: 0 31px, 0 0; }
  to { background-position: -80px 31px, 0 0; }
}

/* --- Live background: TV shots of the circuit behind the menu */
.menu-sky { transition: opacity 0.8s; }
body.attract-on .menu-screen { background: transparent; }
body.attract-on .menu-sky { opacity: 0; }
body.attract-on #game-screen { display: block !important; }
body.attract-on #hud, body.attract-on .mobile-controls, body.attract-on .podium-overlay,
body.attract-on #results, body.attract-on #pause-menu, body.attract-on #loading { display: none !important; }
.attract-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s;
  /* halftone dots + a soft vignette keep the cards readable */
  background:
    radial-gradient(rgba(22, 22, 29, 0.22) 1.1px, transparent 1.6px) 0 0 / 7px 7px,
    radial-gradient(ellipse at 50% 45%, rgba(22, 22, 29, 0) 35%, rgba(22, 22, 29, 0.45) 100%);
}
body.attract-on .attract-fx { opacity: 1; }
.attract-fx::after {
  content: "";
  position: absolute;
  top: -10%;
  bottom: -10%;
  left: -60%;
  width: 45%;
  background:
    radial-gradient(rgba(22, 22, 29, 0.35) 1.4px, transparent 2px) 0 0 / 9px 9px,
    var(--sun);
  border-left: 6px solid var(--ink);
  border-right: 6px solid var(--ink);
  transform: skewX(-14deg) translateX(0);
  opacity: 0;
}
.attract-fx.cut::after { animation: tv-wipe 0.85s ease-in-out; }
@keyframes tv-wipe {
  0% { opacity: 1; transform: skewX(-14deg) translateX(0); }
  100% { opacity: 1; transform: skewX(-14deg) translateX(400%); }
}
.tv-tag {
  position: absolute;
  top: 16px;
  left: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 5px;
  font: 400 16px / 1 var(--logo);
  letter-spacing: 0.5px;
  color: #fff;
  background: var(--red);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--ink);
  -webkit-text-stroke: 1px var(--ink);
  paint-order: stroke fill;
  transform: rotate(-3deg);
}
.tv-tag i { width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); animation: tv-blink 1s steps(2) infinite; }
@keyframes tv-blink { 50% { opacity: 0.2; } }

/* --- Content */
.menu-content {
  position: relative;
  width: min(1180px, 100%);
  max-height: 100dvh;
  overflow-y: auto;
  padding: 18px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
}

.menu-logo {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font: 400 clamp(46px, 7vw, 76px) / 1 var(--logo);
  letter-spacing: 1px;
  transform: rotate(-2deg);
}
.logo-text {
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink);
}
.logo-text b { font-weight: 400; color: var(--red); }
.logo-flag {
  width: 54px; height: 40px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  background: conic-gradient(#fff 0 25%, var(--ink) 0 50%, #fff 0 75%, var(--ink) 0) 0 0 / 18px 20px;
  box-shadow: 0 5px 0 var(--ink);
  transform: skewX(-10deg);
  animation: flag-wave 2.4s ease-in-out infinite;
}
@keyframes flag-wave {
  0%, 100% { transform: skewX(-10deg) rotate(-4deg); }
  50% { transform: skewX(-4deg) rotate(4deg); }
}
.menu-tagline {
  display: inline-block;
  margin: 10px 0 0;
  padding: 4px 16px;
  font: 700 15px var(--font);
  color: var(--ink);
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--ink);
}

.start-wrap { display: flex; flex-direction: column; gap: 8px; }

.menu-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px 16px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 7px 0 var(--ink);
}

.menu-section {
  margin: 4px 0 2px;
  font: 400 19px / 1 var(--logo);
  letter-spacing: 0.5px;
}
.menu-section:first-child { margin-top: 0; }
.menu-section span {
  display: inline-block;
  padding: 5px 14px 6px;
  color: #fff;
  background: var(--red);
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(-2deg);
}

.menu-field-label {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5b5d66;
}

.team-power-hint { margin: 0; font-size: 12.5px; font-weight: 600; color: #5b5d66; line-height: 1.3; }

#pilot-name, .menu-select {
  width: 100%;
  padding: 9px 12px;
  font: 700 14px var(--font);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: inset 0 -3px 0 var(--paper-2);
  outline: none;
}
.menu-select {
  cursor: pointer;
  appearance: none;
  padding-right: 34px;
  background:
    linear-gradient(45deg, transparent 50%, var(--ink) 50%) calc(100% - 18px) 52% / 7px 7px no-repeat,
    linear-gradient(-45deg, transparent 50%, var(--ink) 50%) calc(100% - 11px) 52% / 7px 7px no-repeat,
    #fff;
}
.menu-select option { background: #fff; color: var(--ink); }
#pilot-name::placeholder { color: #9a9ba3; }
#pilot-name:focus, .menu-select:focus-visible { border-color: var(--red); box-shadow: 0 0 0 3px rgba(225, 6, 0, 0.2); }

/* Chunky push buttons */
.menu-screen .lap-opt, .menu-screen .seg button, .pause-menu .lap-opt {
  padding: 8px 4px;
  font: 800 13.5px var(--font);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, background 0.12s;
}
.menu-screen .lap-opt:hover, .menu-screen .seg button:hover, .pause-menu .lap-opt:hover { background: #fff4c7; }
.menu-screen .lap-opt:active, .menu-screen .seg button:active, .pause-menu .lap-opt:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.menu-screen .lap-opt.active, .menu-screen .seg button.active, .pause-menu .lap-opt.active {
  background: var(--sun);
  border-color: var(--ink);
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--ink), inset 0 -4px 0 rgba(0, 0, 0, 0.12);
}
.menu-screen .tyre-dot { width: 15px; height: 15px; border-width: 4px; background: #2a2d35; box-shadow: 0 0 0 1.5px var(--ink); }
.menu-screen .tyre-dot.hard { color: #fff; }

.menu-screen .chips { gap: 7px; }
.menu-screen .chip span {
  padding: 6px 12px 6px 30px;
  position: relative;
  font-size: 12.5px;
  font-weight: 800;
  color: #6b6d75;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
}
.menu-screen .chip span::before {
  content: '';
  position: absolute; left: 8px; top: 50%;
  width: 14px; height: 14px; margin-top: -7px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  background: #e6e2d6;
}
.menu-screen .chip input:checked + span { color: var(--ink); background: #c9f5d5; border-color: var(--ink); }
.menu-screen .chip input:checked + span::before { background: #22c55e; box-shadow: inset 0 0 0 2.5px #fff; }
.menu-screen .chip input:focus-visible + span { outline: 3px solid var(--red); outline-offset: 2px; }

.mini-flag {
  width: 22px; height: 15px;
  flex-shrink: 0;
  border: 2px solid var(--ink);
  border-radius: 3px;
}
.mini-flag.it { background: linear-gradient(90deg, #009246 0 33.3%, #fff 0 66.6%, #ce2b37 0); }
.mini-flag.mc { background: linear-gradient(180deg, #ce1126 0 50%, #fff 0); }
.mini-flag.sg { background: linear-gradient(180deg, #ef3340 0 50%, #fff 0); }
.menu-screen .seg[data-setting="circuit"] { grid-template-columns: repeat(2, 1fr); }
.mini-flag.uk {
  background:
    linear-gradient(90deg, transparent 40%, #c8102e 40% 60%, transparent 60%),
    linear-gradient(180deg, transparent 38%, #c8102e 38% 62%, transparent 62%),
    linear-gradient(90deg, transparent 32%, #fff 32% 68%, transparent 68%),
    linear-gradient(180deg, transparent 28%, #fff 28% 72%, transparent 72%),
    #012169;
}
.menu-screen .seg.locked { opacity: 0.55; pointer-events: none; }
.menu-screen .is-locked { opacity: 0.6; pointer-events: none; }
.mini-link {
  align-self: flex-start;
  margin: 0 0 2px;
  padding: 3px 12px;
  font: 800 12px var(--font);
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 2px 0 var(--ink);
  cursor: pointer;
}
.mini-link[hidden] { display: none; }
.mini-flag.br { position: relative; overflow: hidden; background: #1f9d3a; }
.mini-flag.br::before, .mini-flag.br::after { content: ''; position: absolute; left: 50%; top: 50%; }
.mini-flag.br::before { width: 8px; height: 8px; background: #ffd21f; transform: translate(-50%, -50%) scaleX(1.45) rotate(45deg); }
.mini-flag.br::after { width: 5px; height: 5px; border-radius: 50%; background: #1e3a8a; transform: translate(-50%, -50%); }

/* --- Circuit map preview */
.circuit-preview {
  position: relative;
  margin-top: 4px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background:
    radial-gradient(rgba(255, 255, 255, 0.08) 1.2px, transparent 1.7px) 0 0 / 9px 9px,
    #1d2c5a;
  box-shadow: 0 4px 0 var(--ink);
  overflow: hidden;
}
.circuit-map { display: block; width: 100%; height: 170px; }
.circuit-stats {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 7px;
  display: flex;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}
.cs-name {
  font: 400 17px / 1 var(--logo);
  color: #fff;
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 2px 0 var(--ink);
  margin-right: auto;
}
.cs-chip {
  padding: 2px 8px;
  font-size: 11.5px;
  font-weight: 900;
  color: var(--ink);
  background: var(--sun);
  border: 2px solid var(--ink);
  border-radius: 999px;
}
@media (max-width: 680px) { .circuit-map { height: 150px; } }

/* --- Showcase */
.showcase-card { padding: 10px 10px 14px; gap: 8px; }
.showcase-stage {
  position: relative;
  height: clamp(190px, 30vh, 260px);
  border: 3px solid var(--ink);
  border-radius: 16px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 55% at 50% 72%, rgba(255, 255, 255, 0.85), transparent 70%),
    linear-gradient(180deg, #d9f1ff, #fff3d6);
}
.showcase-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-badge {
  position: absolute; top: 8px; left: 8px;
  padding: 2px 10px;
  font: 400 14px var(--logo);
  color: #fff;
  background: var(--ink);
  border-radius: 999px;
  transform: rotate(-3deg);
}
.nameplate {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}
.np-code {
  flex-shrink: 0;
  min-width: 64px;
  padding: 6px 8px 5px;
  text-align: center;
  font: 400 22px / 1 var(--logo);
  color: #fff;
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
  background: var(--red);
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 4px 0 var(--ink);
  transform: rotate(-3deg);
}
.np-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.np-text strong { font-size: 18px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-text span { font-size: 13px; font-weight: 700; color: #5b5d66; }
.team-swatch {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  background: var(--red);
}
.power-meter { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.pm-label { font-size: 12px; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; color: #5b5d66; }
.pm-bar {
  flex: 1;
  height: 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #e6e2d6;
  overflow: hidden;
}
.pm-bar i {
  display: block;
  height: 100%;
  width: 50%;
  border-right: 3px solid var(--ink);
  background: repeating-linear-gradient(-45deg, #ffd21f 0 8px, #ffbf00 8px 16px);
  transition: width 0.35s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.showcase-card .team-power-hint { padding: 0 4px; }

/* --- Start */
#start-engine-btn {
  width: 100%;
  padding: 14px 16px 16px;
  font: 400 clamp(24px, 3vw, 32px) / 1 var(--logo);
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(180deg, #ff3b2f, var(--red));
  border: 4px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 8px 0 var(--ink), inset 0 -6px 0 rgba(0, 0, 0, 0.18), inset 0 4px 0 rgba(255, 255, 255, 0.25);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
#start-engine-btn span {
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink);
}
#start-engine-btn:hover { filter: brightness(1.08); animation: start-wiggle 0.5s ease-in-out; }
#start-engine-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--ink), inset 0 -3px 0 rgba(0, 0, 0, 0.18); }
#start-engine-btn:disabled { filter: grayscale(0.6); cursor: wait; }
@keyframes start-wiggle {
  0%, 100% { rotate: 0deg; }
  30% { rotate: -1.5deg; }
  65% { rotate: 1.2deg; }
}
.menu-local-best {
  align-self: center;
  margin: 0;
  padding: 3px 14px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
}

.menu-screen kbd {
  padding: 0 6px;
  font: 800 11px var(--font);
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 2px 0 #9a9ba3;
}
.menu-cred { margin: 0; font-size: 11px; font-weight: 700; color: rgba(255, 255, 255, 0.9); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45); }

@media (max-width: 680px) {
  .menu-tagline { font-size: 13px; }
  .menu-sky .sun { width: 74px; height: 74px; right: 6%; }
  .showcase-stage { height: 200px; }
}

/* Landscape phones: low height, keep the preview small */
@media (pointer: coarse) and (max-height: 520px) {
  .menu-tagline { display: none; }
  .showcase-stage { height: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  .menu-sky .cloud, .menu-sky .road, .menu-sky .road::before, .logo-flag, #start-engine-btn:hover { animation: none; }
}

/* ==================================================================
   Pop-art HUD: the same outlined cards, chunky shadows and logo font
   as the menu, over the race (the cars and the 3D world are untouched)
   ================================================================== */
.hud { --hud-shadow: 0 5px 0 var(--ink); }

/* Tower */
.hud .tower {
  top: 12px;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--hud-shadow);
}
.hud .tower-head {
  padding: 5px 10px 6px;
  background: var(--red);
  color: #fff;
  border-bottom: 3px solid var(--ink);
  font: 400 16px / 1 var(--logo);
  letter-spacing: 0.5px;
  -webkit-text-stroke: 1px var(--ink);
  paint-order: stroke fill;
}
.hud .tower-badge {
  background: var(--sun);
  color: var(--ink);
  font: 400 13px / 1.2 var(--logo);
  font-style: normal;
  padding: 1px 6px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  -webkit-text-stroke: 0;
}
.hud .tower-list li { color: var(--ink); font-weight: 800; }
.hud .tower-list li:nth-child(even) { background: #f6efdf; }
.hud .tower-list li.is-player { background: var(--sun); color: var(--ink); }
.hud .t-pos { opacity: 1; }
.hud .t-bar { border-radius: 3px; border: 1.5px solid var(--ink); }
.hud .t-gap { color: #5b5d66; font-weight: 800; }
.hud .tower-list li.is-player .t-gap { color: var(--ink); }
.hud .t-gap.purple { color: #8b2fd6; }
.hud .t-tyre { background: #2a2d35; box-shadow: 0 0 0 1.5px var(--ink); }

/* Minimap: dark card so the white track pops */
.hud .map-container {
  background: #1d2c5a;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--hud-shadow);
}

/* Lap timing */
.hud .timing {
  top: 214px;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--hud-shadow);
}
.hud .t-label { color: #5b5d66; font-weight: 900; }
.hud .timing-row { font-weight: 800; }
.hud .timing-row.big { font: 400 21px / 1.3 var(--logo); }
.hud .timing-row.big .t-label { font-family: var(--font); }
.hud .delta.ahead { color: #15803d; }
.hud .delta.behind { color: #dc2626; }
.hud .sector { border: 2px solid var(--ink); border-radius: 8px; background: #ece6d6; color: #5b5d66; }
.hud .sector.purple { background: #a855f7; color: #fff; }
.hud .sector.green { background: #22c55e; color: var(--ink); }
.hud .sector.yellow { background: var(--sun); color: var(--ink); }
.hud .weather-chip {
  background: var(--sun);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 2px 0 var(--ink);
}
.hud .weather-chip.wet { background: #7cc8f7; color: var(--ink); }

/* Dashboard: navy card, white logo-font speed, yellow gear box */
.hud .dash {
  background: #1d2c5a;
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 6px 0 var(--ink);
  color: #fff;
}
.hud .revlights i { height: 10px; border: 2px solid var(--ink); background: #2b3a6b; }
.hud .revlights i.g.on { background: #22c55e; box-shadow: none; }
.hud .revlights i.r.on { background: #ef4444; box-shadow: none; }
.hud .revlights i.b.on, .hud .revlights.flash i { background: #818cf8; box-shadow: none; }
.hud .speed-number {
  font: 400 44px / 1 var(--logo);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink);
}
.hud .dash-unit { color: #c8d3f5; font-weight: 900; }
.hud .gear-display {
  font: 400 50px / 1 var(--logo);
  color: var(--ink);
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15);
  padding: 4px 0 2px;
}
.hud .m-label { color: #c8d3f5; font-weight: 900; }
.hud .bar { height: 10px; border: 2px solid var(--ink); background: #2b3a6b; }
.hud .mode {
  font-size: 10.5px;
  font-weight: 900;
  padding: 1px 9px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #2b3a6b;
  color: #8a97c4;
}
.hud .mode.on { background: #38bdf8; color: var(--ink); }
.hud .mode.ovt.ready { background: #c4b5fd; color: var(--ink); }
.hud .mode.ovt.on { background: #a855f7; color: #fff; }
.hud .mode.drs.ready { background: #bbf7d0; color: var(--ink); box-shadow: none; }
.hud .mode.drs.on { background: #22c55e; color: var(--ink); }
.hud .mode.brk.on { background: #22c55e; color: var(--ink); }
.hud .mode.dmg.on { background: #f97316; color: var(--ink); }
.hud .mode.pit { border-color: var(--ink); }
.hud .mode.pit.on { background: var(--sun); color: var(--ink); }

/* Team radio: a comic speech bubble */
.hud .radio {
  background: #fff;
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: var(--hud-shadow);
  padding: 8px 16px 11px;
}
.hud .radio::after {
  content: "";
  position: absolute;
  left: 28px;
  bottom: -12px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: rotate(45deg) skew(12deg, 12deg);
}
.hud .radio-head {
  display: inline-flex;
  padding: 2px 9px;
  color: #fff;
  background: var(--red);
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 10.5px;
}
.hud .radio-wave { background: repeating-linear-gradient(90deg, #fff 0 2px, transparent 2px 4px); }
.hud .radio-text { font-size: 16px; font-weight: 800; margin-top: 4px; }

/* Banners and flags: tilted stickers */
.hud .banner, .hud .flag {
  font: 400 21px / 1.15 var(--logo);
  letter-spacing: 0.5px;
  color: var(--ink);
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--hud-shadow);
  padding: 7px 18px 8px;
  rotate: -1.5deg;
}
.hud .banner:empty { display: none; }
.hud .banner.big {
  font: 400 clamp(34px, 5vw, 58px) / 1 var(--logo);
  font-style: normal;
  color: #fff;
  background: none;
  border: none;
  box-shadow: none;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink);
  rotate: -3deg;
}
.hud .flag { background: #fff; }
.hud .flag.green { background: #4ade80; }
.hud .flag.purple { background: #a855f7; color: #fff; -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; }
.hud .flag.yellow { background: var(--sun); }
.hud .flag.blackwhite, .hud .flag.chequered {
  border: 3px solid var(--ink);
  border-image: none;
  padding-left: 48px;
  position: relative;
}
.hud .flag.blackwhite::before, .hud .flag.chequered::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 50%;
  width: 28px;
  height: 20px;
  margin-top: -10px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: linear-gradient(135deg, var(--ink) 50%, #fff 50%);
}
.hud .flag.chequered::before { background: conic-gradient(#fff 0 25%, var(--ink) 0 50%, #fff 0 75%, var(--ink) 0) 0 0 / 10px 10px; }

.hud .reaction {
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--ink);
  font-weight: 900;
}
.hud .popup { font: 400 54px / 1 var(--logo); font-style: normal; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); }
.hud .key-hints {
  bottom: 8px;
  padding: 3px 10px;
  color: #fff;
  background: rgba(22, 22, 29, 0.75);
  border: 2px solid var(--ink);
  border-radius: 999px;
  text-shadow: none;
  font-weight: 700;
}

/* Pit stop card */
.hud .pit-panel {
  background: var(--paper);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 7px 0 var(--ink);
}
.hud .pit-panel.go { background: #bbf7d0; border-color: var(--ink); }
.hud .pit-title { font: 400 22px / 1.1 var(--logo); letter-spacing: 0.5px; }
.hud .pit-panel.go .pit-title { color: #15803d; }
.hud .pit-time { font: 400 42px / 1.1 var(--logo); }
.hud .pit-bar { border: 2px solid var(--ink); background: #ece6d6; height: 12px; }
.hud .pit-hint { color: #5b5d66; }

/* Loading: cartoon sky with a waving chequered flag */
.loading {
  flex-direction: column;
  gap: 18px;
  background: linear-gradient(180deg, #3fa7ef, #bfe6ff);
  color: #fff;
  font: 400 34px / 1 var(--logo);
  letter-spacing: 1px;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
}
.loading::before {
  content: "";
  width: 72px;
  height: 52px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: conic-gradient(#fff 0 25%, var(--ink) 0 50%, #fff 0 75%, var(--ink) 0) 0 0 / 24px 26px;
  box-shadow: 0 6px 0 var(--ink);
  animation: flag-wave 1.2s ease-in-out infinite;
}

/* Touch controls: chunky outlined buttons */
@media (max-width: 768px), (pointer: coarse) and (max-height: 520px) {
  .mobile-controls button {
    color: #fff;
    font: 400 15px var(--logo);
    -webkit-text-stroke: 1px var(--ink);
    paint-order: stroke fill;
    border: 3px solid var(--ink) !important;
    box-shadow: 0 5px 0 var(--ink) !important;
  }
  .mobile-controls button:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink) !important; filter: none; }
  .btn-left, .btn-right { background: rgba(255, 250, 240, 0.85) !important; color: var(--ink) !important; -webkit-text-stroke: 0 !important; }
  .btn-accelerate { background: #22c55e !important; }
  .btn-brake { background: #ef4444 !important; }
  .btn-boost { background: #a855f7 !important; }
  .btn-pit { background: var(--sun) !important; color: var(--ink) !important; -webkit-text-stroke: 0 !important; }
  .btn-drs { background: #4ade80 !important; color: var(--ink) !important; -webkit-text-stroke: 0 !important; }
  .hud .tower, .hud .timing, .hud .map-container { border-width: 2px; border-radius: 12px; box-shadow: 0 3px 0 var(--ink); }
  .hud .tower-head { font-size: 13px; }
  .hud .dash { border-radius: 16px; box-shadow: 0 4px 0 var(--ink); }
  .hud .speed-number { font-size: 28px; -webkit-text-stroke-width: 1.5px; }
  .hud .gear-display { font-size: 32px; border-width: 2px; }
  .hud .banner { font-size: 16px; }
  .hud .banner.big { font-size: 30px; }
  .hud .timing { top: 132px; }
}
@media (max-width: 768px), (pointer: coarse) and (max-height: 520px) {
  .hud .timing-row.big { font-size: 15px; }
  .hud .timing-row.big .t-label { font-size: 9px; }
}
@media (orientation: portrait) and (max-width: 600px) {
  .left-controls, .right-controls { gap: 6px; }
  .btn-left, .btn-right { width: 58px !important; height: 58px !important; }
  .btn-accelerate { width: 66px !important; height: 104px !important; }
  .btn-brake { width: 58px !important; height: 84px !important; }
  .btn-drs { width: 48px !important; }
  .btn-boost, .btn-pit { width: 44px !important; height: 44px !important; }
  .mobile-controls { padding: 0 6px; }
}

/* ------------------------------------------------------------------ Pop-art boost / DRS */
/* Comic action lines: ink-outlined white streaks from the edges, tinted per mode */
.hud .speedlines {
  background:
    repeating-conic-gradient(from 0deg at 50% 55%,
      transparent 0deg 5deg,
      #16161d 5deg 5.6deg, #fff 5.6deg 6.6deg, #16161d 6.6deg 7.2deg,
      transparent 7.2deg 13deg);
  -webkit-mask: radial-gradient(ellipse 60% 55% at 50% 55%, transparent 0 55%, #000 85%);
  mask: radial-gradient(ellipse 60% 55% at 50% 55%, transparent 0 55%, #000 85%);
  animation: lines-jitter 0.12s steps(2) infinite;
}
.hud .speedlines::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.2s;
  /* halftone frame */
  background: radial-gradient(var(--tint, #ffd21f) 1.6px, transparent 2.2px) 0 0 / 9px 9px;
  -webkit-mask: radial-gradient(ellipse 62% 58% at 50% 55%, transparent 0 62%, #000 100%);
  mask: radial-gradient(ellipse 62% 58% at 50% 55%, transparent 0 62%, #000 100%);
}
.hud .speedlines.boost { --tint: #c084fc; }
.hud .speedlines.drs { --tint: #4ade80; }
.hud .speedlines.boost::after, .hud .speedlines.drs::after { opacity: 0.9; }
@keyframes lines-jitter { 50% { transform: rotate(1.2deg) scale(1.02); } }

/* Starburst sticker */
.hud .pow {
  position: absolute;
  left: -90px;
  bottom: 40px;
  width: 180px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: pow-pop 1.05s cubic-bezier(0.2, 1.6, 0.4, 1) forwards;
}
.hud .pow::before, .hud .pow::after {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(50% 0%, 59% 22%, 79% 6%, 74% 30%, 100% 24%, 82% 44%, 100% 62%, 76% 64%, 86% 92%, 62% 76%, 52% 100%, 42% 78%, 18% 96%, 24% 68%, 0% 72%, 16% 50%, 0% 30%, 24% 32%, 16% 6%, 40% 22%);
}
.hud .pow::before { background: #16161d; transform: translate(4px, 6px) scale(1.04); }
.hud .pow::after {
  background:
    radial-gradient(rgba(255, 255, 255, 0.45) 1.4px, transparent 2px) 0 0 / 8px 8px,
    var(--pow, #ffd21f);
  inset: 5px;
}
.hud .pow.boost { --pow: #a855f7; }
.hud .pow.drs { --pow: #22c55e; }
.hud .pow span {
  position: relative;
  z-index: 1;
  font: 400 34px / 1 var(--logo);
  letter-spacing: 1px;
  color: #fff;
  -webkit-text-stroke: 3px #16161d;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #16161d;
  transform: rotate(-8deg);
}
.hud .pow.drs span { color: #ffd21f; }
@keyframes pow-pop {
  0% { transform: scale(0.2) rotate(-25deg); opacity: 0; }
  18% { transform: scale(1.15) rotate(6deg); opacity: 1; }
  32% { transform: scale(1) rotate(0deg); }
  80% { transform: scale(1) rotate(0deg); opacity: 1; }
  100% { transform: scale(0.85) translateY(-30px) rotate(4deg); opacity: 0; }
}
@media (max-width: 768px), (pointer: coarse) and (max-height: 520px) {
  .hud .pow { width: 130px; height: 88px; left: -65px; bottom: 30px; }
  .hud .pow span { font-size: 24px; -webkit-text-stroke-width: 2px; }
}
@media (prefers-reduced-motion: reduce) {
  .hud .speedlines { animation: none; }
}

/* ==================================================================
   Game-style menu: a home screen with big buttons, one page per topic
   ================================================================== */
/* First screen: ink blue + halftone until the live clips start. The painted
   cartoon sky is only for screens without clips (phones, Fast graphics). */
body:not(.sky-bg) .menu-sky { display: none; }
body:not(.sky-bg) .menu-screen {
  background:
    radial-gradient(rgba(255, 255, 255, 0.06) 1.3px, transparent 1.9px) 0 0 / 10px 10px,
    radial-gradient(ellipse at 30% 30%, #26386e, #121a33 75%);
}
body.attract-on .menu-screen { background: transparent; }
/* Nothing but the blue until the menu is ready (no flash of untranslated cards) */
body.booting .menu-content, body.booting .attract-fx { opacity: 0; }
.menu-content { transition: opacity 0.35s; }

.menu-screen .menu-content {
  width: min(1180px, 100%);
  height: 100dvh;
  max-height: none;
  padding: 22px 28px;
  display: block;
  overflow-y: auto;
}
.menu-page { display: none; min-height: 100%; animation: page-in 0.32s cubic-bezier(0.2, 1.3, 0.4, 1); }
.menu-page.active { display: flex; flex-direction: column; gap: 14px; }
@keyframes page-in { from { opacity: 0; transform: translateX(26px); } to { opacity: 1; transform: none; } }

/* --- Home */
.menu-page[data-page="home"].active {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(300px, 400px);
  grid-template-rows: 1fr auto;
  align-items: center;
  gap: 18px 40px;
}
.home-left { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.home-left .menu-logo { font-size: clamp(60px, 8vw, 104px); transform: rotate(-3deg); margin-left: 6px; }
.home-left .logo-flag { width: 66px; height: 48px; }
.home-left .menu-tagline { margin: 0 0 6px; }
.home-nav { display: flex; flex-direction: column; gap: 12px; width: min(440px, 100%); margin-top: 6px; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 10px 18px 11px 12px;
  text-align: left;
  color: var(--ink);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 6px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
  animation: nav-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.home-nav .nav-btn:nth-child(2) { animation-delay: 0.05s; }
.home-nav .nav-btn:nth-child(3) { animation-delay: 0.1s; }
.home-nav .nav-btn:nth-child(4) { animation-delay: 0.15s; }
.home-nav .nav-btn:nth-child(5) { animation-delay: 0.2s; }
@keyframes nav-in { from { opacity: 0; transform: translateX(-40px); } to { opacity: 1; transform: none; } }
.nav-btn i {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  font-style: normal;
  font-size: 24px;
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 14px;
}
.nav-btn span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.nav-btn b { font: 400 25px / 1 var(--logo); letter-spacing: 0.5px; }
.nav-btn small { font-size: 12.5px; font-weight: 700; color: #5b5d66; }
.nav-btn:hover { background: #fff4c7; transform: translateX(6px); }
.nav-btn:active { transform: translate(6px, 4px); box-shadow: 0 2px 0 var(--ink); }
.nav-btn.primary { background: linear-gradient(180deg, #ff3b2f, var(--red)); color: #fff; }
.nav-btn.primary b { -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; text-shadow: 0 3px 0 var(--ink); font-size: 30px; }
.nav-btn.primary small { color: #ffe1dc; }
.nav-btn.primary:hover { background: linear-gradient(180deg, #ff5246, #f01208); }
.home-right { align-self: center; }
.menu-page[data-page="home"] .menu-cred { grid-column: 1 / -1; justify-self: start; }

/* --- Inner pages */
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.back-btn {
  padding: 8px 16px 9px;
  font: 400 19px / 1 var(--logo);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
}
.back-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.page-title {
  margin: 0;
  font: 400 40px / 1 var(--logo);
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
  transform: rotate(-2deg);
}
.page-head .page-mode { flex: 0 1 420px; }
.mode-line:empty { display: none; }
.mode-line {
  align-self: flex-start;
  margin: 0;
  padding: 3px 12px;
  font-weight: 800;
  color: var(--ink);
  background: var(--sun);
  border: 2px solid var(--ink);
  border-radius: 999px;
}
.page-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.menu-page .start-wrap { flex-direction: row; align-items: center; gap: 16px; position: static; margin: 0; padding: 0; background: none; }
.menu-page .start-wrap #start-engine-btn { flex: 1; max-width: 520px; }
.menu-page .showcase-card { display: flex !important; flex-direction: column; }
.menu-page .showcase-stage { grid-row: auto !important; }
.controls-card { max-width: 640px; }
.controls-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 22px; }
.controls-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 2px dashed #e6dfcd; font-size: 14px; }
.controls-list b { font-weight: 800; }

@media (max-width: 860px) {
  .menu-screen .menu-content { padding: 14px 12px; }
  .menu-page[data-page="home"].active { grid-template-columns: 1fr; gap: 14px; align-content: start; }
  .home-left { align-items: center; text-align: center; }
  .home-nav { width: 100%; }
  .home-right { order: 3; }
  .menu-page[data-page="home"] .menu-cred { justify-self: center; }
  .page-cols { grid-template-columns: 1fr; }
  .controls-list { grid-template-columns: 1fr; }
  .menu-page .start-wrap { position: sticky; bottom: 0; z-index: 2; padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); }
  .menu-page .start-wrap .menu-local-best { display: none; }
}
@media (pointer: coarse) and (max-height: 520px) {
  .home-left .menu-logo { font-size: 44px; }
  .nav-btn { padding: 6px 12px; }
  .nav-btn i { width: 36px; height: 36px; font-size: 18px; }
  .nav-btn b { font-size: 19px; }
}
.tv-tag { left: auto; right: 16px; transform: rotate(3deg); }
@media (max-width: 860px) {
  .menu-page[data-page="home"] .menu-cred { order: 4; }
  .tv-tag { top: auto; bottom: 12px; right: 50%; transform: translateX(50%); }
}

/* ------------------------------------------------------------------ Boost / DRS, toned down */
.hud .speedlines {
  background:
    repeating-conic-gradient(from 0deg at 50% 55%,
      transparent 0deg 8deg,
      rgba(22, 22, 29, 0.55) 8deg 8.25deg, rgba(255, 255, 255, 0.8) 8.25deg 8.65deg, rgba(22, 22, 29, 0.55) 8.65deg 8.9deg,
      transparent 8.9deg 17deg);
  -webkit-mask: radial-gradient(ellipse 70% 65% at 50% 55%, transparent 0 68%, #000 100%);
  mask: radial-gradient(ellipse 70% 65% at 50% 55%, transparent 0 68%, #000 100%);
  animation: none;
}
.hud .speedlines::after {
  background: radial-gradient(var(--tint, #ffd21f) 1.2px, transparent 1.7px) 0 0 / 10px 10px;
  -webkit-mask: radial-gradient(ellipse 72% 68% at 50% 55%, transparent 0 78%, #000 100%);
  mask: radial-gradient(ellipse 72% 68% at 50% 55%, transparent 0 78%, #000 100%);
}
.hud .speedlines.boost::after, .hud .speedlines.drs::after { opacity: 0.45; }

/* Small tilted sticker instead of the big starburst */
.hud .pow {
  left: -48px;
  bottom: 18px;
  width: 96px;
  height: auto;
  animation: pow-small 0.9s ease-out forwards;
}
.hud .pow::before, .hud .pow::after { display: none; }
.hud .pow span {
  padding: 3px 10px 4px;
  font-size: 17px;
  color: #fff;
  -webkit-text-stroke: 1.5px #16161d;
  text-shadow: 0 2px 0 #16161d;
  background: var(--pow, #ffd21f);
  border: 2.5px solid #16161d;
  border-radius: 999px;
  box-shadow: 0 3px 0 #16161d;
  transform: rotate(-4deg);
}
.hud .pow.drs span { color: #fff; }
@keyframes pow-small {
  0% { transform: translateY(8px) scale(0.85); opacity: 0; }
  15% { transform: none; opacity: 1; }
  75% { opacity: 1; }
  100% { transform: translateY(-14px); opacity: 0; }
}
@media (max-width: 768px), (pointer: coarse) and (max-height: 520px) {
  .hud .pow { width: 80px; left: -40px; bottom: 12px; height: auto; }
  .hud .pow span { font-size: 14px; }
}

/* Touch: look back + brake assist toggle */
@media (max-width: 768px), (pointer: coarse) and (max-height: 520px) {
  .btn-look { display: flex; width: 54px; height: 44px; border-radius: 12px; background: rgba(255, 250, 240, 0.85) !important; font-size: 20px !important; -webkit-text-stroke: 0 !important; }
  .btn-assist { display: flex; width: 54px; height: 40px; border-radius: 12px; background: #38bdf8 !important; color: var(--ink) !important; font-size: 12px !important; -webkit-text-stroke: 0 !important; }
  body.assist-on .btn-assist { background: #22c55e !important; }
}
@media (orientation: portrait) and (max-width: 600px) {
  .btn-look { width: 44px !important; height: 40px !important; }
  .btn-assist { width: 48px !important; height: 36px !important; }
}
@media (orientation: portrait) and (max-width: 600px) {
  .hud .dash { bottom: 172px; }
  .radio { bottom: 276px; }
}

/* ------------------------------------------------------------------ Account, ranking */
.home-right { display: flex; flex-direction: column; gap: 14px; }
.account-chip[hidden], .acc-user[hidden] { display: none; }
.acc-login {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  color: var(--ink);
  text-decoration: none;
  background: #fff;
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 5px 0 var(--ink);
}
.acc-login:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.acc-login b {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font: 400 24px / 1 var(--logo);
  color: #fff;
  background: conic-gradient(#ea4335 0 25%, #fbbc05 0 50%, #34a853 0 75%, #4285f4 0);
  border: 3px solid var(--ink);
  border-radius: 50%;
  -webkit-text-stroke: 1px var(--ink);
  paint-order: stroke fill;
}
.acc-login span { display: flex; flex-direction: column; }
.acc-login strong { font: 400 19px / 1.1 var(--logo); }
.acc-login small { font-size: 12px; font-weight: 700; color: #5b5d66; }
.acc-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  color: var(--ink);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--ink);
}
.acc-user img { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--ink); background: var(--sun); object-fit: cover; }
.acc-name { flex: 1; font: 400 19px / 1 var(--logo); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-coins { padding: 3px 10px; font-weight: 900; background: var(--sun); border: 2.5px solid var(--ink); border-radius: 999px; }
.rank-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.rank-tabs button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  font: 800 13.5px var(--font);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
}
.rank-tabs button.active { background: var(--sun); transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.rank-card { max-width: 640px; }
.rank-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.rank-list li {
  display: grid;
  grid-template-columns: 34px 30px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-bottom: 2px dashed #e6dfcd;
  font-weight: 800;
}
.rank-list li::before { counter-increment: rank; content: counter(rank); font: 400 20px / 1 var(--logo); text-align: center; }
.rank-list li:nth-child(1)::before { color: #d9a400; }
.rank-list li.me { background: var(--sun); border-radius: 10px; }
.rank-list img, .rank-list .ph { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--ink); background: #ece6d6; object-fit: cover; }
.rank-list .t { font: 400 18px / 1 var(--logo); }
.rank-list .empty { display: block; grid-template-columns: none; color: #5b5d66; }
.rank-list .empty::before { content: none; }
.acc-login[hidden], .nav-btn[hidden], #btn-logout[hidden], #acc-opt-label[hidden] { display: none; }

/* --- Shop (garage) --- */
.shop-card { margin-top: 18px; }
.shop-card[hidden], .shop-logo[hidden], #shop-coins-wrap[hidden] { display: none; }
.shop-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.shop-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 6px; }
.shop-tabs button {
  padding: 7px 12px;
  font: 800 13.5px var(--font);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
}
.shop-tabs button.active { background: var(--sun); transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.shop-item {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 6px 8px;
  font-family: var(--font);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
}
.shop-item canvas { width: 100%; max-width: 128px; aspect-ratio: 128 / 80; border-radius: 9px; background: #3b4250; }
.shop-item b { font-size: 14px; line-height: 1.1; text-align: center; }
.shop-item small { font-size: 12.5px; font-weight: 800; color: #5b5d66; }
.shop-item.owned small { color: #15803d; }
.shop-item.equipped { background: #fff6c2; }
.shop-item.equipped small { color: var(--ink); }
.shop-item.selected { outline: 4px solid var(--red); outline-offset: 1px; transform: translateY(-2px); }
.shop-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.shop-sel { font: 400 19px / 1.1 var(--logo); min-width: 0; }
.shop-sel b { font-weight: 400; }
.shop-sel small { display: block; margin-top: 2px; font: 700 13px / 1.25 var(--font); color: #5b5d66; }
.shop-act {
  padding: 9px 18px;
  font: 400 18px / 1 var(--logo);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
}
.shop-act.buy { background: var(--sun); }
.shop-act.login { background: #fff; }
.shop-act:disabled { opacity: 0.6; cursor: default; box-shadow: 0 2px 0 var(--ink); transform: translateY(2px); }
.shop-logo { display: flex; gap: 14px; align-items: center; margin-top: 10px; padding-top: 10px; border-top: 2px dashed #e6dfcd; }
.shop-logo canvas { width: 160px; height: 80px; flex: none; border-radius: 12px; background: #3b4250; }
.shop-logo-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.shop-logo-text p { margin: 0; font-weight: 800; }
.shop-upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.shop-upload span {
  display: inline-block;
  padding: 7px 14px;
  font: 800 14px var(--font);
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
}
.shop-upload input:focus-visible + span { outline: 3px solid var(--red); }
@media (max-width: 560px) {
  .shop-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .shop-item b { font-size: 12.5px; }
  .shop-logo { flex-direction: column; align-items: flex-start; }
}
