/* Gallery Grid Styles */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  margin-top: 40px;
  margin-bottom: 60px;
}

.gallery-item {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  aspect-ratio: 4 / 3;
  /* button化によるデフォルトリセット */
  appearance: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
}

.gallery-item:focus-visible {
  outline: 2px solid #D4AF37;
  outline-offset: 3px;
}

.gallery-item:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.gallery-item-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
  aspect-ratio: 4 / 3;
}

.gallery-item-error {
  padding: 20px;
  color: var(--text-muted);
  text-align: center;
}

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

.gallery-item-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent);
  padding: 20px;
  transition: background 0.3s ease;
}

.gallery-item:hover .gallery-item-overlay {
  background: linear-gradient(to top, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.3));
}

.gallery-item-date {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.gallery-item-count {
  margin: 4px 0 0;
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.8);
}

/* Modal Styles */
.gallery-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
}

.gallery-modal[aria-hidden="false"] {
  display: flex;
}

.gallery-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(10px);
}

.gallery-modal-content {
  position: relative;
  width: 90vw;
  max-width: 1400px;
  height: 90vh;
  display: flex;
  flex-direction: column;
  z-index: 1;
  padding: 60px 20px 20px;
  overflow: hidden;
}

.gallery-modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  font-size: 2.5rem;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
  line-height: 1;
  z-index: 10;
}

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

.gallery-modal-header {
  text-align: center;
  color: #fff;
  margin-bottom: 30px;
  flex-shrink: 0;
}

.gallery-modal-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
  overflow-y: auto;
  padding: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) rgba(0, 0, 0, 0.1);
}

.gallery-modal-images-grid::-webkit-scrollbar {
  width: 8px;
}

.gallery-modal-images-grid::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

.gallery-modal-images-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
}

.gallery-modal-images-grid::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

.gallery-loading,
.gallery-empty {
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
  padding: 60px 20px;
  font-size: 1.1rem;
}

.gallery-loading::after {
  content: '';
  display: inline-block;
  width: 40px;
  height: 40px;
  margin: 20px auto 0;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: gallery-spin 1s linear infinite;
}

.gallery-modal-grid-item {
  appearance: none;
  width: 100%;
  padding: 0;
  border: 0;
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.3s ease;
  background: var(--panel);
}

.gallery-modal-grid-item:focus-visible {
  outline: 3px solid var(--accent2);
  outline-offset: 3px;
  transform: scale(1.02);
}

.gallery-modal-grid-item:hover {
  transform: scale(1.05);
  z-index: 2;
}

.gallery-modal-grid-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-modal-grid-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: gallery-spin 1s linear infinite;
}

.gallery-modal-grid-item img[src]:not([src=""])~.gallery-modal-grid-loader {
  display: none;
}

@keyframes gallery-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Fullscreen image viewer */
.gallery-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.98);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.gallery-fullscreen.active {
  display: flex;
}

.gallery-fullscreen-image {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
}

.gallery-fullscreen-close,
.gallery-fullscreen-prev,
.gallery-fullscreen-next {
  position: absolute;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  font-size: 2.5rem;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
  line-height: 1;
}

.gallery-fullscreen-close:hover,
.gallery-fullscreen-prev:hover,
.gallery-fullscreen-next:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.1);
}

.gallery-fullscreen-close {
  top: 20px;
  right: 20px;
}

.gallery-fullscreen-prev {
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.gallery-fullscreen-prev:hover {
  transform: translateY(-50%) scale(1.1);
}

.gallery-fullscreen-next {
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.gallery-fullscreen-next:hover {
  transform: translateY(-50%) scale(1.1);
}

.gallery-fullscreen-counter {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  backdrop-filter: blur(10px);
}

.gallery-fullscreen-error {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 1.25rem;
  text-align: center;
}

.gallery-modal-info {
  margin-top: 20px;
  text-align: center;
  color: #fff;
}

.gallery-modal-title {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 600;
}

.gallery-modal-counter {
  margin: 0;
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.7);
}

/* Responsive */
@media (max-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
  }

  .gallery-modal-content {
    padding: 50px 10px 10px;
  }

  .gallery-modal-close {
    width: 40px;
    height: 40px;
    font-size: 2rem;
    top: 10px;
    right: 10px;
  }

  .gallery-modal-header {
    margin-bottom: 20px;
  }

  .gallery-modal-images-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .gallery-fullscreen-close,
  .gallery-fullscreen-prev,
  .gallery-fullscreen-next {
    width: 40px;
    height: 40px;
    font-size: 2rem;
  }

  .gallery-fullscreen-prev {
    left: 10px;
  }

  .gallery-fullscreen-next {
    right: 10px;
  }

  .gallery-fullscreen-counter {
    bottom: 20px;
    font-size: 0.85rem;
    padding: 6px 16px;
  }
}
