/* ==========================================================================
   Swarm Rebuild — In-Situ Real Architecture Multiplayer Rebuild Simulation
   Inspired by Joel Califa's "Swarm Rebuild" Concept
   Assembles the REAL DOM elements of Aminul Haque Chowdhury's Portfolio live
   ========================================================================== */

/* Bound directly to Hero top in document flow (Never follows scroll down screen!) */
#swarm-canvas-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  max-height: 960px;
  z-index: 99990;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  overflow: hidden;
}

#swarm-canvas-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Background grid during active session */
.swarm-wipe-background {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: 
    linear-gradient(to right, rgba(2, 132, 199, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(2, 132, 199, 0.06) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 1;
}

[data-theme="dark"] .swarm-wipe-background {
  background-image: 
    linear-gradient(to right, rgba(56, 189, 248, 0.07) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(56, 189, 248, 0.07) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* Animated Stage Layer */
#swarm-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ==========================================================================
   In-Situ Real DOM Node Rebuilding States
   Hides real elements cleanly on start, then springs them into place live!
   ========================================================================== */
.swarm-rebuild-node {
  transition: opacity 0.45s cubic-bezier(0.16, 1, 0.3, 1), 
              transform 0.45s cubic-bezier(0.16, 1, 0.3, 1), 
              filter 0.4s ease;
}

body.swarm-active-session .swarm-rebuild-node {
  opacity: 0 !important;
  transform: translateY(14px) scale(0.98) !important;
  filter: blur(4px) !important;
  pointer-events: none !important;
}

body.swarm-active-session .swarm-rebuild-node.rebuilt {
  opacity: 1 !important;
  transform: translateY(0) scale(1) !important;
  filter: blur(0) !important;
  pointer-events: auto !important;
  animation: nodeSpringPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes nodeSpringPop {
  0% { transform: scale(0.96) translateY(12px); opacity: 0; }
  60% { transform: scale(1.02) translateY(-2px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* Highlight border flash when element lands */
.swarm-rebuild-node.swarm-just-landed {
  outline: 2px solid #0284c7;
  outline-offset: 4px;
  animation: outlineFade 0.8s ease-out forwards;
}

@keyframes outlineFade {
  0% { outline-color: rgba(2, 132, 199, 0.9); }
  100% { outline-color: rgba(2, 132, 199, 0); }
}

/* ==========================================================================
   Multiplayer Cursors
   ========================================================================== */
.swarm-cursor {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  z-index: 99995;
  transition: transform 0.24s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform;
}

.swarm-cursor-pointer {
  width: 20px;
  height: 20px;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.35));
}

.swarm-cursor-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2.5px 8px;
  border-radius: 5px;
  font-family: 'Fira Code', monospace;
  font-size: 10px;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
  margin-top: 2px;
  margin-left: 14px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
  transform-origin: top left;
  animation: cursorBadgePop 0.25s ease-out;
}

.swarm-cursor-chat {
  position: absolute;
  bottom: 26px;
  left: 18px;
  background: #0f172a;
  color: #f8fafc;
  padding: 5px 12px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.15);
  pointer-events: none;
  animation: chatBubbleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 99998;
}

[data-theme="dark"] .swarm-cursor-chat {
  background: #1e293b;
  color: #ffffff;
}

@keyframes cursorBadgePop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes chatBubbleIn {
  0% { transform: translateY(6px) scale(0.9); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* ==========================================================================
   Figma-Style Dragged Bounding Boxes
   ========================================================================== */
.swarm-box-ghost {
  position: absolute;
  border: 2px dashed var(--cursor-color, #0284c7);
  background: rgba(2, 132, 199, 0.08);
  border-radius: 12px;
  pointer-events: none;
  z-index: 99993;
  box-shadow: 0 0 20px rgba(2, 132, 199, 0.2);
  transition: all 0.15s ease-out;
}

.swarm-dimension-tag {
  position: absolute;
  top: -26px;
  right: 0;
  background: var(--cursor-color, #0284c7);
  color: #ffffff;
  font-family: 'Fira Code', monospace;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
}

/* Ruler Alignment Guides */
.swarm-ruler-guide-h {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: #06b6d4;
  box-shadow: 0 0 8px #06b6d4;
  pointer-events: none;
  z-index: 99992;
}

.swarm-ruler-guide-v {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: #06b6d4;
  box-shadow: 0 0 8px #06b6d4;
  pointer-events: none;
  z-index: 99992;
}

/* Spacing Measure Line */
.swarm-spacing-badge {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(225, 29, 72, 0.95);
  color: #ffffff;
  font-family: 'Fira Code', monospace;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  z-index: 99993;
  box-shadow: 0 2px 6px rgba(225, 29, 72, 0.4);
}

/* Laser Scanline Sweep on Portrait */
.swarm-laser-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #38bdf8, #818cf8, transparent);
  box-shadow: 0 0 12px #38bdf8, 0 0 24px #38bdf8;
  pointer-events: none;
  z-index: 99994;
}

/* ==========================================================================
   Swarm HUD Controls Panel (Permanently Hidden & Disabled)
   ========================================================================== */
#swarm-hud,
#swarm-floating-trigger,
#swarm-trigger-btn,
#hero-swarm-btn {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

#swarm-hud {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(140px);
  z-index: 99999;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 20px 45px -5px rgba(0, 0, 0, 0.5), 0 0 30px rgba(56, 189, 248, 0.3);
  color: #ffffff;
  font-family: 'Plus Jakarta Sans', sans-serif;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
  pointer-events: auto !important;
}

#swarm-hud.active {
  transform: translateX(-50%) translateY(0);
}

.swarm-hud-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 9px;
  font-family: 'Fira Code', monospace;
  font-size: 11px;
  font-weight: 700;
  color: #38bdf8;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.swarm-hud-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e2e8f0;
  padding: 6px 11px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swarm-hud-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.swarm-hud-btn.active {
  background: #0284c7;
  border-color: #38bdf8;
  color: #ffffff;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

.swarm-hud-progress {
  width: 90px;
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 9999px;
  overflow: hidden;
  position: relative;
}

.swarm-hud-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #818cf8, #34d399);
  transition: width 0.3s ease-out;
  border-radius: 9999px;
}
