/* ==========================================================================
   Glossator — Design Tokens
   Colors, Typography, Spacing, Radii, Shadows, Motion
   ==========================================================================
   Source of truth for all CSS custom properties used across the project.
   Mirror this file into prototype/static/design-tokens.css and platform CSS.
   ========================================================================== */

/* Fonts: self-hosted (no external CDN — anti-tracking posture, brief §13).
   Variable WOFF2 files served from /static/fonts/ via FastAPI StaticFiles.
   - Source Serif 4 (Adobe, OFL) : long-form reading + display ; opsz 8..60, wght 200..900
   - Public Sans (USWDS, OFL)    : utilitarian sans for chrome     ; wght 300..800
   - JetBrains Mono (OFL)        : editorial mono for codes/IDs    ; wght 400..700
*/
@font-face {
  font-family: 'Source Serif 4';
  src: url('/static/fonts/SourceSerif4Variable-Roman.ttf.woff2') format('woff2-variations');
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Source Serif 4';
  src: url('/static/fonts/SourceSerif4Variable-Italic.ttf.woff2') format('woff2-variations');
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Public Sans';
  src: url('/static/fonts/PublicSans-Variable.woff2') format('woff2-variations');
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Public Sans';
  src: url('/static/fonts/PublicSans-Italic-Variable.woff2') format('woff2-variations');
  font-weight: 300 800;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/static/fonts/JetBrainsMono-Variable.woff2') format('woff2-variations');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/static/fonts/JetBrainsMono-Italic-Variable.woff2') format('woff2-variations');
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}

:root {
  /* ---------- Color: paper & ink (light mode default) ---------- */
  --paper:        #F4EEE2;   /* warm cream — book paper */
  --paper-2:      #EDE5D4;   /* recessed paper — sidebar, subtle fills */
  --paper-3:      #E4DAC4;   /* deeper recess — table headers */
  --ink:          #1B1714;   /* warm near-black — primary text */
  --ink-2:        #4A413A;   /* secondary text */
  --ink-3:        #786C60;   /* tertiary text, captions */
  --ink-4:        #A99C8B;   /* placeholder, hint */
  --rule:         #C9BDA5;   /* hairline rule */
  --rule-soft:    #DCD0B8;   /* softer rule, dividers */

  /* ---------- Color: rubric (accent) ---------- */
  --rubric:       #8C2A1C;   /* deep oxblood — primary accent */
  --rubric-press: #6E1F14;   /* pressed state */
  --rubric-soft:  #B05749;   /* hover, lighter contexts */
  --rubric-tint:  #F0DCD4;   /* faint tint background */

  /* ---------- Color: Help This Book (LOCKED — spec 05 §3.4) ----------
     Ces 4 couleurs sont fixées par la spec et ne doivent pas être modifiées.
     Toute la palette globale doit s'harmoniser autour. */
  --htb-important:     #D6B056;   /* warm yellow / ochre — catégorie Important */
  --htb-best-practice: #3F6B53;   /* forest green — catégorie Best practice */
  --htb-pitfall:       #B05A3C;   /* terracotta — catégorie Pitfall */
  --htb-confusing:     #4A7494;   /* muted blue — catégorie Confusing */

  /* ---------- Color: highlight ---------- */
  --hl-community: #F0DC9A;   /* desaturated yellow — community highlights */
  --hl-community-strong: #E6CC72; /* dense cluster */
  --hl-personal-bar: var(--rubric);     /* personal mark color */
  --hl-personal-underline: #8C2A1C66;   /* personal underline (rubric @ 40%) */

  /* ---------- Color: status (used sparingly) ---------- */
  --ok:    #4A6B3F;
  --warn:  #8A6A2C;
  --err:   #8C2A1C;

  /* ---------- Color: agent ---------- */
  --agent:        #1F3A40;   /* deep petrol — only for agent affordances */
  --agent-tint:   #DEE5E5;

  /* ---------- Type ---------- */
  --font-serif:  'Source Serif 4', 'Source Serif Pro', Georgia, 'Times New Roman', serif;
  --font-sans:   'Public Sans', 'Söhne', 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:   'JetBrains Mono', 'IBM Plex Mono', ui-monospace, monospace;

  /* Type scale — reading sizes are bigger than UI */
  --fs-micro:    11px;   /* mono labels, captions */
  --fs-caption:  13px;   /* sans captions, metadata */
  --fs-ui:       14px;   /* default UI label */
  --fs-ui-lg:    15px;   /* nav, primary UI */
  --fs-body:     19px;   /* primary reading size */
  --fs-body-lg:  20px;   /* large reading size */
  --fs-h6:       16px;
  --fs-h5:       19px;
  --fs-h4:       24px;
  --fs-h3:       30px;
  --fs-h2:       40px;
  --fs-h1:       56px;
  --fs-display:  76px;   /* chapter openers, book titles */

  /* Leading */
  --lh-tight:   1.1;
  --lh-snug:    1.25;
  --lh-normal:  1.45;
  --lh-reading: 1.65;
  --lh-loose:   1.75;

  /* Tracking */
  --tracking-tight:  -0.01em;
  --tracking-normal: 0;
  --tracking-label:  0.02em;
  --tracking-caps:   0.12em;   /* small caps, editorial labels */

  /* Measure */
  --measure-text: 64ch;        /* reading column width */
  --measure-narrow: 48ch;
  --measure-wide:  72ch;

  /* ---------- Spacing (4px base) ---------- */
  --s-1:   4px;
  --s-2:   8px;
  --s-3:   12px;
  --s-4:   16px;
  --s-5:   24px;
  --s-6:   32px;
  --s-7:   48px;
  --s-8:   64px;
  --s-9:   96px;
  --s-10:  128px;

  /* ---------- Radii ---------- */
  --r-0:    0px;
  --r-1:    2px;     /* almost square — most surfaces */
  --r-2:    4px;     /* buttons */
  --r-pill: 999px;   /* tags, chips */

  /* ---------- Borders ---------- */
  --border-hairline: 1px solid var(--rule);
  --border-soft:     1px solid var(--rule-soft);

  /* ---------- Shadows (used almost never) ---------- */
  --shadow-overlay: 0 12px 36px -12px rgba(27, 23, 20, 0.20),
                    0 2px 6px -2px rgba(27, 23, 20, 0.10);

  /* ---------- Motion ---------- */
  --ease-quiet: cubic-bezier(0.2, 0.6, 0.2, 1);
  --d-fast:   120ms;
  --d-normal: 200ms;
  --d-slow:   320ms;
}

/* ==========================================================================
   Dark mode — warm near-black with warm cream ink
   ========================================================================== */
[data-theme="dark"] {
  --paper:        #14110E;
  --paper-2:      #1C1815;
  --paper-3:      #251F1A;
  --ink:          #ECE3D2;
  --ink-2:        #C2B6A2;
  --ink-3:        #908474;
  --ink-4:        #5F564A;
  --rule:         #2E2620;
  --rule-soft:    #241D18;

  --rubric:       #C76050;
  --rubric-press: #A6483A;
  --rubric-soft:  #D88373;
  --rubric-tint:  #2A1812;

  /* Help This Book — dark variants (LOCKED hues, légèrement éclaircis pour contraste) */
  --htb-important:     #E2C476;
  --htb-best-practice: #6FA388;
  --htb-pitfall:       #D88066;
  --htb-confusing:     #7A9DBA;

  --hl-community: #5C4A1E;
  --hl-community-strong: #7A6326;
  --hl-personal-underline: #C7605066;

  --agent:        #7AA0A6;
  --agent-tint:   #1E2A2C;
}

/* ==========================================================================
   Base & semantic typography
   ========================================================================== */
html, body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: var(--fs-body);
  line-height: var(--lh-reading);
  font-feature-settings: "kern", "liga", "onum"; /* old-style numerals in body */
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.font-sans  { font-family: var(--font-sans); }
.font-serif { font-family: var(--font-serif); }
.font-mono  { font-family: var(--font-mono); }

/* Display + headings — serif, opsz set high for tighter letterforms */
h1, .h1 {
  font-family: var(--font-serif);
  font-size: var(--fs-h1);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  font-weight: 500;
  font-variation-settings: "opsz" 48;
  margin: 0;
}
h2, .h2 {
  font-family: var(--font-serif);
  font-size: var(--fs-h2);
  line-height: var(--lh-snug);
  letter-spacing: var(--tracking-tight);
  font-weight: 500;
  font-variation-settings: "opsz" 32;
  margin: 0;
}
h3, .h3 {
  font-family: var(--font-serif);
  font-size: var(--fs-h3);
  line-height: var(--lh-snug);
  font-weight: 500;
  font-variation-settings: "opsz" 24;
  margin: 0;
}
h4, .h4 {
  font-family: var(--font-serif);
  font-size: var(--fs-h4);
  line-height: var(--lh-snug);
  font-weight: 600;
  font-variation-settings: "opsz" 18;
  margin: 0;
}
h5, .h5 {
  font-family: var(--font-serif);
  font-size: var(--fs-h5);
  font-weight: 600;
  font-style: italic;
  margin: 0;
}
h6, .h6 {
  font-family: var(--font-sans);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0;
}

.display {
  font-family: var(--font-serif);
  font-size: var(--fs-display);
  line-height: 1.05;
  letter-spacing: -0.015em;
  font-weight: 400;
  font-variation-settings: "opsz" 60;
}

/* Reading body */
p, .body {
  font-family: var(--font-serif);
  font-size: var(--fs-body);
  line-height: var(--lh-reading);
  margin: 0 0 1em 0;
  hyphens: auto;
}
.reading-column {
  max-width: var(--measure-text);
  text-align: justify;
  hyphens: auto;
  text-wrap: pretty;
}
.reading-column p + p { text-indent: 1.4em; margin-top: 0; }

/* Block quotation — printed-page style */
blockquote, .blockquote {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--fs-body);
  line-height: var(--lh-reading);
  border-left: 2px solid var(--rubric);
  padding: var(--s-2) var(--s-5);
  margin: var(--s-5) 0;
  color: var(--ink-2);
}

/* Pull-quote — bigger, no quote marks, hairlines above and below */
.pullquote {
  font-family: var(--font-serif);
  font-size: var(--fs-h3);
  line-height: 1.3;
  font-style: italic;
  font-weight: 400;
  border-top: var(--border-hairline);
  border-bottom: var(--border-hairline);
  padding: var(--s-5) 0;
  margin: var(--s-6) 0;
  color: var(--ink);
}

/* Editorial label — small caps with tracking */
.eyebrow, .label {
  font-family: var(--font-sans);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-3);
}

/* Marginalia — small mono, low-key */
.marginalia {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tracking-label);
  color: var(--ink-3);
  line-height: var(--lh-normal);
}

/* Caption */
.caption, figcaption {
  font-family: var(--font-sans);
  font-size: var(--fs-caption);
  color: var(--ink-3);
  line-height: var(--lh-normal);
  font-style: italic;
}

/* UI label */
.ui {
  font-family: var(--font-sans);
  font-size: var(--fs-ui);
  line-height: var(--lh-normal);
}

/* Footnote */
.footnote {
  font-family: var(--font-serif);
  font-size: var(--fs-caption);
  line-height: var(--lh-normal);
  color: var(--ink-2);
}

/* Notes & footnote markers — serif italic, smaller */
.note-marker {
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--rubric);
  vertical-align: super;
  font-size: 0.7em;
  margin-left: 0.1em;
}

/* Links — subtle underline, rubric on hover */
a, .link {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
  transition: color var(--d-fast) var(--ease-quiet),
              text-decoration-color var(--d-fast) var(--ease-quiet);
}
a:hover, .link:hover {
  color: var(--rubric);
  text-decoration-color: var(--rubric);
}

/* Highlights inline */
.hl-community {
  background: linear-gradient(transparent 60%, var(--hl-community) 60%);
  padding: 0 0.05em;
}
.hl-community.dense {
  background: linear-gradient(transparent 60%, var(--hl-community-strong) 60%);
}
.hl-personal {
  border-bottom: 1px solid var(--hl-personal-underline);
  padding-bottom: 1px;
}

/* Selection */
::selection {
  background: var(--hl-community-strong);
  color: var(--ink);
}

/* Small caps utility */
.smallcaps {
  font-variant: small-caps;
  letter-spacing: var(--tracking-caps);
}
