/* ===================================================
   HEUREKA DERGİ — Dergi Okuyucu (Reader)
   =================================================== */

/* --- Reader Layout --- */
.reader-page {
  --bg-primary: #f5f2eb; /* Warm eye-friendly cream */
  --bg-secondary: #fdfbf7;
  --bg-tertiary: #eae6df;
  --text-primary: #2d3436;
  --text-secondary: #636e72;
  --text-muted: #889397;
  --glass-bg: rgba(0, 0, 0, 0.03);
  --glass-bg-hover: rgba(0, 0, 0, 0.06);
  --glass-border: rgba(0, 0, 0, 0.08);
  --glass-border-hover: rgba(0, 0, 0, 0.15);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);

  background: var(--bg-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  transition: background var(--transition-base);
}

body.light-theme .reader-page {
  --bg-primary: #eef1f6; /* Cool soft gray-blue */
  --bg-secondary: #ffffff;
  --bg-tertiary: #dce2e9;
  --text-primary: #2d3436;
  --text-secondary: #636e72;
  --text-muted: #889397;
  --glass-bg: rgba(0, 0, 0, 0.03);
  --glass-bg-hover: rgba(0, 0, 0, 0.06);
  --glass-border: rgba(0, 0, 0, 0.08);
  --glass-border-hover: rgba(0, 0, 0, 0.15);
}

/* --- Reader Toolbar --- */
.reader-toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--bg-secondary);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xl);
  z-index: 1000;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.reader-toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.reader-toolbar-logo {
  height: 35px;
  width: auto;
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.reader-toolbar-logo:hover {
  transform: scale(1.05);
}

.reader-toolbar-title {
  font-family: var(--font-display);
  font-size: var(--fs-small);
  color: var(--text-secondary);
  font-weight: 400;
}

.reader-toolbar-center {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.reader-page-info {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  background: var(--glass-bg);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-full);
  border: 1px solid var(--glass-border);
  min-width: 120px;
  text-align: center;
}

.reader-toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.reader-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--transition-fast);
  position: relative;
}

.reader-btn:hover {
  background: var(--glass-bg-hover);
  color: var(--text-primary);
  border-color: var(--accent-purple);
}

.reader-btn.active {
  background: var(--accent-purple);
  color: var(--bg-primary);
  border-color: var(--accent-purple);
}

.reader-btn-separator {
  width: 1px;
  height: 24px;
  background: var(--glass-border);
  margin: 0 var(--space-xs);
}

/* Tooltip */
.reader-btn[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: -35px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  border: 1px solid var(--glass-border);
}

.reader-btn:hover[data-tooltip]::after {
  opacity: 1;
}

/* --- Main Reader Area --- */
.reader-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 60px;
  padding-bottom: 50px; /* Space for page numbers under the pages */
  position: relative;
  overflow: hidden;
}

/* Background ambient light */
.reader-ambient {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120%;
  height: 120%;
  background: radial-gradient(ellipse at center, rgba(162, 155, 254, 0.03) 0%, transparent 60%);
  pointer-events: none;
}

/* --- Flipbook Container --- */
.flipbook-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease;
}

.flipbook {
  position: relative;
  width: 800px;
  height: 560px;
  perspective: 2500px;
  transform-style: preserve-3d;
}

/* Individual page */
.flipbook .page {
  position: absolute;
  width: 50%;
  height: 100%;
  top: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
  cursor: pointer;
  z-index: 1;
}

.flipbook .page.right-page {
  right: 0;
  left: auto;
  transform-origin: left center;
}

.flipbook .page.left-page {
  left: 0;
  transform-origin: right center;
}

/* Page front and back faces */
.page-front,
.page-back {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

.page-front {
  z-index: 2;
}

.page-back {
  transform: rotateY(180deg);
  z-index: 1;
}

.page-front img,
.page-back img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--bg-primary);
}

/* Page shadow during flip */
.page-shadow {
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.page.flipping .page-shadow {
  opacity: 1;
}

/* Book spine/center shadow */
.flipbook-spine {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 100%;
  background: linear-gradient(90deg,
    rgba(0,0,0,0.3) 0%,
    rgba(0,0,0,0.1) 30%,
    rgba(0,0,0,0.05) 50%,
    rgba(0,0,0,0.1) 70%,
    rgba(0,0,0,0.3) 100%
  );
  z-index: 50;
  pointer-events: none;
}

/* Book edge shadow */
.flipbook::before {
  content: '';
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: var(--radius-md);
  filter: blur(20px);
  z-index: -1;
}

/* --- Navigation Arrows --- */
.reader-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.3rem;
  transition: all var(--transition-base);
  z-index: 20;
}

.reader-nav:hover {
  background: var(--accent-purple);
  color: var(--bg-primary);
  border-color: var(--accent-purple);
  box-shadow: var(--shadow-glow-purple);
  transform: translateY(-50%) scale(1.1);
}

.reader-nav.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.reader-nav-prev {
  left: var(--space-xl);
}

.reader-nav-next {
  right: var(--space-xl);
}

/* --- Thumbnail Strip --- */
.reader-thumbnails {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 90px;
  background: rgba(13, 11, 26, 0.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-xl);
  gap: var(--space-sm);
  overflow-x: auto;
  overflow-y: hidden;
  z-index: 50;
  transition: transform 0.3s ease;
}

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

.reader-thumbnails::-webkit-scrollbar {
  height: 4px;
}

.reader-thumbnails::-webkit-scrollbar-thumb {
  background: var(--accent-purple);
  border-radius: var(--radius-full);
}

.thumb-item {
  flex-shrink: 0;
  width: 50px;
  height: 70px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition-fast);
  opacity: 0.5;
}

.thumb-item:hover {
  opacity: 0.8;
  border-color: var(--glass-border-hover);
  transform: translateY(-3px);
}

.thumb-item.active {
  opacity: 1;
  border-color: var(--accent-purple);
  box-shadow: var(--shadow-glow-purple);
  transform: translateY(-3px);
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- Zoom Controls --- */
.zoom-indicator {
  position: fixed;
  bottom: 100px;
  right: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  z-index: 60;
}

.zoom-level {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-align: center;
  margin-bottom: var(--space-xs);
}

/* --- Fullscreen Mode --- */
.reader-page.fullscreen .reader-toolbar {
  opacity: 0;
  transform: translateY(-100%);
  transition-delay: 0.5s; /* Delay hiding to prevent accidental flickering */
}

/* Trigger zone at the top of the screen in fullscreen */
.fullscreen-trigger-top {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px; /* Matched to toolbar height to eliminate trigger gap */
  z-index: 999;
}

.reader-page.fullscreen .fullscreen-trigger-top {
  display: block;
}

/* Show toolbar only when hovering the top trigger zone OR the toolbar itself */
.reader-page.fullscreen .fullscreen-trigger-top:hover ~ .reader-toolbar,
.reader-page.fullscreen .reader-toolbar:hover {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0s; /* Show immediately on hover */
}

/* --- Single Page View (Mobile) --- */
.single-page-view {
  width: 100%;
  height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 10px 50px 10px; /* Leave space at the bottom for page number */
  position: relative;
}

.single-page-view img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: none !important; /* No dark shadows or borders around pages */
}

#mobile-page-num {
  bottom: 15px;
  left: 50%;
  transform: translateX(-50%);
}

/* --- Loading State --- */
.reader-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
}

.reader-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--glass-border);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.reader-loading-text {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* --- Sound Toggle Visual Feedback --- */
.sound-wave {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 16px;
}

.sound-wave span {
  width: 2px;
  background: currentColor;
  border-radius: 1px;
  animation: sound-bar 0.8s ease-in-out infinite;
}

.sound-wave span:nth-child(1) { height: 4px; animation-delay: 0s; }
.sound-wave span:nth-child(2) { height: 8px; animation-delay: 0.1s; }
.sound-wave span:nth-child(3) { height: 12px; animation-delay: 0.2s; }
.sound-wave span:nth-child(4) { height: 6px; animation-delay: 0.3s; }

@keyframes sound-bar {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}

.reader-btn.muted .sound-wave span {
  animation: none;
  height: 2px;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
  .flipbook {
    width: 600px;
    height: 420px;
  }
}

@media (max-width: 768px) {
  .flipbook {
    display: none;
  }
  
  .reader-container {
    padding-bottom: 60px;
  }

  .reader-toolbar-title {
    display: none;
  }

  .reader-nav {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }

  .reader-nav-prev {
    left: var(--space-sm);
  }

  .reader-nav-next {
    right: var(--space-sm);
  }
  
  .reader-thumbnails {
    height: 70px;
  }
  
  .thumb-item {
    width: 40px;
    height: 55px;
  }
}

@media (max-width: 480px) {
  .reader-toolbar {
    padding: 0 var(--space-md);
  }
  
  .reader-btn-separator,
  .reader-btn[data-tooltip="Tam Ekran"] {
    display: none;
  }
}

/* Background pages to prevent dark gaps */
.page-background-left,
.page-background-right {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  background: var(--bg-primary);
  overflow: hidden;
  z-index: 0;
}

.page-background-left {
  left: 0;
  border-radius: 2px 0 0 2px;
}

.page-background-right {
  right: 0;
  border-radius: 0 2px 2px 0;
}

.page-background-left img,
.page-background-right img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--bg-primary);
}

/* Book page numbers style - Positioned under the pages */
.book-page-num {
  position: absolute;
  bottom: -45px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  padding: 4px 14px;
  border-radius: 20px;
  z-index: 35;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.book-page-num-left {
  left: 20px;
}

.book-page-num-right {
  right: 20px;
}

/* Localized page prefixes */
html[lang="tr"] .book-page-num::before {
  content: "Sayfa ";
}

html[lang="en"] .book-page-num::before {
  content: "Page ";
}

/* Light theme overrides for reader */
body.light-theme .flipbook-spine {
  background: linear-gradient(90deg,
    rgba(0,0,0,0.15) 0%,
    rgba(0,0,0,0.05) 30%,
    rgba(0,0,0,0.02) 50%,
    rgba(0,0,0,0.05) 70%,
    rgba(0,0,0,0.15) 100%
  );
}

/* 
   Hide all book simulation artifacts (shadows, overlays, spines) 
   to provide a clean, modern PDF-like page view. (Keep page numbers visible)
*/
.flipbook-spine,
.page-shadow,
.flipbook::before,
.right-page-container::after,
.left-page-container::after,
.right-page-container.flipping::before,
.flipbook-base {
  display: none !important;
}

/* Ensure page containers use the exact background color to blend seamlessly */
.page-face,
.page-background-left,
.page-background-right,
.page-front img,
.page-back img,
.page-background-left img,
.page-background-right img {
  background: var(--bg-primary) !important;
}

