:root {
  --sidebar-width: 360px;
  --page-bg: #f6f0e6;
  --page-bg-soft: #f8f4ec;
  --card-bg: #fffdf8;
  --card-sheen: rgba(255, 255, 255, 0.3);
  --card-border: rgba(120, 90, 70, 0.14);
  --ink: #191716;
  --muted: #776f67;
  --accent: #a73535;
  --accent-soft: rgba(167, 53, 53, 0.16);
  --sidebar-bg: #141312;
  --sidebar-line: rgba(255, 255, 255, 0.1);
  --shadow: 0 35px 80px rgba(22, 17, 15, 0.28);
  --reader-font-scale: 1;
  --reader-line-height: 1.9;
  --reader-font-family: Georgia, "Times New Roman", serif;
  color-scheme: light;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

body.theme-sepia {
  --page-bg: #efe1cc;
  --page-bg-soft: #f5ead9;
  --card-bg: #fff5e5;
  --card-sheen: rgba(255, 255, 255, 0.24);
  --card-border: rgba(130, 94, 58, 0.18);
  --ink: #2d2218;
  --muted: #7a6854;
  --accent-soft: rgba(143, 89, 38, 0.14);
}

body.theme-night {
  --page-bg: #101218;
  --page-bg-soft: #171a24;
  --card-bg: #1d212d;
  --card-sheen: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.08);
  --ink: #f5efe7;
  --muted: #b2b7c6;
  --accent-soft: rgba(236, 98, 98, 0.12);
  color-scheme: dark;
}

body.font-sans {
  --reader-font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top right, rgba(167, 53, 53, 0.08), transparent 30%),
    linear-gradient(180deg, var(--page-bg-soft) 0%, var(--page-bg) 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  transition: background 180ms ease, color 180ms ease;
}

body.sidebar-open {
  overflow-x: hidden;
}

.sidebar-toggle {
  position: fixed;
  top: 24px;
  left: 24px;
  z-index: 60;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 20px 40px rgba(167, 53, 53, 0.35);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 180ms ease, background-color 180ms ease;
}

.sidebar-toggle:hover {
  transform: scale(1.04);
}

.sidebar-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 99px;
  background: white;
  transition: transform 220ms ease, opacity 220ms ease;
}

body.sidebar-open .sidebar-toggle span:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

body.sidebar-open .sidebar-toggle span:nth-child(2) {
  opacity: 0;
}

body.sidebar-open .sidebar-toggle span:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

.chapter-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #181716 0%, #0f0e0d 100%);
  color: white;
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 320ms cubic-bezier(0.76, 0, 0.24, 1);
  box-shadow: 12px 0 50px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
}

body.sidebar-open .chapter-sidebar {
  transform: translateX(0);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  border: 0;
  background: rgba(7, 8, 14, 0.58);
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}

.sidebar-top {
  padding: 108px 32px 28px;
  border-bottom: 1px solid var(--sidebar-line);
}

.sidebar-kicker,
.eyebrow {
  margin: 0;
  font-size: 0.74rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: #d6beb8;
}

.sidebar-title {
  margin: 14px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.chapter-nav {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 18px 0 32px;
}

.chapter-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chapter-list li {
  border-bottom: 1px solid var(--sidebar-line);
}

.chapter-link {
  display: block;
  padding: 18px 32px 18px calc(32px + var(--chapter-indent, 0px));
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  font-size: 0.95rem;
  line-height: 1.45;
  transition: background-color 180ms ease, color 180ms ease, padding-left 180ms ease;
}

.chapter-link:hover,
.chapter-link.is-active {
  background: rgba(255, 255, 255, 0.04);
  color: white;
  padding-left: calc(40px + var(--chapter-indent, 0px));
}

.reader-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0 0 72px;
  transition: margin-left 320ms cubic-bezier(0.76, 0, 0.24, 1);
}

body.sidebar-open .reader-shell {
  margin-left: var(--sidebar-width);
}

.reader-settings {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 70;
}

.settings-toggle {
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 999px;
  background: #242633;
  color: #ebe6df;
  font: 700 1rem/1 Georgia, "Times New Roman", serif;
  letter-spacing: 0.04em;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

.settings-panel {
  position: absolute;
  top: 74px;
  right: 0;
  width: 240px;
  padding: 8px;
  border-radius: 18px;
  background: #202332;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.35);
}

.settings-panel::before {
  content: "";
  position: absolute;
  top: -8px;
  right: 22px;
  width: 16px;
  height: 16px;
  background: #202332;
  transform: rotate(45deg);
}

.cookie-banner {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 18px;
  max-width: min(560px, calc(100vw - 48px));
  padding: 18px 18px 18px 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 22px;
  background: rgba(25, 27, 38, 0.94);
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(18px);
  pointer-events: auto;
}

.cookie-copy {
  margin: 0;
  color: rgba(245, 241, 234, 0.8);
  font-size: 0.92rem;
  line-height: 1.6;
}

.cookie-accept {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  padding: 14px 22px;
  font: 700 0.92rem/1 Inter, ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
}

.settings-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.settings-row:last-child {
  border-bottom: 0;
}

.setting-btn {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: #858aa0;
  padding: 16px 10px;
  font: 500 0.95rem/1.2 Inter, ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
  transition: color 180ms ease, background-color 180ms ease;
}

.setting-btn:hover,
.setting-btn.is-active {
  color: #f5f1ea;
}

.size-btn {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
}

.size-btn.is-large {
  font-size: 1.5rem;
}

.cover-hero {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(320px, 1fr);
  align-items: center;
  gap: 48px;
  padding: 72px clamp(32px, 7vw, 96px);
}

.cover-copy {
  max-width: 540px;
}

.hero-title {
  margin: 18px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 8vw, 6rem);
  line-height: 0.9;
  letter-spacing: -0.06em;
}

.hero-text {
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.8;
  max-width: 420px;
}

.book-cover-wrap {
  margin: 0;
  display: flex;
  justify-content: center;
}

.book-cover {
  display: block;
  width: min(100%, 500px);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.book-sections {
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding: 0 clamp(32px, 8vw, 120px);
}

.book-section {
  width: min(100%, 860px);
  max-width: 860px;
  margin: 0 auto;
  scroll-margin-top: 32px;
  background:
    linear-gradient(180deg, var(--card-sheen), transparent 160px),
    var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 30px;
  padding: clamp(28px, 5vw, 64px);
  box-shadow:
    0 30px 70px rgba(70, 48, 30, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  overflow: hidden;
}

.section-title {
  margin: 0;
  font-family: var(--reader-font-family);
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
  letter-spacing: -0.05em;
  color: var(--ink);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.section-body {
  margin-top: 28px;
  font-family: var(--reader-font-family);
  font-size: calc(1.08rem * var(--reader-font-scale));
  line-height: var(--reader-line-height);
  color: var(--ink);
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.section-body p {
  margin: 0 0 24px;
}

.section-figure {
  margin: 0 0 28px;
}

.section-image {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 20px;
  box-shadow:
    0 18px 40px rgba(30, 22, 18, 0.14),
    0 2px 10px rgba(30, 22, 18, 0.08);
}

.section-body ul {
  margin: 0 0 28px;
  padding-left: 24px;
  max-width: 100%;
}

.section-body li {
  margin: 0 0 12px;
}

.section-quote {
  margin: 0 0 24px;
  padding: 22px 28px;
  border-left: 4px solid var(--accent);
  border-radius: 0 20px 20px 0;
  background: var(--accent-soft);
  font-style: italic;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .chapter-sidebar {
    width: min(86vw, 360px);
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  body.sidebar-open .reader-shell {
    margin-left: 0;
  }

  .cover-hero {
    grid-template-columns: 1fr;
    min-height: auto;
    padding-top: 112px;
    padding-bottom: 48px;
  }

  .cover-copy {
    max-width: none;
  }
}

@media (max-width: 640px) {
  .sidebar-toggle {
    top: 16px;
    left: 16px;
    width: 52px;
    height: 52px;
  }

  .reader-settings {
    top: 16px;
    right: 16px;
  }

  .settings-toggle {
    width: 52px;
    height: 52px;
  }

  .settings-panel {
    width: min(280px, calc(100vw - 32px));
    max-height: calc(100dvh - 104px);
    overflow: auto;
  }

  .cookie-banner {
    right: 12px;
    bottom: 12px;
    left: 12px;
    max-width: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
    border-radius: 18px;
  }

  .cookie-accept {
    width: 100%;
    padding-block: 16px;
  }

  .sidebar-top {
    padding-inline: 24px;
  }

  .chapter-link {
    padding-right: 24px;
    padding-left: calc(24px + var(--chapter-indent, 0px));
  }

  .chapter-link:hover,
  .chapter-link.is-active {
    padding-left: calc(32px + var(--chapter-indent, 0px));
  }

  .cover-hero {
    padding-inline: 24px;
    gap: 28px;
  }

  .hero-title {
    margin-top: 0;
    font-size: clamp(2.5rem, 14vw, 4rem);
    line-height: 0.95;
    overflow-wrap: anywhere;
  }

  .book-cover {
    width: min(100%, 360px);
  }

  .book-sections {
    gap: 20px;
    padding-inline: 12px;
  }

  .book-section {
    border-radius: 20px;
    padding: 28px 20px 30px;
  }

  .section-title {
    font-size: clamp(2rem, 10vw, 2.8rem);
    letter-spacing: -0.04em;
  }

  .section-body {
    margin-top: 22px;
    font-size: calc(1.02rem * var(--reader-font-scale));
  }

  .section-body p {
    margin-bottom: 20px;
  }

  .section-body ul {
    padding-left: 20px;
  }

  .section-quote {
    padding: 18px 18px 18px 20px;
    border-radius: 0 16px 16px 0;
  }
}
