/* ============================================================
   1. КОСМИЧЕСКИЙ ФОН (ДОБАВЛЕН)
   ============================================================ */
#bg-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    background: linear-gradient(135deg, #0a0a2a, #1a1a3e, #2d1b4e);
    overflow: hidden;
}

#bg-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* ============================================================
   2. ОБЩИЕ СТИЛИ (ЧТОБЫ ВСЁ БЫЛО ПОВЕРХ ФОНА)
   ============================================================ */
body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: transparent !important; /* Убираем старый фон */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    overflow-x: hidden;
}

#game-container, 
.form-container, 
#scroll-text {
    position: relative;
    z-index: 1;
}

/* ============================================================
   3. ФОРМА ВХОДА
   ============================================================ */
.form-container {
    background: rgba(22, 33, 62, 0.85); /* Полупрозрачный, чтобы было видно фон */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 30px 25px;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.7);
    box-sizing: border-box;
    border: 1px solid rgba(255,255,255,0.1);
}

.form-container h2 {
    text-align: center;
    margin-bottom: 25px;
    font-size: 24px;
    color: #ffffff;
    text-shadow: 0 0 20px rgba(100, 100, 255, 0.3);
}

.form-container label {
    display: block;
    margin: 15px 0 5px;
    font-weight: bold;
    font-size: 14px;
    color: #ddd;
}

.form-container input,
.form-container select {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    background: rgba(15, 52, 96, 0.6);
    color: white;
    font-size: 16px;
    box-sizing: border-box;
    appearance: none;
    -webkit-appearance: none;
    transition: 0.3s;
}

.form-container input:focus,
.form-container select:focus {
    border-color: #e94560;
    outline: none;
    box-shadow: 0 0 20px rgba(233, 69, 96, 0.3);
}

.form-container button {
    width: 100%;
    padding: 14px;
    background: #e94560;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: bold;
    margin-top: 20px;
    cursor: pointer;
    transition: 0.3s;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.form-container button:hover {
    background: #c73e54;
    transform: scale(1.02);
    box-shadow: 0 0 30px rgba(233, 69, 96, 0.4);
}

/* ============================================================
   4. ИГРОВОЕ ПОЛЕ
   ============================================================ */
#game-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 10px;
}

#game-container h2 {
    text-align: center;
    font-size: 22px;
    color: #fff;
    text-shadow: 0 0 20px rgba(100, 100, 255, 0.3);
    margin-bottom: 10px;
}

#pairs-counter {
    text-align: center;
    font-size: 18px;
    color: #fff;
    margin: 10px 0 20px;
    background: rgba(0,0,0,0.3);
    padding: 8px;
    border-radius: 8px;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    max-width: 500px;
    margin: 0 auto;
}

/* ============================================================
   5. КАРТОЧКИ
   ============================================================ */
.card {
    aspect-ratio: 1 / 1;
    width: 100%;
    background: rgba(22, 33, 62, 0.8);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    cursor: pointer;
    transition: 0.3s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    user-select: none;
    box-sizing: border-box;
    padding: 6px;
    min-height: 80px;
    border: 1px solid rgba(255,255,255,0.05);
}

.card:hover {
    transform: scale(1.02);
    box-shadow: 0 0 30px rgba(100, 100, 255, 0.2);
}

.card img {
    width: 80%;
    height: 80%;
    object-fit: contain;
    border-radius: 8px;
    display: block;
    pointer-events: none;
}

.card.opened {
    background: rgba(15, 52, 96, 0.9);
    transform: scale(0.95);
    box-shadow: 0 0 30px rgba(233, 69, 96, 0.3);
}

.card.matched {
    background: rgba(39, 174, 96, 0.6);
    opacity: 0.7;
    cursor: default;
    transform: scale(0.9);
}

/* ============================================================
   6. БЕГУЩАЯ СТРОКА (ФИКСИРОВАННАЯ)
   ============================================================ */
#scroll-text {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100vw;
    max-width: 100%;
    background: linear-gradient(90deg, #f1c40f, #e74c3c, #f1c40f);
    color: white;
    font-size: 24px;
    font-weight: bold;
    padding: 15px 0;
    text-align: center;
    z-index: 9999;
    overflow: hidden;
    white-space: nowrap;
    box-sizing: border-box;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
}

#scroll-text span {
    display: inline-block;
    animation: scrollMarquee 8s linear infinite;
    padding-left: 100%;
}

@keyframes scrollMarquee {
    0% { transform: translateX(0%); }
    100% { transform: translateX(-200%); }
}

/* ============================================================
   7. ЭФЕКТЫ ПОБЕДЫ (КОНФЕТТИ, ШАРИКИ, ХЛОПУШКА)
   ============================================================ */
.confetti-piece {
    position: fixed;
    width: 12px;
    height: 12px;
    top: -20px;
    z-index: 9998;
    opacity: 0;
    animation: confettiFall linear forwards;
    pointer-events: none;
}

@keyframes confettiFall {
    0% {
        transform: translateY(0) rotate(0deg) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(110vh) rotate(720deg) scale(0.5);
        opacity: 0.5;
    }
}

.balloon {
    position: fixed;
    font-size: 40px;
    z-index: 9997;
    animation: floatBalloon ease-in-out forwards;
    pointer-events: none;
    filter: drop-shadow(0 8px 16px rgba(0,0,0,0.3));
}

@keyframes floatBalloon {
    0% {
        transform: translateY(100vh) rotate(0deg) scale(0.5);
        opacity: 0;
    }
    20% {
        opacity: 1;
    }
    100% {
        transform: translateY(-10vh) rotate(15deg) scale(1);
        opacity: 0;
    }
}

.burst-particle {
    position: fixed;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    z-index: 9999;
    animation: burstOut 1.2s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
    pointer-events: none;
}

@keyframes burstOut {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

.sparkle {
    position: fixed;
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
    z-index: 9999;
    pointer-events: none;
    animation: sparkleTwinkle 0.8s ease-out forwards;
}

@keyframes sparkleTwinkle {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(3);
        opacity: 0;
    }
}

/* ============================================================
   8. АДАПТИВ ДЛЯ МАЛЕНЬКИХ ЭКРАНОВ (ТЕЛЕФОНЫ)
   ============================================================ */
@media (max-width: 480px) {
    .game-grid {
        gap: 8px;
    }
    .card {
        font-size: 24px;
        min-height: 70px;
    }
    .form-container {
        padding: 20px 16px;
        margin: 10px;
    }
    #scroll-text {
        font-size: 18px;
        padding: 10px 0;
    }
}


/* Плавное размытие для космического фона */
#bg-container canvas {
    filter: blur(5.5px) brightness(0.8);
    opacity: 0.15;
    transition: opacity 0.5s ease;
}