/* Scroll-scrubbed accordion leporello. Timing lives in js/leporello.js */

html:has([data-leporello]) {
  scroll-behavior: auto;
}

.leporello-flow,
.leporello {
  --lepo-stage: var(--ww-bg, #fff);
}

.leporello-flow {
  position: relative;
  width: 100%;
  min-height: 100svh;
  margin: 8px 0 0;
  background: var(--lepo-stage);
  transition: background-color var(--ww-theme-duration, 0.9s) var(--ww-theme-ease, ease);
}

.leporello {
  --lepo-paper: #ffffff;
  --lepo-page-w: 1187;
  --lepo-page-h: 2552;
  position: relative;
  z-index: 2;
  isolation: isolate;
  width: 100%;
  margin: 0;
  overflow: visible;
  background: var(--lepo-stage);
  transition: background-color var(--ww-theme-duration, 0.9s) var(--ww-theme-ease, ease);
}

.leporello__stage {
  position: relative;
  height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  box-sizing: border-box;
  perspective: 1600px;
  perspective-origin: 50% 50%;
  overflow: visible;
  touch-action: pan-y;
  background: var(--lepo-stage);
  transition: background-color var(--ww-theme-duration, 0.9s) var(--ww-theme-ease, ease);
}

.leporello__backdrop {
  position: absolute;
  top: 8px;
  right: 0;
  bottom: 8px;
  left: 0;
  z-index: 0;
  overflow: hidden;
  border-radius: var(--ww-radius, 5px);
  pointer-events: none;
}

.leporello__backdrop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.leporello__scene {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  transform-style: preserve-3d;
}

.leporello__fit {
  --page-h: min(68svh, calc(100svh - 16px), 820px);
  --page-w: calc(var(--page-h) * var(--lepo-page-w) / var(--lepo-page-h));
  position: relative;
  z-index: 1;
  width: var(--page-w);
  height: var(--page-h);
  transform-style: preserve-3d;
  transform-origin: center center;
}

.leporello__orbit {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: 50% 50%;
}

.leporello__rig {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--page-w);
  height: 100%;
  transform-style: preserve-3d;
}

.leporello__panel {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--page-w);
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  background: var(--lepo-paper);
}

.leporello__panel > .leporello__panel {
  left: calc(100% - 1px);
}

.leporello__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--lepo-paper);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.leporello__panel > .leporello__panel > .leporello__face--front {
  border-left: 1px solid rgba(0, 0, 0, 0.12);
}

.leporello__face--back {
  transform: rotateY(180deg);
}

.leporello__face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  background: var(--lepo-paper);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* ——— Reduced motion ——— */

.leporello--reduced {
  margin-top: 8px;
  margin-bottom: 48px;
}

.leporello--reduced .leporello__backdrop {
  display: none;
}

.leporello--reduced .leporello__stage {
  display: none;
}

.leporello__reduced {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.leporello__reduced-sheet {
  margin: 0;
}

.leporello__reduced-frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: var(--lepo-paper);
  border-radius: var(--ww-radius, 5px);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
}

.leporello__reduced-frame img {
  width: 100%;
  height: auto;
  aspect-ratio: 4749 / 2552;
  object-fit: contain;
  display: block;
  background: var(--lepo-paper);
}

.leporello__reduced-sheet figcaption {
  margin-top: 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ww-muted);
}

/* Mobile: keep closed / one-panel size. Never shrink to fit all n panels. */
.leporello--mobile,
.leporello--mobile .leporello__stage,
.leporello--mobile .leporello__scene {
  overflow: hidden;
}

.leporello--mobile .leporello__stage {
  border-radius: var(--ww-radius, 5px);
}

.leporello--mobile .leporello__fit {
  --page-h: min(78svh, calc(100svh - 24px));
}

@media (max-width: 809px) {
  .leporello__stage {
    overflow: hidden;
    border-radius: var(--ww-radius, 5px);
  }

  .leporello__scene {
    overflow: hidden;
  }

  .leporello__fit {
    --page-h: min(78svh, calc(100svh - 24px));
  }
}
