/* motion.css: the motion builder's file (design.md section 7).
   Rule of the file: base.css draws every end state; this file only animates towards it.
   Anything that starts hidden is scoped to html[data-js][data-motion="full"] and to the feature that brings it back,
   so a browser without scroll timelines, a failed script or reduced motion shows the finished page. */

@property --pc-sweep { syntax: "<angle>"; inherits: false; initial-value: 0deg; }

:root {
  --ease-stamp: cubic-bezier(.55, 0, .9, .4);
  --ease-settle: cubic-bezier(.2, 1.4, .4, 1);
  --dur-tab: 320ms;
  --dur-rule: 520ms;
}

/* ---------- 7.1 Hero stage ---------- */
.hero-stage canvas { transform-origin: 50% 55%; }
html:not([data-js]) .hero-stage canvas,
html[data-motion="reduced"] .hero-stage canvas { display: none; }
.hero-still { transition: opacity 320ms var(--ease-std); }
.hero-stage.is-live .hero-still { opacity: 0; }
html[data-motion="reduced"] .hero-stage .hero-still { opacity: 1; }
.hero-replay:not([hidden]) { animation: pc-fade-in 300ms var(--ease-arrive) both; }

/* ---------- 7.2 Scroll-driven details ---------- */
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    /* reading progress under the top bar */
    html[data-js][data-motion="full"] [data-motion="progress"] {
      animation: pc-progress linear both;
      animation-timeline: scroll(root);
    }
  }
  /* the top bar settles from 72 to 56 px without changing layout: the bar moves up, its content moves back down */
  @media (prefers-reduced-motion: no-preference) and (min-width: 960px) {
    html[data-js][data-motion="full"] .site-bar {
      animation: pc-bar linear both;
      animation-timeline: scroll(root);
      animation-range: 0 120px;
    }
    html[data-js][data-motion="full"] .site-bar__inner {
      animation: pc-bar-inner linear both;
      animation-timeline: scroll(root);
      animation-range: 0 120px;
    }
    html[data-js][data-motion="full"] .site-bar .wordmark {
      transform-origin: left center;
      animation: pc-wordmark linear both;
      animation-timeline: scroll(root);
      animation-range: 0 120px;
    }
  }
}

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* sheets pulled from the book (the demo sheet is the test sign-in: it never waits for a scroll) */
    html[data-js][data-motion="full"] main [data-reveal="sheet"]:not(.demo-sheet) {
      animation: pc-pull linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 60%;
    }
    /* the double rule draws under totals as it rises into view; the second line follows the first */
    html[data-js][data-motion="full"] main [data-rule="double"]::before,
    html[data-js][data-motion="full"] main [data-rule="double"]::after {
      animation: pc-rule linear both;
      animation-timeline: view();
      animation-range: entry 40% cover 38%;
    }
    html[data-js][data-motion="full"] main [data-rule="double"]::after { animation-range: entry 60% cover 44%; }
    /* the pink and yellow copies slide out from under the active screenshot */
    html[data-js][data-motion="full"] .shot-stack::before,
    html[data-js][data-motion="full"] .shot-stack::after {
      animation: pc-peek linear both;
      animation-timeline: view();
      animation-range: entry 30% cover 40%;
    }
  }
}

/* ---------- 7.3 Security drawing ----------
   Each animated part carries its place in the story as --a (start) and --b (end), fractions of the whole story.
   With scroll timelines the story is scrubbed by scrolling; without them motion.js arms a timed version. */
.security-drawing .s-spark { --a: 0; --b: .2; }
.security-drawing .s-shared-wire { --a: .2; --b: .45; }
.security-drawing .s-shared-tile[data-row="0"] { --a: .32; --b: .47; }
.security-drawing .s-shared-tile[data-row="1"] { --a: .4; --b: .55; }
.security-drawing .s-shared-tile[data-row="2"] { --a: .48; --b: .62; }
.security-drawing .s-shared-tile[data-row="3"] { --a: .56; --b: .7; }
.security-drawing .s-unit.is-hit { --a: .25; --b: .45; }
.security-drawing .s-calm-rule path { --a: .7; --b: .92; }
.security-drawing .s-calm-rule path + path { --a: .75; --b: .97; }
.security-sentinel { height: 1px; }

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* phone and tablet: each half plays its incident as it crosses the screen */
    html[data-js][data-motion="full"] .security-track { --r0: 12%; --rl: 40%; }
    html[data-js][data-motion="full"] .security-half { view-timeline: --security block; }
    html[data-js][data-motion="full"] .security-drawing :is(.s-spark, .s-shared-wire, .s-shared-tile, .s-unit.is-hit, .s-calm-rule path) {
      animation-duration: auto;
      animation-timing-function: linear;
      animation-fill-mode: both;
      animation-timeline: --security;
      animation-range:
        cover calc(var(--r0) + var(--rl) * var(--a))
        cover calc(var(--r0) + var(--rl) * var(--b));
    }
    /* desktop: the drawing holds still in a sticky stage while the visitor scrolls through the story */
    @media (min-width: 960px) {
      html[data-js][data-motion="full"] .security-track {
        height: 180vh;
        view-timeline: --security block;
        --r0: 30%; --rl: 36%;
      }
      html[data-js][data-motion="full"] .security-half { view-timeline: none; }
      html[data-js][data-motion="full"] .security-drawing {
        position: sticky;
        top: max(15vh, calc(var(--bar-h) + 24px));
      }
    }
  }
}
@supports not (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    html[data-js][data-motion="full"] .security-drawing[data-armed] :is(.s-spark, .s-shared-wire, .s-shared-tile, .s-unit.is-hit, .s-calm-rule path) {
      animation-duration: calc(2400ms * (var(--b) - var(--a)));
      animation-delay: calc(2400ms * var(--a));
      animation-timing-function: var(--ease-std);
      animation-fill-mode: both;
      animation-play-state: paused;
    }
    html[data-js][data-motion="full"] .security-drawing[data-armed].is-played :is(.s-spark, .s-shared-wire, .s-shared-tile, .s-unit.is-hit, .s-calm-rule path) {
      animation-play-state: running;
    }
  }
}
html[data-js][data-motion="full"] .security-drawing .s-spark { animation-name: pc-spark; }
html[data-js][data-motion="full"] .security-drawing .s-shared-wire { animation-name: pc-stroke-in; }
html[data-js][data-motion="full"] .security-drawing :is(.s-shared-tile, .s-unit.is-hit) { animation-name: pc-warn; }
html[data-js][data-motion="full"] .security-drawing .s-calm-rule path { animation-name: pc-stroke-in; }

/* ---------- 7.4 Assistant slip: waiting crossfades to approved (motion.js drops the chop) ---------- */
html[data-js] .proposal-slip [data-slip-state] { transition: opacity 200ms var(--ease-std), visibility 200ms; }
.proposal-slip[data-state="approved"] [data-slip-state="waiting"],
.proposal-slip[data-state="waiting"] [data-slip-state="approved"] { opacity: 0; }
.slip-chop { transform-origin: 50% 50%; }

/* ---------- 7.5 View transitions (same document) ---------- */
@media (prefers-reduced-motion: no-preference) {
  /* product tabs: the screenshot slides 12 px in the direction of travel; the rest of the page does not fade */
  html[data-dir]::view-transition-old(root),
  html[data-dir]::view-transition-new(root) { animation: none; }
  ::view-transition-group(product-shot) { animation-duration: var(--dur-tab); animation-timing-function: var(--ease-arrive); }
  ::view-transition-old(product-shot) { animation: pc-vt-out-next 200ms var(--ease-leave) both; }
  ::view-transition-new(product-shot) { animation: pc-vt-in-next var(--dur-tab) var(--ease-arrive) both; }
  html[data-dir="prev"]::view-transition-old(product-shot) { animation-name: pc-vt-out-prev; }
  html[data-dir="prev"]::view-transition-new(product-shot) { animation-name: pc-vt-in-prev; }
  /* screenshot viewer: the thumbnail grows into the large picture */
  ::view-transition-group(shot-zoom) { animation-duration: var(--dur-tab); animation-timing-function: var(--ease-arrive); }
  ::view-transition-old(shot-zoom), ::view-transition-new(shot-zoom) { animation-duration: 200ms; }
}
@media (prefers-reduced-motion: reduce) {
  html[data-dir]::view-transition-old(root),
  html[data-dir]::view-transition-new(root) { animation: none; }
  ::view-transition-group(product-shot) { animation-duration: 120ms; }
  ::view-transition-old(product-shot) { animation: pc-fade-out 120ms linear both; }
  ::view-transition-new(product-shot) { animation: pc-fade-in 120ms linear both; }
}

/* ---------- Dialogs: the sheet slides up 12 px and the backdrop dims; leaving is quicker ---------- */
#talk, html[data-motion="reduced"] #shot {
  opacity: 0;
  transition: opacity 160ms var(--ease-leave), translate 160ms var(--ease-leave),
    overlay 160ms var(--ease-leave) allow-discrete, display 160ms var(--ease-leave) allow-discrete;
}
#talk[open], html[data-motion="reduced"] #shot[open] {
  opacity: 1;
  transition-duration: var(--dur-dialog);
  transition-timing-function: var(--ease-arrive);
}
@starting-style {
  #talk[open], html[data-motion="reduced"] #shot[open] { opacity: 0; }
}
#talk::backdrop, html[data-motion="reduced"] #shot::backdrop {
  transition: background-color var(--dur-dialog) var(--ease-std),
    overlay var(--dur-dialog) allow-discrete, display var(--dur-dialog) allow-discrete;
}
#talk:not([open])::backdrop, html[data-motion="reduced"] #shot:not([open])::backdrop { background-color: transparent; }
@starting-style {
  #talk[open]::backdrop, html[data-motion="reduced"] #shot[open]::backdrop { background-color: transparent; }
}
@media (prefers-reduced-motion: no-preference) {
  html[data-motion="full"] #talk:not([open]) { translate: 0 8px; }
  @starting-style {
    html[data-motion="full"] #talk[open] { translate: 0 12px; }
  }
}
/* without view transitions the viewer fades and lifts like the contact dialog */
@supports not (view-transition-name: none) {
  #shot { opacity: 0; transition: opacity 160ms var(--ease-leave), overlay 160ms allow-discrete, display 160ms allow-discrete; }
  #shot[open] { opacity: 1; transition-duration: var(--dur-dialog); transition-timing-function: var(--ease-arrive); }
  @starting-style { #shot[open] { opacity: 0; } }
}

/* ---------- 7.6 Micro-interactions ---------- */
/* questions and answers open smoothly where the browser can animate to auto */
@supports (interpolate-size: allow-keywords) and selector(::details-content) {
  @media (prefers-reduced-motion: no-preference) {
    html[data-motion="full"] .faq__list { interpolate-size: allow-keywords; }
    html[data-motion="full"] .faq details::details-content {
      block-size: 0;
      overflow-y: clip;
      transition: block-size 220ms var(--ease-std), content-visibility 220ms allow-discrete;
    }
    html[data-motion="full"] .faq details[open]::details-content { block-size: auto; }
  }
}

/* phone action bar slides in from below; under reduced motion it fades */
@media (max-width: 959px) {
  .action-bar { transition: translate 200ms var(--ease-arrive), visibility 200ms; }
  .action-bar[data-hidden="true"] { transition-duration: 160ms; transition-timing-function: var(--ease-leave); }
  html[data-motion="reduced"] .action-bar { transition: opacity 160ms linear, visibility 160ms; }
  html[data-motion="reduced"] .action-bar[data-hidden="true"] { translate: 0 0; opacity: 0; }
}

/* ---------- Keyframes ---------- */
@keyframes pc-fade-in { from { opacity: 0; } }
@keyframes pc-fade-out { to { opacity: 0; } }
@keyframes pc-progress { to { transform: scaleX(1); } }
@keyframes pc-bar { to { translate: 0 -16px; } }
@keyframes pc-bar-inner { to { translate: 0 8px; } }
@keyframes pc-wordmark { to { scale: .9; } }
@keyframes pc-pull { from { translate: 0 32px; rotate: -1.5deg; opacity: 0; } }
@keyframes pc-rule { from { scale: 0 1; } }
@keyframes pc-peek { from { translate: 0 0; } }
@keyframes pc-spark { from { scale: 0; opacity: 0; } }
@keyframes pc-stroke-in { from { stroke-dashoffset: 1; } }
@keyframes pc-warn { from { stroke: var(--night-rule-strong); } }
@keyframes pc-vt-out-next { to { opacity: 0; translate: -12px 0; } }
@keyframes pc-vt-in-next { from { opacity: 0; translate: 12px 0; } }
@keyframes pc-vt-out-prev { to { opacity: 0; translate: 12px 0; } }
@keyframes pc-vt-in-prev { from { opacity: 0; translate: -12px 0; } }
