/* Reader: pages, curl, chrome, drawer, sheets. */
.reader {
  position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow: hidden;
  --dw: min(72vw, 420px);
  animation: rdIn .3s ease-out both;
}
.reader.instant { animation: none; }
.reader.closing { animation: rdOut .22s ease-in both; }
@keyframes rdIn { from { opacity: 0; } }
@keyframes rdOut { to { opacity: 0; } }
.rd-main { position: absolute; inset: 0; transition: transform .34s cubic-bezier(.2, .8, .2, 1); background: var(--bg); z-index: 2; }
.reader.drawer-open .rd-main { transform: translateX(var(--dw)); box-shadow: -1px 0 0 var(--line); }
.rd-stage { position: absolute; inset: 0; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; outline: none; cursor: default; }
.rd-book { position: absolute; top: 0; bottom: 0; left: 50%; width: var(--rd-W); margin-left: calc(var(--rd-W) / -2); overflow: hidden; }
.rd-page { position: absolute; inset: 0; background: var(--bg); overflow: hidden; contain: layout paint; }
.rd-safe-probe { position: fixed; top: 0; left: 0; width: 0; height: 0; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); visibility: hidden; pointer-events: none; }
.rd-measure { position: fixed; left: -20000px; top: 0; width: var(--rd-W); height: 100%; visibility: hidden; pointer-events: none; contain: strict; }

/* the paginated chapter */
.rd-chapter {
  position: absolute; left: var(--rd-M); top: var(--rd-T); width: var(--rd-w); height: var(--rd-h);
  column-width: var(--rd-w); column-gap: calc(var(--rd-M) * 2); column-fill: auto;
  font-family: var(--rd-font); font-size: var(--rd-size); line-height: var(--rd-lh); color: var(--text);
  font-kerning: normal; font-variant-ligatures: common-ligatures; text-rendering: optimizeLegibility;
  overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; text-align: left;
  orphans: 2; widows: 2;
}
.rd-chapter > :first-child, .rd-chapter section > :first-child { margin-top: 0; }
.rd-chapter p { margin: 0 0 .5em; text-indent: .8em; }
.rd-chapter h1, .rd-chapter h2, .rd-chapter h3, .rd-chapter h4, .rd-chapter h5, .rd-chapter h6 {
  font-family: var(--f-display); font-weight: 600; line-height: 1.25; margin: 0 0 .75em; break-after: avoid; text-indent: 0; letter-spacing: -.005em; hyphens: manual; -webkit-hyphens: manual;
}
.rd-chapter h1 { font-size: 1.5em; }
.rd-chapter h2 { font-size: 1.36em; }
.rd-chapter h3 { font-size: 1.2em; }
.rd-chapter h4, .rd-chapter h5, .rd-chapter h6 { font-size: 1.05em; }
.rd-chapter [data-c~="hgroup"] { margin: 0 0 1em; break-after: avoid; }
.rd-chapter [data-c~="hgroup"] > * { margin-bottom: .35em; }
.rd-chapter img { display: block; max-width: 100%; max-height: calc(var(--rd-h) - 2em); height: auto; width: auto; margin: 0 auto .9em; break-inside: avoid; object-fit: contain; border-radius: 2px; }
.rd-chapter [data-c~="svg-image"] { max-height: var(--rd-h); }
.rd-chapter figure { margin: 0 0 1em; break-inside: avoid; }
.rd-chapter figcaption { font-size: .85em; color: var(--text-muted); text-align: center; }
.rd-chapter blockquote { margin: 0 0 .9em 1em; }
.rd-chapter [data-type~="epigraph"], .rd-chapter [data-c~="epigraph"] { font-style: italic; margin: 30% 0 1.2em; }
.rd-chapter [data-type~="z3998:verse"] p, .rd-chapter [data-c~="stanza"], .rd-chapter [data-c~="poem"] p { text-indent: 0; }
.rd-chapter [data-c~="i1"] { padding-left: 1em; }
.rd-chapter ul, .rd-chapter ol { padding-left: 1.4em; margin: 0 0 .8em; }
.rd-chapter li { margin-bottom: .25em; }
.rd-chapter hr { border: 0; border-top: 1px solid var(--line-strong); margin: 1.2em 20%; }
.rd-chapter table { border-collapse: collapse; width: 100%; max-width: 100%; table-layout: fixed; font-size: .88em; margin: 0 0 1em; break-inside: avoid; }
.rd-chapter td, .rd-chapter th { border-bottom: 1px solid var(--line); padding: .3em .4em; text-align: left; vertical-align: top; overflow-wrap: anywhere; word-break: break-word; min-width: 0; }
.rd-chapter pre { white-space: pre-wrap; font-size: .85em; }
.rd-chapter abbr { text-decoration: none; }
.rd-chapter a[data-href] { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; text-decoration-color: var(--faint); }
.rd-chapter [data-type~="noteref"] { font-size: .75em; vertical-align: super; line-height: 0; text-decoration: none; }
.rd-chapter [data-align="center"] { text-align: center; text-indent: 0; }
.rd-chapter [data-align="right"] { text-align: right; }
.rd-chapter sup, .rd-chapter sub { line-height: 0; }
.rd-chapter mark.rd-hit { background: var(--mark); color: inherit; border-radius: 2px; box-shadow: 0 0 0 2px var(--mark); }
/* Standard Ebooks front matter */
.rd-chapter [data-type~="titlepage"], .rd-chapter [data-type~="halftitlepage"] { text-align: center; }
.rd-chapter [data-type~="titlepage"] p, .rd-chapter [data-type~="imprint"] p, .rd-chapter [data-type~="colophon"] p, .rd-chapter [data-type~="copyright-page"] p { text-indent: .8em; }
.rd-chapter [data-type~="imprint"] img, .rd-chapter [data-type~="colophon"] img { max-width: 34%; }
/* FB2 */
.rd-chapter header[data-c~="title"] { margin: 0 0 1.1em; break-after: avoid; }
.rd-chapter header[data-c~="title"] h1 { margin: 0 0 .2em; }
.rd-chapter [data-c~="subtitle"] { font-size: 1.1em; text-align: center; margin: 1em 0 .6em; }
.rd-chapter [data-c~="text-author"] { text-align: right; font-style: italic; text-indent: 0; }
.rd-chapter [data-c~="annotation"] { font-size: .92em; color: var(--text-2); }
.rd-chapter [data-c~="notesBodyType"] { font-size: .9em; }
.rd-chapter [data-c~="empty-line"] { display: block; height: .6em; }
.rd-end { display: inline; }

/* cover page */
.rd-cover { position: absolute; left: 14px; right: 14px; top: max(calc(var(--rd-T) - 10px), 15%); bottom: max(15%, 96px); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.rd-cover img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.14), 0 10px 30px rgba(0,0,0,.12); display: block; }
.rd-cover .rd-plaque { height: 100%; width: auto; max-width: 100%; aspect-ratio: 2 / 3; border-radius: 12px; }
.rd-cover .rd-plaque .plaque-title { font-size: 9cqw; -webkit-line-clamp: 8; }
.rd-cover .rd-plaque .plaque-author { font-size: 4.2cqw; }
.rd-cover .rd-plaque .plaque-inner { padding: 18% 10% 14%; }

/* curl */
.rd-flap {
  position: absolute; top: 0; bottom: 0; left: 0; width: 0; z-index: 5; opacity: 0; pointer-events: none; will-change: transform, width;
  background: linear-gradient(to right, var(--flap-edge) 0%, var(--flap-mid) 55%, var(--flap-fold) 92%, var(--flap-mid) 100%);
  box-shadow: -10px 0 26px rgba(0, 0, 0, .16), -1px 0 0 rgba(0, 0, 0, .05);
}
.rd-shade { position: absolute; top: 0; bottom: 0; left: 0; width: 0; z-index: 4; opacity: 0; pointer-events: none; background: linear-gradient(to right, rgba(0,0,0,.16), rgba(0,0,0,0)); will-change: transform; }
:root[data-theme="dark"] .rd-shade { background: linear-gradient(to right, rgba(0,0,0,.5), rgba(0,0,0,0)); }
.rd-ribbon { position: absolute; top: 0; right: calc(var(--rd-M) - 4px); z-index: 6; color: var(--text); opacity: 0; transform: translateY(-8px); transition: opacity .2s, transform .2s; pointer-events: none; }
.rd-ribbon svg { width: 22px; height: 34px; }
.reader.bookmarked .rd-ribbon { opacity: .85; transform: translateY(0); }

/* chrome */
.rd-top, .rd-bottom { position: absolute; z-index: 10; left: max(calc(14px + var(--sal)), calc(50% - var(--rd-W) / 2 + 10px)); right: max(calc(14px + var(--sar)), calc(50% - var(--rd-W) / 2 + 10px)); display: flex; justify-content: space-between; transition: opacity .22s ease, visibility 0s linear .22s; opacity: 0; visibility: hidden; pointer-events: none; }
.reader.chrome-on .rd-top, .reader.chrome-on .rd-bottom { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity .22s ease, visibility 0s; }
.rd-top { top: calc(var(--sat) + 14px); }
.rd-bottom { bottom: calc(var(--sab) + 12px); align-items: flex-end; gap: 12px; }
.rd-btn { width: 46px; height: 46px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--text); background: var(--bg-raised); box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 3px 12px rgba(0,0,0,.06); }
.rd-btn:active { transform: scale(.95); }
.rd-title-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; padding: 0 0 12px 8px; color: var(--text-muted); font-size: 15px; }
.rd-book-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.rd-pct { color: var(--text-muted); font-size: 13px; font-variant-numeric: tabular-nums; flex: none; }
.rd-bottom-actions { display: flex; flex-direction: column; gap: 12px; align-items: center; flex: none; }
.rd-more { background: transparent; box-shadow: none; }
.rd-counter { position: absolute; left: 0; right: 0; bottom: calc(var(--sab) + 26px); text-align: center; font-family: var(--f-text); font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; pointer-events: none; transition: opacity .2s; z-index: 7; }
.reader.chrome-on .rd-counter { opacity: 0; }
.reader.tts-on .rd-play { visibility: hidden; }
.rd-drawer-close { position: absolute; inset: 0; z-index: 20; display: none; background: transparent; }
.reader.drawer-open .rd-drawer-close { display: block; }

/* contents drawer */
.rd-drawer { position: absolute; z-index: 1; top: 0; bottom: 0; left: 0; width: var(--dw); overflow-y: auto; overscroll-behavior: contain; background: var(--bg); padding: calc(var(--sat) + 44px) 18px calc(var(--sab) + 30px) calc(22px + var(--sal)); visibility: hidden; transition: visibility 0s .34s; }
.reader.drawer-open .rd-drawer { visibility: visible; transition: none; }
.drawer-title { font-family: var(--f-display); font-weight: 600; font-size: 28px; line-height: 1.18; margin: 0; overflow-wrap: anywhere; }
.drawer-meta { margin: 8px 0 0; color: var(--text-muted); font-size: 15px; }
.drawer-switch { display: inline-flex; align-items: baseline; gap: 6px; margin: 34px 0 14px; font-family: var(--f-display); font-size: 26px; font-weight: 500; min-height: 44px; }
.drawer-switch .ico { color: var(--muted); transform: translateY(-2px); }
.toc { list-style: none; margin: 0; padding: 0; }
.toc li { border-right: 2px solid var(--line); padding-right: 14px; }
.toc-item { display: block; width: 100%; text-align: left; font-size: 19px; line-height: 1.3; padding: 12px 12px; border-radius: 11px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toc-item.toc-future { color: var(--text-muted); }
.toc-item.toc-current { background: var(--surface-2); font-weight: 500; }
.toc-item:disabled { color: var(--faint); }
.ann-list { list-style: none; margin: 0; padding: 0; }
.ann { display: flex; align-items: flex-start; gap: 4px; border-bottom: 1px solid var(--line); }
.ann-main { flex: 1; min-width: 0; text-align: left; padding: 12px 0; display: flex; flex-direction: column; gap: 4px; }
.ann-chapter { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.ann-text { font-size: 17px; color: var(--text); overflow-wrap: anywhere; }
.ann-snippet { font-family: var(--f-text); font-size: 14px; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ann-actions { display: flex; padding-top: 6px; }

/* read aloud */
.rd-tts { position: absolute; z-index: 11; left: 50%; bottom: calc(var(--sab) + 52px); transform: translateX(-50%); display: flex; align-items: center; gap: 6px; padding: 6px 16px 6px 8px; border-radius: 999px; background: var(--bg-raised); border: 1px solid var(--line); box-shadow: 0 4px 20px rgba(0,0,0,.08); max-width: calc(100vw - 24px); }
.tts-btn { width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--text); }
.tts-rates { display: flex; align-items: center; gap: 0; margin-left: 4px; }
.tts-dot { width: 18px; height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.tts-dot::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--line-strong); transition: transform .15s; }
.tts-dot[aria-checked="true"]::after { background: var(--text); transform: scale(1.6); }
.tts-rate { font-family: var(--f-text); font-size: 14px; color: var(--text-muted); min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; }

/* fly-in ghost */
.fly-ghost { position: fixed !important; z-index: 70; margin: 0 !important; transform-origin: 0 0; pointer-events: none; border-radius: 3px; }

/* reading settings & reader sheets */
.reading-sheet .sheet-scroll { padding-bottom: calc(26px + var(--sab) * .6); }
.rs-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.rs-row.col { flex-direction: column; align-items: stretch; gap: 10px; }
.rs-row:last-child { border-bottom: 0; }
.rs-label { font-size: 16px; color: var(--text-muted); }
.stepper { display: flex; align-items: center; gap: 6px; background: var(--surface); border-radius: 14px; padding: 4px; }
.step-btn { width: 52px; height: 44px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center; }
.step-btn:not(:disabled):active { background: var(--surface-2); }
.step-btn:disabled { color: var(--faint); }
.aa { font-family: var(--f-display); line-height: 1; }
.aa.sm { font-size: 15px; } .aa.lg { font-size: 24px; }
.step-val { min-width: 34px; text-align: center; font-variant-numeric: tabular-nums; font-size: 17px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface); border-radius: 14px; padding: 4px; }
.seg-btn { min-height: 44px; border-radius: 11px; font-size: 16px; padding: 0 6px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg-btn[aria-checked="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.note-quote { margin: 0 0 14px; padding: 2px 0 2px 14px; border-left: 2px solid var(--line-strong); color: var(--text-muted); font-family: var(--f-text); font-size: 15px; }
.note-field { min-height: 150px; resize: vertical; line-height: 1.45; }
.search-form { margin: 0 0 10px; }
.search-status { color: var(--text-muted); font-size: 15px; margin: 4px 2px 8px; min-height: 1.2em; }
.search-results { list-style: none; margin: 0; padding: 0; }
.search-hit { display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: left; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hit-chapter { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.hit-text { font-family: var(--f-text); font-size: 16px; line-height: 1.45; color: var(--text-2); overflow-wrap: anywhere; }
.hit-text mark { background: var(--mark); color: var(--text); border-radius: 2px; }
.menu-reader { min-width: 240px; }

@media (min-width: 900px) {
  .reader { --dw: 400px; }
  .rd-cover { left: 40px; right: 40px; }
}
