/* Electron Orbital Animation System for Atomic Lab Periodic Table */

/* Shell color mapping by energy level - Consistent cyan/blue theme */
:root {
  --shell-k-color: #00D4FF; /* Bright Cyan - 1st shell */
  --shell-l-color: #00B8E6; /* Light Blue - 2nd shell */
  --shell-m-color: #0099FF; /* Sky Blue - 3rd shell */
  --shell-n-color: #0080FF; /* Medium Blue - 4th shell */
  --shell-o-color: #0066FF; /* Electric Blue - 5th shell */
  --shell-p-color: #004DCC; /* Deep Blue - 6th shell */
  --shell-q-color: #0033AA; /* Dark Blue - 7th shell */
  
  --nucleus-color: #FFFFFF;
  --electron-color: #00E5FF;
  --electron-glow: 0 0 10px currentColor, 0 0 20px currentColor;
}

/* Orbital system container */
.electron-orbital-system {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120px;
  height: 120px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 10; /* Above background, below text */
}

/* Prevent orbital system from affecting element size perception */
.table-grid .element-hex .electron-orbital-system {
  width: 80px; /* Match cell size */
  height: 80px;
  overflow: hidden; /* Clip anything that exceeds the boundary */
  transition: width 0.4s ease, height 0.4s ease, overflow 0.4s ease 0.2s;
}

/* On click expand, expand the orbital system container */
.table-grid .element-hex.expanded .electron-orbital-system {
  width: 120px !important; /* Larger container for full animation */
  height: 120px !important;
  overflow: visible !important; /* Show full animation */
}

/* Ensure f-block elements use same orbital size */
.table-grid .element-hex[style*="grid-row: 9"] .electron-orbital-system,
.table-grid .element-hex[style*="grid-row: 10"] .electron-orbital-system {
  width: 70px !important;
  height: 70px !important;
}

/* Show on hover */
.element-hex:hover .electron-orbital-system {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Play animations on hover */
.element-hex:hover .electron-shell {
  animation-play-state: running;
}

.element-hex:hover .nucleus {
  animation-play-state: running;
}

/* Nucleus - Default size for table hover */
.nucleus {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: radial-gradient(circle, 
    var(--nucleus-color) 0%, 
    var(--nucleus-color) 40%, 
    rgba(0, 229, 255, 0.8) 60%, 
    rgba(189, 0, 255, 0.4) 100%);
  border-radius: 50%;
  box-shadow: 
    0 0 20px rgba(255, 255, 255, 0.9),
    0 0 40px rgba(0, 229, 255, 0.6),
    0 0 60px rgba(189, 0, 255, 0.3);
  animation: nucleus-pulse 2s ease-in-out infinite paused;
  z-index: 15; /* Above background and shells, below text */
}

@keyframes nucleus-pulse {
  0%, 100% { 
    transform: translate(-50%, -50%) scale(1);
    box-shadow: 
      0 0 20px rgba(255, 255, 255, 0.9),
      0 0 40px rgba(0, 229, 255, 0.6),
      0 0 60px rgba(189, 0, 255, 0.3);
  }
  50% { 
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 
      0 0 30px rgba(255, 255, 255, 1),
      0 0 50px rgba(0, 229, 255, 0.8),
      0 0 70px rgba(189, 0, 255, 0.5);
  }
}

/* Electron shells */
.electron-shell {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid;
  opacity: 0.5; /* Increased visibility */
  transform-style: preserve-3d;
}

/* Shell sizes and colors - Default for table hover (smaller) */
.electron-shell[data-shell="1"] {
  width: 25px;
  height: 25px;
  border-color: var(--shell-k-color);
  animation: rotate-shell-1 3s linear infinite paused;
}

.electron-shell[data-shell="2"] {
  width: 35px;
  height: 35px;
  border-color: var(--shell-l-color);
  animation: rotate-shell-2 3.5s linear infinite paused;
  transform: translate(-50%, -50%) rotateX(20deg);
}

.electron-shell[data-shell="3"] {
  width: 45px;
  height: 45px;
  border-color: var(--shell-m-color);
  animation: rotate-shell-3 4s linear infinite paused;
  transform: translate(-50%, -50%) rotateY(25deg);
}

.electron-shell[data-shell="4"] {
  width: 55px;
  height: 55px;
  border-color: var(--shell-n-color);
  animation: rotate-shell-4 4.5s linear infinite paused;
  transform: translate(-50%, -50%) rotateX(15deg) rotateY(15deg);
}

.electron-shell[data-shell="5"] {
  width: 65px;
  height: 65px;
  border-color: var(--shell-o-color);
  animation: rotate-shell-5 5s linear infinite paused;
  transform: translate(-50%, -50%) rotateX(30deg);
}

.electron-shell[data-shell="6"] {
  width: 75px;
  height: 75px;
  border-color: var(--shell-p-color);
  animation: rotate-shell-6 5.5s linear infinite paused;
  transform: translate(-50%, -50%) rotateY(35deg);
}

.electron-shell[data-shell="7"] {
  width: 85px;
  height: 85px;
  border-color: var(--shell-q-color);
  animation: rotate-shell-7 6s linear infinite paused;
  transform: translate(-50%, -50%) rotateX(10deg) rotateY(10deg);
}

/* Rotation animations for each shell */
@keyframes rotate-shell-1 {
  from { transform: translate(-50%, -50%) rotateZ(0deg); }
  to { transform: translate(-50%, -50%) rotateZ(360deg); }
}

@keyframes rotate-shell-2 {
  from { transform: translate(-50%, -50%) rotateX(20deg) rotateZ(0deg); }
  to { transform: translate(-50%, -50%) rotateX(20deg) rotateZ(360deg); }
}

@keyframes rotate-shell-3 {
  from { transform: translate(-50%, -50%) rotateY(25deg) rotateZ(0deg); }
  to { transform: translate(-50%, -50%) rotateY(25deg) rotateZ(360deg); }
}

@keyframes rotate-shell-4 {
  from { transform: translate(-50%, -50%) rotateX(15deg) rotateY(15deg) rotateZ(0deg); }
  to { transform: translate(-50%, -50%) rotateX(15deg) rotateY(15deg) rotateZ(360deg); }
}

@keyframes rotate-shell-5 {
  from { transform: translate(-50%, -50%) rotateX(30deg) rotateZ(0deg); }
  to { transform: translate(-50%, -50%) rotateX(30deg) rotateZ(360deg); }
}

@keyframes rotate-shell-6 {
  from { transform: translate(-50%, -50%) rotateY(35deg) rotateZ(0deg); }
  to { transform: translate(-50%, -50%) rotateY(35deg) rotateZ(360deg); }
}

@keyframes rotate-shell-7 {
  from { transform: translate(-50%, -50%) rotateX(10deg) rotateY(10deg) rotateZ(0deg); }
  to { transform: translate(-50%, -50%) rotateX(10deg) rotateY(10deg) rotateZ(360deg); }
}

/* Electrons - Default size for table hover */
.electron {
  position: absolute;
  width: 3px;
  height: 3px;
  background: radial-gradient(circle, 
    var(--electron-color) 0%, 
    var(--electron-color) 50%, 
    transparent 100%);
  border-radius: 50%;
  box-shadow: var(--electron-glow);
  pointer-events: none;
  /* Positioning is now handled by JavaScript */
}

/* Electron wrapper for rotation positioning */
.electron-wrapper {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  transform-origin: center center;
}

/* Individual electron orbital animations - CONTINUOUS MOVEMENT */
@keyframes electronOrbit {
  from { 
    transform: rotate(0deg);
  }
  to { 
    transform: rotate(360deg);
  }
}

/* Apply continuous orbital animation to all electron wrappers */
.electron-wrapper {
  animation: electronOrbit 3s linear infinite;
}

/* Different speeds for each shell to create realistic orbital motion */
.electron-shell[data-shell="1"] .electron-wrapper { 
  animation-duration: 2s; /* Fastest - innermost shell */
}

.electron-shell[data-shell="2"] .electron-wrapper { 
  animation-duration: 2.5s; 
}

.electron-shell[data-shell="3"] .electron-wrapper { 
  animation-duration: 3s; 
}

.electron-shell[data-shell="4"] .electron-wrapper { 
  animation-duration: 3.5s; 
}

.electron-shell[data-shell="5"] .electron-wrapper { 
  animation-duration: 4s; 
}

.electron-shell[data-shell="6"] .electron-wrapper { 
  animation-duration: 4.5s; 
}

.electron-shell[data-shell="7"] .electron-wrapper { 
  animation-duration: 5s; /* Slowest - outermost shell */
}

/* Pause animations by default, play on hover */
.electron-wrapper {
  animation-play-state: paused;
}

.element-hex:hover .electron-wrapper {
  animation-play-state: running;
}

/* On detail pages, always run the animation */
.element-detail-hero .electron-wrapper {
  animation-play-state: running;
}

/* Stagger electron starting positions within same shell */
.electron-wrapper:nth-child(2) { animation-delay: -0.5s; }
.electron-wrapper:nth-child(3) { animation-delay: -1s; }
.electron-wrapper:nth-child(4) { animation-delay: -1.5s; }
.electron-wrapper:nth-child(5) { animation-delay: -2s; }
.electron-wrapper:nth-child(6) { animation-delay: -2.5s; }
.electron-wrapper:nth-child(7) { animation-delay: -3s; }
.electron-wrapper:nth-child(8) { animation-delay: -3.5s; }
.electron-wrapper:nth-child(9) { animation-delay: -4s; }
.electron-wrapper:nth-child(10) { animation-delay: -4.5s; }
.electron-wrapper:nth-child(11) { animation-delay: -5s; }
.electron-wrapper:nth-child(12) { animation-delay: -5.5s; }

/* Electrons are positioned at the edge of their wrapper */
/* The wrapper rotation determines their position on the orbit */

/* Electron trails */
.electron::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 2px;
  background: linear-gradient(90deg, 
    transparent 0%, 
    var(--electron-color) 50%, 
    transparent 100%);
  opacity: 0.5;
  top: 1px;
  left: -8px;
  pointer-events: none;
}

/* Detail page larger visualization */
.element-detail-hero .electron-orbital-system {
  width: 400px;
  height: 400px;
  opacity: 1;
  position: relative;
  transform: none;
  top: auto;
  left: auto;
  margin: 0 auto;
}

.element-detail-hero .nucleus {
  width: 30px;
  height: 30px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0, 0, 0, 0.8);
  font-weight: bold;
}

.element-detail-hero .electron {
  width: 6px;
  height: 6px;
}

/* Larger shells for detail page */
.element-detail-hero .electron-shell[data-shell="1"] { width: 100px; height: 100px; }
.element-detail-hero .electron-shell[data-shell="2"] { width: 150px; height: 150px; }
.element-detail-hero .electron-shell[data-shell="3"] { width: 200px; height: 200px; }
.element-detail-hero .electron-shell[data-shell="4"] { width: 250px; height: 250px; }
.element-detail-hero .electron-shell[data-shell="5"] { width: 300px; height: 300px; }
.element-detail-hero .electron-shell[data-shell="6"] { width: 350px; height: 350px; }
.element-detail-hero .electron-shell[data-shell="7"] { width: 380px; height: 380px; }

/* Special effects for radioactive elements */
.radioactive .electron-orbital-system {
  filter: hue-rotate(120deg);
}

.radioactive .nucleus {
  animation: nucleus-pulse 0.5s ease-in-out infinite;
  background: radial-gradient(circle, 
    #00FF00 0%, 
    #00FF00 40%, 
    rgba(0, 255, 0, 0.8) 60%, 
    rgba(255, 255, 0, 0.4) 100%);
}

/* Noble gas special effect */
.noble-gas .electron-shell {
  border-color: var(--color-noble);
  opacity: 0.6;
  box-shadow: 0 0 10px var(--color-noble);
}

/* Alkali metals special effect */
.alkali-metal .electron-shell[data-shell="1"] {
  border-color: #FF4444;
  box-shadow: 0 0 15px #FF4444;
}

/* Transition metals special effect */
.transition-metal .electron {
  background: radial-gradient(circle, 
    #FFA500 0%, 
    #FF6B00 50%, 
    transparent 100%);
}

/* Performance optimizations */
@media (prefers-reduced-motion: reduce) {
  .electron-shell,
  .nucleus,
  .electron-wrapper {
    animation: none;
  }
}

/* Enable orbitals for f-block elements - same as main table */
.table-grid .element-hex[style*="grid-row: 9"] .electron-orbital-system,
.table-grid .element-hex[style*="grid-row: 10"] .electron-orbital-system {
  /* Use same sizing as main table elements */
  width: 80px !important;
  height: 80px !important;
  overflow: hidden !important; /* Clip anything that exceeds the boundary */
}

/* On click expand, f-block elements also expand */
.table-grid .element-hex[style*="grid-row: 9"].expanded .electron-orbital-system,
.table-grid .element-hex[style*="grid-row: 10"].expanded .electron-orbital-system {
  width: 120px !important;
  height: 120px !important;
  overflow: visible !important;
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .electron-orbital-system {
    display: none; /* Hide on mobile table view for performance */
  }
  
  .element-detail-hero .electron-orbital-system {
    display: block; /* Show on detail pages */
    width: 300px;
    height: 300px;
  }
  
  .element-detail-hero .electron-shell[data-shell="1"] { width: 80px; height: 80px; }
  .element-detail-hero .electron-shell[data-shell="2"] { width: 120px; height: 120px; }
  .element-detail-hero .electron-shell[data-shell="3"] { width: 160px; height: 160px; }
  .element-detail-hero .electron-shell[data-shell="4"] { width: 200px; height: 200px; }
  .element-detail-hero .electron-shell[data-shell="5"] { width: 240px; height: 240px; }
  .element-detail-hero .electron-shell[data-shell="6"] { width: 270px; height: 270px; }
  .element-detail-hero .electron-shell[data-shell="7"] { width: 290px; height: 290px; }
}

/* GPU acceleration */
.electron-shell,
.electron,
.nucleus,
.electron-wrapper {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}