:root {
  --red: #ff3b30; --yellow: #ffd23f; --teal: #1fb5c9; --pink: #ff5fa2; --ink: #16161d; --cream: #fff8e6;
  --panel: rgba(22, 22, 29, 0.78);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fc8d8; font-family: 'Nunito', system-ui, sans-serif; color: var(--cream); }
#game { position: fixed; inset: 0; display: block; }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
button { font: inherit; cursor: pointer; }
kbd { display: inline-block; min-width: 1.5em; padding: 0 0.35em; border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 6px; background: #fff; color: var(--ink); font: 800 0.78em 'Nunito', sans-serif; text-align: center; line-height: 1.5; }

/* ---------- logo ---------- */
.logo { font-family: 'Bungee Shade', 'Bungee', sans-serif; font-size: clamp(54px, 10vw, 118px); line-height: 0.9; color: var(--yellow); letter-spacing: 0.02em; transform: rotate(-3deg); text-shadow: 5px 5px 0 var(--red), 10px 10px 0 var(--ink); }
.logo span { color: var(--pink); margin-left: 0.15em; }
.logo.small { font-size: 64px; }

#loading { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; text-align: center; background: radial-gradient(circle at 50% 40%, #2ec4d6, #0f6f8c); }
#loading p { font: 800 20px 'Nunito', sans-serif; margin-top: 30px; animation: bob 0.8s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-6px); } }

/* ---------- title ---------- */
#title { position: fixed; inset: 0; z-index: 20; display: none; overflow-y: auto; padding: 24px 16px; background: linear-gradient(180deg, rgba(10, 40, 60, 0.15), rgba(10, 20, 40, 0.55)); }
#title.on { display: block; }
#title .card { max-width: 980px; margin: 0 auto; background: rgba(22, 22, 29, 0.82); border: 4px solid var(--ink); border-radius: 22px; padding: 26px 28px 22px; box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.35); backdrop-filter: blur(6px); }
.kicker { font: 900 13px 'Nunito'; letter-spacing: 0.2em; text-transform: uppercase; color: var(--teal); margin-bottom: 8px; }
.tagline { font: 800 18px 'Nunito'; margin: 34px 0 18px; max-width: 640px; }
.row { display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 18px; }
.nm { display: flex; flex-direction: column; gap: 6px; font-weight: 900; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; }
.nm input { width: 220px; font: 800 18px 'Nunito'; padding: 8px 12px; border-radius: 10px; border: 3px solid var(--ink); background: var(--cream); color: var(--ink); }
.paintbox span { display: block; font-weight: 900; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
#paints { display: flex; gap: 8px; }
#paints button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--ink); transition: transform 0.1s; }
#paints button.sel { transform: scale(1.18); box-shadow: 0 0 0 3px var(--cream); }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.modes button, .btns button, .toggles button { font: 400 22px 'Bungee', sans-serif; padding: 14px 16px; border-radius: 14px; border: 4px solid var(--ink); background: var(--teal); color: var(--ink); box-shadow: 5px 5px 0 var(--ink); transition: transform 0.08s, box-shadow 0.08s; text-align: left; }
.modes button small { display: block; font: 800 14px 'Nunito'; margin-top: 4px; }
.modes button.primary, .btns button.primary { background: var(--yellow); }
.modes button:hover, .btns button:hover, .toggles button:hover, .race:hover { transform: translate(-2px, -2px); box-shadow: 7px 7px 0 var(--ink); }
.modes button:active, .btns button:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--ink); }
.lab { font: 900 13px 'Nunito'; letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 8px; opacity: 0.85; }
#races { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
.race { display: grid; grid-template-columns: 40px 1fr auto; grid-template-rows: auto auto auto; gap: 2px 10px; text-align: left; padding: 10px 12px; border-radius: 12px; border: 3px solid var(--ink); background: var(--cream); color: var(--ink); box-shadow: 4px 4px 0 var(--ink); transition: transform 0.08s, box-shadow 0.08s; }
.race .num { grid-row: span 3; font: 400 30px 'Bungee'; color: var(--red); align-self: center; }
.race .rn { font: 400 17px 'Bungee'; }
.race .icons { font-size: 20px; }
.race .rb { grid-column: 2 / 4; font: 700 13px 'Nunito'; opacity: 0.8; }
.race .bt { grid-column: 2 / 4; font: 900 12px 'Nunito'; color: #b5285e; }
.foot { display: flex; gap: 16px; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; }
.keys { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; font-weight: 800; max-width: 680px; }
.keys .plane { flex-basis: 100%; }
.toggles { display: flex; gap: 8px; }
.toggles button { font: 800 14px 'Nunito'; padding: 8px 12px; box-shadow: 3px 3px 0 var(--ink); background: var(--cream); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.panel { background: var(--panel); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35); }
#posbox { position: absolute; top: 14px; left: 14px; padding: 8px 16px 10px; min-width: 170px; }
#pos { font: 400 64px/1 'Bungee'; color: var(--yellow); text-shadow: 3px 3px 0 var(--red); }
#pos sup { font-size: 26px; vertical-align: top; margin-left: 2px; }
#pos small { font-size: 22px; color: var(--cream); text-shadow: none; margin-left: 6px; }
#racename { font: 900 14px 'Nunito'; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 4px; }
#legs { margin-top: 6px; font-size: 22px; display: flex; align-items: center; gap: 4px; }
#legs b { opacity: 0.5; font-size: 16px; }
#legs .leg { padding: 2px 6px; border-radius: 8px; opacity: 0.45; }
#legs .leg.done { opacity: 0.35; filter: grayscale(1); }
#legs .leg.now { opacity: 1; background: var(--yellow); box-shadow: 0 0 0 2px var(--ink); }
#timebox { position: absolute; top: 14px; right: 14px; padding: 10px 16px; text-align: right; }
#timer { font: 400 34px 'Bungee'; }
#best, #gate { font: 800 13px 'Nunito'; opacity: 0.85; }
#gate { color: var(--yellow); opacity: 1; }
#freehud { position: absolute; top: 14px; left: 14px; padding: 10px 16px; font: 800 15px 'Nunito'; display: grid; gap: 4px; }
#freehud span { font: 400 20px 'Bungee'; color: var(--yellow); margin-left: 8px; }
#dj { position: absolute; top: 14px; left: 50%; transform: translate(-50%, -140%); max-width: min(560px, 60vw); padding: 8px 18px 10px; transition: transform 0.3s cubic-bezier(.2, 1.6, .5, 1); background: var(--cream); color: var(--ink); }
#dj.on { transform: translate(-50%, 0); }
#dj .who { font: 400 12px 'Bungee'; color: var(--red); }
#dj .say { font: 900 18px 'Nunito'; }
#speedo { position: absolute; right: 14px; bottom: 14px; padding: 10px 16px 12px; min-width: 210px; text-align: right; }
#speedo .v { font: 400 54px/1 'Bungee'; color: var(--yellow); text-shadow: 3px 3px 0 var(--red); }
#speedo .v small { font: 900 14px 'Nunito'; color: var(--cream); text-shadow: none; margin-left: 6px; }
#vname { font: 900 14px 'Nunito'; margin: 4px 0 8px; }
#nitro { position: relative; height: 18px; border: 3px solid var(--ink); border-radius: 9px; background: #333; overflow: hidden; }
#nitro i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, var(--teal), #7fe3ff); transition: width 0.1s; }
#nitro.on i { background: linear-gradient(90deg, var(--red), var(--yellow)); }
#nitro span { position: relative; font: 400 11px/12px 'Bungee'; color: #fff; text-shadow: 1px 1px 0 var(--ink); }
#miniwrap { position: absolute; left: 14px; bottom: 14px; width: 200px; height: 200px; border-radius: 50%; border: 4px solid var(--ink); box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35); overflow: hidden; background: #2a8a9a; }
#mini { display: block; }
#prompt { position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%) scale(0.9); padding: 10px 18px; border-radius: 12px; border: 3px solid var(--ink); background: var(--yellow); color: var(--ink); font: 900 18px 'Nunito'; opacity: 0; transition: opacity 0.15s, transform 0.15s; white-space: nowrap; }
#prompt.on { opacity: 1; transform: translateX(-50%) scale(1); }
#flash { position: absolute; inset: 0; display: grid; place-items: center; }
.big { grid-area: 1 / 1; font: 400 clamp(40px, 9vw, 110px) 'Bungee'; color: var(--yellow); text-shadow: 4px 4px 0 var(--red), 8px 8px 0 var(--ink); animation: pop 1.2s cubic-bezier(.2, 1.5, .4, 1) forwards; transform: translateY(-12vh); text-align: center; }
.big.red { color: var(--red); text-shadow: 4px 4px 0 var(--yellow), 8px 8px 0 var(--ink); }
.big.pink { color: var(--pink); text-shadow: 4px 4px 0 var(--cream), 8px 8px 0 var(--ink); }
.big.blue { color: var(--teal); text-shadow: 4px 4px 0 var(--cream), 8px 8px 0 var(--ink); }
.big.small { font-size: 40px; transform: translateY(-24vh); }
.big.count { font-size: clamp(90px, 18vw, 220px); }
.big.go { font-size: clamp(90px, 18vw, 220px); color: #7bd66b; }
@keyframes pop { 0% { opacity: 0; scale: 0.3; rotate: -12deg; } 18% { opacity: 1; scale: 1.15; rotate: 3deg; } 30% { scale: 1; rotate: -2deg; } 80% { opacity: 1; } 100% { opacity: 0; scale: 1.08; } }
#toasts { position: absolute; right: 14px; top: 110px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; max-width: min(380px, 70vw); }
.toast { background: var(--cream); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; padding: 8px 12px; font: 700 14px 'Nunito'; box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3); animation: slidein 0.3s ease-out; transition: opacity 0.4s, transform 0.4s; }
.toast b { font-weight: 900; }
.toast.out { opacity: 0; transform: translateX(30px); }
@keyframes slidein { from { opacity: 0; transform: translateX(40px); } }
#tags { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
.tag { position: absolute; left: 0; top: 0; padding: 2px 8px; border-radius: 8px; background: rgba(22, 22, 29, 0.8); border: 2px solid var(--ink); font: 900 12px 'Nunito'; white-space: nowrap; transform-origin: 50% 100%; }
.tag i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; border: 1.5px solid #000; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: none; place-items: center; padding: 16px; background: rgba(10, 15, 25, 0.45); }
.modal.on { display: grid; }
.modal .card, #results { color: var(--cream); }
#pause .card, #results.on { background: rgba(22, 22, 29, 0.92); border: 4px solid var(--ink); border-radius: 20px; padding: 22px 26px; box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.35); }
#results.on { place-items: initial; display: block; inset: auto; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; }
.modal h2 { font: 400 34px 'Bungee'; margin: 0 0 12px; color: var(--yellow); text-shadow: 3px 3px 0 var(--red); }
.modal h3 { font: 400 18px 'Bungee'; margin: 18px 0 8px; color: var(--teal); }
.modal table { width: 100%; border-collapse: collapse; font: 800 15px 'Nunito'; }
.modal td, .modal th { padding: 5px 8px; text-align: left; border-bottom: 1px solid rgba(255, 255, 255, 0.12); }
.modal th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.7; }
.modal tr.me td { color: var(--yellow); }
.modal td i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 8px; border: 2px solid #000; vertical-align: -1px; }
.modal .best { font: 800 14px 'Nunito'; opacity: 0.8; }
.modal .champ { font: 400 22px 'Bungee'; color: var(--yellow); text-align: center; }
.btns { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.btns button { font-size: 16px; padding: 10px 14px; box-shadow: 4px 4px 0 var(--ink); background: var(--cream); }
.fine { font: 700 13px 'Nunito'; opacity: 0.8; margin-top: 14px; }

@media (max-width: 720px) {
  .modes, #races { grid-template-columns: 1fr; }
  #title .card { padding: 18px 16px; }
  #miniwrap { width: 140px; height: 140px; }
  #mini { width: 140px; height: 140px; }
  #speedo { min-width: 160px; } #speedo .v { font-size: 38px; }
  #pos { font-size: 46px; }
}

/* ---------- power-ups ---------- */
#hull { position: relative; height: 14px; border: 3px solid var(--ink); border-radius: 8px; background: #333; overflow: hidden; margin-bottom: 6px; }
#hull i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #4fbf5a, #9be36b); transition: width 0.15s; }
#hull.low i { background: linear-gradient(90deg, var(--red), #ff8a2a); animation: blink 0.5s steps(2) infinite; }
#hull span { position: relative; font: 400 10px/9px 'Bungee'; color: #fff; text-shadow: 1px 1px 0 var(--ink); }
@keyframes blink { 50% { opacity: 0.5; } }
#kit { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
#kit .slots { display: flex; gap: 8px; }
#kit .slot { position: relative; width: 58px; height: 58px; border: 3px solid var(--ink); border-radius: 50%; background: rgba(22, 22, 29, 0.6); display: grid; place-items: center; box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35); }
#kit .slot.full { background: var(--cream); }
#kit .slot.wpn { border-radius: 12px; width: 76px; margin-left: 10px; }
#kit .slot.wpn.full { background: var(--yellow); }
#kit .ico { font-size: 30px; line-height: 1; }
#kit .slot b { position: absolute; left: 4px; top: 2px; font: 400 14px 'Bungee'; color: var(--ink); }
#kit .slot kbd { position: absolute; right: -6px; bottom: -6px; font-size: 11px; }
#fxchips { display: flex; gap: 6px; }
#fxchips .chip { padding: 3px 10px; border-radius: 10px; border: 2px solid var(--ink); background: var(--teal); color: var(--ink); font: 900 14px 'Nunito'; }
#fxchips .chip.bad { background: var(--red); color: #fff; }
#hurt { position: absolute; inset: 0; box-shadow: inset 0 0 140px 30px rgba(255, 40, 30, 0.75); opacity: 0; }
#hurt.on { animation: hurt 0.5s ease-out; }
@keyframes hurt { from { opacity: 1; } to { opacity: 0; } }
.tag .hpb { display: block; height: 4px; margin-top: 2px; background: #511; border-radius: 2px; overflow: hidden; }
.tag .hpb s { display: block; height: 100%; width: 100%; background: #7bd66b; }
@media (max-width: 720px) { #kit .slot { width: 44px; height: 44px; } #kit .slot.wpn { width: 56px; } #kit .ico { font-size: 22px; } #kit { bottom: 170px; } }
#hull.fire i { background: linear-gradient(90deg, #ff3b30, #ffd23f); animation: blink 0.25s steps(2) infinite; }

/* ---------- touch controls ---------- */
.touchhelp { display: none; font: 800 14px 'Nunito'; margin-bottom: 10px; line-height: 1.4; }
#touch, #rotate { display: none; }
body.touch .touchhelp { display: block; }
body.touch .keys { display: none; }
body.touch, body.touch * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.touch #game { touch-action: none; }
body.touch.ingame #touch { display: block; }
#touch { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
#stickzone { position: absolute; left: 0; bottom: 0; width: 46%; height: 72%; pointer-events: auto; touch-action: none; }
/* the stick rests bottom-left as a see-through circle; a thumb anywhere on the left half picks it up */
#stickbase { position: absolute; left: calc(max(16px, env(safe-area-inset-left)) + 76px); top: calc(100% - 96px); width: 128px; height: 128px; margin: -64px 0 0 -64px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.5); background: radial-gradient(circle, rgba(255, 255, 255, 0.10), rgba(22, 22, 29, 0.22)); opacity: 0.55; transition: opacity 0.15s, left 0.18s ease-out, top 0.18s ease-out; pointer-events: none; }
#stickbase.on { opacity: 0.95; transition: opacity 0.1s; }
#stickbase .lbl { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; font: 900 9px/1.5 'Nunito'; color: rgba(255, 255, 255, 0.85); text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.6); letter-spacing: 0.06em; }
#stickbase.on .lbl { display: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; background: rgba(255, 210, 63, 0.55); border: 3px solid rgba(22, 22, 29, 0.6); box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.25); }
#stickbase.on #knob { background: var(--yellow); border-color: var(--ink); }
#tbtns { position: absolute; right: env(safe-area-inset-right); bottom: 0; width: 300px; height: 280px; pointer-events: none; }
#tbtns .tb { position: absolute; pointer-events: auto; }
.tb { width: 62px; height: 62px; border-radius: 50%; border: 3px solid var(--ink); background: rgba(255, 248, 230, 0.88); color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35); touch-action: none; }
.tb span { font-size: 24px; line-height: 1; }
.tb small { font: 900 9px 'Nunito'; letter-spacing: 0.04em; margin-top: 2px; }
.tb.tb-big { width: 84px; height: 84px; background: var(--yellow); }
.tb.tb-big span { font-size: 32px; }
.tb.tb-small { width: 48px; height: 48px; opacity: 0.85; }
.tb.tb-small span { font-size: 18px; } .tb.tb-small small { font-size: 7px; }
.tb.down { transform: scale(0.92); background: var(--teal); box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35); }
#tbar { position: absolute; top: 74px; right: 134px; display: flex; gap: 6px; pointer-events: auto; }
#tbar button { width: 40px; height: 40px; border-radius: 12px; border: 3px solid var(--ink); background: rgba(255, 248, 230, 0.85); font-size: 18px; padding: 0; }
@media (orientation: portrait) { body.touch.ingame #rotate { display: grid; } }
#rotate { position: fixed; inset: 0; z-index: 40; place-content: center; text-align: center; background: rgba(22, 22, 29, 0.92); color: var(--cream); font: 900 18px 'Nunito'; }
#rotate div { font-size: 64px; margin-bottom: 10px; }
/* the HUD rearranges itself around the thumbs */
body.touch #miniwrap { left: auto; right: max(12px, env(safe-area-inset-right)); top: 10px; bottom: auto; width: 112px; height: 112px; }
body.touch #mini { width: 112px; height: 112px; }
body.touch #timebox { right: 134px; top: 10px; padding: 6px 10px; } body.touch #timer { font-size: 22px; }
body.touch #posbox, body.touch #freehud { top: 10px; left: max(10px, env(safe-area-inset-left)); transform: scale(0.72); transform-origin: top left; }
body.touch #dj { top: 10px; max-width: 34vw; padding: 5px 12px 7px; } body.touch #dj .say { font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
body.touch #speedo { right: auto; left: 50%; bottom: 8px; transform: translateX(-50%); min-width: 0; width: 170px; padding: 4px 10px 6px; text-align: center; }
body.touch #speedo .v { font-size: 20px; } body.touch #vname { font-size: 10px; margin: 0 0 3px; }
body.touch #hull { height: 9px; margin-bottom: 3px; border-width: 2px; } body.touch #hull span { display: none; }
body.touch #nitro { height: 11px; border-width: 2px; } body.touch #nitro span { display: none; }
body.touch #kit { bottom: 82px; }
body.touch #kit .slot { pointer-events: auto; width: 46px; height: 46px; } body.touch #kit .slot.wpn { width: 58px; } body.touch #kit .ico { font-size: 22px; }
body.touch #kit .slot kbd { display: none; }
body.touch #prompt { bottom: auto; top: 136px; font-size: 14px; padding: 6px 12px; white-space: normal; max-width: 60vw; text-align: center; }
body.touch #toasts { top: 96px; right: auto; left: max(10px, env(safe-area-inset-left)); max-width: 38vw; align-items: flex-start; }
body.touch .toast:nth-last-child(n+3) { display: none; } body.touch .toast { font-size: 12px; padding: 6px 9px; }
body.touch .big { font-size: clamp(30px, 8vw, 70px); }
@media (max-height: 420px) { body.touch #kit { bottom: 80px; } #stickbase { top: calc(100% - 84px); } body.touch .tb.tb-big { width: 72px; height: 72px; } body.touch .tb { width: 56px; height: 56px; } #stickbase { width: 112px; height: 112px; margin: -56px 0 0 -56px; } }
body.touch .keyonly { display: none; }
