:root { --bg: #0b0f17; --panel: rgba(14, 18, 28, .92); --line: #2b3346; --text: #f2efe8; --muted: #a7afbf; --hot: #ff7a1a; --gold: #ffd23f; --good: #4cd964; --bad: #ff3b30; --font: 'Cairo', 'Segoe UI', Tahoma, 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; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 14px; z-index: 10; pointer-events: none; }
#ui[hidden] { display: none; }
#ui > * { pointer-events: auto; }
button, select, input { font-family: inherit; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 18px; border-radius: 10px; border: 1px solid var(--line); background: rgba(30, 36, 50, .9); color: var(--text); font-weight: 800; font-size: 15px; cursor: pointer; text-decoration: none; transition: transform .08s, border-color .15s, background .15s; clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%); }
.btn:hover { border-color: var(--hot); background: rgba(50, 36, 26, .95); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, #ff9a3c, #d9480f); border-color: #ffc078; color: #1a0b02; }
.btn.big { font-size: 20px; padding: 14px 26px; }
.btn.ghost { background: rgba(0, 0, 0, .35); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 14px; }
.warn { color: var(--gold); }

.menu { width: min(460px, 100%); text-align: center; margin-inline-start: auto; margin-inline-end: 4vw; background: linear-gradient(180deg, rgba(10, 13, 20, .85), rgba(10, 13, 20, .65)); padding: 22px; border: 1px solid rgba(255, 122, 26, .35); border-radius: 18px; backdrop-filter: blur(4px); }
.logo .t1 { font-size: clamp(38px, 8vw, 58px); font-weight: 900; line-height: 1.05; background: linear-gradient(180deg, #ffe066, #ff7a1a 60%, #b3261e); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: 0 0 30px rgba(255, 122, 26, .25); letter-spacing: -.01em; }
.logo .t2 { font-size: 15px; letter-spacing: .4em; color: var(--muted); font-weight: 700; direction: ltr; }
.tag { color: #d6d9e0; line-height: 1.8; margin: 12px 0 16px; font-size: 15px; }
.mbtns { display: flex; flex-direction: column; gap: 8px; }
.sel-sum { margin-top: 12px; font-size: 13px; color: var(--gold); }
.sel-sum a { color: var(--gold); }
.rights { display: block; margin-top: 10px; font-size: 11px; color: var(--muted); line-height: 1.6; }

.panel { width: min(720px, 100%); max-height: calc(100vh - 28px); max-height: calc(100dvh - 28px); overflow: auto; background: var(--panel); border: 1px solid rgba(255, 122, 26, .35); border-radius: 16px; padding: 16px 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.panel.wide { width: min(1080px, 100%); }
.panel.small { width: min(440px, 100%); text-align: center; }
.panel h2 { margin: 0; font-size: 22px; color: var(--gold); }
.gtop { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.opt { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0; }
.opt select, .opt input, #oCode { background: #1b2130; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 15px; min-width: 160px; }
.opt input[type=range] { accent-color: var(--hot); }

.garage { position: absolute; inset: 0; pointer-events: none; padding: 14px; display: flex; flex-direction: column; justify-content: space-between; }
.garage > * { pointer-events: auto; }
.gnav { display: flex; justify-content: space-between; align-items: center; pointer-events: none; }
.gnav .arrow { pointer-events: auto; width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--line); background: rgba(0, 0, 0, .5); color: #fff; font-size: 36px; cursor: pointer; line-height: 1; }
.gcard { align-self: flex-start; width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: 14px; padding: 14px; }
.gcard h3 { margin: 0; font-size: 26px; }
.gcard small { color: var(--muted); }
.stats { margin: 10px 0; display: flex; flex-direction: column; gap: 6px; }
.st { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 8px; font-size: 13px; }
.bar { display: block; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #ff7a1a, #ffd23f); }
.spec { font-size: 14px; margin-bottom: 10px; }
.thumbs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.thumb { flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(14, 18, 28, .85); color: var(--text); font-weight: 700; font-size: 12px; cursor: pointer; }
.thumb i { width: 34px; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--c), var(--c2)); }
.thumb.on { border-color: var(--hot); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-bottom: 12px; }
.acard { display: flex; flex-direction: column; gap: 4px; text-align: start; padding: 0 0 10px; border-radius: 12px; border: 2px solid var(--line); background: #141a26; color: var(--text); cursor: pointer; overflow: hidden; }
.acard b, .acard small { padding: 0 10px; }
.acard small { color: var(--muted); line-height: 1.6; }
.acard.on { border-color: var(--hot); }
.aimg { height: 92px; background: linear-gradient(180deg, var(--a), var(--b)); display: flex; align-items: flex-end; padding: 8px; position: relative; }
.aimg::after { content: ''; position: absolute; inset: auto 0 0 0; height: 28px; background: repeating-linear-gradient(90deg, rgba(0, 0, 0, .55) 0 18px, rgba(0, 0, 0, .3) 18px 30px); clip-path: polygon(0 60%, 8% 20%, 14% 50%, 22% 0, 30% 40%, 40% 10%, 52% 45%, 63% 5%, 74% 35%, 86% 15%, 100% 50%, 100% 100%, 0 100%); }
.aimg span { position: relative; z-index: 1; font-weight: 900; text-shadow: 0 2px 6px #000; }
.modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin-bottom: 8px; }
.mcard { text-align: start; padding: 10px; border-radius: 12px; border: 2px solid var(--line); background: #141a26; color: var(--text); cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.mcard small { color: var(--muted); line-height: 1.6; }
.mcard.on { border-color: var(--hot); }
.howto { line-height: 1.9; padding-inline-start: 18px; }
.specs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.specs div { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; background: #141a26; border-radius: 8px; font-size: 13px; }
.loading { font-size: 20px; font-weight: 800; background: var(--panel); padding: 16px 26px; border-radius: 12px; border: 1px solid var(--hot); }
.result h2 { font-size: 30px; }
.result.win h2 { color: var(--gold); }
.result.lose h2 { color: var(--bad); }
.r-emb { font-size: 56px; }
.kv { display: flex; justify-content: space-between; padding: 6px 2px; border-bottom: 1px dashed rgba(255, 255, 255, .1); }
.board { margin: 10px 0; display: flex; flex-direction: column; gap: 4px; }
.board > div { display: flex; justify-content: space-between; padding: 6px 10px; background: #141a26; border-radius: 8px; font-size: 14px; }
.board > div.me { border: 1px solid var(--hot); }
.code { font-size: 24px; letter-spacing: .2em; direction: ltr; color: var(--gold); }

/* ---------- HUD (responsive: sizes follow the measured game area via --k / --kt) ---------- */
:root {
  --k: 1; --kt: 1; --top-h: 120px;
  --st: max(10px, env(safe-area-inset-top)); --sb: max(12px, env(safe-area-inset-bottom));
  --sl: max(12px, env(safe-area-inset-left)); --sr: max(12px, env(safe-area-inset-right));
  --edge: calc(14px * var(--k));
}
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; font-weight: 800; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); font-size: calc(14px * var(--k)); }
#hud[hidden] { display: none; }
.hud-tl { position: absolute; top: var(--st); inset-inline-start: var(--sr); width: clamp(170px, calc(300px * var(--k)), 34vw); }
[dir=ltr] .hud-tl { inset-inline-start: var(--sl); }
.car-name { font-size: calc(16px * var(--k)); color: var(--gold); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar.hp { height: clamp(14px, calc(18px * var(--k)), 20px); border-radius: 6px; position: relative; border: 1px solid rgba(255, 255, 255, .25); background: rgba(0, 0, 0, .5); }
.bar.hp > i { transition: width .15s; }
.bar.hp span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: clamp(10px, calc(12px * var(--k)), 13px); }
.meters { display: flex; gap: 8px; margin-top: 6px; }
.meter { flex: 1; min-width: 0; font-size: clamp(10px, calc(11px * var(--k)), 12px); color: var(--muted); }
.meter b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar.sm { height: 7px; }
.bar.sm > i { background: linear-gradient(90deg, #2bb5ff, #7be0ff); }
.bar.sm.sp > i { background: linear-gradient(90deg, #b14cff, #ff4cd8); }
.bar.sm.sp.ready { box-shadow: 0 0 8px #ff4cd8; }
.armor { font-size: clamp(10px, calc(12px * var(--k)), 13px); color: #cbd2e0; margin-top: 4px; }
.armor .sh { color: #7be0ff; }
.hud-tr { position: absolute; top: var(--st); inset-inline-end: var(--sl); display: flex; flex-direction: column; align-items: center; gap: 4px; }
[dir=ltr] .hud-tr { inset-inline-end: var(--sr); }
#hMini { width: clamp(88px, calc(150px * var(--k)), 170px); height: auto; aspect-ratio: 1; border-radius: 12px; border: 1px solid rgba(255, 255, 255, .25); }
.hud-tr .stats { display: flex; flex-direction: column; align-items: center; font-size: clamp(11px, calc(13px * var(--k)), 14px); margin: 0; gap: 0; }
/* weapon strip: centred at the bottom for keyboard/mouse, kept clear of the bottom edge */
.hud-bl { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--sb) + var(--edge)); display: flex; gap: calc(6px * var(--k)); flex-wrap: nowrap; justify-content: center; max-width: min(calc(100% - 2 * var(--sl)), 900px); direction: inherit; }
.wpn { display: flex; flex-direction: column; align-items: center; min-width: clamp(46px, calc(66px * var(--k)), 76px); padding: calc(5px * var(--k)) calc(8px * var(--k)); border-radius: 10px; background: rgba(0, 0, 0, .55); border: 1px solid rgba(255, 255, 255, .15); font-size: clamp(9px, calc(11px * var(--k)), 12px); }
.wpn.sel { border-color: var(--gold); background: rgba(80, 50, 10, .7); box-shadow: 0 0 10px rgba(255, 210, 63, .35); }
.wpn .wi { font-size: clamp(14px, calc(18px * var(--k)), 20px); } .wpn b { font-size: clamp(12px, calc(15px * var(--k)), 16px); color: var(--gold); }
.wpn .wn { white-space: nowrap; max-width: calc(90px * var(--k)); overflow: hidden; text-overflow: ellipsis; }
.feed { position: absolute; top: calc(var(--top-h) + 8px); inset-inline-end: var(--sl); display: flex; flex-direction: column; gap: 4px; align-items: flex-end; max-width: min(38%, 320px); }
.fi { background: rgba(0, 0, 0, .55); padding: 4px 10px; border-radius: 8px; font-size: clamp(11px, calc(13px * var(--k)), 14px); transition: opacity .5s; }
.fi.me { border: 1px solid var(--good); } .fi.bad { border: 1px solid var(--bad); }
.fi.out { opacity: 0; }
.msg { position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%) scale(.9); font-size: clamp(20px, calc(42px * var(--k)), 46px); font-weight: 900; color: #fff; opacity: 0; transition: opacity .25s, transform .25s; text-align: center; max-width: 90%; text-shadow: 0 0 20px rgba(255, 122, 26, .7), 0 2px 4px #000; }
.msg.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.reticle { position: absolute; display: none; transform: translate(-50%, -50%); }
.ret-box { width: clamp(38px, calc(54px * var(--k)), 60px); aspect-ratio: 1; border: 2px solid #ff3b30; border-radius: 6px; margin: auto; box-shadow: 0 0 10px rgba(255, 59, 48, .6); animation: ret 1s infinite; }
@keyframes ret { 50% { transform: scale(.88); } }
.ret-info { text-align: center; font-size: 12px; margin-top: 4px; }
.bar.xs { height: 5px; width: 70px; margin: 2px auto 0; }
.bar.xs > i { background: #ff3b30; }
.vignette { position: absolute; inset: 0; box-shadow: inset 0 0 120px rgba(255, 0, 0, 0); }
.vignette.on { animation: vig .5s; }
@keyframes vig { 0% { box-shadow: inset 0 0 140px rgba(255, 30, 0, .65); } 100% { box-shadow: inset 0 0 140px rgba(255, 30, 0, 0); } }
.scoreboard { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); min-width: min(260px, 90%); background: var(--panel); border: 1px solid var(--hot); border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; }
.scoreboard[hidden] { display: none; }
.scoreboard > div { display: flex; justify-content: space-between; gap: 20px; }
.scoreboard .me { color: var(--gold); }
.bar.hp span, #hTime, .ret-info { direction: ltr; unicode-bidi: isolate; }

/* ---------- touch controls: shown only while playing and only when touch is the active input ---------- */
#touch { position: fixed; inset: 0; z-index: 6; pointer-events: none; display: none; --bt: clamp(46px, calc(60px * var(--kt)), 78px); --gap: clamp(6px, calc(10px * var(--kt)), 14px); }
html[data-input=touch] body.playing #touch { display: block; }
#stick { position: absolute; left: calc(var(--sl) + 6px); bottom: calc(var(--sb) + 8px); width: clamp(104px, calc(150px * var(--kt)), 190px); aspect-ratio: 1; border-radius: 50%; background: rgba(255, 255, 255, .08); border: 2px solid rgba(255, 255, 255, .25); pointer-events: auto; touch-action: none; }
.knob { position: absolute; left: 50%; top: 50%; width: 42%; aspect-ratio: 1; transform-origin: center; translate: -50% -50%; border-radius: 50%; background: rgba(255, 122, 26, .7); border: 2px solid #ffc078; }
.tbtns { position: absolute; right: calc(var(--sr) + 6px); bottom: calc(var(--sb) + 8px); display: grid; grid-template-columns: repeat(3, var(--bt)); grid-template-areas: "sw sp tu" "hb br fire"; gap: var(--gap); pointer-events: auto; direction: ltr; align-items: end; }
.tb { width: var(--bt); aspect-ratio: 1; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .35); background: rgba(0, 0, 0, .45); color: #fff; font-size: calc(var(--bt) * .38); touch-action: none; padding: 0; line-height: 1; }
.tb.on { background: rgba(255, 122, 26, .7); }
.tb.fire { grid-area: fire; width: calc(var(--bt) * 1.18); margin: calc(var(--bt) * -.18) 0 0 calc(var(--bt) * -.18); background: rgba(200, 40, 30, .6); }
.tb.sp { grid-area: sp; background: rgba(150, 60, 220, .5); }
.tb.tu { grid-area: tu; } .tb.br { grid-area: br; } .tb.hb { grid-area: hb; } .tb.sw { grid-area: sw; }
.tb.pz { position: absolute; top: calc(var(--top-h) + 6px); inset-inline-end: var(--sl); width: clamp(36px, calc(44px * var(--kt)), 50px); font-size: 16px; pointer-events: auto; }
/* touch layout: weapons move to the top (below the status row) so nothing sits under the thumbs */
html[data-input=touch] .hud-bl { bottom: auto; top: calc(var(--top-h) + 6px); max-width: calc(100% - 2 * (var(--sl) + 56px)); flex-wrap: wrap; }
html[data-input=touch] .wpn .wn { display: none; }
html[data-input=touch] .wpn { min-width: clamp(40px, calc(52px * var(--kt)), 60px); padding: 3px 6px; }
html[data-input=touch] .feed { top: calc(var(--top-h) + 64px); }
/* touch landscape: the weapon strip sits in the free space between the stick and the action buttons */
html[data-input=touch][data-orient=land] .hud-bl { top: auto; bottom: calc(var(--sb) + 8px); max-width: calc(100% - 2 * var(--side-w, 220px)); }
html[data-input=touch][data-orient=land] .feed { top: calc(var(--top-h) + 8px); }
html[data-input=touch] .msg { top: 38%; }
/* portrait: compact top row, the controls keep the bottom of the screen */
html[data-orient=port] .hud-tl { width: min(52vw, 260px); }
html[data-orient=port] #hMini { width: clamp(80px, 26vw, 120px); }
html[data-orient=port][data-input=touch] .feed { display: none; }
.rotate-hint { display: none; }
html[data-orient=port][data-input=touch] body.playing .rotate-hint { display: block; position: fixed; left: 50%; top: 48%; transform: translate(-50%, -50%); z-index: 4; padding: 6px 12px; border-radius: 10px; background: rgba(0, 0, 0, .55); font-size: 13px; pointer-events: none; animation: hintfade 4s forwards; }
@keyframes hintfade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
/* very short screens (phone landscape, zoomed browsers) */
html[data-short='1'] .meters, html[data-short='1'] .armor { display: none; }
html[data-short='1'] #touch { --bt: clamp(40px, calc(52px * var(--kt)), 60px); }
html[data-short='1'] #stick { width: clamp(92px, 30vh, 140px); }
/* ultrawide: keep the HUD inside a centred 16:9-ish column instead of stretching to the far edges */
html[data-size=ultrawide] .hud-tl { inset-inline-start: max(var(--sl), calc((100% - 2.1 * var(--gh)) / 2)); }
html[data-size=ultrawide] .hud-tr, html[data-size=ultrawide] .feed { inset-inline-end: max(var(--sl), calc((100% - 2.1 * var(--gh)) / 2)); }
@media (max-height: 760px) { .logo .t1 { font-size: 40px; } .tag { margin: 6px 0 10px; font-size: 14px; } .btn { padding: 8px 16px; } .btn.big { padding: 10px 22px; font-size: 18px; } .mbtns { gap: 6px; } }
@media (max-width: 760px), (max-height: 520px) { .menu { margin: auto; } }
.menu { max-height: calc(100vh - 28px); max-height: calc(100dvh - 28px); overflow-y: auto; }
