/* Early Watauga — design tokens + base styles.
   Aesthetic: a county ledger set by a small newspaper. The palette comes from the
   Watauga County seal: mountain greens, creek and sky blues, rhododendron pink,
   stone, hairline rules, mono for dates/case numbers, tabular numerals.
   Fonts are a neutral system stack on purpose: no webfont request, no layout shift, and it
   is the look Sunny picked over two webfont pairings (see docs/FONTS.md). Swap
   --font-display/--font-body later and nothing else needs to change. */

:root {
  color-scheme: light dark;

  /* Type — the same system stack earlybid.bid uses, so the two sites read as one family.
     Georgia first (not Iowan Old Style): sturdier, wider, and it has a real bold. */
  --font-display: Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  /* Headings sit one step above the original 600. One token, so retuning is one line. */
  --display-weight: 700;
  --display-track: -0.01em;

  /* Fluid type scale (mobile → desktop). */
  --fs-xs: clamp(0.72rem, 0.7rem + 0.1vw, 0.78rem);
  --fs-sm: clamp(0.82rem, 0.8rem + 0.15vw, 0.9rem);
  --fs-md: clamp(1rem, 0.96rem + 0.2vw, 1.08rem);
  --fs-lg: clamp(1.15rem, 1.05rem + 0.5vw, 1.35rem);
  --fs-xl: clamp(1.5rem, 1.2rem + 1.4vw, 2.2rem);
  --fs-2xl: clamp(2rem, 1.4rem + 3vw, 3.6rem);
  --fs-3xl: clamp(2.6rem, 1.6rem + 5vw, 5.2rem);
  /* Front-page lead only. */
  --fs-lead: clamp(2rem, 1.3rem + 2.8vw, 3.35rem);
  --lh-tight: 1.08;
  --lh-snug: 1.25;
  --lh-body: 1.55;

  /* Spacing. */
  --s-1: 0.25rem; --s-2: 0.5rem; --s-3: 0.75rem; --s-4: 1rem; --s-5: 1.5rem;
  --s-6: 2rem; --s-7: 3rem; --s-8: 4.5rem; --s-9: 6rem;
  --gutter: clamp(1rem, 4vw, 2.5rem);
  --measure: 42rem;
  --wide: 76rem;
  --radius: 2px;

  /* County-seal palette (light). Pale colors are fills; text accents are
     accessibility-darkened shades of the same sampled hues. */
  --paper: #f7f8f9;
  --paper-2: #e3eaef;
  --paper-raised: #ffffff;
  --ink: #1e331c;         /* deep forest */
  --ink-2: #46534a;
  --ink-3: #667269;
  --rule: #cedde8;        /* pale sky */
  --rule-strong: #599995; /* creek */
  --accent: #294824;      /* evergreen */
  --accent-ink: #fdfdfd;
  --accent-2: #9b3e75;    /* rhododendron, darkened for text */
  --accent-3: #2f716c;    /* creek, darkened for text */
  --warn: #756b34;        /* stone */
  --focus: var(--accent-2);
  --shadow: 0 1px 0 rgba(30, 51, 28, 0.08), 0 8px 24px -16px rgba(30, 51, 28, 0.3);

  /* Confidence A–D. */
  --conf-a-bg: var(--accent); --conf-a-fg: var(--accent-ink);
  --conf-b-bg: var(--accent-3); --conf-b-fg: var(--accent-ink);
  --conf-c-bg: #d8c56a; --conf-c-fg: #1e331c;
  --conf-d-bg: transparent; --conf-d-fg: #4f6070; --conf-d-border: #599995;

  /* Status ladder groups. */
  --st-early-fg: #756b34; --st-early-bg: #f3efcf;     /* proposed, applied, pending-hearing */
  --st-cleared-fg: var(--accent); --st-cleared-bg: #dcecd5; /* approved, permitted, preparing to build */
  --st-building-fg: #1e331c; --st-building-bg: #da88b9; /* under construction */
  --st-done-fg: var(--accent-ink); --st-done-bg: var(--accent); /* open, complete */
  --st-closed-fg: #70445d; --st-closed-bg: #f1e2ea;     /* operated, then closed */
  --st-delayed-fg: #1e331c; --st-delayed-bg: #d8c56a; /* delayed */
  --st-dead-fg: #4f6070; --st-dead-bg: #e8ecea;       /* withdrawn, canceled */
  --st-far-fg: #35516a; --st-far-bg: #e6f5fd;        /* long-range */

  /* Compatibility aliases used by confirmation/unsubscribe pages. */
  --color-text: var(--ink);
  --color-muted: var(--ink-2);
  --color-accent: var(--accent);
  --color-on-accent: var(--accent-ink);

  --emdash-search-bg: var(--paper-raised);
  --emdash-search-text: var(--ink);
  --emdash-search-muted: var(--ink-3);
  --emdash-search-border: var(--rule);
  --emdash-search-hover: var(--paper-2);
  --emdash-search-highlight: var(--accent-2);
}

/* Dark tokens. An explicit choice stamps data-theme on <html>;
   the default "system" setting stamps nothing, so only the media query separates them.
   The :not([data-theme="light"]):not([data-theme="earlybid"]) guard lets an explicit
   light or EarlyBid choice beat a dark OS. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="earlybid"]) {
    --paper: #151b17;
    --paper-2: #1e2c1c;
    --paper-raised: #263d23;
    --ink: #f7f8f9;
    --ink-2: #cedde8;
    --ink-3: #8c9fa8;
    --rule: #34522e;
    --rule-strong: #599995;
    --accent: #68a54c;
    --accent-ink: #142717;
    --accent-2: #e49ac3;
    --accent-3: #86bab7;
    --warn: #d8c56a;
    --focus: var(--accent-2);
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 10px 28px -16px rgba(0, 0, 0, 0.7);

    --conf-c-bg: #d8c56a; --conf-c-fg: #142717;
    --conf-d-bg: transparent; --conf-d-fg: #c9e2f6; --conf-d-border: #599995;

    --st-early-fg: #e7dca4; --st-early-bg: #4c431f;
    --st-cleared-fg: #b9dca8; --st-cleared-bg: #294824;
    --st-building-fg: #142717; --st-building-bg: #e49ac3;
    --st-done-fg: #142717; --st-done-bg: #68a54c;
    --st-closed-fg: #efc6dc; --st-closed-bg: #4b2d3e;
    --st-delayed-fg: #142717; --st-delayed-bg: #d8c56a;
    --st-dead-fg: #c2d2c6; --st-dead-bg: #243b21;
    --st-far-fg: #a5cced; --st-far-bg: #243b21;
  }
}

/* Explicit dark choice wins over a light OS. */
:root[data-theme="dark"] {
    --paper: #151b17;
    --paper-2: #1e2c1c;
    --paper-raised: #263d23;
    --ink: #f7f8f9;
    --ink-2: #cedde8;
    --ink-3: #8c9fa8;
    --rule: #34522e;
    --rule-strong: #599995;
    --accent: #68a54c;
    --accent-ink: #142717;
    --accent-2: #e49ac3;
    --accent-3: #86bab7;
    --warn: #d8c56a;
    --focus: var(--accent-2);
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 10px 28px -16px rgba(0, 0, 0, 0.7);

    --conf-c-bg: #d8c56a; --conf-c-fg: #142717;
    --conf-d-bg: transparent; --conf-d-fg: #c9e2f6; --conf-d-border: #599995;

    --st-early-fg: #e7dca4; --st-early-bg: #4c431f;
    --st-cleared-fg: #b9dca8; --st-cleared-bg: #294824;
    --st-building-fg: #142717; --st-building-bg: #e49ac3;
    --st-done-fg: #142717; --st-done-bg: #68a54c;
    --st-closed-fg: #efc6dc; --st-closed-bg: #4b2d3e;
    --st-delayed-fg: #142717; --st-delayed-bg: #d8c56a;
    --st-dead-fg: #c2d2c6; --st-dead-bg: #243b21;
    --st-far-fg: #a5cced; --st-far-bg: #243b21;
}


:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* EarlyBid family look: cream, navy, gold, coral. From earlybid.bid tokens.
   Always light; gold is for fills and buttons, not body links (contrast). */
:root[data-theme="earlybid"] {
  color-scheme: light;
  --paper: #fff9eb;
  --paper-2: #fff3d1;
  --paper-raised: #ffffff;
  --ink: #102638;
  --ink-2: #53606a;
  --ink-3: #7a8790;
  --rule: #cbd1d4;
  --rule-strong: #102638;
  --accent: #ebc500;
  --accent-ink: #091923;
  --accent-2: #e95d3f;
  --accent-3: #102638;
  --warn: #c9a000;
  --focus: #e95d3f;
  --shadow: 4px 4px 0 #102638;
  --radius: 0;

  --conf-a-bg: #102638; --conf-a-fg: #ebc500;
  --conf-b-bg: #e95d3f; --conf-b-fg: #fff9eb;
  --conf-c-bg: #ebc500; --conf-c-fg: #091923;
  --conf-d-bg: transparent; --conf-d-fg: #53606a; --conf-d-border: #102638;

  --st-early-fg: #091923; --st-early-bg: #ebc500;
  --st-cleared-fg: #fff9eb; --st-cleared-bg: #102638;
  --st-building-fg: #fff9eb; --st-building-bg: #e95d3f;
  --st-done-fg: #ebc500; --st-done-bg: #102638;
  --st-closed-fg: #102638; --st-closed-bg: #e8eef2;
  --st-delayed-fg: #091923; --st-delayed-bg: #ebc500;
  --st-dead-fg: #53606a; --st-dead-bg: #e8eef2;
  --st-far-fg: #102638; --st-far-bg: #d9e2e8;
}

/* The masthead is sticky, so anything reached by fragment (paging, a linked
   timeline event) needs clearance or it lands underneath it. */
:target, #results { scroll-margin-top: 6rem; }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
  /* Faint paper grain; pure CSS, no image request. */
  background-image:
    radial-gradient(rgba(30, 51, 28, 0.035) 0.6px, transparent 0.6px),
    radial-gradient(rgba(30, 51, 28, 0.025) 0.6px, transparent 0.6px);
  background-size: 7px 7px, 11px 11px;
  background-position: 0 0, 3px 5px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="earlybid"]) body {
    background-image:
      radial-gradient(rgba(247, 248, 249, 0.03) 0.6px, transparent 0.6px),
      radial-gradient(rgba(247, 248, 249, 0.02) 0.6px, transparent 0.6px);
  }
}
:root[data-theme="dark"] body {
  background-image:
    radial-gradient(rgba(247, 248, 249, 0.03) 0.6px, transparent 0.6px),
    radial-gradient(rgba(247, 248, 249, 0.02) 0.6px, transparent 0.6px);
}
:root[data-theme="earlybid"] body { background-image: none; }
:root[data-theme="earlybid"] ::selection { background: #ebc500; color: #091923; }
:root[data-theme="earlybid"] a { color: var(--ink); text-decoration-color: var(--accent-2); }
:root[data-theme="earlybid"] a:hover { color: var(--accent-2); }
:root[data-theme="earlybid"] .kicker { color: var(--accent-2); }
:root[data-theme="earlybid"] .btn-accent { color: var(--accent-ink); box-shadow: 4px 4px 0 var(--ink); }
:root[data-theme="earlybid"] .btn-accent:hover {
  color: var(--paper-raised);
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--ink);
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  line-height: var(--lh-tight);
  letter-spacing: var(--display-track);
  margin: 0 0 var(--s-3);
  text-wrap: balance;
}
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { margin: 0 0 var(--s-4); }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 0.15em; }
a:hover { color: var(--accent-2); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
img, svg, video { max-width: 100%; height: auto; display: block; }
small { font-size: var(--fs-sm); }
hr { border: 0; border-top: 1px solid var(--rule); margin: var(--s-6) 0; }
blockquote {
  margin: var(--s-4) 0;
  padding: var(--s-2) var(--s-4);
  border-left: 3px solid var(--accent-2);
  color: var(--ink-2);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.02em;
}
code, kbd, .mono { font-family: var(--font-mono); font-size: 0.92em; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; vertical-align: top; padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--rule); }
th { font-weight: 600; color: var(--ink-2); font-size: var(--fs-sm); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- utilities ---------- */
.wrap { width: min(100% - 2 * var(--gutter), var(--wide)); margin-inline: auto; }
.measure { max-width: var(--measure); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.kicker {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.num { font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.rule-top { border-top: 1px solid var(--rule); }
.rule-strong { border-top: 2px solid var(--ink); }

/* Section heading: newspaper department head — small caps line with a rule that runs on. */
.dept {
  display: flex; align-items: baseline; gap: var(--s-3);
  margin: var(--s-7) 0 var(--s-4);
}
.dept h2 { font-size: var(--fs-lg); margin: 0; white-space: nowrap; }
.dept::after { content: ""; flex: 1; border-top: 1px solid var(--rule-strong); transform: translateY(-0.35em); }
.dept .more { font-size: var(--fs-sm); white-space: nowrap; }

/* Type chip. One definition — StoryCard, the story page and the wire all wear it, and the
   colour groups are the same ones the status ladder uses (src/lib/ui.mjs storyTypeGroup). */
.chip-type {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  padding: 0.15em 0.45em;
  border-radius: var(--radius);
  color: var(--chip-fg);
  background: var(--chip-bg);
}
.chip-type-early { --chip-fg: var(--st-early-fg); --chip-bg: var(--st-early-bg); }
.chip-type-cleared { --chip-fg: var(--st-cleared-fg); --chip-bg: var(--st-cleared-bg); }
.chip-type-building { --chip-fg: var(--st-building-fg); --chip-bg: var(--st-building-bg); }
.chip-type-done { --chip-fg: var(--st-done-fg); --chip-bg: var(--st-done-bg); }
.chip-type-delayed { --chip-fg: var(--st-delayed-fg); --chip-bg: var(--st-delayed-bg); }
.chip-type-dead { --chip-fg: var(--st-dead-fg); --chip-bg: var(--st-dead-bg); }
.chip-type-far { --chip-fg: var(--st-far-fg); --chip-bg: var(--st-far-bg); }
.chip-type-lg { font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.1em; padding: 0.25em 0.55em; }

/* Headline link: ink until hover, then rust. Every list on the site uses it. */
.hl { color: var(--ink); text-decoration: none; }
.hl:hover { color: var(--accent-2); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.12em; }

/* Buttons / links that act like buttons. */
.btn {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 0.55rem 0.95rem;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background: transparent; color: var(--ink);
  font-weight: 600; font-size: var(--fs-sm); text-decoration: none;
  cursor: pointer; line-height: 1.1;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}
.btn:hover { background: var(--ink); color: var(--paper); transform: translateY(-1px); }
.btn-accent { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: var(--accent-2); border-color: var(--accent-2); color: var(--paper-raised); }
.btn-ghost { border-color: var(--rule-strong); color: var(--ink-2); }

/* Page-load reveal: a single orchestrated stagger, not scattered motion. */
@media (prefers-reduced-motion: no-preference) {
  .reveal > * { animation: ew-rise 520ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  .reveal > *:nth-child(2) { animation-delay: 60ms; }
  .reveal > *:nth-child(3) { animation-delay: 120ms; }
  .reveal > *:nth-child(4) { animation-delay: 180ms; }
  .reveal > *:nth-child(5) { animation-delay: 240ms; }
  .reveal > *:nth-child(n + 6) { animation-delay: 300ms; }
  @keyframes ew-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

/* Prose (Portable Text output). */
.prose { max-width: var(--measure); overflow-wrap: anywhere; }
.prose p, .prose ul, .prose ol { margin-bottom: var(--s-4); }
.prose h2, .prose h3 { margin-top: var(--s-6); }
.prose img { border-radius: var(--radius); }
.prose a { text-decoration-color: var(--rule-strong); }
.prose figure { margin: var(--s-5) 0; }
.prose figcaption { font-size: var(--fs-sm); color: var(--ink-3); }

/* ---------- map island (src/components/ProjectMap.tsx; global because React has no scoped <style>) ---------- */
.pm {
  position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 24rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--paper-2); overflow: hidden;
}
/* Two-class selector on purpose: maplibre's own CSS (`.maplibregl-map { position: relative }`) loads after this. */
.pm > .pm-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.pm-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: var(--s-2);
  align-items: center; justify-content: center; text-align: center; font-size: var(--fs-sm); padding: var(--s-4);
  /* A faint contour-line texture so the empty box still reads as "map". */
  background-image: repeating-radial-gradient(circle at 30% 40%, transparent 0 14px, color-mix(in srgb, var(--ink) 8%, transparent) 14px 15px);
  pointer-events: none;
}
.pm-fallback a { pointer-events: auto; }
.pm-ready .pm-fallback, .pm-flat .pm-fallback { display: none; }
.pm-note { position: absolute; left: var(--s-2); bottom: var(--s-2); background: color-mix(in srgb, var(--paper) 85%, transparent); padding: 0.15em 0.4em; border-radius: var(--radius); z-index: 1; }
.pm .maplibregl-ctrl-attrib { font-size: 0.65rem; }
.pm .maplibregl-popup-content { font-family: var(--font-body); font-size: var(--fs-sm); color: #1e331c; padding: 0.4rem 0.7rem; border-radius: var(--radius); }
@media (min-width: 48rem) { .pm { aspect-ratio: 16 / 10; } }

/* Countywide map. Height comes from the component so the page can size it; the rest mirrors .pm. */
.cm {
  position: relative; width: 100%; min-height: 20rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--paper-2); overflow: hidden;
}
.cm > .cm-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cm-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: var(--s-2);
  align-items: center; justify-content: center; text-align: center; font-size: var(--fs-sm); padding: var(--s-4);
  background-image: repeating-radial-gradient(circle at 30% 40%, transparent 0 14px, color-mix(in srgb, var(--ink) 8%, transparent) 14px 15px);
  pointer-events: none;
}
.cm-ready .cm-fallback, .cm-flat .cm-fallback { display: none; }
.cm-note { position: absolute; left: var(--s-2); bottom: var(--s-2); background: color-mix(in srgb, var(--paper) 85%, transparent); padding: 0.15em 0.4em; border-radius: var(--radius); z-index: 1; }
.cm .maplibregl-ctrl-attrib { font-size: 0.65rem; }
.cm .maplibregl-popup-content { font-family: var(--font-body); font-size: var(--fs-sm); color: #1e331c; padding: 0.4rem 0.7rem; border-radius: var(--radius); }
.cm .cm-stage { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.7rem; opacity: 0.7; }
