:root {
  --bg: #111418;
  --surface: #1a1e24;
  --text: #eef0f3;
  --muted: #8b93a1;
  --border: #2a3039;
  --accent: #f5c400; /* Föli yellow */
  --accent-text: #14171c;
  --live: #22c55e;
  --late: #f87171;
  --early: #60a5fa;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

main { max-width: 640px; margin: 0 auto; padding: 0 16px 32px; }

.tabs {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tabs a {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
}
.tabs a[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.tabs a:last-child { margin-left: auto; }

.head { padding: 20px 0 12px; }
.head h1 { margin: 0; font-size: 26px; letter-spacing: -0.01em; }
.status { margin: 4px 0 0; color: var(--muted); font-size: 13px; min-height: 1.35em; }
.status.error, .meta.error { color: var(--late); }

.departures { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.dep {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.dep.missed { opacity: 0.4; }

.line {
  display: grid;
  place-items: center;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.info { min-width: 0; display: grid; gap: 2px; }
.dest { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 1.35em; }

.live {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .live { animation: none; } }

.late { color: var(--late); font-weight: 600; }
.early { color: var(--early); font-weight: 600; }

.eta { text-align: right; display: grid; gap: 2px; font-variant-numeric: tabular-nums; }
.mins { font-size: 20px; font-weight: 800; white-space: nowrap; }
.clock { color: var(--muted); font-size: 13px; }

.empty { color: var(--muted); text-align: center; padding: 32px 0; }

.finder input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.finder input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.finder-list { list-style: none; margin: 12px 0 0; padding: 0; }
.finder-list a {
  display: flex;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}
.stop-id { min-width: 48px; color: var(--muted); font-variant-numeric: tabular-nums; }

.dep { cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform 0.1s; }
.dep:active { transform: scale(0.985); }
.dep:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Map sheet */
body.map-open { overflow: hidden; }

.map-sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.map-sheet[hidden] { display: none; }

.map-head {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.map-close {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.map { flex: 1; }
/* Match the OpenFreeMap dark style's background so unrendered areas don't flash Leaflet's #ddd
   (leaflet.css loads after this file, hence the extra class for specificity) */
.map.leaflet-container { background: #0c0c0c; }


/* .leaflet-marker-icon prefix: leaflet.css loads after this file and sets display:block */
.leaflet-marker-icon.bus-marker {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font: 800 15px/1 system-ui, -apple-system, sans-serif;
  border: 3px solid var(--text);
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.35);
}
.leaflet-marker-icon.bus-marker.stale { opacity: 0.55; border-style: dashed; }

/* Update timer: last update time over a draining ring + seconds to next poll */
.map-sync {
  display: grid;
  justify-items: end;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.map-next { display: inline-flex; align-items: center; gap: 4px; min-width: 40px; justify-content: flex-end; }
.ring { width: 12px; height: 12px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 2.5; }
.ring-track { stroke: var(--border); }
.ring-fill {
  stroke: var(--muted);
  stroke-dasharray: 37.7; /* 2πr, r=6 */
  stroke-dashoffset: 0;
  animation: ring-drain linear forwards;
}
@keyframes ring-drain { to { stroke-dashoffset: 37.7; } }
.map-sync.syncing .ring-fill { animation: none; stroke-dashoffset: 0; stroke: var(--accent); }
@media (prefers-reduced-motion: reduce) { .ring-fill { animation: none; } }

/* Route: whole trip muted, the stretch you ride highlighted */
.route-dim-casing { stroke: var(--muted); stroke-opacity: 0.7; fill: none; }
.route-dim { stroke: #07080a; fill: none; }
.route-casing { stroke: #14171c; stroke-opacity: 0.35; fill: none; }
.route-ride { stroke: var(--accent); fill: none; }

.stop-dot { stroke: var(--text); fill: var(--surface); }
.stop-dot.off-ride { stroke: var(--muted); fill: #07080a; }

.stop-key.stop-start { stroke: #fff; fill: var(--accent); }
.stop-key.stop-end { stroke: var(--accent); fill: #14171c; }

.leaflet-tooltip.stop-label {
  padding: 2px 8px;
  border: 0;
  border-radius: 6px;
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.3);
  font: 700 12px/1.4 system-ui, -apple-system, sans-serif;
}
.leaflet-tooltip.stop-label::before { display: none; }
.leaflet-tooltip.stop-label-start { background: var(--accent); color: #14171c; }
.leaflet-tooltip.stop-label-end { background: #14171c; color: #fff; }

.leaflet-container .leaflet-control-attribution {
  background: rgb(17 20 24 / 0.75);
  color: var(--muted);
  font-size: 10px;
  padding: 1px 6px;
  border-top-left-radius: 6px;
}
.leaflet-container .leaflet-control-attribution a { color: var(--muted); }

/* Map bottom bar: location status + arrival at destination */
.map-foot {
  display: grid;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.map-foot-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; }

.map-live { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.map-live[hidden], .map-eta[hidden] { display: none; }

.map-eta { margin-left: auto; display: grid; justify-items: end; text-align: right; }
.map-eta-label { color: var(--muted); font-size: 12px; }
.map-eta-value { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
.map-eta-value strong { font-size: 24px; font-weight: 800; letter-spacing: -0.01em; }
#map-eta-mins { color: var(--muted); font-size: 14px; font-weight: 600; }

.map-alert {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #dc2626;
  color: #fff;
  font-size: 13px;
  line-height: 1.3;
}
.map-alert[hidden] { display: none; }
.map-alert strong { display: block; font-size: 16px; font-weight: 800; }
.map-alert-icon { flex: none; width: 28px; height: 28px; }
