/* 割り切れない: shared styles. Colours are tokens; figures read them through W.colors(). */
:root {
  --paper: #f4efe4; --paper-2: #ebe4d4; --fig-bg: #faf7f0;
  --ink: #1e1c1a; --ink-2: #4a4540; --ink-3: #736b60; --rule: #d9d0be;
  --shu: #c0432b; --shu-soft: rgba(192, 67, 43, 0.14);
  --ai: #2c4f7c; --ai-soft: rgba(44, 79, 124, 0.13);
  --kin: #a8761a; --kin-soft: rgba(168, 118, 26, 0.16);
  --matsu: #3f6b4f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --jp: "Yu Mincho", YuMincho, "Hiragino Mincho ProN", "Noto Serif JP", "MS PMincho", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --col: 680px; --wide: 940px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #10141c; --paper-2: #171c27; --fig-bg: #141924;
    --ink: #e9e4d8; --ink-2: #b3ac9e; --ink-3: #8e897e; --rule: #2b3242;
    --shu: #ee7b5c; --shu-soft: rgba(238, 123, 92, 0.17);
    --ai: #8fb0e0; --ai-soft: rgba(143, 176, 224, 0.15);
    --kin: #e2b24f; --kin-soft: rgba(226, 178, 79, 0.15);
    --matsu: #7fb08f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #10141c; --paper-2: #171c27; --fig-bg: #141924;
  --ink: #e9e4d8; --ink-2: #b3ac9e; --ink-3: #8e897e; --rule: #2b3242;
  --shu: #ee7b5c; --shu-soft: rgba(238, 123, 92, 0.17);
  --ai: #8fb0e0; --ai-soft: rgba(143, 176, 224, 0.15);
  --kin: #e2b24f; --kin-soft: rgba(226, 178, 79, 0.15);
  --matsu: #7fb08f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 19px/1.65 var(--serif); font-variant-numeric: oldstyle-nums proportional-nums;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--shu-soft); }
a { color: inherit; text-decoration-color: var(--ink-3); text-underline-offset: 0.18em; }
a:hover { color: var(--shu); text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--shu); outline-offset: 2px; border-radius: 2px; }
.jp, :lang(ja) { font-family: var(--jp); }
rt { font-size: 0.55em; color: var(--ink-2); }
em { font-style: italic; }
strong { font-weight: 600; }
.num, .tab { font-variant-numeric: tabular-nums lining-nums; }
.sc { font-variant: small-caps; letter-spacing: 0.04em; }
.ink3 { color: var(--ink-3); }
.shu { color: var(--shu); }
.ai { color: var(--ai); }
.kin { color: var(--kin); }

/* Stacked fractions: W.fracHTML(p, q) */
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center;
  font-size: 0.82em; line-height: 1.05; font-variant-numeric: tabular-nums lining-nums; margin: 0 0.1em; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 0.15em; }

/* ---------- page frame ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; gap: 14px; align-items: center; justify-content: flex-end;
  padding: 6px 16px; font: 13px/1.3 var(--sans); color: var(--ink-2);
  background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(6px);
  border-bottom: 1px solid transparent; transition: border-color 0.2s;
}
.topbar.scrolled { border-bottom-color: var(--rule); }
.topbar .brand { margin-right: auto; font-family: var(--jp); font-size: 15px; color: var(--ink); text-decoration: none; opacity: 0; transition: opacity 0.3s; }
.topbar.scrolled .brand { opacity: 1; }
.topbar button { font: inherit; color: inherit; background: none; border: 1px solid var(--rule); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.topbar button:hover { border-color: var(--ink-3); color: var(--ink); }
#sound-ctl { display: flex; align-items: center; gap: 6px; }
#sound-ctl input[type="range"] { width: 90px; accent-color: var(--shu); }

/* Chapter rail on wide screens */
.rail { position: fixed; left: 18px; top: 50%; transform: translateY(-50%); z-index: 10; display: none;
  flex-direction: column; gap: 6px; font-family: var(--jp); }
.rail a { display: block; width: 30px; height: 30px; line-height: 30px; text-align: center; font-size: 15px;
  text-decoration: none; color: var(--ink-3); border-radius: 3px; position: relative; }
.rail a:hover, .rail a.here { color: var(--paper); background: var(--shu); }
.rail a span { position: absolute; left: 38px; top: 0; white-space: nowrap; font: 13px/30px var(--sans); color: var(--ink-2);
  opacity: 0; pointer-events: none; transition: opacity 0.15s; }
.rail a:hover span { opacity: 1; }
@media (min-width: 1240px) { .rail { display: flex; } }

main { padding: 0 16px 120px; }
main > *, .chapter > * { max-width: var(--col); margin-left: auto; margin-right: auto; }
main > .chapter { max-width: none; }
.chapter > figure.fig.wide, main > figure.fig.wide { max-width: var(--wide); }

/* ---------- hero ---------- */
/* The way back to the corner's hub (added for ouba.moe/claude). */
.corner { max-width: var(--wide); margin: 24px auto 0; padding: 0 16px; font: 14px/1.4 var(--sans); }
.corner a { color: var(--ink-3); text-decoration: none; }
.corner a:hover { color: var(--shu); }
.corner + .hero { padding-top: 32px; }
.hero { max-width: var(--wide); margin: 0 auto; padding: 72px 16px 40px; display: grid; grid-template-columns: 1fr auto; gap: 40px; align-items: start; }
.hero .vtitle { writing-mode: vertical-rl; font-family: var(--jp); font-size: 64px; line-height: 1.1; letter-spacing: 0.12em; color: var(--ink); margin: 0; font-weight: 500; }
.hero .vtitle .shu { color: var(--shu); }
.hero .lede h1 { font-weight: 400; font-size: 40px; line-height: 1.15; margin: 0.4em 0 0.3em; letter-spacing: -0.01em; }
.hero .lede p { font-size: 21px; color: var(--ink-2); margin: 0.5em 0; }
.hero .lede p.hero-how { font: 15px/1.5 var(--sans); color: var(--ink-3); margin-top: 1.2em; }
.hero .byline { font: 14px/1.5 var(--sans); color: var(--ink-3); margin-top: 1.5em; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; padding-top: 40px; gap: 8px; } .hero .vtitle { writing-mode: horizontal-tb; font-size: 44px; order: -1; } }

/* ---------- chapters ---------- */
.chapter { padding-top: 56px; }
.chapter-head { display: flex; align-items: center; gap: 18px; margin: 40px auto 28px; }
.seal { flex: none; width: 58px; height: 58px; display: grid; place-items: center; background: var(--shu); color: var(--paper);
  font: 34px/1 var(--jp); border-radius: 4px; box-shadow: inset 0 0 0 3px var(--shu), inset 0 0 0 4px color-mix(in srgb, var(--paper) 40%, transparent); }
.chapter-head h2 { margin: 0; font-weight: 400; font-size: 32px; line-height: 1.15; }
.chapter-head .sub { display: block; font: 15px/1.4 var(--jp); color: var(--ink-3); margin-top: 4px; letter-spacing: 0.05em; }
h3 { font-weight: 600; font-size: 21px; margin: 2em auto 0.4em; }
p { margin: 0.9em auto; hyphens: auto; }
blockquote { border-left: 3px solid var(--rule); margin: 1.4em auto; padding: 0.1em 0 0.1em 1.1em; color: var(--ink-2); }
.aside { font-size: 16px; line-height: 1.6; color: var(--ink-2); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 0.6em 0; margin: 1.6em auto; }
.aside b { color: var(--ink); font-weight: 600; }
.pull { font-size: 24px; line-height: 1.4; text-align: center; color: var(--ink); margin: 1.6em auto; max-width: 560px; }
ol, ul { padding-left: 1.3em; }
li { margin: 0.25em 0; }
table.data { border-collapse: collapse; margin: 1.2em auto; font: 15px/1.4 var(--sans); font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 4px 10px; border-bottom: 1px solid var(--rule); text-align: right; }
table.data th { font-weight: 600; color: var(--ink-2); }
table.data td:first-child, table.data th:first-child { text-align: left; }
hr.fleuron { border: 0; text-align: center; margin: 3em auto; }
hr.fleuron::after { content: "◇"; color: var(--ink-3); }
.footnotes { font-size: 15px; color: var(--ink-2); }

/* ---------- figures ---------- */
main { counter-reset: fig; }
figure.fig {
  counter-increment: fig; position: relative;
  background: var(--fig-bg); border: 1px solid var(--rule); border-radius: 6px;
  padding: 16px 16px 12px; margin: 2em auto;
  font: 14px/1.45 var(--sans); color: var(--ink-2);
}
figure.fig canvas.fig-canvas, figure.fig svg.fig-svg { display: block; width: 100%; touch-action: manipulation; }
figure.fig figcaption { margin-top: 10px; font: 14px/1.5 var(--sans); color: var(--ink-2); }
figure.fig figcaption::before { content: "図" counter(fig) "　"; font-family: var(--jp); color: var(--shu); font-weight: 600; }
.fig-missing { padding: 40px 10px; text-align: center; color: var(--ink-3); font-style: italic; border: 1px dashed var(--rule); border-radius: 4px; margin-bottom: 8px; }
.fig-controls { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-top: 10px; }
.fig-readout { margin-top: 8px; font: 14px/1.5 var(--sans); color: var(--ink-2); font-variant-numeric: tabular-nums lining-nums; min-height: 1.5em; }
.fig-readout b { color: var(--ink); font-weight: 600; }
.fig-readout .shu { color: var(--shu); }
.ctl { display: inline-flex; align-items: center; gap: 8px; font: 13px/1.3 var(--sans); color: var(--ink-2); }
.ctl-label { color: var(--ink-3); }
.ctl-slider input[type="range"] { width: 160px; accent-color: var(--shu); }
.ctl-slider.wide { flex: 1 1 320px; }
.ctl-slider.wide input[type="range"] { flex: 1; width: auto; }
.ctl-slider output { min-width: 4.5em; color: var(--ink); font-variant-numeric: tabular-nums lining-nums; }
.ctl-seg { gap: 0; flex-wrap: wrap; }
.ctl-seg .ctl-label { margin-right: 8px; }
.seg-btn, .btn {
  font: 13px/1.2 var(--sans); color: var(--ink-2); background: transparent; cursor: pointer;
  border: 1px solid var(--rule); padding: 5px 10px; margin: 0 -1px 0 0;
}
.seg-btn:first-of-type { border-radius: 4px 0 0 4px; }
.seg-btn:last-of-type { border-radius: 0 4px 4px 0; margin-right: 0; }
.seg-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); position: relative; z-index: 1; }
.seg-btn:hover:not([aria-pressed="true"]), .btn:hover { color: var(--ink); border-color: var(--ink-3); }
.btn { border-radius: 4px; margin: 0; }
.btn-primary { border-color: var(--shu); color: var(--shu); }
.btn-primary:hover { background: var(--shu); color: var(--paper); border-color: var(--shu); }
.btn-quiet { border-color: transparent; }
.ctl-check { cursor: pointer; }
.ctl-check input { accent-color: var(--shu); }
.fig-note { font-size: 12.5px; color: var(--ink-3); }
.fig-table { width: 100%; border-collapse: collapse; margin-top: 10px; font: 13px/1.35 var(--sans); font-variant-numeric: tabular-nums lining-nums; }
.fig-table th, .fig-table td { padding: 3px 8px; border-bottom: 1px solid var(--rule); text-align: right; }
.fig-table th { color: var(--ink-3); font-weight: 500; }
.fig-table td:first-child, .fig-table th:first-child { text-align: left; }
.fig-table tr.hot td { color: var(--shu); }
.fig-table tr.dim td { color: var(--ink-3); }
@media (max-width: 640px) {
  body { font-size: 17.5px; }
  figure.fig { padding: 12px 10px 10px; margin-left: -6px; margin-right: -6px; }
  .ctl-slider input[type="range"] { width: 120px; }
  .chapter-head h2 { font-size: 26px; }
}

/* ---------- coda ---------- */
.colophon { font: 14px/1.6 var(--sans); color: var(--ink-3); border-top: 1px solid var(--rule); padding-top: 1.2em; margin-top: 4em; }
