:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #111827;
  --panel-alt: #1f2937;
  --border: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --success: #22c55e;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #020617 0%, var(--bg) 100%);
  color: var(--text);
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color: #bfdbfe;
}

button {
  font: inherit;
}

.app-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 2rem;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

.version-badge {
  padding: 8px 12px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 999px;
  background: rgba(14, 165, 233, 0.12);
  color: #bae6fd;
  font-weight: 600;
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(420px, 1fr) 280px;
  gap: 20px;
}

.panel {
  background: rgba(17, 24, 39, 0.9);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.panel h2 {
  margin-top: 0;
}

.panel h3 {
  margin: 20px 0 10px;
  font-size: 0.95rem;
  color: #cbd5e1;
}

.panel h3:first-of-type {
  margin-top: 22px;
}

.panel--controls ul {
  padding-left: 18px;
  color: var(--muted);
}

.control-field {
  display: grid;
  gap: 8px;
  margin: 14px 0 18px;
}

.control-field__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.control-field label {
  font-size: 0.92rem;
  color: #cbd5e1;
}

.control-field input[type="number"],
.control-field select {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  padding: 10px 12px;
}

.control-grid {
  display: grid;
  gap: 12px;
}

.control-grid--two-up {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.control-group {
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 14px 0 18px;
}

.control-group legend {
  color: #cbd5e1;
  padding: 0 6px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  margin: 8px 0;
}

.control-value {
  color: #7dd3fc;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.control-field input[type="range"] {
  width: 100%;
  accent-color: #38bdf8;
}

.control-scale {
  display: flex;
  justify-content: space-between;
  color: #94a3b8;
  font-size: 0.76rem;
}

.control-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.control-buttons button {
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(14, 165, 233, 0.12);
  color: #e0f2fe;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

.control-buttons button:hover {
  background: rgba(14, 165, 233, 0.18);
}

.simulation-root {
  min-height: 520px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.8), rgba(15, 23, 42, 0.4)),
    radial-gradient(circle at top, rgba(56, 189, 248, 0.15), transparent 50%);
  color: var(--muted);
  padding: 20px;
}

.world-view {
  display: grid;
  gap: 18px;
}

.world-summary {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.95rem;
}

.world-grid-shell {
  position: relative;
}

.world-grid {
  display: grid;
  gap: 0;
  padding: 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.92));
  border: 1px solid rgba(71, 85, 105, 0.7);
  overflow: hidden;
}

.vehicle-layer {
  position: absolute;
  inset: 12px;
  pointer-events: none;
}

.map-cell {
  position: relative;
  aspect-ratio: 1;
  min-height: 54px;
  border: 1px solid rgba(15, 23, 42, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at center, rgba(34, 197, 94, 0.14), rgba(15, 23, 42, 0.04) 68%),
    linear-gradient(180deg, #244b33, #1a3527);
  overflow: hidden;
}

.map-cell--road,
.map-cell--intersection {
  background: #243244;
}

.map-cell--occupied {
  filter: brightness(1.02);
}

.map-cell--spawn {
  box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.38);
}

.road-surface {
  position: absolute;
  inset: 0;
  display: block;
  background: #4b5563;
}

.road-surface--horizontal {
  inset: 20% 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.16)),
    #555f6e;
}

.road-surface--vertical {
  inset: 0 20%;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.08), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.16)),
    #555f6e;
}

.road-surface--cross {
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 20%, #555f6e 20% 80%, transparent 80%),
    linear-gradient(180deg, transparent 0 20%, #555f6e 20% 80%, transparent 80%);
}

.road-surface--stub {
  inset: 12%;
}

.city-lot {
  position: absolute;
  inset: 0;
}

.city-lot--building {
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.18), rgba(15, 23, 42, 0));
}

.building-mass {
  position: absolute;
  inset: 18% 16% 12%;
  border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, #64748b, #334155);
  box-shadow: inset 0 0 0 1px rgba(226, 232, 240, 0.08);
}

.building-roof {
  position: absolute;
  left: 20%;
  right: 20%;
  top: 14%;
  height: 10%;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.7);
}

.building-windows {
  position: absolute;
  inset: 24% 22% 18%;
  background:
    radial-gradient(circle, rgba(251, 191, 36, 0.55) 0 1px, transparent 2px) 0 0 / 10px 10px,
    radial-gradient(circle, rgba(191, 219, 254, 0.3) 0 1px, transparent 2px) 5px 5px / 10px 10px;
  opacity: 0.7;
}

.city-lot--building-1 .building-mass {
  inset: 12% 22% 10%;
}

.city-lot--building-2 .building-mass {
  inset: 22% 10% 10%;
}

.city-lot--park {
  background: radial-gradient(circle at center, rgba(74, 222, 128, 0.22), rgba(0, 0, 0, 0) 72%);
}

.park-ring {
  position: absolute;
  inset: 18%;
  border-radius: 999px;
  border: 2px solid rgba(187, 247, 208, 0.4);
}

.park-tree {
  position: absolute;
  width: 18%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 35%, #bbf7d0, #15803d 72%);
  box-shadow: 0 0 0 3px rgba(20, 83, 45, 0.28);
}

.park-tree--a { left: 20%; top: 26%; }
.park-tree--b { right: 18%; top: 34%; }
.park-tree--c { left: 40%; bottom: 18%; }

.city-lot--plaza {
  background: linear-gradient(180deg, rgba(226, 232, 240, 0.1), rgba(148, 163, 184, 0.04));
}

.plaza-tile {
  position: absolute;
  inset: 18%;
  border-radius: 10px;
  border: 1px solid rgba(226, 232, 240, 0.14);
}

.plaza-tile--b {
  inset: 28%;
}

.plaza-fountain {
  position: absolute;
  inset: 36%;
  border-radius: 999px;
  background: radial-gradient(circle at center, #7dd3fc, #1d4ed8 68%);
  box-shadow: 0 0 0 4px rgba(125, 211, 252, 0.18);
}

.city-lot--water {
  background: linear-gradient(180deg, rgba(14, 165, 233, 0.4), rgba(30, 64, 175, 0.48));
}

.water-wave {
  position: absolute;
  left: 12%;
  right: 12%;
  height: 12%;
  border-top: 2px solid rgba(186, 230, 253, 0.6);
  border-radius: 999px;
}

.water-wave--a { top: 34%; }
.water-wave--b { top: 56%; }

.lane-marker {
  position: absolute;
  opacity: 0.95;
}

.lane-marker--horizontal {
  left: 0;
  right: 0;
  top: calc(50% - 1px);
  border-top: 2px dashed rgba(250, 204, 21, 0.82);
}

.lane-marker--vertical {
  top: 0;
  bottom: 0;
  left: calc(50% - 1px);
  border-left: 2px dashed rgba(250, 204, 21, 0.82);
}

.intersection-core {
  position: absolute;
  inset: 20%;
  background:
    radial-gradient(circle at center, rgba(148, 163, 184, 0.14), rgba(0, 0, 0, 0) 70%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(0, 0, 0, 0.05));
}

.road-direction {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 0.66rem;
  letter-spacing: -0.08em;
  color: rgba(226, 232, 240, 0.42);
  text-shadow: 0 1px 0 rgba(15, 23, 42, 0.9);
}

.spawn-marker {
  position: absolute;
  inset: 8px;
  border: 2px solid rgba(125, 211, 252, 0.6);
  border-radius: 999px;
  box-shadow: inset 0 0 0 2px rgba(15, 23, 42, 0.82);
}

.traffic-light-cluster {
  position: absolute;
  inset: 0;
}

.traffic-light-housing {
  position: absolute;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.95));
  border: 1px solid rgba(148, 163, 184, 0.28);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  transition: box-shadow 120ms ease-out, border-color 120ms ease-out, background 120ms ease-out;
}

.traffic-light-housing--vertical {
  top: 2px;
  bottom: 2px;
  left: calc(50% - 7px);
  width: 14px;
  border-radius: 999px;
}

.traffic-light-housing--horizontal {
  left: 2px;
  right: 2px;
  top: calc(50% - 7px);
  height: 14px;
  border-radius: 999px;
}

.traffic-light-housing--active {
  border-color: rgba(34, 197, 94, 0.65);
  background: linear-gradient(180deg, rgba(20, 83, 45, 0.96), rgba(22, 101, 52, 0.92));
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.32), 0 1px 2px rgba(0, 0, 0, 0.4);
}

.traffic-light-housing--inactive {
  border-color: rgba(239, 68, 68, 0.28);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.traffic-light-phase-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: rgba(226, 232, 240, 0.92);
  font-size: 0.5rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  letter-spacing: 0.04em;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.traffic-light {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.75);
  background: rgba(71, 85, 105, 0.92);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.4);
  z-index: 1;
}

.traffic-light--north {
  top: 6px;
  left: calc(50% - 4px);
}

.traffic-light--east {
  right: 6px;
  top: calc(50% - 4px);
}

.traffic-light--south {
  bottom: 6px;
  left: calc(50% - 4px);
}

.traffic-light--west {
  left: 6px;
  top: calc(50% - 4px);
}

.traffic-light--green {
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.75);
}

.traffic-light--red {
  background: #ef4444;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.55);
}

.vehicle {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 13px;
  transform:
    translate(
      calc(-50% + var(--vehicle-render-offset-x, 0px)),
      calc(-50% + var(--vehicle-render-offset-y, 0px))
    )
    rotate(var(--vehicle-render-angle, 0deg));
  z-index: 2;
  will-change: left, top, transform;
}

.vehicle--turning .vehicle-svg {
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35)) saturate(1.03);
}

.vehicle[data-motion-kind='straight'],
.vehicle[data-motion-kind='turn'],
.vehicle[data-motion-kind='idle'] {
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .vehicle {
    will-change: auto;
  }
}

.vehicle-svg {
  position: relative;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}

.vehicle-body {
  position: absolute;
  inset: 1px 2px 1px 0;
  border-radius: 999px 7px 7px 999px;
  background: linear-gradient(180deg, var(--vehicle-color-light), var(--vehicle-color));
  border: 1px solid var(--vehicle-color-dark);
}

.vehicle-cabin {
  position: absolute;
  right: 5px;
  top: 2px;
  width: 9px;
  height: 7px;
  border-radius: 4px 5px 5px 4px;
  background: linear-gradient(180deg, rgba(226, 232, 240, 0.95), rgba(148, 163, 184, 0.85));
  border: 1px solid rgba(51, 65, 85, 0.75);
}

.vehicle-windshield {
  position: absolute;
  right: 7px;
  top: 3px;
  width: 4px;
  height: 5px;
  border-radius: 2px 3px 3px 2px;
  background: rgba(191, 219, 254, 0.9);
}

.vehicle-wheels {
  position: absolute;
  width: 5px;
  height: 2px;
  background: #111827;
  border-radius: 999px;
}

.vehicle-wheels--front {
  right: 5px;
  top: 0;
  box-shadow: 0 11px 0 #111827;
}

.vehicle-wheels--rear {
  left: 5px;
  top: 0;
  box-shadow: 0 11px 0 #111827;
}

.status-list {
  display: grid;
  gap: 14px;
  margin: 0;
}

.status-list--compact {
  gap: 10px;
}

.status-list--compact div {
  padding: 10px 12px;
}

.status-list div {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(31, 41, 55, 0.8);
  border: 1px solid rgba(71, 85, 105, 0.7);
}

.status-list dt {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.status-list dd {
  margin: 0;
  font-weight: 600;
}

.status-ok {
  color: #86efac;
}

.info-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  display: grid;
  gap: 8px;
}

.info-list li {
  line-height: 1.35;
}

.app-footer {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }
}
