/* Modern Image Gallery Styles */

/* Root variables for theming */
:root {
  /* Color Palette - Light Mode */
  --color-bg: #ffffff;
  --color-bg-elevated: #f5f5f5;
  --color-text: #1a1a1a;
  --color-text-secondary: #666666;
  --color-border: #e0e0e0;
  --color-hover: #f5f5f5;
  --color-accent: #0066cc;

  /* Animation Timing */
  --transition-fast: 150ms;
  --transition-normal: 250ms;
  --transition-slow: 400ms;
  --easing-smooth: cubic-bezier(0.4, 0.0, 0.2, 1);

  /* Typography Scale */
  --font-size-h1: 2rem;
  --font-size-h2: 1.5rem;
  --font-size-body: 1rem;
  --font-size-caption: 0.875rem;
  --line-height-base: 1.65;
  --line-height-heading: 1.3;
  --letter-spacing-heading: 0.01em;

  /* Spacing (existing) */
  --spacing-unit: 1rem;
  --gap: 1rem;
  --border-radius: 0.5rem;
}

/* CSS Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Body */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: var(--line-height-base);
  color: var(--color-text);
  background-color: var(--color-bg);
  padding: 0;
  overflow-x: hidden;
  max-width: 100vw;
  transition: background-color var(--transition-normal) var(--easing-smooth),
              color var(--transition-normal) var(--easing-smooth);
}

/* Header h1 */
header h1 {
  font-size: var(--font-size-h1);
  line-height: var(--line-height-heading);
  font-weight: 600;
}

/* Main Gallery Container */
.gallery {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--spacing-unit);
}

/* Category Section */
.category-section {
  margin-bottom: calc(var(--spacing-unit) * 3);
}

.category-section h2 {
  font-size: var(--font-size-h2);
  line-height: var(--line-height-heading);
  letter-spacing: var(--letter-spacing-heading);
  font-weight: 500;
  margin-bottom: var(--spacing-unit);
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-border);
}

/* Image Grid - Base (CSS Grid fallback) */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: var(--gap);
  margin-bottom: var(--spacing-unit);
}

/* Image Grid - Enhanced with JS */
.image-grid.layout-calculated {
  display: block;
  position: relative;
  /* height set dynamically by JS */
  margin: 0; /* Minimize external margins for space efficiency */
  padding: 0;
}

/* Single image in grid - center align */
.image-grid.layout-calculated[data-image-count="1"] .image-item {
  max-width: 1200px;
  margin: 0 auto;
}

/* Mobile: 1-2 columns */
@media (max-width: 640px) {
  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.5rem;
  }
}

/* Tablet: 2-3 columns */
@media (min-width: 641px) and (max-width: 1024px) {
  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

/* Image Item - Base */
.image-item {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: var(--border-radius);
  background-color: var(--color-bg-elevated);
  cursor: pointer;
  transition: transform var(--transition-fast) var(--easing-smooth),
              box-shadow var(--transition-fast) var(--easing-smooth);
}

/* Image Item - Enhanced with JS */
.layout-calculated .image-item {
  aspect-ratio: auto; /* Let dimensions control aspect */
  /* position, left, top, width, height set by JS */
}

.image-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.image-item:focus-within {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Image Element */
.image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: filter var(--transition-normal) var(--easing-smooth);
}

/* Image Element - Enhanced with JS (no cropping) */
.layout-calculated .image-item img {
  object-fit: contain; /* Show full image without cropping */
}

/* Lazy loading support */
.image-item img[loading="lazy"] {
  background: linear-gradient(
    90deg,
    var(--color-bg-elevated) 0%,
    rgba(255, 255, 255, 0.3) 50%,
    var(--color-bg-elevated) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 2.0s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Image loaded state */
.image-item img.loaded {
  animation: none;
  background: none;
}

/* Image Caption Overlay (optional) */
.image-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
  color: white;
  font-size: var(--font-size-caption);
  opacity: 0;
  transition: opacity var(--transition-fast) var(--easing-smooth);
  pointer-events: none;
}

.image-item:hover .image-caption {
  opacity: 1;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f0f0f;
    --color-bg-elevated: #1a1a1a;
    --color-text: #e8e8e8;
    --color-text-secondary: #a0a0a0;
    --color-border: #2a2a2a;
    --color-hover: #252525;
    --color-accent: #4a9eff;
  }

  /* Add subtle shadow/border for dark images */
  .image-item img {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05),
                0 2px 8px rgba(0, 0, 0, 0.3);
  }

  /* Enhanced hover effect for dark mode */
  .image-item:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  }

  .image-item:hover img {
    filter: brightness(1.05);
  }

  /* Dark mode shimmer - even more subtle */
  .image-item img[loading="lazy"] {
    background: linear-gradient(
      90deg,
      var(--color-bg-elevated) 0%,
      rgba(255, 255, 255, 0.05) 50%,
      var(--color-bg-elevated) 100%
    );
  }
}

/* Accessibility: Reduced motion */
@media (prefers-reduced-motion: reduce) {
  :root {
    --transition-fast: 0ms;
    --transition-normal: 0ms;
    --transition-slow: 0ms;
  }

  .image-item {
    transition: none;
  }

  .image-item img[loading="lazy"] {
    animation: none;
  }
}

/* Print styles */
@media print {
  .image-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .image-item {
    break-inside: avoid;
  }
}

/* ============================================
   Gallery Banner and Title
   ============================================ */

/* CSS Custom Properties for Banner */
:root {
  --banner-height-desktop: 40vh;
  --banner-height-tablet: 30vh;
  --banner-height-mobile: 25vh;
}

.gallery-banner {
  position: relative;
  width: 100%;
  overflow: hidden;
  margin-bottom: calc(var(--spacing-unit) * 2);
}

.banner-image {
  display: block;
  width: 100%;
  height: var(--banner-height-desktop);
  object-fit: cover;
  object-position: center center;
}

/* Gradient overlay for title readability */
.gallery-banner::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent);
  pointer-events: none;
  z-index: 1;
}

.banner-title {
  position: absolute;
  bottom: 4rem; /* Increased to make room for subtitle */
  left: 2rem;
  right: 2rem;
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.2;
  color: white;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
  text-align: center;
  margin: 0;
  z-index: 2;
}

.banner-subtitle {
  position: absolute;
  bottom: 0.5rem; /* Below title */
  left: 2rem;
  right: 2rem;
  font-size: 1.5rem;
  font-weight: 400; /* Normal weight */
  line-height: 1.4;
  color: white;
  opacity: 0.9; /* Slightly transparent for secondary emphasis */
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7);
  text-align: center;
  margin: 0;
  z-index: 2;
}

/* Responsive breakpoints for banner */
@media (max-width: 1024px) {
  .banner-image {
    height: var(--banner-height-tablet);
  }

  .banner-title {
    font-size: 2.5rem;
  }

  .banner-subtitle {
    font-size: 1.375rem;
  }
}

@media (max-width: 768px) {
  .banner-image {
    height: var(--banner-height-mobile);
  }

  .banner-title {
    font-size: 2rem;
    bottom: 3rem; /* Adjusted for subtitle */
    left: 1rem;
    right: 1rem;
  }

  .banner-subtitle {
    font-size: 1.125rem;
    left: 1rem;
    right: 1rem;
  }
}

@media (max-width: 480px) {
  .banner-title {
    font-size: 1.5rem;
  }

  .banner-subtitle {
    font-size: 1rem;
  }
}

/* Header with banner no longer needs extra padding/border */
header:has(.gallery-banner) {
  padding: 0;
  border-bottom: none;
  margin-bottom: 0;
}

/* Header without banner needs padding */
header:not(:has(.gallery-banner)) {
  text-align: center;
  padding: calc(var(--spacing-unit) * 2) var(--spacing-unit);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: calc(var(--spacing-unit) * 2);
}

/* Dark mode: Banner works well in both themes, no changes needed */


/* Fullscreen Modal */
/* Fullscreen Modal Styles */

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.95);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-normal, 250ms) ease;
}

.modal.visible {
  opacity: 1;
}

.modal[aria-hidden="true"] {
  display: none;
}

.modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
}

.modal-content img {
  max-width: 100%;
  max-height: 80vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-content img:not(.loaded) {
  opacity: 0.95;
}

.modal-content img.loaded {
  opacity: 1;
}

.modal-metadata {
  margin-top: 1rem;
  text-align: center;
  color: white;
  max-width: 600px;
  padding: 0 1rem;
}

.modal-metadata h2 {
  font-size: var(--font-size-h2, 1.5rem);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.modal-metadata p {
  font-size: var(--font-size-body, 1rem);
  line-height: var(--line-height-base, 1.65);
  margin: 0.5rem 0;
}

.modal-category {
  font-size: 0.75rem;
  opacity: 0.7;
  font-style: italic;
}

/* Close button */
.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 3rem;
  height: 3rem;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  transition: background var(--transition-fast, 150ms) var(--easing-smooth, ease),
              transform var(--transition-fast, 150ms) var(--easing-smooth, ease);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.modal-close:focus {
  outline: 2px solid var(--color-accent, #0066cc);
  outline-offset: 2px;
}

/* Navigation buttons */
.modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 3rem;
  height: 3rem;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 2rem;
  cursor: pointer;
  border-radius: 50%;
  transition: background var(--transition-fast, 150ms) var(--easing-smooth, ease),
              transform var(--transition-fast, 150ms) var(--easing-smooth, ease);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-nav:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-50%) scale(1.1);
}

.modal-nav:focus {
  outline: 2px solid var(--color-accent, #0066cc);
  outline-offset: 2px;
}

.modal-prev {
  left: 1rem;
}

.modal-next {
  right: 1rem;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .modal-content {
    padding: 1rem;
  }

  .modal-content img {
    max-height: 75vh;
  }

  .modal-close {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.5rem;
  }

  .modal-nav {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.5rem;
  }

  .modal-prev {
    left: 0.5rem;
  }

  .modal-next {
    right: 0.5rem;
  }

  .modal-metadata h2 {
    font-size: calc(var(--font-size-h2, 1.5rem) * 0.83);
  }

  .modal-metadata p {
    font-size: var(--font-size-caption, 0.875rem);
  }
}

/* Accessibility: Skip link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: #000;
  color: #fff;
  padding: 8px;
  text-decoration: none;
  z-index: 100;
  transition: top 0.2s;
  clip: rect(0, 0, 0, 0);
  overflow: hidden;
}

.skip-link:focus {
  top: 0;
  clip: auto;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal-close,
  .modal-nav {
    transition: none;
  }
}
