/* ============================================================
   Karst Firewall 5.0 — Public Portal
   "Institutional Karst" design system
   Display: Bricolage Grotesque · Body: Public Sans · Data: JetBrains Mono
   Carries the cockpit green→fire brand DNA into a bold civic site.
   ============================================================ */

:root {
  /* — Type — */
  --font-display: "Bricolage Grotesque", Georgia, serif;
  --font-sans: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  /* — Karst neutrals (warm limestone) — */
  --paper:      #FAF8F3;
  --paper-2:    #F2EEE5;
  --limestone:  #E6E0D3;
  --limestone-line: #DAD3C4;
  --ink:        #15211B;   /* near-black, pine-tinted */
  --ink-2:      #36433B;
  --ink-3:      #6B7468;
  --ink-4:      #9AA095;

  /* — Pine / forest (protect) — */
  --pine-900:   #0B1F16;
  --pine-800:   #0E2A1E;
  --pine-700:   #134A33;
  --pine-600:   #15803D;
  --pine-500:   #1D9E75;
  --pine-300:   #6FCF97;
  --pine-soft:  #E3EFE6;

  /* — Ember / fire (alert) — */
  --ember-700:  #9A3412;
  --ember-600:  #C2410C;
  --ember-500:  #EA580C;
  --fire-600:   #DC2626;
  --fire-700:   #991B1B;
  --ember-soft: #FBEADF;

  --gold-500:   #D9A441;

  /* — FWI scale — */
  --fwi-0: #E9E5DB;
  --fwi-1: #DCFCE7;
  --fwi-2: #A7E8B0;
  --fwi-3: #C7DE5B;
  --fwi-4: #F2C53D;
  --fwi-5: #EA8A1E;
  --fwi-6: #DC2626;
  --fwi-7: #7F1D1D;

  /* — Spacing — */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px;
  --s-6: 32px; --s-7: 48px; --s-8: 64px; --s-9: 96px; --s-10: 128px;

  --r-1: 4px; --r-2: 8px; --r-3: 14px; --r-4: 22px;
  --shadow-1: 0 1px 2px rgba(11,31,22,.06);
  --shadow-2: 0 6px 22px rgba(11,31,22,.09);
  --shadow-3: 0 20px 50px rgba(11,31,22,.16);

  --maxw: 1240px;
  --nav-h: 68px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-h) + 12px); }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
  font-size: 16px;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }

/* — Typographic primitives — */
.display {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -.02em;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; letter-spacing: -.02em; margin: 0; }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1, "zero" 1; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .18em;
  color: var(--ember-600);
  display: inline-flex; align-items: center; gap: 10px;
}
.eyebrow::before {
  content: ""; width: 22px; height: 1px; background: var(--ember-500); display: inline-block;
}
.eyebrow.pine { color: var(--pine-600); }
.eyebrow.pine::before { background: var(--pine-500); }
.eyebrow.muted { color: var(--ink-3); }
.eyebrow.muted::before { background: var(--ink-4); }

.lede { font-size: clamp(18px, 2vw, 22px); line-height: 1.5; color: var(--ink-2); }
.section-title { font-size: clamp(30px, 4.4vw, 56px); line-height: 1.06; }
.muted { color: var(--ink-3); }

/* — Layout — */
.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 28px; }
.section { padding: var(--s-9) 0; }
.section.tight { padding: var(--s-8) 0; }
.grid { display: grid; gap: var(--s-5); }
.center { text-align: center; }

/* topographic contour backdrop — tasteful, decorative only */
.topo-bg { position: relative; }
.topo-bg::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image:
    radial-gradient(120% 90% at 18% 0%, transparent 38%, rgba(21,128,61,.05) 39%, transparent 41%),
    radial-gradient(120% 90% at 18% 0%, transparent 50%, rgba(21,128,61,.05) 51%, transparent 53%),
    radial-gradient(120% 90% at 18% 0%, transparent 62%, rgba(21,128,61,.05) 63%, transparent 65%),
    radial-gradient(120% 90% at 18% 0%, transparent 74%, rgba(21,128,61,.05) 75%, transparent 77%);
}

/* ============================================================
   NAV
   ============================================================ */
.nav {
  position: sticky; top: 0; z-index: 100;
  height: var(--nav-h);
  background: rgba(250,248,243,.85);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--limestone-line);
}
.nav__inner {
  max-width: var(--maxw); margin: 0 auto; height: 100%;
  padding: 0 28px;
  display: flex; align-items: center; gap: var(--s-4);
}
.brand { display: flex; align-items: center; gap: 11px; flex: 0 0 auto; }
.brand__glyph {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, var(--pine-600) 0%, var(--pine-700) 45%, var(--ember-500) 100%);
  display: grid; place-items: center; color: #fff;
  font-family: var(--font-display); font-weight: 800; font-size: 17px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22), var(--shadow-1);
  position: relative; overflow: hidden;
}
.brand__glyph::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(60% 60% at 70% 80%, rgba(234,88,12,.55), transparent 70%);
}
.brand__name { font-family: var(--font-display); font-weight: 700; font-size: 16px; line-height: 1.05; letter-spacing: -.01em; }
.brand__name span { display: block; font-family: var(--font-mono); font-weight: 500; font-size: 10px; letter-spacing: .14em; color: var(--ink-3); text-transform: uppercase; }
.nav__links { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.nav__link {
  position: relative; padding: 8px 12px; border-radius: var(--r-1);
  font-size: 14.5px; font-weight: 500; color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.nav__link:hover { background: var(--paper-2); color: var(--ink); }
.nav__link.active { color: var(--pine-700); }
.nav__link.active::after {
  content: ""; position: absolute; left: 13px; right: 13px; bottom: 2px; height: 2px;
  background: var(--ember-500); border-radius: 2px;
}
.nav__has-menu { position: relative; }
.nav__menu {
  position: absolute; top: calc(100% + 8px); left: 0;
  min-width: 248px; background: var(--paper);
  border: 1px solid var(--limestone-line); border-radius: var(--r-3);
  box-shadow: var(--shadow-3); padding: 8px;
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: all .16s ease; z-index: 110;
}
.nav__has-menu:hover .nav__menu { opacity: 1; visibility: visible; transform: translateY(0); }
.nav__menu a { display: block; padding: 9px 12px; border-radius: var(--r-1); font-size: 14px; color: var(--ink-2); }
.nav__menu a:hover { background: var(--pine-soft); color: var(--pine-700); }
.nav__menu a small { display: block; font-size: 11.5px; color: var(--ink-4); font-weight: 400; }
.nav__cta { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.nav__burger { display: none; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 12px 20px; border-radius: 999px;
  font-family: var(--font-sans); font-size: 14.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; line-height: 1;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--ember-500); color: #fff; box-shadow: 0 6px 16px rgba(234,88,12,.28); }
.btn--primary:hover { background: var(--ember-600); }
.btn--pine { background: var(--pine-700); color: #fff; }
.btn--pine:hover { background: var(--pine-800); }
.btn--ghost { background: transparent; border-color: var(--limestone-line); color: var(--ink); }
.btn--ghost:hover { background: var(--paper-2); border-color: var(--ink-4); }
.btn--light { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); }
.btn--light:hover { background: rgba(255,255,255,.2); }
.btn--sm { padding: 8px 14px; font-size: 13px; }
.btn--block { width: 100%; justify-content: center; }
.btn .arrow { transition: transform .15s ease; }
.btn:hover .arrow { transform: translateX(3px); }

.link-arrow {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 600; font-size: 14.5px; color: var(--pine-700);
}
.link-arrow .arrow { transition: transform .15s ease; }
.link-arrow:hover .arrow { transform: translateX(4px); }
.link-arrow:hover { color: var(--ember-600); }

/* ============================================================
   CARDS / chips / pills
   ============================================================ */
.card {
  background: var(--paper); border: 1px solid var(--limestone-line);
  border-radius: var(--r-3); padding: var(--s-5);
}
.card--pad { padding: var(--s-6); }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px; border-radius: 999px;
  font-family: var(--font-mono); font-size: 11.5px; font-weight: 500;
  letter-spacing: .04em; text-transform: uppercase;
  background: var(--paper-2); color: var(--ink-2); border: 1px solid var(--limestone-line);
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip--live { background: var(--ember-soft); color: var(--ember-700); border-color: #F3D3BF; }
.chip--live .dot { background: var(--ember-500); animation: pulse 1.7s infinite; }
.chip--pine { background: var(--pine-soft); color: var(--pine-700); border-color: #C5DECB; }
.chip--locked { background: var(--paper-2); color: var(--ink-3); }
@keyframes pulse { 0%,100% { opacity: 1; box-shadow: 0 0 0 0 rgba(234,88,12,.5); } 50% { opacity: .55; box-shadow: 0 0 0 5px rgba(234,88,12,0); } }

.badge-data {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .03em;
  color: var(--ink-3); padding: 3px 9px; border-radius: 999px;
  border: 1px dashed var(--limestone-line); background: rgba(255,255,255,.5);
}

/* ============================================================
   FOOTER
   ============================================================ */
.footer { background: var(--pine-900); color: #C9D3CB; padding: var(--s-9) 0 var(--s-6); position: relative; overflow: hidden; }
.footer::before {
  content: ""; position: absolute; inset: 0; opacity: .5;
  background-image:
    radial-gradient(120% 80% at 90% 110%, transparent 40%, rgba(255,255,255,.03) 41%, transparent 43%),
    radial-gradient(120% 80% at 90% 110%, transparent 54%, rgba(255,255,255,.03) 55%, transparent 57%),
    radial-gradient(120% 80% at 90% 110%, transparent 68%, rgba(255,255,255,.03) 69%, transparent 71%);
}
.footer .wrap { position: relative; }
.footer__grid { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: var(--s-6); }
.footer h4 { color: #fff; font-size: 13px; font-family: var(--font-mono); font-weight: 500; text-transform: uppercase; letter-spacing: .14em; margin-bottom: 16px; }
.footer a { display: block; color: #A9B6AD; font-size: 14px; padding: 4px 0; }
.footer a:hover { color: #fff; }
.footer__brand .brand__name { color: #fff; }
.footer__brand .brand__name span { color: #7E8C81; }
.footer__bottom {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px;
  margin-top: var(--s-7); padding-top: var(--s-5); border-top: 1px solid rgba(255,255,255,.1);
  font-size: 12.5px; color: #7E8C81;
}
.eu-flag {
  width: 34px; height: 23px; border-radius: 3px; flex: 0 0 auto;
  background: #003399; position: relative;
}
.eu-flag::after { content: "★★★"; position: absolute; inset: 0; color: #FFCC00; font-size: 7px; letter-spacing: 1px; display:grid; place-items:center; line-height: 9px; }

/* ============================================================
   utilities
   ============================================================ */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--s-2); } .gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); } .gap-5 { gap: var(--s-5); }
.wrap-tight { max-width: 760px; }
.mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); }
.mt-5 { margin-top: var(--s-5); } .mt-6 { margin-top: var(--s-6); } .mt-7 { margin-top: var(--s-7); }
.hairline { height: 1px; background: var(--limestone-line); border: 0; }

/* image placeholder slot */
.imgslot {
  position: relative; background:
    repeating-linear-gradient(135deg, var(--paper-2) 0 11px, var(--limestone) 11px 22px);
  border: 1px solid var(--limestone-line); border-radius: var(--r-3);
  display: grid; place-items: center; overflow: hidden; color: var(--ink-3);
}
.imgslot::after {
  content: attr(data-label);
  font-family: var(--font-mono); font-size: 11.5px; letter-spacing: .04em;
  color: var(--ink-2); background: rgba(250,248,243,.9);
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--limestone-line);
  text-align: center; max-width: 80%;
}

/* map mock stage (shared) */
.map-mock {
  position: relative; overflow: hidden; border-radius: var(--r-3);
  background:
    radial-gradient(circle at 22% 30%, rgba(60,90,55,.45) 0, transparent 16%),
    radial-gradient(circle at 72% 22%, rgba(70,100,60,.35) 0, transparent 13%),
    radial-gradient(circle at 84% 74%, rgba(45,80,50,.4) 0, transparent 22%),
    radial-gradient(circle at 12% 80%, rgba(150,165,185,.4) 0, transparent 20%),
    linear-gradient(135deg, #B7CBA9 0%, #93AE89 35%, #C9BC9C 62%, #A6BBA6 100%);
}
.map-mock::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(0deg, rgba(0,0,0,.05) 0 1px, transparent 1px 46px),
    repeating-linear-gradient(90deg, rgba(0,0,0,.05) 0 1px, transparent 1px 46px);
}
.map-attr {
  position: absolute; right: 8px; bottom: 7px; font-size: 9.5px;
  font-family: var(--font-mono); color: rgba(20,40,25,.6);
  background: rgba(250,248,243,.7); padding: 2px 7px; border-radius: 4px;
}

/* ============================================================
   SUB-PAGE PRIMITIVES (shared across data views)
   ============================================================ */
.subhead { background: var(--paper); border-bottom: 1px solid var(--limestone-line); padding: var(--s-6) 0 var(--s-7); position: relative; overflow: hidden; }
.subhead.pine { background: var(--pine-900); color: #DCE5DD; }
.subhead.pine .crumb, .subhead.pine .crumb a { color: #8FA193; }
.subhead.pine h1 { color: #fff; }
.subhead.pine .subhead__lede { color: #A9B6AD; }
.crumb { font-family: var(--font-mono); font-size: 12px; letter-spacing: .04em; color: var(--ink-3); display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.crumb a:hover { color: var(--ember-600); }
.crumb .sep { color: var(--ink-4); }
.subhead h1 { font-size: clamp(30px, 4.6vw, 52px); line-height: 1.04; margin: 16px 0 0; max-width: 18ch; }
.subhead__lede { font-size: clamp(16px, 1.7vw, 19px); color: var(--ink-2); margin: 16px 0 0; max-width: 60ch; line-height: 1.5; }
.subhead__row { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; }

.data-note {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: #FFE9D6; border: 1px solid #F6C79B; border-left: 3px solid var(--ember-500);
  border-radius: var(--r-2);
  font-size: 13.5px; color: #8a4a17;
}
.data-note .ic { flex: 0 0 auto; color: var(--ember-600); }
.data-note b { color: var(--ember-600); }
.data-note a { color: var(--ember-600); }

.tabs { display: inline-flex; padding: 4px; background: var(--paper-2); border: 1px solid var(--limestone-line); border-radius: 999px; gap: 2px; }
.tabs button { border: 0; background: transparent; padding: 8px 18px; font-family: var(--font-sans); font-size: 14px; font-weight: 600; border-radius: 999px; color: var(--ink-2); cursor: pointer; }
.tabs button.active { background: var(--paper); color: var(--pine-700); box-shadow: var(--shadow-1); }

.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-4); }
.stat-card { background: var(--paper); border: 1px solid var(--limestone-line); border-radius: var(--r-3); padding: 18px 20px; }
.stat-card .l { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.stat-card .v { font-family: var(--font-display); font-size: 34px; font-weight: 700; line-height: 1; margin-top: 10px; }
.stat-card .s { font-size: 12.5px; color: var(--ink-3); margin-top: 8px; }
.stat-card .v small { font-size: 14px; color: var(--ink-3); font-weight: 500; }

/* FWI legend swatches */
.fwi-legend { display: flex; flex-direction: column; gap: 3px; }
.fwi-legend .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12.5px; }
.fwi-legend .sw { width: 26px; height: 14px; border-radius: 3px; flex: 0 0 auto; }
.fwi-legend .rng { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }

@media (max-width: 900px) { .stat-cards { grid-template-columns: 1fr 1fr; } }
/* Mobile nav: collapse the inline links into the burger toggle once the
   header gets cramped. (The design export mangled this media query — the
   burger/footer/section rules had leaked to the top level behind a stray
   brace, which left the burger visible on desktop. Restored here.) */
@media (max-width: 980px) {
  .nav__links { display: none; }
  .nav__burger { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--limestone-line); background: var(--paper); margin-left: auto; cursor: pointer; }
  .footer__grid { grid-template-columns: 1fr 1fr; }
  .section { padding: var(--s-8) 0; }
}
@media (max-width: 520px) { .stat-cards { grid-template-columns: 1fr; } }
@media (max-width: 560px) {
  .footer__grid { grid-template-columns: 1fr; }
  .nav__cta .btn--ghost { display: none; }
}

/* entrance */
@media (prefers-reduced-motion: no-preference) {
  .reveal { opacity: 0; transform: translateY(18px); animation: reveal .7s cubic-bezier(.2,.7,.2,1) forwards; }
  .reveal.d1 { animation-delay: .06s; } .reveal.d2 { animation-delay: .14s; }
  .reveal.d3 { animation-delay: .22s; } .reveal.d4 { animation-delay: .3s; } .reveal.d5 { animation-delay: .38s; }
  @keyframes reveal { to { opacity: 1; transform: none; } }
}

/* ============================ DARK THEME ============================ */
/* Token-level dark mode: redefine the warm-limestone neutrals; the pine/
   ember/FWI accents are kept. `html[data-theme="dark"]` wins over any
   `:root` redefinition regardless of stylesheet order. Toggled from the
   nav; persisted in localStorage; honours prefers-color-scheme on first
   visit (see layouts/portal.php no-FOUC script). */
html[data-theme="dark"] {
  --paper:          #141B18;
  --paper-2:        #1B2420;
  --limestone:      #222D27;
  --limestone-line: #2C382F;
  --ink:            #ECF1EE;
  --ink-2:          #C3CCC6;
  --ink-3:          #94A099;
  --ink-4:          #6F7C74;
  --pine-soft:      #14271C;
  --ember-soft:     #2A1A11;
  --pine-700:       #5BC495;   /* lifted so links/active read on dark */
  --shadow-1: 0 1px 2px rgba(0,0,0,.5);
  --shadow-2: 0 6px 22px rgba(0,0,0,.5);
  --shadow-3: 0 20px 50px rgba(0,0,0,.6);
  color-scheme: dark;
}
/* Hardcoded-colour fixes (the few rules not on tokens). */
html[data-theme="dark"] .nav { background: rgba(18,24,21,.85); }
html[data-theme="dark"] .data-note { background: #2a1a0e; border-color: #5a3a1c; border-left-color: var(--ember-500); color: #f0c79a; }
html[data-theme="dark"] .data-note b, html[data-theme="dark"] .data-note a { color: #f8b06a; }
html[data-theme="dark"] .btn--pine { background: var(--pine-600); }
html[data-theme="dark"] .btn--pine:hover { background: var(--pine-500); }
html[data-theme="dark"] img.footer__logo, html[data-theme="dark"] .brand__logo { /* keep brand chips legible */ }

/* Theme toggle button (nav). */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; flex: 0 0 auto;
  border: 1px solid var(--limestone-line); border-radius: 999px;
  background: transparent; color: var(--ink-2); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.theme-toggle:hover { background: var(--paper-2); color: var(--ink); border-color: var(--ink-4); }
