*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #fff;
  color: #222;
}

body.dark {
  background: #1a1a1a;
  color: #eee;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #fff;
}

body.dark #map {
  background: #1a1a1a;
}

/* ── Loading overlay ─────────────────────────────────────────── */
#loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(2px);
  transition: opacity 0.4s ease;
  font-size: 13px;
  color: #444;
}

body.dark #loading-overlay {
  background: rgba(26, 26, 26, 0.72);
  color: #bbb;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── Station dots (white-filled black-ringed circles, tube-map style) ── */
.station-dot {
  background: #fff;
  border: 2.5px solid #222;
  border-radius: 50%;
  box-sizing: border-box;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.1s ease;
}

.station-dot:hover {
  transform: scale(1.5);
  background: #e8f4ff;
}

body.dark .station-dot {
  background: #1a1a1a;
  border-color: #eee;
}

body.dark .station-dot:hover {
  background: #2a3a4a;
}

/* ── Station labels ──────────────────────────────────────────── */
.station-label {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: #111;
  white-space: nowrap;
  text-shadow:
    -1px -1px 2px #fff,
     1px -1px 2px #fff,
    -1px  1px 2px #fff,
     1px  1px 2px #fff;
  transform: translate(10px, -6px);
}

.station-label span {
  display: inline-block;
}

body.dark .station-label {
  color: #eee;
  text-shadow:
    -1px -1px 2px #1a1a1a,
     1px -1px 2px #1a1a1a,
    -1px  1px 2px #1a1a1a,
     1px  1px 2px #1a1a1a;
}

/* ── Theme toggle button ─────────────────────────────────────── */
#theme-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid #ccc;
  background: #fff;
  color: #333;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  z-index: 1100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

body.dark #theme-toggle {
  background: #2a2a2a;
  color: #eee;
  border-color: #444;
}

/* ── Detail panel ─────────────────────────────────────────────── */
#detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100%;
  background: #fff;
  box-shadow: -3px 0 12px rgba(0, 0, 0, 0.18);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.dark #detail-panel {
  background: #2a2a2a;
  color: #eee;
}

#detail-panel.open {
  transform: translateX(0);
}

#detail-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #555;
  z-index: 1;
}

body.dark #detail-close { color: #aaa; }

#detail-close:hover { color: #000; }
body.dark #detail-close:hover { color: #fff; }

#detail-content {
  padding: 16px 16px 24px;
  overflow-y: auto;
  flex: 1;
}

/* ── Detail content typography ───────────────────────────────── */
.detail-header {
  margin-top: 4px;
  margin-bottom: 14px;
  padding-right: 24px;
}

.detail-line-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  margin-right: 6px;
}

.detail-line-name {
  font-size: 16px;
  font-weight: 600;
  vertical-align: middle;
}

.detail-meta {
  font-size: 13px;
  color: #555;
  margin-bottom: 4px;
}

body.dark .detail-meta { color: #bbb; }

.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #888;
  margin: 14px 0 6px;
}

.stop-list {
  list-style: none;
}

.stop-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  border-left: 2px solid #e0e0e0;
  padding-left: 10px;
  margin-left: 4px;
}

body.dark .stop-item { border-left-color: #444; }

.stop-item.next-stop {
  border-left-color: #e4032e;
  font-weight: 600;
}

.stop-item.next-stop .stop-name::before {
  content: "▶ ";
  color: #e4032e;
  font-size: 10px;
}

.stop-time {
  flex-shrink: 0;
  min-width: 44px;
  font-variant-numeric: tabular-nums;
  color: #333;
}

body.dark .stop-time { color: #ddd; }

.stop-name { flex: 1; color: #222; }
body.dark .stop-name { color: #eee; }

.stop-delay {
  flex-shrink: 0;
  color: #c00;
  font-size: 12px;
}

.stop-cancelled {
  color: #c00;
  font-style: italic;
}

.detail-error {
  color: #c00;
  font-size: 14px;
  margin-top: 12px;
}

/* ── Spinner ──────────────────────────────────────────────────── */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e0e0e0;
  border-top-color: #555;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Status bar ───────────────────────────────────────────────── */
#status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 28px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  z-index: 900;
  pointer-events: none;
}

#status-bar.warning {
  background: rgba(180, 60, 0, 0.75);
}

/* ── Train icon (Leaflet DivIcon) ─────────────────────────────── */
.train-icon {
  overflow: visible;
}

/* ── Station popup ────────────────────────────────────────────── */
/* ── Station popup ────────────────────────────────────────────── */
#station-popup[hidden] { display: none; }

#station-popup {
  position: fixed;
  display: flex;
  flex-direction: column;
  width: 460px;
  max-height: 420px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.28);
  z-index: 950;
  overflow: hidden;
}

body.dark #station-popup {
  background: #2a2a2a;
  color: #eee;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.55);
}

#station-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 0;
  flex-shrink: 0;
}

#station-popup-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

#station-popup-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #555;
  padding: 0 2px;
}

body.dark #station-popup-close { color: #aaa; }
#station-popup-close:hover { color: #000; }
body.dark #station-popup-close:hover { color: #fff; }

#station-popup-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 14px 0;
  flex-shrink: 0;
}

.sp-tab {
  padding: 5px 14px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #f5f5f5;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: #444;
  transition: background 0.1s;
}

.sp-tab:hover { background: #e8e8e8; }

.sp-tab.active {
  background: #222;
  color: #fff;
  border-color: #222;
}

body.dark .sp-tab {
  background: #3a3a3a;
  border-color: #555;
  color: #ccc;
}

body.dark .sp-tab:hover { background: #444; }

body.dark .sp-tab.active {
  background: #eee;
  color: #111;
  border-color: #eee;
}

#station-popup-track-row {
  padding: 6px 14px 0;
  font-size: 13px;
  flex-shrink: 0;
}

#station-popup-track-input {
  padding: 3px 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  margin-left: 6px;
  width: 60px;
}

body.dark #station-popup-track-input {
  background: #3a3a3a;
  border-color: #555;
  color: #eee;
}

#station-popup-board {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0 8px;
}

.sp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.sp-table thead th {
  position: sticky;
  top: 0;
  background: #fff;
  padding: 4px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #888;
  border-bottom: 1px solid #e0e0e0;
}

body.dark .sp-table thead th {
  background: #2a2a2a;
  color: #666;
  border-bottom-color: #444;
}

.sp-table tbody tr:hover { background: #f5f5f5; }
body.dark .sp-table tbody tr:hover { background: #333; }

.sp-table td {
  padding: 5px 10px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}

body.dark .sp-table td { border-bottom-color: #3a3a3a; }

.sp-time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.sp-rt {
  font-size: 9px;
  color: #aaa;
  padding-right: 4px !important;
}

.sp-line {
  font-weight: 700;
  min-width: 36px;
}

.sp-dest { color: #333; }
body.dark .sp-dest { color: #ccc; }

.sp-track {
  text-align: center;
  min-width: 32px;
  font-variant-numeric: tabular-nums;
  color: #666;
}

body.dark .sp-track { color: #999; }

.sp-delay {
  color: #c00;
  font-size: 11px;
  font-weight: 600;
  margin-left: 4px;
}

.sp-early {
  color: #090;
  font-size: 11px;
  font-weight: 600;
  margin-left: 4px;
}

.sp-row-cancelled td { opacity: 0.45; text-decoration: line-through; }

.sp-empty, .sp-error {
  padding: 20px 16px;
  font-size: 13px;
  color: #888;
  text-align: center;
}

/* Leaflet attribution — keep small */
.leaflet-control-attribution { display: none; }
