:root {
  --reader-bg: #04080f;
  --reader-surface: rgba(255, 255, 255, 0.08);
  --reader-border: rgba(255, 255, 255, 0.12);
  --reader-accent: #84c8ff;
  --reader-text: #f4f7fb;
  --reader-glass: blur(20px) saturate(180%);
}

.reader-v2-container {
  position: fixed;
  inset: 0;
  background: var(--reader-bg);
  color: var(--reader-text);
  font-family: 'Outfit', 'Inter', sans-serif;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 9999;
}

/* Ambient Background Layer */
.reader-ambient-aura {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.15;
  /* Lowered blur radius for significant GPU savings */
  filter: blur(50px);
  will-change: opacity;
  transform: translateZ(0);
}

.reader-ambient-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Header/Toolbar */
.reader-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: linear-gradient(to bottom, rgba(4, 8, 15, 0.8), transparent);
  backdrop-filter: var(--reader-glass);
  border-bottom: 1px solid var(--reader-border);
  z-index: 10000;
  transform: translateY(0);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.reader-header.is-hidden {
  transform: translateY(-100%);
}

.reader-title-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reader-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.reader-subtitle {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
  font-weight: 500;
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.reader-header-rating {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reader-rating-row {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.reader-rating-label {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.8rem;
  font-weight: 500;
}

.reader-rating-value {
  color: #ffca28;
  font-weight: 800;
  font-size: 1rem;
}

.reader-rating-count {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.85rem;
}

.reader-rating-select {
  background: var(--reader-surface);
  color: #fff;
  border: 1px solid var(--reader-border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
}

.reader-close-btn {
  height: 40px;
  padding: 0 16px;
  background: var(--reader-surface);
  border: 1px solid var(--reader-border);
  border-radius: 12px;
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  transition: all 0.2s;
}

.reader-close-btn:hover,
.reader-download-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

.reader-download-btn {
  height: 40px;
  padding: 0 16px;
  background: var(--reader-surface);
  border: 1px solid var(--reader-border);
  border-radius: 12px;
  color: var(--reader-accent);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

/* Main Viewport */
.reader-viewport {
  flex: 1;
  position: relative;
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 2500px;
  overflow: hidden;
}

.reader-v2-container .modal.comic-reader-modal,
.reader-v2-container .modal-card-reader,
.reader-v2-container .comic-reader-body {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  border: none !important;
  position: absolute !important;
  inset: 0 !important;
  transform: none !important;
}

.reader-v2-container .modal.reader-flat-mode {
  perspective: none !important;
}

/* 3D Stage Overrides */
.comic-reader-3d-stage {
  background: transparent !important;
  padding: 0 !important;
  width: 100% !important;
  height: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Nav Arrows */
.reader-side-nav {
  position: absolute;
  top: 72px;
  bottom: 0;
  width: 15%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10100;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s;
}

.reader-side-nav:hover {
  opacity: 1;
}

.reader-side-nav.prev { left: 0; }
.reader-side-nav.next { right: 0; }

.reader-nav-pill {
  width: 56px;
  height: 56px;
  background: var(--reader-surface);
  backdrop-filter: var(--reader-glass);
  border: 1px solid var(--reader-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #fff;
  transition: transform 0.2s;
}

.reader-side-nav:hover .reader-nav-pill {
  transform: scale(1.1);
}

/* Flat / Vertical Scroll Mode */
.reader-v2-container .modal.reader-flat-mode .comic-reader-3d-stage {
  display: none !important;
}

.reader-v2-container .modal.reader-flat-mode .comic-reader-track {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  overflow-y: auto !important;
  padding: 120px 0 100px 0;
  scroll-padding-top: 0;
  /* Remove scroll-snap to ensure 100% native fluidity */
  scroll-snap-type: none !important;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  width: 100vw !important;
  margin: 0 !important;
  /* Performance Hardening */
  will-change: scroll-position;
  contain: layout style;
  transform: translateZ(0);
}

.reader-v2-container .modal.reader-flat-mode .comic-reader-track::-webkit-scrollbar {
  width: 6px;
}

.reader-v2-container .modal.reader-flat-mode .comic-reader-track::-webkit-scrollbar-track {
  background: transparent;
}

.reader-v2-container .modal.reader-flat-mode .comic-reader-track::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
}

.reader-v2-container .modal.reader-flat-mode .comic-reader-track::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

.reader-flat-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 80px;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
}

.reader-flat-page {
  width: min(900px, 95vw);
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 20px;
  /* Removed animation to prevent GPU jank during virtualization re-injection */
  will-change: transform;
  contain: content;
  scroll-snap-align: center;
  margin: 0 auto !important;
  /* Virtualization Slot Styles */
  transform: translateZ(0);
}

.reader-flat-front-cover {
  scroll-snap-align: start;
}

.reader-flat-back-cover {
  scroll-snap-align: end;
}

.reader-flat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  color: rgba(255, 255, 255, 0.45);
  font-weight: 800;
  text-align: center;
}

.reader-flat-frame {
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.05);
  aspect-ratio: 2 / 3;
}

.reader-flat-frame img {
  width: 100%;
  height: auto;
  display: block;
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}


/* Loading Overlay */
.reader-loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--reader-bg);
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.6s;
}

.reader-loading-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  text-align: center;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--reader-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
}

.loading-progress {
  font-size: 0.9rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.4);
  font-variant-numeric: tabular-nums;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Flat Mode Refinements */
.reader-v2-container .modal.reader-flat-mode .comic-reader-track {
  scroll-padding-top: 0; /* Align to top */
}

.reader-flat-stage {
  gap: 120px; /* More breathable gap */
  padding-top: 100px;
}

.reader-flat-page {
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.8);
  border-radius: 12px;
  overflow: hidden;
}

.reader-flat-frame {
  border: none;
  box-shadow: none;
}

.reader-flat-label {
  opacity: 0.6;
  margin-bottom: 8px;
}

/* Close Button Optimization */
.comic-reader-modal.reader-flat-mode .reader-close-pill,
.comic-reader-modal.mobile-scroll-mode .reader-close-pill {
  position: fixed !important;
  top: 18px !important;
  right: 18px !important;
  z-index: 9999 !important;
}

/* PWA / Mobile Reader Header */
@media (max-width: 768px) {
  .reader-header {
    height: auto;
    min-height: 56px;
    padding: 8px 12px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .reader-title-block {
    flex: 1 1 100%;
    min-width: 0;
    gap: 0;
    order: 1;
  }

  .reader-title {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .reader-subtitle {
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .reader-header-rating {
    gap: 4px;
    flex-shrink: 0;
    order: 2;
  }

  .reader-rating-value {
    font-size: 0.85rem;
  }

  .reader-rating-label {
    font-size: 0.7rem;
  }

  .reader-rating-count {
    font-size: 0.75rem;
  }

  .reader-rating-select {
    padding: 3px 4px;
    font-size: 0.75rem;
  }

  .reader-actions {
    gap: 6px;
    flex-shrink: 0;
    order: 3;
    margin-left: auto;
  }

  .reader-download-btn,
  .reader-close-btn {
    height: 34px;
    padding: 0 8px;
    font-size: 0;
    gap: 0;
    border-radius: 10px;
  }

  .reader-download-btn span,
  .reader-close-btn span {
    font-size: 1rem;
  }
}
