:root {
  --ink: #1c130a;
  --ink-soft: #4a3d2c;
  --paper: #ffffff;
  --line: #cbb589;
  --slate: #7a2415;
  --slate-2: #4e1510;
  --wheat: #c97e0a;
  --wheat-dark: #8a5607;
  --rust: #7a2415;
  --denim: #1f4550;
  --denim-dark: #152f36;
  --max-width: 780px;

  /* --- Chart / data-viz palette ---------------------------------------
     Validated against the dataviz skill's six categorical checks
     (lightness band, chroma floor, CVD separation, normal-vision floor,
     contrast) under --pairs all (the strict gate for maps/scatter/small
     multiples, a superset of what line/bar charts need). These are
     brightened/saturated STEPS of the brand hues (rust, denim, gold) --
     not the literal UI hex, which is too dark/desaturated for data marks
     at the required lightness band. Light mode only for now; the site
     has no dark theme yet. */
  --chart-surface: #ffffff;
  --chart-cat-1: #c23b1f;   /* rust family -- series 1 */
  --chart-cat-2: #0e86a8;   /* denim family -- series 2 */
  --chart-cat-3: #c08c0a;   /* gold family -- series 3, bolder step, still clears 3:1 + CVD under --pairs all */
  --chart-cat-4: #6b4c9a;   /* plum family -- series 4, validated with 1-3 under --pairs all */
  --chart-text-primary: var(--ink);
  /* Chart chrome (gridlines/axis/muted text/secondary labels, and map
     boundary strokes) was built from desaturated brand hues -- warm
     tan/beige -- instead of true neutral gray. Chart/map structure should
     read as independent of the brand palette, not themed to it -- the
     same principle map borders now follow (var(--ink), not brand color).
     True neutral (R=G=B exactly), not just "barely warm": the data marks
     carry color; the chrome doesn't. */
  --chart-text-secondary: #525252;
  --chart-muted: #828282;
  --chart-gridline: #e3e3e3;
  --chart-baseline: #c2c2c2;

  /* Sequential (one hue, light->dark; magnitude -- e.g. the county map) */
  --chart-seq-100: #f8e2d8;
  --chart-seq-250: #e3a88f;
  --chart-seq-400: #c23b1f;
  --chart-seq-550: #8a2414;
  --chart-seq-700: #5c160c;

  /* Diverging (two hues + neutral midpoint; polarity -- e.g. trade deficit/surplus) */
  --chart-div-neg-300: #f2c7b8;
  --chart-div-neg-500: #c23b1f;
  --chart-div-neg-700: #7a2415;
  --chart-div-mid: #ece6d6;
  --chart-div-pos-300: #a9d6e2;
  --chart-div-pos-500: #0e86a8;
  --chart-div-pos-700: #0a5c73;

  /* Status (fixed per the dataviz skill -- never themed to the brand) */
  --chart-status-good: #0ca30c;
  --chart-status-warning: #fab219;
  --chart-status-serious: #ec835a;
  --chart-status-critical: #d03b3b;

  --map-frame: var(--ink);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Work Sans", "Segoe UI", -apple-system, sans-serif;
  line-height: 1.65;
  font-size: 18px;
}

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

h1, h2, h3 {
  font-family: "Zilla Slab", Georgia, serif;
  font-weight: 700;
  color: var(--slate-2);
  line-height: 1.2;
  margin-top: 1.6em;
  margin-bottom: 0.5em;
  letter-spacing: -0.01em;
}

h1 { font-size: 2.4em; margin-top: 0.2em; font-weight: 700; color: var(--slate); }
h2 { font-size: 1.5em; border-top: 3px dashed var(--line); padding-top: 0.9em; }
h3 { font-size: 1.15em; color: var(--denim-dark); }

p, ul, ol, table { margin: 0 0 1.1em 0; }

a { color: var(--denim); font-weight: 600; text-decoration-thickness: 2px; text-decoration-color: var(--wheat); }
a:hover { color: var(--slate); text-decoration-color: var(--slate); }

strong { color: var(--ink); }

hr {
  border: none;
  border-top: 3px dashed var(--line);
  margin: 2.2em 0;
}

blockquote {
  margin: 1.4em 0;
  padding: 0.3em 1.4em;
  border-left: 5px solid var(--wheat);
  color: var(--ink-soft);
  font-style: italic;
  background: var(--paper);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
  background: var(--paper);
  border: 2px solid var(--ink);
}

th, td {
  text-align: left;
  padding: 0.6em 0.85em;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th { color: var(--paper); background: var(--slate-2); font-weight: 700; font-family: "Zilla Slab", Georgia, serif; }

tr:last-child td { border-bottom: none; }

ul, ol { padding-left: 1.4em; }

li { margin-bottom: 0.4em; }

/* ------------------------------------------------------------------ */
/* Charts                                                              */
/* ------------------------------------------------------------------ */

.chart {
  margin: 1.8em 0 2.2em 0;
  border: 2px solid var(--ink);
  background: var(--chart-surface);
  padding: 1.4em 1.4em 1em 1.4em;
  position: relative;
}

.chart-title {
  font-family: "Zilla Slab", Georgia, serif;
  font-weight: 700;
  font-size: 1.05em;
  color: var(--chart-text-primary);
  margin: 0 0 0.15em 0;
}

.chart-subtitle {
  font-size: 0.88em;
  color: var(--chart-text-secondary);
  margin: 0 0 1em 0;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4em;
  margin-top: 0.6em;
  font-size: 0.85em;
  color: var(--chart-text-secondary);
  font-weight: 600;
}

.chart-legend-item { display: flex; align-items: center; gap: 0.5em; }

.chart-legend-swatch {
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 2px;
}
.chart-legend-swatch.line { width: 18px; height: 3px; border-radius: 2px; }

/* Map legends read as a boxed cartographic key -- bordered, on the
   chart surface -- rather than a bare row of swatches, matching the
   neutral reference-atlas convention maps should follow generally. */
.map-legend {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  border: 1.5px solid var(--ink);
  background: var(--chart-surface);
  padding: 0.5em 0.9em;
  border-radius: 2px;
}

/* Shaded-relief backdrop (Natural Earth, pre-warped to Mercator) and the
   context layers drawn over it -- real geography, not data, so they stay
   visually quieter than the data-encoded features on top. */
.map-terrain { pointer-events: none; }
.context-county, .county-ref { pointer-events: none; }

/* Zoom controls -- wheel-zoom is off (it would hijack page scroll), so
   these buttons are the primary way in, alongside drag-to-pan and
   pinch-to-zoom on touch. */
.map-zoom-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 3;
}
.map-zoom-btn {
  background: var(--chart-surface);
  border: 1.5px solid var(--ink);
  color: var(--ink);
  font-family: "Work Sans", "Segoe UI", -apple-system, sans-serif;
  font-weight: 700;
  font-size: 15px;
  width: 28px;
  height: 28px;
  line-height: 1;
  cursor: pointer;
  border-radius: 2px;
  padding: 0;
}
.map-zoom-btn:hover { background: var(--line); }
.map-zoom-reset { width: auto; font-size: 10px; padding: 0 6px; }

/* Locator inset -- a small "where is this in the state" reference,
   the same convention print atlases use for an unfamiliar sub-region
   (their equivalent of an Alaska/Hawaii inset on a US map). */
.map-locator {
  position: absolute;
  bottom: 8px;
  left: 8px;
  width: 30%;
  max-width: 112px;
  min-width: 76px;
  background: var(--chart-surface);
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  padding: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  z-index: 2;
}
.map-locator svg { display: block; width: 100%; height: auto; }

/* Below ~480px the map itself is narrow enough that a wide subbasin
   label (e.g. "Tulare Lake Subbasin") can run under the corner inset.
   Drop the inset out of the map and stack it underneath instead --
   still legible, never overlapping the data. */
@media (max-width: 480px) {
  #gw-map-svg-container { display: flex; flex-direction: column; }
  .map-locator {
    position: static;
    order: 2;
    width: 140px;
    max-width: 140px;
    min-width: 0;
    margin: 10px auto 0 auto;
    box-shadow: none;
  }

  /* The explorer's county base now shows the whole state, so the 4
     focus counties (with their own name+value labels) occupy a small
     cluster -- marker name labels crowd right on top of them at this
     width. The marker is still there, still tappable, and still has a
     tooltip and a click-through detail panel; only the always-on
     floating name text goes away. */
  .marker-label { display: none; }
}

.map-locator-caption {
  font-size: 0.6em;
  line-height: 1.3;
  text-align: center;
  color: var(--chart-text-secondary);
  font-weight: 600;
  margin: 3px 0 0 0;
}

.chart svg text {
  font-family: "Work Sans", "Segoe UI", -apple-system, sans-serif;
  fill: var(--chart-muted);
}

.chart svg .axis-line { stroke: var(--chart-baseline); stroke-width: 1; }
.chart svg .gridline { stroke: var(--chart-gridline); stroke-width: 1; }

.chart svg .mark-label {
  font-weight: 700;
  fill: var(--chart-text-primary);
  font-size: 13px;
}

.chart svg .mark-hit { fill: transparent; cursor: pointer; }
.chart svg .mark-hit:hover ~ .mark-visible,
.chart svg .mark-group:hover .mark-visible { filter: brightness(1.12); }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  padding: 0.55em 0.75em;
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.1s ease;
  white-space: nowrap;
  z-index: 5;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-value { font-weight: 700; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 0.4em; }
.chart-tooltip .tt-key { width: 10px; height: 10px; border-radius: 2px; flex: none; }

.chart-table-toggle {
  margin-top: 0.9em;
  font-size: 0.85em;
}
.chart-table-toggle summary {
  cursor: pointer;
  color: var(--chart-text-secondary);
  font-weight: 600;
}
.chart-table-toggle table {
  margin-top: 0.8em;
  font-size: 0.92em;
  box-shadow: none;
}

.layer-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0.4em 0 1.1em 0;
  border: 2px solid var(--ink);
  width: fit-content;
  max-width: 100%;
}

.layer-toggle-btn {
  font-family: "Work Sans", "Segoe UI", -apple-system, sans-serif;
  font-size: 0.85em;
  font-weight: 600;
  color: var(--chart-text-primary);
  background: var(--paper);
  border: none;
  padding: 0.5em 0.9em;
  cursor: pointer;
}
.layer-toggle-btn + .layer-toggle-btn { border-left: 2px solid var(--ink); }
.layer-toggle-btn:hover { background: var(--line); }
.layer-toggle-btn.active { background: var(--slate-2); color: #fff; }

.tl-event { transition: opacity 0.2s ease; }
.tl-event.tl-dimmed { opacity: 0.15; }

.compare-line { transition: opacity 0.2s ease; }
.compare-line.compare-dimmed { opacity: 0.12; }

.chart-hit { cursor: pointer; }
.chart-hit.tl-selected { stroke: var(--ink); stroke-width: 3; }
.chart-hit:focus-visible { outline: 3px solid var(--wheat-dark); outline-offset: 2px; }

.tl-detail {
  margin: 0.6em 0 0 0;
  padding: 0.9em 1.1em;
  border: 2px solid var(--ink);
  border-left-width: 6px;
  background: var(--paper);
  font-size: 0.92em;
}
.tl-detail-empty { color: var(--chart-muted); margin: 0; }
.tl-detail-event {
  font-family: "Zilla Slab", Georgia, serif;
  font-weight: 700;
  font-size: 1.05em;
  color: var(--chart-text-primary);
  margin: 0 0 0.5em 0;
}
.tl-detail-sourcing { color: var(--chart-text-secondary); margin: 0; }
.tl-detail-photo { display: inline-block; margin-top: 0.7em; font-weight: 600; }

.time-slider {
  margin: 0.2em 0 1.1em 0;
  padding: 0.7em 1em;
  background: var(--paper);
  border: 2px solid var(--ink);
}
.time-slider label {
  display: block;
  font-size: 0.85em;
  font-weight: 600;
  color: var(--chart-text-secondary);
  margin-bottom: 0.4em;
}
.time-slider label strong { color: var(--chart-text-primary); font-size: 1.1em; }
.time-slider input[type="range"] {
  width: 100%;
  accent-color: var(--wheat-dark);
}
.time-slider-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.78em;
  color: var(--chart-muted);
  margin-top: 0.1em;
}

.explorer-marker-toggle {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin: 0 0 1.1em 0;
  font-size: 0.85em;
  font-weight: 600;
  color: var(--chart-text-primary);
  cursor: pointer;
  width: fit-content;
}
.explorer-marker-toggle input { accent-color: var(--wheat-dark); cursor: pointer; }

.chart-source {
  margin-top: 1em;
  font-size: 0.78em;
  color: var(--chart-muted);
}

/* ------------------------------------------------------------------ */
/* Historical photographs                                             */
/* ------------------------------------------------------------------ */

.figure {
  margin: 1.8em 0;
  border: 2px solid var(--ink);
  background: var(--paper);
}

.figure img {
  display: block;
  width: 100%;
  height: auto;
  filter: sepia(12%) saturate(85%);
  cursor: zoom-in;
}
.figure img:focus-visible { outline: 3px solid var(--wheat-dark); outline-offset: -3px; }

.figure-caption {
  padding: 0.85em 1.1em 1em 1.1em;
  font-size: 0.85em;
  color: var(--chart-text-secondary);
  border-top: 2px solid var(--ink);
}

.figure-caption strong {
  color: var(--chart-text-primary);
}

.figure-source {
  display: block;
  margin-top: 0.4em;
  font-size: 0.92em;
  color: var(--chart-muted);
}

.figure-pair {
  display: flex;
  gap: 1.4em;
  flex-wrap: wrap;
  margin: 1.8em 0;
}

.figure-pair .figure {
  flex: 1 1 280px;
  margin: 0;
}

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(28, 19, 10, 0.92);
  padding: 2em;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.lightbox.visible { display: flex; }

.lightbox-img {
  display: block;
  max-width: 92vw;
  max-height: 78vh;
  border: 2px solid #fff;
  filter: sepia(12%) saturate(85%);
}

.lightbox-caption {
  color: #f1e3c8;
  max-width: 700px;
  text-align: center;
  font-size: 0.9em;
  margin: 1em 0 0 0;
}
.lightbox-caption strong { color: #fff; }
.lightbox-caption .figure-source { color: #c9b68f; }

.lightbox-close {
  position: absolute;
  top: 1.1em;
  right: 1.3em;
  width: 40px;
  height: 40px;
  background: none;
  border: 2px solid #fff;
  color: #fff;
  font-size: 1.5em;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.15); }
.lightbox-close:focus-visible { outline: 3px solid var(--wheat); outline-offset: 2px; }

/* ------------------------------------------------------------------ */
/* Stat callouts                                                      */
/* ------------------------------------------------------------------ */

.stat-pair {
  display: flex;
  gap: 1.4em;
  flex-wrap: wrap;
  margin: 1.8em 0;
}

.stat-card {
  flex: 1 1 240px;
  border: 2px solid var(--ink);
  background: var(--paper);
  padding: 1.4em 1.2em;
  text-align: center;
}

.stat-number {
  font-family: "Zilla Slab", Georgia, serif;
  font-weight: 700;
  font-size: 2.6em;
  color: var(--chart-cat-1);
  margin: 0 0 0.3em 0;
  line-height: 1;
}

.stat-label {
  font-size: 0.85em;
  color: var(--chart-text-secondary);
  margin: 0;
}

.chart-download-btn {
  display: inline-block;
  margin: 0.9em 0 0 0;
  padding: 0.45em 0.85em;
  font-family: "Work Sans", "Segoe UI", -apple-system, sans-serif;
  font-size: 0.8em;
  font-weight: 600;
  color: var(--chart-text-primary);
  background: var(--paper);
  border: 2px solid var(--ink);
  cursor: pointer;
}
.chart-download-btn:hover { background: var(--line); }
.chart-download-btn:focus-visible { outline: 3px solid var(--wheat-dark); outline-offset: 2px; }

/* Header */

.site-header {
  background: var(--slate-2);
  border-bottom: 6px solid var(--wheat);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
  padding-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.brand {
  color: var(--paper);
  font-family: "Zilla Slab", Georgia, serif;
  font-weight: 700;
  font-size: 1.3em;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.site-header nav {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.site-header nav a {
  color: #f1e3c8;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95em;
}

.site-header nav a:hover { color: var(--wheat); }

/* Main content */

main.content {
  padding-top: 2.4em;
  padding-bottom: 4em;
}

/* Footer */

.site-footer {
  background: var(--ink);
  color: #d9c9ab;
  padding: 2em 0;
  margin-top: 2em;
  font-size: 0.9em;
  border-top: 5px solid var(--wheat-dark);
}

.site-footer a { color: #f1e3c8; }
.site-footer a:hover { color: var(--wheat); }

@media (max-width: 600px) {
  body { font-size: 16.5px; }
  h1 { font-size: 1.9em; }
  .site-header .wrap { flex-direction: column; align-items: flex-start; }
}
