:root {
  --pw: 420px;
  --ph: 630px;
  --fs: 17px;
  --pad-x: 46px;
  --pad-y: 42px;
  --bg: #0b0f16;
  --chrome: #c9cfd8;
  --chrome-dim: #7d8696;
  --paper: #f3ecdf;
  --paper-edge: #e6dcc8;
  --ink: #2b2723;
  --ink-soft: #6f665b;
  --accent: #7a5c3a;
  --rule: rgba(60, 45, 30, .22);
  --flip-ms: 760ms;
  --serif: "EB Garamond", "Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

body.night {
  --paper: #1b1e25;
  --paper-edge: #14161b;
  --ink: #d9d1c3;
  --ink-soft: #8e877b;
  --accent: #c2a57d;
  --rule: rgba(220, 205, 180, .18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--chrome);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 50% at 62% 38%, rgba(120, 140, 170, .16), transparent 70%),
    radial-gradient(ellipse 120% 80% at 50% 120%, rgba(0, 0, 0, .6), transparent 60%);
}

/* ---------- Toolbar & pager ---------- */

.toolbar, .pager {
  position: fixed;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 max(12px, env(safe-area-inset-left));
  z-index: 30;
  transition: opacity .4s ease;
}

.toolbar { top: 0; height: 56px; padding-top: env(safe-area-inset-top); }
.pager {
  bottom: 0;
  height: 64px;
  padding-bottom: env(safe-area-inset-bottom);
  justify-content: center;
}

.toolbar-title {
  flex: 1;
  text-align: center;
  font-size: 15px;
  letter-spacing: .08em;
  color: var(--chrome-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
}

.toolbar-actions { display: flex; gap: 2px; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--chrome);
  transition: background .2s, color .2s, opacity .2s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .08); }
.icon-btn:focus-visible, .cta:focus-visible, .tab:focus-visible { outline: 1px solid var(--chrome); outline-offset: 2px; }
.icon-btn:disabled { opacity: .25; cursor: default; background: transparent; }
.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn .glyph { font-size: 21px; line-height: 1; }
.icon-btn .glyph.small { font-size: 15px; }
#btn-fav.on svg { fill: #c96b5e; stroke: #c96b5e; }

.page-label {
  min-width: 82px;
  text-align: center;
  font-size: 14px;
  color: var(--chrome-dim);
  font-variant-numeric: oldstyle-nums;
  letter-spacing: .04em;
}

#scrub {
  width: min(360px, 44vw);
  accent-color: #9aa6b8;
  height: 2px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, .18);
  border-radius: 2px;
  outline: none;
}
#scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--chrome);
  cursor: pointer;
}
#scrub::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--chrome); }

body.is-closed .pager,
body.is-closed #btn-font-down,
body.is-closed #btn-font-up,
body.is-closed #btn-theme { opacity: 0; pointer-events: none; }

/* ---------- Stage & book ---------- */

.stage {
  position: fixed;
  inset: 56px 0 64px;
  display: grid;
  place-items: center;
  touch-action: pan-y;
}

.book {
  position: relative;
  width: calc(var(--pw) * 2);
  height: var(--ph);
  perspective: calc(var(--pw) * 5);
  transition: transform var(--flip-ms) cubic-bezier(.45, .05, .3, 1);
  font-size: var(--fs);
}
body.single .book { width: var(--pw); }
.book.closed { transform: translateX(calc(var(--pw) * -.5)); }
body.single .book.closed { transform: none; }

.half, .leaf {
  position: absolute;
  top: 0;
  width: var(--pw);
  height: 100%;
}
.half.left { left: 0; }
.half.right, .leaf { left: var(--pw); }
body.single .half.left { display: none; }
body.single .half.right, body.single .leaf { left: 0; }

.leaf {
  z-index: 10;
  transform-origin: left center;
  transform-style: preserve-3d;
  will-change: transform;
}
.leaf .face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.leaf .face.back { transform: rotateY(180deg); }
.leaf .shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}
.leaf .face.front .shade { background: linear-gradient(to left, rgba(0, 0, 0, .35), rgba(0, 0, 0, .05) 60%, rgba(0, 0, 0, .15)); }
.leaf .face.back .shade { background: linear-gradient(to right, rgba(0, 0, 0, .35), rgba(0, 0, 0, .05) 60%, rgba(0, 0, 0, .15)); }

.book:not(.closed) .half.left .page,
.book:not(.closed) .half.right .page { box-shadow: 0 18px 40px -12px rgba(0, 0, 0, .7); }

/* ---------- Pages ---------- */

.page {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--pad-y) var(--pad-x) calc(var(--pad-y) * .55);
  background:
    radial-gradient(ellipse at 50% 40%, transparent 60%, rgba(120, 90, 50, .06)),
    var(--paper);
  color: var(--ink);
  overflow: hidden;
  font-size: var(--fs);
  line-height: 1.45;
}
body.night .page:not(.cover, .endpaper, .backcover) { background: radial-gradient(ellipse at 50% 40%, transparent 60%, rgba(0, 0, 0, .25)), var(--paper); }

.page::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14%;
  pointer-events: none;
}
.page.left { border-radius: 4px 0 0 4px; }
.page.right { border-radius: 0 4px 4px 0; }
.page.left::after { right: 0; background: linear-gradient(to left, rgba(0, 0, 0, .16), rgba(0, 0, 0, .04) 35%, transparent); }
.page.right::after { left: 0; background: linear-gradient(to right, rgba(0, 0, 0, .2), rgba(0, 0, 0, .05) 30%, transparent); }
body.single .page.right { border-radius: 4px; }
body.single .page.right::after { width: 4%; }

.page-body { flex: 1; min-height: 0; overflow: hidden; }
.folio {
  flex: none;
  height: 1.8em;
  padding-top: .6em;
  text-align: center;
  font-size: .72em;
  color: var(--ink-soft);
  font-variant-numeric: oldstyle-nums;
  letter-spacing: .1em;
}

.page.cover {
  padding: 0;
  background: #0a0d13 url("cover.png") 60% top / cover no-repeat;
  border-radius: 3px 6px 6px 3px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .9), inset 4px 0 6px -2px rgba(255, 255, 255, .08);
}
.page.cover::after { left: 0; width: 5%; background: linear-gradient(to right, rgba(0, 0, 0, .45), rgba(255, 255, 255, .05) 60%, transparent); }

.page.endpaper {
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, .05), transparent 50%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .025) 0 2px, transparent 2px 7px),
    #121823;
}
.page.blank .folio { visibility: hidden; }

/* ---------- Ornaments ---------- */

.orn {
  width: 4.5em;
  height: 1em;
  margin: .5em auto 1.1em;
  position: relative;
}
.orn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  border-top: 1px solid var(--rule);
}
.orn::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: .38em;
  height: .38em;
  background: var(--paper);
  border: 1px solid var(--accent);
  transform: translate(-50%, -50%) rotate(45deg);
}

/* ---------- Title, dividers, end ---------- */

.title-page, .divider {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.title-page { justify-content: space-between; padding: 18% 0 4%; }
.title-page h1 { margin: 0; font-weight: 400; font-size: 2.1em; line-height: 1.15; letter-spacing: .01em; }
.tp-author { margin: 0; font-size: 1.05em; letter-spacing: .35em; text-indent: .35em; }
.tp-bottom { margin: 0; font-size: .85em; letter-spacing: .3em; color: var(--ink-soft); }

.divider { justify-content: center; }
.divider .roman { font-size: 3.2em; line-height: 1; color: var(--accent); font-weight: 400; }
.divider h2 { margin: .3em 0 0; font-weight: 400; font-size: 1.5em; font-style: italic; }
.divider p.divider-years { text-transform: none; font-style: italic; letter-spacing: .08em; font-size: .9em; font-variant-numeric: oldstyle-nums; }
.divider p { margin: .2em 0 0; font-size: .8em; color: var(--ink-soft); letter-spacing: .14em; text-transform: uppercase; }

/* ---------- About the author ---------- */

.author-figure {
  height: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1em;
}
.af-photo {
  width: 100%;
  flex: 0 1 78%;
  min-height: 0;
  padding: .45em;
  background: color-mix(in srgb, var(--paper) 70%, #fff);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .15), 0 10px 24px -10px rgba(60, 40, 20, .45);
  transform: rotate(-.6deg);
}
body.night .af-photo { background: #262a33; }
.af-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 44% 38%;
  filter: sepia(.12) saturate(.92);
}
.author-figure figcaption { display: flex; flex-direction: column; align-items: center; gap: .15em; text-align: center; }
.af-name { font-size: 1.2em; letter-spacing: .22em; text-indent: .22em; }
.af-years { font-size: .78em; font-style: italic; color: var(--ink-soft); }

.bio-head { margin: .4em 0 0; text-align: center; font-weight: 500; font-size: 1.32em; }
.kind-author .page-body p {
  margin: 0 0 .75em;
  font-size: .92em;
  line-height: 1.5;
  text-align: justify;
  hyphens: auto;
}
.bio.tight p { font-size: .86em; line-height: 1.42; margin-bottom: .55em; }
.bio.tight .orn { margin-bottom: .8em; }
.kind-author .page-body .bio.tight p.bio-closing { margin-top: .8em; padding-top: .6em; }
.kind-author .page-body p.bio-first::first-letter {
  float: left;
  font-size: 3.1em;
  line-height: .82;
  padding: .06em .08em 0 0;
  color: var(--accent);
}
.kind-author a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--rule); }
.kind-author a:hover { border-bottom-color: var(--accent); }
.kind-author .page-body p.bio-closing {
  margin-top: 1.2em;
  padding-top: .9em;
  border-top: 1px solid var(--rule);
  font-style: italic;
  text-align: center;
  color: var(--ink-soft);
}

/* ---------- Back cover ---------- */

.book.closed-back { transform: translateX(calc(var(--pw) * .5)); }
body.single .book.closed-back { transform: none; }

.page.backcover {
  padding: 0;
  color: #e9dfc8;
  background:
    radial-gradient(ellipse 80% 55% at 50% 30%, rgba(120, 140, 175, .22), transparent 70%),
    radial-gradient(ellipse 120% 70% at 50% 110%, rgba(0, 0, 0, .55), transparent 60%),
    #0d1320;
  border-radius: 6px 3px 3px 6px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .9);
}
.page.backcover::after { right: 0; left: auto; width: 5%; background: linear-gradient(to left, rgba(0, 0, 0, .45), transparent); }
.bc-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8% 12%;
  text-align: center;
}
.bc-photo {
  margin-top: auto;
  width: 52%;
  aspect-ratio: 1;
  border-radius: 50%;
  padding: 4px;
  background: linear-gradient(145deg, #d8bd84, #8a6a37 60%, #d8bd84);
  box-shadow: 0 12px 30px -8px rgba(0, 0, 0, .8);
}
.bc-photo img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: 44% 36%;
  transform: scale(1.001);
}
.bc-name {
  margin: 1.1em 0 0;
  font-weight: 400;
  font-size: 1.55em;
  letter-spacing: .28em;
  text-indent: .28em;
  text-transform: uppercase;
}
.bc-years { margin: .25em 0 0; font-size: .85em; letter-spacing: .3em; color: #c8a96a; }
.bc-quote { margin: 1.6em 0 0; padding: 0; }
.bc-quote p { margin: 0; font-style: italic; font-size: 1.05em; line-height: 1.45; color: #d9cfba; }
.bc-quote p::before, .bc-quote p::after { color: #c8a96a; }
.bc-quote p::before { content: "“"; }
.bc-quote p::after { content: "”"; }
.bc-quote cite { display: block; margin-top: .5em; font-size: .7em; letter-spacing: .14em; text-transform: uppercase; font-style: normal; color: #8f97a6; }
.bc-note { margin: auto 0 0; font-size: .66em; letter-spacing: .22em; text-transform: uppercase; color: #7d8696; }

/* ---------- Table of contents ---------- */

.toc-head { margin: 0 0 .9em; text-align: center; font-weight: 400; font-size: 1.4em; letter-spacing: .06em; }
.toc-section {
  margin: .8em 0 .35em;
  font-size: .72em;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--accent);
}
.toc-section:first-child { margin-top: 0; }
.toc-year {
  margin: .5em 0 .1em;
  font-size: .78em;
  font-style: italic;
  color: var(--ink-soft);
  font-variant-numeric: oldstyle-nums;
}
.toc-section + .toc-year { margin-top: 0; }
.toc-item {
  display: flex;
  align-items: baseline;
  gap: .4em;
  padding: .05em 0;
  font-size: .86em;
  line-height: 1.35;
  cursor: pointer;
  color: inherit;
  text-decoration: none;
}
.toc-item:hover .toc-title { color: var(--accent); }
.toc-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color .2s; }
.toc-title.untitled { font-style: italic; }
.toc-dots { flex: 1; min-width: 1em; border-bottom: 1px dotted var(--rule); transform: translateY(-.3em); }
.toc-num { font-variant-numeric: oldstyle-nums; color: var(--ink-soft); }

/* ---------- Poems ---------- */

.poem-head { text-align: center; margin-top: .4em; }
.poem-title {
  margin: 0;
  font-weight: 500;
  font-size: 1.32em;
  line-height: 1.2;
  letter-spacing: .01em;
  text-wrap: balance;
}
.poem-title.untitled { letter-spacing: .5em; text-indent: .5em; color: var(--ink-soft); font-weight: 400; }
.epigraph {
  margin: .5em auto 0;
  max-width: 90%;
  font-style: italic;
  font-size: .8em;
  line-height: 1.35;
  color: var(--ink-soft);
}
.cont-title {
  margin-bottom: 1em;
  text-align: center;
  font-size: .72em;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.cont-title span { text-transform: none; font-style: italic; letter-spacing: .04em; }

.poem-text { width: fit-content; max-width: 100%; margin: 0 auto; }
.stanza { margin-bottom: .85em; }
.stanza:last-child { margin-bottom: 0; }
.line { padding-left: 1.3em; text-indent: -1.3em; overflow-wrap: anywhere; }
.line.acro {
  margin-top: .45em;
  font-size: 1.15em;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.2;
}
.line.acro:first-child { margin-top: 0; }
.poem.tight { line-height: 1.3; }
.poem.tight .poem-head { margin-top: 0; }
.poem.tight .orn { margin-bottom: .7em; }
.poem.tight .stanza { margin-bottom: .55em; }
.poem.tight .poem-foot { margin-top: .6em; }
.poem-foot {
  margin-top: 1.2em;
  text-align: right;
  font-style: italic;
  font-size: .78em;
  color: var(--ink-soft);
}

/* ---------- Cover call-to-action ---------- */

.cover-cta {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 64px;
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 31;
  transition: opacity .4s ease;
}
body:not(.is-closed) .cover-cta { opacity: 0; pointer-events: none; }
.cta {
  border: 1px solid rgba(201, 207, 216, .45);
  background: rgba(201, 207, 216, .06);
  color: var(--chrome);
  padding: 9px 26px;
  border-radius: 999px;
  font-size: 16px;
  letter-spacing: .12em;
  transition: background .25s, border-color .25s;
}
.cta:hover { background: rgba(201, 207, 216, .14); border-color: rgba(201, 207, 216, .8); }
.cta.ghost { border-color: transparent; background: transparent; color: var(--chrome-dim); font-style: italic; letter-spacing: .04em; }
.cta.ghost:hover { color: var(--chrome); background: transparent; }

.book.closed .half.right { cursor: pointer; }
.book.closed .half.right .page.cover { transition: transform .5s ease, box-shadow .5s ease; transform-origin: left center; }
.book.closed .half.right:hover .page.cover { transform: perspective(1600px) rotateY(-4deg); }

/* ---------- Drawer ---------- */

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(380px, 88vw);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
  background: #10151e;
  border-right: 1px solid rgba(255, 255, 255, .06);
  box-shadow: 20px 0 60px rgba(0, 0, 0, .5);
  transform: translateX(-105%);
  transition: transform .35s cubic-bezier(.3, .7, .2, 1);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2 { margin: 0; font-weight: 400; font-size: 22px; letter-spacing: .06em; }
#search {
  margin: 12px 0 10px;
  width: 100%;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .1);
  background: rgba(255, 255, 255, .04);
  color: var(--chrome);
  font: inherit;
  font-size: 15px;
  outline: none;
}
#search:focus { border-color: rgba(255, 255, 255, .3); }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tab {
  flex: 1;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  background: none;
  padding: 6px 0;
  color: var(--chrome-dim);
  font-size: 14px;
  letter-spacing: .06em;
}
.tab.active { color: var(--chrome); border-bottom-color: var(--chrome); }

.drawer-list {
  flex: 1;
  overflow-y: auto;
  margin: 0 -8px;
  padding: 0 8px;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .15) transparent;
}
.drawer-list .sec {
  margin: 14px 0 4px;
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: #a08766;
}
.drawer-list .yr {
  margin: 10px 0 2px;
  font-size: 14px;
  font-style: italic;
  color: var(--chrome-dim);
  font-variant-numeric: oldstyle-nums;
}
.drawer-list .sec + .yr { margin-top: 4px; }
.drawer-list .item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 10px;
  padding: 7px 8px;
  margin: 0 -8px;
  border-radius: 6px;
  cursor: pointer;
}
.drawer-list .item:hover, .drawer-list .item.current { background: rgba(255, 255, 255, .06); }
.drawer-list .item .t { font-size: 16px; line-height: 1.25; }
.drawer-list .item .t.untitled { font-style: italic; color: #aab2bf; }
.drawer-list .item .t .heart { color: #c96b5e; font-size: 12px; margin-left: 6px; }
.drawer-list .item .n { font-size: 13px; color: var(--chrome-dim); font-variant-numeric: oldstyle-nums; align-self: center; }
.drawer-list .item .m { grid-column: 1 / -1; font-size: 13px; color: var(--chrome-dim); font-style: italic; }
.drawer-list .item mark { background: rgba(194, 165, 125, .3); color: inherit; border-radius: 2px; }
.drawer-list .empty { padding: 30px 0; text-align: center; color: var(--chrome-dim); font-style: italic; }
.drawer-close-book {
  margin-top: 10px;
  border: 0;
  background: none;
  color: var(--chrome-dim);
  font-size: 14px;
  letter-spacing: .1em;
  padding: 8px;
}
.drawer-close-book:hover { color: var(--chrome); }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.scrim.open { opacity: 1; pointer-events: auto; }

/* ---------- Measuring host ---------- */

.measure-host {
  position: absolute;
  left: -9999px;
  top: 0;
  width: var(--pw);
  height: var(--ph);
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 600px) {
  .toolbar-title { font-size: 13px; }
  .page-label { min-width: 64px; font-size: 13px; }
  #btn-full { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  :root { --flip-ms: 0ms; }
  .drawer, .scrim { transition: none; }
}
