: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: #5fb6ff; 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; }

/* ---------- run 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.75rem 0.45rem; min-width: 7.5rem; }
#dist { font-weight: 900; line-height: 1; display: flex; align-items: baseline; gap: 0.2rem; font-variant-numeric: tabular-nums; }
#dist b { font-size: 2.4rem; font-style: italic; }
#dist small { font-size: 1rem; }
#best { font-weight: 800; font-size: 0.85rem; opacity: 0.9; }
#best.new { color: var(--gold); animation: blink 0.8s ease-in-out infinite; }
#armor { display: flex; gap: 0.2rem; }
.shield { width: 1.2rem; height: 1.2rem; fill: rgba(255, 255, 255, 0.2); stroke: rgba(0, 0, 0, 0.3); stroke-width: 1; }
.shield.on { fill: #3fc46b; }
.hud-r { display: flex; gap: 0.5rem; align-items: center; }
#pause { pointer-events: auto; }
#combo { position: absolute; left: 50%; top: 0.7rem; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; pointer-events: none;
  background: rgba(14, 16, 40, 0.5); border: 2px solid #41f2ff; border-radius: 0.9rem; padding: 0.2rem 0.9rem 0.35rem; overflow: hidden; }
#combo b { font-size: 1.8rem; font-weight: 900; font-style: italic; color: #41f2ff; line-height: 1; }
#combo span { font-size: 0.7rem; font-weight: 900; letter-spacing: 0.12em; }
#combo i { position: absolute; left: 0; bottom: 0; height: 0.25rem; background: #41f2ff; }
@keyframes blink { 50% { opacity: 0.45; } }
#banner { position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; display: flex; flex-direction: column; align-items: center; }
#banner b { font-size: 2.6rem; font-weight: 900; font-style: italic; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.4); white-space: nowrap; }
#banner small { font-weight: 900; font-size: 1rem; color: var(--gold); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); }
#banner.show { animation: bannerIn 2.2s ease forwards; }
@keyframes bannerIn { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); } 20% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* 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); }

/* ---------- start screen ---------- */
#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.6), rgba(14, 16, 40, 0.1) 35%, rgba(14, 16, 40, 0.65)); 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.45rem; font-size: 3.4rem; font-weight: 900; font-style: italic; letter-spacing: 0.02em; text-shadow: 0 5px 0 rgba(0, 0, 0, 0.35); margin-top: 0.4rem; }
.logo b:first-child { color: var(--gold); }
.bestline { font-weight: 900; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); text-align: center; }
.missions { width: 100%; max-width: 30rem; background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; padding: 0.6rem 0.75rem; display: flex; flex-direction: column; gap: 0.4rem; }
.missions h3 { margin: 0; font-size: 0.95rem; font-weight: 900; display: flex; align-items: center; gap: 0.35rem; }
.missions h3 svg { width: 1.1rem; height: 1.1rem; }
.mis { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; gap: 0.15rem 0.6rem; font-size: 0.85rem; font-weight: 800; }
.mis span { grid-column: 1; }
.mis i { grid-column: 1; height: 0.4rem; border-radius: 999px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.mis i b { display: block; height: 100%; background: var(--gold); }
.mis em { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-style: normal; color: var(--gold); display: flex; align-items: center; gap: 0.2rem; }
.mis.done span { color: #8df5a6; }
.mis.done i b { background: #3fc46b; }
.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-drive { min-width: 13rem; font-size: 1.5rem; padding: 0.95rem 1.8rem; }
.btn.ghost { background: rgba(255, 255, 255, 0.14); border: 2px solid rgba(255, 255, 255, 0.35); }
.btn.ghost.done { opacity: 0.6; }
#menu .btn.ghost { background: rgba(14, 16, 40, 0.55); }
.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: 900; text-align: center; letter-spacing: 0.08em; }
.res-head h2 { font-size: 2.4rem; font-style: italic; }
.res-head.win small { color: var(--gold); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.3rem; }
.chips span { background: rgba(255, 255, 255, 0.1); border-radius: 999px; padding: 0.2rem 0.6rem; font-size: 0.78rem; font-weight: 800; }
.lines .good { color: #8df5a6; }
.card.results .missions { max-width: none; background: rgba(255, 255, 255, 0.05); border: 0; }
.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(9rem, 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: 132px; height: 84px; }
.stats em { font-style: normal; color: #fff; }
.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) {
  #dist b { font-size: 2rem; }
  .logo { font-size: 2.6rem; }
  #m-drive { min-width: 0; flex: 1 1 100%; order: -1; }
  .actions .btn.ghost { flex: 1; }
  #banner b { font-size: 2rem; }
}
@media (max-height: 460px) and (min-aspect-ratio: 5/4) {
  #menu { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto auto minmax(0, 1fr); align-items: start; justify-items: center; }
  #menu .top { grid-column: 1 / -1; max-width: none; }
  .logo { font-size: 2.2rem; margin: 0; grid-column: 1; }
  .bestline { grid-column: 1; }
  .missions { grid-column: 1; }
  .actions { grid-column: 2; grid-row: 2 / span 3; flex-direction: column; flex-wrap: nowrap; margin-top: 0; width: auto; align-self: stretch; justify-content: flex-start; }
  #m-drive { min-width: 0; order: -1; }
  .card { padding: 0.7rem 0.9rem; gap: 0.45rem; }
  .card h2 { font-size: 1.3rem; }
  .res-head h2 { font-size: 1.6rem; }
  .card.results .missions { display: none; }
  .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; }
  .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); }
  #dist b { font-size: 1.7rem; }
}
