.epub-reader {
  --reader-paper: #fffdf8; --reader-ink: #242019;
  position: fixed; inset: 0; width: 100%; max-width: none; margin: 0; padding: 0;
  overflow: hidden; color: var(--reader-ink); background: var(--reader-paper);
  font-family: var(--ui);
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "notice" "book" "bottom";
}
.reader-view, .reader-view foliate-view { display: block; width: 100%; height: 100%; }
.reader-view { grid-area: book; min-height: 0; border: 0; background: transparent; }

/* Default: toolbars sit in the layout above and below the book. Full-screen
   mode (.reader-focus) lifts them out as overlays that auto-hide. */
.reader-chrome {
  position: relative; z-index: 20; width: 100%; color: var(--ink);
  background: color-mix(in srgb, var(--surface-raised) 94%, transparent);
  box-shadow: 0 1px 14px rgb(0 0 0 / 12%);
  transition: transform .18s, opacity .18s;
}
.reader-focus .reader-chrome { position: fixed; left: 0; }
.reader-topbar {
  grid-area: top; top: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center; min-height: 3.6rem; padding: .35rem clamp(.45rem, 2vw, 1.5rem);
}
.reader-topbar h1 {
  margin: 0; overflow: hidden; font: 400 clamp(1rem, 2vw, 1.3rem)/1.2 var(--heading);
  text-align: center; text-overflow: ellipsis; white-space: nowrap;
}
.reader-actions { justify-content: end; gap: .15rem; }
.reader-icon-button, .panel-close, .toast-close {
  min-width: 2.65rem; min-height: 2.65rem; padding: .45rem; border: 0;
  color: inherit; background: transparent;
}
.reader-icon-button, .panel-close, .toast-close { border-radius: var(--radius); }
.reader-icon-button:hover, .panel-close:hover, .toast-close:hover { background: var(--surface); }
.reader-icon-button[aria-expanded="true"] { background: var(--surface); }
.reader-icon-button svg {
  width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.reader-icon-button > span:last-child { display: none; }
.reader-bottombar { grid-area: bottom; bottom: 0; padding: .5rem clamp(.75rem, 3vw, 2rem) .65rem; }
.progress-row input { width: 100%; min-height: 1.4rem; accent-color: var(--clay); }
.reader-progress-meta {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: .5rem 1.2rem; color: var(--muted); font-size: .72rem;
}
.reader-progress-meta > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-focus:not(.chrome-visible) .reader-topbar {
  opacity: 0; pointer-events: none; transform: translateY(-105%);
}
.reader-focus:not(.chrome-visible) .reader-bottombar {
  opacity: 0; pointer-events: none; transform: translateY(105%);
}

.reader-warning {
  grid-area: notice; z-index: 19; display: flex; align-items: center; justify-content: center;
  gap: .75rem; padding: .3rem .7rem; border: 0; color: var(--ink); background: var(--warning-bg);
  font-size: .72rem;
}
.reader-warning button { min-width: 1.7rem; min-height: 1.7rem; padding: 0; }
.reader-focus .reader-warning {
  position: fixed; top: 3.6rem; left: 50%; width: min(100%, 42rem);
  justify-content: space-between; border-radius: 0 0 var(--radius) var(--radius);
  transform: translateX(-50%);
}
.reader-focus:not(.chrome-visible) .reader-warning {
  opacity: 0; pointer-events: none;
}
#focus-button .icon-exit-focus,
#focus-button[aria-pressed="true"] .icon-enter-focus { display: none; }
#focus-button[aria-pressed="true"] .icon-exit-focus { display: block; }

.reader-loading, .reader-error {
  position: fixed; z-index: 5; inset: 0; display: grid; place-content: center;
  text-align: center;
}
.reader-loading[hidden], .reader-error[hidden] { display: none; }
.reader-spinner {
  width: 2.4rem; height: 2.4rem; margin: auto; border: 3px solid var(--rule);
  border-top-color: var(--clay); border-radius: 50%; animation: spin .8s linear infinite;
}

.reader-panel {
  position: fixed; z-index: 30; top: 0; bottom: 0; width: min(90vw, 24rem);
  padding: 1rem; overflow-y: auto; color: var(--ink); background: var(--surface-raised);
  box-shadow: 0 0 2.5rem rgb(0 0 0 / 22%);
}
.reader-panel[hidden] { display: none; }
.reader-panel-left { left: 0; }
.reader-panel-right { right: 0; }
.reader-panel-heading { display: flex; align-items: center; justify-content: space-between; }
.reader-panel-heading h2 { margin: 0; font-size: var(--step-1); }
.reader-toc ul { margin: 0; padding: .35rem 0 .35rem .8rem; list-style: none; }
.reader-toc button {
  display: block; width: 100%; min-height: 2.2rem; padding: .35rem;
  border: 0; color: var(--ink); background: transparent; text-align: left;
}
.reader-toc button:hover, .reader-toc button.current { color: var(--clay-dark); background: var(--surface); }
.reader-toc button.current { border-left: .2rem solid var(--clay); font-weight: 750; }

.reader-search-form > div { display: flex; margin-block: 1rem; }
.panel-status { min-height: 1.5rem; color: var(--muted); }
.search-results { margin: 0; padding: 0; list-style: none; }
.search-results button {
  display: block; width: 100%; padding: .7rem .2rem;
  border-width: 1px 0 0; background: transparent; text-align: left;
}
.search-results strong, .search-results span { display: block; }
.search-results span { color: var(--muted); }

.display-settings { display: grid; gap: .5rem; }
.display-settings fieldset { margin: .5rem 0; padding: 0; border: 0; }
.setting-range {
  display: grid; grid-template-columns: auto 1fr auto; gap: .8rem; align-items: center;
}
.theme-options { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.theme-options label { display: flex; gap: .4rem; }
.theme-options input { width: auto; min-height: auto; accent-color: var(--clay); }

.reader-toast {
  position: fixed; z-index: 25; right: 1rem; bottom: 5.3rem;
  display: flex; align-items: center; gap: .55rem; padding: .55rem;
  border-radius: var(--radius); color: var(--ink); background: var(--surface-raised);
  box-shadow: var(--shadow);
}
.reader-toast[hidden] { display: none; }
.reader-toast button { min-height: 2rem; padding: .2rem; }
.reader-noscript { position: fixed; z-index: 50; inset: 1rem; }
.sr-only {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important; border: 0 !important;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 62rem) {
  .reader-icon-button { gap: .4rem; padding-inline: .65rem; }
  .reader-icon-button > span:last-child { display: inline; font-size: .72rem; }
}
@media (max-width: 42rem) {
  .reader-progress-meta { grid-template-columns: minmax(0, 1fr) auto; }
  #reader-time, #reader-scan-link { display: none; }
  .reader-focus .reader-warning { top: 3.2rem; }
  .reader-toast { right: .5rem; bottom: 4.7rem; left: .5rem; justify-content: center; }
}
@media (prefers-reduced-motion: no-preference) {
  .reader-panel-left:not([hidden]) { animation: panel-in-left 200ms var(--ease); }
  .reader-panel-right:not([hidden]) { animation: panel-in-right 200ms var(--ease); }
  .reader-toast:not([hidden]) { animation: toast-in 200ms var(--ease); }
}
@keyframes panel-in-left { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes panel-in-right { from { transform: translateX(100%); } to { transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(.5rem); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .reader-chrome { transition: none; }
  .reader-spinner { animation-duration: 1.5s; }
}
