/* Self-hosted display face for the share poster (variable, latin subset).
   Loaded locally so the poster type is device-consistent and renders even when
   third-party font CDNs are slow or blocked. */
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("./assets/fonts/space-grotesk-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light dark;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  --bg: #06080c;
  --page-bg: linear-gradient(180deg, #0a0d12, #05070a 72%);
  --page-overlay:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 28%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.012), transparent 24%, transparent 76%, rgba(255, 255, 255, 0.012));
  --bg-elevated: #0c1017;
  --frame-bg:
    linear-gradient(180deg, rgba(10, 13, 18, 0.8), rgba(7, 10, 14, 0.92)),
    var(--bg-elevated);
  --frame-shadow: 0 18px 42px rgba(0, 0, 0, 0.36);
  --frame-vignette:
    radial-gradient(circle at center, transparent 52%, rgba(0, 0, 0, 0.14) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.015), rgba(0, 0, 0, 0.12));
  --panel-bg: rgba(18, 22, 30, 0.65);
  --panel-border: rgba(255, 255, 255, 0.06);
  --panel-shadow:
    0 8px 24px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --ink: rgba(244, 247, 251, 0.95);
  --secondary: rgba(244, 247, 251, 0.7);
  --muted: rgba(244, 247, 251, 0.6);
  --faint: rgba(244, 247, 251, 0.4);
  --line: rgba(255, 255, 255, 0.08);
  --outline: rgba(255, 255, 255, 0.24);
  --map-bg: #081017;
  --heat-alpha: 0.95;
  --heat-noise-alpha: 0.032;
  --marker-stroke: rgba(240, 246, 252, 0.84);
  --marker-fill: rgba(10, 15, 21, 0.94);
  --tooltip-bg: rgba(10, 15, 21, 0.94);
  --tooltip-ink: rgba(244, 247, 251, 0.94);
  --popup-bg: rgba(10, 15, 21, 0.94);
  --popup-ink: rgba(244, 247, 251, 0.94);
  --label-shadow: rgba(0, 0, 0, 0.42);
  --temp-label-outline: rgba(6, 10, 16, 0.34);
  --temp-label-glow: rgba(120, 184, 109, 0.16);
  --status-warning: #ffb74d;
  --status-error: #e57373;
}

body[data-theme="light"] {
  --bg: #eef3f7;
  --page-bg: linear-gradient(180deg, #edf4f8, #e4edf4 72%);
  --page-overlay:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), transparent 34%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.22), transparent 24%, transparent 76%, rgba(255, 255, 255, 0.18));
  --bg-elevated: #f7fafc;
  --frame-bg:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(241, 247, 251, 0.94)),
    var(--bg-elevated);
  --frame-shadow: 0 18px 42px rgba(110, 137, 161, 0.16);
  --frame-vignette:
    radial-gradient(circle at center, transparent 58%, rgba(150, 172, 190, 0.14) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(194, 211, 224, 0.1));
  --panel-bg: rgba(247, 250, 252, 0.78);
  --panel-border: rgba(15, 23, 42, 0.08);
  --panel-shadow:
    0 12px 30px rgba(15, 23, 42, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  --ink: rgba(15, 23, 42, 0.95);
  --secondary: rgba(15, 23, 42, 0.72);
  --muted: rgba(15, 23, 42, 0.58);
  --faint: rgba(15, 23, 42, 0.34);
  --line: rgba(15, 23, 42, 0.1);
  --outline: rgba(15, 23, 42, 0.22);
  --map-bg: #dfe8ef;
  --heat-alpha: 0.92;
  --marker-stroke: rgba(255, 255, 255, 0.96);
  --marker-fill: rgba(15, 23, 42, 0.82);
  --tooltip-bg: rgba(248, 250, 252, 0.96);
  --tooltip-ink: rgba(15, 23, 42, 0.94);
  --popup-bg: rgba(248, 250, 252, 0.98);
  --popup-ink: rgba(15, 23, 42, 0.94);
  --label-shadow: rgba(255, 255, 255, 0.82);
  --temp-label-outline: rgba(255, 255, 255, 0.86);
  --temp-label-glow: rgba(15, 23, 42, 0.16);
  --map-title-ink: rgba(15, 23, 42, 0.56);
  --map-title-subtitle: rgba(15, 23, 42, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  /* Ambient polish: the page surround (the "mat") picks up today's average
     temperature colour and a time-of-day warm/cool tint. Both default to
     transparent and are set from JS, so this is a no-op until enabled. */
  background:
    linear-gradient(var(--ambient-breath, transparent), var(--ambient-breath, transparent)),
    linear-gradient(var(--ambient-mat, transparent), var(--ambient-mat, transparent)),
    var(--page-bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: var(--page-overlay);
}

.shell {
  min-height: 100vh;
  padding: 16px;
  overflow: hidden;
  touch-action: none;
}

.map-frame {
  position: relative;
  min-height: calc(100vh - 32px);
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: var(--frame-bg);
  box-shadow: var(--frame-shadow);
}

.map-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 360;
  pointer-events: none;
  background: var(--frame-vignette);
}

/* Print grain — a whisper of film noise inside the frame (above the vignette,
   below the HUD) so the piece reads like a physical print. Toggled by the
   has-grain class so the effect is fully off when disabled. */
body.has-grain .map-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 361;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 220px 220px;
}

#map {
  position: absolute;
  inset: 0;
  isolation: isolate;
}

#map::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 350;
  pointer-events: none;
  background: none;
  opacity: 0;
  mix-blend-mode: normal;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  mask-image: none;
  -webkit-mask-image: none;
}

.leaflet-container {
  background: var(--map-bg);
  font: inherit;
}

.leaflet-overlay-pane {
  filter: none;
}

/* The blur and opacity on .temperature-overlay-layer are set dynamically via
   element.style in redraw() — CSS filter is applied there so it runs through
   the browser's GPU compositor, which is consistent across all browsers
   including Safari < 18 where canvas ctx.filter was silently ignored.
   We only set non-filter properties here as safe baseline resets. */
.heatmap-overlay,
.temperature-overlay-layer {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  mask-image: none;
  -webkit-mask-image: none;
}

.temperature-label-layer {
  z-index: 402;
  opacity: 1;
  filter: none;
  pointer-events: none;
}

.temperature-readout {
  position: absolute;
  transform: translate(-50%, -50%) translateZ(0);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.2px;
  white-space: nowrap;
  /* A consistent dark halo carries the figure-ground contrast so the monochrome
     ink stays legible over any gradient colour (the gold/green midrange is the
     weakest zone). This is what lets us drop the per-label heat tint. */
  text-shadow:
    0 0 4px rgba(0, 0, 0, 0.5),
    0 1px 1px rgba(0, 0, 0, 0.72),
    0 2px 6px rgba(0, 0, 0, 0.32);
  will-change: transform;
}

body[data-theme="light"] .temperature-readout {
  text-shadow:
    0 0 1px rgba(255, 255, 255, 0.78),
    0 1px 3px rgba(255, 255, 255, 0.58),
    0 2px 6px rgba(255, 255, 255, 0.28);
}

.temperature-readout .temperature-value {
  align-items: baseline;
}

.temperature-readout .temperature-whole {
  font-size: 1em;
}

.temperature-readout .temperature-decimal,
.temperature-readout .temperature-unit {
  font-size: var(--temp-tail-size, 0.72em);
}

.temperature-caption {
  font-family: var(--font-sans);
  font-size: var(--temp-caption-size, 8px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  opacity: 0.96;
  text-shadow:
    0 1px 1px rgba(0, 0, 0, 0.18),
    0 1px 2px rgba(0, 0, 0, 0.12);
}

body[data-theme="light"] .temperature-caption {
  text-shadow:
    0 0 1px rgba(255, 255, 255, 0.52),
    0 1px 2px rgba(255, 255, 255, 0.2);
}

.leaflet-control-container {
  display: none;
}

.map-title,
.hud,
.legend-card {
  animation: panel-in 200ms ease both;
}

.map-title {
  position: absolute;
  top: 24px;
  right: 32px;
  z-index: 470;
  max-width: 240px;
  text-align: right;
  pointer-events: none;
}

.map-title span {
  display: block;
  font-size: clamp(17px, 1.8vw, 22px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.03em;
  color: var(--map-title-ink, rgba(244, 247, 251, 0.8));
}

.map-title::after {
  content: attr(data-temperature-label);
  display: block;
  margin-top: 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--map-title-subtitle, rgba(244, 247, 251, 0.48));
}

.top-controls {
  position: absolute;
  top: 24px;
  left: 24px;
  z-index: 500;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0;
  width: fit-content;
  max-width: calc(100% - 56px);
  pointer-events: none;
}

.hud,
.legend-card {
  padding: 13px;
  border-radius: 12px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(8px) saturate(112%);
  -webkit-backdrop-filter: blur(8px) saturate(112%);
  box-shadow: var(--panel-shadow);
}

.hud-top {
  width: fit-content;
  max-width: min(420px, calc(100vw - 220px));
  pointer-events: auto;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.summary-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.summary-item {
  min-width: 0;
}

.summary-item + .summary-item {
  padding-left: 0;
  padding-top: 10px;
  border-left: 0;
  border-top: 1px solid var(--line);
}

.summary-kicker {
  display: block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.summary-time-line,
.summary-station-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 3px;
}

.summary-item-updated {
  white-space: nowrap;
}

.summary-value,
.summary-value-compact {
  display: inline-flex;
  align-items: baseline;
  gap: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
}

.summary-value-compact {
  font-size: 18px;
}

.refresh-countdown {
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  color: var(--muted);
}

.summary-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--secondary);
}

.summary-chip[hidden] {
  display: none;
}

.hint {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--secondary);
}

.hint[hidden] {
  display: none;
}

.legend-card {
  /* Tighten width + padding + internal sizing so the legend pill hugs its content. */
  width: fit-content;
  padding: 10px 7px 10px 12px;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  overflow: hidden;
  pointer-events: auto;
  border-left: 1px solid var(--line);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.legend-scale {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  width: fit-content;
}

.legend-end {
  display: block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}

.legend-max {
  text-align: left;
}

.legend-min {
  text-align: left;
}

.legend-track {
  display: grid;
  grid-template-columns: 16px;
  align-items: stretch;
}

.legend-bar {
  width: 16px;
  height: 64px;
  display: block;
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.legend-bar::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 9px;
  background: var(--legend-gradient, rgba(255, 255, 255, 0.02));
}

.legend-band {
  display: block;
  min-height: 0;
  border-radius: 8px;
}

.legend-mid {
  display: none;
}

.legend-ticks {
  display: none;
}

.legend-card.is-loading .legend-end,
.legend-card.is-loading .legend-ticks {
  opacity: 0;
}

.legend-card.is-loading .legend-bar {
  opacity: 0.88;
}

.legend-options {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.overlay-toggle {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: 0.04em;
  color: rgba(244, 247, 251, 0.58);
}

.overlay-toggle input {
  margin: 0;
  accent-color: #9cbadf;
}

.temperature-value {
  display: inline-flex;
  align-items: baseline;
  gap: 0;
  font-variant-numeric: tabular-nums;
}

.temperature-decimal,
.temperature-unit {
  opacity: 0.6;
}

.temperature-unit {
  margin-left: 1px;
}

.hover-readout,
.station-tooltip {
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.34);
}

.hover-readout::before,
.station-tooltip::before {
  display: none;
}

.hover-readout {
  padding: 8px 12px;
  font-size: 18px;
  font-weight: 600;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.station-tooltip {
  padding: 12px;
}

.station-tooltip-value {
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}

.station-tooltip-name {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.3;
  color: var(--secondary);
}

.point-popup .leaflet-popup-content-wrapper,
.point-popup .leaflet-popup-tip {
  background: var(--popup-bg);
  color: var(--popup-ink);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.34);
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.point-popup .leaflet-popup-content {
  margin: 12px 16px;
  min-width: 0;
  text-align: center;
  line-height: 1.2;
}

.popup-readout {
  font-size: 22px;
  font-weight: 600;
}

.popup-label {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--secondary);
}

.hover-readout.is-hottest {
  border-color: rgba(236, 110, 76, 0.9);
  box-shadow:
    0 0 0 3px rgba(236, 110, 76, 0.32),
    0 10px 28px rgba(236, 110, 76, 0.3);
}

.hover-readout.is-coldest {
  border-color: rgba(87, 149, 234, 0.9);
  box-shadow:
    0 0 0 3px rgba(87, 149, 234, 0.28),
    0 10px 28px rgba(87, 149, 234, 0.24);
}

.point-popup.is-hottest .leaflet-popup-content-wrapper,
.point-popup.is-hottest .leaflet-popup-tip {
  border-color: rgba(236, 110, 76, 0.9);
  box-shadow:
    0 0 0 3px rgba(236, 110, 76, 0.32),
    0 10px 28px rgba(236, 110, 76, 0.3);
}

.point-popup.is-coldest .leaflet-popup-content-wrapper,
.point-popup.is-coldest .leaflet-popup-tip {
  border-color: rgba(87, 149, 234, 0.9);
  box-shadow:
    0 0 0 3px rgba(87, 149, 234, 0.28),
    0 10px 28px rgba(87, 149, 234, 0.24);
}

.status-warning {
  color: var(--status-warning);
}

.status-error {
  color: var(--status-error);
}

.station-point {
  transform-origin: center center;
  transition:
    transform 180ms ease,
    opacity 200ms ease,
    stroke 200ms ease,
    fill 200ms ease;
}

.station-point.is-hovered {
  transform: scale(1.03);
}

/* Share button — bottom-left is the only frame corner free on BOTH layouts
   (desktop: HUD top-left + watermark top-right; mobile: HUD top-left +
   watermark bottom-right). Frosted glass to match the HUD. */
/* Positioning lives on the row, never on the buttons — so the two pills stay a
   matched pair at every breakpoint and only the row moves. */
.share-actions {
  position: absolute;
  left: 24px;
  bottom: 24px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}

.share-button {
  position: relative;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  color: var(--ink);
  backdrop-filter: blur(8px) saturate(112%);
  -webkit-backdrop-filter: blur(8px) saturate(112%);
  box-shadow: var(--panel-shadow);
  cursor: pointer;
  animation: panel-in 200ms ease both;
  transition:
    transform 140ms ease,
    opacity 160ms ease;
}

.share-button:hover {
  transform: translateY(-1px);
}

.share-button:active {
  transform: translateY(0);
}

.share-button:focus-visible {
  outline: 2px solid var(--outline);
  outline-offset: 2px;
}

.share-button[disabled] {
  opacity: 0;
  pointer-events: none;
  /* Stop the panel-in fade from filling opacity:1 over this while disabled —
     otherwise the button looks ready but silently swallows taps during load. */
  animation: none;
}

.share-button svg {
  display: block;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 8px);
  z-index: 600;
  max-width: calc(100% - 48px);
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  backdrop-filter: blur(8px) saturate(112%);
  -webkit-backdrop-filter: blur(8px) saturate(112%);
  box-shadow: var(--panel-shadow);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 960px) {
  #map::after {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .heatmap-overlay,
  .temperature-overlay-layer {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .top-controls {
    top: 16px;
    left: 16px;
    max-width: calc(100% - 32px);
  }

  .share-actions {
    left: 16px;
    bottom: 16px;
  }

  html,
  body {
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
  }

  body {
    position: fixed;
    inset: 0;
    width: 100%;
  }

  .shell {
    height: 100dvh;
    min-height: 100dvh;
    padding: 8px;
    overflow: hidden;
    touch-action: none;
  }

  .map-frame {
    min-height: calc(100dvh - 16px);
  }

  .hud-top {
    width: fit-content;
    max-width: min(360px, calc(100vw - 132px));
  }

  .map-title {
    top: 16px;
    right: 16px;
  }

  .legend-card {
    width: fit-content;
  }

  .legend-bar,
  .legend-ticks {
    height: 64px;
  }
}

@media (max-width: 640px) {
  .top-controls {
    overflow: hidden;
    align-items: stretch;
    flex-wrap: nowrap;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    backdrop-filter: blur(8px) saturate(112%);
    -webkit-backdrop-filter: blur(8px) saturate(112%);
    box-shadow: var(--panel-shadow);
  }

  .hud-top {
    max-width: min(320px, calc(100vw - 108px));
    padding: 10px 12px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .summary-bar {
    gap: 8px;
  }

  .summary-item + .summary-item {
    padding-top: 8px;
    border-top: 1px solid var(--line);
  }

  .summary-time-line,
  .summary-station-line {
    margin-top: 3px;
  }

  .map-title {
    top: auto;
    bottom: 16px;
    right: 16px;
    max-width: 148px;
  }

  .summary-value {
    font-size: 18px;
  }

  .summary-value-compact {
    font-size: 18px;
  }

  .legend-card {
    width: fit-content;
    padding: 10px 5px 10px 9px;
    border: 0;
    border-left: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .legend-bar,
  .legend-ticks {
    height: 58px;
  }

  .legend-track {
    gap: 8px;
  }
}
