/* Turbo Track: a sunny toy-race. Sky-blue page, sticker-style cards with thick navy
   outlines and a hard offset shadow, like a box of candy-coloured racing cars.
   Lilita One (chunky, rounded) for headings and numbers, Nunito for reading.
   The one loud thing is the ? card: it pops in the middle of the track. */

:root {
  --sky: #8ed8ff;
  --sky-deep: #4fb6f2;
  --ink: #1c2f6b;
  --ink-soft: #46578f;
  --sun: #ffd23f;
  --tomato: #ff5d4a;
  --tomato-deep: #d93b2b;
  --mint: #3fd6a3;
  --candy: #ff8fc7;
  --paper: #fffaf0;
  --good: #1fa56b;
  --focus: #1c2f6b;

  --display: "Lilita One", "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  --body: "Nunito", "Avenir Next", system-ui, sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font: 700 1.0625rem/1.45 var(--body);
  background: linear-gradient(var(--sky), #d9f2ff 60%, #c9f0a4);
}

[hidden] { display: none !important; }

.icons { position: absolute; width: 0; height: 0; overflow: hidden; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }

/* ---- frame */

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.bar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.4rem max(1rem, env(safe-area-inset-right)) 0.4rem max(1rem, env(safe-area-inset-left));
  background: linear-gradient(#ffffffd9, #ffffff00);
}
.back {
  color: var(--ink);
  font-weight: 800;
  text-underline-offset: 3px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
h1 {
  margin: 0;
  flex: 1;
  font: 400 clamp(1.5rem, 3.2vw, 2.2rem)/1 var(--display);
  color: var(--tomato);
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 #fff, 0 4px 0 var(--ink);
}
.sound {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--sun);
  box-shadow: 0 3px 0 var(--ink);
}
.sound svg { width: 28px; height: 28px; color: var(--ink); }
.sound[aria-pressed="true"] { background: #e6e6ee; }
.sound[aria-pressed="true"] .waves { display: none; }
.sound:active { transform: translateY(3px); box-shadow: none; }

.stage { grid-row: 2; position: relative; overflow: hidden; min-height: 0; background: var(--sky); }
.scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}
.loading {
  position: absolute;
  inset: 42% 0 auto;
  margin: 0;
  text-align: center;
  font: 400 1.6rem/1.2 var(--display);
  color: var(--ink);
}

/* ---- speed and boost */

.streaks, .boost-glow { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.35s; }
.streaks {
  background: repeating-conic-gradient(from 0deg at 50% 52%, #ffffff00 0deg 5deg, #ffffffcc 5.4deg 5.9deg, #ffffff00 6.3deg 12deg);
  -webkit-mask-image: radial-gradient(circle at 50% 52%, transparent 28%, #000 78%);
  mask-image: radial-gradient(circle at 50% 52%, transparent 28%, #000 78%);
  animation: streak 0.28s steps(3) infinite;
}
.boost-glow { background: radial-gradient(ellipse at 50% 55%, #ffd23f00 40%, #ffb42ccc 100%); }
.app.boosting .streaks { opacity: 0.85; }
.app.boosting .boost-glow { opacity: 1; }
@keyframes streak { to { transform: rotate(4deg) scale(1.06); } }

/* ---- HUD */

.hud { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.place {
  position: absolute;
  top: 10px;
  left: max(12px, env(safe-area-inset-left));
  min-width: 88px;
  height: 88px;
  padding: 0 14px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  padding-top: 12px;
  border: 4px solid var(--ink);
  border-radius: 28px;
  background: var(--sun);
  box-shadow: 0 5px 0 var(--ink);
  font-family: var(--display);
  line-height: 1;
}
.place .n { font-size: 3.6rem; }
.place .suf { font-size: 1.5rem; }
.place.first { background: #ffe066; animation: wiggle 0.5s; }
.lap {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.35rem 1.1rem 0.4rem;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--ink);
  font: 400 1.5rem/1.1 var(--display);
  white-space: nowrap;
}
.map {
  position: absolute;
  top: 8px;
  right: max(10px, env(safe-area-inset-right));
  width: 96px;
  height: 96px;
  border: 4px solid var(--ink);
  border-radius: 24px;
  background: #ffffffd0;
  box-shadow: 0 4px 0 var(--ink);
}
.turbo {
  position: absolute;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  width: min(300px, 46vw);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0.5rem;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--ink);
}
.turbo-label { font: 400 1.1rem/1 var(--display); color: var(--tomato-deep); }
.turbo-bar { flex: 1; height: 18px; border-radius: 999px; background: #dbe6f5; overflow: hidden; border: 2px solid var(--ink); }
.turbo-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff8a2b, #ffd23f);
}
.turbo.on { animation: wiggle 0.4s infinite; }
.msg {
  position: absolute;
  top: 31%;
  left: 50%;
  margin: 0;
  max-width: 88%;
  transform: translate(-50%, 0);
  padding: 0.3rem 1.2rem 0.4rem;
  border: 4px solid var(--ink);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--ink);
  font: 400 clamp(1.6rem, 5vw, 2.4rem)/1.15 var(--display);
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s;
}
.msg.show { opacity: 1; }
.msg.hot { background: var(--sun); color: var(--tomato-deep); }

/* ---- countdown lights */

.lights { position: absolute; inset: 0; z-index: 3; display: grid; place-content: center; justify-items: center; gap: 0.6rem; pointer-events: none; }
.lamps { display: flex; gap: 0.9rem; padding: 0.8rem 1.2rem; border: 4px solid var(--ink); border-radius: 28px; background: #2a3258; box-shadow: 0 6px 0 var(--ink); }
.lamps i { width: 54px; height: 54px; border-radius: 50%; background: #55597c; border: 3px solid #12193d; }
.lamps i.red { background: #ff3b30; box-shadow: 0 0 22px #ff3b30; }
.lamps i.green { background: #38e07b; box-shadow: 0 0 26px #38e07b; }
.count { margin: 0; font: 400 clamp(5rem, 22vw, 9rem)/1 var(--display); color: #fff; text-shadow: 0 6px 0 var(--ink), 0 0 0 var(--ink), -3px 0 0 var(--ink), 3px 0 0 var(--ink), 0 -3px 0 var(--ink); animation: pop 0.5s; }

/* ---- touch pedals */

.pedals { position: absolute; left: 0; right: 0; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 3; display: none; justify-content: space-between; padding: 0 max(14px, env(safe-area-inset-left)); pointer-events: none; }
.touch .pedals:not([hidden]) { display: flex; }
.pedals button {
  pointer-events: auto;
  width: 104px;
  height: 104px;
  display: grid;
  place-items: center;
  border: 5px solid var(--ink);
  border-radius: 32px;
  background: #ffffffcc;
  box-shadow: 0 6px 0 var(--ink);
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pedals button svg { width: 54px; height: 54px; }
.pedals button.down { background: var(--sun); transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }

/* ---- cards */

.start, .power, .finish {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  padding: 30px max(12px, env(safe-area-inset-right)) 14px max(12px, env(safe-area-inset-left));
  overflow-y: auto;
}
.power { background: rgb(28 47 107 / 0.35); }
.start { background: linear-gradient(rgb(255 255 255 / 0), rgb(28 47 107 / 0.18)); }
.finish { background: rgb(28 47 107 / 0.25); }

.card {
  position: relative;
  width: min(520px, 100%);
  margin: auto;
  padding: 1.7rem 1.3rem 1.3rem;
  border: 5px solid var(--ink);
  border-radius: 34px;
  background: var(--paper);
  box-shadow: 0 9px 0 var(--ink);
  text-align: center;
  animation: pop 0.35s cubic-bezier(.3, 1.5, .5, 1);
  outline: none;
}
.card h2 {
  margin: 0.2rem 0 0.4rem;
  font: 400 clamp(2.2rem, 7vw, 3.4rem)/1.05 var(--display);
  color: var(--ink);
}
.lead { margin: 0 0 1rem; font-size: 1.2rem; font-weight: 700; color: var(--ink-soft); }
.ribbon {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  margin: 0;
  padding: 0.2rem 1.4rem 0.3rem;
  border: 4px solid var(--ink);
  border-radius: 14px;
  background: var(--tomato);
  color: #fff;
  font: 400 1.35rem/1.2 var(--display);
  white-space: nowrap;
  letter-spacing: 0.03em;
}
.ribbon:empty { display: none; }

.big {
  display: block;
  width: 100%;
  min-height: 72px;
  margin: 0.4rem 0;
  padding: 0.3rem 1rem 0.5rem;
  border: 5px solid var(--ink);
  border-radius: 26px;
  background: var(--tomato);
  box-shadow: 0 8px 0 var(--ink);
  color: #fff;
  font: 400 clamp(1.9rem, 6vw, 2.5rem)/1.1 var(--display);
  letter-spacing: 0.03em;
  text-shadow: 0 3px 0 rgb(28 47 107 / 0.45);
}
.big:hover { background: #ff7060; }
.big:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--ink); }
.big.go { background: var(--mint); }
.big.now { min-height: 96px; font-size: 3rem; background: var(--good); }
.link, .again {
  min-height: 52px;
  margin-top: 0.4rem;
  padding: 0.3rem 1.2rem;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 4px 0 var(--ink);
  font-weight: 800;
  font-size: 1.1rem;
}
.link { border-color: transparent; background: none; box-shadow: none; text-decoration: underline; text-underline-offset: 4px; }
.link:hover { color: var(--tomato-deep); }
.again:active { transform: translateY(3px); box-shadow: none; }

.mode { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; margin: 0.9rem 0 0.6rem; }
.mode-label { flex-basis: 100%; margin: 0; font-weight: 800; color: var(--ink-soft); }
.mode button {
  min-height: 52px;
  padding: 0.3rem 1rem;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  font-weight: 800;
  font-size: 1.05rem;
}
.mode button[aria-pressed="true"] { background: var(--sun); box-shadow: 0 4px 0 var(--ink); }
.keys { margin: 0.5rem 0 0; font-size: 0.95rem; color: var(--ink-soft); }
.for-touch { display: none; }
.touch .for-touch { display: inline; }
.touch .for-mouse { display: none; }
.shelf { margin: 0.5rem 0 0; font-weight: 800; display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap; }
.shelf:empty { display: none; }
.shelf span { display: inline-flex; align-items: center; gap: 0.3rem; }
.shelf svg { width: 28px; height: 28px; }

/* ---- the power-up card */

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; margin: 0.6rem 0 0; }
.choices button {
  min-height: 84px;
  padding: 0.2rem 0.4rem 0.3rem;
  border: 5px solid var(--ink);
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 7px 0 var(--ink);
  font: 400 clamp(2rem, 7vw, 2.8rem)/1.1 var(--display);
}
.choices button:hover:not(:disabled) { background: #fff3c2; }
.choices button:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 2px 0 var(--ink); }
.choices button:disabled { background: #e3e6ef; color: #8a93b4; box-shadow: 0 2px 0 var(--ink); transform: translateY(5px); }
.choices button.right { background: #b5f1d3; color: var(--ink); }
.choices.text { grid-template-columns: 1fr; }
.choices.text button { font: 800 1.35rem/1.2 var(--body); min-height: 68px; padding: 0.4rem 0.8rem; }
.choices[hidden] { display: none; }
.card h2.small { font-size: clamp(1.6rem, 5.4vw, 2.2rem); }

.feedback { min-height: 3.6em; margin: 0.8rem 0 0.1rem; font-size: 1.15rem; line-height: 1.4; }
.feedback.good { color: var(--good); font-weight: 800; }

.items { display: grid; gap: 0.3rem; justify-items: center; margin: 0.3rem 0 0.5rem; padding: 0.7rem; border: 4px dashed var(--sky-deep); border-radius: 22px; background: #eaf8ff; min-height: 110px; align-content: center; }
.items .row { display: flex; gap: 0.5rem; justify-content: center; }
.items .it { position: relative; width: 52px; height: 52px; }
.items svg { width: 100%; height: 100%; display: block; animation: pop 0.3s; }
.items .num { position: absolute; right: -4px; bottom: -4px; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; font: 400 0.95rem/26px var(--display); }
.items .hidden-note { margin: 0; font: 400 1.6rem/1.2 var(--display); color: var(--sky-deep); }

.meter { position: relative; height: 56px; margin: 0.8rem 0 1rem; border: 5px solid var(--ink); border-radius: 999px; background: linear-gradient(90deg, #ffd0c9, #fff3c2 50%, #ffd0c9); overflow: hidden; }
.meter .zone { position: absolute; top: 0; bottom: 0; background: #3fd6a3; border-left: 4px solid var(--ink); border-right: 4px solid var(--ink); }
.meter .needle { position: absolute; top: -4px; bottom: -4px; width: 10px; margin-left: -5px; border-radius: 5px; background: var(--ink); box-shadow: 0 0 0 3px #fff; }

/* ---- finish */

.finish .card { padding-top: 1.2rem; }
.prize { width: 120px; height: 120px; color: #ffc61a; filter: drop-shadow(0 6px 0 rgb(28 47 107 / 0.25)); animation: wiggle 1.2s infinite; }
.prize.silver { color: #cfd6e4; }
.prize.bronze { color: #e08f4c; }
.prize.ribbon-prize { color: #5bc0ff; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 0 0 1rem; }
.stats div { padding: 0.5rem 0.2rem; border: 3px solid var(--ink); border-radius: 18px; background: #fff; }
.stats dt { font-size: 0.85rem; font-weight: 800; color: var(--ink-soft); }
.stats dd { margin: 0; font: 400 1.6rem/1.2 var(--display); }

/* ---- no 3D */

.fallback { grid-row: 2; overflow-y: auto; padding: 1rem max(1rem, 4vw) 2rem; max-width: 44rem; }
.fallback h2 { font: 400 2rem/1.1 var(--display); color: var(--tomato); }
.fallback li { margin-bottom: 0.6rem; }
.fallback a { color: var(--ink); font-weight: 800; }
.no-3d .stage { display: none; }

@keyframes pop { from { opacity: 0; transform: scale(0.8); } }
@keyframes wiggle { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
.turbo.on { animation-name: wiggle-c; }
@keyframes wiggle-c { 0%, 100% { transform: translateX(-50%) rotate(-1.5deg); } 50% { transform: translateX(-50%) rotate(1.5deg); } }

/* ---- phones */

@media (max-width: 640px) {
  .back { font-size: 1rem; white-space: nowrap; }
  h1 { font-size: 1.45rem; white-space: nowrap; }
  .place { min-width: 74px; height: 74px; border-radius: 22px; padding-top: 10px; }
  .place .n { font-size: 2.9rem; }
  .place .suf { font-size: 1.2rem; }
  .lap { top: 12px; left: 50%; font-size: 1.15rem; padding: 0.25rem 0.8rem 0.3rem; }
  .map { width: 80px; height: 80px; border-radius: 20px; }
  .turbo { top: 92px; width: 78%; }
  .msg { top: 34%; }
  .card { padding: 1.5rem 1rem 1rem; }
  .pedals button { width: 92px; height: 92px; }
  .items .it { width: 44px; height: 44px; }
}
@media (max-height: 520px) and (min-width: 641px) {
  .card { padding-top: 1.2rem; }
  .card h2 { font-size: 1.8rem; }
  .big { min-height: 56px; }
  .choices button { min-height: 64px; }
  .feedback { min-height: 2.4em; margin-top: 0.4rem; }
  .turbo { top: 12px; left: auto; right: 124px; transform: none; width: 200px; }
  .turbo.on { animation: none; }
  .lap { left: 130px; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .streaks { animation: none; }
  .app.boosting .streaks { opacity: 0.3; }
  .card, .count, .items svg, .place.first, .turbo.on, .prize { animation: none; }
}
