:root {
  --bg: #ffffff;
  --fg: #1c2530;
  --muted: #5b6673;
  --line: #d7dde4;
  --accent: #1f5fae;
  --bar-h: 48px;
  --legend-h: 34px;
  --c1: #d7191c;
  --c2: #fdae61;
  --c3: #ffffbf;
  --c4: #abd9e9;
  --c5: #2c7bb6;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  display: grid;
  /* Satu kolom dan baris tetap per bagian: header, legenda, peringatan (kosong bila tersembunyi), peta. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(0, 1fr);
  height: 100dvh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--bar-h); padding: 6px 16px; border-bottom: 1px solid var(--line); gap: 12px;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex-wrap: wrap; }
@media (max-width: 480px) { .brand { flex-direction: column; gap: 0; } }
h1 { font-size: 18px; margin: 0; }
.badge { font-size: 12px; color: var(--muted); }

.btn {
  font: inherit; white-space: nowrap; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--fg); cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:focus-visible, #map:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.legendbar { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.legend {
  display: flex; align-items: center; gap: 12px; padding: 6px 16px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted);
}
.region { display: flex; align-items: center; gap: 6px; padding: 4px 16px; font-size: 12px; color: var(--muted); }
.region select { font: inherit; font-size: 13px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
.region[hidden] { display: none; }
.legend .item { display: inline-flex; align-items: center; gap: 4px; }
.legend .swatch { width: 18px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.25); }
.legend .end { font-weight: 600; }

.topbar { grid-row: 1; }
.legendbar { grid-row: 2; }
.notice {
  grid-row: 3; margin: 0; padding: 6px 16px; background: #fff7e0; border-bottom: 1px solid #e5c76b;
  font-size: 13px;
}

#map { grid-row: 4; min-height: 0; }

.detail {
  position: fixed; z-index: 3; background: var(--bg); border: 1px solid var(--line);
  box-shadow: 0 4px 18px rgba(0,0,0,.18); padding: 14px 16px 16px; overflow: auto;
  left: 0; right: 0; bottom: 0; max-height: 52dvh; border-radius: 12px 12px 0 0;
}
@media (min-width: 720px) {
  .detail { left: auto; right: 16px; top: calc(var(--bar-h) + var(--legend-h) + 16px); bottom: auto;
            width: 340px; max-height: calc(100dvh - var(--bar-h) - var(--legend-h) - 40px); border-radius: 10px; }
}
.weights { z-index: 4; }
@media (min-width: 720px) {
  .weights { right: auto; left: 16px; width: 300px; }
}
.actions { display: flex; gap: 8px; }
.weight-row { padding: 8px 0; border-top: 1px solid var(--line); }
.weight-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; }
.weight-head .val { font-weight: 400; color: var(--muted); }
.weight-row input[type="range"] { width: 100%; margin: 6px 0 0; accent-color: var(--accent); }
.stops h3 { font-size: 13px; margin: 0 0 4px; }
.stop-row { margin: 3px 0; font-size: 13px; }
.stop-row strong { font-weight: 600; }
.chip { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: baseline; background: #6b7a8a; }
.chip-krl { background: #d9232d; }
.chip-mrt { background: #1b9a4a; }
.chip-lrt { background: #7b3fa0; }
.chip-brt { background: #0b6fb8; }
.chip-bus { background: #8d98a5; }
.weight-hint { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.factor.penalty h3 .val { color: #b3261e; font-weight: 600; }
.weight-warn { background: #fff7e0; border: 1px solid #e5c76b; border-radius: 6px; padding: 6px 10px; font-size: 13px; }
.detail h2 { font-size: 15px; margin: 0 0 2px; }
.detail .sub { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
.detail h2, .detail .sub { padding-right: 72px; }
.detail .close { position: absolute; top: 8px; right: 8px; }
.score { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.score .num {
  font-size: 30px; font-weight: 700; min-width: 64px; text-align: center; padding: 4px 8px;
  border-radius: 8px; border: 1px solid rgba(0,0,0,.25); color: #111;
}
.score .cap { font-size: 13px; color: var(--muted); }
.factor { padding: 8px 0; border-top: 1px solid var(--line); }
.factor h3 { font-size: 13px; margin: 0; display: flex; justify-content: space-between; gap: 8px; }
.factor .val { font-weight: 400; color: var(--muted); white-space: nowrap; }
.factor p { margin: 2px 0 0; font-size: 13px; }
.bar { height: 6px; background: #e8edf2; border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

.overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-content: center; gap: 12px;
  justify-items: center; background: rgba(255,255,255,.92); text-align: center; padding: 24px;
}
.overlay[hidden], .detail[hidden], .notice[hidden], .badge[hidden], .btn[hidden], .weight-warn[hidden] { display: none; }

dialog { max-width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; color: var(--fg); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; font-size: 17px; }
#about-body h3 { font-size: 14px; margin: 16px 0 4px; }
#about-body p, #about-body li { font-size: 13px; }
#about-body ul { padding-left: 18px; margin: 4px 0; }
#about-body .warn { background: #fff7e0; border: 1px solid #e5c76b; border-radius: 6px; padding: 8px 10px; }
