/* ==========================================================================
   SiteWright — Global: reset, base elements, typography, layout, utilities
   Depends on: design-system.css
   ========================================================================== */

/* ---------- 1. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + var(--space-6));
  color-scheme: dark;
  hanging-punctuation: first last;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  letter-spacing: var(--ls-body);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv11";
  overflow-x: clip;
}

img, picture, video, canvas, svg { display: block; max-width: 100%; }
img, video { height: auto; }
input, button, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul[role="list"], ol[role="list"] { list-style: none; }
p, h1, h2, h3, h4, h5, h6, li, figcaption, blockquote { overflow-wrap: break-word; }
h1, h2, h3, h4, h5, h6 { text-wrap: balance; }
p { text-wrap: pretty; }
table { border-collapse: collapse; }
fieldset { border: 0; min-width: 0; }
legend { padding: 0; }
[hidden] { display: none !important; }

::selection { background: var(--selection-bg); color: var(--selection-text); }

/* ---------- 2. Accessibility ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
}

.skip-link {
  position: fixed;
  top: var(--space-3);
  left: var(--space-3);
  z-index: var(--z-skip);
  padding: var(--space-3) var(--space-5);
  font-weight: var(--fw-medium);
  color: var(--on-accent);
  background: var(--accent);
  border-radius: var(--radius-pill);
  transform: translateY(-200%);
  transition: transform var(--dur-fast) var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(0); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 3. Typography ---------- */
.display-xl,
.display,
h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6 {
  font-family: var(--font-sans);
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
}

.display-xl { font-size: var(--fs-display-xl); line-height: var(--lh-tight); letter-spacing: var(--ls-display); }
.display    { font-size: var(--fs-display);    line-height: var(--lh-tight); letter-spacing: var(--ls-display); }
h1, .h1 { font-size: var(--fs-h1); line-height: var(--lh-heading); letter-spacing: var(--ls-h1); }
h2, .h2 { font-size: var(--fs-h2); line-height: var(--lh-heading); letter-spacing: var(--ls-h2); }
h3, .h3 { font-size: var(--fs-h3); line-height: var(--lh-snug); letter-spacing: var(--ls-h3); font-weight: var(--fw-medium); }
h4, .h4 { font-size: var(--fs-h4); line-height: var(--lh-snug); letter-spacing: var(--ls-h4); font-weight: var(--fw-medium); }
h5, .h5 { font-size: var(--fs-h5); line-height: var(--lh-snug); letter-spacing: var(--ls-h4); font-weight: var(--fw-medium); }
h6, .h6 { font-size: var(--fs-h6); line-height: var(--lh-snug); letter-spacing: var(--ls-ui);  font-weight: var(--fw-medium); }

.body-lg { font-size: var(--fs-body-lg); line-height: 1.55; }
.body    { font-size: var(--fs-body); }
.small   { font-size: var(--fs-small); line-height: 1.5; }

.text-secondary { color: var(--text-secondary); }
.text-muted     { color: var(--text-muted); }
.text-accent    { color: var(--accent-text); }

.mono,
.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  font-weight: var(--fw-medium);
  line-height: 1.4;
  letter-spacing: var(--ls-mono);
  text-transform: uppercase;
}
.eyebrow { color: var(--accent-text); display: inline-flex; align-items: center; gap: var(--space-2); }
.eyebrow::before {
  content: "";
  width: 6px; height: 6px;
  background: currentColor;
  border-radius: 1px;
}
.eyebrow--plain::before { display: none; }

.measure { max-width: var(--measure); }
.measure-narrow { max-width: var(--measure-narrow); }

/* Long-form content (blog articles, legal) */
.prose { max-width: var(--container-text); color: var(--text-secondary); }
.prose > * + * { margin-top: 1.25em; }
.prose h2 { margin-top: 2em; font-size: var(--fs-h3); }
.prose h3 { margin-top: 1.75em; font-size: var(--fs-h4); }
.prose h2, .prose h3, .prose strong { color: var(--text-primary); }
.prose a { color: var(--accent-text); text-decoration: underline; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
.prose ul, .prose ol { padding-left: 1.25em; }
.prose li + li { margin-top: 0.5em; }
.prose code { font-family: var(--font-mono); font-size: 0.9em; padding: 0.1em 0.35em; background: var(--surface); border-radius: var(--radius-xs); }
.prose blockquote { padding-left: var(--space-6); border-left: 2px solid var(--accent); color: var(--text-primary); font-size: var(--fs-h5); }

/* ---------- 4. Layout ---------- */
.container {
  width: 100%;
  max-width: calc(var(--container-max) + var(--gutter) * 2);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.container--wide { max-width: calc(var(--container-wide) + var(--gutter) * 2); }
.container--text { max-width: calc(var(--container-text) + var(--gutter) * 2); }
.container--full { max-width: none; }

.section { position: relative; padding-block: var(--section-space); }
.section--sm { padding-block: var(--section-space-sm); }
.section--flush-top { padding-top: 0; }
.section--flush-bottom { padding-bottom: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr));
  column-gap: var(--grid-gap);
  row-gap: var(--grid-gap);
}
/* Column spans (desktop). Collapsed in responsive.css */
.col-span-3  { grid-column: span 3; }
.col-span-4  { grid-column: span 4; }
.col-span-5  { grid-column: span 5; }
.col-span-6  { grid-column: span 6; }
.col-span-7  { grid-column: span 7; }
.col-span-8  { grid-column: span 8; }
.col-span-12 { grid-column: 1 / -1; }
.col-start-2 { grid-column-start: 2; }
.col-start-5 { grid-column-start: 5; }
.col-start-7 { grid-column-start: 7; }

.stack > * + * { margin-top: var(--stack-gap); }
.stack-sm > * + * { margin-top: var(--space-4); }
.stack-lg > * + * { margin-top: var(--space-16); }

.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.split { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-8); }

.hairline-top { border-top: var(--hairline); }
.hairline-bottom { border-bottom: var(--hairline); }

/* ---------- 5. Surfaces & texture ---------- */
.bg-secondary { background-color: var(--bg-secondary); }

/* Film grain — adds depth to large dark areas. Pure CSS/SVG, ~0.4KB. */
.grain { position: relative; isolation: isolate; }
.grain::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.035;
  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='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Signature glow — use max 3 times per page (hero, final CTA, footer) */
.flux { position: relative; isolation: isolate; }
.flux::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--flux-glow);
  -webkit-mask-image: var(--flux-mask);
  mask-image: var(--flux-mask);
}

/* Dark <-> light section transitions */
.fade-to-paper { height: clamp(3rem, 6vw, 6rem); background: var(--fade-to-paper); }
.fade-to-ink   { height: clamp(3rem, 6vw, 6rem); background: var(--fade-to-ink); }

/* ---------- 6. Media ---------- */
.media {
  position: relative;
  overflow: hidden;
  background-color: var(--surface);
  border-radius: var(--radius-md);
}
.media > img, .media > video, .media > picture > img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.ratio-16x9 { aspect-ratio: 16 / 9; }
.ratio-4x3  { aspect-ratio: 4 / 3; }
.ratio-3x2  { aspect-ratio: 3 / 2; }
.ratio-1x1  { aspect-ratio: 1 / 1; }
.ratio-4x5  { aspect-ratio: 4 / 5; }
.ratio-21x9 { aspect-ratio: 21 / 9; }

/* ---------- 7. Motion primitives (driven by js/animations.js) ----------
   Content is visible by default. Hidden states apply ONLY when JS has
   confirmed it is running (html.js) and the user allows motion. */
@media (prefers-reduced-motion: no-preference) {
  .js [data-reveal] {
    opacity: 0;
    transform: translate3d(0, var(--reveal-distance), 0);
    transition:
      opacity var(--dur-slow) var(--ease-out-soft),
      transform var(--dur-slow) var(--ease-out-soft);
    transition-delay: calc(var(--reveal-index, 0) * var(--stagger));
  }
  .js [data-reveal="fade"] { transform: none; }
  .js [data-reveal].is-visible { opacity: 1; transform: none; }

  /* Word-by-word headline reveal: words wrapped by JS in .word > .word__inner */
  .js [data-split] .word { display: inline-block; overflow: hidden; vertical-align: top; padding-bottom: 0.08em; margin-bottom: -0.08em; }
  .js [data-split] .word__inner {
    display: inline-block;
    transform: translate3d(0, 105%, 0);
    transition: transform var(--dur-slower) var(--ease-out);
    transition-delay: calc(var(--word-index, 0) * var(--stagger));
  }
  .js [data-split].is-visible .word__inner { transform: none; }

  /* Image reveal: the inner media is clipped (never the observed element itself,
     or IntersectionObserver sees a zero-area target and never fires) */
  .js [data-reveal="image"] { opacity: 1; transform: none; }
  .js [data-reveal="image"] > * {
    clip-path: inset(100% 0 0 0);
    transition: clip-path var(--dur-slower) var(--ease-out);
  }
  .js [data-reveal="image"] img { transform: scale(1.12); transition: transform 1400ms var(--ease-out); }
  .js [data-reveal="image"].is-visible > * { clip-path: inset(0 0 0 0); }
  .js [data-reveal="image"].is-visible img { transform: none; }
}

/* Native cross-document page transitions (progressive enhancement) */
@view-transition { navigation: auto; }
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root) { animation: vt-out var(--dur-base) var(--ease-in) both; }
  ::view-transition-new(root) { animation: vt-in var(--dur-slow) var(--ease-out) both; }
}
@keyframes vt-out { to { opacity: 0; transform: translateY(-12px); } }
@keyframes vt-in  { from { opacity: 0; transform: translateY(16px); } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* Two plain sections in a row: don't stack both paddings */
main > .section + .section:not(.flux):not(.cta-band) { padding-top: 0; }

/* WordPress screen-reader-only text (e.g. "Posts pagination") */
.screen-reader-text { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.pagination .nav-links { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: center; }
