/*
 * Warm neutral scale (round 5, docs/design-backport.md "Warm text colours"). Not (yet) in the Figma tokens: derived from the
 * sand hue (OKLCH hue 70-80, chroma 0.005-0.015), so near-black and dark greys carry a barely visible brownish tint instead of
 * the greenish olive-950. Text roles below point at it; olive stays for brand accents (focus ring, hard hover shadow of buttons,
 * selected chip, dark section, status badge, map pin).
 */
:root {
  --color-warm-gray-50: #f9f6f3;
  --color-warm-gray-100: #f1eee9;
  --color-warm-gray-200: #e5e0db;
  --color-warm-gray-300: #d2cdc6;
  --color-warm-gray-400: #b9b3ac;
  --color-warm-gray-500: #9d9790;
  --color-warm-gray-600: #7f7971;
  --color-warm-gray-700: #655f58;
  --color-warm-gray-800: #4c473f;
  --color-warm-gray-900: #312d27;
  --color-warm-gray-950: #1b1813;
  --color-text-default: var(--color-warm-gray-950); /* Body text, headings, nav. 17.7:1 on white, 12.4:1 on sand/300 */
  --color-text-subtle: var(--color-warm-gray-800); /* Secondary text, meta, breadcrumb. 9.2:1 on white, 6.5:1 on sand/300 */
  --color-text-link: var(--color-warm-gray-900); /* Links, eyebrows, date lines. 13.7:1 on white; links keep the underline */
  --color-action-primary-text: var(--color-warm-gray-950); /* Primary button label on yellow */
}

/*
 * One z-index scale (round 7, docs/design-backport.md "Stacking scale"). Every positioned layer takes its value from here,
 * no raw numbers elsewhere. Order: local layering inside a component < sticky group headings < header < fixed bars <
 * popovers and dropdowns < bottom sheet < dialogs < skip link.
 * Native <dialog> elements opened with showModal() (lightbox, bottom sheet, map dialog) live in the browser's top layer and
 * need no z-index; --z-sheet and --z-dialog stay reserved for non-top-layer fallbacks.
 */
:root {
  --z-below: -1; /* decorative bands behind their parent (wave bands, straddle) */
  --z-base: 0;
  --z-content: 1; /* local layering inside a component (overlay above image, link above stretched link) */
  --z-content-raised: 2;
  --z-sticky: 10; /* sticky group headings */
  --z-header: 100; /* site header with its dropdowns and the mobile menu (own stacking context) */
  --z-bar: 150; /* fixed bars (sticky registration bar) */
  --z-popover: 200; /* filter popovers, dropdown panels */
  --z-sheet: 300; /* bottom sheet */
  --z-dialog: 400; /* dialogs, lightbox */
  --z-skip: 1000; /* skip link: always on top */
}

/*
 * One style for every intro/subline under a page title (round 7 §10): hero subline, page head intro, system pages (404,
 * newsletter status). Currently text/body (18/28), the step the hero subline got in the typography review (§23); change it here only.
 */
:root {
  --text-intro-size: var(--type-text-body-size);
  --text-intro-line-height: var(--type-text-body-line-height);
}

/* Semantic alias not (yet) in the Figma tokens: the stronger beige of header and page heads (see docs/design-backport.md). */
:root {
  --color-background-strong: var(--color-sand-300);
  /*
   * Hover of linked media moves like the button hover (buttons: 4 px shadow, translate -2 px): the shadow grows down-right,
   * the element moves up-left by half the offset, so the object stays visually balanced. One warm brown (sand-600, #b09a7e; no clash with green photos) for photos, placeholders, tiles and boxes; the buttons keep olive-950.
   * Non-production comparison: ?hover-shadow=darker uses sand-700 (see HoverShadow.php).
   * Reduced motion keeps the shadow and drops the movement (see below).
   */
  --color-shadow-media: var(--color-sand-600);
  --shadow-hover-media: 8px 8px 0 var(--color-shadow-media);
  --transform-hover-media: translate(-4px, -4px);
  /*
   * One motion for every static hover (media, cards, buttons): quick start, soft deceleration and a barely visible settle
   * (the curve overshoots by about 3 %, i.e. 0.1 px on a 4 px shift). "Out" sits on the base rule, "in" on :hover / :focus-visible,
   * both on box-shadow and transform together. --transition-hover-media is the out list, --transition-hover-media-in the in list.
   */
  --ease-hover: cubic-bezier(.2, .9, .25, 1.08);
  --duration-hover-in: 280ms;
  --duration-hover-out: 220ms;
  --transition-hover-media: box-shadow var(--duration-hover-out) var(--ease-hover), transform var(--duration-hover-out) var(--ease-hover);
  --transition-hover-media-in: box-shadow var(--duration-hover-in) var(--ease-hover), transform var(--duration-hover-in) var(--ease-hover);
  /* Cream navbar strip of header variant B; nearest token to the live site's #f9f7f1. */
  --color-background-nav: var(--color-sand-50);
  /* Main navigation: hover pill and dropdown entries share one tint; the current page indicator is the text colour. */
  --color-nav-hover: var(--color-sand-200);
  --color-nav-indicator: var(--color-text-default);
  /*
   * Bubble radii scale with the size of the element (s < 160 px, m 160-399, l 400-799, xl >= 800 / heroes). Small
   * images stay close to the design values (s 12, m 24), large ones get clearly rounder corners. They override the values of
   * the exported tokens.css (design/Tokens), see docs/design-backport.md "Typography review (§23)".
   * The corner opposite the tip (component/bubble/radius/opposite-*) is about half of the two other round corners (live
   * site: 12 against 24), always bigger than the tip (4).
   */
  --component-bubble-radius-s: 12px;
  --component-bubble-radius-m: 24px;
  --component-bubble-radius-l: 32px;
  --component-bubble-radius-xl: 40px;
  --component-bubble-radius-opposite-s: 8px;
  --component-bubble-radius-opposite-m: 12px;
  --component-bubble-radius-opposite-l: 16px;
  --component-bubble-radius-opposite-xl: 24px;
}

/*
 * Tablet mode, 768-1023 px (docs/layout-widths.md, docs/design-backport.md "Tablet layout"). Phones keep the 12 px margins
 * and 366 px containers up to 767 px; from 768 px the containers take the desktop maximum widths and the viewport decides:
 * width = min(100% - 2 x margin, max). Margin 32 px from 768, 40 px from 900. Bounded to < 1024 px because tokens.css
 * (exported) holds the desktop values from 1024 px and loads before this file.
 */
@media (min-width: 768px) and (max-width: 1023.98px) {
  :root {
    --layout-margin: 32px;
    --layout-container-full: 1248px;
    --layout-container-wide: 1036px;
    --layout-container-medium: 824px;
    --layout-container-text: 720px;
    --layout-grid-gap: 24px;
    --layout-section-spacing-s: 48px;
    --layout-section-spacing-m: 72px;
    --layout-section-spacing-l: 96px;
    --layout-wave-height: 28px;
    --layout-stack-m: 28px;
    --layout-stack-l: 40px;
    --component-card-padding: 28px;
  }
}

@media (min-width: 900px) and (max-width: 1023.98px) {
  :root {
    --layout-margin: 40px;
  }
}

@media (min-width: 1024px) {
  :root {
    --component-bubble-radius-m: 28px;
    --component-bubble-radius-l: 40px;
    --component-bubble-radius-xl: 64px;
    --component-bubble-radius-opposite-m: 16px;
    --component-bubble-radius-opposite-l: 20px;
    --component-bubble-radius-opposite-xl: 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --transform-hover-media: none;
    --transition-hover-media: none;
    --transition-hover-media-in: none;
  }
}

/* Header variant B: slightly taller bar than A (logo 48 / 64 px) so the logo has air. The mobile menu panel measures from this value. */
[data-header="b"] {
  --layout-header-height: 72px;
}

@media (min-width: 1024px) {
  [data-header="b"] {
    --layout-header-height: 96px;
  }
}

/*
 * Page-head rhythm (see docs/design-backport.md, "Page head spacing (round 3)").
 * --page-head-space is the visible beige above the first line and below the last line. The header wave (variant B)
 * reaches into the head and the head's own wave reaches into the next section, each by about half the wave height,
 * so the paddings are corrected by half a wave: top + overlap / 2, bottom - wave / 2.
 */
:root {
  --page-head-space: var(--space-40);
  --page-head-nav-overlap: 0px;
  --page-head-pad-top: calc(var(--page-head-space) + var(--page-head-nav-overlap) / 2);
  --page-head-pad-bottom: calc(var(--page-head-space) - var(--layout-wave-height) / 2);
  /* Inside the head: breadcrumb → eyebrow/title, eyebrow → title, title → intro, intro → chips. */
  --page-head-gap-meta: var(--space-16);
  --page-head-gap-eyebrow: var(--space-8);
  --page-head-gap-intro: var(--space-8);
  --page-head-gap-extra: var(--space-24);
  /* Text → image that belongs to the head (straddling image, or a same-tone first section with an image). */
  --page-head-gap-media: var(--space-32);
  /* Aside image next to (desktop) or above (mobile) the text. */
  --page-head-gap-aside: var(--space-24);
  /* Top padding of the first section after the head: small section spacing plus the wave that overlaps it. */
  --page-head-next-pad: calc(var(--layout-section-spacing-s) + var(--layout-wave-height));
}

[data-header="b"] {
  --page-head-nav-overlap: var(--layout-wave-height);
}

@media (min-width: 1024px) {
  :root {
    --page-head-space: var(--space-64);
    --page-head-gap-meta: var(--space-24);
    --page-head-gap-intro: var(--space-12);
    --page-head-gap-extra: var(--space-32);
    --page-head-gap-media: var(--space-48);
    --page-head-gap-aside: var(--layout-grid-gap);
  }
}

/* Containers, stacks, prose, bubble shape and shared utilities. */
@layer layout {
  /* Container widths per tokens.md; a section picks one, the page head matches the content below it. */
  .container {
    width: min(100% - 2 * var(--layout-margin), var(--layout-container-wide));
    margin-inline: auto;
  }

  .container--full {
    width: min(100% - 2 * var(--layout-margin), var(--layout-container-full));
  }

  .container--wide {
    width: min(100% - 2 * var(--layout-margin), var(--layout-container-wide));
  }

  .container--medium {
    width: min(100% - 2 * var(--layout-margin), var(--layout-container-medium));
  }

  .container--text {
    width: min(100% - 2 * var(--layout-margin), var(--layout-container-text));
  }

  /* Vertical rhythm: gap between children (s 16, m 24/32, l 32/48). */
  .stack {
    display: flex;
    flex-direction: column;
    gap: var(--layout-stack-m);
  }

  .stack--s {
    gap: var(--layout-stack-s);
  }

  .stack--l {
    gap: var(--layout-stack-l);
  }

  /* Running text (tokens.md): margin-block-start only, no bottom margins. */
  .prose > * + * {
    margin-block-start: var(--layout-prose-paragraph);
  }

  .prose > * + h2 {
    margin-block-start: var(--layout-prose-heading-l-before);
  }

  .prose > h2 + * {
    margin-block-start: var(--layout-prose-heading-l-after);
  }

  .prose > * + h3 {
    margin-block-start: var(--layout-prose-heading-m-before);
  }

  .prose > h3 + * {
    margin-block-start: var(--layout-prose-heading-m-after);
  }

  .prose > * + h4 {
    margin-block-start: var(--layout-prose-heading-s-before);
  }

  .prose > h4 + * {
    margin-block-start: var(--layout-prose-heading-s-after);
  }

  .prose ul,
  .prose ol {
    padding-inline-start: var(--space-24);
  }

  .prose li + li {
    margin-block-start: var(--space-8);
  }

  .prose > :first-child {
    margin-block-start: 0;
  }
}

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

  .text-subtle {
    color: var(--color-text-subtle);
  }

  /*
   * Speech-bubble shape (components.md): three round corners, one at 4 px (tip, always at the bottom), and the corner
   * opposite the tip smaller than the two others (--component-bubble-radius-opposite-*).
   * Size class by element size (short side): s < 160 px, m 160–399 px, l 400–799 px, xl >= 800 px (heroes).
   * Default tip is bottom-left (opposite: top-right); bubble--tip-right flips it, bubble--tip-none rounds all corners.
   * Corner variables: --bubble-tl / -tr / -br / -bl; the modifiers set all four, components override --bubble-radius,
   * --bubble-opposite and the corners they need.
   */
  .bubble {
    --bubble-radius: var(--component-bubble-radius-m);
    --bubble-opposite: var(--component-bubble-radius-opposite-m);
    --bubble-tip-bl: var(--component-bubble-radius-tip);
    --bubble-tip-br: var(--bubble-radius);
    --bubble-tl: var(--bubble-radius);
    --bubble-tr: var(--bubble-opposite);
    border-radius: var(--bubble-tl) var(--bubble-tr) var(--bubble-tip-br) var(--bubble-tip-bl);
  }

  .bubble--s {
    --bubble-radius: var(--component-bubble-radius-s);
    --bubble-opposite: var(--component-bubble-radius-opposite-s);
  }

  .bubble--m {
    --bubble-radius: var(--component-bubble-radius-m);
    --bubble-opposite: var(--component-bubble-radius-opposite-m);
  }

  .bubble--l {
    --bubble-radius: var(--component-bubble-radius-l);
    --bubble-opposite: var(--component-bubble-radius-opposite-l);
  }

  .bubble--xl {
    --bubble-radius: var(--component-bubble-radius-xl);
    --bubble-opposite: var(--component-bubble-radius-opposite-xl);
  }

  .bubble--tip-left {
    --bubble-tip-bl: var(--component-bubble-radius-tip);
    --bubble-tip-br: var(--bubble-radius);
    --bubble-tl: var(--bubble-radius);
    --bubble-tr: var(--bubble-opposite);
  }

  .bubble--tip-right {
    --bubble-tip-bl: var(--bubble-radius);
    --bubble-tip-br: var(--component-bubble-radius-tip);
    --bubble-tl: var(--bubble-opposite);
    --bubble-tr: var(--bubble-radius);
  }

  .bubble--tip-none {
    --bubble-tip-bl: var(--bubble-radius);
    --bubble-tip-br: var(--bubble-radius);
    --bubble-tl: var(--bubble-radius);
    --bubble-tr: var(--bubble-radius);
  }

  /* Hard offset hover shadow for linked images and cards (no blur, hover and keyboard focus only). */
  .hover-media {
    transition: var(--transition-hover-media);
  }

  .hover-media:hover,
  .hover-media:focus-visible,
  .hover-media:focus-within {
    transition: var(--transition-hover-media-in);
    box-shadow: var(--shadow-hover-media);
    transform: var(--transform-hover-media);
  }
}
