/* Register CSS custom properties for animation interpolation */
@property --spacing {
  syntax: '<length>';
  inherits: true;
  initial-value: 0px;
}

/* Essential Overrides */
body {
  overflow-x: hidden;
  background-color: #111111; /* Dark background matches hero */
  color: #ffffff;
  -webkit-font-smoothing: antialiased;
}

interact-element {
  display: block;
}

/* HERO GRID STYLES */
.hero-grid-container {
  display: grid;
  /* Dense grid of small lines */
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  grid-template-rows: repeat(auto-fill, minmax(40px, 1fr));
  width: 100%;
  height: 100%;
  /* Masking the edges slightly */
  mask-image: linear-gradient(to bottom, black 80%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, black 80%, transparent 100%);
}

.text-stroke-black {
  -webkit-text-stroke-width: 12px;
  -webkit-text-stroke-color: #111111;
  paint-order: stroke fill;
  filter: drop-shadow(0px 0px 2px #111111);
}

.grid-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.grid-line {
  width: 2px;
  height: 24px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.05) 0%, #ffffff 100%);
  transform-origin: top;
  will-change: transform;
  border-radius: 2px;
}

@media (max-width: 1000px) {
  .grid-line {
    height: 12px;
  }
}

/* CRITICAL ANIMATION STYLES (Preserved for other sections) */
.sticky-wrapper {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: clip; /* Required for ViewTimeline */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Card Spread Styles */
.spread-card {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 350px;
  height: 500px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  will-change: transform;
  filter: drop-shadow(0 25px 25px rgba(0, 0, 0, 0.15));
}

.spread-card-init {
  transform: translate(-50%, -50%);
}
/* Z-Index desktop card spread */
[data-interact-key='spread-card-0'] .spread-card {
  z-index: 5;
}
[data-interact-key='spread-card-1'] .spread-card {
  z-index: 4;
}
[data-interact-key='spread-card-2'] .spread-card {
  z-index: 3;
}
[data-interact-key='spread-card-3'] .spread-card {
  z-index: 2;
}
[data-interact-key='spread-card-4'] .spread-card {
  z-index: 1;
}

/* Mobile overrides for card spread */
@media (max-width: 1000px) {
  #spread-section {
    height: 500vh !important;
  }

  .spread-card {
    top: 15vh;
    left: 50%;
    width: 85vw;
    height: 65vh;
    max-width: 400px;
    background-size: contain;
    box-shadow: none;
    border-radius: 0;
    transform: translateX(-50%);
  }
  [data-interact-key='spread-card-0'] .spread-card {
    transform: translateX(-50%) translateY(0);
    z-index: 1;
  }
  [data-interact-key='spread-card-1'] .spread-card {
    transform: translateX(-50%) translateY(100vh);
    z-index: 2;
  }
  [data-interact-key='spread-card-2'] .spread-card {
    transform: translateX(-50%) translateY(100vh);
    z-index: 3;
  }
  [data-interact-key='spread-card-3'] .spread-card {
    transform: translateX(-50%) translateY(100vh);
    z-index: 4;
  }
  [data-interact-key='spread-card-4'] .spread-card {
    transform: translateX(-50%) translateY(100vh);
    z-index: 5;
  }
}

/* TUNNEL EFFECT STYLES */
.tunnel-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  /* pointer-events: none; */
  z-index: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Updated Tunnel Circle Styles */
.tunnel-circle {
  display: flex;
  justify-content: center;
  align-items: center;

  border-radius: 50%;
  /* The border color is now set dynamically in JS for the depth/gradient effect */
  border: 1px solid rgba(255, 255, 255, 1);
  will-change: transform;

  opacity: 0.6;

  flex-shrink: 0;
  max-width: none;
  max-height: none;

  width: 93%;
  height: 93%;

  /* Enhanced 3D shadow effect */
  box-shadow:
    inset 3px 3px 6px rgba(255, 255, 255, 0.3),
    inset -3px -3px 6px rgba(0, 0, 0, 0.8);
}

/* Updated constraints for the tunnel circles inside the new container */
.tunnel-container > .tunnel-circle {
  width: 50vmax;
  height: 50vmax;
  margin: auto;
}

/* Horizontal Scroll Styles */
.horizontal-track {
  display: flex;
  gap: 8rem;
  align-items: flex-end;
  padding-left: calc(50vw - 300px);
  padding-right: 50vw;
  will-change: transform;
  width: max-content;
}

.h-card {
  width: 600px;
  height: 400px;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  border-radius: 4px;
  transform-origin: center center;
  will-change: transform;
  /* Added for hover content */
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

/* Mobile responsive for horizontal scroll cards */
@media (max-width: 1000px) {
  .horizontal-track {
    gap: 4vw;
    padding-left: 2.5vw; /* Centers 95vw card: 50vw - 47.5vw */
    padding-right: 50vw;
  }

  .h-card {
    width: 95vw;
    height: 63.33vw; /* Maintains 1.5:1 aspect ratio */
    border-radius: 12px;
  }
}

/* NEW COMPONENT STYLES */
.custom-scrollbar::-webkit-scrollbar {
  width: 3px;
  height: 3px;
}
.custom-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
  background: #bde1ff;
  border-radius: 3px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: #bde1ff;
}

/* Existing Circle Style for Primitives */
.circle {
  width: 16rem; /* w-64 */
  height: 16rem; /* h-64 */
  background-color: transparent;
  border: 1px solid white; /* Ensures white outline on white bg too? No, needs contrast */
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  will-change: transform;
}

.fill-circle {
  width: 100%;
  height: 100%;
  /* Reverted back to solid white */
  background-color: white;
  border-radius: 50%;
  transform: scale(0);
  will-change: transform;
}

/* Utility */
.card-shadow {
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15);
}

.hover-target {
  box-shadow: inset 0 0 0 160px #f3f4f6;
}

/* Initial states for ripples: hidden and slightly smaller */
.ripple-init {
  opacity: 0;
  transform: scale(0.8);
}

/* --- MOUSE TRACK TUNNEL STYLES --- */
.preserve-3d {
  transform-style: preserve-3d;
}

.ring-base {
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.8);
  /* pointer-events: none; */
  position: absolute;
}

.tunnel-static {
  width: 14rem; /* Scaled to fit card */
  height: 14rem;
  border-width: 2px;
  border-color: rgba(255, 255, 255, 0.4);
  z-index: 10;
}

.tunnel-moving {
  width: 85%;
  height: 85%;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* --- PYRAMID STYLES (NEW) --- */
.pyramid-wrapper {
  position: relative;
  width: 400px;
  height: 400px;
  transform-style: preserve-3d;
  z-index: 20;
  transform: scale(0.76);
  transform-origin: center;
}
@media (max-width: 740px) {
  .pyramid-wrapper {
    transform-origin: top center;
    transform: scale(0.45);
  }
}

/* Target Element for Rotation */
.pyramid-rotator {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform-origin: 50% 57%;
  /* Starts at 0, driven by scroll */
  transform: rotateX(0deg) rotateY(0deg);
}

.face {
  position: absolute;
  width: 400px;
  height: 400px;
  box-sizing: border-box;
  pointer-events: none;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  backface-visibility: visible;
  transform-origin: bottom center;
}

.face svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.face polygon,
.face rect {
  vector-effect: non-scaling-stroke;
  stroke: #ffffff;
  stroke-width: 1.5;
}

/* Geometry */
.face.front {
  transform: translateZ(200px) rotateX(30deg);
}
.face.back {
  transform: rotateY(180deg) translateZ(200px) rotateX(30deg);
}
.face.right {
  transform: rotateY(90deg) translateZ(200px) rotateX(30deg);
}
.face.left {
  transform: rotateY(-90deg) translateZ(200px) rotateX(30deg);
}
.face.base {
  transform-origin: center center;
  transform: rotateX(90deg) translateZ(-200px);
  align-items: center;
}

/* --- TEXT/CONTENT STYLES (NEW) --- */
.content-layer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  text-align: center;
  mix-blend-mode: normal;
  width: 100%;
}

.scene-container {
  flex-direction: column;
  perspective: 500px;
  gap: 2rem;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  z-index: 100;
  display: none;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: white;
  border: 1px solid #eee;
  width: 90%;
  max-width: 800px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.1);
  border-radius: 16px;
}

.code-block {
  background: #f9f9f9;
  padding: 1.5rem;
  font-family: 'Menlo', 'Monaco', monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  color: #333;
  overflow-x: auto;
  border-left: 2px solid #111;
  white-space: pre;
}

.hljs {
  background: transparent !important;
}

/* --- MENGER SPONGE STYLES --- */

/* Mobile fix: Give sections more vertical space to prevent clipping */
@media (max-width: 1000px) {
  /* Cube section */
  [data-interact-key='cube-section'] > section {
    min-height: 100vh;
    height: auto;
    padding-bottom: 6rem;
  }

  [data-interact-key='cube-section'] .sticky-wrapper {
    position: relative;
    height: auto;
    min-height: 100vh;
    padding-top: 2rem;
    padding-bottom: 6rem;
  }

  /* Performance section */
  [data-interact-key='performance-section'] > section {
    min-height: 100vh;
    height: auto;
    padding-bottom: 4rem;
  }

  [data-interact-key='performance-section'] .sticky-wrapper {
    position: relative;
    height: auto;
    min-height: 100vh;
    padding-top: 2rem;
    padding-bottom: 6rem;
  }
}

.scene-container-2 {
  perspective: 1200px;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-style: preserve-3d;
  /* Removed overflow: hidden to allow the sponge to explode outside its box */
}

/* Sponge interaction wrapper */
.interact-sponge-wrapper {
  width: 320px;
  height: 320px;
  transform-style: preserve-3d;
  position: relative;
  cursor: pointer;
  z-index: 10;
}

.sponge-root {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  will-change: transform;
}

.voxel {
  position: absolute;
  top: 0;
  left: 0;
  width: 60px;
  height: 60px;
  transform-style: preserve-3d;
  will-change: transform;
  margin-left: -30px;
  margin-top: -30px;
  pointer-events: none;

  /* CSS Var --spacing is animated by Interact via WAAPI */
  transform: translate3d(
    calc(var(--x) * (60px + var(--spacing))),
    calc(var(--y) * (60px + var(--spacing))),
    calc(var(--z) * (60px + var(--spacing)))
  );
}

.cube-face {
  position: absolute;
  box-sizing: border-box;
  width: 60px;
  height: 60px;
  /* Fills are now 70% opacity */
  background-color: rgba(23, 23, 23, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.9);
  backface-visibility: hidden;
  transform-origin: center center;
  pointer-events: none;
}

::-webkit-scrollbar {
  width: 0px;
}
