/* Design tokens shared by every page of the app. Only this file may hold "raw" colour, font-size and spacing values;
   the other files use var(--…), and only the role tokens (second block): never a base colour directly.

   Two layers:
   1. Base palette, drawn from the app icon (packaging/icon/icon.svg, R3 "nib touching a footnote dot"): the nib's ink #1f2126,
      the cream of the tile (#f1e9d7 → #e3d7bf, lightened here for reading), the bronze of the dot #a8813f; three state colours
      chosen to sit with them: verdigris (the patina of bronze), slate and brick.
   2. Roles: what a colour is for (page, text, accent, correct, information, error, highlight…). The dark appearance is the one
      block at the end of this file: it redefines only role tokens, never a base colour or a component, under
      @media screen and (prefers-color-scheme: dark), so print and the PDF report always stay light.

   Contrast in the light appearance (WCAG 2.1; text at least 4.5:1, input edges and graphics at least 3:1), on --paper / --surface / --bg-sunken:
     --text 15.05 / 16.11 / 13.92        --text-muted 6.43 / 6.88 / 5.94        --text-faint 5.72 / 6.11 / 5.29
     --accent-text 5.73 / 6.13 / 5.30, on --accent-bg 5.40      --good-text 6.23 / 6.66 / 5.76, on --good-bg 5.84
     --info-text 6.34 / 6.78 / 5.86, on --info-bg 5.92          --error-text 6.51 / 6.96 / 6.02, on --error-bg 5.77
     --on-solid on --accent-text 6.13, --good-text 6.66, --info-text 6.78, --error 5.98 (solid badges)
     --border-input 3.56 / 3.81; --accent 3.34 / 3.57, --good 3.75 / 4.02, --info 4.06 / 4.35, --error 5.59 / 5.98 (graphics)
     --text on --highlight 12.23, --highlight-strong 9.28, --diff-removed 9.98, --diff-added 11.38, --match-bg (over white) 11.29
     on --log-bg: --log-text 12.25, --log-time 6.99, --log-tool 9.35, --log-system 9.31, --log-error 7.86, --log-done 9.53
     --inverse-text on --inverse-bg 15.05, --inverse-muted 6.99; --on-dark on --page-label-bg over a white page 5.21
   Red–green colour blindness: correct (verdigris) and discrepancy (brick) differ by ΔE 39 (deuteranopia) and 23 (protanopia) in
   the -text shades, against 20 and 14 with the earlier moss and red; the verdict marks also carry ✓ ✗ ?, never colour alone. */
:root {
  /* ---- 1. base palette (from the app icon) ---- */
  --ink: #1f2126;        /* the nib */
  --ink-soft: #34373e;   /* ink, one step lighter (hover) */
  --paper: #faf7f0;      /* the icon's cream, lightened for reading */
  --parchment: #f3eee3;  /* the cream, one step darker */
  --linen: #e7e0d0;      /* the cream of the icon's lower edge */
  --stone: #b3aa96;      /* warm grey between cream and ink */
  --white: #ffffff;
  --bronze: #a8813f;     /* the footnote dot */
  --verdigris: #4f8a76;  /* patina of bronze: correct, matching */
  --slate: #5b7ba6;      /* information, the AI, later */
  --brick: #b2392b;      /* error, discrepancy */

  /* ---- 2. roles ---- */
  --bg: var(--paper);              /* page background */
  --bg-sunken: var(--parchment);   /* sunken areas: sidebar, neutral notices */
  --bg-dark: var(--linen);         /* background behind document pages */
  --bg-hover: var(--linen);        /* a row or step under the pointer */
  --surface: var(--white);         /* raised surfaces: cards, inputs, document pages */
  --track: var(--linen);           /* the empty part of a progress bar */
  --text: var(--ink);
  --text-muted: #5e5a50;           /* secondary text, captions */
  --text-faint: #67615a;           /* input placeholders, ordinal numbers */
  --border: #e0d9ca;
  --border-strong: var(--stone);
  --border-hover: var(--ink);      /* edge of a card, button or field under the pointer */
  --border-input: #8a8272;         /* edge of text fields and selects (WCAG 1.4.11) */
  --focus: var(--slate);           /* keyboard focus ring */

  --inverse-bg: var(--ink);        /* solid ink surfaces: primary button, selected tab, current citation, selection bar */
  --inverse-bg-hover: var(--ink-soft);
  --inverse-text: var(--paper);
  --inverse-muted: var(--stone);   /* secondary text on an ink surface */

  --accent: var(--bronze);         /* accent: what needs attention now */
  --accent-text: #7d5c22;
  --accent-bg: #f7f0e1;
  --accent-border: #e3d0a8;
  --good: var(--verdigris);        /* correct, matching, done */
  --good-text: #2f6655;
  --good-bg: #e9f2ee;
  --good-border: #bcd5cb;
  --info: var(--slate);            /* information, what the AI says, work for later */
  --info-text: #365d8b;
  --info-bg: #ebf0f7;
  --info-border: #c2d1e5;
  --error: var(--brick);           /* errors, mismatches */
  --error-text: #a3311f;
  --error-bg: #f8e6e2;
  --error-border: #e8c1b9;
  --error-text-strong: #5c1c12;    /* text in error notices */
  --on-solid: var(--white);        /* text on a solid state colour (solid badges) */

  --log-bg: var(--ink);            /* the AI's activity log: always a dark panel */
  --log-text: var(--linen);
  --log-time: var(--stone);
  --log-tool: #b3c7e2; --log-system: #dcc28c; --log-error: #f2a097; --log-done: #a7d0c0;   /* kinds of line in the log */
  --on-dark: var(--paper);         /* text on the dark label laid over a page image */
  --diff-removed: #f3c0b5; --diff-added: #c4dfd3;                                         /* removed and added parts in a comparison */
  --highlight: #efdfbb;            /* highlight: the clause being checked and the matching source passage share one colour */
  --highlight-strong: #dfc184;     /* anchor sentence in the source passage */
  --highlight-faint: rgba(168, 129, 63, .14);     /* --bronze */
  --highlight-hover: rgba(168, 129, 63, .3);      /* clause on hover */
  --highlight-outside: rgba(168, 129, 63, .22);   /* matching number outside the highlighted passage */
  --error-highlight: rgba(178, 57, 43, .14);      /* --brick: number the machine did not find in the source */
  --match-bg: rgba(79, 138, 118, .3);             /* --verdigris: figure or quotation found word for word */
  --page-label-bg: rgba(31, 33, 38, .68);         /* --ink: page-number label overlaid on the page image */
  --border-on-solid: rgba(255, 255, 255, .5);
  --backdrop: rgba(31, 33, 38, .45);              /* overlay behind a dialog */

  /* drawn on a document page image (verification screen): the page stays a white sheet in both appearances, so these keep
     their light values in the dark block (the same values as --highlight, --highlight-strong, --match-bg, --highlight-outside,
     --good, --accent-text above); the outlines are at least 3:1 on the page (verdigris 4.02, bronze text 6.13 on white) */
  --page-bg: var(--white);                        /* the sheet behind a page image */
  --page-image-filter: none;                      /* dimmed a little in the dark appearance (Apple HIG: soften white images) */
  --page-highlight: #efdfbb;
  --page-highlight-strong: #dfc184;
  --page-match: rgba(79, 138, 118, .3);
  --page-highlight-outside: rgba(168, 129, 63, .22);
  --page-good: var(--verdigris);
  --page-accent: #7d5c22;
  color-scheme: light;                            /* scroll bars and form controls; dark only in the block at the end */

  /* ---- type ---- */
  --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;   /* interface, section headings */
  --serif: "Lora", Georgia, "Times New Roman", serif;                                 /* reading text, article titles */
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --c-1: 12px;   /* badges, keyboard shortcuts */
  --c0: 13px;    /* secondary interface text */
  --c1: 15px;    /* interface text, captions */
  --c2: 17px;    /* reading text, article titles in the list */
  --c3: 21px;    /* section headings */
  --c4: 30px;    /* page titles */
  --ui-line-height: 1.45;   /* line height of interface text */
  --reading-line-height: 1.72;  /* line height of reading text (serif type needs more air) */

  /* ---- spacing (multiples of 4) ---- */
  --k0: 2px; --k1: 4px; --k2: 8px; --k3: 12px; --k4: 16px; --k5: 24px; --k6: 32px; --k7: 48px; --k8: 72px;

  /* ---- corner radius ---- */
  --radius-0: 3px;      /* small marks: citation numbers, highlighted words, code, keys */
  --radius-1: 6px;      /* buttons, inputs, square badges */
  --radius-2: 12px;     /* cards, dialogs */
  --radius-pill: 999px;

  /* ---- shadows ---- */
  --shadow-1: 0 1px 2px rgba(31, 33, 38, .07), 0 3px 10px rgba(31, 33, 38, .05);   /* document pages, raised cards */
  --shadow-2: 0 18px 56px rgba(31, 33, 38, .24);                                    /* dialogs */

  /* ---- motion ---- */
  --fast: 130ms;
  --ease: cubic-bezier(.2, .7, .2, 1);

  --reading-width: 46rem;   /* width of the reading column */
}

/* ---- dark appearance ----
   Follows the Mac's appearance (Apple HIG, Dark Mode: dimmer backgrounds, brighter foregrounds, not an inversion; base
   backgrounds behind, elevated ones in front: --bg-dark < --bg-sunken < --bg < --surface). Only role tokens change here: no base
   colour, no component. "screen" keeps print, the PDF report and the hidden capture window (app/render.py, pinned to the light
   appearance) light. The page is the icon's ink (as the site, tools/make_site.py), text is ivory, the accent a lighter bronze.
   Roles not listed keep their light value on purpose: --log-text, --log-time, --log-* kinds (written for a dark panel),
   --on-dark and --page-label-bg (a label over a white page image), the --page-* tokens except two (the page stays white).
   Contrast in the dark appearance (computed from these values by rename/verify/test_y_dark_mode.py; rgba composited on
   the background named; text at least 4.5:1, input edges and graphics at least 3:1):
     --text 14.14 / 12.94 / 14.95 / 15.51 (page, surface, sunken, behind pages), on --bg-hover 11.09
     --text-muted 7.98 / 7.30 / 8.44, on --bg-hover 6.26
     --text-faint 6.28 / 5.75 / 6.64, on --bg-hover 4.93
     --accent-text 9.33 / 8.54 / 9.87, on --accent-bg 7.95; --text on --accent-bg 12.05
     --good-text 11.35 / 10.39 / 12.00, on --good-bg 9.69; --text on --good-bg 12.07
     --info-text 9.45 / 8.65 / 10.00, on --info-bg 8.38; --text on --info-bg 12.53
     --error-text 7.02 / 6.42 / 7.42, on --error-bg 6.08; --text on --error-bg 12.26
     --accent-text (links) on --good-bg 7.96, --info-bg 8.27, --error-bg 8.09; --error-text-strong on --error-bg 11.02
     --inverse-text on --inverse-bg 14.14, on -hover 11.69; --inverse-muted 6.27 / 5.18
     --on-solid on --accent-text 9.33, --good-text 11.35, --info-text 9.45, --error 5.79, --text-muted 7.98 (solid badges)
     --text on --highlight 9.56, --highlight-strong 5.32, --diff-removed 9.42, --diff-added 8.01; on --highlight: accent/good/info/error text 6.31 / 7.67 / 6.39 / 4.74
     --text on (over --bg / --surface) --highlight-faint 11.15/10.09, -hover 8.29/7.57, -outside 9.45/8.58, --error-highlight 10.59/9.64, --match-bg 8.26/7.55; --match-bg over --highlight 5.95
     on --log-bg: --log-text 14.68, --log-time 8.37, tool 11.20, system 11.16, error 9.42, done 11.42; --on-dark on --page-label-bg over the dimmed page 5.74
     --border-input 4.11 / 3.76 / 4.34; --focus 7.41 / 6.78; --border-hover on --surface 12.94
     graphics on --bg / --surface: --accent 7.33 / 6.71, --good 7.39 / 6.77, --info 6.49 / 5.94, --error 5.79 / 5.30 (on --error-bg 5.02)
   Red–green colour blindness (Machado 2009, CIELAB distance): correct and discrepancy differ by 34 (deuteranopia) and 28
   (protanopia) in the -text shades, 33 and 20 in the graphic shades; discrepancy and accent by 9 and 21 (light: 4 and 13). */
@media screen and (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #17191d;
    --bg-sunken: #111316;
    --bg-dark: #0d0e11;
    --bg-hover: #2a2d33;
    --surface: #1f2126;
    --track: #2e3137;
    --text: #ece6d8;
    --text-muted: #b5ae9f;
    --text-faint: #a09a8c;
    --border: #2e3137;
    --border-strong: #4d5058;
    --border-hover: #ece6d8;
    --border-input: #7d7a72;
    --focus: #8eaad3;

    --inverse-bg: #ece6d8;
    --inverse-bg-hover: #d9d2c2;
    --inverse-text: #17191d;
    --inverse-muted: #55524a;

    --accent: #c9a15e;
    --accent-text: #dbb877;
    --accent-bg: #2c261b;
    --accent-border: #5a4a2e;
    --good: #5fb89c;
    --good-text: #9edcca;
    --good-bg: #182a26;
    --good-border: #2f5a4e;
    --info: #7f9fcd;
    --info-text: #a6c0e4;
    --info-bg: #1b2433;
    --info-border: #37506f;
    --error: #e8705e;
    --error-text: #f28572;
    --error-bg: #35201e;
    --error-border: #6b3830;
    --error-text-strong: #f8d3cb;
    --on-solid: #17191d;

    --log-bg: #0d0e11;
    --diff-removed: #5a2a24; --diff-added: #1f4a3e;
    --highlight: #40361f;
    --highlight-strong: #6e5a32;
    --highlight-faint: rgba(201, 161, 94, .14);
    --highlight-hover: rgba(201, 161, 94, .28);
    --highlight-outside: rgba(201, 161, 94, .22);
    --error-highlight: rgba(232, 112, 94, .2);
    --match-bg: rgba(95, 184, 156, .28);
    --border-on-solid: rgba(23, 25, 29, .35);
    --backdrop: rgba(0, 0, 0, .6);
    --page-bg: #ebebeb;
    --page-image-filter: brightness(.92);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4), 0 3px 10px rgba(0, 0, 0, .3);
    --shadow-2: 0 18px 56px rgba(0, 0, 0, .6);
  }
}
