:root {
  --bg: #ffffff;
  --fg: #1c1917;
  --muted: #57534e;
  --border: #e7e5e4;
  --panel: rgba(255, 255, 255, 0.96);
  --accent: #0f766e;
  --ok: #16a34a;
  --wait: #eab308;
  --closed: #dc2626;
  --bus: #111111;
  --bus-fg: #ffffff;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0a09;
    --fg: #f5f5f4;
    --muted: #a8a29e;
    --border: #292524;
    --panel: rgba(28, 25, 23, 0.96);
    --accent: #2dd4bf;
    --bus: #f5f5f4;
    --bus-fg: #1c1917;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#map { position: fixed; inset: 0; background: var(--bg); }
.leaflet-tile-pane { filter: grayscale(1) contrast(0.9) brightness(1.04); }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: grayscale(1) invert(1) brightness(0.75) contrast(1.1); }
}

#panel {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1000;
  width: 320px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

#panel header {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

#panel-toggle {
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font-size: 18px;
  cursor: pointer;
}

h1 { margin: 0; font-size: 17px; }
h2 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.sub { margin: 0; font-size: 12px; color: var(--muted); }

#panel-body { overflow-y: auto; padding: 0 14px 12px; }
#panel.collapsed #panel-body { display: none; }

.clock { margin: 10px 0 0; font-variant-numeric: tabular-nums; color: var(--muted); }
.note { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.count { font-weight: 400; text-transform: none; letter-spacing: 0; }

.legend, .lines { list-style: none; margin: 0; padding: 0; }
.legend li { display: flex; gap: 8px; align-items: center; margin: 2px 0; }

.dot {
  flex: none;
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.15);
}
.dot.ok { background: var(--ok); }
.dot.wait { background: var(--wait); }
.dot.closed { background: var(--closed); }
.dot.ink { background: #1c1917; border-color: rgba(255, 255, 255, 0.5); }

.lines li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 6px 4px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  border-radius: 6px;
}
.lines li:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.lines .dot { margin-top: 4px; }
.lines .name { font-weight: 600; }
.lines .detail { display: block; font-size: 12px; color: var(--muted); }

.badge {
  flex: none;
  min-width: 26px;
  padding: 1px 5px;
  border-radius: 4px;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  text-align: center;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

footer { margin-top: 16px; font-size: 12px; color: var(--muted); }
footer a { color: var(--accent); }

.bus-icon {
  display: block;
  overflow: visible;
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.45));
  scale: var(--bus-scale, 1);
  transition: transform 0.4s ease, scale 0.2s;
}

.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content h3 { margin: 0 0 4px; font-size: 14px; }

@media (max-width: 640px) {
  #panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 55%;
    border-radius: 12px 12px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

.lines .detail.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.leaflet-control-layers,
.leaflet-bar a {
  background: var(--panel);
  color: var(--fg);
  border-color: var(--border);
}
.leaflet-control-layers { border-radius: 8px; font: inherit; }
.leaflet-control-layers-expanded { padding: 8px 12px; }
.leaflet-control-layers label { display: flex; gap: 6px; align-items: center; margin: 2px 0; }

.station-icon { display: flex; gap: 2px; }
.station-icon img {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  box-shadow: 0 0 0 1.5px #fff, 0 1px 3px rgba(0, 0, 0, 0.4);
}
.bus-stop-icon svg { display: block; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)); }
