:root {
  --bg: #EEF2F5;
  --card: #FFFFFF;
  --ink: #13212E;
  --muted: #5C6C7B;
  --line: #DDE4EA;
  --route: #B8236E;
  --amber: #9E6205;
  --slate: #4E6476;
  --shadow: 0 14px 36px rgba(19, 33, 46, 0.16), 0 2px 6px rgba(19, 33, 46, 0.08);
  --display: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;
  --text: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1821;
    --card: #14212C;
    --ink: #E6EDF3;
    --muted: #93A4B3;
    --line: #243646;
    --route: #F06AA6;
    --amber: #E7A740;
    --slate: #A2B5C5;
    --shadow: 0 14px 36px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }

#map { position: fixed; inset: 0; background: var(--bg); }

/* ---------- Status card ---------- */
.card {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  max-height: 62vh;
  overflow-y: auto;
  z-index: 500;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px 18px 14px;
}
@media (min-width: 760px) {
  .card { left: 16px; right: auto; top: 16px; bottom: auto; width: 384px; max-height: calc(100vh - 32px); padding: 20px 22px 16px; }
}

.card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font: 600 15px/1 var(--display); color: var(--muted); letter-spacing: 0.01em; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 10px 5px 9px;
  border-radius: 999px;
  font: 600 13px/1 var(--text);
  color: var(--slate);
  background: color-mix(in srgb, var(--slate) 12%, transparent);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.is-air { color: var(--route); background: color-mix(in srgb, var(--route) 12%, transparent); }
.pill.is-away { color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, transparent); }
.pill.is-air .dot { animation: pulse 2s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--route) 55%, transparent); }
  100% { box-shadow: 0 0 0 8px transparent; }
}

.status { margin-top: 14px; }
h1 {
  margin: 0;
  font: 700 30px/1.08 var(--display);
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.place { margin: 6px 0 0; font: 600 19px/1.25 var(--display); }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
.place:empty, .sub:empty { display: none; }

/* ---------- Route progress: the one bold element ---------- */
.route { margin-top: 16px; }
.route-ends { display: flex; justify-content: space-between; gap: 16px; font: 600 15px/1.2 var(--display); }
.route-ends span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 48%; }
.route-ends span:last-child { text-align: right; }
.route-track { position: relative; height: 26px; margin-top: 4px; }
.route-track::before {
  content: ""; position: absolute; left: 0; right: 0; top: 12px; height: 2px;
  background-image: linear-gradient(90deg, var(--line) 50%, transparent 50%);
  background-size: 8px 2px;
}
.route-fill { position: absolute; left: 0; top: 11px; height: 4px; border-radius: 2px; background: var(--route); width: 0; }
.route-plane {
  position: absolute; top: 2px; width: 22px; height: 22px; left: 0;
  margin-left: -11px; fill: var(--route); transform: rotate(90deg);
  stroke: var(--card); stroke-width: 1.4; paint-order: stroke;
}
.route.is-away .route-fill { background: var(--amber); }
.route.is-away .route-plane { fill: var(--amber); }

/* ---------- Numbers ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0 0; }
.stats div { min-width: 0; }
.stats dt { color: var(--muted); font-size: 13px; }
.stats dd { margin: 2px 0 0; font: 600 21px/1.15 var(--display); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats dd.stat-note { font: 400 13px/1.3 var(--text); color: var(--muted); white-space: normal; }
.stats dd.stat-note:empty { display: none; }

.plans { margin: 16px 0 0; }
.plan { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 10px 0; border-top: 1px solid var(--line); }
.plan dt { color: var(--muted); font-size: 15px; flex: none; }
.plan dd { margin: 0; font: 600 19px/1.2 var(--display); text-align: right; overflow-wrap: anywhere; }

.card-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }
.credits a { text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); text-underline-offset: 2px; }

/* ---------- Map pieces ---------- */
.plane-icon svg {
  width: 38px; height: 38px; display: block;
  fill: var(--route); stroke: var(--card); stroke-width: 1.3; paint-order: stroke;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
}
.plane-icon.is-ground svg { fill: var(--slate); }
.plane-icon.is-estimated svg { fill: var(--amber); opacity: 0.75; }
.plane-rot { width: 38px; height: 38px; }

path.trail { stroke: var(--route); stroke-opacity: 0.9; fill: none; }
path.trail-guess { stroke: var(--amber); stroke-opacity: 0.9; fill: none; }
path.ahead { stroke: var(--muted); stroke-opacity: 0.7; fill: none; }
path.dest { stroke: var(--card); stroke-width: 2.5; fill: var(--ink); fill-opacity: 1; }
path.origin { stroke: var(--card); stroke-width: 2; fill: var(--route); fill-opacity: 1; }
path.last-known { stroke: var(--card); stroke-width: 2; fill: var(--amber); fill-opacity: 1; }

.leaflet-tooltip.map-label {
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); font: 600 13px/1.2 var(--text); padding: 4px 8px;
}
.leaflet-tooltip.map-label::before { display: none; }

.leaflet-container { font-family: var(--text); background: var(--bg); }
/* Calm down OpenStreetMap's busy colors; flip them for dark mode */
.leaflet-tile-pane { filter: saturate(0.3) contrast(0.92) brightness(1.04); }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) saturate(0.35) brightness(0.8) contrast(0.95); }
}
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--card) 80%, transparent) !important;
  color: var(--muted) !important; font-size: 10.5px; border-radius: 6px 0 0 6px;
}
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--card); color: var(--ink); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--bg); }

.recenter {
  position: fixed; top: 12px; left: 12px; z-index: 600;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink);
  font: 600 14px/1 var(--text); padding: 10px 14px; box-shadow: var(--shadow); cursor: pointer;
}
@media (min-width: 760px) { .recenter { left: auto; right: 16px; top: 16px; } }

@media (prefers-reduced-motion: reduce) {
  .pill.is-air .dot { animation: none; }
}
