/* Coverly Shelf landing: motion. Same contract as the Coverly ROMs landing.
   The HTML is the finished frame; everything here only plays towards it.
   Only transform, opacity, clip-path, colours, box-shadow and SVG stroke
   offsets move, so nothing shifts the layout.
   Gates: theme.js sets html.anim in <head> (no reduced motion, no
   Save-Data), which runs the hero on first paint; motion.js adds
   html.motion once its setup worked, and .is-in as each block scrolls in.
   Without JS neither class exists and the page renders finished. */

:root {
  --lp-ease-swing: linear(0, 0.23 4%, 0.68 10%, 1.06 17%, 1.16 21%, 1.12 26%, 1 33%, 0.95 40%, 0.97 50%, 1.01 62%, 1);
  --lp-beat: 320ms;
  --lp-beat-l: 560ms;
  --lp-scene: 2400ms;
}

/* Shown without playing: on screen at load, a late load, or halt(). */
html .no-anim,
html .no-anim *,
html .no-anim::before,
html .no-anim::after,
html .no-anim *::before,
html .no-anim *::after {
  animation-duration: 1ms !important;
  animation-delay: 0ms !important;
}

/* Stagger: --n is a child's place in its row, --step the beat between. */
/* The first child resets --n so it never inherits one from an outer stagger
   (.pic-gallery sits inside the second .feature). */
:is(.strip, .features, .duo, .pic-gallery, .credits-grid, .notes, .promises, .steps) > :first-child {
  --n: 0;
}
:is(.strip, .features, .duo, .pic-gallery, .credits-grid, .notes, .promises, .steps) > :nth-child(2) {
  --n: 1;
}
:is(.strip, .features, .duo, .pic-gallery, .credits-grid, .notes, .promises, .steps) > :nth-child(3) {
  --n: 2;
}
:is(.strip, .features, .duo, .pic-gallery, .credits-grid, .notes, .promises, .steps) > :nth-child(4) {
  --n: 3;
}
:is(.strip, .features, .duo, .pic-gallery, .credits-grid, .notes, .promises, .steps) > :nth-child(5) {
  --n: 4;
}
.notes,
.features,
.pic-gallery {
  --step: 90ms;
}
.duo {
  --step: 140ms;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}
@keyframes lift-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
@keyframes shot-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}
@keyframes url-type {
  from {
    clip-path: inset(0 100% 0 0);
  }
}
/* The page under the overlay develops from the top: the overlay slides down
   while its clip shrinks by the same amount, so its manila top edge is the
   scan line and nothing spills onto the shelf below. */
@keyframes develop {
  from {
    transform: translateY(0);
    clip-path: inset(0 0 0 0);
  }
  to {
    transform: translateY(100%);
    clip-path: inset(0 0 100% 0);
  }
}
@keyframes draw-x {
  from {
    transform: scaleX(0);
  }
}
@keyframes draw-y {
  from {
    transform: scaleY(0);
  }
}
@keyframes cta-glow {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--cr-manila) 0%, transparent);
  }
  40% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--cr-manila) 40%, transparent);
  }
}
@keyframes seat {
  from {
    transform: rotate(12deg) translateY(-6px);
  }
}
@keyframes chip-in {
  from {
    clip-path: inset(0 100% 0 0 round 4px);
  }
}

@keyframes cover-seat {
  from {
    opacity: 0;
    transform: translateZ(calc(var(--d) / 2)) translate3d(0, -22px, 40px) rotateX(10deg);
  }
}
@keyframes box-turn {
  from {
    transform: rotateX(var(--rx)) rotateY(0deg);
  }
  to {
    transform: rotateX(var(--rx)) rotateY(var(--ry));
  }
}
/* The focus ring walks the three screens (two presses of the right arrow)
   and fades on Escape. */
@keyframes ring-walk {
  0% {
    opacity: 0;
    transform: translateX(0);
  }
  8%,
  30% {
    opacity: 1;
    transform: translateX(0);
  }
  42%,
  64% {
    transform: translateX(calc(100% + 8px));
  }
  76%,
  88% {
    opacity: 1;
    transform: translateX(calc(200% + 16px));
  }
  100% {
    opacity: 0;
    transform: translateX(calc(200% + 16px));
  }
}
@keyframes key-hit {
  50% {
    background-color: color-mix(in srgb, var(--cr-manila) 55%, var(--cr-surface-raised));
    border-color: var(--cr-manila);
    transform: translateY(1px);
  }
}
@keyframes wipe-l {
  from {
    clip-path: inset(0 0 0 100%);
  }
}
@keyframes mini-drop {
  from {
    opacity: 0;
    transform: translateY(-10px) rotate(-6deg);
  }
}
@keyframes zoom-in {
  from {
    transform: scale(0.94);
    clip-path: inset(6% 6% round 12px);
  }
}
@keyframes ink-spread {
  from {
    clip-path: circle(0 at var(--ink-x, 50%) var(--ink-y, 0));
  }
  to {
    clip-path: circle(150vmax at var(--ink-x, 50%) var(--ink-y, 0));
  }
}

/* The gallery's focus ring: one screen wide, hidden at rest. */
.pic-gallery::before {
  content: '';
  position: absolute;
  left: 0;
  bottom: 14px;
  z-index: 1;
  width: calc((100% - 16px) / 3);
  aspect-ratio: 5 / 3;
  border-radius: var(--cr-radius-sm);
  box-shadow: inset 0 0 0 3px var(--cr-manila);
  opacity: 0;
  pointer-events: none;
}

/* Colour mode: the new one spreads from the control that picked it. */
html.vt-ink::view-transition-old(root),
html.vt-ink::view-transition-new(root) {
  mix-blend-mode: normal;
}
html.vt-ink::view-transition-old(root) {
  animation: none;
}
html.vt-ink::view-transition-new(root) {
  animation: ink-spread 480ms var(--cr-ease-ink) both;
}

@keyframes slot-pop {
  0% {
    transform: scale(0.86);
  }
  60% {
    transform: scale(1.06);
  }
}
@keyframes slot-empty {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
@keyframes seg-slide {
  from {
    transform: translateX(0);
  }
}

.rowmock .row:nth-child(2) {
  --r: 1;
}
.rowmock .row:nth-child(3) {
  --r: 2;
}
.rowmock .row:nth-child(4) {
  --r: 3;
}
.rowmock .row:nth-child(5) {
  --r: 4;
}
.rowmock .row:nth-child(6) {
  --r: 5;
}
.rowmock .bar {
  transform-origin: 0 50%;
}

/* The list mock: each row gets its cover as that row crosses into the
   screen, like the extension's lazy rows. Scrubbed by the scroll; behind
   html.motion so a page without JS, or printed, shows every cover. */
@supports (animation-timeline: view()) {
  @media screen and (prefers-reduced-motion: no-preference) {
    .rowmock {
      view-timeline: --rows block;
    }
    html.motion .rowmock .slot,
    html.motion .rowmock .slot::after,
    html.motion .rowmock .bar {
      animation-timeline: --rows;
      animation-range: entry calc(var(--r, 0) * 15% + 20%) entry calc(var(--r, 0) * 15% + 40%);
      animation-fill-mode: both;
      animation-timing-function: var(--cr-ease-ink);
    }
    html.motion .rowmock .slot {
      animation-name: slot-pop;
    }
    html.motion .rowmock .slot::after {
      animation-name: slot-empty;
    }
    html.motion .rowmock .bar {
      animation-name: draw-x;
    }
  }
}
@supports not (animation-timeline: view()) {
  @media screen and (prefers-reduced-motion: no-preference) {
    html.motion .rowmock.is-in .slot,
    html.motion .rowmock.is-in .slot::after,
    html.motion .rowmock.is-in .bar {
      animation: slot-pop 420ms var(--cr-ease-ink) backwards;
      animation-delay: calc(var(--r, 0) * 110ms + 200ms);
    }
    html.motion .rowmock.is-in .slot::after {
      animation-name: slot-empty;
    }
    html.motion .rowmock.is-in .bar {
      animation-name: draw-x;
    }
  }
}

@keyframes draw {
  from {
    stroke-dashoffset: 1;
  }
}
@keyframes hl {
  0%,
  100% {
    background-color: transparent;
  }
  35% {
    background-color: color-mix(in srgb, var(--cr-manila) 35%, transparent);
  }
}
@keyframes num-pop {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
}
@keyframes swap {
  from {
    opacity: 0.3;
  }
}

.promises {
  --step: 120ms;
}
.steps {
  --step: 110ms;
}
/* manifest.json: c k s k s s, so the k and s spans count 0 to 4. */
.manifest code span:nth-of-type(3) {
  --n: 1;
}
.manifest code span:nth-of-type(4) {
  --n: 2;
}
.manifest code span:nth-of-type(5) {
  --n: 3;
}
.manifest code span:nth-of-type(6) {
  --n: 4;
}

/* Install: a rail beside the step numbers fills as the list scrolls in. */
.steps {
  position: relative;
}
.steps::before {
  content: '';
  position: absolute;
  top: 22px;
  bottom: 22px;
  left: 44px;
  width: 2px;
  border-radius: var(--cr-radius-full);
  background: color-mix(in srgb, var(--cr-manila) 70%, transparent);
  transform-origin: 50% 0;
}
.steps li::before {
  transform-origin: 0.3em 50%;
}
@supports (animation-timeline: view()) {
  @media screen and (prefers-reduced-motion: no-preference) {
    .steps {
      view-timeline: --steps block;
    }
    html.motion .steps::before {
      animation: draw-y linear both;
      animation-timeline: --steps;
      animation-range: entry 0% entry 100%;
    }
  }
}
@supports not (animation-timeline: view()) {
  @media screen and (prefers-reduced-motion: no-preference) {
    html.motion .steps.is-in::before {
      animation: draw-y 1200ms var(--cr-ease-ink) backwards;
    }
  }
}

/* Lightbox: fades and zooms up; moving between pictures cross-fades. */
@media (prefers-reduced-motion: no-preference) {
  html.anim .lightbox,
  html.anim .lightbox::backdrop {
    opacity: 0;
    transition:
      opacity var(--cr-duration-base) var(--cr-ease-exit),
      transform var(--cr-duration-base) var(--cr-ease-exit),
      overlay var(--cr-duration-base) allow-discrete,
      display var(--cr-duration-base) allow-discrete;
  }
  html.anim .lightbox {
    transform: scale(0.96);
  }
  html.anim .lightbox[open],
  html.anim .lightbox[open]::backdrop {
    opacity: 1;
    transform: none;
    transition-duration: var(--cr-duration-slow);
    transition-timing-function: var(--cr-ease-ink);
  }
  @starting-style {
    html.anim .lightbox[open],
    html.anim .lightbox[open]::backdrop {
      opacity: 0;
    }
    html.anim .lightbox[open] {
      transform: scale(0.96);
    }
  }
  html.anim .lightbox-shot.swap {
    animation: swap 200ms var(--cr-ease-standard);
  }
}

/* Reading progress: a manila bar under the top bar, scrubbed by the scroll.
   Decoration only, so it needs no class gate. */
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .topbar::after {
      content: '';
      position: absolute;
      left: 0;
      right: 0;
      bottom: -1px;
      height: 2px;
      background: var(--cr-manila);
      transform-origin: 0 50%;
      animation: draw-x linear both;
      animation-timeline: scroll(root block);
    }
  }
}

/* Shelf lines draw from the left when their block comes in. */
.shot::after,
.feature .pic::after {
  transform-origin: 0 50%;
}
.notes li::before {
  transform-origin: 50% 0;
}

@media screen and (prefers-reduced-motion: no-preference) {
  /* ── Load: the hero, CSS only so it starts on first paint ── */
  html.anim .topbar .brand img {
    animation: seat 900ms var(--lp-ease-swing) 100ms backwards;
  }
  html.anim .topbar .wordmark b {
    animation: chip-in 400ms var(--cr-ease-enter) 250ms backwards;
  }
  html.anim .hero .stage-url {
    animation: url-type 420ms steps(24, end) 80ms backwards;
  }
  html.anim .hero .shot {
    animation: shot-in 520ms var(--cr-ease-ink) 120ms backwards;
  }
  html.anim .hero .shot::after {
    animation: draw-x var(--cr-duration-slower) var(--cr-ease-enter) 300ms backwards;
  }
  /* The overlay ends fully clipped, so the end frame is the plain page. */
  html.anim .hero .shot::before,
  html.motion .lists-grid .stage .shot::before {
    content: '';
    position: absolute;
    inset: 0 0 22px;
    z-index: 1;
    border-radius: var(--cr-radius-md);
    background: linear-gradient(var(--cr-manila) 0 2px, var(--cr-surface) 2px);
    pointer-events: none;
    transform: translateY(100%);
    clip-path: inset(0 0 100% 0);
  }
  html.anim .hero .shot::before {
    animation: develop 640ms var(--cr-ease-ink) 420ms backwards;
  }
  html.motion .lists-grid .stage:not(.is-in) .shot::before {
    transform: none;
    clip-path: none;
  }
  html.motion .lists-grid .stage.is-in .shot::before {
    animation: develop 640ms var(--cr-ease-ink) 200ms backwards;
  }
  html.anim .hero .strip button {
    animation: lift-in var(--lp-beat) var(--cr-ease-ink) backwards;
    animation-delay: calc(760ms + var(--n, 0) * 70ms);
  }
  html.anim .hero .btn-primary {
    animation: cta-glow 640ms var(--cr-ease-standard) 1300ms;
  }

  /* ── Scroll: each block settles in once ── */
  html.motion :is(.section h2, .section .intro, .aside-card, .credits-grid > *, .faq, .feature, .shot-card, .lists-grid .stage, .seg):not(.is-in),
  html.motion :is(.notes, .promises):not(.is-in) > li {
    opacity: 0;
  }
  html.motion :is(.section h2, .section .intro, .aside-card, .credits-grid > *, .faq, .feature, .shot-card, .lists-grid .stage, .seg).is-in,
  html.motion :is(.notes, .promises).is-in > li {
    animation: rise var(--cr-duration-slower) var(--cr-ease-ink) backwards;
    animation-delay: calc(var(--n, 0) * var(--step, 70ms));
  }
  html.motion .notes.is-in > li::before {
    animation: draw-y var(--cr-duration-slower) var(--cr-ease-enter) backwards;
    animation-delay: calc(var(--n, 0) * var(--step, 70ms) + 120ms);
  }
  html.motion :is(.feature, .shot-card, .lists-grid .stage).is-in :is(.shot, .pic)::after {
    animation: draw-x var(--cr-duration-slower) var(--cr-ease-enter) 200ms backwards;
  }
  /* Feature scenes, once each block is half in. The cover seats onto its
     box, then the box turns to its resting angle (no forwards fill: the
     base transform, and a drag, take over). */
  html.motion .feature.is-in .pic-box .face.front {
    animation: cover-seat var(--lp-beat-l) var(--cr-ease-ink) 120ms backwards;
  }
  html.motion .feature.is-in .pic-box .box {
    animation: box-turn 640ms var(--lp-ease-swing) 600ms backwards;
  }
  html.motion .feature.is-in .pic-gallery .screen {
    animation: lift-in 360ms var(--cr-ease-ink) backwards;
    animation-delay: calc(var(--n, 0) * var(--step, 90ms));
  }
  html.motion .feature.is-in .pic-gallery::before {
    animation: ring-walk 1800ms var(--cr-ease-ink) 500ms backwards;
  }
  html.motion .feature.is-in .keys kbd:nth-child(2) {
    animation:
      key-hit 220ms var(--cr-ease-standard) 1040ms,
      key-hit 220ms var(--cr-ease-standard) 1650ms;
  }
  html.motion .feature.is-in .keys kbd:nth-child(3) {
    animation: key-hit 220ms var(--cr-ease-standard) 2080ms;
  }
  html.motion .feature.is-in .pic-modes .dark {
    animation: wipe-l var(--lp-beat-l) var(--cr-ease-ink) 150ms backwards;
  }
  html.motion .feature.is-in .pic-modes .mini {
    animation: mini-drop var(--cr-duration-slower) var(--lp-ease-swing) 300ms backwards;
  }
  html.motion .feature.is-in .pic-modes .dark .mini {
    animation-delay: 640ms;
  }
  /* Two captures zoom open, the second a beat after the first. */
  html.motion .duo .shot-card.is-in img {
    animation: zoom-in var(--lp-beat-l) var(--cr-ease-ink) backwards;
    animation-delay: calc(var(--n, 0) * 140ms);
  }
  /* Cache retention: the choice springs from "this session" to the
     default 7 days, then the storage meter fills. */
  html.motion .seg.is-in .thumb {
    animation: seg-slide 480ms var(--cr-ease-spring) 250ms backwards;
  }
  html.motion .seg.is-in .meter i {
    animation: draw-x 640ms var(--cr-ease-ink) 600ms backwards;
  }
  /* Safety: the promises arrive in turn and their icons draw. */
  html.motion .promises li svg path {
    stroke-dasharray: 1;
  }
  html.motion .promises.is-in li svg path {
    animation: draw var(--lp-beat-l) var(--cr-ease-ink) backwards;
    animation-delay: calc(var(--n, 0) * var(--step, 120ms) + 120ms);
  }
  /* "Only what it needs": a highlighter passes over each key and host. */
  html.motion .manifest.is-in :is(.k, .s) {
    animation: hl 700ms var(--cr-ease-standard) backwards;
    animation-delay: calc(200ms + var(--n, 0) * 160ms);
  }
  html.motion .steps:not(.is-in) li::before {
    opacity: 0;
  }
  html.motion .steps.is-in li::before {
    animation: num-pop var(--lp-beat) var(--cr-ease-spring) backwards;
    animation-delay: calc(var(--n, 0) * var(--step, 110ms));
  }
  html.motion .credits-grid .family.is-in img {
    transform-origin: 50% 100%;
    animation: seat 900ms var(--lp-ease-swing) 300ms backwards;
  }
}

/* Feedback that answers a hand. */
@media (prefers-reduced-motion: no-preference) {
  .btn {
    transition:
      background-color var(--cr-duration-fast) var(--cr-ease-standard),
      border-color var(--cr-duration-fast) var(--cr-ease-standard),
      transform var(--cr-duration-base) var(--cr-ease-ink),
      box-shadow var(--cr-duration-base) var(--cr-ease-ink);
  }
  .strip img {
    transition:
      transform var(--cr-duration-base) var(--cr-ease-ink),
      box-shadow var(--cr-duration-base) var(--cr-ease-ink);
  }
  .mode label,
  .topnav a,
  .footer a,
  .faq summary {
    transition: color var(--cr-duration-fast) var(--cr-ease-standard), background-color var(--cr-duration-fast) var(--cr-ease-standard);
  }
}
@media (hover: hover) {
  .btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--cr-shadow-raised);
  }
  .strip button:hover img {
    transform: translateY(-2px);
    box-shadow: 0 0 0 2px var(--cr-manila), var(--cr-shadow-raised);
  }
  .faq summary:hover {
    color: var(--cr-primary);
  }
}
.btn:active {
  transform: none;
  box-shadow: none;
}

/* FAQ: answers open to their height. */
@supports (interpolate-size: allow-keywords) {
  @media (prefers-reduced-motion: no-preference) {
    :root {
      interpolate-size: allow-keywords;
    }
    .faq details::details-content {
      block-size: 0;
      overflow: clip;
      transition:
        block-size var(--cr-duration-slow) var(--cr-ease-ink),
        content-visibility var(--cr-duration-slow) allow-discrete;
    }
    .faq details[open]::details-content {
      block-size: auto;
    }
  }
}

/* Reduced motion: nothing moves, everything is in place. Keep last. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}
