/* ==========================================================================
   Saepium. Atelier design system.
   Tokens are the only source of color, space, and type values.
   Palette weights: ink 35, brand 20, bone 15, cream 15, slate 10, espresso 5.
   ========================================================================== */

/* ---------- Tokens ---------- */

:root {
  /* Palette */
  --ink: #0B1A35;
  --brand: #336699;
  --slate: #5E738A;
  --bone: #D1CCBF;
  --espresso: #1A1614;
  --cream: #F8F4EE;
  --bone-light: #F1EBE0;
  --rule: #E8E2D5;
  --alert: #B85450;   /* status labels only */
  --teal: #0F766E;    /* positive deltas only */
  --white: #FFFFFF;
  --brand-hover: #2B5680;
  /* Departure, documented: slate #5E738A measures 4.46:1 on cream,
     just under the 4.5:1 body floor the same style guide requires.
     Small slate text on cream uses this shade, slate everywhere else. */
  --slate-text: #5A6E84;

  /* On-ink derived surfaces */
  --ink-raise: #12234233;
  --rule-on-ink: rgba(209, 204, 191, 0.18);

  /* Type */
  --font-display: "Poppins", "Helvetica Neue", Arial, sans-serif;
  --font-head: "Raleway", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Inter", "Helvetica Neue", Arial, sans-serif;

  --text-display: clamp(2.75rem, 1.6rem + 4.8vw, 5.5rem);
  --text-h1: clamp(2.25rem, 1.7rem + 2.2vw, 3.5rem);
  --text-h2: clamp(1.75rem, 1.4rem + 1.4vw, 2.5rem);
  --text-h3: clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem);
  --text-body: 1.0625rem;
  --text-small: 0.875rem;
  --text-eyebrow: 0.8125rem;

  /* Spacing: 8-point scale only */
  --s-4: 4px;
  --s-8: 8px;
  --s-12: 12px;
  --s-16: 16px;
  --s-24: 24px;
  --s-32: 32px;
  --s-48: 48px;
  --s-64: 64px;
  --s-96: 96px;

  /* Layout */
  --container: 1280px;
  --gutter: 24px;
  --prose: 65ch;

  /* Shape and elevation */
  --radius-card: 8px;
  --radius-pill: 999px;
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.08);

  /* Motion */
  --t-fast: 150ms;
  --t-med: 240ms;
  --t-slow: 300ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset and base ---------- */

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

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

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

img, svg, video { max-width: 100%; height: auto; display: block; }

h1, h2, h3, h4 { margin: 0 0 var(--s-24); line-height: 1.15; }

h1 { font-family: var(--font-head); font-weight: 700; font-size: var(--text-h1); letter-spacing: -0.01em; }
h2 { font-family: var(--font-head); font-weight: 700; font-size: var(--text-h2); letter-spacing: -0.01em; }
h3 { font-family: var(--font-head); font-weight: 600; font-size: var(--text-h3); }

p { margin: 0 0 var(--s-16); max-width: var(--prose); }
p:last-child { margin-bottom: 0; }

ul, ol { margin: 0 0 var(--s-16); padding-left: 1.25em; }

a { color: var(--brand); text-decoration: none; transition: color var(--t-fast) var(--ease); }
a:hover { color: var(--brand-hover); }

::selection { background: var(--bone); color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 3px;
  border-radius: 2px;
}

.on-ink :focus-visible { outline-color: var(--bone); }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 300;
  background: var(--ink);
  color: var(--white);
  padding: var(--s-12) var(--s-24);
  font-weight: 600;
}
.skip-link:focus { left: 0; }

/* ---------- Surfaces ---------- */

.on-ink { background: var(--ink); color: var(--bone); }
.on-ink h1, .on-ink h2, .on-ink h3 { color: var(--white); }
.on-cream { background: var(--cream); color: var(--ink); }
.on-white { background: var(--white); color: var(--ink); }

/* Atelier dot grid. Hero zones and dividers only, never behind body copy. */
.dot-grid-ink {
  background-image: radial-gradient(circle, rgba(209, 204, 191, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
}
.dot-grid-cream {
  background-image: radial-gradient(circle, rgba(11, 26, 53, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* ---------- Layout ---------- */

.container {
  width: min(100% - 2 * var(--gutter), var(--container));
  margin-inline: auto;
}

.section { padding-block: var(--s-96); }
.section-tight { padding-block: var(--s-64); }

.grid-2 { display: grid; gap: var(--s-24); }
.grid-3 { display: grid; gap: var(--s-24); }
.grid-4 { display: grid; gap: var(--s-24); }

@media (min-width: 768px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Type utilities ---------- */

.display {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-display);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 var(--s-24);
}

.eyebrow {
  display: block;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--text-eyebrow);
  font-variant-caps: all-small-caps;
  letter-spacing: 0.16em;
  margin-bottom: var(--s-16);
  color: var(--slate-text);
}
.on-ink .eyebrow { color: var(--bone); }

.lede { font-size: clamp(1.125rem, 1.05rem + 0.4vw, 1.375rem); line-height: 1.6; }

.num-prefix {
  font-family: var(--font-head);
  font-weight: 700;
  color: var(--brand);
}
.on-ink .num-prefix { color: var(--bone); }

.pull-quote {
  border-left: 4px solid var(--bone);
  padding-left: var(--s-24);
  margin: var(--s-32) 0;
  font-family: var(--font-head);
  font-weight: 700;
  font-style: italic;
  font-size: var(--text-h3);
  line-height: 1.4;
  color: var(--brand);
  max-width: var(--prose);
}
.pull-quote cite {
  display: block;
  margin-top: var(--s-12);
  font-family: var(--font-body);
  font-weight: 400;
  font-style: normal;
  font-size: var(--text-small);
  color: var(--slate);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-8);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1;
  padding: var(--s-16) var(--s-32);
  min-height: 48px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
}
.btn svg { width: 18px; height: 18px; flex: none; }

.btn-primary { background: var(--brand); color: var(--white); }
.btn-primary:hover { background: var(--brand-hover); color: var(--white); }

.btn-secondary { background: transparent; color: var(--ink); border-color: var(--ink); }
.btn-secondary:hover { background: var(--ink); color: var(--cream); }

.on-ink .btn-secondary { color: var(--bone); border-color: var(--bone); }
.on-ink .btn-secondary:hover { background: var(--bone); color: var(--ink); }

/* ---------- Pills ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-8);
  padding: var(--s-4) var(--s-16);
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--text-eyebrow);
  font-variant-caps: all-small-caps;
  letter-spacing: 0.12em;
  background: var(--bone);
  color: var(--ink);
}
.pill-brand { background: var(--brand); color: var(--white); }
.pill-outline { background: transparent; border: 1px solid var(--rule-on-ink); color: var(--bone); }

/* ---------- Cards ---------- */

.card {
  background: var(--white);
  border: 1px solid var(--rule);
  border-top: 4px solid var(--bone);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--s-24);
  color: var(--ink);
}
.card-brand { border-top-color: var(--brand); }
.card h3 { margin-bottom: var(--s-12); }
.card p { font-size: var(--text-small); line-height: 1.65; color: var(--espresso); }

.icon-seat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-pill);
  background: rgba(51, 102, 153, 0.12);
  color: var(--brand);
  margin-bottom: var(--s-16);
}
.icon-seat svg { width: 24px; height: 24px; }

/* KPI card */
.kpi { display: flex; flex-direction: column; gap: var(--s-8); }
.kpi .kpi-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 1.5rem + 2vw, 3rem);
  line-height: 1;
  color: var(--ink);
}
.kpi .kpi-delta { font-weight: 600; font-size: var(--text-small); color: var(--teal); }
.kpi .kpi-label { font-size: var(--text-small); color: var(--slate); }

/* Bone callout */
.callout {
  background: var(--bone-light);
  border-left: 6px solid var(--bone);
  border-radius: 0 var(--radius-card) var(--radius-card) 0;
  padding: var(--s-24);
  margin: var(--s-32) 0;
  max-width: var(--prose);
}
.callout .callout-eyebrow {
  display: block;
  font-family: var(--font-head);
  font-weight: 700;
  font-style: italic;
  color: var(--ink);
  margin-bottom: var(--s-8);
}
.callout p { font-size: var(--text-small); }

/* ---------- Data table ---------- */

.table-wrap { overflow-x: auto; }
.table-data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-small);
  text-align: left;
}
.table-data th {
  background: var(--cream);
  font-family: var(--font-body);
  font-weight: 600;
  padding: var(--s-12) var(--s-16);
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
.table-data td {
  padding: var(--s-16);
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

/* ---------- Credibility bar ---------- */

.cred-bar {
  border-block: 1px solid var(--rule);
  background: var(--cream);
  padding-block: var(--s-24);
}
.cred-bar p {
  max-width: none;
  text-align: center;
  font-size: var(--text-small);
  color: var(--ink);
  margin: 0;
}
.cred-bar strong { font-weight: 600; }

/* ---------- Header ---------- */

.site-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  transition: background-color var(--t-med) var(--ease),
              border-color var(--t-med) var(--ease);
  border-bottom: 1px solid transparent;
}
.site-header.is-solid {
  background: var(--cream);
  border-bottom-color: var(--rule);
}

.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-24);
  min-height: 72px;
}

.wordmark {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.375rem;
  letter-spacing: 0.02em;
  color: var(--white);
}
.wordmark:hover { color: var(--white); }
.site-header.is-solid .wordmark { color: var(--ink); }
.site-header.is-solid .wordmark:hover { color: var(--ink); }

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--s-24);
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-links a {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--bone);
  padding: var(--s-8) 0;
}
.nav-links a:hover,
.nav-links a[aria-current="page"] { color: var(--white); }
.site-header.is-solid .nav-links a { color: var(--slate); }
.site-header.is-solid .nav-links a:hover,
.site-header.is-solid .nav-links a[aria-current="page"] { color: var(--ink); }

.nav-cta .btn { padding: var(--s-12) var(--s-24); min-height: 44px; font-size: 0.9375rem; }

.nav-toggle {
  display: none;
  background: none;
  border: 0;
  padding: var(--s-12);
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--white);
  margin: 5px 0;
  transition: transform var(--t-med) var(--ease), opacity var(--t-fast) var(--ease);
}
.site-header.is-solid .nav-toggle span { background: var(--ink); }

@media (max-width: 1023px) {
  .nav-toggle { display: block; }
  .nav-links {
    position: fixed;
    inset: 0;
    background: var(--ink);
    flex-direction: column;
    justify-content: center;
    gap: var(--s-24);
    visibility: hidden;
    opacity: 0;
    transition: opacity var(--t-slow) var(--ease), visibility 0s var(--t-slow);
  }
  .nav-links.is-open {
    visibility: visible;
    opacity: 1;
    transition: opacity var(--t-slow) var(--ease);
  }
  .nav-links a { font-size: 1.25rem; color: var(--bone); }
  .site-header.is-solid .nav-links a { color: var(--bone); }
  body.nav-open { overflow: hidden; }
  .nav-open .nav-toggle span { background: var(--white); }
  .nav-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
  .nav-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
}

/* ---------- Hero scenes ---------- */

.hero {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  min-height: 100svh;
  padding-block: calc(var(--s-96) + 72px) var(--s-96);
  overflow: hidden;
}
.hero-interior { min-height: 72svh; }

.hero-media {
  position: absolute;
  inset: 0;
  z-index: -2;
}
.hero-media img,
.hero-media video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Legibility scrim over generated media. Typography stays dominant. */
.hero-scrim {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg,
    rgba(11, 26, 53, 0.78) 0%,
    rgba(11, 26, 53, 0.45) 55%,
    rgba(11, 26, 53, 0.82) 100%);
}

.hero .display { max-width: 16ch; }
.hero .lede { max-width: 52ch; margin-bottom: var(--s-32); }

.hero-ctas { display: flex; flex-wrap: wrap; gap: var(--s-16); }

/* Staged hero entrance in pure CSS: typography first, then support.
   Wrapped in no-preference so reduced motion never sees a hidden state. */
@media (prefers-reduced-motion: no-preference) {
  [data-hero-stage] {
    opacity: 0;
    transform: translateY(16px);
    animation: stage-in 0.4s var(--ease) forwards;
  }
  [data-hero-stage] ~ [data-hero-stage] { animation-delay: 0.1s; }
  [data-hero-stage] ~ [data-hero-stage] ~ [data-hero-stage] { animation-delay: 0.2s; }
  [data-hero-stage] ~ [data-hero-stage] ~ [data-hero-stage] ~ [data-hero-stage] { animation-delay: 0.3s; }
}
@keyframes stage-in {
  to { opacity: 1; transform: none; }
}

/* ---------- Scrollytelling scenes ---------- */

.scene { position: relative; }

.scene-viewport {
  position: relative;
  min-height: 100svh;
  display: flex;
  align-items: center;
  overflow: hidden;
}

/* Beats stack in the same place while the scene holds; JS cross-fades
   them. The hold is native position:sticky (browser layout engine, no
   JS pinning): the .scene gets a JS-set runway height and the viewport
   sticks inside it. Without JS, or with reduced motion, .is-wired is
   never added and everything stacks vertically as normal flow. */
.beat { max-width: var(--prose); }
.scene[data-pin] .beat { margin-bottom: var(--s-64); }
.scene.is-wired .scene-viewport {
  position: sticky;
  top: 0;
}
.scene[data-pin].is-wired .scene-viewport .beat {
  position: absolute;
  margin-bottom: 0;
}

/* Divider bands: generated texture, never behind body content */
.divider-band {
  height: clamp(160px, 24vh, 240px);
  background-size: cover;
  background-position: center;
  position: relative;
}
.divider-band::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(11, 26, 53, 0.35);
}

/* ---------- Loss exceedance curve figure ---------- */

.lec-scene { min-height: 100svh; display: flex; align-items: center; }

.lec-figure { max-width: 720px; margin-inline: auto; }
.lec-figure svg { width: 100%; height: auto; }
.lec-source {
  font-size: 0.8125rem;
  color: var(--slate);
  margin-top: var(--s-12);
  text-align: left;
}

/* ---------- Product frame (client screenshots only) ---------- */

.product-frame {
  background: var(--cream);
  border: 1px solid var(--rule);
  border-radius: var(--radius-card);
  padding: var(--s-16);
}
.product-frame img { border: 1px solid var(--rule); border-radius: 4px; }
.product-frame figcaption {
  font-size: 0.8125rem;
  color: var(--slate-text);
  padding-top: var(--s-12);
}

/* ---------- Forms ---------- */

.form-grid { display: grid; gap: var(--s-16); }
@media (min-width: 768px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-full { grid-column: 1 / -1; }
}

.field { display: flex; flex-direction: column; gap: var(--s-8); }
.field label { font-weight: 600; font-size: var(--text-small); color: var(--ink); }
.field label .optional { font-weight: 400; color: var(--slate-text); }

.field input,
.field select,
.field textarea {
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: var(--radius-card);
  padding: var(--s-12) var(--s-16);
  min-height: 48px;
  width: 100%;
  transition: border-color var(--t-fast) var(--ease);
}
.field textarea { min-height: 128px; resize: vertical; }
.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256' fill='%235E738A'%3E%3Cpath d='M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-16) center;
  background-size: 16px;
  padding-right: var(--s-48);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(51, 102, 153, 0.18);
}

.field input[aria-invalid="true"],
.field select[aria-invalid="true"],
.field textarea[aria-invalid="true"] { border-color: var(--alert); }

.field-error {
  min-height: 1.2em;
  font-size: 0.8125rem;
  color: var(--alert);
}

.form-status { font-weight: 600; color: var(--ink); margin-top: var(--s-16); }

/* ---------- Footer ---------- */

.site-footer {
  background: var(--ink);
  color: var(--bone);
  padding-block: var(--s-64) var(--s-32);
  font-size: var(--text-small);
}
.site-footer a { color: var(--bone); }
.site-footer a:hover { color: var(--white); }
.site-footer .btn-primary { color: var(--white); }
.site-footer .btn-primary:hover { color: var(--white); }

.footer-grid { display: grid; gap: var(--s-32); margin-bottom: var(--s-48); }
@media (min-width: 768px) {
  .footer-grid { grid-template-columns: 2fr 1fr 1fr 1fr; }
}
.footer-grid h2 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--text-eyebrow);
  font-variant-caps: all-small-caps;
  letter-spacing: 0.16em;
  color: var(--bone);
  margin-bottom: var(--s-16);
}
.footer-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-8); }

.footer-note {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-16);
  justify-content: space-between;
  border-top: 1px solid var(--rule-on-ink);
  padding-top: var(--s-24);
  color: var(--bone);
}

/* ---------- Reveal defaults ----------
   Content is visible without JS. GSAP applies hidden states at runtime. */

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .hero-media video { display: none; }
  .hero-media .hero-poster-fallback { display: block; }
}
