/* ========================================= */
/* ОСНОВНОЙ КОНТЕЙНЕР И ФОН (ГЛИТЧ-ЭФФЕКТ) */
/* ========================================= */

.level-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;

    /* Базовый темный фон */
    background-color: #000;
    
    /* Сложный градиент + текстура */
    background-image: 
        repeating-linear-gradient(
            0deg,
            transparent, 
            transparent 2px, 
            #111 2px, 
            #111 4px
        ),
        radial-gradient(circle at center, #2a1f1f 0%, #000 90%),
        linear-gradient(45deg, #8B0000 25%, transparent 25%),
        linear-gradient(-45deg, #09640e 25%, transparent 25%);
        
    background-size: 
        100% 100%, 
        100% 100%, 
        60px 60px, 
        60px 60px;

    height: 100vh;
    width: 100vw;
    overflow-y: auto;
    padding: 2rem 1rem;

    font-family: 'Gochi Hand', cursive;
    position: relative;
    z-index: 0;
    
    /* Анимация "живого" фона */
    animation: bgGlitchMove 12s linear infinite alternate;
}

.level-container,
.level-title,
.level-subtitle,
.level-number,
.level-name,
.level-description,
.level-reward,
.start-game-btn,
.card-face {
    font-family: 'PixeloidMono', monospace;
}

/* Эффект "Сканлайны" (Полоски экрана) */
.level-container::before {
    content: "";
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.1) 0px,
        rgba(0, 0, 0, 0.1) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 998; /* сканлайны level-container::before */
    background-size: 100% 4px;
    animation: scanlineScroll 8s linear infinite;
}

/* Эффект "Цветные помехи" (RGB Split вспышки) */
.level-container::after {
    content: "";
    position: fixed;
    inset: 0;
    background: linear-gradient(
        90deg,
        rgba(255, 0, 0, 0.05),
        rgba(0, 255, 0, 0.02),
        rgba(0, 0, 255, 0.05)
    );
    pointer-events: none;
    z-index: 999; /* цветные помехи level-container::after */
    opacity: 0;
    animation: screenFlash 5s infinite;
    mix-blend-mode: screen;
}

/* АНИМАЦИИ ФОНА */
@keyframes bgGlitchMove {
    0% {
        background-position: 0 0, 0 0, 0 0, 0 0;
        filter: hue-rotate(0deg) contrast(100%);
    }
    50% {
        filter: hue-rotate(10deg) contrast(110%);
    }
    100% {
        background-position: 0 50px, 0 0, 20px 20px, -20px -20px;
        filter: hue-rotate(-10deg) contrast(100%);
    }
}

@keyframes scanlineScroll {
    0% { background-position: 0 0; }
    100% { background-position: 0 100%; }
}

@keyframes screenFlash {
    0%, 92%, 100% { opacity: 0; transform: scale(1); }
    93% { 
        opacity: 0.4; 
        transform: scale(1.02) translateX(-3px);
        background: linear-gradient(90deg, rgba(255,0,0,0.2), transparent);
    }
    94% { opacity: 0.1; transform: translateX(3px); }
    96% { 
        opacity: 0.5; 
        transform: scale(1.01) translateY(3px); 
        background: linear-gradient(90deg, transparent, rgba(0,255,255,0.2));
    }
}

/* ========================================= */
/* ЗАГОЛОВКИ */
/* ========================================= */

.level-title {
    font-size: 3rem;
    color: #f5e6c8;
    text-shadow: 3px 3px #000;
    margin-bottom: 0.5rem;
    text-align: center;
    position: relative;
    z-index: 2;
    animation: titleGlitchPulse 4s infinite;
}

.level-title::before,
.level-title::after {
    content: attr(data-text);
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

.level-title::before {
    color: #ff0066;
    z-index: -1;
    animation: titleGlitchRed 2s infinite steps(4);
}

.level-title::after {
    color: #00ffff;
    z-index: -2;
    animation: titleGlitchCyan 2.5s infinite steps(4);
}

@keyframes titleGlitchPulse {
    0%, 94%, 100% { transform: translate(0, 0); filter: none; }
    95% { transform: translate(-3px, 2px); filter: hue-rotate(90deg); }
    97% { transform: translate(3px, -2px); filter: hue-rotate(-90deg); }
}

@keyframes titleGlitchRed {
    0%, 90%, 100% { clip-path: inset(0); transform: translate(0, 0); }
    92% { clip-path: inset(20% 0 60% 0); transform: translate(-3px, 2px); }
    96% { clip-path: inset(60% 0 20% 0); transform: translate(2px, -2px); }
}

@keyframes titleGlitchCyan {
    0%, 88%, 100% { clip-path: inset(0); transform: translate(0, 0); }
    90% { clip-path: inset(40% 0 40% 0); transform: translate(3px, -2px); }
    94% { clip-path: inset(10% 0 70% 0); transform: translate(-2px, 2px); }
}

.level-subtitle {
    font-size: 1.3rem;
    color: #ffd700;
    margin-bottom: 2rem;
    text-align: center;
    position: relative;
    z-index: 2;
    animation: subtitleFlicker 3s infinite steps(6);
    text-shadow: 2px 2px 0 #000, 0 0 10px rgba(255, 215, 0, 0.5);
}

@keyframes subtitleFlicker {
    0%, 92%, 100% { opacity: 1; }
    94%, 96% { opacity: 0.7; text-shadow: 2px 2px 0 #000, 0 0 20px rgba(255, 215, 0, 1), 0 0 30px rgba(255, 0, 0, 0.5); }
}

/* ========================================= */
/* СЕТКА И КАРТОЧКИ (ИСПРАВЛЕННАЯ ЛОГИКА) */
/* ========================================= */

.level-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    max-width: 380px;
    position: relative;
    z-index: 2;
    padding-bottom: 4rem;
}

/* Обертка карточки с высотой */
.level-card-wrapper {
    --tilt-angle: 0deg;
    width: 100%;
    /* ВАЖНО: Фиксированная минимальная высота, чтобы карточка не схлопывалась */
    min-height: 480px; 
    
    position: relative;
    z-index: 1;
    perspective: 1000px; /* 3D перспектива */

    transform: rotate(var(--tilt-angle));
    opacity: 0;
    animation: fadeIn 0.5s ease forwards, moveIn 0.5s ease, cardIdle 3s ease-in-out infinite;
    transition: transform 0.2s ease, z-index 0.2s;
}

.level-card-wrapper:nth-child(2n) { --tilt-angle: -2deg; }
.level-card-wrapper:nth-child(3n) { --tilt-angle: 2deg; }
.level-card-wrapper:nth-child(4n) { --tilt-angle: -1deg; }

/* Чекбокс скрыт */
.flip-toggle { display: none; }

/* Основной контейнер-кнопка */
.flip-card {
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
    transform-style: preserve-3d;
}

/* Вращающаяся часть */
.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-style: preserve-3d;
}

/* Переворот при клике (чекбоксе) */
.flip-toggle:checked + .flip-card .flip-card-inner {
    transform: rotateY(180deg);
}

/* Стили сторон карточки */
.card-face {
    position: absolute; /* Накладываем друг на друга */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    
    -webkit-backface-visibility: hidden; /* Скрываем изнанку */
    backface-visibility: hidden;
    
    background: #f5e6c8;
    border: 3px solid #000;
    border-radius: 12px;
    box-shadow: 4px 4px 0px #000;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Лицевая сторона */
.flip-card-front {
    z-index: 2;
    transform: rotateY(0deg);
}

/* Обратная сторона */
.flip-card-back {
    transform: rotateY(180deg);
    z-index: 1;
    background: #f5e6c8; /* Фон, чтобы не было дыр */
}

/* Текстура на карточках */
.card-face::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: repeating-linear-gradient(0deg, rgba(0,0,0,0.03) 0px, rgba(0,0,0,0.03) 2px, transparent 2px, transparent 4px);
    pointer-events: none;
    z-index: 0;
}
.reward-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100000; /* pixel particles, fireworks */
    animation: rewardFadeIn 0.5s ease-out;
}

.reward-overlay.closing {
    animation: rewardFadeOut 0.5s ease-in forwards;
}

@keyframes rewardFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes rewardFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

.reward-container {
    position: relative;
    text-align: center;
    padding: 40px 60px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 20px;
    border: 3px solid #ffd700;
    box-shadow: 0 0 50px #ffd70066, inset 0 0 30px rgba(255, 215, 0, 0.1);
    animation: rewardBounce 0.6s ease-out;
}

@keyframes rewardBounce {
    0% { transform: scale(0.3) translateY(50px); opacity: 0; }
    50% { transform: scale(1.1) translateY(-10px); }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

.reward-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, #ffd70044 0%, transparent 70%);
    transform: translate(-50%, -50%);
    animation: rewardGlow 2s ease-in-out infinite;
}

@keyframes rewardGlow {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.5; }
    50% { transform: translate(-50%, -50%) scale(1.5); opacity: 1; }
}

.reward-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: rewardIconPulse 1s ease-in-out infinite;
    filter: drop-shadow(0 0 20px #ffd700);
}

@keyframes rewardIconPulse {
    0%, 100% { transform: scale(1) rotate(-5deg); }
    50% { transform: scale(1.1) rotate(5deg); }
}

.reward-title {
    font-family: "Press Start 2P", monospace, Arial;
    font-size: 18px;
    color: #ffd700;
    text-shadow: 2px 2px 0 #000;
    margin-bottom: 10px;
    animation: rewardTextGlow 1.5s ease-in-out infinite;
}

@keyframes rewardTextGlow {
    0%, 100% { text-shadow: 2px 2px 0 #000, 0 0 10px #ffd700; }
    50% { text-shadow: 2px 2px 0 #000, 0 0 30px #ffd700, 0 0 50px #ffd700; }
}

.reward-name {
    font-family: "Press Start 2P", monospace, Arial;
    font-size: 14px;
    color: #ffffff;
    text-shadow: 1px 1px 0 #000;
    margin-bottom: 30px;
}

.reward-claim-btn {
    font-family: "Press Start 2P", monospace, Arial;
    font-size: 14px;
    padding: 15px 40px;
    background: linear-gradient(135deg, #ffd700 0%, #ffaa00 100%);
    color: #000;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 5px 0 #cc8800, 0 10px 20px rgba(0, 0, 0, 0.5);
}

.reward-claim-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 0 #cc8800, 0 15px 25px rgba(0, 0, 0, 0.5);
}

.reward-claim-btn:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #cc8800, 0 5px 10px rgba(0, 0, 0, 0.5);
}

.reward-particles {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
}

.reward-particle {
    position: absolute;
    font-size: 20px;
    animation: particleFloat 3s ease-out infinite;
    animation-delay: var(--delay);
    opacity: 0;
}

@keyframes particleFloat {
    0% {
        transform: translate(0, 0) scale(0);
        opacity: 0;
    }
    10% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        transform: translate(var(--x), var(--y)) scale(0.3) rotate(360deg);
        opacity: 0;
    }
}
/* Глитч-полоса на карточке */
.card-face::after {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 0, 255, 0.1) 25%, rgba(0, 255, 255, 0.1) 50%, rgba(255, 255, 0, 0.1) 75%, transparent 100%);
    animation: cardSweep 8s infinite;
    pointer-events: none;
    z-index: 1;
}

@keyframes cardSweep {
    0%, 90%, 100% { left: -100%; }
    92%, 98% { left: 100%; }
}

@keyframes cardIdle {
    0%, 100% { transform: rotate(var(--tilt-angle)) translateY(0) scale(1); }
    50% { transform: rotate(var(--tilt-angle)) translateY(-3px) scale(1.005); }
}

/* Hover эффекты */
.level-card-wrapper:hover {
    transform: scale(1.03) rotate(var(--tilt-angle));
    z-index: 10;
}

.level-card-wrapper:hover .card-face {
    box-shadow: 8px 8px 0px #222, 0 0 30px rgba(255, 215, 0, 0.6);
    animation: cardHoverGlitch 0.3s infinite steps(4);
}

@keyframes cardHoverGlitch {
    0%, 80%, 100% { filter: none; }
    85% { filter: drop-shadow(-2px 0 0 rgba(255, 0, 0, 0.5)) drop-shadow(2px 0 0 rgba(0, 255, 255, 0.5)); }
    90% { filter: drop-shadow(2px 0 0 rgba(255, 0, 255, 0.5)) drop-shadow(-2px 0 0 rgba(0, 255, 0, 0.5)); }
}

/* Задержка появления карточек */
.level-card-wrapper:nth-child(1) { animation-delay: 0.1s, 0.1s, 0s; }
.level-card-wrapper:nth-child(2) { animation-delay: 0.3s, 0.3s, 0.2s; }
.level-card-wrapper:nth-child(3) { animation-delay: 0.5s, 0.5s, 0.4s; }
.level-card-wrapper:nth-child(4) { animation-delay: 0.7s, 0.7s, 0.6s; }

/* ========================================= */
/* КОНТЕНТ КАРТОЧЕК И КНОПКИ */
/* ========================================= */

.level-number {
    font-size: 2rem;
    font-weight: bold;
    color: #ff5555;
    margin-bottom: 0.5rem;
    animation: numberFlicker 4s infinite steps(8);
    text-shadow: 2px 2px 0 #000, 0 0 10px rgba(255, 85, 85, 0.5);
    z-index: 2;
}

@keyframes numberFlicker {
    0%, 94%, 100% { opacity: 1; text-shadow: 2px 2px 0 #000, 0 0 10px rgba(255, 85, 85, 0.5); }
    95%, 97% { opacity: 0.8; text-shadow: 2px 2px 0 #000, 0 0 20px rgba(255, 85, 85, 1), 0 0 30px rgba(255, 0, 0, 0.5); }
}

.level-name {
    font-size: 1.3rem;
    font-weight: bold;
    color: #000;
    margin-bottom: 0.5rem;
    position: relative;
    z-index: 2;
}

.level-description {
    font-size: 1rem;
    color: #333;
    margin-bottom: 0.5rem;
    z-index: 2;
}

.flip-card-back .level-description {
    text-align: left;
    width: 100%;
}

.flip-card-back .level-description p {
    margin: 0.5rem 0;
    animation: textGlitch 5s infinite;
}

@keyframes textGlitch {
    0%, 96%, 100% { transform: translate(0, 0); opacity: 1; }
    97% { transform: translate(-1px, 0); opacity: 0.9; }
    98% { transform: translate(1px, 0); opacity: 0.95; }
}

/* Звезды */
.level-difficulty { margin: 0.5rem 0; z-index: 2; }
.difficulty-star {
    color: #ffd700;
    font-size: 1.2rem;
    display: inline-block;
    animation: starTwinkle 1.5s ease-in-out infinite;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.8);
}
.difficulty-star:nth-child(1) { animation-delay: 0s; }
.difficulty-star:nth-child(2) { animation-delay: 0.2s; }
.difficulty-star:nth-child(3) { animation-delay: 0.4s; }
.difficulty-star:nth-child(4) { animation-delay: 0.6s; }
.difficulty-star:nth-child(5) { animation-delay: 0.8s; }

@keyframes starTwinkle {
    0%, 100% { transform: scale(1) rotate(0deg); opacity: 1; }
    50% { transform: scale(1.2) rotate(180deg); opacity: 0.8; text-shadow: 0 0 10px rgba(255, 215, 0, 1); }
}

/* Награда */
.level-reward {
    margin-top: 0.5rem;
    background: #ffd700;
    border: 2px solid #000;
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    font-weight: bold;
    color: #000;
    position: relative;
    overflow: hidden;
    animation: rewardShine 3s ease-in-out infinite;
    z-index: 2;
}

.level-reward::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.5) 50%, transparent 70%);
    animation: rewardGlow 4s infinite;
}

@keyframes rewardShine {
    0%, 100% { box-shadow: 0 0 5px rgba(255, 215, 0, 0.5), inset 0 0 5px rgba(255, 255, 255, 0.3); }
    50% { box-shadow: 0 0 15px rgba(255, 215, 0, 1), inset 0 0 10px rgba(255, 255, 255, 0.5); }
}

@keyframes rewardGlow {
    0% { transform: translate(-50%, -50%) rotate(0deg); opacity: 0; }
    50% { opacity: 1; }
    100% { transform: translate(50%, 50%) rotate(360deg); opacity: 0; }
}

/* Кнопка Старт */
.start-game-btn {
    background: #4CAF50;
    color: white;
    border: 2px solid #000;
    border-radius: 8px;
    padding: 0.8rem 1.5rem;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    margin-top: 1rem;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    animation: btnPulse 2s ease-in-out infinite;
    z-index: 5;
}

.start-game-btn::before {
    content: "";
    position: absolute;
    top: -100%;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: btnScanline 2s infinite;
}

@keyframes btnPulse {
    0%, 100% { box-shadow: 0 0 10px rgba(76, 175, 80, 0.5), inset 0 0 10px rgba(255, 255, 255, 0.1); }
    50% { box-shadow: 0 0 25px rgba(76, 175, 80, 1), inset 0 0 20px rgba(255, 255, 255, 0.3); }
}

@keyframes btnScanline { 0% { top: -100%; } 100% { top: 100%; } }

.start-game-btn:hover {
    background: #45a049;
    transform: scale(1.05);
    animation: btnHoverGlitch 0.2s infinite steps(4), btnHoverShake 0.1s infinite;
    box-shadow: 0 0 30px rgba(76, 175, 80, 1);
}

@keyframes btnHoverGlitch {
    0%, 80%, 100% { filter: hue-rotate(0deg); }
    85% { filter: hue-rotate(30deg); }
    90% { filter: hue-rotate(-30deg); }
}

@keyframes btnHoverShake {
    0% { transform: scale(1.05) translate(0, 0); }
    50% { transform: scale(1.05) translate(-1px, 1px); }
    100% { transform: scale(1.05) translate(1px, -1px); }
}

/* ========================================= */
/* БОСС УРОВЕНЬ (BOSS LEVEL) */
/* ========================================= */

.card-face.boss-level {
    background: #af0d0d;
    border: 4px solid #800000;
    color: #fff;
    box-shadow: 0 0 15px #d45a5a, 0 0 30px #660000, 0 0 45px #ff0000;
    animation: bossGlow 2s ease-in-out infinite;
}

/* Фон сзади у босса тоже красный */
.card-face.boss-level.flip-card-back {
    background: #af0d0d;
}

@keyframes bossGlow {
    0%, 100% { box-shadow: 0 0 15px #d45a5a, 0 0 30px #660000; border-color: #800000; }
    50% { box-shadow: 0 0 25px #ff0000, 0 0 50px #d45a5a, inset 0 0 30px rgba(255, 0, 0, 0.3); border-color: #ff0000; }
}

/* Линии на фоне босса */
.card-face.boss-level::before {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(90deg, transparent 0px, rgba(255, 0, 0, 0.1) 10px, transparent 20px);
    animation: bossLines 1s infinite linear;
    pointer-events: none;
    z-index: 0;
}

@keyframes bossLines { 0% { transform: translateX(0); } 100% { transform: translateX(20px); } }

/* Искры босса */
.card-face.boss-level::after {
    content: "";
    position: absolute;
    inset: -5px;
    border: 2px solid transparent;
    animation: bossSparks 3s infinite steps(12);
    pointer-events: none;
    z-index: 1;
}

@keyframes bossSparks {
    0%, 90%, 100% { border-color: transparent; box-shadow: none; }
    92%, 94%, 96%, 98% { border-color: #ff0000; box-shadow: inset 0 0 20px rgba(255, 0, 0, 0.5), 0 0 20px rgba(255, 0, 0, 0.5); }
}

.card-face.boss-level .level-number {
    color: #fff;
    animation: bossNumberGlitch 2s infinite steps(6);
    text-shadow: 3px 3px 0 #000, 0 0 20px #ff0000;
}

@keyframes bossNumberGlitch {
    0%, 88%, 100% { transform: translate(0, 0) scale(1); filter: hue-rotate(0deg); }
    90% { transform: translate(-3px, 2px) scale(1.05); filter: hue-rotate(30deg); }
    92% { transform: translate(3px, -2px) scale(0.95); filter: hue-rotate(-30deg); }
}

.card-face.boss-level .level-name {
    color: #fff;
    text-shadow: 2px 2px #000, 0 0 15px #ff0000;
    animation: bossNamePulse 3s ease-in-out infinite;
}

@keyframes bossNamePulse {
    0%, 100% { transform: scale(1); letter-spacing: normal; }
    50% { transform: scale(1.05); letter-spacing: 2px; }
}

.card-face.boss-level .level-description {
    font-weight: bold;
    color: #ffe6e6;
    animation: bossDescFlicker 5s infinite steps(10);
}

@keyframes bossDescFlicker {
    0%, 94%, 100% { opacity: 1; }
    95%, 97%, 99% { opacity: 0.7; color: #ffffff; }
}

/* Анимации появления */
@keyframes fadeIn { to { opacity: 1; } }
@keyframes moveIn {
    from { transform: translateY(50px) rotate(-5deg); filter: blur(4px); }
    to { filter: blur(0); }
}
