/* Detail page overlay styles */

/* Blur effect for index page when detail is shown */
html.detail-open,
body.detail-open {
  overflow: hidden !important;
  position: fixed !important;
  width: 100% !important;
  height: 100% !important;
  top: 0 !important;
  left: 0 !important;
}

/* Additional iOS scroll prevention */
html.detail-open body,
body.detail-open {
  touch-action: none;
  -webkit-overflow-scrolling: none;
  overscroll-behavior: none;
}

body.index-page.detail-open #categoriesContainer,
body.index-page.detail-open .arrange-button {
  filter: blur(10px);
  pointer-events: none;
}

/* Detail overlay container */
.detail-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent; /* No background on overlay itself */
  z-index: 10000;
  display: flex;
  align-items: flex-start; /* Start from top */
  justify-content: center;
  overflow-y: auto; /* Enable scrolling */
  overflow-x: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 40px 20px; /* Vertical and horizontal padding */
  /* Hide scrollbar */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.detail-overlay::-webkit-scrollbar {
  display: none;
}

.detail-overlay.active {
  opacity: 1;
  pointer-events: all;
}

/* Background layer - clickable to close */
.detail-overlay-background-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1;
  cursor: pointer;
}

/* Detail content container */
.detail-overlay-content {
  position: relative;
  width: 100%;
  max-width: 1200px; /* Increased from 600px to 1200px for wider layout */
  display: flex;
  flex-direction: column;
  align-items: center;
  background: transparent;
  z-index: 2;
  padding: 0 20px; /* Add horizontal padding */
}

.detail-overlay-inner {
  position: relative;
  width: 100%;
  padding: 0;
  background: transparent;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;  /* Center all children including footer */
}

/* Image container */
.detail-image-container {
  position: relative;
  width: 100%;
  max-width: 600px; /* Keep image at 600px for portrait */
  background: transparent;
  border-radius: 8px;
  overflow: visible;  /* Allow landscape images to overflow */
  margin-bottom: 20px; /* Space before related images */
  display: flex;
  justify-content: center;
}

/* Expand container for landscape images */
.detail-image-container:has(img.landscape-image) {
  max-width: 75vw;  /* Slightly larger than image (70vw) to provide padding */
}

.detail-image-container img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
}

/* Action buttons overlay on image */
.detail-actions {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  flex-wrap: nowrap;
  gap: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 10;
}

/* Show buttons on image container hover */
.detail-image-container:hover .detail-actions {
  opacity: 1;
  pointer-events: all;
}

.detail-action-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #ffffff;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  backdrop-filter: blur(10px);
  flex-shrink: 0; /* Prevent shrinking */
}

.detail-action-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  stroke: currentColor;
}

.detail-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.1);
}

/* Hide old elements */
.back-link,
.back-to-category-btn,
.prev-next-buttons,
.prev-btn-detail,
.next-btn-detail,
.vote-btn-overlay,
.detail-actions-new,
.download-buttons-group,
.share-buttons-group,
.desktop-download-share,
.mobile-download-share {
  display: none !important;
}

/* Related images section */
.related-images-section {
  background: rgba(255, 255, 255, 0.05); /* Very subtle tint */
  backdrop-filter: blur(20px); /* Frosted glass effect */
  -webkit-backdrop-filter: blur(20px);
  border-radius: 12px;
  padding: 30px;
  margin-top: 30px;
  width: 100%;
}

.related-images-section h3 {
  color: #ffffff;
  font-size: 20px;
  margin-bottom: 20px;
  text-align: center;
  font-weight: bold;
}

/* Related images section - HIDDEN (old version, not used) */
.related-images-overlay {
  display: none;
}

.related-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); /* Smaller thumbnails */
  gap: 12px;
}

.related-image-card {
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  aspect-ratio: 9 / 16;
}

.related-image-card:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(255, 255, 255, 0.3);
}

.related-image-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.related-images-grid .loading,
.related-images-grid .empty,
.related-images-grid .error {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  color: #888;
}

/* Ad cards in related images section */
.related-images-section .ad-card {
  background-color: #f8f8f8;
  border: 2px dashed #ddd;
  min-height: 160px;
  cursor: default;
}

.related-images-section .ad-card:hover {
  transform: none;
  box-shadow: none;
}

/* Ensure overlay ad cards are always visible */
.related-images-section .ad-card {
  border: 3px solid #ff9800 !important;
  box-shadow: 0 2px 8px rgba(255, 152, 0, 0.3) !important;
  background-color: #f8f8f8 !important;
}

/* Overlay footer with emoji links */
.overlay-footer {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 30px;
  padding: 15px 40px;
  margin: 40px auto 20px auto;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  width: auto;
  max-width: 90%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.overlay-footer .footer-link {
  font-size: 32px;
  text-decoration: none;
  transition: all 0.3s ease;
  display: inline-block;
  filter: grayscale(0.3);
  opacity: 0.8;
}

.overlay-footer .footer-link:hover {
  transform: scale(1.2);
  filter: grayscale(0);
  opacity: 1;
}

.overlay-footer .footer-link:active {
  transform: scale(0.95);
}

/* ========================================
   Overlay Ad Card - Responsive & Visible
   オーバーレイ内広告カードのレスポンシブ設定
   ======================================== */

.related-images-section .related-image-card.ad-card {
  background-color: #f8f8f8 !important;
  border: 3px solid #ff9800 !important;
  box-shadow: 0 2px 8px rgba(255, 152, 0, 0.3) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 160px !important;
  opacity: 1 !important;
  visibility: visible !important;
  position: relative !important;
}

/* AD badge for overlay ad cards */
.related-images-section .related-image-card.ad-card::before {
  content: 'AD' !important;
  position: absolute !important;
  top: 5px !important;
  left: 5px !important;
  background: #ff9800 !important;
  color: white !important;
  padding: 2px 8px !important;
  border-radius: 3px !important;
  font-size: 10px !important;
  font-weight: bold !important;
  z-index: 10 !important;
  opacity: 1 !important;
  visibility: visible !important;
}

/* Hover effect */
.related-images-section .related-image-card.ad-card:hover {
  border-color: #f57c00 !important;
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.5) !important;
}

/* AdSense content responsive sizing */
.related-images-section .related-image-card.ad-card .adsbygoogle {
  width: 100% !important;
  height: auto !important;
  min-height: 130px !important;
}

/* ========================================
   Overlay Footer Container - Center alignment
   フッターを中央配置するための親要素スタイル
   ======================================== */

/* Don't override related-images-section - it needs to maintain its block display for grid */

/* Ensure footer is centered */
.detail-overlay-content .overlay-footer {
  display: inline-flex;
  margin-left: auto;
  margin-right: auto;
}

/* Center the footer using text-align */
.related-images-section {
  text-align: center;
}

/* Reset text-align for grid items */
.related-images-grid {
  text-align: left;
}

/* ========================================
   Related Images Grid - Responsive Card Sizes
   サムネイルの縦横比と2倍・4倍サイズ対応
   ======================================== */

/* Large cards (2x size) - 80% of cards */
.related-image-card:not(.large-card):not(.double-card) {
  /* This is the "normal" 1x size card */
}

/* Double cards (2x2 grid) - for landscape images */
.related-image-card.double-card {
  grid-column: span 2;
  grid-row: span 2;
}

/* Extra large cards (4x size) - 20% of cards */
.related-image-card.large-card {
  grid-column: span 2;
  grid-row: span 2;
}

/* Landscape cards (wider) - double size */
.related-image-card.landscape-card.double-card {
  aspect-ratio: 16 / 9;
  grid-column: span 2;
  grid-row: span 2;
}

/* Landscape cards (wider) - normal size (not double) */
.related-image-card.landscape-card:not(.large-card):not(.double-card) {
  aspect-ratio: 16 / 9;
}

/* Portrait cards (default - taller) - normal size */
.related-image-card:not(.landscape-card):not(.large-card):not(.double-card) {
  aspect-ratio: 3 / 4;
}

/* Large landscape cards - 4x size */
.related-image-card.large-card.landscape-card {
  aspect-ratio: 16 / 9;
  grid-column: span 4;
  grid-row: span 2;
}

/* ========================================
   Main Image - Landscape 70vw size (70% of viewport width)
   横長画像を画面幅70%に表示
   ======================================== */

.detail-image-container img.landscape-image {
  max-width: 70vw !important;  /* 70% of viewport width */
  max-height: none;
  width: auto !important;
  height: auto;
}
