:root {
  color-scheme: dark;
  --ink: #eef6f6;
  --muted: #aab9bd;
  --panel: rgba(6, 17, 24, 0.84);
  --panel-strong: rgba(5, 14, 20, 0.95);
  --line: rgba(255, 255, 255, 0.13);
  --saffron: #ff9f1c;
  --green: #3bd186;
  --cyan: #66d9ef;
  --danger: #ff5a5f;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.48);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #07131b;
}

body {
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

#app, #scene-root {
  position: fixed;
  inset: 0;
}

#scene-root canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

#app::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(0, 0, 0, 0.22), transparent 22%, transparent 72%, rgba(0, 0, 0, 0.34)),
    radial-gradient(circle at 50% 45%, transparent 52%, rgba(0, 0, 0, 0.26) 100%);
  z-index: 2;
}

.hidden { display: none !important; }

.hud {
  position: fixed;
  z-index: 10;
  inset: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: start;
  gap: 18px;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  pointer-events: none;
}

.hud-left, .hud-right, .hud-center { min-width: 0; }
.hud-right { justify-self: end; display: flex; align-items: flex-start; gap: 10px; }
.hud-center { justify-self: center; }

.brand-mini {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(4, 13, 19, 0.66);
  backdrop-filter: blur(14px);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.13em;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.route-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--saffron), var(--green));
  box-shadow: 0 0 0 3px rgba(255, 159, 28, 0.15);
}

.metric-row {
  display: flex;
  gap: 8px;
  margin-top: 9px;
}

.metric {
  min-width: 84px;
  padding: 9px 12px 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(4, 13, 19, 0.66);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.metric-wide { min-width: 104px; }
.metric-label, .station-pill small {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
  margin-bottom: 2px;
}
.metric strong { font-size: 20px; letter-spacing: -0.03em; }

.station-pill {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 218px;
  padding: 10px 15px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(4, 13, 19, 0.74);
  backdrop-filter: blur(16px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}
.station-pill strong { display: block; font-size: 15px; letter-spacing: 0.04em; white-space: nowrap; }
.station-icon { color: var(--saffron); filter: drop-shadow(0 0 10px rgba(255, 159, 28, 0.65)); }

.status-stack { display: flex; flex-direction: column; gap: 7px; align-items: flex-end; }
.status-chip {
  display: inline-flex;
  justify-content: center;
  min-width: 76px;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(4, 13, 19, 0.66);
  backdrop-filter: blur(14px);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.1em;
}

.icon-actions { display: flex; gap: 7px; pointer-events: auto; }
.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(4, 13, 19, 0.7);
  backdrop-filter: blur(14px);
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transition: transform 120ms ease, background 120ms ease;
}
.icon-button:hover { transform: translateY(-2px); background: rgba(15, 35, 45, 0.88); }
.icon-button:active { transform: translateY(0) scale(0.96); }

.overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 159, 28, 0.16), transparent 34%),
    radial-gradient(circle at 80% 70%, rgba(59, 209, 134, 0.13), transparent 38%),
    linear-gradient(135deg, rgba(4, 13, 19, 0.5), rgba(4, 13, 19, 0.82));
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 240ms ease, visibility 240ms ease;
}
.overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.compact-overlay { background: rgba(3, 10, 15, 0.64); }

.panel {
  width: min(720px, 100%);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 26px;
  background: linear-gradient(145deg, rgba(8, 23, 32, 0.93), rgba(4, 12, 18, 0.96));
  box-shadow: var(--shadow);
}
.start-panel { padding: clamp(24px, 4.6vw, 50px); }
.compact-panel { width: min(480px, 100%); padding: 34px; text-align: center; }

.eyebrow {
  color: var(--saffron);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.18em;
  margin-bottom: 12px;
}

h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 16px;
  font-size: clamp(54px, 10vw, 96px);
  line-height: 0.78;
  letter-spacing: -0.07em;
  font-weight: 950;
  text-transform: uppercase;
}
h1 span {
  color: transparent;
  -webkit-text-stroke: 1.5px rgba(255, 255, 255, 0.92);
  text-shadow: 0 0 40px rgba(255, 255, 255, 0.12);
}
h2 { margin-bottom: 10px; font-size: clamp(30px, 5vw, 48px); letter-spacing: -0.045em; }
.lead {
  max-width: 650px;
  color: #c7d4d7;
  font-size: clamp(15px, 2vw, 18px);
  line-height: 1.58;
}
.compact-panel p { color: var(--muted); }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin: 24px 0 18px;
}
.feature-grid > div {
  min-height: 92px;
  padding: 14px;
  border-radius: 15px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
}
.feature-grid strong { display: block; font-size: 14px; margin-bottom: 5px; }
.feature-grid span { color: var(--muted); font-size: 11px; line-height: 1.35; }

.controls-card {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 19px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.18);
}
.controls-card > div { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.controls-card span { width: 100%; color: var(--muted); font-size: 10px; margin-top: 3px; }
kbd {
  display: inline-grid;
  place-items: center;
  min-width: 25px;
  height: 25px;
  padding: 0 6px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08);
  box-shadow: inset 0 -2px rgba(0,0,0,.25);
  font-size: 10px;
  font-weight: 900;
}

.primary-button {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 21px;
  border: 0;
  border-radius: 15px;
  color: #061018;
  background: linear-gradient(105deg, var(--saffron), #ffd05d 56%, var(--green));
  cursor: pointer;
  font-weight: 950;
  letter-spacing: 0.08em;
  box-shadow: 0 15px 36px rgba(255, 159, 28, 0.22);
  transition: transform 140ms ease, filter 140ms ease;
}
.primary-button:hover { transform: translateY(-2px); filter: brightness(1.04); }
.primary-button:active { transform: translateY(0) scale(0.985); }
.safety-note { margin: 12px 0 0; color: #829498; text-align: center; font-size: 10px; }

.final-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 20px 0;
}
.final-stats div { padding: 13px 8px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.035); }
.final-stats span { display: block; color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .12em; margin-bottom: 3px; }
.final-stats strong { font-size: 24px; }

.station-banner {
  position: fixed;
  z-index: 12;
  left: 50%;
  top: 24%;
  transform: translate(-50%, -18px) scale(0.96);
  display: grid;
  justify-items: center;
  padding: 12px 24px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 16px;
  background: rgba(5, 16, 23, 0.82);
  backdrop-filter: blur(16px);
  box-shadow: 0 18px 50px rgba(0,0,0,.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease, transform 260ms ease;
}
.station-banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.station-banner span { color: var(--saffron); font-size: 9px; font-weight: 900; letter-spacing: .18em; }
.station-banner strong { font-size: clamp(22px, 4vw, 34px); line-height: 1.1; letter-spacing: .02em; }
.station-banner small { color: var(--muted); font-size: 14px; }

.mobile-controls {
  position: fixed;
  z-index: 14;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  bottom: max(15px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.mobile-cluster { display: flex; gap: 9px; }
.mobile-controls button {
  width: 57px;
  height: 57px;
  border: 1px solid rgba(255,255,255,.19);
  border-radius: 16px;
  color: var(--ink);
  background: rgba(5, 16, 23, .58);
  backdrop-filter: blur(12px);
  font-size: 24px;
  font-weight: 900;
  pointer-events: auto;
  box-shadow: 0 12px 30px rgba(0,0,0,.22);
}
.mobile-controls button:active { transform: scale(.94); background: rgba(20, 45, 58, .8); }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 90px;
  transform: translate(-50%, 10px);
  max-width: min(420px, calc(100% - 30px));
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(4, 13, 19, .82);
  backdrop-filter: blur(12px);
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }


@media (hover: hover) and (pointer: fine) {
  .mobile-controls { display: none !important; }
}

@media (hover: none), (pointer: coarse) {
  .mobile-controls:not(.hidden) { display: flex; }
}

@media (max-width: 480px) {
  .start-panel { padding: 22px 18px; }
  h1 { font-size: clamp(47px, 15vw, 68px); margin-bottom: 12px; }
  .lead { font-size: 14px; line-height: 1.48; }
  .feature-grid { margin: 16px 0 12px; gap: 8px; }
  .feature-grid > div { min-height: 78px; padding: 11px; }
  .controls-card { margin-bottom: 12px; padding: 10px; }
  .safety-note { margin-top: 8px; }
}

@media (max-width: 820px) {
  .hud { grid-template-columns: 1fr auto; gap: 8px; padding-top: max(10px, env(safe-area-inset-top)); }
  .hud-center { order: 3; grid-column: 1 / -1; justify-self: center; }
  .brand-mini { display: none; }
  .metric-row { margin-top: 0; }
  .metric { min-width: 67px; padding: 7px 9px; }
  .metric-wide { min-width: 83px; }
  .metric-label { font-size: 8px; }
  .metric strong { font-size: 16px; }
  .status-stack { display: none; }
  .icon-button { width: 35px; height: 35px; }
  .station-pill { min-width: 190px; padding: 8px 12px; }
  .station-pill strong { font-size: 13px; }
  .feature-grid { grid-template-columns: repeat(2, 1fr); }
  .controls-card { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: clamp(50px, 16vw, 82px); }
  .start-panel { padding: 26px 22px; }
}

@media (max-height: 700px) and (orientation: landscape) {
  .start-panel { padding: 20px 28px; }
  h1 { font-size: 58px; margin-bottom: 10px; }
  .lead { font-size: 13px; line-height: 1.42; }
  .feature-grid { margin: 12px 0; grid-template-columns: repeat(4, 1fr); }
  .feature-grid > div { min-height: 70px; padding: 10px; }
  .controls-card { margin-bottom: 12px; }
}

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