/* ═══════════════════════════════════════════════════════════════════
   T. Perry — Animation Layer (Refined)
   Compositor-optimized, progressive enhancement
   Palette: #0c1219 (bg), #1a6fc4 (primary)
   ═══════════════════════════════════════════════════════════════════ */

/* ── @property Registrations ─────────────────────────────────── */
@property --count {
  syntax: '<integer>';
  initial-value: 0;
  inherits: false;
}

/* ── 1. Scroll Progress Bar ──────────────────────────────────── */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 1.5px;
  background: #1a6fc4;
  transform-origin: 0 50%;
  transform: scaleX(0);
  z-index: 10000;
  pointer-events: none;
}

@supports (animation-timeline: scroll()) {
  .scroll-progress {
    animation: progressGrow auto linear forwards;
    animation-timeline: scroll(root block);
  }
  @keyframes progressGrow {
    to { transform: scaleX(1); }
  }
}

/* ── 2. Reveal System (data-reveal) ──────────────────────────── */
[data-reveal] {
  opacity: 0;
  transition-property: opacity, transform;
  transition-duration: 0.5s;
  transition-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
}

[data-reveal="up"]    { transform: translateY(20px); }
[data-reveal="scale"] { transform: scale(0.96); }
[data-reveal="fade"]  { transform: none; }

[data-reveal].is-revealed {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Stagger delay via CSS custom property */
[data-reveal][style*="--d"] {
  transition-delay: calc(var(--d, 0) * 1ms);
}

/* Scroll-driven reveal (modern browsers) */
@supports (animation-timeline: view()) {
  [data-reveal] {
    animation: scrollReveal auto ease-out both;
    animation-timeline: view();
    animation-range: entry 5% entry 70%;
    transition: none;
  }

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

  @keyframes scrollRevealScale {
    from { opacity: 0; transform: scale(0.96) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
  }

  [data-reveal="scale"] {
    animation-name: scrollRevealScale;
  }

  [data-reveal].is-revealed {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* ── 3. Staggered Grid Cards ─────────────────────────────────── */
.anim-card {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s ease,
              transform 0.5s cubic-bezier(0.23, 1, 0.32, 1),
              border-color 0.2s ease,
              box-shadow 0.2s ease;
  transition-delay: calc(var(--stagger, 0) * 80ms);
}

.anim-card.is-revealed {
  opacity: 1;
  transform: translateY(0);
}

.anim-card:hover {
  transform: translateY(-2px);
  border-color: rgba(26, 111, 196, 0.3);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.12);
}

/* ── 4. Number Counter (@property) ───────────────────────────── */
.anim-counter {
  --count: 0;
  counter-reset: stat var(--count);
  font-variant-numeric: tabular-nums;
}

.anim-counter::after {
  content: counter(stat);
}

.anim-counter[data-suffix]::after {
  content: counter(stat) attr(data-suffix);
}

.anim-counter.is-counting {
  transition: --count 1.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Suppress ::after when JS drives the counter to prevent double rendering */
.anim-counter.js-counting::after {
  content: none;
}


/* ── 5. Nav Link Underline Slide ────────────────────────────── */
.nav-link {
  position: relative;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 100%;
  height: 1px;
  background: #1a6fc4;
  transform: scaleX(0);
  transform-origin: right center;
  transition: transform 0.35s cubic-bezier(0.23, 1, 0.32, 1);
}

.nav-link:hover::after {
  transform: scaleX(1);
  transform-origin: left center;
}

/* ── 6. Skeleton Loading ────────────────────────────────────── */
.skeleton {
  position: relative;
  overflow: hidden;
  background: rgba(26, 111, 196, 0.06);
  border-radius: 4px;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(26,111,196,0.08) 50%, transparent 100%);
  transform: translateX(-100%);
  animation: shimmer 1.8s ease-in-out infinite;
}

@keyframes shimmer {
  100% { transform: translateX(100%); }
}

/* ── 7. Cross-Document View Transitions ─────────────────────── */
@view-transition {
  navigation: auto;
}

.site-logo {
  view-transition-name: site-logo;
}

.page-nav {
  view-transition-name: page-nav;
}

::view-transition-old(root) {
  animation: vtOut 0.25s ease-in forwards;
}

::view-transition-new(root) {
  animation: vtIn 0.25s ease-out forwards;
}

@keyframes vtOut {
  to { opacity: 0; transform: translateY(-8px); }
}

@keyframes vtIn {
  from { opacity: 0; transform: translateY(8px); }
}

::view-transition-group(site-logo),
::view-transition-group(page-nav) {
  animation-duration: 0.3s;
  animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
}

/* ── 8. Architecture Diagram Nodes ────────────────────────── */
.arch-node {
  background: rgba(26, 111, 196, 0.06);
  border: 1px solid rgba(26, 111, 196, 0.15);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.arch-node:hover {
  border-color: rgba(26, 111, 196, 0.35);
  background: rgba(26, 111, 196, 0.1);
}

.arch-connector {
  width: 2px;
  background: linear-gradient(180deg, rgba(26, 111, 196, 0.4) 0%, rgba(26, 111, 196, 0.1) 100%);
  position: relative;
}

.arch-connector::after {
  content: '';
  position: absolute;
  top: 0;
  left: -1px;
  width: 4px;
  height: 4px;
  background: #1a6fc4;
  border-radius: 50%;
  animation: svgFlowDown 2s ease-in-out infinite;
}

/* ── 9. Status Indicators ────────────────────────────────── */
.status-live {
  animation: statusPulse 2s ease-in-out infinite;
}

.status-dot-pulse {
  position: relative;
}

.status-dot-pulse::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0;
  animation: dotPulseRing 3s ease-out infinite;
}

/* ── 10. Text Gradient ───────────────────────────────────── */
.text-gradient {
  background: linear-gradient(135deg, #1a6fc4 0%, #3b9aed 50%, #1a6fc4 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: gradientShift 4s ease-in-out infinite;
}

/* ── 11. Hero Background Pattern ─────────────────────────── */
.hero-pattern {
  position: relative;
}

.hero-pattern::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(26, 111, 196, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  mask-image: radial-gradient(ellipse 60% 60% at 50% 50%, black 20%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 60% 60% at 50% 50%, black 20%, transparent 70%);
}

/* ── 12. SVG Diagram Keyframes ───────────────────────────── */
@keyframes svgFlowRight {
  0%   { transform: translateX(-8px); opacity: 0; }
  20%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateX(8px); opacity: 0; }
}

@keyframes svgFlowDown {
  0%   { transform: translateY(0); opacity: 0; }
  20%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(100%); opacity: 0; }
}

@keyframes svgPulseNode {
  0%, 100% { r: 6; opacity: 0.8; }
  50%      { r: 8; opacity: 1; }
}

@keyframes svgDraw {
  from { stroke-dashoffset: 1; }
  to   { stroke-dashoffset: 0; }
}

/* ── 13. Timeline Progressive Draw ───────────────────────── */
.timeline-line {
  background: linear-gradient(180deg, #1a6fc4 0%, rgba(26, 111, 196, 0.1) 100%);
  background-size: 100% 200%;
  background-position: 0 100%;
  transition: background-position 1.5s cubic-bezier(0.23, 1, 0.32, 1);
}

.timeline-line.is-drawn {
  background-position: 0 0;
}

/* ── 14. Card Glow on Hover ──────────────────────────────── */
.card-glow {
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.card-glow:hover {
  box-shadow: 0 0 20px rgba(26, 111, 196, 0.12), 0 4px 16px rgba(0, 0, 0, 0.15);
  border-color: rgba(26, 111, 196, 0.3);
}

/* ── 15. Section Gradient Top Border ─────────────────────── */
.section-gradient-top {
  position: relative;
}

.section-gradient-top::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, 80rem);
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, #1a6fc4 30%, #3b9aed 50%, #1a6fc4 70%, transparent 100%);
}

/* ── Supporting Keyframes ────────────────────────────────── */
@keyframes statusPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.6; transform: scale(1.15); }
}

@keyframes dotPulseRing {
  0%   { transform: scale(0.8); opacity: 0.6; }
  50%  { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1.4); opacity: 0; }
}

@keyframes gradientShift {
  0%   { background-position: 0% center; }
  50%  { background-position: 100% center; }
  100% { background-position: 0% center; }
}

/* ══════════════════════════════════════════════════════════════
   REDUCED MOTION — respect user preference
   ══════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  [data-reveal],
  .anim-card {
    opacity: 1;
    transform: none;
    transition: none;
    animation: none;
  }

  .scroll-progress { display: none; }

  .skeleton::after,
  .status-live,
  .arch-connector::after,
  .status-dot-pulse::after {
    animation: none;
  }

  .text-gradient {
    animation: none;
    background-size: 100% auto;
  }

  .hero-pattern::before { display: none; }

  .timeline-line {
    background-position: 0 0;
    transition: none;
  }

  .card-glow { transition: none; }
  .section-gradient-top::before { display: none; }

  /* SVG animations */
  [data-reveal="scale"] svg *,
  svg .flow-particle,
  svg .pulse-node {
    animation: none !important;
  }
}
