/* ==========================================================================
   Ulgama design tokens · v2.0 "The Registry" · October 17, 2026
   Drop-in replacement for tokens.css 1.1. Every custom property keeps its
   name, so templates and components.css keep working. New names are marked.

   Colour: bound ink on bone paper. Registrar blue is the only colour that
   means "you can act here". The four signals are unchanged. Every text
   pair states its WCAG 2.x contrast ratio (AA: 4.5 text, 3 controls).

   Rules that keep it calm (unchanged from 1.1):
   - --brand is the only action colour. The logo is printed in --logo.
   - Signal colours appear only in text, icons and small tags.
   - Green (moss) means "current" and nothing else.
   - Nothing is said by colour alone: every status has an icon and a word.

   3.1 "Shadow board" (D-092, November 13, 2026): dark mode takes the
   designer's values, the paper gets its sixth look (not checked yet), and
   the menu, the amber box, switches, scrims and loading blocks get tokens.
   docs/shadow-board.md lists every token a page may use.
   ========================================================================== */

/* --- Fonts: two families, both SIL Open Font License 1.1, self-hosted ----- */
/* Atkinson Hyperlegible Next: everything people read and tap.             */
@font-face {
  font-family: "Ulgama Sans";
  src: url("fonts/AtkinsonHyperlegibleNext-Variable.121520b68f71.woff2") format("woff2");
  font-weight: 200 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Ulgama Sans";
  src: url("fonts/AtkinsonHyperlegibleNext-Italic-Variable.19c2e75fb89f.woff2") format("woff2");
  font-weight: 200 800; font-style: italic; font-display: swap;
}
/* EB Garamond: titles, dates, the one big number. Never below 17px.        */
/* Variable woff2 (wght 400–800), © The EB Garamond Project Authors, OFL.   */
@font-face {
  font-family: "Ulgama Serif";
  src: url("fonts/EBGaramond-Variable.4124e11482b4.woff2") format("woff2");
  font-weight: 400 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Ulgama Serif";
  src: url("fonts/EBGaramond-Italic-Variable.0dd5233c9d0e.woff2") format("woff2");
  font-weight: 400 800; font-style: italic; font-display: swap;
}

/* --- Light (default) ------------------------------------------------------ */
:root,
[data-theme="light"] {
  color-scheme: light;

  /* Surfaces */
  --paper: #F3EEE2;            /* page: bone. ink on it 15.0 */
  --paper-2: #E9E3D4;          /* the tinted margin column, hovered rows: ink 13.6, ink-2 5.4 */
  --card: #FBF9F4;             /* sheets: cards, rows, fields. ink 16.5 */
  --hairline: #DAD3C3;         /* rules, card edges (decorative) */
  --control-border: #8F887A;   /* fields, secondary buttons: 3.2 on card */
  --shell: #1B1A17;            /* NEW · sidebar, tab bar, app header */
  --shell-2: #26241F;          /* NEW · hovered item, search field in the shell */
  --shell-hairline: #34312B;   /* NEW */
  --on-shell: #EFE9DC;         /* NEW · text in the shell: 14.4 */
  --on-shell-2: #A8A193;       /* NEW · muted text and icons in the shell: 6.8 */

  /* Text and logo */
  --ink: #1B1A17;              /* body: 15.0 on paper, 16.5 on card */
  --ink-2: #5E5A52;            /* meta, captions: 5.9 on paper, 6.5 on card */
  --logo: #1B1A17;

  /* Registrar blue: links, primary button, focus, selection, current item */
  --brand: #2F4B9E;            /* 7.1 on paper, 7.6 on card */
  --brand-pressed: #233A7D;    /* 10.2 on card */
  --brand-tint: #E2E7F3;       /* selected row, hovered secondary button: brand on it 6.6 */
  --on-brand: #FFFFFF;         /* 8.0 on brand */

  /* Signals: text colour + tag tint. On card / on its tint */
  --brick: #9A2F28;  --brick-tint: #F7E4E0;   /* 6.6 / 6.1 · missing, expired, critical */
  --amber: #7A4E00;  --amber-tint: #F7ECD2;   /* 6.5 / 6.1 · expiring, high */
  --plum:  #6A3E86;  --plum-tint:  #EFE4F3;   /* 6.9 / 6.5 · needs review, medium */
  --moss:  #2B6A3A;  --moss-tint:  #E1EEE3;   /* 5.8 / 5.4 · current, done */
  --grey:  #5E5A52;  --grey-tint:  #E9E3D4;   /* 6.5 / 5.4 · off, not applicable, low */

  /* States */
  --disabled-bg: #B9B1A1;      /* disabled primary: card text on it 2.9, read as disabled by its label */
  --disabled-ink: #FBF9F4;
  --overlay: rgb(27 26 23 / 0.55);
  --toast-bg: #1B1A17;
  --toast-ink: #F3EEE2;
  --toast-mark: #8FCB9B;       /* NEW · the check in a "Marked done" toast: moss for an ink toast */
  --shadow-overlay: 0 1px 2px rgb(27 26 23 / 0.10), 0 12px 32px rgb(27 26 23 / 0.18);

  /* 3.0 Shadow board surfaces (D-091): the pegboard wall, an empty outline, a hung card. */
  --sb-wall: #E9E3D4;
  --sb-wall-dot: rgb(27 26 23 / 0.16);
  --sb-empty: #E2DBCB;
  --sb-card: #FBF9F4;            /* 3.1 · an up card on the wall */
  --sb-area-card: #F3EEE2;       /* 3.1 · an area's card on the pegboard (Documents, "On the wall") */
  --sb-card-border: #C9C1AF;
  --sb-card-shadow: 0 1px 2px rgb(27 26 23 / 0.12), 0 6px 14px rgb(27 26 23 / 0.08);
  --sb-warn-bg: #FBF1D6;

  /* 3.1 (D-092): the paper's six looks. Edges follow the theme in the designer's dark values,
     so they live here and in the dark blocks, not with the tokens that never change. */
  --sb-place-fill: #8DB396;   --sb-place-edge: var(--moss);    /* sage on moss */
  --sb-due-fill: #F3D081;     --sb-due-edge: var(--amber);     /* honey on amber */
  --sb-lapsed-fill: #994234;  --sb-lapsed-edge: var(--brick);  /* terracotta on brick */
  --sb-missing-edge: var(--brick);                             /* no fill, dashed */
  --sb-review-dot: #6A3E86;                                    /* in place, with a plum dot */
  --sb-unchecked-edge: #7A7466;                                /* not checked yet: no fill, dotted */
  --sb-peg-ink: #1B1A17;                                       /* pegs and strings */

  /* 3.1: the amber message box (failures, "shown once", warnings). Never brick. Ink 15.5 on it. */
  --sb-warn-border: #7A4E00;
  --sb-warn-ink: #1B1A17;

  /* 3.1: the menu (ShadowNav). The current item is a cream sheet with a blue bar at its start. */
  --sb-nav-current-bg: #F3EEE2;
  --sb-nav-current-ink: #1B1A17;
  --sb-nav-accent: #2F4B9E;      /* the bar and the current icon: blue in both themes */
  --sb-nav-field-border: #34312B;
  --sb-org-badge: #2F4B9E;
  --sb-org-badge-ink: #FFFFFF;
  --sb-qr-ground: #FFFFFF;       /* white under a QR code in both themes: a camera reads dark on light */
  --sb-tab-mark: #9FB3EA;        /* the 3px line over the current tab, on the ink tab bar */

  /* 3.1: controls */
  --sb-button-2: #FBF9F4;        /* a secondary button's sheet */
  --sb-switch-locked: #8F887A;   /* a switch that is locked on */

  /* 3.1: loading blocks (no edge, no colour: those are paper states), scrims and washes */
  --sb-loading: #DAD3C3;
  --sb-loading-2: #E2DBCB;
  --sb-loading-peg: #C9C1AF;
  --sb-scrim: rgb(27 26 23 / 0.62);
  --sb-wash: rgb(243 238 226 / 0.66);
  --sb-panel-shadow-color: rgb(27 26 23 / 0.16);
  --toast-shadow: 0 12px 32px rgb(27 26 23 / 0.28);
  --toast-close-hover: rgb(128 128 128 / 0.25);
}

/* --- Dark: the designer's values (Shadow board 3.1, "Tokens, light and dark", D-092) --------
   Kept in step with the block under prefers-color-scheme below (a test compares them). */
[data-theme="dark"] {
  color-scheme: dark;
  --paper: #141311;   /* page */
  --paper-2: #26241F;   /* ink-2 on it 6.0 */
  --card: #1F1D19;
  --hairline: #3A3730;
  --control-border: #8F887A;   /* 3.1: the designer's control edge, 4.8 on card */
  --shell: #0E0D0B;   /* the menu */
  --shell-2: #1F1D19;
  --shell-hairline: #3A3730;
  --on-shell: #EFE9DC;
  --on-shell-2: #A8A193;
  --ink: #EFE9DC;   /* text: 15.4 on paper, 13.9 on card */
  --ink-2: #A8A193;   /* muted: 7.2 on paper, 6.6 on card */
  --logo: #EFE9DC;
  --brand: #9FB3EA;   /* link and main button: 8.1 on card */
  --brand-pressed: #C3D0F3;
  --brand-tint: #1E2A4A;   /* brand on it 6.4 */
  --on-brand: #141311;   /* button text: 8.9 on brand */
  --brick: #F0907F;   /* lapsed and missing words */
  --brick-tint: #3B1A17;
  --amber: #E3B35A;   /* coming due words */
  --amber-tint: #3A2A08;
  --plum: #C9A6DD;   /* needs review words */
  --plum-tint: #2E1F38;
  --moss: #8DC79B;   /* in place words */
  --moss-tint: #17301E;
  --grey: #A8A193;
  --grey-tint: #26241F;
  --disabled-bg: #4A463E;
  --disabled-ink: #A8A193;
  --overlay: rgb(0 0 0 / 0.65);
  --toast-bg: #EFE9DC;
  --toast-ink: #141311;
  --toast-mark: #2B6A3A;
  --shadow-overlay: 0 0 0 1px #3A3730, 0 12px 32px rgb(0 0 0 / 0.55);
  --sb-wall: #1F1D19;   /* 3.1: the designer's dark wall */
  --sb-wall-dot: rgb(239 233 220 / 0.10);
  --sb-empty: #171614;   /* a down outline, a step darker than the wall, like a hole */
  --sb-card: #26241F;   /* an up card, a step lighter than the wall */
  --sb-area-card: #26241F;
  --sb-card-border: #4A463E;
  --sb-card-shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 14px rgb(0 0 0 / 0.3);
  --sb-warn-bg: #3A2A08;   /* the amber box on dark: ink 11.5, border 7.2, link 6.7 on it */
  --sb-place-fill: #8DB396;   /* hues kept */
  --sb-place-edge: #2B6A3A;
  --sb-due-fill: #F3D081;
  --sb-due-edge: #7A4E00;
  --sb-lapsed-fill: #B5503F;   /* terracotta lightens, 3.4 on the wall */
  --sb-lapsed-edge: #E08A7E;   /* and takes a light edge */
  --sb-missing-edge: #E08A7E;   /* dashed */
  --sb-review-dot: #6A3E86;
  --sb-unchecked-edge: #A8A193;   /* dotted */
  --sb-peg-ink: #EFE9DC;   /* pegs and strings turn cream */
  --sb-warn-border: #E3B35A;
  --sb-warn-ink: #EFE9DC;
  --sb-nav-current-bg: #EFE9DC;
  --sb-nav-current-ink: #141311;
  --sb-nav-accent: #2F4B9E;
  --sb-nav-field-border: #4A463E;
  --sb-org-badge: #2F4B9E;
  --sb-org-badge-ink: #FFFFFF;
  --sb-tab-mark: #9FB3EA;
  --sb-button-2: #26241F;
  --sb-switch-locked: #8F887A;
  --sb-loading: #2C2924;
  --sb-loading-2: #24221E;
  --sb-loading-peg: #3A3730;
  --sb-scrim: rgb(0 0 0 / 0.7);
  --sb-wash: rgb(20 19 17 / 0.66);
  --sb-panel-shadow-color: rgb(0 0 0 / 0.5);
  --toast-shadow: 0 0 0 1px #3A3730, 0 12px 32px rgb(0 0 0 / 0.55);
  --toast-close-hover: rgb(128 128 128 / 0.25);
  --sb-qr-ground: #FFFFFF;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #141311; --paper-2: #26241F; --card: #1F1D19; --hairline: #3A3730;
    --control-border: #8F887A; --shell: #0E0D0B; --shell-2: #1F1D19; --shell-hairline: #3A3730;
    --on-shell: #EFE9DC; --on-shell-2: #A8A193; --ink: #EFE9DC; --ink-2: #A8A193;
    --logo: #EFE9DC; --brand: #9FB3EA; --brand-pressed: #C3D0F3; --brand-tint: #1E2A4A;
    --on-brand: #141311; --brick: #F0907F; --brick-tint: #3B1A17; --amber: #E3B35A;
    --amber-tint: #3A2A08; --plum: #C9A6DD; --plum-tint: #2E1F38; --moss: #8DC79B;
    --moss-tint: #17301E; --grey: #A8A193; --grey-tint: #26241F; --disabled-bg: #4A463E;
    --disabled-ink: #A8A193; --overlay: rgb(0 0 0 / 0.65); --toast-bg: #EFE9DC; --toast-ink: #141311;
    --toast-mark: #2B6A3A; --shadow-overlay: 0 0 0 1px #3A3730, 0 12px 32px rgb(0 0 0 / 0.55); --sb-wall: #1F1D19; --sb-wall-dot: rgb(239 233 220 / 0.10);
    --sb-empty: #171614; --sb-card: #26241F; --sb-area-card: #26241F; --sb-card-border: #4A463E; --sb-card-shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 14px rgb(0 0 0 / 0.3);
    --sb-warn-bg: #3A2A08; --sb-place-fill: #8DB396; --sb-place-edge: #2B6A3A; --sb-due-fill: #F3D081;
    --sb-due-edge: #7A4E00; --sb-lapsed-fill: #B5503F; --sb-lapsed-edge: #E08A7E; --sb-missing-edge: #E08A7E;
    --sb-review-dot: #6A3E86; --sb-unchecked-edge: #A8A193; --sb-peg-ink: #EFE9DC; --sb-warn-border: #E3B35A;
    --sb-warn-ink: #EFE9DC; --sb-nav-current-bg: #EFE9DC; --sb-nav-current-ink: #141311; --sb-nav-accent: #2F4B9E;
    --sb-nav-field-border: #4A463E; --sb-org-badge: #2F4B9E; --sb-org-badge-ink: #FFFFFF; --sb-tab-mark: #9FB3EA;
    --sb-button-2: #26241F; --sb-switch-locked: #8F887A; --sb-loading: #2C2924; --sb-loading-2: #24221E;
    --sb-loading-peg: #3A3730; --sb-scrim: rgb(0 0 0 / 0.7); --sb-wash: rgb(20 19 17 / 0.66); --sb-panel-shadow-color: rgb(0 0 0 / 0.5);
    --toast-shadow: 0 0 0 1px #3A3730, 0 12px 32px rgb(0 0 0 / 0.55); --toast-close-hover: rgb(128 128 128 / 0.25);
    --sb-qr-ground: #FFFFFF;
  }
}

/* --- Everything that does not change with the theme ------------------------ */
:root {
  --font-sans: "Ulgama Sans", "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Ulgama Serif", "EB Garamond", Georgia, "Times New Roman", serif;   /* NEW */
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Type scale. Sans sizes unchanged; serif sizes are NEW and never below 17px. */
  --text-sm: 0.875rem;    /* 15 · meta, tags */
  --text-md: 1rem;        /* 17 · body, fields, buttons */
  --text-lg: 1.0625rem;   /* 18 · card titles (sans, 600) */
  --text-xl: min(1.647rem, 37px);    /* 28 · h2, serif 500; capped at 37 (Text sizes) */
  --text-2xl: min(2.824rem, 63px);   /* 48 · h1, serif 500, tracking -0.01em; cap 63 */
  --text-3xl: min(4.235rem, 90px);   /* 72 · the one big number, serif, tracking -0.02em; cap 90 */
  --text-date: 1.412rem;  /* 24 · the italic date beside h1 */
  --text-stamp: 1.765rem; /* 30 · the day in a date stamp */
  --text-logo: 2.1rem;    /* 36 · the wordmark on the sign-in cover */

  --leading-tight: 1.15;
  --leading-body: 1.5;
  --weight-regular: 400;
  --weight-strong: 600;
  --weight-serif: 500;    /* NEW · serif titles */
  --measure: 66ch;

  /* Space, 4px rhythm */
  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem; --space-4: 1rem;
  --space-5: 1.5rem;  --space-6: 2rem;   --space-7: 3rem;    --space-8: 4rem;

  /* Shape: a bound record, not a toy. */
  --radius-sm: 3px;       /* tags, checkboxes, buttons, fields, cards: ONE radius */
  --radius-md: 3px;
  --radius-lg: 12px;      /* phone sheets only */
  --radius-round: 999px;  /* counts, avatars, PIN keys */
  --border: 1px;
  --border-strong: 2px;
  --rule: 2px solid var(--ink);          /* NEW · the double rule under a page title: */
  --rule-2: 1px solid var(--ink);        /*       border-top: var(--rule); border-bottom: var(--rule-2); height 3px */

  --target: max(44px, 2.7625rem); /* 58 at Large (21px), 47 at Standard */
  --focus-width: 2px;
  --focus-gap: 2px;

  --duration-fast: 120ms; --duration: 200ms; --ease: cubic-bezier(0.2, 0, 0, 1);
  --z-sticky: 10; --z-overlay: 100; --z-toast: 200;

  --sidebar-width: var(--nav); /* 2.0 name, kept for any sheet that still reads it */

  /* --- 3.0 "Shadow board" (D-091) · November 11, 2026 ------------------------------ */
  /* A paper has six looks (3.1 adds "not checked yet"). Its fill sits inside an edge; the
     fills and edges are set per theme above. In grey the states run light to dark: honey,
     sage, terracotta; missing is dashed, not checked yet dotted. */
  --sb-wall-dots: radial-gradient(circle, var(--sb-wall-dot) 1.1px, transparent 1.5px) 0 0 / 12px 12px;
  --sb-peg: 10px;
  --sb-string: 1.5px;
  /* Paper tiles never scale with text (width height). */
  --sb-tile-lg: 44px 56px;  --sb-tile-md: 22px 28px;  --sb-tile-sm: 10px 14px;  --sb-tile-xs: 6px 9px;
  --sb-nav-row: 44px;                         /* 3.1 · a menu row; 58 at Large */
  --sb-dir: 1;                                /* 3.1 · -1 in a right-to-left page: mirrors offsets */

  /* Type: new roles. Paper tiles and strokes never scale with text. */
  --text-count: clamp(46px, 2.706rem, 57px);  /* 46 · the count on the strip */
  --text-count-phone: clamp(38px, 2.235rem, 47px); /* 38 · I2 · the strip's count on a phone */
  --text-count-phone-lg: clamp(52px, 3.06rem, 64px); /* 52 · X1 · Compliance's count on a phone */
  --text-setup: clamp(40px, 2.353rem, 50px);        /* 40 · X1 · a first-run step's title (First run) */
  --text-title: 2rem;                         /* 34 · screen titles, serif 500 */
  --text-date-sm: 1.176rem;                   /* 20 · the date beside a screen title, serif italic */
  --text-paper: 0.941rem;                     /* 16 · a paper's name, sans 600 */
  --text-display: clamp(36px, 2.588rem, 55px); /* 44 · 3.1 · "The wall did not load.", "You can't open …" */
  --text-lede: 1.118rem;                      /* 19 · 3.1 · the sentence under a display title */
  --text-tab: 15px;                           /* 3.1 · tab bar labels: 15 at every text size (the
                                                 system's Large Content Viewer shows them large) */
  --text-code: 1.176rem;                      /* 20 · 3.1 · an error code, mono, read one character at a time */

  /* Sizes */
  --nav: clamp(232px, 13.65rem, 264px);       /* the sidebar */
  --panel: 26rem;                             /* the filing panel: 442 Standard */
  --popover: 22.5rem;                         /* the (?) layer: 383 Standard */

  /* Motion, skipped under reduced motion */
  --sb-hang: 820ms cubic-bezier(0.2, 0.7, 0.3, 1);
  --sb-layer: 200ms ease-out;
}
@media (prefers-reduced-motion: reduce) {
  :root { --duration-fast: 0ms; --duration: 0ms; --sb-hang: 0ms linear; --sb-layer: 0ms linear; }
}

/* Two text sizes, chosen by each person in Me (D-091): Standard 17px, Large 21px. Both are
   relative to the browser's own size, so a reader who has set theirs larger keeps it. */
html { font-size: 106.25%; }
html[data-text-size="large"] { font-size: 131.25%; }
html[data-text-size="large"] { --sb-nav-row: 58px; } /* 3.1: the menu's rows at Large */
/* Right to left: offsets drawn with --sb-dir (the menu's current bar, the panel's shadow) mirror. */
[dir="rtl"] { --sb-dir: -1; }
@supports (font: -apple-system-body) and (-webkit-touch-callout: none) {
  html,
  html[data-text-size="large"] { font: -apple-system-body; } /* a phone follows its own text size */
  /* Dynamic Type: body and controls follow the system size without limit.
     Serif display sizes are capped so a 48px title at AX5 (x2.35) does not
     become 113px and wrap every word: clamp(floor px, rem, ceiling px). */
  :root {
    --text-2xl: clamp(48px, 2.824rem, 63px);     /* h1 */
    --text-xl:  clamp(28px, 1.647rem, 37px);     /* h2 */
    --text-3xl: clamp(72px, 4.235rem, 90px);     /* big number */
    --text-date: clamp(24px, 1.412rem, 32px);
    --text-stamp: clamp(30px, 1.765rem, 39px);
    --text-logo: clamp(36px, 2.1rem, 48px);
    /* The wide gaps and page margins stop at about 1.5 times their size, so at AX sizes the
       width goes to the words (T-18: at AX5 a 1.5rem margin is 80px a side on a 402px phone). */
    --space-4: clamp(16px, 1rem, 24px);
    --space-5: clamp(24px, 1.5rem, 36px);
    --space-6: clamp(32px, 2rem, 48px);
    --space-7: clamp(48px, 3rem, 72px);
    --space-8: clamp(64px, 4rem, 96px);
  }
}
