/* Site home (/) and book page (/<slug>/): "plain ink" on warm paper, covers face-out on a ledge. */

:root {
  --paper: #f7f6f2; --ink: #1c1d21; --muted: #565961; --faint: #656a78;
  --dim: #a3a6ad; --rule: #dfdcd3; --hair: #e3e0d8; --accent: #1f3f8f;
  --panel: #eeece6; --soft: #eef2ff; --ledge: #cfc8b8;
  --serif: Newsreader, 'Hiragino Mincho ProN', 'Yu Mincho', 'Noto Serif JP', serif;
  --ja-serif: 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', 'Noto Serif JP', serif;
  --sans: 'Source Sans 3', 'Hiragino Sans', 'Yu Gothic', 'Noto Sans JP', sans-serif;
  color-scheme: light;
}
/* mf.theme (one site-wide setting, shared with the reader; none = follow the system): the reader's
   palette (reader.css). The covers stay white paper in every theme. */
:root[data-theme="sepia"] {
  --paper: #f2eadb; --ink: #2c2619; --muted: #62553f; --faint: #75664d;
  --dim: #b3a487; --rule: #d6c8ae; --hair: #dccfb7; --accent: #2a4787;
  --panel: #e9dfcb; --soft: #e6dac3; --ledge: #c9b998;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper: #1f2023; --ink: #dddbd5; --muted: #a19e97; --faint: #8a877f;
    --dim: #5c5b58; --rule: #44454b; --hair: #36373c; --accent: #9fbde6;
    --panel: #28292d; --soft: #2a2f3a; --ledge: #6a6a70;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1f2023; --ink: #dddbd5; --muted: #a19e97; --faint: #8a877f;
  --dim: #5c5b58; --rule: #44454b; --hair: #36373c; --accent: #9fbde6;
  --panel: #28292d; --soft: #2a2f3a; --ledge: #6a6a70;
  color-scheme: dark;
}

/* ---------- Languages ---------- */
html:not([data-ui="ja"]) [data-l="ja"], html[data-ui="ja"] [data-l="en"] { display: none !important; }
.no-js .h-lang, .no-js .h-settings-toggle, .no-js .b-paths, .no-js .b-path-note, .no-js .b-asneeded { display: none !important; }

/* ---------- Base ---------- */
html { -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--serif); font-size: 19px; line-height: 1.6;
  overflow-wrap: break-word;
}
a { color: var(--ink); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
svg { display: block; }

.h-head, .h-hero, .h-continue, #books, #about, main, aside, footer, .b-layout {
  box-sizing: border-box; max-width: 1120px; margin-left: auto; margin-right: auto;
  padding-left: 24px; padding-right: 24px;
}

/* ---------- Header ---------- */
.h-head {
  display: flex; flex-wrap: wrap; gap: 12px 32px; align-items: baseline; justify-content: flex-end;
  padding-top: 22px; padding-bottom: 22px; border-bottom: 1px solid var(--ink);
}
.h-head nav { display: flex; flex-wrap: wrap; gap: 4px 20px; align-items: baseline; font-family: var(--sans); font-size: 16px; }
.h-head nav > a { padding: 10px 0; }
.h-head nav:has(> .h-mark) { gap: 6px 10px; font-family: var(--serif); font-size: inherit; }
.h-head nav:has(> .h-mark) em, .h-head nav:has(> .h-mark) i { color: var(--muted); }
.h-mark { text-decoration: none; font-size: 28px; font-weight: 600; letter-spacing: -0.01em; }
.h-head nav > .h-mark { padding: 0; }
.h-head > .h-mark { margin-right: auto; }
.h-head > .h-mark + nav + .h-tools { margin-left: 0; }
.b-paths button {
  min-height: 44px; padding: 0 2px; border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: 16px; color: var(--faint);
}
.b-paths button[aria-pressed="true"] {
  color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 6px;
}
.b-paths button:hover { color: var(--accent); }

/* Right-hand controls: the other language and aA (theme only), as in the reader's bar. */
.h-tools { position: relative; margin-left: auto; display: flex; align-items: center; gap: 4px; font-family: var(--sans); font-size: 15px; }
.h-tools button {
  font: inherit; color: inherit; background: none; cursor: pointer;
  min-width: 44px; min-height: 44px; border: 1px solid transparent; border-radius: 8px;
}
.h-tools > button:hover { background: var(--panel); }
.h-tools > .h-lang { padding: 0 6px; color: var(--muted); }
.h-settings-toggle { font-weight: 600; }
.h-settings-toggle[aria-expanded="true"] { color: var(--accent); }
.h-settings {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40;
  width: min(300px, calc(100vw - 16px)); box-sizing: border-box;
  padding: 12px; display: grid; gap: 12px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 12px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.15);
}
.h-settings[hidden] { display: none; }
.h-settings fieldset { margin: 0; padding: 0; border: 0; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.h-settings legend { padding: 0 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.h-settings button { flex: 1; padding: 0 8px; border-color: var(--rule); background: var(--panel); }
.h-settings button[aria-pressed="true"] { border-color: var(--accent); background: var(--soft); color: var(--accent); font-weight: 600; }
.h-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Hero (home) ---------- */
.h-hero { padding-top: 64px; padding-bottom: 40px; }
.h-hero h1 {
  margin: 0 0 14px; max-width: 18em; font-size: 50px; line-height: 1.1;
  font-weight: 400; letter-spacing: -0.015em; text-wrap: balance;
}
.h-lede { margin: 0; max-width: 34em; font-style: italic; color: var(--muted); }

/* ---------- Continue reading ---------- */
.h-continue { padding-bottom: 40px; }
.h-continue[hidden] { display: none; }
.h-continue-row {
  display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: baseline;
  padding: 14px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.h-continue-label { font-family: var(--sans); font-size: 14px; font-weight: 600; color: var(--muted); }
.h-continue-where { flex: 1 1 360px; min-width: 0; }
.h-continue-pct { color: var(--faint); font-size: 15px; }
.h-continue-go { font-family: var(--sans); font-size: 16px; font-weight: 600; }

/* ---------- Books ---------- */
#books { padding-top: 8px; padding-bottom: 48px; }
#books > h2 {
  margin: 0 0 24px; font-family: var(--sans); font-size: 15px; font-weight: 600;
  letter-spacing: 0.04em; color: var(--muted);
}
/* The home's shelf: a grid of cards, each cover, title, subtitle, meta, blurb, then the button. */
.h-shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 48px 32px; }
.h-book { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.h-hero:has(> .h-cover) { display: flex; flex-wrap: wrap; gap: 44px; align-items: flex-start; padding-top: 56px; padding-bottom: 48px; }
.h-hero > .h-cover + * { flex: 1 1 420px; min-width: 0; }

/* The cover: one series design in every theme, like printed paper. White with a spine in the
   book.json colour (--cover), the motif in a darker shade of it, the short title and subtitle,
   then the math-folio mark and the author. Sizes are in cqw, so it scales with its width. */
.h-cover {
  position: relative; display: block; max-width: 100%; aspect-ratio: 2 / 3; container-type: inline-size;
  background: linear-gradient(90deg, var(--cover, #4c8fdc) 5%, #ffffff 0); color: #1b1c20; text-decoration: none;
  box-shadow: 0 0 0 1px rgb(0 0 0 / .06), 0 14px 28px -18px rgb(20 20 20 / .45); border-radius: 1px 3px 3px 1px;
}
.h-cover > * { position: absolute; }
.h-cover > svg { left: 14cqw; right: 8cqw; top: 14cqw; width: 78cqw; height: auto; color: color-mix(in oklab, var(--cover) 78%, black); }
@supports (color: oklch(from red l c h)) { .h-cover > svg { color: oklch(from var(--cover) calc(l * .76) c h); } }
.h-cover-txt { left: 14cqw; right: 8cqw; bottom: 17cqw; }
.h-cover-txt > * { display: block; }
.h-cover-txt > :first-child {
  font-family: var(--serif); font-size: 8.4cqw; line-height: 1.12; font-weight: 500; letter-spacing: -0.01em; text-wrap: balance;
}
html[data-ui="ja"] .h-cover-txt > :first-child { font-size: 7.6cqw; font-weight: 600; letter-spacing: 0; line-height: 1.3; word-break: auto-phrase; }
.h-cover-txt > :last-child { margin-top: 3cqw; font-family: var(--sans); font-size: 4cqw; line-height: 1.35; color: #55575d; }
.h-cover-mark {
  left: 14cqw; bottom: 7cqw; display: flex; align-items: center; gap: 2cqw;
  font-family: var(--sans); font-size: 4cqw; font-weight: 600; letter-spacing: .06em; line-height: 1;
}
.h-cover-mark i { position: relative; width: 4.2cqw; height: 5.4cqw; box-sizing: border-box; border: .55cqw solid currentColor; }
.h-cover-mark i::after { content: ""; position: absolute; left: .9cqw; right: .9cqw; top: 1.1cqw; height: .55cqw; background: currentColor; }
.h-cover-au { right: 9cqw; bottom: 7.4cqw; font-family: var(--sans); font-size: 3.4cqw; letter-spacing: .08em; line-height: 1; color: #6a6c72; }
.h-hero > .h-cover { flex: 0 0 240px; }
/* On the home, each cover stands on a thin light-oak ledge. */
.h-book > .h-cover { margin-bottom: 14px; }
.h-book > .h-cover::after {
  content: ""; position: absolute; left: -12px; right: -12px; bottom: -14px; height: 6px;
  border-top: 1px solid var(--ledge); background: linear-gradient(var(--ledge), transparent); opacity: .55;
}

.h-book h3 { margin: 4px 0 0; font-size: 21px; line-height: 1.25; font-weight: 600; text-wrap: balance; }
.h-book h3 a { text-decoration: none; }
.h-book h3 a:hover { text-decoration: underline; }
.h-hero:has(> .h-cover) h1 { margin: 0; max-width: none; font-size: 44px; letter-spacing: -0.012em; }
.h-sub { font-style: italic; color: var(--muted); }
.h-book .h-sub { font-size: 16px; line-height: 1.4; }
.h-hero .h-sub { margin-top: 8px; font-size: 22px; }
.h-meta { font-family: var(--sans); color: var(--muted); }
.h-book .h-meta { font-size: 14px; }
.h-hero .h-meta { margin-top: 14px; font-size: 15px; }
.h-book p {
  margin: 0; font-size: 16px; line-height: 1.55; color: var(--muted);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden;
}
.h-hero:has(> .h-cover) p { margin: 16px 0 0; max-width: 36em; }
.h-actions {
  display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center;
  margin-top: 24px; font-family: var(--sans); font-size: 16px;
}
.h-book .h-actions { margin-top: auto; padding-top: 6px; }
.h-actions a { padding: 10px 0; }
.h-actions a.h-primary {
  min-height: 46px; box-sizing: border-box; display: inline-flex; align-items: center;
  padding: 0 22px; background: var(--ink); color: var(--paper); text-decoration: none; font-weight: 600;
}
.h-book .h-actions a.h-primary { min-height: 40px; padding: 0 16px; }
.h-actions a.h-primary:hover { background: var(--accent); color: var(--paper); }

/* ---------- Features (home) ---------- */
#about {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px;
  padding-top: 32px; padding-bottom: 56px; border-top: 1px solid var(--rule);
}
#about > h2 { grid-column: 1 / -1; margin: 0; font-family: var(--sans); font-size: 15px; font-weight: 600; color: var(--muted); }
#about :is(h3, dt, strong, b), #about > div > :first-child { display: block; margin: 0 0 4px; font-size: inherit; font-weight: 600; }
#about :is(p, dd), #about > div > :not(:first-child) { margin: 0; color: var(--muted); font-size: 17px; }

/* ---------- Book page: contents and aside ---------- */
.b-layout { display: flex; flex-wrap: wrap; gap: 56px; align-items: flex-start; padding-bottom: 72px; }
.b-layout > main, .b-layout > aside { padding-left: 0; padding-right: 0; margin: 0; }
main:has(.b-toc) { border-top: 1px solid var(--ink); padding-top: 20px; }
.b-layout > main { flex: 999 1 560px; min-width: 0; }
main:has(.b-toc) > h2 { margin: 0; font-size: 28px; font-weight: 600; }
main:has(.b-toc) > h2:has(+ .b-paths) { float: left; margin-right: 16px; }
.b-paths {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 16px; align-items: baseline;
  font-family: var(--sans); font-size: 15px; color: var(--faint);
}
.b-paths button { min-height: 44px; font-size: 15px; color: var(--muted); }
.b-paths button[aria-pressed="true"] { text-underline-offset: 5px; }
.b-path-note { clear: both; margin: 6px 0 12px; font-style: italic; color: var(--muted); font-size: 17px; }
.b-path-note[hidden] { display: none; }
.b-toc { clear: both; list-style: none; margin: 0; padding: 0; }
.b-toc > li {
  display: grid; grid-template-columns: 44px minmax(0, 1fr); column-gap: 12px; align-items: baseline;
  padding: 12px 0; border-top: 1px solid var(--hair);
}
.b-toc > li > * { grid-column: 2; min-width: 0; }
.b-toc > li > :first-child {
  grid-column: 1; grid-row: 1 / span 3;
  font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.b-toc a { font-weight: 600; text-decoration: none; }
.b-toc a:hover { text-decoration: underline; }
.b-toc > li > :not(:first-child):not(a):not(:has(a)) { color: var(--muted); font-size: 17px; }
.b-asneeded { font-style: italic; color: var(--muted); font-size: 17px; }
.b-asneeded[hidden] { display: none; }
.b-toc > li[data-dim], .b-toc > li[data-dim] * { color: var(--dim) !important; }
/* A \part: a heading row over its chapters (home.js dims it when the path dims all of them). */
.b-toc > li.b-part { border-top-color: var(--ink); }
.b-toc > li.b-part > * { font-size: 20px; font-weight: 600; }
.b-toc > li.b-part:not([data-dim]) > * { color: var(--ink) !important; }

.b-layout > aside { flex: 1 1 260px; max-width: 320px; }
aside { display: flex; flex-direction: column; gap: 28px; font-size: 17px; }
aside > section { border-top: 1px solid var(--ink); padding-top: 14px; }
aside h2 { margin: 0 0 8px; font-family: var(--sans); font-size: 15px; font-weight: 600; }
aside p { margin: 0 0 6px; color: var(--muted); }
aside li { color: var(--muted); }
aside ul { margin: 0; padding-left: 1.1em; }

/* ---------- Footer ---------- */
footer {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
  padding-top: 18px; padding-bottom: 32px; border-top: 1px solid var(--ink);
  font-family: var(--sans); font-size: 14px; color: var(--muted);
}

/* ---------- Narrow screens ---------- */
/* One shelf column (under 2 × 230px + gap + gutters): keep the cover book-sized. */
@media (max-width: 540px) { .h-book > .h-cover { width: 240px; } }
@media (max-width: 760px) {
  body { font-size: 18px; }
  .h-head, .h-hero, .h-continue, #books, #about, main, aside, footer, .b-layout { padding-left: 16px; padding-right: 16px; }
  .b-layout > main, .b-layout > aside { padding-left: 0; padding-right: 0; }
  .h-hero { padding-top: 40px; }
  .h-hero h1 { font-size: 36px; }
  .h-hero:has(> .h-cover) h1 { font-size: 32px; }
  .h-hero:has(> .h-cover) { gap: 28px; }
  .h-hero > .h-cover { flex-basis: 180px; width: 180px; }
  .h-hero > .h-cover + * { flex-basis: 100%; }
  #about { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .b-layout { gap: 40px; }
  .b-layout > aside { max-width: none; flex-basis: 100%; }
  main:has(.b-toc) > h2:has(+ .b-paths) { float: none; }
  .b-paths { justify-content: flex-start; }
}

/* Japanese headings and cover titles: one web face on every device (body text keeps the system fonts). */
:is(.h-hero h1, .h-book h3, .h-sub, h2, #about h3, .h-cover-txt > :first-child):lang(ja),
:is(.h-hero h1, .h-book h3, .h-sub, h2, #about h3, .h-cover-txt > :first-child) :lang(ja) { font-family: var(--ja-serif); }
/* Japanese has no italic; a synthetic slant reads as a mistake. */
:is(.h-lede, .h-sub, .b-path-note, .b-asneeded):lang(ja), :is(.h-lede, .h-sub, .b-path-note, .b-asneeded) :lang(ja) { font-style: normal; }
