:root {
  color-scheme: dark;
  --bg: #11151c; --panel: rgba(14, 18, 26, 0.72); --panel2: rgba(24, 30, 42, 0.92); --line: rgba(255, 255, 255, 0.1);
  --text: #eef2f7; --muted: #9aa6b8; --accent: #ff8a3d; --accent2: #ffd23f; --good: #3ddc84; --bad: #ff5a5a; --blue: #4fc3f7;
  --r: 14px; --display: "Saira Semi Condensed", "Arial Narrow", system-ui, sans-serif; --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
button { font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; cursor: pointer; transition: background .15s, transform .08s; }
button:hover { background: rgba(255, 255, 255, 0.15); } button:active { transform: scale(0.97); }
button.primary { background: var(--accent); border-color: transparent; color: #1b1004; font-weight: 700; }
button.primary:hover { background: #ffa05e; }
button.danger { background: rgba(255, 90, 90, 0.18); border-color: rgba(255, 90, 90, 0.4); }
button:disabled { opacity: .45; cursor: not-allowed; }
.iconbtn { width: 40px; height: 40px; padding: 0; border-radius: 12px; font-size: 18px; }
input, select { font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
select option { background: #1b2130; }
input[type=range] { padding: 0; accent-color: var(--accent); }
code, kbd { font-family: ui-monospace, Menlo, Consolas, monospace; background: rgba(255, 255, 255, 0.1); border-radius: 5px; padding: 1px 6px; font-size: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; backdrop-filter: blur(8px); white-space: nowrap; }
.money { color: var(--good); font-weight: 800; font-variant-numeric: tabular-nums; }
.row { display: flex; flex-wrap: wrap; align-items: center; } .gap { gap: 8px; } .center { justify-content: center; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #hud input { pointer-events: auto; }
#topLeft { position: absolute; left: 14px; top: 14px; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, 60vw); }
#obj { padding: 10px 14px; }
#objTitle { font-weight: 800; color: var(--accent2); font-size: 14px; letter-spacing: .02em; }
#objText { font-size: 13px; margin-top: 3px; line-height: 1.35; }
#objRow { display: flex; gap: 12px; margin-top: 6px; font-size: 13px; font-variant-numeric: tabular-nums; }
#objTimer { font-weight: 800; } #objTimer.low { color: var(--bad); }
#where { align-self: flex-start; font-size: 12px; color: var(--muted); }
#topRight { position: absolute; right: 14px; top: 14px; display: flex; gap: 8px; align-items: center; }
#money { font-size: 16px; padding: 7px 14px; }
#money.flash { animation: flash .6s; }
@keyframes flash { 0% { transform: scale(1.25); } 100% { transform: scale(1); } }
#fps { position: absolute; right: 14px; top: 62px; font-size: 11px; }
#toasts { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.toast { background: var(--panel2); border: 1px solid var(--line); padding: 8px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; animation: tin .25s ease-out; }
.toast.good { border-color: rgba(61, 220, 132, .5); color: var(--good); } .toast.bad { border-color: rgba(255, 90, 90, .5); color: #ff8f8f; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }
#big { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%); font-size: 110px; font-weight: 900; color: #fff; text-shadow: 0 6px 30px rgba(0, 0, 0, .6); opacity: 0; }
#big.show { animation: bigpop 1s ease-out; }
@keyframes bigpop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.8); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; } }
#arrow { position: absolute; left: 50%; top: 84px; transform: translateX(-50%); text-align: center; }
#arrowIcon { font-size: 30px; color: var(--accent2); text-shadow: 0 2px 8px rgba(0,0,0,.6); transition: transform .1s linear; }
#arrowDist { font-size: 12px; font-weight: 700; text-shadow: 0 1px 4px #000; }
#prompt { position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--accent); padding: 9px 18px; border-radius: 999px; font-weight: 600; font-size: 14px; }
#parkMeter { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); width: 230px; padding: 10px 14px; }
.pm-row { display: flex; justify-content: space-between; font-size: 13px; } .pm-row b { font-size: 18px; }
.pm-dots { display: flex; gap: 6px; margin: 6px 0; } .pm-dots i { flex: 1; height: 6px; border-radius: 3px; background: rgba(255,255,255,.15); } .pm-dots i.on { background: var(--good); }
#pmInfo { font-size: 11px; color: var(--muted); margin-top: 5px; }
.bar { height: 7px; background: rgba(255, 255, 255, .12); border-radius: 4px; overflow: hidden; flex: 1; }
.bar > div { height: 100%; width: 0; background: var(--good); border-radius: 4px; transition: width .15s; }
.bar.dmg > div { background: var(--bad); }
#chat { position: absolute; left: 14px; bottom: 210px; width: min(360px, 70vw); display: flex; flex-direction: column; gap: 6px; }
#chatLog { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
#chatLog div { background: rgba(0,0,0,.45); padding: 4px 9px; border-radius: 8px; align-self: flex-start; transition: opacity 1s; }
#chatLog b { color: var(--blue); } #chatLog .sys { color: var(--muted); font-style: italic; }
#chatInput { pointer-events: auto; width: 100%; }
#minimap { position: absolute; left: 14px; bottom: 14px; width: 180px; height: 180px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); box-shadow: 0 6px 24px rgba(0,0,0,.4); background: #1c232b; }
#dash { position: absolute; right: 14px; bottom: 10px; display: flex; flex-direction: column; align-items: center; }
#speedo { width: 200px; height: 200px; }
#bars { width: 190px; margin-top: -8px; display: flex; flex-direction: column; gap: 5px; }
.barrow { display: flex; align-items: center; gap: 7px; font-size: 13px; }
#signals { display: flex; justify-content: space-between; font-size: 14px; color: rgba(255,255,255,.25); padding: 2px 8px; }
#signals .on { color: var(--good); } #signals #sigHead.on { color: var(--blue); } #signals #sigHb.on { color: var(--bad); }

/* ---------- Touch ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; }
#touch .tb { pointer-events: auto; background: rgba(20, 25, 34, 0.55); border: 1px solid rgba(255,255,255,.18); color: #fff; border-radius: 16px; font-weight: 800; touch-action: none; backdrop-filter: blur(4px); }
#touch .tb.on { background: rgba(255, 138, 61, 0.55); }
#tLeft { position: absolute; left: calc(14px + env(safe-area-inset-left)); bottom: 18px; }
#tSteerBtns { display: flex; gap: 12px; }
#tSteerBtns .tb { width: 88px; height: 88px; font-size: 32px; }
#tWheel { width: 170px; height: 170px; border-radius: 50%; border: 10px solid rgba(255,255,255,.35); pointer-events: auto; touch-action: none; position: relative; background: rgba(20,25,34,.3); }
#tWheelInner { position: absolute; inset: 0; } #tWheelInner span { position: absolute; left: 50%; top: -6px; width: 14px; height: 30px; margin-left: -7px; background: var(--accent); border-radius: 6px; }
#tRight { position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: 18px; display: flex; align-items: flex-end; gap: 10px; }
#tRight .pedal { width: 78px; height: 120px; font-size: 13px; }
#tRight .gas { height: 150px; background: rgba(61, 220, 132, .3); }
#tRight .brake { background: rgba(255, 90, 90, .3); }
#tHand { width: 64px; height: 64px; font-size: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
#tHand small { font-size: 9px; margin-top: 3px; }
#tTop { position: absolute; right: calc(10px + env(safe-area-inset-right)); top: 64px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 250px; }
#tTop .tb.s { width: 44px; height: 44px; font-size: 18px; padding: 0; border-radius: 12px; }
body.touch #minimap { width: 120px; height: 120px; left: 12px; bottom: auto; top: 118px; }
body.touch #topLeft { max-width: 50vw; }
body.touch #dash { right: auto; left: 50%; bottom: auto; top: 6px; transform: translateX(-50%) scale(.52); transform-origin: top center; }
body.touch #toasts { top: 150px; }
body.touch #arrow { top: 128px; }
body.touch #big { top: 45%; }
body.touch #chat { bottom: auto; top: 250px; width: 50vw; }
body.touch #parkMeter { bottom: 170px; }
body.touch #prompt { bottom: 190px; }
body.touch #where { display: none; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(8, 11, 16, 0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); padding: 16px; z-index: 10; }
.titlecard { text-align: center; max-width: 520px; }
.logo { font-weight: 900; font-size: 58px; letter-spacing: .04em; line-height: .95; }
.logo span { color: #fff; } .logo em { font-style: normal; color: var(--accent); margin-left: .25em; }
.logo.sm { font-size: 20px; }
.tag { color: var(--muted); margin: 10px 0 26px; font-size: 17px; }
#btnPlay { font-size: 20px; padding: 14px 54px; border-radius: 14px; }
#loadMsg { margin-top: 12px; min-height: 20px; }
.menucard { width: min(980px, 100%); height: min(700px, 100%); background: var(--panel2); border: 1px solid var(--line); border-radius: 20px; display: flex; flex-direction: column; overflow: hidden; }
.menuhead { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { background: transparent; border-color: transparent; color: var(--muted); padding: 8px 12px; }
.tabs button.active { color: var(--text); background: rgba(255,255,255,.1); }
.menubody { flex: 1; overflow-y: auto; padding: 16px 18px 26px; touch-action: pan-y; user-select: text; }
.menubody section { display: none; } .menubody section.active { display: block; }
h3 { margin: 22px 0 10px; font-size: 15px; letter-spacing: .03em; color: var(--accent2); text-transform: uppercase; }
h4 { margin: 0 0 6px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.card { background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.card b { font-size: 15px; } .card span { font-size: 12px; } .card button { margin-top: auto; }
.stars { color: var(--accent2); letter-spacing: 2px; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin: 10px 0 16px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; }
.status { font-weight: 700; } .plist { padding-left: 18px; margin: 4px 0; } .plist li { margin: 3px 0; }
.help { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; } .help p { line-height: 1.9; margin: 0; font-size: 14px; }
.resultcard { background: var(--panel2); border: 1px solid var(--line); border-radius: 20px; padding: 26px 30px; min-width: min(380px, 100%); text-align: center; }
.resultcard h2 { margin: 0 0 12px; font-size: 30px; } #resLines div { color: var(--muted); margin: 4px 0; }
.money.big { font-size: 28px; margin: 14px 0 18px; }
/* garage */
.garage { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.sw { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); padding: 0; }
.sw.sel { outline: 3px solid var(--accent); outline-offset: 2px; }
.opt { display: flex; flex-wrap: wrap; gap: 6px; } .opt button.sel { background: var(--accent); color: #1b1004; font-weight: 700; }
.upg { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.pips { color: var(--accent2); letter-spacing: 2px; }
.carlist { display: flex; flex-direction: column; gap: 8px; }
.carrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px; border-radius: 12px; background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.carrow.cur { border-color: var(--accent); }
.stat { display: grid; grid-template-columns: 80px 1fr; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.stat .bar > div { background: var(--blue); }
.notice { background: rgba(255,138,61,.12); border: 1px solid rgba(255,138,61,.4); padding: 10px 12px; border-radius: 12px; margin-bottom: 12px; font-size: 14px; }
@media (max-width: 720px) {
  .garage { grid-template-columns: 1fr; }
  .logo { font-size: 42px; }
  #speedo { width: 170px; height: 170px; }
  .menucard { height: 100%; border-radius: 14px; }
  #topRight .chip#clock { display: none; }
}

/* garage showcase: menu slides to the right so the car stays visible */
#menu.showcase { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; justify-content: flex-end; }
#menu.showcase .menucard { width: min(600px, 100%); }
@media (max-width: 720px) { #menu.showcase .menucard { height: 62%; align-self: flex-end; } }

.logo, h3, #objTitle, #money, .toast, #big, .resultcard h2, .money.big { font-family: var(--display); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { #big.show, .toast, #money.flash { animation: none; } #big.show { opacity: 1; } }
