/* 01-tokens.css — the design contract. Every value the design layer may
   change lives here; rules elsewhere reference tokens and never hardcode a
   colour, size or spacing value. Override the property, not the rule — if
   you're rewriting a selector in the design layer, a token is missing.
   Precedence: these neutral defaults < design layer < admin settings
   (partials/config.hbs). */

:root {
  /* Spacing — multiples of 0.25rem (--space-4 = 1rem). Use the scale; for
     in-between gazet values use calc() off it, e.g. calc(var(--space-1) * 3).
     CSS comments don't nest: never put comment syntax inside a comment block
     here — it ends the block early and the rest becomes live CSS. */
  --space-0: 0;
  --space-half: 0.125rem;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;

  /* Breakpoints — var() is INVALID in @media, so components repeat these as
     literals. Don't "fix" that; the query would silently never match. These
     properties exist for JS and as the source of truth. Mobile-first range
     syntax: @media (width >= 48rem).
       --bp-sm 30rem · --bp-md 48rem · --bp-lg 64rem · --bp-xl 80rem
     gazet's md/lg/xl match; its sm (40rem) has no equivalent here. */
  --bp-sm: 30rem;
  --bp-md: 48rem;
  --bp-lg: 64rem;
  --bp-xl: 80rem;

  /* Measure and containers. --measure is the body line length. */
  --measure: 660px;
  --container-content: 660px;
  --container-wide: 1200px;
  --container-site: 1400px;
  --gutter: var(--space-5);

  /* Colour — neutral placeholders. config.hbs overrides the first three from
     admin; tones are color-mixed from them so a change stays consistent. */
  --color-bg: #ffffff;
  --color-fg: #0c141c;
  --color-border: #0c141c;

  --color-bg-tone: color-mix(in srgb, var(--color-bg) 97%, var(--color-fg) 3%);
  --color-fg-tone: color-mix(in srgb, var(--color-fg) 80%, var(--color-bg) 20%);
  --color-border-soft: color-mix(in srgb, var(--color-border) 15%, var(--color-bg) 85%);

  /* The same gray as --color-border-soft over the page, but as 15% of
     currentColor, so it follows the text through light/dark and inversions.
     Keep the percentage in sync with --color-border-soft. */
  --color-border-soft-alpha: color-mix(in srgb, currentColor 15%, transparent);

  /* Swapped pair for inverted surfaces (open menu, banner bands, lightbox).
     Light mode only; dark mode re-points it (see DARK MODE). Aliased here
     because redeclaring bg/fg against each other in one scope is circular. */
  --color-bg-invert: var(--color-fg);
  --color-fg-invert: var(--color-bg);

  /* Pushed-back text (e.g. Secondary Navigation). Mixed into the background,
     not opacity, so focus rings and icons don't fade. The inverted panel
     swaps in the -invert variant. */
  --color-fg-muted: color-mix(in srgb, var(--color-fg) 60%, var(--color-bg) 40%);
  --color-fg-muted-invert: color-mix(in srgb, var(--color-fg-invert) 60%, var(--color-bg-invert) 40%);

  /* Hairline that survives every inversion: 10% of currentColor, mixed toward
     transparent so it composites correctly over the hero photo too. */
  --color-border-faint: color-mix(in srgb, currentColor 10%, transparent);

  /* Hover and focus steps of the same hairline (search row). Focus stops at
     50%, which still clears 3:1 as the field's only focus indicator. */
  --color-border-faint-hover: color-mix(in srgb, currentColor 30%, transparent);
  --color-border-faint-focus: color-mix(in srgb, currentColor 50%, transparent);

  /* Text a step back (search excerpts): 75% of currentColor. */
  --color-fg-soft: color-mix(in srgb, currentColor 75%, transparent);

  /* Lightest step back (Sign In beside Subscribe): 85% of currentColor. */
  --color-fg-subtle: color-mix(in srgb, currentColor 85%, transparent);

  /* Well back, for non-hovered nav links: 40% of currentColor. Compounds with
     --color-fg-muted. */
  --color-fg-dim: color-mix(in srgb, currentColor 40%, transparent);

  --color-accent: var(--ghost-accent-color, var(--color-fg));

  /* Text over the home editorial hero (its nav and caption). Set from admin
     (home_hero_text_color) for legibility against a specific photo. */
  --color-hero-text: var(--color-fg);

  /* Hero scrim colour (home_hero_gradient_color), independent of the text. */
  --color-hero-gradient: var(--color-fg);

  /* Post colour band (BAND below): the pair a banded post's top section and
     the masthead above it are drawn in. Dark by default; [data-band]
     re-points it. --color-band-custom-bg / -fg are deliberately not declared
     here: they arrive inline from a post's #custom-bg- / #custom-text- /
     #accent tags, and BAND's var() fallbacks cover whichever one is missing. */
  --color-band-bg: var(--color-bg-invert);
  --color-band-fg: var(--color-fg-invert);

  /* Focus ring: restyle, never remove. */
  --color-focus: var(--color-accent);
  --focus-width: 2px;
  --focus-offset: 2px;

  /* The one hue: editorial QA only (alt-audit.css). Hardcoded so it doesn't
     follow a brand recolour. */
  --color-danger: #d92d20;
  --color-danger-soft: color-mix(in srgb, var(--color-danger) 12%, var(--color-bg) 88%);

  /* Typography — neutral stacks; the design layer replaces them. Faces are
     declared in partials/fonts.hbs. The size steps match Tailwind v4, so gazet
     text-* classes map straight across. */
  --font-body: Georgia, "Times New Roman", serif;
  --font-heading: var(--font-body);
  --font-ui: system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;

  /* Second headline face (editorial voice). Neutral here. Switching
     --font-heading to it MUST switch --weight-heading too. */
  --font-heading-alt: var(--font-heading);
  --weight-heading-alt: var(--weight-heading);

  /* The wordmark face. Resolved on :root, so it keeps the default voice even
     inside editorial-voice scopes. */
  --font-brand: var(--font-heading);

  /* The default voice, pinned on :root so the News rule can restore it inside
     a serif scope (THE EDITORIAL VOICE in design/typography.css). */
  --font-heading-default: var(--font-heading);
  --weight-heading-default: var(--weight-heading);
  --tracking-tight-default: var(--tracking-tight);
  --tracking-snug-default: var(--tracking-snug);

  /* Every size step is multiplied by --text-scale, which TYPE SIZE (end of
     file) raises when a reader asks for larger type. A step written without
     the multiplier — here or in the design layer — won't follow the reader's
     choice. Only type scales; spacing and containers stay put. */
  --text-scale: 1;

  --text-xs: calc(0.75rem * var(--text-scale));
  --text-sm: calc(0.875rem * var(--text-scale));
  --text-base: calc(1rem * var(--text-scale));
  --text-lg: calc(1.125rem * var(--text-scale));
  --text-xl: calc(1.25rem * var(--text-scale));
  --text-2xl: calc(1.5rem * var(--text-scale));
  --text-3xl: calc(1.875rem * var(--text-scale));
  --text-4xl: calc(2.25rem * var(--text-scale));
  --text-5xl: calc(3rem * var(--text-scale));
  --text-6xl: calc(3.75rem * var(--text-scale));
  --text-7xl: calc(4.5rem * var(--text-scale));

  --leading-tight: 1.15;
  --leading-snug: 1.35;
  --leading-normal: 1.6;

  /* Article prose leading, tuned separately from card decks. */
  --leading-body: var(--leading-normal);

  /* Letter-spacing — `normal` until the design layer sets it (in em). */
  --tracking-tight: normal;
  --tracking-snug: normal;
  --tracking-slight: normal;
  --tracking-normal: normal;
  --tracking-wide: normal;

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --weight-heading: var(--weight-medium);

  /* Surface — zero decoration by default. */
  --radius: 0;
  --border-width: 1px;
  /* Link underline. Sub-pixel on purpose: a crisp hairline on 2x screens;
     1x screens round it up to 1px. */
  --link-underline-width: 0.75px;
  --shadow: none;
  --transition: 150ms ease;

  /* How far a card's text dims on hover (every card's HOVER rule). Opacity,
     not color-mix, so a card's mixed colours keep their hierarchy. */
  --card-hover-opacity: 0.65;

  /* Placeholder box for a missing card image. */
  --card-media-placeholder-bg: color-mix(in srgb, var(--color-fg) 6%, var(--color-bg));

  /* Ghost's yellow callout card. Light mode keeps Ghost's own tint; dark mode
     re-points it (see DARK MODE). */
  --callout-yellow-bg: #f0a50f21;

  /* Icons are em-sized; override --icon-size per component. */
  --icon-size: 1.25em;

  /* The "Read all →" arrow, painted as a mask (section-header.css). The value
     is assets/icons/arrow.svg, base64-encoded — edit that file and re-encode:
       base64 -i assets/icons/arrow.svg | tr -d '\n'
     --icon-arrow-size is its width (13 × 12 viewBox). */
  --icon-arrow: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTMiIGhlaWdodD0iMTIiIHZpZXdCb3g9IjAgMCAxMyAxMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTcuMzAxNzYgMC4wODc4OTA2TDEyLjk2MTkgNS43NDkwMkwxMi44NzQgNS44Mzc4OUw3LjMwMTc2IDExLjQxMDJMNy4yMTI4OSAxMS40OThMNi41ODg4NyAxMC44NzRMNi41IDEwLjc4NjFMMTEuMDMzMiA2LjI1MjkzSDBWNS4yNDUxMkgxMS4wMzIyTDYuNTg4ODcgMC44MDA3ODFMNi41IDAuNzEyODkxTDcuMjEyODkgMEw3LjMwMTc2IDAuMDg3ODkwNloiIGZpbGw9ImN1cnJlbnRDb2xvciIvPgo8L3N2Zz4K");
  --icon-arrow-size: 0.93em;

  /* Layering — never invent z-index numbers. */
  --z-base: 0;
  --z-sticky: 100;
  --z-header: 200;
  --z-menu: 300;
  --z-modal: 400;

  /* Ghost Portal's dialogs render in iframes no stylesheet here reaches;
     assets/js/portal-style.js copies these (and the font tokens) in. The
     backdrop stays dark in both palettes — it dims the page, not a surface. */
  --portal-backdrop: rgb(0 0 0 / 0.6);
  --portal-backdrop-blur: 2px;

  /* Stands in for the admin accent colour in Portal. Literal, not
     --color-fg, because the dialogs stay white in dark mode; keep in sync
     with the light palette's --color-fg. */
  --portal-ink: #0c141c;

  /* Editorial hero: fills the opening viewport exactly. */
  --editorial-hero-height: 100vh;

  /* Post with Hero Image: the same, under the masthead. */
  --post-hero-height: var(--editorial-hero-height);

  /* Story image crops, everywhere: 16 / 9 when the title sits under the
     image, 3 / 2 when it sits beside or over it. The one exception is the
     big lead image in featured-1-2-5, trending-features and news, which is
     3 / 2 even with the title under it. */
  --media-ratio-stacked: 16 / 9;
  --media-ratio-beside: 3 / 2;
  --media-ratio-lead: 3 / 2;

  /* Author pictures on a post (byline and author box). */
  --avatar-filter: none;

  /* Co-author byline avatars (post-info.css): how far each tucks under the
     one before it, and the ring that keeps overlapping pictures from running
     together. */
  --avatar-stack-overlap: var(--space-3);
  --avatar-ring-width: 2px;

  /* Membership page band and off-ladder sizes. Neutral here (a light grey
     band); the design layer sets the brand values. */
  --membership-hero-bg: var(--color-bg-tone);
  --membership-hero-fg: var(--color-fg);
  --membership-title-size: var(--text-4xl);
  --membership-price-size: var(--text-3xl);

  /* Membership CTA band — really set from admin via config.hbs. */
  --membership-cta-bg: var(--membership-hero-bg);

  /* CTA button text on hover. Pinned: --color-bg inside the band is the band. */
  --membership-cta-button-hover-fg: #ffffff;

  /* Paywall (components/paywall.css). The backdrop is darker than Portal's;
     its fade is slower than --transition, as a dim rather than a hover. */
  /* The page colour, so the sheet becomes part of the page once docked. */
  --paywall-bg: var(--color-bg);
  --paywall-backdrop: rgb(0 0 0 / 0.85);
  /* Behind the image: the engraving is black ink on transparent, so dark
     mode pins this light (see DARK MODE). */
  --paywall-media-bg: var(--paywall-bg);
  --paywall-transition: 400ms ease;

  /* Newsletter box headline size. Neutral here. */
  --newsletter-signup-title-size: var(--text-3xl);

  /* Author archive name — a step under the tag archive's h1. Neutral here. */
  --archive-author-title-size: var(--text-3xl);

  /* Post headline below --bp-md (wider, it's the h1's --text-4xl). Neutral here. */
  --post-title-mobile-size: var(--text-3xl);

  /* Homepage lead headlines below --bp-md. Neutral here. */
  --lead-title-mobile-size: var(--text-3xl);
}

/* Reduced motion, at the token level. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --transition: 0ms;
    --paywall-transition: 0ms;
  }
}

/* DARK MODE — override the three roots and everything derived follows. The
   exception is the invert pair: in dark mode inverted surfaces (open menu,
   banner bands, lightbox) stay on --color-bg, the same darkest ink as the
   page, with light text instead of flashing white. The yellow
   callout gets a stronger tint, since Ghost's 13% reads as olive over navy.
   Hero colours sit on a photo, so they're not overridden.
   The OS preference is the default (media query, no JS); [data-theme] on
   <html> is an explicit choice (theme-toggle.js). Both selectors include an
   attribute, so they out-rank config.hbs's bare :root — keep it that way,
   or admin colours would beat dark mode. */

/* Colours sampled from the reference footers: the light palette swapped.
   Not pure black/white, which crush hairlines and strain long reading. */

/* Explicit choice. */
:root[data-theme="dark"] {
  --color-bg: #0c141c;
  --color-fg: #f6f7f7;
  --color-border: #f6f7f7;
  --color-bg-invert: var(--color-bg);
  --color-fg-invert: var(--color-fg);
  --callout-yellow-bg: color-mix(in srgb, #f0a50f 24%, var(--color-bg));
  --paywall-media-bg: #f6f7f7;
}

/* OS default, when nothing is chosen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #0c141c;
    --color-fg: #f6f7f7;
    --color-border: #f6f7f7;
    --color-bg-invert: var(--color-bg);
    --color-fg-invert: var(--color-fg);
    --callout-yellow-bg: color-mix(in srgb, #f0a50f 24%, var(--color-bg));
    --paywall-media-bg: #f6f7f7;
  }
}

/* TYPE SIZE — the reader's larger-type choice (type-size.js, from the
   footer's Increase/Decrease Type Size button). [data-type-size] on <html>
   raises the multiplier every --text-* step is built on, so the whole scale
   grows in proportion. No attribute = the design's own sizes. The
   anti-flash script in default.hbs applies a stored choice before first
   paint. */
:root[data-type-size="large"] {
  --text-scale: 1.125;
}

/* BAND — a post's #custom-bg-<hex> / #custom-text-<hex> tags (post-band.hbs)
   re-point the band pair. [data-band] is on both <body> and .post, so the
   masthead and the post's top section agree. #dark needs no rule: it is the
   default. Without a bg tag the band stays dark. */
[data-band="custom"] {
  --color-band-bg: var(--color-band-custom-bg, var(--color-bg-invert));
  --color-band-fg: var(--color-band-custom-fg, var(--color-fg-invert));
}

/* Without a text tag, pick white or the light palette's ink by the band's
   lightness. --band-light is 1 on a dark band, 0 on a light one; l is the
   band's lightness once it lands inside oklch(from). 0.1874 0.0204 249 is
   #0c141c (light --color-fg, dark --color-bg) — keep them in sync. Guarded;
   without support the light text above stands. */
@supports (color: oklch(from red l c h)) {
  [data-band="custom"] {
    --band-light: clamp(0, (0.65 - l) * 1000, 1);
    --color-band-fg: var(--color-band-custom-fg, oklch(from var(--color-band-bg) calc(0.1874 + 0.8126 * var(--band-light)) calc(0.0204 * (1 - var(--band-light))) 249));
  }
}
