/* ==========================================================================
   ZERG Website — Custom CSS Foundation
   Dark/light theming, glassmorphism, animations, pipeline, utilities
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Custom Properties — Theming
   --------------------------------------------------------------------------
   Dark mode is the default (applied via .dark on <body> or <html>).
   Light mode uses :root without .dark.
   -------------------------------------------------------------------------- */

:root {
  /* ---- Light palette ---- */
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-tertiary: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --accent-purple: #6d28d9;
  --accent-green: #16a34a;
  --accent-purple-soft: rgba(109, 40, 217, 0.12);
  --accent-green-soft: rgba(22, 163, 74, 0.12);
  --border-color: rgba(0, 0, 0, 0.1);
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(0, 0, 0, 0.1);
  --glass-shadow: rgba(0, 0, 0, 0.06);
  --code-bg: #1e293b;
  --code-text: #e2e8f0;
  --focus-ring: rgba(109, 40, 217, 0.5);
  --gradient-start: #6d28d9;
  --gradient-end: #16a34a;
  --pipeline-connector: #cbd5e1;
}

.dark {
  /* ---- Dark palette ---- */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent-purple: #7c3aed;
  --accent-green: #22c55e;
  --accent-purple-soft: rgba(124, 58, 237, 0.15);
  --accent-green-soft: rgba(34, 197, 94, 0.15);
  --border-color: rgba(255, 255, 255, 0.08);
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: rgba(0, 0, 0, 0.25);
  --code-bg: #0c1222;
  --code-text: #e2e8f0;
  --focus-ring: rgba(124, 58, 237, 0.6);
  --gradient-start: #7c3aed;
  --gradient-end: #22c55e;
  --pipeline-connector: #475569;
}

/* --------------------------------------------------------------------------
   2. Dark / Light Transition
   -------------------------------------------------------------------------- */

body,
body *:not(script):not(style) {
  transition:
    background-color 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   3. Glassmorphism Card
   -------------------------------------------------------------------------- */

.glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 1rem;
  padding: 1.5rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 24px var(--glass-shadow);
  transform: scale(0.98);
  transition:
    transform 0.5s ease,
    box-shadow 0.3s ease,
    background-color 0.3s ease,
    border-color 0.3s ease;
}

.glass-card:hover {
  box-shadow: 0 8px 32px var(--glass-shadow);
}

.glass-card.visible {
  transform: scale(1.02);
}

/* --------------------------------------------------------------------------
   4. Scroll Animations — Fade-In
   -------------------------------------------------------------------------- */

.fade-in {
  opacity: 0;
  transform: translateY(20px);
  transition:
    opacity 0.6s ease,
    transform 0.6s ease;
}

.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger delays for sequential children */
.fade-in:nth-child(2) {
  transition-delay: 0.1s;
}

.fade-in:nth-child(3) {
  transition-delay: 0.2s;
}

.fade-in:nth-child(4) {
  transition-delay: 0.3s;
}

.fade-in:nth-child(5) {
  transition-delay: 0.4s;
}

.fade-in:nth-child(6) {
  transition-delay: 0.5s;
}

.fade-in:nth-child(7) {
  transition-delay: 0.6s;
}

.fade-in:nth-child(8) {
  transition-delay: 0.7s;
}

/* --------------------------------------------------------------------------
   5. Pipeline Visualization
   -------------------------------------------------------------------------- */

.pipeline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0;
  width: 100%;
}

.pipeline-step {
  flex: 1;
  position: relative;
  text-align: center;
  padding: 1.25rem 1rem;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 0.75rem;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.pipeline-step:not(:last-child) {
  margin-right: 2rem;
}

/* Arrow connector between steps */
.pipeline-step:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -1.75rem;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 12px solid var(--pipeline-connector);
}

/* Horizontal line connector */
.pipeline-step:not(:last-child)::before {
  content: "";
  position: absolute;
  top: 50%;
  right: -1.5rem;
  transform: translateY(-50%);
  width: 1.5rem;
  height: 2px;
  background: var(--pipeline-connector);
  z-index: -1;
}

/* Pipeline step label */
.pipeline-step-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.pipeline-step-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Active step highlight */
.pipeline-step.active {
  border-color: var(--accent-purple);
  box-shadow: 0 0 16px var(--accent-purple-soft);
}

.pipeline-step.active .pipeline-step-title {
  color: var(--accent-purple);
}

.pipeline-step.completed {
  border-color: var(--accent-green);
}

.pipeline-step.completed .pipeline-step-title {
  color: var(--accent-green);
}

/* --------------------------------------------------------------------------
   6. Code Blocks
   -------------------------------------------------------------------------- */

.code-block {
  position: relative;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", "SF Mono", Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.7;
  padding: 1.25rem 1.5rem;
  border-radius: 0.75rem;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  tab-size: 2;
  word-break: break-word;
  overflow-wrap: break-word;
}

.code-block code {
  font-family: inherit;
  font-size: inherit;
  background: none;
  padding: 0;
  border: none;
}

.copy-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.375rem;
  cursor: pointer;
  transition:
    background 0.2s ease,
    color 0.2s ease;
  z-index: 1;
}

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
}

.copy-btn.copied {
  color: var(--accent-green);
  border-color: var(--accent-green);
}

/* --------------------------------------------------------------------------
   7. Gradient Text Utility
   -------------------------------------------------------------------------- */

.gradient-text {
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* Reverse direction variant */
.gradient-text-reverse {
  background: linear-gradient(135deg, var(--gradient-end), var(--gradient-start));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* --------------------------------------------------------------------------
   8. FAQ Chevron (details/summary)
   -------------------------------------------------------------------------- */

details summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
  font-weight: 600;
  color: var(--text-primary);
  user-select: none;
}

details summary::-webkit-details-marker {
  display: none;
}

details summary .chevron {
  display: inline-block;
  transition: transform 0.3s ease;
  font-size: 0.875rem;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 1rem;
}

details[open] summary .chevron {
  transform: rotate(90deg);
}

details .faq-answer {
  padding: 0 0 1rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   8b. Visually Hidden — Screen Reader Only
   -------------------------------------------------------------------------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* --------------------------------------------------------------------------
   9. Focus Styles — Accessibility
   -------------------------------------------------------------------------- */

*:focus-visible {
  outline: 2px solid var(--accent-purple);
  outline-offset: 2px;
  border-radius: 2px;
}

a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--accent-purple);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--focus-ring);
  border-radius: 4px;
}

details summary:focus-visible {
  outline: 2px solid var(--accent-purple);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--focus-ring);
  border-radius: 4px;
}

/* Skip-nav link for screen readers */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  padding: 0.5rem 1rem;
  background: var(--accent-purple);
  color: #fff;
  z-index: 9999;
  border-radius: 0 0 0.5rem 0;
  font-weight: 600;
}

.skip-link:focus {
  top: 0;
}

/* --------------------------------------------------------------------------
   10. Responsive Breakpoints
   --------------------------------------------------------------------------
   Standard Tailwind-equivalent breakpoints:
     sm:  640px
     md:  768px
     lg:  1024px
     xl:  1280px
     2xl: 1536px
   -------------------------------------------------------------------------- */

/* --- Extra Small (< 360px) — Narrow mobile --- */

@media (max-width: 359px) {
  html, body {
    overflow-x: hidden;
  }

  .code-block {
    font-size: 0.7rem;
    padding: 0.75rem;
  }

  .glass-card {
    padding: 0.75rem;
  }
}

/* --- Small (< 640px) — Mobile defaults --- */

@media (max-width: 639px) {
  .pipeline {
    flex-direction: column;
    gap: 1rem;
  }

  .pipeline-step:not(:last-child) {
    margin-right: 0;
    margin-bottom: 0;
  }

  /* Replace horizontal arrow with vertical arrow */
  .pipeline-step:not(:last-child)::after {
    top: auto;
    bottom: -0.85rem;
    right: 50%;
    transform: translateX(50%);
    border-top: 12px solid var(--pipeline-connector);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: none;
  }

  .pipeline-step:not(:last-child)::before {
    top: auto;
    bottom: -0.6rem;
    right: 50%;
    transform: translateX(50%);
    width: 2px;
    height: 0.6rem;
  }

  .glass-card {
    padding: 1rem;
  }

  .code-block {
    font-size: 0.8rem;
    padding: 1rem;
    border-radius: 0.5rem;
  }

  /* Ensure tables scroll horizontally on mobile */
  .overflow-x-auto {
    -webkit-overflow-scrolling: touch;
  }

  .overflow-x-auto table {
    min-width: 28rem;
  }
}

/* --- Medium (>= 768px) --- */

@media (min-width: 768px) {
  .glass-card {
    padding: 2rem;
  }
}

/* --- Large (>= 1024px) --- */

@media (min-width: 1024px) {
  .pipeline-step {
    padding: 1.5rem 1.25rem;
  }
}

/* --- Extra Large (>= 1280px) --- */

@media (min-width: 1280px) {
  .pipeline {
    max-width: 72rem;
    margin-inline: auto;
  }
}

/* --------------------------------------------------------------------------
   Utility: Reduced Motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .fade-in {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .glass-card {
    transform: none;
    transition: none;
  }

  .glass-card.visible {
    transform: none;
  }

  body,
  body * {
    transition-duration: 0s !important;
  }

  details summary .chevron {
    transition: none;
  }
}

/* --------------------------------------------------------------------------
   Utility: High Contrast
   -------------------------------------------------------------------------- */

@media (forced-colors: active) {
  .glass-card {
    border: 2px solid CanvasText;
  }

  .gradient-text,
  .gradient-text-reverse {
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
    -webkit-text-fill-color: currentColor;
    color: LinkText;
  }

  *:focus-visible {
    outline: 3px solid Highlight;
  }
}
