:root {
  --bg: #0a0d12;
  --land: #161b24;
  --land-edge: rgba(150, 175, 210, 0.22);
  --rail: rgba(140, 175, 220, 0.16);
  --ink: #e8eef7;
  --ink-dim: #8695ab;
  --panel: rgba(12, 16, 22, 0.72);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* The canvas handles its own pan and zoom, so the browser must not also try. */
  touch-action: none;
}

.hud { position: fixed; z-index: 2; pointer-events: none; }

/* A day can take a couple of seconds to build, so say so plainly rather than
   leaving the map looking merely stale. */
.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 5;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
}
.progress[hidden] { display: none; }
.progress::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  background: linear-gradient(90deg, transparent, #4aa3ff, transparent);
  animation: sweep 1.1s ease-in-out infinite;
}
@keyframes sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(350%); }
}

.date.busy input {
  border-color: rgba(74, 163, 255, 0.7);
  box-shadow: 0 0 0 1px rgba(74, 163, 255, 0.25);
}

.hud-left { top: 22px; left: 26px; }
.hud-left h1 {
  margin: 0;
  font-size: clamp(20px, 2.1vw, 30px);
  font-weight: 600;
  letter-spacing: -0.015em;
}
.hud-left p {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--ink-dim);
  letter-spacing: 0.01em;
}

/* Where the data comes from, small but legible, and it travels with a shared
   snapshot too — see composeSnapshot in app.js. */
.credits {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 0 0 16px;
  pointer-events: auto;
}
.credits a { display: block; opacity: 0.7; transition: opacity 0.15s; }
.credits a:hover { opacity: 1; }
.credits img { display: block; width: auto; }
.credits .mt { height: 42px; }
.credits .ulb { height: 34px; }

.hud-right { top: 22px; right: 30px; text-align: right; }
.clock {
  font-size: clamp(38px, 5vw, 64px);
  font-weight: 300;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.running { margin-top: 8px; }
.running span { font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; }
.running small {
  display: block;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.legend {
  left: 26px;
  /* Sits clear of the control bar, whose height changes as it wraps. */
  bottom: calc(var(--controls-h, 52px) + 24px);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  font-size: 13px;
  max-width: min(680px, 70vw);
}
.legend .item { display: flex; align-items: center; gap: 7px; color: var(--ink-dim); }
.legend .swatch { width: 9px; height: 9px; border-radius: 50%; }
.legend .name { color: var(--ink); }
.legend .count { font-variant-numeric: tabular-nums; min-width: 2ch; }
.legend .item.off { opacity: 0.35; }
.legend .item { pointer-events: auto; cursor: pointer; }

.tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.controls {
  left: 26px;
  right: 26px;
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 18px;
  pointer-events: auto;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 10px 14px;
}

.modes { display: flex; background: rgba(255, 255, 255, 0.05); border-radius: 8px; padding: 2px; }
.mode {
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 13px;
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
}
.mode.is-active { background: rgba(255, 255, 255, 0.12); color: var(--ink); }

.group { display: flex; align-items: center; gap: 14px; flex: 1; }

.date input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 5px 8px;
  color-scheme: dark;
}
.date.hidden { display: none; }
.date input:disabled { opacity: 0.4; }

.ghost {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  min-width: 4.5ch;
}
.ghost:disabled { opacity: 0.35; cursor: default; }

#map { cursor: grab; }
#map.dragging { cursor: grabbing; }
.group.hidden { display: none; }

.controls button#playpause {
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  width: 34px;
  height: 30px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
#scrub { flex: 1; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--ink);
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border: 0; border-radius: 50%; background: var(--ink);
}

.speed { display: flex; align-items: center; gap: 8px; }
.speed input { width: 110px; }
#speed-label { font-size: 12px; color: var(--ink-dim); width: 5ch; font-variant-numeric: tabular-nums; }

#live-status { font-size: 13px; color: var(--ink-dim); flex: 1; }
#live-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #2ee6a8;
  box-shadow: 0 0 8px #2ee6a8;
  animation: pulse 2s ease-in-out infinite;
}
#live-status.stale .dot { background: #ff7a45; box-shadow: 0 0 8px #ff7a45; }
@keyframes pulse { 50% { opacity: 0.35; } }

.stats {
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.stats.hidden { display: none; }

.mode[disabled] { opacity: 0.3; cursor: not-allowed; }

.tooltip {
  position: fixed;
  z-index: 3;
  pointer-events: none;
  background: rgba(10, 14, 20, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12.5px;
  line-height: 1.5;
  transform: translate(12px, 12px);
  max-width: 260px;
}
.tooltip.hidden { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  z-index: 4;
  background: rgba(18, 24, 33, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13px;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.hidden { opacity: 0; }

select.ghost {
  appearance: none;
  padding-right: 10px;
  min-width: 0;
}
select.ghost option { background: #12161d; color: var(--ink); }

#share svg { display: block; }
.tooltip strong { font-weight: 600; }
.tooltip .muted { color: var(--ink-dim); }

/* ------------------------------------------------------------------ phones --
   The map is the point, so on a small screen the furniture shrinks out of its
   way: the title drops to one line, the legend becomes a single scrolling row,
   and the controls stack into two rows that stay reachable with a thumb. */

@media (max-width: 780px) {
  .hud-left { top: max(12px, env(safe-area-inset-top)); left: 16px; right: 96px; }
  .hud-left h1 { font-size: 19px; }
  .hud-left p { font-size: 12px; }
  .credits { gap: 13px; margin-bottom: 10px; }
  .credits .mt { height: 30px; }
  .credits .ulb { height: 24px; }

  .hud-right { top: max(12px, env(safe-area-inset-top)); right: 16px; }
  .clock { font-size: 30px; }
  .running span { font-size: 16px; }
  .running small { font-size: 9px; letter-spacing: 0.1em; }
  .stats { font-size: 10px; }

  .legend {
    left: 0;
    right: 0;
    bottom: calc(var(--controls-h, 120px) + 20px);
    padding: 0 16px;
    max-width: none;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 14px;
    font-size: 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .legend::-webkit-scrollbar { display: none; }
  .legend .item { flex: 0 0 auto; }

  .controls {
    left: 8px;
    right: 8px;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }
  .modes { flex: 1 1 100%; justify-content: space-between; }
  .mode { flex: 1; padding: 8px 4px; font-size: 12px; text-align: center; }
  .group { flex: 1 1 100%; gap: 10px; }
  .date { order: 3; }
  .date input { padding: 7px 8px; }
  .tools { order: 4; }

  /* Touch targets: the sliders and buttons need real estate under a thumb. */
  .controls button#playpause { width: 40px; height: 36px; }
  .ghost { padding: 8px 10px; }
  input[type="range"] { height: 6px; }
  input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; }
  input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; }
  .speed input { width: 64px; }

  .toast { bottom: calc(var(--controls-h, 120px) + 60px); }
}

/* Short viewports — a phone held sideways. Height is the scarce dimension, so
   the legend collapses to one scrolling row and the furniture gives back rows. */
@media (max-height: 540px) {
  .hud-left { top: 10px; }
  .hud-left h1 { font-size: 17px; }
  .hud-left p { font-size: 11px; }
  .credits { gap: 11px; margin-bottom: 7px; }
  .credits .mt { height: 24px; }
  .credits .ulb { height: 19px; }
  .hud-right { top: 10px; }
  .clock { font-size: 26px; }
  .running { margin-top: 3px; }
  .running span { font-size: 15px; }

  .legend {
    left: 0;
    right: 0;
    padding: 0 16px;
    max-width: none;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 14px;
    font-size: 12px;
    scrollbar-width: none;
  }
  .legend::-webkit-scrollbar { display: none; }
  .legend .item { flex: 0 0 auto; }

  .controls { padding: 6px 10px; gap: 10px; bottom: 10px; }
  .modes { flex: 0 0 auto; }
  .group { flex: 1 1 auto; }
}
