:root {
  --black: #07080b;
  --char: #14171c;
  --char2: #1d2128;
  --silver: #c9ced6;
  --white: #f4f6f8;
  --red: #e0262e;
  --red-d: #9d151b;
  --line: rgba(201, 206, 214, .22);
  --font: "Eurostile", "Bank Gothic", "DIN Alternate", "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--black); color: var(--white); font-family: var(--font); overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
body { position: fixed; inset: 0; }
body.in-run { touch-action: none; }
#stage { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--white); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }

/* ---------- screens ---------- */
#app { position: fixed; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; display: none; pointer-events: auto; }
.screen.show { display: flex; }
.panel-screen, .dim { align-items: center; justify-content: center; background: rgba(5, 6, 9, .82); padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 12px); overflow-y: auto; }
.dim { background: rgba(4, 5, 8, .78); }

/* ---------- main menu ---------- */
#screen-menu { flex-direction: column; background: linear-gradient(180deg, rgba(0, 0, 0, 0) 55%, rgba(4, 5, 7, .88) 100%); padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
.menu-layout { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; max-width: 1280px; margin: 0 auto; padding: 8px 16px 6px; }
.hero-slot { flex: 0 0 auto; height: min(66vw, 38vh); margin-top: auto; }
.menu-side { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* title */
.title { display: flex; flex-direction: column; align-items: center; margin: 0; line-height: 1; text-align: center; }
.t-main {
  font-size: min(9.4vw, 6.6vh, 68px); font-weight: 900; letter-spacing: .035em; white-space: nowrap;
  background: linear-gradient(180deg, #ffffff 0%, #dfe3e9 38%, #8b939f 52%, #e6e9ee 70%, #a4acb7 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .6)) drop-shadow(0 0 18px rgba(0, 0, 0, .55));
}
.t-sub { display: flex; align-items: center; gap: .9em; margin-top: .5em; font-size: min(4.3vw, 3vh, 24px); font-weight: 800; letter-spacing: .5em; padding-left: .5em; color: var(--white); text-shadow: 0 2px 8px rgba(0, 0, 0, .8); }
.t-sub i { display: block; width: clamp(24px, 9vw, 74px); height: 2px; background: linear-gradient(90deg, transparent, var(--red)); }
.t-sub i:last-child { transform: scaleX(-1); }
.t-main, .t-sub { opacity: 0; transform: translateY(10px); transition: opacity .7s ease, transform .7s ease; }
#screen-menu.i-title .t-main { opacity: 1; transform: none; }
#screen-menu.i-sub .t-sub { opacity: 1; transform: none; }
.menu-buttons { opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .6s ease, transform .6s ease; }
#screen-menu.i-menu .menu-buttons { opacity: 1; transform: none; pointer-events: auto; }
#screen-menu.i-skipped .t-main, #screen-menu.i-skipped .t-sub, #screen-menu.i-skipped .menu-buttons { transition-duration: .01s; }

/* buttons */
.btn {
  position: relative; min-height: 48px; padding: 0 22px; border: 1px solid var(--line); background: linear-gradient(180deg, rgba(40, 45, 54, .86), rgba(18, 21, 26, .9));
  color: var(--white); font-weight: 800; letter-spacing: .16em; font-size: 13.5px; text-align: center;
  clip-path: polygon(14px 0, 100% 0, calc(100% - 14px) 100%, 0 100%); transition: background .15s, transform .1s, filter .15s;
}
.btn:hover { filter: brightness(1.18); }
.btn:active { transform: scale(.98); }
.btn.play { min-height: 60px; font-size: 21px; letter-spacing: .3em; padding-left: calc(22px + .3em); border-color: rgba(255, 130, 130, .6); background: linear-gradient(180deg, #f0343c, var(--red-d)); box-shadow: 0 0 30px rgba(224, 38, 46, .25); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; margin-top: 14px; }
.btn.small { min-height: 40px; font-size: 12px; padding: 0 16px; }
.danger-btn { background: linear-gradient(180deg, #7b1b1f, #4a0e11); border-color: rgba(255, 120, 120, .5); }
.menu-buttons { display: grid; width: min(100%, 420px); grid-template-columns: 1fr; gap: 9px; }
.menu-buttons .btn.play { grid-column: 1 / -1; }
.skip { position: absolute; right: calc(var(--safe-r) + 14px); top: calc(var(--safe-t) + 12px); background: rgba(0, 0, 0, .35); border: 1px solid var(--line); color: var(--silver); padding: 9px 14px; font-size: 12px; letter-spacing: .1em; border-radius: 2px; }
body.intro-done .skip { display: none; }
.legal { flex: 0 0 auto; padding: 2px 0 6px; text-align: center; font-size: 10px; color: rgba(201, 206, 214, .45); pointer-events: none; }

/* compact portrait: two-column secondary buttons */
@media (max-height: 740px) { .menu-buttons { grid-template-columns: 1fr 1fr; gap: 8px; } .btn { min-height: 46px; } .btn.play { min-height: 54px; font-size: 19px; } }
@media (max-height: 600px) and (orientation: portrait) { .menu-side { gap: 8px; } }

/* landscape / desktop: cinematic split */
@media (orientation: landscape) {
  .menu-layout { flex-direction: row-reverse; align-items: stretch; gap: 2vw; padding: 10px 3vw 18px; }
  .hero-slot { flex: 1 1 58%; height: auto; margin-top: 0; min-height: 0; }
  .menu-side { flex: 0 0 min(38%, 440px); justify-content: center; align-items: center; gap: 2.4vh; }
  .t-main { font-size: min(5.1vw, 10vh, 64px); }
  .t-sub { font-size: min(2.2vw, 4.4vh, 24px); }
  .menu-buttons { grid-template-columns: 1fr 1fr; width: 100%; gap: 7px; }
  .btn { min-height: min(46px, 8.6vh); font-size: min(13px, 3.4vh); }
  .btn.play { min-height: min(58px, 11vh); font-size: min(20px, 5vh); }
  #screen-menu { background: linear-gradient(90deg, rgba(4, 5, 7, .78) 0%, rgba(4, 5, 7, .25) 50%, rgba(0, 0, 0, 0) 70%); }
}
@media (orientation: landscape) and (max-height: 420px) { .t-sub { margin-top: .35em; } .menu-side { gap: 1.6vh; } .legal { display: none; } }

/* ---------- panels ---------- */
.panel { width: min(100%, 640px); max-height: 100%; overflow-y: auto; background: linear-gradient(180deg, rgba(26, 30, 37, .96), rgba(14, 16, 20, .97)); border: 1px solid var(--line); padding: 18px 18px 20px; margin: auto; }
.panel-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.panel-head h2, .garage-head h2 { font-size: 22px; font-weight: 800; letter-spacing: .04em; }
.back { min-height: 40px; padding: 0 14px 0 10px; background: transparent; border: 1px solid var(--line); color: var(--silver); font-size: 13px; letter-spacing: .08em; }
.back::before { content: "\2039"; font-size: 20px; margin-right: 8px; vertical-align: -1px; }
.cards { display: grid; gap: 10px; }
.mode-card { text-align: left; display: grid; gap: 6px; padding: 14px 16px; background: linear-gradient(180deg, rgba(40, 45, 54, .7), rgba(22, 25, 31, .8)); border: 1px solid var(--line); border-left: 3px solid var(--red); min-height: 64px; }
.mode-card:hover { background: rgba(50, 56, 67, .8); }
.mode-card.police { border-left-color: #3d7bff; background: linear-gradient(90deg, rgba(224,38,46,.16), rgba(61,123,255,.16)); }
.mc-name { font-size: 18px; font-weight: 800; letter-spacing: .03em; }
.mc-desc { font-size: 13.5px; line-height: 1.4; color: var(--silver); }
.mc-best { font-size: 12px; color: rgba(201, 206, 214, .7); }
.mc-best b { color: var(--white); }
.howto { padding-left: 18px; margin: 0 0 16px; display: grid; gap: 10px; font-size: 14.5px; line-height: 1.45; color: var(--silver); }
.howto b { color: var(--white); }
.keys-guide h3 { font-size: 13px; letter-spacing: .1em; margin: 12px 0 6px; color: var(--white); }
.keys-guide p { font-size: 14px; color: var(--silver); line-height: 1.7; }
kbd { display: inline-block; min-width: 26px; text-align: center; padding: 2px 7px; margin: 0 2px; border: 1px solid var(--line); border-bottom-width: 2px; background: var(--char2); font: 700 12px var(--font); color: var(--white); }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.setting b { display: block; font-size: 15px; }
.setting span { font-size: 12.5px; color: rgba(201, 206, 214, .7); }
.toggle { min-width: 72px; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); background: var(--char2); font-weight: 800; letter-spacing: .06em; }
.toggle[aria-pressed="true"] { background: linear-gradient(180deg, #f0343c, var(--red-d)); border-color: rgba(255, 140, 140, .6); }
.slider { display: flex; align-items: center; gap: 10px; }
.slider input { width: 120px; accent-color: var(--red); }
output { font-variant-numeric: tabular-nums; color: var(--white); }
.note { font-size: 12.5px; color: rgba(201, 206, 214, .7); line-height: 1.45; margin-top: 10px; }
.best-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.best-table th, .best-table td { padding: 12px 8px; text-align: right; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.best-table thead th { border-top: 0; font-size: 11px; letter-spacing: .1em; color: rgba(201, 206, 214, .7); font-weight: 700; }
.best-table th:first-child { text-align: left; }
.best-table tbody th { font-weight: 800; }
.best-table td:nth-child(2) { color: var(--white); font-weight: 800; }

/* sim */
#simCanvas { width: 100%; height: 150px; display: block; border: 1px solid var(--line); background: #0b0e13; }
.sim-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 14px 0; }
.sim-grid label { display: grid; gap: 6px; font-size: 12.5px; color: var(--silver); }
.sim-grid output { float: right; color: var(--white); font-weight: 700; }
.sim-grid input { width: 100%; accent-color: var(--red); }
.meters { display: grid; gap: 10px; }
.meters span { font-size: 12.5px; color: var(--silver); display: flex; justify-content: space-between; margin-bottom: 4px; }
.meters b { color: var(--white); }
.mbar { height: 8px; background: rgba(255, 255, 255, .1); }
.mbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #9fe8ff, #f2b705); transition: width .25s; }
.mbar.red i { background: linear-gradient(90deg, #f2b705, var(--red)); }
#screen-sim .btn { margin-top: 12px; }

/* garage */
.garage-head { display: flex; align-items: center; gap: 14px; width: 100%; }
.garage-card { width: min(100%, 440px); background: linear-gradient(180deg, rgba(26, 30, 37, .92), rgba(14, 16, 20, .94)); border: 1px solid var(--line); padding: 14px 16px 16px; }
.g-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.arrow { width: 52px; height: 52px; border: 1px solid var(--line); background: var(--char2); font-size: 18px; }
.g-name { text-align: center; display: grid; gap: 2px; }
.g-name b { font-size: 20px; letter-spacing: .03em; }
.g-name span { font-size: 12px; color: rgba(201, 206, 214, .7); }
.dots { display: flex; justify-content: center; gap: 12px; margin: 12px 0 6px; }
.dot { width: 36px; height: 36px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .2); background: linear-gradient(135deg, var(--c1), var(--c2) 55%, var(--c3)); padding: 0; position: relative; }
.dot.sel { border-color: var(--white); box-shadow: 0 0 0 3px rgba(255, 255, 255, .15); }
.dot.lock { filter: grayscale(.8) brightness(.55); }
.dot.lock::after { content: ""; position: absolute; left: 50%; top: 50%; width: 12px; height: 9px; background: #fff; transform: translate(-50%, -30%); border-radius: 2px; box-shadow: 0 -6px 0 -3px #fff; }
.req { text-align: center; font-size: 12.5px; margin: 6px 0 2px; min-height: 1.4em; }
.req.ok { color: #8fe8c2; }
.req.locked { color: #ffb4b4; }
.g-sub { font-size: 12px; letter-spacing: .12em; color: rgba(201, 206, 214, .75); margin: 14px 0 8px; text-align: center; font-weight: 700; }
.pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.pill { min-height: 42px; padding: 0 14px 0 10px; display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--char2); font-size: 13px; font-weight: 700; }
.pill i { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle, #fff 0%, var(--f1) 45%, var(--f2) 100%); box-shadow: 0 0 10px var(--f2); }
.pill.sel { border-color: var(--white); background: #2a2f38; }
.pill.lock { opacity: .55; }
.garage-layout .menu-side { align-items: stretch; width: 100%; gap: 10px; }
.garage-layout .garage-card { align-self: center; }
@media (orientation: landscape) { .garage-layout .menu-side { flex-basis: min(42%, 460px); } .garage-layout .hero-slot { flex-basis: 56%; } }

/* dialogs */
.dialog { width: min(100%, 420px); background: linear-gradient(180deg, rgba(28, 32, 39, .97), rgba(14, 16, 20, .98)); border: 1px solid var(--line); padding: 22px; display: grid; gap: 10px; margin: auto; text-align: center; }
.dialog h2 { font-size: 26px; letter-spacing: .04em; }
.dialog .btn { width: 100%; }
.results { width: min(100%, 520px); }
#rTitle.win { color: #8fe8c2; } #rTitle.lose { color: #ff8a8a; }
.rsub { color: var(--silver); font-size: 13.5px; }
.rscore { display: grid; justify-items: center; gap: 2px; margin: 6px 0; }
.rscore span { font-size: 11px; letter-spacing: .16em; color: rgba(201, 206, 214, .7); }
.rscore b { font-size: 46px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.rscore em { display: none; font-style: normal; background: var(--red); font-size: 11px; font-weight: 800; letter-spacing: .14em; padding: 3px 10px; margin-top: 6px; }
.rstats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin: 4px 0; text-align: left; }
.rstats div { border-top: 1px solid var(--line); padding-top: 6px; }
.rstats dt { font-size: 11px; color: rgba(201, 206, 214, .7); letter-spacing: .06em; }
.rstats dd { margin: 2px 0 0; font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.runlock { display: none; font-size: 13px; color: #ffe27a; }
.rbtns { display: grid; gap: 8px; margin-top: 6px; }
@media (orientation: landscape) and (max-height: 520px) { .rbtns { grid-template-columns: 1fr 1fr 1fr; } .rbtns .btn.play { grid-column: auto; min-height: 48px; font-size: 14px; letter-spacing: .12em; padding-left: 12px; } .dialog { padding: 14px; gap: 6px; } .rscore b { font-size: 34px; } .dialog h2 { font-size: 21px; } .rstats { grid-template-columns: repeat(3, 1fr); } }

/* ---------- HUD ---------- */
#hud { position: fixed; left: 0; right: 0; top: 0; display: none; align-items: center; gap: 14px; padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 12px) 8px calc(var(--safe-l) + 12px); background: linear-gradient(180deg, rgba(3, 4, 6, .78), rgba(3, 4, 6, 0)); pointer-events: none; flex-wrap: wrap; }
body.in-run #hud { display: flex; }
#hud button { pointer-events: auto; }
#btnPause { width: 44px; height: 44px; display: grid; grid-auto-flow: column; gap: 5px; place-content: center; background: rgba(20, 23, 28, .8); border: 1px solid var(--line); flex: 0 0 auto; }
#btnPause i { width: 4px; height: 16px; background: var(--white); }
.stat { display: grid; gap: 1px; min-width: 64px; }
.stat span { font-size: 10px; letter-spacing: .14em; color: rgba(201, 206, 214, .75); font-weight: 700; }
.stat b { font-size: 22px; font-weight: 900; font-variant-numeric: tabular-nums; text-shadow: 0 2px 6px rgba(0, 0, 0, .8); }
.hp { display: flex; gap: 5px; }
.hp i { width: 20px; height: 10px; background: var(--white); transform: skewX(-20deg); box-shadow: 0 0 8px rgba(255, 255, 255, .4); transition: background .2s, opacity .2s; }
.hp i.off { background: #3a3f48; box-shadow: none; opacity: .7; }
.bars { display: flex; gap: 12px; flex: 1 1 220px; min-width: 200px; max-width: 420px; margin-left: auto; }
.bar { flex: 1; display: grid; gap: 3px; }
.bar span { font-size: 10px; letter-spacing: .14em; color: rgba(201, 206, 214, .75); font-weight: 700; display: flex; justify-content: space-between; }
.bar span em { font-style: normal; color: var(--white); }
.bar > div { height: 8px; background: rgba(255, 255, 255, .14); }
.bar i { display: block; height: 100%; width: 100%; transition: width .12s linear; }
.bar.battery i { background: linear-gradient(90deg, #5be0bf, #b8ffe9); }
.bar.battery.low i { background: linear-gradient(90deg, var(--red), #ff8a8a); }
.bar.boost i { background: linear-gradient(90deg, #8fd3ff, #ffffff); }
.bar.boost.lock i { background: #6b717d; }
.chip { display: none; position: absolute; left: 50%; top: calc(var(--safe-t) + 56px); transform: translateX(-50%); font-size: 12px; font-weight: 900; letter-spacing: .12em; padding: 3px 10px; background: rgba(224, 38, 46, .85); }
.chip.on { display: block; }
#toasts { position: fixed; left: 0; right: 0; top: 26%; display: grid; justify-items: center; gap: 8px; pointer-events: none; z-index: 5; }
.toast { padding: 8px 16px; background: rgba(8, 10, 13, .82); border: 1px solid var(--line); border-left: 3px solid var(--red); font-weight: 800; font-size: 14px; letter-spacing: .03em; max-width: 90vw; text-align: center; animation: toastIn .25s ease-out, toastOut .4s ease-in 1.3s forwards; }
.toast.big { font-size: 17px; border-left-color: #8fe8c2; animation-delay: 0s, 1.9s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }
#countdown { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; font-size: min(28vw, 30vh); font-weight: 900; letter-spacing: .04em; opacity: 0; text-shadow: 0 6px 30px rgba(0, 0, 0, .8); z-index: 4; }
#countdown.show { animation: cd .7s ease-out forwards; }
@keyframes cd { 0% { opacity: 0; transform: scale(1.5); } 25% { opacity: 1; transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: scale(.9); } }

/* touch controls */
#touch { display: none; position: fixed; left: 0; right: 0; bottom: 0; pointer-events: none; z-index: 3; padding: 0 calc(var(--safe-r) + 18px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 18px); justify-content: space-between; align-items: flex-end; touch-action: none; }
body.in-run.has-touch #touch { display: flex; }
#dpad { pointer-events: auto; touch-action: none; position: relative; width: min(190px, 40vh); aspect-ratio: 1; flex: 0 0 auto; }
#dpad button { position: absolute; width: 36%; height: 36%; border: 1px solid rgba(255, 255, 255, .28); background: rgba(16, 19, 24, .55); backdrop-filter: blur(2px); font-size: 20px; color: rgba(255, 255, 255, .85); pointer-events: none; display: grid; place-items: center; padding: 0; }
#dpad button.on { background: rgba(224, 38, 46, .7); border-color: #fff; }
#dpU { left: 32%; top: 0; } #dpD { left: 32%; bottom: 0; } #dpL { left: 0; top: 32%; } #dpR { right: 0; top: 32%; }
#btnBoost { pointer-events: auto; touch-action: none; width: min(120px, 26vh); aspect-ratio: 1; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .5); background: radial-gradient(circle at 35% 30%, rgba(143, 211, 255, .55), rgba(30, 60, 110, .6)); font-weight: 900; letter-spacing: .1em; font-size: 14px; color: #fff; margin-bottom: 8px; }
#btnBoost.on { background: radial-gradient(circle at 35% 30%, #fff, #4aa8ff); color: #05203d; transform: scale(.96); }
#keyhint { display: none; position: fixed; left: 0; right: 0; bottom: calc(var(--safe-b) + 10px); text-align: center; font-size: 12px; color: rgba(201, 206, 214, .55); pointer-events: none; }
body.in-run.has-keys:not(.has-touch) #keyhint { display: block; }

/* portrait HUD: two rows */
@media (orientation: portrait) { #hud { gap: 10px 12px; } .bars { flex-basis: 100%; max-width: none; margin-left: 0; } .stat b { font-size: 19px; } .stat { min-width: 0; } }
@media (max-width: 420px) { .stat b { font-size: 18px; } #hud { gap: 8px 10px; } }
@media (orientation: landscape) and (max-height: 460px) { .stat b { font-size: 18px; } #btnPause { width: 38px; height: 38px; } #hud { padding-top: calc(var(--safe-t) + 4px); padding-bottom: 4px; } }

/* rotate message + confirm */
#rotateMsg, #confirm { position: fixed; inset: 0; display: none; place-items: center; background: rgba(4, 5, 8, .88); z-index: 20; padding: 16px; }
#rotateMsg.show, #confirm.show { display: grid; }
.rot-card { text-align: center; display: grid; gap: 10px; justify-items: center; max-width: 340px; }
.rot-card h2 { font-size: 22px; } .rot-card p { color: var(--silver); font-size: 14px; }
.rot-ico { width: 58px; height: 94px; border: 3px solid var(--white); border-radius: 10px; animation: rot 2.4s ease-in-out infinite; }
@keyframes rot { 0%, 25% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }

@media (prefers-reduced-motion: reduce) {
  .t-main, .t-sub, .menu-buttons { transition-duration: .01s; }
  .rot-ico { animation: none; }
  .toast { animation: none; }
}
