:root {
  --nav-h: 3.4rem;
  --paper: #EDF0F1;
  --surface: #FFFFFF;
  --surface-2: #F6F8F8;
  --code-bg: #F4F6F6;
  --ink: #17262E;
  --ink-soft: #45555D;
  --ink-faint: #71818A;
  --line: #D8DFDF;
  --line-strong: #BFCACA;
  --accent: #0C6C75;
  --accent-bright: #0A8996;
  --accent-wash: #E1EFEF;
  --ok: #2C7A57;
  --warn: #9C6207;
  --warn-wash: #F6ECD9;
  --danger: #B23A2C;
  --shadow: 0 1px 2px rgba(23,38,46,.05), 0 10px 30px -16px rgba(23,38,46,.16);
  --font-display: "Archivo", "Noto Sans JP", system-ui, sans-serif;
  --font-body: "Noto Serif JP", Georgia, "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", "Noto Sans JP", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0C1418;
    --surface: #131D23;
    --surface-2: #0F181D;
    --code-bg: #0E171C;
    --ink: #E5ECEC;
    --ink-soft: #9EADB3;
    --ink-faint: #78888F;
    --line: #24333B;
    --line-strong: #33454E;
    --accent: #37AEB8;
    --accent-bright: #52C7D1;
    --accent-wash: #10262A;
    --ok: #4CB588;
    --warn: #D69F51;
    --warn-wash: #241E12;
    --danger: #E0776A;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 34px -18px rgba(0,0,0,.65);
  }
}
:root[data-theme="dark"] {
  --paper: #0C1418;
  --surface: #131D23;
  --surface-2: #0F181D;
  --code-bg: #0E171C;
  --ink: #E5ECEC;
  --ink-soft: #9EADB3;
  --ink-faint: #78888F;
  --line: #24333B;
  --line-strong: #33454E;
  --accent: #37AEB8;
  --accent-bright: #52C7D1;
  --accent-wash: #10262A;
  --ok: #4CB588;
  --warn: #D69F51;
  --warn-wash: #241E12;
  --danger: #E0776A;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 34px -18px rgba(0,0,0,.65);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-h) + 1.2rem); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.02rem;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 3rem);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}
@media (min-width: 1000px) {
  .page { grid-template-columns: 15rem minmax(0, 1fr); column-gap: clamp(2rem, 5vw, 4rem); }
}
/* Grid/flex children default to min-width:auto, which lets wide content
   (560px-min tables, the SVG, long code) blow out the track and scroll
   the whole page. Pin every layout child to 0 so the inner
   overflow-x:auto containers do their job. */
.masthead, .toc, main { min-width: 0; }


/* ---------- Masthead ---------- */
.masthead {
  grid-column: 1 / -1;
  border-bottom: 1px solid var(--line-strong);
  padding: clamp(2.4rem, 6vw, 4rem) 0 clamp(1.8rem, 4vw, 2.6rem);
}
.masthead-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: .6rem 1.4rem;
  margin: 0 0 1rem;
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0;
  display: flex; align-items: center; gap: .7rem;
}
.eyebrow::before { content: ""; width: 24px; height: 2px; background: var(--accent); }
.lang-switch {
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  display: flex;
  gap: .8rem;
  white-space: nowrap;
}
.lang-switch a { color: var(--ink-faint); text-decoration: none; }
.lang-switch a:hover, .lang-switch a:focus-visible { color: var(--accent-bright); }
.lang-switch [aria-current="true"] { color: var(--ink); font-weight: 600; }
h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.8rem, 4.6vw, 2.7rem);
  line-height: 1.12;
  letter-spacing: -0.015em;
  margin: 0 0 1rem;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.subtitle {
  font-size: clamp(1rem, 2.2vw, 1.16rem);
  color: var(--ink-soft);
  max-width: 60ch;
  margin: 0 0 1.8rem;
  line-height: 1.8;
}
.doc-meta {
  display: flex; flex-wrap: wrap;
  gap: .45rem 1.5rem;
  font-family: var(--font-mono);
  font-size: .76rem;
  color: var(--ink-faint);
}
.doc-meta b { color: var(--ink-soft); font-weight: 500; }

/* ---------- Side nav ---------- */
.toc {
  grid-column: 1;
  display: none;
}
@media (min-width: 1000px) {
  .toc {
    display: block;
    align-self: start;
    position: sticky;
    top: calc(var(--nav-h) + 1.4rem);
    padding: 2.4rem 0;
    font-family: var(--font-mono);
    font-size: .78rem;
    line-height: 1.5;
    border-right: 1px solid var(--line);
    max-height: calc(100vh - var(--nav-h) - 3rem);
    overflow-y: auto;
  }
}
.toc ol { list-style: none; margin: 0; padding: 0; counter-reset: toc; }
.toc li { margin: 0 0 .55rem; }
.toc a {
  color: var(--ink-faint);
  text-decoration: none;
  display: grid;
  grid-template-columns: 1.6rem 1fr;
  gap: .3rem;
}
.toc a::before { content: "§" counter(toc); counter-increment: toc; color: var(--accent); }
.toc a:hover, .toc a:focus-visible { color: var(--ink); }
.toc .toc-appendix a::before { content: "A"; }

/* ---------- Content ---------- */
main { grid-column: 1 / -1; padding-bottom: 4rem; }
@media (min-width: 1000px) { main { grid-column: 2; } }

section { padding: clamp(2.2rem, 5vw, 3.4rem) 0; border-bottom: 1px solid var(--line); }
section:last-of-type { border-bottom: none; }

h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0 0 1.1rem;
  text-wrap: balance;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .8rem;
  align-items: baseline;
}
h2 > span { min-width: 0; overflow-wrap: anywhere; }
h2 .num {
  font-family: var(--font-mono);
  font-size: .82rem;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: .04em;
  white-space: nowrap;
}
h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  margin: 2rem 0 .6rem;
  letter-spacing: -0.005em;
}
p { margin: 0 0 1.05rem; max-width: 70ch; }
a { color: var(--accent-bright); text-underline-offset: 2px; }
strong { font-weight: 600; }
code {
  font-family: var(--font-mono);
  font-size: .86em;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: .08em .38em;
  word-break: break-word;
}
ul, ol { max-width: 70ch; padding-left: 1.3rem; margin: 0 0 1.1rem; }
li { margin-bottom: .5rem; }
li > ul, li > ol { margin-top: .5rem; margin-bottom: .2rem; }

pre {
  font-family: var(--font-mono);
  font-size: .82rem;
  line-height: 1.65;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  margin: 0 0 1.3rem;
  max-width: 100%;
}
pre code { background: none; border: none; padding: 0; font-size: 1em; word-break: normal; }
.c-dim { color: var(--ink-faint); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 0 1.4rem; border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; min-width: 560px; background: var(--surface); }
caption {
  caption-side: top;
  text-align: left;
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: .3rem .1rem .7rem;
}
th, td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.6; }
thead th {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: .82rem;
  color: var(--ink-soft);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
td code, th code { font-size: .82em; white-space: nowrap; }
.col-mono { font-family: var(--font-mono); font-size: .82rem; white-space: nowrap; }

/* ---------- Callouts ---------- */
.callout {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  padding: 1rem 1.2rem;
  margin: 0 0 1.4rem;
  max-width: 74ch;
}
.callout .mark {
  display: block;
  font-family: var(--font-mono);
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 .5rem;
}
.callout p { margin: 0 0 .6rem; font-size: .95rem; max-width: none; }
.callout p:last-child { margin: 0; }
.callout.disclosure { border-left-color: var(--warn); }
.callout.disclosure .mark { color: var(--warn); }
.callout.disclosure { background: var(--warn-wash); }
.callout.verified { border-left-color: var(--ok); }
.callout.verified .mark { color: var(--ok); }

/* ---------- Diagram ---------- */
figure { margin: 0 0 1.6rem; }
.diagram {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.4rem;
  overflow-x: auto;
  box-shadow: var(--shadow);
}
.diagram svg { display: block; width: 100%; min-width: 540px; height: auto; }
figcaption { font-size: .82rem; color: var(--ink-faint); margin-top: .7rem; font-family: var(--font-mono); }

.svg-box { fill: var(--surface-2); stroke: var(--line-strong); }
.svg-box-root { fill: var(--accent-wash); stroke: var(--accent); }
.svg-label { fill: var(--ink); font-family: "Archivo", sans-serif; font-size: 13px; font-weight: 600; }
.svg-sub { fill: var(--ink-faint); font-family: "IBM Plex Mono", monospace; font-size: 10px; }
.svg-line { stroke: var(--ink-faint); stroke-width: 1.5; fill: none; }
.svg-line-strong { stroke: var(--accent); stroke-width: 2; fill: none; }
.svg-edge-label { fill: var(--ink-soft); font-family: "IBM Plex Mono", monospace; font-size: 10px; }

/* ---------- misc ---------- */
.lead-list { list-style: none; padding: 0; max-width: 74ch; }
.lead-list li { padding-left: 1.4rem; position: relative; }
.lead-list li::before { content: "▸"; position: absolute; left: 0; color: var(--accent); }
hr.soft { border: none; border-top: 1px solid var(--line); margin: 2rem 0; }
.foot {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line-strong);
  padding: 1.8rem 0 3rem;
  font-family: var(--font-mono);
  font-size: .74rem;
  color: var(--ink-faint);
}
:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 3px; border-radius: 2px; }
/* ---------- reconcile css/style.css globals with this document ---------- */
html { color-scheme: light dark; }
body::before, body::after { display: none !important; }
.navbar, .navbar *, .footer, .footer * { font-family: var(--font-main); }
.container { max-width: 1180px; }
.page h1, .page h2, .page h3 { color: var(--ink); }
.page a { text-decoration: underline; text-underline-offset: 2px; }
.page .toc a { text-decoration: none; }
/* dropdown: hover-open is flaky on this layout, so drive it purely by click (JS toggles .is-open) */
.nav-dropdown-trigger { cursor: pointer; user-select: none; }
.nav-dropdown:hover > .nav-dropdown-menu,
.nav-dropdown:focus-within > .nav-dropdown-menu { display: none; }
.nav-dropdown.is-open > .nav-dropdown-menu { display: block; }
