/* ── vizvani viz brand kit ───────────────────────────────────────────────────
   The ONE stylesheet a viz should link:  <link rel="stylesheet" href="/viz/_theme/viz.css">
   It pulls the self-hosted fonts and exposes the site's brand tokens as CSS
   variables, so any viz can theme against the same palette/typography without
   importing anything new. Mirrors src/styles/global.css on the main site. */

@import "/viz/_fonts/fonts.css";

:root {
  color-scheme: light;
  /* palette — matches the core website */
  --viz-paper:      #faf8f4;
  --viz-paper-2:    #f2efe8;
  --viz-ink:        #17150f;
  --viz-muted:      #6c665b;
  --viz-line:       #e6e0d5;
  --viz-accent:     #9a3b2f;   /* brick */
  --viz-accent-ink: #7e3025;
  /* warm near-black for dramatic/dark sections */
  --viz-dark:       #16150f;
  --viz-dark-2:     #201d15;

  /* typography — self-hosted; reuse these, don't add new font imports */
  --viz-serif: "Playfair Display", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --viz-sans:  "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Shared editorial shell. Individual stories can keep their own chart language,
     while these tokens hold navigation, reading measure, and section rhythm steady. */
  --story-width: 880px;
  --story-text-measure: 68ch;
}

/* Dark palette — mirrors the main site. Applies when the OS prefers dark AND the
   reader hasn't forced light, OR when the reader explicitly picked dark. A viz
   honours the reader's site-wide choice by adding the tiny no-FOUC bootstrap
   (see _theme/theme-init.html) so the same localStorage "theme" key sets
   [data-theme] on <html> before paint. Charts should read these vars, not
   hard-coded hexes, to follow the theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --viz-paper:      #16150f;
    --viz-paper-2:    #201e16;
    --viz-ink:        #f2efe6;
    --viz-muted:      #a8a291;
    --viz-line:       #322f25;
    --viz-accent:     #e0836f;
    --viz-accent-ink: #f0a892;
    --viz-dark:       #16150f;
    --viz-dark-2:     #201e16;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --viz-paper:      #16150f;
  --viz-paper-2:    #201e16;
  --viz-ink:        #f2efe6;
  --viz-muted:      #a8a291;
  --viz-line:       #322f25;
  --viz-accent:     #e0836f;
  --viz-accent-ink: #f0a892;
  --viz-dark:       #16150f;
  --viz-dark-2:     #201e16;
}

/* Published story shell --------------------------------------------------- */
.story-page {
  min-width: 0;
  color: var(--ink, var(--viz-ink));
  background: var(--paper, var(--viz-paper));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.story-page:not(.story-page--cinematic) {
  max-width: none;
  margin: 0;
  padding: 0;
  font-family: var(--sans, var(--viz-sans));
  line-height: 1.65;
}

.story-page:not(.story-page--cinematic) > .story-header,
.story-page:not(.story-page--cinematic) > main,
.story-page:not(.story-page--cinematic) > .story-footer,
.story-page:not(.story-page--cinematic) > .story-endnav {
  width: min(calc(100% - 40px), var(--story-width));
  margin-inline: auto;
}

.story-topbar {
  position: sticky;
  top: 0;
  z-index: 850;
  width: 100%;
  border-bottom: 1px solid var(--rule, var(--viz-line));
  background: color-mix(in srgb, var(--paper, var(--viz-paper)) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.15) blur(10px);
  backdrop-filter: saturate(1.15) blur(10px);
}

.story-topbar__inner {
  width: min(calc(100% - 32px), var(--story-width));
  min-height: 60px;
  margin-inline: auto;
  padding-right: 94px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.story-topbar a {
  color: var(--ink, var(--viz-ink));
  text-decoration: none;
}

.story-topbar a:hover { color: var(--accent, var(--viz-accent)); }

.story-brand {
  font-family: var(--serif, var(--viz-serif));
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.story-all {
  font-family: var(--sans, var(--viz-sans));
  font-size: 0.82rem;
  font-weight: 700;
}

.story-page--cinematic { --story-width: 1100px; }
.story-page--cinematic .story-topbar {
  border-color: rgba(255,255,255,.14);
  background: rgba(20,17,9,.92);
}
.story-page--cinematic .story-topbar a { color: rgba(255,255,255,.88); }
.story-page--cinematic .story-topbar a:hover { color: #fff; }

.story-header {
  padding-block: clamp(3.25rem, 8vw, 5.5rem) clamp(2.75rem, 6vw, 4.5rem);
}

.story-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.7rem;
  margin: 0 0 1.1rem;
  color: var(--accent, var(--viz-accent));
  font-family: var(--mono, ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.075em;
  line-height: 1.4;
  text-transform: uppercase;
}

.story-meta > * + *::before {
  content: "·";
  margin-right: 0.7rem;
  color: var(--ink-faint, var(--viz-muted));
}

.story-meta--light {
  justify-content: center;
  color: rgba(255,255,255,.72);
}
.story-meta--light > * + *::before { color: rgba(255,255,255,.32); }

.story-page .story-header h1 {
  max-width: 17ch;
  margin: 0;
  font-family: var(--serif, var(--viz-serif));
  font-size: clamp(2.55rem, 7vw, 4.65rem);
  font-weight: 500;
  line-height: 1.04;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.story-page .story-deck {
  max-width: var(--story-text-measure);
  margin: 1rem 0 0;
  color: var(--ink-soft, var(--viz-muted));
  font-size: clamp(1.05rem, 1rem + .45vw, 1.28rem);
  line-height: 1.55;
  text-wrap: pretty;
}

.story-byline {
  margin: 1.25rem 0 0;
  color: var(--ink-faint, var(--viz-muted));
  font-size: 0.86rem;
}

.story-byline a {
  color: var(--ink-soft, var(--viz-ink));
  font-weight: 600;
  text-decoration: none;
}
.story-byline a:hover { color: var(--accent, var(--viz-accent)); }

.story-byline--light { color: rgba(255,255,255,.58); }
.story-byline--light a { color: rgba(255,255,255,.88); }
.story-byline--light a:hover { color: #fff; }

.story-page .story-section {
  margin-block: clamp(3.75rem, 8vw, 6rem);
  padding-top: 1rem;
}

.story-page .story-section:first-of-type { margin-top: 0; }

.story-page .story-section h2 {
  max-width: 29ch;
  margin: 0 0 1rem;
  font-family: var(--serif, var(--viz-serif));
  font-size: clamp(1.9rem, 4.2vw, 2.75rem);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.story-page .lede,
.story-page .prose {
  max-width: var(--story-text-measure);
  line-height: 1.72;
  text-wrap: pretty;
}

.story-page .lede { font-size: 1.04rem; }

.story-page .caption,
.story-page figure figcaption {
  max-width: 72ch;
  color: var(--ink-soft, var(--viz-muted));
  line-height: 1.65;
}

.story-page .kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.story-page .kpi-card {
  min-width: 0;
  min-height: 11.5rem;
  display: flex;
  flex-direction: column;
}

.story-page .kpi-card .kpi-value {
  font-variant-numeric: tabular-nums lining-nums;
}

.story-page .kpi-card .kpi-sub {
  margin-top: auto;
  padding-top: 0.8rem;
}

.story-footer {
  margin-top: clamp(4rem, 9vw, 7rem);
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule, var(--viz-line));
  color: var(--ink-soft, var(--viz-muted));
  font-size: 0.82rem;
  line-height: 1.75;
}

.story-footer a {
  color: inherit;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
  text-underline-offset: 2px;
}
.story-footer a:hover { color: var(--accent, var(--viz-accent)); }

.story-endnav {
  margin-top: 1.75rem;
  padding-bottom: clamp(3rem, 8vw, 5.5rem);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  font-family: var(--sans, var(--viz-sans));
  font-size: 0.9rem;
  font-weight: 700;
}

.story-endnav a {
  color: var(--accent, var(--viz-accent));
  text-decoration: none;
}
.story-endnav a:hover { color: var(--accent-ink, var(--viz-accent-ink)); }

.story-page--cinematic > .story-endnav {
  width: min(calc(100% - 40px), var(--story-width));
  margin-inline: auto;
}

@media (max-width: 760px) {
  .story-page .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .story-page .kpi-row > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .story-page .kpi-card { min-height: 0; }
}

@media (max-width: 480px) {
  .story-topbar__inner { min-height: 56px; padding-right: 88px; gap: 0.75rem; }
  .story-all { font-size: 0.78rem; }
  .story-page:not(.story-page--cinematic) > .story-header,
  .story-page:not(.story-page--cinematic) > main,
  .story-page:not(.story-page--cinematic) > .story-footer,
  .story-page:not(.story-page--cinematic) > .story-endnav {
    width: min(calc(100% - 32px), var(--story-width));
  }
  .story-header { padding-block: 2.75rem 2.25rem; }
  .story-page .story-header h1 { font-size: clamp(2.35rem, 12vw, 3.25rem); }
  .story-meta { gap: 0.35rem 0.55rem; }
  .story-meta > * + *::before { margin-right: 0.55rem; }
  .story-page .story-section { margin-block: 3.5rem; }
}

@media print {
  .story-topbar,
  .story-endnav { display: none !important; }
  .story-page:not(.story-page--cinematic) > .story-header,
  .story-page:not(.story-page--cinematic) > main,
  .story-page:not(.story-page--cinematic) > .story-footer {
    width: 100%;
  }
}
