/* Анімації: переходи між сторінками, цикли з паузою, появи, відповіді на дії. */
/* Motion. Rules (docs/DESIGN.md): transform and opacity only; loops run only while their block
   is on screen (.is-inview, set by motion.js) and stop when the tab is hidden (html.is-paused);
   at most three loops in view at once; reduced motion shows the final, static state
   (base.css switches every animation off). Without JS nothing loops and nothing is hidden. */

/* ---------- Page to page: cross-fade where the browser supports it ---------- */

@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}

/* Use our transform/opacity rule instead of the browser's geometry morphs. */
::view-transition-group(*),
::view-transition-old(root),
::view-transition-new(root) { animation: none; }
::view-transition-old(root) { opacity: 0; }

@media (prefers-reduced-motion: no-preference) {
  html.motion-arrival body::before {
    content: "";
    position: fixed;
    inset: env(safe-area-inset-top, 0) 0 auto;
    height: 1px;
    z-index: 100;
    background: var(--line);
    pointer-events: none;
    transform-origin: left;
    animation: page-rule 300ms var(--ease-out) both;
  }
  html.motion-back body::before { transform-origin: right; }
  html.motion-arrival .site-main { animation: page-resolve 300ms linear both; }
}
@keyframes page-rule {
  0% { transform: scaleX(0); opacity: 1; }
  90% { transform: scaleX(1); opacity: 1; }
  100% { transform: scaleX(1); opacity: 0; }
}
@keyframes page-resolve {
  0%, 90% { opacity: 0; }
  100% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  html.motion-arrival body::before { animation: none !important; opacity: 0; transform: scaleX(1); }
  html.motion-arrival .site-main { animation: none !important; opacity: 1; transform: none; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* The header stays put while the page under it changes. */
::view-transition-group(site-header) { animation: none; }

/* The current-tab mark slides to the new tab (header nav, Discover, For You, profile, /mod/). One name per tab row, so
   a mark never flies from one row to another page's row; a row that is only on one side just fades. Names are set
   only when motion is welcome; a duplicate name would cancel the transition, so the phone menu's copy is hidden. */
@media (prefers-reduced-motion: no-preference) {
  .site-nav .tab-mark { view-transition-name: nav-mark; }
  .explore-tabs .tab-mark { view-transition-name: discover-tab-mark; }
  .feed-tabs .tab-mark { view-transition-name: feed-tab-mark; }
  .profile-tabs .tab-mark { view-transition-name: profile-tab-mark; }
  .mod-tabs .tab-mark { view-transition-name: mod-tab-mark; }
  .tab-mark { view-transition-class: tab-mark; }
}

::view-transition-group(*.tab-mark) { animation: none; }

/* ---------- Pause: offscreen and hidden tabs ---------- */

/* Pause only loops, not the one-shot marks inside the old data-loop example wrapper. */
html.js.is-paused *,
html.js.is-paused *::before,
html.js.is-paused *::after,
.js .btn[data-loop]:not(.is-inview) > .motion-shimmer::before {
  animation-play-state: paused !important;
}

/* ---------- Sections: 18px rise, 520ms, 70ms child stagger; once on entry ---------- */
@media (prefers-reduced-motion: no-preference) {
  .motion-reveal { transition: opacity 520ms var(--ease-out), transform 520ms var(--ease-out); }
  .motion-reveal:not(.is-revealed) { opacity: 0; transform: translateY(18px); }
  .motion-reveal .motion-child {
    transition: opacity 520ms var(--ease-out) var(--reveal-at, 0ms);
  }
  .motion-reveal:not(.is-revealed) .motion-child { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .motion-reveal, .motion-child { animation: none !important; transition: none !important; opacity: 1; transform: none; }
}

/* ---------- The strike: earned marks pressed in one after another, once ---------- */
/* Put .strike on any block with hallmarks. The base styles are the final state. */

.strike .hallmark.is-earned:nth-child(1) { --strike-at: 0ms; }
.strike .hallmark.is-earned:nth-child(2) { --strike-at: 120ms; }
.strike .hallmark.is-earned:nth-child(3) { --strike-at: 240ms; }
.strike .hallmark-info:nth-child(1) .hallmark.is-earned { --strike-at: 0ms; }
.strike .hallmark-info:nth-child(2) .hallmark.is-earned { --strike-at: 120ms; }
.strike .hallmark-info:nth-child(3) .hallmark.is-earned { --strike-at: 240ms; }

.strike .hallmark.is-earned .hallmark__chip {
  animation: hm-press 420ms var(--ease-press) var(--strike-at, 0ms) both;
}
@keyframes hm-press {
  0% { transform: translateY(-8px); opacity: 0; }
  65% { transform: translateY(2px); opacity: 1; }
  82% { transform: translateY(-1px); opacity: 1; }
  100% { transform: none; opacity: 1; }
}

.pulse-dot {
  position: relative;
  display: inline-block;
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: var(--signal);
}

/* Uptime bars rise once when they scroll into view (uptime.js adds .is-in). Without JS, or with reduced motion,
   the bars are simply there. Transform only; the bottom edge stays put. */
@media (prefers-reduced-motion: no-preference) {
  .js .uptime-bars:not(.is-in) .uptime-bar__fill { transform: scaleY(0); }
  .js .uptime-bars.is-in .uptime-bar__fill {
    animation: uptime-rise 420ms var(--ease-out) calc(var(--cell, 0) * 24ms) both;
  }
}
.uptime-bars__days > .uptime-bar:nth-child(1) { --cell: 0; }
.uptime-bars__days > .uptime-bar:nth-child(2) { --cell: 1; }
.uptime-bars__days > .uptime-bar:nth-child(3) { --cell: 2; }
.uptime-bars__days > .uptime-bar:nth-child(4) { --cell: 3; }
.uptime-bars__days > .uptime-bar:nth-child(5) { --cell: 4; }
.uptime-bars__days > .uptime-bar:nth-child(6) { --cell: 5; }
.uptime-bars__days > .uptime-bar:nth-child(7) { --cell: 6; }
.uptime-bars__days > .uptime-bar:nth-child(8) { --cell: 7; }
.uptime-bars__days > .uptime-bar:nth-child(9) { --cell: 8; }
.uptime-bars__days > .uptime-bar:nth-child(10) { --cell: 9; }
.uptime-bars__days > .uptime-bar:nth-child(11) { --cell: 10; }
.uptime-bars__days > .uptime-bar:nth-child(12) { --cell: 11; }
.uptime-bars__days > .uptime-bar:nth-child(13) { --cell: 12; }
.uptime-bars__days > .uptime-bar:nth-child(14) { --cell: 13; }
.uptime-bars__days > .uptime-bar:nth-child(15) { --cell: 14; }
.uptime-bars__days > .uptime-bar:nth-child(16) { --cell: 15; }
.uptime-bars__days > .uptime-bar:nth-child(17) { --cell: 16; }
.uptime-bars__days > .uptime-bar:nth-child(18) { --cell: 17; }
.uptime-bars__days > .uptime-bar:nth-child(19) { --cell: 18; }
.uptime-bars__days > .uptime-bar:nth-child(20) { --cell: 19; }
.uptime-bars__days > .uptime-bar:nth-child(21) { --cell: 20; }
.uptime-bars__days > .uptime-bar:nth-child(22) { --cell: 21; }
.uptime-bars__days > .uptime-bar:nth-child(23) { --cell: 22; }
.uptime-bars__days > .uptime-bar:nth-child(24) { --cell: 23; }
.uptime-bars__days > .uptime-bar:nth-child(25) { --cell: 24; }
.uptime-bars__days > .uptime-bar:nth-child(26) { --cell: 25; }
.uptime-bars__days > .uptime-bar:nth-child(27) { --cell: 26; }
.uptime-bars__days > .uptime-bar:nth-child(28) { --cell: 27; }
.uptime-bars__days > .uptime-bar:nth-child(29) { --cell: 28; }
.uptime-bars__days > .uptime-bar:nth-child(30) { --cell: 29; }
@keyframes uptime-rise {
  from { transform: scaleY(0); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .strike .hallmark__chip, .uptime-bar__fill {
    animation: none !important;
    transform: none;
    opacity: 1;
  }
}

/* ---------- Blinking cursor after a mono label ---------- */

.cursor::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 0.2em;
  vertical-align: -0.12em;
  background: currentColor;
}

/* ---------- Answers to actions ---------- */

/* A state that just turned on (liked, followed, verified): the icon pops once. */
.pop { animation: pop 260ms var(--ease-press); }

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ---------- Inner pages: enter, lists, cards, empty states ----------
   All of it runs once, on load, with CSS only (no script needed, nothing waits for one). "backwards" fill: the
   start state applies only during the delay, so nothing keeps a transform (or a stacking context) afterwards.
   Content is never hidden for longer than the 0.6 s an entrance takes, and clicks work during it. */

@media (prefers-reduced-motion: no-preference) {
  /* Page enter: the head, then the content, rise a few pixels into place. */
  .shell > :not(.motion-reveal) { animation: rise 420ms var(--ease-out) backwards; }
  .shell > :nth-child(2) { animation-delay: 60ms; }
  .shell > :nth-child(3) { animation-delay: 120ms; }
  .shell > :nth-child(n + 4) { animation-delay: 160ms; }

  /* Lists: cards and rows come in one after another (the first eight; later ones, also "Load more", together). */
  :is(.feed-list, .plate-list, .news__list, .mod-list, .explore__list) > * { animation: rise 380ms var(--ease-out) 140ms backwards; }
  :is(.feed-list, .plate-list, .news__list, .mod-list, .explore__list) > :nth-child(2) { animation-delay: 190ms; }
  :is(.feed-list, .plate-list, .news__list, .mod-list, .explore__list) > :nth-child(3) { animation-delay: 240ms; }
  :is(.feed-list, .plate-list, .news__list, .mod-list, .explore__list) > :nth-child(4) { animation-delay: 290ms; }
  :is(.feed-list, .plate-list, .news__list, .mod-list, .explore__list) > :nth-child(5) { animation-delay: 340ms; }
  :is(.feed-list, .plate-list, .news__list, .mod-list, .explore__list) > :nth-child(6) { animation-delay: 380ms; }
  :is(.feed-list, .plate-list, .news__list, .mod-list, .explore__list) > :nth-child(7) { animation-delay: 420ms; }
  :is(.feed-list, .plate-list, .news__list, .mod-list, .explore__list) > :nth-child(n + 8) { animation-delay: 460ms; }

  /* Empty state: the three dashed marks are set down one by one, the first one is pressed once and does not take. */
  .empty__marks > * { animation: rise 360ms var(--ease-out) backwards; }
  .empty__marks > :nth-child(1) { animation-delay: 200ms; }
  .empty__marks > :nth-child(2) { animation-delay: 280ms; }
  .empty__marks > :nth-child(3) { animation-delay: 360ms; }
  .empty__marks > :first-child .hallmark__chip { animation: try-stamp 520ms var(--ease-press) 900ms; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes try-stamp {
  0% { transform: none; }
  35% { transform: scale(0.94); }
  65% { transform: scale(1.03); }
  100% { transform: none; }
}

/* Cards answer the pointer: the frame firms up and the cover moves in a little. A press on the card's own link
   (not on a button inside it) pushes the card down a touch. No lift, no shadow. */
.feed-card,
.news-card,
.card {
  transition: transform var(--t-fast) var(--ease-press);
}

.feed-card__cover,
.card__media,
.project-thumb { overflow: hidden; }

.feed-card__cover img,
.card__media img,
.project-thumb img { transition: transform 500ms var(--ease-out); }

@media (hover: hover) {
  .feed-card:hover,
  .news-card:hover,
  .card:hover { border-color: var(--line-strong); }

  .feed-card:hover .feed-card__cover img,
  .card:hover .card__media img,
  .plate-row:hover .project-thumb img { transform: scale(1.03); }
}

:is(.feed-card, .news-card, .card):has(a:not(.btn):active) { transform: scale(0.995); }

/* ---------- Answers to changes made in place ---------- */

@media (prefers-reduced-motion: no-preference) {
  /* Disclosures (hallmark explanation, DNS / meta help, feed filters and community boards on phones): the opened
     content drops 4px into place, like the menus. */
  :is(.hallmark-info, .method__help, .feed-filters-fold, .community-boards-fold)[open] > :not(summary) {
    animation: menu-in var(--t-base) var(--ease-out);
  }

  /* A build log entry that was just posted (build-log.js adds .is-new) rises into the list. */
  .log > .is-new { animation: rise 320ms var(--ease-out); }

  /* Domain verification: the status block that "Verify now" brought back (domain-verify.js adds .is-updated). */
  [data-domain-status].is-updated { animation: rise 260ms var(--ease-out); }

  /* The "new replies" dot on the account button is set down once, after the page has settled. */
  .user-menu__dot { animation: dot-in 320ms var(--ease-press) 500ms backwards; }
}

@keyframes dot-in {
  from { opacity: 0; transform: scale(0); }
  to { opacity: 1; transform: none; }
}

/* ---------- Reading progress (legal and content pages, news posts) ----------
   A 2px hairline at the top grows with the scroll: a scroll-driven animation, no script, nothing hijacked. Shown only
   where the browser supports scroll timelines and motion is welcome; on a page too short to scroll it stays at 0. */

.read-progress { display: none; }

@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .read-progress {
      display: block;
      position: fixed;
      top: env(safe-area-inset-top, 0);
      left: 0;
      right: 0;
      z-index: 50;
      height: 2px;
      background: var(--muted);
      transform: scaleX(0);
      transform-origin: left center;
      pointer-events: none;
      animation: read-progress linear both;
      animation-timeline: scroll(root block);
    }
  }
}

@keyframes read-progress {
  to { transform: scaleX(1); }
}

/* ---------- Count-up: a number on a stats row counts up once when it comes into view (motion.js) ---------- */
/* The real number is in the HTML; the script only animates it, and not at all with reduced motion. */
[data-count] { font-variant-numeric: tabular-nums; }

/* Existing filled launch nodes are the live nodes in the project's changelog. */
.log-entry--launch::before { background: var(--signal); border-color: var(--signal); }
@media (prefers-reduced-motion: no-preference) {
  .log-entry--launch.motion-node-seen::before { animation: timeline-pulse 600ms var(--ease-out) 1; }
}
@keyframes timeline-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  45% { transform: scale(1.6); opacity: 0.45; }
}
@media (prefers-reduced-motion: reduce) {
  .log-entry--launch.motion-node-seen::before { animation: none !important; transform: none; opacity: 1; }
}
