body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #f0f0f0;
    margin: 0;
}

.container {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    text-align: center;
    width: 80%;
    max-width: 900px;
}

h1 {
    color: #333;
}

.controls label,
.controls select,
.controls button {
    margin: 10px 5px;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.controls button {
    background-color: #007bff;
    color: white;
    cursor: pointer;
    border: none;
}

.controls button:hover {
    background-color: #0056b3;
}

.simulation-area {
    margin-top: 20px;
    border: 1px solid #eee;
    padding: 20px;
    min-height: 400px; /* Increased height for visuals */
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* Adjusted for equation positioning */
    align-items: center;
    background-color: #a0a0a0;
    position: relative; /* For positioning apparatus elements */
}

.apparatus {
    width: 100%;
    height: 300px; /* Dedicated space for apparatus */
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-end; /* Align items to the bottom */
}

/* Retort Stand */
.retort-stand {
    position: absolute;
    bottom: 20px; /* Positioned from bottom */
    left: calc(50% - 100px); /* Centered with offset */
    width: 10px;
    height: 220px;
}
.retort-stand .base {
    width: 100px;
    height: 10px;
    background-color: #555;
    position: absolute;
    bottom: 0;
    left: -35px;
    border-radius: 2px;
}
.retort-stand .rod {
    width: 10px;
    height: 250px;
    background-color: #777;
    position: absolute;
    bottom: 10px;
    left: 0;
    border-radius: 2px 2px 0 0;
}
.retort-stand .clamp {
    width: 100px; /* Wider to encompass test tube */
    height: 10px; /* Thinner to look like a clamp arm */
    background-color: #666;
    position: absolute;
    top: 0px; /* Position of the clamp */
    left: -25px; /* Adjust left to center around test tube */
    border-radius: 3px;
    z-index: 10;
}
.clamp-jaw {
    position: absolute;
    width: 10px;
    height: 28px;
    top: -9px;
    background: linear-gradient(135deg, #bbb 60%, #888 100%);
    border-radius: 50% 50% 40% 40% / 70% 70% 100% 100%;
    border: 2px solid #666;
    z-index: 11;
    box-shadow: 0 2px 6px #8886 inset;
}
.clamp-jaw.left {
    left: 100px;
    transform: rotate(-0deg);
}
.clamp-jaw.right {
    right: -55px;
    transform: scaleX(-1) rotate(-0deg);
}

/* Removed old clamp fingers for realistic jaws */

/* Test Tube */
.test-tube {
    width: 30px;
    height: 120px;
    background-color: rgba(200, 200, 255, 0.5); /* Semi-transparent glass */
    border: 2px solid #aaa;
    border-radius: 0 0 15px 15px; /* Rounded bottom */
    position: absolute;
    bottom: 160px; /* Adjusted position to align with clamp */
    left: calc(50% - 15px); /* Centered */
    overflow: hidden; /* To contain chemical and gas */
    z-index: 10;
}

.chemical {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 0%; /* Initially empty, controlled by JS */
    transition:
        height 1s ease-in-out,
        background-color 1s ease-in-out;
    border-radius: 0 0 10px 10px; /* Rounded bottom of chemical */
    z-index: 2;
}

.gas {
    position: absolute;
    left: 0;
    width: 100%;
    height: 0%; /* Initially no gas */
    background: linear-gradient(
        to top,
        rgba(220, 220, 220, 0.7) 60%,
        rgba(180, 220, 255, 0.25) 100%
    );
    transition:
        height 1s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 1s cubic-bezier(0.4, 0, 0.2, 1),
        bottom 1s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    border-radius: 10px 10px 18px 18px;
    z-index: 4;
    bottom: 50%; /* Default: above chemical */
    pointer-events: none;
    overflow: visible;
    animation: gas-overflow 2.5s infinite linear alternate;
    filter: blur(1.5px);
}

/* SO2 and SO3 gas visuals for ferrous sulphate */
.gas.so2 {
    background: linear-gradient(
        to top,
        rgba(200, 255, 100, 0.7) 60%,
        rgba(255, 255, 200, 0.25) 100%
    );
    z-index: 5;
    left: 0;
    width: 60%;
}

.gas.so3 {
    background: linear-gradient(
        to top,
        rgba(200, 255, 100, 0.7) 60%,
        rgba(220, 220, 255, 0.25) 100%
    );
    z-index: 6;
    left: 40%;
    width: 60%;
}

@keyframes gas-overflow {
    0% {
        filter: blur(1.5px) brightness(1);
        opacity: 0.85;
        background-position: 0% 100%;
        box-shadow: 0 0 0 0 rgba(180, 220, 255, 0.12);
        transform: translateY(0) scaleX(1) scaleY(1);
    }
    60% {
        opacity: 1;
        filter: blur(2.5px) brightness(1.08);
        box-shadow: 0 -12px 32px 8px rgba(180, 220, 255, 0.18);
        transform: translateY(-12px) scaleX(1.05) scaleY(1.08);
    }
    100% {
        opacity: 0.7;
        filter: blur(3.5px) brightness(1.13);
        box-shadow: 0 -32px 64px 24px rgba(180, 220, 255, 0.13);
        transform: translateY(-40px) scaleX(1.12) scaleY(1.15);
    }
}

/* SO2 Test Beaker and KMnO4 Color Change */
.so2-test-area {
    position: absolute;
    left: 70%;
    bottom: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 20;
    pointer-events: none;
}

.so2-test-label {
    font-size: 0.95em;
    color: #333;
    margin-bottom: 2px;
    pointer-events: none;
}

.beaker-label {
    font-size: 1em;
    color: #333;
    margin-top: 4px;
    text-align: center;
    width: 100%;
    pointer-events: none;
}

/* CO2 Lime Water Test Beaker */
#co2TestBeaker {
    width: 12vw;
    min-width: 60px;
    max-width: 120px;
    height: auto;
    position: absolute;
    right: 40px;
    bottom: 120px;
    display: none;
    z-index: 21;
}
#co2TestBeaker svg {
    width: 100%;
    height: auto;
    display: block;
}
.limewater-label {
    font-size: 1em;
    color: #333;
    margin-top: 4px;
    text-align: center;
    width: 100%;
    pointer-events: none;
}

/* Lime water solution visuals */
#limewaterSolution {
    transition: fill 1.2s, filter 1.2s;
}
.limewater-clear {
    fill: url(#limewaterClear);
    filter: none;
}
.limewater-milky {
    fill: url(#limewaterMilky);
    filter: blur(1.2px) brightness(1.08);
    transition: fill 1.8s, filter 1.8s;
}

/* Responsive SO2 Test Flask SVG */
#so2TestBeaker {
    width: 12vw;
    min-width: 60px;
    max-width: 120px;
    height: auto;
}
#so2TestBeaker svg {
    width: 100%;
    height: auto;
    display: block;
}

.so2-test-beaker::after {
    content: "";
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 8px;
    background: rgba(180, 180, 255, 0.15);
    border-radius: 50% 50% 40% 40% / 60% 60% 100% 100%;
    z-index: 3;
}

/* Bunsen Burner */
.bunsen-burner {
    position: absolute;
    bottom: 20px;
    left: calc(50% - 18px);
    width: 36px;
    height: 90px;
    z-index: 3;
}
.bunsen-burner .burner-base {
    width: 60px;
    height: 18px;
    background: radial-gradient(ellipse at 50% 60%, #444 70%, #222 100%);
    position: absolute;
    bottom: 0;
    left: -12px;
    border-radius: 10px 10px 12px 12px;
    box-shadow:
        0 2px 8px #2228,
        0 0 0 2px #8884 inset;
    border: 2px solid #222;
}
.bunsen-burner .burner-tube {
    width: 16px;
    height: 68px;
    background: linear-gradient(135deg, #b0bec5 0%, #eceff1 60%, #78909c 100%);
    position: absolute;
    bottom: 18px;
    left: 10px;
    border-radius: 8px 8px 7px 7px;
    border: 2px solid #888;
    box-shadow: 0 0 8px #b0bec544 inset;
    z-index: 2;
}
.bunsen-burner .collar {
    width: 22px;
    height: 12px;
    background: linear-gradient(90deg, #888 0%, #bbb 100%);
    position: absolute;
    bottom: 54px;
    left: 7px;
    border-radius: 6px 6px 6px 6px;
    border: 1.5px solid #666;
    z-index: 3;
    box-shadow: 0 2px 6px #8886 inset;
}
.bunsen-burner .air-hole {
    width: 6px;
    height: 6px;
    background: #222;
    border-radius: 50%;
    position: absolute;
    bottom: 58px;
    left: 15px;
    z-index: 4;
    box-shadow: 0 0 2px #000a;
}
.bunsen-burner .gas-inlet {
    width: 14px;
    height: 8px;
    background: linear-gradient(90deg, #888 0%, #444 100%);
    position: absolute;
    bottom: 6px;
    left: 23px;
    border-radius: 4px 8px 8px 4px;
    border: 1px solid #555;
    z-index: 5;
    box-shadow: 0 1px 3px #2226;
}

.flame {
    width: 0;
    height: 0;
    position: absolute;
    bottom: 110px;
    left: calc(50% - 8px);
    border-radius: 50% 50% 40% 40% / 60% 60% 100% 100%;
    opacity: 0;
    pointer-events: none;
    z-index: 5;
    transition: opacity 0.4s;
    box-shadow: 0 0 0px 0px rgba(255, 140, 0, 0);
}

/* Electrolysis Setup */
.electrolysis-setup {
    display: none; /* Hidden by default */
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 220px;
}

.electrolysis-setup .beaker {
    width: 120px;
    height: 150px;
    background-color: rgba(200, 200, 255, 0.3);
    border: 2px solid #aaa;
    border-radius: 5px 5px 10px 10px;
    position: relative;
    margin: 0 auto;
    overflow: hidden;
}

.electrolysis-setup .water-level {
    width: 100%;
    height: 70%; /* Default water level */
    background-color: rgba(100, 150, 255, 0.5);
    position: absolute;
    bottom: 0;
}

.electrolysis-setup .electrode {
    width: 10px;
    height: 100px;
    background-color: #555;
    position: absolute;
    bottom: 5px;
}

.electrolysis-setup .electrode-anode {
    left: 25px;
}

.electrolysis-setup .electrode-cathode {
    right: 25px;
}

.electrolysis-setup .bubbles {
    position: absolute;
    bottom: 10px; /* Start above electrode base */
    width: 5px;
    height: 5px;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    opacity: 0;
    animation: rise 2s infinite linear;
}

.electrolysis-setup .anode-bubbles {
    left: 27.5px; /* Centered on anode */
}

.electrolysis-setup .cathode-bubbles {
    right: 27.5px; /* Centered on cathode */
}

.electrolysis-setup .power-supply {
    width: 60px;
    height: 30px;
    background-color: #333;
    border: 2px solid #111;
    border-radius: 5px;
    margin: 10px auto 0;
}

/* Animations */
.flame.active {
    width: 22px;
    height: 54px;
    opacity: 1;
    background: radial-gradient(
        ellipse at 60% 80%,
        #fffbe6 0%,
        #ffe066 30%,
        #ffb347 60%,
        #ff7300 85%,
        #ff4800 100%
    );
    box-shadow:
        0 0 32px 8px rgba(255, 180, 60, 0.25),
        0 0 64px 24px rgba(255, 120, 0, 0.13);
    animation: flame-flicker 0.22s infinite alternate;
    transition:
        width 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        height 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.4s;
}

.flame.active::after {
    content: "";
    position: absolute;
    left: 6px;
    bottom: 10px;
    width: 8px;
    height: 22px;
    border-radius: 50% 50% 40% 40% / 60% 60% 100% 100%;
    background: radial-gradient(
        ellipse at 50% 80%,
        #b3e0ff 0%,
        #4fc3f7 80%,
        transparent 100%
    );
    opacity: 0.7;
    filter: blur(1.5px);
    z-index: 6;
    pointer-events: none;
}

@keyframes flame-flicker {
    0% {
        transform: scaleY(1) scaleX(1) skewX(0deg);
        filter: brightness(1) blur(0.5px);
        box-shadow:
            0 0 32px 8px rgba(255, 180, 60, 0.25),
            0 0 64px 24px rgba(255, 120, 0, 0.13);
    }
    40% {
        transform: scaleY(1.08) scaleX(0.96) skewX(-2deg);
        filter: brightness(1.08) blur(1.2px);
    }
    70% {
        transform: scaleY(0.93) scaleX(1.04) skewX(2deg);
        filter: brightness(0.95) blur(0.8px);
    }
    100% {
        transform: scaleY(1.12) scaleX(0.98) skewX(-1deg);
        filter: brightness(1.13) blur(1.5px);
        box-shadow:
            0 0 48px 16px rgba(255, 200, 80, 0.22),
            0 0 96px 32px rgba(255, 120, 0, 0.1);
    }
}

@keyframes rise {
    0% {
        transform: translateY(0);
        opacity: 1;
    }
    100% {
        transform: translateY(-100px);
        opacity: 0;
    }
}

.chemical-equation {
    font-weight: bold;
    color: #333;
    margin-top: 10px;
    min-height: 20px; /* Ensure space for equation */
}

/* SO2 gas flow animation for delivery tube */
@keyframes so2-gas-flow {
    to {
        stroke-dashoffset: -100;
    }
}

/* CO2 gas flow animation for delivery tube */
@keyframes co2-gas-flow {
    to {
        stroke-dashoffset: -100;
    }
}

/* Hide/show apparatus based on reaction type */
.thermal-active .electrolysis-setup {
    display: none;
}
.thermal-active .retort-stand,
.thermal-active .test-tube,
.thermal-active .bunsen-burner {
    display: block; /* Or flex/grid as needed */
}

.electrolytic-active .retort-stand,
.electrolytic-active .test-tube,
.electrolytic-active .bunsen-burner {
    display: none;
}
.electrolytic-active .electrolysis-setup {
    display: block; /* Or flex/grid as needed */
}
