/*
 * Chemistry Visual Effects Library
 * Scientific animations for molecular structures, chemical reactions,
 * periodic table elements, and laboratory equipment
 * Created for educational and scientific visualization purposes
 */

/* ===== MOLECULAR STRUCTURE ANIMATIONS ===== */

/* DNA Double Helix */
.dna-helix {
  position: relative;
  width: 200px;
  height: 400px;
  margin: 2rem auto;
  perspective: 1000px;
}

.dna-strand {
  position: absolute;
  width: 100%;
  height: 100%;
  animation: dnaRotate 4s linear infinite;
  transform-style: preserve-3d;
}

.dna-strand:nth-child(2) {
  animation-delay: -2s;
}

.dna-base {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #ff6b35;
  border-radius: 50%;
  left: 50%;
  transform-origin: 0 0;
}

.dna-base:nth-child(odd) {
  background: #4ecdc4;
}

.dna-base:nth-child(1) { top: 0%; transform: translateX(-50%) rotateY(0deg) translateZ(50px); }
.dna-base:nth-child(2) { top: 10%; transform: translateX(-50%) rotateY(36deg) translateZ(50px); }
.dna-base:nth-child(3) { top: 20%; transform: translateX(-50%) rotateY(72deg) translateZ(50px); }
.dna-base:nth-child(4) { top: 30%; transform: translateX(-50%) rotateY(108deg) translateZ(50px); }
.dna-base:nth-child(5) { top: 40%; transform: translateX(-50%) rotateY(144deg) translateZ(50px); }
.dna-base:nth-child(6) { top: 50%; transform: translateX(-50%) rotateY(180deg) translateZ(50px); }
.dna-base:nth-child(7) { top: 60%; transform: translateX(-50%) rotateY(216deg) translateZ(50px); }
.dna-base:nth-child(8) { top: 70%; transform: translateX(-50%) rotateY(252deg) translateZ(50px); }
.dna-base:nth-child(9) { top: 80%; transform: translateX(-50%) rotateY(288deg) translateZ(50px); }
.dna-base:nth-child(10) { top: 90%; transform: translateX(-50%) rotateY(324deg) translateZ(50px); }

@keyframes dnaRotate {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(360deg); }
}

/* Molecular Orbital Animation */
.molecular-orbital {
  position: relative;
  width: 300px;
  height: 300px;
  margin: 2rem auto;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(76, 175, 80, 0.1), transparent);
}

.electron {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #2196f3;
  border-radius: 50%;
  box-shadow: 0 0 15px #2196f3;
}

.electron-orbit-1 {
  animation: electronOrbit1 2s linear infinite;
}

.electron-orbit-2 {
  animation: electronOrbit2 3s linear infinite;
}

.electron-orbit-3 {
  animation: electronOrbit3 4s linear infinite;
}

@keyframes electronOrbit1 {
  0% {
    transform: rotate(0deg) translateX(80px) rotate(0deg);
  }
  100% {
    transform: rotate(360deg) translateX(80px) rotate(-360deg);
  }
}

@keyframes electronOrbit2 {
  0% {
    transform: rotate(0deg) translateX(120px) rotate(0deg);
  }
  100% {
    transform: rotate(360deg) translateX(120px) rotate(-360deg);
  }
}

@keyframes electronOrbit3 {
  0% {
    transform: rotate(0deg) translateX(140px) rotate(0deg);
  }
  100% {
    transform: rotate(360deg) translateX(140px) rotate(-360deg);
  }
}

.nucleus {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  background: #ff5722;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 20px #ff5722;
  animation: nucleusPulse 2s ease-in-out infinite;
}

@keyframes nucleusPulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.2);
  }
}

/* Benzene Ring Animation */
.benzene-ring {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 2rem auto;
}

.benzene-carbon {
  position: absolute;
  width: 20px;
  height: 20px;
  background: #424242;
  border-radius: 50%;
  border: 3px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
  font-weight: bold;
  animation: carbonVibrate 1s ease-in-out infinite;
}

.benzene-carbon:nth-child(1) {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  animation-delay: 0s;
}

.benzene-carbon:nth-child(2) {
  top: 25%;
  right: 0;
  animation-delay: 0.1s;
}

.benzene-carbon:nth-child(3) {
  bottom: 25%;
  right: 0;
  animation-delay: 0.2s;
}

.benzene-carbon:nth-child(4) {
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  animation-delay: 0.3s;
}

.benzene-carbon:nth-child(5) {
  bottom: 25%;
  left: 0;
  animation-delay: 0.4s;
}

.benzene-carbon:nth-child(6) {
  top: 25%;
  left: 0;
  animation-delay: 0.5s;
}

@keyframes carbonVibrate {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

.benzene-bond {
  position: absolute;
  background: #666;
  height: 3px;
  transform-origin: left center;
}

.benzene-bond:nth-child(7) {
  top: 15%;
  left: 60%;
  width: 60px;
  transform: rotate(30deg);
}

.benzene-bond:nth-child(8) {
  top: 50%;
  right: 10%;
  width: 60px;
  transform: rotate(90deg);
}

.benzene-bond:nth-child(9) {
  bottom: 15%;
  right: 60%;
  width: 60px;
  transform: rotate(150deg);
}

.benzene-bond:nth-child(10) {
  bottom: 15%;
  left: 60%;
  width: 60px;
  transform: rotate(210deg);
}

.benzene-bond:nth-child(11) {
  top: 50%;
  left: 10%;
  width: 60px;
  transform: rotate(270deg);
}

.benzene-bond:nth-child(12) {
  top: 15%;
  left: 60%;
  width: 60px;
  transform: rotate(330deg);
}

/* ===== CHEMICAL REACTION ANIMATIONS ===== */

/* Reaction Progress Bar */
.reaction-progress {
  position: relative;
  width: 100%;
  height: 60px;
  background: linear-gradient(90deg, #e3f2fd 0%, #bbdefb 50%, #e8f5e8 100%);
  border-radius: 30px;
  overflow: hidden;
  margin: 2rem 0;
}

.reaction-arrow {
  position: absolute;
  top: 50%;
  left: 0;
  width: 40px;
  height: 40px;
  background: #2196f3;
  border-radius: 50%;
  transform: translateY(-50%);
  animation: reactionProgress 4s ease-in-out infinite;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
}

.reaction-arrow::after {
  content: '→';
  font-size: 20px;
}

@keyframes reactionProgress {
  0% {
    left: 0;
    background: #2196f3;
  }
  50% {
    left: calc(50% - 20px);
    background: #ff9800;
  }
  100% {
    left: calc(100% - 40px);
    background: #4caf50;
  }
}

/* Combustion Reaction */
.combustion-reaction {
  position: relative;
  width: 300px;
  height: 200px;
  margin: 2rem auto;
  background: radial-gradient(circle, rgba(255, 87, 34, 0.1), transparent);
  border-radius: 15px;
  overflow: hidden;
}

.flame {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 60px;
  height: 80px;
  background: linear-gradient(to top, #ff5722 0%, #ff9800 50%, #ffeb3b 100%);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  transform: translateX(-50%);
  animation: flameFlicker 1s ease-in-out infinite alternate;
}

.flame::before {
  content: '';
  position: absolute;
  top: 10px;
  left: 50%;
  width: 40px;
  height: 60px;
  background: linear-gradient(to top, #ff9800 0%, #ffeb3b 50%, #fff 100%);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  transform: translateX(-50%);
}

@keyframes flameFlicker {
  0% {
    transform: translateX(-50%) scale(1) rotate(-2deg);
  }
  100% {
    transform: translateX(-50%) scale(1.1) rotate(2deg);
  }
}

.smoke {
  position: absolute;
  top: 20px;
  left: 50%;
  width: 20px;
  height: 20px;
  background: #9e9e9e;
  border-radius: 50%;
  opacity: 0.6;
  animation: smokeRise 3s ease-out infinite;
}

.smoke:nth-child(2) {
  animation-delay: 0.5s;
  left: 45%;
}

.smoke:nth-child(3) {
  animation-delay: 1s;
  left: 55%;
}

@keyframes smokeRise {
  0% {
    transform: translateX(-50%) translateY(0) scale(0.5);
    opacity: 0.8;
  }
  100% {
    transform: translateX(-50%) translateY(-150px) scale(2);
    opacity: 0;
  }
}

/* ===== PERIODIC TABLE ANIMATIONS ===== */

/* Element Card Animation */
.element-card {
  position: relative;
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  margin: 0.5rem;
  overflow: hidden;
}

.element-card:hover {
  transform: scale(1.1) rotateY(10deg);
  box-shadow: 0 15px 30px rgba(102, 126, 234, 0.4);
}

.element-symbol {
  font-size: 1.5rem;
  margin-bottom: 0.2rem;
}

.element-number {
  font-size: 0.8rem;
  opacity: 0.8;
}

.element-name {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.element-card:hover .element-name {
  bottom: -25px;
  opacity: 1;
}

/* Element Group Colors */
.alkali-metal {
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
}

.alkaline-earth {
  background: linear-gradient(135deg, #feca57, #ff9ff3);
}

.transition-metal {
  background: linear-gradient(135deg, #48dbfb, #0abde3);
}

.noble-gas {
  background: linear-gradient(135deg, #ff9ff3, #f368e0);
}

.halogen {
  background: linear-gradient(135deg, #54a0ff, #2e86de);
}

/* Periodic Table Wave Animation */
.periodic-wave {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  gap: 2px;
  max-width: 900px;
  margin: 2rem auto;
}

.periodic-wave .element-card {
  animation: elementWave 2s ease-in-out infinite;
  animation-delay: calc(var(--delay) * 0.1s);
}

@keyframes elementWave {
  0%, 100% {
    transform: scale(1);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.1);
    opacity: 1;
  }
}

/* ===== LABORATORY EQUIPMENT ANIMATIONS ===== */

/* Beaker Bubbling Animation */
.lab-beaker {
  position: relative;
  width: 120px;
  height: 150px;
  margin: 2rem auto;
}

.beaker-container {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 120px;
  background: linear-gradient(to top, transparent 0%, rgba(33, 150, 243, 0.3) 100%);
  border: 4px solid #424242;
  border-top: none;
  border-radius: 0 0 20px 20px;
}

.beaker-liquid {
  position: absolute;
  bottom: 4px;
  left: 4px;
  right: 4px;
  height: 80px;
  background: linear-gradient(to top, #2196f3 0%, #64b5f6 100%);
  border-radius: 0 0 16px 16px;
  animation: liquidBubble 2s ease-in-out infinite;
}

@keyframes liquidBubble {
  0%, 100% {
    height: 80px;
  }
  50% {
    height: 85px;
  }
}

.bubble {
  position: absolute;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  animation: bubbleRise 2s ease-out infinite;
}

.bubble:nth-child(1) {
  width: 8px;
  height: 8px;
  left: 20%;
  animation-delay: 0s;
}

.bubble:nth-child(2) {
  width: 6px;
  height: 6px;
  left: 50%;
  animation-delay: 0.5s;
}

.bubble:nth-child(3) {
  width: 10px;
  height: 10px;
  left: 70%;
  animation-delay: 1s;
}

@keyframes bubbleRise {
  0% {
    bottom: 0;
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    bottom: 100px;
    opacity: 0;
  }
}

/* Test Tube Reaction */
.test-tube {
  position: relative;
  width: 40px;
  height: 200px;
  margin: 2rem auto;
  background: linear-gradient(to bottom, transparent 0%, rgba(76, 175, 80, 0.3) 100%);
  border: 3px solid #424242;
  border-radius: 0 0 20px 20px;
  overflow: hidden;
}

.test-tube-liquid {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 60%;
  background: linear-gradient(to top, #4caf50 0%, #81c784 100%);
  animation: testTubeReaction 3s ease-in-out infinite;
}

@keyframes testTubeReaction {
  0%, 100% {
    height: 60%;
    background: linear-gradient(to top, #4caf50 0%, #81c784 100%);
  }
  50% {
    height: 80%;
    background: linear-gradient(to top, #ff5722 0%, #ff8a65 100%);
  }
}

/* Microscope Animation */
.microscope {
  position: relative;
  width: 200px;
  height: 250px;
  margin: 2rem auto;
}

.microscope-base {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 40px;
  background: #424242;
  border-radius: 20px;
}

.microscope-arm {
  position: absolute;
  bottom: 40px;
  left: 50%;
  width: 20px;
  height: 150px;
  background: #616161;
  transform: translateX(-50%);
  border-radius: 10px;
}

.microscope-lens {
  position: absolute;
  top: 20px;
  left: 50%;
  width: 60px;
  height: 60px;
  background: radial-gradient(circle, #2196f3 30%, #424242 70%);
  border-radius: 50%;
  transform: translateX(-50%);
  animation: microscopeFocus 2s ease-in-out infinite;
}

@keyframes microscopeFocus {
  0%, 100% {
    box-shadow: 0 0 20px rgba(33, 150, 243, 0.5);
  }
  50% {
    box-shadow: 0 0 40px rgba(33, 150, 243, 0.8);
  }
}

/* ===== MOLECULAR INTERACTION EFFECTS ===== */

/* Hydrogen Bonding */
.hydrogen-bond {
  position: relative;
  width: 300px;
  height: 200px;
  margin: 2rem auto;
}

.h2o-molecule {
  position: absolute;
  width: 80px;
  height: 60px;
}

.h2o-molecule:nth-child(1) {
  top: 20px;
  left: 50px;
  animation: moleculeFloat1 3s ease-in-out infinite;
}

.h2o-molecule:nth-child(2) {
  top: 80px;
  right: 50px;
  animation: moleculeFloat2 3s ease-in-out infinite;
}

.oxygen {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  background: #f44336;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.hydrogen {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid #424242;
  border-radius: 50%;
}

.hydrogen:nth-child(2) {
  top: 20%;
  left: 20%;
}

.hydrogen:nth-child(3) {
  top: 20%;
  right: 20%;
}

@keyframes moleculeFloat1 {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-10px) rotate(5deg);
  }
}

@keyframes moleculeFloat2 {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(10px) rotate(-5deg);
  }
}

/* ===== RESPONSIVE DESIGN ===== */

@media (max-width: 768px) {
  .dna-helix {
    width: 150px;
    height: 300px;
  }
  
  .molecular-orbital {
    width: 250px;
    height: 250px;
  }
  
  .periodic-wave {
    grid-template-columns: repeat(9, 1fr);
    max-width: 450px;
  }
  
  .element-card {
    width: 60px;
    height: 60px;
  }
}

@media (max-width: 480px) {
  .benzene-ring {
    width: 150px;
    height: 150px;
  }
  
  .combustion-reaction {
    width: 250px;
    height: 150px;
  }
  
  .element-card {
    width: 50px;
    height: 50px;
    margin: 0.2rem;
  }
  
  .element-symbol {
    font-size: 1.2rem;
  }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

@media (prefers-reduced-motion: reduce) {
  .dna-strand,
  .electron-orbit-1,
  .electron-orbit-2,
  .electron-orbit-3,
  .nucleus,
  .carbon-vibrate,
  .reaction-arrow,
  .flame,
  .smoke,
  .element-wave,
  .liquid-bubble,
  .bubble,
  .test-tube-liquid,
  .microscope-lens,
  .molecule-float1,
  .molecule-float2 {
    animation: none;
  }
}

/* GPU acceleration */
.dna-strand,
.electron,
.element-card,
.flame,
.bubble {
  will-change: transform;
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */

.element-card:focus {
  outline: 3px solid #ff6b35;
  outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .element-card {
    border: 2px solid currentColor;
  }
  
  .beaker-container,
  .test-tube {
    border-width: 3px;
  }
}

/* ===== EDUCATIONAL UTILITY CLASSES ===== */

.chem-fade-in {
  animation: chemFadeIn 1s ease-out forwards;
}

@keyframes chemFadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chem-highlight {
  animation: chemHighlight 2s ease-in-out infinite;
}

@keyframes chemHighlight {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.7);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(255, 193, 7, 0);
  }
}

.chem-pulse {
  animation: chemPulse 1.5s ease-in-out infinite;
}

@keyframes chemPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}