/* UK Explained design tokens: the single source of truth for colour, type, space, radius, shadow, motion and layers.
   Direction: "The almanac, refined" (see docs/DESIGN.md). Change a value here, not in a component.
   Light theme is the default; dark is set by the visitor's system (prefers-color-scheme) or by the theme button
   (data-theme="light|dark" on <html>). The dark values appear twice below on purpose: once for each of those routes. */

/* ---- Fonts: self-hosted, Latin subsets, SIL Open Font License (static/fonts/OFL.txt) ----
   Files never change in place: a new version gets a new file name, so browsers can keep them for a year. */
@font-face { font-family: 'Newsreader'; src: url('/fonts/newsreader-400.woff2') format('woff2'); font-weight: 300 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Newsreader'; src: url('/fonts/newsreader-800.woff2') format('woff2'); font-weight: 600 900; font-style: normal; font-display: swap; }
@font-face { font-family: 'Newsreader'; src: url('/fonts/newsreader-italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('/fonts/plex-sans-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('/fonts/plex-sans-500.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('/fonts/plex-sans-600.woff2') format('woff2'); font-weight: 600 700; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('/fonts/plex-mono-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('/fonts/plex-mono-500.woff2') format('woff2'); font-weight: 500 700; font-display: swap; }
/* Stand-ins sized to match, so text does not jump when the real fonts arrive */
@font-face { font-family: 'Newsreader Fallback'; src: local('Georgia'); size-adjust: 96.12%; ascent-override: 76.47%; descent-override: 27.57%; line-gap-override: 0%; }
@font-face { font-family: 'IBM Plex Sans Fallback'; src: local('Arial'); size-adjust: 101.17%; ascent-override: 101.32%; descent-override: 27.18%; line-gap-override: 0%; }
@font-face { font-family: 'IBM Plex Mono Fallback'; src: local('Courier New'); size-adjust: 99.98%; ascent-override: 102.52%; descent-override: 27.5%; line-gap-override: 0%; }

:root {
  color-scheme: light;

  /* ---- Neutrals: a warm ramp tinted toward the paper, never pure grey ---- */
  --n-0: #FFFDF8;
  --n-50: #F6F1E7;
  --n-100: #EEE7D8;
  --n-200: #E4DDCC;
  --n-300: #D5CDB9;
  --n-400: #B4AB96;
  --n-500: #8C8472;
  --n-600: #5F5A4E;
  --n-700: #4A463E;
  --n-800: #2E2B25;
  --n-900: #1B1A17;

  /* ---- Brand ---- */
  --primary: #0F5B3E;          /* racing green: links, primary buttons, the masthead */
  --primary-hover: #0B4A32;
  --primary-tint: #E3ECE4;     /* quiet green wash behind "In short" boxes */
  --on-primary: #FFFFFF;
  --accent: #A31F34;           /* pillar-box red: kicker labels, the figure-card shadow, one thing per view */
  --accent-tint: #F5E3E2;

  /* ---- Semantic (always paired with an icon or words, never colour alone) ---- */
  --success: #2F6A1E;
  --success-tint: #E6EEDB;
  --warning: #8A5A0B;
  --warning-tint: #F5EAD3;
  --danger: #A4161A;
  --danger-tint: #F6E0DB;
  --info: #1D4E89;
  --info-tint: #E2E9F2;

  /* ---- Surfaces ---- */
  --surface-page: var(--n-50);
  --surface-raised: var(--n-0);    /* cards, inputs, tables' sticky heads */
  --surface-sunken: var(--n-100);  /* code, skeletons, table stripes */
  --surface-overlay: var(--n-0);   /* menus, search results, glossary pop-ups, toasts */
  --surface-band: var(--primary);  /* the masthead */
  --on-band: #FFFFFF;
  --scrim: rgb(27 26 23 / 0.45);   /* behind the phone topics sheet */

  /* ---- Text ---- */
  --text: var(--n-900);
  --text-secondary: var(--n-700);
  --text-muted: var(--n-600);      /* 6:1 on paper: still comfortably readable */
  --link: var(--primary);
  --link-hover: var(--primary-hover);

  /* ---- Borders and rules ---- */
  --rule: var(--n-300);            /* hairlines between rows */
  --rule-strong: var(--n-900);     /* section rules and table heads: ink */
  --border-control: var(--n-500);  /* inputs and checkboxes: 3.3:1, passes WCAG for components */
  --track: var(--n-200);           /* empty part of bars and meters */

  /* ---- Focus: an ink ring, visible on paper, on cards and next to red shadows ---- */
  --focus-color: var(--n-900);
  --focus-ring: 3px solid var(--focus-color);
  --focus-offset: 2px;

  /* ---- Charts: colour-blind-safe (based on Okabe and Ito), tuned for paper ---- */
  --chart-1: #0F5B3E;
  --chart-2: #C24E00;
  --chart-3: #1D6FA8;
  --chart-4: #B5578F;
  --chart-5: #B88400;
  --chart-6: #8C8472;
  --chart-grid: var(--n-300);
  --chart-hatch: var(--n-500);   /* the striped "no" part of vote bars */
  --chart-label: var(--n-700);

  /* ---- Party colours: each party's own brand colour, deepened where a pale one would vanish on paper ---- */
  --party-lab: #E4003B; --party-con: #0087DC; --party-ld: #F29A0E; --party-snp: #E8C300; --party-reform: #12B6CF;
  --party-green: #02A95B; --party-plaid: #005B54; --party-dup: #D46A4C; --party-sf: #326760; --party-sdlp: #2AA82C;
  --party-alliance: #D9A800; --party-uup: #48A5EE; --party-tuv: #0C3A6A; --party-other: var(--chart-6);

  /* ---- Electricity sources ---- */
  --fuel-wind: var(--chart-3); --fuel-gas: var(--chart-2); --fuel-nuclear: var(--chart-4); --fuel-solar: var(--chart-5);
  --fuel-biomass: var(--chart-1); --fuel-hydro: #1A8C8C; --fuel-imports: var(--chart-6); --fuel-coal: #3B3730; --fuel-other: var(--n-400);

  /* ---- Type ---- */
  --font-serif: 'Newsreader', 'Newsreader Fallback', Georgia, 'Times New Roman', serif;
  --font-sans: 'IBM Plex Sans', 'IBM Plex Sans Fallback', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'IBM Plex Mono Fallback', ui-monospace, Consolas, monospace;

  /* A 1.25 scale that grows gently between a 375px phone and a 1280px desktop */
  --step--2: 0.75rem;                                         /* 12px  labels, captions */
  --step--1: 0.875rem;                                        /* 14px  table text, notes */
  --step-0: clamp(1rem, 0.96rem + 0.18vw, 1.0625rem);         /* 16-17 body */
  --step-1: clamp(1.125rem, 1.06rem + 0.28vw, 1.25rem);       /* 18-20 lede, sidenote-free prose */
  --step-2: clamp(1.25rem, 1.15rem + 0.45vw, 1.5rem);         /* 20-24 h3 */
  --step-3: clamp(1.5rem, 1.33rem + 0.72vw, 1.875rem);        /* 24-30 h2 */
  --step-4: clamp(1.875rem, 1.59rem + 1.2vw, 2.5rem);         /* 30-40 h1 on inner pages */
  --step-5: clamp(2.25rem, 1.77rem + 2.05vw, 3.25rem);        /* 36-52 home h1 */
  --step-6: clamp(3rem, 2.1rem + 3.85vw, 5.25rem);            /* 48-84 the one big figure */

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;   /* sans only */
  --weight-display: 800;    /* serif headings and big figures */

  --leading-tight: 1.08;    /* display */
  --leading-snug: 1.25;     /* headings */
  --leading-body: 1.6;
  --leading-relaxed: 1.7;   /* long prose */

  --tracking-display: -0.02em;
  --tracking-heading: -0.01em;
  --tracking-label: 0.08em; /* mono capitals */

  --measure: 27em;          /* prose line length: about 56-70 characters at any text size ("em" follows each paragraph's own size) */
  --measure-narrow: 22em;

  /* ---- Space: one 4px-based scale ---- */
  --space-1: 0.25rem;   /* 4 */
  --space-2: 0.5rem;    /* 8 */
  --space-3: 0.75rem;   /* 12 */
  --space-4: 1rem;      /* 16 */
  --space-5: 1.5rem;    /* 24 */
  --space-6: 2rem;      /* 32 */
  --space-7: 3rem;      /* 48 */
  --space-8: 4rem;      /* 64 */
  --space-9: 6rem;      /* 96 */

  /* ---- Radius: square is the house style ---- */
  --radius-0: 0;          /* everything by default */
  --radius-1: 2px;        /* tiny inline things: kbd, the inside of a toggle */
  --radius-round: 999px;  /* dots, avatars, chart markers */

  /* ---- Shadow and elevation: layered, tinted toward the ink, used sparingly ---- */
  --shadow-1: 0 1px 0 rgb(27 26 23 / 0.05), 0 1px 3px rgb(46 43 37 / 0.08);
  --shadow-2: 0 2px 4px rgb(46 43 37 / 0.06), 0 10px 24px -6px rgb(46 43 37 / 0.18);
  --shadow-3: 0 4px 8px rgb(46 43 37 / 0.08), 0 24px 48px -12px rgb(46 43 37 / 0.28);
  --shadow-figure: 6px 6px 0 var(--accent);   /* the signature: key-figure cards only */

  /* ---- Motion ---- */
  --dur-1: 120ms;   /* hover, press */
  --dur-2: 200ms;   /* menus, pop-ups, fades */
  --dur-3: 280ms;   /* sheets, page-load reveal */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);     /* things arriving */
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);  /* things moving across the screen */
  --move: 8px;      /* how far things travel when they appear; 0 when motion is reduced */

  /* ---- Layers ---- */
  --z-raised: 10;
  --z-sticky: 100;     /* header, phone tab bar */
  --z-dropdown: 200;   /* menus, search results, glossary pop-ups */
  --z-overlay: 300;    /* scrim behind sheets */
  --z-sheet: 400;      /* phone topics sheet, dialogs */
  --z-toast: 500;
  --z-skip: 600;       /* skip link sits above everything */

  /* ---- Layout ---- */
  --page-max: 1280px;
  --gutter: clamp(1rem, 4vw, 3.5rem);
  --header-h: 4.5rem;  /* used for scroll-padding so headings are never hidden */
  --sidenote-w: 15rem;
  /* Breakpoints (media queries cannot read variables, so these are the agreed numbers):
     sm 480px · md 720px (phone layout below this) · lg 960px · xl 1200px (sidenotes move to the margin) */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --n-0: #201D16; --n-50: #17150F; --n-100: #110F0B; --n-200: #2A271E; --n-300: #3A3629; --n-400: #5A5444;
    --n-500: #7A7262; --n-600: #A39B88; --n-700: #C2BAA6; --n-800: #DAD3C3; --n-900: #EDE6D6;
    --primary: #8CCBA8; --primary-hover: #A9DBBF; --primary-tint: #17261D; --on-primary: #0B2A1B;
    --accent: #E8949F; --accent-tint: #2E1A1B;
    --success: #A5CF8A; --success-tint: #1C2615; --warning: #E3B866; --warning-tint: #2B2212;
    --danger: #F09A8E; --danger-tint: #2E1916; --info: #9DBDE8; --info-tint: #18202C;
    --surface-overlay: #27231A; --surface-band: #12382A; --on-band: #E8F1EA; --scrim: rgb(5 4 2 / 0.6);
    --chart-1: #8CCBA8; --chart-2: #F0A167; --chart-3: #86BCE6; --chart-4: #E3A3C8; --chart-5: #E3C25E; --chart-6: #A39B88; --chart-hatch: var(--n-600);
    --party-plaid: #3FA597; --party-sf: #5FA79C; --party-tuv: #6C8FBF; --fuel-hydro: #6CC6C2; --fuel-coal: #C2BAA6;
    --shadow-1: 0 1px 0 rgb(0 0 0 / 0.3), 0 1px 3px rgb(5 4 2 / 0.4);
    --shadow-2: 0 2px 4px rgb(5 4 2 / 0.4), 0 10px 24px -6px rgb(5 4 2 / 0.6);
    --shadow-3: 0 4px 8px rgb(5 4 2 / 0.45), 0 24px 48px -12px rgb(5 4 2 / 0.7);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --n-0: #201D16; --n-50: #17150F; --n-100: #110F0B; --n-200: #2A271E; --n-300: #3A3629; --n-400: #5A5444;
  --n-500: #7A7262; --n-600: #A39B88; --n-700: #C2BAA6; --n-800: #DAD3C3; --n-900: #EDE6D6;
  --primary: #8CCBA8; --primary-hover: #A9DBBF; --primary-tint: #17261D; --on-primary: #0B2A1B;
  --accent: #E8949F; --accent-tint: #2E1A1B;
  --success: #A5CF8A; --success-tint: #1C2615; --warning: #E3B866; --warning-tint: #2B2212;
  --danger: #F09A8E; --danger-tint: #2E1916; --info: #9DBDE8; --info-tint: #18202C;
  --surface-overlay: #27231A; --surface-band: #12382A; --on-band: #E8F1EA; --scrim: rgb(5 4 2 / 0.6);
  --chart-1: #8CCBA8; --chart-2: #F0A167; --chart-3: #86BCE6; --chart-4: #E3A3C8; --chart-5: #E3C25E; --chart-6: #A39B88; --chart-hatch: var(--n-600);
    --party-plaid: #3FA597; --party-sf: #5FA79C; --party-tuv: #6C8FBF; --fuel-hydro: #6CC6C2; --fuel-coal: #C2BAA6;
  --shadow-1: 0 1px 0 rgb(0 0 0 / 0.3), 0 1px 3px rgb(5 4 2 / 0.4);
  --shadow-2: 0 2px 4px rgb(5 4 2 / 0.4), 0 10px 24px -6px rgb(5 4 2 / 0.6);
  --shadow-3: 0 4px 8px rgb(5 4 2 / 0.45), 0 24px 48px -12px rgb(5 4 2 / 0.7);
}

/* Reduced motion: nothing travels; fades stay but are quicker. */
@media (prefers-reduced-motion: reduce) {
  :root { --move: 0px; --dur-3: 120ms; --dur-2: 120ms; }
}
