:root {
  color-scheme: dark;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --ice: rgba(240, 248, 250, 0.96);
  --muted: rgba(226, 237, 240, 0.68);
  --glass: rgba(11, 18, 21, 0.58);
  --line: rgba(230, 245, 248, 0.16);
  --electric: #41bdf1;
  --electric-soft: rgba(65, 189, 241, 0.22);
  --danger: #f0674f;
  --cockpit-lean: 0deg;
  --cockpit-shake-x: 0px;
  --cockpit-shake-y: 0px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #748b94;
  color: var(--ice);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.sky-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 78% 17%, rgba(255, 252, 225, 0.66) 0 3%, transparent 18%),
    linear-gradient(180deg, #87a7b9 0%, #b9c9cf 36%, #d6dcda 58%, #8da08d 100%);
}

.sky-layer::after {
  content: "";
  position: absolute;
  inset: 40% -10% -18%;
  background:
    radial-gradient(ellipse at 12% 45%, rgba(72, 91, 74, 0.84) 0 12%, transparent 13%),
    radial-gradient(ellipse at 29% 52%, rgba(88, 102, 79, 0.78) 0 16%, transparent 17%),
    radial-gradient(ellipse at 52% 44%, rgba(69, 87, 73, 0.8) 0 18%, transparent 19%),
    radial-gradient(ellipse at 77% 51%, rgba(83, 98, 75, 0.86) 0 17%, transparent 18%),
    radial-gradient(ellipse at 97% 43%, rgba(66, 84, 70, 0.84) 0 16%, transparent 17%);
  filter: blur(8px);
  opacity: 0.74;
  transform: scaleY(0.62);
  transform-origin: bottom;
}

.cloud {
  position: absolute;
  width: 36vw;
  min-width: 350px;
  height: 12vw;
  min-height: 100px;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 20% 60%, rgba(255,255,255,.52) 0 19%, transparent 20%),
    radial-gradient(ellipse at 42% 42%, rgba(255,255,255,.62) 0 28%, transparent 29%),
    radial-gradient(ellipse at 66% 57%, rgba(245,249,250,.52) 0 25%, transparent 26%),
    radial-gradient(ellipse at 84% 66%, rgba(235,240,242,.43) 0 18%, transparent 19%);
  filter: blur(9px);
  opacity: 0.74;
  animation: cloudDrift 80s linear infinite;
}

.cloud-a { top: 8%; left: -15%; }
.cloud-b { top: 19%; left: 34%; transform: scale(.72); opacity: .52; animation-duration: 112s; }
.cloud-c { top: 4%; left: 72%; transform: scale(.9); opacity: .58; animation-duration: 96s; }

@keyframes cloudDrift {
  from { translate: 0 0; }
  to { translate: 135vw 2vh; }
}

.experience,
#renderCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

.experience {
  isolation: isolate;
}

#renderCanvas {
  display: block;
  outline: none;
  background: transparent;
  z-index: 1;
}

#renderCanvas:focus-visible {
  box-shadow: inset 0 0 0 2px var(--electric);
}

.glass {
  background: linear-gradient(145deg, rgba(18, 27, 30, .76), rgba(7, 13, 15, .54));
  border: 1px solid var(--line);
  box-shadow: 0 18px 55px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255,255,255,.06);
  backdrop-filter: blur(20px) saturate(115%);
  -webkit-backdrop-filter: blur(20px) saturate(115%);
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 22px;
  background:
    radial-gradient(circle at 50% 58%, rgba(44, 87, 104, .28), transparent 38%),
    linear-gradient(160deg, rgba(9,15,18,.98), rgba(18,27,31,.96));
  transition: opacity .7s ease, visibility .7s ease;
}

.loading-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-wordmark,
.intro-wordmark {
  width: min(310px, 57vw);
  height: auto;
  filter: brightness(0) invert(1);
}

.loading-ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.14);
  border-top-color: var(--electric);
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-screen p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.engine-error,
.intro-panel,
.finish-panel {
  position: fixed;
  z-index: 30;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(700px, calc(100vw - 32px));
  max-height: calc(100vh - 32px - var(--safe-top) - var(--safe-bottom));
  overflow: auto;
  border-radius: 28px;
  padding: clamp(25px, 4.5vw, 48px);
}

.engine-error {
  text-align: center;
}

.engine-error h1,
.finish-panel h1,
.intro-panel h1 {
  margin: 8px 0 14px;
  font-size: clamp(34px, 7vw, 68px);
  line-height: .96;
  letter-spacing: -.045em;
}

.engine-error p,
.intro-copy {
  color: var(--muted);
  line-height: 1.56;
  font-size: clamp(14px, 2.2vw, 17px);
}

.intro-panel {
  text-align: left;
}

.intro-wordmark {
  width: min(235px, 47vw);
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0;
  color: #a8dff5;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .18em;
}

.route-card {
  display: grid;
  grid-template-columns: auto repeat(3, 1fr);
  align-items: center;
  gap: 13px;
  margin: 26px 0 18px;
  padding: 15px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 18px;
  background: rgba(255,255,255,.04);
}

.route-card > span:not(.route-shield) {
  min-width: 0;
  padding-left: 13px;
  border-left: 1px solid rgba(255,255,255,.1);
}

.route-card strong,
.route-card small {
  display: block;
}

.route-card strong {
  font-size: 13px;
}

.route-card small {
  margin-top: 3px;
  color: rgba(226,237,240,.58);
  font-size: 10px;
  line-height: 1.3;
}

.route-shield {
  display: inline-grid;
  place-items: center;
  min-width: 68px;
  height: 38px;
  padding: 0 10px;
  color: #fff;
  background: #2d8844;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 4px;
  box-shadow: 0 0 0 2px #2d8844;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .04em;
}

.route-shield-small {
  min-width: 54px;
  height: 29px;
  font-size: 10px;
  border-width: 1px;
  box-shadow: 0 0 0 1px #2d8844;
}

.graphics-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 17px 0;
  color: rgba(235,245,248,.76);
  font-size: 13px;
}

.graphics-row select {
  min-width: 154px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  padding: 10px 36px 10px 12px;
  color: #f7fbfc;
  background: rgba(4,10,12,.64);
  outline: none;
}

.intro-actions {
  display: flex;
  gap: 12px;
  margin-top: 22px;
}

.primary-button,
.secondary-button {
  min-height: 52px;
  padding: 0 22px;
  border-radius: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 850;
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}

.primary-button {
  flex: 1;
  color: #061116;
  background: linear-gradient(135deg, #86dafb, #3db8eb);
  box-shadow: 0 10px 28px rgba(28,151,203,.24);
}

.secondary-button {
  color: var(--ice);
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.13);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(1px) scale(.99);
}

.controls-copy,
.safety-copy {
  color: rgba(226,237,240,.58);
  font-size: 10px;
  line-height: 1.52;
}

.controls-copy {
  margin: 22px 0 8px;
}

.controls-copy strong {
  color: rgba(240,248,250,.82);
}

.safety-copy {
  margin: 0;
}

.ride-header {
  position: fixed;
  z-index: 12;
  top: calc(14px + var(--safe-top));
  left: calc(14px + var(--safe-left));
  right: calc(14px + var(--safe-right));
  display: grid;
  grid-template-columns: auto minmax(80px, 1fr) auto;
  align-items: center;
  gap: 15px;
  pointer-events: none;
}

.location-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 14px;
}

.location-chip strong,
.location-chip small {
  display: block;
}

.location-chip strong {
  font-size: 10px;
  letter-spacing: .1em;
}

.location-chip small {
  margin-top: 2px;
  color: rgba(225,238,241,.58);
  font-size: 9px;
}

.progress-shell {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.15);
}

.progress-shell span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #72d3f7, #effcff);
  box-shadow: 0 0 13px rgba(83,199,242,.85);
}

.header-actions {
  display: flex;
  gap: 7px;
  pointer-events: auto;
}

.round-button {
  min-width: 42px;
  height: 38px;
  padding: 0 10px;
  color: rgba(246,251,252,.8);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  background: rgba(8,15,17,.58);
  backdrop-filter: blur(13px);
  cursor: pointer;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .08em;
}

.round-button[aria-pressed="true"] {
  color: #071216;
  background: #7ad2f5;
  border-color: #aee7fb;
}

.countdown {
  position: fixed;
  z-index: 25;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  font-size: clamp(110px, 22vw, 260px);
  line-height: 1;
  font-weight: 950;
  letter-spacing: -.08em;
  text-shadow: 0 12px 50px rgba(0,0,0,.44);
  animation: countPulse .72s ease both;
}

@keyframes countPulse {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.28); }
  26% { opacity: 1; }
  100% { opacity: .78; transform: translate(-50%, -50%) scale(.86); }
}

.ride-notice {
  position: fixed;
  z-index: 14;
  top: calc(86px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 250px;
  padding: 11px 15px;
  border-radius: 14px;
  opacity: 0;
  translate: 0 -9px;
  transition: opacity .25s ease, translate .25s ease;
}

.ride-notice.is-visible {
  opacity: 1;
  translate: 0 0;
}

.ride-notice > span:first-child {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: #071216;
  background: #88d7f5;
  font-size: 19px;
  font-weight: 900;
}

.ride-notice strong,
.ride-notice small {
  display: block;
}

.ride-notice strong { font-size: 11px; }
.ride-notice small { color: rgba(227,239,242,.62); font-size: 9px; margin-top: 2px; }

.cockpit-rig {
  position: fixed;
  z-index: 8;
  left: 50%;
  bottom: clamp(-270px, -19vw, -150px);
  width: clamp(880px, 102vw, 1510px);
  aspect-ratio: 1398 / 1125;
  pointer-events: none;
  transform-origin: 50% 88%;
  transform:
    translateX(calc(-50% + var(--cockpit-shake-x)))
    translateY(var(--cockpit-shake-y))
    rotate(var(--cockpit-lean));
  filter: drop-shadow(0 -4px 12px rgba(0,0,0,.22));
  will-change: transform;
}

.cockpit-rig > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.evo-dash {
  position: absolute;
  left: 50%;
  top: 53.6%;
  width: 18.7%;
  height: 9.7%;
  transform: translateX(-50%) perspective(240px) rotateX(3deg);
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr auto;
  align-items: center;
  padding: 5.5% 8% 5%;
  overflow: hidden;
  border-radius: 12%;
  color: #d5f5ff;
  background:
    linear-gradient(180deg, rgba(4,14,18,.95), rgba(2,8,10,.96)),
    radial-gradient(circle at 50% 32%, rgba(61,189,236,.16), transparent 54%);
  box-shadow: inset 0 0 18px rgba(44,178,228,.08);
  text-shadow: 0 0 8px rgba(75,207,255,.5);
}

.evo-dash::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .15;
  background: repeating-linear-gradient(180deg, transparent 0 3px, rgba(147,225,250,.14) 4px);
}

.dash-mode,
.dash-unit,
.dash-bottom {
  position: relative;
  z-index: 1;
}

.dash-mode {
  grid-column: 1;
  grid-row: 1;
  font-size: clamp(6px, .62vw, 10px);
  font-weight: 900;
  letter-spacing: .18em;
}

.evo-dash > strong {
  position: relative;
  z-index: 1;
  grid-column: 1;
  grid-row: 2;
  align-self: center;
  font-family: "Arial Narrow", ui-sans-serif, sans-serif;
  font-size: clamp(24px, 4.1vw, 64px);
  line-height: .8;
  letter-spacing: -.08em;
}

.dash-unit {
  grid-column: 2;
  grid-row: 2;
  align-self: end;
  padding-bottom: 10%;
  font-size: clamp(5px, .55vw, 9px);
  font-weight: 850;
  letter-spacing: .08em;
}

.dash-bottom {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: clamp(4px, .5vw, 8px);
  font-weight: 750;
  letter-spacing: .08em;
}

.telemetry {
  position: fixed;
  z-index: 11;
  left: calc(16px + var(--safe-left));
  bottom: calc(18px + var(--safe-bottom));
  display: flex;
  gap: 16px;
  padding: 10px 13px;
  border-radius: 13px;
}

.telemetry span + span {
  padding-left: 16px;
  border-left: 1px solid rgba(255,255,255,.12);
}

.telemetry small,
.telemetry strong {
  display: block;
}

.telemetry small {
  color: rgba(226,238,241,.48);
  font-size: 7px;
  font-weight: 800;
  letter-spacing: .12em;
}

.telemetry strong {
  margin-top: 3px;
  font-size: 11px;
}

.touch-controls {
  position: fixed;
  z-index: 16;
  inset: auto calc(14px + var(--safe-right)) calc(14px + var(--safe-bottom)) calc(14px + var(--safe-left));
  align-items: end;
  justify-content: space-between;
  pointer-events: none;
}

.steer-pad,
.drive-pad {
  display: flex;
  align-items: end;
  gap: 9px;
  pointer-events: auto;
}

.touch-controls button {
  display: grid;
  place-items: center;
  width: clamp(64px, 17vw, 92px);
  height: clamp(64px, 17vw, 92px);
  border: 1px solid rgba(255,255,255,.18);
  color: rgba(255,255,255,.88);
  background: rgba(6,12,14,.36);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04), 0 12px 24px rgba(0,0,0,.12);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  touch-action: none;
}

.steer-pad button {
  border-radius: 50%;
  font-size: clamp(42px, 10vw, 60px);
  font-weight: 250;
  line-height: 1;
}

.drive-pad button {
  border-radius: 24px;
}

.drive-pad button span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .16em;
}

.throttle-control {
  height: clamp(105px, 28vw, 150px) !important;
  background: linear-gradient(180deg, rgba(64,184,230,.25), rgba(6,12,14,.45)) !important;
}

.brake-control {
  height: clamp(82px, 21vw, 112px) !important;
  background: linear-gradient(180deg, rgba(236,86,60,.19), rgba(6,12,14,.45)) !important;
}

.touch-controls button.is-active {
  transform: scale(.96);
  border-color: rgba(141,222,251,.72);
  background: rgba(65,189,241,.28) !important;
}

.brake-control.is-active {
  border-color: rgba(255,139,112,.75) !important;
  background: rgba(227,75,48,.28) !important;
}

.finish-panel {
  text-align: center;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 28px 0 24px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 16px;
  background: rgba(255,255,255,.08);
}

.result-grid span {
  padding: 17px 10px;
  background: rgba(7,13,15,.6);
}

.result-grid small,
.result-grid strong {
  display: block;
}

.result-grid small {
  color: rgba(225,238,241,.53);
  font-size: 9px;
}

.result-grid strong {
  margin-top: 6px;
  font-size: clamp(18px, 4vw, 28px);
}

.finish-panel .primary-button,
.finish-panel .secondary-button {
  width: 100%;
  margin-top: 9px;
}

[hidden] {
  display: none !important;
}

@media (pointer: coarse), (max-width: 900px) {
  .touch-controls.is-riding {
    display: flex !important;
  }

  .telemetry {
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(16px + var(--safe-bottom));
  }

  .cockpit-rig {
    width: max(1160px, 145vw);
    bottom: max(-330px, -30vw);
  }

  .ride-header {
    grid-template-columns: auto 1fr auto;
    gap: 8px;
  }

  .progress-shell {
    min-width: 40px;
  }

  .round-button {
    min-width: 38px;
    padding: 0 8px;
  }
}

@media (max-width: 720px) {
  .intro-panel,
  .finish-panel,
  .engine-error {
    width: calc(100vw - 20px);
    border-radius: 22px;
    padding: 24px 20px;
  }

  .intro-wordmark {
    margin-bottom: 17px;
  }

  .route-card {
    grid-template-columns: auto 1fr 1fr;
  }

  .route-card > span:last-child {
    display: none;
  }

  .intro-actions {
    flex-direction: column;
  }

  .secondary-button {
    min-height: 46px;
  }

  .location-chip > span:last-child {
    display: none;
  }

  .ride-header {
    left: calc(9px + var(--safe-left));
    right: calc(9px + var(--safe-right));
    top: calc(9px + var(--safe-top));
  }

  .ride-notice {
    top: calc(65px + var(--safe-top));
  }

  .header-actions .round-button:first-child,
  .header-actions .round-button:nth-child(2) {
    font-size: 7px;
  }
}

@media (orientation: portrait) and (pointer: coarse) {
  .cockpit-rig {
    width: max(1180px, 230vw);
    bottom: max(-420px, -54vw);
  }

  .evo-dash {
    border-radius: 8%;
  }

  .telemetry {
    bottom: calc(125px + var(--safe-bottom));
  }

  .touch-controls {
    bottom: calc(12px + var(--safe-bottom));
  }

  .touch-controls button {
    width: 68px;
  }

  .throttle-control { height: 126px !important; }
  .brake-control { height: 94px !important; }

  .intro-panel {
    max-height: calc(100vh - 16px - var(--safe-top) - var(--safe-bottom));
  }
}

@media (max-height: 610px) and (orientation: landscape) {
  .intro-panel {
    top: calc(50% + 2px);
    width: min(900px, calc(100vw - 24px));
    padding: 20px 25px;
  }

  .intro-wordmark {
    width: 165px;
    margin-bottom: 9px;
  }

  .intro-panel h1 {
    font-size: 38px;
    margin: 3px 0 7px;
  }

  .intro-copy {
    margin: 0;
    font-size: 12px;
  }

  .route-card {
    margin: 12px 0 9px;
    padding: 10px;
  }

  .graphics-row {
    margin: 8px 0;
  }

  .intro-actions {
    margin-top: 10px;
  }

  .controls-copy,
  .safety-copy {
    display: none;
  }

  .cockpit-rig {
    width: max(900px, 104vw);
    bottom: -260px;
  }

  .telemetry {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cloud,
  .loading-ring,
  .countdown {
    animation: none;
  }
}
