/* The original layered photo gallery, rendered in HTML and enhanced in place. */
.photo-stack-gallery {
  --card-size: clamp(150px, 50vw, 500px);
  --circle-radius: clamp(80px, 28vw, 280px);
  --background-shift: clamp(40px, 12.5vw, 125px);
  --jitter-unit: clamp(.35px, .1vw, 1px);
  position: relative;
  height: 90vh;
  min-height: 660px;
  max-height: 960px;
  margin: 20px auto;
  isolation: isolate;
}
.photo-stack-instructions {
  position: absolute;
  inset: 12px auto auto 20px;
  z-index: 48;
  font-size: .875rem;
  color: var(--text-muted);
}
.photo-stack-filters {
  position: absolute;
  top: 52px;
  left: 20px;
  width: 132px;
  z-index: 48;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.photo-stack-filters button, .photo-stack-controls button {
  min-height: 44px;
  border: 1px solid var(--text-muted);
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 6px 10px;
  font-size: .875rem;
  text-align: left;
  cursor: pointer;
}
.photo-stack-filters button:hover, .photo-stack-controls button:hover {
  border-color: var(--text-accent);
}
.photo-stack-filters button[aria-pressed="true"] {
  background: #ff9800;
  border-color: #ff9800;
  color: #292524;
}
.photo-stack-filters .photo-stack-edge {
  background: #57534e;
  color: #fff;
}
.photo-stack-filters .photo-stack-edge[data-edge-mode]:not([data-edge-mode="both"]) {
  background: var(--bg-accent);
  color: #fff;
}
.photo-stack-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
}
.photo-stack-card {
  position: absolute;
  left: 62%;
  top: 50%;
  width: calc(var(--card-size) * var(--width-ratio));
  height: calc(var(--card-size) * var(--height-ratio));
  margin: 0;
  border: 6px solid var(--frame-color);
  box-shadow: 5px 5px 15px rgba(0, 0, 0, .35);
  box-sizing: border-box;
  backface-visibility: hidden;
  overflow: hidden;
  cursor: pointer;
  transform: translate(-50%, -50%)
    translate(calc(var(--circle-x) * var(--circle-radius) + var(--jitter-x) * var(--jitter-unit)), calc(var(--circle-y) * var(--circle-radius) + var(--jitter-y) * var(--jitter-unit) + var(--background-shift)))
    rotate(var(--rotation)) scale(var(--stack-scale));
  filter: brightness(var(--brightness));
  z-index: var(--stack-order);
}
.photo-stack-card.photo-stack-tape { border-width: 15px; }
.photo-stack-card.is-focused {
  transform: translate(-50%, -50%) rotate(0deg) scale(1.15);
  filter: none;
  z-index: 32;
}
.photo-stack-gallery[data-enhanced] .photo-stack-card {
  transition: transform .5s ease, filter .5s ease;
}
.photo-stack-card > a {
  display: block;
  position: absolute;
  inset: -6px;
  padding: 6px;
  box-sizing: border-box;
}
.photo-stack-card.photo-stack-tape > a { inset: -15px; padding: 15px; }
.photo-stack-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #242426;
  pointer-events: none;
}
.photo-stack-card figcaption {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 100%;
  padding: 4px 8px;
  background: rgba(0, 0, 0, .85);
  color: #fff;
  font: 1.15rem/1.12 Caveat, "Segoe Print", cursive;
  pointer-events: none;
}
.photo-stack-card h2 { font: inherit; }
.photo-stack-card .photo-stack-caption {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.photo-stack-card.photo-stack-caption-vertical figcaption {
  writing-mode: vertical-rl;
  max-height: 100%;
  max-width: 3.2em;
  padding: 8px 4px;
}
.photo-stack-card.photo-stack-caption-right figcaption { left: auto; right: 0; }
.photo-stack-card .photo-stack-title, .photo-stack-card .photo-stack-categories {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.photo-stack-card:focus-within {
  outline: 3px solid #fff;
  outline-offset: 4px;
}
.photo-stack-controls {
  position: absolute;
  bottom: 10px;
  left: 62%;
  transform: translateX(-50%);
  z-index: 48;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  background: var(--bg-primary);
  border-radius: 6px;
}
.photo-stack-controls button { text-align: center; }
.photo-stack-status { min-width: 65px; text-align: center; font-size: .875rem; }
.photo-stack-empty {
  position: absolute;
  inset: 50% 20px auto;
  text-align: center;
  z-index: 33;
}
.photo-stack-empty[hidden], .photo-stack-card[hidden] { display: none; }
.photo-stack-modal {
  max-width: none;
  max-height: none;
  width: 100vw;
  height: 100dvh;
  margin: 0;
  border: 0;
  padding: 56px 24px 24px;
  color: #fff;
  background: rgba(0, 0, 0, .92);
}
.photo-stack-modal::backdrop { background: #000; }
.photo-stack-modal[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.photo-stack-modal figure { max-width: 94vw; margin: 0; text-align: center; }
.photo-stack-modal img { display: block; max-width: 100%; max-height: 72dvh; object-fit: contain; margin: auto; }
.photo-stack-modal h2 { font-weight: 700; margin-top: 12px; }
.photo-stack-modal figcaption p { margin-top: 6px; max-width: 820px; }
.photo-stack-modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 44px;
  height: 44px;
  font-size: 30px;
  color: #fff;
  background: #44403c;
  border-radius: 50%;
  cursor: pointer;
}
body:has(.photo-stack-modal[open]) { overflow: hidden; }
.light-theme .photo-stack-card:not(.is-focused) { filter: none; opacity: .65; }
@media (max-width: 800px), (orientation: portrait) {
  .photo-stack-gallery { min-height: 660px; height: 82vh; }
  .photo-stack-instructions { inset: 0 10px auto; text-align: center; }
  .photo-stack-filters {
    top: 56px;
    left: 0;
    right: 0;
    width: auto;
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px;
  }
  .photo-stack-filters > span { display: none; }
  .photo-stack-filters button { text-align: center; }
  .photo-stack-card { left: 50%; top: 55%; }
  .photo-stack-controls { left: 50%; width: max-content; max-width: 100%; }
  .photo-stack-card figcaption { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .photo-stack-gallery[data-enhanced] .photo-stack-card { transition: none; }
}
