:root {
  --reader-topbar-h: 50px;
  --reader-footer-h: 50px;

  --brand-purple: #6d28d9;
  --brand-purple-2: #8b5cf6;
  --brand-purple-3: #cbb8f7;
  --ink: rgba(38, 14, 71, 0.92);
  --ink-muted: rgba(38, 14, 71, 0.62);
}

@media (max-width: 768px) {
  :root {
    --reader-topbar-h: 46px;
    --reader-footer-h: 50px;
  }
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:
    radial-gradient(circle at 20% 10%, rgba(184, 179, 255, 0.22), transparent 45%),
    radial-gradient(circle at 80% 30%, rgba(122, 114, 242, 0.16), transparent 55%),
    #0b0b10;
}

.reader-shell {
  position: relative;
  width: min(980px, 96vw);
  height: min(820px, 96vh);
  min-height: 520px;
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.08);
  display: none;
  flex-direction: column;
}

.reader-shell.active {
  display: flex;
}

@media (max-width: 900px) {
  body {
    align-items: flex-start;
  }
  .reader-shell {
    width: 100vw;
    height: calc(var(--vh, 1vh) * 100);
    min-height: 0;
    border-radius: 0;
    border: 0;
    box-shadow: none;
  }
}

.reader-topbar {
  flex-shrink: 0;
}

.reader-footer {
  flex-shrink: 0;
}

.reader-stage {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: #f7f5fb;
}

/* Stage dim overlay (shown when dropdowns are open) */
.reader-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 22, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 20;
}

.reader-shell.is-lang-open .reader-stage::after,
.reader-shell.is-menu-open .reader-stage::after {
  opacity: 1;
}

.book-viewport {
  position: relative;
  background: transparent;
  display: flex;
  transition: opacity 0.3s ease;
}

.page-slot {
  position: relative;
  overflow: hidden;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(20, 10, 50, 0.12);
}

.page-slot + .page-slot {
  margin-left: 12px;
}

.page-slot.empty {
  background: transparent;
  box-shadow: none;
}

.page-slot img:not(.fx-img) {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.page-loading {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: linear-gradient(110deg, #f0ecf5 8%, #faf8ff 18%, #f0ecf5 33%);
  background-size: 200% 100%;
  animation: shimmer 1.5s linear infinite;
}

@keyframes shimmer {
  to { background-position: -200% 0; }
}

/* Page turn fade animations */
.page-turn-left { animation: turnLeft 0.35s ease-out; }
.page-turn-right { animation: turnRight 0.35s ease-out; }

@keyframes turnLeft {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes turnRight {
  from { opacity: 0; transform: translateX(-40px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Title overlay on cover page — reader-style gradient card */
.page-overlay-text {
  position: absolute;
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  z-index: 20;
  pointer-events: none;
}

.page-overlay-text.title-overlay {
  top: 22px;
  left: 14px;
  right: 14px;
  padding: 18px 18px 22px;
  border-radius: 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.62),
    rgba(0, 0, 0, 0.22) 70%,
    rgba(0, 0, 0, 0)
  );
}

.page-overlay-text.title-overlay > span:first-child {
  margin: 0;
  font-size: 28px;
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: 0.3px;
  text-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
}

.page-overlay-text.title-overlay .book-author {
  font-family: 'Quicksand', sans-serif;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0.96;
  text-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
}

.page-overlay-text.end-overlay {
  bottom: 22px;
  left: 14px;
  right: 14px;
  padding: 22px 18px 18px;
  border-radius: 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.62),
    rgba(0, 0, 0, 0.22) 70%,
    rgba(0, 0, 0, 0)
  );
}

.page-overlay-text.end-overlay > span {
  font-size: 28px;
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: 0.4px;
  text-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
}

/* Loading screen - full viewport overlay */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 10060;
  display: none;
  align-items: center;
  justify-content: center;
  background: #0b0b10;
}

#loading-screen.active {
  display: flex;
}
