/* EPUB layout and controls; shared controls keep their existing state owners. */
html:has(.reader-shell[data-current-format="ebook"]),
body:has(.reader-shell[data-current-format="ebook"]) { height:100%; overflow:hidden; overscroll-behavior:none; }
.reader-shell[data-current-format="ebook"] { height:100dvh; min-height:0; overflow:clip; }
body.is-tauri:not(.is-embedded) .reader-shell[data-current-format="ebook"] { height:calc(100dvh - var(--mac-window-bar-height, 0px)); }
.reader-shell[data-current-format="ebook"] .reader-main { display:flex; flex-direction:column; height:100%; min-height:0; overflow:clip; box-sizing:border-box; }
.reader-shell[data-current-format="ebook"] #reader-paper-wrap { display:flex; flex-direction:column; min-width:0; min-height:0; height:100%; padding:0; overflow:clip; box-sizing:border-box; }
.reader-shell[data-current-format="ebook"] #document-surface-toolbar { flex:0 0 auto; }
.reader-shell[data-current-format="ebook"] .ebook-viewer { flex:1 1 0; min-height:0; }
.ebook-toolbar,.ebook-search-results { flex-shrink:0; }
.reader-shell[data-current-format="ebook"].is-reader-layout-custom #reader-paper-wrap,
.reader-shell[data-current-format="ebook"] #reader-paper-wrap:has(.ebook-stage[data-flow="scrolled"]) { width:100%; max-width:none; }
.ebook-viewer { display:none; width:100%; min-width:0; overflow:hidden; background:var(--surface-1); container-type:inline-size; }
.ebook-viewer.is-active { display:flex; flex-direction:column; }
.ebook-toolbar { display:flex; align-items:center; justify-content:center; flex-wrap:wrap; gap:6px; width:max-content; max-width:calc(100% - 24px); align-self:center; margin:0 auto 10px; padding:6px; border:1px solid var(--nr-control-border,var(--border-subtle)); border-radius:12px; background:var(--nr-control-surface,var(--surface-2)); font:700 11px/1.2 var(--font-main); }
.ebook-toolbar > select { flex:0 1 190px; min-width:120px; width:190px; max-width:100%; }
.ebook-toolbar [data-ebook-progress] { flex:0 0 auto; min-width:0; padding:0 8px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; color:var(--text-muted); }
.ebook-flow-switch { display:flex; flex:0 0 auto; gap:2px; }
.ebook-toolbar .ebook-search { display:flex; flex:0 1 210px; width:210px; min-width:120px; gap:6px; }
.ebook-toolbar .ebook-search input { width:100%; min-width:0; flex:1; }
.ebook-toolbar :is(button,select,input),.ebook-search-result,.ebook-continuous-section button { height:32px; min-height:32px; padding:0 8px; border:1px solid var(--nr-control-border,var(--border-subtle)); border-radius:8px; background:var(--nr-control-surface,var(--surface-2)); color:var(--nr-control-text,var(--text-primary)); font:inherit; }
.ebook-toolbar button { cursor:pointer; white-space:nowrap; }
.ebook-toolbar button[aria-pressed="true"] { color:var(--accent-primary); border-color:var(--accent-primary); background:rgba(var(--accent-pr),var(--accent-pg),var(--accent-pb),.14); }
.ebook-toolbar :focus-visible,.ebook-page-turn:focus-visible { outline:2px solid var(--accent-primary); outline-offset:2px; }
.ebook-search-results { display:flex; overflow:auto; gap:6px; padding:0 12px; }
.ebook-search-results:empty { display:none; }
.ebook-search-result { height:auto; padding:8px; flex:0 0 260px; text-align:left; }
.ebook-stage { display:grid; grid-template-columns:40px minmax(0,1fr) 40px; align-items:stretch; min-height:0; flex:0 0 auto; position:relative; }
.ebook-stage foliate-view { display:block; grid-column:2; width:100%; height:100%; min-height:0; }
.ebook-page-turn { align-self:center; justify-self:center; width:34px; height:52px; border:1px solid var(--border-subtle); border-radius:10px; background:var(--surface-2); color:var(--text-primary); font:400 29px/1 var(--font-main); cursor:pointer; }
.ebook-stage[data-flow="scrolled"],.ebook-stage.is-text-fallback { grid-template-columns:minmax(0,1fr); }
.ebook-stage[data-flow="scrolled"] .ebook-page-turn,.ebook-stage foliate-view[hidden],.ebook-continuous[hidden] { display:none!important; }
.ebook-continuous { grid-column:1/-1; width:100%; height:100%; min-height:0; overflow:auto; overscroll-behavior:contain; overflow-anchor:none; }
.ebook-continuous-section { width:100%; }
.ebook-continuous-section iframe { display:block; width:100%; border:0; }
.ebook-continuous-section.is-load-error { display:flex; align-items:center; justify-content:center; padding:24px; }
.ebook-stage.is-text-fallback { overflow:auto; }
.ebook-text-fallback { padding:20px; white-space:pre-wrap; overflow-wrap:anywhere; color:var(--text-primary); line-height:1.8; }
.ebook-fallback-notice { padding:8px 16px; color:var(--text-muted); }
.ebook-loading,.ebook-error { display:grid; place-content:center; gap:10px; min-height:320px; padding:24px; text-align:center; }
body:has(.reader-shell[data-current-format="ebook"]) .site-footer-nr { display:none; }
@container (max-width:640px) { .ebook-toolbar { justify-content:flex-start; } .ebook-toolbar > select { flex:1 1 120px; } .ebook-toolbar .ebook-search { flex:1 1 180px; } }
@media (pointer:coarse) { .ebook-toolbar :is(button,select,input) { min-height:44px; height:44px; } }
@media (max-width:820px) {
 body.nextreader-analysis-owner-ai:has(.reader-shell[data-current-format="ebook"]) .ai-assistant-modal { inset:var(--nextreader-analysis-top) 0 0!important; width:100vw!important; max-width:100vw!important; height:calc(100dvh - var(--nextreader-analysis-top))!important; max-height:none!important; transform:none!important; }
}
@media (max-width:820px),(max-height:559px) { body:has(.reader-shell[data-current-format="ebook"]) .ai-analysis-mode-btn:not([hidden]) { display:inline-flex!important; } }
