/* r4_tokens_v1.css
   {{BRAND}} design tokens. Recommended palette: A Warm Paper.
   Light is the default. Dark follows prefers-color-scheme, with a
   manual override via data-theme="light" or data-theme="dark" on <html>.
   No external font is loaded by this file. Font files are self-hosted
   in R6. See r4_design_system_v1.md for the font plan and budget.
   Version: v1. Date: 26 November 2026. Status: PROVISIONAL APPROVAL.
*/

:root {
  color-scheme: light dark;

  /* Colour roles, light theme (default) */
  --color-canvas: #fbf7ef;
  --color-surface: #ffffff;
  --color-raised: #f3ede0;
  --color-text: #1c1a17;
  --color-muted: #534c47;
  --color-border: #d8cfc0;
  --color-border-strong: #756e66;
  --color-primary: #0a5947;
  --color-primary-ink: #ffffff;
  --color-primary-hover: #07402f;
  --color-accent: #8a2f10;
  --color-accent-ink: #ffffff;
  --color-link: #0a5947;
  --color-link-visited: #5b3a8e;
  --color-success: #166534;
  --color-success-surface: #dcfce7;
  --color-warning: #92400e;
  --color-warning-surface: #fef3c7;
  --color-error: #991b1b;
  --color-error-surface: #fee2e2;
  --color-focus: #1d4ed8;
  --color-answer: #e7f0eb;
  --color-answer-border: #0a5947;
  --color-summary: #fdeedd;
  --color-summary-border: #8a2f10;
  --color-chip: #f3ede0;
  --color-chip-text: #1c1a17;
  --color-ad-label: #534c47;
  --color-on-primary: #ffffff;
  --color-on-accent: #ffffff;

  /* Type */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Fraunces", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --font-size-body: 1.125rem;
  --font-size-body-mobile: 1.0625rem;
  --line-height-body: 1.65;
  --line-height-heading: 1.15;
  --line-height-heading-small: 1.25;
  --letter-spacing-heading: -0.018em;
  --measure-reading: 68ch;
  --measure-reading-max: 75ch;
  --measure-wide: 60rem;
  --measure-shell: 75rem;

  /* Modular type scale, base 18px, ratio 1.25 */
  --step--2: 0.64rem;
  --step--1: 0.8rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.563rem;
  --step-3: 1.953rem;
  --step-4: 2.441rem;
  --step-5: 3.052rem;
  --text-h1: var(--step-5);
  --text-h1-mobile: var(--step-4);
  --text-h2: var(--step-3);
  --text-h2-mobile: var(--step-2);
  --text-h3: var(--step-2);
  --text-h3-mobile: var(--step-1);
  --text-h4: var(--step-1);
  --text-small: var(--step--1);
  --text-caption: var(--step--1);

  /* Spacing, 4px base */
  --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-24: 6rem;
  --space-section: clamp(2rem, 5vw, 3.5rem);
  --space-gutter-mobile: 1rem;
  --space-gutter-tablet: 1.5rem;
  --space-gutter-desktop: 2rem;

  /* Radius */
  --radius-control: 0.375rem;
  --radius-card: 0.625rem;
  --radius-major: 1rem;
  --radius-pill: 999px;
  --radius-circle: 50%;

  /* Shadow: one subtle level only. Cards use borders, not shadows. */
  --shadow-menu: 0 12px 32px rgb(28 26 23 / 0.14);
  --shadow-card: 0 1px 2px rgb(28 26 23 / 0.06);
  --shadow-none: none;

  /* Border */
  --border-width: 1px;
  --border-width-strong: 2px;
  --border-card: 1px solid var(--color-border);
  --border-input: 1px solid var(--color-border-strong);

  /* Targets and focus */
  --target-min: 2.75rem;
  --target-min-px: 44px;
  --focus-width: 3px;
  --focus-offset: 3px;
  --focus-ring: 0 0 0 var(--focus-width) var(--color-focus);

  /* Motion */
  --duration-fast: 120ms;
  --duration-base: 180ms;
  --ease-base: ease;

  /* Breakpoints (use in media queries, not in var() for queries):
     --bp-phone: 390px (base, mobile first)
     --bp-tablet: 768px
     --bp-desktop: 1024px
     --bp-wide: 1440px */
  --bp-tablet: 48rem;
  --bp-desktop: 64rem;
  --bp-wide: 90rem;

  /* Header and progress */
  --header-height-mobile: 4rem;
  --header-height-desktop: 4.5rem;
  --progress-height: 3px;
}

/* Dark theme by system setting, only when no manual choice is set */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --color-canvas: #191713;
    --color-surface: #221f1b;
    --color-raised: #2e2a24;
    --color-text: #f5f0e6;
    --color-muted: #cfc6b8;
    --color-border: #4a443b;
    --color-border-strong: #9a958a;
    --color-primary: #5eead4;
    --color-primary-ink: #191713;
    --color-primary-hover: #7df0de;
    --color-accent: #fdba74;
    --color-accent-ink: #191713;
    --color-link: #5eead4;
    --color-link-visited: #c4b5fd;
    --color-success: #86efac;
    --color-success-surface: #052e16;
    --color-warning: #fcd34d;
    --color-warning-surface: #451a03;
    --color-error: #fca5a5;
    --color-error-surface: #450a0a;
    --color-focus: #fbbf24;
    --color-answer: #14332c;
    --color-answer-border: #5eead4;
    --color-summary: #3b1d0e;
    --color-summary-border: #fdba74;
    --color-chip: #2e2a24;
    --color-chip-text: #f5f0e6;
    --color-ad-label: #cfc6b8;
    --color-on-primary: #191713;
    --color-on-accent: #191713;
    --shadow-menu: 0 12px 32px rgb(0 0 0 / 0.44);
    --shadow-card: 0 1px 2px rgb(0 0 0 / 0.3);
  }
}

/* Dark theme by manual toggle. This rule wins over the media query. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --color-canvas: #191713;
  --color-surface: #221f1b;
  --color-raised: #2e2a24;
  --color-text: #f5f0e6;
  --color-muted: #cfc6b8;
  --color-border: #4a443b;
  --color-border-strong: #9a958a;
  --color-primary: #5eead4;
  --color-primary-ink: #191713;
  --color-primary-hover: #7df0de;
  --color-accent: #fdba74;
  --color-accent-ink: #191713;
  --color-link: #5eead4;
  --color-link-visited: #c4b5fd;
  --color-success: #86efac;
  --color-success-surface: #052e16;
  --color-warning: #fcd34d;
  --color-warning-surface: #451a03;
  --color-error: #fca5a5;
  --color-error-surface: #450a0a;
  --color-focus: #fbbf24;
  --color-answer: #14332c;
  --color-answer-border: #5eead4;
  --color-summary: #3b1d0e;
  --color-summary-border: #fdba74;
  --color-chip: #2e2a24;
  --color-chip-text: #f5f0e6;
  --color-ad-label: #cfc6b8;
  --color-on-primary: #191713;
  --color-on-accent: #191713;
  --shadow-menu: 0 12px 32px rgb(0 0 0 / 0.44);
  --shadow-card: 0 1px 2px rgb(0 0 0 / 0.3);
}

/* Manual light choice. This rule wins over a dark system setting. */
:root[data-theme="light"] {
  color-scheme: light;
}

/* Base rules that belong with the tokens, so a token change is one file */
* { box-sizing: border-box; }
html { overflow-wrap: break-word; scroll-padding-top: 5rem; }
body {
  margin: 0;
  background: var(--color-canvas);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--font-size-body-mobile);
  line-height: var(--line-height-body);
}
a {
  color: var(--color-link);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.16em;
}
a:visited { color: var(--color-link-visited); }
a:hover { text-decoration-thickness: 0.14em; }

/* Focus: 3px outline plus 3px offset. The offset puts page background
   between the ring and a filled button, so the ring is read against
   the background and surface, not against the button fill. On a
   primary fill the focus colour alone is 1.15:1 in light and 1.13:1
   in dark, so the offset is part of the pass, not a detail. R7 must
   test keyboard focus on a primary button in both themes. */
:focus-visible {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--focus-offset);
}
button, input, select, summary { min-block-size: var(--target-min); font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: var(--line-height-heading);
  letter-spacing: var(--letter-spacing-heading);
  text-wrap: balance;
}
h1 { font-size: var(--text-h1-mobile); }
h2 { font-size: var(--text-h2-mobile); }
h3 { font-size: var(--text-h3-mobile); }
h4 { font-family: var(--font-sans); font-size: var(--text-h4); line-height: var(--line-height-heading-small); letter-spacing: 0; }
p, li { max-inline-size: var(--measure-reading); }
img, svg { max-inline-size: 100%; block-size: auto; }
table { border-collapse: collapse; inline-size: 100%; font-variant-numeric: tabular-nums; }
th, td { border-block-end: 1px solid var(--color-border); padding: var(--space-3); text-align: start; vertical-align: top; }
th { background: var(--color-raised); }
.shell { inline-size: min(100% - 2rem, var(--measure-shell)); margin-inline: auto; }
.reading { inline-size: min(100%, var(--measure-reading)); margin-inline: auto; }
.wide { inline-size: min(100%, var(--measure-wide)); margin-inline: auto; }
.card { background: var(--color-surface); border: var(--border-card); border-radius: var(--radius-card); padding: var(--space-6); }
.answer { background: var(--color-answer); border-inline-start: 0.3rem solid var(--color-answer-border); border-radius: var(--radius-major); padding: var(--space-6); }
.summary { background: var(--color-summary); border-inline-start: 0.3rem solid var(--color-summary-border); border-radius: var(--radius-major); padding: var(--space-6); }
.warning { color: var(--color-warning); background: var(--color-warning-surface); border-radius: var(--radius-card); padding: var(--space-4); }
.chip { display: inline-flex; align-items: center; min-block-size: 2rem; border: 1px solid var(--color-border); border-radius: var(--radius-pill); padding-inline: 0.75rem; font-size: var(--step--1); background: var(--color-chip); color: var(--color-chip-text); }
.button { display: inline-flex; align-items: center; justify-content: center; min-block-size: var(--target-min); border: 2px solid var(--color-primary); border-radius: var(--radius-control); padding: 0.55rem 1rem; background: var(--color-primary); color: var(--color-primary-ink); font-weight: 700; text-decoration: none; }
.button:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.button:active { transform: translateY(1px); }
.button--quiet { background: transparent; color: var(--color-primary); }
.grid { display: grid; gap: var(--space-4); }
.cluster-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }
.table-scroll { max-inline-size: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
.skip-link { position: fixed; inset: 0 auto auto 0; z-index: 100; transform: translateY(-130%); background: var(--color-surface); color: var(--color-text); padding: var(--space-3); }
.skip-link:focus { transform: none; }
.visually-hidden { position: absolute; inline-size: 1px; block-size: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Breakpoints: 390px is the base. 768px tablet. 1440px wide desktop. */
@media (min-width: 48rem) {
  body { font-size: var(--font-size-body); }
  h1 { font-size: var(--text-h1); }
  h2 { font-size: var(--text-h2); }
  h3 { font-size: var(--text-h3); }
  .shell { inline-size: min(100% - 3rem, var(--measure-shell)); }
}
@media (min-width: 90rem) {
  .shell { inline-size: min(100% - 4rem, var(--measure-shell)); }
}

@media (prefers-reduced-motion: no-preference) {
  a, button, summary { transition: color var(--duration-fast) var(--ease-base), background-color var(--duration-fast) var(--ease-base), border-color var(--duration-fast) var(--ease-base), transform var(--duration-fast) var(--ease-base); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
@media print {
  nav, .site-search, .theme-toggle, .phrase-copy-button, .consent, .ad-slot { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  a { color: #000; }
}
