/* ============================================================================
   Pokémon: The Origin of Species — unified styles
   Token architecture:
     :root / [data-theme]   surface / ink palette  (sepia · light · dark · oled)
     [data-font]            reading typeface        (serif · sans)
     [data-direction]       codex flavor            (manuscript · field · dex)
     [data-page="reader"]   locks overflow for 3-col reader shell
   ========================================================================== */

/* ── Fonts ───────────────────────────────────────────────────────────────── */
:root {
  --font-serif: "IBM Plex Serif", Georgia, "Times New Roman", serif;
  --font-sans:  "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono:  "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-body:  var(--font-serif);
}

/* ── Theme: Sepia (default) ──────────────────────────────────────────────── */
:root,
[data-theme="sepia"] {
  --paper:       oklch(0.957 0.013 78);
  --surface:     oklch(0.975 0.010 80);
  --surface-2:   oklch(0.935 0.016 76);
  --rail:        oklch(0.945 0.014 78);
  --ink:         oklch(0.305 0.022 55);
  --ink-soft:    oklch(0.46  0.020 55);
  --ink-faint:   oklch(0.62  0.016 58);
  --line:        oklch(0.88  0.018 74);
  --line-soft:   oklch(0.915 0.014 76);
  --accent:      oklch(0.55  0.15  35);
  --accent-ink:  oklch(0.47  0.16  35);
  --accent-soft: oklch(0.93  0.04  45);
  --hl:          oklch(0.90  0.055 80);
  --hl-edge:     oklch(0.78  0.11  70);
  --shadow:      0 1px 2px rgba(60,40,20,.05), 0 12px 30px rgba(60,40,20,.07);
  color-scheme: light;
}

[data-theme="light"] {
  --paper:       oklch(0.992 0.001 250);
  --surface:     oklch(1 0 0);
  --surface-2:   oklch(0.965 0.003 250);
  --rail:        oklch(0.975 0.002 250);
  --ink:         oklch(0.255 0.012 260);
  --ink-soft:    oklch(0.44  0.012 260);
  --ink-faint:   oklch(0.6   0.01  260);
  --line:        oklch(0.9   0.005 260);
  --line-soft:   oklch(0.945 0.004 260);
  --accent:      oklch(0.55  0.16  28);
  --accent-ink:  oklch(0.5   0.17  28);
  --accent-soft: oklch(0.95  0.03  30);
  --hl:          oklch(0.93  0.07  95);
  --hl-edge:     oklch(0.83  0.13  90);
  --shadow:      0 1px 2px rgba(20,20,40,.05), 0 14px 34px rgba(20,20,40,.08);
  color-scheme: light;
}

[data-theme="dark"] {
  --paper:       oklch(0.205 0.011 60);
  --surface:     oklch(0.245 0.012 60);
  --surface-2:   oklch(0.285 0.013 60);
  --rail:        oklch(0.23  0.012 60);
  --ink:         oklch(0.9   0.012 70);
  --ink-soft:    oklch(0.74  0.013 70);
  --ink-faint:   oklch(0.58  0.012 65);
  --line:        oklch(0.34  0.013 60);
  --line-soft:   oklch(0.3   0.012 60);
  --accent:      oklch(0.74  0.14  45);
  --accent-ink:  oklch(0.8   0.13  50);
  --accent-soft: oklch(0.34  0.06  45);
  --hl:          oklch(0.42  0.06  70);
  --hl-edge:     oklch(0.62  0.11  65);
  --shadow:      0 1px 2px rgba(0,0,0,.3), 0 16px 40px rgba(0,0,0,.45);
  color-scheme: dark;
}

[data-theme="oled"] {
  --paper:       oklch(0 0 0);
  --surface:     oklch(0.155 0.006 60);
  --surface-2:   oklch(0.2   0.008 60);
  --rail:        oklch(0.115 0.005 60);
  --ink:         oklch(0.92  0.01  70);
  --ink-soft:    oklch(0.72  0.012 70);
  --ink-faint:   oklch(0.55  0.011 65);
  --line:        oklch(0.27  0.01  60);
  --line-soft:   oklch(0.21  0.008 60);
  --accent:      oklch(0.76  0.15  50);
  --accent-ink:  oklch(0.82  0.14  52);
  --accent-soft: oklch(0.28  0.06  48);
  --hl:          oklch(0.34  0.07  70);
  --hl-edge:     oklch(0.6   0.12  62);
  --shadow:      0 1px 2px rgba(0,0,0,.5), 0 16px 40px rgba(0,0,0,.6);
  color-scheme: dark;
}

[data-font="serif"] { --font-body: var(--font-serif); }
[data-font="sans"]  { --font-body: var(--font-sans); }

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: color .35s ease, background-color .35s ease;
}
button { font-family: inherit; }
::selection { background: var(--hl); color: var(--ink); }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Reader page: lock overflow for 3-column shell ───────────────────────── */
[data-page="reader"],
[data-page="reader"] body {
  overflow: hidden;
}
[data-page="reader"] body {
  display: flex; flex-direction: column;
}

/* ============================================================================
   HOME PAGE
   ========================================================================== */

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.hnav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 16px;
  /* needed so the Aa menu drop-down positions relative to the bar */
  padding: 0 32px;
  height: 56px;
  background: color-mix(in oklch, var(--paper) 90%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  backdrop-filter: blur(12px) saturate(150%);
  border-bottom: 1px solid var(--line-soft);
}

.nav-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}
.nav-logo {
  width: 30px; height: 30px; flex: none;
  border-radius: 8px;
  background: linear-gradient(to bottom, var(--accent) 44%, #fff 44%);
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.nav-logo::before {
  content: ""; position: absolute; inset: 0;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, var(--surface) 0 22%, transparent 23%),
    linear-gradient(to bottom, transparent 44%, rgba(0,0,0,.28) 44% 56%, transparent 56%);
}
.nav-brand-txt { display: flex; flex-direction: column; line-height: 1.1; }
.nav-brand-txt b { font: 600 13px/1.2 var(--font-sans); color: var(--ink); letter-spacing: .01em; }
.nav-brand-txt span { font: 500 9.5px/1.4 var(--font-mono); color: var(--ink-faint); letter-spacing: .05em; text-transform: uppercase; }

.nav-links {
  display: flex; align-items: center; gap: 4px;
  margin: 0 auto;
}
.nav-link {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 6px 12px;
  font: 500 12.5px/1 var(--font-sans);
  color: var(--ink-soft);
  border-radius: 8px;
  text-decoration: none;
  transition: color .13s, background .13s;
}
.nav-link:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }
.nav-link .ext { font-size: 10px; opacity: .55; }

/* Aa button wrapper in navbar — menu drops below the button */
.nav-aa-wrap { position: relative; }
.nav-aa-wrap .menu-pop { top: 44px; right: 0; left: auto; }

.nav-cta {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 16px;
  background: var(--accent);
  color: oklch(0.97 0.01 75);
  border: none; border-radius: 9px;
  font: 600 12.5px/1 var(--font-sans);
  text-decoration: none; cursor: pointer; flex-shrink: 0;
  transition: filter .14s, transform .12s;
}
.nav-cta:hover { filter: brightness(1.07); transform: translateY(-1px); text-decoration: none; color: oklch(0.97 0.01 75); }

/* ── Page shell ──────────────────────────────────────────────────────────── */
.hw {
  min-height: 100vh;
  background: var(--paper);
  display: flex; flex-direction: column;
}
.hmain {
  flex: 1;
  max-width: 920px; width: 100%;
  margin: 0 auto;
  padding: 0 32px 100px;
}

/* ── Hero ────────────────────────────────────────────────────────────────── */
.hero {
  padding: 68px 0 62px;
  border-bottom: 1px solid var(--line);
  position: relative; overflow: hidden;
}
.hero-text { position: relative; z-index: 1; }
.hero-eyebrow {
  font: 600 16px/1 var(--font-mono);
  letter-spacing: .18em; text-transform: uppercase;
  color: var(--accent-ink); margin-bottom: 18px;
}
.hero-title {
  font: 600 clamp(43px, 7vw, 71px)/1.0 var(--font-serif);
  letter-spacing: -.025em; color: var(--ink); margin: 0 0 22px;
}
.hero-tagline {
  font: 500 12.5px/1 var(--font-mono);
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 22px;
}
.hero-desc {
  font: 400 16px/1.68 var(--font-serif);
  color: var(--ink-soft); max-width: 58ch;
  margin: 0 0 36px; text-wrap: pretty;
}
.hero-desc em { font-style: italic; color: var(--ink); }
.hero-ctas { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.btn-start {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 22px;
  background: var(--accent); color: oklch(0.97 0.01 75);
  border: none; border-radius: 11px;
  font: 600 13px/1 var(--font-sans);
  text-decoration: none; cursor: pointer;
  transition: filter .14s, transform .13s;
}
.btn-start:hover { filter: brightness(1.07); transform: translateY(-1px); text-decoration: none; color: oklch(0.97 0.01 75); }

.btn-outline {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 22px;
  background: var(--surface); color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 11px;
  font: 500 13px/1 var(--font-sans);
  text-decoration: none; cursor: pointer;
  transition: border-color .14s, color .14s, transform .13s;
}
.btn-outline:hover { border-color: var(--ink-faint); color: var(--ink); transform: translateY(-1px); text-decoration: none; }

.hero-ball {
  position: absolute; right: 60px; top: 50%; transform: translateY(-50%);
  width: 260px; height: 260px; opacity: .08; pointer-events: none;
}

/* ── Section chrome ──────────────────────────────────────────────────────── */
.section { padding: 50px 0 0; }
.sec-eyebrow {
  font: 600 10.5px/1 var(--font-mono);
  letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 20px;
}

/* ── Arc stack ───────────────────────────────────────────────────────────── */
.arc-stack { display: flex; flex-direction: column; gap: 12px; }

.arc-card {
  border: 1px solid var(--line); border-radius: 15px;
  background: var(--surface); overflow: hidden;
}
.arc-card.dim { opacity: .68; }
.arc-card .arc-head { cursor: pointer; user-select: none; }
.arc-card .arc-head a { cursor: auto; }

.arc-head {
  padding: 22px 26px 18px;
  display: grid; grid-template-columns: 52px 1fr;
  gap: 0 16px; align-items: start;
}
.arc-roman {
  font: 700 38px/1 var(--font-serif);
  color: var(--line); letter-spacing: -.02em; padding-top: 2px;
}
.arc-card:nth-child(1) .arc-roman { color: var(--ink-soft); opacity: .6; }
.arc-card:nth-child(2) .arc-roman { color: var(--ink-faint); opacity: .45; }
.arc-card:nth-child(3) .arc-roman { color: var(--ink-faint); opacity: .3; }

.arc-lbl {
  font: 600 10px/1 var(--font-mono);
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent-ink); margin-bottom: 5px;
}
.arc-card.dim .arc-lbl { color: var(--ink-faint); }
.arc-ttl { font: 600 19px/1.15 var(--font-serif); color: var(--ink); margin: 0 0 4px; }
.arc-meta { font: 400 11.5px/1 var(--font-mono); color: var(--ink-faint); }
.arc-desc {
  font: 400 13.5px/1.6 var(--font-sans); color: var(--ink-soft);
  margin: 11px 0 0; text-wrap: pretty; grid-column: 2;
}

.arc-foot { padding: 0 26px 18px 94px; display: flex; gap: 16px; align-items: center; }
.arc-ext {
  font: 500 11px/1 var(--font-mono); color: var(--accent-ink);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in oklch, var(--accent) 30%, transparent);
  padding-bottom: 1px; transition: border-color .13s;
}
.arc-ext:hover { border-bottom-color: var(--accent); text-decoration: none; }

/* ── Chapter list collapse ───────────────────────────────────────────────── */
.arc-collapse { display: none; }
.arc-collapse.open { display: block; }
.ch-toggle {
  background: none; border: none;
  font: 500 11px/1 var(--font-mono); letter-spacing: .04em;
  color: var(--ink-faint); cursor: pointer; padding: 0;
  transition: color .13s;
}
.ch-toggle:hover { color: var(--ink); }

.arc-avail {
  display: inline-flex; align-items: center; gap: 5px;
  font: 500 10.5px/1 var(--font-mono); color: var(--accent-ink); margin-top: 8px;
}
.arc-avail::before { content: '●'; font-size: 6px; opacity: .8; }

.ch-intro {
  padding: 14px 22px 10px;
  display: flex; flex-direction: column; gap: 4px;
  border-bottom: 1px solid var(--line-soft);
}
.ch-intro-label { font: 600 10px/1 var(--font-mono); letter-spacing: .13em; text-transform: uppercase; color: var(--ink-faint); }
.ch-intro-note { font: 400 12px/1.45 var(--font-sans); color: var(--ink-faint); }

.arc-divider { height: 1px; background: var(--line); margin: 0 16px; }
.ch-list { padding: 8px 10px 12px; display: flex; flex-direction: column; gap: 1px; }

.ch-row {
  display: grid; grid-template-columns: 32px 1fr auto;
  gap: 8px; align-items: center;
  padding: 7px 12px; border-radius: 8px;
  text-decoration: none; color: inherit;
  transition: background .12s;
}
.ch-row:hover { background: var(--surface-2); text-decoration: none; }
.ch-n { font: 500 11px/1 var(--font-mono); color: var(--ink-faint); text-align: right; }
.ch-t { font: 400 13px/1.3 var(--font-sans); color: var(--ink-soft); }
.ch-row.ch-cur .ch-n { color: var(--accent-ink); font-weight: 600; }
.ch-row.ch-cur .ch-t { color: var(--ink); font-weight: 600; }
.ch-row.ch-itl .ch-t { font-style: italic; color: var(--ink-faint); }
.ch-pin {
  font: 600 8.5px/1 var(--font-mono); letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent-ink);
  white-space: nowrap; flex-shrink: 0;
}
.ch-arrow { font: 400 11px/1 var(--font-mono); color: var(--ink-faint); opacity: .55; }

/* ── Coming soon ─────────────────────────────────────────────────────────── */
.coming-note { font: 400 13.5px/1.65 var(--font-sans); color: var(--ink-faint); max-width: 60ch; margin: 0 0 22px; }
.coming-note a { color: var(--accent-ink); text-decoration: none; }
.coming-note a:hover { text-decoration: underline; }

.coming-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0; }
.c-ch {
  display: grid; grid-template-columns: 30px 1fr; gap: 8px; align-items: baseline;
  padding: 5px 10px; border-radius: 7px; text-decoration: none; min-width: 0;
  transition: background .12s;
}
.c-ch:hover { background: var(--surface); text-decoration: none; }
.c-n { font: 500 10.5px/1.5 var(--font-mono); color: var(--ink-faint); text-align: right; white-space: nowrap; }
.c-t { font: 400 12.5px/1.5 var(--font-sans); color: var(--ink-soft); min-width: 0; }
.c-ch.c-itl .c-t { font-style: italic; color: var(--ink-faint); }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.hfooter {
  border-top: 1px solid var(--line); padding: 24px 32px;
  max-width: 920px; width: 100%; margin: 0 auto;
  font: 400 11px/1.5 var(--font-mono); color: var(--ink-faint);
  display: flex; gap: 6px 20px; flex-wrap: wrap; align-items: center;
}
.hfooter a { color: var(--accent-ink); text-decoration: none; }
.hfooter a:hover { text-decoration: underline; }
.hfooter .sep { opacity: .35; }

/* ── Home responsive ─────────────────────────────────────────────────────── */
@media (max-width: 700px) { .hero-ball { display: none; } }
@media (max-width: 600px) {
  .hnav { padding: 0 18px; }
  .nav-links { display: none; }
  .hmain { padding: 0 18px 80px; }
  .hfooter { padding: 20px 18px; }
  .arc-head { grid-template-columns: 42px 1fr; padding: 18px 18px 14px; }
  .arc-foot { padding: 0 18px 16px 76px; }
  .arc-divider { margin: 0 10px; }
  .ch-list { padding: 6px 6px 10px; }
  .coming-grid { grid-template-columns: 1fr; }
}

/* ============================================================================
   ARC PAGE
   ========================================================================== */
.arc-page-shell {
  max-width: 800px; width: 100%; margin: 0 auto; padding: 48px 32px 80px;
}
.arc-back {
  display: inline-flex; align-items: center; gap: 6px;
  font: 500 12px/1 var(--font-mono); color: var(--ink-soft);
  text-decoration: none; margin-bottom: 36px;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
  transition: color .13s, border-color .13s;
}
.arc-back:hover { color: var(--ink); border-color: var(--ink-faint); text-decoration: none; }

.arc-page-eyebrow {
  font: 600 11px/1 var(--font-mono); letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent-ink); margin-bottom: 14px;
}
.arc-page-title {
  font: 600 clamp(28px, 5vw, 42px)/1.08 var(--font-serif);
  letter-spacing: -.015em; color: var(--ink); margin: 0 0 8px;
}
.arc-page-range {
  font: 400 12px/1 var(--font-mono); color: var(--ink-faint);
  letter-spacing: .04em; text-transform: uppercase; margin-bottom: 36px;
}
.arc-page-divider { border: none; border-top: 1px solid var(--line); margin: 36px 0; }

.arc-section-label {
  font: 600 10.5px/1 var(--font-mono); letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 14px;
}
.arc-prose-block {
  font: 400 15px/1.75 var(--font-serif); color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 13px;
  background: var(--surface); padding: 22px 26px;
  margin-bottom: 28px;
}
.arc-prose-block p + p { margin-top: .85em; }
.arc-prose-block a { color: var(--accent-ink); }

.arc-ch-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.arc-ch-item a {
  display: grid; grid-template-columns: 36px 1fr auto;
  gap: 8px; align-items: center;
  padding: 10px 14px; border-radius: 10px;
  text-decoration: none; color: var(--ink-soft);
  font: 400 13.5px/1.3 var(--font-sans);
  transition: background .12s, color .12s;
}
.arc-ch-item a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.arc-ch-num { font: 500 11px/1 var(--font-mono); color: var(--ink-faint); text-align: right; }
.arc-ch-title { flex: 1; }
.arc-ch-arrow { font: 400 11px/1 var(--font-mono); color: var(--ink-faint); opacity: .5; }

/* ============================================================================
   READER PAGE — 3-column shell
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--lw, 286px) minmax(0, 1fr) var(--rw, 300px);
  grid-template-rows: 100%;
  height: 100vh;
  --lw: 286px;
  --rw: 300px;
}
.app[data-left="collapsed"]  { --lw: 52px; }
.app[data-right="collapsed"] { --rw: 52px; }

/* ── Shared sidebar chrome ───────────────────────────────────────────────── */
.side {
  position: relative;
  background-color: var(--rail);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
.side.right { border-right: 0; border-left: 1px solid var(--line); }

.side-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.side-scroll::-webkit-scrollbar { width: 9px; }
.side-scroll::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 6px;
  border: 3px solid transparent; background-clip: content-box;
}

/* ── Collapsed rail ──────────────────────────────────────────────────────── */
.rail { display: none; flex-direction: column; align-items: center; gap: 14px; padding: 14px 0; }
.app[data-left="collapsed"]  .side.left  .panel-full,
.app[data-right="collapsed"] .side.right .panel-full { display: none; }
.app[data-left="collapsed"]  .side.left  .rail,
.app[data-right="collapsed"] .side.right .rail { display: flex; }

.rail-btn {
  width: 36px; height: 36px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-soft);
  border-radius: 9px; cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s, color .15s, border-color .15s;
}
.rail-btn:hover { color: var(--accent-ink); border-color: var(--accent); }
.rail-label {
  writing-mode: vertical-rl;
  font: 600 11px/1 var(--font-mono); letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-faint); margin-top: 4px;
}
.rail-label-text { display: none; }
.app[data-left="collapsed"]  .side.left  .rail-label,
.app[data-right="collapsed"] .side.right .rail-label { display: block; }

/* ── Panel full ──────────────────────────────────────────────────────────── */
.panel-full { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 14px 12px 18px; gap: 8px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; flex: none; border-radius: 9px;
  background: linear-gradient(to bottom, var(--accent) 46%, #fff 46%); position: relative;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.brand-mark::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(circle at 50% 50%, var(--surface) 0 24%, transparent 25%),
    linear-gradient(to bottom, transparent 46%, rgba(0,0,0,.25) 46% 54%, transparent 54%);
}
.brand-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.1; }
.brand-txt b { font: 600 13.5px/1.2 var(--font-sans); color: var(--ink); letter-spacing: .01em; }
.brand-txt span { font: 500 10px/1.4 var(--font-mono); color: var(--ink-faint); letter-spacing: .04em; text-transform: uppercase; }

.icon-btn {
  width: 32px; height: 32px; flex: none;
  border: 1px solid transparent; background: transparent;
  color: var(--ink-faint); border-radius: 8px; cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ── Breadcrumbs ─────────────────────────────────────────────────────────── */
.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
  padding: 2px 18px 14px;
  font: 500 11px/1.4 var(--font-mono); color: var(--ink-faint);
}
.crumbs a { color: var(--ink-soft); text-decoration: none; border-radius: 4px; padding: 1px 3px; }
.crumbs a:hover { color: var(--accent-ink); background: var(--accent-soft); text-decoration: none; }
.crumbs .sep { opacity: .5; }
.crumbs .here { color: var(--ink); }

.side-divider { height: 1px; background: var(--line); margin: 0 18px; }

/* ── TOC ─────────────────────────────────────────────────────────────────── */
.toc { padding: 14px 10px 24px; }
.toc-arc { margin-bottom: 6px; }
.toc-arc-h {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; font: 600 10.5px/1 var(--font-mono);
  letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint);
}
.toc-arc-h a {
  font: 600 10.5px/1 var(--font-mono); color: var(--ink-soft);
  text-decoration: none; letter-spacing: .1em; text-transform: uppercase;
}
.toc-arc-h a:hover { color: var(--accent-ink); }
.toc-list { display: flex; flex-direction: column; gap: 1px; }
.toc-item {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: baseline;
  gap: 8px; padding: 8px 10px; border-radius: 9px;
  text-decoration: none; color: var(--ink-soft);
  transition: background .14s, color .14s;
}
.toc-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.toc-item .num { font: 500 11px/1.5 var(--font-mono); color: var(--ink-faint); }
.toc-item .ttl { font: 500 13px/1.35 var(--font-sans); }
.toc-item .mins { font: 400 10px/1.5 var(--font-mono); color: var(--ink-faint); opacity: 0; transition: opacity .14s; }
.toc-item:hover .mins, .toc-item.current .mins { opacity: 1; }
.toc-item.current {
  background: var(--accent-soft); color: var(--accent-ink);
  box-shadow: inset 2px 0 0 var(--accent);
}
.toc-item.current .num { color: var(--accent-ink); }
.toc-item.current .ttl { font-weight: 600; }
.toc-sections { padding-left: 14px; display: flex; flex-direction: column; gap: 1px; margin: 2px 0 4px; }
.toc-section-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px; border-radius: 7px;
  background: none; border: none; cursor: pointer; text-align: left; width: 100%;
  font: 400 12px/1.3 var(--font-sans); color: var(--ink-faint);
  text-decoration: none;
  transition: background .14s, color .14s;
}
.toc-section-item::before { content: '·'; color: var(--accent); margin-right: 2px; }
.toc-section-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }

/* ── Main reading column ─────────────────────────────────────────────────── */
.main { position: relative; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 22px;
  background: color-mix(in oklch, var(--paper) 86%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  backdrop-filter: blur(14px) saturate(150%);
  border-bottom: 1px solid var(--line-soft);
}
.topbar .chap-label { font: 500 12px/1.4 var(--font-mono); color: var(--ink-faint); letter-spacing: .02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .chap-label b { color: var(--ink-soft); font-weight: 600; }
.topbar .grow { flex: 1; min-width: 0; }

.reading-meta { display: flex; align-items: center; gap: 10px; font: 500 11.5px/1 var(--font-mono); color: var(--ink-faint); flex-shrink: 0; }
.reading-meta .pct { color: var(--ink-soft); }
.reading-meta .meter { width: 84px; height: 5px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.reading-meta .meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .15s linear; }

.tb-btn {
  height: 32px; padding: 0 11px;
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-soft); border-radius: 9px; cursor: pointer;
  font: 500 12px/1 var(--font-sans);
  transition: background .15s, color .15s, border-color .15s;
  flex-shrink: 0;
}
.tb-btn:hover { color: var(--ink); border-color: var(--ink-faint); }
.tb-btn.icon { padding: 0; width: 32px; justify-content: center; }
.tb-btn.mobile-only { display: none; }

/* ── Scroll progress hairline ────────────────────────────────────────────── */
.scroll-progress {
  position: absolute; left: 0; top: 0; height: 2px;
  background: var(--accent); z-index: 30;
  transition: width .12s linear; width: 0%;
}

/* ── Reader scroll pane ──────────────────────────────────────────────────── */
.reader-scroll {
  flex: 1; min-height: 0; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.reader-scroll::-webkit-scrollbar { width: 11px; }
.reader-scroll::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 7px;
  border: 3px solid transparent; background-clip: content-box;
}

/* ── Aa reading menu ─────────────────────────────────────────────────────── */
.menu-pop {
  position: absolute; z-index: 50; top: 52px; right: 18px;
  width: 268px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 14px;
  display: none; flex-direction: column; gap: 14px;
}
.menu-pop.open { display: flex; }
.menu-sect-label { font: 600 10px/1 var(--font-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 8px; }
.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.seg button {
  flex: 1; border: 0; background: transparent; cursor: pointer;
  padding: 7px 4px; border-radius: 7px;
  font: 500 12px/1 var(--font-sans); color: var(--ink-soft);
  transition: background .15s, color .15s;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.theme-seg button {
  font-size: 11px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 8px 4px 7px; gap: 0;
}
.theme-dot { width: 18px; height: 18px; border-radius: 50%; display: block; margin-bottom: 5px; border: 1px solid var(--line); flex-shrink: 0; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-row .v { font: 500 11px/1 var(--font-mono); color: var(--ink-faint); width: 42px; text-align: right; }

/* ── Article ─────────────────────────────────────────────────────────────── */
.article {
  max-width: calc(var(--measure, 68ch) + 0px);
  margin: 0 auto;
  padding: 54px 40px 40vh;
}

.chap-eyebrow {
  font: 600 11px/1 var(--font-mono); letter-spacing: .16em; text-transform: uppercase;
  color: var(--accent-ink); margin-bottom: 18px;
}
.chap-title {
  font: 600 clamp(30px, 4.4vw, 44px)/1.08 var(--font-serif);
  letter-spacing: -.01em; color: var(--ink); margin: 0 0 14px; text-wrap: balance;
}
[data-font="sans"] .chap-title { font-family: var(--font-sans); letter-spacing: -.02em; }
.chap-sub { font: 400 16px/1.5 var(--font-sans); color: var(--ink-soft); margin: 0 0 26px; max-width: 52ch; }
.chap-rule { border: 0; height: 1px; background: var(--line); margin: 0 0 30px; }
.chap-read-orig { font: 400 11px/1 var(--font-mono); color: var(--ink-faint); margin-bottom: 30px; }
.chap-read-orig a { color: var(--accent-ink); border-bottom: 1px solid color-mix(in oklch, var(--accent) 35%, transparent); }
.chap-read-orig a:hover { border-bottom-color: var(--accent); text-decoration: none; }

/* ── Prose ───────────────────────────────────────────────────────────────── */
.prose { font-family: var(--font-body); }
.prose p {
  font-size: var(--read-size, 15pt);
  line-height: var(--read-leading, 1.72);
  color: var(--ink); margin: 0 0 1.35em; text-wrap: pretty;
}
.prose p:first-of-type::first-letter {
  font-family: var(--font-serif); font-weight: 600;
  font-size: 3.1em; line-height: .82;
  float: left; padding: 6px 10px 0 0; color: var(--accent-ink);
}
[data-font="sans"] .prose p:first-of-type::first-letter { font-family: var(--font-sans); }
.prose em, .prose i { font-style: italic; }
.prose strong { font-weight: 700; color: var(--ink); }
.prose a { color: var(--accent-ink); border-bottom: 1.5px solid color-mix(in oklch, var(--accent) 45%, transparent); border-radius: 2px; padding: 0 1px; }
.prose a:hover { background: var(--accent-soft); border-bottom-color: var(--accent); text-decoration: none; }

/* ── Word-level highlight (reader.js) ────────────────────────────────────── */
.w { cursor: pointer; border-radius: 2px; transition: background .08s; }
.w:hover { background: color-mix(in oklch, var(--hl) 50%, transparent); }
.w.active { background: var(--hl); box-shadow: 0 0 0 3px var(--hl); }
.w.active.lessons-word { background: color-mix(in oklch, var(--hl) 70%, var(--accent-soft)); box-shadow: 0 0 0 3px color-mix(in oklch, var(--hl) 70%, var(--accent-soft)); }

/* ── Lesson callout ──────────────────────────────────────────────────────── */
.lesson {
  margin-top: 40px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); padding: 24px 28px 26px; box-shadow: var(--shadow);
}
.lesson-tag {
  display: inline-flex; align-items: center; gap: 7px;
  font: 600 10.5px/1 var(--font-mono); letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent-ink); margin-bottom: 12px;
}
.lesson-tag::before {
  content: ""; width: 13px; height: 13px; border-radius: 3px;
  background: var(--accent); display: inline-block;
}
.lesson h3 { font: 600 19px/1.3 var(--font-sans); margin: 0 0 12px; color: var(--ink); }
.lesson .prose p { font-size: calc(var(--read-size, 20px) - 2px); margin-bottom: 1em; }
.lesson .prose p:first-of-type::first-letter { all: unset; }

/* ── Chapter nav ─────────────────────────────────────────────────────────── */
.chap-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 44px; }
.chap-nav a {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 18px; border: 1px solid var(--line); border-radius: 13px;
  text-decoration: none; background: var(--surface);
  transition: border-color .15s, transform .15s;
}
.chap-nav a:hover { border-color: var(--accent); transform: translateY(-1px); text-decoration: none; }
.chap-nav a.next { text-align: right; }
.chap-nav .dir { font: 600 10px/1 var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); }
.chap-nav .name { font: 500 14px/1.3 var(--font-sans); color: var(--ink); }
.chap-nav a.disabled { opacity: .4; pointer-events: none; }

/* ── Right sidebar: player ───────────────────────────────────────────────── */
.player { padding: 16px 16px 18px; border-bottom: 1px solid var(--line); }
.player-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.player-head .lbl { font: 600 10.5px/1 var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); }

.now-card {
  display: flex; gap: 12px; align-items: center;
  padding: 11px; border-radius: 12px; background: var(--surface-2); margin-bottom: 14px;
}
.now-art {
  width: 46px; height: 46px; flex: none; border-radius: 9px;
  background: repeating-linear-gradient(45deg, var(--line) 0 6px, transparent 6px 12px), var(--surface);
  display: grid; place-items: center; color: var(--ink-faint); border: 1px solid var(--line);
  font: 500 9px/1.2 var(--font-mono); text-align: center; padding: 4px;
}
.now-meta { min-width: 0; line-height: 1.3; }
.now-meta .t { font: 500 13px/1.25 var(--font-sans); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-meta .s { font: 400 11px/1.3 var(--font-mono); color: var(--ink-faint); }

.transport { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 12px; }
.tp-btn {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-soft); border-radius: 50%;
  width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer;
  font-size: 14px;
  transition: background .14s, color .14s, border-color .14s;
}
.tp-btn:hover { color: var(--ink); border-color: var(--ink-faint); }
.tp-btn.tp-play {
  width: 50px; height: 50px;
  background: var(--accent); border-color: var(--accent); color: var(--surface);
}
.tp-btn.tp-play:hover { filter: brightness(1.05); }

.seek { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.seek-bar { position: relative; height: 6px; border-radius: 99px; background: var(--surface-2); cursor: pointer; }
.seek-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 99px; pointer-events: none; }
.seek-knob {
  position: absolute; top: 50%; width: 13px; height: 13px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent);
  transform: translate(-50%, -50%); box-shadow: 0 1px 3px rgba(0,0,0,.25); pointer-events: none;
}
.seek-time { display: flex; justify-content: space-between; font: 500 10.5px/1 var(--font-mono); color: var(--ink-faint); }

.pc-row { display: flex; gap: 8px; flex-wrap: wrap; }
.pc-field { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.pc-field > label { font: 600 9.5px/1 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); padding-left: 2px; }
.pc-select {
  height: 32px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--ink);
  width: 100%; padding: 0 26px 0 9px; font: 500 12px/1 var(--font-sans);
  appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path fill='gray' d='M0 0h10L5 6z'/></svg>");
  background-repeat: no-repeat; background-position: right 9px center;
}

.go-back-btn {
  display: none; width: 100%; margin-bottom: 10px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface-2); color: var(--accent-ink);
  font: 500 11.5px/1 var(--font-mono); cursor: pointer;
  text-align: left; transition: background .13s, border-color .13s;
}
.go-back-btn.visible { display: block; }
.go-back-btn:hover { background: var(--accent-soft); border-color: var(--accent); }

.player-hint { font: 400 11.5px/1.5 var(--font-sans); color: var(--ink-faint); margin-top: 12px; padding: 0 16px 16px; }

/* ── Right sidebar: codex ────────────────────────────────────────────────── */
.codex { padding: 16px 14px 30px; }
.codex-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 4px 12px; }
.codex-head .lbl { font: 600 10.5px/1 var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); }

.codex-list { display: flex; flex-direction: column; gap: 8px; }
.codex-card {
  display: grid; grid-template-columns: 52px 1fr; gap: 12px;
  padding: 11px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color .15s, box-shadow .15s;
}
.codex-card:hover { border-color: var(--ink-faint); }
.codex-card.in-view { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft); }

.sprite {
  width: 52px; height: 52px; border-radius: 10px; position: relative; overflow: hidden;
  display: grid; place-items: center; border: 1px solid var(--line);
  background: repeating-linear-gradient(45deg, color-mix(in oklch, var(--sprite-tint, var(--line)) 22%, var(--surface-2)) 0 5px, var(--surface-2) 5px 10px);
}
.sprite .ph { font: 500 8px/1.1 var(--font-mono); color: var(--ink-faint); text-align: center; padding: 2px; text-transform: lowercase; }
.sprite .dexno { position: absolute; top: 3px; left: 4px; font: 500 7.5px/1 var(--font-mono); color: var(--ink-faint); }
.sprite-img { width: 100%; height: 100%; object-fit: contain; }

.codex-body { min-width: 0; }
.codex-name { font: 600 14px/1.2 var(--font-sans); color: var(--ink); text-decoration: none; }
.codex-name:hover { color: var(--accent-ink); text-decoration: underline; }
.role-tag { font: 400 10.5px/1 var(--font-mono); color: var(--ink-faint); margin-top: 3px; }
.type-row { display: flex; gap: 5px; margin-top: 7px; flex-wrap: wrap; }
.chip {
  font: 600 9.5px/1 var(--font-mono); letter-spacing: .04em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 999px;
  background: var(--chip-bg, var(--surface-2)); 
  color: var(--chip-fg, var(--ink-faint)); 
  border: 1px solid var(--chip-border, var(--line));
}
.codex-blurb { font: 400 12px/1.5 var(--font-sans); color: var(--ink-soft); margin-top: 9px; grid-column: 1 / -1; }
.codex-empty {
  border: 1px dashed var(--line); border-radius: 12px; padding: 16px; text-align: center;
  font: 400 11.5px/1.5 var(--font-sans); color: var(--ink-faint);
}
.codex-sub-label {
  font: 600 10px/1 var(--font-mono); letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-faint); padding: 22px 4px 10px;
}

/* ── Reader mobile responsive ─────────────────────────────────────────────── */
.scrim { display: none; }
@media (max-width: 1080px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: fixed; top: 0; bottom: 0; z-index: 200; width: 300px;
    box-shadow: 0 0 60px rgba(0,0,0,.25);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
  }
  .side.left { left: 0; transform: translateX(-104%); }
  .side.right { right: 0; left: auto; transform: translateX(104%); }
  .app[data-left="open"] .side.left { transform: none; }
  .app[data-right="open"] .side.right { transform: none; }
  .scrim {
    display: none; position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.4);
  }
  .app[data-left="open"] .scrim,
  .app[data-right="open"] .scrim { display: block; }
  .tb-btn.mobile-only { display: inline-flex; }
  .article { padding: 40px 22px 40vh; }
}
@media (min-width: 1081px) {
  .app[data-left="collapsed"]  .side.left  .rail,
  .app[data-right="collapsed"] .side.right .rail { display: flex; }
}
