@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700;800&display=swap');

:root {
    --primary: #667eea;
    --primary-dark: #5568d3;
    --secondary: #764ba2;
    --accent: #f093fb;
    --success: #4ade80;
    --warning: #fbbf24;
    --background: #0f172a;
    --card-bg: #1e293b;
    --text: #f8fafc;
    --text-light: #94a3b8;
    --glass: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: var(--text);
    user-select: none;
    overflow: hidden;
    min-height: 100vh;
}

/* Animated Background */
.bg-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
}

.bubble {
    position: absolute;
    bottom: -100px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    opacity: 0.1;
    animation: rise 15s infinite ease-in;
}

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

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

.bubble:nth-child(3) {
    left: 35%;
    width: 100px;
    height: 100px;
    animation-delay: 4s;
}

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

.bubble:nth-child(5) {
    left: 65%;
    width: 90px;
    height: 90px;
    animation-delay: 3s;
}

.bubble:nth-child(6) {
    left: 80%;
    width: 75px;
    height: 75px;
    animation-delay: 5s;
}

.bubble:nth-child(7) {
    left: 90%;
    width: 65px;
    height: 65px;
    animation-delay: 2.5s;
}

@keyframes rise {
    0% {
        bottom: -100px;
        transform: translateX(0) scale(1);
    }

    50% {
        transform: translateX(100px) scale(1.2);
    }

    100% {
        bottom: 110vh;
        transform: translateX(-100px) scale(0.8);
    }
}

#game {
    position: relative;
    min-height: 100vh;
    width: 100%;
    z-index: 1;
}

/* Menu Styles */
#menu {
    position: fixed;
    top: 0;
    left: 0;
    height: 90vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 10;
    gap: 20px;
}

#menu-heading {
    width: 90%;
    max-width: 600px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    font-size: 2rem;
    font-weight: 800;
    text-align: center;
    padding: 20px 20px;
    border-radius: 30px;
    margin-bottom: 20px;
    box-shadow: 0 20px 60px rgba(102, 126, 234, 0.4);
    position: relative;
    overflow: hidden;
    letter-spacing: 2px;
}

#menu-heading::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%) translateY(-100%) rotate(45deg);
    }

    100% {
        transform: translateX(100%) translateY(100%) rotate(45deg);
    }
}

.lvl {
    width: 90%;
    max-width: 450px;
    padding: 20px 40px;
    font-size: 1.6rem;
    font-weight: 700;
    text-align: center;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
    background: var(--glass);
    backdrop-filter: blur(10px);
    border: 2px solid var(--glass-border);
    color: white;
}

.lvl::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.lvl:hover::before {
    left: 100%;
}

.lvl:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 20px 40px rgba(102, 126, 234, 0.3);
    border-color: var(--primary);
}

.lvl:active {
    transform: translateY(-4px) scale(0.98);
}

#easy {
    background: linear-gradient(135deg, #10b981, #059669);
}

#medium {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

#hard {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

#very-hard {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

/* Level Display */
#level {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 100vw;
    overflow-y: auto;
    overflow-x: hidden;
    margin-bottom: 20px;
}

#lvl-heading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 90px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 800;
    color: white;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 100;
    letter-spacing: 3px;
}

/* Test Tube Styles */
.test-tube {
    position: absolute;
    height: 140px;
    width: 45px;
    border: 3px solid rgba(148, 163, 184, 0.4);
    border-radius: 3px 3px 22px 22px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05));
    backdrop-filter: blur(10px);
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2),
        inset 0 2px 10px rgba(255, 255, 255, 0.1);
}

.test-tube::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.2) 50%, transparent 100%);
    z-index: 10;
    pointer-events: none;
}

.test-tube:hover {
    transform: scale(1.05);
    border-color: rgba(148, 163, 184, 0.6);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
}

.test-tube.selected {
    border: 4px solid #ef4444;
    border-color: #ef4444;
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.6),
        0 12px 30px rgba(0, 0, 0, 0.3);
    animation: pulse 0.6s ease-in-out infinite alternate;
}

@keyframes pulse {
    from {
        box-shadow: 0 0 20px rgba(239, 68, 68, 0.4), 0 12px 30px rgba(0, 0, 0, 0.3);
    }

    to {
        box-shadow: 0 0 40px rgba(239, 68, 68, 0.8), 0 12px 30px rgba(0, 0, 0, 0.3);
    }
}

.colors {
    position: absolute;
    left: 0;
    height: 32px;
    width: 100%;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Game Controls */
.game-buttons {
    position: fixed;
    bottom: 30px;
    height: 60px;
    width: 140px;
    font-size: 1.2rem;
    font-weight: 700;
    text-align: center;
    line-height: 60px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-radius: 30px;
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 100;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.game-buttons:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(102, 126, 234, 0.5);
}

.game-buttons:active {
    transform: translateY(-2px);
}

#restart {
    left: 30px;
}

#home {
    right: 30px;
}

#moves {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 30px;
    font-size: 1.3rem;
    font-weight: 700;
    color: white;
    background: var(--glass);
    backdrop-filter: blur(10px);
    border: 2px solid var(--glass-border);
    border-radius: 50px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    z-index: 100;
}

/* Win Screen */
#won {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5rem;
    font-weight: 900;
    color: var(--success);
    text-shadow: 0 0 20px rgba(74, 222, 128, 0.5);
    animation: wonAnimation 1s infinite alternate;
    z-index: 200;
    text-align: center;
}

@keyframes wonAnimation {
    from {
        transform: translate(-50%, -50%) scale(1);
    }

    to {
        transform: translate(-50%, -50%) scale(1.1);
    }
}

/* Rules Modal */
#rules-btn {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 15px 40px;
    background: linear-gradient(135deg, var(--warning), #f59e0b);
    color: white;
    border-radius: 30px;
    font-size: 1.3rem;
    font-weight: 700;
    box-shadow: 0 10px 25px rgba(251, 191, 36, 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 100;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

#rules-btn:hover {
    transform: translateX(-50%) translateY(-5px);
    box-shadow: 0 15px 35px rgba(251, 191, 36, 0.5);
}

#rules-page {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 100vw;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#rules {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    background: var(--card-bg);
    border-radius: 30px;
    overflow: hidden;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
    border: 2px solid var(--glass-border);
}

#rules-heading {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    padding: 30px;
    font-size: 2rem;
    font-weight: 800;
    text-align: center;
    color: white;
    letter-spacing: 2px;
}

#rules-text {
    padding: 30px;
    max-height: calc(80vh - 180px);
    overflow-y: auto;
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--text-light);
}

#rules-text::-webkit-scrollbar {
    width: 8px;
}

#rules-text::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

#rules-text strong {
    color: var(--text);
    font-weight: 600;
}

#rules-text ul {
    margin: 15px 0 15px 25px;
}

#rules-text li {
    margin: 10px 0;
}

#back {
    position: absolute;
    bottom: 20px;
    right: 20px;
    padding: 15px 40px;
    background: linear-gradient(135deg, var(--success), #22c55e);
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

#back:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(74, 222, 128, 0.4);
}

/* Preloader */
#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, var(--background), var(--card-bg));
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#preloader.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent, var(--primary), var(--accent), transparent);
    animation: rotate 1.5s linear infinite;
    position: relative;
}

.loader::before {
    content: "";
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    background: var(--background);
    border-radius: 50%;
}

@keyframes rotate {
    to {
        transform: rotate(360deg);
    }
}

#preloader p {
    color: white;
    font-size: 1.5rem;
    font-weight: 600;
    margin-top: 30px;
    letter-spacing: 1px;
}

/* Sound Toggle */
#sound-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    z-index: 1001;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

#sound-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.6);
}

/* Responsive */
@media (max-width: 768px) {
    #menu-heading {
        font-size: 1.2rem;
        padding: 30px 15px;
    }

    .lvl {
        font-size: 1.4rem;
        padding: 20px 30px;
    }

    #lvl-heading {
        font-size: 2rem;
        height: 80px;
    }

    #won {
        font-size: 3.5rem;
    }

    .game-buttons {
        width: 120px;
        height: 50px;
        line-height: 50px;
        font-size: 1.1rem;
    }

    #menu {
        gap: 10px !important;
    }

    .lvl {
        padding: 15px 30px !important;
    }

    #rules-btn {
        font-size: 1.0rem;
        padding: 15px 30px;
    }
}

#white-bg,
#colorful-bg {
    position: absolute;
    left: 0;
    width: 100%;
    transition: all 0.8s ease;
    z-index: 5;
}

/* Water Sort Themed Preloader */
#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, var(--background), var(--card-bg));
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#preloader.hidden {
    opacity: 0;
    visibility: hidden;
}

#preloader p {
    color: white;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-align: center;
}

.loader-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 40px;
}

.loader-tube {
    width: 40px;
    height: 120px;
    border: 3px solid rgba(148, 163, 184, 0.4);
    border-radius: 3px 3px 15px 15px;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    backdrop-filter: blur(10px);
}

.loader-water {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(to top, #667eea, #764ba2);
    border-radius: 0 0 12px 12px;
    animation: waterFill 1.5s ease-in-out infinite;
}

.loader-tube:nth-child(1) .loader-water {
    animation-delay: 0s;
}

.loader-tube:nth-child(2) .loader-water {
    animation-delay: 0.3s;
}

.loader-tube:nth-child(3) .loader-water {
    animation-delay: 0.6s;
}

@keyframes waterFill {
    0% {
        height: 0%;
        opacity: 0.7;
    }

    50% {
        height: 100%;
        opacity: 1;
    }

    100% {
        height: 0%;
        opacity: 0.7;
    }
}