/* ==========================================================================
   coverflow.css — Photo room carousel + lightbox (js/coverflow.js)
   The stage is a physical "table" in both themes, so its ink is fixed.
   html.js (set in <head>) switches the list from a scroll-snap row to the
   3D stage before first paint, so nothing shifts when the script runs.
   ========================================================================== */
.cf-section {
  padding-block-start: var(--space-8);
}

.cf-title {
  font-size: var(--step-2);
  line-height: var(--leading-snug);
}

.cf {
  --cf-card: clamp(148px, 22vw, 260px);
  margin-block-start: var(--space-4);
  padding-block: var(--space-6) var(--space-4);
  background-color: var(--room-accent);
  color: #3f3f3a; /* 7.4:1 on the stage grey */
  overflow: hidden;
  overflow: clip;
}

/* ---- Frame: same height with and without JS ---- */
.cf-frame {
  position: relative;
  block-size: calc(var(--cf-card) + 2 * var(--space-2));
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.cf-list {
  display: flex;
  gap: var(--space-2);
  block-size: 100%;
  margin: 0;
  padding: var(--space-2) var(--gutter);
  list-style: none;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.cf-list li { max-inline-size: none; }

.cf-card {
  display: block;
  flex: 0 0 var(--cf-card);
  inline-size: var(--cf-card);
  aspect-ratio: 1;
  border-radius: var(--radius-2);
  background-color: #cfcec8;
  box-shadow: 0 0 0 1px rgb(36 37 33 / 0.08);
  scroll-snap-align: center;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.cf-card img {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  pointer-events: none;
}

.cf-card:focus-visible {
  outline: 2px solid #242521;
  outline-offset: 4px;
}

/* ---- With JS: cards stacked in the centre, transforms from the script ---- */
.js .cf-list {
  display: block;
  padding: 0;
  overflow: visible;
  perspective: calc(var(--cf-card) * 3);
  transform-style: preserve-3d;
  /* 3D hit testing is unreliable: the frame takes the pointer and the
     script picks the card from its on-screen box */
  pointer-events: none;
}

.js .cf-list li {
  position: absolute;
  inset-block-start: var(--space-2);
  inset-inline-start: 50%;
  margin-inline-start: calc(var(--cf-card) / -2);
  transform-style: preserve-3d;
}

.js .cf-card {
  position: relative;
  opacity: 0; /* until the first paint from the script */
  backface-visibility: hidden;
  will-change: transform;
}

.js .cf-frame { cursor: pointer; }

/* ---- Controls: prev · caption · next ---- */
.cf-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-block-start: var(--space-3);
  padding-inline: var(--gutter);
  visibility: hidden; /* keeps its space without JS */
}

.js .cf-controls { visibility: visible; }

.cf-caption {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-inline-size: 10rem;
  font-size: var(--step--1);
  text-align: center;
}

.cf-genre {
  font-size: var(--step-0);
  font-weight: var(--weight-semibold);
  color: #242521;
}

.cf-count { font-variant-numeric: tabular-nums; }

.cf-btn,
.lb-btn {
  display: grid;
  place-items: center;
  inline-size: var(--space-6);
  block-size: var(--space-6);
  padding: 0;
  border: 1px solid rgb(36 37 33 / 0.3);
  border-radius: var(--radius-pill);
  background-color: transparent;
  color: #242521;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.cf-btn:hover { background-color: rgb(36 37 33 / 0.08); }
.cf-btn:focus-visible { outline: 2px solid #242521; outline-offset: 2px; }

/* ---- Lightbox: dark in both themes ---- */
html.lb-open { overflow: hidden; }

.lb {
  inline-size: 100%;
  block-size: 100%;
  max-inline-size: none;
  max-block-size: none;
  margin: 0;
  padding: var(--space-8) var(--space-2) var(--space-4);
  border: 0;
  background: transparent;
  color: #f5f3ee;
  overscroll-behavior: contain;
  touch-action: pan-y pinch-zoom;
}

.lb[open] {
  display: grid;
  place-items: center;
}

.lb::backdrop { background-color: rgb(20 21 18 / 0.94); }

.lb-figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
}

.lb-img {
  display: block;
  inline-size: auto;
  block-size: auto;
  max-inline-size: calc(100vw - 2 * var(--space-2));
  max-block-size: calc(100dvh - 12rem);
  border-radius: var(--radius-2);
  background-color: #2b2c28;
  user-select: none;
  -webkit-user-drag: none;
}

.lb-cap {
  display: flex;
  gap: var(--space-2);
  font-size: var(--step--1);
  color: rgb(245 243 238 / 0.8);
}

.lb-genre { font-weight: var(--weight-semibold); color: #f5f3ee; }
.lb-count { font-variant-numeric: tabular-nums; }

.lb-btn {
  position: fixed;
  border-color: rgb(245 243 238 / 0.3);
  background-color: rgb(20 21 18 / 0.6);
  color: #f5f3ee;
}

.lb-btn:hover { background-color: rgb(245 243 238 / 0.16); }
.lb-btn:focus-visible { outline: 2px solid #f5f3ee; outline-offset: 2px; }

.lb-close { inset-block-start: var(--space-2); inset-inline-end: var(--space-2); }
.lb-prev,
.lb-next { inset-block-start: 50%; translate: 0 -50%; }
.lb-prev { inset-inline-start: var(--space-2); }
.lb-next { inset-inline-end: var(--space-2); }

/* Wide screens: arrows sit beside the photo, not on it */
@media (min-width: 40em) {
  .lb { padding-inline: var(--space-10); }
  .lb-img { max-inline-size: calc(100vw - 2 * var(--space-10)); }
}

/* Phones: arrows at the bottom so they don't cover the photo */
@media (max-width: 39.99em) {
  .lb { padding-block-end: var(--space-10); }
  .lb-img { max-block-size: calc(100dvh - 14rem); }
  .lb-prev,
  .lb-next { inset-block-start: auto; inset-block-end: var(--space-2); translate: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .lb[open],
  .lb[open]::backdrop { animation: lb-in 200ms var(--ease-out); }
}

@keyframes lb-in { from { opacity: 0; } }
