/* Import base styles and variables from main stylesheet */
@import url('./styles.css');

/* Gallery-specific styles */
.gallery-page {
  min-height: 100vh;
}

.gallery-hero {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
  text-align: center;
}

.gallery-hero h1 {
  font-family: var(--font-h1);
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 600;
  background: var(--prime-text-bg);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 1rem;
}

.gallery-hero p {
  font-size: 1.1rem;
  color: var(--hakuji);
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.6;
}

/* Gallery Filters */
.gallery-filters {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem 2rem 1rem;
  text-align: center;
}

.gallery-filters h2 {
  font-family: var(--font-h1);
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--hakuji);
  margin-bottom: 1.5rem;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.filter-btn {
  background: var(--bg);
  background-clip: text;
  border: 2px solid var(--line);
  color: var(--gofun);
  padding: 0.5rem 1rem;
  border-radius: 25px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 300ms ease;
  white-space: nowrap;
}

.filter-btn:hover {
  background: var(--prime-theme);
  background-clip: text;
  color: transparent;
  border-color: var(--prime-theme);
  transform: translateY(-2px);
  transition: all 350ms ease;
}

.filter-btn.active {
  background: var(--prime-text-bg);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  border: 2px solid var(--prime-theme);
  font-weight: 600;
}

.filter-btn:focus-visible {
  outline: 2px solid var(--prime-theme);
  outline-offset: 2px;
}

.filter-btn.active:focus-visible {
  outline: none;
}

/* Mobile responsive filter buttons */
@media (max-width: 768px) {
  .filter-buttons {
    gap: 0.5rem;
  }

  .filter-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
  }

  .gallery-filters {
    padding: 0 1rem 1.5rem 1rem;
  }

  .gallery-filters h2 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
  }
}

.gallery-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* Responsive Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  width: 100%;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.gallery-grid.filtering {
  opacity: 0;
}

/* Desktop: 3-4 columns */
@media (min-width: 1200px) {
  .gallery-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 2.5rem;
  }
}

@media (min-width: 900px) and (max-width: 1199px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
  }
}

/* Tablet: 2 columns */
@media (min-width: 600px) and (max-width: 899px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
  }
}

/* Mobile: 1 column */
@media (max-width: 599px) {
  .gallery-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .gallery-container {
    padding: 1rem;
  }
}

/* Gallery Item Styles */
.gallery-item {
  background: var(--surface-1);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  transition: all 0.3s ease, opacity 0.4s ease, transform 0.4s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: scale(0.9) translateY(20px);
  animation: fadeInUp 0.6s ease forwards;
}

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.gallery-item:nth-child(1) { animation-delay: 0.1s; }
.gallery-item:nth-child(2) { animation-delay: 0.15s; }
.gallery-item:nth-child(3) { animation-delay: 0.2s; }
.gallery-item:nth-child(4) { animation-delay: 0.25s; }
.gallery-item:nth-child(5) { animation-delay: 0.3s; }
.gallery-item:nth-child(6) { animation-delay: 0.35s; }
.gallery-item:nth-child(7) { animation-delay: 0.4s; }
.gallery-item:nth-child(8) { animation-delay: 0.45s; }
.gallery-item:nth-child(9) { animation-delay: 0.5s; }
.gallery-item:nth-child(10) { animation-delay: 0.55s; }
.gallery-item:nth-child(11) { animation-delay: 0.6s; }
.gallery-item:nth-child(12) { animation-delay: 0.65s; }

.gallery-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  border-color: var(--prime-theme);
}

.gallery-item:focus-visible {
  outline: 2px solid var(--prime-theme);
  outline-offset: 2px;
}

.gallery-item-image-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-item-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  transition: transform 0.3s ease;
}

.gallery-item:hover .gallery-item-image {
  transform: scale(1.05);
}

.gallery-item-info {
  padding: 1rem;
}

.gallery-item-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--hakuji);
  line-height: 1.4;
  margin: 0;
}

/* Modern Carousel Modal Styles */
.carousel-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(5px);
  opacity: 1;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.carousel-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  cursor: pointer;
}

.carousel-container {
  position: relative;
  width: 95vw;
  height: 95vh;
  max-width: 1400px;
  max-height: 900px;
  background: rgba(20, 20, 20, 0.9);
  border-radius: 16px;
  backdrop-filter: blur(20px);
  border: 1px solid rgba(252, 126, 32, 0.2);
  overflow: hidden;
  transform: scale(0.9);
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.carousel-modal:not(.hidden) .carousel-container {
  transform: scale(1);
  opacity: 1;
}

/* Header */
.carousel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  height: 60px;
}

.carousel-counter {
  color: var(--hakuji);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
}

.carousel-close {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--hakuji);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.carousel-close:hover {
  background: rgba(252, 126, 32, 0.9);
  border-color: rgba(252, 126, 32, 1);
  transform: scale(1.1);
}

/* Main Content */
.carousel-content {
  position: absolute;
  top: 60px;
  bottom: 150px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  padding: 1rem;
}

.carousel-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  overflow: hidden;
}

.carousel-image-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transform: translateX(0);
  opacity: 1;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform, opacity;
  object-fit: contain;
  display: block;
}

/* Loading Spinner */
.carousel-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(252, 126, 32, 0.3);
  border-top: 3px solid rgba(252, 126, 32, 1);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Navigation */
.carousel-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(20, 20, 20, 0.8);
  border: 2px solid rgba(252, 126, 32, 0.5);
  color: var(--hakuji);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(10px);
  z-index: 2;
}

.carousel-nav:hover {
  background: rgba(252, 126, 32, 0.9);
  border-color: rgba(252, 126, 32, 1);
  transform: translateY(-50%) scale(1.1);
  color: var(--bg);
}

.carousel-nav-prev {
  left: 20px;
}

.carousel-nav-next {
  right: 20px;
}

.carousel-nav svg {
  width: 28px;
  height: 28px;
}

/* Footer */
.carousel-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 150px;
  background: rgba(0, 0, 0, 0.3);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 1rem 1.5rem;
  overflow: hidden;
}

.carousel-caption {
  text-align: center;
  margin-bottom: 1rem;
}

.carousel-title {
  font-family: var(--font-h1);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--hakuji);
  margin: 0 0 0.5rem 0;
  line-height: 1.4;
}

.carousel-description {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.5;
}

/* Thumbnails */
.carousel-thumbnails {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(252, 126, 32, 0.5) rgba(255, 255, 255, 0.1);
}

.carousel-thumbnails::-webkit-scrollbar {
  height: 6px;
}

.carousel-thumbnails::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.carousel-thumbnails::-webkit-scrollbar-thumb {
  background: rgba(252, 126, 32, 0.5);
  border-radius: 3px;
}

.carousel-thumbnails::-webkit-scrollbar-thumb:hover {
  background: rgba(252, 126, 32, 0.7);
}

.thumbnails-container {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.thumbnail-item {
  flex-shrink: 0;
  width: 60px;
  height: 45px;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s ease;
  opacity: 0.7;
}

.thumbnail-item:hover {
  opacity: 1;
  border-color: rgba(252, 126, 32, 0.5);
  transform: scale(1.05);
}

.thumbnail-item.active {
  border-color: rgba(252, 126, 32, 1);
  opacity: 1;
}

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

/* Mobile scroll prevention */
.noscroll {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

/* Loading state */
.gallery-item.loading {
  opacity: 0.6;
  pointer-events: none;
}

.gallery-item.loading .gallery-item-image {
  filter: blur(2px);
}

/* Mobile carousel adjustments */
@media (max-width: 768px) {
  .carousel-container {
    width: 98vw;
    height: 98vh;
    border-radius: 12px;
  }

  .carousel-header {
    padding: 0.75rem 1rem;
  }

  .carousel-close {
    width: 36px;
    height: 36px;
  }

  .carousel-content {
    padding: 0.5rem;
  }

  .carousel-nav {
    width: 50px;
    height: 50px;
  }

  .carousel-nav-prev {
    left: 10px;
  }

  .carousel-nav-next {
    right: 10px;
  }

  .carousel-nav svg {
    width: 24px;
    height: 24px;
  }

  .carousel-footer {
    padding: 1rem;
  }

  .carousel-title {
    font-size: 1rem;
  }

  .carousel-description {
    font-size: 0.8rem;
  }

  .thumbnail-item {
    width: 50px;
    height: 38px;
  }
}

@media (max-width: 480px) {
  .carousel-container {
    border-radius: 8px;
  }

  .carousel-header {
    padding: 0.5rem 0.75rem;
  }

  .carousel-counter {
    font-size: 0.8rem;
  }

  .carousel-close {
    width: 32px;
    height: 32px;
  }

  .carousel-nav {
    width: 44px;
    height: 44px;
  }

  .carousel-nav svg {
    width: 20px;
    height: 20px;
  }

  .carousel-footer {
    padding: 0.75rem;
  }

  .carousel-caption {
    margin-bottom: 0.75rem;
  }

  .carousel-title {
    font-size: 0.9rem;
  }

  .thumbnail-item {
    width: 45px;
    height: 34px;
  }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  .gallery-item,
  .gallery-item-image,
  .carousel-modal,
  .carousel-container,
  .carousel-close,
  .carousel-nav,
  .carousel-image,
  .thumbnail-item {
    transition: none;
    animation: none;
  }

  .gallery-item:hover {
    transform: none;
  }

  .gallery-item:hover .gallery-item-image {
    transform: none;
  }

  .carousel-nav:hover {
    transform: translateY(-50%);
  }

  .loading-spinner {
    animation: none;
  }
}

/* Focus styles for keyboard navigation */

.carousel-close:focus-visible,
.carousel-nav:focus-visible {
  outline: 2px solid var(--prime-theme);
  outline-offset: 2px;
}

.thumbnail-item:focus-visible {
  outline: 2px solid var(--prime-theme);
  outline-offset: 2px;
  border-color: rgba(252, 126, 32, 1);
}

/* Back to Top Button */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 56px;
  height: 56px;
  background: rgba(20, 20, 20, 0.9);
  border: 2px solid rgba(252, 126, 32, 0.5);
  color: var(--hakuji);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(10px);
  z-index: 1000;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

.back-to-top:not(.hidden) {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover {
  background: rgba(252, 126, 32, 0.9);
  border-color: rgba(252, 126, 32, 1);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(252, 126, 32, 0.3);
  color: var(--bg);
}

.back-to-top:focus-visible {
  outline: 2px solid var(--prime-theme);
  outline-offset: 2px;
}

.back-to-top svg {
  width: 24px;
  height: 24px;
}

/* Mobile adjustments for back to top */
@media (max-width: 768px) {
  .back-to-top {
    bottom: 1.5rem;
    right: 1.5rem;
    width: 50px;
    height: 50px;
  }

  .back-to-top svg {
    width: 20px;
    height: 20px;
  }
}

/* Very small screens */
@media (max-width: 480px) {
  .gallery-hero h1 {
    font-size: 2rem;
  }

  .gallery-hero p {
    font-size: 1rem;
  }

  .gallery-item-image-container {
    aspect-ratio: 3/2; /* Slightly wider ratio for mobile */
  }

  .gallery-item-info {
    padding: 0.75rem;
  }

  .gallery-item-title {
    font-size: 0.85rem;
  }
}