/* Photo deck: stacked cards inside a project panel.
   deck.js sets --k on .deck (visible slivers) and --d / z-index on each .card (depth),
   and toggles .is-moving on .deck while a move ripples through the stack. */

.deck {
  --k: 0;
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--paper);
  container-type: size; /* lets the phone layout size the stack in cqw / cqh */
}

.deck-stage {
  position: absolute;
  inset: var(--deck-inset);
  z-index: 0;
  isolation: isolate;
  /* The deck reads every one-finger drag itself (deck.js); pinch-zoom stays with the browser. */
  touch-action: pinch-zoom;
}

.deck:not(.is-single) .deck-stage {
  cursor: pointer;
}

.deck-stage,
.card-img {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ---- Cards ---------------------------------------------------------------- */

.card {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0; /* <figure> has UA margins */
  height: 100%;
  width: calc(100% - var(--k) * var(--peek));
  overflow: hidden;
  border-radius: var(--radius);
  isolation: isolate; /* keeps the rounded clip intact in Safari while transformed */
  background: #cfcac3;
  transform-origin: 100% 50%;
  transform: translateX(calc(var(--d, 0) * var(--peek))) scale(calc(1 - var(--d, 0) * 0.06));
  /* Must equal SHADOW_REST in deck.js, which animates this shadow during a move. */
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.08),
    0 22px 44px -20px rgba(0, 0, 0, 0.42),
    20px 0 40px -18px rgba(0, 0, 0, 0.38);
  transition:
    transform var(--dur-deck) var(--ease-out),
    opacity 500ms ease,
    translate 500ms var(--ease-spring),
    rotate 500ms var(--ease-spring);
}

/* Depth tint: deeper cards read darker. */
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #000;
  opacity: calc(var(--d, 0) * 0.12);
  transition: opacity var(--dur-deck) var(--ease-out);
  pointer-events: none;
}

.card-media {
  position: absolute;
  inset: 0;
  display: flex;
}

.card--pair .card-media {
  gap: clamp(4px, 0.45vw, 8px);
  background: var(--paper);
}

.card-pane {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}

.card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  -webkit-user-drag: none;
}

.card.no-anim,
.card.no-anim::after {
  transition: none !important;
}

.card.is-buried {
  opacity: 0;
}

/* ---- Moves ---------------------------------------------------------------- */

/* While the stack moves, each card's spring waits for its depth, so the stack ripples back or forward. */
.deck.is-moving .card {
  transition:
    transform 900ms var(--ease-spring),
    opacity 500ms ease,
    translate 500ms var(--ease-spring),
    rotate 500ms var(--ease-spring);
  transition-delay: calc(var(--d, 0) * 55ms + 70ms);
}

.deck.is-moving .card::after {
  transition-delay: calc(var(--d, 0) * 55ms + 70ms);
}

/* Listed after the ripple, so a card grabbed mid-ripple follows the finger at once. */
.deck .card.is-dragging {
  transition: none;
}

/* ---- Scrim and caption ---------------------------------------------------- */

/* Each card carries its own scrim, so the white margin around the stack stays white. */
.card-scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to top, rgba(0, 0, 0, 0.46) 0%, rgba(0, 0, 0, 0.16) 26%, rgba(0, 0, 0, 0) 48%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.28) 0%, rgba(0, 0, 0, 0) 20%);
}

.deck-caption {
  position: absolute;
  z-index: 2;
  left: var(--gutter);
  bottom: var(--gutter);
  max-width: 60%;
  color: var(--on-photo);
  pointer-events: none;
}

.deck-kicker {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: var(--fs-label);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--on-photo-soft);
  opacity: 0;
  transform: translateY(10px);
}

.deck-kicker-sep {
  width: 24px;
  height: 1px;
  background: currentColor;
}

.deck-title {
  /* Extend the reveal mask below serif descenders without moving the caption. */
  margin: 0 0 -0.12em;
  padding-bottom: 0.18em;
  overflow: hidden;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: var(--fs-title);
  line-height: 0.95;
  letter-spacing: -0.015em;
}

.deck-title em {
  font-style: italic;
}

.deck-title-line {
  display: inline-block;
  transform: translateY(110%);
}

/* Revealed by sections.js, which sets .is-revealed on the .panel. */
.panel.is-revealed .deck-title-line {
  transform: none;
  transition: transform var(--dur-reveal) var(--ease-out) 0.2s;
}

.panel.is-revealed .deck-kicker {
  opacity: 1;
  transform: none;
  transition:
    opacity var(--dur-reveal) var(--ease-out) 0.45s,
    transform var(--dur-reveal) var(--ease-out) 0.45s;
}

.panel.is-revealed .deck.is-intro .deck-title-line {
  transition-delay: 0.8s;
}

.panel.is-revealed .deck.is-intro .deck-kicker {
  transition-delay: 1.05s;
}

/* ---- Controls ------------------------------------------------------------- */

.deck-controls {
  position: absolute;
  z-index: 2;
  right: calc(var(--gutter) + var(--k) * var(--peek));
  bottom: var(--gutter);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 16px;
  color: var(--on-photo);
}

.deck-room {
  display: grid;
  height: 1.3em;
  margin: 0;
  overflow: hidden;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: var(--fs-label);
  line-height: 1.3;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--on-photo-soft);
}

.deck-room > span,
.deck-current > span {
  grid-area: 1 / 1;
  white-space: nowrap;
}

.deck-nav {
  display: flex;
  align-items: center;
  gap: 14px;
}

.deck-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--hair-photo);
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}

.deck-btn svg {
  display: block;
  width: 18px;
  height: 18px;
}

.deck-btn:hover {
  background: #fff;
  color: var(--ink);
  border-color: #fff;
}

.deck-btn:focus-visible {
  outline: 1px solid #fff;
  outline-offset: 3px;
}

.deck-counter {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

/* Odometer window for the current number; deck.js rolls the inner spans. */
.deck-current {
  position: relative;
  display: inline-grid;
  height: 1.2em;
  overflow: hidden;
  line-height: 1.2;
}

.deck-counter-rule {
  width: 28px;
  height: 1px;
  background: var(--hair-photo);
}

/* A single-card deck has nothing to step through. */
.deck.is-single .deck-btn,
.deck.is-single .deck-counter {
  display: none;
}

/* While the deal-in waits for the first photo to decode, hide the chrome. */
.deck.is-hold .deck-stage,
.deck.is-hold .deck-caption,
.deck.is-hold .deck-controls {
  visibility: hidden;
}

/* ---- Mobile: portrait cards on paper -------------------------------------- */

/* Top to bottom: header space, the 2:3 card stack, then caption and controls in ink on white.
   cqw / cqh measure the .deck's content box, so its padding is already taken out. */
@media (max-width: 719px) and (min-height: 501px) {
  .deck {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding:
      calc(var(--header-h) + env(safe-area-inset-top))
      var(--gutter)
      calc(64px + env(safe-area-inset-bottom)); /* clear of the fixed scroll cue */
  }

  /* A card is the stage minus its slivers, 2:3 portrait; the second term keeps
     short phones from overflowing (150px is the caption, controls and gaps below the stack). */
  .deck-stage {
    position: relative;
    inset: auto;
    flex: none;
    height: max(
      0px,
      min(
        calc((100cqw - var(--k) * var(--peek)) * 1.5),
        calc(100cqh - 150px)
      )
    );
  }

  .card-scrim {
    display: none;
  }

  .deck-caption {
    position: static;
    flex: none;
    max-width: none;
    color: var(--ink);
  }

  .deck-kicker {
    margin: 18px 0 12px;
    color: var(--ink-soft);
  }

  .deck-title {
    margin-bottom: -0.08em;
    padding-bottom: 0.18em;
    font-size: clamp(34px, 10.5vw, 46px);
    line-height: 1;
  }

  /* Counter left, then the room; the buttons sit at the right. .deck-nav drops out of the
     layout so its children can be ordered alongside the room label. */
  .deck-controls {
    position: static;
    flex: none;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
    color: var(--ink);
  }

  .deck-nav {
    display: contents;
  }

  .deck-counter {
    order: 1;
  }

  .deck-room {
    order: 2;
    min-width: 0;
    margin: 0 auto 0 4px;
    color: var(--ink-soft);
  }

  .deck-prev {
    order: 3;
  }

  .deck-next {
    order: 4;
  }

  .deck-counter-rule {
    background: var(--hair);
  }

  .deck-btn {
    width: 40px;
    height: 40px;
    border-color: var(--hair);
  }

  .deck-btn:active {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
  }

  .deck-btn:focus-visible {
    outline-color: var(--ink);
  }
}

/* Hover is skipped on touch, where it would stay stuck after a tap. */
@media (max-width: 719px) and (min-height: 501px) and (hover: hover) {
  .deck-btn:hover {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
  }
}

/* ---- Reduced motion: instant swaps, no deal-in ---------------------------- */

@media (prefers-reduced-motion: reduce) {
  html:not(.force-motion) .card,
  html:not(.force-motion) .card::after,
  html:not(.force-motion) .deck-title-line,
  html:not(.force-motion) .deck-kicker {
    transition-duration: 1ms !important;
    transition-delay: 0s !important;
  }
}
