/*
 * <Demo> — interactive examples expressed in CSS alone.
 *
 * Why no JavaScript: the article body is compiled to static HTML before it is stored, and the
 * browser only ever loads the shared `site.js`. So every effect here is driven by a CSS state
 * that needs no script — `:active`, `:hover`, and `<details>` for anything that toggles.
 *
 * The class names are allow-listed in `src/lib/mdx-components.ts`; add a kind there and here.
 */

.demo {
  margin: 1.75rem 0;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-sunk);
}

.demo-caption {
  margin: 0.9rem 0 0;
  color: var(--ink-faint);
  font-size: 0.85rem;
}

.demo-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

/* ---- kind="press": the pressed state is the whole trick (tip 1) ---------------- */

.demo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: 0 1.1rem;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  /* Only paint the properties that move, and keep it short: a press has to feel immediate. */
  transition: transform 120ms ease-out;
  will-change: transform;
}

.demo-btn:active {
  transform: scale(0.97);
}

/* ---- kind="easing": same distance, same duration, different curve (tip 4) ------ */

.demo-card {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 6rem;
  min-height: 3rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 300ms;
}

.demo-card-in {
  transition-timing-function: ease-in;
}

.demo-card-out {
  /* The curve the tips recommend for anything entering or exiting the screen. */
  transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

.demo-card-in:hover,
.demo-card-out:hover {
  transform: translateY(-10px);
}

/* ---- kind="blur": reveal with and without a blur bridge (tip 7) ---------------- */

.demo-reveal {
  margin-top: 0.6rem;
}

.demo-reveal-trigger {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.demo-body {
  margin: 0.6rem 0 0;
  color: var(--ink-soft);
}

/* The incoming state fades in through a blur; the unblurred one in the second <details> just
   appears. Same distance, same duration, and the blurred one reads as one object moving. */
.demo-reveal-blur[open] .demo-body {
  animation: demo-blur-in 260ms ease-out;
}

@keyframes demo-blur-in {
  from {
    opacity: 0;
    filter: blur(2px);
  }
  to {
    opacity: 1;
    filter: blur(0);
  }
}

/* ---- kind="spinner": same work, different perceived speed (tip 6) -------------- */

.demo-spin {
  width: 1.75rem;
  height: 1.75rem;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: demo-spin 1.2s linear infinite;
}

.demo-spin-slow {
  animation-duration: 2.4s;
}

.demo-spin-fast {
  animation-duration: 0.6s;
}

@keyframes demo-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .demo-spin {
    animation: none;
  }

  .demo-btn,
  .demo-card {
    transition-duration: 1ms;
  }
}
