@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Fraunces:opsz,wght@9..144,300;9..144,450;9..144,600;9..144,700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Theme tokens ────────────────────────────────── */
/* Dark — the editorial identity in a dark mood: warm cream ink and rust
   accent (carried from [data-theme="light"]), but grounded on dreamcatcher's
   neutral "ink" background instead of a warm brown, which read muddy. Warm
   content on a near-neutral dark. This :root is also the data-theme="dark"
   fallback. */
:root {
  --bg:        oklch(0.18 0.012 270);
  --surface:   oklch(0.22 0.015 270);
  --border:    rgba(237, 228, 214, 0.12);
  --blue:      oklch(68% 0.14 48);
  --blue-dim:  oklch(68% 0.14 48 / 0.14);
  --blue-glow: oklch(68% 0.14 48 / 0.30);
  --sun:       var(--blue);   /* accent-touch colour (labels, stat numbers, bullet markers); defaults to the theme accent, overridden only by Ocean */
  --text:      #ece3d5;
  --muted:     #a2968a;
  --faint:     oklch(0.24 0.016 270);
  --mono:      'JetBrains Mono', monospace;
  --sans:      'Space Grotesk', sans-serif;
  --serif:     'Fraunces', 'Space Grotesk', serif;
  --display:   var(--serif);
  --dot-color: rgba(230,220,205,0.045);
}

/* Editorial — the site's primary identity: warm paper, ink type, a
   single rust accent, restraint over glow. Matches the language already
   shared by the grant-tracker demo and the portfolio-hub front door. */
[data-theme="light"] {
  --bg:        #faf7f2;
  --surface:   #ffffff;
  --border:    rgba(26, 20, 16, 0.11);
  --blue:      oklch(52% 0.15 45);
  --blue-dim:  oklch(52% 0.15 45 / 0.09);
  --blue-glow: oklch(52% 0.15 45 / 0.16);
  --text:      #1a1410;
  --muted:     #7a6f63;
  --faint:     #f1ece3;
  --display:   var(--serif);
  --dot-color: transparent;
}

/* Ocean — the dreamcatcher demo's ocean/sun combination: deep ocean-navy
   ground, pale-blue ink. The ocean sky-blue is the primary accent so the
   theme reads calm and cohesive; the warm gold "sun" is dialled back to
   glow/highlight duty (--blue-glow) so it enhances rather than takes over. */
[data-theme="ocean"] {
  --bg:        #050d1c;
  --surface:   #091628;
  --border:    rgba(74, 174, 232, 0.14);
  --blue:      #4aaee8;
  --blue-dim:  rgba(74, 174, 232, 0.15);
  --blue-glow: oklch(0.86 0.16 90 / 0.42);
  --sun:       #ffd24d;   /* the dreamcatcher/Walmart "sun" — gold accent used judiciously on touches */
  --text:      #deeaf8;
  --muted:     #7a9ab8;
  --faint:     #0c1e34;
  --dot-color: rgba(74,174,232,0.06);
  --display:   var(--sans);   /* Ocean keeps the original technical (Space Grotesk) headline, not the editorial serif */
}

/* ── Base ────────────────────────────────────────── */
/* scrollbar-gutter reserves the scrollbar's space on EVERY page, so navigating
   between a scrolling page and a non-scrolling one no longer shifts the centered
   layout sideways. scrollbar-* recolours the bar to the theme (Firefox). */
html {
  /* Stop iOS Safari auto-inflating text (esp. in landscape) — render at the
     CSS size so fonts stay consistent across orientations and pages. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth; overflow-y: scroll; scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: var(--faint) transparent;
}

/* Themed scrollbars (WebKit/Blink) */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--faint); border-radius: 8px; border: 3px solid var(--bg); transition: background 0.2s; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.35s, color 0.35s;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle, var(--dot-color) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.35s;
}

/* ── Page transition overlay ─────────────────────── */
#page-transition {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.22s ease;
}

#page-transition.fade-out { opacity: 1; }

/* ── Nav ─────────────────────────────────────────── */
nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  padding: 0 max(48px, env(safe-area-inset-right)) 0 max(48px, env(safe-area-inset-left));
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(22,23,31,0.82);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  transition: background 0.35s, border-color 0.35s;
}

[data-theme="light"] nav  { background: rgba(250,247,242,0.88); }
[data-theme="ocean"] nav { background: rgba(5,13,28,0.85); }

.nav-logo {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--blue);
  text-decoration: none;
  letter-spacing: 0.04em;
}
.nav-logo span { color: var(--muted); transition: opacity 0.38s ease; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 36px;
  list-style: none;
}

.nav-links a {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 0.2s;
}
.nav-links a:hover, .nav-links a.active { color: var(--blue); }

/* Theme toggle button */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 6px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.35s;
}
.theme-toggle:hover { border-color: var(--blue); }

.theme-btn {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}
.theme-btn.active, .theme-btn:hover {
  background: var(--blue-dim);
  color: var(--blue);
}

/* ── Main wrapper ────────────────────────────────── */
main {
  position: relative;
  z-index: 1;
  padding-top: 64px;
  flex: 1 0 auto;   /* grow so the footer sits at the bottom on short pages (e.g. contact) */
}

/* ── Section layout ──────────────────────────────── */
.section {
  max-width: 1200px;
  margin: 0 auto;
  /* Safe-area insets keep content clear of the notch / Dynamic Island in
     landscape (viewport-fit=cover runs content edge-to-edge). env() is 0 on
     non-notched devices, so desktop is unchanged. */
  padding: 96px max(48px, env(safe-area-inset-right)) 96px max(48px, env(safe-area-inset-left));
}
/* Large and ultrawide screens: let content breathe instead of pinching
   into a centered sliver. */
@media (min-width: 1800px) {
  .section { max-width: 1440px; }
}

/* ── Typography ──────────────────────────────────── */
h1 { font-family: var(--display); font-size: clamp(2.5rem, 6vw, 4.5rem); font-weight: 600; line-height: 1.05; letter-spacing: -0.02em; }
h2 { font-family: var(--display); font-size: clamp(1.6rem, 3vw, 2.4rem); font-weight: 600; line-height: 1.15; letter-spacing: -0.01em; }
h3 { font-size: 1.15rem; font-weight: 600; }

.label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sun);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.label::before {
  content: '';
  display: block;
  width: 24px; height: 1px;
  background: var(--sun);
}

/* ── Button ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.06em;
  border-radius: 4px;
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
}
.btn-primary {
  background: var(--blue);
  color: #000;
  border: 1px solid transparent;
  font-weight: 500;
}
.btn-primary:hover {
  background: transparent;
  color: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 0 20px var(--blue-glow);
}
.btn-ghost {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  border-color: var(--blue);
  box-shadow: 0 0 16px var(--blue-glow);
}

/* ── Card ────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.35s;
}
.card:hover {
  border-color: rgba(79,158,255,0.35);
  box-shadow: 0 0 32px rgba(79,158,255,0.08);
}

/* ── Tag ─────────────────────────────────────────── */
.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 3px;
  background: var(--blue-dim);
  color: var(--blue);
  letter-spacing: 0.04em;
  transition: background 0.35s, color 0.35s;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 48px 0;
  transition: border-color 0.35s;
}

/* ── Scroll reveal ───────────────────────────────── */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}
.reveal-d1 { transition-delay: 0.1s; }
.reveal-d2 { transition-delay: 0.2s; }
.reveal-d3 { transition-delay: 0.3s; }
.reveal-d4 { transition-delay: 0.4s; }

/* Keep fade-up for above-the-fold (hero) elements that don't need IntersectionObserver */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up              { animation: fadeUp 0.6s ease both; }
.fade-up-d1           { animation-delay: 0.10s; }
.fade-up-d2           { animation-delay: 0.22s; }
.fade-up-d3           { animation-delay: 0.34s; }
.fade-up-d4           { animation-delay: 0.46s; }

/* ── Footer ──────────────────────────────────────── */
footer {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 28px 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color 0.35s;
}
footer p {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

/* ── Hamburger (hidden on desktop) ───────────────── */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 4px;
  margin-left: auto;
}
.hamburger-line {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--muted);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
nav.menu-open .hamburger .hamburger-line:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
nav.menu-open .hamburger .hamburger-line:nth-child(2) { opacity: 0; }
nav.menu-open .hamburger .hamburger-line:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

/* ── Back-to-top ─────────────────────────────────── */
.back-to-top {
  position: fixed;
  bottom: 22px; right: 22px;
  z-index: 90;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--blue);
  font-size: 18px; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s, visibility 0.25s, border-color 0.2s, box-shadow 0.2s;
  backdrop-filter: blur(8px);
}
.back-to-top.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.back-to-top:hover { border-color: var(--blue); box-shadow: 0 0 16px var(--blue-glow); }

/* ── AI chat widget (chat-widget.js) ─────────────────── */
.gp-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.gp-chat { position: fixed; bottom: 24px; right: 24px; z-index: 1000; font-family: var(--sans); }
.gp-chat-toggle {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--blue); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.28);
  transition: transform 0.18s, box-shadow 0.18s;
}
.gp-chat-toggle svg { width: 20px; height: 20px; } /* match back-to-top's glyph weight */
.gp-chat-toggle:hover { transform: scale(1.06); box-shadow: 0 8px 30px rgba(0,0,0,0.34); }
.gp-chat-toggle:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.gp-chat-ico-open, .gp-chat-ico-close { display: flex; }
.gp-chat-ico-close { display: none; }
.gp-chat.open .gp-chat-ico-open { display: none; }
.gp-chat.open .gp-chat-ico-close { display: flex; }

.gp-chat-panel {
  position: absolute; bottom: 60px; right: 0;
  width: 380px; max-width: calc(100vw - 40px);
  max-height: min(560px, calc(100vh - 120px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.32);
  display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; transform: translateY(10px) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease;
  transform-origin: bottom right;
}
.gp-chat-panel[hidden] { display: none; }
.gp-chat.open .gp-chat-panel { opacity: 1; transform: translateY(0) scale(1); }

.gp-chat-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px; background: var(--blue); color: #fff;
  font-weight: 600; font-size: 0.95rem; letter-spacing: 0.01em;
}
.gp-chat-x { background: transparent; border: none; color: #fff; cursor: pointer; display: flex; padding: 2px; border-radius: 6px; opacity: 0.85; }
.gp-chat-x:hover { opacity: 1; }

.gp-chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.gp-chat-msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; font-size: 0.9rem; line-height: 1.55; }
.gp-chat-msg p { margin: 0; }
.gp-chat-msg p + p { margin-top: 9px; }
.gp-chat-msg.user { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.gp-chat-msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }
.gp-chat-msg.loading { opacity: 0.6; font-style: italic; letter-spacing: 3px; }

.gp-chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); }
.gp-chat-form input {
  flex: 1; min-width: 0; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-size: 0.9rem; font-family: var(--sans);
}
.gp-chat-form input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-dim); }
.gp-chat-form input::placeholder { color: var(--muted); }
/* Send button uses --sun (the accent-touch colour). --sun == --blue on dark/
   light, so it only changes on Ocean, where it becomes the gold "sun". */
.gp-chat-send { width: 42px; height: 42px; flex: none; border: none; border-radius: 10px; background: var(--sun); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: filter 0.15s; }
.gp-chat-send:hover { filter: brightness(1.08); }
[data-theme="ocean"] .gp-chat-send { color: #062033; } /* dark glyph for contrast on gold */
.gp-chat-foot { margin: 0; padding: 8px 12px; font-size: 10.5px; color: var(--muted); text-align: center; background: var(--surface); border-top: 1px solid var(--border); }

/* Stack back-to-top above the chat toggle; hide it while the panel is open. */
body.gp-has-chat .back-to-top { right: 24px; }
body.gp-chat-open .back-to-top { opacity: 0 !important; visibility: hidden !important; pointer-events: none; }

@media (max-width: 640px) {
  .gp-chat { bottom: 16px; right: 16px; }
  .gp-chat-toggle { width: 42px; height: 42px; }
  .gp-chat-panel { bottom: 56px; width: calc(100vw - 32px); max-height: min(70vh, calc(100vh - 110px)); }
  body.gp-has-chat .back-to-top { right: 16px; }
}
@media print { .gp-chat { display: none !important; } }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 640px) {
  .back-to-top { bottom: 16px; right: 16px; width: 42px; height: 42px; }
  /* Fixed 64px bar as a 3-column grid: logo (left) | theme-picker (dead-centre)
     | menu icon (right, with clear edge margin). The menu is an absolute
     dropdown, so the bar never resizes or shifts on open. Explicit grid-column
     assignment ignores the DOM append order of the injected picker/hamburger. */
  nav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: 64px;   /* explicit full-height row — items centre in it (no drop to bottom) */
    align-items: center;
    /* generous edge padding + safe-area insets so the menu icon clears the
       screen edge / rounded corners and can rotate to an X smoothly */
    padding: 0 max(22px, env(safe-area-inset-right, 22px)) 0 max(22px, env(safe-area-inset-left, 22px));
    height: 64px;
    min-height: 64px;
  }
  /* grid-row:1 on all three — the picker/hamburger are injected out of DOM
     order, and sparse auto-placement was bumping the picker to a 2nd row
     (dropping it below the bar). Pinning the row keeps them on the 64px line. */
  .nav-logo { grid-column: 1; grid-row: 1; justify-self: start; align-self: center; }
  .theme-toggle { grid-column: 2; grid-row: 1; justify-self: center; align-self: center; }
  .hamburger { grid-column: 3; grid-row: 1; justify-self: end; align-self: center; margin: 0; align-items: center; padding: 6px 2px; }
  /* Menu is an absolute dropdown BELOW the bar — so opening it never resizes
     the 64px header row (which used to make the logo/picker/menu-icon jump). */
  .nav-links {
    display: none;
    position: absolute;
    top: 100%; left: 0; right: 0;
    flex-direction: column;
    gap: 0;
    padding: 4px 20px 14px;
    text-align: center;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: rgba(22,23,31,0.97);
    backdrop-filter: blur(18px);
  }
  [data-theme="light"] .nav-links { background: rgba(250,247,242,0.97); }
  [data-theme="ocean"] .nav-links { background: rgba(5,13,28,0.95); }
  .nav-links li { display: block; }
  .nav-links a { display: block; padding: 11px 0; font-size: 13px; }
  nav.menu-open .nav-links { display: flex; }
  .hamburger { display: flex; }
  .section { padding: 64px max(20px, env(safe-area-inset-right)) 64px max(20px, env(safe-area-inset-left)); }
}

/* ── Case-study hero CTA ───────────────────────────
   The sidebar card that holds "Launch Live Demo" drops below the whole article
   when .proj-layout collapses (<=768px), and on long cards the button falls
   under the fold even on desktop. The primary action therefore also lives in
   the hero at every width. Guarded by scripts/case-study-cta-check.mjs. */
.hero-cta { margin: -20px 0 40px; }
@media (max-width: 768px) {
  .hero-cta { display: flex; width: 100%; justify-content: center; margin: -24px 0 32px; }
}

/* ── Case-study layout: no grid blowout ─────────────
   .proj-layout is `1fr 280px` (one column at <=768px). `1fr` means
   minmax(auto, 1fr), so a `white-space: pre` receipt or architecture block
   forced the article track to its longest line: the page overflowed sideways
   on phones and the sidebar card was pushed off-screen on desktop. Letting the
   grid items shrink makes those blocks scroll inside themselves instead. */
.proj-layout > * { min-width: 0; }
