/* ==========================================================================
   ENHANCEMENT LAYER — 3D hero, Face ID scanner, motion system, mobile polish
   Loaded after style.css; every rule here either adds to or overrides it.
   ========================================================================== */

:root {
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ==========================================================================
   SCROLL PROGRESS METER
   ========================================================================== */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--accent-emerald), var(--accent-cyan), var(--accent-violet));
  box-shadow: 0 0 12px rgba(0, 245, 160, 0.6);
  z-index: 1200;
  pointer-events: none;
  will-change: transform;
}

/* ==========================================================================
   3D BINARY RAIN CANVAS
   ========================================================================== */
.binary-rain-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.72;
  /* Vignette the rain toward the edges so hero copy stays readable. */
  -webkit-mask-image: radial-gradient(ellipse 72% 78% at 50% 45%, rgba(0, 0, 0, 0.35) 0%, #000 62%);
  mask-image: radial-gradient(ellipse 72% 78% at 50% 45%, rgba(0, 0, 0, 0.35) 0%, #000 62%);
}

.hero-section {
  overflow: hidden;
  isolation: isolate;
}

/* Keep hero content above the rain. */
.hero-section .container { position: relative; z-index: 2; }

/* Depth-of-field haze behind the hero copy. */
.hero-content::before {
  content: '';
  position: absolute;
  inset: -8% -12%;
  background: radial-gradient(ellipse at 30% 50%, rgba(7, 10, 15, 0.82) 0%, transparent 68%);
  z-index: -1;
  pointer-events: none;
}
.hero-content { position: relative; }

/* ==========================================================================
   HERO PORTRAIT — 3D ANGLED RIG
   ========================================================================== */
.hero-visual {
  perspective: 1400px;
  perspective-origin: 50% 50%;
  padding: 30px 10px;
}

.cyber-frame {
  /* Base pose: the frame sits at an angle, pointer tilt layers on top. */
  --tilt-x: 0deg;
  --tilt-y: 0deg;
  --glare-x: 50%;
  --glare-y: 30%;
  transform-style: preserve-3d;
  transform:
    rotateX(calc(4deg + var(--tilt-x)))
    rotateY(calc(-14deg + var(--tilt-y)))
    translateZ(0);
  transition: transform 0.6s var(--ease-out-expo), box-shadow 0.6s var(--ease-out-expo);
  box-shadow:
    -28px 34px 70px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(0, 245, 160, 0.18),
    var(--glow-emerald);
  overflow: visible;           /* let depth layers escape the box */
  animation: frame-float 9s ease-in-out infinite;
}

/* While the pointer drives it, kill the slow transition and the float. */
.cyber-frame.tilting {
  transition: box-shadow 0.4s var(--ease-out-expo);
  animation: none;
  box-shadow:
    -34px 40px 90px rgba(0, 0, 0, 0.78),
    0 0 0 1px rgba(0, 245, 160, 0.35),
    0 0 50px rgba(0, 245, 160, 0.3);
}

/* Touch devices get a gentle automatic orbit instead of pointer tilt. */
.cyber-frame.auto-orbit { animation: frame-orbit 12s ease-in-out infinite; }

@keyframes frame-float {
  0%, 100% { transform: rotateX(4deg) rotateY(-14deg) translate3d(0, 0, 0); }
  50%      { transform: rotateX(6deg) rotateY(-10deg) translate3d(0, -12px, 20px); }
}

@keyframes frame-orbit {
  0%, 100% { transform: rotateX(4deg) rotateY(-13deg) translate3d(0, 0, 0); }
  25%      { transform: rotateX(6deg) rotateY(-4deg) translate3d(0, -8px, 14px); }
  50%      { transform: rotateX(3deg) rotateY(4deg)  translate3d(0, 0, 0); }
  75%      { transform: rotateX(6deg) rotateY(-6deg) translate3d(0, -8px, 14px); }
}

/* Image wrapper needs its own clipping context inside the 3D frame. */
.frame-image-wrapper {
  overflow: hidden;
  transform: translateZ(0);
}

/* Floating parallax planes that sell the depth. */
.frame-depth-layer {
  position: absolute;
  inset: -1px;
  border-radius: 16px;
  pointer-events: none;
}

.depth-grid {
  transform: translateZ(-46px) scale(1.06);
  background-image:
    linear-gradient(rgba(0, 245, 160, 0.10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 245, 160, 0.10) 1px, transparent 1px);
  background-size: 26px 26px;
  border: 1px solid rgba(0, 245, 160, 0.16);
  opacity: 0.85;
}

.depth-halo {
  transform: translateZ(-90px) scale(1.16);
  background: radial-gradient(ellipse at 50% 50%, rgba(0, 210, 255, 0.16) 0%, transparent 70%);
  filter: blur(14px);
}

/* Specular glare that tracks the pointer across the glass. */
.frame-glare {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  pointer-events: none;
  z-index: 6;
  transform: translateZ(2px);
  background: radial-gradient(circle 220px at var(--glare-x) var(--glare-y),
    rgba(255, 255, 255, 0.14) 0%, rgba(0, 245, 160, 0.06) 35%, transparent 70%);
  opacity: 0;
  transition: opacity 0.4s var(--ease-out-expo);
  mix-blend-mode: screen;
}
.cyber-frame:hover .frame-glare { opacity: 1; }

/* Corners and telemetry tags pop forward in Z. */
.cyber-frame-corner { transform: translateZ(26px); }
.telemetry-tag {
  transform: translateZ(40px);
  transition: transform 0.5s var(--ease-out-expo);
}
.cyber-frame.tilting .telemetry-tag { transform: translateZ(58px); }

/* ==========================================================================
   FACE ID SCANNER
   ========================================================================== */
.face-mesh-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
  mix-blend-mode: screen;
}

/* Cool "under structured light" wash that pulses with the scan cycle. */
.face-scan-wash {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(180deg,
    rgba(0, 210, 255, 0.10) 0%,
    rgba(0, 245, 160, 0.06) 50%,
    rgba(0, 210, 255, 0.10) 100%);
  opacity: 0;
  animation: scan-wash 7.5s ease-in-out infinite;
}

@keyframes scan-wash {
  0%, 62%, 100% { opacity: 0; }
  12%, 46%      { opacity: 1; }
}

/* IR dot-projector speckle over the face during the sweep. */
.ir-speckle {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background-image: radial-gradient(rgba(0, 245, 160, 0.55) 0.7px, transparent 0.8px);
  background-size: 7px 7px;
  opacity: 0;
  animation: speckle-pulse 7.5s ease-in-out infinite;
  mix-blend-mode: screen;
}

@keyframes speckle-pulse {
  0%, 60%, 100% { opacity: 0; }
  10%, 42%      { opacity: 0.35; }
}

/* HUD readout under the portrait. */
.face-readout {
  position: absolute;
  left: 50%;
  bottom: -14px;
  transform: translate(-50%, 0) translateZ(60px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(7, 10, 15, 0.92);
  border: 1px solid var(--border-emerald);
  backdrop-filter: blur(12px);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  z-index: 8;
}

.face-readout .fr-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 10px var(--accent-emerald);
  animation: pulse-dot 1.6s infinite;
  flex-shrink: 0;
}

.face-readout .fr-status { color: var(--accent-emerald); font-weight: 600; }
.face-readout .fr-match {
  color: var(--accent-cyan);
  padding-left: 10px;
  border-left: 1px solid var(--border-subtle);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   SCROLL REVEAL SYSTEM
   ========================================================================== */
.reveal {
  opacity: 0;
  transform: translate3d(0, 26px, 0);
  transition:
    opacity 0.7s var(--ease-out-expo) var(--reveal-delay, 0ms),
    transform 0.7s var(--ease-out-expo) var(--reveal-delay, 0ms);
  will-change: opacity, transform;
}

.reveal.revealed {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  will-change: auto;
}

/* The portrait arrives from depth and off-angle. */
.hero-visual.reveal {
  opacity: 0;
  transform: perspective(1400px) translate3d(60px, 20px, -220px) rotateY(-26deg);
  transition: opacity 1.1s var(--ease-out-expo), transform 1.1s var(--ease-out-expo);
}
.hero-visual.reveal.revealed {
  opacity: 1;
  transform: perspective(1400px) translate3d(0, 0, 0) rotateY(0deg);
}

/* ==========================================================================
   HERO TITLE WORD ANIMATION
   ========================================================================== */
.hero-title.word-anim .word {
  display: inline-block;
  opacity: 0;
  transform: translate3d(0, 0.5em, -40px) rotateX(-40deg);
  animation: word-in 0.75s var(--ease-out-expo) forwards;
}

@keyframes word-in {
  to { opacity: 1; transform: translate3d(0, 0, 0) rotateX(0); }
}

/* The gradient phrase animates as one block and keeps its own text clip. */
.hero-title.word-anim .word-block {
  display: inline;
  animation: word-in-flat 0.8s var(--ease-out-expo) forwards;
  transform: none;
}

@keyframes word-in-flat {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Slow sheen across the gradient headline. */
.gradient-text {
  background-size: 220% auto;
  animation: gradient-sheen 7s linear infinite;
}

@keyframes gradient-sheen {
  0%   { background-position: 0% center; }
  100% { background-position: 200% center; }
}

/* ==========================================================================
   INTERACTIVE CARDS — spotlight + micro 3D tilt
   ========================================================================== */
.interactive-card {
  --mx: 50%;
  --my: 50%;
  --card-rx: 0deg;
  --card-ry: 0deg;
  transform: perspective(900px) rotateX(var(--card-rx)) rotateY(var(--card-ry));
  transition: transform 0.45s var(--ease-out-expo), border-color 0.3s ease, box-shadow 0.45s var(--ease-out-expo);
  transform-style: preserve-3d;
}

.interactive-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
  background: radial-gradient(circle 260px at var(--mx) var(--my),
    rgba(0, 245, 160, 0.13) 0%, transparent 65%);
}

.interactive-card:hover::after { opacity: 1; }

.interactive-card:hover {
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 245, 160, 0.22);
}

/* ==========================================================================
   SKILL BAR FILL
   ========================================================================== */
.skill-bar-fill {
  transition: width 1.2s var(--ease-out-expo);
  position: relative;
  overflow: hidden;
}

.skill-bar-fill.filled::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  animation: bar-sheen 2.4s ease-in-out 0.6s infinite;
}

@keyframes bar-sheen {
  0%   { transform: translateX(-100%); }
  60%, 100% { transform: translateX(200%); }
}

/* ==========================================================================
   BUTTON & CHIP MICRO-INTERACTIONS
   ========================================================================== */
.btn-primary, .btn-secondary, .btn-nav-gh {
  position: relative;
  overflow: hidden;
  transition: transform 0.28s var(--ease-spring), box-shadow 0.28s var(--ease-out-expo), background 0.28s ease;
}

.btn-primary::after, .btn-secondary::after {
  content: '';
  position: absolute;
  top: 0;
  left: -120%;
  width: 60%;
  height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.28), transparent);
  transform: skewX(-18deg);
  transition: left 0.6s var(--ease-out-expo);
}

.btn-primary:hover::after, .btn-secondary:hover::after { left: 140%; }

.btn-primary:hover, .btn-secondary:hover, .btn-nav-gh:hover { transform: translateY(-2px); }
.btn-primary:active, .btn-secondary:active, .btn-nav-gh:active { transform: translateY(0) scale(0.98); }

.term-chip, .filter-btn {
  transition: transform 0.22s var(--ease-spring), background 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}
.term-chip:hover, .filter-btn:hover { transform: translateY(-2px); }
.term-chip:active, .filter-btn:active { transform: scale(0.95); }

.role-tag {
  transition: transform 0.3s var(--ease-spring), border-color 0.3s ease, color 0.3s ease;
}
.role-tag:hover { transform: translateY(-3px) scale(1.04); }

/* Visible keyboard focus everywhere. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent-emerald);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ==========================================================================
   MOBILE NAV
   ========================================================================== */
body.nav-locked { overflow: hidden; }

/* Hamburger morphs into a close X. Line order in the markup is
   middle (y=12), top (y=6), bottom (y=18). */
.nav-toggle svg line {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.32s var(--ease-out-expo), opacity 0.2s ease;
}
.nav-toggle.active svg line:nth-child(1) { opacity: 0; }
.nav-toggle.active svg line:nth-child(2) { transform: translateY(6px) rotate(45deg); }
.nav-toggle.active svg line:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ==========================================================================
   RESPONSIVE / MOBILE REFINEMENTS
   ========================================================================== */
@media (max-width: 1024px) {
  .hero-visual { padding: 24px 0 40px; }

  /* Head-on at tablet width — an angled frame crops awkwardly in one column. */
  .cyber-frame {
    transform: rotateX(3deg) rotateY(-6deg);
    animation: frame-float-soft 10s ease-in-out infinite;
  }

  @keyframes frame-float-soft {
    0%, 100% { transform: rotateX(3deg) rotateY(-6deg) translate3d(0, 0, 0); }
    50%      { transform: rotateX(4deg) rotateY(-2deg) translate3d(0, -10px, 12px); }
  }

  .binary-rain-canvas { opacity: 0.55; }
}

@media (max-width: 768px) {
  /* --- Header: keep the brand on one line and give the toggle room --- */
  .nav-container { gap: 10px; }

  .brand-logo {
    gap: 8px;
    font-size: 0.92rem;
    white-space: nowrap;
    min-width: 0;
    overflow: hidden;
  }

  .brand-badge { padding: 3px 6px; font-size: 0.7rem; }
  .brand-sub { display: none; }
  .brand-text { text-overflow: ellipsis; overflow: hidden; }

  .nav-actions { gap: 6px; flex-shrink: 0; }

  /* GitHub shrinks to its glyph; the label lives in the drawer anyway. */
  .btn-nav-gh { padding: 8px 10px; }
  .btn-nav-gh span { display: none; }

  .nav-toggle { padding: 10px 6px; }

  .hero-section {
    min-height: auto;
    padding-top: calc(var(--header-height) + 24px);
    padding-bottom: 48px;
  }

  .hero-grid { gap: 32px; }

  /* Fluid frame so it never overflows a narrow viewport. */
  .cyber-frame {
    width: min(300px, 80vw);
    height: min(360px, 96vw);
  }

  .hero-title { font-size: clamp(1.9rem, 8vw, 2.5rem); line-height: 1.18; }
  .hero-bio { font-size: 0.96rem; }

  .hero-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .hero-actions .btn-primary,
  .hero-actions .btn-secondary {
    width: 100%;
    justify-content: center;
    min-height: 48px;          /* comfortable tap target */
  }

  .hero-roles { flex-wrap: wrap; justify-content: center; gap: 8px; }
  .role-tag { font-size: 0.78rem; padding: 5px 11px; }

  .telemetry-tag { font-size: 0.66rem; padding: 4px 9px; }
  .tag-top { top: 14px; left: 14px; }
  .tag-bottom { bottom: 14px; right: 14px; }

  .face-readout { font-size: 0.62rem; padding: 6px 11px; gap: 7px; bottom: -12px; }
  .face-readout .fr-match { padding-left: 7px; }

  .binary-rain-canvas { opacity: 0.45; }

  /* Mobile drawer: full-height sheet with its own scroll. */
  .nav-menu {
    height: calc(100vh - var(--header-height));
    height: calc(100dvh - var(--header-height));
    overflow-y: auto;
    justify-content: flex-start;
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
  }

  .nav-menu li { width: 100%; }
  .nav-menu .nav-link {
    display: block;
    width: 100%;
    padding: 12px 4px;
    font-size: 1.05rem;
    border-bottom: 1px solid var(--border-subtle);
  }

  .nav-menu.open li {
    animation: nav-item-in 0.4s var(--ease-out-expo) backwards;
  }
  .nav-menu.open li:nth-child(1) { animation-delay: 0.04s; }
  .nav-menu.open li:nth-child(2) { animation-delay: 0.08s; }
  .nav-menu.open li:nth-child(3) { animation-delay: 0.12s; }
  .nav-menu.open li:nth-child(4) { animation-delay: 0.16s; }
  .nav-menu.open li:nth-child(5) { animation-delay: 0.20s; }
  .nav-menu.open li:nth-child(6) { animation-delay: 0.24s; }

  @keyframes nav-item-in {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* Horizontal scroll rails instead of cramped wrapped rows. */
  .filter-group,
  .terminal-chips-bar {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    padding-bottom: 6px;
  }
  .filter-group::-webkit-scrollbar,
  .terminal-chips-bar::-webkit-scrollbar { display: none; }
  .filter-group .filter-btn,
  .terminal-chips-bar .term-chip {
    flex: 0 0 auto;
    scroll-snap-align: start;
    min-height: 40px;
  }

  /* Terminal readability on small screens. */
  .terminal-body { font-size: 0.78rem; }
  .terminal-title { display: none; }
  .terminal-input { font-size: 16px; }   /* prevents iOS zoom-on-focus */

  .copy-trigger { min-height: 34px; padding-inline: 12px; }

  .stats-grid { gap: 12px; }
  .section-title { font-size: clamp(1.5rem, 6vw, 2rem); }

  .footer-inner { flex-direction: column; gap: 14px; text-align: center; }
}

@media (max-width: 480px) {
  .brand-badge { display: none; }
  .brand-logo { font-size: 0.88rem; }

  .stats-grid { grid-template-columns: 1fr; }
  .cyber-frame { width: min(260px, 78vw); height: min(312px, 94vw); }
  .hero-roles { justify-content: center; gap: 8px; }
  .role-tag { font-size: 0.74rem; }
  .binary-rain-canvas { opacity: 0.38; }
}

/* Landscape phones: the 100vh hero is unusable, so let it collapse. */
@media (max-height: 520px) and (orientation: landscape) {
  .hero-section { min-height: auto; padding-bottom: 40px; }
  .cyber-frame { width: 220px; height: 264px; }
}

/* ==========================================================================
   REDUCED MOTION
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .reveal { opacity: 1 !important; transform: none !important; }
  .cyber-frame { transform: rotateY(-8deg) rotateX(2deg) !important; }
  .face-scan-wash, .ir-speckle, .scan-line { animation: none !important; }
  .binary-rain-canvas { opacity: 0.25; }
}
