/*
 * Small movements inside a page, only for people who have not asked their device to reduce motion
 * (test/unit/design/tokens.test.ts holds the rule). Moving between pages stays still on purpose,
 * with no page-turn or view transition (test/integration/web/settings.test.ts keeps it out).
 * Without these rules every screen is complete; nothing here carries meaning the static page lacks.
 */
/*
 * From a tap until the next page paints, a bar along the top edge (public/js/navigation.js), so a
 * slow answer does not look like a page that ignored the tap. It holds still without motion.
 */
.is-navigating body::after {
  content: "";
  position: fixed;
  inset-block-start: env(safe-area-inset-top, 0);
  inset-inline: 0;
  z-index: 100;
  block-size: 0.1875rem;
  background: var(--color-primary);
  transform-origin: left;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  /*
   * Already a short stretch on the first frame, then fast and slowing, so the tap shows at once
   * and the bar never reaches the end before the page arrives.
   */
  .is-navigating body::after {
    animation: navigating 8s cubic-bezier(0.1, 0.7, 0.2, 1) both;
  }

  @keyframes navigating {
    from {
      transform: scaleX(0.15);
    }

    to {
      transform: scaleX(0.9);
    }
  }

  /* The entry just saved glows yellow, then settles into the page like the others. */
  .entry-saved .entry-card {
    animation: entry-saved-fade 2.4s ease-in 0.6s both;
  }

  @keyframes entry-saved-fade {
    from {
      background: var(--color-saved-bg);
    }
  }

  /* The hanamaru lands like a rubber stamp: big and faint, then pressed down. */
  .entry-saved .entry-actions::before {
    animation: stamp 0.5s var(--ease-spring) 0.5s both;
  }

  @keyframes stamp {
    from {
      opacity: 0;
      scale: 2.2;
      rotate: 10deg;
    }
  }

  /* Yomochi breathes on the cover, slowly enough not to pull the eye from the form. */
  .login-hero .mascot {
    animation: bob 4.5s ease-in-out infinite;
  }

  @keyframes bob {
    50% {
      translate: 0 -0.5rem;
      rotate: -2deg;
    }
  }

  /*
   * On the welcome cards she moves to suit each card, tilting from her feet; the hand group turns
   * at her shoulder, in the SVG's own units.
   */
  .welcome-art .mascot {
    transform-origin: 50% 90%;
  }

  .welcome-art .mascot-hand {
    transform-box: view-box;
    transform-origin: 104px 86px;
  }

  /* The first card: she toddles side to side, hopping mid-step, and waves. */
  .welcome-art[data-pose="intro"] .mascot {
    animation: sway 3.2s ease-in-out infinite;
  }

  .welcome-art[data-pose="intro"] .mascot-hand {
    animation: wave 1.1s ease-in-out infinite;
  }

  .welcome-art[data-pose="labels"] .mascot {
    animation: peek 3.6s ease-in-out infinite;
  }

  .welcome-asking .mascot {
    animation: ponder 3s ease-in-out infinite;
  }

  .welcome-asking .mascot-hand {
    animation: scribble 0.5s ease-in-out infinite alternate;
  }

  .welcome-greeting .mascot {
    animation: hop 1s cubic-bezier(0.3, 0.6, 0.4, 1) infinite;
  }

  .welcome-art[data-pose="passkey"] .mascot {
    animation: bob 2.4s ease-in-out infinite;
  }

  .welcome-art[data-pose="passkey"] .mascot-hand {
    animation: raise 2.4s ease-in-out infinite;
  }

  @keyframes wave {
    50% {
      rotate: -30deg;
    }
  }

  @keyframes peek {
    0%,
    100% {
      translate: 0 0.5rem;
      rotate: -6deg;
    }

    40%,
    70% {
      translate: 0 0;
      rotate: 4deg;
    }
  }

  @keyframes ponder {
    0%,
    100% {
      rotate: -5deg;
    }

    50% {
      rotate: 5deg;
    }
  }

  @keyframes scribble {
    from {
      rotate: -8deg;
    }

    to {
      rotate: 8deg;
    }
  }

  @keyframes hop {
    0%,
    100% {
      translate: 0 0;
      scale: 1.05 0.95;
    }

    40% {
      translate: 0 -0.875rem;
      scale: 0.96 1.04;
    }

    70% {
      translate: 0 0;
      scale: 1.06 0.94;
    }
  }

  @keyframes raise {
    50% {
      rotate: -12deg;
    }
  }

  @keyframes sway {
    0%,
    100% {
      translate: -0.75rem 0;
      rotate: -6deg;
    }

    25%,
    75% {
      translate: 0 -0.375rem;
      rotate: 0deg;
    }

    50% {
      translate: 0.75rem 0;
      rotate: 6deg;
    }
  }

  /* Sticky notes settle onto the page as they scroll into view. */
  @supports (animation-timeline: view()) {
    .use {
      animation: settle linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 60%;
    }

    @keyframes settle {
      from {
        opacity: 0;
        translate: 0 2rem;
        rotate: 0deg;
      }
    }
  }

  /* As the sheet covers the cover, the title sinks back; the wide layout never covers it. */
  @supports (animation-timeline: scroll()) {
    @media (max-width: 71.99rem) {
      .login-hero .ui\:hero-content {
        animation: recede linear both;
        animation-timeline: scroll(root);
        animation-range: 0 60dvh;
      }
    }

    @keyframes recede {
      to {
        opacity: 0.3;
        scale: 0.92;
        translate: 0 2rem;
      }
    }
  }

  /* Buttons and chips give under the finger. */
  .ui\:btn,
  .tabbar .tab,
  .settings-link,
  .day-cell {
    transition:
      scale 0.15s var(--ease-out),
      background-color 0.2s ease,
      color 0.2s ease,
      box-shadow 0.2s ease;
  }

  .ui\:btn:active,
  .tabbar .tab:active,
  .day-cell:active {
    scale: 0.96;
  }

  .tabbar .tab .icon {
    transition: background-color 0.25s ease;
  }

  /* Only on a tap; placing it on load or resize stays still. */
  .tabbar.is-sliding::before {
    transition:
      translate 0.3s var(--ease-out),
      width 0.3s var(--ease-out),
      height 0.3s var(--ease-out);
  }

  @media (hover: hover) {
    .entry-card,
    .label-card {
      transition:
        translate 0.25s var(--ease-out),
        box-shadow 0.25s var(--ease-out);
    }

    .entry-card:hover {
      translate: 0 -0.125rem;
      box-shadow: var(--shadow-lift);
    }

    .day-cell:not([aria-current]):hover {
      background: var(--color-soft);
    }
  }
}
