/* ---- base ---- */
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: "Jua", "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

html, body { height: 100%; }
input, textarea { user-select: text; -webkit-user-select: text; }

:link, :visited { color: var(--brand-ink); }
a:hover { text-decoration: none; }

button {
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
button:disabled { cursor: not-allowed; opacity: 0.6; }

h1, h2, h3 { font-weight: normal; }

[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--brand-ink);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- brand colour tokens (7 swatches) ---- */
:root,
:root[data-color-theme="classic"] {
  --brand: #ccffcc;
  --brand-rgb: 204, 255, 204;
}
:root[data-color-theme="not-green-1"] { --brand: #ffcccc; --brand-rgb: 255, 204, 204; }
:root[data-color-theme="not-green-2"] { --brand: #ccccff; --brand-rgb: 204, 204, 255; }
:root[data-color-theme="not-green-3"] { --brand: #ffffcc; --brand-rgb: 255, 255, 204; }
:root[data-color-theme="not-green-4"] { --brand: #ffccff; --brand-rgb: 255, 204, 255; }
:root[data-color-theme="not-green-5"] { --brand: #ccffff; --brand-rgb: 204, 255, 255; }
:root[data-color-theme="really-light-green"] { --brand: #ffffff; --brand-rgb: 255, 255, 255; }

/* ---- light / dark surface tokens ---- */
:root,
:root[data-mode="light"] {
  --bg: #eef2f0;
  --surface: rgba(255, 255, 255, 0.55);
  --surface-strong: rgba(255, 255, 255, 0.78);
  --surface-border: rgba(255, 255, 255, 0.65);
  --ink: #121815;
  --muted: #5b665f;
  --shadow: 0 10px 30px rgba(20, 40, 30, 0.10);
  --brand-ink: #1f6b3d;
  --ok: #0f7234;
  --warn: #a24b08;
  --busy: #627288;
  --error: #b91c1c;

  /* Chart series, one per region in a fixed order (north, south, east, west,
     central). Fixed-meaning colours, not brand: the dataviz reference palette's
     first five slots, validated for colour-blind separation on these surfaces.
     Three sit under 3:1 on the light surface, so every chart also has a legend,
     a tooltip and a table view. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;

  /* NEA's bands, Good to Hazardous. Fixed-meaning accents like the footer heart:
     they must read as the same severity on every brand colour. Always shown
     beside the band's name, never as colour alone. */
  --band-1: #0ca30c;
  --band-2: #fab219;
  --band-3: #ec835a;
  --band-4: #d03b3b;
  --band-5: #8b2c7a;
}

:root[data-mode="dark"] {
  --bg: #0c100e;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-strong: rgba(255, 255, 255, 0.11);
  --surface-border: rgba(255, 255, 255, 0.14);
  --ink: #eef2ef;
  --muted: #9aa7a0;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  --brand-ink: #bff5cf;
  --ok: #4ade80;
  --warn: #fbbf24;
  --busy: #94a3b8;
  --error: #fa9696;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;

  --band-1: #0ca30c;
  --band-2: #fab219;
  --band-3: #ec835a;
  --band-4: #d03b3b;
  /* The light step would sit under 3:1 on the dark page. */
  --band-5: #c45bb0;
}

/* Same in both modes: brand tints are pale whatever the mode. */
:root {
  --on-brand: #121815;
  /* Brand-derived fills. Any surface that tracked the brand swatch before
     still tracks it, in both modes. Text on these is always --on-brand. */
  --brand-fill: color-mix(in srgb, var(--brand) 55%, var(--surface-strong));
  --brand-fill-strong: color-mix(in srgb, var(--brand) 75%, var(--surface-strong));
  /* Secondary text on --surface-strong. Plain --muted only reaches 3.6:1
     there in dark mode, since the strong surface lightens the backdrop. */
  --muted-strong: color-mix(in srgb, var(--ink) 70%, transparent);

  --page-bg: color-mix(in srgb, var(--brand) 10%, var(--bg));
  /* Over map tiles a translucent surface isn't enough: the tiles show through. */
  --surface-solid: color-mix(in srgb, var(--page-bg) 90%, transparent);

  /* Where the floating controls start: under the update bar when there is one,
     which already clears the notch, or under the notch. */
  --hud-top: max(calc(var(--notice-h, 0px) + 14px), calc(env(safe-area-inset-top) + 14px));
  --hud-edge: max(16px, calc(env(safe-area-inset-right) + 16px));
  --hud-edge-left: max(16px, calc(env(safe-area-inset-left) + 16px));
  --glass-btn: 44px;
}

/* flat, static colour derived from theme, no gradients */
body {
  background-color: var(--page-bg);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* ---- glass primitive ---- */
.glass {
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

/* ---- icon button (modal close, refresh) ---- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn.small svg { width: 16px; height: 16px; }

.icon-btn.busy svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- modal shell ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 15, 12, 0.35);
  padding: 12px;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease, visibility 0s linear 0s;
}
.modal-backdrop.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, visibility 0s linear 0.18s;
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}

.modal {
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-strong);
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.18s ease;
}
.modal-backdrop.hidden .modal {
  opacity: 0;
  transform: translateY(14px) scale(0.97);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h2 { font-size: 1.1rem; color: var(--brand-ink); }

/* Section labels inside the modal: "Mode", "Brand colour". */
.modal-section-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

body.modal-open { overflow: hidden; }

/* ---- mode toggle ---- */
.mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface);
}
.mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  font-size: 0.85rem;
  /* --muted-strong, not --muted: the toggle's --surface stacks on the modal's
     --surface-strong, and plain --muted lands at 4.0:1 in dark. */
  color: var(--muted-strong);
  transition: background 0.15s ease, color 0.15s ease;
}
.mode-btn svg { width: 16px; height: 16px; }
.mode-btn > [data-icon] { display: inline-flex; }
.mode-btn.active {
  background: var(--brand-fill);
  color: var(--on-brand);
}

/* Time based mode. Light and dark stay side by side and the third spans the
   row beneath them: two equal columns would put the longer label in a box too
   narrow to read at 320px, and the full width row also signals this is a
   different kind of choice, a rule for picking a mode rather than a mode. */
.mode-btn-wide { grid-column: 1 / -1; }
.mode-note {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---- swatch grid ---- */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.swatch {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  font-size: 0.78rem;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
/* Ringed in its own colour, plus a containment ring. On a light modal the
   pale swatches reach only 1:1 against the surface on their own, so the
   outer ring is what actually carries the active state, at 3.4:1. */
.swatch.active {
  border-color: var(--swatch-color);
  box-shadow:
    0 0 0 2px var(--swatch-color),
    0 0 0 3px color-mix(in srgb, var(--ink) 50%, transparent);
}
.swatch-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--swatch-color);
  border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
  flex-shrink: 0;
}

/* ---- update bar ---- */
/* Above everything, quieter than the page, and tinted enough to read as a
   notice. The tint is --brand-ink rather than --brand: the pastel swatches all
   but vanish at this strength, in dark mode most of all. Text stays --ink.
   Sticky, so the floating tray can sit under it (--notice-h). */
.update-notice {
  position: sticky;
  top: 0;
  z-index: 900;
  background: color-mix(in srgb, var(--brand-ink) 12%, var(--page-bg));
  border-bottom: 1px solid var(--surface-border);
  color: var(--ink);
  font-size: 0.875rem;
  animation: update-notice-in 0.2s ease;
}
.update-notice.is-leaving { animation: update-notice-out 0.18s ease forwards; }

.update-notice-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.5rem 14px;
  /* Under the notch on a phone, where the bar is the topmost thing on screen. */
  padding-top: max(0.5rem, env(safe-area-inset-top));
}

.update-notice p { flex: 1 1 auto; min-width: 0; }
.update-notice .btn { flex: none; padding: 6px 14px; font-size: 0.85rem; }

@keyframes update-notice-in {
  from { opacity: 0; transform: translateY(-6px); }
}
@keyframes update-notice-out {
  to { opacity: 0; transform: translateY(-6px); }
}

/* ---- the floating tray: the nav (wordrain-game's) ---- */

.glass-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--glass-btn);
  height: var(--glass-btn);
  border-radius: 14px;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.glass-btn:hover { transform: translateY(-1px); background: var(--surface-strong); }
.glass-btn svg { width: 22px; height: 22px; }
.glass-btn > [data-icon] { display: inline-flex; }

/* The view on screen. Tracks the brand swatch, with --on-brand on it. */
.glass-btn[aria-selected="true"],
.glass-btn[aria-selected="true"]:hover {
  background: var(--brand-fill);
  color: var(--on-brand);
}

/* Top right, over everything but the modals and the update bar. */
.hud-right {
  position: fixed;
  z-index: 800;
  top: var(--hud-top);
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
  transition: top 0.2s ease;
}
.hud-right > * { pointer-events: auto; }

/* The tray: a column of glass buttons with an arrow tab beside it. Collapsed,
   the buttons slide off the right edge and the tab is left peeking out. */
.tray {
  --tray-shift: calc(var(--glass-btn) + 8px + var(--hud-edge));
  display: flex;
  align-items: flex-start;
  gap: 8px;
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tray.collapsed { transform: translateX(var(--tray-shift)); }

.tray-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: var(--glass-btn);
  border-radius: 12px;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
  transition: border-radius 0.22s ease;
}
.tray-tab > [data-icon] { display: inline-flex; }
.tray-tab svg {
  width: 16px;
  height: 16px;
  transition: transform 0.22s ease;
}
/* At the edge it is a tab, flat on the side the screen cuts off. */
.tray.collapsed .tray-tab { border-radius: 12px 0 0 12px; border-right: none; }
.tray.collapsed .tray-tab svg { transform: rotate(180deg); }

.tray-buttons,
.tray-views {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.tray-buttons {
  margin-right: var(--hud-edge);
  transition: opacity 0.22s ease;
}
.tray.collapsed .tray-buttons { opacity: 0; }

/* Between the views and the two settings buttons. */
.tray-rule {
  width: 24px;
  height: 1px;
  margin: 2px 0;
  background: color-mix(in srgb, var(--ink) 25%, transparent);
}

/* ---- layout ---- */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px;
  padding-bottom: 48px;
}

/* Where the column would run under the open tray, it makes room for it; the
   arrow tab alone only needs the brand line kept clear. */
@media (max-width: 920px) {
  body.tray-open main.container { padding-right: calc(var(--glass-btn) + var(--hud-edge) + 12px); }
  body.tray-open .brand { padding-right: 34px; }
  body:not(.tray-open) .brand { padding-right: 34px; }
}

.view:not([hidden]) { animation: view-in 0.2s ease; }
@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
}

/* ---- brand ---- */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0 14px;
}

/* The app icon, which carries its own background. */
.logo {
  flex-shrink: 0;
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  object-fit: cover;
}

.brand-text h1 {
  font-size: 1.25rem;
  letter-spacing: 0.2px;
  color: var(--ink);
}

.brand-text small {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Fixed-meaning accent: the byline heart must read as a heart on every brand
   colour, so it does not use a theme token. */
.heart { color: #34c759; display: inline-flex; }
.heart svg { width: 13px; height: 13px; }

/* ---- status line ---- */
.status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--muted);
}
.status p { flex: 1; min-width: 0; }

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--surface-border);
  background: var(--brand-fill);
  color: var(--on-brand);
  font-size: 0.9rem;
  white-space: nowrap;
  transition: transform 0.12s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); background: var(--brand-fill-strong); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--surface-strong); color: var(--ink); }
.btn.secondary:hover { background: var(--brand-fill); color: var(--on-brand); }

/* A row of pressed-state buttons where one is on. */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
}
.segmented button {
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--muted-strong);
  transition: background 0.15s ease, color 0.15s ease;
}
.segmented button.active {
  background: var(--brand-fill);
  color: var(--on-brand);
}

.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  font-size: 0.85rem;
  color: var(--muted-strong);
  transition: background 0.15s ease, color 0.15s ease;
}
.toggle-btn > [data-icon] { display: inline-flex; }
.toggle-btn svg { width: 16px; height: 16px; }
.toggle-btn.active {
  background: var(--brand-fill);
  color: var(--on-brand);
}

/* ---- cards ---- */
.card { margin-bottom: 14px; overflow: hidden; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--surface-border);
}

.card-title {
  font-size: 0.95rem;
  color: var(--brand-ink);
}

.card-body { padding: 16px 18px; }
.card-body > * + * { margin-top: 10px; }

.muted { color: var(--muted); font-size: 0.85rem; }
.fine { font-size: 0.78rem; }
.unit { font-size: 0.45em; color: var(--muted); letter-spacing: 0; }

.link {
  color: var(--brand-ink);
  text-decoration: none;
  border-bottom: 1px dashed currentColor;
}
.link:hover { opacity: 0.75; }

.section-title {
  font-size: 1rem;
  color: var(--brand-ink);
  margin: 6px 4px 10px;
}

/* ---- bands ---- */
.band-dot {
  display: inline-block;
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--band-colour, transparent);
  border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
}
.band-dot[data-level=""] { display: none; }
[data-level="1"] { --band-colour: var(--band-1); }
[data-level="2"] { --band-colour: var(--band-2); }
[data-level="3"] { --band-colour: var(--band-3); }
[data-level="4"] { --band-colour: var(--band-4); }
[data-level="5"] { --band-colour: var(--band-5); }

.band-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  font-size: 0.9rem;
  color: var(--ink);
}

/* ---- overview ---- */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-value {
  font-size: 3.6rem;
  line-height: 1;
  letter-spacing: -1px;
}

.stat-value {
  font-size: 2.2rem;
  line-height: 1;
}

.advice {
  display: grid;
  gap: 8px;
}
.advice div {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
}
.advice dt { font-size: 0.8rem; color: var(--muted-strong); }
.advice dd { font-size: 0.95rem; }

.region-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.region-card {
  padding: 14px 16px;
  border-radius: 18px;
}
.region-card h3 { font-size: 0.95rem; color: var(--brand-ink); }
.region-value {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 4px 0;
}
.region-value strong { font-size: 2rem; font-weight: normal; line-height: 1.1; }
.band-label { display: inline-flex; align-items: center; font-size: 0.85rem; }
.region-sub { font-size: 0.85rem; color: var(--muted); }
.region-sub strong { color: var(--ink); font-weight: normal; }

/* ---- tables ---- */
.table-wrap {
  overflow-x: auto;
  max-height: 480px;
  overflow-y: auto;
  border-radius: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}
.data-table th,
.data-table td {
  padding: 8px 10px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--surface-border);
}
.data-table th:first-child { text-align: left; }
.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-solid);
  color: var(--muted-strong);
  font-size: 0.8rem;
}
.data-table tbody th { color: var(--ink); }
.data-table .row-note {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}
/* The sub-index that sets the region's PSI: a ring, not colour alone, plus
   screen reader text in the cell. */
.data-table td.is-top {
  box-shadow: inset 0 0 0 2px var(--brand-ink);
  border-radius: 8px;
}
.data-table tr.gap td {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}
.data-table tr.total th,
.data-table tr.total td {
  border-bottom: none;
  color: var(--brand-ink);
}

/* ---- charts ---- */
.chart { position: relative; }
.chart.is-loading,
#trendChart.is-loading { opacity: 0.5; transition: opacity 0.2s ease; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  list-style: none;
  margin-bottom: 8px;
  font-size: 0.82rem;
  color: var(--muted-strong);
}
.chart-legend li { display: inline-flex; align-items: center; gap: 6px; }

/* A short stroke of the series colour: the line key for legend and tooltip. */
.chart-key {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

.chart-frame { position: relative; }
.chart-svg {
  display: block;
  width: 100%;
  overflow: visible;
  touch-action: pan-y;
  border-radius: 8px;
}

.chart-grid line { stroke: color-mix(in srgb, var(--ink) 10%, transparent); stroke-width: 1; }
.chart-grid line.chart-base { stroke: color-mix(in srgb, var(--ink) 28%, transparent); }
.chart-grid line.chart-guide { stroke: color-mix(in srgb, var(--ink) 30%, transparent); }
.chart-tick {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.chart-guide-label {
  fill: var(--muted);
  font-size: 10.5px;
  paint-order: stroke;
  stroke: var(--page-bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
/* A ring in the page colour keeps each dot legible where lines cross. */
.chart-dot { stroke: var(--page-bg); stroke-width: 2; }
.chart-crossline { stroke: color-mix(in srgb, var(--ink) 45%, transparent); stroke-width: 1; }

.chart-tip {
  position: absolute;
  top: 6px;
  z-index: 2;
  min-width: 140px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--surface-solid);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: 0.8rem;
}
.chart-tip-time { color: var(--muted-strong); margin-bottom: 4px; }
.chart-tip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-strong);
}
.chart-tip-row strong { color: var(--ink); font-weight: normal; font-variant-numeric: tabular-nums; }

/* ---- wind ---- */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.tile { padding: 12px 14px; border-radius: 18px; }
.tile-label { font-size: 0.8rem; color: var(--muted); }
.tile-value { font-size: 1.7rem; line-height: 1.2; }
.tile-value .unit { font-size: 0.55em; }
.tile-sub {
  font-size: 0.8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.station-list { list-style: none; }
.station-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  grid-template-areas: "arrow name speed" "arrow dir speed";
  align-items: center;
  column-gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--surface-border);
}
.station-list li:last-child { border-bottom: none; }
.station-list .wind-arrow { grid-area: arrow; }
.station-name { grid-area: name; }
.station-dir { grid-area: dir; font-size: 0.8rem; color: var(--muted); }
.station-speed { grid-area: speed; text-align: right; font-size: 0.85rem; }
.station-speed strong { font-size: 1.1rem; font-weight: normal; }
.station-speed .muted { display: block; font-size: 0.75rem; }

.wind-arrow {
  display: inline-flex;
  width: 24px;
  height: 24px;
  color: var(--brand-ink);
  transition: transform 0.3s ease;
}
.wind-arrow svg { width: 100%; height: 100%; fill: currentColor; }

/* ---- the Map view: the whole screen ---- */

/* The map sits behind everything, from under the update bar to the bottom. */
#map {
  position: fixed;
  top: var(--notice-h, 0px);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 0;
  background: var(--page-bg);
  font-family: "Jua", "Segoe UI", sans-serif;
}

/* Nothing scrolls behind a full screen map, and the column's own furniture
   steps aside so only the controls float on it. */
body.view-map { overflow: hidden; }
body.view-map .brand,
body.view-map .site-footer { display: none; }
body.view-map main.container { padding: 0; }
body.view-map .view#view-map { animation: none; }

/* The status line and the map's own controls float top left, opposite the tray. */
body.view-map .status {
  position: fixed;
  z-index: 700;
  top: var(--hud-top);
  left: var(--hud-edge-left);
  max-width: min(420px, calc(100vw - var(--hud-edge-left) - var(--glass-btn) - var(--hud-edge) - 48px));
  margin: 0;
  padding: 6px 6px 6px 14px;
  border-radius: 16px;
  background: var(--surface-solid);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.map-controls {
  position: fixed;
  z-index: 700;
  top: calc(var(--hud-top) + 58px);
  left: var(--hud-edge-left);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100vw - var(--hud-edge-left) - var(--glass-btn) - var(--hud-edge) - 48px);
}
.map-controls .segmented,
.map-controls .toggle-btn:not(.active) { background: var(--surface-solid); }

/* Leaflet, in the theme. */
.leaflet-container { font-family: "Jua", "Segoe UI", sans-serif; font-size: 0.8rem; }
.leaflet-bar {
  border: 1px solid var(--surface-border) !important;
  border-radius: 14px !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
}
.leaflet-bar a,
.leaflet-bar a:hover {
  width: 40px !important;
  height: 40px !important;
  line-height: 40px !important;
  background: var(--surface-solid);
  color: var(--ink);
  border-bottom-color: var(--surface-border);
}
.leaflet-bar a.leaflet-disabled { background: var(--surface-solid); color: var(--muted); }
.leaflet-bottom.leaflet-right { margin-bottom: max(0px, env(safe-area-inset-bottom)); }
.leaflet-bottom.leaflet-right .leaflet-bar { margin-right: var(--hud-edge); }
.leaflet-control-attribution {
  background: var(--surface-solid) !important;
  color: var(--muted-strong);
  border-top-left-radius: 10px;
  padding: 2px 8px !important;
}
.leaflet-control-attribution a { color: var(--brand-ink); }

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--surface-solid);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.leaflet-popup-content-wrapper { border-radius: 14px; border: 1px solid var(--surface-border); }
.leaflet-popup-content { margin: 10px 14px; line-height: 1.5; }
.leaflet-popup-content p { margin: 0; }
.leaflet-popup-content strong { font-weight: normal; font-size: 1.05rem; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted-strong); }
.popup-title { color: var(--brand-ink); }

/* OpenStreetMap has no dark style, so in dark mode its tiles are turned down to
   match. Only the tile pane: the pins and controls keep their own colours. */
:root[data-mode="dark"] .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9);
}

/* Pins. Leaflet places the outer element; the pill inside centres on the point. */
.region-pin,
.wind-pin { background: none; border: none; }
.pin {
  position: absolute;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--surface-solid);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 0.8rem;
}
.pin .band-dot { margin-right: 0; }
.pin strong { font-weight: normal; font-size: 1.1rem; line-height: 1; }
.pin.wind {
  gap: 2px;
  padding: 2px 7px 2px 2px;
  font-size: 0.72rem;
  color: var(--muted-strong);
  box-shadow: none;
}
.pin.wind .wind-arrow { width: 20px; height: 20px; }
/* Zoomed out, the speeds would crowd the region pins: arrows only. Further out,
   as a phone opens, the region names go too, leaving dot and value. */
.map-wide .pin.wind { padding: 2px; }
.map-wide .pin.wind > span:last-child { display: none; }
.map-compact .region-pin .pin { padding: 4px 9px; gap: 5px; }
.map-compact .region-pin .pin > span:last-child { display: none; }

/* ---- alerts modal ---- */
.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface);
}
.choice {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--muted-strong);
  transition: background 0.15s ease, color 0.15s ease;
}
.choice-wide { grid-column: 1 / -1; }
.choice.active {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.alerts-toggle { margin-top: 6px; }
.alerts-note { font-size: 0.85rem; color: var(--muted); }
.alerts-note[data-tone="bad"] { color: var(--error); }

/* ---- footer ---- */
.site-footer {
  margin-top: 24px;
  text-align: center;
}
.site-footer p + p { margin-top: 6px; }

/* ---- responsive ---- */
@media (max-width: 480px) {
  :root {
    --glass-btn: 40px;
    --hud-edge: max(10px, calc(env(safe-area-inset-right) + 10px));
    --hud-edge-left: max(10px, calc(env(safe-area-inset-left) + 10px));
  }
  .container { padding: 10px; padding-bottom: 40px; }
  .update-notice-inner { flex-wrap: wrap; padding-left: 10px; padding-right: 10px; gap: 0.5rem; }
  .update-notice p { flex-basis: 100%; }
  .swatch-grid { grid-template-columns: 1fr; }
  .hero-value { font-size: 2.8rem; }
  .tiles { grid-template-columns: 1fr; }
  .card-header { padding: 10px 14px; }
  .card-body { padding: 14px; }
  .brand-text h1 { font-size: 1.1rem; }
}
