/* @pivotal/ui-theme — tokens.css
 *
 * One :root schema (PLAN.md 6.5) and the presets as [data-theme="<id>"] blocks.
 * Load this file, then fonts.css, then the app's own stylesheet.
 *
 * Groups: surfaces, ink, states, highlights, type, shape, zman — plus the legacy
 * aliases (--hfont --cfont --tfont --targ --tabbg and the dark family's --fg --card
 * --card2 --bg2 --dim --gold2 --serif) so a legacy stylesheet keeps working unchanged.
 *
 * Default = klaf (the parchment light of zohar/tehillim/shulchan). Without data-theme
 * and with the OS in dark mode = layla (the parchment dark). The preset blocks apply
 * to any element, so a subtree can carry its own theme (see demo/).
 *
 * --texture and --ornament are hooks: `none` today; a preset may later set an image.
 * Tokens are listed in index.js (`tokens()`); test/tokens.test.mjs keeps this file,
 * PLAN.md and index.js in agreement.
 */

/* ---------------------------------------------------------------------------
 * 1. Schema and default: קלף / klaf — the current parchment light.
 *    Colours identical to zohar/public/style.css :root (also tehillim).
 * ------------------------------------------------------------------------- */
:root, [data-theme="klaf"], [data-theme="light"] {
  color-scheme: light;

  /* surfaces */
  --bg: #f7f1e3;
  --paper: #fbf7ec;
  --paper-2: #efe5cd;
  --line: #e4dac3;
  --rule: #d2c29b;
  --shadow: 0 1px 3px #0002;
  --texture: none;

  /* ink */
  --ink: #1d1a14;
  --ink-2: #4a4132;
  --mute: #8a7f6a;
  --faint: #b9ae98;
  --accent: #7a3e12;
  --accent-2: #2f6b4f;
  --gold: #9a6b12;

  /* states */
  --ok: #2f6b4f;
  --warn: #b0701c;
  --bad: #b3263e;
  --mark: #f1d98c66;
  --chipbg: #efe5cd;

  /* highlights (translucent, so they sit on any paper) */
  --hl-chidush: #f1d98c80;
  --hl-kushya: #e9b1b680;
  --hl-halacha: #bcd9c280;
  --hl-dvar: #b8cde980;

  /* type */
  --f-ui: -apple-system, 'Segoe UI', Roboto, 'Noto Sans Hebrew', sans-serif;
  --f-he: 'Taamey Frank', 'Noto Serif Hebrew', 'Times New Roman', serif;
  --f-text: var(--f-he);
  --f-rashi: 'Noto Rashi Hebrew', var(--f-he);
  --f-display: 'Frank Ruhl Libre', var(--f-he);
  --f-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --fs: 23px;
  --lh: 1.85;
  --measure: 34em;

  /* shape */
  --radius: 12px;
  --radius-sm: 6px;
  --gutter: 16px;
  --ornament: none;

  /* zman */
  --day: #c97a1c;
  --night: #5a4a9e;

  /* legacy aliases — the parchment family (zohar, shulchan, tehillim, mishnayot…) */
  --hfont: var(--f-he);
  --cfont: var(--f-text);
  --tfont: var(--f-text);
  --targ: var(--accent-2);
  --tabbg: color-mix(in srgb, var(--bg) 93%, transparent);

  /* legacy aliases — the dark family (zmanim, meah-shearim, maasiyot) */
  --fg: var(--ink);
  --card: var(--paper);
  --card2: var(--paper-2);
  --bg2: var(--paper-2);
  --dim: var(--ink-2);
  --gold2: color-mix(in srgb, var(--gold) 70%, white);
  --serif: var(--f-display);
}

/* ---------------------------------------------------------------------------
 * 2. OS fallback: no data-theme and the OS prefers dark = layla.
 *    (Identical to the [data-theme="layla"] block below; the test checks it.)
 * ------------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #16130f; --paper: #1d1914; --paper-2: #2a241b; --line: #332c22; --rule: #4a3f2c;
    --shadow: 0 1px 3px #0006; --texture: none;
    --ink: #ece3cf; --ink-2: #c9bea4; --mute: #9c907a; --faint: #6b6252;
    --accent: #e3a066; --accent-2: #8cc9a8; --gold: #d8a948;
    --ok: #8cc9a8; --warn: #e0a95a; --bad: #e07a8a; --mark: #6b551f66; --chipbg: #2a241b;
    --hl-chidush: #6b551f99; --hl-kushya: #6b2f3a99; --hl-halacha: #2f5a4099; --hl-dvar: #2f466b99;
    --day: #f0932b; --night: #9b6bff;
  }
}

/* ---------------------------------------------------------------------------
 * 3. Presets. Each sets color-scheme and every colour token; type and shape
 *    tokens are inherited from :root unless the preset changes them.
 * ------------------------------------------------------------------------- */

/* לילה / layla — the current parchment dark (zohar/tehillim data-theme="dark"). */
[data-theme="layla"], [data-theme="dark"] {
  color-scheme: dark;
  --bg: #16130f; --paper: #1d1914; --paper-2: #2a241b; --line: #332c22; --rule: #4a3f2c;
  --shadow: 0 1px 3px #0006; --texture: none;
  --ink: #ece3cf; --ink-2: #c9bea4; --mute: #9c907a; --faint: #6b6252;
  --accent: #e3a066; --accent-2: #8cc9a8; --gold: #d8a948;
  --ok: #8cc9a8; --warn: #e0a95a; --bad: #e07a8a; --mark: #6b551f66; --chipbg: #2a241b;
  --hl-chidush: #6b551f99; --hl-kushya: #6b2f3a99; --hl-halacha: #2f5a4099; --hl-dvar: #2f466b99;
  --day: #f0932b; --night: #9b6bff;
}

/* ספר / sefer — the printed page: warm white, black ink, red rubrics, thin double rules. */
[data-theme="sefer"] {
  color-scheme: light;
  --bg: #f3efe6; --paper: #fffdf8; --paper-2: #f1ece0; --line: #ddd6c6; --rule: #6b6256;
  --shadow: 0 1px 2px #0001; --texture: none;
  --ink: #141210; --ink-2: #3b3630; --mute: #746c60; --faint: #aaa295;
  --accent: #9b1c1c; --accent-2: #2d5a3f; --gold: #8a6a1f;
  --ok: #2d6a3f; --warn: #a8611a; --bad: #9b1c1c; --mark: #f3e3a866; --chipbg: #f1ece0;
  --hl-chidush: #f3e3a880; --hl-kushya: #f0b9b980; --hl-halacha: #c3dcc580; --hl-dvar: #c2d3ec80;
  --day: #b8651a; --night: #4a4680;
  --radius: 4px; --radius-sm: 2px;
}

/* בית מדרש / beit-midrash — warm wood and cream, heavier type for long sessions. */
[data-theme="beit-midrash"] {
  color-scheme: light;
  --bg: #d9c3a0; --paper: #f6eedc; --paper-2: #ead9bb; --line: #c7ad85; --rule: #8a6238;
  --shadow: 0 2px 6px #4a30181a; --texture: none;
  --ink: #2a1d12; --ink-2: #4e3a26; --mute: #7f6447; --faint: #b09a7c;
  --accent: #7c3a1d; --accent-2: #3f6b3a; --gold: #a8792a;
  --ok: #3f6b3a; --warn: #b26a1e; --bad: #9f2f3c; --mark: #e9c57066; --chipbg: #ead9bb;
  --hl-chidush: #e9c57080; --hl-kushya: #e0a8a380; --hl-halacha: #b9d1ad80; --hl-dvar: #b7c7df80;
  --day: #c76f1a; --night: #4f4b8f;
  --fs: 25px; --lh: 1.9;
}

/* תכלת / tchelet — Jerusalem stone with a tchelet accent; the brightest and most modern. */
[data-theme="tchelet"] {
  color-scheme: light;
  --bg: #ebe6dc; --paper: #f7f4ee; --paper-2: #e3ded2; --line: #d3ccbd; --rule: #a79e8c;
  --shadow: 0 1px 4px #1c223014; --texture: none;
  --ink: #1c2230; --ink-2: #3a4254; --mute: #6f7585; --faint: #a4a9b5;
  --accent: #1f5f9e; --accent-2: #0e7c86; --gold: #a8862a;
  --ok: #2e7d4f; --warn: #b56d1d; --bad: #b23a48; --mark: #bcd6ef66; --chipbg: #e3ded2;
  --hl-chidush: #f0dca080; --hl-kushya: #efb6bc80; --hl-halacha: #b9dccb80; --hl-dvar: #b5d1f080;
  --day: #e0821f; --night: #3d5fb8;
  --fs: 22px; --radius: 10px; --radius-sm: 5px;
}

/* נגיש / nagish — high contrast, large type and spacing, no texture, no ornament, no shadow. */
[data-theme="nagish"] {
  color-scheme: light;
  --bg: #ffffff; --paper: #ffffff; --paper-2: #f2f2f2; --line: #000000; --rule: #000000;
  --shadow: none; --texture: none;
  --ink: #000000; --ink-2: #000000; --mute: #333333; --faint: #555555;
  --accent: #0000c8; --accent-2: #006400; --gold: #6b4e00;
  --ok: #006400; --warn: #7a4500; --bad: #b00000; --mark: #ffee0099; --chipbg: #f2f2f2;
  --hl-chidush: #ffe680; --hl-kushya: #ffb3b3; --hl-halacha: #b3e6b3; --hl-dvar: #b3ccff;
  --day: #8a4b00; --night: #2c2c8a;
  --fs: 28px; --lh: 2; --radius: 6px; --radius-sm: 3px; --gutter: 20px; --ornament: none;
}

/* legacy-navy — zmanim / meah-shearim: dark navy and gold. Ships for one release, then retires. */
[data-theme="legacy-navy"] {
  color-scheme: dark;
  --bg: #10142a; --paper: #1e2446; --paper-2: #171c38; --line: #2c3462; --rule: #3a4478;
  --shadow: 0 1px 3px #0008; --texture: none;
  --ink: #eef0fa; --ink-2: #c8cde6; --mute: #9aa2c8; --faint: #6a7299;
  --accent: #e8be5c; --accent-2: #5fd39a; --gold: #e8be5c;
  --ok: #5fd39a; --warn: #f0a35b; --bad: #ef6b7b; --mark: #e8be5c33; --chipbg: #171c38;
  --hl-chidush: #6b551f99; --hl-kushya: #6b2f3a99; --hl-halacha: #2f5a4099; --hl-dvar: #2f466b99;
  --day: #f0932b; --night: #9b6bff;
  --radius: 16px; --radius-sm: 10px;
  --f-ui: -apple-system, 'Segoe UI', Rubik, Arial, sans-serif;
  --f-display: 'Frank Ruhl Libre', 'Times New Roman', 'David', serif;
}

/* legacy-brown — maasiyot: dark brown and gold. Ships for one release, then retires. */
[data-theme="legacy-brown"] {
  color-scheme: dark;
  --bg: #15110d; --paper: #1f1a14; --paper-2: #2a231b; --line: #3a3026; --rule: #4e4030;
  --shadow: 0 1px 3px #0008; --texture: none;
  --ink: #efe6d6; --ink-2: #b4a790; --mute: #b4a790; --faint: #7e735f;
  --accent: #d9a441; --accent-2: #6cc28a; --gold: #d9a441;
  --ok: #6cc28a; --warn: #e0a35b; --bad: #e0607a; --mark: #d9a44133; --chipbg: #2a231b;
  --hl-chidush: #6b551f99; --hl-kushya: #6b2f3a99; --hl-halacha: #2f5a4099; --hl-dvar: #2f466b99;
  --day: #f0932b; --night: #9b6bff;
  --radius: 16px; --radius-sm: 10px;
  --f-ui: -apple-system, 'Segoe UI', Rubik, Arial, sans-serif;
  --f-display: 'Frank Ruhl Libre', 'Times New Roman', 'David', serif;
}
