* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #15221c;
  color: #f6fbf4;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#introOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 213, 77, 0.22), transparent 34%),
    linear-gradient(135deg, #173f58, #15221c 58%, #0b1715);
  transition: opacity 0.55s ease, transform 0.55s ease;
}

html[data-intro="seen"] #introOverlay,
#introOverlay.finished {
  display: none;
}

#introOverlay.leaving {
  opacity: 0;
  transform: scale(0.97);
  pointer-events: none;
}

#introBrand { width: min(820px, 92vw); text-align: center; }
.intro-logo-row { position: relative; display: flex; align-items: center; justify-content: center; height: 190px; }
.intro-car {
  position: absolute;
  left: 50%;
  width: clamp(110px, 16vw, 155px);
  fill: #ffcc33;
  stroke: #fff7d3;
  stroke-width: 5;
  stroke-linejoin: round;
  opacity: 0;
  filter: drop-shadow(0 18px 20px rgba(0, 0, 0, 0.34));
  animation: introCarZoom 0.9s cubic-bezier(.2,.8,.2,1) forwards, introCarShift 0.85s cubic-bezier(.2,.8,.2,1) 0.95s forwards;
}
.intro-window { fill: #69b8da; stroke-width: 3; }
.intro-light { fill: none; stroke: #fff; stroke-width: 7; stroke-linecap: round; }
.intro-logo-row h1 {
  margin: 0 0 0 clamp(155px, 25vw, 250px);
  color: white;
  font-size: clamp(3.4rem, 9vw, 6.7rem);
  line-height: 1;
  letter-spacing: -0.065em;
  opacity: 0;
  transform: translateX(90px);
  animation: introTextSlide 0.85s ease 0.95s forwards;
}
#introBrand > p {
  margin: 15px 0 0;
  color: #eef9f5;
  font-size: clamp(1.35rem, 3vw, 2.1rem);
  opacity: 0;
  animation: introSubtitle 0.75s ease 1.95s forwards;
}
#introDirections {
  position: absolute;
  width: min(720px, calc(100vw - 32px));
  padding: clamp(22px, 4vw, 38px);
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 22px;
  background: rgba(9, 24, 28, 0.82);
  box-shadow: 0 28px 80px rgba(0,0,0,.42);
  backdrop-filter: blur(18px);
  opacity: 0;
  transform: translateY(24px);
  pointer-events: none;
}
#introOverlay.directions #introBrand { animation: introBrandOut .55s ease forwards; }
#introOverlay.directions #introDirections { animation: introDirectionsIn .7s ease .25s forwards; pointer-events: auto; }
.intro-kicker { color: #ffdc69; font-size: 12px; font-weight: 900; letter-spacing: .16em; }
#introDirections h2 { margin: 8px 0 22px; font-size: clamp(1.8rem, 5vw, 3rem); }
.intro-control-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.intro-control-grid > div { display: grid; grid-template-columns: 82px 1fr; padding: 12px; border-radius: 12px; background: rgba(255,255,255,.08); text-align: left; }
.intro-control-grid kbd { grid-row: 1 / 3; align-self: center; justify-self: start; }
.intro-control-grid strong { font-size: 14px; }
.intro-control-grid span { color: #bcd0cc; font-size: 12px; }
kbd { display: inline-block; min-width: 29px; padding: 5px 8px; border: 1px solid rgba(255,255,255,.28); border-bottom-width: 3px; border-radius: 7px; background: rgba(255,255,255,.13); color: white; font: 800 12px/1 system-ui; text-align: center; }
.intro-more-controls { margin: 17px 0; color: #c9dbd7; font-size: 13px; line-height: 2.2; }
#startNow { width: 100%; padding: 14px 20px; border: 0; border-radius: 11px; background: #ffcc33; color: #172019; font: 900 16px/1 system-ui; cursor: pointer; box-shadow: 0 10px 28px rgba(255,204,51,.22); }
#startNow:hover { background: #ffda61; transform: translateY(-1px); }

@keyframes introCarZoom { from { opacity: 0; transform: translateX(-50%) scale(.45); } to { opacity: 1; transform: translateX(-50%) scale(1); } }
@keyframes introCarShift { from { left: 50%; transform: translateX(-50%); } to { left: 7%; transform: translateX(0); } }
@keyframes introTextSlide { to { opacity: 1; transform: translateX(0); } }
@keyframes introSubtitle { to { opacity: 1; } }
@keyframes introBrandOut { to { opacity: 0; transform: scale(.95); pointer-events: none; } }
@keyframes introDirectionsIn { to { opacity: 1; transform: translateY(0); } }

@media (max-width: 600px) {
  .intro-control-grid { grid-template-columns: 1fr; }
  #introDirections { max-height: calc(100vh - 24px); overflow: auto; }
  .intro-logo-row { height: 145px; }
}

@media (prefers-reduced-motion: reduce) {
  .intro-car, .intro-logo-row h1, #introBrand > p { animation-duration: .01ms; animation-delay: 0s; }
}

#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(8, 13, 12, 0.72);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(10px);
}

body.security-view #hud {
  top: auto;
  bottom: 10px;
  left: 50%;
  max-width: calc(100vw - 20px);
  padding: 5px 8px;
  transform: translateX(-50%);
  border-color: rgba(89, 217, 255, 0.38);
  background: rgba(7, 16, 22, 0.52);
  box-shadow: none;
  pointer-events: none;
}

body.security-view #hud > .brand,
body.security-view #hud > .controls,
body.security-view #hud > .range-control,
body.security-view #speed,
body.security-view #signal {
  display: none;
}

body.security-view #status {
  min-width: 0;
  padding: 3px 7px;
  background: transparent;
  color: #dff9ff;
  font-size: 11px;
}

.controls {
  display: flex;
  gap: 6px;
}

.controls button {
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: #f6fbf4;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.controls button.active {
  background: #ffcc33;
  color: #171713;
}

.range-control {
  display: grid;
  grid-template-columns: auto minmax(90px, 150px) 64px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.range-control input {
  width: 100%;
  accent-color: #ffcc33;
  cursor: pointer;
}

.range-control output {
  color: #ffdc69;
  text-align: right;
}

.brand {
  flex: 0 0 auto;
  font-size: 18px;
  font-weight: 800;
}

.readout {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  line-height: 1.2;
}

.readout span {
  min-width: 78px;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.13);
  white-space: nowrap;
}

#restart {
  position: fixed;
  left: 50%;
  bottom: 32px;
  z-index: 5;
  transform: translateX(-50%);
  min-width: 152px;
  padding: 12px 18px;
  border: 0;
  border-radius: 8px;
  background: #ffcc33;
  color: #171713;
  font: inherit;
  font-weight: 800;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

#loading {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  background: #15221c;
  color: #eaf5e7;
  font-weight: 800;
}

body.police-interview #hud {
  display: none;
}

#policeInteraction {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 8;
  width: min(360px, calc(100vw - 40px));
  padding: 16px;
  border: 1px solid rgba(115, 190, 255, 0.65);
  border-radius: 12px;
  background: rgba(5, 12, 20, 0.9);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
}

.interaction-title {
  color: #83c8ff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.driver-response {
  min-height: 64px;
  margin: 12px 0;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  line-height: 1.4;
}

.interaction-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.interaction-actions button {
  min-height: 44px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.12);
  color: #f6fbf4;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.interaction-actions button:hover {
  border-color: #83c8ff;
  background: rgba(74, 154, 220, 0.28);
}

.interaction-hint {
  margin-top: 12px;
  color: #ffdc69;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

#cockpitDashboard {
  position: fixed;
  left: 50%;
  bottom: -8px;
  z-index: 7;
  width: min(760px, 94vw);
  height: 245px;
  transform: translateX(-50%);
  border: 2px solid #101417;
  border-bottom: 0;
  border-radius: 46% 46% 0 0 / 28% 28% 0 0;
  background: linear-gradient(180deg, rgba(38, 45, 49, 0.97), rgba(9, 12, 14, 0.99));
  box-shadow: 0 -14px 35px rgba(0, 0, 0, 0.55), inset 0 3px 0 rgba(255,255,255,.08);
  pointer-events: none;
}

#cockpitCabin {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.cockpit-roof {
  position: fixed;
  left: 0;
  top: 66px;
  width: 100vw;
  height: 22px;
  border-bottom: 5px solid #0b0e10;
  background: linear-gradient(#161b1e, #252c30);
  box-shadow: 0 5px 12px rgba(0, 0, 0, .45);
}

.windshield-pillar {
  position: fixed;
  top: 82px;
  width: 34px;
  height: 72vh;
  border: 3px solid #090b0c;
  background: linear-gradient(90deg, #111517, #323a3e 50%, #101315);
  box-shadow: 0 0 12px rgba(0, 0, 0, .5);
}

.pillar-left { left: 4.5vw; transform: skewX(8deg); }
.pillar-right { right: 4.5vw; transform: skewX(-8deg); }

.side-mirror {
  position: fixed;
  top: 56vh;
  width: clamp(130px, 14vw, 210px);
  aspect-ratio: 2.05 / 1;
  overflow: hidden;
  border: 9px solid #0b0e10;
  border-radius: 48% 32% 38% 42%;
  background: transparent;
  box-shadow: 0 0 0 2px #3b454a, 0 8px 16px rgba(0, 0, 0, .5);
}

.side-mirror::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, .48);
}

.mirror-left { left: 6vw; transform: rotate(-2deg); }
.mirror-right { right: 6vw; transform: scaleX(-1) rotate(-2deg); }

.dashboard-top { display: flex; align-items: center; justify-content: center; gap: 24px; padding-top: 25px; }
.dash-cluster { width: 220px; padding: 10px 18px; border: 2px solid #313b40; border-radius: 42px; background: #05090b; text-align: center; box-shadow: inset 0 0 20px rgba(75, 190, 255, .12); }
.dash-cluster strong { color: #f5fbff; font: 800 44px/1 system-ui; }
.dash-cluster small { margin-left: 6px; color: #8ba1aa; font-size: 11px; }
.dash-cluster output { display: block; margin-top: 5px; color: #68d6ff; font-size: 11px; font-weight: 800; }
.rpm-track { height: 5px; margin-top: 8px; overflow: hidden; border-radius: 5px; background: #1e282d; }
.rpm-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #45df8b 55%, #ffcc33 78%, #ff4b3e); transition: width .08s linear; }
.dash-indicator { color: #4e5a5f; font-size: 28px; filter: drop-shadow(0 0 8px transparent); }
.dash-indicator.active { color: #ffb000; filter: drop-shadow(0 0 8px #ff9d00); }
.infotainment { position: absolute; right: 46px; top: 72px; display: grid; width: 170px; padding: 13px; border: 3px solid #161c20; border-radius: 10px; background: linear-gradient(145deg, #12344a, #07151c); box-shadow: inset 0 0 18px rgba(60, 184, 255, .13); }
.infotainment strong { color: #ffdc69; font-size: 17px; }
.infotainment span { margin: 7px 0 12px; color: #e4f7ff; font-size: 12px; font-weight: 800; }
.infotainment small { color: #8fb1bd; font-size: 9px; }
.steering-wheel { position: absolute; left: 65px; bottom: -83px; width: 190px; height: 190px; border: 18px solid #080a0b; border-radius: 50%; box-shadow: 0 0 0 3px #30383b; }
.steering-wheel::before, .steering-wheel::after, .steering-wheel span { content: ""; position: absolute; left: 50%; top: 50%; width: 75px; height: 13px; border-radius: 8px; background: #0b0e10; transform-origin: 0 50%; }
.steering-wheel::before { transform: rotate(25deg); }
.steering-wheel::after { transform: rotate(155deg); }
.steering-wheel span { width: 58px; transform: rotate(270deg); }

@media (max-width: 700px) {
  #cockpitDashboard { height: 210px; }
  .infotainment { right: 18px; width: 145px; }
  .steering-wheel { left: 25px; }
  .dashboard-top { gap: 10px; }
  .dash-cluster { width: 180px; }
}

@media (max-width: 640px) {
  #hud {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .controls {
    flex-wrap: wrap;
  }

  .range-control {
    grid-template-columns: auto minmax(110px, 1fr) 64px;
    width: 100%;
  }

  .readout span {
    min-width: auto;
  }
}
