/* =========================================================
   Aab-e-Hayat — a quiet reading edition
   ========================================================= */

:root {
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-read: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --reader-size: 19px;
  --reader-leading: 1.84;

  --bg: #f3ede1;
  --bg-deep: #e9dfcd;
  --paper: #fffdf7;
  --paper-2: #faf5e9;
  --paper-3: #f4ecdd;
  --ink: #27231c;
  --ink-soft: #4b4439;
  --muted: #746b5b;
  --line: #e3d8c5;
  --line-strong: #d2c2a7;
  --emerald: #0f5c4e;
  --emerald-deep: #0a4338;
  --emerald-soft: #e2efe9;
  --gold: #a37532;
  --gold-soft: #f3e5c8;
  --on-accent: #fffdf7;
  --danger: #9d3d33;
  --shadow-sm: 0 2px 10px rgba(55, 42, 22, 0.06);
  --shadow-md: 0 14px 40px rgba(55, 42, 22, 0.10);
  --shadow-lg: 0 30px 80px rgba(35, 28, 16, 0.20);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --topbar: 72px;
  --sidebar: 304px;
  --ease: cubic-bezier(.2, .7, .25, 1);
}

[data-theme="sepia"] {
  --bg: #eadcc3;
  --bg-deep: #ddc9a7;
  --paper: #fbf0dc;
  --paper-2: #f6e8d0;
  --paper-3: #f0dfc3;
  --ink: #382c1e;
  --ink-soft: #5a4935;
  --muted: #7c674d;
  --line: #d9c4a4;
  --line-strong: #c6aa82;
  --emerald: #6f4324;
  --emerald-deep: #573219;
  --emerald-soft: #f0dfc5;
  --gold: #98672e;
  --gold-soft: #efd9b4;
  --on-accent: #fff9ef;
  --shadow-sm: 0 2px 10px rgba(80, 50, 20, 0.07);
  --shadow-md: 0 14px 40px rgba(80, 50, 20, 0.12);
  --shadow-lg: 0 30px 80px rgba(60, 35, 10, 0.22);
}

[data-theme="dark"] {
  --bg: #0b1413;
  --bg-deep: #08100f;
  --paper: #111e1c;
  --paper-2: #152522;
  --paper-3: #1a2c28;
  --ink: #e9e2d3;
  --ink-soft: #c7bfae;
  --muted: #a49a87;
  --line: #243a35;
  --line-strong: #335048;
  --emerald: #6fd6bd;
  --emerald-deep: #9ae7d4;
  --emerald-soft: #16312b;
  --gold: #d8b06a;
  --gold-soft: #2b2418;
  --on-accent: #06201b;
  --danger: #f0a096;
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.30);
  --shadow-md: 0 16px 44px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 36px 90px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(1000px 600px at 85% -10%, rgba(163, 117, 50, 0.10), transparent 60%),
    radial-gradient(900px 700px at -10% 100%, rgba(15, 92, 78, 0.09), transparent 60%);
}
[data-theme="dark"] body::before {
  background:
    radial-gradient(1000px 600px at 85% -10%, rgba(216, 176, 106, 0.07), transparent 60%),
    radial-gradient(900px 700px at -10% 100%, rgba(111, 214, 189, 0.06), transparent 60%);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--emerald); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--emerald); outline-offset: 3px; }
::selection { background: var(--gold-soft); color: var(--ink); }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; left: 16px; top: -80px; z-index: 200;
  padding: 12px 18px; border-radius: 999px;
  background: var(--emerald); color: var(--on-accent);
  font-weight: 650; transition: top .2s var(--ease);
}
.skip-link:focus { top: 14px; text-decoration: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: relative;
  z-index: 50;
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 clamp(14px, 3vw, 28px);
  background: rgba(255, 253, 247, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(1.1);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
}
[data-theme="sepia"] .topbar { background: rgba(251, 240, 220, 0.84); }
[data-theme="dark"] .topbar { background: rgba(11, 20, 19, 0.82); }

.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand img {
  width: 38px; height: 38px; border-radius: 11px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
  background: var(--paper);
}
.brand-text {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  line-height: 1.05;
  white-space: nowrap;
}
.brand-text small {
  display: block;
  margin-top: 3px;
  font-family: var(--font-ui);
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-2);
  color: var(--ink-soft);
  transition: background .18s, color .18s, border-color .18s, transform .18s;
}
.icon-btn:hover { background: var(--emerald); border-color: var(--emerald); color: var(--on-accent); transform: translateY(-1px); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.is-on { background: var(--emerald); border-color: var(--emerald); color: var(--on-accent); }

.search-trigger {
  display: flex; align-items: center; gap: 10px;
  min-width: 230px;
  padding: 10px 12px 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--muted);
  font-size: 13px;
  text-align: left;
  transition: border-color .18s, background .18s, box-shadow .18s;
}
.search-trigger:hover { border-color: var(--line-strong); background: var(--paper); }
.search-trigger svg { width: 17px; height: 17px; flex: none; }
.search-trigger span { flex: 1; }
.search-trigger kbd {
  font-family: var(--font-ui);
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 6px;
  background: var(--paper);
}

.font-group {
  display: flex; align-items: center; gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-2);
}
.font-group button {
  width: 34px; height: 32px;
  border: 0; border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px; font-weight: 750;
}
.font-group button:hover { background: var(--emerald); color: var(--on-accent); }

.theme-wrap { position: relative; }
.theme-menu {
  position: absolute; right: 0; top: calc(100% + 10px);
  width: 190px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow-md);
  z-index: 80;
}
.theme-menu-title {
  margin: 2px 8px 8px;
  font-size: 10px; font-weight: 750; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--muted);
}
.theme-menu button {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border: 0; border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px; text-align: left;
}
.theme-menu button:hover { background: var(--paper-2); }
.theme-menu button.is-active { background: var(--emerald-soft); color: var(--emerald); font-weight: 700; }
.theme-menu-sep { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.switch { position: relative; width: 28px; height: 16px; flex: none; border-radius: 999px; background: var(--line-strong); transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--paper); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .2s; }
[aria-checked="true"] > .switch { background: var(--emerald); }
[aria-checked="true"] > .switch::after { transform: translateX(12px); }
.swatch { width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line-strong); flex: none; }
.swatch-auto { background: linear-gradient(90deg, #fffdf7 50%, #111e1c 50%); }
.swatch-light { background: #fffdf7; }
.swatch-sepia { background: #fbf0dc; }
.swatch-dark { background: #111e1c; }

/* ---------- Shell ---------- */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  height: calc(100dvh - var(--topbar));
  height: calc(100vh - var(--topbar));
}
.main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: auto;
  outline: none;
  overscroll-behavior: contain;
}
.main::-webkit-scrollbar, .sidebar::-webkit-scrollbar { width: 10px; }
.main::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box;
}
.main { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.sidebar { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar);
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(255, 253, 247, 0.62);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
[data-theme="sepia"] .sidebar { background: rgba(251, 240, 220, 0.58); }
[data-theme="dark"] .sidebar { background: rgba(11, 20, 19, 0.58); }
.sidebar-head {
  display: flex; align-items: center; gap: 8px;
  padding: 18px 16px 10px;
}
.sidebar-tabs {
  flex: 1;
  display: flex; gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--paper-2);
  border: 1px solid var(--line);
}
.sidebar-tab {
  flex: 1;
  padding: 8px 10px;
  border: 0; border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.03em;
}
.sidebar-tab.is-active { background: var(--paper); color: var(--emerald); box-shadow: var(--shadow-sm); }
.sidebar-close { display: none; flex: none; }
.sidebar-filter {
  position: relative;
  display: flex; align-items: center;
  margin: 4px 16px 10px;
}
.sidebar-filter svg { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.sidebar-filter input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper-2);
  color: var(--ink);
  font-size: 12.5px;
  outline: none;
}
.sidebar-filter input:focus { border-color: var(--emerald); box-shadow: 0 0 0 3px var(--emerald-soft); }
.chapter-list { flex: 1; overflow-y: auto; padding: 0 10px 14px; }
.chapter-item {
  width: 100%;
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
  transition: background .15s, color .15s, border-color .15s;
}
.chapter-item:hover { background: var(--paper-2); }
.chapter-item[aria-current="page"] {
  background: var(--emerald-soft);
  border-color: rgba(15, 92, 78, 0.18);
  color: var(--emerald-deep);
  font-weight: 700;
}
[data-theme="dark"] .chapter-item[aria-current="page"] { color: var(--emerald); }
.chapter-num {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--paper-3);
  color: var(--muted);
  font-size: 10.5px; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.chapter-item[aria-current="page"] .chapter-num { background: var(--emerald); color: var(--on-accent); }
.chapter-label { flex: 1; min-width: 0; font-size: 12.5px; }
.chapter-label small { display: block; margin-top: 1px; color: var(--muted); font-size: 10px; font-weight: 500; }
.chapter-pages { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.bookmark-list { flex: 1; overflow-y: auto; padding: 4px 12px 14px; }
.bookmark-empty, .chapter-empty { padding: 26px 14px; color: var(--muted); font-size: 12.5px; text-align: center; line-height: 1.6; }
.bookmark-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  margin-bottom: 8px;
}
.bookmark-jump { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; color: var(--ink-soft); }
.bookmark-jump b { display: block; font-size: 12.5px; }
.bookmark-jump small { display: block; margin-top: 2px; color: var(--muted); font-size: 10.5px; }
.bookmark-remove { border: 0; background: transparent; color: var(--muted); padding: 2px; border-radius: 6px; }
.bookmark-remove:hover { color: var(--danger); }
.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10.5px;
}
.sidebar-count { font-variant-numeric: tabular-nums; white-space: nowrap; }
.text-btn {
  border: 0; background: transparent; padding: 4px 0;
  color: var(--emerald); font-size: 11.5px; font-weight: 700;
}
.text-btn:hover { text-decoration: underline; text-underline-offset: 3px; }
.scrim { display: none; }

/* ---------- Boot ---------- */
.boot {
  min-height: 60vh;
  display: grid; place-content: center; justify-items: center; gap: 16px;
  color: var(--muted); text-align: center;
}
.boot-mark {
  width: 62px; height: 62px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--emerald);
  font-family: var(--font-display);
  font-size: 28px;
  box-shadow: var(--shadow-sm);
  animation: breathe 2.2s var(--ease) infinite;
}
.boot p { margin: 0; font-size: 13px; letter-spacing: 0.04em; }
@keyframes breathe { 0%, 100% { transform: scale(1); opacity: .8; } 50% { transform: scale(1.04); opacity: 1; } }

/* ---------- Hero ---------- */
.hero-wrap {
  position: relative;
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(34px, 5vw, 70px) clamp(20px, 5vw, 60px) 70px;
  min-height: calc(100dvh - var(--topbar));
  display: flex; align-items: center;
}
.hero-ornament {
  position: absolute;
  right: -4%; top: 50%;
  width: min(56vw, 720px);
  transform: translateY(-50%);
  opacity: .16;
  pointer-events: none;
  filter: saturate(.8);
  mask-image: radial-gradient(ellipse closest-side, #000 45%, transparent);
  -webkit-mask-image: radial-gradient(ellipse closest-side, #000 45%, transparent);
}
.hero {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(230px, 320px) minmax(0, 1fr);
  gap: clamp(32px, 5vw, 72px);
  align-items: center;
  width: 100%;
}
.hero-cover {
  position: relative;
  transform: rotate(-2.5deg);
  transition: transform .5s var(--ease);
}
.hero-cover:hover { transform: rotate(0deg) translateY(-6px); }
.hero-cover::before {
  content: "";
  position: absolute; inset: 10px -12px -14px 12px;
  border-radius: 18px;
  background: var(--emerald-deep);
  opacity: .18;
  filter: blur(22px);
  z-index: -1;
}
.hero-cover-frame {
  position: relative;
  padding: 9px;
  border-radius: 14px;
  background: linear-gradient(145deg, #e8d6b2, #b98b4e 45%, #f4e7cc 70%, #a97a3f);
  box-shadow: var(--shadow-lg);
}
.hero-cover-frame img { border-radius: 8px; width: 100%; height: auto; }
.hero-cover-caption {
  margin-top: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.hero-copy { min-width: 0; }
.eyebrow {
  margin: 0 0 12px;
  color: var(--gold);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(46px, 8.4vw, 96px);
  line-height: .93;
  letter-spacing: -0.045em;
  color: var(--ink);
}
.hero-sub {
  margin: 14px 0 0;
  font-family: var(--font-display);
  font-size: clamp(17px, 2.2vw, 23px);
  font-style: italic;
  color: var(--emerald);
}
.hero-lede {
  max-width: 52ch;
  margin: 22px 0 0;
  color: var(--ink-soft);
  font-family: var(--font-read);
  font-size: 16.5px;
  line-height: 1.75;
}
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 48px;
  padding: 12px 22px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-size: 13px; font-weight: 750;
  letter-spacing: 0.01em;
  transition: transform .18s var(--ease), background .18s, color .18s, border-color .18s, box-shadow .18s;
}
.btn:hover { transform: translateY(-2px); text-decoration: none; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--emerald); color: var(--on-accent); box-shadow: 0 10px 24px rgba(15, 92, 78, 0.22); }
.btn-primary:hover { background: var(--emerald-deep); box-shadow: 0 14px 30px rgba(15, 92, 78, 0.28); }
.btn-quiet { background: var(--paper-2); border-color: var(--line); color: var(--ink-soft); }
.btn-quiet:hover { background: var(--paper); border-color: var(--line-strong); }
.btn-gold { background: var(--gold-soft); color: #5a3a10; border-color: rgba(163, 117, 50, 0.22); }
[data-theme="dark"] .btn-gold { color: var(--gold); }
.hero-stats {
  display: flex; flex-wrap: wrap; gap: 0;
  margin-top: 34px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}
.hero-stat { min-width: 104px; padding-right: 24px; margin-right: 24px; border-right: 1px solid var(--line); }
.hero-stat:last-child { border-right: 0; margin-right: 0; padding-right: 0; }
.hero-stat b { display: block; font-family: var(--font-display); font-size: 22px; line-height: 1; color: var(--ink); }
.hero-stat span { display: block; margin-top: 6px; color: var(--muted); font-size: 9.5px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }
.hero-quote {
  margin: 36px 0 0;
  padding: 18px 22px;
  border-left: 2px solid var(--gold);
  background: linear-gradient(90deg, var(--gold-soft), transparent 80%);
  border-radius: 0 12px 12px 0;
  color: var(--ink-soft);
  font-family: var(--font-read);
  font-size: 15px;
  font-style: italic;
  line-height: 1.7;
}
.hero-quote cite { display: block; margin-top: 8px; font-family: var(--font-ui); font-size: 9.5px; font-style: normal; font-weight: 750; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); }
.hero-note { margin: 20px 0 0; color: var(--muted); font-size: 10.5px; line-height: 1.6; }

/* ---------- Reader ---------- */
.reader-wrap { max-width: 860px; margin: 0 auto; padding: clamp(26px, 4vw, 54px) clamp(16px, 4vw, 40px) 90px; }
.reader-head { text-align: center; padding: 4px 0 26px; }
.reader-kicker {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: var(--gold);
  font-size: 10px; font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase;
}
.reader-kicker::before, .reader-kicker::after {
  content: ""; width: 34px; height: 1px; background: var(--line-strong);
}
.reader-head h1 {
  margin: 12px 0 4px;
  font-family: var(--font-display);
  font-size: clamp(30px, 5vw, 44px);
  line-height: 1.08;
  letter-spacing: -0.025em;
}
.reader-head .reader-book { color: var(--muted); font-family: var(--font-display); font-size: 14px; font-style: italic; }
.reader-tools { display: flex; justify-content: center; gap: 8px; margin-top: 18px; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--muted);
  font-size: 11px; font-weight: 700;
}
.tool-btn:hover { border-color: var(--line-strong); color: var(--ink-soft); }
.tool-btn.is-on { background: var(--emerald); border-color: var(--emerald); color: var(--on-accent); }
.tool-btn svg { width: 14px; height: 14px; }
.reader-divider { width: 170px; margin: 22px auto 0; opacity: .8; }
.progress-track {
  position: relative;
  height: 3px; max-width: 420px;
  margin: 20px auto 0;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}
.progress-fill { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--emerald), var(--gold)); transition: width .25s var(--ease); }

.page-card {
  position: relative;
  padding: clamp(30px, 6vw, 62px) clamp(22px, 7vw, 70px);
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 22%),
    var(--paper);
  box-shadow: var(--shadow-md);
  color: var(--ink);
  font-family: var(--font-read);
  font-size: var(--reader-size);
  line-height: var(--reader-leading);
  overflow-wrap: break-word;
}
[data-theme="dark"] .page-card { background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 20%), var(--paper); }
.page-card::before {
  content: "";
  position: absolute; left: 9%; right: 9%; top: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: .55;
}
.page-card p { margin: 0 0 1.18em; }
.page-card p:last-child { margin-bottom: 0; }
.page-card p.dialogue {
  position: relative;
  margin: 0 0 1.25em;
  padding: 0.15em 0 0.15em 1.05em;
  border-left: 2px solid var(--gold);
  border-radius: 0 10px 10px 0;
  background: linear-gradient(90deg, var(--gold-soft), transparent 72%);
  color: var(--ink-soft);
}
[data-theme="dark"] .page-card p.dialogue { background: linear-gradient(90deg, rgba(216, 176, 106, 0.10), transparent 72%); }
.page-card p.dialogue + p.dialogue { margin-top: -0.55em; }
.page-card.show-speakers p.dialogue[data-speaker]::before {
  content: attr(data-speaker);
  display: block;
  margin-bottom: 0.3em;
  color: var(--emerald);
  font-family: var(--font-ui);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.page-card.is-first p:first-of-type::first-letter {
  float: left;
  margin: 0.08em 0.12em 0 0;
  color: var(--emerald);
  font-family: var(--font-display);
  font-size: 3.45em;
  line-height: .78;
  font-weight: 700;
}
.page-card mark.search-hit { background: var(--gold-soft); color: var(--ink); border-radius: 3px; padding: 0 2px; box-shadow: 0 0 0 1px rgba(163, 117, 50, 0.18); }
.page-foot {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-top: 22px;
}
.page-foot .nav-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper-2);
  color: var(--ink-soft);
  font-size: 12px; font-weight: 700;
  transition: background .18s, color .18s, border-color .18s, transform .18s;
}
.page-foot .nav-btn:hover:not(:disabled) { background: var(--emerald); border-color: var(--emerald); color: var(--on-accent); transform: translateY(-1px); }
.page-foot .nav-btn:disabled { opacity: .35; cursor: not-allowed; }
.page-foot .nav-btn svg { width: 15px; height: 15px; }
.page-foot .nav-btn.next { justify-self: end; }
.page-meta { color: var(--muted); font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-align: center; white-space: nowrap; }
.chapter-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 30px; }
.chapter-card {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--paper-2);
  text-align: left;
  color: var(--muted);
  font-size: 11.5px;
  transition: border-color .18s, background .18s, transform .18s;
}
.chapter-card:hover:not(:disabled) { border-color: var(--emerald); background: var(--paper); transform: translateY(-2px); }
.chapter-card:disabled { opacity: .35; cursor: not-allowed; }
.chapter-card small { display: block; margin-bottom: 5px; font-size: 9px; font-weight: 800; letter-spacing: 0.15em; text-transform: uppercase; color: var(--gold); }
.chapter-card b { display: block; color: var(--ink-soft); font-family: var(--font-display); font-size: 16px; font-weight: 600; }
.chapter-card.next { text-align: right; }
.reader-end { text-align: center; padding: 30px 10px 10px; color: var(--muted); font-size: 12px; }
.reader-end b { display: block; margin-bottom: 6px; color: var(--ink-soft); font-family: var(--font-display); font-size: 18px; }

/* ---------- Mobile bar ---------- */
.mobile-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: none;
  grid-template-columns: repeat(4, 1fr);
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 247, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
[data-theme="dark"] .mobile-bar { background: rgba(11, 20, 19, 0.94); }
.mobile-bar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 48px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 9px; font-weight: 700;
  letter-spacing: 0.04em;
}
.mobile-bar button:active { background: var(--paper-2); }
.mobile-bar button svg { width: 20px; height: 20px; }
.mobile-bar button.is-on { color: var(--emerald); }

/* ---------- Search overlay ---------- */
.search-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: start center;
  padding: clamp(16px, 5vh, 60px) 16px 24px;
  background: rgba(24, 20, 14, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
}
.search-panel {
  width: min(780px, 100%);
  max-height: calc(100dvh - 40px);
  display: flex; flex-direction: column;
  padding: clamp(20px, 3vw, 30px);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: var(--shadow-lg);
}
.search-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.search-panel h2 { margin: 0; font-family: var(--font-display); font-size: clamp(24px, 4vw, 32px); letter-spacing: -0.02em; }
.search-panel .eyebrow { margin-bottom: 8px; }
.search-box {
  display: flex; align-items: center; gap: 10px;
  margin-top: 18px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: var(--paper-2);
}
.search-box:focus-within { border-color: var(--emerald); box-shadow: 0 0 0 3px var(--emerald-soft); }
.search-box svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search-box input {
  flex: 1; min-width: 0;
  padding: 15px 0;
  border: 0; outline: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-read);
  font-size: 17px;
}
.search-box input::placeholder { color: var(--muted); }
.search-status { margin: 14px 2px 8px; color: var(--muted); font-size: 11px; }
.search-results { overflow-y: auto; padding-right: 4px; }
.search-result {
  width: 100%;
  display: block;
  padding: 14px 16px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-2);
  text-align: left;
  color: var(--ink-soft);
}
.search-result:hover { border-color: var(--emerald); background: var(--paper); }
.search-result small { display: block; margin-bottom: 5px; color: var(--gold); font-size: 9.5px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.search-result p { margin: 0; font-family: var(--font-read); font-size: 14px; line-height: 1.65; }
.search-result mark { background: var(--gold-soft); color: var(--ink); border-radius: 3px; padding: 0 2px; }
.search-empty { padding: 40px 10px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- About dialog ---------- */
.about-dialog {
  width: min(680px, calc(100vw - 28px));
  max-height: calc(100dvh - 40px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
.about-dialog::backdrop { background: rgba(24, 20, 14, 0.5); backdrop-filter: blur(5px); }
.about-inner { position: relative; padding: clamp(24px, 4vw, 40px); overflow-y: auto; }
.about-close { position: absolute; right: 16px; top: 16px; }
.about-dialog h2 { margin: 0 0 14px; font-family: var(--font-display); font-size: clamp(26px, 4vw, 36px); line-height: 1.1; letter-spacing: -0.025em; }
.about-dialog p { color: var(--ink-soft); font-family: var(--font-read); font-size: 15px; line-height: 1.75; }
.about-facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 22px 0; }
.about-facts div { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper-2); text-align: center; }
.about-facts b { display: block; font-family: var(--font-display); font-size: 20px; color: var(--emerald); }
.about-facts span { display: block; margin-top: 3px; color: var(--muted); font-size: 8.5px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.about-note { font-size: 13px !important; color: var(--muted) !important; border-top: 1px solid var(--line); padding-top: 16px; }
.about-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }

/* ---------- Toast / top ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 120;
  transform: translate(-50%, 16px);
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .22s, transform .22s var(--ease);
  box-shadow: var(--shadow-md);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
#toTop {
  position: fixed; right: 20px; bottom: 20px; z-index: 55;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink-soft);
  box-shadow: var(--shadow-md);
}
#toTop:hover { background: var(--emerald); border-color: var(--emerald); color: var(--on-accent); }
#toTop svg { width: 18px; height: 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  :root { --sidebar: 278px; }
  .hero { grid-template-columns: minmax(200px, 280px) minmax(0, 1fr); gap: 40px; }
  .search-trigger { min-width: 190px; }
}
@media (max-width: 900px) {
  .menu-btn { display: grid; }
  .brand-text small { display: none; }
  .search-trigger span { display: none; }
  .search-trigger { min-width: 0; width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 12px; }
  .search-trigger kbd { display: none; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar); bottom: 0; z-index: 70;
    width: min(86vw, 330px);
    transform: translateX(-102%);
    transition: transform .28s var(--ease);
    box-shadow: var(--shadow-lg);
    background: var(--paper);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-close { display: grid; }
  .scrim { display: block; position: fixed; inset: var(--topbar) 0 0 0; z-index: 65; background: rgba(20, 16, 10, 0.42); backdrop-filter: blur(2px); }
  .hero-wrap { min-height: 0; padding-top: 34px; }
  .hero { grid-template-columns: 1fr; gap: 36px; justify-items: center; text-align: center; }
  .hero-cover { width: min(240px, 64vw); }
  .hero-lede { margin-left: auto; margin-right: auto; }
  .hero-actions { justify-content: center; }
  .hero-stats { justify-content: center; }
  .hero-stat { min-width: 86px; padding-right: 18px; margin-right: 18px; }
  .hero-quote { text-align: left; }
  .hero-ornament { opacity: .10; width: 90vw; right: -30%; }
  .page-card { border-radius: 4px; }
}
@media (max-width: 640px) {
  :root { --topbar: 62px; }
  .topbar { gap: 8px; padding: 0 10px; }
  .brand img { width: 34px; height: 34px; }
  .brand-text { font-size: 15px; }
  .font-group { display: none; }
  .mobile-bar { display: grid; }
  .main { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .reader-wrap { padding: 20px 10px 36px; }
  .reader-head { padding-bottom: 18px; }
  .reader-tools { margin-top: 14px; }
  .reader-divider { width: 130px; margin-top: 16px; }
  .page-card { padding: 28px 20px 30px; font-size: var(--reader-size); }
  .page-foot { grid-template-columns: 1fr 1fr; }
  .page-foot .page-meta { grid-column: 1 / -1; grid-row: 1; }
  .page-foot .nav-btn { width: 100%; justify-content: center; }
  .page-foot .nav-btn.next { justify-self: stretch; }
  .chapter-cards { grid-template-columns: 1fr; }
  .chapter-card.next { text-align: left; }
  .hero-wrap { padding: 26px 18px 48px; }
  .hero h1 { font-size: clamp(42px, 14vw, 64px); }
  .hero-lede { font-size: 15.5px; }
  .hero-stat { min-width: 74px; padding-right: 12px; margin-right: 12px; }
  .hero-stat b { font-size: 19px; }
  .hero-stat span { font-size: 8px; }
  .hero-quote { margin-top: 26px; padding: 14px 16px; font-size: 14px; }
  .about-facts { grid-template-columns: repeat(2, 1fr); }
  .search-overlay { padding: 10px; }
  .search-panel { max-height: calc(100dvh - 20px); border-radius: 16px; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
  #toTop { bottom: calc(78px + env(safe-area-inset-bottom)); }
}
@media (min-width: 901px) {
  .menu-btn { display: none; }
  .sidebar-close { display: none; }
  .mobile-bar { display: none !important; }
}

/* ---------- Motion / print ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .hero-cover { transform: none; }
}
@media print {
  body { overflow: visible; background: #fff; color: #000; }
  body::before, .topbar, .sidebar, .mobile-bar, .search-overlay, #toTop, .toast, .reader-tools, .page-foot, .chapter-cards, .reader-divider, .progress-track, .skip-link, .about-dialog { display: none !important; }
  .app-shell { display: block; height: auto; }
  .main { overflow: visible; }
  .reader-wrap { max-width: none; padding: 0; }
  .page-card { border: 0; box-shadow: none; background: #fff; color: #000; padding: 0; font-size: 12pt; line-height: 1.6; }
  .page-card p.dialogue { background: none; border-left: 1px solid #999; color: #000; }
  .reader-head h1 { color: #000; }
  a { color: #000; text-decoration: underline; }
}
.hero-resume { margin: 10px 0 0; color: var(--muted); font-size: 10.5px; letter-spacing: 0.04em; }

/* ---------- cursor light (desktop fine pointers only; see cursor-light.js) ---------- */
/* One fixed glow + CSS vars --mx/--my. Everything below is gated by body.has-cursor-light. */
.cc-light {
  position: fixed; top: 0; left: 0; width: 640px; height: 640px;
  pointer-events: none; z-index: 9999; border-radius: 50%;
  background: radial-gradient(circle, rgba(246, 206, 80, 0.42) 0%, rgba(232, 180, 50, 0.2) 30%, rgba(232, 180, 50, 0) 68%);
  mix-blend-mode: screen; opacity: 1;
  will-change: transform, opacity; transition: opacity 300ms ease;
}
/* screen does nothing on pale paper: use a warm multiply halo instead */
[data-theme="light"] .cc-light, [data-theme="sepia"] .cc-light {
  background: radial-gradient(circle, rgba(226, 150, 30, 0.5) 0%, rgba(226, 160, 40, 0.24) 32%, rgba(226, 160, 40, 0) 68%);
  mix-blend-mode: multiply; opacity: 0.75;
}
.cc-light.is-hover { opacity: 1; }
.cc-light.is-field { opacity: 0.4; }
.cc-light.is-read { opacity: 0.45; }
[data-theme="light"] .cc-light.is-read, [data-theme="sepia"] .cc-light.is-read { opacity: 0.3; }
.cc-light.is-hidden, [data-theme="light"] .cc-light.is-hidden, [data-theme="sepia"] .cc-light.is-hidden { opacity: 0; }

body.has-cursor-light {
  --ring: rgba(190, 125, 20, 0.95); --sheen: rgba(222, 150, 30, 0.2); --lit-c: var(--emerald);
  --at: var(--mx, -999px) var(--my, -999px);
}
[data-theme="sepia"] body.has-cursor-light { --ring: rgba(170, 100, 15, 0.95); --sheen: rgba(200, 120, 20, 0.2); }
[data-theme="dark"] body.has-cursor-light { --ring: rgba(244, 208, 90, 1); --sheen: rgba(232, 190, 60, 0.13); --lit-c: var(--gold); }

/* Spotlight: glowing border segment (masked ring) + soft sheen, both pinned to the pointer via fixed backgrounds. */
body.has-cursor-light :is(.page-card, .chapter-item, .btn, .tool-btn, .hero-cover-frame) { position: relative; }
body.has-cursor-light :is(.page-card, .chapter-item, .btn, .tool-btn, .hero-cover-frame)::after {
  content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1.5px;
  pointer-events: none; opacity: 0; transition: opacity .25s;
  background: radial-gradient(circle 240px at var(--at), var(--ring), transparent 100%) fixed;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
body.has-cursor-light .page-card::after { opacity: 1; padding: 2px; background-image: radial-gradient(circle 340px at var(--at), var(--ring), transparent 100%); }
body.has-cursor-light :is(.chapter-item, .btn, .tool-btn, .hero-cover-frame):hover::after { opacity: 1; }
body.has-cursor-light .page-card {
  background-image: radial-gradient(circle 460px at var(--at), var(--sheen), transparent 100%), linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 22%);
  background-attachment: fixed, scroll;
}
[data-theme="dark"] body.has-cursor-light .page-card { background-image: radial-gradient(circle 460px at var(--at), var(--sheen), transparent 100%), linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 20%); }
body.has-cursor-light :is(.chapter-item, .tool-btn, .btn-quiet, .hero-cover-frame):hover {
  background-image: radial-gradient(circle 150px at var(--at), var(--sheen), transparent 100%); background-attachment: fixed;
}
body.has-cursor-light .btn-primary:hover { background-image: radial-gradient(circle 160px at var(--at), rgba(255, 255, 255, 0.28), transparent 100%); background-attachment: fixed; }

/* Text catches the light: colour pulled toward the accent, never fainter than base. */
body.has-cursor-light {
  --lit: radial-gradient(circle 200px at var(--at), color-mix(in srgb, var(--lit-c) 85%, transparent), transparent 100%);
}
body.has-cursor-light :is(.hero-lede, .chapter-label, .page-card:not(.is-first) p, .page-card.is-first p:not(:first-of-type)) {
  background-image: var(--lit), linear-gradient(currentColor, currentColor);
  background-attachment: fixed, scroll;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
/* dialogue keeps its tint as an extra border-box layer (per-layer background-clip) under the clipped text layers */
body.has-cursor-light :is(.page-card:not(.is-first) p, .page-card.is-first p:not(:first-of-type)).dialogue {
  background-image: var(--lit), linear-gradient(currentColor, currentColor), linear-gradient(90deg, var(--gold-soft), transparent 72%);
  background-attachment: fixed, scroll, scroll;
  -webkit-background-clip: text, text, border-box; background-clip: text, text, border-box;
}
[data-theme="dark"] body.has-cursor-light :is(.page-card:not(.is-first) p, .page-card.is-first p:not(:first-of-type)).dialogue { background-image: var(--lit), linear-gradient(currentColor, currentColor), linear-gradient(90deg, rgba(216, 176, 106, 0.10), transparent 72%); }
/* drop-cap paragraph stays out of text clipping (it cuts the floated ::first-letter); the card spotlight still lights it. Speaker labels keep their colour. */
body.has-cursor-light .page-card.show-speakers p.dialogue[data-speaker]::before { -webkit-text-fill-color: var(--emerald); }
/* inline children keep their own colour */
body.has-cursor-light :is(.hero-lede, .chapter-label, .page-card p) :is(a, mark) { -webkit-text-fill-color: currentColor; }
