:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #6b7686;
  --border: #e2e6eb;
  --accent: #1f6feb;
  --on-accent: #fff;
  --warn: #c2410c;
  /* intensity scales, as RGB channels so cells can vary alpha */
  --rain: 37 99 235;
  --snow: 124 58 237;
  --wind: 234 160 8;
  --gale: 220 38 38;
  --cold: 14 116 196;
  color-scheme: light dark;
}
/* Dark theme: follows the system unless the visitor picked light or dark (data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151b;
    --surface: #1a2029;
    --text: #e6eaf0;
    --muted: #8e99a8;
    --border: #2a323d;
    --accent: #6ea8fe;
  --on-accent: #0b1220;
    --warn: #fb923c;
    --rain: 59 130 246;
    --snow: 167 139 250;
    --wind: 250 204 21;
    --gale: 248 113 113;
    --cold: 56 189 248;
  }
}
:root[data-theme="dark"] {
  --bg: #11151b;
  --surface: #1a2029;
  --text: #e6eaf0;
  --muted: #8e99a8;
  --border: #2a323d;
  --accent: #6ea8fe;
  --on-accent: #0b1220;
  --warn: #fb923c;
  --rain: 59 130 246;
  --snow: 167 139 250;
  --wind: 250 204 21;
  --gale: 248 113 113;
  --cold: 56 189 248;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
/* The theme button shows the mode it switches to. */
.icon-btn .sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .sun { display: block; }
  :root:not([data-theme="light"]) .icon-btn .moon { display: none; }
}
:root[data-theme="dark"] .icon-btn .sun { display: block; }
:root[data-theme="dark"] .icon-btn .moon { display: none; }

* { box-sizing: border-box; }
body {
  margin: 0 auto;
  max-width: 960px;
  padding: 0 16px 32px;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.crumbs { margin-top: 20px; font-size: 0.9rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.crumbs .sep { opacity: 0.6; }
.crumbs + h1 { margin-top: 4px; }
.siblings { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.siblings > .muted { width: 100%; font-size: 0.9rem; }
h1 { margin: 24px 0 0; font-size: 1.75rem; }
h1 + p { margin-top: 2px; }
.muted { color: var(--muted); font-weight: normal; }

header { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand svg { color: var(--accent); }
.brand:hover { text-decoration: none; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}

.search { position: relative; }
#q {
  width: 100%; padding: 12px 14px; font: inherit;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
#results {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px 0; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
}
#results a { display: block; padding: 8px 14px; color: var(--text); }
#results a:hover, #results [aria-selected] a { background: var(--bg); text-decoration: none; }
#results .empty { padding: 8px 14px; }

.intro { margin: 20px 0 8px; color: var(--muted); }
.group { margin: 24px 0 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.range-card { padding: 12px 0; border-bottom: 1px solid var(--border); }
.range-card h2 { margin: 0 0 4px; font-size: 1.05rem; }
.range-card h2 .muted { font-size: 0.9rem; margin-left: 4px; }
.range-card p { margin: 0; }

.bands { display: inline-flex; margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.bands button {
  font: inherit; font-weight: 600; padding: 6px 14px; cursor: pointer;
  border: 0; border-left: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.bands button:first-child { border-left: 0; }
.bands button span { font-weight: normal; font-size: 0.85rem; color: var(--muted); }
.bands button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.bands button[aria-pressed="true"] span { color: inherit; opacity: 0.85; }
.bands.units { font-size: 0.85rem; }
.bands.units button { padding: 4px 12px; }

.scroll { overflow-x: auto; margin-top: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
tbody tr:last-child > * { border-bottom: 0; }
tbody th { font-weight: 600; }
.icon { font-size: 1.2rem; }
.warn { color: var(--warn); font-weight: 600; }
.low { opacity: 0.55; }

/* Base chip style must come before the intensity colors so they can override its background. */
.highlights { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
.highlights + .highlights { margin-top: 8px; }
.highlights[hidden] { display: none; }
a.chip { color: var(--text); }
a.chip:hover { text-decoration: none; filter: brightness(0.95); }
.highlights > .muted:first-child { min-width: 6.5em; } /* lines up the row labels */
.chip { display: inline-block; max-width: 100%; padding: 4px 12px; border-radius: 15px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 0.9rem; }
.chip small { font-weight: normal; opacity: 0.75; margin-left: 2px; }

/* Intensity colors: stronger = more opaque. Top levels flip to white text. */
.r1 { background: rgb(var(--rain) / 0.14); }
.r2 { background: rgb(var(--rain) / 0.35); }
.r3 { background: rgb(var(--rain) / 0.8); color: #fff; }
.s1 { background: rgb(var(--snow) / 0.14); }
.s2 { background: rgb(var(--snow) / 0.35); }
.s3 { background: rgb(var(--snow) / 0.8); color: #fff; }
.w1 { background: rgb(var(--wind) / 0.18); }
.w2 { background: rgb(var(--wind) / 0.45); }
.w3 { background: rgb(var(--gale) / 0.6); color: #fff; }
.w4 { background: rgb(var(--gale) / 0.9); color: #fff; }
.c1 { background: rgb(var(--cold) / 0.15); }
.c2 { background: rgb(var(--cold) / 0.4); }
.c3 { background: rgb(var(--cold) / 0.85); color: #fff; }


table.grid th, table.grid td { padding: 6px 4px; min-width: 44px; text-align: center; font-size: 0.9rem; }
table.grid thead tr:first-child th { font-size: 0.85rem; color: var(--text); text-transform: none; letter-spacing: 0; }
table.grid .period-names th { font-size: 0.7rem; padding-top: 0; }
table.grid tbody th { text-align: left; padding: 6px 12px; font-size: 0.85rem; }
table.grid tbody th small { color: var(--muted); font-weight: normal; }
table.grid .day-start { border-left: 2px solid var(--border); }
table.grid td.icon { font-size: 1.3rem; vertical-align: top; }
/* Descriptor under each weather icon; wraps to two lines in narrow cells */
.desc { display: block; margin-top: 2px; font-size: 0.68rem; line-height: 1.2; color: var(--muted); white-space: normal; }
table.grid td.icon .desc { max-width: 60px; margin-inline: auto; }
table.range .desc { margin-bottom: 2px; }
table.grid :is(.w1, .w2, .w3, .w4, .s1, .s2, .s3, .r1, .r2, .r3, .c1, .c2, .c3) { font-weight: 700; }
.none { color: var(--muted); opacity: 0.6; font-weight: normal; }
.arrow { display: inline-block; font-style: normal; font-size: 0.85em; transform: rotate(var(--dir)); }

table.grid tbody th, table.range tbody th { position: sticky; left: 0; z-index: 1; background: var(--surface); }
table.grid thead th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }

table.range td, table.range thead th:not(:first-child) { text-align: center; }
table.range td { font-size: 0.9rem; vertical-align: top; }
.badge { display: block; margin-top: 4px; padding: 1px 6px; border-radius: 4px; font-size: 0.75rem; font-weight: 600; }

.note { font-size: 0.85rem; color: var(--muted); margin-top: 12px; }
.error { color: var(--warn); }
footer { margin-top: 32px; font-size: 0.8rem; color: var(--muted); }

@media (max-width: 560px) {
  header { padding: 10px 0; }
  h1 { margin-top: 16px; font-size: 1.5rem; }
  .crumbs { margin-top: 14px; }

  /* Band picker spans the width, with each elevation on its own line */
  .bands:not(.units) { display: flex; }
  .bands:not(.units) button { flex: 1; padding: 6px 8px; }
  .bands:not(.units) button span { display: block; }
  th, td { padding: 8px; }

  /* Row labels sit above their chips instead of beside them */
  .highlights { gap: 6px; margin-top: 14px; }
  .highlights > .muted:first-child { width: 100%; min-width: 0; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
  .highlights > small { width: 100%; }

  /* Tables run edge to edge so more days fit */
  .scroll { margin-inline: -16px; border-radius: 0; border-inline: 0; }
  table.grid th, table.grid td { min-width: 40px; padding: 6px 3px; }
  table.grid tbody th { padding: 6px 8px; font-size: 0.8rem; white-space: normal; line-height: 1.2; }
  table.grid tbody th small { display: block; }
  table.range th, table.range td { padding: 8px 6px; }
  table.range tbody th { min-width: 96px; max-width: 120px; padding-left: 12px; font-size: 0.85rem; white-space: normal; line-height: 1.3; }
  table.range thead th:first-child { padding-left: 12px; }
  table.range td { min-width: 76px; }

  /* Smaller chips so other peaks fit two to a line */
  .siblings { gap: 6px; }
  .siblings .chip { padding: 3px 10px; font-size: 0.85rem; }
}
