/* ============================================================
   Reaper: a quiet reader that listens along.
   Palette: Mars dusk. Crimson for the Reds, gold for the Golds.
   ============================================================ */

:root {
  --bg: #F8F5F4;
  --bg-2: #EFE9E7;
  --surface: #FFFFFF;
  --ink: #241B1A;
  --ink-2: #5E5250;
  --ink-3: #8E8280;
  --line: #E3DBD8;
  --crimson: #A41E2B;
  --gold: #946F24;
  --pill: rgba(164, 30, 43, 0.13);
  --bar: rgba(248, 245, 244, 0.86);
  --shade: 36, 27, 26;

  --ui: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --serif: "Literata", "Iowan Old Style", Georgia, serif;
  --read-font: var(--serif);
  --read-size: 20px;
  --read-lh: 1.7;
  --measure: 34em;
  --gutter: 16px;
  --ease: cubic-bezier(.2, .7, .2, 1);

  color-scheme: light;
}

:root[data-theme="sepia"] {
  --bg: #F1E6D3;
  --bg-2: #E7D9C1;
  --surface: #F7EEDF;
  --ink: #3A2B1F;
  --ink-2: #6B5843;
  --ink-3: #97836B;
  --line: #DACAAF;
  --crimson: #962530;
  --gold: #85621E;
  --pill: rgba(150, 37, 48, 0.14);
  --bar: rgba(241, 230, 211, 0.88);
  --shade: 58, 43, 31;
}

:root[data-theme="dark"] {
  --bg: #1C1615;
  --bg-2: #261E1C;
  --surface: #2A2120;
  --ink: #E9E0DA;
  --ink-2: #B3A6A0;
  --ink-3: #807370;
  --line: #3A2F2C;
  --crimson: #E0505A;
  --gold: #D6B16C;
  --pill: rgba(224, 80, 90, 0.26);
  --bar: rgba(28, 22, 21, 0.86);
  --shade: 0, 0, 0;
  color-scheme: dark;
}

:root[data-theme="oled"] {
  --bg: #000000;
  --bg-2: #120E0D;
  --surface: #171211;
  --ink: #D6CEC8;
  --ink-2: #9E928C;
  --ink-3: #6A5F5A;
  --line: #2A211F;
  --crimson: #E0505A;
  --gold: #CDA862;
  --pill: rgba(224, 80, 90, 0.3);
  --bar: rgba(0, 0, 0, 0.84);
  --shade: 0, 0, 0;
  color-scheme: dark;
}

:root[data-font="sans"] { --read-font: var(--ui); }

* { box-sizing: border-box; }
html { overflow-anchor: none; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  transition: background-color .35s var(--ease), color .35s var(--ease);
  min-height: 100vh;
}
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

.ibtn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 999px;
  color: var(--ink-2);
  transition: background-color .2s, color .2s;
}
.ibtn:hover { background: var(--bg-2); color: var(--ink); }
.ibtn svg { width: 22px; height: 22px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 20px 0 16px; border-radius: 999px;
  font-weight: 600; font-size: 15px;
  transition: background-color .2s, transform .15s var(--ease), color .2s;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--crimson); color: #FFF7F4; }
.btn-primary:hover { background: color-mix(in oklab, var(--crimson) 88%, black); }
.btn-quiet { background: var(--bg-2); color: var(--ink); }
.btn-quiet:hover { background: color-mix(in oklab, var(--bg-2) 80%, var(--ink) 8%); }

/* ============================================================
   Library
   ============================================================ */
.library {
  max-width: 1120px; margin: 0 auto;
  padding: 0 max(var(--gutter), env(safe-area-inset-left)) 160px;
}
.libbar { display: flex; align-items: center; height: 72px; }
.wordmark {
  display: inline-flex; align-items: center; gap: 10px;
  font: italic 500 24px/1 var(--serif);
  font-variation-settings: "opsz" 48;
  letter-spacing: -0.01em;
}
.wordmark svg { width: 22px; height: 22px; color: var(--crimson); }

.hero {
  position: relative; isolation: isolate;
  display: grid; grid-template-columns: minmax(180px, 300px) 1fr; gap: clamp(24px, 5vw, 64px);
  align-items: center;
  padding: clamp(24px, 5vw, 56px) 0 clamp(40px, 7vw, 80px);
}
.hero-glow {
  position: absolute; z-index: -1; top: 0; left: -8%; width: min(560px, 70%); aspect-ratio: 1;
  background-size: cover; background-position: center;
  filter: blur(70px) saturate(1.3);
  opacity: .28;
  mask-image: radial-gradient(closest-side, black 30%, transparent);
  -webkit-mask-image: radial-gradient(closest-side, black 30%, transparent);
  pointer-events: none;
}
:root[data-theme="dark"] .hero-glow, :root[data-theme="oled"] .hero-glow { opacity: .3; }
.hero-cover .art { border-radius: 10px; box-shadow: 0 2px 4px rgba(var(--shade), .12), 0 24px 60px -12px rgba(var(--shade), .45); }
.hero-kicker { margin: 0 0 6px; color: var(--crimson); font-weight: 600; font-size: 14px; }
.hero-title {
  margin: 0;
  font: 400 clamp(44px, 7vw, 84px)/0.95 var(--serif);
  font-variation-settings: "opsz" 72;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.hero-author { margin: 12px 0 0; color: var(--ink-2); font-size: 16px; }
.hero-chapter { margin: 22px 0 0; font: italic 400 19px/1.35 var(--serif); color: var(--ink); }
.hero-prog { display: flex; align-items: center; gap: 12px; margin-top: 14px; color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.hero-prog .bar { flex: 0 1 220px; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.hero-prog .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--crimson), var(--gold)); border-radius: inherit; }
.hero-left { color: var(--ink-3); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.hero-empty { grid-column: 1 / -1; display: flex; gap: 14px; align-items: center; color: var(--ink-2); padding: 40px 0; }
.hero-empty svg { width: 28px; height: 28px; color: var(--crimson); flex: none; }

.shelf-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; padding-bottom: 20px; border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.shelf-head h2 { margin: 0; font: 500 22px/1.2 var(--serif); font-variation-settings: "opsz" 32; letter-spacing: -0.01em; }
.build-status { margin: 0; font-size: 13px; color: var(--ink-3); display: flex; align-items: center; gap: 8px; }
.build-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .25; } }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 40px 28px; }
.tile { display: flex; flex-direction: column; min-width: 0; }
.tile .art { border-radius: 8px; box-shadow: 0 1px 2px rgba(var(--shade), .12), 0 10px 28px -10px rgba(var(--shade), .35); transition: transform .3s var(--ease), box-shadow .3s var(--ease); }
.tile:hover .art { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(var(--shade), .12), 0 18px 40px -12px rgba(var(--shade), .45); }
.tile.is-waiting { cursor: default; }
.tile.is-waiting .art { filter: grayscale(.7); opacity: .55; }
.tile.is-waiting:hover .art { transform: none; }
.tile-prog { height: 2px; margin-top: 10px; background: var(--line); border-radius: 2px; overflow: hidden; }
.tile-prog i { display: block; height: 100%; background: var(--crimson); }
.tile-prog.is-empty { background: transparent; } /* keeps titles aligned across a row */
.tile-meta { display: flex; flex-direction: column; gap: 2px; padding-top: 12px; }
.tile-title { font: 500 17px/1.25 var(--serif); font-variation-settings: "opsz" 24; }
.tile-sub { font-size: 13px; color: var(--ink-3); }
.tile-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; color: var(--gold);
  padding: 3px 9px 3px 7px; border-radius: 999px;
  background: color-mix(in oklab, var(--gold) 12%, transparent);
}
.tag svg { width: 13px; height: 13px; stroke-width: 2; }
.tag.is-pending { color: var(--ink-3); background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.tag-plain { color: var(--ink-2); background: var(--bg-2); }

.art { position: relative; aspect-ratio: 1; overflow: hidden; background: var(--bg-2); }
.art-bg { position: absolute; inset: -12%; width: 124%; height: 124%; max-width: none; object-fit: cover; filter: blur(22px) saturate(1.2); opacity: .9; }
.art-fg { position: relative; width: 100%; height: 100%; object-fit: contain; }
.art-empty { display: grid; place-items: center; color: var(--ink-3); }
.art-empty svg { width: 36px; height: 36px; opacity: .5; }

/* ============================================================
   Reader
   ============================================================ */
.rbar {
  position: fixed; z-index: 20; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 4px;
  height: 60px; padding: 0 max(8px, env(safe-area-inset-left)) 0 max(8px, env(safe-area-inset-right));
  padding-top: env(safe-area-inset-top);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(1.4) blur(18px);
  backdrop-filter: saturate(1.4) blur(18px);
  border-bottom: 1px solid color-mix(in oklab, var(--line) 60%, transparent);
  transition: transform .35s var(--ease), background-color .35s;
}
.rbar.tucked { transform: translateY(-100%); }
.rbar.tucked:focus-within { transform: none; } /* keyboard users can always see what they tabbed to */
.rbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; text-align: center; line-height: 1.25; }
.rb-book { font-size: 12px; color: var(--ink-3); }
.rb-chap { font: 500 15px/1.3 var(--serif); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aa { font: 500 18px/1 var(--serif); letter-spacing: -0.02em; }

.pages {
  position: relative;
  max-width: calc(var(--measure) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 104px var(--gutter) 220px;
  font-family: var(--read-font);
  font-size: var(--read-size);
  line-height: var(--read-lh);
  font-optical-sizing: auto;
  hyphens: auto; -webkit-hyphens: auto;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
}
:root[data-align="justify"] .pages { text-align: justify; }
.flow { position: relative; z-index: 1; }

/* the moving highlight behind the spoken word */
.pill {
  position: absolute; z-index: 0; top: 0; left: 0;
  width: 0; height: 0;
  border-radius: .32em;
  background: var(--pill);
  opacity: 0;
  pointer-events: none;
  /* positioned with `translate` (not `transform`) so the line-change pop can use `scale` around the pill's own centre */
  transition: translate .16s var(--ease), width .16s var(--ease), height .16s var(--ease), opacity .3s;
  will-change: translate;
}
.pill.on { opacity: 1; }

/* the sentence being narrated stays full ink; the rest settles back while playing */
.pages.has-audio.playing .flow { color: color-mix(in oklab, var(--ink) 64%, var(--bg)); }
.pages.has-audio.playing .flow .now { color: var(--ink); }
.flow span[data-w] { transition: color .5s ease; }
.pages.has-audio .flow span[data-w] { cursor: pointer; }
@media (hover: hover) {
  .pages.has-audio .flow span[data-w]:hover { text-decoration: underline; text-decoration-color: color-mix(in oklab, var(--crimson) 45%, transparent); text-decoration-thickness: 1.5px; text-underline-offset: .22em; }
}

/* book typography */
.sec { padding-bottom: 1em; }
.sec + .sec { margin-top: 3.5em; padding-top: 3.5em; position: relative; }
.sec + .sec::before {
  content: ""; position: absolute; top: 0; left: 50%; width: 18px; height: 18px; margin-left: -9px;
  background: var(--gold); opacity: .7;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3.6 14C4 7.6 9.8 2.6 19 3.2c-5.8 1.6-9.6 5.6-9.9 10.9z'/%3E%3Cpath d='M9.4 14 6 21' stroke='black' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3.6 14C4 7.6 9.8 2.6 19 3.2c-5.8 1.6-9.6 5.6-9.9 10.9z'/%3E%3Cpath d='M9.4 14 6 21' stroke='black' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.sec.no-audio { opacity: .82; }
.sec p { margin: 0; text-indent: 1.4em; }
.sec div > p:first-child, .sec > p:first-child, .sec h1 + p, .sec h2 + p, .sec h3 + p, .sec h4 + p, .sec hr + p, .sec .c + p, .sec blockquote + p { text-indent: 0; }
.sec .c { text-align: center; text-indent: 0; }
.sec .sc { font-variant: small-caps; letter-spacing: .03em; }
.sec p.c { margin: .3em 0; }
.sec p.c + p:not(.c) { margin-top: 1.6em; }

/* chapter openers: "1" / "Helldiver" style centered paragraphs */
.sec > p.c:first-child {
  font-size: 2.9em; line-height: 1; font-weight: 300;
  font-variation-settings: "opsz" 72;
  color: var(--crimson);
  margin: .2em 0 .25em;
}
.sec > p.c:first-child + p.c { font-size: 1.3em; font-style: italic; font-variation-settings: "opsz" 36; margin-bottom: 1.4em; }
.sec > p.c:first-child + p.c + p:not(.c)::first-line { font-variant: small-caps; letter-spacing: .02em; }

.sec h1, .sec h2, .sec h3, .sec h4, .sec h5, .sec h6 {
  text-align: center; font-weight: 400; line-height: 1.15;
  font-variation-settings: "opsz" 60;
  margin: 1.2em 0 1em; text-wrap: balance; hyphens: manual;
}
.sec h1 { font-size: 1.9em; }
.sec h2 { font-size: 1.55em; }
.sec h3 { font-size: 1.25em; font-style: italic; }
.sec h4, .sec h5, .sec h6 { font-size: 1.05em; font-weight: 600; }
.sec blockquote { margin: 1.2em 0 1.2em 1.4em; font-style: italic; }
.sec blockquote p { text-indent: 0; }
.sec hr { border: 0; margin: 1.8em auto; width: 40%; height: 1px; background: var(--line); }
.sec ul, .sec ol { padding-left: 1.4em; }
.sec li p { text-indent: 0; }
.sec em em { font-style: normal; }

.book-end { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 5em; color: var(--ink-3); font: italic 17px var(--serif); }
.book-end svg { width: 24px; height: 24px; color: var(--crimson); }

.follow {
  position: fixed; z-index: 25; left: 50%;
  bottom: calc(var(--player-h, 0px) + 16px);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px 10px 14px; border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font-weight: 600; font-size: 14px;
  box-shadow: 0 8px 28px -6px rgba(var(--shade), .5);
  transform: translateX(-50%);
  animation: rise .3s var(--ease);
}
.follow svg { width: 18px; height: 18px; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

.loading { display: grid; place-items: center; height: 70vh; }
.loading span { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--crimson); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-msg { display: grid; place-items: center; gap: 16px; height: 70vh; text-align: center; color: var(--ink-2); }

/* ============================================================
   Player bar
   ============================================================ */
.player {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  padding: 10px max(var(--gutter), env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  background: var(--bar);
  -webkit-backdrop-filter: saturate(1.4) blur(22px);
  backdrop-filter: saturate(1.4) blur(22px);
  border-top: 1px solid color-mix(in oklab, var(--line) 70%, transparent);
  transition: background-color .35s;
}
body.has-player { --player-h: 118px; }
.pl-scrub { display: flex; align-items: center; gap: 12px; max-width: 1120px; margin: 0 auto; }
.pl-time { flex: none; min-width: 58px; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.pl-rem { text-align: right; }

.scrub { position: relative; flex: 1; height: 22px; cursor: pointer; touch-action: none; display: flex; align-items: center; }
@media (pointer: coarse) { .scrub { height: 40px; margin: -9px 0; } .scrub-tip { bottom: 33px; } } /* a full finger's worth to grab, same look */
.scrub-track { position: relative; width: 100%; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; transition: height .15s var(--ease); }
.scrub:hover .scrub-track, .scrub.is-drag .scrub-track { height: 5px; }
.scrub-fill { position: absolute; inset: 0; transform-origin: left; transform: scaleX(0); background: linear-gradient(90deg, var(--crimson), color-mix(in oklab, var(--crimson) 55%, var(--gold))); }
.scrub-ticks { position: absolute; inset: 0; z-index: 1; }
.scrub-ticks i { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--bg); opacity: .8; }
.scrub-thumb {
  position: absolute; top: 50%; left: 0; width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px;
  border-radius: 50%; background: var(--crimson);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--crimson) 20%, transparent);
  transform: scale(.0); transition: transform .15s var(--ease);
}
.scrub:hover .scrub-thumb, .scrub.is-drag .scrub-thumb, .scrub:focus-visible .scrub-thumb { transform: scale(1); }
.scrub-tip {
  position: absolute; bottom: 24px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 10px; border-radius: 8px; white-space: nowrap; max-width: 260px;
  background: var(--ink); color: var(--bg); font-size: 12px; pointer-events: none;
}
.scrub-tip b { font-variant-numeric: tabular-nums; }
.scrub-tip span { opacity: .75; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }

.pl-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; max-width: 1120px; margin: 4px auto 0; }
.pl-now { display: flex; align-items: center; gap: 12px; min-width: 0; text-align: left; border-radius: 8px; justify-self: start; max-width: 100%; }
.pl-cover { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; flex: none; box-shadow: 0 2px 8px -2px rgba(var(--shade), .4); }
.pl-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.pl-chap { font: 500 14px/1.3 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-book { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-ctrls { display: flex; align-items: center; gap: 10px; }
.pl-skip { width: 44px; height: 44px; color: var(--ink); }
.pl-skip svg { width: 26px; height: 26px; }
.pl-play {
  display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%;
  background: var(--crimson); color: #FFF7F4;
  box-shadow: 0 6px 18px -6px color-mix(in oklab, var(--crimson) 70%, transparent);
  transition: transform .15s var(--ease), background-color .2s;
}
.pl-play:hover { background: color-mix(in oklab, var(--crimson) 88%, black); }
.pl-play:active { transform: scale(.94); }
.pl-play svg { width: 24px; height: 24px; }
.pl-opts { display: flex; justify-content: flex-end; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 34px; min-width: 44px; padding: 0 11px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums;
  transition: background-color .2s, color .2s;
}
.chip:hover { background: var(--bg-2); color: var(--ink); }
.chip svg { width: 17px; height: 17px; }
.chip.is-on { color: var(--gold); background: color-mix(in oklab, var(--gold) 13%, transparent); }
.pl-ed { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; line-height: 34px; }

/* ============================================================
   Drawer (contents)
   ============================================================ */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(var(--shade), .32); opacity: 0; transition: opacity .25s; }
.scrim.in { opacity: 1; }
.drawer {
  position: fixed; z-index: 41; top: 0; bottom: 0; left: 0;
  width: min(400px, 88vw);
  display: flex; flex-direction: column;
  background: var(--surface);
  box-shadow: 12px 0 40px -12px rgba(var(--shade), .35);
  transform: translateX(-102%);
  transition: transform .3s var(--ease);
  padding-top: env(safe-area-inset-top);
}
.drawer.in { transform: none; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 22px 16px 14px 24px; }
.drawer-head h2 { margin: 0; font: 500 24px/1.15 var(--serif); font-variation-settings: "opsz" 40; letter-spacing: -0.01em; }
.drawer-sub { margin: 4px 0 0; color: var(--ink-3); font-size: 13px; }
.toc-eds { margin: 0 24px 12px; }
.toc { list-style: none; margin: 0; padding: 4px 12px 40px; overflow-y: auto; flex: 1; overscroll-behavior: contain; border-top: 1px solid var(--line); }
.toc-item {
  display: flex; align-items: baseline; gap: 12px; width: 100%;
  padding: 10px 12px; border-radius: 8px; text-align: left;
  transition: background-color .15s;
}
.toc-item:hover { background: var(--bg-2); }
.toc-t { flex: 1; font: 400 16px/1.35 var(--serif); }
.toc-d { flex: none; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.toc-item.is-current { background: color-mix(in oklab, var(--crimson) 10%, transparent); }
.toc-item.is-current .toc-t { color: var(--crimson); font-weight: 500; }
.toc-item.no-audio .toc-t { color: var(--ink-3); }

/* ============================================================
   Popovers, segmented controls, toasts
   ============================================================ */
.pop {
  position: fixed; z-index: 50;
  min-width: 200px; padding: 8px;
  background: var(--surface); color: var(--ink);
  border-radius: 14px;
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--line) 80%, transparent), 0 18px 50px -12px rgba(var(--shade), .45);
  opacity: 0; transform: scale(.96);
  transition: opacity .16s, transform .18s var(--ease);
}
.pop.in { opacity: 1; transform: none; }
.pop-title { padding: 6px 10px 6px; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.menu { display: flex; flex-direction: column; }
.menu-item { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 9px 12px; border-radius: 8px; text-align: left; font-size: 14px; font-variant-numeric: tabular-nums; }
.menu-item:hover { background: var(--bg-2); }
.menu-item.is-active { color: var(--crimson); font-weight: 600; }
.menu-item.is-active::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.menu-hint { color: var(--ink-3); font-size: 12px; }

.pop-type { width: 320px; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.type-row.themes { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px 0; border-radius: 10px; font-size: 12px; color: var(--ink-2); }
.swatch:hover { background: var(--bg-2); }
.sw-dot { width: 32px; height: 32px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(128, 112, 108, .35); }
.sw-auto .sw-dot { background: linear-gradient(135deg, #F8F5F4 50%, #1C1615 50%); }
.sw-light .sw-dot { background: #F8F5F4; }
.sw-sepia .sw-dot { background: #F1E6D3; }
.sw-dark .sw-dot { background: #1C1615; }
.sw-oled .sw-dot { background: #000; }
.swatch[aria-checked="true"] { color: var(--ink); font-weight: 600; }
.swatch[aria-checked="true"] .sw-dot { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--crimson); }
.type-row.size { display: flex; align-items: center; gap: 8px; }
.ibtn.sm { width: 36px; height: 36px; }
.a-sm { font: 500 14px var(--serif); }
.a-lg { font: 500 22px var(--serif); }
.type-row input[type="range"] { flex: 1; accent-color: var(--crimson); }

.seg { display: flex; padding: 3px; border-radius: 10px; background: var(--bg-2); }
.seg button { flex: 1; height: 34px; padding: 0 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); white-space: nowrap; transition: background-color .2s, color .2s, box-shadow .2s; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(var(--shade), .14); }
.seg .f-serif { font-family: var(--serif); font-weight: 500; font-size: 14px; }

.toasts { position: fixed; z-index: 60; left: 50%; top: 16px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 500;
  background: var(--ink); color: var(--bg);
  box-shadow: 0 10px 30px -10px rgba(var(--shade), .5);
  opacity: 0; transform: translateY(-8px);
  transition: opacity .25s, transform .3s var(--ease);
}
.toast.in { opacity: 1; transform: none; }

/* ============================================================
   Small screens
   ============================================================ */
@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; gap: 24px; padding-top: 8px; }
  .hero-cover { width: min(240px, 64vw); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 16px; }
  .pages { padding-top: 88px; }
  .pl-row { grid-template-columns: auto 1fr auto; gap: 6px; }
  .pl-now .pl-text { display: none; }
  .pl-now { order: 0; }
  .pl-ctrls { justify-self: center; gap: 4px; }
  .pl-cover { width: 40px; height: 40px; }
  .pl-ed { display: none !important; }
  .chip { padding: 0 8px; min-width: 40px; height: 40px; }
  .pl-time { min-width: 44px; font-size: 11px; }
  body.has-player { --player-h: 112px; }
}
@media (max-width: 380px) {
  .pl-cover { display: none; }
  .pl-skip { width: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
.drawer:focus { outline: none; }

/* ============================================================
   Highlight preference
   ============================================================ */
:root[data-hl="sentence"] .pill, :root[data-hl="off"] .pill { display: none; }
:root[data-hl="off"] .pages.has-audio.playing .flow { color: var(--ink); }

/* search results / bookmarks land here */
.flow span.flash { animation: flash 2.2s ease-out; border-radius: .2em; }
@keyframes flash {
  0%, 35% { background: color-mix(in oklab, var(--gold) 38%, transparent); box-shadow: 0 0 0 .12em color-mix(in oklab, var(--gold) 38%, transparent); }
  100% { background: transparent; box-shadow: 0 0 0 .12em transparent; }
}
.pop-anim svg { animation: bm-pop .55s var(--ease); }
@keyframes bm-pop { 40% { transform: scale(1.25); color: var(--crimson); fill: color-mix(in oklab, var(--crimson) 30%, transparent); } }

/* ============================================================
   Drawer tabs + bookmarks
   ============================================================ */
.tabs { display: flex; gap: 6px; margin: 0 24px; border-bottom: 1px solid var(--line); }
.tabs button {
  padding: 10px 4px; margin-right: 14px; margin-bottom: -1px;
  font-size: 14px; font-weight: 600; color: var(--ink-3);
  border-bottom: 2px solid transparent; border-radius: 0;
  transition: color .2s, border-color .2s;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--crimson); }
.tab-n { margin-left: 2px; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.drawer .toc { border-top: 0; padding-top: 8px; }
.bms { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px 12px 40px; }
.bm-top { padding: 0 12px 10px; }
.bm-list { list-style: none; margin: 0; padding: 0; }
.bm { display: flex; align-items: flex-start; gap: 2px; border-radius: 10px; transition: background-color .15s; }
.bm:hover { background: var(--bg-2); }
.bm-go { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; text-align: left; border-radius: 10px; }
.bm-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bm-ch { font-weight: 600; color: var(--crimson); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-snip { font: italic 400 15px/1.45 var(--serif); color: var(--ink-2); }
.bm-del { margin-top: 6px; flex: none; opacity: .55; }
.bm-del svg { width: 16px; height: 16px; }
.bm:hover .bm-del, .bm-del:focus-visible { opacity: 1; }
.bm-empty { padding: 12px 12px; color: var(--ink-2); }
.bm-empty p { margin: 0 0 6px; font: 400 17px/1.4 var(--serif); }
.bm-empty .bm-hint { font: 14px/1.5 var(--ui); color: var(--ink-3); margin-bottom: 16px; }
.btn.sm { height: 36px; padding: 0 14px 0 12px; font-size: 14px; gap: 6px; }
.btn.sm svg { width: 16px; height: 16px; }

/* text panel extras */
.type-row.stack { display: flex; flex-direction: column; gap: 8px; }
.row-label { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.focus-row { display: flex; align-items: center; justify-content: flex-start; gap: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--crimson); }

/* player: time left in chapter */
.pl-sub { display: flex; gap: 10px; min-width: 0; align-items: baseline; }
.pl-sub .pl-book { flex: 0 1 auto; }
.pl-left { flex: none; font-size: 12px; color: var(--gold); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ============================================================
   Dialogs: search, shortcuts, finished
   ============================================================ */
.modal { position: fixed; inset: 0; z-index: 70; display: grid; justify-items: center; align-items: start; padding: max(9vh, 20px) 16px 24px; }
.modal-scrim { position: absolute; inset: 0; background: rgba(var(--shade), .36); opacity: 0; transition: opacity .2s; }
.modal.in .modal-scrim { opacity: 1; }
.modal-card {
  position: relative; width: min(640px, 100%); max-height: min(78vh, 760px);
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--ink); border-radius: 16px;
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--line) 80%, transparent), 0 30px 80px -20px rgba(var(--shade), .55);
  opacity: 0; transform: translateY(-8px) scale(.985);
  transition: opacity .18s, transform .22s var(--ease);
}
.modal.in .modal-card { opacity: 1; transform: none; }
.modal-card:focus { outline: none; }

kbd {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 7px;
  border-radius: 6px; background: var(--bg-2); color: var(--ink);
  box-shadow: inset 0 -2px 0 color-mix(in oklab, var(--line) 85%, var(--ink) 15%);
  font: 600 12px/1 var(--ui);
}

.search-box { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); color: var(--ink-3); }
.search-box svg { width: 20px; height: 20px; flex: none; }
.search-box input {
  flex: 1; min-width: 0; border: 0; background: none; color: var(--ink);
  font: 400 19px/1.3 var(--serif); outline: none;
}
.search-box input::placeholder { color: var(--ink-3); }
.search-status { margin: 0; padding: 10px 20px 2px; font-size: 12px; color: var(--ink-3); }
.search-status:empty { display: none; }
.results { list-style: none; margin: 0; padding: 6px 8px 10px; overflow-y: auto; overscroll-behavior: contain; }
.results:empty { display: none; }
.result { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border-radius: 10px; cursor: pointer; }
.result[aria-selected="true"] { background: var(--bg-2); }
.r-ch { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.result[aria-selected="true"] .r-ch { color: var(--crimson); }
.r-snip { font: 400 15px/1.5 var(--serif); color: var(--ink-2); }
.r-snip mark { background: var(--pill); color: var(--ink); border-radius: 3px; padding: 0 2px; }

.modal-sheet .modal-card { width: min(720px, 100%); padding: 20px 26px 26px; overflow-y: auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font: 500 24px/1.2 var(--serif); font-variation-settings: "opsz" 40; }
.sheet-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 40px; }
.sheet-cols h3 { margin: 18px 0 6px; font-size: 13px; font-weight: 600; color: var(--crimson); }
.sheet-cols dl { margin: 0; }
.sc-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.sc-row:last-child { border-bottom: 0; }
.sc-row dt { display: flex; align-items: center; flex: none; }
.sc-row dd { margin: 0; color: var(--ink-2); font-size: 14px; text-align: right; }
.plus { margin: 0 4px; font-size: 12px; color: var(--ink-3); }

.modal-finish { align-items: center; }
.modal-finish .modal-card { width: min(440px, 100%); }
.finish { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 34px 28px 28px; text-align: center; }
.finish > svg { width: 30px; height: 30px; color: var(--crimson); }
.finish h2 { margin: 0; font: 400 30px/1.15 var(--serif); font-variation-settings: "opsz" 60; letter-spacing: -0.01em; text-wrap: balance; }
.finish-sub { margin: 0; color: var(--ink-2); }
.finish-next { display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px; border-radius: 12px; background: var(--bg-2); text-align: left; }
.finish-next img { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; flex: none; }
.finish-next p { margin: 0; font-size: 13px; color: var(--ink-3); }
.finish-next .finish-title { font: 500 20px/1.2 var(--serif); color: var(--ink); }
.finish-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; }

@media (max-width: 720px) {
  .sheet-cols { grid-template-columns: 1fr; }
  .modal { padding-top: 12px; }
  .pl-left { display: none; }
}
@media (max-width: 480px) {
  .rb-focus { display: none; }
  .rb-cover { display: none; }
  .rbar .ibtn { width: 40px; height: 40px; }
  .rbar { gap: 0; }
  .rb-book { display: none; }
}

/* ============================================================
   Motion tokens, Hearth theme, paper grain
   ============================================================ */
:root {
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --grain-dark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .22 0 0 0 0 .14 0 0 0 0 .09 0 0 0 .1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --grain-light: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 .9 0 0 0 0 .76 0 0 0 .13 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --paper: var(--grain-dark);
  --glow-a: .22;
}
:root[data-theme="sepia"] { --glow-a: .26; }
:root[data-theme="dark"], :root[data-theme="oled"] { --paper: none; --glow-a: .32; }

/* Hearth: reading by the fire. Brown-black paper, candle-cream ink, ember accent. */
:root[data-theme="hearth"] {
  --bg: #1A120D;
  --bg-2: #261A12;
  --surface: #2B1E15;
  --ink: #F1E1C6;
  --ink-2: #CDB596;
  --ink-3: #937C63;
  --line: #3C2B1F;
  --crimson: #E9824C;
  --gold: #E7BA6A;
  --pill: rgba(233, 130, 76, 0.26);
  --bar: rgba(26, 18, 13, 0.84);
  --shade: 0, 0, 0;
  --paper: var(--grain-light);
  --glow-a: .34;
  color-scheme: dark;
}
:root[data-theme="hearth"] body {
  background-image: radial-gradient(110% 55% at 50% -8%, rgba(233, 130, 76, .13), transparent 70%), var(--grain-light);
  background-repeat: no-repeat, repeat;
}
body { background-image: var(--paper); }
.sw-hearth .sw-dot { background: radial-gradient(circle at 38% 32%, #6b3a1f, #1A120D 72%); }

/* themes crossfade via a view-transition snapshot */
html.theme-vt::view-transition-old(root), html.theme-vt::view-transition-new(root) { animation-duration: 460ms; animation-timing-function: ease; }

/* ============================================================
   Library: shared cover transition, tilt, entrance
   ============================================================ */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 300ms; animation-timing-function: cubic-bezier(.2, .8, .2, 1); }
::view-transition-group(book-cover) { animation-duration: 540ms; animation-timing-function: var(--ease-out); }
::view-transition-old(book-cover), ::view-transition-new(book-cover) { animation-duration: 540ms; height: 100%; }

.tile .art {
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(0);
  transition: transform .7s var(--spring-soft, var(--ease-out)), box-shadow .5s ease;
}
.tile:hover .art {
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(-6px);
  box-shadow: 0 3px 8px rgba(var(--shade), .14), 0 30px 60px -22px rgba(var(--c1, 120, 30, 30), .65);
}
.tile .art::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at var(--gx, 50%) var(--gy, 30%), rgba(255, 255, 255, .2), transparent 48%);
  opacity: 0; transition: opacity .4s ease;
}
.tile:hover .art::after { opacity: 1; }
.tile.is-waiting:hover .art { transform: none; box-shadow: none; }
.tile.rise { animation: rise-in .7s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 60ms + 60ms); }
@keyframes rise-in { from { opacity: 0; transform: translateY(16px); } }

.hero-glow { filter: none; opacity: 1; -webkit-mask-image: none; mask-image: none; inset: -30% -10% -20% -25%; width: auto; aspect-ratio: auto; top: -30%; left: -25%; }
.hero-glow i { position: absolute; border-radius: 50%; width: min(48vmax, 680px); aspect-ratio: 1; }
.hero-glow i:nth-child(1) { left: 0; top: 0; background: radial-gradient(closest-side, rgba(var(--c1, 178, 38, 46), var(--glow-a)), transparent); }
.hero-glow i:nth-child(2) { left: 24%; top: 18%; width: min(40vmax, 560px); background: radial-gradient(closest-side, rgba(var(--c2, 205, 150, 70), calc(var(--glow-a) * .8)), transparent); }
.hero-glow i:nth-child(3) { left: 4%; top: 46%; width: min(36vmax, 500px); background: radial-gradient(closest-side, rgba(var(--c3, 120, 40, 30), calc(var(--glow-a) * .7)), transparent); }

/* ============================================================
   Reader motion
   ============================================================ */
.rb-cover { width: 30px; height: 30px; flex: none; border-radius: 6px; object-fit: cover; margin: 0 2px 0 -2px; box-shadow: 0 2px 8px -2px rgba(var(--shade), .45); }
.pages { transition: transform .62s var(--ease-out), filter .62s var(--ease-out); }
.rbar { transition: transform .45s var(--ease-out), opacity .35s ease, background-color .35s; }
.player { transition: background-color .35s, transform .55s var(--ease-out); }

.sec + .sec::before { opacity: 0; transform: scale(.4) rotate(-35deg); transition: opacity .9s ease .1s, transform 1.1s var(--spring, var(--ease-out)) .1s; }
.sec + .sec.seen::before { opacity: .7; transform: none; }

.drawer { transition: transform var(--spring-d, 480ms) var(--spring, var(--ease-out)); }
.drawer::before { content: ""; position: absolute; top: 0; bottom: 0; right: 100%; width: 60px; background: var(--surface); }
.scrim { -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); transition: opacity .35s ease; }

.pop { transform: scale(.9); transition: opacity .16s ease, transform var(--spring-d, 300ms) var(--spring, var(--ease-out)); }

.toasts { top: auto; bottom: calc(var(--player-h, 0px) + 24px); flex-direction: column-reverse; }
.toast { transform: translateY(16px) scale(.96); transition: opacity .3s ease, transform var(--spring-d, 400ms) var(--spring, var(--ease-out)); }
.toast.in { transform: none; }
.toast.out { opacity: 0; transform: translateY(-12px) scale(.98); transition: opacity .25s ease, transform .35s var(--ease-out); }

.scrub.is-drag .scrub-thumb { transform: scale(1.35); }
.scrub-thumb { transition: transform .3s var(--spring, var(--ease-out)); }

/* play / pause crossfade-morph */
.pp { position: relative; display: grid; place-items: center; width: 24px; height: 24px; }
.pp > span { grid-area: 1 / 1; display: grid; place-items: center; transition: opacity .2s ease, transform .45s var(--spring, var(--ease-out)); }
.pp svg { width: 24px; height: 24px; }
.pp-pause { opacity: 0; transform: scale(.4) rotate(-90deg); }
.is-playing .pp-play { opacity: 0; transform: scale(.4) rotate(90deg); }
.is-playing .pp-pause { opacity: 1; transform: none; }

/* ============================================================
   Spotlight
   ============================================================ */
@property --fill { syntax: '<percentage>'; inherits: false; initial-value: 0%; }

body.spot-on .pages { transform: scale(.955); filter: blur(12px) brightness(.6) saturate(1.2); }
body.spot-on .rbar { opacity: 0; transform: translateY(-100%); pointer-events: none; }
body.spot-on .player { transform: translateY(110%); }
body.spot-on .follow { opacity: 0; pointer-events: none; }

.spot {
  --c1: 178, 38, 46; --c2: 205, 150, 70; --c3: 120, 40, 30;
  --s-ink: 244, 231, 212;
  position: fixed; inset: 0; z-index: 50;
  color: rgb(var(--s-ink));
  outline: none;
}
.spot > * { pointer-events: none; }
.spot > .spot-stage, .spot > .spot-pill { pointer-events: auto; }
.spot.leaving > * { pointer-events: none; }

.spot-backdrop {
  position: absolute; inset: 0;
  background: rgba(30, 15, 8, .5);
  opacity: 0; transition: opacity .62s var(--ease-out);
}
.spot-glow { position: absolute; inset: 0; overflow: hidden; opacity: 0; mix-blend-mode: screen; transition: opacity 1.4s ease .1s; }
.spot-glow i { position: absolute; width: 72vmax; aspect-ratio: 1; border-radius: 50%; will-change: transform; animation: drift-a 38s ease-in-out infinite alternate; }
.spot-glow .g1 { left: -24vmax; top: -22vmax; background: radial-gradient(closest-side, rgba(var(--c1), .55), transparent); }
.spot-glow .g2 { right: -30vmax; top: 6vmax; background: radial-gradient(closest-side, rgba(var(--c2), .42), transparent); animation-name: drift-b; animation-duration: 47s; }
.spot-glow .g3 { left: 0; bottom: -44vmax; background: radial-gradient(closest-side, rgba(var(--c3), .5), transparent); animation-name: drift-c; animation-duration: 55s; }
@keyframes drift-a { to { transform: translate(12vmax, 7vmax) scale(1.12); } }
@keyframes drift-b { to { transform: translate(-10vmax, 9vmax) scale(.92); } }
@keyframes drift-c { to { transform: translate(8vmax, -9vmax) scale(1.08); } }
.spot-vignette {
  position: absolute; inset: 0;
  background: radial-gradient(125% 95% at 50% 46%, transparent 36%, rgba(14, 7, 3, .5) 74%, rgba(8, 4, 2, .82));
  opacity: 0; transition: opacity .8s ease;
}
.spot-grain { position: absolute; inset: 0; background-image: var(--grain-light); mix-blend-mode: overlay; opacity: 0; transition: opacity 1s ease; }
.spot.on .spot-backdrop, .spot.on .spot-vignette { opacity: 1; }
.spot.on .spot-glow { opacity: .6; }
.spot.on .spot-grain { opacity: .55; }

.spot-chap {
  position: absolute; left: 16px; right: 16px; top: calc(env(safe-area-inset-top) + 28px);
  display: grid; justify-items: center; text-align: center;
  font: italic 400 15px/1.3 var(--serif); color: rgba(var(--s-ink), .5);
  opacity: 0; transition: opacity .6s ease .25s;
}
.spot.on .spot-chap { opacity: 1; }
.spot-chap span { grid-area: 1 / 1; opacity: 0; transform: translateY(5px); transition: opacity .8s ease, transform .8s var(--ease-out); }
.spot-chap span.on { opacity: 1; transform: none; }

.spot-stage {
  position: absolute; inset: 0; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 7%, #000 27%, #000 72%, transparent 93%);
  mask-image: linear-gradient(to bottom, transparent 7%, #000 27%, #000 72%, transparent 93%);
}
.spot-track {
  position: absolute; top: 0; left: 50%;
  font-family: var(--read-font); font-optical-sizing: auto;
  font-size: clamp(22px, calc(var(--read-size) * 1.45), 46px);
  line-height: 1.5; letter-spacing: -0.004em;
  width: min(34ch, calc(100vw - 48px));
  text-wrap: pretty; hyphens: manual;
  transform: translate3d(-50%, 0, 0);
  transition: transform var(--spring-soft-d, 800ms) var(--spring-soft, var(--ease-out));
  will-change: transform;
}
.su {
  margin: 0 0 .7em;
  opacity: 0; filter: blur(6px);
  transform: scale(.94); transform-origin: 0 50%;
  transition: opacity .75s ease, filter .75s ease, transform .95s var(--spring-soft, var(--ease-out));
}
.su.para-start { margin-top: 1.4em; }
.su.su-c { text-align: center; transform-origin: 50% 50%; }
.su.sec-start { margin-top: 2.6em; }
.su.near { opacity: .32; filter: blur(.7px); transform: scale(.955); }
.su.past.near { opacity: .24; }
.su.cur { opacity: 1; filter: none; transform: none; }
.sw {
  position: relative;
  display: inline-block; transform-origin: 0 0;
  color: rgba(var(--s-ink), .55);
  transition: color .45s ease; /* only colour: a transitioning text-shadow forces a layout every frame */
  cursor: pointer;
}
/* the ember glow behind the spoken word: its own box, so it can fade on the compositor */
.sw::before {
  content: ""; position: absolute; z-index: -1; inset: -.05em -.3em;
  background: radial-gradient(closest-side, rgba(255, 158, 82, .3), rgba(255, 158, 82, .12) 55%, transparent);
  opacity: 0; transition: opacity .6s ease;
  pointer-events: none;
}
.sw.now::before { opacity: 1; }
.su.past .sw, .sw.said { color: rgb(247, 230, 203); }
.sw.now {
  color: transparent;
  background-image: linear-gradient(90deg, #FFE6BF var(--fill), rgba(var(--s-ink), .55) var(--fill));
  -webkit-background-clip: text; background-clip: text;
  animation: word-fill var(--d, 300ms) linear forwards;
}
.spot:not(.playing) .sw.now { animation-play-state: paused; }
@keyframes word-fill { from { --fill: 0%; } to { --fill: 100%; } }
.spot.ro .sw, .spot.browsing .sw { color: rgb(var(--s-ink)); }
.spot.ro .sw { cursor: default; }
@media (hover: hover) {
  .spot:not(.ro) .sw:hover { text-decoration: underline 1px rgba(255, 200, 150, .4); text-underline-offset: .22em; }
}

.spot-pill {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 26px);
  display: flex; align-items: center; gap: 2px; padding: 6px;
  border-radius: 999px;
  background: rgba(44, 26, 16, .52);
  -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: inset 0 0 0 1px rgba(255, 214, 170, .1), 0 18px 50px -14px rgba(0, 0, 0, .7);
  color: rgb(var(--s-ink));
  opacity: 0; transform: translate(-50%, 16px);
  transition: opacity .45s ease, transform .6s var(--spring, var(--ease-out));
}
.spot.on .spot-pill { opacity: 1; transform: translate(-50%, 0); transition-delay: .25s; }
.spot.on.idle .spot-pill:not(:focus-within) { opacity: 0; transform: translate(-50%, 12px); transition-delay: 0s; }
.spot.idle { cursor: none; }
.sp-btn { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; color: rgba(var(--s-ink), .82); transition: background-color .2s, color .2s, transform .15s; }
.sp-btn:hover { background: rgba(255, 220, 180, .1); color: #FFF3E2; }
.sp-btn:active { transform: scale(.92); }
.sp-btn svg { width: 22px; height: 22px; }
.sp-play { width: 48px; height: 48px; background: rgba(255, 214, 170, .15); color: #FFF1DE; }
.sp-left { padding: 0 10px 0 8px; font-size: 12.5px; color: rgba(var(--s-ink), .62); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sp-left:empty { display: none; }
.spot :focus-visible { outline: 2px solid rgba(255, 200, 140, .85); outline-offset: 2px; }

@media (max-width: 600px) {
  .spot-track { width: calc(100vw - 40px); font-size: clamp(21px, calc(var(--read-size) * 1.3), 30px); }
  .spot-pill { bottom: calc(env(safe-area-inset-bottom) + 18px); }
}

@media (prefers-reduced-motion: reduce) {
  .spot-glow i { animation: none; }
  .tile.rise { animation: none; }
  .sw.now { animation: none; --fill: 100%; }
}

.spot.leaving .spot-chap, .spot.leaving .spot-pill { opacity: 0; transition: opacity .2s ease; transition-delay: 0s; }

/* light papers need a deeper dusk for cream stage text to read */
:root[data-theme="light"] body.spot-on .pages, :root[data-theme="sepia"] body.spot-on .pages { filter: blur(18px) brightness(.3) saturate(1.25) sepia(.3); }
:root[data-theme="light"] .spot-backdrop, :root[data-theme="sepia"] .spot-backdrop { background: rgba(30, 15, 8, .64); }
/* ...and the paper beyond the page column dims with it, so the stage sits in a warm dark room, not a grey haze */
:root[data-theme="light"] body.spot-on, :root[data-theme="sepia"] body.spot-on { background-color: #2B1D16; }

/* the library's ambient glow bleeds past the column; never let it widen the page */
.view { overflow-x: clip; }

/* the player bar rides above page transitions: it stays put while pages crossfade, and a cover
   flying back to its tile passes beneath it instead of landing on top and then snapping under */
.player { view-transition-name: player-bar; }
::view-transition-group(player-bar) { animation-duration: 300ms; }
