:root {
  --ink: #07090f;
  --panel: #0e1420;
  --panel-2: #151e2d;
  --red: #f0442f;
  --orange: #ff8a3d;
  --cream: #f5ead7;
  --steel: #91a0b2;
  --line: rgba(255,255,255,.14);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% -20%, #253248 0, transparent 38rem),
    repeating-linear-gradient(90deg, rgba(255,255,255,.018) 0 1px, transparent 1px 5px),
    var(--ink);
  font-family: "Chakra Petch", sans-serif;
  overflow-x: hidden;
}

button { font: inherit; }

.game-shell { width: min(1180px, 100%); margin: 0 auto; padding: 18px 20px 28px; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.brand { font-family: "Press Start 2P", monospace; font-size: clamp(12px, 2vw, 19px); letter-spacing: -1px; }
.brand span { color: var(--red); }
.plate { background: #e9edf0; color: #111; border: 3px solid #bbc2c8; border-radius: 4px; padding: 5px 10px; font-weight: 700; letter-spacing: 2px; box-shadow: 0 2px 0 #59616a; }
.plate b { color: #fff; background: #1458b4; font-size: 10px; padding: 7px 3px; margin: -5px 7px -5px -10px; display: inline-block; }

.game-stage { position: relative; border: 1px solid var(--line); background: #080b11; box-shadow: 0 20px 70px #000, 0 0 0 4px #05070a; overflow: hidden; aspect-ratio: 16 / 10; }
#game { display: block; width: 100%; height: 100%; image-rendering: pixelated; outline: none; }

.screen { position: absolute; inset: 0; }
.hidden { display: none !important; }

.menu-screen { background: linear-gradient(90deg, rgba(3,6,12,.98) 0%, rgba(3,6,12,.9) 38%, rgba(3,6,12,.1) 75%), url("assets/denis-garage.png") center/cover; padding: clamp(26px, 6vw, 74px); display: flex; align-items: center; }
.menu-copy { position: relative; z-index: 2; }
.eyebrow { color: var(--orange); font-weight: 700; letter-spacing: 3px; margin: 0 0 12px; font-size: clamp(10px, 1.3vw, 14px); }
h1, h2 { font-family: "Press Start 2P", monospace; margin: 0; line-height: 1.13; text-shadow: 5px 5px 0 #000; }
h1 { font-size: clamp(32px, 7vw, 80px); letter-spacing: -5px; }
h1 span { color: var(--red); }
h2 { font-size: clamp(20px, 4vw, 42px); }
.tagline { margin: 24px 0; color: #c0c9d2; font-size: clamp(15px, 2vw, 22px); line-height: 1.3; text-transform: uppercase; font-weight: 600; letter-spacing: 1px; }
.menu-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.btn { cursor: pointer; border: 0; padding: 14px 18px; font-weight: 700; letter-spacing: 1px; color: var(--cream); clip-path: polygon(7px 0,100% 0,100% calc(100% - 7px),calc(100% - 7px) 100%,0 100%,0 7px); transition: transform .15s, filter .15s; }
.btn:hover { transform: translateY(-2px); filter: brightness(1.12); }
.btn-primary { background: var(--red); box-shadow: inset 0 -4px 0 #8b1a14; }
.btn-secondary { background: #202b3a; box-shadow: inset 0 -4px 0 #0c1119; }
.denis-card { display: none; }

.garage-screen { background: linear-gradient(rgba(3,6,11,.82), rgba(3,6,11,.94)), url("assets/denis-garage.png") center/cover; padding: clamp(18px, 4vw, 46px); }
.garage-head { display: flex; align-items: flex-start; justify-content: space-between; }
.credits { text-align: right; background: rgba(5,8,13,.82); border-left: 3px solid var(--red); padding: 9px 13px; }
.credits span, .credits b { display: block; }
.credits span { font-size: 11px; color: var(--steel); letter-spacing: 2px; }
.credits b { color: var(--orange); font-size: 20px; }
.garage-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: clamp(16px, 3vw, 38px); margin-top: 25px; align-items: stretch; }
.garage-visual { position: relative; background: #090e16; border: 1px solid var(--line); overflow: hidden; min-height: 230px; }
.garage-visual img { width: 100%; height: 100%; object-fit: cover; filter: contrast(1.08) brightness(.75); }
.garage-visual span { position: absolute; left: 20px; bottom: 16px; background: #eef1f1; color: #111; border: 3px solid #b7bec4; padding: 5px 10px; font-weight: 700; letter-spacing: 2px; }
.upgrades { display: grid; gap: 9px; }
.upgrade { width: 100%; cursor: pointer; text-align: left; color: var(--cream); background: rgba(16,23,34,.94); border: 1px solid var(--line); border-left: 4px solid #586575; padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 12px; transition: border-color .15s, transform .15s; }
.upgrade:hover:not(:disabled) { border-left-color: var(--red); transform: translateX(3px); }
.upgrade span { grid-row: 1 / span 2; }
.upgrade b, .upgrade small { display: block; }
.upgrade small { color: var(--steel); margin-top: 2px; }
.upgrade em { color: var(--orange); font-style: normal; font-weight: 700; }
.upgrade strong { color: #d5dde5; font-size: 12px; }
.upgrade:disabled { opacity: .48; cursor: not-allowed; }
.garage-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.hud { position: absolute; inset: 0; pointer-events: none; padding: 17px 20px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; text-shadow: 2px 2px 0 #000; }
.hud-block, .hud-time { background: rgba(3,6,10,.74); border-top: 2px solid var(--red); padding: 7px 10px; width: max-content; }
.hud-time { justify-self: center; text-align: center; }
.hud-block.right { justify-self: end; text-align: right; }
.hud span { display: block; color: var(--steel); letter-spacing: 2px; font-size: 10px; }
.hud b { font-family: "Press Start 2P", monospace; font-size: clamp(11px, 1.7vw, 18px); }
.hud i { font-style: normal; color: var(--orange); }
.nitro { position: absolute; left: 20px; bottom: 18px; width: min(220px, 28vw); }
.nitro > div { height: 10px; border: 2px solid #e5ebee; background: #0b1118; margin-top: 4px; }
.nitro i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #1bd4ff, #ef3b2d); box-shadow: 0 0 10px #1bd4ff; }
.pause { pointer-events: auto; position: absolute; right: 20px; bottom: 18px; border: 1px solid var(--line); color: white; background: rgba(3,6,10,.76); width: 38px; height: 34px; cursor: pointer; }

.countdown { position: absolute; inset: 0; display: grid; place-items: center; color: white; font: 84px "Press Start 2P", monospace; text-shadow: 7px 7px 0 var(--red), 12px 12px 0 #000; pointer-events: none; }
.result-screen { background: rgba(3,6,10,.9); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 18px; backdrop-filter: blur(6px); }
.result-time { background: #101824; border: 1px solid var(--line); border-top: 3px solid var(--red); padding: 14px 28px; }
.result-time span, .result-time b { display: block; }
.result-time span { color: var(--steel); letter-spacing: 3px; font-size: 11px; }
.result-time b { font: clamp(18px, 3vw, 30px) "Press Start 2P", monospace; margin-top: 7px; }
.result-screen > p:not(.eyebrow) { color: var(--orange); font-weight: 700; }

.controls-note { display: flex; gap: 28px; justify-content: center; padding: 17px 0 4px; color: var(--steel); font-size: 12px; }
.controls-note div { display: flex; gap: 6px; align-items: center; }
kbd { color: var(--cream); background: #171e29; border: 1px solid #495566; border-bottom-width: 3px; padding: 4px 6px; border-radius: 3px; font: 10px "Press Start 2P", monospace; }
.touch-controls { display: none; }
.rotate-overlay { display: none; }

@media (max-width: 760px), (pointer: coarse) {
  .game-shell { padding: 10px 8px 20px; }
  .topbar { margin-bottom: 8px; }
  .game-stage { aspect-ratio: 16 / 11; }
  .controls-note { display: none; }
  .touch-controls { position: absolute; z-index: 20; inset: auto 0 0; padding: 12px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); justify-content: space-between; align-items: flex-end; pointer-events: none; }
  .touch-controls:not(.hidden) { display: flex; }
  .touch-controls button { pointer-events: auto; touch-action: none; user-select: none; width: 64px; height: 64px; border: 2px solid rgba(255,255,255,.36); border-bottom: 5px solid rgba(0,0,0,.65); background: rgba(16,23,34,.7); color: white; font-weight: 700; border-radius: 50%; box-shadow: 0 4px 18px rgba(0,0,0,.45), inset 0 0 0 2px rgba(255,255,255,.06); backdrop-filter: blur(3px); -webkit-tap-highlight-color: transparent; }
  .touch-controls button.active { transform: translateY(2px); border-bottom-width: 2px; background: #344054; }
  .touch-steer, .touch-drive { display: flex; align-items: flex-end; gap: 7px; }
  .touch-drive { order: 1; margin-bottom: 0; }
  .touch-steer { order: 2; }
  .touch-steer button { font-size: 23px; }
  .touch-drive button { width: 58px; height: 58px; font-size: 9px; }
  .touch-drive .gas { width: 70px; height: 70px; background: rgba(199,48,36,.76); }
  .touch-drive .boost { background: rgba(11,126,164,.76); }
  .touch-drive .boost.depleted { opacity: .34; filter: grayscale(1); box-shadow: none; }
  .touch-drive .drift { background: rgba(106,72,150,.74); }
  .garage-grid { grid-template-columns: 1fr 1.25fr; gap: 10px; margin-top: 12px; }
  .garage-visual { min-height: 160px; }
  .upgrade { padding: 8px; }
  .upgrade small { display: none; }
  .garage-actions { margin-top: 10px; }
}

@media (pointer: coarse) and (orientation: portrait) {
  body { overflow: hidden; }
  .rotate-overlay {
    position: fixed;
    z-index: 9999;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 28px;
    background:
      radial-gradient(circle at 50% 42%, rgba(240,68,47,.16), transparent 40%),
      repeating-linear-gradient(135deg, rgba(255,255,255,.025) 0 2px, transparent 2px 8px),
      #07090f;
  }
  .rotate-overlay h2 { color: var(--cream); font-size: clamp(18px, 6vw, 28px); text-shadow: 4px 4px 0 #000; }
  .rotate-overlay p { max-width: 310px; margin: 16px 0 0; color: var(--steel); font-size: 16px; }
  .phone-turn { width: 112px; height: 112px; margin-bottom: 28px; position: relative; animation: turn-phone 1.8s ease-in-out infinite; }
  .phone-turn span { position: absolute; width: 54px; height: 88px; left: 29px; top: 12px; border: 5px solid var(--orange); border-radius: 9px; box-shadow: 0 0 22px rgba(255,138,61,.28); }
  .phone-turn span::before { content: ""; position: absolute; width: 18px; height: 3px; background: var(--orange); border-radius: 2px; top: 7px; left: 13px; }
  .phone-turn::after { content: "↻"; position: absolute; color: var(--red); font-size: 38px; right: -18px; bottom: -8px; }
}

@keyframes turn-phone {
  0%, 18% { transform: rotate(0); }
  62%, 100% { transform: rotate(90deg); }
}

@media (pointer: coarse) and (orientation: landscape) {
  html, body { width: 100%; height: 100%; overflow: hidden; background: #03050a; }
  body { display: grid; place-items: center; }
  .game-shell { width: 100vw; height: 100dvh; max-width: none; padding: 0; display: grid; place-items: center; }
  .topbar, .controls-note { display: none; }
  .game-stage {
    width: min(100vw, calc(100dvh * 1.6));
    height: min(100dvh, calc(100vw / 1.6));
    aspect-ratio: 16 / 10;
    border: 0;
    box-shadow: 0 0 70px rgba(0,0,0,.8);
  }
  .hud { padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); }
  .nitro { left: max(16px, env(safe-area-inset-left)); top: max(62px, calc(env(safe-area-inset-top) + 48px)); bottom: auto; width: 220px; }
  .pause { right: max(16px, env(safe-area-inset-right)); bottom: auto; top: max(10px, env(safe-area-inset-top)); }
  .menu-screen { padding: max(20px, env(safe-area-inset-top)) max(32px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(32px, env(safe-area-inset-left)); }
  .garage-screen { overflow-y: auto; padding: max(14px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left)); }
}

@media (max-width: 540px) {
  .plate { font-size: 11px; }
  .menu-screen { padding: 24px; align-items: flex-end; }
  .tagline { margin: 13px 0; }
  .btn { padding: 11px 13px; font-size: 12px; }
  .garage-screen { padding: 14px; }
  .garage-head h2 { font-size: 15px; }
  .garage-grid { grid-template-columns: 1fr; }
  .garage-visual { display: none; }
  .upgrade { min-height: 54px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
