:root {
  --bg: #ffffff;
  --fg: #1a1d21;
  --muted: #5b6470;
  --panel: #f5f6f8;
  --border: #d5d9df;
  --accent: #0b6bcb;
  --notice-bg: #fff4d6;
  --notice-fg: #4a3500;
  --notice-border: #e8c766;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --fg: #e6e9ed;
    --muted: #9aa4b0;
    --panel: #1d2127;
    --border: #343a43;
    --accent: #6cb2ff;
    --notice-bg: #3a2f10;
    --notice-fg: #f5deaa;
    --notice-border: #7a6320;
  }
  .leaflet-tile-pane { filter: brightness(0.72) contrast(1.05) saturate(0.85); }
  .leaflet-container { background: #1a1d21; }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  padding-top: max(6px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
#topbar h1 { font-size: 1.05rem; margin: 0; }
.tag {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
}
#panel-toggle {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  min-height: 36px;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#map { flex: 1; min-height: 200px; }
#panel {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  max-height: 42vh;
  overflow-y: auto;
}
#panel.hidden { display: none; }
#panel h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 10px 0 4px; }
#updated { margin: 0 0 8px; font-weight: 600; }
.notice {
  background: var(--notice-bg);
  color: var(--notice-fg);
  border: 1px solid var(--notice-border);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0;
  font-size: 0.9rem;
}
.small { font-size: 0.8rem; color: var(--muted); margin: 6px 0 0; }

#legend { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; gap: 2px; }
#legend label, .row { display: flex; align-items: center; gap: 8px; padding: 5px 0; min-height: 32px; cursor: pointer; }
#legend .count { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.35); flex: none; }
.swatch.square { border-radius: 2px; border: 2px dashed #111; background: #fff; }

footer {
  padding: 6px 12px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--panel);
}

/* Inferred heavy-rail railcars: square, dashed outline, "?" to signal inference. */
.railcar {
  width: 22px;
  height: 22px;
  border: 2px dashed #111;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  white-space: nowrap;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8);
}
.railcar-L { background: #0097d6; }
.railcar-B { background: #f26100; }
.railcar small { display: none; position: absolute; left: 26px; top: 2px; padding: 0 4px;
  background: rgba(255, 255, 255, 0.92); color: #111; border-radius: 3px; font-size: 10px; font-weight: 600; }
.zoomed .railcar small { display: inline; }

.popup h3 { margin: 0 0 4px; font-size: 0.95rem; }
.popup dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 1px 8px; font-size: 0.85rem; }
.popup dt { color: #666; }
.popup dd { margin: 0; }
.popup .inferred { margin: 6px 0 0; font-size: 0.8rem; color: #7a4b00; }

@media (min-width: 800px) {
  main { flex-direction: row; }
  #panel {
    order: 2;
    width: 320px;
    max-height: none;
    border-top: 0;
    border-left: 1px solid var(--border);
  }
}
