:root {
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'Source Serif 4', Georgia, serif;
  --font-ui: 'Inter', system-ui, sans-serif;
  --max-width: 1180px;
  --text-width: 72ch;
  --radius: 22px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.08);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.05);
}

body.theme-sepia {
  --bg: #f3ece0;
  --bg-elevated: rgba(255, 252, 246, 0.88);
  --bg-strong: rgba(255, 250, 242, 0.95);
  --panel: #fffaf3;
  --panel-soft: #f7f0e4;
  --border: rgba(73, 53, 33, 0.16);
  --border-strong: rgba(73, 53, 33, 0.28);
  --text: #2d241d;
  --text-soft: #352c24;
  --muted: #483d34;
  --accent: #7a4d2e;
  --accent-soft: rgba(122, 77, 46, 0.11);
  --accent-strong: #5d3920;
  --progress: #7a4d2e;
}

body.theme-light {
  --bg: #f6f6f4;
  --bg-elevated: rgba(255, 255, 255, 0.9);
  --bg-strong: rgba(255, 255, 255, 0.96);
  --panel: #ffffff;
  --panel-soft: #f3f4f6;
  --border: rgba(26, 26, 26, 0.1);
  --border-strong: rgba(26, 26, 26, 0.18);
  --text: #171717;
  --text-soft: #1d252e;
  --muted: #3f4a58;
  --accent: #7c3f2a;
  --accent-soft: rgba(124, 63, 42, 0.08);
  --accent-strong: #5d2412;
  --progress: #7c3f2a;
}

body.theme-night {
  --bg: #151515;
  --bg-elevated: rgba(30, 30, 30, 0.88);
  --bg-strong: rgba(24, 24, 24, 0.96);
  --panel: #1d1d1d;
  --panel-soft: #232323;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #ece5d9;
  --text-soft: #d0c5b5;
  --muted: #d8cebf;
  --accent: #d7a16f;
  --accent-soft: rgba(215, 161, 111, 0.08);
  --accent-strong: #efb987;
  --progress: #d7a16f;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 12px 28px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: radial-gradient(circle at top, rgba(255,255,255,0.2), transparent 35%), var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.7;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }
img { max-width: 100%; }
button, select { font: inherit; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
}
.skip-link:focus {
  left: 1rem;
  top: 1rem;
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 0.65rem 0.95rem;
  z-index: 1000;
}

.site-shell,
.home-main,
.book-main,
.site-footer {
  width: min(calc(100% - 2rem), var(--max-width));
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 0;
}
.topbar.sticky {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.brand-wrap,
.toolbar,
.companion-links,
.pager-links {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.brand,
.current-book,
.brand-sep {
  font-family: var(--font-ui);
  font-size: 0.93rem;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
}
.brand-sep,
.current-book { color: var(--muted); }

.toggle,
.jump-select,
.primary-btn,
.secondary-btn {
  border: 1px solid var(--border-strong);
  background: var(--bg-strong);
  color: var(--text);
  border-radius: 999px;
  padding: 0.7rem 1rem;
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 0.88rem;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.toggle:hover,
.jump-select:hover,
.primary-btn:hover,
.secondary-btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}
.primary-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
body.theme-night .primary-btn { color: #20150d; }
.primary-btn:hover {
  background: var(--accent-strong);
  color: #fff;
}
body.theme-night .primary-btn:hover { color: #20150d; }

.progress-strip {
  height: 3px;
  background: transparent;
}
.progress-strip span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--progress), color-mix(in srgb, var(--progress) 60%, white));
  transition: width 0.2s ease;
}

.eyebrow {
  margin: 0 0 0.75rem;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.hero-block,
.book-hero {
  padding: clamp(1.25rem, 3vw, 3rem) 0 1rem;
}
.hero-block h1,
.book-hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3rem, 6vw, 5.5rem);
  line-height: 0.96;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.hero-block h1 em { font-style: italic; font-weight: 500; }
.hero-copy,
.book-summary {
  max-width: 46rem;
  margin: 1rem 0 0;
  font-size: 1.2rem;
  color: var(--text-soft);
}
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-top: 1.5rem;
}
.hero-stats,
.book-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem;
  margin: 1.4rem 0 0;
}
.hero-stats div,
.book-stats div {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-soft);
}
.hero-stats dt,
.book-stats dt {
  font-family: var(--font-ui);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}
.hero-stats dd,
.book-stats dd {
  margin: 0.35rem 0 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1rem 0 2rem;
}
.home-note,
.reading-note,
.book-tools,
.companion-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow-soft);
}
.home-note h2,
.section-head h2,
.companion-head h2 {
  margin: 0 0 0.65rem;
  font-family: var(--font-display);
  font-size: 2rem;
}
.home-note p,
.section-head p,
.reading-note p,
.book-tools p,
.companion-head p,
.notes-item p,
.apparatus-copy p {
  margin: 0.65rem 0 0;
  color: var(--text-soft);
}
.books-section { padding: 1rem 0 4rem; }
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}
.section-head-stack {
  align-items: start;
}
.book-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}
.book-card-link {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  text-decoration: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 1.2rem;
  box-shadow: var(--shadow-soft);
}
.book-card-link:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.book-card-top {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}
.book-kicker { font-weight: 700; }
.book-card h2 {
  margin: 0.7rem 0 0.45rem;
  font-family: var(--font-display);
  font-size: 2.05rem;
}
.book-card p {
  margin: 0;
  color: var(--text-soft);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
}
.book-meta {
  margin-top: 0.9rem;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.crumbs {
  display: flex;
  gap: 0.7rem;
  padding-top: 1rem;
  font-family: var(--font-ui);
  font-size: 0.88rem;
  color: var(--muted);
}
.crumbs a { text-decoration: none; }
.crumbs span::before {
  content: '/';
  margin-right: 0.7rem;
}
.book-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1rem;
  align-items: start;
}
.jump-label {
  display: block;
  margin-bottom: 0.4rem;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.jump-select {
  width: 100%;
  margin-bottom: 0.85rem;
  appearance: none;
}
.book-tools {
  display: grid;
  gap: 0.85rem;
}
.companion-links,
.pager-links {
  flex-wrap: wrap;
}
.companion-links a,
.pager-links a {
  flex: 1 1 100%;
  text-align: center;
}
.reading-note {
  margin: 0 0 1rem;
}

.units-wrap {
  display: grid;
  gap: 1rem;
  padding-bottom: 2rem;
}
.unit-card {
  scroll-margin-top: 5.6rem;
  background: color-mix(in srgb, var(--bg-elevated) 93%, white 7%);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: clamp(1.2rem, 2.6vw, 2rem);
  box-shadow: var(--shadow-soft);
}
.unit-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}
.unit-label {
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.76rem;
  color: var(--muted);
}
.unit-title {
  margin: 0.2rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3vw, 2.35rem);
  line-height: 1.05;
}
.unit-link {
  flex: 0 0 auto;
  text-decoration: none;
  font-family: var(--font-ui);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
}
.reading-copy {
  max-width: var(--text-width);
  font-size: clamp(1.13rem, 1.3vw, 1.24rem);
}
.reading-copy p { margin: 0.9rem 0 0; }
.reading-copy p:first-child { margin-top: 0; }

.apparatus-wrap {
  display: grid;
  gap: 1rem;
  padding: 0 0 4rem;
}
.companion-head {
  margin-bottom: 1rem;
}
.adaptation-list,
.notes-list {
  display: grid;
  gap: 0.85rem;
}
.adaptation-item,
.notes-item {
  border: 1px solid color-mix(in srgb, var(--border) 75%, transparent);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-radius: 18px;
  padding: 1rem 1rem 1.05rem;
}
.apparatus-item-head {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  margin-bottom: 0.65rem;
}
.apparatus-kicker {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.apparatus-item-head h3,
.notes-item h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  line-height: 1.05;
}
.apparatus-copy {
  max-width: var(--text-width);
  font-size: 1.04rem;
}
.apparatus-copy p:first-child { margin-top: 0; }
.notes-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.notes-item {
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--panel));
}

.book-footer,
.site-footer {
  padding: 0 0 4rem;
}
.book-colophon {
  margin: 0 0 1rem;
  font-style: italic;
  color: var(--muted);
}
.footer-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-family: var(--font-ui);
}
.footer-nav a,
.site-footer p {
  color: var(--muted);
  text-decoration: none;
}
.site-footer {
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: 0.9rem;
}
.site-footer p { padding-top: 1rem; }

a:focus-visible,
button:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 1100px) {
  .notes-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .home-grid,
  .book-grid,
  .book-hero {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .site-shell,
  .home-main,
  .book-main,
  .site-footer {
    width: min(calc(100% - 1rem), var(--max-width));
  }
  .topbar,
  .hero-block,
  .book-hero {
    padding-top: 0.75rem;
  }
  .hero-block h1,
  .book-hero h1 {
    font-size: clamp(2.4rem, 13vw, 4rem);
  }
  .toolbar { gap: 0.45rem; }
  .toggle,
  .primary-btn,
  .secondary-btn,
  .jump-select {
    padding: 0.68rem 0.9rem;
  }
  .section-head {
    display: block;
  }
  .section-head p { margin-top: 0.35rem; }
  .hero-actions,
  .footer-nav,
  .companion-links,
  .pager-links {
    flex-direction: column;
    align-items: stretch;
  }
  .unit-card,
  .companion-section {
    padding: 1rem;
    border-radius: 24px;
  }
  .adaptation-item,
  .notes-item {
    padding: 0.95rem 0.95rem 1rem;
  }
  .reading-copy {
    font-size: 1.05rem;
  }
  .apparatus-copy {
    font-size: 1rem;
  }
}
