/* Motion, and the visual language that depends on it: cards that lift, buttons that press,
   things that arrive rather than appear. Every duration comes from a token, and the whole
   file stands down under `prefers-reduced-motion`. */

/* ── the canvas is a soft wash rather than a flat fill ─────────────── */
body {
  background: var(--bg);
  background-image: linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 420px);
  background-attachment: fixed;
}

/* ── cards lift under the pointer ──────────────────────────────────── */
.card,
.home-card,
.shortcut,
.stat,
.table-wrap,
.viewer,
.draft,
.draft-outline,
.usage {
  box-shadow: var(--shadow-card);
  transition:
    box-shadow var(--base),
    transform var(--base),
    border-color var(--fast),
    background var(--fast);
}

a.card:hover,
button.card:hover,
.home-card:hover,
.shortcut:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}

a.card:active,
button.card:active,
.shortcut:active {
  transform: translateY(0);
  box-shadow: var(--shadow-card);
  transition-duration: 60ms;
}

/* ── buttons press ─────────────────────────────────────────────────── */
.btn,
.icon-btn,
.chip,
.tool,
.dock-tool,
.send-btn,
.send-cta {
  transition:
    background var(--fast),
    border-color var(--fast),
    color var(--fast),
    box-shadow var(--fast),
    transform var(--fast);
}

.btn[data-variant="primary"],
.btn[data-variant="accent"],
.send-cta,
.send-btn {
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.12);
}

.btn:active,
.icon-btn:active,
.chip:active,
.send-btn:active,
.send-cta:active {
  transform: scale(0.97);
  transition-duration: 60ms;
}

.btn:disabled:active {
  transform: none;
}

/* ── the view arrives ──────────────────────────────────────────────── */
.page {
  animation: page-in var(--slow) both;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* Cards in a grid arrive one after another, which reads as the page settling. */
.home-grid > *,
.card-grid > *,
.grid.g-3 > *,
.grid.g-4 > * {
  animation: card-in var(--base) both;
}

.home-grid > *:nth-child(1),
.card-grid > *:nth-child(1),
.grid.g-3 > *:nth-child(1),
.grid.g-4 > *:nth-child(1) {
  animation-delay: 20ms;
}

.home-grid > *:nth-child(2),
.card-grid > *:nth-child(2),
.grid.g-3 > *:nth-child(2),
.grid.g-4 > *:nth-child(2) {
  animation-delay: 60ms;
}

.home-grid > *:nth-child(3),
.card-grid > *:nth-child(3),
.grid.g-3 > *:nth-child(3),
.grid.g-4 > *:nth-child(3) {
  animation-delay: 100ms;
}

.home-grid > *:nth-child(4),
.card-grid > *:nth-child(4),
.grid.g-3 > *:nth-child(4),
.grid.g-4 > *:nth-child(4) {
  animation-delay: 140ms;
}

.home-grid > *:nth-child(n + 5),
.card-grid > *:nth-child(n + 5),
.grid.g-3 > *:nth-child(n + 5),
.grid.g-4 > *:nth-child(n + 5) {
  animation-delay: 180ms;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
}

/* ── overlays spring in ────────────────────────────────────────────── */
.dialog,
.palette,
.menu,
.account-menu,
.comment-pop,
.cite-pop {
  animation: pop-in var(--base) var(--ease-spring) both;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
  }
}

.dialog-wrap .palette,
.dialog-wrap .dialog {
  transform-origin: top center;
}

.panel {
  animation: panel-in var(--base) both;
}

@keyframes panel-in {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
}

.toast {
  animation: toast-in var(--base) var(--ease-spring) both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
}

/* ── small lives ───────────────────────────────────────────────────── */
.nav-item .ico,
.shortcut-go,
.file-row .ico:last-child {
  transition:
    transform var(--base),
    color var(--fast),
    background var(--fast);
}

.nav-item:hover .ico {
  transform: translateX(1px);
}

.shortcut:hover .shortcut-go,
.file-row:hover .ico:last-child {
  transform: translate(2px, -2px);
}

.btn .ico:last-child {
  transition: transform var(--base);
}

.btn:hover .ico:last-child {
  transform: translateX(2px);
}

/* A status dot that is working looks like it is working. */
.status[data-state="running"]::before {
  animation: breathe 2s var(--ease) infinite;
}

@keyframes breathe {
  50% {
    box-shadow: 0 0 0 5px color-mix(in oklab, var(--accent) 22%, transparent);
  }
}

.tile {
  transition: transform var(--base);
}

.shortcut:hover .tile,
.home-card:hover .tile,
button.card:hover .tile {
  transform: scale(1.06) rotate(-2deg);
}

/* The flow's connections draw themselves once, so a branch reads as a path. */
.flow-world path[marker-end] {
  stroke-dasharray: 1200;
  stroke-dashoffset: 0;
  animation: draw 900ms var(--ease) both;
}

@keyframes draw {
  from {
    stroke-dashoffset: 1200;
  }
}

.step,
.wf-node {
  animation: card-in var(--base) both;
}

@media (prefers-reduced-motion: reduce) {
  body {
    background-image: none;
  }

  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 1ms !important;
  }

  a.card:hover,
  button.card:hover,
  .home-card:hover,
  .shortcut:hover,
  .btn:active,
  .icon-btn:active {
    transform: none;
  }
}
