/* ============================================================
   MIDPOINT — BASE
   Modern reset, typography defaults, accessibility utilities.
   ============================================================ */

/* ---------- Modern reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: var(--leading-body);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  background: var(--surface-cream);
  color: var(--ink-primary);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  min-height: 100vh;
  overflow-x: hidden;
  font-feature-settings: "kern", "liga";
}

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

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

a {
  color: var(--brand-orange-deep);
  text-decoration: none;
}

button {
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}

/* ---------- Headings — apply named styles via classes, not default tags ---------- */
h1, h2, h3, h4, h5, h6 {
  font-family: inherit;
  font-weight: var(--weight-bold);
  letter-spacing: var(--track-snug);
  line-height: var(--leading-tight);
  text-wrap: balance;
}

p { text-wrap: pretty; }

/* ---------- Typography classes ---------- */
.text-hero-title {
  font-size: var(--text-display-xl);
  font-weight: var(--weight-extrabold);
  line-height: var(--leading-display);
  letter-spacing: var(--track-tight);
}

.text-page-title {
  font-size: var(--text-display-l);
  font-weight: var(--weight-extrabold);
  line-height: var(--leading-display);
  letter-spacing: var(--track-tight);
}

.text-section {
  font-size: var(--text-h2);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--track-snug);
}

.text-subsection,
.text-card-title {
  font-size: var(--text-h3);
  font-weight: var(--weight-bold);
  line-height: var(--leading-snug);
}

.text-h4 {
  font-size: var(--text-h4);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
}

.text-lead {
  font-size: var(--text-lead);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--ink-mid);
}

.text-body { font-size: var(--text-body); line-height: var(--leading-body); }
.text-small { font-size: var(--text-small); line-height: var(--leading-loose); color: var(--ink-mid); }
.text-caption {
  font-size: var(--text-small);
  line-height: var(--leading-loose);
  color: var(--ink-soft);
  font-style: italic;
}

.eyebrow {
  display: inline-block;
  font-size: var(--text-micro);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--track-eyebrow);
  line-height: var(--leading-flat);
  text-transform: uppercase;
  color: var(--brand-green-deep);
  margin-bottom: var(--space-3);
}

.eyebrow--light { color: var(--brand-orange); }

.text-quote {
  font-size: var(--text-display-m);
  font-weight: var(--weight-bold);
  line-height: 1.2;
  letter-spacing: var(--track-snug);
}

.text-source {
  font-size: 13px;
  line-height: var(--leading-relaxed);
  color: var(--ink-soft);
  font-style: italic;
}

.text-on-dark { color: var(--ink-on-dark); }
.text-on-dark-soft { color: var(--ink-on-dark-soft); }

/* Inline link inside prose */
.text-link {
  color: var(--brand-orange-deep);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
  transition: text-decoration-thickness var(--duration-default) var(--ease-out);
}
.text-link:hover { text-decoration-thickness: 2px; }

/* ---------- Containers ---------- */
.container {
  width: 100%;
  max-width: var(--container-content);
  margin-inline: auto;
  padding-inline: var(--grid-outer);
}

.container--narrow { max-width: var(--container-narrow); }
.container--wide { max-width: var(--container-wide); }

/* ---------- Section primitive ---------- */
.section {
  padding-block: var(--section-padding-y);
}

.section--lg { padding-block: var(--section-padding-y-lg); }
.section--xl { padding-block: var(--section-padding-y-xl); }

.section--cream { background: var(--surface-cream); color: var(--ink-primary); }
.section--sand { background: var(--surface-sand); color: var(--ink-primary); }
.section--forest { background: var(--surface-forest); color: var(--ink-on-dark); }
.section--forest-deep { background: var(--surface-forest-deep); color: var(--ink-on-dark); }

.section__header {
  max-width: 720px;
  margin-bottom: var(--space-8);
}

.section__header--centered {
  margin-inline: auto;
  text-align: center;
}

.section__header--split { max-width: none; }

.section__header .text-section { margin-bottom: var(--space-4); }
.section__header--split .text-section { margin-bottom: 0; }
.section__header .text-lead { margin-bottom: 0; }

/* ---------- Accessibility utilities ---------- */
.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;
}

.skip-link {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  transform: translateY(-200%);
  background: var(--surface-forest);
  color: var(--ink-on-dark);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  font-weight: var(--weight-semibold);
  z-index: var(--z-toast);
  transition: transform var(--duration-default) var(--ease-out);
}
.skip-link:focus {
  transform: translateY(0);
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- Focus default — never remove. Components may override with a more refined ring. ---------- */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- Reveal-on-scroll utility ----------
   Only applies when JS is available. Without JS, content is visible by default. */
.js .reveal {
  opacity: 0;
  transform: translateY(28px);
  transition:
    opacity 700ms var(--ease-out),
    transform 700ms var(--ease-out);
  will-change: opacity, transform;
}
.js .reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger siblings within grids — delays only apply while hidden */
.js .focus-grid .reveal:nth-child(2),
.js .stats-grid  .reveal:nth-child(2) { transition-delay: 100ms; }

.js .focus-grid .reveal:nth-child(3),
.js .stats-grid  .reveal:nth-child(3) { transition-delay: 200ms; }

.js .focus-grid .reveal:nth-child(4),
.js .stats-grid  .reveal:nth-child(4) { transition-delay: 300ms; }

@media (prefers-reduced-motion: reduce) {
  .js .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
  .js .focus-grid .reveal,
  .js .stats-grid  .reveal { transition-delay: 0ms; }
}

/* ---------- Selection ---------- */
::selection {
  background: var(--brand-orange-40);
  color: var(--ink-primary);
}
