:root {
  color-scheme: light dark;
  --bg: #f6f5f1;
  --fg: #1d2127;
  --muted: #6b7380;
  --card: #fff;
  --line: #dcd9d0;
  --accent: #d7261e;
  --bar: #1d2127;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15181c; --fg: #e8e6e1; --muted: #98a0ab; --card: #1f2329; --line: #343a42; --bar: #0d0f12; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--fg); }
a { color: inherit; }
.muted { color: var(--muted); }

/* ---- top bar (all pages) */
.bar { height: 46px; display: flex; align-items: center; gap: 14px; padding: 0 12px; background: var(--bar); color: #fff; }
.bar .title { font-weight: 700; text-decoration: none; letter-spacing: .2px; }
.bar .title b { color: #ff5a4f; }
.bar nav { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.bar a.btn, .bar button.btn { color: #fff; text-decoration: none; border: 1px solid #ffffff44; background: transparent; border-radius: 8px; padding: 5px 10px; font: inherit; cursor: pointer; }
.bar .btn:hover { background: #ffffff1f; }
.bar .status { font-size: 12px; opacity: .7; white-space: nowrap; }

/* ---- departure tables, line badges, star */
a.line, .badge { display: inline-block; min-width: 2.2em; padding: 1px 6px; border-radius: 6px; color: #fff; font-weight: 700; text-align: center; text-decoration: none; }
table.departures { border-collapse: collapse; width: 100%; }
table.departures td { padding: 3px 6px 3px 0; vertical-align: baseline; }
table.departures .time, table.departures .diff { text-align: right; white-space: nowrap; }
table.departures .diff { font-weight: 600; min-width: 5.5em; }
table.departures tr.gone { opacity: .5; }
.detour { color: #b87400; cursor: help; }
button.star { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: #e2a400; padding: 0 4px; }

/* ---- plain pages (stop, favourites) */
main.page { max-width: 760px; margin: 0 auto; padding: 16px 12px 40px; }
main.page h1 { font-size: 24px; margin: 4px 0 2px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 12px 0; }
.card h2 { font-size: 17px; margin: 0 0 6px; display: flex; align-items: center; gap: 6px; }
.card h2 .grow { flex: 1; }
.card .links { font-size: 13px; }
input[type="search"] { width: 100%; padding: 9px 12px; font: inherit; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg); }
.results { list-style: none; margin: 6px 0 0; padding: 0; }
.results li { display: flex; align-items: center; gap: 6px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.results li a { flex: 1; text-decoration: none; }

/* ---- map page */
body.map { display: flex; flex-direction: column; }
#map { flex: 1; min-height: 0; }
#lines { position: absolute; z-index: 1000; top: 54px; left: 10px; width: min(330px, calc(100vw - 20px)); max-height: calc(100% - 70px); overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; box-shadow: 0 6px 24px #0004; }
#lines[hidden] { display: none; }
#lines p { margin: 0 0 8px; font-size: 13px; }
#line-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
#line-buttons button { min-width: 44px; padding: 7px 8px; border-radius: 8px; border: 2px solid var(--c); background: transparent; color: var(--fg); font: inherit; font-weight: 700; cursor: pointer; }
#line-buttons button[aria-pressed="true"] { background: var(--c); color: #fff; }
#lines .all { margin-top: 10px; font: inherit; border: 1px solid var(--line); background: transparent; color: var(--fg); border-radius: 8px; padding: 5px 10px; cursor: pointer; }

.tram { background: none; border: 0; }
.tram .badge { position: absolute; left: -15px; top: -11px; width: 30px; min-width: 0; padding: 2px 0; font-size: 13px; line-height: 17px; border: 2px solid #fff; box-shadow: 0 1px 4px #0006; }
.tram .dir { position: absolute; left: -22px; top: -22px; width: 44px; height: 44px; pointer-events: none; transition: transform .8s linear; }
.tram .dir i { position: absolute; left: 14px; top: -3px; border: 8px solid transparent; border-bottom: 11px solid var(--c, #333); border-top: 0; filter: drop-shadow(0 0 1px #fff); }
.tram.unknown-dir .dir { display: none; }
.leaflet-popup-content { margin: 10px 12px; min-width: 230px; color: #1d2127; }
.leaflet-popup-content h3 { margin: 0 0 4px; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.leaflet-popup-content table.departures td { color: #1d2127; }
.leaflet-popup-content .facts { margin: 6px 0 0; font-size: 13px; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.leaflet-popup-content .facts dt { color: #6b7380; }
.leaflet-popup-content .facts dd { margin: 0; }
.leaflet-popup-content .popup-links { margin-top: 6px; font-size: 13px; display: flex; gap: 12px; }

/* ---- reordering favourites */
button.grip { border: 0; background: none; color: var(--muted); font-size: 18px; letter-spacing: -3px; padding: 4px 6px; cursor: grab; touch-action: none; user-select: none; }
.card.dragging { opacity: .85; box-shadow: 0 8px 24px #0005; position: relative; z-index: 1; }
