:root {
  /* ─── Fluid Type Scale ─── */
  --type-scale-fluid: clamp(1.25rem, 0.85vw + 1rem, 2.5rem);

  /* ─── Fibonacci-based spacing ─── */
  --space-fibonacci-1: 1px;
  --space-fibonacci-2: 1px;
  --space-fibonacci-3: 2px;
  --space-fibonacci-5: 3px;
  --space-fibonacci-8: 5px;
  --space-fibonacci-13: 8px;
  --space-fibonacci-21: 13px;
  --space-fibonacci-34: 21px;
  --space-fibonacci-55: 34px;
  --space-fibonacci: var(--space-fibonacci-13);

  /* ─── Grid Fracture Scale ─── */
  --grid-fracture-scale: 1;
  --grid-fracture-max: 1.08;

  /* ─── Palette — "Cult Movie" dark aesthetic ─── */
  --bg: #0a0a0f;
  --fg: #e0dcd4;
  --accent: #ff2a5f;
  --accent-glow: rgba(255, 42, 95, 0.45);
  --grid-color: rgba(255, 255, 255, 0.06);
  --grid-locked: rgba(255, 42, 95, 0.18);
  --grid-fractured: rgba(255, 180, 40, 0.25);

  /* ─── Easing ─── */
  --ease-lock: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-fracture: cubic-bezier(0.77, 0, 0.175, 1);
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'Courier New', monospace;
  font-size: var(--type-scale-fluid);
  line-height: 1.4;
  overflow-x: hidden;
  min-height: 100vh;
  width: 100vw;
}

/* ───── Layout Shell ───── */
#drop-page {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-fibonacci-55);
  z-index: 1;
}

/* ───── Grid Canvas ───── */
#grid-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  transform-origin: center center;
  will-change: transform;
  transition: transform 0.15s var(--ease-lock);
}

/* ───── Helmet overlay ───── */
#helmet {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: transparent;
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity 0.2s var(--ease-lock);
}

#helmet.active {
  opacity: 1;
  background: radial-gradient(ellipse at center, var(--accent-glow) 0%, transparent 70%);
}

#helmet.pulse {
  animation: helmet-pulse 0.12s ease-out forwards;
}

@keyframes helmet-pulse {
  0% { opacity: 1; }
  50% { opacity: 0.6; }
  100% { opacity: 1; }
}

/* ───── Narrative text block ───── */
#narrative {
  position: relative;
  z-index: 10;
  text-align: center;
  max-width: 42rem;
  letter-spacing: 0.04em;
}

#narrative h1 {
   font-size: calc(var(--type-scale-fluid) * 1.6);
   text-transform: uppercase;
   color: var(--accent);
   text-shadow:
     calc(1px * var(--grid-fracture-scale, 1)) 0 0 rgba(255, 0, 80, 0.5),
     calc(-1px * var(--grid-fracture-scale, 1)) 0 0 rgba(0, 180, 255, 0.4),
     0 0 12px var(--accent-glow);
   margin-bottom: var(--space-fibonacci-21);
   line-height: 1.1;
   transition: text-shadow 0.15s var(--ease-fracture);
}

#narrative h1::selection {
   background: var(--accent);
   color: var(--bg);
}

#narrative .subtitle {
  font-size: var(--type-scale-fluid);
  opacity: 0.7;
  margin-bottom: var(--space-fibonacci-34);
}

#narrative .status {
  font-size: calc(var(--type-scale-fluid) * 0.65);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg);
  opacity: 0.5;
  margin-bottom: var(--space-fibonacci-13);
}

/* ───── Controls ───── */
#controls {
  position: relative;
  z-index: 10;
  display: flex;
  gap: var(--space-fibonacci-13);
  margin-top: var(--space-fibonacci-34);
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  background: transparent;
  border: 1px solid var(--fg);
  color: var(--fg);
  font-family: inherit;
  font-size: calc(var(--type-scale-fluid) * 0.6);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: var(--space-fibonacci-8) var(--space-fibonacci-21);
  cursor: pointer;
  transition: all 0.12s var(--ease-lock);
  outline: none;
}

.btn:hover {
  background: var(--fg);
  color: var(--bg);
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-accent {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-accent:hover {
  background: var(--accent);
  color: var(--bg);
}

  /* ───── Fracture overlay ───── */
  .fracture-slice {
    position: fixed;
    z-index: 3;
    background: var(--bg);
    pointer-events: none;
    will-change: transform, opacity;
    transform-origin: center center;
    animation:
      fracture-slide-in 0.18s var(--ease-fracture) both,
      fracture-dissolve 0.9s 0.3s ease-out both;
  }

  @keyframes fracture-slide-in {
    0% {
      transform: translate3d(0, 0, 0) scale(calc(1 / var(--grid-fracture-scale, 1)));
      opacity: 0;
    }
    40% {
      opacity: 1;
    }
    100% {
      transform: translate3d(
        calc((var(--rand-x, 0) - 50) * 0.6px),
        calc((var(--rand-y, 0) - 50) * 0.6px),
        0
        )
        scale(var(--grid-fracture-scale, 1));
      opacity: 0.95;
    }
  }

  @keyframes fracture-dissolve {
    0% {
      opacity: 0.95;
      transform: translate3d(
          calc((var(--rand-x, 0) - 50) * 0.6px),
          calc((var(--rand-y, 0) - 50) * 0.6px),
          0
          )
          scale(var(--grid-fracture-scale, 1));
      }
    100% {
      opacity: 0;
      transform: translate3d(
          calc((var(--rand-x, 0) - 50) * 1.4px),
          calc((var(--rand-y, 0) - 50) * 1.4px),
          0
          )
          scale(calc(var(--grid-fracture-scale, 1) + 0.04));
      }
  }

  /* Edge-glitch: scanline tear accent on fracture */
  .fracture-slice::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
      90deg,
      transparent 0%,
      var(--accent-glow) 20%,
      transparent 40%,
      rgba(255, 180, 40, 0.2) 60%,
      transparent 100%
      );
    mix-blend-mode: screen;
    animation: glitch-sweep 0.24s var(--ease-fracture) both;
  }

  @keyframes glitch-sweep {
    0% { transform: translateX(-100%); opacity: 0; }
    30% { opacity: 1; }
    100% { transform: translateX(100%); opacity: 0; }
  }

/* ─── Scanline grain ─── */
#grain {
   position: fixed;
   inset: 0;
   z-index: 100;
   pointer-events: none;
   opacity: 0.035;
   background-image: repeating-linear-gradient(
      0deg,
    transparent,
    transparent 2px,
    rgba(255, 255, 255, 0.03) 2px,
    rgba(255, 255, 255, 0.03) 4px
   );
   animation: grain-shift 0.8s steps(3) infinite;
}

@keyframes grain-shift {
   0% { transform: translate3d(0, 0, 0); }
   33% { transform: translate3d(-1px, 1px, 0); }
   66% { transform: translate3d(1px, -1px, 0); }
   100% { transform: translate3d(0, 0, 0); }
}

/* ─── CRT screen flicker ─── */
body::before {
   content: "";
   position: fixed;
   inset: 0;
   z-index: 101;
   pointer-events: none;
   background: radial-gradient(
      ellipse at 50% 50%,
      transparent 60%,
      rgba(0, 0, 0, 0.25) 100%
   );
   animation: crt-flicker 8s ease-in-out infinite;
}

@keyframes crt-flicker {
   0%, 100% { opacity: 1; }
   4% { opacity: 0.97; }
   6%, 7% { opacity: 1; }
   42% { opacity: 0.98; }
   44% { opacity: 1; }
   89% { opacity: 0.96; }
   91% { opacity: 1; }
}

    /* ─── CRT vignette ring ─── */
    body::after {
        content: "";
        position: fixed;
        inset: 0;
        z-index: 102;
        pointer-events: none;
        background: radial-gradient(
           ellipse at center,
           transparent 55%,
           rgba(0, 0, 0, 0.5) 80%,
           rgba(0, 0, 0, 0.8) 100%
         );
     }

    /* ─── Locked state: visual anchoring ─── */
    body.locked #grid-canvas {
        filter: drop-shadow(0 0 2px var(--accent-glow));
    }

    /* ─── Stressing state: micro-vibration ─── */
    body.stressing #narrative {
        animation: stress-vibrate 0.08s steps(2) infinite;
    }

    @keyframes stress-vibrate {
        0%  { transform: translate3d(0, 0, 0); }
        25% { transform: translate3d(var(--stress-level, 0.5), 0, 0); }
        50% { transform: translate3d(0, calc(var(--stress-level, 0.5) * -1px), 0); }
        75% { transform: translate3d(calc(var(--stress-level, 0.5) * -1px), 0, 0); }
        100% { transform: translate3d(0, 0, 0); }
    }

    /* ─── Fracturing: dramatic shift ─── */
    body.fracturing #drop-page {
        transform: scale(var(--grid-fracture-scale, 1));
        transition: transform 0.12s var(--ease-fracture);
    }

    /* ─── Helmet breathing ring ─── */
    #helmet.locked-ring {
        background:
          radial-gradient(ellipse at center, var(--accent-glow) 0%, transparent 50%),
          conic-gradient(
            from 0deg,
            transparent 0%,
            var(--accent-glow) 10%,
            transparent 20%,
            transparent 80%,
            var(--accent-glow) 90%,
            transparent 100%
          );
    }

    /* ─── Active state: subtle grid pulse on canvas border ─── */
    body.active #grid-canvas {
        box-shadow: inset 0 0 80px rgba(255, 42, 95, calc(var(--breath-pulse, 0) * 0.15));
        transition: box-shadow 0.1s ease-out;
    }

   /* ─── Fracture state on body ─── */
   body.fracturing #narrative h1 {
    text-shadow:
      calc(3px * var(--grid-fracture-scale, 1)) 0 0 rgba(255, 0, 80, 0.8),
      calc(-3px * var(--grid-fracture-scale, 1)) 2px 0 rgba(0, 180, 255, 0.7),
      0 0 24px var(--accent-glow),
      0 0 48px rgba(255, 42, 95, 0.2);
    animation: title-glitch 0.15s steps(2) both;
   }

   @keyframes title-glitch {
      0% { transform: translate3d(0, 0, 0) skewX(0); }
      25% { transform: translate3d(-2px, 1px, 0) skewX(-0.5deg); }
      50% { transform: translate3d(2px, -1px, 0) skewX(0.5deg); }
      75% { transform: translate3d(-1px, -1px, 0) skewX(-0.25deg); }
      100% { transform: translate3d(0, 0, 0) skewX(0); }
   }

   body.fracturing .status {
    color: var(--accent);
    opacity: 1;
    text-shadow: 0 0 8px var(--accent-glow);
    animation: status-flash 0.5s steps(1) 3 both;
   }

   @keyframes status-flash {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.3; }
   }

    /* ─── Stress Meter ─── */
   #meter-row {
     display: flex;
     align-items: center;
     justify-content: center;
     gap: var(--space-fibonacci-34);
     margin-bottom: var(--space-fibonacci-13);
     opacity: 0;
     transition: opacity 0.3s ease;
    }
   body:not(.standby) #meter-row {
     opacity: 1;
    }

   #stress-meter {
     display: flex;
     flex-direction: column;
     align-items: flex-start;
     min-width: 120px;
    }

   .meter-label {
     font-size: calc(var(--type-scale-fluid) * 0.45);
     text-transform: uppercase;
     letter-spacing: 0.15em;
     color: var(--fg);
     opacity: 0.5;
     margin-bottom: var(--space-fibonacci-5);
    }

   .meter-track {
     width: 120px;
     height: 3px;
     background: rgba(255, 255, 255, 0.08);
     border-radius: 1px;
     overflow: hidden;
    }

   .meter-fill {
     height: 100%;
     width: 0%;
     background: var(--accent);
     box-shadow: 0 0 6px var(--accent-glow);
     transition: width 0.25s var(--ease-lock);
    }

    /* ─── Beat Indicator ─── */
   #beat-indicator {
     display: flex;
     gap: var(--space-fibonacci-5);
     align-items: center;
    }

   .beat-dot {
     display: block;
     width: 6px;
     height: 6px;
     border-radius: 50%;
     background: rgba(255, 255, 255, 0.1);
     transition: background 0.08s ease, box-shadow 0.08s ease;
    }

   .beat-dot.active {
     background: var(--accent);
     box-shadow: 0 0 8px var(--accent-glow);
    }

   .beat-dot.downbeat {
     width: 8px;
     height: 8px;
    }

   .beat-dot.downbeat.active {
     box-shadow: 0 0 14px var(--accent-glow), 0 0 24px rgba(255, 42, 95, 0.2);
    }

    /* ─── Responsive ─── */
    @media (max-width: 480px) {
     #drop-page {
     padding: var(--space-fibonacci-21);
     }

     #narrative h1 {
     font-size: calc(var(--type-scale-fluid) * 1.2);
     }

     .meter-track {
     width: 80px;
     }

     #stress-meter {
     min-width: 80px;
     }
    }
