/* =========================================================================
   Nest.IQ — Design System v2  ·  "Light Editorial Luxury"
   Warm porcelain + ink · clay/teal/gold/indigo · photography-led · chart-first.
   The single source of truth for the website, decks, brand, and docs.
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300..600;1,9..144,300..500&family=Geist:wght@300..600&family=Geist+Mono:wght@400;500&display=swap');

:root {
  /* ---- Light canvas (warm porcelain) ---- */
  --paper:      #FDFBF6;   /* lifted surfaces / cards */
  --canvas:     #F6F1E7;   /* page background */
  --sand:       #EFE7D6;   /* subtle panel */
  --sand-deep:  #E3D7BF;   /* hairline-ish fills */

  /* ---- Ink (text + dramatic dark sections) ---- */
  --ink:        #14181C;   /* primary text + dark sections */
  --ink-2:      #20262C;   /* dark section raised */
  --ink-soft:   #3C434A;   /* secondary text */
  --ink-muted:  #6E747B;   /* tertiary text */
  --ink-faint:  #A9AAA2;   /* captions on light */

  /* ---- Accents = also the categorical data-viz palette ---- */
  --clay:   #C8552E;  --clay-deep: #A23E1F;  --clay-soft: #E7A187;
  --teal:   #0E5A52;  --teal-deep: #093F39;  --teal-soft: #6FA39B;
  --gold:   #C9A24B;  --gold-deep: #9A7B30;  --gold-soft: #E4CD96;
  --indigo: #2E3A8C;  --indigo-deep:#1E2762; --indigo-soft:#8E97C9;
  --plum:   #7A3B57;  /* 5th viz hue */

  --viz-1: var(--clay);  --viz-2: var(--teal);  --viz-3: var(--gold);
  --viz-4: var(--indigo); --viz-5: var(--plum);

  /* text-on color */
  --on-clay: #FDF4EE; --on-teal: #EAF4F1; --on-indigo: #ECEEFA; --on-ink: #F6F1E7;

  /* ---- Type ---- */
  --font-display: 'Fraunces', 'Hoefler Text', Georgia, serif;
  --font-sans:    'Geist', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono:    'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --t-mega:    clamp(3.5rem, 1.8rem + 8vw, 9rem);
  --t-display: clamp(2.5rem, 1.6rem + 4vw, 5rem);
  --t-h1:      clamp(2rem, 1.4rem + 2.4vw, 3.25rem);
  --t-h2:      clamp(1.5rem, 1.2rem + 1.2vw, 2.1rem);
  --t-lede:    clamp(1.1rem, 1rem + 0.5vw, 1.4rem);
  --t-body:    1.02rem;
  --t-eyebrow: 0.74rem;

  /* ---- Geometry / rhythm ---- */
  --r-sm: 8px; --r: 14px; --r-lg: 20px; --r-xl: 30px; --r-pill: 999px;
  --gutter: clamp(1.25rem, 0.6rem + 2.6vw, 3.5rem);
  --maxw: 1240px;
  --space-section: clamp(4.5rem, 3rem + 6vw, 9rem);

  /* ---- Motion ---- */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-io: cubic-bezier(0.65, 0, 0.35, 1);
  --dur: 0.7s; --dur-fast: 0.28s;

  /* ---- Shadow (soft, warm — light world) ---- */
  --shadow-s: 0 1px 2px rgba(20,24,28,0.05), 0 2px 8px rgba(20,24,28,0.05);
  --shadow-m: 0 2px 6px rgba(20,24,28,0.06), 0 16px 40px -12px rgba(20,24,28,0.16);
  --shadow-l: 0 4px 12px rgba(20,24,28,0.08), 0 36px 70px -20px rgba(20,24,28,0.26);
  --hair: 1px solid rgba(20,24,28,0.12);
  --hair-soft: 1px solid rgba(20,24,28,0.08);

  /* Surface used by the "dramatic dark" panels (.panel-ink, .sec.dark, footers).
     In LIGHT mode these are ink-on-light; the token lets dark mode retarget them
     to a *lifted* dark surface instead of inheriting the now-light --ink. */
  --ink-surface:   var(--ink);
  --ink-surface-2: var(--ink-2);
  /* Full-bleed accent panels — saturated in light, deepened in dark. */
  --teal-surface:   var(--teal);
  --clay-surface:   var(--clay);
  --indigo-surface: var(--indigo);
  --on-ink-soft:   rgba(246,241,231,0.78);
  --on-ink-muted:  rgba(246,241,231,0.6);
  --on-ink-faint:  rgba(246,241,231,0.5);
  --on-ink-line:   rgba(246,241,231,0.16);
  --grain-opacity: 0.035;
  --grain-blend:   multiply;
  --rule-color:    rgba(20,24,28,0.14);
  --selection:     rgba(200,85,46,0.20);
  --meter-track:   rgba(20,24,28,0.10);
  color-scheme: light;
}

/* =========================================================================
   DARK · "Warm Editorial Midnight"
   A real, designed warm-dark theme — deep-charcoal canvas, lifted warm panels,
   alabaster text, slightly brightened accents. Not an invert, not pure black.
   Every var(--token) below re-points, so all usages flip automatically.
   ========================================================================= */
html[data-theme="dark"] {
  /* ---- Warm dark canvas + lifted panels ---- */
  --paper:      #1E1A15;   /* lifted surfaces / cards */
  --canvas:     #15120E;   /* page background (warm deep charcoal) */
  --sand:       #241F18;   /* subtle panel */
  --sand-deep:  #322A20;   /* hairline-ish fills */

  /* ---- "Ink" now means TEXT (alabaster) — warm off-white ---- */
  --ink:        #F4EEE2;   /* primary text */
  --ink-2:      #E9E2D4;   /* raised text / hover */
  --ink-soft:   #D8D2C6;   /* secondary text (~10:1 on canvas) */
  --ink-muted:  #A39C8E;   /* tertiary text (≥4.5:1 on canvas) */
  --ink-faint:  #7C766B;   /* captions (≥3:1 — large/UI only) */

  /* ---- Accents brightened for a dark field; deep variants lifted ---- */
  --clay:   #E07A52;  --clay-deep: #C8552E;  --clay-soft: #F0A988;
  --teal:   #4FA89C;  --teal-deep: #2C8076;  --teal-soft: #8FC4BC;
  --gold:   #D9B86A;  --gold-deep: #C9A24B;  --gold-soft: #ECD9A6;
  --indigo: #7C88D6;  --indigo-deep:#5A66B8; --indigo-soft:#A6AEE0;
  --plum:   #C57B98;  /* 5th viz hue — lifted */

  --viz-1: var(--clay);  --viz-2: var(--teal);  --viz-3: var(--gold);
  --viz-4: var(--indigo); --viz-5: var(--plum);

  /* text-on color — these are ALWAYS light text on deep/saturated accent
     panels (.panel-*, .sec.teal, audience blocks), so they stay light in dark. */
  --on-clay: #FBEBE2; --on-teal: #E6F2EF; --on-indigo: #ECEEFA; --on-ink: #F4EEE2;

  /* ---- Dramatic-dark panels: lift ABOVE the canvas so they read on dark ---- */
  --ink-surface:   #221D17;
  --ink-surface-2: #2B251D;
  /* Deep, still-saturated accent panels for dark mode (light text stays AA). */
  --teal-surface:   #0F433D;
  --clay-surface:   #8C3A1F;
  --indigo-surface: #232C66;
  --on-ink-soft:   rgba(244,238,226,0.80);
  --on-ink-muted:  rgba(244,238,226,0.62);
  --on-ink-faint:  rgba(244,238,226,0.48);
  --on-ink-line:   rgba(244,238,226,0.14);

  /* ---- Shadows: deeper + softer on a dark canvas ---- */
  --shadow-s: 0 1px 2px rgba(0,0,0,0.40), 0 2px 10px rgba(0,0,0,0.36);
  --shadow-m: 0 2px 6px rgba(0,0,0,0.44), 0 18px 44px -12px rgba(0,0,0,0.62);
  --shadow-l: 0 4px 14px rgba(0,0,0,0.50), 0 40px 80px -20px rgba(0,0,0,0.72);

  /* ---- Hairlines: light-on-dark ---- */
  --hair:      1px solid rgba(244,238,226,0.12);
  --hair-soft: 1px solid rgba(244,238,226,0.07);
  --rule-color: rgba(244,238,226,0.14);
  --meter-track: rgba(244,238,226,0.12);

  /* ---- Atmosphere ---- */
  --grain-opacity: 0.05;
  --grain-blend:   soft-light;
  --selection:     rgba(224,122,82,0.32);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body {
  margin: 0; min-height: 100dvh;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--t-body);
  font-weight: 360;
  line-height: 1.62;
  letter-spacing: 0.002em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Subtle warm paper grain (very light) */
.grain::after {
  content:''; position: fixed; inset:0; z-index:-1; pointer-events:none; opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  mix-blend-mode: var(--grain-blend);
}

/* =========================================================================
   Type
   ========================================================================= */
.font-display { font-family: var(--font-display); }
.font-mono { font-family: var(--font-mono); }
h1,h2,h3,h4 { margin: 0; font-weight: 400; }
.mega    { font-family: var(--font-display); font-size: var(--t-mega); line-height: 0.92; letter-spacing: -0.025em; font-weight: 380; }
.display { font-family: var(--font-display); font-size: var(--t-display); line-height: 1.0; letter-spacing: -0.02em; font-weight: 400; }
.h1      { font-family: var(--font-display); font-size: var(--t-h1); line-height: 1.08; letter-spacing: -0.015em; }
.h2      { font-family: var(--font-display); font-size: var(--t-h2); line-height: 1.18; letter-spacing: -0.01em; }
.lede    { font-size: var(--t-lede); line-height: 1.5; color: var(--ink-soft); font-weight: 360; }
p { margin: 0 0 1em; }
.accent  { font-family: var(--font-display); font-style: italic; font-weight: 400; }
.eyebrow {
  font-family: var(--font-mono); font-size: var(--t-eyebrow);
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--clay); font-weight: 500;
}
.mono { font-family: var(--font-mono); } .tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-muted); } .soft { color: var(--ink-soft); }

/* =========================================================================
   Layout
   ========================================================================= */
.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gutter); }
.section { padding-block: var(--space-section); }
.rule { height: 1px; background: var(--rule-color); border: 0; }
.bento { display: grid; gap: 1.1rem; grid-template-columns: repeat(12, 1fr); }
.bento > * { grid-column: span 12; }
@media (min-width: 760px) {
  .col-6 { grid-column: span 6; } .col-4 { grid-column: span 4; }
  .col-8 { grid-column: span 8; } .col-5 { grid-column: span 5; } .col-7 { grid-column: span 7; } .col-3 { grid-column: span 3; }
}

/* =========================================================================
   Surfaces — light cards + colour-blocked + ink (dramatic) panels
   ========================================================================= */
.card { background: var(--paper); border: var(--hair-soft); border-radius: var(--r-lg); box-shadow: var(--shadow-s); padding: 1.6rem; }
.card-lift { transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.card-lift:hover { transform: translateY(-4px); box-shadow: var(--shadow-m); }
.panel-ink    { background: var(--ink-surface); color: var(--on-ink); border-radius: var(--r-lg); }
.panel-clay   { background: var(--clay-surface); color: var(--on-clay); border-radius: var(--r-lg); }
.panel-teal   { background: var(--teal-surface); color: var(--on-teal); border-radius: var(--r-lg); }
.panel-indigo { background: var(--indigo-surface); color: var(--on-indigo); border-radius: var(--r-lg); }
.panel-sand   { background: var(--sand); border-radius: var(--r-lg); }
.on-dark { color: var(--on-ink); } .on-dark .eyebrow { color: var(--gold-soft); }
.on-dark .lede { color: var(--on-ink-soft); } .on-dark .muted { color: var(--on-ink-muted); }

.chip { display:inline-flex; align-items:center; gap:0.45em; padding:0.34em 0.8em; border-radius:var(--r-pill); border:1px solid currentColor; font-family:var(--font-mono); font-size:0.66rem; letter-spacing:0.12em; text-transform:uppercase; }

/* =========================================================================
   Buttons
   ========================================================================= */
.btn { display:inline-flex; align-items:center; gap:0.5em; font-family:var(--font-sans); font-weight:500; font-size:0.96rem; padding:0.82em 1.5em; border-radius:var(--r-pill); cursor:pointer; border:1px solid transparent; text-decoration:none; transition: transform var(--dur-fast) var(--ease), background var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast); }
.btn:active { transform: scale(0.98); }
.btn-ink { background: var(--ink-surface); color: var(--on-ink); }
.btn-ink:hover { background: var(--clay); color: var(--on-clay); }
.btn-clay { background: var(--clay); color: var(--on-clay); box-shadow: var(--shadow-s); }
.btn-clay:hover { background: var(--clay-deep); }
.btn-ghost { background: transparent; color: var(--ink); border-color: color-mix(in oklab, var(--ink) 25%, transparent); }
.btn-ghost:hover { border-color: var(--clay); color: var(--clay); }

/* =========================================================================
   Data-viz primitives (editorial charts)
   ========================================================================= */
.viz-axis { stroke: color-mix(in oklab, var(--ink) 18%, transparent); stroke-width: 1; }
.viz-grid { stroke: color-mix(in oklab, var(--ink) 8%, transparent); stroke-width: 1; }
.viz-label { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em; fill: var(--ink-muted); }
.viz-value { font-family: var(--font-display); fill: var(--ink); }
.bar { transition: width var(--dur) var(--ease), height var(--dur) var(--ease); }
/* progress / share meter */
.meter { height: 10px; border-radius: var(--r-pill); background: var(--meter-track); overflow: hidden; }
.meter > span { display:block; height:100%; border-radius: var(--r-pill); background: var(--clay); }

/* big stat */
.stat-xl { font-family: var(--font-display); font-size: clamp(2.6rem, 2rem + 3vw, 4.6rem); line-height: 0.92; letter-spacing: -0.02em; }
.stat-src { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.06em; color: var(--ink-soft); }

/* =========================================================================
   Motion — reveal (fail-safe: visible without JS, hidden only with .js)
   ========================================================================= */
.js .reveal { opacity: 0; transform: translateY(22px); transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .reveal { opacity:1 !important; transform:none !important; } }

/* =========================================================================
   A11y
   ========================================================================= */
:focus-visible { outline: 2px solid var(--clay); outline-offset: 3px; border-radius: 4px; }
::selection { background: var(--selection); }
a { color: inherit; }

/* =========================================================================
   Theme toggle — fixed, accessible, brand-styled (sun/moon)
   ========================================================================= */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--r-pill);
  background: var(--paper); color: var(--ink);
  border: var(--hair); box-shadow: var(--shadow-s);
  cursor: pointer; padding: 0; line-height: 0;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.theme-toggle:hover { color: var(--clay); border-color: var(--clay); transform: translateY(-1px); }
.theme-toggle svg { width: 19px; height: 19px; display: block; }
.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun  { display: block; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
html[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }
/* Floating variant for pages without a header slot */
.theme-toggle-fixed {
  position: fixed; right: clamp(1rem, 2.5vw, 1.6rem); bottom: clamp(1rem, 2.5vw, 1.6rem);
  z-index: 80; width: 46px; height: 46px;
}
.theme-toggle-fixed svg { width: 21px; height: 21px; }
@media print { .theme-toggle, .theme-toggle-fixed { display: none !important; } }
