/* ═══════════════════════════════════════════════════════════
   TECHLAB HUD — Military Heads-Up Display Overlay
   Sprint 1: HUD corners · HexGrid · Glitch · Sonar · Typing
   ═══════════════════════════════════════════════════════════ */

/* ═══ 1.1 — HUD CORNER OVERLAY ═══ */

.tl-hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9990;
  font-family: var(--tl-font-mono, 'JetBrains Mono', monospace);
  color: rgba(0, 229, 255, 0.35);
  font-size: 0.5rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Corner brackets */
.tl-hud-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tl-hud-tl { top: 12px; left: 12px; }
.tl-hud-tr { top: 12px; right: 12px; text-align: right; }
.tl-hud-bl { bottom: 12px; left: 12px; }
.tl-hud-br { bottom: 12px; right: 12px; text-align: right; }

/* Corner bracket decorations */
.tl-hud-corner::before {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
}
.tl-hud-tl::before { top: -4px; left: -4px; border-left: 1px solid rgba(0,229,255,0.2); border-top: 1px solid rgba(0,229,255,0.2); }
.tl-hud-tr::before { top: -4px; right: -4px; border-right: 1px solid rgba(0,229,255,0.2); border-top: 1px solid rgba(0,229,255,0.2); }
.tl-hud-bl::before { bottom: -4px; left: -4px; border-left: 1px solid rgba(0,229,255,0.2); border-bottom: 1px solid rgba(0,229,255,0.2); }
.tl-hud-br::before { bottom: -4px; right: -4px; border-right: 1px solid rgba(0,229,255,0.2); border-bottom: 1px solid rgba(0,229,255,0.2); }

.tl-hud-label {
  line-height: 1.4;
  white-space: nowrap;
}

.tl-hud-val { color: rgba(0, 229, 255, 0.55); }
.tl-hud-warn { color: rgba(255, 61, 87, 0.6); }
.tl-hud-ok { color: rgba(0, 255, 136, 0.5); }

/* HUD horizontal scanline */
.tl-hud-scanline {
  position: fixed;
  left: 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0,229,255,0.08), transparent);
  z-index: 9989;
  pointer-events: none;
  animation: hudScanline 8s linear infinite;
}

@keyframes hudScanline {
  0%   { top: -2px; opacity: 0; }
  5%   { opacity: 1; }
  95%  { opacity: 1; }
  100% { top: 100vh; opacity: 0; }
}

/* Top HUD bar */
.tl-hud-topbar {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2rem;
  padding: 6px 24px;
  font-size: 0.5rem;
  color: rgba(0,229,255,0.3);
  z-index: 9991;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(3,6,13,0.6), transparent);
}

.tl-hud-topbar span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tl-hud-topbar .blink {
  animation: hudBlink 2s step-end infinite;
}

@keyframes hudBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* ═══ 1.2 — HEXAGONAL GRID ═══ */

.tl-hexgrid {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.tl-hexgrid-canvas {
  width: 100%;
  height: 100%;
  opacity: 0.4;
}

/* CSS fallback if canvas not supported */
.tl-hexgrid-css {
  position: absolute;
  inset: 0;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='100'%3E%3Cpath d='M28 66L0 50L0 16L28 0L56 16L56 50L28 66L28 100' fill='none' stroke='rgba(0,229,255,0.04)' stroke-width='0.5'/%3E%3Cpath d='M28 0L28 34L0 50L0 84L28 100L56 84L56 50L28 34' fill='none' stroke='rgba(0,229,255,0.04)' stroke-width='0.5'/%3E%3C/svg%3E");
  background-size: 56px 100px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, black 20%, transparent 65%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, black 20%, transparent 65%);
  animation: hexShift 20s linear infinite;
}

@keyframes hexShift {
  0%   { background-position: 0 0; }
  100% { background-position: 56px 100px; }
}

/* ═══ 1.3 — GLITCH EFFECT ═══ */

.tl-glitch {
  position: relative;
  display: inline-block;
}

.tl-glitch::before,
.tl-glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  opacity: 0;
}

.tl-glitch::before {
  color: var(--tl-cyan, #00e5ff);
  animation: glitchTop 3s infinite linear alternate-reverse;
  clip-path: polygon(0 0, 100% 0, 100% 33%, 0 33%);
}

.tl-glitch::after {
  color: var(--tl-red, #ff3d57);
  animation: glitchBottom 2.5s infinite linear alternate-reverse;
  clip-path: polygon(0 67%, 100% 67%, 100% 100%, 0 100%);
}

.tl-glitch:hover::before,
.tl-glitch:hover::after {
  opacity: 0.8;
}

@keyframes glitchTop {
  0%, 90%, 100% { transform: translate(0); opacity: 0; }
  91% { transform: translate(-2px, -1px); opacity: 0.7; }
  92% { transform: translate(2px, 1px); opacity: 0.7; }
  93% { transform: translate(-1px, 2px); opacity: 0; }
}

@keyframes glitchBottom {
  0%, 88%, 100% { transform: translate(0); opacity: 0; }
  89% { transform: translate(2px, 1px); opacity: 0.6; }
  90% { transform: translate(-2px, -2px); opacity: 0.6; }
  91% { transform: translate(1px, -1px); opacity: 0; }
}

/* Full-screen glitch flash (triggered by JS) */
.tl-glitch-flash {
  position: fixed;
  inset: 0;
  z-index: 9995;
  pointer-events: none;
  opacity: 0;
}

.tl-glitch-flash.active {
  animation: glitchFlash 0.3s ease;
}

@keyframes glitchFlash {
  0%   { opacity: 0; }
  10%  { opacity: 1; background: rgba(0,229,255,0.03); }
  20%  { opacity: 0; transform: translateX(3px); }
  30%  { opacity: 1; background: rgba(255,61,87,0.02); transform: translateX(-2px); }
  40%  { opacity: 0; transform: translateX(0); }
  50%  { opacity: 1; background: rgba(0,229,255,0.02); }
  60%  { opacity: 0; }
  100% { opacity: 0; }
}

/* ═══ 1.7 — SONAR PULSE ═══ */

.tl-sonar {
  position: relative;
  display: inline-flex;
}

.tl-sonar::before,
.tl-sonar::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: inherit;
  border: 1px solid var(--cat-color, var(--tl-cyan));
  opacity: 0;
  pointer-events: none;
}

.tl-sonar::before {
  animation: sonarPing 3s ease-out infinite;
}

.tl-sonar::after {
  animation: sonarPing 3s ease-out infinite 1.5s;
}

@keyframes sonarPing {
  0%   { transform: scale(0.85); opacity: 0.5; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* Sonar applied to category icons */
.tl-cat-icon.tl-sonar::before,
.tl-cat-icon.tl-sonar::after {
  border-radius: 10px;
}

/* ═══ 1.9 — MILITARY TYPING ═══ */

.tl-typewriter {
  overflow: hidden;
  white-space: nowrap;
  border-right: 2px solid var(--tl-cyan, #00e5ff);
  animation: typewriterCursor 0.8s step-end infinite;
  width: 0;
}

.tl-typewriter.typing {
  animation:
    typewriterExpand var(--tw-duration, 2s) steps(var(--tw-steps, 30), end) forwards,
    typewriterCursor 0.8s step-end infinite;
}

.tl-typewriter.done {
  width: auto;
  border-right-color: transparent;
  animation: none;
}

@keyframes typewriterExpand {
  from { width: 0; }
  to   { width: 100%; }
}

@keyframes typewriterCursor {
  0%, 100% { border-right-color: var(--tl-cyan); }
  50%      { border-right-color: transparent; }
}

/* Military classified stamp */
.tl-stamp {
  display: inline-block;
  font-family: var(--tl-font-mono);
  font-size: 0.5rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 3px 12px;
  border: 1px solid currentColor;
  border-radius: 2px;
  opacity: 0;
  transform: scale(1.5) rotate(-3deg);
  transition: none;
}

.tl-stamp.stamped {
  animation: stampSlam 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes stampSlam {
  0%   { opacity: 0; transform: scale(2) rotate(-5deg); }
  60%  { opacity: 1; transform: scale(0.95) rotate(-2deg); }
  100% { opacity: 0.7; transform: scale(1) rotate(-2deg); }
}

.tl-stamp.authorized { color: var(--tl-green, #00ff88); }
.tl-stamp.classified { color: var(--tl-red, #ff3d57); }
.tl-stamp.restricted { color: var(--tl-accent, #f59e0b); }

/* ═══ 1.5 — DATA STREAM ═══ */

#dataStreamCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
}

/* ═══ 4.1/4.2 — AUDIO TOGGLE ═══ */

.tl-audio-toggle {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 9992;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0, 229, 255, 0.04);
  border: 1px solid rgba(0, 229, 255, 0.1);
  color: rgba(0, 229, 255, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  transition: all 0.3s ease;
}

.tl-audio-toggle:hover {
  background: rgba(0, 229, 255, 0.08);
  color: rgba(0, 229, 255, 0.6);
}

.tl-audio-toggle.active {
  background: rgba(0, 229, 255, 0.1);
  border-color: rgba(0, 229, 255, 0.3);
  color: var(--tl-cyan, #00e5ff);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.15);
}

/* Active icon swap */
.tl-audio-toggle .fa-volume-mute { display: inline; }
.tl-audio-toggle .fa-volume-up { display: none; }
.tl-audio-toggle.active .fa-volume-mute { display: none; }
.tl-audio-toggle.active .fa-volume-up { display: inline; }

/* ═══ 4.3 — VIDEO BACKGROUND ═══ */

.tl-hero-video {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}

.tl-hero-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.45;
  filter: saturate(0.6) brightness(0.8);
  pointer-events: none;
}

/* Gradient overlay on top of video */
.tl-hero-video::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, rgba(20,28,46,0.3) 0%, rgba(20,28,46,0.85) 100%),
    radial-gradient(ellipse at center, transparent 40%, rgba(20,28,46,0.6) 70%);
  pointer-events: none;
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  .tl-hud { display: none; }
  .tl-hud-topbar { display: none; }
  .tl-hud-scanline { display: none; }
  #dataStreamCanvas { display: none; }
  .tl-hero-video { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tl-hud-scanline,
  .tl-glitch::before, .tl-glitch::after,
  .tl-sonar::before, .tl-sonar::after,
  .tl-hexgrid-css,
  .tl-typewriter,
  .tl-stamp,
  .tl-glitch-flash,
  #dataStreamCanvas { animation: none !important; display: none; }
}
