/* Rufabula design tokens: docs/design-system.md §3.3 (type), §4.1 (colour), §6 (layout).
   Light and dark values sit side by side in light-dark(); the theme follows the system
   (color-scheme: light dark) unless <html data-theme="light|dark"> is set by theme-init.js.
   Every text pair is contrast-checked by tests/design/test_design_tokens.py. */

@layer reset, tokens, base, layout, components, blocks, utilities, overrides;

@layer tokens {
  :root {
    color-scheme: light dark;

    /* Colour: light-dark(light, dark) */
    --paper: light-dark(#FBFAF7, #0B0E14);
    --surface: light-dark(#FFFFFF, #121722);
    --sunken: light-dark(#F2F1EC, #07090D);
    --ink: light-dark(#16181D, #E8EBF1);
    --ink-2: light-dark(#3D434D, #C2C8D3);
    --ink-3: light-dark(#5B6270, #9BA4B3);
    --rule: light-dark(#E2DFD8, #232B38);
    --rule-strong: light-dark(#8A8F99, #5E6878);
    --link: light-dark(#0051CC, #7DB3FF);
    --link-hover: light-dark(#003D99, #A9CDFF);
    --link-visited: light-dark(#5B3FB0, #C3A9FF);
    --on-link: light-dark(#FFFFFF, #0B0E14);
    --brand: #3A88FE;
    --brand-deep: #0065FF;
    --neon: light-dark(#3A88FE, #4D94FE);
    --neon-cyan: light-dark(#08769C, #4FD8FF);
    --focus: light-dark(#0065FF, #7DB3FF);
    --glow: light-dark(rgb(58 136 254 / .28), rgb(58 136 254 / .55));
    --glow-far: light-dark(rgb(0 101 255 / .12), rgb(0 101 255 / .35));
    --badge-bg: light-dark(#E8F1FF, #0F2547);
    --badge-ink: light-dark(#0047B3, #A9CDFF);
    --mark-bg: light-dark(#DCEBFF, #1C3A66);
    --selection: light-dark(#CFE2FF, #23467A);
    --error: light-dark(#B42318, #FF8A80);
    /* Editors' note (home masthead): warm paper with a cinnabar rule, like the phoenix */
    --note-bg: light-dark(#FFF5D6, #1F1A10);
    --note-rule: light-dark(#C2410C, #F3B47C);
    --note-kicker: light-dark(#9A3412, #F3B47C);
    --footer-bg: light-dark(#0B0E14, #07090D);
    --footer-ink: light-dark(#FBFAF7, #E8EBF1);
    --footer-ink-2: light-dark(#AEB5C1, #9BA4B3);
    --footer-link: #7DB3FF;
    --footer-link-hover: #A9CDFF;
    --footer-rule: light-dark(#232B38, #1A212C);

    /* Brand decoration (never behind text): the phoenix's body, outline and dark-mode halo, and "blue fire" */
    --logo-body: light-dark(#5E160D, #F3B47C);
    --logo-outline: #2B140C;
    --logo-halo: light-dark(transparent, rgb(238 106 44 / .45));
    --fire: light-dark(transparent, rgb(0 101 255 / .30));
    --fire-far: light-dark(transparent, rgb(58 136 254 / .12));
    --numeral-glow: light-dark(transparent, rgb(79 216 255 / .45)); /* «most read» numerals */

    /* Type (§3.3) */
    --font-serif: "Literata", "Literata Fallback", Georgia, "PT Serif", "Times New Roman", serif;
    --font-sans: "Inter", "Inter Fallback", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --step--2: 0.78125rem;
    --step--1: 0.875rem;
    --step-0: clamp(1.0625rem, 0.99rem + 0.36vw, 1.1875rem);
    --step-1: clamp(1.25rem, 1.13rem + 0.6vw, 1.5rem);
    --step-2: clamp(1.5rem, 1.3rem + 1vw, 2rem);
    --step-3: clamp(1.875rem, 1.5rem + 1.9vw, 2.75rem);
    --step-4: clamp(2rem, 1.4rem + 3vw, 3.75rem);
    --step-5: clamp(2.25rem, 1.5rem + 4vw, 5rem);
    --weight-body: 400;
    --weight-medium: 500;
    --weight-label: 600;
    --weight-bold: 650;
    --weight-headline: 640;
    --weight-display: 600;
    --leading-body: 1.62;
    --leading-lead: 1.45;
    --leading-h1: 1.08;
    --leading-h2: 1.15;
    --leading-h3: 1.25;
    --leading-ui: 1.4;
    --tracking-kicker: 0.08em;
    --tracking-display: -0.01em;

    /* Layout (§6) */
    --measure: 66ch;
    --measure-narrow: 60ch;
    --container: 80rem;
    --gutter: clamp(1rem, 4vw, 2.5rem);
    --column-gap: clamp(1rem, 2.5vw, 2rem);
    --space-3xs: 0.25rem;
    --space-2xs: 0.5rem;
    --space-xs: 0.75rem;
    --space-s: 1rem;
    --space-m: 1.5rem;
    --space-l: 2rem;
    --space-xl: clamp(2.5rem, 2rem + 2vw, 3.5rem);
    --space-2xl: clamp(3.5rem, 2.5rem + 4vw, 5.5rem);
    --space-3xl: clamp(4.5rem, 3rem + 6vw, 8rem);
    --radius: 2px;
    --radius-pill: 999px;
    --target: 2.75rem;
    --z-header: 10;
    --z-menu: 20;
    --z-skip: 100;

    /* Motion (§5.3) */
    --ease: cubic-bezier(.2, .7, .2, 1);
    --duration: 160ms;
  }

  :root[data-theme="light"] { color-scheme: light; }
  :root[data-theme="dark"] { color-scheme: dark; }

  /* Browsers without light-dark() (Safari < 17.5) get the light theme. */
  @supports not (color: light-dark(#000, #fff)) {
    :root,
    :root[data-theme] { color-scheme: light; }
    :root {
      --paper: #FBFAF7;
      --surface: #FFFFFF;
      --sunken: #F2F1EC;
      --ink: #16181D;
      --ink-2: #3D434D;
      --ink-3: #5B6270;
      --rule: #E2DFD8;
      --rule-strong: #8A8F99;
      --link: #0051CC;
      --link-hover: #003D99;
      --link-visited: #5B3FB0;
      --on-link: #FFFFFF;
      --neon: #3A88FE;
      --neon-cyan: #08769C;
      --focus: #0065FF;
      --glow: rgb(58 136 254 / .28);
      --glow-far: rgb(0 101 255 / .12);
      --badge-bg: #E8F1FF;
      --badge-ink: #0047B3;
      --mark-bg: #DCEBFF;
      --selection: #CFE2FF;
      --error: #B42318;
      --note-bg: #FFF5D6;
      --note-rule: #C2410C;
      --note-kicker: #9A3412;
      --footer-bg: #0B0E14;
      --footer-ink: #FBFAF7;
      --footer-ink-2: #AEB5C1;
      --footer-rule: #232B38;
      --logo-body: #5E160D;
      --logo-halo: transparent;
      --fire: transparent;
      --fire-far: transparent;
      --numeral-glow: transparent;
    }
  }

  /* §5.3: more contrast removes every glow and strengthens hairlines and meta text. */
  @media (prefers-contrast: more) {
    :root {
      --glow: transparent;
      --glow-far: transparent;
      --logo-halo: transparent;
      --fire: transparent;
      --fire-far: transparent;
      --numeral-glow: transparent;
      --rule: var(--rule-strong);
      --ink-3: var(--ink-2);
    }
  }
}

/* Self-hosted variable fonts, subset by scripts/build_fonts.py (Latin + Cyrillic, wght 400–700).
   base.html preloads the two roman files; the italic loads when first used. */
@font-face {
  font-family: "Literata";
  src: url("../fonts/literata-roman.8f4cea8ece77.woff2") format("woff2");
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: "Literata";
  src: url("../fonts/literata-italic.232b1ae0335d.woff2") format("woff2");
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-roman.4fe886ff7240.woff2") format("woff2");
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
}

/* Metric-matched local fallbacks keep the font swap free of layout shift (§3.2). */
/* fallback-metrics:start (generated by scripts/build_fonts.py, do not edit) */
@font-face {
  font-family: "Literata Fallback";
  src: local("Georgia");
  font-style: normal;
  font-weight: 100 549;
  size-adjust: 107.88%;
  ascent-override: 109.11%;
  descent-override: 28.55%;
  line-gap-override: 0.00%;
}
@font-face {
  font-family: "Literata Fallback";
  src: local("Georgia Bold"), local("Georgia-Bold");
  font-style: normal;
  font-weight: 550 900;
  size-adjust: 97.43%;
  ascent-override: 120.80%;
  descent-override: 31.61%;
  line-gap-override: 0.00%;
}
@font-face {
  font-family: "Literata Fallback";
  src: local("Georgia Italic"), local("Georgia-Italic");
  font-style: italic;
  font-weight: 100 549;
  size-adjust: 98.03%;
  ascent-override: 120.06%;
  descent-override: 31.42%;
  line-gap-override: 0.00%;
}
@font-face {
  font-family: "Literata Fallback";
  src: local("Georgia Bold Italic"), local("Georgia-BoldItalic");
  font-style: italic;
  font-weight: 550 900;
  size-adjust: 89.87%;
  ascent-override: 130.97%;
  descent-override: 34.27%;
  line-gap-override: 0.00%;
}
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial"), local("ArialMT");
  font-style: normal;
  font-weight: 100 549;
  size-adjust: 106.18%;
  ascent-override: 91.24%;
  descent-override: 22.72%;
  line-gap-override: 0.00%;
}
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial Bold"), local("Arial-BoldMT");
  font-style: normal;
  font-weight: 550 900;
  size-adjust: 100.88%;
  ascent-override: 96.03%;
  descent-override: 23.91%;
  line-gap-override: 0.00%;
}
/* fallback-metrics:end */
