:root {
  --red: #d62828; --blue: #1f6fd1; --gold: #ffd23f; --cream: #fff8e7; --ink: #1d1410;
  --panel: rgba(22, 18, 32, 0.72);
  --display: 'Luckiest Guy', 'Arial Black', Impact, sans-serif;
  --ui: 'Lilita One', 'Arial Black', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fd0f0; color: var(--cream); font-family: var(--ui); user-select: none; -webkit-user-select: none; touch-action: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px 16px; text-align: center; z-index: 10; }
.screen.on { display: flex; }
.screen.dim { background: rgba(10, 6, 20, 0.55); backdrop-filter: blur(3px); }
#loading { background: radial-gradient(circle at 50% 40%, #ffcf5a, #e8641e 55%, #8a1d12); }
.loading-bar { width: min(320px, 70vw); height: 14px; border-radius: 99px; background: rgba(0, 0, 0, 0.3); overflow: hidden; border: 3px solid #fff; }
.loading-bar i { display: block; height: 100%; width: 10%; background: var(--gold); transition: width 0.3s; }
.loading-text { font-size: 18px; text-shadow: 0 2px 0 rgba(0,0,0,0.3); margin: 0; }

h2 { font-family: var(--display); font-size: clamp(26px, 4.5vw, 46px); margin: 0; letter-spacing: 1px; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink); }

.logo { display: flex; flex-direction: column; align-items: center; line-height: 0.85; transform: rotate(-4deg); filter: drop-shadow(0 8px 0 rgba(0,0,0,0.25)); }
.logo span { font-family: var(--display); -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; }
.logo-top { font-size: clamp(54px, 11vw, 128px); color: var(--gold); text-shadow: 0 6px 0 #b8450f; }
.logo-bottom { font-size: clamp(64px, 13vw, 152px); color: var(--red); text-shadow: 0 6px 0 #6e0f0f; margin-top: -6px; }
.logo.small .logo-top { font-size: 64px; } .logo.small .logo-bottom { font-size: 74px; }
.tagline { margin: 0; font-size: clamp(16px, 2.4vw, 22px); color: #fff; text-shadow: 0 2px 0 var(--ink), 0 0 12px rgba(0,0,0,0.4); }
.press { margin: 0; font-size: 16px; color: #fff; text-shadow: 0 2px 0 var(--ink); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: 0.45; } }

.menu { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.menu.row, .row { flex-direction: row; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn { font-family: var(--ui); font-size: 22px; color: #fff; background: var(--blue); border: 4px solid #fff; border-radius: 16px; padding: 10px 26px; cursor: pointer; box-shadow: 0 5px 0 var(--ink); transition: transform 0.08s, background 0.15s; text-shadow: 0 2px 0 rgba(0,0,0,0.35); min-width: 200px; }
.btn.primary { background: var(--red); font-size: 28px; }
.btn.small { font-size: 17px; padding: 7px 16px; min-width: 0; }
.btn.ghost { background: rgba(0,0,0,0.35); }
a.btn { text-decoration: none; display: inline-block; }
.btn:hover, .btn:focus-visible, .btn.focus { transform: translateY(-2px) scale(1.04); outline: none; background: #ff8a1a; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.controls-card { background: var(--panel); border: 3px solid #fff; border-radius: 16px; padding: 14px 20px; text-align: left; font-family: system-ui, sans-serif; font-size: 14px; display: grid; gap: 4px; }
.controls-card[hidden] { display: none; }
.controls-card b { font-family: var(--ui); font-weight: normal; color: var(--gold); margin-right: 6px; }

/* ---------- character select ---------- */
#select { justify-content: flex-end; padding-bottom: 5vh; background: linear-gradient(transparent 55%, rgba(10,6,20,0.55)); }
#select h2 { position: absolute; top: 4vh; left: 0; right: 0; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 200px)); gap: 10px; justify-content: center; }
.card { background: var(--panel); border: 3px solid rgba(255,255,255,0.45); border-radius: 16px; padding: 8px 12px; text-align: left; cursor: pointer; transition: transform 0.12s, border-color 0.12s; display: flex; gap: 10px; align-items: center; }
#course { background: linear-gradient(rgba(10,6,20,0.25), rgba(10,6,20,0.6)); gap: 18px; }
.courses { display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
.course-card { width: 300px; background: var(--panel); border: 4px solid rgba(255,255,255,0.5); border-radius: 20px; padding: 12px 14px 14px; color: #fff; cursor: pointer; text-align: center; transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s; font: inherit; }
.course-card canvas { width: 100%; height: auto; display: block; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #2a8fc4, #12507a); }
.course-card[data-id="neon"] canvas { background: radial-gradient(circle at 50% 40%, #3a1460, #0b0620); }
.course-card h3 { margin: 10px 0 2px; font-family: var(--display); font-weight: normal; font-size: 25px; letter-spacing: 0.5px; }
.course-card p { margin: 0; font-size: 13px; opacity: 0.85; font-family: system-ui, sans-serif; }
.course-card.on, .course-card:hover { border-color: var(--gold); transform: translateY(-5px) scale(1.04); box-shadow: 0 0 0 5px rgba(255,210,63,0.35), 0 7px 0 var(--ink); }
.course-card[data-id="neon"].on, .course-card[data-id="neon"]:hover { border-color: #ff3cd6; box-shadow: 0 0 0 5px rgba(255,60,214,0.35), 0 0 30px rgba(80,255,255,0.45), 0 7px 0 var(--ink); }
@media (max-height: 520px) { .course-card { width: 230px; padding: 8px; } .course-card h3 { font-size: 19px; margin-top: 6px; } .course-card p { display: none; } #course h2 { font-size: 22px; } }
.card .swatch { flex: none; width: 14px; align-self: stretch; border-radius: 8px; border: 2px solid rgba(255,255,255,0.7); }
.card .info { flex: 1; min-width: 0; }
.card.on { border-color: var(--gold); transform: translateY(-4px) scale(1.04); box-shadow: 0 0 0 4px rgba(255,210,63,0.35), 0 6px 0 var(--ink); }
.card h3 { margin: 0; font-family: var(--display); font-size: 21px; font-weight: normal; letter-spacing: 0.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .role { font-size: 12px; opacity: 0.85; margin: 1px 0 4px; font-family: system-ui, sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 6px; font-size: 11px; margin: 2px 0; }
.stat i { display: block; height: 9px; border-radius: 9px; background: rgba(255,255,255,0.15); overflow: hidden; }
.stat i b { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), #ff7a1a); border-radius: 9px; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 5; font-family: var(--ui); }
.hud.on { display: block; }
.hud-top-left { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 16px; }
.place { display: inline-flex; align-items: baseline; gap: 4px; background: rgba(20, 16, 30, 0.6); border: 3px solid rgba(255,255,255,0.85); border-radius: 18px; padding: 2px 16px 6px; }
.place-n { font-family: var(--display); font-size: 64px; line-height: 1; color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
.place[data-p="1"] .place-n { color: var(--gold); } .place[data-p="2"] .place-n { color: #dfe6ef; } .place[data-p="3"] .place-n { color: #f0a96a; }
.place-s { font-family: var(--display); font-size: 26px; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
.place-of { font-size: 22px; opacity: 0.85; margin-left: 6px; }
.place.pop { animation: pop 0.35s; }
@keyframes pop { 40% { transform: scale(1.18); } }
.slots { display: flex; gap: 10px; margin-top: 10px; }
.slot { width: 74px; height: 74px; border-radius: 18px; border: 4px solid rgba(255,255,255,0.8); background: rgba(20,16,30,0.55); display: grid; place-items: center; font-size: 42px; position: relative; }
.slot.s1 { width: 58px; height: 58px; font-size: 32px; opacity: 0.85; }
.slot.full { border-color: #8be0ff; box-shadow: 0 0 14px rgba(120,210,255,0.8); background: rgba(30,60,110,0.6); }
.slot.rolling { border-color: var(--gold); }
.slot i { position: absolute; right: 4px; bottom: 0; font-size: 16px; font-style: normal; color: #fff; -webkit-text-stroke: 1px var(--ink); }
.hud-top-right { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 16px; text-align: right; }
.lap { display: inline-block; background: rgba(20,16,30,0.6); border: 3px solid rgba(255,255,255,0.85); border-radius: 18px; padding: 4px 18px; font-size: 26px; }
.lap b { font-family: var(--display); font-size: 48px; font-weight: normal; color: #6fd6ff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; margin: 0 4px; }
.timer { font-size: 22px; margin-top: 6px; text-shadow: 0 2px 0 var(--ink); }
.laptimes { font-size: 14px; opacity: 0.85; text-shadow: 0 1px 0 var(--ink); }
.hud-bottom-left { position: absolute; left: 16px; bottom: max(16px, env(safe-area-inset-bottom)); }
.coins { display: flex; align-items: center; gap: 6px; background: rgba(20,16,30,0.6); border: 3px solid rgba(255,255,255,0.85); border-radius: 16px; padding: 4px 14px; font-size: 22px; }
.coin-icon { width: 30px; height: 18px; background: radial-gradient(circle at 50% 100%, #ffd27a 0 40%, #e39a2c 41% 70%, transparent 71%); border-radius: 30px 30px 4px 4px; border-bottom: 3px solid #b8650f; }
.coin-n { font-family: var(--display); font-size: 30px; font-weight: normal; color: var(--gold); -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; }
.minimap { position: absolute; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); width: min(220px, 30vw); height: auto; aspect-ratio: 1; filter: drop-shadow(0 3px 0 rgba(0,0,0,0.3)); }
.banner { position: absolute; top: 26%; left: 0; right: 0; text-align: center; font-family: var(--display); font-size: clamp(42px, 9vw, 110px); color: #fff; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink); opacity: 0; transform: scale(0.6); transition: opacity 0.2s, transform 0.25s cubic-bezier(.2,1.6,.4,1); }
.banner.show { opacity: 1; transform: scale(1); }
.banner.count { font-size: clamp(90px, 18vw, 220px); color: var(--gold); }
.banner.go { color: #6fe36f; font-size: clamp(70px, 14vw, 170px); }
.banner.final { color: #ff5a5a; } .banner.secret { color: #d89cff; } .banner.finish { color: var(--gold); }
.banner.title { font-size: clamp(34px, 6vw, 72px); color: var(--gold); top: 12%; }
.sub-banner { position: absolute; top: calc(26% + clamp(60px, 11vw, 130px)); left: 0; right: 0; text-align: center; font-size: clamp(18px, 2.6vw, 28px); color: #fff; text-shadow: 0 3px 0 var(--ink); opacity: 0; transition: opacity 0.25s; }
.sub-banner.show { opacity: 1; }
.wrongway { position: absolute; top: 44%; left: 50%; transform: translateX(-50%); background: var(--red); border: 4px solid #fff; border-radius: 16px; padding: 8px 22px; font-size: 28px; opacity: 0; transition: opacity 0.2s; }
.wrongway.show { opacity: 1; animation: blink 0.6s infinite; }
.speedlines { position: absolute; inset: 0; width: 100%; height: 100%; }
.splat { position: absolute; inset: 0; width: 100%; height: 100%; }
.hitflash { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(255,255,255,0.75) 80%, rgba(255,60,40,0.85) 100%); }
.hitflash.on { animation: hitflash 0.45s ease-out; }
@keyframes hitflash { 0% { opacity: 1; } 30% { opacity: 0.8; background: radial-gradient(ellipse at center, transparent 40%, rgba(255,70,50,0.55) 85%, rgba(200,20,20,0.85) 100%); } 100% { opacity: 0; } }

/* results */
.standings { list-style: none; padding: 0; margin: 0; width: min(520px, 92vw); display: grid; gap: 6px; counter-reset: pos; }
.standings li { counter-increment: pos; display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; background: var(--panel); border: 3px solid rgba(255,255,255,0.35); border-radius: 14px; padding: 6px 14px; font-size: 20px; text-align: left; }
.standings li::before { content: counter(pos); font-family: var(--display); font-size: 30px; color: #fff; -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; }
.standings li:nth-child(1)::before { color: var(--gold); }
.standings li.me { border-color: var(--gold); background: rgba(198, 40, 40, 0.75); }
.standings .dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-right: 8px; border: 2px solid #fff; vertical-align: -1px; }
.standings small { opacity: 0.8; font-size: 15px; }

/* touch: shown only while racing on a touch device */
.touch-ui { position: fixed; inset: 0; display: none; z-index: 6; pointer-events: none; }
body.touch.racing .touch-ui { display: block; }
.touch-steer-zone { position: absolute; left: 0; top: 22%; bottom: 0; width: 45%; pointer-events: auto; }
.touch-base { position: absolute; width: 150px; height: 74px; border-radius: 40px; transform: translate(-50%, -50%); background: rgba(255,255,255,0.14); border: 3px solid rgba(255,255,255,0.55); opacity: 0; transition: opacity 0.12s; }
.touch-base.on { opacity: 1; }
.touch-base::before, .touch-base::after { content: '◀'; position: absolute; top: 50%; left: 10px; transform: translateY(-50%); color: rgba(255,255,255,0.6); font-size: 14px; }
.touch-base::after { content: '▶'; left: auto; right: 10px; }
.touch-knob { position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; border-radius: 50%; transform: translate(-50%, -50%); background: rgba(255,255,255,0.85); box-shadow: 0 3px 0 rgba(0,0,0,0.3); }
.touch-right { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); width: 220px; height: 210px; pointer-events: none; }
.touch-right button { position: absolute; pointer-events: auto; border-radius: 50%; border: 3px solid rgba(255,255,255,0.9); color: #fff; font-family: var(--ui); text-shadow: 0 2px 0 rgba(0,0,0,0.4); box-shadow: 0 4px 0 rgba(0,0,0,0.35); -webkit-tap-highlight-color: transparent; }
.touch-right button.down { transform: translateY(3px) scale(0.95); box-shadow: 0 1px 0 rgba(0,0,0,0.35); filter: brightness(1.2); }
.t-drift { right: 0; bottom: 0; width: 112px; height: 112px; font-size: 22px; background: rgba(31,111,209,0.82); }
.t-item { right: 118px; bottom: 54px; width: 84px; height: 84px; background: rgba(214,40,40,0.8); display: grid; place-items: center; line-height: 1; }
.t-item span { font-size: 30px; } .t-item small { font-size: 11px; margin-top: -8px; }
.t-brake { right: 30px; bottom: 124px; width: 66px; height: 66px; font-size: 13px; background: rgba(40,30,50,0.7); }
.t-pause { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); pointer-events: auto; width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.8); background: rgba(20,16,30,0.55); color: #fff; font-size: 14px; }
/* Make room for the thumbs: the minimap and coins move up out of the way. */
body.touch .minimap { bottom: auto; top: 96px; right: 12px; width: min(150px, 22vh); }
body.touch .hud-bottom-left { bottom: auto; top: 180px; }
.ios-tip { max-width: 520px; margin: 0; font-size: 14px; background: var(--panel); border: 2px solid #fff; border-radius: 14px; padding: 10px 14px; font-family: system-ui, sans-serif; }
.rotate-hint { display: none; position: fixed; inset: 0; z-index: 30; background: rgba(10,6,20,0.88); color: #fff; flex-direction: column; align-items: center; justify-content: center; text-align: center; font-size: 20px; gap: 8px; }
.rotate-hint div { font-size: 64px; }
@media (orientation: portrait) and (max-width: 820px) { body.touch.racing .rotate-hint { display: flex; } }

/* Phones held sideways: compact HUD so the road stays visible. */
@media (max-height: 520px) {
  .place { padding: 0 10px 3px; border-width: 2px; }
  .place-n { font-size: 38px; } .place-s { font-size: 18px; } .place-of { font-size: 16px; }
  .slots { margin-top: 6px; gap: 6px; }
  .slot { width: 48px; height: 48px; font-size: 26px; border-width: 3px; border-radius: 12px; }
  .slot.s1 { width: 38px; height: 38px; font-size: 20px; }
  .lap { font-size: 15px; padding: 2px 12px; border-width: 2px; } .lap b { font-size: 28px; }
  .timer { font-size: 15px; } .laptimes { display: none; }
  .coins { font-size: 16px; padding: 2px 10px; border-width: 2px; } .coin-n { font-size: 22px; }
  .minimap { width: 24vh; }
  .banner { top: 18%; }
  .card .stat { display: none; } .card h3 { font-size: 17px; }
  body.touch .hud-bottom-left { top: 128px; } body.touch .minimap { top: 70px; }
  #select h2 { font-size: 22px; top: 2vh; }
}
@media (max-width: 700px) {
  .place-n { font-size: 46px; } .slot { width: 58px; height: 58px; font-size: 32px; }
  .lap { font-size: 18px; } .lap b { font-size: 34px; }
  .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; width: 100%; }
  .card { padding: 6px; } .card h3 { font-size: 15px; } .card .role, .card .stat { display: none; }
  .minimap { bottom: 180px; }
}

/* Keep thumb targets visible, separated, and clear of Android gesture edges. */
.mobile-help{display:none;max-width:540px;margin:0;font:14px/1.4 system-ui,sans-serif;background:var(--panel);padding:10px 14px;border-radius:12px}
.portrait-pause{display:none;font:16px/1.4 system-ui,sans-serif}@media(orientation:portrait){body.touch .portrait-pause{display:block}}
body.touch .mobile-help{display:block}body.touch .press{display:none}
html,body{touch-action:manipulation}
#game{touch-action:none}
.screen{overflow-y:auto;overscroll-behavior:contain;touch-action:pan-y;justify-content:safe center}
.card{min-height:48px}
@media(orientation:portrait) and (max-width:700px){.cards{grid-template-columns:repeat(2,minmax(0,1fr))}}
.touch-ui button,.touch-steer-zone{touch-action:none}
.touch-steer-zone{left:max(16px,env(safe-area-inset-left));bottom:max(24px,env(safe-area-inset-bottom));width:42%}
.touch-base{left:100px;top:calc(100% - 80px);opacity:.65}
.touch-base.on{opacity:1}
.steer-label{position:absolute;bottom:12px;left:24px;font-size:13px;text-shadow:0 2px 3px #000}
.touch-right{right:max(24px,env(safe-area-inset-right));bottom:max(24px,env(safe-area-inset-bottom));height:190px;width:214px}
.t-drift{width:96px;height:96px}
.t-item{right:110px;bottom:20px;width:88px;height:88px}
.t-brake{right:18px;bottom:112px;width:72px;height:72px}
.t-pause{width:48px;height:48px}
.touch-tip{position:absolute;bottom:max(8px,env(safe-area-inset-bottom));left:50%;transform:translateX(-50%);font-size:11px;text-shadow:0 2px 3px #000;white-space:nowrap}
@media(max-height:520px){
  .screen{gap:10px;padding:12px max(20px,env(safe-area-inset-right))}
  #title .logo-top{font-size:48px}#title .logo-bottom{font-size:56px}
  #title .tagline{font-size:15px}.btn.primary{font-size:21px;padding:7px 20px}
  .btn.small{min-height:44px;font-size:14px;padding:7px 12px}
  .mobile-help{font-size:12px;padding:6px 12px}.menu,.menu .row{gap:7px}
  #pause .menu{gap:8px}#pause .btn{font-size:17px;padding:7px 20px}
  #select .cards{gap:6px}#select .card{min-height:44px;padding:6px 10px}
  #select .card h3{font-size:15px}#select .card .role{display:none}
  #select .btn.primary{font-size:18px;padding:6px 20px}
  body.touch .hud-top-left{left:max(16px,env(safe-area-inset-left))}
  body.touch .hud-top-right{right:max(16px,env(safe-area-inset-right))}
}
@media(max-height:370px){.touch-right{transform:scale(.88);transform-origin:bottom right}.touch-base{top:calc(100% - 65px)}.mobile-help{display:none!important}}
