/* Lightbox: photo first, the story is on its back. Fonts and colours from main.css
   Desktop, portrait photo:  photo stays, the text unfolds in the free space beside it   (data-layout="beside")
   Desktop, landscape photo: photo slides aside and shrinks, the text unfolds next to it (data-layout="push")
   Both on desktop: the whole screen takes on the photo's colours as a heavy blur.
   Phone: tap opens fullscreen, the turn button flips the photo, the back shows the text on the blurred photo. */
:root { --lb-story-w: min(440px, 34vw); --lb-ease: cubic-bezier(.65, 0, .35, 1); --lb-paper: #15120f; }

.lightbox {
  position: fixed; inset: 0; z-index: 500; isolation: isolate; overflow: hidden;
  background: rgba(0, 0, 0, .97); color: #fff;
  display: grid; grid-template-columns: 1fr 0px; grid-template-rows: 1fr auto;
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease, grid-template-columns .8s var(--lb-ease);
}
.lightbox.active { opacity: 1; pointer-events: all; }

/* ambient wash in the photo's colours, far beyond recognition */
.lightbox::before {
  content: ''; position: absolute; inset: -20%; z-index: -1; pointer-events: none;
  background: var(--story-bg, none) center / cover no-repeat;
  filter: blur(120px) saturate(1.35) brightness(.5);
  opacity: 0; transition: opacity 1s ease;
}
.lightbox.story-open::before { opacity: 1; }

.lightbox__stage {
  grid-column: 1; grid-row: 1;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; min-height: 0; padding: 24px 64px 0;
}
.lightbox__image {
  max-width: 100%; max-height: 100%; object-fit: contain;
  user-select: none; -webkit-user-select: none; cursor: zoom-in;
}

/* Zoom: image at its own pixel size (CSS px), scroll or drag to move */
.lightbox.is-zoomed .lightbox__stage { display: block; overflow: auto; padding: 0; cursor: grab; touch-action: pan-x pan-y; }
.lightbox.is-zoomed .lightbox__stage.is-dragging { cursor: grabbing; }
.lightbox.is-zoomed .lightbox__image { max-width: none; max-height: none; cursor: inherit; margin: auto; }

/* ---------- Story ---------- */
.lightbox__story {
  grid-column: 2; grid-row: 1 / span 2;
  position: relative; isolation: isolate; overflow: hidden; min-width: 0;
  perspective: 1400px; perspective-origin: 0 50%;
  border-left: 1px solid rgba(255, 255, 255, .1);
  pointer-events: none;
}
.lightbox.story-open .lightbox__story { pointer-events: auto; }
.lightbox__story-inner {
  position: relative; width: var(--lb-story-w); height: 100%; overflow-y: auto;
  padding: 88px 40px 48px;
  font-family: var(--serif); font-size: 19px; line-height: 1.75; color: rgba(255, 255, 255, .9);
  transform-origin: 0 50%; transform: rotateY(-80deg); opacity: 0;
  transition: transform .8s var(--lb-ease), opacity .45s ease;
}
.lightbox.story-open .lightbox__story-inner { transform: none; opacity: 1; transition-delay: .12s, .2s; }
.lightbox__story-meta {
  font-family: var(--sans); font-size: 12px; letter-spacing: .22em; text-transform: uppercase;
  color: #d3b29b; padding-bottom: 18px; margin-bottom: 28px; border-bottom: 1px solid rgba(255, 255, 255, .2);
}
.lightbox__story-inner p + p { margin-top: 1em; }
.lightbox__story-inner h2, .lightbox__story-inner h3 { font-family: var(--sans); font-weight: 300; font-size: 26px; margin-bottom: .6em; }
/* browsing with the story open: the text changes with a short fade */
.lightbox__story-text.is-new { animation: story-swap .5s ease both; }
@keyframes story-swap { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* the photo turns slightly while the text unfolds */
.lightbox.story-open .lightbox__image { animation: lb-turn 1s var(--lb-ease); }
@keyframes lb-turn {
  0% { transform: perspective(1600px) rotateY(0); }
  45% { transform: perspective(1600px) rotateY(-22deg) scale(.97); }
  100% { transform: perspective(1600px) rotateY(0); }
}

/* Landscape: photo slides aside */
.lightbox[data-layout="push"].story-open { grid-template-columns: 1fr var(--lb-story-w); }
/* Portrait: photo stays, text in the free space beside it, top-aligned with the photo (positions from lightbox.js) */
.lightbox[data-layout="beside"] .lightbox__story {
  grid-column: 1 / -1; grid-row: 1 / -1; /* containing block = the whole lightbox */
  position: absolute; left: var(--beside-left); top: var(--beside-top);
  width: var(--beside-w); height: var(--beside-h); border-left: 0;
}
.lightbox[data-layout="beside"] .lightbox__story-inner { width: 100%; padding: 0 0 24px; }

/* ---------- Toolbar ---------- */
.lightbox__bar {
  grid-column: 1; grid-row: 2;
  display: flex; align-items: center; justify-content: flex-end; gap: 6px;
  padding: 10px 16px 14px;
}
.lightbox__counter { margin-right: auto; font-size: 13px; letter-spacing: .1em; opacity: .5; }
.lightbox__btn {
  font: inherit; font-size: 14px; color: #fff; background: none;
  border: 1px solid rgba(255, 255, 255, .25); border-radius: 3px;
  padding: 4px 12px; cursor: pointer; opacity: .75;
}
.lightbox__btn:hover, .lightbox__btn[aria-pressed="true"] { opacity: 1; border-color: #fff; }
.lightbox__btn[hidden] { display: none; }

/* Turn button: two arrows chasing each other, icon only */
.lightbox__turn {
  width: 40px; height: 40px; display: grid; place-items: center;
  color: #fff; background: none; border: 1px solid rgba(255, 255, 255, .3); border-radius: 50%;
  cursor: pointer; opacity: .8; transition: opacity .2s, border-color .2s;
}
.lightbox__turn:hover, .lightbox__turn[aria-pressed="true"] { opacity: 1; border-color: #fff; }
.lightbox__turn[hidden] { display: none; }
.lightbox__turn svg { width: 20px; height: 20px; transition: transform .8s var(--lb-ease); }
.lightbox__turn[aria-pressed="true"] svg { transform: rotate(180deg); }

.lightbox__close { position: relative; width: 40px; height: 40px; background: none; border: 0; cursor: pointer; }
.lightbox__close::before, .lightbox__close::after {
  content: ''; position: absolute; top: 50%; left: 50%; width: 20px; height: 1px; background: #fff;
}
.lightbox__close::before { transform: translate(-50%, -50%) rotate(45deg); }
.lightbox__close::after { transform: translate(-50%, -50%) rotate(-45deg); }

.lightbox__nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: none; border: 0; color: #fff; font-size: 2.4rem;
  padding: 1rem; cursor: pointer; opacity: .5; transition: opacity .3s, right .8s var(--lb-ease);
}
.lightbox__nav:hover { opacity: 1; }
.lightbox__prev { left: 8px; }
.lightbox__next { right: 8px; }
.lightbox[data-layout="push"].story-open .lightbox__next { right: calc(var(--lb-story-w) + 8px); }
.lightbox.is-zoomed .lightbox__nav { opacity: .3; }

/* Grid marker for images that have a story */
.gallery-grid__item { position: relative; }
.gallery-grid__story-badge {
  position: absolute; left: 12px; bottom: 12px;
  font-size: 13px; letter-spacing: .08em; text-transform: uppercase;
  background: rgba(0, 0, 0, .55); color: #fff; padding: 2px 10px;
}

/* ---------- Phone: fullscreen photo, turn it over ---------- */
@media (max-width: 767px) {
  .lightbox, .lightbox.story-open, .lightbox[data-layout].story-open { grid-template-columns: 1fr; grid-template-rows: 1fr auto; background: #000; }
  .lightbox::before { display: none; }
  .lightbox.story-open .lightbox__image { animation: none; }
  /* the photo turns exactly around its own vertical axis, the back (same size) turns in */
  .lightbox__stage { padding: 0; }
  .lightbox__image { transition: transform .38s cubic-bezier(.5, 0, .75, 0) .38s, opacity 0s linear .76s; }
  .lightbox.story-open .lightbox__image { transform: perspective(1200px) rotateY(90deg); opacity: 0; transition: transform .38s cubic-bezier(.5, 0, .75, 0), opacity 0s linear .38s; }
  .lightbox__story, .lightbox[data-layout] .lightbox__story {
    position: relative; left: auto; top: auto; max-width: 100%;
    width: var(--card-w, 100%); height: max(var(--card-h, 100%), 62vh); max-height: 100%;
    justify-self: center; align-self: center;
    grid-column: 1; grid-row: 1; z-index: 2; perspective: none; border: 0;
    background: var(--lb-paper);
    transform: perspective(1200px) rotateY(-90deg); visibility: hidden;
    transition: transform .38s cubic-bezier(.5, 0, .75, 0), visibility 0s linear .38s;
  }
  .lightbox.story-open .lightbox__story {
    transform: perspective(1200px) rotateY(0deg); visibility: visible;
    transition: transform .38s cubic-bezier(.25, 1, .5, 1) .38s, visibility 0s linear .38s;
  }
  /* the back: the photo itself, heavily blurred and darkened */
  .lightbox__story::before, .lightbox__story::after { content: ''; position: absolute; z-index: -1; pointer-events: none; }
  .lightbox__story::before { inset: -80px; background: var(--story-bg, none) center / cover no-repeat; filter: blur(44px) saturate(1.15); }
  .lightbox__story::after { inset: 0; background: linear-gradient(rgba(12, 10, 8, .5), rgba(12, 10, 8, .74)); }
  .lightbox__story-inner, .lightbox[data-layout] .lightbox__story-inner, .lightbox.story-open .lightbox__story-inner {
    width: auto; transform: none; opacity: 1; transition: none; padding: 56px 24px 32px; font-size: 18px;
  }
  .lightbox__btn--zoom, .lightbox__btn--fs, .lightbox__nav { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox, .lightbox::before, .lightbox__story, .lightbox__story-inner, .lightbox__stage, .lightbox__nav, .lightbox__turn svg { transition: none !important; }
  .lightbox__story-text.is-new, .lightbox.story-open .lightbox__image { animation: none; }
}

/* During the morph between grid and lightbox the lightbox must not fade on its own */
.lightbox.no-fade { transition: none; }
