:root {
  color-scheme: dark;
  --ink: #f8f3df;
  --muted: #b9c9b9;
  --deep: #0a1713;
  --panel: rgba(15, 38, 30, 0.94);
  --leaf: #61d17d;
  --sun: #ffd66b;
  --orange: #ee8b42;
  font-family: Inter, ui-rounded, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at 50% -20%, #315f48, var(--deep) 62%); color: var(--ink); }
body { min-height: 100vh; overflow-x: hidden; }
button, a { font: inherit; }
button { color: inherit; }

.cabinet { width: min(1180px, 100%); margin: 0 auto; padding: 18px clamp(10px, 2.5vw, 28px) 24px; }
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px; margin-bottom: 14px; }
.topbar > div { text-align: center; }
.topbar h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(1.8rem, 4vw, 3.1rem); letter-spacing: -.04em; }
.eyebrow, .kicker { margin: 0 0 4px; color: var(--sun); font-size: .72rem; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; }
.back-link, .icon-button { justify-self: start; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; padding: 9px 14px; background: rgba(0,0,0,.22); color: var(--ink); text-decoration: none; }
.icon-button { justify-self: end; cursor: pointer; }

.game-stage { position: relative; margin: 0 auto; overflow: hidden; border: 3px solid #8ab66f; border-radius: 24px; background: #82a95f; box-shadow: 0 28px 80px #0008, inset 0 0 0 1px #d8ef9b66; transform-origin: top left; }
#raceCanvas { display: block; width: 100%; height: 100%; outline: none; }

.panel { position: absolute; left: 50%; top: 50%; width: min(620px, calc(100% - 34px)); transform: translate(-50%, -50%); padding: clamp(20px, 4vw, 38px); border: 1px solid #c9e89a55; border-radius: 24px; background: linear-gradient(160deg, rgba(22, 58, 43, .97), rgba(8, 24, 19, .97)); box-shadow: 0 24px 70px #000a; text-align: center; backdrop-filter: blur(10px); }
.panel[hidden], .race-hud[hidden] { display: none; }
.panel h2 { margin: 0; font: 800 clamp(1.8rem, 5vw, 3.4rem)/.98 Georgia, serif; }
.lede { color: var(--muted); line-height: 1.5; }
.pet-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 9px; max-height: 190px; overflow: auto; margin: 20px 0 16px; padding: 3px; }
.pet-card { position: relative; min-height: 92px; padding: 13px; border: 1px solid #ffffff1f; border-radius: 16px; background: #ffffff0a; cursor: pointer; text-align: left; }
.pet-card[aria-checked="true"] { border-color: var(--sun); background: #ffd66b18; box-shadow: 0 0 0 2px #ffd66b33; }
.pet-card strong, .pet-card small { display: block; }
.pet-card small { margin-top: 8px; color: var(--muted); font-size: .7rem; }
.pet-dot { display: inline-block; width: 12px; height: 12px; margin-right: 7px; border-radius: 50%; box-shadow: 0 0 10px currentColor; }
.race-options { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 12px auto; padding: 10px 14px; border: 1px solid #ffffff1f; border-radius: 14px; color: var(--muted); text-align: left; }
.race-options span { color: var(--ink); font-weight: 800; }
.race-options select { min-width: 170px; border: 1px solid #ffffff36; border-radius: 9px; padding: 8px 10px; background: #081a14; color: var(--ink); }
.briefing { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px 13px; margin: 14px 0; color: var(--muted); font-size: .76rem; }
kbd { display: inline-block; min-width: 22px; margin-right: 3px; padding: 3px 6px; border: 1px solid #ffffff36; border-bottom-width: 3px; border-radius: 5px; background: #0005; color: white; }
.primary, .secondary { border: 0; border-radius: 999px; padding: 13px 24px; font-weight: 900; letter-spacing: .05em; cursor: pointer; }
.primary { background: linear-gradient(#ffe58f, #efb841); color: #2a210c; box-shadow: 0 6px 0 #966520; }
.primary:disabled { opacity: .5; cursor: wait; }
.secondary { margin-left: 8px; border: 1px solid #ffffff2c; background: #ffffff0b; }
.load-note { min-height: 1em; margin: 12px 0 0; color: var(--muted); font-size: .75rem; }

.race-hud { position: absolute; inset: 14px 16px auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; pointer-events: none; text-shadow: 0 2px 8px #000; }
.race-hud > div:last-child { text-align: right; }
.race-hud__middle { padding: 7px 18px; border-radius: 13px; background: #10291fd9; text-align: center; }
.race-hud small, .race-hud strong { display: block; }
.race-hud small { color: var(--sun); font-size: .62rem; font-weight: 900; letter-spacing: .14em; }
.race-hud strong { font-size: clamp(1rem, 2.5vw, 1.55rem); }
.countdown { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%); color: #fff9c8; font: 900 clamp(5rem, 16vw, 9rem)/1 Georgia, serif; text-shadow: 0 8px 0 #5d3b1d, 0 15px 35px #000b; pointer-events: none; }
.result-times { display: flex; justify-content: center; gap: 28px; margin: 20px 0; }
.result-times span, .result-times strong { display: block; }
.result-times span { color: var(--muted); font-size: .75rem; text-transform: uppercase; }
.result-times strong { color: var(--ink); font-size: 1.4rem; }
.result-standings { max-height: 160px; margin: 0 auto 18px; padding-left: 2rem; overflow: auto; color: var(--muted); text-align: left; }
.result-standings li { padding: 3px 6px; }
.result-standings li.is-player { color: var(--sun); font-weight: 900; }

.touch-controls { position: absolute; inset: auto 14px 13px; display: none; justify-content: space-between; pointer-events: none; }
.touch-cluster { display: flex; gap: 8px; }
.touch-controls button { width: 60px; height: 60px; border: 1px solid #fff5; border-radius: 50%; background: #10291fbb; color: white; font-size: .72rem; font-weight: 900; pointer-events: auto; touch-action: none; }
.touch-controls button.is-held { background: var(--orange); transform: translateY(2px); }
footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 28px; padding: 14px; color: #9bb2a2; font-size: .75rem; text-align: center; }

@media (hover: none), (pointer: coarse) {
  .touch-controls.is-racing { display: flex; }
}

@media (max-width: 620px) {
  .topbar { grid-template-columns: auto 1fr auto; gap: 8px; }
  .back-link, .icon-button { padding: 8px 10px; font-size: .75rem; }
  .eyebrow { display: none; }
  .panel { padding: 18px; }
  .lede { margin: 9px 0; font-size: .84rem; }
  .briefing { display: none; }
}
