/* ============================================================================
 * jp-typography-contract.css
 * ----------------------------------------------------------------------------
 * ADAPTED preamble that every generated lang="ja" candidate MUST include
 * (or reproduce token-equivalently). Adapted from hirokaji/jp-ui-contracts
 * recipes (MIT, commit 5700b944...; see SOURCE.md) with this store's G36
 * thresholds baked in. Self-contained — no @import, no external deps.
 *
 * Machine gate: scripts/design_factory/check_jp_typography.py (G36).
 * Every threshold in the comments below is the value G36 enforces; do not
 * deviate from these when authoring a JP page.
 * ==========================================================================*/

/* ---------------------------------------------------------------------------
 * 1. Root Japanese text environment
 * line-break:strict            — Japanese kinsoku (no orphaned punctuation)
 * word-break:normal            — never break-all (break-all wrecks JP prose)
 * overflow-wrap:anywhere       — long Latin URLs/words may still wrap
 * font-kerning:auto            — let the JP face decide
 * font-feature-settings:normal — NO body-wide palt (palt is headings-only; G36 FAIL if body-wide)
 * text-autospace:normal        — progressive enhancement, Chrome 139+ /
 *                                fallback (older engines) = no auto spacing,
 *                                which is an acceptable graceful degradation
 * ------------------------------------------------------------------------- */
html:lang(ja) {
  line-break: strict;
  word-break: normal;
  overflow-wrap: anywhere;
  font-kerning: auto;
  font-feature-settings: normal;
  text-autospace: normal;
}

/* ---------------------------------------------------------------------------
 * 2. Font families (PLACEHOLDER shape — replace names per engagement)
 * A named modern JP family MUST appear BEFORE the generic keyword. A bare
 * generic `serif` / `sans-serif` fallback with NO bundled JP family fails
 * G36 (it renders as the dated OS default — Yu Mincho / Hiragino).
 * First-choice mincho: Shippori Mincho B1 or Zen Old Mincho (bundled in
 * templates/design/_golden/fonts/). Noto Serif JP is acceptable if bundled.
 * ------------------------------------------------------------------------- */
:root {
  --font-body:          "Noto Sans JP", system-ui, sans-serif;        /* body: named JP family BEFORE generic */
  --font-serif-display: "Shippori Mincho B1", "Zen Old Mincho", serif; /* mincho display: named JP family BEFORE generic */
}

html:lang(ja) body {
  font-family: var(--font-body);
  text-rendering: optimizeLegibility;
}

/* ---------------------------------------------------------------------------
 * 3. Japanese body (long-form text)
 * line-height: 1.75 recommended.  G36: FAIL < 1.5, WARN < 1.7.
 * letter-spacing: 0 to 0.02em only. NEGATIVE letter-spacing on JP text is
 *                 PROHIBITED (G36 FAIL) — it collides CJK glyph bodies.
 * prose paragraph max-width: 42em.
 * ------------------------------------------------------------------------- */
:lang(ja) p,
:lang(ja) li,
:lang(ja) dd {
  line-height: 1.75;      /* recommended; G36 FAIL < 1.5, WARN < 1.7 */
  letter-spacing: 0;      /* allowed range 0 to 0.02em; negative is G36 FAIL */
  line-break: strict;
  word-break: normal;
  overflow-wrap: anywhere;
}

:where(article, .prose, .content):lang(ja) p,
:lang(ja) :where(article, .prose, .content) p {
  max-width: 42em;        /* prose measure cap */
}

/* ---------------------------------------------------------------------------
 * 4. Japanese headings
 * line-height: h1 1.35 / h2 1.40 / h3 1.45.  G36: FAIL < 1.2, WARN outside 1.2–1.5.
 * letter-spacing: positive tracking up to 0.1em allowed on headings/labels;
 *                 negative is still PROHIBITED (G36 FAIL).
 * word-break:auto-phrase — phrase-aware wrapping (Chrome 119+). Important
 *                 standalone headings should ALSO carry manual <wbr> break points.
 * text-wrap:pretty for left-aligned headings / balance for centered headings.
 * ------------------------------------------------------------------------- */
:lang(ja) h1,
:lang(ja) h2,
:lang(ja) h3,
:lang(ja) h4 {
  line-break: strict;
  word-break: normal;
  overflow-wrap: anywhere;
  font-kerning: auto;
}

:lang(ja) h1,
:lang(ja) h2,
:lang(ja) h3 {
  word-break: auto-phrase;  /* Chrome 119+; add manual <wbr> on key headings */
  text-wrap: pretty;        /* left-aligned default; use `balance` when centered */
}

:lang(ja) h1 { line-height: 1.35; letter-spacing: 0; } /* 0 to 0.1em allowed */
:lang(ja) h2 { line-height: 1.40; letter-spacing: 0; } /* 0 to 0.1em allowed */
:lang(ja) h3 { line-height: 1.45; letter-spacing: 0; } /* 0 to 0.1em allowed */

/* Centered headings should balance rather than prettify the last line. */
:lang(ja) :where(h1, h2, h3).is-centered,
:lang(ja) :where(h1, h2, h3)[style*="text-align:center"] {
  text-wrap: balance;
}

/* ---------------------------------------------------------------------------
 * 5. palt — headings / short labels ONLY (never body-wide; body-wide = G36 FAIL)
 * ------------------------------------------------------------------------- */
:lang(ja) :where(h1, h2, h3, .label, .eyebrow, .badge) {
  font-feature-settings: "palt";
}

/* ---------------------------------------------------------------------------
 * 6. Forms — separated from body density (do not inherit article spacing)
 * ------------------------------------------------------------------------- */
:lang(ja) label,
:lang(ja) input,
:lang(ja) textarea,
:lang(ja) select,
:lang(ja) button {
  line-break: strict;
  word-break: normal;
}

:lang(ja) input,
:lang(ja) textarea,
:lang(ja) select {
  line-height: 1.5;
}
