:root {
  color-scheme: dark;
  --ink: #f5f7fa;
  --muted: #8f9aa7;
  --panel: #171e26;
  --panel-2: #202934;
  --asphalt: #303a45;
  --line: rgba(255,255,255,.1);
  --amber: #ffc629;
  --red: #ef3f45;
  --cell: 16.6667%;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: #0d1217;
  overscroll-behavior: none;
}

body {
  min-height: 100svh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% -20%, rgba(255,198,41,.13), transparent 38%),
    linear-gradient(180deg, #131920 0%, #0c1116 100%);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; }

.game-shell {
  width: min(100%, 520px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 20px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.topbar { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand h1 { margin: 0; font-size: 1.12rem; line-height: 1; letter-spacing: -.03em; }
.brand h1 em { color: var(--amber); font-style: normal; }
.brand p { margin: 5px 0 0; color: var(--muted); font-size: .68rem; font-weight: 750; letter-spacing: .11em; text-transform: uppercase; }
.brand-mark { width: 38px; height: 38px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 7px 6px; border: 1px solid #3c4652; border-radius: 10px; transform: skewX(-6deg); background: #1a222b; }
.brand-mark i { display: block; background: #697684; border-radius: 3px; }
.brand-mark i:nth-child(2) { background: var(--amber); }
.brand-mark i:nth-child(3) { background: #e8494f; }

.icon-button { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid #303a45; border-radius: 50%; color: #c8d0d8; background: #171e26; cursor: pointer; }
.icon-button svg { width: 21px; fill: currentColor; }
.sound-off { display: none; }
.icon-button.is-muted .sound-on { display: none; }
.icon-button.is-muted .sound-off { display: block; }

.hud { display: grid; grid-template-columns: 76px 1fr 76px; gap: 8px; margin: 22px 0 14px; }
.hud-card { min-height: 58px; padding: 8px 10px; border: 1px solid #2c3641; border-radius: 12px; background: linear-gradient(180deg,#1a222b,#141b22); box-shadow: inset 0 1px rgba(255,255,255,.025); }
.hud-card > span { display: block; color: #71808f; font-size: .62rem; font-weight: 850; letter-spacing: .12em; }
.hud-card strong { display: block; margin-top: 2px; font-family: "Arial Narrow", Inter, sans-serif; font-size: 1.55rem; line-height: 1.15; font-weight: 900; }
.hud-card:last-child { text-align: right; }
.level-track { height: 4px; margin-top: 14px; display: flex; gap: 4px; }
.level-track i { flex: 1; border-radius: 5px; background: #333e49; transition: background .25s, transform .25s; }
.level-track i.done { background: #70808f; }
.level-track i.active { background: var(--amber); transform: scaleY(1.5); box-shadow: 0 0 10px rgba(255,198,41,.38); }

.board-wrap { position: relative; width: 100%; margin-top: auto; margin-bottom: auto; }
.board { position: relative; width: calc(100% - 16px); aspect-ratio: 1; border: 8px solid #222b34; border-radius: 22px 14px 14px 22px; overflow: visible; background-color: var(--asphalt); background-image: linear-gradient(rgba(255,255,255,.055) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.055) 1px, transparent 1px), radial-gradient(circle at 20% 10%, rgba(255,255,255,.045), transparent 35%); background-size: var(--cell) var(--cell), var(--cell) var(--cell), 100% 100%; box-shadow: 0 22px 50px rgba(0,0,0,.33), inset 0 0 35px rgba(0,0,0,.2); touch-action: none; }
.board::before { content: ""; position: absolute; inset: -8px; border: 1px solid rgba(255,255,255,.08); border-radius: inherit; pointer-events: none; }
.exit-lane { position: absolute; z-index: 0; left: 0; right: -24px; top: 33.333%; height: 16.667%; background: repeating-linear-gradient(90deg, transparent 0 24px, rgba(255,198,41,.2) 24px 42px); pointer-events: none; }
.exit-sign { position: absolute; z-index: 8; right: -2px; top: calc(41.667% - 15px); width: 70px; height: 30px; display: flex; align-items: center; justify-content: center; gap: 5px; border-radius: 6px; background: var(--amber); color: #161b20; font-size: .57rem; font-weight: 950; letter-spacing: .04em; transform: translateX(48%); box-shadow: 0 8px 18px rgba(0,0,0,.28); }
.exit-sign b { font-size: 1rem; }
.lane { position: absolute; left: 4%; right: 4%; height: 1px; background: repeating-linear-gradient(90deg, rgba(255,255,255,.18) 0 20px, transparent 20px 35px); pointer-events: none; }
.lane--a { top: 33.333%; }
.lane--b { top: 50%; }

#carsLayer { position: absolute; inset: 0; z-index: 2; }
.car { position: absolute; padding: 4px; cursor: grab; transition: filter .15s, box-shadow .15s; touch-action: none; will-change: left, top; }
.car:active, .car.is-dragging { cursor: grabbing; z-index: 6; filter: brightness(1.12); }
.car-body { position: relative; width: 100%; height: 100%; border-radius: 12px; overflow: hidden; background: var(--car); border: 2px solid rgba(255,255,255,.22); box-shadow: 0 7px 12px rgba(0,0,0,.28), inset 0 -6px rgba(0,0,0,.1), inset 0 5px rgba(255,255,255,.12); }
.car-body::before { content: ""; position: absolute; inset: 19% 18%; border-radius: 7px; background: linear-gradient(135deg, #dce8ed, #66808e); border: 2px solid rgba(0,0,0,.25); box-shadow: inset 8px 0 rgba(255,255,255,.18); }
.car.vertical .car-body::before { inset: 18% 20%; background: linear-gradient(45deg, #dce8ed, #66808e); box-shadow: inset 0 8px rgba(255,255,255,.18); }
.car-body::after { content: ""; position: absolute; inset: 8%; border-radius: 8px; border-top: 3px solid rgba(255,255,255,.2); border-bottom: 3px solid rgba(0,0,0,.16); }
.car.target .car-body { box-shadow: 0 8px 18px rgba(239,63,69,.38), inset 0 -6px rgba(0,0,0,.1), inset 0 5px rgba(255,255,255,.14); }
.car.target .car-body::before { background: linear-gradient(135deg, #ffe2bd, #8d5960); }
.car.is-hinted .car-body { animation: hintPulse .55s ease-in-out 3; }
@keyframes hintPulse { 50% { box-shadow: 0 0 0 5px var(--amber), 0 0 28px var(--amber); transform: scale(.95); } }

.instruction { min-height: 24px; margin: 14px 0 11px; text-align: center; color: #aab4bd; font-size: .78rem; font-weight: 650; }
.instruction span { display: inline-block; min-width: 24px; color: var(--amber); font-size: 1.1rem; vertical-align: -1px; }
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.action-button { min-height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 1px solid #303b46; border-radius: 13px; color: #c9d1d8; background: linear-gradient(180deg,#1d2630,#151c23); cursor: pointer; box-shadow: 0 5px 13px rgba(0,0,0,.14); }
.action-button:active { transform: translateY(1px); }
.action-button:disabled { opacity: .35; cursor: default; }
.action-button span { font-size: 1.18rem; font-weight: 900; line-height: 1; }
.action-button small { font-size: .61rem; font-weight: 850; letter-spacing: .08em; }
.action-button--primary { color: #171b20; border-color: #ffd456; background: linear-gradient(180deg,#ffd657,#f2b70c); }

footer { display: flex; justify-content: space-between; padding-top: 11px; color: #566371; font-size: .6rem; font-weight: 850; letter-spacing: .11em; }

.overlay { position: fixed; z-index: 20; inset: 0; padding: 22px; display: grid; place-items: center; background: rgba(6,9,12,.82); backdrop-filter: blur(12px); opacity: 0; visibility: hidden; transition: opacity .25s, visibility .25s; }
.overlay.is-visible { opacity: 1; visibility: visible; }
.modal { width: min(100%, 390px); padding: 32px 28px 28px; border: 1px solid #35414d; border-radius: 24px; text-align: center; background: linear-gradient(160deg,#202a34,#11181f 72%); box-shadow: 0 32px 80px rgba(0,0,0,.55); transform: translateY(12px) scale(.98); transition: transform .3s cubic-bezier(.2,.8,.2,1); }
.overlay.is-visible .modal { transform: none; }
.eyebrow { margin: 0 0 9px; color: var(--amber) !important; font-size: .68rem !important; font-weight: 900 !important; letter-spacing: .18em; text-transform: uppercase; }
.modal h2 { margin: 0; font-size: clamp(2.15rem, 10vw, 3.2rem); line-height: .98; letter-spacing: -.06em; text-transform: uppercase; }
.modal > p:not(.eyebrow) { margin: 17px auto 23px; max-width: 290px; color: #9ea9b4; font-size: .9rem; line-height: 1.55; }
.play-button { width: 100%; min-height: 55px; display: flex; align-items: center; justify-content: center; gap: 12px; border: 0; border-radius: 14px; color: #171b20; background: var(--amber); font-size: .84rem; font-weight: 950; letter-spacing: .08em; cursor: pointer; box-shadow: 0 12px 26px rgba(255,198,41,.2); }
.play-button span { font-size: 1.25rem; }
.mini-lot { position: relative; height: 98px; margin: -4px auto 24px; border: 5px solid #36414c; border-radius: 15px; background: #303a45; overflow: hidden; }
.mini-lot::before { content: ""; position: absolute; left: 0; right: 0; top: 48%; border-top: 1px dashed rgba(255,255,255,.15); }
.mini-lot > span { position: absolute; right: 8px; top: 34px; color: var(--amber); font-size: 1.5rem; font-weight: 900; }
.mini-car { position: absolute; display: block; border-radius: 7px; border: 2px solid rgba(255,255,255,.2); box-shadow: inset 0 -4px rgba(0,0,0,.15); }
.mini-car--red { left: 32px; top: 35px; width: 96px; height: 28px; background: var(--red); }
.mini-car--yellow { left: 126px; top: 8px; width: 30px; height: 78px; background: #f1b92a; }
.mini-car--blue { left: 6px; top: 6px; width: 70px; height: 26px; background: #4c8ccf; }
.success-badge { width: 70px; height: 70px; margin: -3px auto 23px; display: grid; place-items: center; border-radius: 50%; color: #15201a; background: #5fda87; font-size: 2rem; font-weight: 950; box-shadow: 0 0 0 8px rgba(95,218,135,.09), 0 12px 30px rgba(95,218,135,.18); }
.win-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 18px; }
.win-stats div { padding: 12px; border: 1px solid #303b46; border-radius: 12px; background: rgba(255,255,255,.03); }
.win-stats span { display: block; color: #71808f; font-size: .6rem; font-weight: 850; letter-spacing: .12em; }
.win-stats strong { display: block; margin-top: 2px; font-size: 1.45rem; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); min-width: 190px; max-width: calc(100% - 40px); padding: 11px 16px; border: 1px solid #495665; border-radius: 999px; color: #eef2f5; background: rgba(25,33,41,.95); text-align: center; font-size: .78rem; font-weight: 750; box-shadow: 0 12px 30px rgba(0,0,0,.35); transform: translate(-50%, 18px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.is-visible { opacity: 1; transform: translate(-50%,0); }
.confetti { position: fixed; z-index: 25; width: 8px; height: 15px; top: -20px; border-radius: 2px; animation: fall var(--duration) linear forwards; }
@keyframes fall { to { transform: translate(var(--drift), 110vh) rotate(720deg); } }

@media (min-width: 700px) and (min-height: 720px) {
  .game-shell { padding-top: 28px; padding-bottom: 24px; }
  .board-wrap { max-width: 470px; align-self: center; }
}

@media (max-height: 720px) {
  .game-shell { padding-top: 10px; padding-bottom: 8px; }
  .hud { margin: 12px 0 9px; }
  .board-wrap { width: min(100%, 55vh); align-self: center; }
  .instruction { margin: 8px 0 6px; }
  .action-button { min-height: 49px; }
  footer { padding-top: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
