/* ==========================================================================
   editorial-web.css (v3.0)
   Full-Spectrum Japanese & Latin Editorial Stylesheet for Next.js / Astro / React
   - Native Latin Metrics + GPOS `kern` / `liga` / `font-optical-sizing: auto`
   - ALL CAPS 5.5% tracking (`--ed-caps-tracking: 0.055em`) + GPOS `kern` preservation
   - Smartphone-and-up Hakogumi (`>= 300px` justify + `palt` + `--ed-fit-offset`)
   - Dark-mode irradiation compensation, mood tones, vertical-rl + `.ed-tcy`
   ========================================================================== */

:root {
  --ed-latin-scale: 1;
  --ed-latin-shift: 0em;
  --ed-latin-word-space: 0em;
  --ed-latin-tracking: 0em;
  --ed-wao-right: 0em;
  --ed-caps-scale: 0.96;
  --ed-caps-tracking: 0.045em;

  --ed-tone-offset: 0em;
  --ed-irradiation-offset: 0em;
  --ed-fit-offset: 0em;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ed-irradiation-offset: 0.016em;
  }
}

.dark,
[data-theme="dark"],
.ed-on-dark {
  --ed-irradiation-offset: 0.018em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.light,
[data-theme="light"] {
  --ed-irradiation-offset: 0em;
}

[data-ed-tone="tight"] {
  --ed-tone-offset: -0.015em;
}
[data-ed-tone="neutral"] {
  --ed-tone-offset: 0em;
}
[data-ed-tone="airy"] {
  --ed-tone-offset: 0.028em;
}

/* 1. Tier 3 Prose Paragraphs, Lists & Table Cells (.ed-prose) */
.ed-prose,
.ed-container p,
.ed-container li,
.ed-container td,
.ed-container dd,
.ed-container blockquote {
  word-break: keep-all;
  overflow-wrap: break-word;
  line-break: strict;
  font-kerning: normal;
  font-optical-sizing: auto;
  text-spacing-trim: trim-start;
  text-autospace: normal;
  letter-spacing: calc(0.012em + var(--ed-tone-offset) + var(--ed-irradiation-offset) + var(--ed-fit-offset, 0em));
  text-align: left;
}

@media (min-width: 300px) {
  .ed-prose,
  .ed-container p,
  .ed-container li,
  .ed-container dd,
  .ed-container blockquote {
    text-align: justify;
    text-justify: inter-ideograph;
    text-wrap: wrap;
  }
}

@media (min-width: 300px) and (max-width: 639px) {
  .ed-prose,
  .ed-container p,
  .ed-container li,
  .ed-container dd,
  .ed-container blockquote {
    font-feature-settings: "palt" 1, "kern" 1;
    letter-spacing: calc(0.006em + var(--ed-tone-offset) + var(--ed-irradiation-offset) + var(--ed-fit-offset, 0em));
  }
}

/* 2. Tier 2 Lead Copy (.ed-lead) */
.ed-lead {
  word-break: keep-all;
  overflow-wrap: break-word;
  line-break: strict;
  font-kerning: normal;
  font-optical-sizing: auto;
  font-feature-settings: "palt" 1, "kern" 1;
  text-autospace: normal;
  letter-spacing: calc(0.015em + var(--ed-tone-offset) + var(--ed-irradiation-offset));
  text-align: left;
  text-wrap: pretty;
}

/* 3. Tier 1 Display & Section Headings (.ed-heading) */
.ed-heading,
.ed-container h1,
.ed-container h2,
.ed-container h3,
.ed-container h4,
.ed-container h5,
.ed-container h6 {
  word-break: keep-all;
  overflow-wrap: anywhere;
  line-break: strict;
  font-kerning: normal;
  font-optical-sizing: auto;
  font-feature-settings: "palt" 1;
  text-autospace: normal;
  letter-spacing: calc(var(--ed-tone-offset) + var(--ed-irradiation-offset));
  text-align: left;
  text-wrap: balance;
}

.ed-optical {
  letter-spacing: 0em;
  text-autospace: no-autospace;
}

/* CJK optical units are single glyphs whose gaps are solved from their real contours.
   Font pair-kerning between them is switched off so the rendered gap is exactly the solved one:
   Blink applies a CJK GPOS pair only when both neighbours happen to share one letter-spacing value,
   which would make the result depend on unrelated deltas. Latin runs keep `font-kerning: normal`. */
.ed-optical [data-ed-u]:not(.ed-latin):not(.ed-caps):not(.ed-caps-phrase):not(.ed-caps-optical):not(.ed-tcy) {
  font-kerning: none;
}

.ed-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  user-select: none;
  -webkit-user-select: none;
}

/* 4. Native Latin Metrics & GPOS `kern` / `liga` Protection (W3C JLReq §3.2.6 & Butterick) */
.ed-latin,
.ed-latin-ch {
  font-size: calc(1em * var(--ed-latin-scale, 1));
  vertical-align: var(--ed-latin-shift, 0em);
  letter-spacing: var(--ed-latin-tracking, 0em) !important;
  word-spacing: var(--ed-latin-word-space, 0em);
  margin-inline-end: var(--ed-wao-right, 0em);
  font-kerning: normal;
  font-optical-sizing: auto;
  font-variant-ligatures: common-ligatures contextual;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
}

/* Display lines solved by the optical engine set their figures proportionally. A face whose default figures are
   tabular (every digit on one advance) leaves a hole on both sides of a narrow `1`; the engine measures the same
   proportional glyphs on its canvas (`"pnum" 1`), so the boundary kerning matches what is drawn. */
.ed-optical .ed-latin,
.ed-optical .ed-latin-ch {
  font-variant-numeric: proportional-nums;
}

/* A calibrated Latin run is a little larger than 1em and sits on a shifted baseline. With a zero-height inline
   box it can no longer push its line box taller, so every line keeps the line-height of the Japanese text. */
.ed-latin,
.ed-latin-ch,
.ed-latin-pure,
.ed-caps,
.ed-caps-phrase,
.ed-caps-optical {
  line-height: 0;
}

/* Pure-Latin headings (zero CJK on the line): keep exact 100% font size & native word-spacing */
.ed-latin-pure {
  font-size: 1em !important;
  vertical-align: 0em !important;
  letter-spacing: 0em !important;
  word-spacing: normal !important;
  margin-inline-end: 0em !important;
  font-kerning: normal;
  font-optical-sizing: auto;
  font-variant-ligatures: common-ligatures contextual;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
}

/* Standalone ALL-CAPS phrases/eyebrows: Ch 1-3 proportional `word-spacing` (+0.09em) paired with +0.045em tracking
   so inter-word spaces stay >= 2x wider than tracked inter-letter stems while preserving GPOS (`AV`, `LT`)! */
.ed-caps-phrase {
  font-size: 1em;
  letter-spacing: calc(0.045em + var(--ed-irradiation-offset)) !important;
  word-spacing: 0.09em !important;
  margin-inline-end: var(--ed-wao-right, 0em);
  font-kerning: normal;
  font-optical-sizing: auto;
  font-feature-settings: "kern" 1, "cpsp" 1;
}

/* Embedded CJK ALL-CAPS acronyms (`生成AIの時代`, `UIデザイン`): slight 96% cap moderation + symmetric right cancel */
.ed-caps {
  font-size: calc(1em * var(--ed-caps-scale, 0.96));
  vertical-align: var(--ed-latin-shift, 0em);
  letter-spacing: calc(var(--ed-caps-tracking, 0.045em) + var(--ed-irradiation-offset)) !important;
  margin-inline-end: calc(var(--ed-wao-right, 0em) - (var(--ed-caps-tracking, 0.045em) + var(--ed-irradiation-offset)));
  font-kerning: normal;
  font-optical-sizing: auto;
  font-feature-settings: "kern" 1, "cpsp" 1;
}

.ed-caps-optical {
  font-size: calc(1em * var(--ed-caps-scale, 0.96));
  vertical-align: var(--ed-latin-shift, 0em);
  letter-spacing: 0em;
  margin-inline-end: var(--ed-wao-right, 0em);
  font-kerning: normal;
  font-feature-settings: "kern" 1, "cpsp" 1;
}

@supports not (text-autospace: normal) {
  .ed-latin,
  .ed-caps {
    margin-inline: 0.08em;
  }
}

/* 5. Vertical Writing (`vertical-rl`), Vertical Hakogumi (`天地揃え`) & Tatechuyoko (`縦中横`)
   Note: `text-autospace: no-autospace` works around Chromium's vertical `<span>Latin</span>かな<wbr>` X/Y offset bug;
   symmetric vertical Wao spacing is provided explicitly via `margin-inline` / optical `--ed-wao-right`. */
.ed-vertical {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-feature-settings: "vert" 1, "vkna" 1;
  text-spacing-trim: trim-start;
  text-autospace: no-autospace;
}

/* Vertical Display Headings & Lead Copy: symmetric `vert` + `vkna` grid solved by 2D Vertical HTLS (avoids asymmetric `vpal` YPlacement on `一`) */
.ed-vertical.ed-heading,
.ed-vertical.ed-lead,
.ed-vertical h1,
.ed-vertical h2,
.ed-vertical h3,
.ed-vertical h4,
.ed-vertical h5,
.ed-vertical h6 {
  font-feature-settings: "vert" 1, "vkna" 1, "kern" 1, "liga" 1;
  text-align: start;
  text-autospace: no-autospace;
}

/* Vertical Prose Paragraphs: true Square-Em Bunkobon Grid (`vert` + `vkna`) + Top/Bottom Flush Hakogumi */
.ed-vertical.ed-prose,
.ed-vertical p,
.ed-vertical li,
.ed-vertical blockquote {
  font-feature-settings: "vert" 1, "vkna" 1;
  text-align: justify;
  text-justify: inter-ideograph;
  text-wrap: wrap;
  text-autospace: no-autospace;
}

/* Keep sideways Latin runs centered on the CJK vertical central axis */
.ed-vertical .ed-latin,
.ed-vertical .ed-caps,
.ed-vertical .ed-caps-phrase,
.ed-vertical .ed-caps-optical {
  vertical-align: baseline;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
}

/* Symmetric top/bottom Wao cushion around sideways Latin/Caps words inside justified vertical prose */
.ed-vertical.ed-prose .ed-latin,
.ed-vertical p .ed-latin,
.ed-vertical li .ed-latin,
.ed-vertical.ed-prose .ed-caps,
.ed-vertical p .ed-caps,
.ed-vertical li .ed-caps {
  margin-inline: 0.12em;
}

.ed-tcy {
  text-combine-upright: all;
  -webkit-text-combine: horizontal;
  letter-spacing: 0em !important;
  text-indent: 0;
  vertical-align: baseline;
  margin-inline-end: var(--ed-wao-right, 0em);
  font-feature-settings: "tnum" 1, "hwid" 0;
}

/* 6. Utilities */
.ed-prose-left {
  text-align: left !important;
}

.ed-prose-justify {
  text-align: justify !important;
  text-justify: inter-ideograph;
  text-wrap: wrap !important;
}

.ed-prose em,
.ed-lead em,
.ed-heading em,
.ed-container em {
  font-style: normal;
}

.ed-nowrap,
.nowrap {
  white-space: nowrap;
}
