/* ==========================================================================
   Typora-Benchmarked Motion System
   - Strictly GPU-composited properties (transform, opacity, stroke-dashoffset)
   - Full prefers-reduced-motion accessibility fallback
   ========================================================================== */

/* ---------- 1. Reading Progress Hairline ---------- */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 120;
  background: linear-gradient(90deg, #24292f 0%, #57606a 100%);
  transform-origin: left center;
  transform: scaleX(0);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-base) var(--ease);
}

.scroll-progress.active {
  opacity: 0.88;
}

/* ---------- 2. Hero Editorial Staggered Entrance ---------- */
@keyframes heroFadeUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes heroWindowFloatIn {
  from {
    opacity: 0;
    transform: translateY(26px) scale(0.988);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.hero-stagger {
  opacity: 0;
  animation: heroFadeUp 680ms var(--ease-out-expo) forwards;
}

.hero-stagger-1 { animation-delay: 40ms; }
.hero-stagger-2 { animation-delay: 110ms; }
.hero-stagger-3 { animation-delay: 190ms; }
.hero-stagger-4 { animation-delay: 260ms; }
.hero-stagger-5 { animation-delay: 320ms; }

.hero-window-entrance {
  opacity: 0;
  animation: heroWindowFloatIn 820ms var(--ease-out-expo) 360ms forwards;
}

/* Scroll down gentle breathing cue */
@keyframes scrollCueFloat {
  0%, 100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  50% {
    transform: translateY(5px);
    opacity: 1;
  }
}

.hero-scroll-cue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 32px;
  color: var(--text-muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  transition: color var(--t-fast) var(--ease);
}

.hero-scroll-cue:hover {
  color: var(--text-primary);
}

.hero-scroll-cue svg {
  width: 16px;
  height: 16px;
  animation: scrollCueFloat 2.4s var(--ease-in-out) infinite;
}

/* ---------- 3. Scroll Reveal Choreography ---------- */
[data-reveal] {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--t-reveal) var(--ease-out-expo),
    transform var(--t-reveal) var(--ease-out-expo);
  will-change: opacity, transform;
}

[data-reveal="fade"] {
  transform: none;
}

[data-reveal="scale"] {
  transform: translateY(14px) scale(0.982);
}

[data-reveal].is-visible {
  opacity: 1;
  transform: none;
  will-change: auto;
}

/* Editorial ink rule draw animation */
.section-rule {
  transform-origin: center;
  transform: scaleX(0);
  transition: transform 760ms var(--ease-out-expo) 120ms;
}

.is-visible .section-rule,
.section-rule.is-visible {
  transform: scaleX(1);
}

/* Staggered child reveal inside grids/lists */
[data-reveal-stagger] > * {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 560ms var(--ease-out-expo),
    transform 560ms var(--ease-out-expo);
}

[data-reveal-stagger].is-visible > * {
  opacity: 1;
  transform: none;
}

[data-reveal-stagger].is-visible > *:nth-child(1) { transition-delay: 0ms; }
[data-reveal-stagger].is-visible > *:nth-child(2) { transition-delay: 70ms; }
[data-reveal-stagger].is-visible > *:nth-child(3) { transition-delay: 140ms; }
[data-reveal-stagger].is-visible > *:nth-child(4) { transition-delay: 210ms; }
[data-reveal-stagger].is-visible > *:nth-child(5) { transition-delay: 280ms; }
[data-reveal-stagger].is-visible > *:nth-child(6) { transition-delay: 350ms; }

/* ---------- 4. Live Typing & WYSIWYM Morph Keyframes ---------- */
@keyframes caretBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.live-caret {
  display: inline-block;
  width: 2px;
  height: 1.08em;
  background: var(--app-link);
  vertical-align: -0.15em;
  margin-left: 1px;
  border-radius: 1px;
  animation: caretBlink 980ms steps(1) infinite;
}

.live-caret.typing {
  animation: none;
  opacity: 1;
}

@keyframes renderSettle {
  0% {
    opacity: 0.45;
    transform: translateY(3px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.block-just-rendered {
  animation: renderSettle 320ms var(--ease-out-expo);
}

@keyframes inlineMorphPop {
  0% {
    opacity: 0.5;
    transform: scale(0.97);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.inline-morphed {
  display: inline-block;
  animation: inlineMorphPop 260ms var(--ease-out-expo);
}

@keyframes demoPulseDot {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.76);
  }
}

.demo-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #1a7f37;
  display: inline-block;
  flex-shrink: 0;
  animation: demoPulseDot 1.8s var(--ease-in-out) infinite;
}

.demo-live-dot.paused {
  background: var(--text-muted);
  animation: none;
}

/* ---------- 5. Showcase Stage & Living Demo Keyframes ---------- */
@keyframes stageFadeInRight {
  from {
    opacity: 0;
    transform: translateX(14px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes stageFadeInLeft {
  from {
    opacity: 0;
    transform: translateX(-14px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.stage-enter-next {
  animation: stageFadeInRight 360ms var(--ease-out-expo);
}

.stage-enter-prev {
  animation: stageFadeInLeft 360ms var(--ease-out-expo);
}

@keyframes svgPathDraw {
  from {
    stroke-dashoffset: 84;
    opacity: 0.25;
  }
  to {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}

@keyframes svgNodePop {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.mermaid-node-anim {
  transform-box: fill-box;
  transform-origin: center;
  opacity: 0;
  animation: svgNodePop 420ms var(--ease-out-expo) forwards;
}

.mermaid-edge-anim {
  stroke-dasharray: 84;
  stroke-dashoffset: 84;
  animation: svgPathDraw 480ms var(--ease-out-expo) forwards;
}

@keyframes codeLineReveal {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.code-line-anim {
  display: block;
  opacity: 0;
  animation: codeLineReveal 340ms var(--ease-out-expo) forwards;
}

@keyframes alertBarGrow {
  from {
    transform: scaleY(0);
  }
  to {
    transform: scaleY(1);
  }
}

@keyframes rowCascadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.row-cascade-anim {
  opacity: 0;
  animation: rowCascadeIn 380ms var(--ease-out-expo) forwards;
}

@keyframes syncProgressSlide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(220%);
  }
}

/* ---------- 6. Smooth Accordion & Expandable Drawers ---------- */
.smooth-expand {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 300ms var(--ease-out-expo),
    opacity 240ms var(--ease);
}

.smooth-expand > .smooth-expand-inner {
  overflow: hidden;
  min-height: 0;
}

.smooth-expand.is-open {
  grid-template-rows: 1fr;
  opacity: 1;
}

/* ---------- 7. Back-to-Top Floating Button ---------- */
.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 28px;
  z-index: 90;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--page-border-strong);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
  opacity: 0;
  transform: translateY(12px) scale(0.92);
  pointer-events: none;
  transition: opacity var(--t-base) var(--ease),
    transform var(--t-base) var(--ease-out-expo),
    color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease);
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.back-to-top:hover {
  color: var(--text-primary);
  border-color: var(--text-primary);
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

.back-to-top svg {
  width: 17px;
  height: 17px;
}

/* ---------- 8. Reduced Motion Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  .hero-stagger,
  .hero-window-entrance,
  [data-reveal],
  [data-reveal-stagger] > *,
  .mermaid-node-anim,
  .code-line-anim,
  .row-cascade-anim {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
    transition: none !important;
  }

  .section-rule {
    transform: scaleX(1) !important;
    transition: none !important;
  }

  .mermaid-edge-anim {
    stroke-dashoffset: 0 !important;
    animation: none !important;
  }

  .hero-scroll-cue svg,
  .live-caret,
  .demo-live-dot {
    animation: none !important;
  }

  .scroll-progress {
    display: none;
  }

  .lang-prompt {
    transform: none !important;
    transition: none !important;
  }
}

@media (max-width: 700px) {
  .back-to-top {
    right: 16px;
    bottom: 18px;
    width: 38px;
    height: 38px;
  }
}
