:root {
  --asphalt: #14171c;
  --panel: #1c2129;
  --panel-line: #262d38;
  --steel: #3d4a5c;
  --steel-light: #5a6b82;
  --amber: #ffb100;
  --merah: #e8433d;
  --hijau: #2fa84f;
  --text: #e8e6df;
  --text-dim: #8b93a1;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--asphalt);
  background-image:
    radial-gradient(circle at 15% 10%, rgba(255,177,0,0.05), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(47,168,79,0.05), transparent 40%);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
}

.mono { font-family: var(--mono); }

.scanline {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--amber), transparent);
  opacity: 0.5;
  animation: scan 6s linear infinite;
  z-index: 5;
  pointer-events: none;
}
@keyframes scan {
  0% { top: 0; }
  100% { top: 100%; }
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  border-bottom: 1px solid var(--panel-line);
  background: linear-gradient(180deg, #191d24, transparent);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 22px; color: var(--amber); }
.brand-title {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 3px;
}
.brand-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
  margin-top: 2px;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--text-dim);
}
.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--steel);
  transition: background 0.2s, box-shadow 0.2s;
}
.dot.on {
  background: var(--hijau);
  box-shadow: 0 0 10px var(--hijau);
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------- Layout ---------- */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
}
.controls-card, .log-card { grid-column: 1 / -1; }

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

.card {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 20px;
  position: relative;
}
.card-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 16px;
  border-bottom: 1px dashed var(--panel-line);
  padding-bottom: 10px;
}

/* ---------- Intersection ---------- */
.intersection {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: #0e1013;
  border-radius: 8px;
  padding: 24px 12px;
  position: relative;
  overflow: hidden;
}
.crossroad {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.crossroad-line {
  position: absolute;
  background: repeating-linear-gradient(90deg, #444 0 10px, transparent 10px 20px);
}
.crossroad-line.horizontal { top: 50%; left: 0; right: 0; height: 2px; }
.crossroad-line.vertical { left: 50%; top: 0; bottom: 0; width: 2px; background: repeating-linear-gradient(180deg, #444 0 10px, transparent 10px 20px); }

.road-block { text-align: center; z-index: 1; }
.road-name {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.signal-head {
  background: #05060a;
  border: 1px solid var(--steel);
  border-radius: 6px;
  padding: 10px 8px;
  display: inline-flex;
  flex-direction: column;
  gap: 10px;
}

.bulb {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #1b1b1b;
  opacity: 0.3;
  position: relative;
  transition: opacity 0.25s, background 0.25s;
}
.bulb .ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid transparent;
  opacity: 0;
  transition: opacity 0.25s;
}
.bulb.merah.active { background: var(--merah); opacity: 1; box-shadow: 0 0 18px var(--merah); }
.bulb.kuning.active { background: var(--amber); opacity: 1; box-shadow: 0 0 18px var(--amber); }
.bulb.hijau.active { background: var(--hijau); opacity: 1; box-shadow: 0 0 18px var(--hijau); }
.bulb.active .ring { opacity: 0.5; border-color: currentColor; animation: ring-out 1.1s ease-out infinite; }
.bulb.merah.active .ring { color: var(--merah); }
.bulb.kuning.active .ring { color: var(--amber); }
.bulb.hijau.active .ring { color: var(--hijau); }
@keyframes ring-out {
  0% { transform: scale(0.8); opacity: 0.5; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* ---------- Readout ---------- */
.readout { margin-top: 18px; }
.readout-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}
.readout-key { color: var(--text-dim); letter-spacing: 1px; font-family: var(--mono); font-size: 11px; }
.readout-val { font-size: 16px; font-weight: 700; color: var(--amber); }

.timer-track {
  height: 5px;
  background: var(--panel-line);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--amber), var(--hijau));
  transition: width 1s linear;
}

/* ---------- FSA graph ---------- */
.fsa-graph { width: 100%; height: auto; display: block; }
.edge {
  stroke: var(--steel);
  stroke-width: 2;
  transition: stroke 0.3s, stroke-width 0.3s, filter 0.3s;
}
.edge.pulse {
  stroke: var(--amber);
  stroke-width: 3;
  filter: drop-shadow(0 0 5px var(--amber));
}
.edge-label {
  fill: var(--text-dim);
  font-size: 12px;
}
.node circle {
  fill: var(--panel);
  stroke: var(--steel);
  stroke-width: 2;
  transition: fill 0.3s, stroke 0.3s, filter 0.3s;
}
.node-text {
  fill: var(--text-dim);
  font-size: 15px;
  font-weight: 700;
  text-anchor: middle;
  transition: fill 0.3s;
}
.node.active circle {
  fill: rgba(255,177,0,0.12);
  stroke: var(--amber);
  filter: drop-shadow(0 0 8px var(--amber));
}
.node.active .node-text { fill: var(--amber); }

.legend {
  display: flex;
  gap: 16px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.legend div { display: flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.swatch.merah { background: var(--merah); }
.swatch.kuning { background: var(--amber); }
.swatch.hijau { background: var(--hijau); }

/* ---------- Controls ---------- */
.controls { display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  flex: 1;
  min-width: 140px;
  padding: 12px;
  border-radius: 6px;
  border: 1px solid var(--steel);
  background: #10131a;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 1px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.2s, color 0.2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-go:hover { border-color: var(--hijau); color: var(--hijau); }
.btn-stop:hover { border-color: var(--merah); color: var(--merah); }
.btn-reset:hover { border-color: var(--amber); color: var(--amber); }

/* ---------- Log ---------- */
#history {
  font-size: 12px;
  color: var(--text-dim);
  background: #0e1013;
  border-radius: 6px;
  padding: 12px;
  max-height: 110px;
  overflow-y: auto;
  line-height: 1.7;
  word-break: break-all;
}
