/* Every Good Regulator — reading site.
   Motion uses only opacity and transform, runs once, and is switched off for prefers-reduced-motion. */

:root {
  --paper: #f6f3ec;
  --paper-2: #efeae0;
  --card: #fffdf8;
  --ink: #16202a;
  --ink-2: #3c4651;
  --muted: #6b7178;
  --line: #ddd6c8;
  --grid: rgba(20, 45, 80, .055);
  --accent: #d9582a;
  --accent-soft: #fbe6da;
  --accent-ink: #a8401b;
  --good: #3f7a52;
  --shadow: 0 1px 2px rgba(22, 32, 42, .06), 0 8px 28px rgba(22, 32, 42, .08);
  --radius: 14px;
  --serif: "Literata", Georgia, "Times New Roman", serif;
  --display: "Gloock", Georgia, serif;
  --ui: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --measure: 40rem;
  --top: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #11161c; --paper-2: #161d25; --card: #19212b; --ink: #e9e4da; --ink-2: #c3beb4; --muted: #8f949a;
    --line: #2a333e; --grid: rgba(160, 190, 230, .045); --accent: #f07a48; --accent-soft: #3a2419; --accent-ink: #ffb08c;
    --good: #7cc195; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #11161c; --paper-2: #161d25; --card: #19212b; --ink: #e9e4da; --ink-2: #c3beb4; --muted: #8f949a;
  --line: #2a333e; --grid: rgba(160, 190, 230, .045); --accent: #f07a48; --accent-soft: #3a2419; --accent-ink: #ffb08c;
  --good: #7cc195; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--top) + 16px); }
body {
  margin: 0; background: var(--paper); color: var(--ink); font-family: var(--serif); font-size: 1.0625rem; line-height: 1.7;
  text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
}
img { max-width: 100%; height: auto; }
a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 8px; font-family: var(--ui); }
.skip:focus { left: 12px; }

@view-transition { navigation: auto; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--top); display: flex; align-items: center; gap: 12px;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--paper) 86%, transparent); border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: saturate(1.4) blur(10px); backdrop-filter: saturate(1.4) blur(10px);
  font-family: var(--ui); font-size: .9rem;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: var(--display); font-weight: 400; font-size: 1.3rem; white-space: nowrap; }
.brand-mark { width: 10px; height: 22px; border-radius: 5px; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.crumb { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; border: 1px solid transparent;
  background: transparent; color: var(--ink); cursor: pointer; list-style: none; transition: background .2s, border-color .2s;
}
.icon-btn:hover { background: var(--paper-2); border-color: var(--line); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn summary::-webkit-details-marker, summary.icon-btn::-webkit-details-marker { display: none; }
.theme-btn .moon { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .sun { display: none; }
  :root:not([data-theme="light"]) .theme-btn .moon { display: block; }
}
.pill { font-family: var(--ui); font-weight: 600; text-decoration: none; color: var(--ink); padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; }
.pill:hover { border-color: var(--accent); color: var(--accent-ink); }
.dl { position: relative; }
.dl-menu {
  position: absolute; right: 0; top: 48px; min-width: 200px; padding: 6px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); display: grid;
}
.dl-menu a { padding: 10px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.dl-menu a:hover { background: var(--paper-2); }
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 40; pointer-events: none; }
.progress span { display: block; height: 100%; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); }

/* ---------- reader layout ---------- */
.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); max-width: 1320px; margin: 0 auto; }
.sidebar {
  position: sticky; top: var(--top); height: calc(100dvh - var(--top)); overflow-y: auto; overscroll-behavior: contain;
  padding: 22px 14px 40px 20px; border-right: 1px solid var(--line); font-family: var(--ui); font-size: .86rem;
  scrollbar-width: thin;
}
.sidebar-head { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.sidebar-head img { width: 54px; border-radius: 4px; box-shadow: var(--shadow); }
.sidebar-head strong { display: block; font-family: var(--display); font-size: 1rem; }
.sidebar-head span { color: var(--muted); font-size: .8rem; }
.toc { list-style: none; margin: 0; padding: 0; }
.toc li a { display: grid; grid-template-columns: 74px 1fr; gap: 8px; padding: 7px 10px; border-radius: 9px; color: var(--ink-2); text-decoration: none; line-height: 1.35; }
.toc li a:hover { background: var(--paper-2); color: var(--ink); }
.toc .toc-k { color: var(--muted); font-size: .75rem; padding-top: 1px; }
.toc li.current a { background: var(--accent-soft); color: var(--ink); }
.toc li.current .toc-k { color: var(--accent-ink); }
.toc-part { margin: 16px 10px 6px; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-ink); font-weight: 600; }
main { min-width: 0; outline: none; }
.prose { max-width: var(--measure); margin: 0 auto; padding: 44px 24px 24px; }
.scrim { display: none; }

/* ---------- typography ---------- */
.prose h1 { font-family: var(--display); font-weight: 400; font-size: clamp(2.3rem, 1.5rem + 3.4vw, 3.5rem); line-height: 1.04; letter-spacing: -.01em; margin: 1.6em 0 .5em; text-wrap: balance; }
.prose > h1:first-child { margin-top: .2em; }
.prose h1[id^="part-"] { font-size: .95rem; font-family: var(--ui); text-transform: uppercase; letter-spacing: .1em; color: var(--accent-ink); margin: 0 0 1.5em; }
.prose h2 { font-family: var(--display); font-weight: 400; font-size: clamp(1.65rem, 1.3rem + 1.1vw, 2.05rem); line-height: 1.2; margin: 2.2em 0 .6em; text-wrap: balance; position: relative; }
.prose h3 { font-family: var(--display); font-weight: 400; font-size: 1.45rem; margin: 1.8em 0 .4em; position: relative; }
.anchor { position: absolute; left: -1.1em; color: var(--muted); text-decoration: none; opacity: 0; transition: opacity .2s; font-weight: 400; }
h2:hover .anchor, h3:hover .anchor { opacity: 1; }
.prose p { margin: 0 0 1.05em; hanging-punctuation: first; }
.prose > h1 + p > em:only-child { display: block; font-size: 1.2rem; color: var(--ink-2); line-height: 1.5; }
.prose hr { border: 0; height: 1px; background: var(--line); margin: 2.6em auto; width: 40%; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin: .3em 0; }
.prose strong { font-weight: 600; }
.prose table { width: 100%; border-collapse: collapse; font-size: .92rem; display: block; overflow-x: auto; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.prose code { font-size: .9em; background: var(--paper-2); padding: 1px 5px; border-radius: 5px; }
sup a, .footnote-ref { text-decoration: none; font-family: var(--ui); font-size: .75em; }
.footnotes { font-size: .9rem; color: var(--ink-2); border-top: 1px solid var(--line); margin-top: 3em; padding-top: 1em; }
.footnotes hr { display: none; }

/* epigraph: the first blockquote after the chapter title */
.prose h1 + p + .box:not([class*="box-"]), .prose h1 + .box:not([class*="box-"]) { background: none; border: 0; box-shadow: none; padding: 0 0 0 2.4rem; position: relative; font-style: italic; color: var(--ink-2); }
.prose h1 + p + .box:not([class*="box-"])::before, .prose h1 + .box:not([class*="box-"])::before { content: "“"; position: absolute; left: 0; top: -.35em; font-family: var(--display); font-size: 3.6rem; line-height: 1; color: var(--accent); font-style: normal; }

/* ---------- boxes ---------- */
.box { margin: 1.8em 0; padding: 18px 20px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.box p:last-child { margin-bottom: 0; }
.box > p:first-child > strong:first-child { display: block; font-family: var(--ui); font-size: .72rem; letter-spacing: .09em; text-transform: uppercase; color: var(--accent-ink); margin-bottom: 2px; }
.box-weird { background: linear-gradient(135deg, var(--accent-soft), var(--card) 60%); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.box-small { background: color-mix(in srgb, var(--good) 8%, var(--card)); border-color: color-mix(in srgb, var(--good) 30%, var(--line)); }
.box-small > p:first-child > strong:first-child { color: var(--good); }
.box-myth { background: repeating-linear-gradient(135deg, var(--card) 0 14px, color-mix(in srgb, var(--accent) 4%, var(--card)) 14px 28px); }
.box-movies { background: color-mix(in srgb, #6b7fd6 8%, var(--card)); border-color: color-mix(in srgb, #6b7fd6 30%, var(--line)); }
.box-movies > p:first-child > strong:first-child { color: #6b7fd6; }
.box-try { border: 1.5px dashed color-mix(in srgb, var(--accent) 60%, var(--line)); }
.box-mech { background: var(--card); }
.box.haiku { text-align: center; font-family: var(--display); font-size: 1.3rem; line-height: 1.6; background: none; border: 0; box-shadow: none; padding: 10px 0; }
.box.haiku p { margin: 0; }

/* ---------- figures ---------- */
figure { margin: 2em 0; }
figure img, .prose p > img { display: block; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: zoom-in; transition: transform .25s ease, box-shadow .25s ease; }
figure img:hover { box-shadow: var(--shadow); }
figcaption { font-family: var(--ui); font-size: .82rem; color: var(--muted); text-align: center; margin-top: .6em; }
.kind-ev .prose { max-width: 60rem; }
:root[data-theme="dark"] figure img { filter: brightness(.94); }

/* ---------- pager ---------- */
.pager { max-width: var(--measure); margin: 40px auto 10px; padding: 0 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pager a { display: grid; gap: 2px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); text-decoration: none; transition: border-color .2s, transform .2s; }
.pager a:hover { border-color: var(--accent); transform: translateY(-2px); }
.pager span { font-family: var(--ui); font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.pager strong { font-family: var(--display); font-weight: 400; line-height: 1.3; }
.pager .next { text-align: right; }
.foot { max-width: var(--measure); margin: 30px auto; padding: 20px 24px 40px; font-family: var(--ui); font-size: .8rem; color: var(--muted); }

/* ---------- lightbox ---------- */
.lightbox { border: 0; padding: 0; background: transparent; max-width: 96vw; max-height: 94dvh; overflow: visible; }
.lightbox::backdrop { background: rgba(8, 12, 16, .82); }
.lb-frame img { display: block; max-width: 96vw; max-height: 86dvh; width: auto; border-radius: 10px; background: #fff; }
.lb-cap { color: #eee; text-align: center; font-family: var(--ui); font-size: .85rem; margin: 10px 0 0; }
.lightbox .close { position: absolute; top: -48px; right: 0; color: #fff; font-size: 1.1rem; }

/* ---------- home ---------- */
.topbar-home { background: transparent; border-bottom-color: transparent; }
.home .topbar-home.scrolled { background: color-mix(in srgb, var(--paper) 86%, transparent); border-bottom-color: var(--line); }
.hero { max-width: 1180px; margin: 0 auto; padding: 5vh 24px 7vh; display: grid; grid-template-columns: 1.1fr .9fr; gap: 48px; align-items: center; min-height: calc(92dvh - var(--top)); }
.eyebrow { font-family: var(--ui); font-weight: 600; font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-ink); margin: 0 0 14px; }
.hero h1 { font-family: var(--display); font-weight: 400; font-size: clamp(3.4rem, 1.8rem + 7vw, 7.2rem); line-height: .9; letter-spacing: -.02em; margin: 0 0 18px; }
.hero h1 span { display: block; color: var(--accent); font-style: italic; }
.lede { font-size: clamp(1.15rem, 1rem + .6vw, 1.45rem); color: var(--ink-2); max-width: 30ch; line-height: 1.45; margin: 0 0 12px; }
.byline { font-family: var(--ui); font-weight: 600; color: var(--muted); margin: 0 0 28px; }
.cta { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 14px 22px; border-radius: 12px; font-family: var(--ui); font-weight: 600; text-decoration: none; transition: transform .2s, box-shadow .2s, background .2s; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn-primary:hover { color: #fff; transform: translateY(-2px); }
.btn-ghost { border: 1px solid var(--line); color: var(--ink); background: var(--card); }
.btn-ghost:hover { border-color: var(--accent); }
.downloads { font-family: var(--ui); font-size: .88rem; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.hero-art { position: relative; display: grid; place-items: center; }
.cover-wrap { position: relative; z-index: 2; width: min(340px, 70vw); transform: rotate(-3deg); transition: transform .5s cubic-bezier(.2, .8, .2, 1); }
.cover-wrap img { display: block; width: 100%; border-radius: 6px 12px 12px 6px; box-shadow: -2px 0 0 rgba(0,0,0,.15) inset, 0 30px 60px rgba(22, 32, 42, .28), 0 6px 14px rgba(22, 32, 42, .18); }
.hero-art:hover .cover-wrap { transform: rotate(0deg) translateY(-6px); }
.loop { position: absolute; width: min(470px, 96vw); z-index: 1; }
.loop circle { fill: none; stroke: var(--line); stroke-width: 2; }
.loop .loop-run { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 90 1041; transform-origin: 200px 200px; animation: orbit 9s linear infinite; }
@keyframes orbit { to { transform: rotate(360deg); } }

.intro { max-width: 46rem; margin: 0 auto; padding: 20px 24px 40px; font-size: 1.2rem; line-height: 1.65; }
.intro-q { font-family: var(--display); font-size: 1.45rem; line-height: 1.4; }
.words, .contents { max-width: 1180px; margin: 0 auto; padding: 40px 24px; }
.words h2, .contents h2 { font-family: var(--display); font-size: clamp(1.8rem, 1.3rem + 2vw, 2.6rem); margin: 0 0 22px; }
.word-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.word { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 18px; transition: transform .25s, border-color .25s, box-shadow .25s; }
.word:hover { transform: translateY(-4px); border-color: var(--accent); box-shadow: var(--shadow); }
.w-n { font-family: var(--ui); font-size: .75rem; color: var(--accent-ink); font-weight: 600; }
.word h3 { font-family: var(--display); font-size: 1.45rem; margin: 6px 0 8px; }
.word p { margin: 0; font-size: .95rem; color: var(--ink-2); line-height: 1.55; }
.stats { max-width: 1180px; margin: 10px auto; padding: 28px 24px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; text-align: center; }
.stats strong { display: block; font-family: var(--display); font-size: clamp(2.2rem, 1.6rem + 2vw, 3.2rem); color: var(--accent); line-height: 1; }
.stats span { font-family: var(--ui); font-size: .85rem; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.grid-part { grid-column: 1 / -1; font-family: var(--ui); font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-ink); margin: 22px 0 2px; }
.card { display: grid; gap: 4px; align-content: start; min-height: 96px; padding: 16px 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); transition: transform .22s, border-color .22s, box-shadow .22s; }
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow); color: var(--ink); }
.card-k { font-family: var(--ui); font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.card-t { font-family: var(--display); font-size: 1.12rem; line-height: 1.25; }
.card-interlude, .card-ev { background: var(--paper-2); }
.card-interlude .card-k, .card-ev .card-k { color: var(--accent-ink); }
.foot-home { max-width: 1180px; text-align: center; }

/* ---------- motion (opt-in via .js, off for reduced motion) ---------- */
.js .reveal { opacity: 0; transform: translateY(14px); transition: opacity .6s ease, transform .6s cubic-bezier(.2, .8, .2, 1); transition-delay: calc(var(--i, 0) * 70ms); }
.js .reveal.in { opacity: 1; transform: none; }
.js .rise { opacity: 0; transform: translateY(16px); animation: rise .8s cubic-bezier(.2, .8, .2, 1) forwards; animation-delay: calc(var(--d, 0) * 90ms + 80ms); }
@keyframes rise { to { opacity: 1; transform: none; } }
.js .cover-wrap { animation: floatin 1.1s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes floatin { from { opacity: 0; transform: rotate(-8deg) translateY(30px) scale(.96); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .js .reveal, .js .rise { opacity: 1 !important; transform: none !important; }
  @view-transition { navigation: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .word-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; width: min(86vw, 330px); height: 100dvh; background: var(--card);
    border-right: 1px solid var(--line); box-shadow: var(--shadow); transform: translateX(-102%); transition: transform .3s cubic-bezier(.2, .8, .2, 1);
    padding-top: max(22px, env(safe-area-inset-top)); visibility: hidden;
  }
  body.toc-open .sidebar { transform: none; visibility: visible; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(8, 12, 16, .45); opacity: 0; transition: opacity .3s; pointer-events: none; }
  body.toc-open .scrim { opacity: 1; pointer-events: auto; }
  body.toc-open { overflow: hidden; }
  .hero { grid-template-columns: 1fr; text-align: left; padding-top: 3vh; min-height: 0; gap: 30px; }
  .hero-art { order: -1; }
  .cover-wrap { width: min(230px, 58vw); }
  .loop { width: min(330px, 86vw); }
}
@media (min-width: 961px) { .menu-btn { display: none; } }
@media (max-width: 640px) {
  body { font-size: 1.03rem; }
  .crumb { display: none; }
  .prose { padding: 26px 18px 10px; }
  .word-grid { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .pager { grid-template-columns: 1fr; padding: 0 18px; }
  .pager .next { text-align: left; }
  .box { padding: 16px; margin-left: -4px; margin-right: -4px; }
  .anchor { display: none; }
}
@media print {
  .topbar, .sidebar, .pager, .progress, .foot { display: none !important; }
  body { background: #fff; }
  .layout { display: block; }
}
