/* ===========================
   3D Video Stage & Showcase
   =========================== */

/* ---- Ambient Canvas ---- */
#ambient-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-ambient);
  pointer-events: none;
}

/* ---- Stage Container ---- */
#stage {
  position: relative;
  z-index: var(--z-stage);
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  padding: 68px 36px 96px;
  gap: 28px;
  box-sizing: border-box;
  perspective: 1800px;
}

/* ---- 3D Device Frame ---- */
#video-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transform-style: preserve-3d;
  transition: transform var(--transition-slow);
}

#device-frame {
  position: relative;
  width: 100%;
  max-width: 1080px;
  max-height: calc(100vh - 190px);
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-lg);
  overflow: hidden;
  transform-style: preserve-3d;
  transition: transform var(--transition-slow), box-shadow var(--transition-normal);
  /* 3D parallax tilt – updated dynamically */
  transform: rotateX(1.5deg) rotateY(0deg);
  will-change: transform;

  /* Bezel gradient */
  background: linear-gradient(145deg, #181c2e 0%, #0d0f1a 100%);
  padding: 4px;

  /* Glow shadow */
  box-shadow:
    0 0 0 1px rgba(var(--accent-rgb), 0.16),
    0 8px 36px rgba(0, 0, 0, 0.55),
    0 0 70px rgba(var(--accent-rgb), 0.08),
    0 20px 80px rgba(0, 0, 0, 0.45);
  animation: glow-pulse 4s ease-in-out infinite;
}

/* Accent border ring */
#device-frame::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(var(--accent-rgb), 0.22);
  z-index: 3;
  pointer-events: none;
  transition: border-color var(--transition-normal);
}

/* ---- Video Container ---- */
#video-container {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--radius-lg) - 4px);
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#video-container video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #020408;
  opacity: 0;
  transition: opacity 700ms ease;
  will-change: opacity, transform;
}

#video-container video.active {
  opacity: 1;
  z-index: 1;
}

/* ---- Glass Reflection Overlay ---- */
.frame-reflection {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  background: linear-gradient(
    168deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.01) 20%,
    transparent 50%,
    transparent 100%
  );
  z-index: 2;
  pointer-events: none;
}

/* ---- Stage Shadow (beneath device) ---- */
.stage-shadow {
  width: 75%;
  height: 24px;
  margin-top: 14px;
  background: radial-gradient(ellipse at center, rgba(var(--accent-rgb), 0.16) 0%, transparent 70%);
  filter: blur(14px);
  transition: background var(--transition-normal);
}

/* ---- Video Transition Classes ---- */
.video-transition-enter {
  animation: videoEnter 700ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

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

.video-transition-exit {
  animation: videoExit 700ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

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

/* ===========================
   Matrix Grid Mode
   =========================== */
#matrix-grid {
  position: fixed;
  inset: 0;
  z-index: var(--z-matrix);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 8px;
  padding: 72px 20px 20px;
  background: var(--bg-primary);
  opacity: 0;
  visibility: hidden;
  transition: opacity 600ms var(--ease-out-expo), visibility 0s 600ms;
}

#matrix-grid.visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 600ms var(--ease-out-expo), visibility 0s;
}

.matrix-cell {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #0a0c16;
  border: 2px solid transparent;
  transition: border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  cursor: pointer;
}

.matrix-cell:hover {
  border-color: rgba(var(--accent-rgb), 0.5);
  transform: scale(1.015);
  box-shadow: 0 0 40px rgba(var(--accent-rgb), 0.18);
  z-index: 2;
}

.matrix-cell video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.matrix-cell .matrix-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 16px 14px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, transparent 100%);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.matrix-label .matrix-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  flex-shrink: 0;
}

/* ===========================
   Big-Screen Responsive
   =========================== */
@media (min-width: 2560px) {
  #device-frame {
    max-width: 1400px;
    padding: 7px;
  }
}

@media (min-width: 3840px) {
  #device-frame {
    max-width: 2000px;
    padding: 10px;
  }
  .matrix-cell .matrix-label {
    font-size: var(--text-2xl);
    padding: 30px 24px 18px;
  }
}
