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

/* Базовые стили */
html {
    height: -webkit-fill-available;
}

body {
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    overflow-x: hidden;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

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

/* Снег с оптимизацией производительности */
.snow {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image: radial-gradient(circle at 10% 20%, white 1px, transparent 1px);
    background-size: 50px 50px;
    animation: snowFall 10s linear infinite;
    opacity: 0.5;
    will-change: transform;
}

/* Отключаем снег на слабых устройствах */
@media (prefers-reduced-motion: reduce) {
    .snow {
        animation: none;
        opacity: 0.2;
    }
}

/* Для TV отключаем сложные анимации */
body[data-device="tv"] .snow,
body[data-device="console"] .snow {
    animation: none;
    opacity: 0.3;
}

@keyframes snowFall {
    0% { transform: translateY(-10%); }
    100% { transform: translateY(10%); }
}

/* Основной контейнер */
.container {
    text-align: center;
    padding: clamp(1rem, 5vw, 3rem);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: min(20px, 5vw);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-width: min(1200px, 90%);
    margin: env(safe-area-inset-top) auto env(safe-area-inset-bottom);
    width: -webkit-fill-available;
}

/* Заголовок */
.glowing-text {
    font-size: clamp(1.5rem, 6vw, 3.5rem);
    color: white;
    text-shadow: 0 0 10px #ffd700, 0 0 20px #ffd700, 0 0 30px #ff8c00;
    animation: glow 2s ease-in-out infinite alternate;
    margin-bottom: clamp(1rem, 4vh, 2rem);
    line-height: 1.2;
    word-break: break-word;
}

@keyframes glow {
    from { text-shadow: 0 0 10px #ffd700, 0 0 20px #ffd700; }
    to { text-shadow: 0 0 20px #ff8c00, 0 0 30px #ff8c00, 0 0 40px #ff4500; }
}

/* Таймер */
.countdown {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: clamp(0.5rem, 2vw, 2rem);
    margin: clamp(1rem, 4vh, 2rem) 0;
}

.time-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: clamp(70px, 20vw, 120px);
    padding: clamp(0.5rem, 2vh, 1rem);
    background: rgba(255, 255, 255, 0.15);
    border-radius: clamp(10px, 3vw, 15px);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: transform 0.3s ease;
}

/* Для TV добавляем фокус для навигации */
body[data-device="tv"] .time-block:focus,
body[data-device="tv"] .time-block:focus-within,
body[data-device="console"] .time-block:focus {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.35);
    outline: 3px solid #ffd700;
    outline-offset: 3px;
}

.time-block:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.25);
}

.number {
    font-size: clamp(2rem, 10vw, 4rem);
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
    line-height: 1;
}

.label {
    font-size: clamp(0.8rem, 3vw, 1.2rem);
    color: #f0f0f0;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 0.5rem;
}

/* Подарки */
.gifts {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: clamp(1rem, 4vw, 2rem);
    margin: clamp(1.5rem, 5vh, 3rem) 0;
}

.gift {
    font-size: clamp(2rem, 10vw, 4rem);
    animation: bounce 2s infinite;
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.5));
    transition: transform 0.3s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* Для TV */
body[data-device="tv"] .gift:focus,
body[data-device="console"] .gift:focus {
    outline: 3px solid #ffd700;
    outline-offset: 5px;
    transform: scale(1.2);
}

.gift:nth-child(1) { animation-delay: 0s; }
.gift:nth-child(2) { animation-delay: 0.2s; }
.gift:nth-child(3) { animation-delay: 0.4s; }
.gift:nth-child(4) { animation-delay: 0.6s; }
.gift:nth-child(5) { animation-delay: 0.8s; }

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

/* Отключаем анимацию на TV для производительности */
body[data-device="tv"] .gift,
body[data-device="console"] .gift {
    animation: none;
    transform: translateY(0);
}

/* Кнопка */
.magic-button {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    border: none;
    padding: clamp(12px, 3vh, 20px) clamp(20px, 5vw, 40px);
    font-size: clamp(1rem, 4vw, 1.5rem);
    color: white;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: bold;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
    margin: 1rem 0;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

/* Стили для разных подсказок на кнопке */
.magic-button .tv-hint,
.magic-button .gamepad-hint,
.magic-button .touch-hint {
    display: none;
    font-size: 0.8em;
    opacity: 0.8;
    margin-left: 5px;
}

body[data-device="tv"] .magic-button .tv-hint,
body[data-device="console"] .magic-button .gamepad-hint,
body[data-device="mobile"] .magic-button .touch-hint {
    display: inline-block;
}

/* Для TV кнопка больше */
body[data-device="tv"] .magic-button {
    padding: 20px 50px;
    font-size: 2rem;
}

.magic-button:hover {
    transform: scale(1.1);
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
    background: linear-gradient(45deg, #ff8c8c, #6ee7df);
}

.magic-button:active {
    transform: scale(0.95);
}

/* Для TV */
body[data-device="tv"] .magic-button:focus,
body[data-device="console"] .magic-button:focus {
    outline: 4px solid #ffd700;
    outline-offset: 4px;
    transform: scale(1.1);
}

/* Сообщение */
.surprise-message {
    font-size: clamp(1.2rem, 5vw, 2rem);
    color: white;
    margin-top: 1rem;
    min-height: 60px;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    transition: all 0.5s ease;
    padding: 0 1rem;
}

/* Подсказки для TV */
.tv-controls-hint {
    display: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1rem;
    margin-top: 2rem;
    padding: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

body[data-device="tv"] .tv-controls-hint,
body[data-device="console"] .tv-controls-hint {
    display: block;
}

/* Планшетная ориентация */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    .time-block {
        min-width: 100px;
    }
    
    .number {
        font-size: 3rem;
    }
}

@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .container {
        max-width: 90%;
    }
    
    .gifts {
        gap: 1.5rem;
    }
}

/* Android TV / Smart TV */
@media (min-width: 1920px) {
    .container {
        max-width: 70%;
    }
    
    .time-block {
        min-width: 200px;
    }
    
    .number {
        font-size: 5rem;
    }
    
    .label {
        font-size: 2rem;
    }
    
    .gift {
        font-size: 5rem;
    }
}

/* Landscape на мобильных */
@media (max-width: 768px) and (orientation: landscape) {
    .countdown {
        gap: 0.5rem;
    }
    
    .time-block {
        min-width: 60px;
        padding: 0.3rem;
    }
    
    .number {
        font-size: 1.8rem;
    }
    
    .gifts {
        gap: 0.8rem;
        margin: 1rem 0;
    }
    
    .gift {
        font-size: 2rem;
    }
}

/* Очень маленькие экраны */
@media (max-width: 320px) {
    .time-block {
        min-width: 50px;
    }
    
    .number {
        font-size: 1.5rem;
    }
    
    .label {
        font-size: 0.6rem;
    }
}

/* Поддержка safe areas для iPhone X и новее */
@supports (padding: max(0px)) {
    .container {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* Темная тема */
@media (prefers-color-scheme: dark) {
    .container {
        background: rgba(0, 0, 0, 0.3);
    }
}

/* Светлая тема */
@media (prefers-color-scheme: light) {
    .container {
        background: rgba(255, 255, 255, 0.2);
    }
}

/* Для слабовидящих - увеличенный контраст */
@media (prefers-contrast: high) {
    .glowing-text {
        text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
    }
    
    .time-block {
        border: 2px solid white;
    }
}

/* Отключение анимаций по запросу пользователя */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
