/* ==========================================================================
   Gallery — /gallery/

   Additive only. Nothing here restyles a class owned by main.css; every colour,
   space, radius, shadow and font comes from a main.css custom property, so this
   file inherits the palette and spacing scale automatically. The two literals
   in this file are explained where they appear.

   States that must both work today:
     - photos present  -> the grid and the lightbox
     - no photos       -> the empty state under each section heading
   ========================================================================== */

:root {
  /* A scrim has to stay dark in both colour schemes, so it cannot be derived
     from a theme token: --color-bg is near-white in light mode, and a light
     scrim behind a photo is not a scrim. One named literal, used everywhere. */
  --gallery-scrim: rgb(8 10 14 / 0.9);
  --gallery-tile-ratio: 4 / 3;
  --gallery-tile-min: 260px;
}

/* --------------------------------------------------------------- intro prose */

.gallery-prose {
  margin-bottom: var(--space-2xl);
}

/* ------------------------------------------------------------------ sections */

.gallery-section {
  margin-bottom: var(--space-3xl);
}

.gallery-section__title {
  margin: 0 0 var(--space-lg);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
  font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.6rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-text);
}

/* --------------------------------------------------------------------- grid */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--gallery-tile-min), 1fr));
  gap: var(--space-lg);
  margin: 0;
  padding: 0;
  list-style: none;
}

.gallery-tile {
  margin: 0;
}

.gallery-tile__link {
  display: block;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-alt);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  transition: transform var(--transition), box-shadow var(--transition),
              border-color var(--transition);
}

/* A fixed ratio plus object-fit means a mixed portrait/landscape set still
   forms a clean grid instead of a ragged one. */
.gallery-tile__img {
  display: block;
  width: 100%;
  aspect-ratio: var(--gallery-tile-ratio);
  object-fit: cover;
  background: var(--color-bg-alt);
}

.gallery-tile__caption {
  display: block;
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--color-text-muted);
}

@media (hover: hover) {
  .gallery-tile__link:hover {
    transform: translateY(-2px);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
  }
}

/* Keyboard focus on a tile has to be clearly visible: these are links, and a
   photo grid is otherwise a field of unlabelled rectangles to a keyboard user. */
.gallery-tile__link:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
  border-color: var(--color-focus);
}

/* -------------------------------------------------------------- empty state */

.gallery-empty {
  padding: var(--space-xl);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-bg-alt);
}

.gallery-empty__lead {
  margin: 0 0 var(--space-sm);
  font-weight: 600;
  color: var(--color-text);
}

.gallery-empty__body {
  margin: 0 0 var(--space-sm);
  max-width: 62ch;
  color: var(--color-text-muted);
}

.gallery-empty__body code,
.gallery-empty__command {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

.gallery-empty__body code {
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  background: var(--color-code-bg);
  color: var(--color-text);
  word-break: break-word;
}

.gallery-empty__command {
  margin: 0 0 var(--space-md);
  padding: var(--space-sm) var(--space-md);
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-code-bg);
  color: var(--color-text);
}

/* ------------------------------------------------------------------ lightbox */

.gallery-lightbox[hidden] {
  display: none;
}

.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  background: var(--gallery-scrim);
  animation: gallery-fade var(--transition) ease-out;
}

@keyframes gallery-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.gallery-lightbox__backdrop {
  position: absolute;
  inset: 0;
  cursor: zoom-out;
}

.gallery-lightbox__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: min(100%, 1100px);
  max-height: 100%;
  padding: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg);
  box-shadow: var(--shadow-lg);
}

.gallery-lightbox__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.gallery-lightbox__counter {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.gallery-lightbox__image {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  margin: 0 auto;
  border-radius: var(--radius-sm);
  object-fit: contain;
  background: var(--color-bg-alt);
}

.gallery-lightbox__foot {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.gallery-lightbox__caption {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: 0.9375rem;
  color: var(--color-text);
}

.gallery-lightbox__btn,
.gallery-lightbox__nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0 var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-alt);
  color: var(--color-text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.gallery-lightbox__nav {
  font-size: 1.125rem;
}

@media (hover: hover) {
  .gallery-lightbox__btn:hover,
  .gallery-lightbox__nav:hover {
    border-color: var(--color-primary);
    background: var(--color-bg-alt);
  }
}

.gallery-lightbox__btn:focus-visible,
.gallery-lightbox__nav:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

/* Body scroll lock while the overlay is open, so the page behind does not move
   under the dialog. Toggled by gallery.js on <body>. */
body.gallery-lightbox-open {
  overflow: hidden;
}

/* ------------------------------------------------------------------ responsive */

@media (max-width: 768px) {
  :root {
    --gallery-tile-min: 150px;
  }

  .gallery-lightbox {
    padding: var(--space-sm);
  }

  .gallery-lightbox__image {
    max-height: 60vh;
  }
}

@media (max-width: 480px) {
  :root {
    --gallery-tile-min: 132px;
  }
}

/* ------------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  .gallery-lightbox {
    animation: none;
  }

  .gallery-tile__link {
    transition: none;
  }

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

/* ---------------------------------------------------------------------- print */

@media print {
  .gallery-grid,
  .gallery-lightbox {
    display: none;
  }

  .gallery-empty {
    border-style: solid;
  }
}
