/* =============================================================================
   STORYCATION — GLOBAL BASE  (Static V2)
   Reset, document defaults, element typography, and accessibility primitives.
   Loaded after tokens.css, before components.css.
   Carried over from Astro V1 (global.css + typography.css + utilities.css).
   ========================================================================== */

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

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

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  /* Keeps the footer at the bottom on short pages. */
  display: flex;
  flex-direction: column;
  /* Full-bleed sections use 100vw, which includes the scrollbar width.
     `clip` contains the overflow without breaking position: sticky. */
  overflow-x: clip;
  background-color: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--type-body);
  line-height: var(--leading-relaxed);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body > main {
  flex: 1 0 auto;
}

h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd {
  margin: 0;
}

/* :where() keeps this reset at zero specificity, so a component class can
   set its own margin without fighting it. */
:where(ul, ol)[role="list"] {
  list-style: none;
  margin: 0;
  padding: 0;
}

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

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

button {
  cursor: pointer;
}

hr {
  border: 0;
  border-top: var(--border-hairline) solid var(--color-line);
  margin: var(--space-xl) 0;
}

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

/* ---------------------------------------------------------------------------
   ELEMENT TYPOGRAPHY
   --------------------------------------------------------------------------- */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--weight-regular);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-snug);
  text-wrap: balance;
  color: var(--color-ink);
}

h1 {
  font-size: var(--type-h1);
  line-height: var(--leading-tight);
}

h2 {
  font-size: var(--type-h2);
}

h3 {
  font-size: var(--type-h3);
  font-family: var(--font-body);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-normal);
}

h4 {
  font-size: var(--type-body);
  font-family: var(--font-body);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-normal);
}

p {
  text-wrap: pretty;
}

a {
  color: var(--color-ink);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: var(--color-line-strong);
  transition: text-decoration-color var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out);
}

a:hover {
  color: var(--color-accent);
  text-decoration-color: currentColor;
}

strong,
b {
  font-weight: var(--weight-semibold);
}

small {
  font-size: var(--type-small);
}

blockquote {
  font-family: var(--font-display);
  font-size: var(--type-body-lg);
  line-height: var(--leading-normal);
}

/* ---------------------------------------------------------------------------
   TYPE CLASSES — deliberately few.
   --------------------------------------------------------------------------- */

/* The largest editorial voice. Reserved for page-opening statements. */
.t-display-xl,
.t-display {
  font-family: var(--font-display);
  font-weight: var(--weight-regular);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}

.t-display-xl {
  font-size: var(--type-display-xl);
}

.t-display {
  font-size: var(--type-display);
}

/* Introductory paragraph beneath a heading. */
.t-lede {
  font-size: var(--type-body-lg);
  line-height: var(--leading-normal);
  color: var(--color-ink-muted);
  text-wrap: pretty;
}

/* Small uppercase label — eyebrows, statuses, metadata keys. */
.t-label {
  font-family: var(--font-body);
  font-size: var(--type-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  line-height: var(--leading-normal);
}

.t-meta {
  font-size: var(--type-small);
  color: var(--color-ink-muted);
  line-height: var(--leading-normal);
}

/* Long-form prose flow. Applied to a wrapper, not to every paragraph. */
.t-prose > * + * {
  margin-block-start: var(--space-md);
}

.t-prose h2 {
  margin-block-start: var(--space-xl);
}

.t-prose h3 {
  margin-block-start: var(--space-lg);
}

/* ---------------------------------------------------------------------------
   FOCUS — visible, high-contrast, never removed.
   --------------------------------------------------------------------------- */

:focus-visible {
  outline: var(--border-medium) solid var(--color-focus);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* <main> is a skip-link target, not a control: no ring when it takes focus. */
main:focus {
  outline: none;
}

/* ---------------------------------------------------------------------------
   TOUCH TARGETS — parents meet Storycation on a phone.
   --------------------------------------------------------------------------- */

a,
button,
[role="button"],
summary {
  touch-action: manipulation;
}

@media (pointer: coarse) {
  nav a,
  button,
  [role="button"] {
    min-height: 44px;
  }
  nav a {
    display: inline-flex;
    align-items: center;
  }
}

/* ---------------------------------------------------------------------------
   LAYOUT PRIMITIVES — containers, rhythm, stack, cluster, grid.
   Not a utility framework. Colour and type decisions belong in components.
   --------------------------------------------------------------------------- */

.u-container {
  width: 100%;
  max-width: var(--width-wide);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.u-container--reading {
  max-width: calc(var(--width-reading) + var(--gutter) * 2);
}

.u-container--full {
  max-width: var(--width-full);
}

/* Escapes the container to the viewport edge for full-bleed imagery. */
.u-bleed {
  width: 100vw;
  margin-inline: calc(50% - 50vw);
}

.u-stack > * + * {
  margin-block-start: var(--stack-space, var(--space-md));
}

.u-stack--tight {
  --stack-space: var(--space-2xs);
}

.u-stack--loose {
  --stack-space: var(--space-lg);
}

/* Horizontal group that wraps gracefully — CTA rows, tag lists, metadata. */
.u-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cluster-space, var(--space-sm));
  align-items: center;
}

/* Responsive grid that reflows without breakpoint declarations. */
.u-grid {
  display: grid;
  gap: var(--grid-space, var(--space-lg));
  grid-template-columns: repeat(
    auto-fill,
    minmax(min(var(--grid-min, 18rem), 100%), 1fr)
  );
}

.u-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------------------
   MOTION — one scroll-linked reveal, used sparingly.
   Animates TRANSFORM ONLY, never opacity: V1 testing found opacity reveals
   could leave copy stuck invisible when a page was jumped rather than
   scrolled. The worst case here is an element resting 1rem low, still legible.
   --------------------------------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .u-reveal {
      animation: u-reveal-in linear both;
      animation-timeline: view();
      animation-range: entry 5% entry 60%;
    }
  }
}

@keyframes u-reveal-in {
  from {
    transform: translateY(1rem);
  }
  to {
    transform: none;
  }
}
