:root {
  --asphalt: #0c0f12;
  --asphalt-2: #141a20;
  --fog: #1a222b;
  --concrete: #8ea0ad;
  --core: #6d8fa3;
  --brain: #2f8f86;
  --make: #c47a3a;
  --sodium: #f0b35a;
  --window: #f3d9a6;
  --ink: #e8eef2;
  --mute: #8b97a3;
  --panel: rgba(12, 15, 18, 0.82);
  --line: rgba(240, 179, 90, 0.28);
  --display: "Syne", "Avenir Next", sans-serif;
  --body: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--asphalt);
  color: var(--ink);
  font-family: var(--body);
}

#stage {
  position: fixed;
  inset: 0;
  display: block;
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.brand {
  position: absolute;
  top: 22px;
  left: 24px;
  pointer-events: none;
  max-width: min(420px, 72vw);
}

.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: -0.04em;
  font-size: clamp(1.7rem, 3.4vw, 2.55rem);
  line-height: 0.95;
}

.brand h1 span {
  display: block;
  color: var(--sodium);
  font-size: 0.42em;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 0.35em;
}

.brand p {
  margin: 10px 0 0;
  color: var(--mute);
  font-size: 0.92rem;
  line-height: 1.35;
  max-width: 34ch;
}

.controls {
  position: absolute;
  top: 22px;
  right: 22px;
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.search {
  width: min(280px, 52vw);
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: 12px 16px;
  font: 500 0.92rem var(--body);
  outline: none;
  backdrop-filter: blur(10px);
}

.search::placeholder { color: var(--mute); }
.search:focus { border-color: var(--sodium); }

.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 999px;
  padding: 0 14px;
  font: 600 0.78rem var(--body);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.chip:hover, .chip.on { border-color: var(--sodium); color: var(--sodium); }

.legend {
  position: absolute;
  left: 24px;
  bottom: 24px;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.legend .row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--mute);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.swatch.core { background: var(--core); }
.swatch.brain { background: var(--brain); }
.swatch.make { background: var(--make); }
.swatch.road { background: linear-gradient(90deg, transparent, var(--sodium), transparent); height: 3px; }

.stats {
  position: absolute;
  right: 22px;
  bottom: 24px;
  text-align: right;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--mute);
  line-height: 1.55;
  pointer-events: none;
}

.stats b { color: var(--ink); font-weight: 600; }

.panel {
  position: absolute;
  top: 50%;
  right: 22px;
  transform: translateY(-50%);
  width: min(340px, 88vw);
  max-height: min(70vh, 560px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 18px 16px;
  backdrop-filter: blur(14px);
  pointer-events: auto;
  opacity: 0;
  translate: 12px 0;
  transition: opacity .25s ease, translate .25s ease;
}

.panel.open {
  opacity: 1;
  translate: 0 0;
}

.panel .kicker {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sodium);
  margin-bottom: 8px;
}

.panel h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.panel .meta {
  margin: 8px 0 0;
  color: var(--mute);
  font-size: 0.82rem;
}

.panel .summary {
  margin: 14px 0 0;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.45;
}

.panel .roads {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
}

.panel .roads li {
  font-size: 0.8rem;
  color: var(--mute);
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 7px;
}

.panel .roads strong {
  color: var(--ink);
  font-weight: 600;
}

.panel .actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.panel a, .panel button {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 13px;
  font: 600 0.78rem var(--body);
  text-decoration: none;
  cursor: pointer;
}

.panel a.primary {
  background: var(--sodium);
  color: #1a1206;
  border-color: var(--sodium);
}

.blocker {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background:
    linear-gradient(180deg, rgba(12,15,18,0.35), rgba(12,15,18,0.78)),
    radial-gradient(circle at 50% 40%, rgba(240,179,90,0.12), transparent 55%);
  pointer-events: auto;
  transition: opacity .3s ease;
}

.blocker.hide { opacity: 0; pointer-events: none; }

.gate {
  width: min(460px, 90vw);
  text-align: center;
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  backdrop-filter: blur(14px);
}

.gate-kicker {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--sodium);
}

.gate h1 {
  margin: 10px 0 0;
  font-family: var(--display);
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  letter-spacing: -0.04em;
}

.gate-copy {
  margin: 12px auto 0;
  max-width: 34ch;
  color: var(--mute);
  line-height: 1.4;
}

.play {
  margin-top: 20px;
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--sodium);
  color: #1a1206;
  font: 700 0.95rem var(--body);
  padding: 14px 22px;
  cursor: pointer;
}

.keys {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  color: var(--mute);
  font-size: 0.82rem;
}

.keys kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 2px 7px;
  margin-right: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.75rem;
}

.crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease;
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: var(--sodium);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
}

.crosshair::before {
  left: 6px;
  top: 0;
  width: 2px;
  height: 14px;
}

.crosshair::after {
  left: 0;
  top: 6px;
  width: 14px;
  height: 2px;
}

body.playing .crosshair { opacity: 0.85; }
body.playing .playing-hide { opacity: 0; }

.look-hint {
  position: fixed;
  left: 50%;
  top: calc(50% + 28px);
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  backdrop-filter: blur(10px);
}

.look-hint b {
  display: block;
  font-family: var(--display);
  font-size: 0.95rem;
}

.look-hint span {
  display: block;
  margin-top: 2px;
  color: var(--sodium);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.district-hud {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--sodium);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  opacity: 0;
  transition: opacity .2s ease;
}

body.playing .district-hud { opacity: 1; }

.keys-mobile { display: none; }

.touch-controls {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  display: none;
}

.touch-controls .stick {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: 128px;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  text-align: center;
}

.touch-controls .stick span {
  display: block;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mute);
}

#stick-move { left: max(18px, env(safe-area-inset-left)); }
#stick-look { right: max(18px, env(safe-area-inset-right)); }

.stick-base {
  width: 112px;
  height: 112px;
  margin: 0 auto;
  border-radius: 50%;
  border: 1px solid rgba(240, 179, 90, 0.35);
  background: rgba(12, 15, 18, 0.45);
  position: relative;
  backdrop-filter: blur(8px);
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(240, 179, 90, 0.85);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
  transition: background .15s ease;
}

.stick.active .stick-knob { background: #f0b35a; }

.touch-action {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(160px + env(safe-area-inset-bottom));
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px solid rgba(240, 179, 90, 0.45);
  background: rgba(240, 179, 90, 0.88);
  color: #1a1206;
  font: 700 0.78rem var(--body);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: auto;
  touch-action: manipulation;
}

body.touch-mode .keys-pc { display: none; }
body.touch-mode .keys-mobile { display: grid; }
body.touch-mode .crosshair { display: none; }
body.touch-mode.playing .touch-controls { display: block; }
body.touch-mode .controls {
  top: auto;
  bottom: calc(170px + env(safe-area-inset-bottom));
  left: 12px;
  right: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
body.touch-mode .stats { display: none; }
body.touch-mode .legend { display: none; }

.loading {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, #1a222b 0%, var(--asphalt) 65%);
  font-family: var(--display);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--sodium);
  transition: opacity .4s ease;
}

.loading.hide { opacity: 0; pointer-events: none; }

@media (max-width: 720px) {
  .brand { top: 14px; left: 14px; }
  .controls { top: auto; bottom: 88px; right: 14px; left: 14px; }
  .search { flex: 1; width: auto; }
  .legend { display: none; }
  .stats { left: 14px; right: auto; text-align: left; bottom: 18px; }
  .panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 42vh;
    transform: none;
    border-radius: 18px 18px 0 0;
  }
  .district-hud { top: 10px; }
  .gate { padding: 22px 16px; }
}
