/* SkipTo — design tokens
   Direction C · Proofreader's caret
   Two separate layers:
     1. Interface (--ui-*): chrome, library, sheets. Carries the brand.
     2. Reading themes (--page-*): the book page. Never carries the brand accent.
   Contrast ratios for every text pair are listed in handoff.md §6. */

/* ---------- Fonts (bundled, SIL OFL 1.1, see assets/LICENSES.md) ----------
   "SkipTo UI Sans" is IBM Plex Sans, subset and renamed as required by its
   Reserved Font Name "Plex". Spectral has no reserved name. */
@font-face { font-family: "Spectral"; src: url("../assets/fonts/Spectral-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Spectral"; src: url("../assets/fonts/Spectral-Italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Spectral"; src: url("../assets/fonts/Spectral-Medium.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Spectral"; src: url("../assets/fonts/Spectral-SemiBold.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "SkipTo UI Sans"; src: url("../assets/fonts/SkipToUISans-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "SkipTo UI Sans"; src: url("../assets/fonts/SkipToUISans-Medium.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "SkipTo UI Sans"; src: url("../assets/fonts/SkipToUISans-SemiBold.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }

:root {
  /* ---------- Brand constants (logo artwork only) ---------- */
  --brand-ink: #26221C;
  --brand-paper: #F2ECDF;
  --brand-ochre: #8A5513;          /* caret on light grounds */
  --brand-ochre-on-dark: #E0A85A;  /* caret on dark grounds */

  /* ---------- Interface · light (default) ---------- */
  --ui-bg: #F6F2EA;
  --ui-surface: #FFFDF8;           /* cards, sheets, popovers */
  --ui-surface-2: #EFE9DD;         /* segmented tracks, pressed, table heads */
  --ui-text: #26221C;              /* 14.2:1 on bg */
  --ui-text-muted: #5E564A;        /* 6.5:1 on bg, 6.0:1 on surface-2 */
  --ui-border: #E0D7C6;            /* decorative dividers only */
  --ui-border-strong: #8E8270;     /* control boundaries, 3.4:1+ */
  --ui-accent: #8A5513;            /* links, active state, progress, focus */
  --ui-accent-contrast: #FFFDF8;
  --ui-primary-bg: #26221C;        /* the one primary button per view */
  --ui-primary-text: #F6F2EA;
  --ui-focus: #8A5513;
  --ui-danger: #A3321F;
  --ui-success: #2F6B3A;
  --ui-scrim: rgba(23, 20, 15, 0.32);
  --ui-shadow: 0 12px 32px rgba(38, 34, 28, 0.14), 0 1px 3px rgba(38, 34, 28, 0.08);

  /* ---------- Reading theme · light (default) ---------- */
  --page-bg: #FCFBF8;
  --page-text: #1F1C17;            /* 16.4:1 */
  --page-muted: #5E564A;           /* running heads, folios: 7.0:1 */
  --page-link: #2A5A86;            /* in-book links, always underlined */
  --page-rule: #D9D2C4;
  --page-selection: rgba(42, 90, 134, 0.22);
  --page-highlight-1: rgba(224, 168, 90, 0.40);   /* "Amber" + solid underline */
  --page-highlight-2: rgba(95, 150, 110, 0.32);   /* "Sage"  + dotted underline */
  --page-highlight-3: rgba(110, 135, 190, 0.30);  /* "Blue"  + dashed underline */

  /* ---------- Typography ---------- */
  --font-ui: "SkipTo UI Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  --font-book: "Spectral", "Iowan Old Style", Charter, "Noto Serif", Georgia, "Times New Roman", serif;
  --font-book-sans: "SkipTo UI Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --text-xs: 0.75rem;    /* 12 — captions only, never interactive labels */
  --text-sm: 0.875rem;   /* 14 */
  --text-md: 1rem;       /* 16 — default UI text */
  --text-lg: 1.125rem;   /* 18 */
  --text-xl: 1.375rem;   /* 22 */
  --text-2xl: 1.75rem;   /* 28 */
  --text-3xl: 2.25rem;   /* 36 */
  --leading-ui: 1.45;
  --leading-tight: 1.2;

  /* Book defaults (user-adjustable; these are the starting values) */
  --book-size: 1.1875rem;     /* 19px at 100% zoom; phone default 18px */
  --book-leading: 1.6;
  --book-measure: 30em;       /* ≈ 66–70 characters of Spectral; user “wide” max 34em */
  --book-margin-inline: clamp(1.25rem, 6vw, 3.5rem);
  --book-paragraph-indent: 1.4em;

  /* ---------- Space (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;

  /* ---------- Shape & stroke ---------- */
  --radius-sm: 6px;     /* chips, inputs inside groups */
  --radius-md: 8px;     /* buttons, inputs */
  --radius-lg: 12px;    /* cards, popovers */
  --radius-sheet: 20px; /* top corners of phone sheets */
  --radius-pill: 999px;
  --stroke-hairline: 1px;
  --stroke-focus: 2px;
  --focus-offset: 2px;
  --icon-stroke: 1.75;
  --icon-size: 1.25rem;

  /* ---------- Sizing ---------- */
  --target-min: 44px;           /* touch/pointer target minimum */
  --bar-height: 56px;           /* reader top bar */
  --sheet-max-height: 90dvh;
  --popover-width: 22.5rem;     /* 360px */

  /* ---------- Motion ---------- */
  --dur-instant: 80ms;
  --dur-fast: 140ms;            /* controls fade */
  --dur-base: 220ms;            /* sheets, popovers */
  --dur-page: 260ms;            /* page turn (fade/slide), optional */
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-exit: cubic-bezier(0.4, 0, 1, 1);

  /* ---------- Layers ---------- */
  --z-page: 0; --z-bars: 10; --z-pill: 20; --z-sheet: 30; --z-dialog: 40; --z-toast: 50;

  color-scheme: light;
}

/* ---------- Interface · dark (follows device unless data-ui forces) ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-ui="light"]) {
    --ui-bg: #17140F; --ui-surface: #221E18; --ui-surface-2: #2C271F;
    --ui-text: #EFE8DA; --ui-text-muted: #ADA493;
    --ui-border: #3A342B; --ui-border-strong: #7D7362;
    --ui-accent: #E0A85A; --ui-accent-contrast: #17140F;
    --ui-primary-bg: #EFE8DA; --ui-primary-text: #17140F;
    --ui-focus: #E0A85A; --ui-danger: #F08A74; --ui-success: #8CC79A;
    --ui-scrim: rgba(0, 0, 0, 0.5);
    --ui-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}
:root[data-ui="dark"] {
  --ui-bg: #17140F; --ui-surface: #221E18; --ui-surface-2: #2C271F;
  --ui-text: #EFE8DA; --ui-text-muted: #ADA493;
  --ui-border: #3A342B; --ui-border-strong: #7D7362;
  --ui-accent: #E0A85A; --ui-accent-contrast: #17140F;
  --ui-primary-bg: #EFE8DA; --ui-primary-text: #17140F;
  --ui-focus: #E0A85A; --ui-danger: #F08A74; --ui-success: #8CC79A;
  --ui-scrim: rgba(0, 0, 0, 0.5);
  --ui-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

/* ---------- Reading themes (set on .reader via data-reading) ---------- */
[data-reading="warm"] {
  --page-bg: #F4ECD8; --page-text: #3A2F22; --page-muted: #6B5A45;
  --page-link: #6A3E12; --page-rule: #DCCFAF;
  --page-selection: rgba(106, 62, 18, 0.20);
}
[data-reading="dark"] {
  --page-bg: #121110; --page-text: #D8D2C6; --page-muted: #A39C90;
  --page-link: #9DB8D9; --page-rule: #34302A;
  --page-selection: rgba(157, 184, 217, 0.28);
  --page-highlight-1: rgba(224, 168, 90, 0.30);
  --page-highlight-2: rgba(140, 199, 154, 0.24);
  --page-highlight-3: rgba(157, 184, 217, 0.26);
  /* Reader chrome over a dark page is always dark, even if the device UI is light,
     so revealing controls never flashes a bright bar. */
  --ui-bg: #17140F; --ui-surface: #221E18; --ui-surface-2: #2C271F;
  --ui-text: #EFE8DA; --ui-text-muted: #ADA493;
  --ui-border: #3A342B; --ui-border-strong: #7D7362;
  --ui-accent: #E0A85A; --ui-accent-contrast: #17140F;
  --ui-primary-bg: #EFE8DA; --ui-primary-text: #17140F;
  --ui-focus: #E0A85A; --ui-danger: #F08A74; --ui-success: #8CC79A;
  --ui-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}
/* Light/warm page while the device UI is dark: chrome follows the page (light). */
[data-reading="light"], [data-reading="warm"] {
  --ui-bg: #F6F2EA; --ui-surface: #FFFDF8; --ui-surface-2: #EFE9DD;
  --ui-text: #26221C; --ui-text-muted: #5E564A;
  --ui-border: #E0D7C6; --ui-border-strong: #8E8270;
  --ui-accent: #8A5513; --ui-accent-contrast: #FFFDF8;
  --ui-primary-bg: #26221C; --ui-primary-text: #F6F2EA;
  --ui-focus: #8A5513; --ui-danger: #A3321F; --ui-success: #2F6B3A;
  color-scheme: light;
}
[data-reading="warm"] { --ui-surface: #FBF5E6; --ui-bg: #EFE5CC; --ui-surface-2: #E8DDC3; }

/* Phone default book size */
@media (max-width: 599px) { :root { --book-size: 1.125rem; } }

/* Reduced motion: no slides, no fades longer than a blink */
@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur-base: 0ms; --dur-page: 0ms; }
}
