:root {
  --ink: #ffffff;
  --muted: #c9d0e6;
  --panel: rgba(22, 24, 48, 0.86);
  --line: rgba(255, 255, 255, 0.16);
  --gold: #ffd23f;
  --go: #ff5a36;
  --green: #3fc46b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #7cc95a; 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; }
#ui > [hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.coin { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; }
.star { width: 1em; height: 1em; fill: rgba(255, 255, 255, 0.25); stroke: rgba(0, 0, 0, 0.3); stroke-width: 1; }
.star.on { fill: var(--gold); }
.pill { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0.3rem 0.8rem; font-weight: 900; white-space: nowrap; }
.pill.coins { display: flex; align-items: center; gap: 0.35rem; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.round { width: 2.7rem; height: 2.7rem; border-radius: 50%; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); }
.round svg { width: 1.3rem; height: 1.3rem; }
.dot { position: absolute; top: -0.2rem; right: -0.2rem; width: 0.8rem; height: 0.8rem; border-radius: 50%; background: #ff3b3b; border: 2px solid #fff; }

/* ---------- race HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 0.6rem 0.7rem; pointer-events: none; }
.hud-l { display: flex; flex-direction: column; gap: 0.15rem; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); background: rgba(14, 16, 40, 0.42); border-radius: 0.9rem; padding: 0.3rem 0.7rem 0.4rem; }
#place { font-weight: 900; line-height: 1; display: flex; align-items: baseline; gap: 0.1rem; }
#place b { font-size: 3rem; }
#place small { font-size: 1.2rem; }
#place span { font-size: 1rem; opacity: 0.85; margin-left: 0.3rem; }
#place.lead b, #place.lead small { color: var(--gold); }
#lap { font-weight: 900; font-size: 1.05rem; }
#clock { font-weight: 800; font-size: 0.95rem; font-variant-numeric: tabular-nums; opacity: 0.9; }
.hud-r { display: flex; gap: 0.5rem; align-items: flex-start; }
#mini { width: 7.5rem; height: 7.5rem; border-radius: 1rem; background: rgba(10, 12, 30, 0.35); }
#pause { pointer-events: auto; }
#count { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); font-size: 6rem; font-weight: 900; pointer-events: none;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35); }
#count.go { color: var(--gold); }
#count.show { animation: countIn 0.9s ease forwards; }
@keyframes countIn { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.8); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); } }
#popups { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 0.2rem; }
.popup { font-weight: 900; font-size: 1.5rem; color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.4); animation: popUp 1.3s ease forwards; white-space: nowrap; }
.popup.drift { color: #7df9ff; }
.popup.big { font-size: 2rem; color: var(--gold); }
.popup.lap { color: #fff; font-size: 1.7rem; }
@keyframes popUp { 0% { opacity: 0; transform: translateY(12px) scale(0.8); } 15% { opacity: 1; transform: translateY(0) scale(1.08); } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-18px); } }
#wrong { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%); background: #ff3b3b; color: #fff; font-weight: 900; font-size: 1.4rem;
  padding: 0.5rem 1.2rem; border-radius: 0.8rem; pointer-events: none; animation: blink 0.8s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.4; } }

/* touch controls */
#controls { position: absolute; inset: auto 0 0 0; height: 0; pointer-events: none; }
.pad { position: absolute; bottom: max(1rem, env(safe-area-inset-bottom)); width: 5.6rem; height: 5.6rem; border-radius: 50%; display: grid; place-items: center;
  background: rgba(20, 22, 48, 0.42); border: 3px solid rgba(255, 255, 255, 0.6); color: #fff; touch-action: none; pointer-events: auto; font-weight: 900; }
.pad svg { width: 2.4rem; height: 2.4rem; }
.pad.down { background: rgba(255, 255, 255, 0.32); transform: scale(0.95); }
#pad-left { left: max(0.9rem, env(safe-area-inset-left)); }
#pad-right { left: calc(max(0.9rem, env(safe-area-inset-left)) + 6.4rem); }
#pad-nitro { right: max(0.9rem, env(safe-area-inset-right)); width: 6.4rem; height: 6.4rem; overflow: hidden; font-size: 0.95rem; }
#pad-nitro span { position: relative; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); }
#nitro-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(0deg, #1fb8ff, #41f2ff); opacity: 0.55; }
#pad-nitro.ready { border-color: #41f2ff; box-shadow: 0 0 18px rgba(65, 242, 255, 0.6); }
#pad-nitro.on { transform: scale(0.95); background: rgba(65, 242, 255, 0.35); }
.pad.small { width: 4.2rem; height: 4.2rem; font-size: 0.72rem; right: calc(max(0.9rem, env(safe-area-inset-right)) + 1.1rem); bottom: calc(max(1rem, env(safe-area-inset-bottom)) + 7.2rem); }
#nitro-bar { position: absolute; left: 50%; bottom: 1rem; transform: translateX(-50%); width: min(22rem, 60vw); height: 1.6rem; border-radius: 999px; overflow: hidden;
  background: rgba(20, 22, 48, 0.55); border: 2px solid rgba(255, 255, 255, 0.55); pointer-events: none; }
#nitro-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, #1fb8ff, #41f2ff); }
#nitro-bar span { position: relative; display: block; text-align: center; font-weight: 900; font-size: 0.8rem; line-height: 1.45rem; letter-spacing: 0.08em; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5); }
#nitro-bar.ready { border-color: #41f2ff; box-shadow: 0 0 14px rgba(65, 242, 255, 0.6); }

/* ---------- trip map ---------- */
#menu { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; padding: 0.8rem; gap: 0.7rem;
  background: linear-gradient(180deg, rgba(14, 16, 40, 0.55), rgba(14, 16, 40, 0.15) 30%, rgba(14, 16, 40, 0.55)); overflow-y: auto; touch-action: pan-y; }
#menu .top { width: 100%; max-width: 46rem; display: flex; justify-content: space-between; align-items: center; }
.logo { display: flex; gap: 0.4rem; font-size: 2.2rem; font-weight: 900; font-style: italic; letter-spacing: 0.02em; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); }
.logo b:first-child { color: var(--gold); }
.top-r { display: flex; gap: 0.5rem; align-items: center; }
.map { width: 100%; max-width: 46rem; background: var(--panel); border: 1px solid var(--line); border-radius: 1.2rem; padding: 0.7rem; display: flex; flex-direction: column; gap: 0.6rem; }
.cups { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; }
.cup { border-radius: 0.8rem; padding: 0.5rem 0.4rem; text-align: center; display: flex; flex-direction: column; gap: 0.15rem; border: 2px solid transparent; opacity: 0.85; }
.cup b { font-size: 0.85rem; }
.cup span { font-size: 0.78rem; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 0.2rem; }
.cup span svg { width: 0.95em; height: 0.95em; }
.cup.meadow { background: #3f8f3a; } .cup.canyon { background: #b8692f; } .cup.snow { background: #5b84b8; } .cup.neon { background: #5a2a8f; }
.cup.on { border-color: #fff; opacity: 1; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3); }
.cup.locked { filter: grayscale(0.7); opacity: 0.55; }
.tracks { display: flex; flex-direction: column; gap: 0.35rem; }
.track { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.7rem; border-radius: 0.8rem; background: rgba(255, 255, 255, 0.07); text-align: left; }
.track.next { background: rgba(255, 210, 63, 0.18); outline: 2px solid rgba(255, 210, 63, 0.7); }
.track.locked { opacity: 0.45; cursor: default; }
.track .num { width: 1.9rem; height: 1.9rem; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, 0.14); font-weight: 900; flex: none; }
.tname { flex: 1; font-weight: 900; display: flex; flex-direction: column; }
.tname small { font-weight: 700; font-size: 0.75rem; color: var(--muted); }
.tstars { display: flex; gap: 0.1rem; }
.tstars .star { width: 1.25rem; height: 1.25rem; }
.tstars svg:not(.star) { width: 1.2rem; height: 1.2rem; color: var(--muted); }
.actions { width: 100%; max-width: 46rem; display: flex; gap: 0.6rem; justify-content: center; align-items: stretch; flex-wrap: wrap; margin-top: auto; padding-bottom: 0.3rem; }
.btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.75rem 1.3rem; border-radius: 1rem; font-weight: 900; font-size: 1.1rem; }
.btn svg { width: 1.5rem; height: 1.5rem; flex: none; }
.btn span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
.btn small { font-size: 0.72rem; font-weight: 800; opacity: 0.9; }
.btn.go { background: linear-gradient(180deg, #ff7a45, #f04a24); box-shadow: 0 4px 0 #a52c12; }
.btn.go:active { transform: translateY(2px); box-shadow: 0 2px 0 #a52c12; }
#m-race { min-width: 13rem; font-size: 1.4rem; padding: 0.9rem 1.6rem; }
.btn.ghost { background: rgba(255, 255, 255, 0.14); border: 2px solid rgba(255, 255, 255, 0.35); }
.btn.ghost.done { opacity: 0.6; }
.btn.ghost.attn { border-color: var(--gold); background: rgba(255, 210, 63, 0.22); animation: attn 1.2s ease-in-out infinite; }
.btn.ghost.attn small { color: var(--gold); opacity: 1; }
@keyframes attn { 50% { box-shadow: 0 0 0 0.35rem rgba(255, 210, 63, 0.35); } }
.btn.ad { background: linear-gradient(180deg, #4fd06a, #2fa64b); box-shadow: 0 4px 0 #1d7432; flex-direction: row; }
.btn.ad small { margin-left: 0.4rem; }
.ad-tag { font-style: normal; font-size: 0.62rem; background: rgba(0, 0, 0, 0.3); border-radius: 0.3rem; padding: 0.1rem 0.3rem; }

/* ---------- windows ---------- */
#modal { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8, 10, 26, 0.55); padding: 0.8rem; }
.card { width: min(30rem, 100%); max-height: 100%; overflow-y: auto; touch-action: pan-y; background: #1b1d3d; border: 2px solid rgba(255, 255, 255, 0.2); border-radius: 1.3rem;
  padding: 1.1rem; display: flex; flex-direction: column; gap: 0.75rem; box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45); animation: cardIn 0.25s ease; }
.card.garage { width: min(40rem, 100%); }
@keyframes cardIn { from { transform: scale(0.92); opacity: 0; } to { transform: none; opacity: 1; } }
.card h2 { margin: 0; font-size: 1.6rem; font-weight: 900; text-align: center; }
.note { margin: 0; text-align: center; color: var(--muted); font-size: 0.9rem; font-weight: 700; }
.note.good { color: #8df5a6; }
.note.small { font-size: 0.75rem; }
.btns { display: flex; gap: 0.5rem; justify-content: center; }
.btns.col { flex-direction: column; align-items: stretch; }
.btns .row2 { display: flex; gap: 0.5rem; }
.btns .row2 .btn { flex: 1; }
.res-head { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; }
.res-head svg { width: 3.6rem; height: 3.6rem; }
.res-head.win h2 { color: var(--gold); font-size: 2rem; }
.res-head small { color: var(--muted); font-weight: 700; text-align: center; }
.bigstars { display: flex; justify-content: center; gap: 0.4rem; }
.bigstars .star { width: 2.6rem; height: 2.6rem; }
.lines { display: flex; flex-direction: column; gap: 0.3rem; background: rgba(255, 255, 255, 0.06); border-radius: 0.9rem; padding: 0.6rem 0.8rem; }
.lines div { display: flex; justify-content: space-between; font-weight: 800; }
.lines .total { border-top: 1px solid var(--line); padding-top: 0.35rem; font-size: 1.15rem; color: var(--gold); }
.lines .total b { display: flex; align-items: center; gap: 0.3rem; }
.doubled { text-align: center; font-weight: 900; color: #8df5a6; padding: 0.6rem; }
.toggles { display: flex; gap: 0.5rem; justify-content: center; }
.toggles button { padding: 0.55rem 1.1rem; border-radius: 0.8rem; font-weight: 900; background: rgba(255, 255, 255, 0.1); border: 2px solid rgba(255, 255, 255, 0.25); text-decoration: line-through; opacity: 0.7; }
.toggles button.on { background: rgba(63, 196, 107, 0.3); border-color: var(--green); text-decoration: none; opacity: 1; }
.ghead { display: flex; justify-content: space-between; align-items: center; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.tabs button { padding: 0.5rem; border-radius: 0.8rem; font-weight: 900; background: rgba(255, 255, 255, 0.08); }
.tabs button.on { background: rgba(255, 255, 255, 0.22); }
.gbody { display: flex; flex-direction: column; gap: 0.45rem; }
.row { display: flex; align-items: center; gap: 0.6rem; background: rgba(255, 255, 255, 0.06); border-radius: 0.9rem; padding: 0.5rem 0.6rem; }
.ico { width: 2.6rem; height: 2.6rem; border-radius: 0.7rem; background: rgba(255, 255, 255, 0.1); display: grid; place-items: center; flex: none; }
.ico svg { width: 1.7rem; height: 1.7rem; }
.rtxt { flex: 1; display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.rtxt small { color: var(--muted); font-weight: 700; font-size: 0.78rem; }
.pips { display: flex; gap: 2px; }
.pips i { flex: 1; max-width: 1.1rem; height: 0.4rem; border-radius: 2px; background: rgba(255, 255, 255, 0.15); }
.pips i.on { background: var(--gold); }
.buy { min-width: 5.6rem; padding: 0.5rem 0.7rem; border-radius: 0.8rem; font-weight: 900; background: linear-gradient(180deg, #ffd23f, #f0a800); color: #3a2600;
  box-shadow: 0 3px 0 #a87400; display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem; font-variant-numeric: tabular-nums; }
.buy.off { filter: grayscale(0.8); opacity: 0.6; }
.buy.sel { background: rgba(63, 196, 107, 0.35); color: #fff; box-shadow: none; }
.buy:disabled:not(.sel) { background: rgba(255, 255, 255, 0.15); color: #fff; box-shadow: none; }
.cars { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: 0.5rem; }
.carcard { background: rgba(255, 255, 255, 0.06); border-radius: 0.9rem; padding: 0.5rem; display: flex; flex-direction: column; align-items: center; gap: 0.3rem; border: 2px solid transparent; }
.carcard.on { border-color: var(--green); }
.carcard canvas { width: 120px; height: 70px; }
.stats { width: 100%; display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.4rem; align-items: center; font-size: 0.7rem; font-weight: 800; color: var(--muted); }
.stats i { height: 0.4rem; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.stats i b { display: block; height: 100%; background: #41f2ff; }
.paints { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; justify-content: center; font-weight: 900; }
.paint { width: 2rem; height: 2rem; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.3); }
.paint.on { border-color: #fff; transform: scale(1.12); }

/* ---------- hint, toast ---------- */
#hint { position: fixed; z-index: 5; pointer-events: none; background: #fff; color: #1b2446; font-weight: 900; font-size: 1rem; padding: 0.5rem 0.85rem; border-radius: 0.7rem;
  max-width: min(20rem, 86vw); text-align: center; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3); }
#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; }
#hint.down::after { content: ""; position: absolute; top: -0.45rem; left: 50%; transform: translateX(-50%); border: 0.5rem solid transparent; border-top: 0; border-bottom-color: #fff; }
#hint.center { transform: translate(-50%, -50%); }
@keyframes nudgeU { 50% { margin-top: -6px; } }
@keyframes nudgeD { 50% { margin-top: 6px; } }
#toasts { position: absolute; left: 50%; top: 5.5rem; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 0.3rem; pointer-events: none; }
.toast { padding: 0.5rem 1.1rem; border-radius: 999px; background: var(--panel); border: 1px solid rgba(255, 210, 63, 0.7); color: var(--gold); font-weight: 900;
  animation: toastIn 2.8s ease forwards; text-align: center; max-width: 90vw; }
@keyframes toastIn { 0% { opacity: 0; transform: translateY(-8px); } 10% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }

/* small screens */
@media (max-width: 560px) {
  #place b { font-size: 2.4rem; }
  #mini { width: 5.6rem; height: 5.6rem; }
  .logo { font-size: 1.7rem; }
  .cup b { font-size: 0.72rem; }
  .cup span { font-size: 0.68rem; }
  #m-race { min-width: 0; flex: 1 1 100%; order: -1; }
  .actions .btn.ghost { flex: 1; }
}
@media (max-height: 460px) and (min-aspect-ratio: 5/4) {
  #menu { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); align-items: start; }
  #menu .top { grid-column: 1 / -1; max-width: none; }
  .map { max-width: none; }
  .actions { grid-column: 2; grid-row: 2; flex-direction: column; flex-wrap: nowrap; margin-top: 0; width: auto; align-self: stretch; justify-content: flex-start; }
  #m-race { min-width: 0; order: -1; }
  .card { padding: 0.7rem 0.9rem; gap: 0.45rem; }
  .card h2 { font-size: 1.3rem; }
  .res-head svg { display: none; }
  .res-head.win h2 { font-size: 1.5rem; }
  .bigstars .star { width: 1.7rem; height: 1.7rem; }
  .lines { padding: 0.4rem 0.7rem; gap: 0.15rem; }
  .btn { padding: 0.55rem 1rem; font-size: 1rem; }
  .btns.col { flex-direction: row; flex-wrap: wrap; }
  .btns.col > .btn { flex: 1 1 40%; }
  .btns.col .row2 { flex: 1 1 100%; }
}
@media (max-height: 460px) {
  #menu { padding: 0.5rem; gap: 0.4rem; }
  .map { padding: 0.5rem; gap: 0.4rem; }
  .track { padding: 0.3rem 0.6rem; }
  .pad { width: 4.8rem; height: 4.8rem; }
  #pad-right { left: calc(max(0.9rem, env(safe-area-inset-left)) + 5.5rem); }
  #pad-nitro { width: 5.4rem; height: 5.4rem; }
  .pad.small { bottom: calc(max(1rem, env(safe-area-inset-bottom)) + 6rem); }
  #count { font-size: 4.5rem; }
}
