/* History gallery modal — fade in fast, blurred backdrop */

.gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.gallery-modal.is-open {
  display: flex;
}

.gallery-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 5, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  /* fast fade of the blurred backdrop */
  opacity: 0;
  transition: opacity 0.18s var(--ease-out);
}

.gallery-modal.is-open .gallery-modal__backdrop {
  opacity: 1;
}

.gallery-modal__panel {
  position: relative;
  z-index: 1;
  width: min(100%, 1040px);
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  overflow: hidden;
  /* fast fade/slide in */
  opacity: 0;
  transform: translateY(14px) scale(0.99);
  transition: opacity 0.18s var(--ease-out), transform 0.18s var(--ease-out);
}

.gallery-modal.is-open .gallery-modal__panel {
  opacity: 1;
  transform: none;
}

.gallery-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

/* Tabs */
.gallery-tabs {
  display: flex;
  gap: var(--space-2);
  margin-inline: auto;
}

.gallery-tab {
  padding: 0.5rem 1.1rem;
  font-size: var(--text-small);
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.gallery-tab:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.gallery-tab.is-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.gallery-modal__body {
  overflow-y: auto;
}

/* Generic hidden utility used by tabs */
.hidden {
  display: none !important;
}

.gallery-modal__grid,
.gallery-credits {
  min-height: 200px;
}

.gallery-modal__grid.is-hidden,
.gallery-credits.hidden {
  display: none !important;
}

.gallery-modal__close {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  transition: color 0.2s, border-color 0.2s;
}

.gallery-modal__close:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.gallery-modal__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-4);
  padding: var(--space-5);
  overflow-y: auto;
}

/* Credits (resume) layout */
.gallery-credits {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-6);
  padding: var(--space-6) var(--space-5);
}

/* Large group (TV, 54 entries) spans 2/3 width */
.gallery-credits__group--wide {
  grid-column: span 2;
}

@media (max-width: 900px) {
  .gallery-credits {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .gallery-credits__group--wide {
    grid-column: span 2;
  }
}

@media (max-width: 620px) {
  .gallery-credits {
    grid-template-columns: minmax(0, 1fr);
  }
  .gallery-credits__group--wide {
    grid-column: auto;
  }
}

.gallery-credits__discogs {
  grid-column: 1 / -1;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.5rem 1.1rem;
  font-size: var(--text-small);
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  transition: background 0.2s var(--ease-out), transform 0.2s;
}

.gallery-credits__discogs:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.gallery-credits__section {
  font-family: var(--font-display);
  font-size: var(--text-h4);
  color: var(--accent);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}

.gallery-credits__list {
  list-style: none;
  display: grid;
  gap: var(--space-1);
}

/* Long lists (e.g. TV with 54 entries) condense into multiple columns */
.gallery-credits__list--cols {
  display: block;
  columns: 4;
  column-gap: var(--space-7);
  column-rule: 1px solid var(--border-subtle);
  break-inside: avoid;
}

.gallery-credits__list--cols li {
  break-inside: avoid;
  margin-bottom: var(--space-3);
  padding-right: var(--space-3);
  line-height: 1.55;
}

.gallery-credits__list--cols li:last-child {
  margin-bottom: 0;
}

@media (max-width: 900px) {
  .gallery-credits__list--cols {
    columns: 3;
  }
}

@media (max-width: 620px) {
  .gallery-credits__list--cols {
    columns: 2;
    column-gap: var(--space-4);
  }
}

.gallery-credits__list li {
  color: var(--text-secondary);
  font-size: var(--text-small);
  line-height: 1.5;
  padding: 2px 0;
}

.gallery-modal__grid img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  cursor: zoom-in;
  transition: transform 0.2s var(--ease-out), border-color 0.2s;
}

.gallery-modal__grid img:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
}

/* Lightbox zoom view */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: rgba(5, 5, 5, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.gallery-lightbox.is-open {
  display: flex;
}

.gallery-lightbox img {
  max-width: 90vw;
  max-height: 88vh;
  box-shadow: var(--shadow-elevated);
}

.gallery-lightbox__close {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
  width: 44px;
  height: 44px;
  font-size: 2rem;
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .gallery-modal__backdrop,
  .gallery-modal__panel {
    transition: none;
  }
}
