:root {
  --ink: #f5ead3;
  --muted: #c9bfa8;
  --panel: #292c29;
  --course: #35463e;
  --accent: #ef8b42;
  --focus: #f5cf73;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, "Trebuchet MS", "Segoe UI", sans-serif; color: var(--ink); background: #191b1a; }
button, input { font: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.game-wrap { display: grid; width: min(100vw, 56.25vh); height: min(100vh, 177.7778vw); margin: auto; }
.race-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: clamp(10px, 2.8cqw, 13px);
  gap: clamp(7px, 2.1cqw, 9px);
  overflow: hidden;
  border: 4px solid #655d4c;
  border-radius: 8px;
  background: #252a27;
  container-type: inline-size;
}
.race-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.race-title { font-size: clamp(16px, 5cqw, 22px); font-weight: 900; letter-spacing: .04em; }
.race-sub { margin-top: 3px; color: var(--muted); font-size: clamp(10px, 2.9cqw, 17px); }
.race-clock { font-size: clamp(22px, 7cqw, 30px); font-weight: 900; font-variant-numeric: tabular-nums; }
.race-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #313a35; }
#courseCanvas { display: block; width: 100%; height: 100%; }
.race-hud { position: absolute; inset: 10px 10px auto; display: flex; justify-content: space-between; gap: 6px; font-size: clamp(11px, 3.3cqw, 14px); font-weight: 800; text-shadow: 0 1px 2px #000; }
.race-effect { position: absolute; right: 10px; bottom: 12px; left: 10px; padding: 8px; font-size: clamp(11px, 3.7cqw, 16px); line-height: 1.4; text-align: center; text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; }
.race-result { position: absolute; inset: 0; z-index: 4; display: grid; place-content: center; padding: 18px; background: #20251fed; text-align: center; }
.race-result strong { font-size: 26px; }
.race-result p { line-height: 1.5; }
.play-instruction { margin: 0; font-size: clamp(11px, 3.1cqw, 18px); line-height: 1.4; text-align: center; }
.drive-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.drive-controls button { min-width: 0; min-height: 44px; border: 1px solid #979581; border-radius: 5px; background: #3d453d; color: var(--ink); font-weight: 800; touch-action: none; }
.drive-controls button[data-active=true] { background: #b95a23; }
.last-gift { min-height: 2.6em; margin: 0; color: var(--muted); font-size: clamp(10px, 2.8cqw, 17px); line-height: 1.3; overflow-wrap: anywhere; }
.mode-label { position: absolute; z-index: 5; top: 58px; left: 50%; transform: translateX(-50%); padding: 5px 10px; border-radius: 999px; background: #14161ae8; color: #ffd43b; font-size: clamp(10px, 2.8cqw, 18px); font-weight: 800; }

/* Gift keys sit over the track edges so they never reduce the course area. */
.gift-rails { position: absolute; z-index: 3; inset: 0; pointer-events: none; }
.gift-rail { position: absolute; top: 35%; display: grid; gap: 5px; width: 31%; }
.gift-rail.left { left: 5px; }
.gift-rail.right { right: 5px; }
.gift-rail-item { display: flex; align-items: center; gap: 5px; min-width: 0; padding: 4px 5px; border-radius: 7px; background: #151b18d9; box-shadow: 0 1px 4px #0007; font-size: clamp(8px, 2.35cqw, 14px); line-height: 1.15; }
.gift-rail.right .gift-rail-item { flex-direction: row-reverse; text-align: right; }
.gift-rail-item .tt-core-gift-icon { width: clamp(20px, 6cqw, 26px); height: clamp(20px, 6cqw, 26px); flex-basis: clamp(20px, 6cqw, 26px); }
.gift-rail-item span:last-child { min-width: 0; overflow-wrap: anywhere; }

html.source-page, html.source-page body { width: 100%; height: 100%; overflow: hidden; background: var(--tt-source-bg, #191b1a) !important; }
.source-page body { display: flex; align-items: center; justify-content: center; }
.source-page .tt-core-status > .tt-core-pill { display: none; }

html.tt-shell { --accent: #ffd43b; --accent-text: #ffd43b; }
html.tt-shell .preview-wrap { background: #191b1a; }
html.tt-shell .settings-error { color: #ffaaa0; }
html.tt-shell .practice-panel .effects { grid-template-columns: repeat(2, minmax(0, 1fr)); }
html.tt-shell .practice-panel .effects button { min-width: 0; }
html.tt-shell .gift-copy > span { display: flex; align-items: center; gap: 7px; }
html.tt-shell .tt-core-assigned-gift-icon { flex: 0 0 auto; object-fit: contain; }
html.tt-shell .setting-copy { color: var(--copy); font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

@media (max-width: 600px) {
  html.tt-shell .practice-panel .effects { grid-template-columns: 1fr; }
}
