/* ============================================================================
   DESIGN TOKENS — the single source of truth for colour and rhythm.

   A theme is a complete look: paper, surfaces, text, lines and accent all come
   from one palette. There is no separate accent setting, because an accent
   chosen apart from its surfaces is how a calm room turns loud.

   Families choose light and dark looks; Paper shares Graphite with Silver Mist:

       FAMILY       LIGHT        DARK
       alabaster    Alabaster    Midnight     clean, focused, neutral
       paper        Paper        Graphite     warm, familiar
       silver-mist  Silver Mist  Graphite     cool, clear
       linen        Linen        Grove        calm, contemplative (brand sage)
       ember        Paper        Ember        warm, scholarly

   `:root` carries Alabaster and `:root[data-theme='dark']` carries Midnight —
   the default pair — so the pre-JS paint in index.html lands on real values.
   Neither has a `[data-surface]` block of its own for that reason. The other
   seven do, and they come after the dark block so they win on source order at
   equal specificity.

   Every palette is declared once under two selectors: the document root that
   paints the app, and `[data-theme-preview]`, which lets a settings card draw
   a miniature in a theme the reader is not currently in. Custom properties set
   on an element beat the ones it inherits, so the miniature re-themes without
   the palette being written out a second time.

   Rule: components never hard-code a colour. If a value is missing, add a
   token here rather than reaching for a hex code in a className.
   ========================================================================= */

:root,
[data-theme-preview='alabaster'] {
  /* --- Alabaster: the reference Porcelain palette --- */
  --paper: #fbfbf9;          /* app background            */
  --paper-2: #f2f3f1;        /* sidebar / recessed chrome */
  --surface: #ffffff;        /* cards, drawers, popovers  */
  --surface-2: #f0f1ee;      /* hover / nested surface    */
  --surface-sunk: #f0f1ee;   /* wells, segmented tracks   */
  --settings-surface: #f6f6f3; /* long settings panes     */

  --ink: #252726;            /* primary text              */
  --ink-2: #252726;          /* body copy in panels       */
  --muted: #686e6b;          /* secondary text            */
  --faint: #676f6b;          /* tertiary / metadata       */

  --line: #e2e5e0;           /* default divider           */
  --line-secondary: #e2e5e0; /* quieter, inside a surface */
  --line-strong: #85908a;    /* emphasis, control borders */

  --qr-paper: #ffffff;       /* QR codes are always dark on light, in every theme */
  --qr-ink: #000000;
  --brand-gold: #B8924F;     /* the logo's gold: stem and cross, nothing else */
  --accent: #343b37;
  --accent-hover: #252726;
  --accent-soft: #e4e8e2;
  --accent-line: rgb(52 59 55 / 0.36);
  --accent-ink: #ffffff;     /* text on a filled accent   */

  /* The passage control in the top bar, tinted from the theme's own accent so
     it never reads as one of the workspace tabs beside it. */
  --bible-tab: #e4e8e2;
  --bible-tab-line: rgb(52 59 55 / 0.26);

  --danger: #a5453b;
  --danger-soft: rgb(165 69 59 / 0.1);

  /* Words of Christ in red-letter editions. Deep enough to hold 4.5:1 on every
     light surface, including Paper. */
  --wj: #ad2828;

  /* --- Elevation: soft, never harsh --- */
  --shadow-1: 0 1px 2px rgb(15 18 24 / 0.06), 0 1px 1px rgb(15 18 24 / 0.04);
  --shadow-2: 0 4px 12px rgb(15 18 24 / 0.08), 0 1px 3px rgb(15 18 24 / 0.06);
  --shadow-3: 0 18px 44px rgb(15 18 24 / 0.14), 0 3px 10px rgb(15 18 24 / 0.08);

  /* --- Highlight palette: soft, premium, legible in both themes --- */
  --hl-yellow: #fbe8a0;
  --hl-blue: #d6e6fa;
  --hl-green: #d1eddb;
  --hl-pink: #fbdbe5;
  --hl-purple: #e4dcfa;
  --hl-ink: #15181e;

  /* --- Layout --- */
  --sidebar-w: 15.625rem;    /* 250px default; live value from preferences */
  --sidebar-w-collapsed: 3.875rem; /* 62px */
  --drawer-w: 24rem;         /* 384px */
  --note-panel-w: clamp(23.75rem, 30vw, 28.75rem); /* 380–460px docked note editor */
  --bible-min-w: 45rem;      /* 720px: Scripture is never squeezed below this; BIBLE_MIN_WIDTH */
  --radius-pill: calc(infinity * 1px);
  --mobile-dock-height: 3.5rem;
  --mobile-dock-region: calc(var(--mobile-dock-height) + 0.75rem + env(safe-area-inset-bottom));
  --topbar-h: 3rem;          /* 48px — the Study drawer and note panel headers use this too, so their bottom borders line up with the top bar's */

  /* --- Density: set by [data-density]; chrome reads these, Scripture never
         does, so tightening the interface cannot tighten the text. --- */
  --row-h: 2.25rem;          /* 36px: sidebar rows, list rows */
  --pane-pad-y: 1rem;        /* workspace header rhythm       */
  --card-pad: 0.625rem;      /* library cards                 */

  /* --- Motion --- */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --t-fast: 130ms;
  --t-med: 220ms;
  --t-panel: 280ms;
  --t-exit: var(--t-fast);
  --ease-enter: var(--ease);
  --ease-exit: cubic-bezier(0.4, 0, 1, 1);
  --motion-rise: 8px;
  --motion-sheet: 24px;
  --motion-side: 10px;
  /* Selah Stillness: a slow fade out, so nothing seems to jump. */
  --t-still: 1400ms;

  /* --- Reading typography: bound to UserPreferences at runtime by
         useReadingStyles(). Never set these in a component's style prop. --- */
  --chapter-title-size: clamp(19px, 2.375vw, 21.85px);
  --scrollbar-size: 6px;
  --read-size: 19px;
  --read-leading: 1.75;
  --read-align: left;
  --read-measure: 640px;
  /* Live value from preferences: one of the --font-reader-* stacks below. */
  --read-family: var(--font-reader-classic);

  /* --- Typography roles -------------------------------------------------
     Three jobs, three stacks. The interface never borrows the reader's face,
     and the reader is never offered a face meant for codes or for Greek.
     Every family is self-hosted (see fonts.css); the trailing system names
     are what renders before the file arrives, or if it never does. --- */

  --ui-family: 'Source Sans 3', 'Noto Sans', system-ui, -apple-system,
    BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Reading experiences, chosen in Settings → Reading. */
  --font-reader-classic: 'Noto Serif', Georgia, serif;
  /* Carter's Charter when the reader already has it, XCharter otherwise. */
  --font-reader-book: 'Charter', 'XCharter', 'Noto Serif', Georgia, serif;
  --font-reader-literary: 'EB Garamond', 'Noto Serif', Georgia, serif;
  --font-reader-modern: 'Bitter', 'Noto Serif', Georgia, serif;
  --font-reader-clean: 'Source Sans 3', 'Noto Sans', system-ui, sans-serif;
  --font-reader-accessible: 'OpenDyslexic', 'Noto Sans', sans-serif;

  /* Specialist scripts, applied by language rather than chosen. */
  --font-hebrew: 'Ezra SIL', 'Noto Serif Hebrew', serif;
  --font-greek: 'Gentium Plus', 'Noto Serif', serif;

  /* Technical and linguistic data: Strong's numbers, morphology codes. */
  --font-mono-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas,
    monospace;

  color-scheme: light;
}

/* ---------------------------------------------------------------------------
   Dark: shared ground, plus Midnight — the dark partner of Alabaster above.
   The reference Deep Navy palette: blue-grey paper with a pale accent.
   ------------------------------------------------------------------------- */
:root[data-theme='dark'],
[data-theme-preview='midnight'] {
  --paper: #1d2731;
  --paper-2: #18212a;
  --surface: #293641;
  --surface-2: #344553;
  --surface-sunk: #2b3945;
  --settings-surface: #26323d;

  --ink: #f2f4f6;
  --ink-2: #f2f4f6;
  --muted: #b1bec9;
  --faint: #a5b4c1;

  --line: #3a4753;
  --line-secondary: #3a4753;
  --line-strong: #a5b4c1;

  --accent: #dbe6ef;
  --accent-hover: #f2f4f6;
  --accent-soft: #334653;
  --accent-line: rgb(219 230 239 / 0.42);
  --accent-ink: #17212b;

  --bible-tab: #334653;
  --bible-tab-line: rgb(219 230 239 / 0.3);

  --danger: #e08078;
  --danger-soft: rgb(224 128 120 / 0.14);

  --wj: #f87171;

  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.34);
  --shadow-2: 0 4px 14px rgb(0 0 0 / 0.4);
  --shadow-3: 0 20px 48px rgb(0 0 0 / 0.55), 0 3px 10px rgb(0 0 0 / 0.35);

  /* Highlights are re-mixed, not merely dimmed: pastel washes on a dark
     ground fail contrast, so each becomes a saturated low-luminance field. */
  --hl-yellow: #6a5c2c;
  --hl-blue: #2f4a66;
  --hl-green: #325141;
  --hl-pink: #6a3b48;
  --hl-purple: #4a3e68;
  --hl-ink: #f2ece2;

  color-scheme: dark;
}

/* --------------------------------------------------------------- LIGHT ---- */

/* Paper: the reference Warm Paper palette. */
:root[data-surface='paper'],
[data-theme-preview='paper'] {
  --paper: #f7f3eb;
  --paper-2: #f0ebe2;
  --surface: #fcf9f3;
  --surface-2: #f2ebdf;
  --surface-sunk: #f2ebdf;
  --settings-surface: #fbf7f0;

  --ink: #302d29;
  --ink-2: #302d29;
  --muted: #71695e;
  --faint: #73685c;

  --line: #e3dbcf;
  --line-secondary: #e3dbcf;
  --line-strong: #928474;

  --accent: #514334;
  --accent-hover: #302d29;
  --accent-soft: #eae0d1;
  --accent-line: rgb(81 67 52 / 0.36);
  --accent-ink: #ffffff;

  --bible-tab: #eae0d1;
  --bible-tab-line: rgb(81 67 52 / 0.26);
  --wj: #9c2727;
}

/* Silver Mist: cool, clear paper from the sample app. */
:root[data-surface='silver-mist'],
[data-theme-preview='silver-mist'] {
  --paper: #f0f2f4;
  --paper-2: #e7eaed;
  --surface: #ffffff;
  --surface-2: #e9edf0;
  --surface-sunk: #e9edf0;
  --settings-surface: #f7f8fa;

  --ink: #273039;
  --ink-2: #273039;
  --muted: #5f6a73;
  --faint: #5d6a75;

  --line: #dce0e4;
  --line-secondary: #dce0e4;
  --line-strong: #7e8e99;

  --accent: #354553;
  --accent-hover: #273039;
  --accent-soft: #dce4ea;
  --accent-line: rgb(53 69 83 / 0.36);
  --accent-ink: #ffffff;

  --bible-tab: #dce4ea;
  --bible-tab-line: rgb(53 69 83 / 0.26);
  --wj: #ad2828;
}

/* Linen: calm and contemplative. Closest to Buckler's own sage identity. */
:root[data-surface='linen'],
[data-theme-preview='linen'] {
  --paper: #f3f5f0;
  --paper-2: #ebeee7;
  --surface: #f8faf6;
  --surface-2: #eef1ea;
  --surface-sunk: #dfe5dc;
  --settings-surface: #f5f7f3;

  --ink: #252a24;
  --ink-2: #3c433b;
  --muted: #5f675d;
  --faint: #60675e;

  --line: #d9ded6;
  --line-secondary: #e4e8e1;
  --line-strong: #7c927a;

  --accent: #4d6a4b;
  --accent-hover: #3d563c;
  --accent-soft: rgb(77 106 75 / 0.12);
  --accent-line: rgb(77 106 75 / 0.38);
  --accent-ink: #ffffff;

  --bible-tab: rgb(77 106 75 / 0.08);
  --bible-tab-line: rgb(77 106 75 / 0.3);
}

/* ---------------------------------------------------------------- DARK ---- */

/* Graphite: soft neutral charcoal from the sample app. */
:root[data-surface='graphite'],
[data-theme-preview='graphite'] {
  --paper: #292d30;
  --paper-2: #222629;
  --surface: #373c3f;
  --surface-2: #42494d;
  --surface-sunk: #363c3f;
  --settings-surface: #32373a;

  --ink: #f5f5f2;
  --ink-2: #f5f5f2;
  --muted: #b2babd;
  --faint: #afb9bc;

  --line: #42484c;
  --line-secondary: #42484c;
  --line-strong: #a8b3b7;

  --accent: #e3e7e7;
  --accent-hover: #f5f5f2;
  --accent-soft: #3e484b;
  --accent-line: rgb(227 231 231 / 0.42);
  --accent-ink: #222629;

  --bible-tab: #3e484b;
  --bible-tab-line: rgb(227 231 231 / 0.3);
  --wj: #f87171;
}

/* Grove: quiet and contemplative. Deep, desaturated forest. */
:root[data-surface='grove'],
[data-theme-preview='grove'] {
  --paper: #151b16;
  --paper-2: #101510;
  --surface: #1c241e;
  --surface-2: #273229;
  --surface-sunk: #273229;
  --settings-surface: #19211b;

  --ink: #e2e8e1;
  --ink-2: #c8d1c7;
  --muted: #9ca99b;
  --faint: #8f9c8e;

  --line: #303b32;
  --line-secondary: #273129;
  --line-strong: #637b64;

  --accent: #8aa887;
  --accent-hover: #a2bc9f;
  --accent-soft: rgb(138 168 135 / 0.16);
  --accent-line: rgb(138 168 135 / 0.42);
  --accent-ink: #151b16;

  --bible-tab: rgb(138 168 135 / 0.1);
  --bible-tab-line: rgb(138 168 135 / 0.3);
}

/* Ember: warm and scholarly after dark. Brown-charcoal, muted copper. */
:root[data-surface='ember'],
[data-theme-preview='ember'] {
  --paper: #1d1713;
  --paper-2: #171210;
  --surface: #271f19;
  --surface-2: #332820;
  --surface-sunk: #332820;
  --settings-surface: #231c17;

  --ink: #eadfd3;
  --ink-2: #d2c5b7;
  --muted: #aa9989;
  --faint: #a08f7f;

  --line: #3d3128;
  --line-secondary: #342a23;
  --line-strong: #8d6849;

  --accent: #c98b55;
  --accent-hover: #dda068;
  --accent-soft: rgb(201 139 85 / 0.16);
  --accent-line: rgb(201 139 85 / 0.42);
  --accent-ink: #1d1713;

  --bible-tab: rgb(201 139 85 / 0.1);
  --bible-tab-line: rgb(201 139 85 / 0.3);
}

/* --------------------------------------------------------------------------
   Density. Comfortable is the default declared on :root; Compact tightens the
   interface chrome only.
   ------------------------------------------------------------------------ */
:root[data-density='compact'] {
  --row-h: 2rem;             /* 32px */
  --pane-pad-y: 0.75rem;
  --card-pad: 0.5rem;
  --topbar-h: 2.75rem;       /* 44px */
}

/* Reduced motion keeps short fades and removes spatial movement. OS reduction
   is a ceiling even when Standard is selected. None has no nonessential motion. */
:root[data-motion='reduced'], :root[data-reduce-motion='true']:not([data-motion='none']) {
  --t-fast: 100ms; --t-med: 100ms; --t-panel: 100ms; --t-still: 100ms;
  --motion-rise: 0px; --motion-sheet: 0px; --motion-side: 0px;
}
@media (prefers-reduced-motion: reduce) {
  :root {
    --t-fast: 100ms; --t-med: 100ms; --t-panel: 100ms; --t-still: 100ms;
    --motion-rise: 0px; --motion-sheet: 0px; --motion-side: 0px;
  }
}
:root[data-motion='none'] {
  --t-fast: 0ms; --t-med: 0ms; --t-panel: 0ms; --t-still: 0ms;
  --motion-rise: 0px; --motion-sheet: 0px; --motion-side: 0px;
}

/* ============================================================================
   HIGH CONTRAST — an accessibility modifier, not a ninth and tenth theme.

   `data-contrast="high"` layers over whichever theme is painted, strengthening
   the semantic tokens that carry meaning: text, lines, and the accent that
   draws focus rings and selected states. Paper and surface are left alone, so
   Linen still reads sage and Paper still reads warm — the identity the
   reader chose survives, it simply separates better.

   Highlights (--hl-*) are deliberately untouched. They are the reader's own
   annotations, not chrome, and recolouring them would overwrite meaning.

   Each block pairs with its theme's selector so source order and specificity
   match the theme blocks above.
   ========================================================================= */

/* --- Alabaster (and the light default) ----------------------------------- */
:root[data-contrast='high'] {
  --wj: #7f0c04;
  --ink: #000000;
  --ink-2: #1a1a1a;
  --muted: #3d3d3d;
  --faint: #4d4d4d;

  --line: #8a8d93;
  --line-secondary: #a8abb0;
  --line-strong: #3f3f3f;

  --accent: #1a1a1a;
  --accent-hover: #000000;
  --accent-soft: rgb(0 0 0 / 0.14);
  --accent-line: rgb(0 0 0 / 0.6);

  --bible-tab: rgb(0 0 0 / 0.08);
  --bible-tab-line: rgb(0 0 0 / 0.5);
}

/* --- Midnight (and the dark default) ------------------------------------- */
:root[data-theme='dark'][data-contrast='high'] {
  --wj: #ff9d93;
  --ink: #ffffff;
  --ink-2: #e8ecf2;
  --muted: #c3cbd6;
  --faint: #b4bdca;

  --line: #6a7a92;
  --line-secondary: #566579;
  --line-strong: #9fb0c6;

  --accent: #cdd7e6;
  --accent-hover: #eef2f8;
  --accent-soft: rgb(205 215 230 / 0.22);
  --accent-line: rgb(205 215 230 / 0.65);
  --accent-ink: #0b1220;

  --bible-tab: rgb(205 215 230 / 0.16);
  --bible-tab-line: rgb(205 215 230 / 0.55);
}

/* --- Light themes -------------------------------------------------------- */
:root[data-surface='paper'][data-contrast='high'] {
  --ink: #15110a;
  --ink-2: #2a241a;
  --muted: #4a4336;
  --faint: #574f41;

  --line: #9a8f79;
  --line-secondary: #b5aa95;
  --line-strong: #6b6252;

  --accent: #5e3a16;
  --accent-hover: #472b10;
  --accent-soft: rgb(94 58 22 / 0.18);
  --accent-line: rgb(94 58 22 / 0.6);

  --bible-tab: rgb(94 58 22 / 0.12);
  --bible-tab-line: rgb(94 58 22 / 0.5);
}

:root[data-surface='silver-mist'][data-contrast='high'] {
  --ink: #131b22;
  --ink-2: #24313b;
  --muted: #43515c;
  --faint: #52616c;

  --line: #82909b;
  --line-secondary: #a2adb5;
  --line-strong: #405360;

  --accent: #263846;
  --accent-hover: #182833;
  --accent-soft: rgb(38 56 70 / 0.18);
  --accent-line: rgb(38 56 70 / 0.6);

  --bible-tab: rgb(38 56 70 / 0.12);
  --bible-tab-line: rgb(38 56 70 / 0.5);
}

:root[data-surface='linen'][data-contrast='high'] {
  --ink: #0f140e;
  --ink-2: #232a22;
  --muted: #434a41;
  --faint: #4f574d;

  --line: #8a9286;
  --line-secondary: #a8b0a4;
  --line-strong: #4d6a4b;

  --accent: #2f4a2d;
  --accent-hover: #223821;
  --accent-soft: rgb(47 74 45 / 0.18);
  --accent-line: rgb(47 74 45 / 0.6);

  --bible-tab: rgb(47 74 45 / 0.12);
  --bible-tab-line: rgb(47 74 45 / 0.5);
}


/* --- Dark themes --------------------------------------------------------- */
:root[data-surface='graphite'][data-contrast='high'] {
  --ink: #ffffff;
  --ink-2: #ebebeb;
  --muted: #c9c9c9;
  --faint: #bababa;

  --line: #6e6a64;
  --line-secondary: #57534e;
  --line-strong: #9c958b;

  --accent: #f0f4f4;
  --accent-hover: #ffffff;
  --accent-soft: rgb(240 244 244 / 0.22);
  --accent-line: rgb(240 244 244 / 0.65);
  --accent-ink: #222629;

  --bible-tab: rgb(240 244 244 / 0.16);
  --bible-tab-line: rgb(240 244 244 / 0.55);
}

:root[data-surface='grove'][data-contrast='high'] {
  --ink: #f4f8f3;
  --ink-2: #e0e8df;
  --muted: #bcc8ba;
  --faint: #adbaab;

  --line: #5f7060;
  --line-secondary: #47554a;
  --line-strong: #90a890;

  --accent: #b2cdaf;
  --accent-hover: #cde6ca;
  --accent-soft: rgb(178 205 175 / 0.22);
  --accent-line: rgb(178 205 175 / 0.65);
  --accent-ink: #0e1410;

  --bible-tab: rgb(178 205 175 / 0.16);
  --bible-tab-line: rgb(178 205 175 / 0.55);
}

:root[data-surface='ember'][data-contrast='high'] {
  --ink: #fbf3ea;
  --ink-2: #ece0d2;
  --muted: #cbb9a6;
  --faint: #bcaa97;

  --line: #796758;
  --line-secondary: #58483a;
  --line-strong: #ab8663;

  --accent: #e3a76e;
  --accent-hover: #f2bd87;
  --accent-soft: rgb(227 167 110 / 0.22);
  --accent-line: rgb(227 167 110 / 0.65);
  --accent-ink: #17110c;

  --bible-tab: rgb(227 167 110 / 0.16);
  --bible-tab-line: rgb(227 167 110 / 0.55);
}
