/* Antiphon v2 · The Institute — design tokens
   warm paper, near-black ink, clay signal. no radius, no gloss. */

:root {
  /* day: archive paper (Anthropic-warm) */
  --wall: #EDEAE0;
  --wall-2: #E5E1D4;
  --on-wall: #15140F;
  --on-wall-muted: #6D6759;
  --wall-rule: #D4CDBB;

  --panel: #F8F6EF;
  --panel-2: #EEEAE0;
  --panel-3: #F2EFE5;

  --ink: #15140F;
  --ink-2: #3D3931;
  --muted: #726C5E;

  --rule: #DAD3C2;
  --rule-2: #C4BBA6;

  --signal: #C2663C;
  --signal-led: #D97757;
  --seal: #9C3A24;
  --rubric: #9C3A24;
  --link: #A54A2A;

  --code-bg: #EAE5D8;
  --code-ink: #2D2921;

  --success: #5F6B54;
  --warn: #A2673A;
  --danger: #9C3A24;
  --info: #565F6A;

  --grid-dot: rgba(21, 20, 15, 0.06);
  --veil: rgba(21, 20, 15, 0.72);

  /* lateral feathering: the sheet dissolves into the desk instead of being cut */
  --edge-veil: rgba(237, 234, 224, 0.9);

  /* type · per-script stacks
     Latin faces are listed first so Latin glyphs always take Newsreader;
     CJK glyphs fall through to the Song face. Both scripts keep one stack,
     which is what makes mixed paragraphs (中文 quoting English) behave. */

  /* Two spellings of every Noto CJK face are listed, because the font ships
     under two names: `Noto Serif SC` is the Google Fonts / macOS-installed
     family, while distro packages (`fonts-noto-cjk` on Debian/Ubuntu,
     Fedora, Arch, and Android's system fonts) register `Noto Serif CJK SC`.
     Without the `CJK` spelling a Linux browser matches nothing and falls
     through to the generic serif, which is a different face per distro. */

  --font-ui-sans: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Noto Sans SC", "Noto Sans CJK SC", Arial, sans-serif;

  --font-latin: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-cjk: "Songti SC", "Songti TC", "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", "Source Han Serif CN", STSong, serif;
  --font-serif: var(--font-latin), var(--font-cjk), serif;

  /* The Gothic counterparts. Needed separately from --font-ui-sans: that stack
     is tuned for 14px chrome, while the sans body presets in css/fonts.css need
     a face that holds up at reading size. Keeping them as their own custom
     property means a sans preset can swap --font-cjk without having to know
     which language is active. */
  --font-cjk-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans SC", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;

  /* display: same faces, opt into fuller optical sizes for headlines */
  --font-display: var(--font-latin), var(--font-cjk), serif;

  --font-ui: var(--font-ui-sans);

  --font-mono-latin: ui-monospace, "SFMono-Regular", "Roboto Mono", Menlo, Consolas, monospace;
  --font-mono-cjk: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", monospace;
  --font-mono: var(--font-mono-latin), var(--font-mono-cjk), monospace;

  --text-base: 17px;
  --text-body: 1.0625rem;
  --leading-body: 1.82;
  --para-gap: 1.3em;
  --script-dropcap: 3em;
  --script-title-tracking: 0.02em;
  --script-h2-tracking: -0.008em;
  --text-small: 0.75rem;
  --text-micro: 0.6875rem;
  --tracking-label: 0.2em;
  --text-entry: 1.5rem;
  --text-h2: clamp(1.55rem, 2.4vw, 1.95rem);
  --text-h3: 1.18rem;
  --text-display: clamp(2.2rem, 5vw, 3.3rem);
  --text-article-title: clamp(1.9rem, 4vw, 2.85rem);
  --text-lede: clamp(1.15rem, 1.8vw, 1.4rem);

  /* layout */
  --measure: 40rem;
  --panel-max: 64rem;
  --gutter: 1.6rem;
  --radius: 0;
  --shadow-panel: 0 40px 80px -70px rgba(21, 20, 15, 0.5);

  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;
  --s8: 4rem;
  --s9: 6rem;

  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);
  --dur: 190ms;
  --dur-slow: 420ms;

  --hairline: 1px solid var(--rule);

  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.62'/%3E%3C/svg%3E");
}

body[data-mode="night"] {
  /* night shift — near-black, warm accents.
     The desk is neutral black (no brown cast) so the paper reads as a dark
     slate laid on ink; every warmth in the picture comes from the clay accents,
     the embers and the window light rather than from the surrounding wall.
     Contrast measured against --panel: ink 16.4:1, ink-2 11.4:1, muted 6.2:1,
     signal 5.9:1, link 7.4:1 — all above AA for body text. */
  --wall: #070706;
  --wall-2: #100E0B;
  --on-wall: #F2EDE3;
  --on-wall-muted: #9A9184;
  --wall-rule: #26221C;

  --panel: #110F0C;
  --panel-2: #17140F;
  --panel-3: #14110E;

  --ink: #F2EDE3;
  --ink-2: #CFC7B8;
  --muted: #9A9184;

  --rule: #2A2620;
  --rule-2: #3A342C;

  --signal: #D2764F;
  --signal-led: #E08C6B;
  --seal: #C86A45;
  --rubric: #C86A45;
  --link: #DC8E62;

  --code-bg: #050504;
  --code-ink: #EDE6D8;

  --success: #93AE9C;
  --warn: #D9A06E;
  --danger: #C97A6A;
  --info: #A9B4C0;

  --grid-dot: rgba(242, 237, 227, 0.05);
  --veil: rgba(4, 4, 3, 0.8);

  /* the sheet must fade into a black desk now, not a brown one */
  --edge-veil: rgba(7, 7, 6, 0.94);

  --shadow-panel: 0 40px 80px -60px rgba(0, 0, 0, 0.95);
}

body[data-mode="day"] {
  color-scheme: light;
}

body[data-mode="night"] {
  color-scheme: dark;
}

/* ——— per-language type scale ———
   Three languages, three rhythms. `data-script` is set on <body> from the BBG site
   language (js/i18n.js A.setLang, called in js/app.js boot() before the first
   view paints), so there is no reflow after render. The `:lang()` selectors are
   a safety net: if the attribute is ever missing, the document language still
   picks the right block.

   `--measure` lives here so each language gets its own column. applyCfg() writes an
   inline --measure on <body> only when 外观.版心宽度（rem） is positive or the 更窄
   switch is on, and removes it otherwise so these per-language defaults govern. An
   inline declaration wins over these rules in every language. */

body[data-script="cjk"],
body:not([data-script]):lang(zh) {
  --leading-body: 1.82;
  --measure: 40rem;
  --text-body: 1.0625rem;
  --para-gap: 1.3em;
  --script-dropcap: 3em;
  --script-title-tracking: 0.02em;
  --script-h2-tracking: -0.008em;
  --text-article-title: clamp(1.9rem, 4vw, 2.85rem);
  --text-h2: clamp(1.55rem, 2.4vw, 1.95rem);
}

/* Japanese runs longest in the fewest columns, so it takes the loosest leading,
   the shortest measure, and one step down in display sizes. It also gets its own
   CJK stack: Songti's kana are Chinese-drawn, so Japanese leads with a Mincho. */

body[data-script="ja"],
body:not([data-script]):lang(ja) {
  --font-cjk: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP",
    "Noto Serif CJK JP", "Source Han Serif JP", "Songti SC", serif;
  --font-cjk-sans: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP",
    "Noto Sans CJK JP", "Source Han Sans JP", "PingFang SC", sans-serif;
  --font-serif: var(--font-latin), var(--font-cjk), serif;
  --font-display: var(--font-latin), var(--font-cjk), serif;
  --font-mono-cjk: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP",
    "Noto Sans CJK JP", "PingFang SC", monospace;
  --font-mono: var(--font-mono-latin), var(--font-mono-cjk), monospace;
  --leading-body: 1.9;
  --measure: 38rem;
  --text-body: 1.0625rem;
  --para-gap: 1.35em;
  --script-dropcap: 3em;
  --script-title-tracking: 0.015em;
  --script-h2-tracking: -0.004em;
  --text-article-title: clamp(1.72rem, 3.5vw, 2.5rem);
  --text-h2: clamp(1.45rem, 2.2vw, 1.8rem);
  --text-display: clamp(2rem, 4.6vw, 3rem);
  --text-entry: 1.42rem;
}

/* English: 1.62 leading and a ~34rem measure land on the 62–70 character line
   the eye prefers. Headlines are set optically tight; body tracking goes to 0
   so the label tracking on the institutional chrome never leaks into prose. */

body[data-script="latin"],
body:not([data-script]):lang(en) {
  --leading-body: 1.62;
  --measure: 34rem;
  --text-body: 1.0625rem;
  --para-gap: 1.15em;
  --text-h2: clamp(1.5rem, 2.2vw, 1.85rem);
  --text-h3: 1.16rem;
  --text-entry: 1.42rem;
  --text-display: clamp(2.3rem, 5.2vw, 3.5rem);
  --text-article-title: clamp(1.95rem, 4.2vw, 3rem);
  --text-lede: clamp(1.18rem, 1.9vw, 1.45rem);
  --script-dropcap: 2.6em;
  --script-title-tracking: -0.02em;
  --script-h2-tracking: -0.01em;
}

/* ——— hant: Traditional Chinese
   Follows the CJK rhythm — ideographs need the same generous leading and the
   same wide measure as Simplified — but the font stack has to prefer TC faces,
   because Songti SC will happily render Traditional glyphs with Simplified
   shapes for a fair number of characters. Own drop-cap box: the TC Song faces
   sit slightly smaller on the em than SC ones. */

body[data-script="hant"],
body:not([data-script]):lang(zh-Hant),
body:not([data-script]):lang(zh-TW),
body:not([data-script]):lang(zh-HK) {
  --font-cjk: "Songti TC", "Songti SC", "Noto Serif TC", "Noto Serif CJK TC",
    "Source Han Serif TC", "Source Han Serif TW", STSong, serif;
  --font-serif: var(--font-latin), var(--font-cjk), serif;
  --font-display: var(--font-latin), var(--font-cjk), serif;
  --font-cjk-sans: "PingFang TC", "Hiragino Sans CNS", "Microsoft JhengHei",
    "Noto Sans TC", "Noto Sans CJK TC", "Source Han Sans TC", sans-serif;
  --font-mono-cjk: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC",
    "Noto Sans CJK TC", monospace;
  --font-mono: var(--font-mono-latin), var(--font-mono-cjk), monospace;
  --leading-body: 1.82;
  --measure: 40rem;
  --text-body: 1.0625rem;
  --para-gap: 1.3em;
  --script-dropcap: 2.92em;
  --script-title-tracking: 0.02em;
  --script-h2-tracking: -0.008em;
}

/* ——— ko: Korean
   Hangul is a recorded-in-blocks script with very even optical density, so it
   takes a slightly shorter measure than CJK: at 40rem the line becomes a wall
   of identical syllables and the eye loses its place. Leading is the loosest
   of any script here, and there is no drop cap — a magnified syllable reads as
   a typo rather than a flourish. */

body[data-script="ko"],
body:not([data-script]):lang(ko) {
  --font-cjk: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Serif KR",
    "Noto Serif CJK KR", "Source Han Serif KR", "Nanum Myeongjo", serif;
  --font-serif: var(--font-latin), var(--font-cjk), serif;
  --font-display: var(--font-latin), var(--font-cjk), serif;
  --font-cjk-sans: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR",
    "Noto Sans CJK KR", "Source Han Sans KR", sans-serif;
  --font-mono-cjk: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR",
    "Noto Sans CJK KR", monospace;
  --font-mono: var(--font-mono-latin), var(--font-mono-cjk), monospace;
  --leading-body: 1.78;
  --measure: 37rem;
  --text-body: 1.03rem;
  --para-gap: 1.24em;
  --text-entry: 1.34rem;
  --text-display: clamp(2.1rem, 4.8vw, 3.2rem);
  --text-article-title: clamp(1.8rem, 3.9vw, 2.75rem);
  --text-lede: clamp(1.12rem, 1.8vw, 1.36rem);
}

/* ——— cyrillic
   Follows the Latin scale almost exactly: Cyrillic lowercase is a little
   narrower on average, so the measure opens by a hair, and the leading drops a
   fraction because the x-height reads large. No drop cap — the Latin preset
   already swapped it for an all-small-caps opener, and that treatment carries
   over unchanged. */

body[data-script="cyrillic"],
body:not([data-script]):lang(ru),
body:not([data-script]):lang(uk),
body:not([data-script]):lang(bg),
body:not([data-script]):lang(sr) {
  --leading-body: 1.6;
  --measure: 35rem;
  --text-body: 1.0625rem;
  --para-gap: 1.12em;
  --text-h2: clamp(1.5rem, 2.2vw, 1.85rem);
  --text-h3: 1.16rem;
  --text-entry: 1.4rem;
  --text-display: clamp(2.25rem, 5vw, 3.4rem);
  --text-article-title: clamp(1.9rem, 4vw, 2.9rem);
  --text-lede: clamp(1.16rem, 1.85vw, 1.42rem);
  --script-title-tracking: -0.018em;
  --script-h2-tracking: -0.008em;
}

/* ——— arabic
   Right-to-left with a connected script: the measure has to stay inside the
   comfortable scan length for cursive text, which is shorter than Latin, and
   the leading has to clear the ascender/descender collisions Arabic makes
   unavoidable. No drop cap, and no small-caps opener either — both are Latin
   devices. `text-autospace` is neutralised because it exists to space CJK
   against Latin, and applying it to Arabic word boundaries inserts gaps where
   the script has its own joining rules. */

body[data-script="arabic"],
body:not([data-script]):lang(ar),
body:not([data-script]):lang(fa),
body:not([data-script]):lang(ur) {
  --font-cjk: "Geeza Pro", "Noto Naskh Arabic", "Amiri", "Times New Roman", serif;
  --font-serif: var(--font-latin), var(--font-cjk), serif;
  --font-display: var(--font-latin), var(--font-cjk), serif;
  --font-cjk-sans: "Geeza Pro", "Noto Sans Arabic", "Segoe UI", sans-serif;
  --leading-body: 1.88;
  --measure: 32rem;
  --text-body: 1.09rem;
  --para-gap: 1.3em;
  --text-h2: clamp(1.45rem, 2.1vw, 1.8rem);
  --text-h3: 1.14rem;
  --text-entry: 1.32rem;
  --text-display: clamp(2rem, 4.6vw, 3.1rem);
  --text-article-title: clamp(1.75rem, 3.8vw, 2.7rem);
  --text-lede: clamp(1.1rem, 1.75vw, 1.34rem);
  --script-title-tracking: 0;
  --script-h2-tracking: 0;
  text-autospace: no-autospace;
}
