/* Derived Logic — site stylesheet
   Light/dark via tokens; justified, hyphenated text set per language. */

:root {
  --paper: #F3F4EF;
  --paper-deep: #E7EAE2;
  --ink: #1A242D;
  --ink-soft: #4A5560;
  --olive: #586943;
  --blue: #2B5C8C;
  --rule: #C9D0C3;
  --scrim: rgba(20, 27, 33, 0.42);
  --shadow: 0 18px 50px rgba(20, 27, 33, 0.18);
  --gutter: clamp(18px, 7vw, 120px);
  --measure: 64ch;
  --font: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #12191F;
  --paper-deep: #19222A;
  --ink: #E3E8E1;
  --ink-soft: #A9B3AC;
  --olive: #A2B488;
  --blue: #8DB4DE;
  --rule: #2C3841;
  --scrim: rgba(0, 0, 0, 0.6);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

:lang(ja) { --font: "IBM Plex Sans", "IBM Plex Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif; --measure: 37em; }
:lang(ko) { --font: "IBM Plex Sans", "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; --measure: 38em; }
:lang(zh) { --font: "IBM Plex Sans", "IBM Plex Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif; --measure: 37em; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 84px; }
html.dl-wait body { visibility: hidden; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: clamp(16.5px, 0.94rem + 0.32vw, 19px);
  line-height: 1.62;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:lang(ja) body, body:lang(ja), :lang(zh) body, body:lang(zh) { line-height: 1.95; }
:lang(ko) body, body:lang(ko) { line-height: 1.9; }

a { color: var(--blue); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; border-radius: 2px; }
p { margin: 0 0 1em; }
h1, h2, h3 { font-weight: 600; text-wrap: balance; hyphens: manual; margin: 0; }
:lang(ja) h1, :lang(ja) h2, :lang(ja) h3 { font-feature-settings: "palt"; letter-spacing: 0.04em; }
:lang(zh) h1, :lang(zh) h2, :lang(zh) h3 { letter-spacing: 0.04em; }
code { font-size: 0.92em; }

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 100;
  background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 3px;
}
.skip:focus { top: 12px; }

.wrap { max-width: 1280px; margin: 0 auto; padding-inline: var(--gutter); }

/* ---------- The typesetting ----------
   Justified, hyphenated text in the spirit of LaTeX. Hyphenation needs the
   correct lang attribute, which every page sets. */
.just {
  text-align: justify;
  text-justify: inter-word;
  -webkit-hyphens: auto;
  hyphens: auto;
  hyphenate-limit-chars: 7 3 3;
  text-wrap: pretty;
  overflow-wrap: break-word;
}
/* CJK: no letter-spacing and no text-wrap:pretty, or WebKit (Safari) stops justifying. */
:lang(ja) .just, :lang(ko) .just, :lang(zh) .just { letter-spacing: 0; text-wrap: wrap; -webkit-hyphens: manual; hyphens: manual; line-break: strict; }
:lang(ja) .just, :lang(zh) .just { text-justify: inter-character; }
/* Korean: whole words on wide screens; on phones allow syllable breaks, as Korean newspapers do, to avoid wide gaps. */
:lang(ko) .just { word-break: keep-all; overflow-wrap: anywhere; }
@media (max-width: 699px) { :lang(ko) .just { word-break: normal; } }
@media (max-width: 1080px) { :lang(ko) .problems .just { word-break: normal; } }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  /* Solid, not blurred: a backdrop-filter would trap the fixed menu drawer inside the header. */
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 68px;
}
.wordmark {
  display: inline-flex; align-items: center; gap: 11px;
  font-weight: 650; font-stretch: 100%; font-size: 1.04rem; letter-spacing: 0.01em;
  color: var(--ink); text-decoration: none;
}
.wordmark svg { width: 26px; height: 26px; flex: none; }
.tools { display: flex; align-items: center; gap: 6px; }

.pill {
  list-style: none; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; min-width: 44px; padding: 0 12px;
  border: 1px solid var(--rule); border-radius: 999px;
  color: var(--ink); background: transparent;
  font: inherit; font-size: 0.82rem; font-weight: 600; letter-spacing: 0.06em;
}
.pill::-webkit-details-marker { display: none; }
.pill:hover { border-color: var(--ink-soft); }
.pill svg { width: 20px; height: 20px; }

/* Language menu */
.lang { position: relative; }
.lang-list {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  min-width: 210px; margin: 0; padding: 6px; list-style: none;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 6px; box-shadow: var(--shadow);
}
.lang-list a {
  display: flex; justify-content: space-between; gap: 18px; padding: 10px 12px; border-radius: 4px;
  color: var(--ink); text-decoration: none; font-size: 0.95rem;
}
.lang-list a span { color: var(--ink-soft); font-size: 0.78rem; letter-spacing: 0.06em; }
.lang-list a:hover { background: var(--paper-deep); }
.lang-list a[aria-current="true"] { font-weight: 600; }
.lang-list li[hidden] { display: none; }

/* Hamburger menu: a <details> drawer that works without JavaScript */
.menu > summary { padding: 0; width: 44px; }
.menu[open] > summary::before {
  content: ""; position: fixed; inset: 0; z-index: 60; background: var(--scrim); cursor: default;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 70;
  width: min(340px, 100vw);
  display: flex; flex-direction: column;
  background: var(--paper); box-shadow: var(--shadow);
  padding: 18px clamp(20px, 5vw, 32px) 28px;
  overflow-y: auto; overscroll-behavior: contain;
  animation: drawer-in 0.22s cubic-bezier(.2,.7,.2,1);
}
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; min-height: 50px; margin-bottom: 18px; }
.drawer-title { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft); }
.drawer-close { display: none; }
.js .drawer-close { display: inline-flex; }
.toc { list-style: none; margin: 0 0 28px; padding: 0; counter-reset: none; }
.toc a {
  display: block;
  padding: 13px 0; border-top: 1px solid var(--rule);
  color: var(--ink); text-decoration: none; font-size: 1.12rem; font-weight: 500;
}
.toc li:last-child a { border-bottom: 1px solid var(--rule); }
.toc a:hover { color: var(--blue); }
.drawer-group { margin-top: auto; display: grid; gap: 14px; }
.drawer-label { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.seg button {
  font: inherit; font-size: 0.88rem; padding: 10px 6px; min-height: 44px;
  color: var(--ink); background: transparent; border: 0; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.no-js .seg { display: none; }
.linkish { font: inherit; color: var(--blue); background: none; border: 0; padding: 0; cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 0.2em; }

/* ---------- Hero ---------- */
.hero { padding-block: clamp(40px, 9vw, 132px) clamp(48px, 9vw, 128px); }
.eyebrow {
  margin: 0 0 22px; color: var(--olive);
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase;
}
:lang(ja) .eyebrow, :lang(ko) .eyebrow, :lang(zh) .eyebrow { letter-spacing: 0.08em; font-size: 0.86rem; }
.hero h1 {
  font-size: clamp(2.5rem, 1.4rem + 4.4vw, 5.2rem);
  line-height: 1.02; letter-spacing: -0.02em; font-weight: 600;
  max-width: 14ch; margin-bottom: clamp(24px, 3vw, 36px);
}
:lang(ja) .hero h1, :lang(ko) .hero h1, :lang(zh) .hero h1 { line-height: 1.25; letter-spacing: 0; max-width: 16em; font-size: clamp(2rem, 1.2rem + 3.4vw, 4rem); }
.hero .lede { font-size: clamp(1.1rem, 1rem + 0.4vw, 1.32rem); line-height: 1.58; max-width: 40em; color: var(--ink-soft); margin-bottom: 34px; }
:lang(ja) .hero .lede, :lang(ko) .hero .lede, :lang(zh) .hero .lede { max-width: 34em; line-height: 1.9; }
.actions { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: center; }
.button {
  display: inline-flex; align-items: center; min-height: 48px; padding: 0 22px;
  background: var(--ink); color: var(--paper); border-radius: 3px;
  font-weight: 600; font-size: 0.98rem; text-decoration: none;
}
.button:hover { background: var(--blue); color: var(--paper); }
.textlink { font-weight: 600; font-size: 0.98rem; }

/* ---------- Sections ---------- */
section { padding-block: clamp(56px, 8vw, 116px); border-top: 1px solid var(--rule); }
.section-grid {
  display: grid; grid-template-columns: minmax(200px, 300px) minmax(0, 1fr);
  gap: clamp(24px, 5vw, 80px);
}
.section-head { align-self: start; position: sticky; top: 96px; }
.section-head h2 { font-size: clamp(1.55rem, 1.15rem + 1.3vw, 2.25rem); line-height: 1.12; letter-spacing: -0.01em; }
:lang(ja) .section-head h2, :lang(ko) .section-head h2, :lang(zh) .section-head h2 { line-height: 1.4; letter-spacing: 0.02em; font-size: clamp(1.4rem, 1.1rem + 1vw, 1.95rem); }
.body { max-width: var(--measure); }
.body h3 { font-size: 1.08rem; margin: 2.1em 0 0.45em; }

.problems { list-style: none; padding: 0; margin: 1.8em 0 0; display: grid; }
.problems li { padding: 22px 0 18px; border-top: 1px solid var(--rule); }
.problems li:last-child { border-bottom: 1px solid var(--rule); }
.problems h3 { margin: 0 0 0.4em; font-size: 1.06rem; }
.problems p { margin: 0; color: var(--ink-soft); }

.pull {
  margin: 1.8em 0; padding-left: 20px; border-left: 3px solid var(--olive);
  font-size: clamp(1.18rem, 1.02rem + 0.6vw, 1.5rem); line-height: 1.4; font-style: italic; color: var(--ink);
  max-width: 34ch;
}
:lang(ja) .pull, :lang(ko) .pull, :lang(zh) .pull { font-style: normal; line-height: 1.7; max-width: 26em; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin: 1.8em 0; }
.pair > div { border-top: 3px solid var(--olive); padding-top: 14px; }
.pair > div:last-child { border-top-color: var(--blue); }
.pair h3 { margin: 0 0 0.35em; }
.pair p { margin: 0; color: var(--ink-soft); }

/* ---------- Figures (HTML, so every language wraps naturally) ---------- */
.fig { margin: 2.2em 0; padding: clamp(18px, 3vw, 30px); background: var(--paper-deep); border-radius: 5px; }
.fig figcaption { margin-top: 18px; font-size: 0.88rem; line-height: 1.5; color: var(--ink-soft); }
.step-t { display: block; font-weight: 600; font-size: 0.98rem; line-height: 1.3; }
.step-n { display: block; color: var(--ink-soft); font-size: 0.88rem; line-height: 1.4; margin-top: 4px; }
.cycle { display: grid; grid-template-columns: 1fr 34px 1fr 34px 1fr; align-items: stretch; }
.step { border: 2px solid var(--ink-soft); border-radius: 4px; padding: 16px 14px; text-align: center; background: var(--paper); display: flex; flex-direction: column; justify-content: center; }
.step:nth-child(1) { border-color: var(--olive); }
.step:nth-child(3) { border-color: var(--blue); }
.arr { display: flex; align-items: center; justify-content: center; color: var(--ink-soft); }
.arr svg { width: 26px; height: 14px; }
.cycle-return {
  margin: 0 calc(100% / 6) 0; padding: 18px 12px 10px;
  border: 2px dashed var(--ink-soft); border-top: 0; border-radius: 0 0 14px 14px;
  text-align: center; font-size: 0.9rem; color: var(--ink-soft);
}

.nations { display: grid; grid-template-columns: 1fr minmax(96px, auto) 1fr; grid-template-rows: auto auto auto; column-gap: 0; }
.nation {
  grid-row: 1 / 4; display: grid; grid-template-rows: subgrid; row-gap: 10px;
  border: 2px solid var(--olive); border-radius: 4px; padding: 14px; background: var(--paper);
}
.nation.b { grid-column: 3; border-color: var(--blue); }
.nation strong { font-size: 1rem; font-weight: 600; text-align: center; }
.cell { border-radius: 3px; padding: 10px; text-align: center; font-size: 0.88rem; line-height: 1.35; display: flex; align-items: center; justify-content: center; }
.cell.shared { border: 1px solid var(--rule); }
.cell.data { background: color-mix(in srgb, var(--olive) 18%, transparent); }
.nation.b .cell.data { background: color-mix(in srgb, var(--blue) 18%, transparent); }
.link { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 6px; color: var(--ink-soft); }
.link svg { width: 100%; min-width: 70px; height: 14px; }
.link span { font-size: 0.78rem; line-height: 1.25; text-align: center; margin-top: 4px; }

/* ---------- Contact & footer ---------- */
.contact h2 { font-size: clamp(1.9rem, 1.2rem + 2.6vw, 3.2rem); line-height: 1.06; letter-spacing: -0.015em; max-width: 18ch; margin-bottom: 20px; }
:lang(ja) .contact h2, :lang(ko) .contact h2, :lang(zh) .contact h2 { line-height: 1.35; letter-spacing: 0.02em; max-width: 20em; }
.contact p { max-width: 40em; color: var(--ink-soft); }
:lang(ja) .contact p, :lang(ko) .contact p, :lang(zh) .contact p { max-width: 34em; }
.contact .button { margin-top: 12px; }

.site-footer { border-top: 1px solid var(--rule); padding-block: 28px 44px; font-size: 0.86rem; color: var(--ink-soft); }
.footer-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 24px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.footer-links a, .footer-links .linkish { color: var(--ink-soft); font-size: inherit; }
.sovereignty { margin: 22px 0 0; padding-top: 18px; border-top: 1px solid var(--rule); max-width: 46em; font-size: 0.86rem; line-height: 1.6; }
:lang(ja) .sovereignty, :lang(ko) .sovereignty, :lang(zh) .sovereignty { line-height: 1.85; max-width: 40em; }

/* ---------- Consent banner ---------- */
.consent {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 80;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 24px));
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 8px; box-shadow: var(--shadow);
  padding: 20px clamp(18px, 3vw, 26px);
}
.consent[hidden] { display: none; }
.consent h2 { font-size: 1rem; margin-bottom: 6px; }
.consent p { font-size: 0.9rem; line-height: 1.55; color: var(--ink-soft); margin-bottom: 14px; }
.consent-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.consent-actions button {
  font: inherit; font-weight: 600; font-size: 0.95rem; min-height: 44px; min-width: 120px; padding: 0 18px;
  border-radius: 3px; cursor: pointer; border: 2px solid var(--ink);
  background: var(--ink); color: var(--paper);
}
.consent-actions .consent-more { margin-left: auto; font-size: 0.88rem; }

/* ---------- Privacy page ---------- */
.doc { padding-block: clamp(36px, 7vw, 96px); }
.doc h1 { font-size: clamp(2rem, 1.3rem + 2.4vw, 3rem); line-height: 1.1; margin-bottom: 12px; }
.doc .updated { color: var(--ink-soft); font-size: 0.9rem; margin-bottom: 2em; }
.doc article { max-width: var(--measure); }
.doc h2 { font-size: 1.15rem; margin: 2em 0 0.5em; }

/* ---------- Responsive: tablets get a newspaper column; phones a single justified column ---------- */
@media (max-width: 1080px) and (min-width: 700px) {
  .problems { grid-template-columns: 1fr 1fr; column-gap: 32px; }
  .problems li:nth-last-child(2) { border-bottom: 1px solid var(--rule); }
}
@media (max-width: 900px) {
  .section-grid { grid-template-columns: 1fr; gap: 18px; }
  .section-head { position: static; }
  .body { max-width: none; }
}
@media (max-width: 699px) {
  :root { --gutter: 18px; }
  body { font-size: 16.5px; }
  section { padding-block: 44px; }
  .pair { grid-template-columns: 1fr; gap: 22px; }
  .cycle { grid-template-columns: 1fr; grid-template-rows: auto 30px auto 30px auto; }
  .arr svg { transform: rotate(90deg); }
  .cycle-return { margin: 12px 0 0; border-top: 2px dashed var(--ink-soft); border-radius: 8px; padding: 12px; }
  .nations { grid-template-columns: 1fr; grid-template-rows: none; }
  .nation, .nation.b { grid-column: 1; grid-row: auto; grid-template-rows: auto; }
  .link { grid-column: 1; grid-row: auto; padding: 10px 0; }
  .link svg { transform: rotate(90deg); width: 40px; min-width: 0; height: 40px; }
  .consent-actions button { flex: 1 1 0; min-width: 0; }
  .consent-actions .consent-more { margin-left: 0; flex-basis: 100%; }
  .hide-sm { display: none; }
}
