/* ==========================================================================
   Where Is Sid
   --------------------------------------------------------------------------
   Colour roles come from a validated palette: two categorical slots (blue for
   night, orange for day) and one sequential blue ramp for the heatmap. Both
   themes are selected, not flipped — the dark steps are chosen for the dark
   surface. See the ramp comment above --heat-1.
   ========================================================================== */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;   /* cards, chart surfaces */
  --surface-2: #f9f9f7;   /* page plane */
  --surface-3: #f2f1ed;   /* wells, hover washes */

  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;

  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 8px 24px -12px rgba(11, 11, 11, 0.18);

  /* Categorical — night and day. */
  --night: #2a78d6;
  --day: #eb6834;
  --twilight: #c3c2b7;   /* neutral by design: "neither", not a third identity */

  /* Sequential blue ramp, light→dark, for dwell-time intensity. */
  --heat-1: #cde2fb;
  --heat-2: #9ec5f4;
  --heat-3: #6da7ec;
  --heat-4: #3987e5;
  --heat-5: #256abf;
  --heat-6: #184f95;
  --heat-7: #0d366b;

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;

  --radius: 14px;
  --radius-sm: 9px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;

  --shell-max: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --surface-3: #252523;

    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;

    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.7);

    --night: #3987e5;
    --day: #d95926;
    --twilight: #4a4a46;

    /* Ramp runs the other way on a dark surface: near-zero recedes into it. */
    --heat-1: #104281;
    --heat-2: #184f95;
    --heat-3: #256abf;
    --heat-4: #2a78d6;
    --heat-5: #3987e5;
    --heat-6: #6da7ec;
    --heat-7: #9ec5f4;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --surface-1: #1a1a19;
  --surface-2: #0d0d0d;
  --surface-3: #252523;

  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;

  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.7);

  --night: #3987e5;
  --day: #d95926;
  --twilight: #4a4a46;

  --heat-1: #104281;
  --heat-2: #184f95;
  --heat-3: #256abf;
  --heat-4: #2a78d6;
  --heat-5: #3987e5;
  --heat-6: #6da7ec;
  --heat-7: #9ec5f4;
}

/* ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--surface-2);
  color: var(--text-primary);
  line-height: 1.5;
  font-size: 16px;
  overflow-x: hidden;
}

h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 640; letter-spacing: -0.015em; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -48px;
  background: var(--surface-1); color: var(--text-primary);
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); z-index: 2000;
  transition: top 120ms ease;
}
.skip-link:focus { top: 8px; }

:focus-visible {
  outline: 2px solid var(--night);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.site-header {
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 28px 20px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 16px;
}

/* The tagline sorts after the theme button and takes the full flex basis, so
   it wraps onto its own line spanning the whole header width. */
.site-tagline {
  order: 1;
  flex-basis: 100%;
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
}
.site-tagline a { color: inherit; text-decoration: underline; }

.wordmark {
  display: flex;
  align-items: baseline;
  gap: 0.34em;
  font-size: clamp(26px, 5.2vw, 40px);
  font-weight: 700;
  letter-spacing: -0.03em;
}
.wordmark-where { color: var(--text-muted); font-weight: 560; }
.wordmark-sid { color: var(--text-primary); }
.wordmark-name { white-space: nowrap; }
/* The question mark belongs to "Sid", not to the gap between words. */
.wordmark-q { color: var(--text-muted); }

.icon-button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 17px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background 120ms ease, color 120ms ease;
}
.icon-button:hover { background: var(--surface-3); color: var(--text-primary); }

/* ── Layout ─────────────────────────────────────────────────────────────── */

main {
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 0 20px 64px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.panel-head { margin-bottom: 18px; }
.panel-head h2 { font-size: clamp(19px, 2.6vw, 23px); }
.panel-sub {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 62ch;
}

/* ── AI activity summary ────────────────────────────────────────────────── */

.summary-panel .panel-head { margin-bottom: 12px; }
.summary-text {
  margin: 0;
  font-size: clamp(16px, 2vw, 18px);
  line-height: 1.6;
  max-width: 72ch;
}

/* ── Visitor photos ─────────────────────────────────────────────────────── */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.gallery-item { margin: 0; }
.gallery-item img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid var(--border);
}
.gallery-item figcaption {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 480px;
}
.upload-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}
.upload-field textarea,
.upload-field input[type="file"] {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-2, transparent);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.upload-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.upload-status { font-size: 14px; color: var(--text-secondary); }

/* ── "Right now" + map ──────────────────────────────────────────────────── */

.now-section {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 20px;
  /* Stretch, not start: the map takes its height from the column beside it, so
     the two sides finish level however tall the status card and photo run. */
  align-items: stretch;
}

@media (max-width: 900px) {
  .now-section { grid-template-columns: 1fr; }
}

/* Left column: the status card, then Sid himself filling the space the taller
   map leaves beside it. */
.now-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.sid-portrait {
  margin: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.sid-portrait[hidden] { display: none; }

.sid-portrait img {
  display: block;
  width: 100%;
  height: auto;
  /* A 4:3 photo would run taller than the space beside the map; this crops to
     a calmer band and keeps Sid off the bottom edge. */
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: 50% 42%;
}

.sid-portrait figcaption {
  padding: 11px 16px 0;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text-secondary);
  border-top: 1px solid var(--grid);
}

.portrait-submit-link {
  display: block;
  padding: 4px 16px 13px;
  font-size: 12.5px;
  color: var(--accent, var(--text-primary));
}

@media (max-width: 900px) {
  /* Stacked, the photo no longer has a gap to fill — keep it, but shorter, so
     it does not push the charts off the first screen. */
  .sid-portrait img { aspect-ratio: 16 / 9; }
}

.now-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.now-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 620;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.pulse {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent);
  animation: pulse 2.4s ease-out infinite;
  flex: none;
}
.pulse[data-state="stale"] { background: var(--warning); animation: none; }
.pulse[data-state="unknown"] { background: var(--text-muted); animation: none; }
/* Dozing is a working state, not a warning — a calm blue, and no pulse,
   because nothing is arriving to pulse about. */
.pulse[data-state="dozing"] { background: var(--night); animation: none; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); }
  70%  { box-shadow: 0 0 0 9px color-mix(in srgb, var(--good) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 0%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  .pulse { animation: none; }
}

/* The hero figure — exactly one per view. */
.now-headline {
  margin: 0;
  font-size: clamp(27px, 4.4vw, 38px);
  font-weight: 660;
  letter-spacing: -0.028em;
  line-height: 1.12;
}

.now-detail {
  margin: 10px 0 0;
  color: var(--text-secondary);
  font-size: 15px;
}

.now-facts {
  margin: 20px 0 0;
  padding: 18px 0 0;
  border-top: 1px solid var(--grid);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 12px;
}
.now-facts div { min-width: 0; }
.now-facts dt {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 620;
}
.now-facts dd {
  margin: 3px 0 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ghost-button {
  margin-top: 18px;
  appearance: none;
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 14px;
  font-weight: 560;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.ghost-button:hover:not(:disabled) { background: var(--surface-3); color: var(--text-primary); }
.ghost-button:disabled { opacity: 0.55; cursor: progress; }

/* ── Map ────────────────────────────────────────────────────────────────── */

.map-shell {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--surface-3);
  display: flex;
  flex-direction: column;
  /* A floor for the stacked layout, where there is no neighbouring column to
     take height from. */
  min-height: clamp(420px, 58vh, 620px);
}

#map {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  background: var(--surface-3);
}

.leaflet-container {
  font-family: var(--font);
  background: var(--surface-3);
}
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface-1) 88%, transparent) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--text-secondary) !important; }

.leaflet-bar a {
  background: var(--surface-1) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}
.leaflet-bar a:hover { background: var(--surface-3) !important; }

.map-controls {
  position: absolute;
  left: 12px; bottom: 12px;
  z-index: 500;
  background: color-mix(in srgb, var(--surface-1) 94%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  box-shadow: var(--shadow);
  max-width: min(300px, calc(100% - 24px));
}

.control-group { display: flex; flex-direction: column; gap: 4px; }
.control-group[hidden] { display: none; }

.control-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 640;
  color: var(--text-muted);
}
.control-hint { font-size: 11px; color: var(--text-muted); }

.segmented {
  display: inline-flex;
  background: var(--surface-3);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12.5px;
  font-weight: 560;
  padding: 6px 11px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease;
}
.segmented button:hover { color: var(--text-primary); }
.segmented button[aria-checked="true"] {
  background: var(--surface-1);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

input[type="range"] {
  accent-color: var(--night);
  width: 100%;
  margin: 0;
}

.map-legend {
  position: absolute;
  right: 12px; top: 12px;
  z-index: 500;
  background: color-mix(in srgb, var(--surface-1) 94%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  font-size: 11px;
  color: var(--text-secondary);
  max-width: 190px;
}
.map-legend[hidden] { display: none; }
.legend-title {
  font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase;
  font-weight: 640; color: var(--text-muted); margin-bottom: 7px;
}
.legend-ramp {
  display: flex; height: 9px; border-radius: 5px; overflow: hidden; gap: 0;
}
.legend-ramp span { flex: 1; }
.legend-scale {
  display: flex; justify-content: space-between;
  margin-top: 5px; font-size: 10.5px; color: var(--text-muted);
}
.legend-note { margin-top: 8px; line-height: 1.35; color: var(--text-muted); }

.legend-rows { display: flex; flex-direction: column; gap: 6px; }
.legend-row { display: flex; align-items: center; gap: 7px; }
.legend-chip { width: 11px; height: 11px; border-radius: 3px; flex: none; }

/* Map popups */
.leaflet-popup-content-wrapper {
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--surface-1); border: 1px solid var(--border); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.45; }
.leaflet-popup-content strong { display: block; font-size: 14px; margin-bottom: 4px; }
.leaflet-popup-content .pop-row {
  display: flex; justify-content: space-between; gap: 16px;
  color: var(--text-secondary);
}
.leaflet-popup-content .pop-row b {
  color: var(--text-primary); font-variant-numeric: tabular-nums; font-weight: 600;
}

/* Sid's marker */
.sid-marker {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--day);
  border: 3px solid var(--surface-1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.sid-marker[data-stale="true"] { background: var(--text-muted); }

/* ── Stat tiles ─────────────────────────────────────────────────────────── */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.tile-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 620;
}
.tile-value {
  margin-top: 7px;
  font-size: clamp(25px, 3.4vw, 31px);
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.05;
}
.tile-value small {
  font-size: 0.5em;
  font-weight: 560;
  color: var(--text-secondary);
  letter-spacing: 0;
  margin-left: 2px;
}
.tile-note {
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* ── Charts ─────────────────────────────────────────────────────────────── */

.chart-scroll { overflow-x: auto; overflow-y: hidden; }
.chart { min-width: 0; }
.chart svg { display: block; max-width: 100%; height: auto; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }

.axis-text { font-size: 11.5px; fill: var(--text-muted); }
.axis-text.tabular { font-variant-numeric: tabular-nums; }
.value-text {
  font-size: 12px; font-weight: 600; fill: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.label-text { font-size: 12.5px; fill: var(--text-secondary); }
.label-text.is-home { fill: var(--text-primary); font-weight: 620; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }

.hit { fill: transparent; cursor: pointer; }
.bar-group:hover .bar-seg { opacity: 0.82; }

/* ── Tables ─────────────────────────────────────────────────────────────── */

.table-details { margin-top: 18px; }
.table-details summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 560;
  padding: 6px 0;
  list-style: none;
}
.table-details summary::-webkit-details-marker { display: none; }
.table-details summary::before { content: "▸ "; color: var(--text-muted); }
.table-details[open] summary::before { content: "▾ "; }
.table-details summary:hover { color: var(--text-primary); }

.table-scroll { overflow-x: auto; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td {
  text-align: right;
  padding: 8px 12px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
th:first-child, td:first-child { text-align: left; font-variant-numeric: normal; }
thead th {
  color: var(--text-muted);
  font-weight: 620;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-bottom-color: var(--axis);
}
tbody tr:hover { background: var(--surface-3); }

/* ── Tooltip ────────────────────────────────────────────────────────────── */

.tooltip {
  position: fixed;
  z-index: 3000;
  pointer-events: none;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.45;
  max-width: 260px;
  opacity: 0;
  transition: opacity 90ms ease;
}
.tooltip[data-show="true"] { opacity: 1; }
.tooltip-title { font-weight: 640; margin-bottom: 5px; }
.tooltip-row {
  display: flex; align-items: center; gap: 8px;
  justify-content: space-between;
  color: var(--text-secondary);
}
.tooltip-row b {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.tooltip-key { display: inline-flex; align-items: center; gap: 6px; }
.tooltip-swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }

/* ── Footer ─────────────────────────────────────────────────────────────── */

.site-footer {
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 0 20px 48px;
  color: var(--text-muted);
  font-size: 13px;
}
.site-footer p { margin: 0 0 6px; }
.footer-fine { font-size: 11.5px; }
.footer-fine a { color: var(--text-secondary); }

/* ── Empty state ────────────────────────────────────────────────────────── */

.empty {
  padding: 30px 4px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

@media (max-width: 620px) {
  .panel { padding: 18px 16px; }
  .map-controls { left: 8px; right: 8px; bottom: 8px; max-width: none; }
  .map-legend { top: 8px; right: 8px; }
  .now-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
