/* ==========================================================================
   Reader
   ========================================================================== */
:root {
	--read-size: 21px;
	--read-leading: 1.75;
	--read-measure: 36em;
	--player-h: 136px;
	--bar-h: 64px;
	--hl-word: rgba(232, 184, 64, .55);
	--hl-solid: #f7d774;
	--hl-ink: #141a26;
	--hl-sentence: rgba(232, 184, 64, .2);
	--mark-gold: rgba(232, 184, 64, .42);
	--mark-blue: rgba(96, 165, 250, .38);
	--mark-green: rgba(74, 222, 128, .36);
	--mark-pink: rgba(244, 114, 182, .34);
}
:root[data-width="narrow"] { --read-measure: 31em; }
:root[data-width="wide"] { --read-measure: 44em; }
:root[data-font="sans"] { --f-read: "DM Sans", system-ui, sans-serif; }
:root[data-font="legible"] { --f-read: "Atkinson Hyperlegible", Verdana, sans-serif; }
:root[data-font="lexend"] { --f-read: "Lexend", Verdana, sans-serif; }
:root[data-theme="night"] { --hl-word: rgba(232, 184, 64, .42); --hl-sentence: rgba(232, 184, 64, .14); --hl-solid: #E8B840; --hl-ink: #111826; }
:root[data-theme="sepia"] { --hl-solid: #f2c95a; }
:root[data-theme="contrast"] { --hl-word: #ffd400; --hl-sentence: rgba(255, 212, 0, .25); --hl-solid: #ffd400; --hl-ink: #000; }

.page-reader { overflow-x: hidden; }

/* faint licensed-to watermark */
.watermark { position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: .055; background-repeat: repeat; }
:root[data-theme="night"] .watermark, :root[data-theme="contrast"] .watermark { opacity: .045; filter: invert(1); }

/* ---------- top bar ---------- */
.rbar {
	position: sticky; top: 0; z-index: 30; height: var(--bar-h);
	display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
	padding: 0 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
	backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.rbar__titles { min-width: 0; display: grid; text-align: center; }
.rbar__book { font: 700 17px var(--f-display); letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbar__chapter { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbar__tools { display: flex; gap: 2px; }
.rbar__progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; }
.rbar__progress span { display: block; height: 100%; width: 0; background: var(--gold); transition: width .3s; }
.icon-btn {
	width: 48px; height: 48px; display: inline-grid; place-items: center; border-radius: 12px;
	background: transparent; border: 0; cursor: pointer; color: var(--ink); text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn--text span { font: 700 20px var(--f-display); }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.icon-btn--sm { width: 38px; height: 38px; }
.icon-btn--sm svg { width: 20px; height: 20px; }
@media (max-width: 640px) {
	.rbar { grid-template-columns: auto 1fr; grid-template-rows: var(--bar-h) auto; height: auto; padding-bottom: 4px; }
	.rbar__tools { grid-column: 1 / -1; justify-content: space-around; }
	.rbar__titles { text-align: left; }
}

/* ---------- text ---------- */
.reader { position: relative; z-index: 2; padding: 28px 20px calc(var(--player-h) + 60px); outline: none; }
.edition-mode { display: flex; width: fit-content; margin: 0 auto 18px; padding: 4px; gap: 3px; border: 1px solid var(--line); border-radius: 12px; font: 600 13px var(--f-ui); }
.edition-mode[hidden] { display: none; }
.edition-mode button { border: 0; border-radius: 8px; padding: 8px 12px; color: var(--ink-2); background: transparent; cursor: pointer; }
.edition-mode button[aria-pressed="true"] { color: var(--ink); background: var(--gold); }
.edition-audio-only .chapter .b, .edition-listen .chapter .b { display: none; }
.edition-audio-only [data-panel="search"], .edition-audio-only [data-panel="display"], .edition-audio-only #btn-view { display: none !important; }
.edition-audio-only #p-follow, .edition-audio-only #follow-pill, .edition-audio-only .follow-shortcut { display: none !important; }
.edition-listen #btn-view, .edition-listen #pageview, .edition-listen #p-follow, .edition-listen #follow-pill,
.edition-listen [data-panel="search"], .edition-listen .follow-shortcut { display: none !important; }
.edition-listen .chapter__reading-time { display: none; }
.edition-ebook-only #wp-play, .edition-ebook-only #wp-tts, .edition-ebook-only #setting-audio, .edition-ebook-only #setting-autonext { display: none !important; }
.preview-files { max-width: var(--read-measure); margin: 0 auto 18px; display: flex; gap: 10px 20px; flex-wrap: wrap; justify-content: center; font: 600 13px var(--f-ui); }
.preview-files a { color: var(--gold-deep); text-decoration: underline; text-underline-offset: 3px; }
.chapter { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; max-width: var(--read-measure); margin: 0 auto; font-family: var(--f-read); font-size: var(--read-size); line-height: var(--read-leading); color: var(--ink); }
.chapter__loading { display: flex; align-items: center; gap: 12px; justify-content: center; padding: 80px 0; color: var(--muted); font-family: var(--f-ui); }
.chapter__head { text-align: center; padding: 30px 0 34px; margin-bottom: 26px; border-bottom: 1px solid var(--line); }
.chapter__label { font: 700 14px var(--f-ui); letter-spacing: .22em; text-transform: uppercase; color: var(--gold-deep); margin: 0 0 12px; }
:root[data-theme="night"] .chapter__label, :root[data-theme="contrast"] .chapter__label { color: var(--gold); }
.chapter__title { font: 700 clamp(30px, 4.6vw, 44px)/1.15 var(--f-display); margin: 0; }
.chapter__meta { font: 500 15px var(--f-ui); color: var(--muted); margin-top: 14px; }
.chapter .b { margin: 0 0 1em; position: relative; border-radius: 6px; transition: opacity .25s; }
.chapter .b-p { text-indent: 0; }
.chapter .b-dup { display: none; }
.chapter .b-h2 { font: 700 1.25em/1.3 var(--f-display); margin: 1.6em 0 .6em; }
.chapter .b-title { font: 700 1.5em/1.25 var(--f-display); margin: 1.4em 0 .6em; text-align: center; }
.chapter .b-label { font: 700 .7em var(--f-ui); letter-spacing: .2em; text-transform: uppercase; color: var(--muted); text-align: center; margin: 1.6em 0 .2em; }
.chapter .b-quote { font-style: italic; padding: .2em 0 .2em 1.1em; border-left: 3px solid var(--gold); color: var(--ink-2); }
.chapter .b.reading::before { content: ""; position: absolute; left: -18px; top: .25em; bottom: .25em; width: 4px; border-radius: 4px; background: var(--gold); }
.chapter.focus.has-reading .b:not(.reading) { opacity: .32; }
.w { border-radius: 4px; cursor: pointer; transition: background-color .12s; -webkit-tap-highlight-color: transparent; }
.w:hover { background: color-mix(in srgb, var(--gold) 18%, transparent); }
.hl-sentence .w.s-on { background: var(--hl-sentence); }
.chapter .w.on { background: var(--hl-solid); color: var(--hl-ink); box-shadow: 0 0 0 3px var(--hl-solid); border-radius: 4px; }
.w.m-gold { background: var(--mark-gold); }
.w.m-blue { background: var(--mark-blue); }
.w.m-green { background: var(--mark-green); }
.w.m-pink { background: var(--mark-pink); }
.w.has-note { text-decoration: underline dotted var(--gold-deep) 2px; text-underline-offset: 4px; }
.w.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 40% { background: var(--gold); color: #111; } 100% { background: transparent; } }
.chapter__end { margin: 48px 0 0; padding: 28px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-align: center; font-family: var(--f-ui); }
.chapter__end h3 { font: 700 26px var(--f-display); }
.licensed { margin-top: 30px; text-align: center; font: 13px var(--f-ui); color: var(--muted); }
.chapter ::selection { background: color-mix(in srgb, var(--gold) 45%, transparent); }

/* ---------- page view ---------- */
.pageview { max-width: 760px; margin: 0 auto; font-family: var(--f-ui); }
.pageview__nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.pageview__frame { position: relative; background: #fff; border-radius: 6px; box-shadow: var(--shadow); overflow: hidden; cursor: pointer; }
:root[data-theme="night"] .pageview__frame img { filter: invert(.88) hue-rotate(180deg); }
.pageview__frame img { width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.pageview__frame { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pageview__line { position: absolute; background: rgba(232, 184, 64, .14); border-radius: 4px; mix-blend-mode: multiply; transition: top .2s, left .2s, width .2s; display: none; pointer-events: none; }
.pageview__hl { position: absolute; background: rgba(232, 184, 64, .55); box-shadow: 0 0 0 2px rgba(185, 138, 20, .55); border-radius: 4px; mix-blend-mode: multiply; transition: left .12s, top .2s, width .12s; display: none; pointer-events: none; }
.pageview__mark { position: absolute; inset: 0; pointer-events: none; opacity: .09; background-repeat: repeat; background-size: 360px auto; }
:root[data-theme="night"] .pageview__line, :root[data-theme="night"] .pageview__hl { mix-blend-mode: normal; }

/* ---------- follow pill ---------- */
.follow-pill { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--player-h) + 18px); z-index: 35; display: inline-flex; align-items: center; gap: 8px; padding: 12px 20px; border-radius: 999px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: var(--shadow); cursor: pointer; }
.follow-pill svg { fill: none; stroke: currentColor; stroke-width: 2.4; }

/* ---------- player ---------- */
.player {
	position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; min-height: var(--player-h);
	background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 30px rgba(0, 0, 0, .08);
	padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
}
.player__scrub { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; gap: 10px; max-width: 980px; margin: 0 auto; }
.player__time { font: 600 14px var(--f-ui); color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
#p-seek { width: 100%; height: 32px; -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; }
#p-seek::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: linear-gradient(to right, var(--gold) var(--fill, 0%), var(--line) var(--fill, 0%)); }
#p-seek::-moz-range-track { height: 6px; border-radius: 999px; background: var(--line); }
#p-seek::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--gold); }
#p-seek::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
#p-seek::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); }
.player__row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; max-width: 980px; margin: 4px auto 0; }
.player__main { display: flex; align-items: center; gap: 6px; }
.player__side { display: flex; gap: 6px; }
.player__side--end { justify-content: flex-end; }
.play-btn { width: 68px; height: 68px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent); position: relative; }
.play-btn svg { width: 32px; height: 32px; fill: currentColor; }
.play-btn .i-pause, .play-btn .spinner { display: none; }
.playing .play-btn .i-play { display: none; }
.playing .play-btn .i-pause { display: block; }
.buffering .play-btn svg { display: none !important; }
.buffering .play-btn .spinner { display: inline-block; }
.pill-btn { min-height: 44px; padding: 6px 12px; display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; border: 2px solid var(--line); background: transparent; color: var(--ink); font-weight: 700; font-size: 15px; cursor: pointer; }
.pill-btn svg { fill: none; stroke: currentColor; stroke-width: 2; }
.pill-btn[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
@media (max-width: 640px) {
	:root { --player-h: 150px; }
	.player__row { grid-template-columns: 1fr 1fr; grid-template-areas: "main main" "a b"; row-gap: 6px; }
	.player__main { grid-area: main; justify-content: center; }
	.player__side { grid-area: a; }
	.player__side--end { grid-area: b; }
	.pill-btn span:not(#p-sleep-label) { display: none; }
}

/* ---------- player: minimize / narration off ---------- */
.player { transition: transform .28s ease, box-shadow .28s ease; }
.player__min { position: absolute; top: 8px; right: 12px; width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.player__min:hover { background: var(--surface-2); color: var(--ink); }
.player__min svg, .player-tab__open svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.player-min .player { transform: translateY(calc(100% + 8px)); box-shadow: none; }
.player-min.player-peeking .player { transform: none; box-shadow: 0 -8px 30px rgba(0, 0, 0, .12); }
.player-peek { position: fixed; left: 0; right: 0; bottom: 0; height: 28px; z-index: 39; display: none; }
.player-min .player-peek { display: block; }
.player-tab {
	position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 41;
	display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 999px;
	background: var(--surface); border: 1px solid var(--line); box-shadow: 0 8px 26px rgba(0, 0, 0, .14); transition: opacity .2s;
}
.player-min.player-peeking .player-tab { opacity: 0; pointer-events: none; }
.player-tab__play { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; }
.player-tab__play svg { fill: currentColor; width: 22px; height: 22px; }
.player-tab__play .i-pause { display: none; }
.playing .player-tab__play .i-play { display: none; }
.playing .player-tab__play .i-pause { display: block; }
.player-tab__time { font: 600 14px var(--f-ui); color: var(--muted); font-variant-numeric: tabular-nums; min-width: 42px; text-align: center; }
.player-tab__open { width: 46px; height: 46px; border-radius: 50%; border: 0; background: transparent; color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.player-tab__open:hover { background: var(--surface-2); }
.player-min .reader { padding-bottom: 110px; }
.player-min .follow-pill { bottom: 84px; }
.audio-off .player, .audio-off .player-tab, .audio-off .player-peek, .audio-off .follow-pill,
.audio-off #wp-play, .audio-off #wp-tts, .audio-off #setting-playerbar { display: none !important; }
.audio-off .reader { padding-bottom: 60px; }
@media (max-width: 640px) { .player-min .wordpop { bottom: 84px; } .audio-off .wordpop { bottom: 12px; } }

/* ---------- sheet (panels) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 15, 25, .38); z-index: 50; }
.sheet {
	position: fixed; z-index: 60; top: 0; right: 0; bottom: 0; width: min(440px, 100vw);
	background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow);
	display: flex; flex-direction: column; animation: sheet-in .2s ease-out;
}
@keyframes sheet-in { from { transform: translateX(24px); opacity: 0; } }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 22px; border-bottom: 1px solid var(--line); }
.sheet__head h2 { margin: 0; font: 700 24px var(--f-display); }
.sheet__body { overflow-y: auto; padding: 18px 22px 40px; flex: 1; }
@media (max-width: 640px) {
	.sheet { top: auto; left: 0; width: 100%; max-height: 86vh; border-radius: 22px 22px 0 0; border-left: 0; animation-name: sheet-up; }
	@keyframes sheet-up { from { transform: translateY(30px); opacity: 0; } }
}
.toc { list-style: none; padding: 0; margin: 0; counter-reset: toc; }
.toc li button { width: 100%; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 12px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; }
.toc li button:hover { background: var(--surface-2); }
.toc li[aria-current="true"] button { background: color-mix(in srgb, var(--gold) 18%, transparent); }
.toc__label { font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700; grid-column: 1 / -1; }
.toc__title { font: 600 19px/1.3 var(--f-display); }
.toc__time { color: var(--muted); font-size: 14px; align-self: center; white-space: nowrap; }
.toc__done { color: var(--ok); font-weight: 700; }
.search { display: flex; gap: 8px; }
.search input { min-height: 52px; }
.results, .notes { list-style: none; padding: 0; margin: 12px 0 0; }
.results li button, .notes li .note-jump { width: 100%; text-align: left; background: transparent; border: 0; padding: 14px 12px; border-radius: 12px; cursor: pointer; display: grid; gap: 4px; font-size: 16px; }
.results li button:hover, .notes li .note-jump:hover { background: var(--surface-2); }
.results mark { background: var(--hl-word); color: inherit; border-radius: 3px; padding: 0 2px; }
.res__ch { font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.notes li { display: grid; grid-template-columns: 1fr auto; align-items: start; border-bottom: 1px solid var(--line); }
.note__excerpt { font-family: var(--f-read); border-left: 4px solid var(--gold); padding-left: 10px; }
.note__excerpt[data-c="blue"] { border-color: #60a5fa; } .note__excerpt[data-c="green"] { border-color: #4ade80; } .note__excerpt[data-c="pink"] { border-color: #f472b6; }
.note__text { color: var(--ink-2); font-style: italic; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 2px solid var(--line); background: transparent; font-weight: 600; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.setting { margin: 0 0 24px; }
.setting__label { display: block; font-weight: 700; margin-bottom: 10px; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper output { min-width: 3ch; text-align: center; font-weight: 700; font-size: 20px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices button { min-height: 48px; padding: 8px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 600; }
.choices button[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.swatch--paper { background: #fff !important; color: #1f2633 !important; }
.swatch--sepia { background: #f1e7d3 !important; color: #3b2f22 !important; }
.swatch--night { background: #10151f !important; color: #e9ecf2 !important; }
.swatch--contrast { background: #000 !important; color: #ffd400 !important; }
.f-serif { font-family: "Literata", serif; } .f-sans { font-family: "DM Sans", sans-serif; } .f-legible { font-family: "Atkinson Hyperlegible", sans-serif; } .f-lexend { font-family: "Lexend", sans-serif; }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; }
.shortcuts dt { font-weight: 700; }
.shortcuts dd { margin: 0; color: var(--ink-2); }

/* ---------- word popover ---------- */
.wordpop {
	position: fixed; z-index: 70; width: min(380px, calc(100vw - 24px)); max-height: 70vh; overflow: auto;
	background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 18px;
	box-shadow: 0 18px 48px rgba(0, 0, 0, .22); padding: 14px; font-family: var(--f-ui);
}
.wordpop__head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.wordpop__word { font: 700 24px var(--f-display); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wordpop__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 6px 14px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; }
.chip:hover { border-color: var(--ink-2); }
.chip svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chip--sm { min-height: 36px; padding: 4px 12px; }
.wordpop__hl { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.dot { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.dot--gold { background: #e8b840; } .dot--blue { background: #60a5fa; } .dot--green { background: #4ade80; } .dot--pink { background: #f472b6; }
.wordpop__def { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 16px; }
.def__phon { color: var(--muted); margin: 0 0 6px; }
.def__pos { font-weight: 700; font-style: italic; color: var(--gold-deep); margin: 10px 0 4px; }
:root[data-theme="night"] .def__pos { color: var(--gold); }
.def__list { margin: 0; padding-left: 20px; }
.def__list li { margin-bottom: 6px; }
.def__eg { color: var(--muted); font-style: italic; }
.wordpop__noteform { display: grid; gap: 8px; margin-top: 12px; }
.wordpop__noteform textarea { min-height: 90px; font-size: 16px; }
@media (max-width: 640px) {
	.wordpop { left: 8px !important; right: 8px; top: auto !important; bottom: calc(var(--player-h) + 8px); width: auto; }
}
