/* Rural Innovations — design tokens.
   Palette: Sky + Soil + Ochre. Type: Source Serif 4 (headings) + Inter (body). */

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,500;0,8..60,700;1,8..60,400;1,8..60,700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f7f5f0;            /* paper */
  --surface: #ffffff;
  --surface-alt: #ece8de;
  --ink: #1f2422;
  --ink-soft: #5a635f;
  --ink-faint: #8a8d87;
  --line: #dfdacf;
  --line-strong: #c9c2b1;
  --accent: #1f3554;        /* indigo */
  --accent-deep: #142339;
  --accent-soft: #e6ebf2;
  --highlight: #8a5d1f;          /* ochre — for em on cream and primary buttons */
  --highlight-on-dark: #d8a861;  /* lighter ochre — for em on dark indigo */
  --highlight-soft: #f3e7c6;     /* light ochre tint for backgrounds */
  --max-width: 76rem;
  --max-prose: 44rem;
  --radius: 12px;
  --radius-sm: 8px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: 'Source Serif 4', 'Source Serif Pro', Georgia, "Iowan Old Style", serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; transition: color 0.15s ease; }
a:hover { color: var(--highlight); }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ---------- Header ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 1rem 0;
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--accent);
}
.brand:hover { color: var(--accent); }
.brand img { width: 36px; height: 36px; display: block; }
.brand-name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.015em;
  color: var(--accent);
}
.site-nav { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: baseline; }
.site-nav a {
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: 0.005em;
  line-height: 1;
}
.site-nav a:hover { color: var(--accent); }
.site-nav a.nav-chat {
  color: var(--highlight);
  font-weight: 500;
}
.site-nav a.nav-chat:hover { color: var(--accent); }

/* ---------- Hero ---------- */
.hero {
  position: relative;
  margin: 0 0 4rem;
  background: var(--accent);
  color: #fff;
  overflow: hidden;
}
.hero-image {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(31,53,84,0.65) 0%, rgba(20,35,57,0.85) 100%),
    radial-gradient(ellipse at 70% 30%, #c66a3d22 0%, transparent 60%),
    linear-gradient(180deg, #2a4567 0%, #1f3554 50%, #142339 100%);
  background-size: cover;
  background-position: center;
}
.hero-image[data-image] {
  background:
    linear-gradient(180deg, rgba(20,35,57,0.25) 0%, rgba(20,35,57,0.7) 100%),
    var(--hero-bg);
  background-size: cover, cover;
  background-position: center, center;
}
.hero-inner {
  position: relative;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 6rem 1.5rem 7rem;
}
.hero h1 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(2.25rem, 5vw, 4rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
  max-width: 18ch;
  color: #fff;
}
.hero h1 em {
  font-style: italic;
  color: var(--highlight-on-dark);
  font-weight: 700;
}
.hero .lede {
  font-size: clamp(1.05rem, 1.5vw, 1.2rem);
  line-height: 1.55;
  color: rgba(255,255,255,0.9);
  margin: 0 0 2rem;
  max-width: 38rem;
}
.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.hero-credit {
  position: absolute;
  bottom: 1rem;
  right: 1.5rem;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.02em;
}
.hero-wave {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  width: 100%;
  height: 60px;
  display: block;
  fill: var(--bg);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 1.4rem;
  border-radius: var(--radius-sm);
  background: var(--highlight);
  color: #fff;
  font-weight: 500;
  font-size: 0.95rem;
  border: 1px solid var(--highlight);
  letter-spacing: 0.005em;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn:hover { background: #6e4818; color: #fff; }
.btn-ghost {
  background: transparent;
  color: #fff;
  border-color: rgba(255,255,255,0.4);
}
.btn-ghost:hover { background: rgba(255,255,255,0.1); color: #fff; }

main .btn-ghost {
  color: var(--accent);
  border-color: var(--accent);
}
main .btn-ghost:hover { background: var(--accent-soft); color: var(--accent); }

/* Buttons on dark backgrounds use the lighter ochre tint for contrast */
.hero .btn:not(.btn-ghost),
.home-subscribe .subscribe-button {
  background: var(--highlight-on-dark);
  color: var(--accent-deep);
  border-color: var(--highlight-on-dark);
}
.hero .btn:not(.btn-ghost):hover,
.home-subscribe .subscribe-button:hover {
  background: #c8943a;
  color: var(--accent-deep);
}

/* ---------- Stats strip ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0;
  margin: -2rem auto 4rem;
  max-width: var(--max-width);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  position: relative;
  z-index: 2;
}
.stat {
  padding: 1.5rem 1.75rem;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.stat:last-child { border-right: none; }
.stat .num {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.stat .label {
  margin-top: 0.4rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
  letter-spacing: 0.005em;
}

/* ---------- Section heading ---------- */
.section-heading {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(1.75rem, 2.5vw, 2.25rem);
  letter-spacing: -0.015em;
  color: var(--accent);
  margin: 0 0 1.5rem;
  line-height: 1.15;
}
.section-heading em {
  font-style: italic;
  color: var(--highlight);
  font-weight: 700;
}
.section-kicker {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  color: var(--highlight);
  font-weight: 500;
  margin: 0 0 0.5rem;
}

/* ---------- Recent / card grid ---------- */
.recent { margin: 4rem 0; }
.card-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: 1.25rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem 1.5rem 1.4rem;
  transition: border-color 0.15s ease;
}
.card:hover { border-color: var(--line-strong); }
.card .kicker {
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  color: var(--highlight);
  font-weight: 500;
  margin-bottom: 0.6rem;
}
.card h3 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.15rem;
  margin: 0 0 0.55rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.card h3 a { color: var(--ink); }
.card h3 a:hover { color: var(--accent); }
.card p { margin: 0; color: var(--ink-soft); font-size: 0.95rem; line-height: 1.55; }

/* ---------- Page header (interior pages) ---------- */
.page-header {
  padding: 4rem 0 2rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2rem;
}
.page-header h1 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(2rem, 3.5vw, 3rem);
  margin: 0 0 0.75rem;
  letter-spacing: -0.02em;
  color: var(--accent);
  line-height: 1.1;
}
.page-header h1 em {
  font-style: italic;
  color: var(--highlight);
  font-weight: 700;
}
.lede {
  font-size: 1.1rem;
  color: var(--ink-soft);
  margin: 0;
  max-width: 50rem;
}

/* ---------- Entry list ---------- */
.entry-list { list-style: none; padding: 0; margin: 0; }
.entry {
  padding: 1.75rem 0;
  border-bottom: 1px solid var(--line);
}
.entry:first-child { padding-top: 0.75rem; }
.entry h2, .entry h3 {
  font-family: var(--font-serif);
  font-weight: 700;
  margin: 0 0 0.4rem;
  font-size: 1.4rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.entry h2 a, .entry h3 a { color: var(--ink); }
.entry h2 a:hover, .entry h3 a:hover { color: var(--accent); }
.entry .meta {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin: 0 0 0.6rem;
  font-style: italic;
}
.entry p { margin: 0.4rem 0; }
.entry-past { opacity: 0.75; }
.entry-past .meta { font-size: 0.88rem; font-style: normal; }

.tags { margin: 0.85rem 0 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag {
  background: var(--surface-alt);
  color: var(--ink-soft);
  font-size: 0.78rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.tag-region { background: var(--accent-soft); color: var(--accent); }

/* ---------- Detail page ---------- */
.entry-detail {
  max-width: var(--max-prose);
  padding: 2.5rem 0 3rem;
}
.entry-detail .back {
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.entry-detail .back a { color: var(--ink-soft); }
.entry-detail .back a:hover { color: var(--accent); }
.entry-detail h1 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(1.85rem, 3vw, 2.5rem);
  margin: 0 0 0.75rem;
  letter-spacing: -0.015em;
  color: var(--accent);
  line-height: 1.15;
}
.entry-detail .meta {
  color: var(--ink-soft);
  margin: 0 0 1.75rem;
  font-style: italic;
}
.entry-detail .summary {
  background: var(--surface);
  border-left: 3px solid var(--highlight);
  padding: 1rem 1.4rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 1.75rem 0;
  font-size: 1.02rem;
}
.entry-detail h2 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.45rem;
  margin: 2.25rem 0 0.6rem;
  letter-spacing: -0.01em;
  color: var(--accent);
}

.detail-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1.5rem;
  margin: 0.5rem 0;
  font-size: 0.95rem;
}
.detail-list dt { color: var(--ink-soft); font-weight: 500; }
.detail-list dd { margin: 0; }

/* ---------- Prose pages ---------- */
.prose { max-width: var(--max-prose); padding: 3rem 0; }
.prose h1 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(2rem, 3.5vw, 2.75rem);
  margin: 0 0 0.75rem;
  letter-spacing: -0.02em;
  color: var(--accent);
  line-height: 1.1;
}
.prose h1 em { font-style: italic; color: var(--highlight); font-weight: 700; }
.prose h2 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.5rem;
  margin: 2.25rem 0 0.6rem;
  letter-spacing: -0.01em;
  color: var(--accent);
}
.prose .lede { margin-bottom: 1.5rem; }

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 0;
  padding: 3.5rem 0 2.5rem;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.92rem;
}
.footer-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2.5rem;
  margin: 0 0 2.5rem;
}
.footer-col h3 {
  font-family: var(--font-serif);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin: 0 0 1rem;
}
.footer-col ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.footer-col a {
  color: var(--ink);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.15s ease;
}
.footer-col a:hover { color: var(--highlight); }
.footer-col .social-links a {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.social-icon {
  width: 1.05em;
  height: 1.05em;
  flex: 0 0 auto;
  vertical-align: middle;
}
/* Inline social row used on About page */
.social-row {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
}
.social-row a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--ink);
  text-decoration: none;
}
.social-row a:hover { color: var(--highlight); }
.footer-bottom {
  border-top: 1px solid var(--line);
  padding-top: 1.75rem;
}
.footer-bottom p { margin: 0.3rem 0; }
.footer-bottom a { color: var(--ink-soft); text-decoration: underline; text-underline-offset: 2px; }
.footer-bottom a:hover { color: var(--accent); }
.muted { color: var(--ink-faint); font-size: 0.85rem; }
@media (max-width: 720px) {
  .footer-nav { grid-template-columns: 1fr 1fr; gap: 2rem; }
}
@media (max-width: 480px) {
  .footer-nav { grid-template-columns: 1fr; gap: 1.75rem; }
}

/* ---------- Polish layer: fade-in, hover lift, focus ---------- */

/* Scroll-triggered fade-in. Class added by interactions.js. */
.fade-in {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.55s ease, transform 0.55s ease;
  will-change: opacity, transform;
}
.fade-in.is-visible {
  opacity: 1;
  transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
  .fade-in { opacity: 1 !important; transform: none !important; transition: none !important; }
}

/* ========== Mobile fixes (≤640px) ==========
   Comprehensive responsive layer for phone-width viewports. Existing
   breakpoints at 880px (library-layout), 760px (home-feature),
   720px (footer/page-header-photo) already handle tablet sizes; this
   block targets phone-specific issues. */
@media (max-width: 640px) {
  /* --- Site header: separate brand and nav with a divider --- */
  .site-header { padding: 0.85rem 0; }
  .site-header .container {
    gap: 0.6rem;
  }
  .brand img { width: 30px; height: 30px; }
  .brand-name { font-size: 1.05rem; }
  .site-nav {
    width: 100%;
    gap: 0.85rem 1.1rem;
    padding-top: 0.55rem;
    border-top: 1px solid var(--line);
    align-items: center;
  }
  .site-nav a { font-size: 0.9rem; }

  /* --- Container padding: tighter --- */
  main .container,
  .footer-subscribe .container,
  .site-footer .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* --- Hero: smaller heading and lede --- */
  .hero { margin-bottom: 2.5rem; }
  .hero-inner { padding: 3.25rem 1rem 4.5rem; }
  .hero h1 {
    font-size: clamp(1.85rem, 7vw, 2.5rem);
    line-height: 1.1;
  }
  .hero .lede {
    font-size: 1rem;
  }

  /* --- Page header photos (article/list page banners) --- */
  .page-header-photo { min-height: 320px; }
  .page-header-photo-inner {
    padding: 1.5rem 1rem 2rem;
  }
  .page-header-photo h1 {
    font-size: clamp(1.7rem, 6vw, 2.2rem);
  }
  .page-header-photo .lede {
    font-size: 1rem;
  }
  .page-header-photo.page-header-photo-detail { min-height: 180px; }

  /* --- Form inputs: 16px prevents iOS zooming on focus --- */
  .search-input,
  .subscribe-email,
  .chat-input,
  .home-chat-input,
  input[type="text"],
  input[type="email"],
  input[type="search"],
  textarea {
    font-size: 16px;
  }

  /* --- Stats strip: tighter on phones --- */
  .stats { gap: 0.75rem; }
  .stat .num { font-size: 2rem; }
  .stat .label { font-size: 0.78rem; }

  /* --- Tags: tighter spacing and smaller text --- */
  .tags { gap: 0.3rem; }
  .tag {
    font-size: 0.78rem;
    padding: 0.2rem 0.6rem;
  }

  /* --- Citation block: handle long DOI URLs and BibTeX/RIS lines --- */
  .citation-body,
  .citation-mono {
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .citation-mono {
    font-size: 0.78rem;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .citation-tab {
    font-size: 0.85rem;
    padding: 0.35rem 0.7rem;
  }

  /* --- Detail pages: tighter top/bottom padding --- */
  .entry-detail {
    padding: 1.5rem 0 2.5rem;
  }
  .entry-detail h1 {
    font-size: clamp(1.55rem, 5.5vw, 1.95rem);
  }
  .entry-detail h2 {
    font-size: 1.2rem;
  }

  /* --- Detail metadata list: stack dt and dd --- */
  .detail-list dt,
  .detail-list dd {
    display: block;
  }
  .detail-list dt {
    margin-top: 0.6rem;
    margin-bottom: 0.15rem;
  }
  .detail-list dd {
    margin-left: 0;
  }

  /* --- Subscribe form (default + footer variant): stack input above button.
     `flex: 0 0 auto` is critical: without it, the desktop rule
     `.subscribe-email { flex: 1 1 16rem; }` would treat 16rem as a *height*
     once the form flips to flex-direction column, ballooning the input to
     ~256px tall on phones. --- */
  .subscribe-form {
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
  }
  .subscribe-form .subscribe-email,
  .subscribe-form .subscribe-button {
    width: 100%;
    flex: 0 0 auto;
  }

  /* --- Sidebar filter labels: break long slug tokens like
     `regional-innovation-systems` so they don't push the sidebar wider than
     the viewport on the articles page. --- */
  .library-sidebar .sb-link > span:first-child {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  /* --- Map page: shorter on phones --- */
  .map-canvas {
    height: 360px;
  }
  .map-canvas-home {
    height: 320px;
  }

  /* --- Section headings: smaller on phones --- */
  .section-heading {
    font-size: 1.55rem;
  }

  /* --- Card grid: tighter --- */
  .card-grid {
    gap: 1rem;
  }
  .card {
    padding: 1rem 1.1rem;
  }
}

/* ---- Cookie consent banner ----
   Fixed at the bottom of the viewport. Only appears on tracked pages
   (main pages and tag/region aggregations) until the visitor accepts
   or declines, after which the choice is remembered in localStorage. */
.consent-banner {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: 640px;
  width: calc(100% - 2rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(20, 35, 57, 0.18);
  padding: 1.1rem 1.25rem;
  z-index: 1000;
  font-size: 0.92rem;
  line-height: 1.5;
}
.consent-banner-msg {
  margin: 0 0 0.85rem;
  color: var(--ink);
}
.consent-banner-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}
.consent-btn {
  font-family: var(--font-sans);
  font-size: 0.92rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.consent-btn-secondary {
  background: transparent;
  color: var(--ink-soft);
}
.consent-btn-secondary:hover {
  background: var(--surface-alt);
  color: var(--ink);
}
.consent-btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.consent-btn-primary:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}
@media (max-width: 480px) {
  .consent-banner {
    bottom: 0.5rem;
    width: calc(100% - 1rem);
    padding: 0.95rem 1rem;
  }
  .consent-banner-actions { flex-direction: column-reverse; }
  .consent-btn { width: 100%; }
}

/* Card hover lift — a quiet 2px raise with a soft shadow */
.card {
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px -10px rgba(20, 35, 57, 0.18);
}

/* Tag pills — subtle hover for clickable tags (which are anchor tags) */
a.tag {
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
a.tag:hover {
  background: var(--accent-soft);
  color: var(--accent);
  transform: translateY(-1px);
  text-decoration: none;
}
a.tag.tag-region:hover {
  background: var(--highlight-soft);
  color: var(--highlight);
}

/* Entry list rows — gentle hover to suggest interactivity */
.entry h2 a, .entry h3 a {
  transition: color 0.18s ease;
}

/* Polished keyboard focus rings — only for keyboard users via :focus-visible */
*:focus { outline: none; }
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.btn:focus-visible,
.subscribe-button:focus-visible,
.chat-send:focus-visible {
  outline-color: var(--highlight-on-dark);
  outline-offset: 3px;
}
.search-input:focus-visible,
.subscribe-email:focus-visible,
.chat-input:focus-visible {
  outline: none; /* these have their own focus styling via box-shadow */
}
.sb-link:focus-visible,
.sb-toggle:focus-visible {
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}
a:focus-visible {
  outline-offset: 3px;
}

/* ---------- Library layout (sidebar + main) ---------- */
.library-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 2.5rem;
  margin: 0 0 3rem;
}
@media (max-width: 880px) {
  .library-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
  }
}

.library-sidebar {
  position: sticky;
  top: 1rem;
  align-self: start;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding-right: 0.5rem;
  font-size: 0.92rem;
}
@media (max-width: 880px) {
  .library-sidebar {
    position: static;
    max-height: none;
    padding-right: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    background: var(--surface);
  }
}

.library-sidebar .sb-section {
  margin-top: 0.85rem;
  border-top: 1px solid var(--line);
  padding-top: 0.6rem;
}
.library-sidebar .sb-section:first-of-type {
  border-top: 0;
  padding-top: 0.5rem;
  margin-top: 0.5rem;
}
.library-sidebar h3 {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  font-weight: 500;
  margin: 0 0 0.5rem;
}

/* Sidebar accordion toggle */
.sb-toggle {
  display: flex !important;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  background: transparent;
  border: 0;
  padding: 0.45rem 0.4rem 0.45rem 0.7rem;
  margin: 0 0 0.35rem;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  font-weight: 500;
  text-align: left;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
}
.sb-toggle:hover { color: var(--accent); background: var(--accent-soft); }
.sb-toggle::after {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.sb-toggle[aria-expanded="false"]::after {
  transform: rotate(-45deg) translate(0, -1px);
}
.sb-toggle[aria-expanded="false"] + ul {
  display: none !important;
}
.library-sidebar ul {
  list-style: none !important;
  padding: 0 !important;
  margin: 0 !important;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.library-sidebar li { list-style: none !important; }
.library-sidebar ul.sb-compact {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(5rem, 1fr));
  gap: 0.25rem;
}

.sb-link {
  display: flex !important;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: transparent;
  border: 0;
  border-left: 2px solid transparent;
  text-align: left;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  padding: 0.4rem 0.7rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  cursor: pointer;
  gap: 0.6rem;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.sb-link:hover { background: var(--accent-soft); color: var(--accent); }
.sb-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--highlight);
  font-weight: 500;
}
.sb-link .sb-count {
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  margin-left: 0.5rem;
}
.sb-link.active .sb-count { color: var(--accent); }
.sb-all {
  font-weight: 500;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 0.25rem;
}
.sb-all.active { border-color: var(--accent); }

.sb-result-count {
  margin: 0 0 1rem;
  color: var(--ink-soft);
  font-size: 0.88rem;
  font-style: italic;
}

.sb-empty {
  padding: 2rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
  color: var(--ink-soft);
}
.sb-clear-link {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}
.sb-clear-link:hover { color: var(--highlight); }

/* ---------- Citation block (article detail) ---------- */
.citation {
  margin: 1.75rem 0 0;
  padding: 1.1rem 1.3rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 100%;
}
.citation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.7rem;
}
.citation-head h3 {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0;
  letter-spacing: -0.005em;
}
.citation-copy {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.85rem;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.citation-copy:hover { border-color: var(--highlight); color: var(--highlight); }
.citation-copy.copied { color: var(--accent); border-color: var(--accent); }
.citation-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.7rem;
  margin-bottom: 0.85rem;
}
.citation-tab {
  background: transparent;
  border: 0;
  padding: 0.2rem 0.6rem;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  border-radius: 999px;
  transition: all 0.12s ease;
}
.citation-tab:hover { color: var(--accent); }
.citation-tab.active {
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}
.citation-bodies {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--ink);
}
.citation-body {
  margin: 0;
}
.citation-body em {
  font-style: italic;
}
.citation-body[hidden] { display: none; }
.citation-mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--ink-soft);
  background: var(--bg);
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-x: auto;
}

/* ---------- Map page ---------- */
.map-controls { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1rem; }
.map-layer-btn { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.9rem; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; color: var(--ink); font-family: inherit; font-size: 0.88rem; cursor: pointer; transition: all 0.15s ease; }
.map-layer-btn:hover { border-color: var(--accent); }
.map-layer-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.map-layer-btn:not(.active) { opacity: 0.55; }
.map-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.2); display: inline-block; }
.map-dot-org { background: var(--accent); }
.map-dot-event { background: var(--highlight); }
.map-count { font-size: 0.78rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; margin-left: 0.15rem; }
.map-canvas { height: 70vh; min-height: 480px; width: 100%; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #e8ecef; margin-bottom: 1rem; }
.map-empty-note { margin-top: 0.85rem; }
.map-canvas-home { height: 460px; min-height: 0; }
.home-map-section { margin: 4rem 0; }
.home-map-lede { color: var(--ink-soft); margin: 0 0 1.25rem; max-width: 50rem; }
.home-map-cta { margin: 1rem 0 0; font-size: 0.95rem; }
.home-map-cta a { font-weight: 500; }
.leaflet-popup-content-wrapper { border-radius: var(--radius-sm); }
.leaflet-popup-content { font-family: var(--font-sans); margin: 0.7rem 0.85rem !important; line-height: 1.5; min-width: 200px; }
.popup-kind { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); font-weight: 500; margin-bottom: 0.25rem; }
.popup-kind-event { color: var(--highlight); }
.popup-title { font-family: var(--font-serif); font-weight: 700; font-size: 1rem; color: var(--ink); display: block; margin-bottom: 0.35rem; line-height: 1.25; }
.popup-title:hover { color: var(--accent); }
.popup-body { margin: 0 0 0.35rem; font-size: 0.85rem; color: var(--ink-soft); line-height: 1.5; }
.popup-meta { margin: 0; font-size: 0.78rem; color: var(--ink-faint); font-style: italic; }

/* ---------- Search page ---------- */
.search-wrap { margin: 0 0 1rem; }
.search-input {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 1.1rem;
  padding: 0.95rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-input::placeholder { color: var(--ink-faint); }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-status { margin: 0.75rem 0 0; color: var(--ink-soft); font-size: 0.9rem; font-style: italic; }
.search-filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1.25rem 0 1.5rem; }
.search-kind {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.search-kind:hover { border-color: var(--accent); color: var(--accent); }
.search-kind.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.search-results { list-style: none; padding: 0; margin: 0; }
.search-result { padding: 1.25rem 0; border-bottom: 1px solid var(--line); }
.search-result h3 { font-family: var(--font-serif); font-weight: 700; font-size: 1.2rem; line-height: 1.3; margin: 0.4rem 0 0.3rem; letter-spacing: -0.01em; }
.search-result h3 a { color: var(--ink); }
.search-result h3 a:hover { color: var(--accent); }
.search-meta { margin: 0 0 0.4rem; color: var(--ink-soft); font-size: 0.92rem; font-style: italic; }
.search-snippet { margin: 0.3rem 0 0; color: var(--ink); font-size: 0.95rem; line-height: 1.55; }
.search-result mark { background: var(--highlight-soft); color: inherit; padding: 0.05em 0.15em; border-radius: 3px; }
.search-kind-badge {
  display: inline-block;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--ink-soft);
}
.search-kind-article { background: var(--accent-soft); color: var(--accent); }
.search-kind-media { background: var(--highlight-soft); color: var(--highlight); }
.search-kind-organization { background: #e6f0e6; color: #2f6b4f; }
.search-kind-event { background: #fef3e2; color: #b25c33; }
.search-empty { text-align: center; padding: 3rem 1rem; color: var(--ink-soft); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 1rem; }

/* ---------- Photographic page header ---------- */
.page-header-photo {
  position: relative;
  margin: 0 0 4rem;
  background: var(--accent-deep);
  color: #fff;
  overflow: hidden;
  min-height: 480px;
  display: flex;
  align-items: flex-end;
}
.page-header-photo-image {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
}
.page-header-photo-inner {
  position: relative;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 6rem 1.5rem 7rem;
}
.page-header-photo-inner h1 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(2.25rem, 5vw, 4rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: #fff;
  margin: 0 0 1rem;
  max-width: 22ch;
}
.page-header-photo-inner h1 em {
  font-style: italic;
  color: var(--highlight-on-dark);
  font-weight: 700;
}
.page-header-photo-inner .lede {
  color: rgba(255,255,255,0.92);
  font-size: clamp(1.05rem, 1.5vw, 1.2rem);
  line-height: 1.55;
  margin: 0;
  max-width: 38rem;
}
.page-header-photo-credit {
  position: absolute;
  bottom: 1rem;
  right: 1.5rem;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.02em;
  z-index: 2;
}
.page-header-photo-wave {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  width: 100%;
  height: 60px;
  display: block;
  fill: var(--bg);
  z-index: 1;
}
@media (max-width: 720px) {
  .page-header-photo { min-height: 360px; }
  .page-header-photo-inner { padding: 4rem 1.25rem 5rem; }
}

/* Smaller variant for article and organization detail pages */
.page-header-photo.page-header-photo-detail {
  min-height: 240px;
  margin-bottom: 0;
}
.page-header-photo-detail .page-header-photo-inner {
  padding: 3rem 1.5rem 3.5rem;
}
.page-header-photo-detail .page-header-photo-kicker {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--highlight-on-dark);
  font-weight: 500;
  margin: 0 0 0.4rem;
}
.page-header-photo-detail .page-header-photo-kicker a {
  color: rgba(255,255,255,0.78);
  text-decoration: none;
}
.page-header-photo-detail .page-header-photo-kicker a:hover { color: var(--highlight); }
@media (max-width: 720px) {
  .page-header-photo.page-header-photo-detail { min-height: 200px; }
}

/* ---------- Homepage side-feature block ---------- */
.home-feature {
  margin: 4rem 0;
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 3rem;
  align-items: center;
}
@media (max-width: 760px) {
  .home-feature { grid-template-columns: 1fr; gap: 1.75rem; }
}
.home-feature-image {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 5;
  background: var(--accent-deep);
}
.home-feature-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.6s ease;
}
.home-feature-image:hover img { transform: scale(1.03); }
.home-feature-credit {
  position: absolute;
  bottom: 0.7rem;
  right: 0.85rem;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.02em;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.home-feature-text .section-heading { margin-bottom: 1rem; }
.home-feature-text p { font-size: 1.02rem; line-height: 1.7; color: var(--ink); margin: 0 0 1rem; }
.home-feature-meta { display: flex; flex-wrap: wrap; gap: 1.5rem; margin-top: 1.25rem !important; font-weight: 500; }
.home-feature-meta a { font-size: 0.95rem; }

/* ---------- Prose lift (about, glossary, funding intros) ---------- */
.prose-lede {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(1.15rem, 1.75vw, 1.4rem);
  line-height: 1.45;
  color: var(--accent);
  margin: 1.5rem 0 2rem;
  max-width: 38rem;
}
.prose-note {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font-size: 0.95rem;
  color: var(--ink-soft);
}

/* ---------- Subscribe form (Mailchimp) ---------- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.subscribe-form {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  flex-wrap: wrap;
}
.subscribe-email {
  flex: 1 1 16rem;
  min-width: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.subscribe-email:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.subscribe-email::placeholder { color: var(--ink-faint); }
.subscribe-button {
  flex-shrink: 0;
  background: var(--highlight);
  color: #fff;
  border: 1px solid var(--highlight);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.4rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}
.subscribe-button:hover { background: #6e4818; }

.subscribe-form-hero { max-width: 32rem; }
.subscribe-form-hero .subscribe-email { font-size: 1.05rem; padding: 0.85rem 1.05rem; }
.subscribe-form-hero .subscribe-button { padding: 0.85rem 1.6rem; font-size: 1.05rem; }

.subscribe-fineprint, .home-subscribe-fineprint {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-style: italic;
}
.subscribe-page .subscribe-hero { margin: 1.5rem 0 2.5rem; }
.subscribe-page h2 { margin-top: 2rem; }

/* Homepage subscribe block */
.home-subscribe {
  margin: 4rem 0;
  padding: 2.25rem 2rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}
.home-subscribe::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 80% 20%, rgba(216,168,97,0.18) 0%, transparent 60%);
  pointer-events: none;
}
.home-subscribe-inner { position: relative; max-width: 38rem; }
.home-subscribe .section-kicker { color: var(--highlight-on-dark); }
.home-subscribe .section-heading { color: #fff; margin-bottom: 0.75rem; }
.home-subscribe .section-heading em { color: var(--highlight-on-dark); }
.home-subscribe-lede {
  color: rgba(255,255,255,0.92);
  margin: 0 0 1.25rem;
  line-height: 1.55;
}
.home-subscribe .subscribe-email {
  border-color: rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.home-subscribe .subscribe-email::placeholder { color: rgba(255,255,255,0.6); }
.home-subscribe .subscribe-email:focus {
  background: rgba(255,255,255,0.12);
  border-color: var(--highlight-on-dark);
  box-shadow: 0 0 0 3px rgba(216,168,97,0.25);
}
.home-subscribe-fineprint { color: rgba(255,255,255,0.65); }

/* ---- Homepage chat CTA ----
   Sits above the map. Cream/ochre treatment to read as "interactive
   library tool" rather than a marketing banner. Submitting the form
   GETs /chat/index.html?q=... — chat.js reads the query and auto-sends. */
.home-chat-cta {
  margin: 4rem 0 2.5rem;
  padding: 1.75rem 2rem 1.5rem;
  background: var(--highlight-soft);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}
.home-chat-cta::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
  background: var(--highlight);
  opacity: 0.5;
}
.home-chat-inner {
  position: relative;
  max-width: 42rem;
}
.home-chat-cta .section-kicker { color: var(--highlight); margin-bottom: 0.35rem; }
/* Override the section-heading size for this CTA — it's not a top-level
   section, just a prominent input box, so the standard heading scale
   makes it dominate the page. */
.home-chat-cta .section-heading {
  font-size: 1.7rem;
  line-height: 1.15;
  margin: 0 0 0.6rem;
}
.home-chat-lede {
  margin: 0 0 1.1rem;
  line-height: 1.5;
  color: var(--ink-soft);
  font-size: 1rem;
}
.home-chat-form {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
  margin-bottom: 1rem;
}
.home-chat-input {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 1.05rem;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1.05rem;
  min-width: 0;  /* allow input to shrink inside flex on narrow viewports */
}
.home-chat-input::placeholder { color: var(--ink-faint); }
.home-chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.home-chat-submit {
  flex-shrink: 0;
  width: 52px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 1.4rem;
  transition: background 0.15s ease;
}
.home-chat-submit:hover { background: var(--accent-deep); }
.home-chat-submit:focus-visible {
  outline: 2px solid var(--highlight);
  outline-offset: 3px;
}
.home-chat-examples {
  margin: 0;
  font-size: 0.92rem;
  color: var(--ink-soft);
  line-height: 1.5;
}
.home-chat-examples em { color: var(--ink); font-style: italic; }

/* Stack the form vertically on narrow screens — submit becomes full-width */
@media (max-width: 540px) {
  .home-chat-form { flex-direction: column; gap: 0.55rem; }
  .home-chat-submit { width: 100%; height: 48px; font-size: 1.2rem; }
}

/* Footer subscribe block */
.footer-subscribe {
  background: var(--surface-alt);
  border-top: 1px solid var(--line);
  padding: 2.25rem 0;
}
.footer-subscribe-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem 2rem;
  align-items: center;
  justify-content: space-between;
}
.footer-subscribe-pitch { flex: 1 1 18rem; min-width: 0; }
.footer-subscribe-kicker {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--accent);
  margin: 0 0 0.2rem;
  letter-spacing: -0.01em;
}
.footer-subscribe-lede { margin: 0; color: var(--ink-soft); font-size: 0.95rem; }
.footer-subscribe .subscribe-form { flex: 1 1 22rem; max-width: 28rem; }

/* ---------- Chat page ---------- */
.chat-page {
  max-width: 48rem;
  margin: 0 auto;
  padding: 2rem 0 4rem;
  display: flex;
  flex-direction: column;
}
.chat-header { margin-bottom: 1.5rem; }
.chat-header h1 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(1.85rem, 3vw, 2.5rem);
  color: var(--accent);
  margin: 0 0 0.5rem;
  letter-spacing: -0.015em;
}
.chat-subtitle {
  color: var(--ink-soft);
  font-size: 1.05rem;
  margin: 0;
}

.chat-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  margin-bottom: 1.25rem;
}

.chat-message { display: flex; }
.chat-message-user { justify-content: flex-end; }
.chat-message-assistant { justify-content: flex-start; }

.chat-bubble {
  max-width: 92%;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: 0.97rem;
}
.chat-message-user .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
}
.chat-message-user .chat-bubble p { margin: 0; }
.chat-message-user .chat-bubble a { color: #fff; text-decoration: underline; }

.chat-message-assistant .chat-bubble {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) var(--radius) 4px;
}
.chat-message-assistant .chat-bubble p { margin: 0 0 0.6rem; }
.chat-message-assistant .chat-bubble p:last-child { margin-bottom: 0; }
.chat-message-assistant .chat-bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.chat-message-assistant .chat-bubble a:hover { color: var(--highlight); }
.chat-message-assistant .chat-bubble ul,
.chat-message-assistant .chat-bubble ol { margin: 0.4rem 0 0.6rem; padding-left: 1.4rem; }
.chat-message-assistant .chat-bubble li { margin-bottom: 0.25rem; }
.chat-message-assistant .chat-bubble code {
  background: var(--surface-alt);
  padding: 0.05em 0.35em;
  border-radius: 3px;
  font-size: 0.92em;
}
.chat-message-assistant .chat-bubble em { font-style: italic; color: var(--ink-soft); }
.chat-meta-hint { font-size: 0.85rem; color: var(--ink-soft); font-style: italic; margin-top: 0.5rem; }

/* Typing indicator */
.chat-typing .chat-bubble {
  display: inline-flex;
  gap: 0.3rem;
  padding: 1rem 1.1rem;
  align-items: center;
}
.chat-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-soft);
  display: inline-block;
  animation: chat-pulse 1.2s infinite ease-in-out;
}
.chat-dot:nth-child(2) { animation-delay: 0.18s; }
.chat-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes chat-pulse {
  0%, 70%, 100% { opacity: 0.25; transform: scale(0.85); }
  35% { opacity: 1; transform: scale(1); }
}

/* Input */
.chat-input-bar {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.chat-input {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  resize: none;
  min-height: 44px;
  max-height: 220px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.chat-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-input:disabled { opacity: 0.6; }
.chat-send {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 1.3rem;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.chat-send:hover:not(:disabled) { background: var(--accent-deep); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.chat-reset {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chat-reset:hover { border-color: var(--accent); color: var(--accent); }
.chat-status { font-style: italic; }

@media (max-width: 640px) {
  .chat-page { padding: 1.25rem 0 3rem; }
  .chat-bubble { max-width: 95%; }
}

/* ---------- Resources dropdown in nav ---------- */
.nav-resources {
  position: relative;
}
.nav-resources > summary {
  display: inline-flex;
  align-items: baseline;
  list-style: none;
  cursor: pointer;
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0;
  line-height: 1;
}
.nav-resources > summary::-webkit-details-marker { display: none; }
.nav-resources > summary::after {
  content: "▾";
  font-size: 0.7rem;
  margin-left: 0.35rem;
  display: inline-block;
  transition: transform 0.2s ease;
  transform-origin: center;
}
.nav-resources[open] > summary::after {
  transform: rotate(180deg);
}
.nav-resources > summary:hover { color: var(--accent); }
.nav-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0;
  min-width: 11rem;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(20, 35, 57, 0.06);
}
.nav-dropdown a {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 400;
}
.nav-dropdown a:hover { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 720px) {
  .nav-dropdown { position: static; border: 0; box-shadow: none; padding: 0.25rem 0 0 1rem; min-width: 0; }
}

/* ---------- Glossary ---------- */
.glossary { margin: 1rem 0 3rem; max-width: var(--max-prose); }
.glossary-entry { padding: 1.25rem 0; border-bottom: 1px solid var(--line); }
.glossary-entry dt {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
  letter-spacing: -0.005em;
}
.glossary-entry dd { margin: 0; }
.glossary-entry dd p { margin: 0 0 0.5rem; line-height: 1.65; }
.glossary-see-also {
  font-size: 0.88rem;
  color: var(--ink-soft);
  font-style: italic;
}

/* ---------- Funding ---------- */
.funding-disclaimer {
  background: var(--surface);
  border-left: 3px solid var(--highlight);
  padding: 0.85rem 1.2rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
  margin: 0 0 2rem;
}
.funding-detail {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1.25rem;
  margin: 0.75rem 0 0;
  font-size: 0.92rem;
}
.funding-detail dt { color: var(--ink-soft); font-weight: 500; }
.funding-detail dd { margin: 0; }

/* ---------- Image credits ---------- */
.credits-list { margin: 1.5rem 0; }
.credits-entry { padding: 1rem 0; border-bottom: 1px solid var(--line); }
.credits-entry dt {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.4rem;
}
.credits-entry dt a { color: var(--accent); }
.credits-kind {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--highlight);
  font-weight: 500;
  margin-right: 0.5rem;
  vertical-align: 0.1em;
}
.credits-entry dd { margin: 0; }
.credits-entry dd p { margin: 0 0 0.3rem; font-size: 0.95rem; line-height: 1.55; }

/* ---------- Tag/region index pages ---------- */
.taxonomy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.75rem;
  margin: 1.5rem 0;
}
.taxonomy-grid a {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.taxonomy-grid a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.taxonomy-grid .tax-count {
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
