/* ═══════════════════════════════════════════════════════════════════
   OS VAULT — effects.css
   Full 3D scene: scroll depth, barrel focus, paper roll, animations
   Load AFTER style.css
   ═══════════════════════════════════════════════════════════════════ */

/* ─── 1. ROOT 3D SCENE ───────────────────────────────────────────── */
:root {
  --scene-perspective: 1200px;
  --card-focus-scale:  1.05;
  --card-blur-scale:   0.84;
  --card-far-scale:    0.70;
  --row-focus-z:       40px;
  --row-blur-z:        -40px;
  --row-far-z:         -100px;
}

/* DO NOT add perspective to body — it breaks position:fixed on modal,
   specs panel, USB calc, compare tray, and tool panels.
   Perspective lives only on the grids via cards-grid in section 2. */

.vault-main {
  /* No perspective here either — individual grids have it */
}

/* ─── 2. CARD HOVER 3D ZOOM — pure CSS, no row wrapping ─────────── */
/*
   When any card in a grid is hovered:
   - Hovered card: punches forward with translateZ + scale
   - All other cards in same grid: dim and slightly shrink back
   No JS required. No layout interference.
*/

/* Give grids a perspective so translateZ on cards renders in 3D */
.cards-grid,
.distro-family-grid {
  perspective: 1000px;
  perspective-origin: 50% 50%;
}

/* When a grid has a hovered card, dim all other cards */
.cards-grid:has(.iso-card:hover) .iso-card:not(:hover),
.distro-family-grid:has(.iso-card:hover) .iso-card:not(:hover) {
  transform: scale(0.96) translateZ(-20px);
  opacity: 0.65;
  filter: brightness(0.75) blur(0.4px);
  transition:
    transform  0.38s cubic-bezier(0.16, 1, 0.3, 1),
    opacity    0.38s ease,
    filter     0.38s ease;
}

/* Hovered card: punch forward */
.iso-card:hover {
  transform: scale(1.06) translateZ(40px) !important;
  opacity: 1 !important;
  filter: brightness(1.05) !important;
  z-index: 20;
  box-shadow:
    0 28px 80px rgba(0,0,0,0.72),
    0 0 0 1px rgba(212,175,55,0.35),
    0 0 48px rgba(212,175,55,0.12);
  border-color: var(--glass-border-gold) !important;
  transition:
    transform  0.32s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity    0.25s ease,
    filter     0.25s ease,
    box-shadow 0.32s ease,
    border-color 0.25s !important;
}

/* When grid has NO hover (mouse left): all cards return to normal */
.cards-grid .iso-card,
.distro-family-grid .iso-card {
  transition:
    transform    0.45s cubic-bezier(0.16, 1, 0.3, 1),
    opacity      0.45s ease,
    filter       0.45s ease,
    box-shadow   0.35s ease,
    border-color 0.25s;
  will-change: transform, opacity;
}

/* Override the old JS tilt — CSS handles it now */
.iso-card[style*="perspective"] {
  transform: none !important;
}

/* ─── 3. BACKGROUND 3D GRID MESH ─────────────────────────────────── */
.vault-grid-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  perspective: 600px;
}

.vault-grid-mesh::before {
  content: '';
  position: absolute;
  bottom: -20%;
  left: -50%;
  right: -50%;
  height: 80%;
  background-image:
    linear-gradient(rgba(212,175,55,0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(212,175,55,0.07) 1px, transparent 1px);
  background-size: 60px 60px;
  transform: rotateX(72deg) translateZ(0);
  transform-origin: bottom center;
  animation: gridScroll 14s linear infinite;
  mask-image: linear-gradient(to top, rgba(212,175,55,0.6) 0%, transparent 70%);
  -webkit-mask-image: linear-gradient(to top, rgba(212,175,55,0.5) 0%, transparent 70%);
}

@keyframes gridScroll {
  from { background-position: 0 0; }
  to   { background-position: 0 60px; }
}

.vault-grid-mesh::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 50% at 50% 100%,
    rgba(212,175,55,0.06) 0%, transparent 70%);
  pointer-events: none;
}

/* ─── 4. LOGO ENTRANCE ANIMATION ─────────────────────────────────── */
.vault-logo {
  animation: logoEntrance 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes logoEntrance {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.92);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

.logo-icon {
  animation: logoIconPop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s both;
}

@keyframes logoIconPop {
  from { transform: scale(0) rotate(-20deg); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.logo-name {
  display: inline-block;
  animation: logoNameSlide 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.2s both;
}

@keyframes logoNameSlide {
  from { opacity: 0; transform: translateX(-18px); }
  to   { opacity: 1; transform: none; }
}

.logo-accent {
  display: inline-block;
  animation: logoAccentSlide 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.28s both;
}

@keyframes logoAccentSlide {
  from { opacity: 0; transform: translateX(18px); }
  to   { opacity: 1; transform: none; }
}

/* Gold shimmer sweep across wordmark after entrance */
.logo-text {
  position: relative;
  overflow: hidden;
}

.logo-text::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255,255,255,0.35) 50%,
    transparent 100%
  );
  transform: skewX(-15deg);
  animation: logoShimmer 1.2s cubic-bezier(0.16, 1, 0.3, 1) 0.9s both;
  pointer-events: none;
}

@keyframes logoShimmer {
  from { left: -100%; }
  to   { left: 160%; }
}

/* ─── 5. SECTION HEADING LETTER-FLIP ANIMATION ───────────────────── */
/*
   JS splits .section-h2 text into individual spans with class .letter
   and adds .animate class when section enters viewport.
*/

.section-h2 {
  display: flex;
  flex-wrap: wrap;
  gap: 0.01em;
  overflow: visible;
}

.section-h2 .letter {
  display: inline-block;
  opacity: 0;
  transform: rotateX(90deg) translateY(-16px);
  transform-origin: top center;
  transition: none;
  will-change: transform, opacity;
}

.section-h2.letters-animate .letter {
  animation: letterFlip 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes letterFlip {
  from {
    opacity: 0;
    transform: rotateX(90deg) translateY(-16px);
  }
  to {
    opacity: 1;
    transform: rotateX(0deg) translateY(0);
  }
}

/* Section entrance — translateY only, no translateZ */
.os-section {
  opacity: 0;
  transform: translateY(28px) scale(0.98);
  transition:
    opacity   0.65s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.65s cubic-bezier(0.16, 1, 0.3, 1);
}

.os-section.visible {
  opacity: 1;
  transform: none;
}

/* Section icon entrance */
.section-icon {
  animation: none;
  opacity: 0;
  transform: scale(0.5) rotate(-15deg);
  transition: opacity 0.5s, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.os-section.visible .section-icon {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* Filter buttons stagger in */
.filter-btn, .subfilter-btn {
  opacity: 0;
  transform: translateX(-10px);
  transition:
    opacity       0.35s ease,
    transform     0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
    background    0.2s,
    border-color  0.2s,
    color         0.2s,
    box-shadow    0.2s;
}

.os-section.visible .filter-btn,
.os-section.visible .subfilter-btn {
  opacity: 1;
  transform: none;
}

/* Stagger filter buttons */
.filter-btn:nth-child(1), .subfilter-btn:nth-child(1) { transition-delay: 0.05s; }
.filter-btn:nth-child(2), .subfilter-btn:nth-child(2) { transition-delay: 0.10s; }
.filter-btn:nth-child(3), .subfilter-btn:nth-child(3) { transition-delay: 0.15s; }
.filter-btn:nth-child(4), .subfilter-btn:nth-child(4) { transition-delay: 0.20s; }
.filter-btn:nth-child(5), .subfilter-btn:nth-child(5) { transition-delay: 0.25s; }
.filter-btn:nth-child(6), .subfilter-btn:nth-child(6) { transition-delay: 0.30s; }
.filter-btn:nth-child(7), .subfilter-btn:nth-child(7) { transition-delay: 0.35s; }

/* ─── 6. CARD META STAGGER ───────────────────────────────────────── */
.card-meta-item {
  opacity: 0;
  transform: translateY(8px);
  animation: metaFadeUp 0.4s var(--ease-out) both;
}

.iso-card:nth-child(1) .card-meta-item:nth-child(1) { animation-delay: 0.08s; }
.iso-card:nth-child(1) .card-meta-item:nth-child(2) { animation-delay: 0.13s; }
.iso-card:nth-child(1) .card-meta-item:nth-child(3) { animation-delay: 0.18s; }
.iso-card:nth-child(2) .card-meta-item:nth-child(1) { animation-delay: 0.13s; }
.iso-card:nth-child(2) .card-meta-item:nth-child(2) { animation-delay: 0.18s; }
.iso-card:nth-child(2) .card-meta-item:nth-child(3) { animation-delay: 0.23s; }
.iso-card:nth-child(3) .card-meta-item:nth-child(1) { animation-delay: 0.18s; }
.iso-card:nth-child(4) .card-meta-item:nth-child(1) { animation-delay: 0.23s; }

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

/* ─── 7. CARD OPEN → MODAL BRIDGE ───────────────────────────────── */
/*
   JS adds .card-is-opening to the clicked card.
   After 200ms it opens the modal.
*/

.iso-card.card-is-opening {
  transform:
    perspective(800px)
    scale(1.1)
    translateZ(60px) !important;
  box-shadow:
    0 40px 100px rgba(0,0,0,0.8),
    0 0 0 2px var(--gold-400),
    0 0 60px rgba(212,175,55,0.4) !important;
  z-index: 50;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.18s ease !important;
}

/* ─── 8. MODAL ENTRANCE ANIMATION ───────────────────────────────── */
/* No perspective on .card-modal — perspective on a fixed ancestor
   breaks position:fixed children (modal renders in wrong position at zoom < 100%)  */

.modal-frame {
  transform: scale(0.88) translateY(18px);
  opacity: 0;
  transition:
    transform 0.42s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity   0.26s ease;
}

.card-modal.open .modal-frame {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.card-modal.open .modal-backdrop {
  backdrop-filter: blur(10px) saturate(130%);
  -webkit-backdrop-filter: blur(10px) saturate(130%);
}

/* Modal inner content fade up staggered */
.modal-main {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.32s ease 0.16s, transform 0.32s var(--ease-out) 0.16s;
}

.scroll-section {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.32s ease 0.22s, transform 0.32s var(--ease-out) 0.22s;
}

.card-modal.open .modal-main,
.card-modal.open .scroll-section {
  opacity: 1;
  transform: none;
}

/* ─── 9. PAPER ROLL FIX (PREVIOUS VERSIONS) ─────────────────────── */
/*
   Root cause: clip-path on scroll-parchment fought max-height on container.
   Fix: container handles max-height only.
         parchment handles the visual unroll via scaleY + clip-path on inner body.
*/

.scroll-container {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition:
    max-height  0.7s cubic-bezier(0.16, 1, 0.3, 1),
    opacity     0.35s ease;
}

.scroll-container.open {
  /* 340px fits ~8 version rows inside the capped modal */
  max-height: 340px;
  opacity: 1;
}

/* Parchment: no animation by default */
.scroll-parchment {
  transform-origin: top center;
  transform: scaleY(0);
  opacity: 0;
  max-height: 340px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(212,175,55,0.2) transparent;
  transition:
    transform 0.65s cubic-bezier(0.16, 1, 0.3, 1) 0.05s,
    opacity   0.4s ease 0.05s;
  border-radius: 12px;
  background: linear-gradient(180deg,
    rgba(212,175,55,0.07) 0%,
    var(--glass-bg) 8%,
    var(--glass-bg) 92%,
    rgba(212,175,55,0.07) 100%
  );
  border: 1px solid var(--glass-border-gold);
}

/* When open: unroll downward */
.scroll-container.open .scroll-parchment {
  transform: scaleY(1);
  opacity: 1;
}

/* Roll caps: 3D cylinder look */
.roll-cap {
  height: 22px;
  position: relative;
  display: flex;
  align-items: center;
  background: linear-gradient(180deg,
    rgba(212,175,55,0.28) 0%,
    rgba(212,175,55,0.12) 40%,
    rgba(212,175,55,0.20) 100%
  );
  border-bottom: 1px solid rgba(212,175,55,0.3);
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.1),
    inset 0 -2px 4px rgba(0,0,0,0.2),
    0 4px 12px rgba(0,0,0,0.3);
  transform-style: preserve-3d;
}

.roll-cap::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    rgba(0,0,0,0.12) 0%,
    transparent 15%,
    transparent 85%,
    rgba(0,0,0,0.12) 100%
  );
  border-radius: inherit;
}

.roll-bottom {
  border-top: 1px solid rgba(212,175,55,0.3);
  border-bottom: none;
  box-shadow:
    inset 0 -2px 4px rgba(255,255,255,0.08),
    inset 0 2px 4px rgba(0,0,0,0.15),
    0 -4px 12px rgba(0,0,0,0.2);
}

.roll-cylinder {
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    90deg,
    transparent 0px,
    transparent 22px,
    rgba(212,175,55,0.1) 22px,
    rgba(212,175,55,0.1) 23px
  );
}

/* Scroll body: rows stagger in after unroll */
.scroll-body { padding: 14px 16px; }

.prev-version-row {
  opacity: 0;
  transform: translateX(-14px);
  transition: none;
}

.scroll-container.open .prev-version-row {
  animation: prevRowSlide 0.38s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Stagger each row */
.scroll-container.open .prev-version-row:nth-child(1)  { animation-delay: 0.28s; }
.scroll-container.open .prev-version-row:nth-child(2)  { animation-delay: 0.33s; }
.scroll-container.open .prev-version-row:nth-child(3)  { animation-delay: 0.38s; }
.scroll-container.open .prev-version-row:nth-child(4)  { animation-delay: 0.43s; }
.scroll-container.open .prev-version-row:nth-child(5)  { animation-delay: 0.48s; }
.scroll-container.open .prev-version-row:nth-child(6)  { animation-delay: 0.53s; }
.scroll-container.open .prev-version-row:nth-child(7)  { animation-delay: 0.58s; }
.scroll-container.open .prev-version-row:nth-child(8)  { animation-delay: 0.63s; }
.scroll-container.open .prev-version-row:nth-child(9)  { animation-delay: 0.68s; }
.scroll-container.open .prev-version-row:nth-child(10) { animation-delay: 0.73s; }

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

/* ─── 10. BUTTON 3D DEPTH MICRO-INTERACTIONS ─────────────────────── */
.card-btn,
.modal-btn,
.filter-btn,
.subfilter-btn,
.nav-btn,
.tool-btn-trigger,
.tool-dl-btn,
.prev-btn {
  transform-style: preserve-3d;
}

.card-btn:hover {
  transform: translateY(-3px) translateZ(8px);
}

.card-btn:active {
  transform: translateY(0) translateZ(0);
}

.modal-btn:hover {
  transform: translateY(-3px) translateZ(10px);
}

.nav-btn:hover {
  transform: translateY(-2px) translateZ(6px);
}

.tool-dl-btn:hover {
  transform: translateY(-3px) translateZ(12px) scale(1.02);
}

/* ─── 11. GOLD FLAKE BEZIER DRIFT ────────────────────────────────── */
/* Override the existing simple fall with bezier path drift */
.gold-flake-particle {
  animation: flakeDrift linear infinite !important;
}

/* Each particle gets its own drift amount via inline style offset */
@keyframes flakeDrift {
  0%   { transform: translate(0, -10px) rotate(0deg);    opacity: 0; }
  8%   { opacity: 0.85; }
  25%  { transform: translate(12px, 22vh) rotate(90deg); }
  50%  { transform: translate(-8px, 50vh) rotate(200deg); opacity: 0.65; }
  75%  { transform: translate(16px, 75vh) rotate(340deg); }
  92%  { opacity: 0.4; }
  100% { transform: translate(-4px, 108vh) rotate(480deg); opacity: 0; }
}

/* Varied drift for different particles via nth-child offsets */
.gold-flake-particle:nth-child(odd) {
  animation-name: flakeDriftAlt !important;
}

@keyframes flakeDriftAlt {
  0%   { transform: translate(0, -10px) rotate(0deg);      opacity: 0; }
  8%   { opacity: 0.7; }
  30%  { transform: translate(-14px, 28vh) rotate(120deg); }
  55%  { transform: translate(10px, 52vh) rotate(260deg);  opacity: 0.55; }
  80%  { transform: translate(-18px, 80vh) rotate(400deg); }
  92%  { opacity: 0.3; }
  100% { transform: translate(6px, 108vh) rotate(520deg);  opacity: 0; }
}

/* ─── 12. LOADER EXIT WITH DEPTH ─────────────────────────────────── */
.vault-loader.done {
  opacity: 0;
  transform: scale(1.04) translateZ(60px);
  transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.16,1,0.3,1), visibility 0.7s;
}

/* ─── 13. HEADER SCROLL STATE 3D SHADOW ─────────────────────────── */
.vault-header {
  transform-style: preserve-3d;
  transition: background 0.4s, box-shadow 0.4s, transform 0.3s;
}

.vault-header.scrolled {
  box-shadow:
    0 1px 0 rgba(212,175,55,0.22),
    0 8px 48px rgba(0,0,0,0.55),
    0 16px 64px rgba(0,0,0,0.2);
}

/* ─── 14. CARD ENTRANCE DEPTH STAGGER ────────────────────────────── */
@keyframes cardEntrance3D {
  from {
    opacity: 0;
    transform: perspective(800px) translateZ(-80px) translateY(24px) scale(0.93);
    filter: blur(2px);
  }
  to {
    opacity: 1;
    transform: perspective(800px) translateZ(0) translateY(0) scale(1);
    filter: none;
  }
}

/* Override existing cardEntrance with 3D version */
.iso-card {
  animation: cardEntrance3D 0.65s var(--ease-out) both !important;
}

/* ─── 15. DISTRO FAMILY HOVER ────────────────────────────────────── */
.distro-family {
  transition: box-shadow 0.3s, border-color 0.3s;
}

.distro-family:hover {
  box-shadow:
    0 12px 40px rgba(0,0,0,0.4),
    0 0 0 1px rgba(212,175,55,0.2);
  border-color: var(--glass-border-gold);
}

/* ─── 16. SECTION COUNT BADGE POP ────────────────────────────────── */
.section-count {
  animation: badgePop 0.5s cubic-bezier(0.34,1.56,0.64,1) 0.6s both;
}

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

/* ─── 17. VAULT STATS COUNTER SLIDE ─────────────────────────────── */
.stat {
  opacity: 0;
  transform: translateY(-8px);
  animation: statSlideIn 0.5s cubic-bezier(0.16,1,0.3,1) both;
}

.stat:nth-child(1) { animation-delay: 0.4s; }
.stat:nth-child(3) { animation-delay: 0.55s; }

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

/* ─── 18. SCROLL TOGGLE BUTTON 3D ───────────────────────────────── */
.scroll-toggle {
  transform-style: preserve-3d;
  transition:
    background   0.25s,
    border-color 0.25s,
    color        0.25s,
    transform    0.25s cubic-bezier(0.34,1.56,0.64,1),
    box-shadow   0.25s;
}

.scroll-toggle:hover {
  transform: translateZ(8px) scale(1.01);
  box-shadow: 0 6px 20px rgba(212,175,55,0.15);
}

/* ─── 19. PREFERS REDUCED MOTION SAFETY ──────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration:   0.01ms !important;
    animation-delay:      0ms    !important;
    transition-duration:  0.01ms !important;
  }

  .vault-grid-mesh::before { animation: none; }
  .gold-flake-particle     { display: none;   }
}
