/* 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). Iron-gall ink on unbleached paper, lacquer in the
       dark; cinnabar, the phoenix's colour, is the only accent (design-system §4–5). */
    --paper: light-dark(#F8F3E9, #17110D);
    --surface: light-dark(#FFFCF5, #211913);
    --sunken: light-dark(#EFE7D8, #100B08);
    --ink: light-dark(#1E1915, #E3DACB);
    --ink-2: light-dark(#463D36, #CEC1AF);
    --ink-3: light-dark(#685B50, #A99785);
    --rule: light-dark(#E2D8C7, #3A2E25);
    --rule-strong: light-dark(#8C7D6E, #7D6A5A);
    --link: light-dark(#8A2B14, #F2B07A);
    --link-hover: light-dark(#5E160D, #FFD2A6);
    --link-visited: light-dark(#6E4A3A, #D9AE9C);
    --on-link: light-dark(#FFFCF5, #17110D);
    --rubric: light-dark(#B3301B, #EE7A48);
    --kicker: light-dark(#9A3412, #EE7A48);
    --date: light-dark(#2C5F57, #8FBFB2); /* verdigris (ярь-медянка): years and big dates only */
    --ornament: var(--rubric);
    --link-underline: var(--rubric);
    --focus: light-dark(#A12A16, #EE7A48);
    --badge-bg: light-dark(#F5E1D0, #3B1D12);
    --badge-ink: light-dark(#7E2512, #F6C49C);
    --mark-bg: light-dark(#F8E2B4, #4A3216);
    --selection: light-dark(#F1CDB6, #5B2B1B);
    --error: light-dark(#8E1A4A, #FF9EC0);
    --note-bg: light-dark(#F7EAD0, #251B12);
    --footer-bg: light-dark(#1A130F, #0E0A07);
    --footer-ink: light-dark(#F4ECDF, #E3DACB);
    --footer-ink-2: light-dark(#BDAE9B, #A99785);
    --footer-link: #F2B07A;
    --footer-link-hover: #FFD2A6;
    --footer-accent: #EE7A48;
    --footer-rule: light-dark(#3A2C23, #2A201A);
    --footer-logo-body: #F3B47C;

    /* The phoenix: body, outline, dark-mode halo (the only glow) */
    --logo-body: light-dark(#5E160D, #F3B47C);
    --logo-outline: #2B140C;
    --logo-halo: light-dark(transparent, rgb(238 106 44 / .45));

    /* 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);
    /* Literata is a robust e-reader design: at text optical sizes its Regular is ~14 % darker
       than Georgia or PT Serif, so reading text sits just below 400 (§3.3). Inter clamps
       anything under 400 to its Regular, so UI text is unaffected. */
    --weight-body: 380;
    --weight-medium: 500;
    --weight-label: 600;
    --weight-bold: 600;
    --weight-headline: 580;
    --weight-display: 560;
    --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.12em;
    --tracking-caps-wide: 0.22em;
    --tracking-display: -0.01em;

    /* Layout (§6) */
    /* Measures in em, not ch: ch follows whichever font is loaded, so the fallback→web-font swap
       resized the reading column (and the lead picture in it). 38.35em = 66ch of Literata
       (zero 0.581 em); 37.85em = 60ch of Inter (zero 0.631 em), which captions use. */
    --measure: 38.35em;
    --measure-narrow: 37.85em;
    --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;
    --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; }

  /* Light text on a dark ground looks bolder (irradiation): the dark theme reads one step lighter. */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --weight-body: 360; }
  }
  :root[data-theme="dark"] { --weight-body: 360; }

  /* 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: #F8F3E9;
      --surface: #FFFCF5;
      --sunken: #EFE7D8;
      --ink: #1E1915;
      --ink-2: #463D36;
      --ink-3: #685B50;
      --rule: #E2D8C7;
      --rule-strong: #8C7D6E;
      --link: #8A2B14;
      --link-hover: #5E160D;
      --link-visited: #6E4A3A;
      --on-link: #FFFCF5;
      --rubric: #B3301B;
      --kicker: #9A3412;
      --date: #2C5F57;
      --focus: #A12A16;
      --badge-bg: #F5E1D0;
      --badge-ink: #7E2512;
      --mark-bg: #F8E2B4;
      --selection: #F1CDB6;
      --error: #8E1A4A;
      --note-bg: #F7EAD0;
      --footer-bg: #1A130F;
      --footer-ink: #F4ECDF;
      --footer-ink-2: #BDAE9B;
      --footer-rule: #3A2C23;
      --logo-body: #5E160D;
      --logo-halo: transparent;
    }
  }

  /* §5.3: more contrast: no halo, ink ornaments, stronger hairlines and meta */
  @media (prefers-contrast: more) {
    :root {
      --logo-halo: transparent;
      --ornament: var(--ink);
      --date: var(--ink);
      --link-underline: currentColor;
      --rule: var(--rule-strong);
      --ink-3: var(--ink-2);
    }
  }
}

/* Self-hosted variable fonts, subset by scripts/build_fonts.py (Latin + Cyrillic; Literata wght 350–700, Inter 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.0b76baeb9226.woff2") format("woff2");
  font-style: normal;
  font-weight: 350 700;
  font-display: swap;
}

@font-face {
  font-family: "Literata";
  src: url("../fonts/literata-italic.66309edfbfeb.woff2") format("woff2");
  font-style: italic;
  font-weight: 350 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.19%;
  ascent-override: 109.80%;
  descent-override: 28.73%;
  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: 96.36%;
  ascent-override: 122.14%;
  descent-override: 31.96%;
  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: 97.67%;
  ascent-override: 120.51%;
  descent-override: 31.53%;
  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: 88.47%;
  ascent-override: 133.03%;
  descent-override: 34.81%;
  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 */
