/* ============================================
   ULTRA-REALISTIC 3D FLASK PRELOADER
   Red Chemical Vapour Edition
============================================ */

:root {
    --glass-surface: rgba(255, 255, 255, 0.25);
    --glass-border: rgba(255, 255, 255, 0.6);
    --glass-shadow: rgba(0, 0, 0, 0.15);
    
    /* Vibrant Chemical Colors */
    --chem-dark: #800000;
    --chem-mid: #cc0000;
    --chem-light: #ff3333;
    --chem-glow: #ff6666;
    
    /* Vapour Colors */
    --vapour-color: rgba(255, 200, 200, 0.3);
}

.preloader {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    /* Subtle radial gradient focus */
    background: radial-gradient(circle at center, #ffffff 0%, #f0f2f5 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    overflow: hidden;
}

.preloader * { box-sizing: border-box; }

.loader {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

/* ============================
   3D CONTAINER & ANIMATION
============================ */

.flask-container {
    position: relative;
    width: 70px; /* Slightly wider for better proportions */
    height: 90px;
    perspective: 1000px;
    transform-style: preserve-3d;
}

.flask {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    /* Smoother, more organic rotation */
    animation: flaskFloat 6s ease-in-out infinite; 
}

@keyframes flaskFloat {
    0%, 100% { transform: rotateY(-10deg) rotateX(5deg) translateY(0); }
    50% { transform: rotateY(10deg) rotateX(-5deg) translateY(-8px); }
}

/* ============================
   THE VAPOUR (SMOKE) EFFECT
============================ */
.vapour {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    z-index: 0;
    opacity: 0;
    animation: vapourFadeIn 2s ease-out forwards 1s; /* Delays smoke until liquid fills */
}

.vapour span {
    position: relative;
    bottom: 0;
    display: block;
    margin: 0 2px 50px 2px;
    min-width: 8px;
    height: 120px;
    background: #fff;
    border-radius: 50%;
    animation: vapourRise 5s linear infinite;
    opacity: 0;
    filter: blur(8px);
    animation-delay: calc(var(--i) * -0.5s);
}

@keyframes vapourRise {
    0% { transform: translateY(0) scaleX(1); opacity: 0; background: var(--chem-light); }
    15% { opacity: 0.6; }
    50% { transform: translateY(-50px) scaleX(3); background: #fff; }
    95% { opacity: 0; }
    100% { transform: translateY(-100px) scaleX(6); opacity: 0; }
}
@keyframes vapourFadeIn { to { opacity: 1; } }

/* ============================
   GLASS ARCHITECTURE
============================ */

/* The Rim/Neck */
.flask-neck {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 14px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid var(--glass-border);
    border-radius: 50%;
    z-index: 10;
    backdrop-filter: blur(4px);
    box-shadow: 
        inset 0 2px 5px rgba(255,255,255,0.8),
        0 5px 10px rgba(0,0,0,0.05);
}

/* Inner Neck Depth */
.flask-neck::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 80%; height: 70%;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0.1) 0%, transparent 80%);
    border-radius: 50%;
}

/* The Main Body */
.flask-body {
    position: absolute;
    top: 7px; /* Tuck under neck */
    left: 50%;
    transform: translateX(-50%);
    width: 95%;
    height: calc(100% - 7px);
    background: rgba(255, 255, 255, 0.05);
    border-left: 2px solid var(--glass-border);
    border-right: 2px solid var(--glass-border);
    border-bottom: 4px solid var(--glass-border);
    border-radius: 0 0 25px 25px; /* Softer, rounder bottom */
    overflow: hidden;
    z-index: 5;
    
    /* The "Thick Glass" Effect */
    box-shadow: 
        inset 10px 0 15px rgba(255,255,255,0.4),  /* Left Inner Highlight */
        inset -10px 0 15px rgba(255,255,255,0.4), /* Right Inner Highlight */
        inset 0 -10px 20px rgba(255,255,255,0.5), /* Bottom Thickness */
        0 15px 35px rgba(0,0,0,0.1);              /* Drop Shadow */
    
    backdrop-filter: blur(2px);
}

/* Vertical Reflection Highlight */
.flask-body::before {
    content: '';
    position: absolute;
    top: 10%; left: 15%;
    width: 6px; height: 70%;
    background: linear-gradient(to bottom, rgba(255,255,255,0.8), rgba(255,255,255,0));
    border-radius: 10px;
    z-index: 20;
    filter: blur(1px);
}

/* Measurement Lines */
.flask::before {
    content: '';
    position: absolute;
    top: 30%; right: 15%;
    width: 15px; height: 40%;
    background: repeating-linear-gradient(
        to bottom,
        rgba(255,255,255,0.6) 0,
        rgba(255,255,255,0.6) 2px,
        transparent 2px,
        transparent 10px
    );
    z-index: 15;
    opacity: 0.6;
}

/* ============================
   THE CHEMICAL LIQUID
============================ */

.liquid {
    position: absolute;
    bottom: 0; left: 0;
    width: 100%;
    height: 0%; /* Start empty */
    background: linear-gradient(to right, var(--chem-dark), var(--chem-mid), var(--chem-light), var(--chem-mid), var(--chem-dark));
    border-radius: 0 0 20px 20px;
    z-index: 2;
    animation: fillLevel 4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    box-shadow: 0 0 20px var(--chem-glow); /* Radioactive glow */
}

@keyframes fillLevel {
    0% { height: 0%; opacity: 0.8; }
    50% { height: 75%; opacity: 1; }
    80% { height: 75%; opacity: 1; } /* Pause at top */
    100% { height: 0%; opacity: 0.8; }
}

/* Liquid Surface (Meniscus) */
.liquid-surface {
    position: absolute;
    top: -5px;
    left: 0;
    width: 100%;
    height: 10px;
    background: rgba(255, 100, 100, 0.5);
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: inset 0 0 10px var(--chem-light);
    animation: slosh 4s ease-in-out infinite;
}

@keyframes slosh {
    0%, 100% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(2deg) scale(1.05); }
}

/* Rising Bubbles inside Liquid */
.liquid-bubbles span {
    position: absolute;
    bottom: -10px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: bubbleRise 2s infinite ease-in;
}

.liquid-bubbles span:nth-child(1) { left: 20%; width: 5px; height: 5px; animation-duration: 2.2s; }
.liquid-bubbles span:nth-child(2) { left: 50%; width: 7px; height: 7px; animation-duration: 1.8s; animation-delay: 0.5s; }
.liquid-bubbles span:nth-child(3) { left: 70%; width: 4px; height: 4px; animation-duration: 2.5s; animation-delay: 1s; }
.liquid-bubbles span:nth-child(4) { left: 85%; width: 6px; height: 6px; animation-duration: 2s; animation-delay: 1.5s; }

@keyframes bubbleRise {
    0% { bottom: 0; opacity: 0; transform: translateX(0); }
    50% { opacity: 1; }
    100% { bottom: 100%; opacity: 0; transform: translateX(-5px); }
}

/* Floor Reflection */
.flask-reflection {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 15px;
    background: radial-gradient(ellipse at center, rgba(200,0,0,0.3) 0%, transparent 70%);
    border-radius: 50%;
    filter: blur(5px);
    animation: reflectionPulse 4s infinite;
}

@keyframes reflectionPulse {
    0%, 100% { width: 30px; opacity: 0.2; }
    50% { width: 60px; opacity: 0.6; }
}

/* ============================
   MOLECULAR LOADING DOTS
============================ */
.loading-dots {
    margin-top: 40px;
    display: flex;
    gap: 12px;
}

.loading-dots span {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    /* 3D Sphere look */
    background: radial-gradient(circle at 30% 30%, #ff8888, var(--chem-mid));
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    animation: moleculeBounce 1.5s infinite ease-in-out;
}

.loading-dots span:nth-child(2) { animation-delay: 0.1s; }
.loading-dots span:nth-child(3) { animation-delay: 0.2s; }
.loading-dots span:nth-child(4) { animation-delay: 0.3s; }
.loading-dots span:nth-child(5) { animation-delay: 0.4s; }

@keyframes moleculeBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* ============================
   RESPONSIVE SCALING
   (Simplified Approach: Scale the container)
============================ */

/* Mobile optimization */
@media (max-width: 768px) {
    .flask-container { transform: scale(0.85); }
    .loading-dots { margin-top: 30px; }
    .vapour { top: -25px; } /* Adjust vapour start point */
}

@media (max-width: 480px) {
    .flask-container { transform: scale(0.75); }
    .loading-dots span { width: 10px; height: 10px; }
}

/* --------------------------------------------
     HTML structure required for enhanced realism:

     <div class="preloader">
         <div class="loader">
             <div class="flask-container">
                 <div class="flask">
                     <div class="flask-neck"></div>
                     <div class="flask-body">
                         <div class="liquid">
                             <div class="liquid-surface"></div>
                             <div class="liquid-bubbles">
                                 <!-- JS will inject multiple <span> bubble elements -->
                             </div>
                         </div>
                     </div>
                 </div>
                 <div class="flask-reflection"></div>
             </div>
             <div class="loading-text">Loading</div>
         </div>
     </div>

     Optional JS to populate bubbles (minimal):
     const container = document.querySelector('.liquid-bubbles');
     for (let i=0;i<6;i++){
         const b=document.createElement('span');
         b.style.left = (10 + Math.random()*80)+'%';
         b.style.animationDelay = (Math.random()*2)+'s';
         container.appendChild(b);
     }
-------------------------------------------- */
