:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --display-font: "Copperplate Gothic Bold", "Copperplate", "Copperplate Gothic", "Cinzel", Georgia, serif;
  --page: #faf5e9;
  --panel: #efe6d3;
  --ink: #30271d;
  --muted: #70604b;
  --faint: #dbceb5;
  --accent: #85500e;
  --accent-soft: rgba(166, 103, 21, 0.12);
  --quote: rgba(255, 255, 255, 0.38);
  --shadow: rgba(47, 42, 33, 0.08);
  --reading-font: "Literata", ui-serif, Georgia, serif;
  --reading-tracking: -0.012em;
  --highlight: #f2d382;
  --highlight-ink: #30271d;
}

body[data-theme="sepia"] {
  color-scheme: light;
  --page: #dfcbaa;
  --panel: #d2bc98;
  --ink: #34281c;
  --muted: #5c4833;
  --faint: #b9a07b;
  --accent: #6d3e0f;
  --accent-soft: rgba(117, 68, 17, 0.13);
  --quote: rgba(255, 249, 237, 0.28);
  --shadow: rgba(56, 42, 31, 0.1);
}

body[data-theme="dark"] {
  --highlight: #806021;
  --highlight-ink: #fff6df;
  color-scheme: dark;
  --page: #211d17;
  --panel: #2b251d;
  --ink: #f0e6d3;
  --muted: #bdae95;
  --faint: #453b2e;
  --accent: #e0b46d;
  --accent-soft: rgba(224, 180, 109, 0.13);
  --quote: rgba(255, 255, 255, 0.035);
  --shadow: rgba(0, 0, 0, 0.2);
}

body[data-reading-font="literata"] {
  --reading-font: "Literata", ui-serif, Georgia, serif;
  --reading-tracking: -0.012em;
}

body[data-reading-font="source-serif"] {
  --reading-font: "Source Serif 4", ui-serif, Georgia, serif;
  --reading-tracking: -0.006em;
}

body[data-reading-font="atkinson"] {
  --reading-font: "Atkinson Hyperlegible", ui-sans-serif, sans-serif;
  --reading-tracking: 0;
}

body[data-reading-font="noto-sans"] {
  --reading-font: "Noto Sans", ui-sans-serif, sans-serif;
  --reading-tracking: -0.008em;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  transition: background-color 240ms ease, color 240ms ease;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
  font: inherit;
}

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

.reading-column:focus {
  outline: none;
}

[hidden] {
  display: none !important;
}

.cover {
  --ink: #fff5df;
  --page: #302417;
  --muted: #fff5df;
  --accent: #fff5df;
  position: relative;
  display: grid;
  min-height: 100svh;
  place-items: center;
  overflow: hidden;
  padding: 1.5rem 1rem;
  background: #302417;
  color: var(--ink);
  isolation: isolate;
}

.cover::before {
  position: absolute;
  z-index: -1;
  inset: -4rem;
  background: linear-gradient(rgba(24, 16, 8, 0.6), rgba(24, 16, 8, 0.6)),
    url("deep-prayer-cover-original.jpg") center / cover;
  filter: blur(3rem);
  content: "";
}

.cover-content {
  position: relative;
  width: min(90%, max(14.4rem, calc((100svh - 3rem) * 900 / 1491)));
  border-radius: 0.75rem;
  box-shadow: 0 2rem 5rem rgba(17, 12, 5, 0.6),
    0 0 2.5rem rgba(17, 12, 5, 0.35);
}

.cover-artwork {
  display: block;
  width: 100%;
  height: auto;
  border-radius: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.read-button {
  position: absolute;
  top: 62%;
  left: 50%;
  translate: -50% -100%;
  display: inline-flex;
  align-items: center;
  gap: 1.5rem;
  margin: 0;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--page);
  box-shadow: 0 0.4rem 1.25rem rgba(48, 36, 23, 0.3);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  padding: 0.95rem 1.1rem 0.95rem 1.45rem;
  text-transform: uppercase;
  white-space: nowrap;
  transition: gap 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.read-button:hover {
  gap: 2rem;
  box-shadow: 0 0.7rem 2rem rgba(48, 36, 23, 0.4);
  transform: translateY(-2px);
}

.read-button svg,
.menu-button svg,
.close-sidebar svg {
  width: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.75;
}

.theme-switcher {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.theme-dot {
  width: 1.15rem;
  height: 1.15rem;
  border: 1px solid color-mix(in srgb, var(--ink) 28%, transparent);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--page);
  cursor: pointer;
  padding: 0;
}

.theme-dot[data-set-theme="light"] { background: #faf5e9; }
.theme-dot[data-set-theme="sepia"] { background: #dfcbaa; }
.theme-dot[data-set-theme="dark"] { background: #211d17; }

.theme-dot[aria-pressed="true"] {
  outline: 1px solid var(--ink);
  outline-offset: 3px;
}

.reader {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  z-index: 20;
  inset: 0 auto 0 0;
  display: flex;
  width: clamp(18rem, 25vw, 21.5rem);
  flex-direction: column;
  border-right: 1px solid var(--faint);
  background: var(--panel);
  padding: 1.7rem 1.35rem 1.35rem;
  transition: background-color 240ms ease, transform 240ms ease;
}

.sidebar-heading,
.contents-label,
.theme-control,
.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-heading {
  gap: 0.75rem;
}

.sidebar-heading .close-sidebar {
  flex: 0 0 2.75rem;
  height: 2.75rem;
  align-items: center;
  justify-content: center;
}

.wordmark {
  flex: 1;
  min-width: 0;
  min-height: 2.75rem;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: var(--display-font);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.1;
  padding: 0;
  text-align: left;
}

.wordmark-text {
  display: inline-block;
  white-space: nowrap;
}

.contents-label {
  margin-top: 2.6rem;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.13em;
  padding: 0 0.35rem 0.75rem;
  text-transform: uppercase;
}

.chapter-list {
  overflow-y: auto;
  padding-right: 0.25rem;
  scrollbar-color: var(--faint) transparent;
}

.chapter-link {
  display: grid;
  width: 100%;
  grid-template-columns: 2.15rem 1fr;
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  gap: 0.35rem;
  padding: 0.72rem 0.38rem;
  text-align: left;
  transition: background-color 150ms ease, color 150ms ease;
}

.chapter-link:hover {
  background: var(--accent-soft);
  color: var(--ink);
}

.chapter-link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--ink);
}

.chapter-number {
  color: var(--muted);
  font-size: 0.69rem;
  font-variant-numeric: tabular-nums;
  padding-top: 0.18rem;
  text-align: center;
}

.chapter-name {
  font-size: 0.84rem;
  font-weight: 620;
  line-height: 1.35;
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--faint);
  padding: 1rem 0.35rem 0;
}

.font-control {
  margin-bottom: 1.15rem;
}

.font-control > span,
.theme-control > span {
  color: var(--muted);
  font-size: 0.73rem;
}

.font-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  margin-top: 0.65rem;
}

.font-picker button {
  overflow: hidden;
  border: 1px solid var(--faint);
  border-radius: 0.45rem;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.71rem;
  padding: 0.5rem 0.45rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.font-picker button:hover,
.font-picker button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
}

.font-picker [data-set-font="literata"] { font-family: "Literata", ui-serif, serif; }
.font-picker [data-set-font="source-serif"] { font-family: "Source Serif 4", ui-serif, serif; }
.font-picker [data-set-font="atkinson"] { font-family: "Atkinson Hyperlegible", ui-sans-serif, sans-serif; }
.font-picker [data-set-font="noto-sans"] { font-family: "Noto Sans", ui-sans-serif, sans-serif; }

.sidebar-footer p {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.65rem;
}

.reader-panel {
  min-height: 100vh;
  margin-left: clamp(18rem, 25vw, 21.5rem);
}

.reading-progress {
  position: fixed;
  z-index: 15;
  top: 0;
  right: 0;
  left: clamp(18rem, 25vw, 21.5rem);
  height: 2px;
  background: var(--faint);
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 100ms linear;
}

.reader-toolbar {
  position: sticky;
  z-index: 10;
  top: 0;
  height: 4rem;
  border-bottom: 1px solid color-mix(in srgb, var(--faint) 70%, transparent);
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(15px);
  gap: 0.75rem;
  justify-content: flex-start;
  padding: 0 1.5rem;
}

.reader-toolbar p {
  overflow: hidden;
  margin: 0;
  margin-right: auto;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-button,
.close-sidebar {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.menu-button,
.close-sidebar {
  display: none;
  padding: 0.35rem;
}

.reading-column {
  --chapter-space: clamp(3rem, 6vw, 5rem);
  width: min(100% - 3rem, 48rem);
  margin: 0 auto;
  padding: var(--chapter-space) 0 7rem;
}

.chapter-header {
  display: grid;
  gap: 1.25rem;
  margin-bottom: var(--chapter-space);
}

.chapter-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

.chapter-header h1 {
  --title-base-size: clamp(2.8rem, 6.5vw, 5.6rem);
  max-width: 13ch;
  margin: 0;
  font-family: var(--display-font);
  font-size: calc(var(--title-base-size) * 1.1);
  font-weight: 790;
  letter-spacing: -0.02em;
  line-height: calc(var(--title-base-size) * 1.15);
  overflow-wrap: anywhere;
}

.chapter-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.book-prose {
  font-family: var(--reading-font);
  font-size: clamp(1.06rem, 1.5vw, 1.22rem);
  letter-spacing: var(--reading-tracking);
  line-height: 1.78;
}

.book-prose .body-copy {
  margin: 0 0 1.35em;
}

.book-prose h2 {
  margin: 2.8em 0 0.8em;
  font-size: 1.28em;
  font-weight: 760;
  letter-spacing: -0.027em;
  line-height: 1.25;
}

.book-prose > :first-child {
  margin-top: 0;
}

.book-prose ::selection,
.book-prose::selection {
  background: var(--highlight);
  color: var(--highlight-ink);
}

.shared-highlight {
  background: var(--highlight);
  color: var(--highlight-ink);
  scroll-margin-block: 6rem;
}

.clear-highlight {
  flex-shrink: 0;
  min-height: 2.75rem;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.8rem;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.quote-actions {
  position: fixed;
  z-index: 15;
  left: 0;
  top: 0;
  width: max-content;
  max-width: calc(100% - 3rem);
  max-height: 45svh;
  overflow: auto;
  border: 1px solid var(--faint);
  border-radius: 0.8rem;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 0.7rem 2.5rem rgba(30, 22, 12, 0.2);
  padding: 0.4rem;
}

.quote-buttons {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.quote-actions button {
  min-height: 2.75rem;
  border: 1px solid var(--faint);
  border-radius: 0.4rem;
  background: var(--page);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.875rem;
  padding: 0.5rem 0.8rem;
}

.quote-buttons button:hover {
  border-color: var(--accent);
}

.quote-status,
.quote-notice {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.quote-status:empty {
  margin: 0;
}

.quote-copy-badge {
  position: fixed;
  z-index: 16;
  pointer-events: none;
  border: 1px solid var(--faint);
  border-radius: 999px;
  background: var(--ink);
  color: var(--page);
  box-shadow: 0 0.25rem 0.8rem rgba(30, 22, 12, 0.15);
  padding: 0.25rem 0.65rem;
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: nowrap;
}

.quote-actions textarea {
  width: 100%;
  margin-top: 0.75rem;
  border: 1px solid var(--faint);
  border-radius: 0.4rem;
  background: var(--page);
  color: var(--ink);
  padding: 0.5rem;
  font: inherit;
  font-size: 1rem;
}

.book-prose .quotation {
  margin: 0;
  border-left: 1px solid var(--accent);
  background: var(--quote);
  padding: 0.12em 1.4em;
  font-size: 0.96em;
  line-height: 1.72;
}

.book-prose .body-copy + .quotation,
.book-prose h2 + .quotation {
  padding-top: 0.9em;
}

.book-prose .quotation + .body-copy,
.book-prose .quotation + h2 {
  margin-top: 1.5em;
}

.book-prose .quotation + .quotation:last-of-type {
  padding-bottom: 0.9em;
}

.book-prose em {
  font-style: italic;
}

.footnote-marker {
  margin-left: 0.08em;
  font-size: 0.6em;
  line-height: 0;
}

.footnote-marker a,
.footnote-back {
  color: var(--accent);
  font-weight: 750;
  text-decoration: none;
}

.footnotes {
  margin-top: 5rem;
  border-top: 1px solid var(--faint);
  color: var(--muted);
  font-size: 0.72em;
}

.footnotes h2 {
  color: var(--ink);
}

.footnotes ol {
  padding-left: 1.5rem;
}

.footnotes li {
  margin-bottom: 1.1em;
  padding-left: 0.35rem;
}

.footnotes li p {
  display: inline;
  margin: 0;
}

.footnote-back {
  margin-left: 0.5rem;
}

.chapter-pagination {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 5rem;
  border-top: 1px solid var(--faint);
  gap: 1rem;
  padding-top: 1.5rem;
}

.page-chapter {
  border: 0;
  border-radius: 0.7rem;
  background: var(--accent-soft);
  cursor: pointer;
  padding: 1.25rem;
  text-align: left;
}

.page-chapter:last-child {
  text-align: right;
}

.page-chapter small {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.page-chapter span {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.35;
}

.sidebar-scrim {
  display: none;
}

@media (max-width: 800px) {
  .sidebar {
    width: min(89vw, 22rem);
    box-shadow: 1rem 0 3rem var(--shadow);
    transform: translateX(-105%);
  }

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

  .sidebar-scrim {
    position: fixed;
    z-index: 19;
    inset: 0;
    display: block;
    background: rgba(10, 10, 9, 0.38);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
  }

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

  .reader-panel {
    margin-left: 0;
  }

  .reading-progress {
    left: 0;
  }

  .menu-button,
  .close-sidebar {
    display: inline-flex;
  }

  .reading-column {
    width: min(100% - 2.2rem, 43rem);
  }

  .chapter-pagination {
    grid-template-columns: 1fr;
  }

  .page-chapter:last-child {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}

@media print {
  .quote-actions,
  .quote-copy-badge,
  .clear-highlight { display: none !important; }
  .sidebar,
  .reader-toolbar,
  .reading-progress,
  .chapter-pagination { display: none !important; }
  .reader-panel { margin: 0; }
  .reading-column { width: 100%; padding: 0; }
}
