html.history-open { overflow: hidden; }

.history-dialog {
  width: min(calc(100% - 3rem), 98rem);
  height: min(calc(100svh - 4.6rem), 64rem);
  max-width: none;
  max-height: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid #ffffff18;
  border-radius: .85rem;
  color: var(--ink);
  background: #060606;
}
.history-dialog[open] { animation: history-open .32s cubic-bezier(.2, .75, .28, 1) both; }
.history-dialog::backdrop { background: #000d; backdrop-filter: blur(10px); }
@keyframes history-open { from { opacity: 0; scale: .982; } to { opacity: 1; scale: 1; } }

.history-close {
  position: absolute;
  z-index: 4;
  top: clamp(.85rem, 1.55vw, 1.35rem);
  right: clamp(.85rem, 1.55vw, 1.35rem);
  width: 2.8rem;
  height: 2.8rem;
  padding: 0;
  display: grid;
  place-items: center;
  color: white;
  background: #161616bd;
  backdrop-filter: blur(12px);
  border: 1px solid #ffffff31;
  border-radius: 50%;
  cursor: pointer;
  transition: background .18s;
}
.history-close:hover { background: #3c3c3ce0; }
.history-close .icon { width: 1.3rem; height: 1.3rem; }

.history-scroll {
  --history-height: 100svh;
  height: 100%;
  overflow: hidden auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  scrollbar-width: none;
  scroll-behavior: auto;
  touch-action: pan-y;
}
.history-scroll::-webkit-scrollbar { display: none; }
.history-scroll:focus-visible { outline-offset: -3px; }
.history-track { min-height: calc(var(--history-height) * var(--history-viewports, 15)); }
.history-stage {
  position: sticky;
  top: 0;
  height: var(--history-height);
  overflow: hidden;
  isolation: isolate;
  background: #060606;
}

.history-scene {
  --focus-x: 50%;
  --focus-y: 50%;
  --photo-x: var(--focus-x);
  --pivot-x: var(--focus-x);
  --subject-growth: .175;
  --subject-fit: cover;
  --depth-progress: 0;
  --grade: #943b0618;
  --saturation: 1.08;
  position: absolute;
  inset: 0;
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  background: #060606;
}
.history-scene.is-current { visibility: visible; opacity: var(--frame-opacity, 1); }
.history-scene[data-tone="archive"] { --grade: #a76c341a; --saturation: .91; }
.history-scene[data-tone="cool"] { --grade: #1a3b6a1c; --saturation: 1.03; }
.history-scene[data-tone="final"] { --grade: #1d2c4714; --saturation: 1.08; }
.history-scene[data-framing="object"] {
  --subject-fit: contain;
  --subject-growth: .115;
}
.history-shot {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: var(--pivot-x) var(--focus-y);
}
.history-shot {
  object-fit: cover;
  object-position: var(--photo-x) var(--focus-y);
  transform: scale(calc(1.025 + .14 * var(--depth-progress)));
  filter: saturate(var(--saturation));
}
.history-depth {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: saturate(var(--saturation));
  pointer-events: none;
}

.history-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(0deg, #030305f0, #030305ba 12%, #03030558 27%, transparent 51%),
    linear-gradient(137deg, var(--grade), transparent 63%);
  pointer-events: none;
}
.history-caption {
  position: absolute;
  z-index: 2;
  inset: auto clamp(1.6rem, 5.35vw, 5.5rem) clamp(2.15rem, 6.4vh, 5.4rem);
  max-width: 31ch;
  margin: 0;
  color: #fff;
  font-size: clamp(1.5rem, 3.55vw, 3.6rem);
  font-weight: 630;
  line-height: 1.09;
  letter-spacing: -.041em;
  text-wrap: balance;
  text-shadow: 0 .125rem .85rem #000a;
  pointer-events: none;
}
.history-soundtrack { display: none; }

.history-credits {
  max-width: 47rem;
  padding-block: clamp(2.8rem, 7vw, 6rem);
  line-height: 1.65;
}
.history-credits h1 {
  margin-block: .6rem 1rem;
  font-size: clamp(2.6rem, 6vw, 5rem);
  line-height: 1;
  letter-spacing: -.055em;
}
.history-credits h2 { margin-block: 2.3rem .8rem; font-size: 1.4rem; }
.history-credits p, .history-credits li { color: var(--muted); }
.history-credits ol { padding-inline-start: 1.35rem; }
.history-credits li + li { margin-top: .64rem; }
.history-credits strong, .history-credits a { color: var(--ink); }
.history-credits a { text-decoration: underline; text-underline-offset: .2em; }

@media (max-width: 640px) {
  .history-dialog {
    width: 100%;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .history-close { top: max(.85rem, env(safe-area-inset-top)); }
  .history-caption {
    inset: auto 1.45rem max(2.4rem, calc(env(safe-area-inset-bottom) + 1.65rem));
    font-size: clamp(1.42rem, 6.2vw, 2.4rem);
  }
}

@media (max-width: 640px) and (orientation: portrait) {
  .history-scene {
    --photo-x: var(--portrait-x, var(--focus-x));
    --pivot-x: var(--portrait-pivot, var(--focus-x));
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .history-dialog { height: calc(100svh - 1.1rem); }
  .history-caption { bottom: 1.45rem; font-size: clamp(1.35rem, 3.2vw, 2.2rem); }
}

@media (prefers-reduced-motion: reduce) {
  .history-dialog[open] { animation: none; }
  .history-scene.is-current { opacity: 1; }
  .history-depth { display: none; }
  .history-scene .history-shot {
    object-fit: var(--subject-fit);
    transform: none;
    filter: none !important;
  }
}
