/* ---- Pinned scroll story ----
   Base styles are the final state (all layers out, tokens in place), shown as a normal section.
   Inside @supports + no-preference, the track grows tall, the stage sticks, and the --story
   view timeline drives every step. Step k owns the range [k*20%, (k+1)*20%] of the track. */
.story { padding-block: var(--inset); }
.story__stage { padding-block: 72px; }
.story__grid { display: grid; gap: 32px; align-items: center; }

.story__steps { display: grid; gap: 28px; }
.story__num { font-size: .75rem; letter-spacing: .06em; color: var(--on-panel-2); }
.story__step h3 { margin-top: 12px; font-size: var(--step-3); letter-spacing: -.05em; }
.story__step p { margin-top: 12px; max-width: 36ch; color: var(--on-panel-2); font-size: var(--step-1); }
.story__progress { display: none; }

/* Scene: one incident ticket and the layers built from it. */
.story__scene { --w: 270px; --h: 168px; --gap: 64px; --drop: 70px; position: relative; height: 420px; display: grid; place-items: center; perspective: 1600px; }
.scene__tilt {
  position: relative; width: var(--w); height: var(--h); transform-style: preserve-3d;
  transform: translateY(var(--drop)) rotateX(55deg) rotateZ(-34deg) scale(.94);
}
/* Faint dot ground beneath the stack. */
.scene__tilt::before {
  content: ""; position: absolute; inset: -60%; pointer-events: none;
  background: radial-gradient(circle, rgba(220, 235, 228, .22) 1px, transparent 1.4px) 0 0 / 22px 22px;
  mask-image: radial-gradient(closest-side, #000 25%, transparent);
  -webkit-mask-image: radial-gradient(closest-side, #000 25%, transparent);
  transform: translateZ(-30px);
}
.slab {
  position: absolute; inset: 0; padding: 14px 16px; overflow: hidden;
  border: 1px solid var(--panel-line-2); border-radius: 12px;
  background: rgba(16, 16, 16, .86);
  font-size: 11px; line-height: 1.5;
  transform: translateZ(calc(var(--z, 0) * var(--gap)));
}
.slab__tag { position: relative; height: 1.5em; font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--on-panel-2); }
.slab__tag > span { position: absolute; left: 0; top: 0; }
.slab__tag-raw { opacity: 0; }
.slab__tag-clear { color: var(--signal); }
.slab__id { margin-top: 10px; color: var(--on-panel-2); font-size: 10px; }
.slab__title { margin-top: 4px; font-size: 13px; letter-spacing: -.01em; color: var(--on-panel); }
.slab__pii { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

/* Redaction: the raw value blurs out of focus and a frosted token settles over it. */
.pii { position: relative; display: inline-grid; }
.pii > * { grid-area: 1 / 1; white-space: nowrap; }
.pii__raw { padding: 2px 6px; color: var(--on-panel); filter: blur(5px); opacity: .35; }
.pii__tok {
  z-index: 1; padding: 2px 6px; border-radius: 5px; text-align: center; font-size: 10px; letter-spacing: .05em;
  color: var(--on-panel); background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .28);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}

.slab__nodes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.slab__nodes span { padding: 10px 6px; text-align: center; border: 1px dashed var(--panel-line-2); border-radius: 6px; color: var(--on-panel-2); font-size: 10px; }
.slab--env { border-color: rgba(124, 242, 193, .65); background: rgba(8, 24, 18, .9); }
.slab--env .slab__tag { color: var(--signal); }
.slab__checks { display: grid; gap: 4px; margin-top: 10px; }
.slab__checks li { display: flex; align-items: center; gap: 8px; color: var(--on-panel-2); }
.slab__checks i { width: 8px; height: 8px; border-radius: 2px; background: var(--signal); border: 1px solid var(--signal); }
.slab--refresh { border-style: dashed; border-color: rgba(124, 242, 193, .45); background: rgba(10, 10, 10, .7); }

@media (min-width: 600px) {
  .story__scene { --w: 360px; --h: 220px; --gap: 86px; --drop: 96px; height: 540px; }
  .slab { font-size: 12px; padding: 18px 20px; }
  .slab__title { font-size: 15px; }
  .slab__tag { font-size: 10px; }
  .slab__id, .pii__tok, .slab__nodes span { font-size: 11px; }
}
@media (min-width: 1000px) {
  .story__grid { grid-template-columns: 5fr 6fr; gap: 48px; }
  .story__scene { --w: 460px; --h: 270px; --gap: 104px; --drop: 120px; height: 640px; }
}

/* ---- Scroll-driven version ---- */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .story__track { height: 520vh; view-timeline-name: --story; }
    .story__stage {
      position: sticky; top: var(--nav-h);
      height: calc(100svh - var(--nav-h) - var(--inset)); padding-block: 0;
      display: grid; align-items: center;
    }
    .story__grid { height: 100%; grid-template-rows: 1fr auto; align-content: center; gap: 8px; padding-block: 24px; }
    .story__copy { order: 2; }
    .story__scene { order: 1; height: 100%; min-height: 300px; }

    /* Captions cross-fade, one step at a time. */
    .story__steps { position: relative; display: block; height: 10.5rem; }
    .story__step {
      position: absolute; inset: 0;
      animation: step linear both; animation-timeline: --story;
      animation-range: contain calc(var(--k) * 20%) contain calc((var(--k) + 1) * 20%);
    }
    .story__step:first-child { animation-name: step-first; }
    .story__step:last-child { animation-name: step-last; }

    .story__progress { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 18px; max-width: 360px; }
    .story__progress i { position: relative; height: 2px; border-radius: 1px; background: var(--panel-line-2); overflow: hidden; }
    .story__progress i::after {
      content: ""; position: absolute; inset: 0; background: var(--signal); transform-origin: left;
      animation: fill linear both; animation-timeline: --story;
      animation-range: contain calc(var(--k) * 20%) contain calc((var(--k) + 1) * 20%);
    }

    /* Scene: flat ticket first, tilting into 3D as the twin is built. */
    .scene__tilt { animation: tilt linear both; animation-timeline: --story; animation-range: contain 38% contain 50%; }
    .scene__tilt::before { animation: fade-in linear both; animation-timeline: --story; animation-range: contain 40% contain 52%; }
    .slab--twin { animation: rise-1 linear both; animation-timeline: --story; animation-range: contain 46% contain 58%; }
    .slab--env { animation: rise-2 linear both; animation-timeline: --story; animation-range: contain 62% contain 72%; }
    .slab--refresh { animation: rise-3 linear both; animation-timeline: --story; animation-range: contain 82% contain 92%; }

    .slab__tag-raw { animation: fade-out linear both; animation-timeline: --story; animation-range: contain 30% contain 34%; }
    .slab__tag-clear { animation: fade-in linear both; animation-timeline: --story; animation-range: contain 32% contain 36%; }
    .pii__raw {
      animation: defocus linear both; animation-timeline: --story;
      animation-range: contain calc(22% + var(--p) * 3%) contain calc(28% + var(--p) * 3%);
    }
    .pii__tok {
      animation: token-in linear both; animation-timeline: --story;
      animation-range: contain calc(25% + var(--p) * 3%) contain calc(31% + var(--p) * 3%);
    }
    .slab__checks i {
      animation: tick linear both; animation-timeline: --story;
      animation-range: contain calc(72% + var(--c) * 3%) contain calc(73.5% + var(--c) * 3%);
    }

    @media (min-width: 1000px) {
      .story__grid { grid-template-rows: none; gap: 48px; }
      .story__copy { order: 0; }
      .story__steps { height: 15rem; }
    }
  }
}

@keyframes step       { 0% { opacity: 0; transform: translateY(28px); filter: blur(6px); } 20%, 80% { opacity: 1; transform: none; filter: none; } 100% { opacity: 0; transform: translateY(-28px); filter: blur(6px); } }
@keyframes step-first { 0%, 80% { opacity: 1; transform: none; filter: none; } 100% { opacity: 0; transform: translateY(-28px); filter: blur(6px); } }
@keyframes step-last  { 0% { opacity: 0; transform: translateY(28px); filter: blur(6px); } 20%, 100% { opacity: 1; transform: none; filter: none; } }
@keyframes fill       { from { transform: scaleX(0); } }
@keyframes tilt       { from { transform: translateY(0) rotateX(0) rotateZ(0) scale(1.08); } }
@keyframes rise-1     { from { opacity: 0; transform: translateZ(0); } }
@keyframes rise-2     { from { opacity: 0; transform: translateZ(var(--gap)); } }
@keyframes rise-3     { from { opacity: 0; transform: translateZ(calc(var(--gap) * 2)); } }
@keyframes fade-out   { to { opacity: 0; } from { opacity: 1; } }
@keyframes fade-in    { from { opacity: 0; } }
@keyframes defocus    { from { filter: blur(0); opacity: 1; } }
@keyframes token-in   { from { opacity: 0; transform: translateY(4px) scale(.92); } }
@keyframes tick       { from { background: transparent; border-color: var(--on-panel-2); } }
