:root {
  --night: #0c1733;
  --night-deep: #08101f;
  --navy: #11265e;
  --ink: #1c2433;
  --gold: #a68445;
  --gold-soft: #e8d7ae;
  --paper-0: #f8f3e8;
  --paper-1: #f1e6d2;
  --muted: #6e6254;
  --serif: "Cormorant Garamond", Palatino, "Palatino Linotype", Georgia, serif;
  --text: "Source Serif 4", Palatino, Georgia, serif;
  --sans: Outfit, "Avenir Next", "Segoe UI", sans-serif;
  --edge: 12px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--sans);
  color: var(--gold-soft);
  background: var(--night);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

::selection { background: rgba(184, 154, 94, .35); }

.live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.stage {
  height: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px 18px 18px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(1.2px 1.2px at 8% 18%, rgba(255,255,255,.85) 50%, transparent 52%),
    radial-gradient(1px 1px at 18% 62%, rgba(255,255,255,.45) 50%, transparent 52%),
    radial-gradient(1.6px 1.6px at 74% 14%, rgba(255,244,214,.95) 50%, transparent 52%),
    radial-gradient(1px 1px at 88% 46%, rgba(255,255,255,.55) 50%, transparent 52%),
    radial-gradient(1px 1px at 46% 10%, rgba(255,255,255,.4) 50%, transparent 52%),
    radial-gradient(1.2px 1.2px at 62% 78%, rgba(255,255,255,.5) 50%, transparent 52%),
    radial-gradient(1px 1px at 32% 34%, rgba(255,255,255,.35) 50%, transparent 52%),
    radial-gradient(1px 1px at 92% 82%, rgba(255,255,255,.4) 50%, transparent 52%),
    radial-gradient(ellipse at 50% 120%, rgba(28, 52, 110, .45), transparent 55%),
    linear-gradient(180deg, var(--night-deep) 0%, #122652 58%, #0b152c 100%);
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  position: relative;
  z-index: 4;
  margin-bottom: 12px;
}

.top-title {
  margin: 0;
  text-align: center;
  font-family: var(--serif);
  font-size: 1.15rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--gold-soft);
  font-weight: 600;
}

.text-btn {
  justify-self: start;
  border: 1px solid rgba(232, 215, 174, .38);
  border-radius: 999px;
  padding: 7px 14px;
  letter-spacing: .16em;
  text-transform: uppercase;
  font-size: .68rem;
  font-weight: 500;
  color: var(--gold-soft);
}

.text-btn:hover,
.text-btn:focus-visible {
  background: rgba(232, 215, 174, .12);
  outline: none;
}

.switch {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--gold-soft);
}

.switch-label {
  letter-spacing: .14em;
  text-transform: uppercase;
  font-size: .68rem;
  font-weight: 500;
}

.switch-ui {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(232, 215, 174, .45);
  background: transparent;
  position: relative;
  flex: none;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(232, 215, 174, .75);
  transition: transform .2s ease, background .2s ease;
}

.switch[aria-checked="true"] .switch-ui {
  background: rgba(166, 132, 69, .85);
  border-color: transparent;
}

.switch[aria-checked="true"] .switch-ui::after {
  transform: translateX(16px);
  background: #fff8ea;
}

.book-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  position: relative;
  container-type: size;
}

.nav-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(232, 215, 174, .42);
  color: var(--gold-soft);
  display: grid;
  place-items: center;
  flex: none;
  position: relative;
  z-index: 1;
  background: rgba(8, 16, 36, .25);
}

.nav-btn:hover,
.nav-btn:focus-visible {
  background: rgba(232, 215, 174, .14);
  outline: none;
}

.nav-btn:disabled {
  opacity: .28;
  cursor: default;
  background: transparent;
}

.book {
  position: relative;
  z-index: 2;
  aspect-ratio: 3 / 4.15;
  width: min(500px, calc(100cqh * 3 / 4.15), calc(100cqw - 140px));
  height: auto;
  max-height: 100%;
  perspective: 2400px;
}

.book::before {
  content: "";
  position: absolute;
  z-index: 7;
  left: -4px;
  top: 3px;
  bottom: 3px;
  width: 7px;
  border-radius: 3px 0 0 3px;
  pointer-events: none;
  background: linear-gradient(90deg, #5c4a2e, #d9c59a 70%, #8d7344);
}

.fore-edge {
  position: absolute;
  top: 7px;
  bottom: 7px;
  right: calc(-1 * var(--edge));
  width: var(--edge);
  border-radius: 0 3px 3px 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    90deg,
    #f6efe2 0 1px,
    #cbb992 1px 2px
  );
  box-shadow: 2px 1px 5px rgba(0, 0, 0, .2);
}

.page,
.face {
  background-color: var(--paper-0);
  background-image:
    radial-gradient(120% 70% at 0% 0%, rgba(255, 253, 248, .75), transparent 52%),
    linear-gradient(168deg, var(--paper-0) 0%, var(--paper-1) 100%);
  color: var(--ink);
}

.page {
  position: absolute;
  inset: 0;
  border-radius: 2px 8px 8px 2px;
  overflow: hidden;
  box-shadow:
    0 24px 50px rgba(0, 0, 0, .4),
    0 2px 8px rgba(0, 0, 0, .22);
}

.page.settle { animation: rise .36s ease; }

@keyframes rise {
  from { opacity: .4; }
  to { opacity: 1; }
}

.leaf {
  position: absolute;
  inset: 0;
  z-index: 5;
  transform-style: preserve-3d;
  transform-origin: left center;
  pointer-events: auto;
}

.leaf * { pointer-events: none; }

.face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 2px 8px 8px 2px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.face.back { transform: rotateY(180deg); }

.shade {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg, rgba(28, 18, 6, .32), rgba(28, 18, 6, 0) 46%);
}

.page-inner {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 20px 28px 16px 32px;
}

.page-inner::before {
  content: "";
  position: absolute;
  z-index: 4;
  left: 0;
  top: 0;
  bottom: 0;
  width: 24px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(62, 42, 16, .15), rgba(62, 42, 16, .04) 62%, transparent);
}

.page-inner::after {
  content: "";
  position: absolute;
  z-index: 4;
  inset: 11px 11px 11px 16px;
  border: 1px solid rgba(146, 116, 58, .32);
  pointer-events: none;
}

.running {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--sans);
  font-size: .66rem;
  font-weight: 500;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--gold);
  padding: 2px 4px 10px;
}

.page-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: #c4b089 transparent;
}

.is-opening .page-body { justify-content: center; }

.opening { margin: auto; text-align: center; width: 100%; }

.opening h1 {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.eyebrow {
  font-family: var(--sans);
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: .7rem;
}

.big {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(4.6rem, 13vh, 7.2rem);
  line-height: .82;
  letter-spacing: -.03em;
  color: var(--navy);
  font-variant-numeric: lining-nums;
  font-feature-settings: "lnum" 1, "tnum" 1;
}

.kind-span .big {
  font-size: clamp(3rem, 8vh, 5rem);
  letter-spacing: -.02em;
}

.bookname {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.3rem, 6vh, 3.4rem);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--navy);
  line-height: 1.05;
  padding-left: .2em;
}

.range {
  font-family: var(--serif);
  font-weight: 500;
  font-style: italic;
  font-size: clamp(1.4rem, 3.2vh, 1.85rem);
  color: #3a3228;
  margin-top: .45rem;
}

.lang {
  font-family: var(--sans);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--gold);
  margin-top: .9rem;
}

.ornament {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 132px;
  margin: 18px auto 0;
}

.ornament span {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, #b89a5e, transparent);
}

.ornament i {
  width: 6px;
  height: 6px;
  background: #b89a5e;
  transform: rotate(45deg);
  display: block;
}

.has-text .page-body { justify-content: flex-start; }

.has-text .opening {
  margin: 4px 0 0;
  text-align: left;
}

.has-text .opening h1 { align-items: flex-start; }

.has-text .eyebrow { margin-bottom: .2rem; letter-spacing: .18em; }

.has-text .range {
  font-style: normal;
  font-weight: 600;
  font-size: clamp(1.7rem, 3vh, 2.15rem);
  color: var(--navy);
  margin-top: 0;
  line-height: 1.1;
}

.scripture {
  margin-top: 1.15rem;
  padding-bottom: .5rem;
}

.scripture p {
  font-family: var(--text);
  font-size: 1.12rem;
  line-height: 1.62;
  color: #241e16;
  margin: 0 0 .95em;
}

.scripture p:first-of-type::first-letter {
  font-family: var(--serif);
  float: left;
  font-size: 3.15rem;
  line-height: .78;
  padding: .12em .1em 0 0;
  color: var(--navy);
  font-weight: 600;
}

.player {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 16px;
  align-items: center;
  margin-top: 10px;
  padding-top: 12px;
  position: relative;
  z-index: 5;
}

.play {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--navy);
  color: #f6efe2;
  display: grid;
  place-items: center;
  position: relative;
  box-shadow:
    0 0 0 1px rgba(184, 154, 94, .75),
    0 8px 16px rgba(17, 38, 94, .22);
}

.play:hover,
.play:focus-visible { transform: scale(1.04); outline: none; }

.icon-pause { display: none; }

.page-inner.is-playing .icon-play { display: none; }
.page-inner.is-playing .icon-pause { display: block; }

.page-inner.is-waiting .play::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1.5px solid transparent;
  border-top-color: var(--gold-soft);
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.nudges { display: flex; gap: 2px; justify-content: center; }

.nudge {
  min-width: 34px;
  min-height: 28px;
  font-size: .66rem;
  letter-spacing: .04em;
  color: var(--muted);
  border-radius: 6px;
}

.nudge:hover,
.nudge:focus-visible { color: var(--navy); outline: none; }

.player-main { min-width: 0; padding-right: 8px; }

.seek {
  padding: 10px 0;
  cursor: pointer;
  touch-action: none;
}

.seek:focus-visible { outline: none; }

.seek:focus-visible .seek-track { box-shadow: 0 0 0 3px rgba(166, 132, 69, .25); }

.seek-track {
  height: 3px;
  border-radius: 99px;
  background: rgba(17, 38, 94, .14);
  position: relative;
}

.seek-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8d7040, #c6a15a);
  width: 0;
  position: relative;
}

.seek-fill::after {
  content: "";
  position: absolute;
  right: -5px;
  top: 50%;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--navy);
  transform: translateY(-50%);
  box-shadow: 0 0 0 2px rgba(198, 161, 90, .7);
}

.times {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  font-variant-numeric: tabular-nums;
  font-size: .72rem;
  letter-spacing: .04em;
  color: var(--muted);
  margin-top: -2px;
}

.time-total { text-align: right; }

.resume,
.end-note,
.player-error {
  position: relative;
  z-index: 5;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  color: #5c5144;
  margin: 4px 0 0;
}

.resume button {
  font: inherit;
  font-style: italic;
  color: var(--navy);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.end-note { display: none; }
.page-inner.is-finished .end-note { display: block; }

.player-error { font-family: var(--sans); font-style: normal; font-size: .78rem; color: #8a3d2a; }
.player-error[hidden] { display: none; }

.folio {
  margin: 6px 28px 2px;
  text-align: center;
  font-family: var(--serif);
  font-size: .95rem;
  letter-spacing: .16em;
  color: var(--gold);
}

.corner {
  position: absolute;
  z-index: 6;
  right: 0;
  bottom: 0;
  width: 86px;
  height: 86px;
  cursor: pointer;
}

.fold {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 54px;
  height: 54px;
  background: linear-gradient(135deg, transparent 0 49%, rgba(255,255,255,.7) 49% 52%, #e7dcc4 52% 100%);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  filter: drop-shadow(-5px -4px 4px rgba(48, 32, 8, .16));
  transition: width .22s ease, height .22s ease;
}

.corner:hover .fold,
.corner:focus-visible .fold {
  width: 82px;
  height: 82px;
  outline: none;
}

.corner.hint .fold { animation: peel 1s ease-in-out 3; }

@keyframes peel {
  0%, 100% { width: 54px; height: 54px; }
  45% { width: 88px; height: 88px; }
}

.toc[hidden] { display: none; }

.toc-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(6, 12, 28, .55);
}

.toc-panel {
  position: fixed;
  z-index: 31;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(400px, 92vw);
  overflow: auto;
  color: var(--ink);
  background: #f6f0e4;
  box-shadow: 16px 0 48px rgba(0, 0, 0, .35);
  padding: 0 22px 28px;
  animation: tocIn .32s ease;
  scrollbar-width: thin;
  scrollbar-color: #c4b089 transparent;
}

@keyframes tocIn {
  from { transform: translateX(-18px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.toc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  position: sticky;
  top: 0;
  background: linear-gradient(#f6f0e4 78%, rgba(246, 240, 228, 0));
  padding: 22px 0 14px;
  margin: 0;
  z-index: 1;
}

.toc-panel h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 600;
  color: var(--navy);
  letter-spacing: .02em;
}

.toc-book {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.15rem;
  color: #3e362c;
}

#toc-meta {
  margin: 4px 0 0;
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--gold);
}

.toc-close {
  color: var(--navy);
  border-color: rgba(17, 38, 94, .25);
  flex: none;
}

.toc-group h3 {
  margin: 1.15rem 0 .25rem;
  font-family: var(--sans);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--gold);
}

.toc-group:first-child h3 { margin-top: .2rem; }

.toc-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  font-family: var(--serif);
  font-size: 1.22rem;
  color: var(--ink);
}

.toc-item:hover { background: rgba(17, 38, 94, .05); }

.toc-item[aria-current="true"] {
  background: rgba(17, 38, 94, .08);
  box-shadow: inset 2px 0 0 var(--navy);
  color: var(--navy);
}

.toc-time {
  font-family: var(--sans);
  font-size: .72rem;
  letter-spacing: .04em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex: none;
}

.toc-hint {
  margin: 1.4rem 0 0;
  font-size: .72rem;
  letter-spacing: .06em;
  color: var(--muted);
}

@media (max-width: 760px) {
  .stage { padding: 12px 10px 12px; }
  .top-title { display: none; }
  .topbar { grid-template-columns: auto 1fr; }
  .switch-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .book-wrap { gap: 0; }
  .book {
    width: 100%;
    max-width: 100%;
    height: 100%;
    aspect-ratio: auto;
  }
  .nav-btn {
    position: absolute;
    top: 8px;
    bottom: auto;
    transform: none;
    z-index: 8;
    width: 34px;
    height: 34px;
    background: rgba(8, 16, 36, .5);
  }
  .nav-prev { left: 6px; }
  .nav-next { right: 6px; }
  .page-inner { padding: 14px 16px 12px 18px; }
  .running { padding-left: 30px; padding-right: 30px; }
  .big { font-size: 4.4rem; }
  .scripture p { font-size: 1.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  .page.settle,
  .corner.hint .fold,
  .toc-panel,
  .page-inner.is-waiting .play::after { animation: none; }
  .fold { transition: none; }
}
