.stack-figure {
  --plate-width: min(50%, 178px);
  --stack-gap: 17px;
  --stack-shift: calc((100% - var(--plate-width)) / 2);
  --stack-ease: cubic-bezier(.2, .78, .28, 1.14);
  --stack-edge: rgba(61, 240, 122, .35);
  position: relative;
  width: 100%;
  max-width: 408px;
  min-width: 0;
  height: 362px;
  overflow: hidden;
  border: 1px solid var(--hair);
  background: radial-gradient(var(--hair) .7px, transparent .8px) 4px 5px / 14px 14px, var(--void);
  font: 400 13px/1.25 "JetBrains Mono", "JetBrains Mono Fallback", monospace;
}

.stack-figure__still {
  width: min(100%, 328px);
  height: 100%;
  margin-inline: auto;
}
.stack-figure__still-name { fill: var(--bright); font-weight: 600; }
.stack-figure__still-tools { fill: var(--muted); }

.stack-figure__scene {
  position: absolute;
  inset: 0 9px 55px;
}

.stack-figure__stages {
  margin: 0;
  padding: 0;
  list-style: none;
}

.stack-figure__stage {
  position: absolute;
  inset: calc(50% - 24px) 0 auto;
  height: 48px;
  transform: translate(var(--stack-shift), calc(var(--stage-offset) * var(--stack-gap)));
}

.stack-figure__link {
  position: relative;
  display: block;
  height: 100%;
  color: var(--bright);
  text-decoration: none;
  pointer-events: none;
}

.stack-figure__link:focus-visible { outline-offset: -1px; }

.stack-figure__plate {
  position: absolute;
  top: 50%;
  left: 0;
  width: var(--plate-width);
  overflow: visible;
  transform: translateY(-50%);
}

.stack-figure__face { fill: var(--panel); }
.stack-figure__side { fill: var(--void); }
.stack-figure__front { fill: var(--hair); }
.stack-figure__edge,
.stack-figure__etch,
.stack-figure__symbol { fill: none; stroke-width: 1; }
.stack-figure__edge { stroke: var(--stack-edge); }
.stack-figure__etch { stroke: var(--hair); }
.stack-figure__symbol { stroke: var(--muted); vector-effect: non-scaling-stroke; }
.stack-figure__micro { fill: var(--bright); font-size: 11px; }
.stack-figure__tool-mark { fill: var(--muted); font-size: 11px; }
.stack-figure__link[data-inspected] .stack-figure__edge { stroke: var(--phosphor); }
.stack-figure__link[data-inspected] .stack-figure__name { color: var(--phosphor); }

.stack-figure__label {
  position: absolute;
  inset: 0 0 0 calc(var(--plate-width) - 4px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-inline-start: 21px;
  line-height: 1.2;
  opacity: 0;
  transform: translateX(-7px);
}

.stack-figure__label::before {
  position: absolute;
  top: 50%;
  left: 4px;
  width: 11px;
  border-top: 1px solid var(--stack-edge);
  content: "";
}

.stack-figure__tool { color: var(--muted); }
.stack-figure__name { font-weight: 600; }

.stack-figure[data-exploded] {
  --stack-gap: 51px;
  --stack-shift: 0px;
}

.stack-figure[data-exploded] .stack-figure__plate :is(.stack-figure__face, .stack-figure__side, .stack-figure__front) {
  pointer-events: visibleFill;
}
.stack-figure[data-exploded] .stack-figure__label {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.stack-figure__toolbar {
  position: absolute;
  inset: auto 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 55px;
  padding: 4px 9px 4px 12px;
  border-top: 1px solid var(--hair);
  background: var(--panel);
}

.stack-figure__readout { flex: 1; color: var(--body); }

.stack-figure__toggle {
  display: none;
  min-width: 44px;
  min-height: 44px;
  padding-inline: 9px;
  border: 1px solid var(--stack-edge);
  background: var(--void);
  color: var(--phosphor);
}

@media (any-pointer: coarse) and (prefers-reduced-motion: no-preference) {
  .stack-figure__toggle { display: block; }
}

@media (prefers-reduced-motion: no-preference) {
  .stack-figure__scene { transition: transform 220ms ease-out; }
  /* Clear the annotations before the closing gaps become narrower than their labels. */
  .stack-figure__stage { transition: transform 385ms var(--stack-ease) 65ms; }
  .stack-figure__label { transition: transform 450ms var(--stack-ease), opacity 65ms ease-out; }
  .stack-figure[data-exploded] .stack-figure__stage { transition-duration: 450ms; transition-delay: 0ms; }
  .stack-figure[data-exploded] .stack-figure__label {
    transition-duration: 450ms, 210ms;
    transition-delay: 0ms, 95ms;
  }
  .stack-figure[data-entrance] .stack-figure__link {
    animation: stack-figure-arrive 600ms ease-out var(--entrance-delay) both;
  }
  .stack-figure[data-awaiting-entrance] .stack-figure__link { animation-play-state: paused; }
}

@keyframes stack-figure-arrive {
  from { opacity: 0; transform: translateY(-24px); }
  to { opacity: 1; transform: translateY(0); }
}
