/* ==========================================================================
   Novellion — online EPUB reader (/epub-reader/). Stand-alone, no site chrome.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body.nv-rd-body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #fdfaf3;
}

.nv-rd {
  --rd-bg: #fdfaf3;
  --rd-fg: #2e2620;
  --rd-soft: #6b5d4d;
  --rd-line: #e6dcc6;
  --rd-panel: #ffffff;
  --rd-accent: #8a5626;
  --rd-toc-w: 300px;
  --rd-bar-h: 48px;

  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--rd-bg);
  color: var(--rd-fg);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
}
.nv-rd[data-rtheme="sepia"] { --rd-bg: #f4ecd8; --rd-fg: #5b4636; --rd-soft: #8a7358; --rd-line: #e0d2b4; --rd-panel: #faf4e4; --rd-accent: #7a4a1e; }
.nv-rd[data-rtheme="gray"] { --rd-bg: #e4e4e4; --rd-fg: #262626; --rd-soft: #5e5e5e; --rd-line: #c4c4c4; --rd-panel: #efefef; --rd-accent: #6b4219; }
.nv-rd[data-rtheme="black"] { --rd-bg: #000000; --rd-fg: #cfcfcf; --rd-soft: #8e8e8e; --rd-line: #2a2a2a; --rd-panel: #151515; --rd-accent: #d9a566; }
.nv-rd[data-rtheme="night"] { --rd-bg: #1c1b19; --rd-fg: #d6d0c4; --rd-soft: #9a9386; --rd-line: #38352f; --rd-panel: #262420; --rd-accent: #d9a566; }

/* ---------- top bar ---------- */
.nv-rd__bar {
  flex: 0 0 var(--rd-bar-h);
  height: var(--rd-bar-h);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.5rem;
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--rd-line);
  background: var(--rd-bg);
  z-index: 30;
}
.nv-rd__bar[hidden] { display: none; }
.nv-rd__title {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--rd-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 0.5rem;
}
.nv-rd__btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--rd-fg);
  cursor: pointer;
  font-size: 1.6rem;
  line-height: 1;
}
.nv-rd__btn:hover { background: var(--rd-line); }
.nv-rd__btn:focus-visible,
.nv-rd__seg:focus-visible,
.nv-rd__menu-item:focus-visible,
.nv-rd__nav:focus-visible,
.nv-rd__toc-item:focus-visible { outline: 2px solid var(--rd-accent); outline-offset: 2px; }

/* ---------- pop-up panels (settings, menu) ---------- */
.nv-rd__panel {
  position: absolute;
  top: calc(var(--rd-bar-h) + env(safe-area-inset-top) + 4px);
  z-index: 40;
  background: var(--rd-panel);
  color: var(--rd-fg);
  border: 1px solid var(--rd-line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}
.nv-rd__panel[hidden] { display: none; }
.nv-rd__panel--settings { left: 8px; width: min(340px, calc(100vw - 16px)); padding: 0.4rem 0.9rem 0.7rem; }
.nv-rd__panel--menu { right: 8px; width: min(240px, calc(100vw - 16px)); padding: 0.35rem; display: flex; flex-direction: column; }
.nv-rd__menu-item {
  display: block;
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--rd-fg);
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.nv-rd__menu-item:hover { background: var(--rd-line); }

.nv-rd__row { padding: 0.55rem 0; border-bottom: 1px solid var(--rd-line); }
.nv-rd__row:last-child { border-bottom: 0; }
.nv-rd__row-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--rd-soft); margin-bottom: 0.35rem; }
.nv-rd__row-ctl { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.nv-rd__seg {
  flex: 1 1 0;
  min-width: 0;
  min-height: 38px;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--rd-line);
  border-radius: 8px;
  background: transparent;
  color: var(--rd-fg);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.nv-rd__seg.is-on { border-color: var(--rd-accent); box-shadow: inset 0 0 0 1px var(--rd-accent); font-weight: 600; }
.nv-rd__seg--a-small { font-size: 0.85rem; }
.nv-rd__seg--a-big { font-size: 1.35rem; }
.nv-rd__seg--light { background: #fdfaf3; color: #2e2620; }
.nv-rd__seg--sepia { background: #f4ecd8; color: #5b4636; }
.nv-rd__seg--night { background: #1c1b19; color: #d6d0c4; }
.nv-rd__seg--gray { background: #e4e4e4; color: #262626; }
.nv-rd__seg--black { background: #000000; color: #cfcfcf; }
.nv-rd__val { min-width: 3.2rem; text-align: center; font-size: 0.9rem; color: var(--rd-soft); }

/* ---------- contents: side column on desktop, left drawer on phones ---------- */
.nv-rd__toc {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(86vw, 340px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--rd-panel);
  border-right: 1px solid var(--rd-line);
  box-shadow: 8px 0 30px rgba(0, 0, 0, 0.22);
  animation: nv-rd-slide 0.18s ease-out;
}
.nv-rd__toc[hidden] { display: none; }
@keyframes nv-rd-slide { from { transform: translateX(-100%); } to { transform: none; } }
.nv-rd__toc-head {
  flex: 0 0 var(--rd-bar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) 0.5rem 0 1rem;
  border-bottom: 1px solid var(--rd-line);
  font-weight: 600;
}
.nv-rd__toc-list { flex: 1 1 auto; overflow-y: auto; padding: 0.4rem 0 1rem; -webkit-overflow-scrolling: touch; }
.nv-rd__toc-item {
  display: block;
  padding: 0.6rem 1rem;
  color: var(--rd-fg);
  text-decoration: none;
  font-size: 0.95rem;
  border-left: 3px solid transparent;
}
.nv-rd__toc-item:hover { background: var(--rd-line); }
.nv-rd__toc-item.is-current { border-left-color: var(--rd-accent); color: var(--rd-accent); font-weight: 600; }
.nv-rd__scrim { position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, 0.45); }
.nv-rd__scrim[hidden] { display: none; }

@media (min-width: 900px) {
  .nv-rd__toc {
    top: calc(var(--rd-bar-h) + env(safe-area-inset-top));
    width: var(--rd-toc-w);
    z-index: 20;
    box-shadow: none;
    animation: none;
  }
  .nv-rd__toc-head { display: none; }
  .nv-rd--toc .nv-rd__main,
  .nv-rd--toc .nv-rd__foot { margin-left: var(--rd-toc-w); }
}

/* ---------- reading area ---------- */
.nv-rd__main { position: relative; flex: 1 1 auto; min-height: 0; }
.nv-rd__stage { position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 100%; margin: 0 auto; }
.nv-rd:not(.nv-rd--open) .nv-rd__stage { display: none; }
.nv-rd__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 44px;
  height: 96px;
  border: 0;
  background: transparent;
  color: var(--rd-soft);
  font-size: 2.6rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.55;
}
.nv-rd__nav:hover { opacity: 1; background: var(--rd-line); }
.nv-rd__nav[hidden] { display: none; }
.nv-rd__nav--prev { left: 0; border-radius: 0 12px 12px 0; }
.nv-rd__nav--next { right: 0; border-radius: 12px 0 0 12px; }
@media (max-width: 600px) {
  .nv-rd__nav { width: 28px; height: 72px; font-size: 2rem; opacity: 0.4; }
}

.nv-rd__foot {
  flex: 0 0 auto;
  padding: 0 0 env(safe-area-inset-bottom);
  border-top: 1px solid var(--rd-line);
  background: var(--rd-bg);
}
.nv-rd__foot[hidden] { display: none; }
.nv-rd__progress { height: 3px; background: var(--rd-line); }
.nv-rd__progress span { display: block; height: 100%; width: 0; background: var(--rd-accent); transition: width 0.25s; }
.nv-rd__foot-text {
  min-height: 24px;
  padding: 3px 1rem;
  font-size: 0.75rem;
  color: var(--rd-soft);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- start screen ---------- */
.nv-rd__start {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  text-align: center;
}
.nv-rd__start[hidden] { display: none; }
.nv-rd__start h1 { margin: 0 0 1.2rem; font-family: Georgia, serif; font-weight: 600; font-size: 1.7rem; }
.nv-rd__drop {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: min(420px, 100%);
  padding: 2rem 1rem;
  border: 2px dashed var(--rd-line);
  border-radius: 16px;
  cursor: pointer;
  position: relative;
}
.nv-rd__drop:hover, .nv-rd__drop.is-drag { border-color: var(--rd-accent); background: var(--rd-panel); }
.nv-rd__drop input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.nv-rd__drop-main { font-size: 1.1rem; font-weight: 600; color: var(--rd-accent); }
.nv-rd__drop-sub { font-size: 0.85rem; color: var(--rd-soft); }
.nv-rd__note { max-width: 420px; margin: 1rem 0 0; font-size: 0.85rem; color: var(--rd-soft); }
.nv-rd__error { max-width: 420px; margin: 1rem 0 0; padding: 0.6rem 0.8rem; border-radius: 8px; background: #fbe9e7; color: #8c2a1c; font-size: 0.9rem; }
.nv-rd__error[hidden] { display: none; }
.nv-rd__home { color: var(--rd-soft); font-size: 0.9rem; text-decoration: none; }
.nv-rd__home:hover { color: var(--rd-accent); }
.nv-rd__loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--rd-bg);
  color: var(--rd-soft);
  z-index: 15;
}
.nv-rd__loading[hidden] { display: none; }

/* Picture-only pages (cover, full-page illustrations), drawn by the reader itself. */
.nv-rd__pic {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 2.75rem;
  background: var(--rd-bg);
}
.nv-rd__pic[hidden] { display: none; }
.nv-rd__pic img { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; }
@media (max-width: 600px) {
  .nv-rd__pic { padding: 1rem 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .nv-rd__toc { animation: none; }
  .nv-rd__progress span { transition: none; }
}


/* ---------- "Listen" (0.56.0) ---------- */
.nv-rd__btn--listen[hidden] { display: none; }
.nv-rd__btn--listen[aria-pressed="true"] { color: var(--rd-accent); }

.nv-tts {
  position: fixed;
  left: 50%;
  bottom: 0.75rem;
  transform: translateX(-50%);
  z-index: 60;
  width: min(640px, calc(100vw - 1.5rem));
  padding: 0.6rem 0.8rem;
  background: var(--rd-panel);
  color: var(--rd-fg);
  border: 1px solid var(--rd-line);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
  font-size: 0.9rem;
}
.nv-tts[hidden] { display: none; }
.nv-tts__row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.nv-tts__row--opts { margin-top: 0.5rem; gap: 0.6rem; }
.nv-tts__btn {
  min-width: 2.4rem; height: 2.4rem; border: 1px solid var(--rd-line); border-radius: 8px;
  background: transparent; color: inherit; font-size: 1.05rem; cursor: pointer;
}
.nv-tts__btn--main { min-width: 3rem; background: var(--rd-accent); border-color: var(--rd-accent); color: #fff; }
.nv-tts__status { margin-left: auto; color: var(--rd-soft); font-variant-numeric: tabular-nums; }
.nv-tts__resume {
  flex-basis: 100%; padding: 0.5rem 0.8rem; border: 0; border-radius: 8px;
  background: var(--rd-accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.nv-tts__resume[hidden] { display: none; }
.nv-tts__field { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.nv-tts__label { font-size: 0.72rem; color: var(--rd-soft); }
.nv-tts__select {
  max-width: 100%; padding: 0.3rem 0.4rem; border: 1px solid var(--rd-line); border-radius: 6px;
  background: var(--rd-bg); color: inherit; font: inherit;
}
.nv-tts__select--voice { width: 15rem; }
.nv-tts__hint { margin: 0.5rem 0 0; font-size: 0.8rem; color: var(--rd-soft); }
@media (max-width: 600px) {
  .nv-tts__select--voice { width: 100%; }
  .nv-tts__field:nth-child(2) { flex: 1 1 100%; order: 3; }
}
