/* Toy style: blue doodle background, white chunky cards. Fonts and rules: DESIGN.md. */
:root {
  --blue: #3a63d8;
  --blue-deep: #2c4fb8;
  --ink: #24305e;
  --ink-soft: #5b6690;
  --yellow: #ffd23d;
  --yellow-deep: #d9a514;
  --green: #3ddc84;
  --green-deep: #20a85e;
  --red: #ff5d5d;
  --red-deep: #c93b3b;
  --soft: #eef3ff;
  --lift: rgba(20, 32, 90, 0.28);
  --me: #3ddc84;
  --font-title: Poppins, system-ui, sans-serif;
  --font-head: Fredoka, Nunito, system-ui, sans-serif;
  --font-body: Nunito, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-family: var(--font-body);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--blue); color: #fff; }
body { height: var(--app-height, 100dvh); overflow: hidden; overscroll-behavior: none; -webkit-touch-callout: none; }
.toy, .lobby { background: var(--blue) url(/doodles.svg) center / cover no-repeat; }
input, textarea { user-select: text; -webkit-user-select: text; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
.muted { opacity: 0.8; }
.small { font-size: 0.85rem; }
.error { color: var(--red-deep); font-weight: 700; min-height: 1.2em; }

/* ---------- buttons ---------- */
button {
  font: inherit; color: inherit; border: 0; cursor: pointer; background: none;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn-link { color: #fff; opacity: 0.85; text-decoration: underline; text-underline-offset: 3px; padding: 8px; font-weight: 600; }
.btn-primary, .btn-secondary {
  padding: 14px 28px; border-radius: 999px; font-weight: 800; font-size: 1.1rem; text-decoration: none; text-align: center;
  transition: transform 80ms, box-shadow 80ms;
}
.btn-primary { background: var(--yellow); color: var(--ink); box-shadow: 0 6px 0 var(--yellow-deep); }
.btn-secondary { background: #fff; color: var(--ink); box-shadow: 0 6px 0 var(--lift); }
.btn-primary:active:not(:disabled), .btn-secondary:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--yellow-deep); }
.btn-secondary:active { box-shadow: 0 2px 0 var(--lift); }
.btn-primary:disabled { background: rgba(255, 255, 255, 0.28); color: rgba(255, 255, 255, 0.85); box-shadow: none; cursor: not-allowed; }
.btn-big { font-size: 1.35rem; padding: 16px 36px; }
.btn-small { padding: 10px 18px; font-size: 1rem; }

/* ---------- host (TV) ---------- */
.host { overflow: hidden; }
.host canvas { position: fixed; inset: 0; width: 100vw; height: var(--app-height, 100vh); touch-action: none; }
.tv-buttons { position: fixed; top: 14px; right: 14px; z-index: 10; display: flex; gap: 8px; }
.sound-chip {
  background: rgba(255, 255, 255, 0.92); color: var(--ink); padding: 8px 16px; border-radius: 999px;
  font-weight: 700; font-size: 0.9rem; box-shadow: 0 3px 0 var(--lift);
}
.sound-chip.attention { background: var(--yellow); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.lobby {
  position: fixed; inset: 0; overflow: auto;
  display: grid; grid-template-columns: minmax(0, 1fr) clamp(280px, 26vw, 400px); grid-template-rows: auto 1fr;
  grid-template-areas: 'head ticket' 'main ticket'; column-gap: clamp(24px, 3.5vw, 64px); row-gap: clamp(12px, 2.4vh, 28px);
  padding: clamp(20px, 4vh, 48px) clamp(20px, 4vw, 64px);
}
.lobby-head { grid-area: head; display: flex; align-items: baseline; gap: 18px; flex-wrap: wrap; }
.lobby-head h1 {
  font-size: clamp(30px, min(3.6vw, 6.4vh), 64px); line-height: 0.88; font-weight: 900; letter-spacing: -0.02em;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.12);
}
.lobby-head p { font-weight: 600; opacity: 0.85; font-size: clamp(14px, 1.9vh, 20px); }
.lobby-main { grid-area: main; display: flex; flex-direction: column; gap: clamp(14px, 3vh, 34px); min-width: 0; }
.lobby h2 { font-size: clamp(18px, 2.6vh, 28px); font-weight: 800; margin-bottom: clamp(8px, 1.4vh, 14px); display: flex; align-items: center; gap: 10px; }
.count {
  min-width: 1.6em; padding: 0 8px; border-radius: 999px; background: #fff; color: var(--blue);
  font-size: 0.8em; text-align: center; line-height: 1.5;
}

/* Game cards: big cartridges with art on top. The chosen one lifts and turns yellow. */
.games { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: clamp(12px, 1.6vw, 24px); }
.game-card {
  position: relative; display: flex; flex-direction: column; gap: 4px; min-width: 0;
  padding: 10px 10px 16px; background: #fff; color: var(--ink); border: 4px solid #fff; border-radius: 26px; text-align: left;
  box-shadow: 0 6px 0 var(--lift); transition: transform 160ms cubic-bezier(0.3, 1.6, 0.5, 1), box-shadow 160ms, border-color 160ms;
}
.game-card:hover:not(.selected) { transform: translateY(-2px); }
.game-card:focus-visible { outline: 4px solid #fff; outline-offset: 4px; }
.game-art {
  position: relative; height: clamp(72px, 15vh, 190px); border-radius: 18px; margin-bottom: 8px; overflow: hidden;
  display: flex; align-items: center; justify-content: center; background: var(--soft);
}
.game-art i { font-style: normal; font-size: clamp(44px, 9vh, 104px); filter: drop-shadow(0 6px 0 rgba(20, 32, 90, 0.18)); }
.game-card strong, .game-card span { padding-inline: 6px; }
.game-card strong { font-weight: 900; font-size: clamp(17px, 2.4vh, 26px); line-height: 1.15; }
.game-card span { color: var(--ink-soft); font-size: clamp(13px, 1.7vh, 17px); font-weight: 500; line-height: 1.35; }
.game-card.selected { border-color: var(--yellow); transform: translateY(-6px); box-shadow: 0 12px 0 var(--yellow-deep); }
.game-card.selected::after {
  content: '✓'; position: absolute; top: -14px; right: -14px; width: 40px; height: 40px; border-radius: 50%;
  background: var(--yellow); color: var(--ink); font-weight: 900; font-size: 1.2rem; display: grid; place-items: center;
  box-shadow: 0 4px 0 var(--yellow-deep); animation: pop-in 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}
/* Card art is one picture per game (games/<id>/img/card.png). The color shows while it loads. */
.game-card .game-art img { width: 100%; height: 100%; object-fit: cover; }
.game-card[data-game='kart'] .game-art { background: #3a9a35; }
.game-card[data-game='kart3d'] .game-art { background: #6fbff8; }
.game-card[data-game='kart3d'] .game-art img { object-position: 50% 75%; }
.game-card[data-game='karttoy'] .game-art { background: #54a8f5; }
.game-card[data-game='karttoy'] .game-art img { object-position: 50% 65%; }
.game-card[data-game='rescue'] .game-art {
  background: repeating-linear-gradient(0deg, #f2d4a2 0 30px, #e6c18a 30px 33px);
}

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 18px; flex-wrap: wrap; margin-bottom: clamp(8px, 1.4vh, 14px); }
.section-head h2 { margin-bottom: 0; }
.soon { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-weight: 700; font-size: 0.9rem; }
.soon span { opacity: 0.75; margin-right: 4px; }
.soon em {
  font-style: normal; display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 6px; border-radius: 999px;
  border: 2px dashed rgba(255, 255, 255, 0.4);
}
.soon i { font-style: normal; filter: grayscale(1); opacity: 0.8; }

/* Racers: one token per player who joined, plus one open seat. No empty slots. */
/* One row on a TV: tokens shrink and names cut off before the row wraps. */
.players { display: flex; gap: clamp(8px, 1.2vw, 18px); padding-top: 10px; }
.racer { flex: 0 1 auto; }
.racer {
  position: relative; display: flex; align-items: center; gap: 12px; min-width: 0; max-width: 100%;
  padding: 6px 20px 6px 6px; border-radius: 999px; background: #fff; color: var(--ink); box-shadow: 0 5px 0 var(--lift);
}
.racer.new { animation: pop-in 0.55s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes pop-in { from { transform: scale(0.6) translateY(20px); opacity: 0; } }
.racer-pic {
  position: relative; flex: none; width: clamp(48px, 7.5vh, 76px); aspect-ratio: 1; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; background: var(--c); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15);
}
.racer-pic img { position: absolute; left: 50%; bottom: -14%; translate: -50% 0; height: 130%; aspect-ratio: 1; object-fit: contain; }
.racer-pic span { font-size: clamp(22px, 3.6vh, 36px); font-weight: 900; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); }
.racer-name { font-weight: 800; font-size: clamp(16px, 2.2vh, 24px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.racer .tag {
  position: absolute; top: -10px; left: 50%; translate: -50% 0; white-space: nowrap; font-style: normal; font-weight: 800; font-size: 0.72rem;
  padding: 2px 9px; border-radius: 999px; background: var(--yellow); color: var(--ink); box-shadow: 0 2px 0 var(--yellow-deep);
}
.racer .tag.off { background: var(--ink); color: #fff; box-shadow: none; }
/* Five or more: picture above the name, so names keep their room. */
.players.crowd .racer { flex: 1 1 0; flex-direction: column; gap: 6px; padding: 10px 10px 12px; border-radius: 26px; }
.players.crowd .racer-name { max-width: 100%; font-size: clamp(14px, 2vh, 22px); }
.players.crowd .racer.join-slot .racer-name { white-space: normal; text-align: center; line-height: 1.2; }
.racer.offline { opacity: 0.6; filter: grayscale(0.7); }
.racer.join-slot { background: transparent; color: #fff; box-shadow: none; outline: 3px dashed rgba(255, 255, 255, 0.5); outline-offset: -3px; }
.racer.join-slot .racer-pic { background: rgba(255, 255, 255, 0.16); box-shadow: none; }
.racer.join-slot .racer-pic span { text-shadow: none; animation: breathe 1.6s ease-in-out infinite; }
.racer.join-slot .racer-name { font-weight: 700; }

.start-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-top: auto; }
.start-row .btn-big { min-width: min(380px, 100%); }
.btn-primary:focus-visible { outline: 4px solid #fff; outline-offset: 4px; }
.hint { font-weight: 600; opacity: 0.8; font-size: 0.95rem; }

/* Join ticket: an arcade prize ticket with a tear line between the code and the link. */
.ticket {
  grid-area: ticket; align-self: center; display: flex; flex-direction: column; color: var(--ink);
  filter: drop-shadow(0 8px 0 var(--lift)); rotate: 1.5deg;
}
.ticket-top, .ticket-stub {
  background: #fff; padding: clamp(16px, 2.8vh, 28px) clamp(16px, 2vw, 28px); text-align: center;
}
.ticket-top {
  border-radius: 30px 30px 0 0; display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 1.8vh, 18px);
  mask: radial-gradient(circle 16px at 0 100%, #0000 98%, #000) left / 51% 100% no-repeat,
        radial-gradient(circle 16px at 100% 100%, #0000 98%, #000) right / 51% 100% no-repeat;
}
.ticket-stub {
  border-radius: 0 0 30px 30px; border-top: 4px dashed var(--soft); display: flex; flex-direction: column; gap: 10px;
  mask: radial-gradient(circle 16px at 0 0, #0000 98%, #000) left / 51% 100% no-repeat,
        radial-gradient(circle 16px at 100% 0, #0000 98%, #000) right / 51% 100% no-repeat;
}
.ticket-title { font-weight: 800; font-size: clamp(17px, 2.4vh, 24px); }
.code { display: flex; gap: clamp(5px, 0.6vw, 10px); justify-content: center; }
.code span {
  width: clamp(44px, 7.6vh, 76px); aspect-ratio: 0.82; display: grid; place-items: center; border-radius: 14px;
  background: var(--blue); color: #fff; font-weight: 900; font-size: clamp(30px, 5.6vh, 56px); line-height: 1;
  box-shadow: 0 5px 0 var(--blue-deep);
}
.code span:nth-child(odd) { rotate: -3deg; }
.code span:nth-child(even) { rotate: 2deg; translate: 0 3px; }
.qr { width: clamp(130px, 27vh, 280px); aspect-ratio: 1; }
.qr svg { width: 100%; height: 100%; display: block; }
.ticket-stub p { color: var(--ink-soft); font-weight: 600; font-size: clamp(13px, 1.7vh, 16px); line-height: 1.4; }
.ticket-stub strong { color: var(--ink); overflow-wrap: anywhere; }
.ticket-stub .seats {
  align-self: center; color: var(--ink); font-weight: 800; background: var(--yellow); padding: 4px 14px; border-radius: 999px;
}

@media (max-width: 900px), (orientation: portrait) {
  .lobby { grid-template-columns: 1fr; grid-template-rows: none; grid-template-areas: 'head' 'ticket' 'main'; align-content: start; }
  .ticket { rotate: none; align-self: stretch; }
  .games { grid-auto-flow: row; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .players { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  .racer.new, .game-card.selected::after, .racer.join-slot .racer-pic span { animation: none; }
  .game-card { transition: none; }
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 30;
  background: #fff; color: var(--ink); padding: 12px 22px; border-radius: 999px; font-weight: 800; box-shadow: 0 5px 0 var(--lift);
}

/* In-game menu on the TV */
.menu { position: fixed; inset: 0; z-index: 20; background: rgba(28, 44, 120, 0.6); backdrop-filter: blur(6px); display: grid; place-items: center; }
.menu-box {
  background: #fff; color: var(--ink); border-radius: 28px; padding: 28px; display: flex; flex-direction: column; gap: 14px;
  min-width: 320px; box-shadow: 0 8px 0 var(--lift);
}
.menu-box h2 { text-align: center; font-weight: 900; font-size: 2rem; margin-bottom: 4px; }
.menu-box .btn-secondary { background: var(--soft); }
.menu-games { display: flex; flex-direction: column; gap: 14px; }
.menu-games:empty { display: none; }

/* ---------- phone controller ---------- */
.pad {
  overflow: hidden; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; touch-action: none; overscroll-behavior: none;
}
.view {
  height: 100%;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; font-weight: 600; }
.center-col { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.title { font-size: clamp(44px, 14vw, 72px); line-height: 0.9; font-weight: 900; letter-spacing: -0.02em; text-shadow: 0 6px 0 rgba(0, 0, 0, 0.12); }
.card {
  background: #fff; color: var(--ink); border-radius: 28px; padding: 22px; box-shadow: 0 8px 0 var(--lift);
  display: flex; flex-direction: column; gap: 14px;
}
.join { display: flex; flex-direction: column; gap: 22px; justify-content: center; max-width: 400px; margin: 0 auto; touch-action: auto; }
.join label, .home-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 0.9rem; color: var(--ink-soft); }
.join input, .home-card input {
  font: inherit; font-size: 1.35rem; font-weight: 700; padding: 12px 16px; border-radius: 16px;
  border: 3px solid transparent; background: var(--soft); color: var(--ink); outline: none;
}
.join input:focus, .home-card input:focus { border-color: var(--blue); background: #fff; }
.join .error:empty { display: none; }

.spinner {
  width: 52px; height: 52px; border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, 0.3); border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Loader: a toy racer that hops, plus a bar. Used on the TV boot screen and the phone loading screen. */
.loader { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.loader-kart { position: relative; width: clamp(120px, 22vmin, 220px); aspect-ratio: 1; }
.loader-kart img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: contain; animation: hop 0.9s cubic-bezier(0.3, 0, 0.5, 1) infinite; }
.loader-kart::after {
  content: ''; position: absolute; left: 22%; right: 22%; bottom: 6%; height: 9%; border-radius: 50%;
  background: rgba(20, 32, 90, 0.3); animation: hop-shadow 0.9s cubic-bezier(0.3, 0, 0.5, 1) infinite;
}
@keyframes hop {
  0%, 100% { transform: translateY(0) scale(1.06, 0.94); }
  15% { transform: translateY(0) scale(0.96, 1.05); }
  50% { transform: translateY(-16%) scale(1); }
  85% { transform: translateY(0) scale(1); }
}
@keyframes hop-shadow { 0%, 100%, 85% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.65); opacity: 0.5; } }
.loader-text { font-weight: 800; font-size: clamp(1.05rem, 3.2vmin, 1.6rem); }
.loader-text::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.loader-bar { position: relative; width: clamp(160px, 30vmin, 280px); height: 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.22); overflow: hidden; }
.loader-bar i { position: absolute; top: 0; bottom: 0; width: 40%; border-radius: 999px; background: var(--yellow); box-shadow: inset 0 -3px 0 var(--yellow-deep); animation: bar 1.3s ease-in-out infinite; }
@keyframes bar { from { left: -40%; } to { left: 100%; } }
.boot { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; transition: opacity 0.35s, visibility 0.35s; }
.boot .title { font-size: clamp(40px, 9vmin, 96px); line-height: 0.9; font-weight: 900; text-align: center; text-shadow: 0 6px 0 rgba(0, 0, 0, 0.12); margin-bottom: 6px; }
.boot.done { opacity: 0; visibility: hidden; }
.boot.error .loader-kart img, .boot.error .loader-kart::after, .boot.error .loader-bar { animation: none; }
.boot.error .loader-text::after { content: none; }
@media (prefers-reduced-motion: reduce) {
  .loader-kart img, .loader-kart::after, .loader-text::after { animation: none; }
}

/* Lobby with the racer picker */
.lobby-view { display: flex; flex-direction: column; gap: 10px; text-align: center; }
.lobby-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 46px; }
.badge {
  display: inline-flex; align-items: center; gap: 10px; max-width: 70%;
  padding: 9px 18px 9px 10px; border-radius: 999px; background: #fff; color: var(--ink);
  font-weight: 800; font-size: 1.1rem; box-shadow: 0 4px 0 var(--lift); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge::before { content: ''; flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--me); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15); }
button.badge::after { content: '✎'; opacity: 0.5; }
button.badge:disabled { opacity: 1; cursor: default; }
button.badge:disabled::after { content: none; }
.lead-chip { background: var(--yellow); color: var(--ink); font-weight: 800; padding: 7px 14px; border-radius: 999px; box-shadow: 0 3px 0 var(--yellow-deep); font-size: 0.9rem; white-space: nowrap; }
.rename { touch-action: auto; display: flex; gap: 8px; align-items: center; flex: 1; }
.rename:not([hidden]) ~ .lead-chip { display: none; }
.rename input {
  flex: 1; width: 0; min-width: 80px; padding: 10px 14px; border-radius: 999px; border: 3px solid #fff;
  background: #fff; color: var(--ink); font: inherit; font-size: 1.1rem; font-weight: 800; outline: none;
}

.stage { position: relative; flex: 1 1 auto; min-height: 180px; touch-action: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage.loading .stage-img { animation: breathe 1.2s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(0.96); opacity: 0.8; } }
.stage-img { position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%; aspect-ratio: 1; object-fit: contain; pointer-events: none; }
.arrow {
  position: absolute; top: 50%; translate: 0 -50%; z-index: 2; width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.92); color: var(--ink);
  display: grid; place-items: center; box-shadow: 0 4px 0 var(--lift);
}
.arrow:active { translate: 0 calc(-50% + 3px); box-shadow: 0 1px 0 var(--lift); }
.arrow svg { width: 22px; height: 22px; }
.arrow.prev { left: 0; }
.arrow.next { right: 0; }
.swipe-hint {
  position: absolute; left: 50%; bottom: 4px; translate: -50% 0; font-weight: 700; font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.18); padding: 4px 12px; border-radius: 999px; pointer-events: none;
  animation: nudge 1.8s ease-in-out infinite;
}
.swiped .swipe-hint { display: none; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-8px); } 60% { transform: translateX(8px); } }

.lobby-side { display: flex; flex-direction: column; align-items: center; gap: 12px; }
body:not(.picking) .lobby-side { flex: 1; justify-content: center; }
.char-info { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.char-name { font-size: clamp(34px, 10vw, 48px); font-weight: 900; line-height: 1; text-transform: uppercase; letter-spacing: -0.01em; text-shadow: 0 5px 0 rgba(0, 0, 0, 0.12); }
.char-name.pop { animation: name-pop 0.4s cubic-bezier(0.3, 1.7, 0.5, 1); }
@keyframes name-pop { from { transform: scale(0.7); opacity: 0.3; } }
.char-tag { font-weight: 600; opacity: 0.85; }
.dots { display: flex; gap: 8px; margin-top: 8px; }
.dots i { width: 10px; height: 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.35); transition: width 0.2s, background 0.2s; }
.dots i.on { width: 26px; background: #fff; }
.hello h2 { font-size: 2.2rem; font-weight: 900; }

.swatches {
  display: flex; gap: 12px; flex-wrap: wrap; justify-content: center;
  padding: 10px 14px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); backdrop-filter: blur(10px);
}
.swatch {
  position: relative; width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; background: var(--c);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2); transition: transform 0.15s;
}
.swatch[aria-pressed='true'] { transform: scale(1.2); box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.45), 0 3px 0 rgba(0, 0, 0, 0.2); }
.swatch:disabled { opacity: 0.5; cursor: not-allowed; border-style: dashed; }
.swatch:disabled::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 120%; height: 3px; background: #fff; border-radius: 2px;
  transform: translate(-50%, -50%) rotate(-45deg);
}
.lobby-text { font-weight: 600; opacity: 0.92; max-width: 340px; }
.lobby-side .btn-big { width: min(340px, 100%); }

/* Phone held sideways: racer on the left, choices on the right. */
@media (min-aspect-ratio: 3/2) and (max-height: 560px) {
  body.picking .lobby-view {
    display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: 'stage top' 'stage side'; column-gap: 18px; row-gap: 6px;
  }
  body.picking .lobby-top { grid-area: top; }
  body.picking .stage { grid-area: stage; min-height: 0; }
  body.picking .lobby-side { grid-area: side; justify-content: safe center; gap: 8px; min-height: 0; overflow-y: auto; }
  .char-name { font-size: 34px; }
  .char-tag { font-size: 0.85rem; }
  .dots { margin-top: 4px; }
  .swatches { gap: 10px; padding: 8px 12px; }
  .swatch { width: 32px; height: 32px; }
  .lobby-text { font-size: 0.85rem; }
  .lobby-side .btn-big { padding: 11px 24px; font-size: 1.1rem; }
  .lobby-side .btn-link { padding: 2px; font-size: 0.85rem; }
  .join { flex-direction: row; align-items: center; max-width: 760px; gap: 32px; }
  .join .title { flex: 1; font-size: 56px; }
  .join .card { flex: 1.2; padding: 16px; gap: 10px; }
  .join input { padding: 8px 14px; font-size: 1.15rem; }
}

@media (min-aspect-ratio: 3/2) and (max-height: 340px) {
  body.picking .lobby-side { gap: 5px; }
  .char-name { font-size: 28px; }
  .char-tag { display: none; }
  .swatches { gap: 8px; padding: 6px 10px; }
  .swatch { width: 28px; height: 28px; }
  .lobby-text { font-size: 0.8rem; line-height: 1.25; }
  .lobby-side .btn-big { padding: 9px 20px; font-size: 1rem; }
}

/* Race pad */
.kart { display: flex; flex-direction: column; gap: 12px; position: relative; }
.kart-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 800; }
.k-place {
  min-width: 72px; padding: 4px 16px; border-radius: 999px; background: var(--me); color: #fff; text-align: center;
  font-size: 1.8rem; font-weight: 900; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}
.k-status { font-size: 1.1rem; flex: 1; min-width: 0; text-align: center; line-height: 1.15; }
.k-lap { white-space: nowrap; background: #fff; color: var(--ink); padding: 6px 14px; border-radius: 999px; box-shadow: 0 3px 0 var(--lift); }
.k-menu-btn { background: #fff; color: var(--ink); width: 40px; height: 40px; border-radius: 50%; font-weight: 900; box-shadow: 0 3px 0 var(--lift); }
.kart-pad { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; min-height: 0; padding-bottom: 8px; }
.steer { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pedals { display: grid; grid-template-rows: 2fr 1fr; gap: 14px; }
.pad-btn {
  border-radius: 28px; font-size: 2.6rem; font-weight: 900; touch-action: none;
  transition: transform 60ms, box-shadow 60ms, background 60ms;
}
.pad-btn.steer-btn { background: #fff; color: var(--ink); box-shadow: 0 8px 0 var(--lift); }
.pad-btn.gas { background: var(--green); color: var(--ink); font-size: 1.8rem; box-shadow: 0 8px 0 var(--green-deep); }
.pad-btn.brake { background: var(--red); color: #fff; font-size: 1.3rem; box-shadow: 0 8px 0 var(--red-deep); }
.pad-btn.down { transform: translateY(6px); box-shadow: 0 2px 0 var(--lift); }
.pad-btn.steer-btn.down { background: var(--me); color: #fff; }
.pad-btn.gas.down { box-shadow: 0 2px 0 var(--green-deep); }
.pad-btn.brake.down { box-shadow: 0 2px 0 var(--red-deep); }
.k-results {
  position: absolute; inset: 0; z-index: 7; background: rgba(58, 99, 216, 0.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; font-weight: 700;
}
.k-final { font-size: clamp(48px, 14vw, 84px); font-weight: 900; text-shadow: 0 6px 0 rgba(0, 0, 0, 0.15); }
.k-results #k-leader, .k-leader { display: flex; gap: 14px; }
.k-wrong {
  position: absolute; left: 16px; right: 16px; top: 70px; z-index: 5; pointer-events: none;
  background: var(--red); color: #fff; text-align: center; font-weight: 900; font-size: 1.6rem;
  padding: 10px; border-radius: 20px; box-shadow: 0 5px 0 var(--red-deep); animation: pulse 0.6s ease-in-out infinite;
}
.k-menu { position: fixed; inset: 0; z-index: 8; background: rgba(28, 44, 120, 0.6); display: grid; place-items: center; padding: 20px; }
.k-menu-box {
  background: #fff; color: var(--ink); border-radius: 28px; padding: 22px; width: min(360px, 100%); max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 8px 0 var(--lift);
}
.k-menu-box h2 { text-align: center; font-weight: 900; }
.k-menu-box .btn-secondary { background: var(--soft); }
.k-menu-box .btn-link { color: var(--ink); }

/* Don't Drop It! pad: joystick left, GRAB right */
.r-wobble { height: 14px; border-radius: 999px; background: rgba(255, 255, 255, 0.3); overflow: hidden; }
.r-wobble i { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--green); transition: width 0.2s, background 0.2s; }
.r-wobble i.warn { background: var(--yellow); }
.r-wobble i.danger { background: var(--red); }
.rescue-pad { flex: 1; min-height: 0; container-type: size; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: center; justify-items: center; padding-bottom: 8px; }
.stick {
  position: relative; width: min(42vw, 62vh, 260px); width: min(44cqw, 92cqh, 260px); aspect-ratio: 1; border-radius: 50%; touch-action: none;
  background: rgba(255, 255, 255, 0.22); border: 5px solid #fff; box-shadow: inset 0 6px 0 rgba(0, 0, 0, 0.08);
}
.stick-knob {
  position: absolute; left: 50%; top: 50%; width: 44%; aspect-ratio: 1; border-radius: 50%; pointer-events: none;
  background: #fff; box-shadow: 0 6px 0 var(--lift); transform: translate(-50%, -50%);
}
.stick.down .stick-knob { background: var(--me); }
.grab-btn {
  width: min(40vw, 58vh, 240px); width: min(42cqw, 86cqh, 240px); aspect-ratio: 1; border-radius: 50%; touch-action: none;
  background: var(--yellow); color: var(--ink); font-size: 1.9rem; font-weight: 900; box-shadow: 0 10px 0 var(--yellow-deep);
  transition: transform 60ms, box-shadow 60ms, background 60ms;
}
.grab-btn.down { transform: translateY(8px); box-shadow: 0 2px 0 var(--yellow-deep); }
.grab-btn.holding { background: var(--me); color: #fff; }
.r-stars { font-size: 1.4rem; font-weight: 800; }

/* Phone held sideways: smaller top bar, pad fills the rest, menu buttons in 2 columns. */
@media (min-aspect-ratio: 3/2) and (max-height: 560px) {
  .kart { gap: 8px; }
  .k-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .kart .k-lap { padding: 4px 12px; font-size: 0.95rem; }
  .kart .k-place { font-size: 1.4rem; padding: 2px 14px; }
  .kart .k-menu-btn { width: 34px; height: 34px; }
  .r-wobble { height: 10px; }
  .rescue-pad { padding-bottom: 0; }
  .grab-btn { font-size: 1.5rem; box-shadow: 0 7px 0 var(--yellow-deep); }
  .k-menu { padding: 10px; }
  .k-menu-box { width: min(560px, 100%); padding: 14px 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .k-menu-box h2, .k-menu-box .btn-link { grid-column: 1 / -1; }
  .k-menu-box h2 { font-size: 1.3rem; }
  .k-menu-box .menu-games { display: contents; }
  .k-menu-box button { padding-top: 10px; padding-bottom: 10px; font-size: 1rem; }
  .k-results { gap: 10px; }
  .k-final { font-size: 44px; }
}

.conn {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--yellow); color: var(--ink); padding: 6px 16px; border-radius: 999px; font-weight: 800; box-shadow: 0 3px 0 var(--yellow-deep);
}
.mute-btn {
  position: fixed; bottom: max(10px, env(safe-area-inset-bottom)); right: 10px; z-index: 5;
  width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, 0.2); font-size: 1.1rem;
}
.kart:not([hidden]) ~ .mute-btn { display: none; }

/* Start page: join with a code or host. */
.home {
  display: flex; flex-direction: column; gap: 18px; height: 100%; overflow-y: auto; justify-content: safe center; text-align: center;
  touch-action: pan-y; overscroll-behavior: contain; padding: 20px max(16px, calc((100% - 420px) / 2));
}
.home h1 { font-size: clamp(72px, 26vw, 120px); line-height: 0.9; font-weight: 900; letter-spacing: 0.02em; text-shadow: 0 6px 0 rgba(0, 0, 0, 0.12); }
.home header p, .home-or { font-family: var(--font-head); font-weight: 600; font-size: 1.1rem; }
.home header p { margin-top: 10px; }
.home-card { background: #fff; color: var(--ink); border-radius: 28px; padding: 22px; display: flex; flex-direction: column; gap: 12px; text-align: left; box-shadow: 0 8px 0 var(--lift); font-family: var(--font-body); }
.home-card h2 { font-family: var(--font-head); font-size: 1.65rem; font-weight: 600; line-height: 1.1; }
.home-card label { font-weight: 800; font-size: 0.95rem; }
.home-card .muted { color: var(--ink-soft); opacity: 1; font-weight: 700; line-height: 1.45; }
.home-card .btn-primary, .home-card .btn-secondary { font-family: var(--font-head); font-weight: 600; font-size: 1.25rem; }
.home-card a.btn-secondary { background: var(--soft); }
.home .error:empty { display: none; }

/* Room code as 4 letter tiles, like the code on the TV ticket. An invisible input on top takes the typing. */
.code-tiles { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.code-tiles span {
  display: grid; place-items: center; aspect-ratio: 1 / 1; max-height: 64px; width: 100%; border-radius: 16px;
  background: var(--soft); border: 3px solid transparent; color: var(--ink);
  font-family: var(--font-head); font-weight: 600; font-size: 1.9rem; line-height: 1;
  transition: border-color 150ms ease-out, background-color 150ms ease-out;
}
.code-tiles span:empty::before { content: attr(data-ghost); color: #c3cbe6; }
.code-tiles span.filled { background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-deep); }
.code-tiles.focus span.next { border-color: var(--blue); }
.code-tiles.focus span.next:empty::before { content: ''; width: 3px; height: 1.1em; border-radius: 2px; background: var(--blue); animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.code-tiles input#code {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; padding: 0; border: 0; font-size: 16px; caret-color: transparent;
}
@media (prefers-reduced-motion: reduce) {
  .code-tiles span { transition: none; }
  .code-tiles.focus span.next:empty::before { animation: none; }
}

/* Menu screen scene (lib/scene.js): stripes drift, doodles move, toy karts drive from far (top right) to near (bottom left). */
.live { isolation: isolate; }
/* Fixed to the screen and behind the screen's content (z-index -1 inside the isolated .live box).
   Its own blue covers the static doodles.svg background. */
.scene { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; background: var(--blue); }
.scene-layer { position: absolute; inset: 0; }
.scene-lines {
  position: absolute; inset: -120px;
  background: repeating-linear-gradient(66deg, transparent 0 88px, rgba(255, 255, 255, 0.07) 88px 90px);
  animation: lines-drift 9s linear infinite;
}
/* One stripe period (90px) along the stripe normal, so the loop has no jump. */
@keyframes lines-drift { to { transform: translate(82.2px, -36.6px); } }
.scene-doodles { position: absolute; inset: 0; width: 100%; height: 100%; }
.scene-doodles :is(path, g) { transform-box: fill-box; transform-origin: center; }
.d-twinkle { animation: twinkle 2.6s ease-in-out infinite alternate; }
.d-swing { transform-origin: 50% 0 !important; animation: swing 3.2s ease-in-out infinite alternate; }
.d-bob { animation: bob 3.6s ease-in-out infinite alternate; }
.d-wave { transform-origin: 0 100% !important; animation: sway 2.8s ease-in-out infinite alternate; }
.d-burst { animation: burst 1.9s ease-in-out infinite alternate; }
.d-draw { stroke-dasharray: 1; animation: draw 6s ease-in-out infinite; }
.d-late { animation-delay: -1.3s; }
.d-slow { animation-duration: 3.8s; }
.d-draw.d-slow { animation-duration: 8s; }
@keyframes twinkle { from { transform: scale(1) rotate(0); } to { transform: scale(0.72) rotate(20deg); opacity: 0.5; } }
@keyframes swing { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
@keyframes bob { from { transform: translateY(-6px); } to { transform: translateY(6px); } }
@keyframes sway { from { transform: rotate(-3deg); } to { transform: rotate(4deg); } }
@keyframes burst { from { transform: scale(0.8); opacity: 0.35; } to { transform: scale(1.12); opacity: 1; } }
/* Draw in, hold, then erase from the start: the line always moves forward. */
@keyframes draw { 0% { stroke-dashoffset: 1; } 40%, 60% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -1; } }

/* The road is one long band, turned so it runs from top right (far) to bottom left (near).
   Karts move along its local x axis, so they stay on the road at any screen size.
   Road width and kart size both grow from 0.4 (far end) to 1.1 (near end). */
.scene-road {
  --w: clamp(96px, 16vmin, 190px);
  --len: 170vmax;
  --far: 36.4%; /* 0.4 / 1.1: road width at the far end */
  position: absolute; left: 50%; top: 64%; width: var(--len); height: calc(var(--w) * 1.6);
  transform: translate(-50%, -50%) rotate(155deg);
  /* Depth: the far end fades out, like haze. */
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 22%);
  mask-image: linear-gradient(90deg, transparent 0, #000 22%);
}
/* Loading screens: the loader sits in the middle, so the road runs low along the bottom right. */
.boot > .scene .scene-road, #loading > .scene .scene-road { left: 64%; top: 96%; }
.road-curb, .road-top, .road-dash { position: absolute; left: 0; width: 100%; }
.road-curb {
  top: 0; height: 100%;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.85) 0 34px, #ff5a5a 34px 68px);
  clip-path: polygon(0 calc(50% - var(--far) / 2), 100% 0, 100% 100%, 0 calc(50% + var(--far) / 2));
}
.road-top {
  top: 7%; height: 86%;
  background: linear-gradient(180deg, #213f9c 0, var(--blue-deep) 14%, #3156c4 32%, var(--blue-deep) 46%,
    var(--blue-deep) 54%, #3156c4 68%, var(--blue-deep) 86%, #213f9c 100%);
  clip-path: polygon(0 calc(50% - var(--far) / 2), 100% 0, 100% 100%, 0 calc(50% + var(--far) / 2));
}
.road-dash {
  top: calc(50% - 3px); height: 6px;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.55) 0 46px, transparent 46px 92px);
  clip-path: polygon(0 calc(50% - var(--far) / 2), 100% 0, 100% 100%, 0 calc(50% + var(--far) / 2));
}
/* A zero-size point on the road center line. The kart body hangs from it. */
.scene-kart {
  position: absolute; left: 0; top: 50%; width: 0; height: 0; transform-origin: 0 0;
  animation: drive var(--dur) linear var(--delay) infinite;
}
/* Turn back upright and put the kart's wheel center on the point. */
.kart-body {
  position: absolute; left: calc(var(--w) * -0.5); top: calc(var(--w) * -0.72); width: var(--w); aspect-ratio: 1;
  transform-origin: 50% 72%; transform: translateY(calc(var(--lane) * var(--w) * 0.26)) rotate(-155deg);
}
.kart-body::before {
  content: ''; position: absolute; left: 8%; top: 70%; width: 84%; height: 18%; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(12, 22, 80, 0.45), rgba(12, 22, 80, 0));
}
/* Speed lines behind the kart. It drives down-left, so they trail up-right. */
.kart-body::after {
  content: ''; position: absolute; left: 62%; top: 22%; width: 70%; height: 34%;
  transform-origin: 0 50%; rotate: -25deg;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0)) 0 10% / 100% 3px no-repeat,
    linear-gradient(90deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0)) 20% 50% / 80% 3px no-repeat,
    linear-gradient(90deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0)) 0 90% / 100% 3px no-repeat;
  animation: streak 0.5s linear infinite;
}
.kart-body img { position: relative; display: block; width: 100%; height: 100%; animation: rumble 0.34s ease-in-out infinite alternate; }
/* Dust puffs behind the back wheels. */
.kart-body i {
  position: absolute; left: 72%; top: 68%; width: 24%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.75) 0 30%, rgba(255, 255, 255, 0) 70%);
  animation: puff 0.8s cubic-bezier(0.23, 1, 0.32, 1) infinite;
}
.kart-body i + i { left: 30%; top: 58%; width: 16%; animation-delay: -0.4s; }
@keyframes drive {
  from { transform: translateX(0) scale(0.4); }
  to { transform: translateX(var(--len)) scale(1.1); }
}
@keyframes rumble { from { transform: translateY(0) rotate(0); } to { transform: translateY(-3%) rotate(-1.2deg); } }
@keyframes streak {
  from { transform: translateX(-10%); opacity: 0; }
  30% { opacity: 1; }
  to { transform: translateX(30%); opacity: 0; }
}
@keyframes puff {
  from { transform: translate(0, 0) scale(0.4); opacity: 0.9; }
  to { transform: translate(70%, -60%) scale(1.5); opacity: 0; }
}

/* TV lobby: one drawing per game. Only the picked one shows; the others fade out and pause. */
.scene-game { opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0s 0.3s; }
.scene-game.on { opacity: 1; visibility: visible; transition: opacity 0.3s ease; }
.scene-game:not(.on) * { animation-play-state: paused; }
/* Toy Rescue: toys step, the cake wobbles, the table ring turns. */
.toy-step { animation: step 0.36s ease-in-out infinite alternate; }
.cake-wobble { animation: cake-sway 0.9s ease-in-out infinite alternate; }
.table-ring { transform-box: fill-box; transform-origin: center; animation: spin 8s linear infinite; }
@keyframes step { from { transform: translateX(-3px); } to { transform: translateX(3px); } }
@keyframes cake-sway { from { transform: translateY(-5px) rotate(-6deg); } to { transform: translateY(5px) rotate(6deg); } }
.scene-track { position: absolute; inset: 0; width: 100%; height: 100%; }
/* The 3D box sits in the empty space between the racers list and the join card. Edges fade into the page. */
/* The 3D box is a soft trapezoid: narrow under the game cards, full width at the bottom, like a road
   coming toward you. The SVG mask is stretched to the box; the gradient fades the top and bottom. */
.scene canvas.chase3d {
  --fade-y: linear-gradient(180deg, #000 78%, transparent);
  position: absolute; left: 0; top: 46%; width: 100%; height: 54%;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cfilter id='b' x='-20%25' y='-20%25' width='140%25' height='140%25'%3E%3CfeGaussianBlur stdDeviation='3.5'/%3E%3C/filter%3E%3Cpath d='M38 -10H62L101 106H-1Z' filter='url(%23b)'/%3E%3C/svg%3E"), var(--fade-y);
  -webkit-mask-size: 100% 100%;
  -webkit-mask-composite: source-in;
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cfilter id='b' x='-20%25' y='-20%25' width='140%25' height='140%25'%3E%3CfeGaussianBlur stdDeviation='3.5'/%3E%3C/filter%3E%3Cpath d='M38 -10H62L101 106H-1Z' filter='url(%23b)'/%3E%3C/svg%3E"), var(--fade-y);
  mask-size: 100% 100%;
  mask-composite: intersect;
}
.scene-game.chase-wait > :not(canvas) { display: none; }
.scene canvas.chase3d { opacity: 0; transition: opacity 0.4s ease; }
.scene canvas.chase3d.ready { opacity: 1; }
.chase-steer { animation: steer 2.6s ease-in-out infinite alternate; }
.chase-rumble { animation: rumble 0.2s ease-in-out infinite alternate; }
.rush-dash { opacity: 0; animation: rush 1.6s linear infinite; }
@keyframes steer { from { transform: translateX(-60px) rotate(-3deg); } to { transform: translateX(60px) rotate(3deg); } }
/* Dashes come from the horizon and speed up and grow as they get near, like real perspective. */
@keyframes rush {
  0% { transform: translate(720px, 486px) scale(0.05); opacity: 0; }
  15% { opacity: 1; }
  40% { transform: translate(720px, 510px) scale(0.12); }
  70% { transform: translate(720px, 569px) scale(0.3); }
  85% { transform: translate(720px, 651px) scale(0.55); }
  100% { transform: translate(720px, 833px) scale(1.1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .scene-kart, .top-kart, .rescue-team, .rush-dash { display: none; }
  .chase-steer, .chase-rumble { animation: none; }
  .table-ring { animation: none; }
  .scene-lines, .scene-doodles * { animation: none !important; }
  .d-draw { stroke-dasharray: none; }
}

/* Phone held sideways: title on the left, join and host on the right. */
@media (min-aspect-ratio: 3/2) and (max-height: 560px) {
  .home {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, min(380px, 58%)); column-gap: 24px; row-gap: 10px;
    align-content: safe center; padding-inline: max(16px, calc((100% - 840px) / 2));
  }
  .home header { grid-row: 1 / 4; align-self: start; position: sticky; top: 0; padding-top: 16px; }
  .home h1 { font-size: clamp(56px, 12vw, 104px); }
  .home header p { font-size: 0.9rem; }
  .home-card { padding: 14px 18px; gap: 8px; }
  .code-tiles span { max-height: 48px; font-size: 1.5rem; border-radius: 12px; }
  .home-card .btn-primary, .home-card .btn-secondary { padding-top: 10px; padding-bottom: 10px; }
  .home-or { line-height: 1; }
}
/* The toy scene has a sky, so its top edge fades too. */
.scene-game[data-game='karttoy'] canvas.chase3d { --fade-y: linear-gradient(180deg, transparent, #000 14%, #000 80%, transparent); }

/* ---------- type (DESIGN.md): Poppins 900 titles and big numbers, Fredoka 600 headings, buttons and letters, Nunito text ---------- */
h1, .title, .k-final, .k-place, .racer-pic span { font-family: var(--font-title); font-weight: 900; }
h2, .lobby h2, .menu-box h2, .k-menu-box h2, .hello h2, .char-name,
.btn-primary, .btn-secondary, .sound-chip, .lead-chip, .badge, .k-lap, .k-status, .k-wrong, .pad-btn, .grab-btn,
.code span, .ticket-title, .game-card strong, .racer-name, .loader-text, .lobby-head p, .r-stars {
  font-family: var(--font-head); font-weight: 600;
}
