/* ============================================================
   ÉKO '77 — GALLERY
   Loads after style.css. Only what the design system does not
   already carry: the justified photo grid and the lightbox.
   ============================================================ */

/* ------------------------------------------------------------
   MASTHEAD — one dark block, then straight into the pictures
   ------------------------------------------------------------ */

.gal-head {
  position: relative;
  overflow: hidden;
  padding-top: clamp(112px, 15vw, 176px);
  padding-bottom: clamp(44px, 6vw, 76px);
}
.gal-head::before {
  content: "";
  position: absolute; inset: 0;
  background-image: url("../img/adire.png?v=3");
  background-size: var(--adire) var(--adire);
  opacity: .085;
  pointer-events: none;
}
.gal-head > .gal-wrap { position: relative; z-index: 1; }
.gal-head .whisper { color: rgba(243,238,227,.66); }
.gal-head h1 { color: var(--paper); }
.gal-head__note {
  margin: 20px 0 0;
  max-width: 44ch;
  font-size: 17px;
  line-height: 1.6;
  color: rgba(243,238,227,.74);
}

/* ------------------------------------------------------------
   SECTIONS
   ------------------------------------------------------------ */

.gal-wrap {
  max-width: 1440px;
  margin-inline: auto;
  padding-inline: var(--gut);
}

.gal-sec__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 16px;
  margin-bottom: clamp(16px, 2.2vw, 28px);
  border-bottom: 1px solid var(--rule);
}
.gal-sec__head .whisper { margin-bottom: 7px; }
.gal-sec__n { white-space: nowrap; padding-bottom: 5px; }

/* ------------------------------------------------------------
   THE GRID
   A justified row layout: every frame in a row grows in exact
   proportion to its own aspect ratio, so the row squares off at
   the bottom without a single pixel of crop. Upright pictures
   stay upright, wide ones stay wide.
   ------------------------------------------------------------ */

.gal-grid {
  --h: 178px;                       /* target row height */
  display: flex;
  flex-wrap: wrap;
  gap: clamp(8px, 1vw, 15px);
  margin: 0;
  padding: 0;
}
@media (min-width: 561px)  { .gal-grid { --h: 236px; } }
@media (min-width: 901px)  { .gal-grid { --h: 296px; } }
@media (min-width: 1200px) { .gal-grid { --h: 336px; } }

/* the rooms come from small source files — they are held back a
   size so they never get asked to do more than they can */
.gal-grid--rooms { --h: 166px; }
@media (min-width: 561px)  { .gal-grid--rooms { --h: 200px; } }
@media (min-width: 901px)  { .gal-grid--rooms { --h: 248px; } }
@media (min-width: 1200px) { .gal-grid--rooms { --h: 320px; } }

.gal-item {
  /* grow in proportion to the frame's own ratio — scaled by 100 so a row
     holding a single upright frame still adds up to more than 1 and fills */
  flex-grow: calc(var(--ar) * 100);
  flex-shrink: 1;
  flex-basis: calc(var(--ar) * var(--h));
  min-width: 0;
  position: relative;
  display: block;
  overflow: hidden;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--paper-2);
  cursor: zoom-in;
  -webkit-appearance: none;
          appearance: none;
  -webkit-tap-highlight-color: transparent;
}
.gal-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .8s cubic-bezier(.2,.7,.3,1), opacity .6s ease;
}
/* hairline edge, the same one the archive plates wear */
.gal-item::after {
  content: "";
  position: absolute; inset: 0;
  box-shadow: inset 0 0 0 1px rgba(28,25,23,.14);
  pointer-events: none;
  transition: box-shadow .35s ease;
}
@media (hover: hover) {
  .gal-item:hover img { transform: scale(1.045); }
  .gal-item:hover::after { box-shadow: inset 0 0 0 1px rgba(28,25,23,.4); }
}
.gal-item:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

/* absorbs the slack in the final row so two orphans are not
   blown up to the width of the page */
.gal-fill { flex: 9999999 1 0; height: 0; }

/* fade each frame in as it decodes — only when the script is
   running, so a broken script never hides the photographs */
.gal-grid.is-js .gal-item img { opacity: 0; }
.gal-grid.is-js .gal-item img.is-on { opacity: 1; }

/* ------------------------------------------------------------
   CLOSING BAND
   ------------------------------------------------------------ */

.gal-end .whisper { margin-bottom: 12px; }
.gal-end .btn-row { margin-top: 26px; }

/* ------------------------------------------------------------
   LIGHTBOX
   ------------------------------------------------------------ */

.lb[hidden] { display: none; }
.lb {
  --lb-px: clamp(12px, 5vw, 96px);      /* stage padding, sides   */
  --lb-pt: clamp(46px, 6vw, 64px);      /* stage padding, top     */
  --lb-pb: clamp(12px, 2vw, 28px);      /* stage padding, bottom  */
  --lb-bar: 46px;                       /* the counter row        */

  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  grid-template-rows: minmax(0, 1fr) var(--lb-bar);
  background: rgba(11, 10, 8, .975);
  touch-action: none;
  animation: lbIn .28s ease both;
}
@keyframes lbIn { from { opacity: 0; } to { opacity: 1; } }

.lb__stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: var(--lb-pt) var(--lb-px) var(--lb-pb);
}

/* the frame is measured against the viewport rather than a percentage of a
   grid area — percentages of an auto-height ancestor quietly resolve to none,
   and the picture spills off the bottom of the screen. --cw / --ch come from
   the script and stop a small original being blown past twice its own size. */
.lb__img {
  display: block;
  width: auto;
  height: auto;
  object-fit: cover;
  max-width: min(100%, var(--cw, 100%));
  max-height: min(calc(100vh - var(--lb-bar) - var(--lb-pt) - var(--lb-pb)), var(--ch, 100vh));
  border: 6px solid var(--paper);
  background: var(--night-2);
  opacity: 0;
  transition: opacity .3s ease;
}
@supports (height: 100dvh) {
  .lb__img {
    max-height: min(calc(100dvh - var(--lb-bar) - var(--lb-pt) - var(--lb-pb)), var(--ch, 100dvh));
  }
}
.lb__img.is-on { opacity: 1; }

/* controls ---------------------------------------------------- */

.lb__btn {
  position: absolute;
  z-index: 2;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(243,238,227,.38);
  border-radius: 50%;
  background: rgba(11,10,8,.5);
  color: var(--paper);
  cursor: pointer;
  transition: background .25s ease, border-color .25s ease, transform .25s ease;
  -webkit-tap-highlight-color: transparent;
}
.lb__btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) {
  .lb__btn:hover { background: var(--paper); border-color: var(--paper); color: var(--ink); }
}
.lb__btn:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

.lb__close { top: clamp(10px, 2vw, 22px); right: clamp(10px, 2vw, 22px); }
.lb__prev, .lb__next { top: 50%; transform: translateY(-50%); }
.lb__prev { left: clamp(8px, 1.6vw, 22px); }
.lb__next { right: clamp(8px, 1.6vw, 22px); }
@media (hover: hover) {
  .lb__prev:hover { transform: translateY(-50%) translateX(-2px); }
  .lb__next:hover { transform: translateY(-50%) translateX(2px); }
}

.lb__bar {
  height: var(--lb-bar);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 16px;
}
.lb__count {
  margin: 0;
  color: rgba(243,238,227,.62);
  font-variant-numeric: tabular-nums;
}
.lb__hint {
  margin: 0;
  color: rgba(243,238,227,.34);
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .17em;
  text-transform: uppercase;
}

/* ------------------------------------------------------------
   SMALL SCREENS
   ------------------------------------------------------------ */

@media (max-width: 900px) {
  .gal-head__note { font-size: 16px; }

  .lb { --lb-px: 10px; --lb-pt: 62px; --lb-pb: 8px; --lb-bar: 44px; }
  .lb__btn { width: 44px; height: 44px; }
  .lb__img { border-width: 4px; }
  .lb__prev { left: 8px; }
  .lb__next { right: 8px; }
  .lb__hint { display: none; }
}

@media (max-width: 560px) {
  .gal-sec__head { display: block; }
  .gal-sec__n { margin: 12px 0 0; padding-bottom: 0; }
}
