/* ==========================================================================
   Manga Reader - Modern Dark Design System & Aesthetics
   ========================================================================== */

:root {
  /* Color Palette - Vibrant Rose / Slate Dark Theme */
  --accent-primary: #f43f5e;
  --accent-glow: rgba(244, 63, 94, 0.35);
  --accent-hover: #fb7185;
  --accent-cyan: #38bdf8;

  /* Surfaces & Glassmorphism */
  --glass-bg: rgba(15, 17, 23, 0.78);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.6), 0 0 1px 1px rgba(255, 255, 255, 0.05);

  /* Text Colors */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Typography */
  --font-family: 'Prompt', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Layout & Animations */
  --hud-height: 58px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  --transition-fast: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.3s cubic-bezier(0.16, 1, 0.3, 1);

  /* Webtoon Spacing */
  --webtoon-gap: 0px;
}

/* Background Themes */
body.theme-oled {
  --bg-main: #000000;
  --bg-surface: #0a0b0d;
}

body.theme-charcoal {
  --bg-main: #121316;
  --bg-surface: #1a1c22;
}

body.theme-slate {
  --bg-main: #171c26;
  --bg-surface: #222938;
}

/* ==========================================================================
   Reset & Base Styles
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-family);
  user-select: none;
  -webkit-user-select: none;
}

/* Custom Minimalist Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

/* ==========================================================================
   HUD Bars (Top & Bottom Controls)
   ========================================================================== */
.hud-bar {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-color: var(--glass-border);
  box-shadow: var(--glass-shadow);
  transition: transform var(--transition-smooth), opacity var(--transition-smooth);
}

/* Top HUD */
.top-hud {
  top: 0;
  height: var(--hud-height);
  border-bottom: 1px solid var(--glass-border);
  padding-top: env(safe-area-inset-top, 0);
  transform: translateY(0);
  opacity: 1;
}

.top-hud:not(.visible) {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

/* Bottom HUD */
.bottom-hud {
  bottom: 0;
  height: var(--hud-height);
  border-top: 1px solid var(--glass-border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  transform: translateY(0);
  opacity: 1;
}

.bottom-hud:not(.visible) {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

/* Left Section: Back button & Title */
.hud-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.manga-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.title-text {
  font-size: 0.925rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.subtitle-text {
  font-size: 0.75rem;
  color: var(--accent-cyan);
  font-weight: 500;
}

/* Center Section: Chapter Dropdown */
.hud-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.chapter-selector-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.hud-select {
  appearance: none;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.825rem;
  font-weight: 500;
  padding: 0.4rem 2.2rem 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  outline: none;
  transition: all var(--transition-fast);
}

.hud-select:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}

.select-arrow {
  position: absolute;
  right: 0.75rem;
  pointer-events: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* Right Section: Quick Switcher, Fullscreen, Settings */
.hud-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-end;
  flex: 1;
}

/* Mode Quick Switch Pills */
.mode-pills {
  display: flex;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
}

.pill-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-full);
  font-family: var(--font-family);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pill-btn:hover {
  color: var(--text-primary);
}

.pill-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* Button Component */
.hud-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.hud-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.hud-btn:active {
  transform: translateY(0);
}

.hud-btn.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-full);
}

/* ==========================================================================
   Bottom Scrubber Controls
   ========================================================================== */
.hud-nav-buttons {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.scrubber-container {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex: 1;
  max-width: 500px;
  margin: 0 1rem;
}

.page-indicator {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 28px;
  text-align: center;
}

#page-counter-start {
  color: var(--accent-primary);
}

/* Custom Range Slider */
.page-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.15);
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}

.page-slider:hover {
  background: rgba(255, 255, 255, 0.25);
}

.page-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-primary);
  box-shadow: 0 0 10px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.page-slider::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}

/* ==========================================================================
   Reader Viewport & Containers
   ========================================================================== */
.reader-viewport {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Click Zones for Tap Navigation */
.click-zones {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  display: flex;
  pointer-events: none;
}

.click-zone {
  height: 100%;
  pointer-events: auto;
}

.zone-prev {
  width: 30%;
  cursor: w-resize;
}

.zone-hud {
  width: 40%;
  cursor: pointer;
}

.zone-next {
  width: 30%;
  cursor: e-resize;
}

/* In Webtoon mode, click zones let user scroll naturally */
body[data-reading-mode="webtoon"] .click-zones {
  pointer-events: none;
}
body[data-reading-mode="webtoon"] .zone-hud {
  pointer-events: auto;
  position: fixed;
  top: 30%;
  left: 30%;
  width: 40%;
  height: 40%;
}

/* Pages Container */
.pages-container {
  width: 100%;
  height: 100%;
  display: flex;
}

/* Mode: Webtoon (Continuous Vertical Scroll) */
body[data-reading-mode="webtoon"] .reader-viewport {
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

body[data-reading-mode="webtoon"] .pages-container {
  flex-direction: column;
  align-items: center;
  min-height: 100%;
  padding: calc(var(--hud-height) + 10px) 0 80px 0;
  gap: var(--webtoon-gap);
}

body[data-reading-mode="webtoon"] .manga-page-wrapper {
  display: flex;
  justify-content: center;
  width: 100%;
}

/* Mode: Single Page */
body[data-reading-mode="single"] .pages-container {
  align-items: center;
  justify-content: center;
  height: 100%;
}

/* Mode: Double Page */
body[data-reading-mode="double"] .pages-container {
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 4px;
}

/* RTL handling for Double Mode: In RTL, right page comes first */
body[data-reading-mode="double"][data-direction="rtl"] .pages-container {
  flex-direction: row-reverse;
}

/* Page Images */
.manga-page {
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  object-fit: contain;
  transition: opacity 0.2s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Image Fit Modes */
body[data-fit="fit-width"] .manga-page {
  width: 100%;
  max-width: 900px;
  height: auto;
}

body[data-fit="fit-height"] .manga-page {
  height: calc(100vh - 20px);
  max-height: 100vh;
  width: auto;
  max-width: 100vw;
}

body[data-fit="original"] .manga-page {
  width: auto;
  height: auto;
  max-width: none;
}

/* Double Page fit sizing */
body[data-reading-mode="double"] .manga-page {
  max-height: calc(100vh - 20px);
  max-width: 48vw;
  width: auto;
  height: auto;
}

/* ==========================================================================
   Chapter End Card
   ========================================================================== */
.chapter-end-card {
  display: none;
  justify-content: center;
  align-items: center;
  padding: 4rem 1.5rem;
  width: 100%;
}

.chapter-end-card.visible {
  display: flex;
}

.end-card-content {
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  text-align: center;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.4s ease;
}

.end-badge {
  display: inline-block;
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.3);
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.end-card-content h3 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

.end-card-desc {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-full);
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: all var(--transition-fast);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

/* ==========================================================================
   Settings Drawer & Modal Overlay
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-smooth);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 90vw;
  height: 100%;
  background: var(--bg-surface);
  border-left: 1px solid var(--glass-border);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.7);
  z-index: 250;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-smooth);
}

.settings-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem;
  border-bottom: 1px solid var(--glass-border);
}

.drawer-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
}

.close-btn:hover {
  color: var(--text-primary);
}

.drawer-body {
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.setting-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Radio Pill Group */
.radio-pill-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 0.5rem;
}

.choice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 0.4rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.choice-btn strong {
  font-size: 0.8rem;
  color: var(--text-primary);
}

.choice-btn span {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.choice-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
}

.choice-btn.active {
  background: rgba(244, 63, 94, 0.15);
  border-color: var(--accent-primary);
  box-shadow: 0 0 10px rgba(244, 63, 94, 0.2);
}

.choice-btn.active strong {
  color: var(--accent-primary);
}

/* Color Theme Palette */
.color-palette-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.theme-choice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 0.5rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.theme-choice-btn .color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.theme-choice-btn.active {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

/* Keyboard Shortcuts List */
.shortcuts-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.shortcut-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

kbd {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-primary);
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 22, 28, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 300;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ==========================================================================
   Responsive & Mobile Adaptations
   ========================================================================== */
@media (max-width: 768px) {
  .title-text {
    max-width: 150px;
  }
  .hud-select {
    max-width: 120px;
    font-size: 0.75rem;
    padding: 0.35rem 1.8rem 0.35rem 0.65rem;
  }
  .mode-pills .pill-label {
    display: none;
  }
  .btn-text {
    display: none;
  }
  .hud-btn.icon-btn {
    width: 32px;
    height: 32px;
  }
  .scrubber-container {
    margin: 0 0.5rem;
  }
}

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