:root {
  --ink: #ffffff;
  --muted: #b9c3dd;
  --panel: rgba(20, 26, 52, 0.78);
  --line: rgba(255, 255, 255, 0.18);
  --gold: #ffd23f;
  --green: #4fcf5a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #5fb8ef; color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent; touch-action: none; }
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.coin { width: 1.2em; height: 1.2em; vertical-align: -0.22em; }
.star { width: 1em; height: 1em; fill: rgba(255, 255, 255, 0.28); stroke: rgba(0, 0, 0, 0.25); stroke-width: 1; }
.star.on { fill: var(--gold); }
.text-shadow, #timer, #lvl { text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; pointer-events: none; display: grid; grid-template-columns: 1fr minmax(10rem, 26rem) 1fr;
  align-items: start; gap: 0.8rem; padding: 0.7rem 0.8rem; }
.hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 0.35rem; }
.clock { background: rgba(20, 26, 52, 0.45); border-radius: 0.9rem; padding: 0.2rem 0.7rem 0.35rem 0.5rem; }
.hud-mid { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding-top: 0.55rem; }
.hud-right { display: flex; justify-content: flex-end; align-items: center; gap: 0.5rem; }
.pill { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0.3rem 0.8rem; font-weight: 800; font-size: 0.9rem; white-space: nowrap; }
.pill.coins { font-size: 1.05rem; display: flex; align-items: center; gap: 0.35rem; font-variant-numeric: tabular-nums; }
#timer { font-size: 2rem; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.1; padding-left: 0.2rem; }
#target { display: flex; align-items: center; gap: 0.1rem; padding-left: 0.25rem; font-size: 1.05rem; }
#target span { font-size: 0.85rem; font-weight: 800; margin-left: 0.35rem; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4); }
#prog { position: relative; width: 100%; height: 0.75rem; border-radius: 999px; background: rgba(20, 26, 52, 0.55); border: 2px solid rgba(255, 255, 255, 0.55); }
#prog-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: linear-gradient(90deg, #ffd23f, #ff8a2a); width: 0; }
#prog-car { position: absolute; top: 50%; width: 1.25rem; height: 1.25rem; border-radius: 50%; background: #ff4d5e; border: 3px solid #fff; transform: translate(-50%, -50%); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); }
#prog-flag { position: absolute; right: -0.9rem; top: 50%; transform: translateY(-62%); width: 1.6rem; height: 1.6rem; }
#prog-flag svg { width: 100%; height: 100%; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5)); }
#prog-ticks i { position: absolute; top: -0.3rem; width: 0.3rem; height: 1.1rem; margin-left: -0.15rem; border-radius: 0.15rem; background: #ff9f1c; border: 1px solid rgba(0, 0, 0, 0.3); }
#prog-ticks i.on { background: var(--green); }
#skip { background: linear-gradient(180deg, #5ed0f5, #2f9fd8); border-radius: 999px; padding: 0.45rem 0.9rem; font-weight: 900; font-size: 0.9rem; box-shadow: 0 3px 0 #1d6f9b; pointer-events: auto; }
#skip[hidden] { display: none; }
.ad-tag { font-size: 0.62rem; font-weight: 900; background: rgba(0, 0, 0, 0.3); border-radius: 0.3rem; padding: 0.08rem 0.3rem; margin-left: 0.25rem; vertical-align: 0.1em; }
.round { width: 2.7rem; height: 2.7rem; border-radius: 50%; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); pointer-events: auto; }
.round svg { width: 1.3rem; height: 1.3rem; }

body.portrait #hud, #hud.portrait { grid-template-columns: 1fr 1fr; }
@media (max-aspect-ratio: 1/1) {
  #hud { grid-template-columns: 1fr auto; padding: 0.55rem 0.6rem; gap: 0.3rem 0.6rem; }
  .hud-mid { grid-column: 1 / -1; grid-row: 2; width: 100%; padding: 0 1rem 0 0.2rem; }
  #timer { font-size: 1.6rem; }
}

/* ---------- pedals (touch only) ---------- */
.pad { position: absolute; bottom: max(1.1rem, env(safe-area-inset-bottom)); width: 6.6rem; height: 6.6rem; border-radius: 50%; display: none; place-items: center;
  background: rgba(20, 26, 52, 0.38); border: 3px solid rgba(255, 255, 255, 0.55); color: #fff; touch-action: none; }
.pad svg { width: 2.8rem; height: 2.8rem; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35)); }
.pad:active { background: rgba(255, 255, 255, 0.28); transform: scale(0.96); }
#pad-brake { left: max(1.1rem, env(safe-area-inset-left)); }
#pad-gas { right: max(1.1rem, env(safe-area-inset-right)); width: 7.4rem; height: 7.4rem; background: rgba(79, 207, 90, 0.38); }
body.touch .pad { display: grid; }
/* first screen: the gas pedal calls for the first press */
#pad-gas.call { animation: padCall 1.1s ease-out infinite; }
#pad-gas.call:active { animation: none; }
@keyframes padCall {
  0% { box-shadow: 0 0 0 0 rgba(140, 255, 150, 0.75); transform: scale(1); }
  35% { transform: scale(1.07); }
  70% { box-shadow: 0 0 0 1.4rem rgba(140, 255, 150, 0); transform: scale(1); }
  100% { box-shadow: 0 0 0 0 rgba(140, 255, 150, 0); }
}

/* ---------- banner, hint, toast ---------- */
#banner { position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); pointer-events: none; text-align: center; padding: 0.7rem 1.8rem; border-radius: 1rem;
  background: var(--panel); border: 2px solid rgba(255, 255, 255, 0.5); }
#banner[hidden] { display: none; }
#banner small { display: block; font-size: 0.75rem; font-weight: 900; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); }
#banner b { font-size: 2rem; font-weight: 900; }
#banner.show { animation: bannerIn 1.6s ease forwards; }
@keyframes bannerIn { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); } 25% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
#hint { position: fixed; z-index: 5; pointer-events: none; width: max-content; background: #fff; color: #1b2446; font-weight: 900; font-size: 1rem; padding: 0.5rem 0.85rem; border-radius: 0.7rem;
  max-width: min(22rem, 86vw); text-align: center; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3); }
#hint[hidden] { display: none; }
#hint.up { transform: translate(-50%, -100%); animation: nudgeU 0.9s ease-in-out infinite; }
#hint.up::after { content: ""; position: absolute; bottom: -0.45rem; left: 50%; transform: translateX(-50%); border: 0.5rem solid transparent; border-bottom: 0; border-top-color: #fff; }
#hint.down { transform: translate(-50%, 0); animation: nudgeD 0.9s ease-in-out infinite; }
@keyframes nudgeU { 50% { margin-top: -6px; } }
@keyframes nudgeD { 50% { margin-top: 6px; } }
.toast { position: absolute; left: 50%; top: 5.2rem; transform: translateX(-50%); pointer-events: none; padding: 0.5rem 1.1rem; border-radius: 999px; white-space: nowrap;
  background: var(--panel); border: 1px solid rgba(255, 210, 63, 0.7); color: var(--gold); font-weight: 900; animation: toastIn 2.6s ease forwards; }
@media (max-aspect-ratio: 1/1) { .toast { top: 8.4rem; } }
@keyframes toastIn { 0% { opacity: 0; transform: translate(-50%, -10px); } 10%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

/* ---------- windows ---------- */
#modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(8, 12, 30, 0.5); z-index: 10; padding: 1rem; }
#modal[hidden] { display: none; }
.modal-card { width: min(23rem, 100%); max-height: calc(100vh - 2rem); overflow-y: auto; background: linear-gradient(180deg, #2b3a74, #1b244f); border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 1.3rem; padding: 1.2rem 1.2rem 1rem; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45); text-align: center; animation: pop 0.25s ease; }
.modal-card.wide { width: min(36rem, 100%); }
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }
.modal-card h2 { margin: 0 0 0.7rem; font-size: 1.5rem; font-weight: 900; display: flex; align-items: center; justify-content: center; gap: 0.6rem; }
.total { font-size: 0.95rem; font-weight: 800; background: rgba(0, 0, 0, 0.25); border-radius: 999px; padding: 0.2rem 0.6rem; display: inline-flex; align-items: center; gap: 0.25rem; }
.big-stars { display: flex; justify-content: center; gap: 0.4rem; margin: 0.1rem 0 0.6rem; }
.big-stars .star { width: 3.6rem; height: 3.6rem; }
.big-stars .star.pop { animation: starPop 0.4s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes starPop { from { transform: scale(0.2) rotate(-40deg); } }
.big-stars .star:nth-child(2) { transform: translateY(-0.5rem); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.stats div { background: rgba(255, 255, 255, 0.07); border-radius: 0.7rem; padding: 0.45rem; display: flex; flex-direction: column; }
.stats small { color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.stats b { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.stats b.c { display: flex; align-items: center; justify-content: center; gap: 0.3rem; }
.unlock { margin: 0.4rem 0 0; color: #ffd23f; font-weight: 700; }
#r-garage.attn { animation: bbPulse 1.4s ease-in-out infinite; }
@keyframes bbPulse { 50% { transform: scale(1.03); } }
.muted { color: var(--muted); }
.small { font-size: 0.78rem; line-height: 1.35; margin: 0.6rem 0 0; }
.modal-btns { display: flex; flex-direction: column; gap: 0.55rem; margin-top: 1rem; }
.modal-btns.row, .modal-btns .row { display: flex; flex-direction: row; gap: 0.55rem; }
.modal-btns .row > *, .modal-btns.row > * { flex: 1; }
.modal-btns button { padding: 0.8rem 1rem; border-radius: 0.9rem; font-weight: 900; font-size: 1rem; background: rgba(255, 255, 255, 0.1); border: 1px solid var(--line); }
.modal-btns .primary { background: linear-gradient(180deg, #7be36f, #3db845); color: #0f3d14; border: 0; box-shadow: 0 4px 0 #23802b; font-size: 1.15rem; }
.modal-btns .primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #23802b; }
.modal-btns .ad { background: rgba(94, 208, 245, 0.18); color: #d4f4ff; border: 1px solid rgba(94, 208, 245, 0.6); }
.modal-btns button:disabled { opacity: 0.6; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 0.55rem 0.2rem; border-bottom: 1px solid rgba(255, 255, 255, 0.07); font-weight: 800; }
.tog { width: 3rem; height: 1.7rem; border-radius: 999px; background: rgba(255, 255, 255, 0.18); position: relative; transition: background 0.2s; }
.tog::after { content: ""; position: absolute; left: 0.2rem; top: 0.2rem; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: #fff; transition: left 0.2s; }
.tog.on { background: #4fcf5a; }
.tog.on::after { left: 1.5rem; }

/* level select */
.tabs { display: flex; gap: 0.4rem; margin-bottom: 0.7rem; }
.tab { flex: 1; padding: 0.5rem 0.3rem; border-radius: 0.8rem; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); font-weight: 900; font-size: 0.85rem; display: flex; flex-direction: column; align-items: center; gap: 0.15rem; }
.tab small { font-size: 0.75rem; display: flex; align-items: center; gap: 0.2rem; color: var(--muted); }
.tab svg:not(.star) { width: 0.9rem; height: 0.9rem; }
.tab.on { background: rgba(255, 210, 63, 0.2); border-color: rgba(255, 210, 63, 0.75); }
.tab.locked { opacity: 0.55; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
.tile { border-radius: 0.9rem; padding: 0.55rem 0.2rem 0.45rem; display: flex; flex-direction: column; align-items: center; gap: 0.15rem; border: 2px solid rgba(255, 255, 255, 0.25);
  background: linear-gradient(180deg, #4cb944, #2f8a35); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); min-height: 5.2rem; }
.theme-1 .tile { background: linear-gradient(180deg, #f2b45c, #c97e30); }
.theme-2 .tile { background: linear-gradient(180deg, #5a55b8, #2f2a78); }
.tile b { font-size: 1.5rem; font-weight: 900; line-height: 1.1; }
.tile b svg { width: 1.3rem; height: 1.3rem; }
.tile small { font-size: 0.66rem; font-weight: 800; min-height: 1.6em; line-height: 1.2; }
.tile .tstars { display: flex; gap: 0.05rem; font-size: 0.95rem; }
.tile.locked { background: rgba(255, 255, 255, 0.07) !important; box-shadow: none; color: var(--muted); }
.tile.cur { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35), 0 3px 0 rgba(0, 0, 0, 0.25); }
@media (max-width: 420px) { .tiles { grid-template-columns: repeat(4, 1fr); gap: 0.35rem; } .tile small { font-size: 0.58rem; } }

/* garage */
#g-car { width: 100%; max-width: 18rem; height: auto; aspect-ratio: 2 / 1; background: radial-gradient(ellipse at 50% 85%, rgba(255, 255, 255, 0.16), transparent 60%); border-radius: 1rem; }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-top: 0.5rem; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; padding: 0.45rem 0.2rem; border-radius: 0.8rem; background: rgba(255, 255, 255, 0.06); border: 2px solid transparent; }
.swatch i { width: 2.2rem; height: 2.2rem; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.85); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); }
.swatch small { font-size: 0.72rem; font-weight: 800; display: flex; align-items: center; gap: 0.15rem; }
.swatch:not(.own) i { opacity: 0.6; }
.swatch.on { border-color: var(--gold); background: rgba(255, 210, 63, 0.14); }
