:root {
  --night: #13213F;
  --night-2: #1C2E54;
  --night-3: #2A4170;
  --snow: #F7F8FB;
  --frost: #B9C4DA;
  --amber: #F5B83D;
  --red: #E0334B;
  --pine: #3FA37A;
  --bulb-off: #33466F;
  --bg: var(--night);
  --surface: var(--night-2);
  --line: var(--night-3);
  --text: var(--snow);
  --muted: var(--frost);
  --accent: var(--amber);
  --display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F4F6FA;
    --surface: #FFFFFF;
    --line: #D4DAE6;
    --text: #13213F;
    --muted: #4A5878;
    --accent: #A86A00;
    --bulb-off: #D4DAE6;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1.0625rem/1.55 var(--body);
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; z-index: 2000; background: var(--surface); padding: 8px 12px; }

main, .masthead, .foot { max-width: 760px; margin: 0 auto; padding: 0 16px; }

/* ---------- masthead */
.masthead { padding-top: 28px; }
.masthead h1 {
  font: 800 clamp(2rem, 7vw, 3.25rem)/1.02 var(--display);
  letter-spacing: -0.02em;
  margin: 0;
  text-wrap: balance;
}
.when { margin: 8px 0 0; color: var(--muted); }

/* ---------- live hero */
.live { margin-top: 24px; }
.badge {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 0 0 10px; padding: 3px 12px 3px 10px;
  border-radius: 999px;
  font-weight: 700; font-size: 0.9rem;
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--line);
}
.badge::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.badge[data-state="live"] { color: var(--snow); background: var(--red); border-color: var(--red); }
.badge[data-state="live"]::before { background: var(--snow); animation: blink 1.6s ease-in-out infinite; }
.badge[data-state="stale"] { color: var(--amber); border-color: var(--amber); }
.badge[data-state="finished"] { color: var(--pine); border-color: var(--pine); }

.headline {
  font: 800 clamp(1.5rem, 5vw, 2.15rem)/1.15 var(--display);
  letter-spacing: -0.01em;
  margin: 0;
  max-width: 28ch;
  text-wrap: balance;
}
.subline { margin: 8px 0 0; color: var(--muted); max-width: 60ch; }

/* ---------- string of lights */
.strand {
  position: relative;
  display: flex; justify-content: space-between; align-items: flex-start;
  margin: 26px 0 0;
  padding-top: 6px;
  height: 34px;
}
.strand::before { /* the wire */
  content: ""; position: absolute; left: 0; right: 0; top: 4px; height: 10px;
  border-bottom: 2px solid var(--line);
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.bulb {
  position: relative;
  width: 11px; height: 17px;
  border-radius: 50% 50% 46% 46% / 40% 40% 60% 60%;
  background: var(--bulb-off);
  margin-top: 8px;
  transition: background 0.6s, box-shadow 0.6s;
}
.bulb::before { /* socket */
  content: ""; position: absolute; top: -5px; left: 2px; width: 7px; height: 6px;
  border-radius: 2px; background: var(--line);
}
.bulb:nth-child(4n+1).on { --c: var(--red); }
.bulb:nth-child(4n+2).on { --c: var(--amber); }
.bulb:nth-child(4n+3).on { --c: var(--pine); }
.bulb:nth-child(4n+4).on { --c: #7FB2FF; }
.bulb.on { background: var(--c); box-shadow: 0 0 10px 2px color-mix(in srgb, var(--c) 60%, transparent); }
.bulb.here { animation: twinkle 1.2s ease-in-out infinite alternate; }
.bulb.bulb-stop::after { /* a stop on the route */
  content: ""; position: absolute; left: 50%; top: 22px; width: 4px; height: 4px;
  margin-left: -2px; border-radius: 50%; background: var(--muted);
}
.strand-ends {
  display: flex; justify-content: space-between;
  font-size: 0.85rem; color: var(--muted); margin-top: 2px;
}

/* ---------- map */
.map-wrap { position: relative; margin-top: 18px; }
#map {
  height: min(62vh, 520px);
  min-height: 340px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.locate {
  position: absolute; z-index: 500; left: 12px; bottom: 12px;
  font: 700 1rem var(--body);
  padding: 12px 18px;
  border-radius: 999px; border: 0;
  background: var(--amber); color: var(--night);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.locate:disabled { opacity: 0.7; cursor: progress; }
.mine {
  margin: 14px 0 0; padding: 12px 14px;
  border-left: 4px solid var(--amber);
  background: var(--surface);
  border-radius: 0 10px 10px 0;
  font-weight: 700;
}
.hint, .updated { margin: 8px 0 0; font-size: 0.9rem; color: var(--muted); }

#map:has(.map-missing) { height: auto; min-height: 0; padding: 16px; }
.map-missing { margin: 0 0 12px; color: var(--muted); }

/* leaflet tweaks */
.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9) saturate(0.6); }
.leaflet-container { font: inherit; background: var(--surface); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--night); color: var(--snow); }
.leaflet-popup-content { margin: 10px 14px; line-height: 1.4; }
.leaflet-control-attribution { font-size: 10px; }
.unit-pin { display: grid; place-items: center; }
.unit-pin .dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--red); border: 3px solid var(--snow);
  box-shadow: 0 0 0 0 rgba(224, 51, 75, 0.6);
  animation: ping 2s ease-out infinite;
}
.unit-pin.santa .dot { background: var(--pine); box-shadow: none; animation: none; }
.unit-pin.stale .dot { background: #6B7894; animation: none; box-shadow: none; }
.unit-pin .tag {
  margin-top: 3px; padding: 1px 7px; border-radius: 6px;
  background: var(--night); color: var(--snow);
  font: 700 12px var(--body); white-space: nowrap;
}
.stop-pin {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--night); border: 3px solid var(--amber);
}
.me-pin { width: 16px; height: 16px; border-radius: 50%; background: #7FB2FF; border: 3px solid #fff; }

/* ---------- schedule */
.schedule, .info { margin-top: 56px; }
.schedule h2, .info h2 {
  font: 800 1.6rem/1.2 var(--display);
  margin: 0 0 6px;
}
.sched-note { margin: 0 0 18px; color: var(--muted); }
.stops { list-style: none; margin: 0; padding: 0; }
.town-head {
  font: 800 1.15rem var(--display);
  margin: 22px 0 6px;
  padding-left: 28px;
  color: var(--accent);
}
.stop {
  position: relative;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 14px;
  padding: 10px 0 10px 28px;
}
.stop::before { /* route line */
  content: ""; position: absolute; left: 7px; top: 0; bottom: 0; width: 2px; background: var(--line);
}
.stop::after { /* stop marker */
  content: ""; position: absolute; left: 1px; top: 15px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--bg); border: 3px solid var(--line);
}
.stop.passed::after { background: var(--red); border-color: var(--red); }
.stop.passed::before { background: var(--red); }
.stop.next::after { border-color: var(--amber); background: var(--amber); }
.stop-name { font-weight: 700; }
.stop-time { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stop-eta { grid-column: 1 / -1; font-size: 0.9rem; color: var(--muted); }
.stop.next .stop-eta { color: var(--accent); font-weight: 700; }

/* ---------- info */
.info-grid { display: grid; gap: 0; }
.info-item { padding: 16px 0; border-top: 1px solid var(--line); }
.info-item h3 { margin: 0 0 4px; font: 800 1.1rem var(--display); }
.info-item p { margin: 0; max-width: 64ch; }

/* ---------- footer */
.foot { margin-top: 56px; padding-bottom: 40px; color: var(--muted); }
.foot p { margin: 0 0 6px; max-width: 64ch; }
.foot-small { font-size: 0.85rem; }

@keyframes blink { 50% { opacity: 0.3; } }
@keyframes twinkle { from { filter: brightness(0.75); } to { filter: brightness(1.35); } }
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(224, 51, 75, 0.6); }
  100% { box-shadow: 0 0 0 18px rgba(224, 51, 75, 0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 700px) {
  .info-grid { grid-template-columns: 1fr 1fr; column-gap: 32px; }
}
