/* ===========================
   Pro Animated Grid (v2.1)
   - Cleaner tokens
   - Smoother motion
   - Unified reveal classes
   - Mobile/perf tweaks
   =========================== */

/* Design tokens */
:root {
  color-scheme: dark;

  /* Grid */
  --tile: clamp(28px, 5vw, 44px);
  --line: 1px;

  /* Palette */
  --bg: #050507;
  --line-base: rgba(255, 255, 255, 0.05);
  --glow: rgba(139, 92, 246, 0.26);
  --sweep-1: rgba(139, 92, 246, 0.16);
  --sweep-2: rgba(34, 211, 238, 0.14);
  --sweep-3: rgba(244, 63, 94, 0.1);

  /* Effects */
  --glow-blur: 6px;
  --sweep-blur: 22px;
  --vignette: radial-gradient(
    120% 80% at 50% 100%,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.35) 75%,
    rgba(0, 0, 0, 0.6) 100%
  );
  --fade-mask: linear-gradient(to bottom, #000 40%, transparent 100%);
}

@media (prefers-contrast: more) {
  :root {
    --line-base: rgba(255, 255, 255, 0.09);
    --glow: rgba(139, 92, 246, 0.32);
    --vignette: radial-gradient(
      120% 80% at 50% 100%,
      rgba(0, 0, 0, 0) 0%,
      rgba(0, 0, 0, 0.45) 70%,
      rgba(0, 0, 0, 0.75) 100%
    );
  }
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial;
  background: var(--bg);
}

/* ===========================
   GRID SCENE (place behind content)
   =========================== */
.grid-pro {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(
        to right,
        var(--line-base) var(--line),
        transparent var(--line)
      )
      0 0 / var(--tile) var(--tile),
    linear-gradient(
        to bottom,
        var(--line-base) var(--line),
        transparent var(--line)
      )
      0 0 / var(--tile) var(--tile),
    var(--bg);
  -webkit-mask-image: var(--fade-mask);
  mask-image: var(--fade-mask);
  animation: grid-drift 16s linear infinite;
  will-change: background-position;
}
.grid-pro::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
        to right,
        var(--glow) var(--line),
        transparent var(--line)
      )
      0 0 / var(--tile) var(--tile),
    linear-gradient(to bottom, var(--glow) var(--line), transparent var(--line))
      0 0 / var(--tile) var(--tile);
  filter: blur(var(--glow-blur));
  opacity: 0.55;
  animation: grid-drift 16s linear infinite;
}
.grid-pro::before {
  content: "";
  position: absolute;
  inset: -12%;
  background: linear-gradient(
    135deg,
    transparent 0%,
    var(--sweep-1) 30%,
    var(--sweep-2) 50%,
    var(--sweep-3) 70%,
    transparent 100%
  );
  mix-blend-mode: screen;
  filter: blur(var(--sweep-blur));
  opacity: 0.42;
  animation: sweep-pan 18s linear infinite;
  will-change: transform, opacity;
}
/* optional vignette + grain overlay */
.grid-pro-mask {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(
        1px 1px at 25% 25%,
        rgba(255, 255, 255, 0.02) 0,
        transparent 60%
      )
      0 0/3px 3px,
    radial-gradient(
        1px 1px at 75% 75%,
        rgba(255, 255, 255, 0.015) 0,
        transparent 60%
      )
      0 0/3px 3px,
    var(--vignette);
  animation: grain-float 6s linear infinite;
  opacity: 0.9;
}

/* Keyframes */
@keyframes grid-drift {
  0% {
    background-position: 0 0, 0 0;
  }
  100% {
    background-position: var(--tile) var(--tile), var(--tile) var(--tile);
  }
}
@keyframes sweep-pan {
  0% {
    transform: translate(-25%, -25%) rotate(0.001deg);
  }
  50% {
    transform: translate(10%, 10%) rotate(0.001deg);
  }
  100% {
    transform: translate(45%, 45%) rotate(0.001deg);
  }
}
@keyframes grain-float {
  0% {
    background-position: 0 0, 0 0;
  }
  100% {
    background-position: 6px 6px, -6px -6px;
  }
}

/* Themes */
.grid-pro[data-theme="blue"] {
  --glow: rgba(96, 165, 250, 0.28);
  --sweep-1: rgba(96, 165, 250, 0.18);
  --sweep-2: rgba(56, 189, 248, 0.16);
  --sweep-3: rgba(20, 184, 166, 0.12);
}
.grid-pro[data-theme="amber"] {
  --glow: rgba(245, 158, 11, 0.28);
  --sweep-1: rgba(245, 158, 11, 0.2);
  --sweep-2: rgba(234, 179, 8, 0.16);
  --sweep-3: rgba(244, 63, 94, 0.12);
}

/* ===========================
   Reveal on Scroll (unified)
   =========================== */
.reveal {
  opacity: 0;
  transform: translateY(16px) scale(0.998);
  transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.2, 0.9, 0.2, 1);
  will-change: transform, opacity;
}
.reveal.is-visible,
.reveal.in-view {
  /* supports both class names */
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* === FAQ (one-open-only, no text hide) === */

.faq-item {
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: border-color 0.2s;
}
.faq-item:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

/* Toggle button */
.faq-btn {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.faq-btn[aria-expanded="true"] {
  background-color: rgba(255, 255, 255, 0.03);
}

/* Panel (no opacity tricks => no flicker/hide) */
.panel {
  max-height: 0;
  overflow: hidden; /* clip while animating */
  padding-top: 0;
  padding-bottom: 0;
  transition: max-height 0.4s cubic-bezier(0.2, 0.9, 0.2, 1), padding 0.3s ease;
  will-change: max-height;
}

/* Wrap content inside for stable measure */
.panel__inner {
  /* Avoid margin-collapsing issues */
  padding-top: 1rem; /* visually equals panel.open padding-top */
  padding-bottom: 1.25rem; /* visually equals panel.open padding-bottom */
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: 0; /* keep clean */
}

/* We move padding into inner wrapper so text is never cut
   and panel height is strictly content height. */
.panel.open {
  /* keep panel padding 0; inner handles spacing */
  padding-top: 0;
  padding-bottom: 0;
}

/* Icon animation */
.rot {
  transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.2, 1);
  transform-origin: center;
}
.rot-open {
  transform: rotate(45deg) scale(1.06);
  animation: rot-pop 0.35s ease;
}
@keyframes rot-pop {
  0% {
    transform: rotate(0) scale(1);
  }
  60% {
    transform: rotate(55deg) scale(1.1);
  }
  100% {
    transform: rotate(45deg) scale(1.06);
  }
}

/* ===========================
   Icon Rotation
   =========================== */
.rot {
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.2, 1);
  transform-origin: center;
}

/* ===========================
   Accessible Focus
   =========================== */
a:focus-visible,
button:focus-visible {
  outline: 2px solid #8b5cf6;
  outline-offset: 2px;
}

/* Premium gradient ring on hover (no layout shift) */
.service-card {
  position: relative;
  isolation: isolate;
}
.service-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 1rem; /* matches rounded-2xl */
  padding: 1px;
  opacity: 0;
  transition: opacity 0.3s ease;
  background: linear-gradient(
    145deg,
    rgba(139, 92, 246, 0.35),
    rgba(56, 189, 248, 0.25)
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  z-index: 0;
}
.service-card:hover::before {
  opacity: 0.9;
}
.service-card > * {
  position: relative;
  z-index: 1;
}

/* ===========================
   Bento Card (animated border)
   =========================== */
@keyframes spin {
  from {
    transform: rotate(0);
  }
  to {
    transform: rotate(360deg);
  }
}

.bento-card {
  position: relative;
  background: #111827;
  border-radius: 0.75rem;
  overflow: hidden;
  isolation: isolate;
  transition: transform 0.35s ease, box-shadow 0.35s ease;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
}
@media (hover: hover) {
  .bento-card:hover {
    transform: scale(1.02);
    box-shadow: 0 18px 45px rgba(59, 130, 246, 0.18);
  }
}
.bento-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background: conic-gradient(
    from 0deg,
    #8b5cf6 0%,
    #22d3ee 25%,
    #34d399 50%,
    #f59e0b 75%,
    #f43f5e 100%
  );
  padding: 2px;
  z-index: 0;
  opacity: 0;
  filter: blur(0.5px);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: spin 6s linear infinite;
  transition: opacity 0.3s ease-in-out;
}
@supports not ((-webkit-mask-composite: xor) or (mask-composite: exclude)) {
  /* Fallback: simple glow ring if mask-composite unsupported */
  .bento-card::before {
    padding: 0;
    filter: none;
    opacity: 0.35;
    mix-blend-mode: screen;
  }
}
@media (hover: hover) {
  .bento-card:hover::before {
    opacity: 0.9;
  }
}
.bento-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(
      100% 100% at 50% 0%,
      rgba(139, 92, 246, 0.12),
      transparent 60%
    ),
    #111827;
  z-index: 1;
}
.card-content {
  position: relative;
  z-index: 2;
}

/* ===========================
   Counter finish micro-interaction
   =========================== */
.counter.done {
  animation: counter-pop 0.3s ease;
}
@keyframes counter-pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

/* ===========================
   Reduced Motion
   =========================== */
@media (prefers-reduced-motion: reduce) {
  .grid-pro,
  .grid-pro::before,
  .grid-pro::after,
  .grid-pro-mask,
  .reveal {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    opacity: 1 !important;
  }
}
