/* CHOBA whitepaper: typeset like a two-column LaTeX article in Computer Modern (Latin Modern, subset WOFF2 in fonts/, see docs/fonts.md). */
@font-face { font-family: "Latin Modern Roman"; src: url("fonts/lmroman10-regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Latin Modern Roman"; src: url("fonts/lmroman10-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Latin Modern Roman"; src: url("fonts/lmroman10-bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
/* italic Greek in running text (<i>λ</i>): the math italic Greek of Latin Modern Math, re-mapped to U+03xx */
@font-face { font-family: "Latin Modern Roman"; src: url("fonts/lmmath-greek-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; unicode-range: U+0391-03A9, U+03B1-03C9, U+03D1, U+03D5, U+03F5; }
@font-face { font-family: "Latin Modern Mono"; src: url("fonts/lmmono10-regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Latin Modern Math"; src: url("fonts/latinmodern-math.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
/* the same file as a text fallback for Greek, arrows and operators; without U+221A, whose math glyph hangs below the baseline */
@font-face { font-family: "Latin Modern Math Text"; src: url("fonts/latinmodern-math.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; unicode-range: U+00B1, U+00B7, U+00D7, U+00F7, U+0391-03C9, U+03D1, U+03D5, U+03F5, U+2032-2034, U+2113, U+2190-21FF, U+2200-2219, U+221B-22FF, U+2308-230B; }
:root {
  --page: #fff; --ink: #111; --ink-2: #444; --rule: #333; --hair: #999; --link: #1a4f9c; --frame: #f2f2f2;
  /* Greek letters and arrows in running text come from the math font; Japanese from the system Mincho. */
  --serif: "Latin Modern Roman", "Latin Modern Math Text", "Hiragino Mincho ProN", "Yu Mincho", YuMincho, "Noto Serif CJK JP", serif;
  --math: "Latin Modern Math", "Latin Modern Roman", "Hiragino Mincho ProN", "Yu Mincho", YuMincho, "Noto Serif CJK JP", math, serif;
  --mono: "Latin Modern Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
html { background: var(--page); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 17px/1.5 var(--serif); font-kerning: normal; font-variant-numeric: lining-nums; }
:lang(ja) body, body:lang(ja) { font-size: 16px; line-height: 1.8; }
b, strong, th, h1, h2, h3, h4 { font-weight: 700; }

/* page: one column up to ~1000 px, then a two-column page (see .cols) */
.masthead, main, footer.colophon { max-width: 720px; margin: 0 auto; padding-left: 16px; padding-right: 16px; box-sizing: border-box; }
.masthead { padding-top: 12px; padding-bottom: 6px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 14px; font-variant: small-caps; letter-spacing: .04em; border-bottom: .6px solid var(--hair); }
.masthead a { color: var(--ink); text-decoration: none; }
.masthead a:hover { text-decoration: underline; }
main { padding-bottom: 48px; }

/* title block (\maketitle) and abstract */
header.title { text-align: center; margin: 44px 0 24px; }
header.title h1 { font-size: 1.75rem; line-height: 1.25; margin: 0 0 8px; font-weight: 400; }
header.title .subtitle { font-size: 1.05rem; font-style: italic; margin: 0 0 18px; }
:lang(ja) header.title .subtitle { font-style: normal; }
header.title p { text-align: center; text-align-last: center; }
header.title .author { font-size: 1.1rem; margin: 0 0 6px; text-indent: 0; }
header.title .meta { font-size: 1rem; margin: 0; text-indent: 0; }
.abstract { max-width: 760px; margin: 0 auto 24px; padding: 0 2.5em; font-size: .9em; }
.abstract h2 { font-size: 1em; text-align: center; margin: 0 0 4px; }
/* table of contents: a plain numbered list */
.toc { font-size: .95em; margin: 0 0 24px; }
.toc::before { content: "Contents"; display: block; font-weight: 700; font-size: 1.1rem; margin-bottom: 4px; }
.toc:lang(ja)::before { content: "目次"; }
.toc ol { margin: 0; padding-left: 1.8em; columns: 2 220px; column-gap: 30px; }
.toc li { margin: 0; break-inside: avoid; }

/* headings: 1  Introduction / 3.1  Markets / run-in \paragraph */
h2 { font-size: 1.3rem; line-height: 1.3; margin: 1.6em 0 .6em; }
h3 { font-size: 1.1rem; line-height: 1.35; margin: 1.3em 0 .45em; }
h4 { font-size: 1em; line-height: inherit; margin: .9em 0 .2em; }
h2 .n, h3 .n { display: inline-block; min-width: 1em; margin-right: 1em; }
h2, h3, h4 { break-after: avoid; page-break-after: avoid; }
/* h4 followed by a paragraph runs into it; the English page ends it with a full stop, like \paragraph */
h4:has(+ p:not(.note)) { float: left; margin: .6em .6em 0 0; }
:lang(ja) h4:has(+ p:not(.note)) { margin-right: 1em; }
h4:has(+ p:not(.note)):lang(en)::after { content: "."; }
h4:has(+ p:not(.note)) + p { padding-top: .6em; text-indent: 0; }

/* paragraphs: justified, indented, no space between; no indent after a heading, figure, table, equation or box */
p { margin: 0; text-align: justify; hyphens: auto; -webkit-hyphens: auto; orphans: 2; widows: 2; }
p + p { text-indent: 1.5em; }
:lang(ja) p { hyphens: manual; line-break: strict; }
:lang(ja) em { font-style: normal; font-weight: 700; }
:lang(ja) p + p { text-indent: 1em; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
sup.fn { font-size: .7em; line-height: 0; }
code { font-family: var(--mono); font-size: .93em; overflow-wrap: anywhere; hyphens: none; }
ul, ol { margin: .5em 0; padding-left: 1.6em; }
li { margin: .15em 0; text-align: justify; break-inside: avoid; }
/* English lists and box text are set ragged right: justified in a narrow measure they open wide word gaps */
li:lang(en), :is(.guide, .glossary, .keypoints, .example, .why) p:lang(en), .glossary dd:lang(en) { text-align: left; }
p.note { font-size: .9em; margin: .7em 0; padding-left: 1.5em; text-indent: 0; }
p.related { font-size: .9em; text-indent: 0; margin-top: .3em; }

/* displayed equations: centred, number flush right */
.eq { display: flex; align-items: center; gap: 12px; margin: .7em 0; break-inside: avoid; }
.eq math { min-width: 0; flex: 1; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.eq .eqn { flex: none; }
.eq mtd { text-align: left; padding: 2px 0; }
math { font-family: var(--math); font-size: 1em; }
.eq + p { text-indent: 0; }

/* figures and tables: caption below figures, above tables; one line centred, longer ones justified */
figure { margin: 1.1em 0; break-inside: avoid; }
figure.table { overflow-x: auto; break-inside: auto; }
caption, figcaption { font-size: .9em; line-height: 1.45; text-align: justify; text-align-last: center; }
/* a shrink-to-fit caption: centred when it fits on one line, full width and justified when longer */
figcaption { display: table; margin: 8px auto 0; text-align-last: auto; }
caption { margin: 0 0 6px; }
/* tables: booktabs, no vertical rules, no zebra */
table { width: 100%; border-collapse: collapse; font-size: .88em; line-height: 1.4; font-variant-numeric: lining-nums tabular-nums; }
th, td { text-align: left; vertical-align: top; padding: 3px 10px 3px 0; border: 0; }
th:last-child, td:last-child { padding-right: 0; }
thead th { border-top: 1.2px solid var(--ink); border-bottom: .6px solid var(--ink); padding-top: 5px; padding-bottom: 4px; }
table:not(:has(thead)) tbody tr:first-child > * { border-top: 1.2px solid var(--ink); }
tbody tr:last-child > * { border-bottom: 1.2px solid var(--ink); padding-bottom: 5px; }
tbody th { font-weight: 400; }
tr { break-inside: avoid; }
td.num { white-space: nowrap; }
td ul { margin: 0; padding-left: 1.2em; }
td li { margin: .1em 0; text-align: left; }

/* ---------------------------------------------------------------------------------------------
   FIGURES (inline SVG). Line art: black strokes, white boxes, grey grouping frames, one accent
   (#1a4f9c, the link blue) for "the path this figure is about" -- always paired with a label or
   a line style, never the only carrier of meaning. Text uses the page fonts; sizes are viewBox units.
   Classes a figure should use:
     shapes   .box      plain box: white fill, black 1.2 outline
              .state    rounded state (UML): as .box, rx/ry 10 (also give rx="10" in markup for old browsers)
              .panel    grouping frame: grey #f2f2f2 fill, grey 0.8 outline (alias .frame)
              .ext      external program / input: white fill, dark-grey dashed outline
              .start    initial-state dot: solid black circle (r about 6)
              .end      final-state ring: white circle, black outline; put a .start dot inside it
     lines    .ar       arrow or connector: black 1.2 stroke, no fill; marker head uses .fill-ink
              .ar.shu   accent arrow: blue 1.5 stroke; marker head uses .fill-shu (alias .ar.acc / .fill-acc)
              .dash     external-input connector (4 3); internal flows and guides stay solid
     fills    .fill-ink black (arrowheads, dots)   .fill-shu blue accent   .fill-mut grey #9a9a9a
     text     (none)    13 px regular, black
              .h        heading text: 14 px bold
              .b        bold label
              .s        secondary text: 13 px (same readable minimum)
              .mut      muted text: dark grey #555
              .shu      accent text: blue (alias .acc); pair it with an accent arrow or frame
   Width: add class "narrow" to figure.fig when the viewBox is at most ~480 wide; it sits in one column.
   A figure without "narrow" spans both columns on a wide page (figure*); keep its viewBox about 680 wide.
   Current narrow figures use a 320-unit viewBox to stay legible in one printed column.
   Minimum screen widths keep 13-unit labels above 12 px; overflow stays inside the figure.
   --------------------------------------------------------------------------------------------- */
figure.fig { overflow-x: auto; -webkit-overflow-scrolling: touch; font-variant-numeric: lining-nums tabular-nums; }
figure svg { display: block; width: 100%; height: auto; max-width: 680px; margin: 0 auto; }
figure.fig:not(.narrow) svg { min-width: 630px; }
figure.fig.narrow svg { min-width: 296px; max-width: 320px; }
figure svg text { font-family: var(--serif); font-variant-numeric: lining-nums tabular-nums; fill: var(--ink); font-size: 13px; }
figure svg text.h { font-size: 14px; font-weight: 700; }
figure svg text.b { font-weight: 700; }
figure svg text.s { font-size: 13px; }
figure svg text.mut { fill: #555; }
figure svg text.shu, figure svg text.acc { fill: var(--link); }
figure svg .box, figure svg .state { fill: #fff; stroke: var(--ink); stroke-width: 1.2; }
figure svg .state { rx: 10px; ry: 10px; }
figure svg .panel, figure svg .frame { fill: var(--frame); stroke: #8c8c8c; stroke-width: .8; }
figure svg .ext { fill: #fff; stroke: #333; stroke-width: 1.1; stroke-dasharray: 4 3; }
figure svg .start { fill: var(--ink); stroke: none; }
figure svg .end { fill: #fff; stroke: var(--ink); stroke-width: 1.2; }
figure svg .ar { fill: none; stroke: var(--ink); stroke-width: 1.2; }
figure svg .ar.shu, figure svg .ar.acc { stroke: var(--link); stroke-width: 1.5; }
figure svg .fill-ink { fill: var(--ink); } figure svg .fill-shu, figure svg .fill-acc { fill: var(--link); } figure svg .fill-mut { fill: #9a9a9a; }
figure svg .dash { stroke-dasharray: 4 3; }
figure svg .guide-line { stroke: #777; stroke-width: 1.1; }
figure svg .rate-curve { stroke-width: 2; }
figure svg .observation { fill: #fff; stroke: var(--ink); stroke-width: 1.3; }

/* boxes: reading guide, glossary, comparisons, worked examples, "why this design" (framed) */
.guide, .glossary, .keypoints, .example, .why { margin: 1em 0; padding: 8px 12px 9px; background: #fff; border: .6px solid var(--rule); overflow-wrap: anywhere; break-inside: avoid; }
div.keypoints { break-inside: auto; overflow-x: auto; }
.guide h2, .glossary h3, .example h4, .why h4 { font-size: 1em; line-height: inherit; margin: 0 0 .2em; }
.guide > h2, .why > h4 { float: left; margin: 0 .6em 0 0; }
:lang(ja) .guide > h2, :lang(ja) .why > h4 { margin-right: 1em; }
.guide > h2:lang(en)::after, .why > h4:lang(en)::after, .glossary > h3:lang(en)::after { content: "."; }
.guide > h2 + p, .why > h4 + p { text-indent: 0; }
.guide p + p { text-indent: 0; margin-top: .3em; }
.glossary dl { margin: 0; }
.glossary dl > div { break-inside: avoid; }
.glossary dt { margin-top: .35em; font-weight: 700; }
.glossary dd { margin: 0 0 0 1.5em; }
.example ol { margin: .2em 0 0; }
/* comparison tables sit unframed under their bold caption; column widths follow the content */
div.keypoints { border: 0; padding: 0; }
.keypoints caption { font-weight: 700; font-size: 1em; text-align: left; text-align-last: auto; }
.keypoints caption:lang(en)::after { content: "."; }
.keypoints > p { text-indent: 0; }
.keypoints > table + p { font-size: .9em; margin-top: 6px; }
/* table cells break long words only when they must (min-content ignores overflow-wrap: break-word) */
.keypoints th, .keypoints td { overflow-wrap: break-word; }
/* the row label (operation, measure, route) keeps a few characters per line; auto layout would squeeze Japanese to one */
.keypoints tr > :first-child { min-width: 4em; }
.related { color: var(--ink); }

/* notes (endnotes, smaller) and references ([1] hanging labels) */
section.notes, section.refs { font-size: .88em; }
section.notes h2, section.refs h2 { font-size: 1.3rem; }
section.notes ol { padding-left: 1.8em; line-height: 1.45; }
section.notes li { margin: .25em 0; text-align: left; }
section.refs ol { list-style: none; padding-left: 2.4em; line-height: 1.45; }
section.refs li { position: relative; margin: .3em 0; overflow-wrap: anywhere; text-align: left; }
section.refs li::before { content: "[" counter(list-item) "]"; position: absolute; right: calc(100% + .5em); white-space: nowrap; }
.backref { margin-left: .3em; }
dl.notation { display: grid; grid-template-columns: max-content 1fr; gap: 3px 16px; font-size: .92em; }
dl.notation dd { margin: 0; }
footer.colophon { padding-top: 12px; padding-bottom: 40px; font-size: .82rem; color: var(--ink-2); border-top: .6px solid var(--hair); }
footer.colophon p { text-align: left; }

/* two-column page: each subsection (div.cols) is balanced across two columns; wide elements span both */
@media (min-width: 1000px) {
  .masthead, main, footer.colophon { max-width: 1032px; }
}
@media (min-width: 1000px), print {
  .cols { column-count: 2; column-gap: 30px; column-fill: balance; }
  .cols > :first-child { margin-top: 0; }
  .cols > figure.fig:not(.narrow), .cols > figure.table, .cols > div.keypoints, .cols > .wide, .cols > .glossary { column-span: all; }
  /* glossary in three columns read row by row; a grid breaks cleanly between rows across pages */
  .glossary dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 24px; }
  .glossary dl > div:nth-child(-n+3) > dt { margin-top: 0; }
  /* endnotes are mostly source paths: one full-width column wraps them far less */
  section.notes .cols { column-count: 1; }
  /* a heading directly above a spanning element spans with it (otherwise it can sit alone in a column, or overlap in print) */
  .cols > h3:has(+ figure.fig:not(.narrow), + figure.table, + div.keypoints, + .wide, + .glossary) { column-span: all; }
  /* equations a little wider than a column are set slightly smaller rather than spanning */
  #e7 math, #e12 math, #e19 math { font-size: .9em; }
  .cols > .wide .eq { margin: .7em auto; max-width: 900px; }
}
@media (max-width: 560px) {
  body { font-size: 16px; }
  header.title h1 { font-size: 1.5rem; }
  .abstract { padding: 0 .5em; }
  table { font-size: .8em; }
  td.num { white-space: normal; }
  .guide, .glossary, aside.keypoints, .example, .why { padding: 8px 10px; }
  .keypoints table { font-size: .76rem; }
  dl.notation { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 6px 12px; }
  dl.notation dt, dl.notation dd { overflow-wrap: anywhere; }
}
/* print: A4, two columns, same look */
@page { size: A4; margin: 18mm 16mm 20mm;
  @bottom-center { content: counter(page); font-family: "Latin Modern Roman", serif; font-size: 9pt; color: #000; vertical-align: top; padding-top: 6mm; }
}
@media print {
  body, :lang(ja) body, body:lang(ja) { font-size: 9.5pt; line-height: 1.4; color: #000; }
  :lang(ja) body, body:lang(ja) { line-height: 1.65; }
  .masthead { display: none; }
  main, footer.colophon { max-width: none; padding: 0; }
  header.title { margin-top: 0; }
  a { color: inherit; }
  sup.fn a { color: inherit; }
  h2 { break-before: auto; }
  figure.fig, .eq, tr, li, .example, .why, .guide, .glossary dl > div, dl.notation > * { break-inside: avoid; page-break-inside: avoid; }
  /* tables break between rows and repeat their header; a wide worked example may break between its steps and its figure */
  figure.table, table, div.keypoints, .glossary, dl.notation, .example.wide { break-inside: auto; page-break-inside: auto; }
  caption, thead, .example h4, .glossary h3 { break-after: avoid; page-break-after: avoid; }
  figure.table, figure.fig, div.keypoints { overflow: visible; }
  thead { display: table-header-group; }
  figure.fig:not(.narrow) svg, figure.fig.narrow svg { min-width: 0; max-height: 230mm; }
  p { orphans: 3; widows: 3; }
  footer.colophon { padding: 8px 0 0; }
}

/* Preserve the full printed contents; mobile readers open the index on demand. */
.toc-fold { margin-bottom: 24px; border-block: .6px solid var(--hair); padding-block: 10px; }
.toc-fold > summary { cursor: pointer; font-weight: 700; font-size: 1.1rem; }
.toc-fold .toc { margin: 12px 0 0; }
.toc-fold .toc::before { display: none; }
@media (max-width: 700px) {
  :lang(ja) header.title h1 { text-wrap: balance; }
  :lang(ja) .guide p { text-wrap: pretty; }
}
@media print { .toc-fold { border: 0; padding: 0; } .toc-fold > summary { list-style: none; } }

/* Keep notation entries intact when flowing across columns. */
dl.notation > :is(dt, dd) { break-inside: avoid; }
.inline-formula { display: inline-block; max-width: 100%; overflow-x: auto; vertical-align: middle; white-space: nowrap; text-indent: 0; }
@media (max-width: 560px) { p { text-align: left; } }
@media (max-width: 700px) {
  :lang(ja) header.title :is(h1, .subtitle) { text-wrap: balance; word-break: auto-phrase; }
  :lang(ja) .keypoints th { word-break: keep-all; }
}

@media print { .inline-formula { overflow: visible; white-space: normal; } }

/* Long formulas and numbered headings retain natural reading alignment. */
p:has(> .inline-formula) { text-align: left; }
h2:has(> .n), h3:has(> .n) { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 1em; }
h2 > .n, h3 > .n { margin-right: 0; }
:lang(ja) .guide p { text-wrap: pretty; word-break: auto-phrase; }
.masthead a, footer.colophon a { display: inline-flex; align-items: center; min-height: 44px; }
.toc-fold { padding-block: 1px; }
.toc-fold > summary { min-height: 44px; align-content: center; padding-block: 9px; box-sizing: border-box; }
@media print {
  .masthead a, footer.colophon a, .toc-fold > summary { min-height: 0; }
  .toc-fold > summary { padding: 0; }
}
