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

:root {
    --primary: #7c3aed;
    --secondary: #ec4899;
    --accent: #06b6d4;
    --success: #10b981;
    --danger: #ef4444;
    --dark-bg: #0f172a;
    --card-bg: #1e293b;
    --border: #334155;
    --text-light: #e2e8f0;
    --text-dim: #94a3b8;
    --gold: #fbbf24;
    --purple: #a78bfa;
    --green: #4ade80;
    --cyan: #22d3ee;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: var(--text-light);
}

/* Animated background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 20% 50%, rgba(124, 58, 237, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(236, 72, 153, 0.1) 0%, transparent 50%);
    animation: float 20s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(30px, -30px);
    }
}

.container {
    width: 100%;
    max-width: 1200px;
    padding: 20px;
    z-index: 1;
}

/* ============ PRELOADER ============ */
.preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 9999;
    animation: fadeOut 0.8s ease-in-out 2.5s forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        pointer-events: none;
    }
}

.preloader-content {
    text-align: center;
}


.preloader-content h1 {
    font-weight: 700;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-family: 'Bangers', cursive;
    font-size: 3.5rem;
    margin-bottom: 0.5rem;
    color: #fff;
    text-shadow: 2px 2px 0px #ff6b6b, 4px 4px 0px #4ecdc4, 12px 12px 20px rgba(0, 0, 0, 0.5);

}

.spinner {
    width: 80px;
    height: 80px;
    margin: 0 auto 30px;
    position: relative;
}

.spinner::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 4px solid rgba(124, 58, 237, 0.3);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.spinner::after {
    content: '';
    position: absolute;
    top: 10px;
    left: 10px;
    width: 60px;
    height: 60px;
    border: 4px solid transparent;
    border-top-color: #7c3aed;
    border-right-color: #ec4899;
    border-radius: 50%;
    animation: spin 1.5s linear infinite reverse;
}

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

.preloader h1 {
    font-size: 32px;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #7c3aed, #ec4899, #06b6d4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.preloader p {
    color: var(--text-dim);
    font-size: 14px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }
}

/* ============ MAIN GAME ============ */
.game-container {
    background: var(--card-bg);
    border-radius: 40px 80px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
    border: 1px solid var(--border);
    animation: slideIn 0.6s ease-out 2.5s both;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.title {
    font-weight: 700;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-family: 'Bangers', cursive;
    font-size: 3.5rem;
    margin-bottom: 0.5rem;
    color: #fff;
    text-shadow: 2px 2px 0px #ff6b6b, 4px 4px 0px #4ecdc4, 12px 12px 20px rgba(0, 0, 0, 0.5);
}

.level-info {
    text-align: right;
    margin-right: 20px;
}

.level-number {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 5px;
}

.level-display {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
}

/* ============ GAME BOARD ============ */
.board {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.tube-container {
    position: relative;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.tube-container:hover {
    transform: translateY(-10px);
}

.tube-container.dragging {
    opacity: 0.7;
}

.tube {
    width: 70px;
    height: 280px;
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.8), rgba(30, 41, 59, 0.6));
    border: 2px solid var(--border);
    border-radius: 20px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.3);
}

.tube::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 20px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.1), transparent);
    border-radius: 20px 20px 0 0;
    z-index: 10;
}

.tube-top {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 70px;
    height: 20px;
    background: linear-gradient(135deg, #475569, #64748b);
    border-radius: 50%;
    border: 2px solid var(--border);
    z-index: 11;
}

.balls {
    display: flex;
    flex-direction: column-reverse;
    height: 100%;
    padding: 10px;
    gap: 8px;
    position: relative;
    z-index: 5;
}

.ball {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: grab;
    position: relative;
    flex-shrink: 0;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3), inset -2px -2px 5px rgba(0, 0, 0, 0.2);
}

.ball:active {
    cursor: grabbing;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
}

.ball::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 15%;
    width: 30%;
    height: 30%;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.6), transparent);
    border-radius: 50%;
}

.ball.yellow {
    background: linear-gradient(135deg, #fcd34d, #f59e0b);
}

.ball.green {
    background: linear-gradient(135deg, #4ade80, #22c55e);
}

.ball.purple {
    background: linear-gradient(135deg, #c084fc, #a855f7);
}

.ball.cyan {
    background: linear-gradient(135deg, #22d3ee, #06b6d4);
}

.ball.pink {
    background: linear-gradient(135deg, #f472b6, #ec4899);
}

.ball.dragging {
    transform: scale(1.15);
    z-index: 1000;
    animation: pulse-glow 0.6s ease-in-out infinite;
    filter: drop-shadow(0 0 15px rgba(124, 58, 237, 0.8));
}

@keyframes pulse-glow {

    0%,
    100% {
        filter: drop-shadow(0 0 15px rgba(124, 58, 237, 0.8));
    }

    50% {
        filter: drop-shadow(0 0 25px rgba(236, 72, 153, 0.8));
    }
}

.particle {
    position: fixed;
    pointer-events: none;
    font-size: 20px;
    animation: float-up 1.2s ease-out forwards;
    z-index: 999;
}

@keyframes float-up {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(0.3);
    }
}

.ripple {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle, rgba(124, 58, 237, 0.4), transparent);
    animation: ripple-out 0.8s ease-out forwards;
}

@keyframes ripple-out {
    0% {
        width: 0;
        height: 0;
        opacity: 1;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    100% {
        width: 200px;
        height: 200px;
        opacity: 0;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
}

.flash {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    animation: flash-out 0.4s ease-out forwards;
}

@keyframes flash-out {
    0% {
        background: rgba(255, 255, 255, 0.5);
    }

    100% {
        background: rgba(255, 255, 255, 0);
    }
}

/* ============ TUTORIAL ============ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--card-bg);
    border-radius: 20px 80px;
    padding: 40px;
    max-width: 500px;
    border: 1px solid var(--border);
    animation: scaleIn 0.4s ease-out;
    text-align: center;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal h2 {
    font-size: 28px;
    margin-bottom: 20px;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal p {
    color: var(--text-dim);
    line-height: 1.8;
    margin-bottom: 20px;
    font-size: 16px;
}

.tutorial-steps {
    text-align: left;
    background: rgba(0, 0, 0, 0.3);
    padding: 20px;
    border-radius: 30px 40px;
    margin-bottom: 20px;
}

.tutorial-step {
    display: flex;
    gap: 12px;
    margin-bottom: 15px;
    align-items: flex-start;
}

.tutorial-step:last-child {
    margin-bottom: 0;
}

.step-number {
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
    font-size: 14px;
}

.step-text {
    color: var(--text-light);
    font-size: 14px;
    line-height: 1.6;
}

/* ============ CONTROLS ============ */
.controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 28px;
    border: none;
    border-radius: 30px 40px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;

    background: linear-gradient(135deg, #ffcc00, #ff9500);
    color: #000;
    border: none;


    font-weight: 900;
    border-radius: 50px;
    cursor: pointer;
    text-transform: uppercase;
    box-shadow: 0 10px 30px rgba(255, 204, 0, 0.4), 0 5px 0 #b8860b;
    transition: all 0.1s;
    letter-spacing: 2px;
}

.btn-primary {
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    color: white;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.4);
    box-shadow: 0 10px 30px rgba(124, 58, 237, 0.4), 0 5px 0 #7c3aed;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.6);
}

.btn-secondary {
    background: transparent;
    color: var(--text-light);
    border: 2px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--primary);
    background: rgba(124, 58, 237, 0.1);
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.6);
}

/* ============ STATS & FEEDBACK ============ */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.stat-box {
    background: rgba(124, 58, 237, 0.1);
    padding: 10px;
    border-radius: 30px 40px;
    border: 1px solid var(--border);
    text-align: center;
}

.stat-label {
    color: var(--text-dim);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
}

.feedback {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: 12px;
    max-width: 300px;
    animation: slideInRight 0.4s ease-out;
    display: none;
    z-index: 4000;
}

.feedback.show {
    display: block;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.feedback.success {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success);
}

.feedback.error {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
}

.feedback-title {
    font-weight: 700;
    margin-bottom: 5px;
    color: var(--text-light);
}

.feedback-text {
    color: var(--text-dim);
    font-size: 14px;
}

/* ============ WIN SCREEN ============ */
.win-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.3), rgba(6, 182, 212, 0.3));
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 6000;
    backdrop-filter: blur(15px);
    animation: fadeInBg 0.4s ease-out;
}

@keyframes fadeInBg {
    from {
        opacity: 0;
        backdrop-filter: blur(0);
    }

    to {
        opacity: 1;
        backdrop-filter: blur(15px);
    }
}

.win-screen.show {
    display: flex;
}

.win-content {
    text-align: center;
    background: linear-gradient(135deg, var(--card-bg), rgba(30, 41, 59, 0.9));
    padding: 80px 50px;
    border-radius: 30px 40px;
    border: 3px solid var(--accent);
    max-width: 600px;
    animation: bounceIn 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: 0 25px 80px rgba(6, 182, 212, 0.3);
    position: relative;
    overflow: hidden;
}

.win-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.1), rgba(16, 185, 129, 0.1));
    animation: shimmer 2s ease-in-out infinite;
    pointer-events: none;
}

@keyframes shimmer {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3) rotateX(-90deg);
    }

    50% {
        opacity: 1;
        transform: scale(1.05) rotateX(0deg);
    }

    100% {
        transform: scale(1);
    }
}

.confetti {
    position: fixed;
    pointer-events: none;
    animation: confetti-fall 3s ease-in forwards;
}

@keyframes confetti-fall {
    0% {
        opacity: 1;
        transform: translateY(0) rotateZ(0deg) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateY(1000px) rotateZ(720deg) scale(0);
    }
}

.win-content h2 {
    font-size: 36px;
    margin-bottom: 20px;
    background: linear-gradient(135deg, #10b981, #06b6d4, #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: scaleInText 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.2s both;
    text-shadow: 0 0 30px rgba(16, 185, 129, 0.2);
}

@keyframes scaleInText {
    from {
        opacity: 0;
        transform: scale(0.5);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.win-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin: 30px 0;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 30px 40px;
    position: relative;
    z-index: 1;
}

.win-stat {
    animation: slideUp 0.6s ease-out 0.3s both;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.win-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
}

.win-stat-label {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.win-content p {
    color: var(--text-light);
    font-size: 18px;
    margin-bottom: 30px;
    line-height: 1.8;
    position: relative;
    z-index: 1;
    animation: fadeInText 0.8s ease-out 0.4s both;
    white-space: pre-wrap;
}

@keyframes fadeInText {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.win-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    position: relative;
    z-index: 1;
    flex-wrap: wrap;
}

.btn-next {
    animation: slideUp 0.6s ease-out 0.5s both;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    .game-container {
        padding: 20px;
    }

    .tube {
        width: 80px;
        height: 240px;
    }

    .ball {
        width: 45px;
        height: 45px;
        margin-left: 7px;
    }

    .title {
        font-size: 22px;
    }

    .modal {
        max-width: 90%;
        padding: 30px 20px;
    }

    .feedback {
        bottom: 20px;
        right: 20px;
        max-width: calc(100% - 40px);
    }

    .win-content {
        padding: 40px 20px;
    }

    .win-content h2 {
        font-size: 26px;
    }

    .win-stats {
        grid-template-columns: 1fr;
    }
}