/* Gallery Main Container */
#galleryMain {
  display: none;
}

/* Video/Media Display Overlay */
#videoDisplay {
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(5, 5, 7, 0.95);
  backdrop-filter: blur(20px);
  display: none;
  width: 100%;
  height: 100%;
  z-index: 101;
  animation: fadeIn 0.3s ease;
}

/* Media Module (Video/Image/GIF Player) */
.mediaModule {
  position: fixed;
  z-index: 102; /* Must sit above #videoDisplay (z-index: 101) */
  max-width: 90vw;
  max-height: 80vh;
  margin: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 16px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
}

/* Gallery Images Grid */
#gallerySet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.5rem;
  padding: 2rem;
  text-align: center;
}

/* Gallery Image Container */
.galleryImageContainer {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.galleryImageContainer:hover {
  transform: translateY(-8px);
  border-color: rgba(74, 109, 237, 0.4);
  box-shadow: 0 12px 40px rgba(74, 109, 237, 0.2);
}

/* Gallery Image */
.galleryImage {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  transition: all 0.4s ease;
  border-radius: 16px;
}

.galleryImage:hover {
  transform: scale(1.05);
}

/* Diamond Tier Overlay */
.galleryImageDiamond {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: linear-gradient(135deg, rgba(74, 109, 237, 0.95), rgba(255, 107, 53, 0.95));
  backdrop-filter: blur(10px);
  color: white;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 1.5rem;
  line-height: 1.6;
  border-radius: 16px;
  z-index: 2;
}

/* Video Resolution Selector */
#selectVideoResolution {
  padding: 0.75rem 1rem;
  background: rgba(18, 18, 26, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  outline: none;
}

#selectVideoResolution:hover {
  border-color: var(--primary);
  background: rgba(18, 18, 26, 0.95);
}

#selectVideoResolution:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 109, 237, 0.2);
}

/* Loading Animation */
#loadingSign {
  display: flex;
  position: relative;
  top: 50%;
  align-items: center;
  justify-content: center;
  margin: auto;
}

.videoDownloadPos {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translate(-50%, 0%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem 1rem;
  background: #4A6DED; /* Modern blue, no gradient */
  color: white;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  box-shadow: 0 5px 20px rgba(74, 109, 237, 0.3);
}

@media (max-width: 480px) {
  #gallerySet {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .gallerySidebar .gallerySidebarHeader {
    font-size: 1.25rem;
    padding: 1.5rem 1rem;
  }

  .gallerySidebar .galleryTab {
    padding: 0.875rem 1rem;
    font-size: 0.9rem;
  }
}

/* ---------------------------------- Comic Viewer Modal ---------------------------------- */

/* Overlay — same pattern as #videoDisplay */
#comicDisplay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 5, 7, 0.95);
  backdrop-filter: blur(20px);
  display: none;
  z-index: 101;
  animation: fadeIn 0.3s ease;
  cursor: pointer; /* signals the background is clickable to close */
}

/* Inner container — centered, blocks click-to-close from propagating */
#comicViewer {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  /* gap removed — controls are no longer a flex child */
}

/* Comic loading spinner — reuses .loading but needs its own positioning */
#comicLoadingSign {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Rendered page canvas */
#comicCanvas {
  border-radius: 8px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
  /* max-width / max-height intentionally removed — JS controls CSS pixel size */
  /* Allow single-finger pan on touch; pinch is handled by JS touchstart */
  touch-action: pan-x pan-y;
}

/* Page navigation bar — fixed overlay at bottom-centre.
   Sibling of #comicDisplay (NOT a child) so position:fixed is always
   viewport-relative regardless of comicDisplay's overflow/backdrop-filter. */
#comicControls {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(18, 18, 26, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 0.4rem 1.25rem;
  white-space: nowrap;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* Collapsed state — toggled by #comicToggleBtn */
#comicControls.controls-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(0.5rem);
}

/* Persistent toggle pill — always visible when a comic is open */
#comicToggleBtn {
  position: fixed;
  bottom: 1.5rem;
  left: 1.25rem;
  z-index: 201;
  width: 38px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 18, 26, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.6rem;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

#comicToggleBtn:hover {
  background: rgba(74, 109, 237, 0.3);
  color: var(--primary);
}

#comicPageCounter {
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  min-width: 110px;
  text-align: center;
  user-select: none;
}

/* Prev / Next / Download buttons */
.comic-nav-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  transition: background 0.2s ease, color 0.2s ease;
  text-decoration: none;
}

.comic-nav-btn:hover {
  background: rgba(74, 109, 237, 0.2);
  color: var(--primary);
}

.comic-nav-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

/* Zoom controls group */
.comic-zoom-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

#comicZoomLabel {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  min-width: 3.5rem;
  text-align: center;
  user-select: none;
}

/* Divider between nav arrows and the action buttons (fullscreen + download) */
.comic-action-btn {
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  padding-left: 1rem;
  margin-left: 0.25rem;
}

#comicDownloadBtn {
  font-size: 1.4rem;
}

#comicFullscreenBtn {
  font-size: 1.1rem;
}

/* Fullscreen — document.documentElement is the fullscreen target.
   comicDisplay fills the viewport; just update background opacity. */
:fullscreen #comicDisplay,
:-webkit-full-screen #comicDisplay {
  background: rgb(5, 5, 7); /* fully opaque, no bleed-through */
}

/* ── Wide / scroll mode ───────────────────────────────────────────────────── */

/* Overlay becomes scrollable vertically */
#comicDisplay.wide-mode {
  overflow-y: auto;
  overflow-x: hidden;
  cursor: default;
}

/* Viewer stacks from top, fills width */
#comicDisplay.wide-mode #comicViewer {
  position: relative;
  top: auto;
  left: auto;
  transform: none;
  /* block + text-align:center centers the canvas at zoom=1 (canvas == viewport width).
     At zoom>1 the same JS margin+scroll trick is applied via _applyCenteredScroll(). */
  display: block;
  min-height: 100%;
  text-align: left; /* JS handles horizontal centering via margin:auto on canvas */
  padding: 1.5rem 0 6rem;
}

/* Canvas fills full viewport width */
#comicDisplay.wide-mode #comicCanvas {
  border-radius: 0;
  box-shadow: none;
}

/* When zoom > 1 in wide mode, allow horizontal scrolling too */
#comicDisplay.wide-mode.zoom-overflow {
  overflow-x: auto;
}

/* ── Grab cursor when content is pannable ─────────────────────────────────── */

#comicDisplay.fit-overflow,
#comicDisplay.zoom-overflow {
  cursor: grab;
}

/* ── Fit mode + zoom > 1: enable scrolling ────────────────────────────────── */

#comicDisplay.fit-overflow {
  overflow: auto;
}

#comicDisplay.fit-overflow #comicViewer {
  position: relative;
  top: auto;
  left: auto;
  transform: none;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  /* JS sets explicit width/height and canvas margins — no padding needed.
     min-height keeps the viewer tall enough before JS runs. */
  min-height: 100%;
  padding: 0;
}

/* ── Touch / mobile ─────────────────────────────────────────────────────────── */

/* On touch screens, pinch-to-zoom replaces zoom buttons and fullscreen.
   Wide-mode is redundant too since panning handles scroll. */
@media (hover: none) and (pointer: coarse) {
  .comic-zoom-group   { display: none !important; }
  #comicFullscreenBtn { display: none !important; }
  #comicWideModeBtn   { display: none !important; }

  /* Viewer: prevent the centered transform-based viewer from overflowing at zoom=1.
     At zoom>1, fit-overflow mode takes over and the viewer becomes position:relative,
     so this max-width no longer applies there. */
  #comicViewer {
    max-width: 100vw;
  }
  /* NOTE: no max-width on #comicCanvas — at zoom>1 the canvas intentionally
     overflows the viewport so the user can pan/scroll to see the full page.
     _fitScaleCSS already limits the canvas to 90vw at zoom=1. */
}

@media (max-width: 480px) {
  #comicControls {
    padding: 0.4rem 0.75rem;
    gap: 0.5rem;
    bottom: 1rem;
    /* Stretch and wrap buttons if needed on narrow screens */
    left: 4rem; /* leave room for the toggle button */
    right: 0.75rem;
    transform: none;
    border-radius: 10px;
    flex-wrap: wrap;
    justify-content: center;
  }

  #comicToggleBtn {
    bottom: 1rem;
  }

  #comicPageCounter {
    font-size: 0.85rem;
    min-width: 80px;
  }
}

/* ── Media Controls bar (image / GIF / video viewer) ─────────────────────── */

#mediaControls {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(18, 18, 26, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 0.4rem 1.25rem;
  white-space: nowrap;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#mediaControls.controls-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(0.5rem);
}

/* Toggle pill — identical look/position to #comicToggleBtn */
#mediaToggleBtn {
  position: fixed;
  bottom: 1.5rem;
  left: 1.25rem;
  z-index: 201;
  width: 38px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 18, 26, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.6rem;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

#mediaToggleBtn:hover {
  background: rgba(74, 109, 237, 0.3);
  color: var(--primary);
}

#mediaIndexCounter {
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  min-width: 60px;
  text-align: center;
  user-select: none;
}

#mediaZoomLabel {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  min-width: 3.5rem;
  text-align: center;
  user-select: none;
}

#mediaDownloadBtn {
  font-size: 1.4rem;
}

#mediaFullscreenBtn {
  font-size: 1.1rem;
}

/* Touch / mobile: hide zoom, wide-mode and fullscreen (touch handles zoom natively) */
@media (hover: none) and (pointer: coarse) {
  #mediaZoomGroup    { display: none !important; }
  #mediaFullscreenBtn { display: none !important; }
  #mediaWideModeBtn   { display: none !important; }
}

@media (max-width: 480px) {
  #mediaControls {
    padding: 0.4rem 0.75rem;
    gap: 0.5rem;
    bottom: 1rem;
    left: 4rem; /* leave room for the toggle pill */
    right: 0.75rem;
    transform: none;
    border-radius: 10px;
    flex-wrap: wrap;
    justify-content: center;
  }

  #mediaToggleBtn {
    bottom: 1rem;
  }

  #mediaIndexCounter {
    font-size: 0.85rem;
    min-width: 50px;
  }
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

