/* OpenFreeMap-like site chrome + RR overlay */
:root {
  --text: #1a1a1a;
  --muted: #5a6570;
  --line: #e4e7eb;
  --bg: #fafbfc;
  --card: #fff;
  --accent: #1e4a7a;
  --ofm: #2d6a4f;
  --btn-hover-border: #bbb;
  --code-bg: #eef1f4;
  --sheet-bg: rgba(255, 255, 255, 0.98);
  --sheet-border: rgba(0, 0, 0, 0.06);
  --data-note-bg: #fff6ee;
  --data-note-border: #f0d4bc;
  --data-note-text: #5a4030;
  --notify-bg: #fff3cd;
  --notify-border: #e6c200;
  --notify-text: #5c4b00;
  --access-bg: #eef4fb;
  --access-border: #c5d6ea;
  --empty-bg: #f4f6f9;
  --near-bg: #e8f5ee;
  --near-border: #a8d5b5;
  --near-title: #1a7f4b;
  --credits-box-bg: #eef6f1;
  --credits-box-border: #c5e0d0;
  --drawer-bg: #fff;
  --topbar-bg: #0f2744;
  --topbar-text: #f0f4f8;
  --topbar-sub: #9aabbc;
  --grip: #c5cdd6;
  --shadow: rgba(0, 0, 0, 0.18);
}

/* Default passenger UI: dark (toggle can switch to light) */
html.theme-dark,
html.theme-dark body,
body.theme-dark {
  --text: #e8eef5;
  --muted: #9aabbc;
  --line: #2a3a4d;
  --bg: #0b1522;
  --card: #142033;
  --accent: #6db3e8;
  --ofm: #3d9b6e;
  --btn-hover-border: #4a5d72;
  --code-bg: #1a2a3d;
  --sheet-bg: rgba(20, 32, 51, 0.97);
  --sheet-border: rgba(255, 255, 255, 0.08);
  --data-note-bg: rgba(196, 92, 38, 0.22);
  --data-note-border: rgba(196, 92, 38, 0.4);
  --data-note-text: #f0dcc8;
  --notify-bg: rgba(230, 194, 0, 0.15);
  --notify-border: rgba(230, 194, 0, 0.4);
  --notify-text: #f5e6a8;
  --access-bg: rgba(30, 74, 122, 0.3);
  --access-border: rgba(197, 214, 234, 0.28);
  --empty-bg: rgba(255, 255, 255, 0.04);
  --near-bg: rgba(26, 127, 75, 0.2);
  --near-border: rgba(168, 213, 181, 0.35);
  --near-title: #5ddea0;
  --credits-box-bg: rgba(45, 106, 79, 0.22);
  --credits-box-border: rgba(168, 213, 181, 0.3);
  --drawer-bg: #142033;
  --topbar-bg: #081018;
  --topbar-text: #f0f4f8;
  --topbar-sub: #8fa0b3;
  --grip: #5a6570;
  --shadow: rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}
html.theme-light {
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--accent); }
.site-header {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 20px 8px;
  text-align: center;
}
.brand-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.logo-mark { font-size: 48px; line-height: 1; }
.site-header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.tagline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 36em;
}
.intro, .how {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 20px 20px;
}
.intro h2, .how h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}
.intro p, .how p, .how li { color: var(--muted); font-size: 0.95rem; }
.button-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 10px;
}
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--btn-hover-border); }
.btn.selected {
  background: var(--ofm);
  border-color: var(--ofm);
  color: #fff;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
html.theme-dark .btn.primary {
  color: #061018;
}
.style-url-line {
  font-size: 0.85rem;
  color: var(--muted);
}
.style-url-line code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
  word-break: break-all;
  color: var(--text);
}
#map-wrap {
  position: relative;
  max-width: 1100px;
  margin: 0 auto 28px;
  padding: 0 12px;
}
#map-container {
  width: 100%;
  height: min(70vh, 640px);
  min-height: 420px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  border: 1px solid var(--line);
  position: relative;
}
.rr-card {
  position: absolute;
  z-index: 2;
  top: 16px;
  left: 28px;
  width: min(320px, calc(100% - 56px));
  background: var(--sheet-bg);
  color: var(--text);
  border-radius: 12px;
  box-shadow: 0 6px 28px var(--shadow);
  border: 1px solid var(--sheet-border);
  padding: 14px 16px;
  max-height: calc(100% - 32px);
  overflow: auto;
  font-size: 0.88rem;
}
.rr-card h3 { margin: 0 0 8px; font-size: 1rem; }
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 999px;
  background: #ffe8d6;
  color: #8a3b00;
}
.badge.live { background: #d8f5e4; color: #0a5c32; }
html.theme-dark .badge {
  background: rgba(255, 180, 100, 0.22);
  color: #ffd7a8;
}
html.theme-dark .badge.live {
  background: rgba(26, 127, 75, 0.35);
  color: #9eecc0;
}
.msg { margin: 8px 0; color: var(--muted); font-size: 0.82rem; }
.muted { color: var(--muted); }
.tiny { font-size: 0.75rem; }

/* Honesty / freshness banner */
.data-freshness {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
  border: 1px solid var(--line);
  background: var(--empty-bg);
  color: var(--text);
}
.data-freshness.is-fresh {
  background: rgba(26, 127, 75, 0.14);
  border-color: rgba(26, 127, 75, 0.35);
  color: var(--near-title);
}
html.theme-light .data-freshness.is-fresh {
  color: #0a5c32;
}
.data-freshness.is-stale {
  background: var(--notify-bg);
  border-color: var(--notify-border);
  color: var(--notify-text);
}
.data-freshness.is-error {
  background: rgba(180, 40, 40, 0.15);
  border-color: rgba(200, 70, 70, 0.45);
  color: #f0b4b4;
}
html.theme-light .data-freshness.is-error {
  background: #fdeaea;
  border-color: #e8a0a0;
  color: #8a1f1f;
}
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.actions .btn { padding: 6px 10px; font-size: 0.78rem; }
#vehicle-list { margin-top: 8px; }
.v-row {
  padding: 6px 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.v-row:hover { color: var(--accent); }
#timetable { margin-top: 10px; }
#timetable table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
#timetable th, #timetable td {
  text-align: left;
  padding: 4px 2px;
  border-bottom: 1px solid var(--line);
}
.pin {
  width: 14px; height: 14px; border-radius: 50%;
  background: #2f80ed; border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(47,128,237,0.4);
}
.pin.demo {
  background: #c45c26;
  box-shadow: 0 0 0 2px rgba(196,92,38,0.4);
}
.pickup {
  width: 12px; height: 12px;
  background: #e8c547; border: 2px solid #fff;
  transform: rotate(45deg);
}
.how ul { padding-left: 1.2em; }
@media (max-width: 720px) {
  .rr-card {
    position: absolute;
    top: auto;
    bottom: 16px;
    left: 20px;
    right: 20px;
    width: auto;
    max-height: 38%;
  }
  #map-container { min-height: 360px; height: 55vh; }
}
.rr-card .muted,
.rr-card .msg { color: var(--muted); }
.rr-card .v-row { border-top-color: var(--line); }

/* Credits footer — OpenFreeMap attribution as requested by the project */
.credits {
  max-width: 960px;
  margin: 0 auto 48px;
  padding: 24px 20px 40px;
  border-top: 1px solid var(--line);
}
.credits h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}
.credits p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 48em;
}
.credits-required {
  color: var(--text) !important;
  font-size: 0.95rem !important;
  padding: 12px 14px;
  background: var(--credits-box-bg);
  border: 1px solid var(--credits-box-border);
  border-radius: 10px;
}
.credits a { font-weight: 600; }
.logo-mark {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(145deg, #2d6a4f, #1e4a7a);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.02em;
}

/* Passenger pilot card */
.alert-banner {
  display: inline-block;
  background: #c45c26;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
}
.route-title { margin: 0 0 6px; font-size: 0.95rem; line-height: 1.3; }
.fact-list {
  margin: 8px 0 10px;
  padding-left: 1.1em;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}
.fact-list li { margin-bottom: 4px; }
.fact-list strong { color: var(--text); }
.data-note {
  font-size: 0.75rem;
  background: var(--data-note-bg);
  border: 1px solid var(--data-note-border);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0;
  color: var(--data-note-text);
  line-height: 1.35;
}
.list-head {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 8px 0 4px;
}
.tt-head { margin-bottom: 6px; font-size: 0.85rem; }

.pin.rr {
  background: #1a7f4b !important;
  box-shadow: 0 0 0 2px rgba(26, 127, 75, 0.55) !important;
}
.legend-row { font-size: 0.75rem; margin: 6px 0 8px; color: var(--muted); line-height: 1.4; }
.legend-row .swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 4px; vertical-align: middle; border: 1px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.12);
}
.swatch.rr { background: #1a7f4b; }
.swatch.station { background: #e8c547; border-radius: 2px; }
.swatch.corridor { background: #c45c26; border-radius: 2px; height: 4px; width: 14px; vertical-align: middle; }
.notify-banner {
  background: var(--notify-bg);
  border: 1px solid var(--notify-border);
  color: var(--notify-text);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  font-size: 0.8rem;
  line-height: 1.4;
}
.access-box {
  background: var(--access-bg);
  border: 1px solid var(--access-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0;
  font-size: 0.8rem;
  color: var(--text);
}
.access-box strong { display: block; margin-bottom: 4px; }
.empty-rb {
  background: var(--empty-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--text);
}
.empty-rb ol { margin: 8px 0 0; }
.rb-tag {
  display: inline-block;
  background: #1a7f4b;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  vertical-align: middle;
  letter-spacing: 0.03em;
}

/* Station RB zone popups — dark panel, light text (readable on map) */
.maplibregl-popup-content {
  padding: 0;
  border-radius: 12px;
  background: #142033;
  color: #f0f4f8;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.maplibregl-popup-close-button {
  color: #f0f4f8;
  font-size: 18px;
  padding: 4px 8px;
  right: 2px;
  top: 2px;
}
.maplibregl-popup-close-button:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}
.maplibregl-popup-tip {
  border-top-color: #142033 !important;
  border-bottom-color: #142033 !important;
}
.rb-popup {
  font-size: 13px;
  line-height: 1.45;
  color: #e8eef5;
  max-width: 300px;
  padding: 14px 16px 14px 14px;
}
.rb-popup strong {
  color: #ffffff;
  font-size: 15px;
}
.rb-popup p { margin: 8px 0; color: #d0dae6; }
.rb-popup ol {
  margin: 4px 0 10px;
  padding-left: 1.25em;
  color: #d0dae6;
}
.rb-popup li { margin-bottom: 4px; }
.rb-popup .rb-zone-title {
  font-weight: 800;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5ddea0;
  margin: 8px 0 6px;
}
.rb-popup .tiny {
  font-size: 11px;
  color: #9aabbc;
}
.rb-popup a {
  color: #7ec8ff;
  font-weight: 600;
  text-decoration: underline;
}
.rb-popup a:hover { color: #b3e0ff; }

@media (max-width: 720px) {
  .rr-card {
    max-height: 36vh;
    font-size: 0.82rem;
    padding: 10px 12px;
  }
  .rr-card .actions .btn {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 0.85rem;
  }
  #map-container {
    height: 58vh !important;
    min-height: 320px;
  }
  .site-header { padding: 16px 14px 4px; }
  .intro { padding: 8px 14px 12px; }
  .button-container .btn { min-height: 36px; }
  #timetable table { font-size: 0.8rem; }
  #timetable th, #timetable td { padding: 6px 4px; }
}
.near-station {
  margin: 10px 0;
  padding: 10px 12px;
  background: var(--near-bg);
  border: 1px solid var(--near-border);
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text);
}
.near-station .near-inner .btn { margin-top: 6px; margin-right: 4px; }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
  border-top-color: #142033 !important;
}
.maplibregl-popup-anchor-top .maplibregl-popup-tip {
  border-bottom-color: #142033 !important;
}
/* Short map tip — full text lives in left panel */
.rb-popup.rb-popup-tip {
  max-width: 200px;
  padding: 10px 12px;
  font-size: 12px;
}
.rb-popup.rb-popup-tip p { margin: 4px 0 0; }

/* Station detail in side panel — always readable without moving map */
.near-station {
  position: relative;
  z-index: 2;
  max-height: none;
}
.near-inner .rb-zone-title {
  font-weight: 800;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--near-title);
  margin: 8px 0 6px;
}

/* =========================================================
   Mobile-first passenger shell (iPhone) + top bar / sheet
   ========================================================= */

.mobile-only { display: none !important; }
.desktop-only { display: block; }
.button-container.desktop-only,
.actions-secondary .desktop-only { display: inline-flex !important; }

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--topbar-bg);
  color: var(--topbar-text);
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  box-shadow: 0 2px 12px rgba(0,0,0,.2);
}
.top-bar-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.theme-toggle {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: var(--topbar-text);
  border-radius: 999px;
  min-height: 36px;
  min-width: 36px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  outline: none;
}
.theme-toggle .theme-icon {
  display: inline-block;
  margin-right: 4px;
}
@media (max-width: 420px) {
  .theme-toggle .theme-label { display: none; }
  .theme-toggle .theme-icon { margin-right: 0; }
}
.top-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.top-bar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-sub {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--topbar-sub);
}
.logo-mark-sm {
  width: 36px;
  height: 36px;
  font-size: 12px;
  border-radius: 10px;
  flex-shrink: 0;
}
.top-status {
  flex-shrink: 0;
  max-width: 46%;
  text-align: center;
  white-space: normal;
  line-height: 1.2;
}

/* Sheet handle (mobile) */
.sheet-handle {
  display: none;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 10px 12px 6px;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.sheet-grip {
  display: block;
  width: 40px;
  height: 5px;
  border-radius: 99px;
  background: var(--grip);
  margin: 0 auto 8px;
}
.sheet-handle-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}
.sheet-status-line {
  display: block;
  margin-top: 6px;
  padding: 0 6px;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}
.sheet-title { margin: 0 0 8px; color: var(--text); }
.situation-line {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(196, 92, 38, 0.16);
  border: 1px solid rgba(196, 92, 38, 0.35);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.35;
}
html.theme-light .situation-line {
  background: #fff4ec;
  border-color: #f0c9a8;
  color: #5a2e0a;
}
.actions-utility {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}
.actions-utility .btn {
  min-height: 40px;
  width: 100%;
  font-size: 0.8rem;
  margin: 0;
}
.btn.is-busy,
.btn:disabled {
  opacity: 0.7;
  cursor: wait;
}
.station-list {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
}
.station-list-head {
  margin: 0;
  padding: 10px 12px 6px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.station-list-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 12px 12px;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.station-list-btn:hover,
.station-list-btn:focus-visible {
  background: rgba(109, 179, 232, 0.12);
  outline: none;
}
.station-list-btn .role {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}
.official-links {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--empty-bg);
}
.official-links a {
  display: inline-block;
  margin: 4px 8px 4px 0;
  font-weight: 600;
  font-size: 0.85rem;
}
.install-hint {
  margin: 8px 0 4px;
  line-height: 1.4;
}
.fail-soft {
  margin: 14px 0 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  background: var(--empty-bg);
  font-size: 0.8rem;
  color: var(--muted);
}
.fail-soft strong {
  display: block;
  color: var(--text);
  margin-bottom: 6px;
  font-size: 0.82rem;
}
.fail-soft ol {
  margin: 0;
  padding-left: 1.2em;
}
.fail-soft li { margin-bottom: 4px; }
.share-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(8, 16, 24, 0.92);
  color: #f0f4f8;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.more-drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: env(safe-area-inset-top) 0 0;
}
.more-drawer[hidden] { display: none !important; }
.more-drawer-inner {
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow: auto;
  background: var(--drawer-bg);
  color: var(--text);
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 32px rgba(0,0,0,.25);
}
.more-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.more-drawer h3 { margin: 14px 0 8px; font-size: 1rem; }
.more-drawer .theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.more-drawer .theme-row p {
  margin: 0;
  font-size: 0.88rem;
}

/* ---- Phone layout ----
   Portrait: max-width 720px.
   Landscape: short height (phone rotated) — width is often >720px so max-width alone fails.
*/
@media (max-width: 720px), (max-height: 520px) and (orientation: landscape) {
  html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background: #0b1522;
  }

  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex !important; }

  .top-bar h1 { font-size: 0.98rem; }

  #map-wrap {
    position: fixed;
    left: 0;
    right: 0;
    top: calc(56px + env(safe-area-inset-top));
    bottom: 0;
    max-width: none;
    margin: 0;
    padding: 0;
  }

  #map-container {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    border-radius: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
  }

  /* Bottom sheet instead of floating side card */
  .rr-card.sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-width: none;
    max-height: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 28px rgba(0,0,0,.28);
    border: 0;
    border-top: 1px solid rgba(0,0,0,.06);
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--sheet-bg);
    /* collapsed height — status one-liner + primary actions */
    height: calc(220px + env(safe-area-inset-bottom));
    transition: height 0.25s ease, width 0.25s ease;
    z-index: 5;
  }
  .rr-card.sheet[data-sheet="expanded"] {
    height: min(78dvh, 640px);
  }

  .sheet-handle { display: block; }
  .sheet-body {
    flex: 1 1 auto;
    min-height: 0; /* critical: let flex child scroll */
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 0 14px calc(16px + env(safe-area-inset-bottom));
  }
  .rr-card.sheet[data-sheet="collapsed"] .sheet-body {
    overflow: hidden;
  }
  /* In collapsed mode, clip to summary */
  .rr-card.sheet[data-sheet="collapsed"] #vehicle-list,
  .rr-card.sheet[data-sheet="collapsed"] #timetable,
  .rr-card.sheet[data-sheet="collapsed"] #station-list,
  .rr-card.sheet[data-sheet="collapsed"] #official-links,
  .rr-card.sheet[data-sheet="collapsed"] #near-station,
  .rr-card.sheet[data-sheet="collapsed"] .fail-soft,
  .rr-card.sheet[data-sheet="collapsed"] .access-box,
  .rr-card.sheet[data-sheet="collapsed"] .fact-list,
  .rr-card.sheet[data-sheet="collapsed"] .legend-row,
  .rr-card.sheet[data-sheet="collapsed"] .foot-note,
  .rr-card.sheet[data-sheet="collapsed"] .install-hint,
  .rr-card.sheet[data-sheet="collapsed"] .actions-secondary,
  .rr-card.sheet[data-sheet="collapsed"] .actions-utility,
  .rr-card.sheet[data-sheet="collapsed"] #data-freshness,
  .rr-card.sheet[data-sheet="collapsed"] #situation-line,
  .rr-card.sheet[data-sheet="collapsed"] #msg,
  .rr-card.sheet[data-sheet="collapsed"] #corridor {
    display: none;
  }
  /* Collapsed: status in handle + primary actions only */
  .rr-card.sheet[data-sheet="collapsed"] .sheet-title {
    display: none;
  }
  .rr-card.sheet[data-sheet="collapsed"] .sheet-body > .tiny:not(.foot-note) {
    display: none;
  }
  .rr-card.sheet[data-sheet="collapsed"] .actions-primary {
    margin-top: 0;
  }
  .rr-card.sheet[data-sheet="collapsed"] #corridor .msg,
  .rr-card.sheet[data-sheet="collapsed"] #corridor .data-note {
    display: none;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 10px 0;
  }
  .actions .btn {
    min-height: 44px;
    width: 100%;
    justify-content: center;
    font-size: 0.88rem;
    margin: 0;
  }
  .actions-primary { margin-top: 8px; }

  .maplibregl-ctrl-top-right {
    top: 8px;
    right: 8px;
  }
  .maplibregl-ctrl-bottom-right {
    bottom: calc(210px + env(safe-area-inset-bottom));
  }

  .actions-utility {
    grid-template-columns: 1fr 1fr;
  }
  .actions-utility #btn-tts-stop {
    grid-column: 1 / -1;
  }
}

/* When sheet expanded on mobile, push attribution higher via body class */
@media (max-width: 720px), (max-height: 520px) and (orientation: landscape) {
  body.sheet-expanded .maplibregl-ctrl-bottom-right {
    bottom: calc(55dvh);
  }
}

/* Landscape phone: side panel so details can scroll without fighting the map */
@media (max-height: 520px) and (orientation: landscape) {
  .top-bar {
    padding: 6px 12px;
    padding-top: max(6px, env(safe-area-inset-top));
  }
  .top-bar h1 { font-size: 0.9rem; }
  .logo-mark-sm {
    width: 30px;
    height: 30px;
    font-size: 11px;
  }

  #map-wrap {
    top: calc(44px + env(safe-area-inset-top));
  }

  .rr-card.sheet {
    left: auto;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(340px, 46vw);
    height: 100% !important;
    border-radius: 14px 0 0 14px;
    border-top: 0;
    border-left: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.22);
  }

  /* Collapsed = thin strip with handle only */
  .rr-card.sheet[data-sheet="collapsed"] {
    width: 52px;
  }
  .rr-card.sheet[data-sheet="collapsed"] .sheet-body {
    display: none;
  }
  .rr-card.sheet[data-sheet="collapsed"] .sheet-handle {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 14px 6px;
    gap: 10px;
  }
  .rr-card.sheet[data-sheet="collapsed"] .sheet-grip {
    width: 5px;
    height: 36px;
    margin: 0;
  }
  .rr-card.sheet[data-sheet="collapsed"] .sheet-handle-label {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    white-space: nowrap;
    font-size: 0.72rem;
  }
  .rr-card.sheet[data-sheet="collapsed"] .sheet-status-line {
    display: none;
  }

  .rr-card.sheet[data-sheet="expanded"] {
    width: min(360px, 52vw);
    height: 100% !important;
  }

  .sheet-body {
    padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  }

  .actions {
    grid-template-columns: 1fr 1fr;
  }
  .actions .btn {
    min-height: 40px;
    font-size: 0.82rem;
  }

  .maplibregl-ctrl-bottom-right {
    bottom: 12px;
    right: calc(min(340px, 46vw) + 8px);
  }
  body.sheet-expanded .maplibregl-ctrl-bottom-right {
    bottom: 12px;
    right: calc(min(360px, 52vw) + 8px);
  }
}

/* Timetable in dark UI */
#timetable table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
}
#timetable th,
#timetable td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 6px 4px;
}
#timetable th { color: var(--muted); font-size: 0.75rem; }

/* MapLibre controls readable on both themes */
.maplibregl-ctrl-group {
  background: var(--card) !important;
  border: 1px solid var(--line) !important;
}
.maplibregl-ctrl-group button {
  background-color: var(--card) !important;
}
html.theme-dark .maplibregl-ctrl-group button + button {
  border-top-color: var(--line) !important;
}
html.theme-dark .maplibregl-ctrl button .maplibregl-ctrl-icon {
  filter: invert(1) brightness(1.1);
}