/* ==========================================================================
   Antikythera Mechanism Scroll-Driven Animation
   ========================================================================== */

/* Main scroll section — tall enough to give scroll room */
.mechanism-scroll {
  position: relative;
  height: 500vh;
  background: #000;
  /* Do NOT use overflow:hidden here — it breaks position:sticky on the viewport */
}

/* Sticky viewport that holds the canvas and overlays */
.mechanism-viewport {
  position: sticky;
  top: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: clip;
}

/* Canvas fills the viewport */
.mechanism-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Dark gradient overlays for text readability */
.mechanism-viewport::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 30% 50%, rgba(0, 0, 0, 0.3) 0%, transparent 70%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.2) 0%, transparent 20%, transparent 80%, rgba(0, 0, 0, 0.4) 100%);
  z-index: 2;
  pointer-events: none;
}

/* Text overlay container */
.mechanism-text-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
}

/* Individual milestone text blocks */
.mechanism-milestone {
  position: absolute;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.1s ease-out, transform 0.1s ease-out;
  pointer-events: none;
  max-width: 500px;
  padding: 1.25rem 1.5rem;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(122, 162, 247, 0.15);
  border-radius: 12px;
}

/* First milestone: bottom-left (video shows gears left, title right) */
.mechanism-milestone--1 {
  bottom: 15%;
  left: 5%;
  text-align: left;
}

/* Second milestone: top-left (video starts showing AI face center, text right) */
.mechanism-milestone--2 {
  top: 12%;
  left: 5%;
  text-align: left;
}

/* Third milestone: bottom-left (video shows contact details on right) */
.mechanism-milestone--3 {
  bottom: 15%;
  left: 5%;
  text-align: left;
}

/* Fourth milestone: top-left area */
.mechanism-milestone--4 {
  top: 12%;
  left: 5%;
  text-align: left;
  max-width: 500px;
}

/* Milestone typography */
.milestone-quote {
  font-family: var(--font-display, 'Orbitron', sans-serif);
  font-size: clamp(1.1rem, 2.5vw, 1.6rem);
  font-weight: 600;
  line-height: 1.4;
  color: #c0caf5;
  text-shadow:
    0 0 30px rgba(122, 162, 247, 0.4),
    0 2px 10px rgba(0, 0, 0, 0.8);
  letter-spacing: 0.02em;
}

.milestone-quote em {
  font-style: normal;
  background: linear-gradient(135deg, #7aa2f7, #bb9af7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.milestone-sub {
  font-family: var(--font-body, 'Roboto', sans-serif);
  font-size: clamp(0.85rem, 1.5vw, 1rem);
  color: rgba(169, 177, 214, 0.8);
  margin-top: 0.5rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

/* Progress bar at bottom */
.mechanism-progress-track {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: rgba(192, 202, 245, 0.1);
  z-index: 4;
}

.mechanism-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #7aa2f7, #bb9af7, #7dcfff);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 0.05s linear;
}

/* Scroll indicator hint */
.mechanism-scroll-hint {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  opacity: 0.7;
  animation: mechanism-hint-pulse 2s ease-in-out infinite;
  transition: opacity 0.5s ease;
}

.mechanism-scroll.frames-ready .mechanism-scroll-hint {
  opacity: 0.7;
}

/* Hide hint after user starts scrolling */
.mechanism-scroll.scrolled .mechanism-scroll-hint {
  opacity: 0;
  pointer-events: none;
}

.mechanism-scroll-hint span {
  font-family: var(--font-body, 'Roboto', sans-serif);
  font-size: 0.75rem;
  color: rgba(192, 202, 245, 0.6);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.mechanism-scroll-hint .scroll-arrow {
  width: 20px;
  height: 20px;
  border-right: 2px solid rgba(122, 162, 247, 0.5);
  border-bottom: 2px solid rgba(122, 162, 247, 0.5);
  transform: rotate(45deg);
  animation: mechanism-arrow-bounce 2s ease-in-out infinite;
}

@keyframes mechanism-hint-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 0.4; }
}

@keyframes mechanism-arrow-bounce {
  0%, 100% { transform: rotate(45deg) translateY(0); }
  50% { transform: rotate(45deg) translateY(6px); }
}

/* Frame loading overlay */
.mechanism-loader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  transition: opacity 0.8s ease, visibility 0.8s ease;
}

.mechanism-loader.loaded {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-track {
  width: 200px;
  height: 2px;
  background: rgba(192, 202, 245, 0.1);
  border-radius: 1px;
  overflow: hidden;
}

.loader-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7aa2f7, #bb9af7);
  transition: width 0.15s ease-out;
}

.loader-text {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 0.75rem;
  color: rgba(192, 202, 245, 0.5);
  margin-top: 0.75rem;
  letter-spacing: 0.1em;
}

.loader-label {
  font-family: var(--font-body, 'Roboto', sans-serif);
  font-size: 0.7rem;
  color: rgba(192, 202, 245, 0.3);
  margin-top: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

/* Transition from mechanism section to story section */
.mechanism-scroll::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 200px;
  background: linear-gradient(to bottom, transparent, var(--tn-bg-primary, #1a1b26));
  z-index: 6;
  pointer-events: none;
}

/* ==========================================================================
   Mobile Fallback
   ========================================================================== */
.mechanism-scroll.mechanism-mobile {
  height: auto;
  min-height: 100vh;
}

.mechanism-mobile .mechanism-viewport {
  position: relative;
  height: auto;
  overflow: visible;
  flex-direction: column;
}

.mechanism-mobile .mechanism-canvas {
  position: relative;
  height: 50vh;
  width: 100%;
  flex-shrink: 0;
}

/* Video element on mobile — replaces canvas */
.mechanism-mobile .mechanism-video {
  object-fit: contain;
  background: #000;
}

.mechanism-mobile .mechanism-milestone {
  position: relative;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.8s ease, transform 0.8s ease;
  padding: 2rem 1.5rem;
  max-width: 100%;
  top: auto;
  left: auto;
  right: auto;
  bottom: auto;
  text-align: center;
}

.mechanism-mobile .mechanism-milestone.visible {
  opacity: 1;
  transform: translateY(0);
}

.mechanism-mobile .mechanism-text-overlay {
  position: relative;
  background: linear-gradient(to bottom, #000, var(--tn-bg-primary, #1a1b26));
  padding: 2rem 0;
}

.mechanism-mobile .mechanism-scroll::after {
  display: none;
}

.mechanism-mobile .mechanism-scroll-hint {
  display: none;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1024px) {
  .mechanism-milestone {
    max-width: 380px;
  }

  .mechanism-milestone--1 {
    top: 12%;
    right: 3%;
  }

  .mechanism-milestone--2 {
    top: 32%;
    left: 3%;
  }

  .mechanism-milestone--3 {
    bottom: 28%;
    right: 3%;
  }

  .milestone-quote {
    font-size: clamp(1rem, 2vw, 1.3rem);
  }
}

@media (max-width: 768px) {
  .mechanism-scroll {
    height: auto;
    min-height: 100vh;
  }

  .mechanism-viewport {
    position: relative;
    height: auto;
    overflow: visible;
    flex-direction: column;
  }

  .mechanism-canvas {
    position: relative;
    height: 50vh;
    width: 100%;
    flex-shrink: 0;
  }

  .mechanism-milestone {
    position: relative;
    max-width: 100%;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    text-align: center;
    padding: 1.5rem;
  }

  .mechanism-text-overlay {
    position: relative;
    background: linear-gradient(to bottom, #000, var(--tn-bg-primary, #1a1b26));
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .mechanism-milestone {
    opacity: 0;
    transform: translateY(20px) !important;
    transition: opacity 0.6s ease, transform 0.6s ease;
  }

  .mechanism-milestone.visible {
    opacity: 1 !important;
    transform: translateY(0) !important;
  }

  .mechanism-scroll::after {
    display: none;
  }

  .mechanism-scroll-hint {
    display: none;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .mechanism-scroll {
    height: auto;
  }

  .mechanism-viewport {
    position: relative;
    height: 60vh;
  }

  .mechanism-milestone {
    transition: none;
    opacity: 1;
    transform: none;
  }

  .mechanism-scroll-hint {
    display: none;
  }
}
