/* ---------------------------------------------------------------------------
   Tokens. Light is the base; the dark values are declared twice on purpose --
   once for the OS setting, once for the explicit toggle -- so the toggle wins
   in both directions. Every colour below is taken from the validated reference
   palette; the drought ramp is the official U.S. Drought Monitor scale.
--------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  --plane:          #f9f9f7;
  --surface:        #fcfcfb;
  --ink:            #0b0b0b;
  --ink-2:          #52514e;
  --ink-muted:      #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --hairline:       rgba(11, 11, 11, 0.10);

  --series-1:       #2a78d6;   /* the historical distribution */
  --series-2:       #1baf7a;   /* the comparison year */
  --focus:          #0b0b0b;   /* the current year -- ink, so it never competes
                                  with the warm drought ramp on the precip panel */

  --band-outer:     rgba(42, 120, 214, 0.10);
  --band-inner:     rgba(42, 120, 214, 0.16);
  --ensemble:       rgba(137, 135, 129, 0.40);

  /* U.S. Drought Monitor scale, as washes rather than lines */
  --d1: #fcd37f;
  --d2: #ffaa00;
  --d3: #e60000;
  --d4: #730000;
  --d1-fill: rgba(252, 211, 127, 0.38);
  --d2-fill: rgba(255, 170, 0, 0.28);
  --d3-fill: rgba(230, 0, 0, 0.20);
  --d4-fill: rgba(115, 0, 0, 0.22);

  /* warm/cool diverging pair, for a departure from normal. Deliberately not the
     drought ramp: that ramp is a status scale and means one specific thing.
     Contrast on --surface is 5.8 warm / 5.6 cool, near enough to equal that
     neither direction reads as the louder one. */
  --anomaly-warm: #b5361f;
  --anomaly-cool: #2166b8;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:      #0d0d0d;
    --surface:    #1a1a19;
    --ink:        #ffffff;
    --ink-2:      #c3c2b7;
    --ink-muted:  #898781;
    --grid:       #2c2c2a;
    --axis:       #383835;
    --hairline:   rgba(255, 255, 255, 0.10);
    --series-1:   #3987e5;
    --series-2:   #199e70;
    --focus:      #ffffff;
    --band-outer: rgba(57, 135, 229, 0.14);
    --band-inner: rgba(57, 135, 229, 0.22);
    --ensemble:   rgba(137, 135, 129, 0.45);
    --d4:         #9c2020;   /* lifted; #730000 is unreadable on the dark surface */
    --d1-fill:    rgba(252, 211, 127, 0.30);
    --d2-fill:    rgba(255, 170, 0, 0.28);
    --d3-fill:    rgba(230, 0, 0, 0.28);
    --d4-fill:    rgba(156, 32, 32, 0.36);
    /* stepped up, not flipped -- the light values sit at 2.9 and 3.0 on the
       dark surface, under the 4.5 floor. These land at 6.8 / 6.6. */
    --anomaly-warm: #ff7a5c;
    --anomaly-cool: #57a3f3;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:      #0d0d0d;
  --surface:    #1a1a19;
  --ink:        #ffffff;
  --ink-2:      #c3c2b7;
  --ink-muted:  #898781;
  --grid:       #2c2c2a;
  --axis:       #383835;
  --hairline:   rgba(255, 255, 255, 0.10);
  --series-1:   #3987e5;
  --series-2:   #199e70;
  --focus:      #ffffff;
  --band-outer: rgba(57, 135, 229, 0.14);
  --band-inner: rgba(57, 135, 229, 0.22);
  --ensemble:   rgba(137, 135, 129, 0.45);
  --d4:         #9c2020;
  --d1-fill:    rgba(252, 211, 127, 0.30);
  --d2-fill:    rgba(255, 170, 0, 0.28);
  --d3-fill:    rgba(230, 0, 0, 0.28);
  --d4-fill:    rgba(156, 32, 32, 0.36);
  --anomaly-warm: #ff7a5c;
  --anomaly-cool: #57a3f3;
}

/* --------------------------------------------------------------------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

.page-head { padding: 40px 0 8px; }
.page-head h1 { margin: 0; font-size: 30px; letter-spacing: -0.02em; }
.lede { margin: 6px 0 0; color: var(--ink-2); }

/* navigation ------------------------------------------------------------ */

.nav { border-bottom: 1px solid var(--hairline); margin-top: 18px; }
.nav .wrap { display: flex; align-items: center; gap: 4px; }
.nav a {
  font-size: 14px;
  color: var(--ink-2);
  text-decoration: none;
  padding: 11px 13px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.nav a:hover { color: var(--ink); }
/* the current page is marked by weight and a rule, not by colour alone */
.nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--focus);
}
.nav .nav-end { margin-left: auto; min-height: 32px; padding: 5px 11px; font-size: 13px; }
@media (max-width: 640px) {
  .nav .wrap { overflow-x: auto; }
  .nav .nav-end { margin-left: 8px; }
}

/* home page cards ------------------------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: inherit;
}
.card:hover { border-color: var(--axis); }
.card h2 { margin: 0 0 6px; font-size: 19px; letter-spacing: -0.01em; }
.card p { margin: 0 0 12px; font-size: 14px; color: var(--ink-2); }
.card-go { font-size: 14px; color: var(--focus); }

/* about page prose ------------------------------------------------------ */

.prose { max-width: 68ch; margin: 26px 0; }
.prose h2 { font-size: 20px; letter-spacing: -0.01em; margin: 30px 0 8px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: 15px; margin: 22px 0 4px; }
.prose p { margin: 0 0 10px; color: var(--ink-2); }
.prose ul { margin: 0 0 10px; padding-left: 20px; color: var(--ink-2); }
.prose a { color: var(--focus); }

/* controls -------------------------------------------------------------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  margin: 24px 0 20px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.ctl { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.ctl > span { color: var(--ink-2); }
.ctl select, .ctl-btn {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--plane);
  border: 1px solid var(--hairline);
  border-radius: 7px;
  padding: 7px 10px;
  min-height: 36px;
}
.ctl-btn { cursor: pointer; align-self: flex-end; }
.ctl-btn:hover { border-color: var(--axis); }

/* stat tiles ------------------------------------------------------------ */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}
/* display:grid above would otherwise beat the browser's [hidden] rule, so a
   section the script hides would still show as an empty grid */
.tiles[hidden] { display: none; }
.tile {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.tile .k { font-size: 12px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tile .v { font-size: 26px; line-height: 1.2; margin-top: 3px; }   /* proportional figures */
.tile .s { font-size: 13px; color: var(--ink-2); }

/* Departure from normal, beside the forecast temperature. The arrow and the
   sign both carry the direction, so colour is reinforcement and the tile still
   reads in greyscale -- and the .s line underneath spells it out in words. */
.tile .delta {
  margin-left: 10px;
  font-size: 0.85em;      /* weight and colour carry it; full 26px overflows a
                             narrow tile once the temperature is beside it */
  font-weight: 600;
  white-space: nowrap;    /* wrap before the sign, never inside "+5.2°" */
}
.tile .delta .arrow { font-size: 0.78em; margin-right: 2px; }
.tile .delta.warm { color: var(--anomaly-warm); }
.tile .delta.cool { color: var(--anomaly-cool); }
.tile .delta.even { color: var(--ink-muted); }
/* severity swatch; the value text stays in ink so colour is never the only cue */
.tile .dot {
  display: inline-block;
  width: 11px; height: 11px;
  border-radius: 3px;
  margin-right: 9px;
  vertical-align: middle;
  position: relative; top: -2px;
}

.tiles-head {
  font-size: 13px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin: 26px 0 10px;
}

/* chart panels ---------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 18px 18px 14px;
  margin-bottom: 22px;
}
.panel h2 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.panel .sub { margin: 3px 0 12px; font-size: 13px; color: var(--ink-2); }

/* the legend is also the show/hide control */
.legend { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--plane);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 5px 12px 5px 9px;
  min-height: 30px;
  cursor: pointer;
}
.chip:hover { border-color: var(--axis); }
.chip[aria-pressed="false"] { color: var(--ink-muted); }
.chip[aria-pressed="false"] .sw { opacity: 0.3; }

/* hover/focus bubble explaining what a legend layer is */
.chip[data-tip] { position: relative; }
.chip[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 0;
  z-index: 10;
  width: max-content;
  max-width: 230px;
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  color: var(--ink);
  background: var(--plane);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.16);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  pointer-events: none;
}
.chip[data-tip]:hover::after,
.chip[data-tip]:focus-visible::after { opacity: 1; visibility: visible; }
/* the last chips in a row would push the bubble off the right edge */
.chip[data-tip]:nth-last-child(-n+2)::after { left: auto; right: 0; }
@media (hover: none) { .chip[data-tip]::after { display: none; } }
.sw { width: 13px; height: 13px; border-radius: 3px; flex: none; }
.sw.line { height: 3px; border-radius: 2px; }
/* the drought chip shows the whole severity ramp rather than one step */
.sw.ramp {
  width: 22px;
  background: linear-gradient(to right, var(--d1) 0 25%, var(--d2) 25% 50%,
                                        var(--d3) 50% 75%, var(--d4) 75% 100%);
}

.chart { width: 100%; height: 420px; }

.panel-foot { display: flex; justify-content: flex-end; margin-top: 6px; }
.link-btn {
  font: inherit; font-size: 13px; color: var(--ink-2);
  background: none; border: 0; cursor: pointer; padding: 4px 2px;
  text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:hover { color: var(--ink); }

/* table view ------------------------------------------------------------ */

.tablewrap { max-height: 380px; overflow: auto; margin-top: 10px; border: 1px solid var(--hairline); border-radius: 8px; }
.tablewrap[hidden] { display: none; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th {
  position: sticky; top: 0;
  background: var(--surface);
  color: var(--ink-2);
  font-weight: 600;
  border-bottom: 1px solid var(--axis);
}
tbody tr + tr td { border-top: 1px solid var(--grid); }

/* footer ---------------------------------------------------------------- */

.page-foot { margin: 34px 0 60px; color: var(--ink-2); font-size: 14px; }
.page-foot h2 { font-size: 15px; color: var(--ink); margin: 0 0 8px; }
.page-foot ul { margin: 8px 0; padding-left: 18px; }
.page-foot a { color: var(--series-1); }
.fine { font-size: 13px; color: var(--ink-muted); }

@media (max-width: 640px) {
  .chart { height: 320px; }
  .page-head h1 { font-size: 24px; }
}
