/* ==========================================
   MEF_MAJOR — Main Stylesheet (UI Polished + Dynamic BG + Global Event Themes + Low-End Mode)
   ========================================== */

/* === 1. ПЕРЕМЕННЫЕ (Настройка прозрачности и цветов) === */
:root {
    --glass-bg: rgba(255, 255, 255, 0.55); 
    --glass-border: rgba(255, 255, 255, 0.4);
    --glass-shadow: rgba(0, 0, 0, 0.05); 
    --text-main: #1e293b;
    --text-muted: #475569;
    --accent: #0ea5e9;
    --bg-overlay: rgba(255, 255, 255, 0.1);
    --font-main: 'Inter';
    --blur-amount: 18px; 
}

html.dark {
    --glass-bg: rgba(15, 23, 42, 0.55); 
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: rgba(0, 0, 0, 0.3);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --bg-overlay: rgba(15, 23, 42, 0.5);
}

/* ==========================================
   ГЛОБАЛЬНЫЕ ТЕМЫ ДЛЯ ИВЕНТОВ
   ========================================== */
html[data-event-theme="newyear"] { --accent: #38bdf8 !important; --glass-bg: rgba(14, 165, 233, 0.15) !important; --glass-border: rgba(14, 165, 233, 0.4) !important; }
html.dark[data-event-theme="newyear"] { --glass-bg: rgba(2, 132, 199, 0.2) !important; }
html[data-event-theme="halloween"] { --accent: #f97316 !important; --glass-bg: rgba(249, 115, 22, 0.1) !important; --glass-border: rgba(249, 115, 22, 0.3) !important; }
html.dark[data-event-theme="halloween"] { --glass-bg: rgba(194, 65, 12, 0.2) !important; }
html[data-event-theme="valentine"] { --accent: #ec4899 !important; --glass-bg: rgba(236, 72, 153, 0.15) !important; --glass-border: rgba(236, 72, 153, 0.3) !important; }
html.dark[data-event-theme="valentine"] { --glass-bg: rgba(190, 24, 93, 0.2) !important; }
html[data-event-theme="summer"] { --accent: #eab308 !important; --glass-bg: rgba(250, 204, 21, 0.15) !important; --glass-border: rgba(250, 204, 21, 0.4) !important; }
html.dark[data-event-theme="summer"] { --glass-bg: rgba(161, 98, 7, 0.2) !important; }
html[data-event-theme="winter"] { --accent: #2dd4bf !important; --glass-bg: rgba(45, 212, 191, 0.1) !important; --glass-border: rgba(45, 212, 191, 0.3) !important; }
html.dark[data-event-theme="winter"] { --glass-bg: rgba(15, 118, 110, 0.2) !important; }
html[data-event-theme="custom1"] { --accent: #a855f7 !important; --glass-bg: rgba(168, 85, 247, 0.15) !important; }
html.dark[data-event-theme="custom1"] { --glass-bg: rgba(126, 34, 206, 0.2) !important; }
html[data-event-theme="custom2"] { --accent: #ef4444 !important; --glass-bg: rgba(239, 68, 68, 0.15) !important; }
html.dark[data-event-theme="custom2"] { --glass-bg: rgba(185, 28, 28, 0.2) !important; }

/* === LOW-END MODE ОПТИМИЗАЦИИ === */
body.low-end * { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
body.low-end .frosted-glass, body.low-end .tour-tooltip-box {
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
    background-color: rgba(255, 255, 255, 0.98) !important;
}
html.dark body.low-end .frosted-glass, html.dark body.low-end .tour-tooltip-box { background-color: rgba(15, 23, 42, 0.98) !important; }
body.low-end .tilt-card { transform: none !important; }
body.low-end .animate-float { animation: none !important; transform: translateY(0) !important; }
body.low-end #dynamic-bg, body.low-end #particle-container { display: none !important; }

/* === 2. БАЗОВЫЕ СТИЛИ & UI POLISH === */
body {
    background-color: transparent !important;
    background-image: none !important;
    color: var(--text-main);
    overflow: hidden; height: 100vh; margin: 0; display: flex; flex-direction: column;
    font-family: var(--font-main), sans-serif; transition: color 0.3s;
    text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}

.bg-container { position: fixed; inset: 0; z-index: -2; overflow: hidden; }

/* АНТИ-ЛАГ: Блюр картинки работает намного быстрее, чем тяжелый backdrop-filter */
.bg-image {
    position: absolute; inset: -5%; width: 110%; height: 110%; object-fit: cover;
    transition: opacity 1.5s ease; opacity: 0;
    filter: blur(8px) brightness(0.9);
}
.bg-image.active { opacity: 1; transform: scale(1.05); }
html.dark .bg-image { filter: blur(8px) brightness(0.6) contrast(1.1); }

.bg-overlay { 
    position: absolute; inset: 0; background: var(--bg-overlay); 
    transition: background 0.5s; z-index: 1;
}

/* --- DYNAMIC BACKGROUND (Day/Night cycle) --- */
.dynamic-bg-container { position: fixed; inset: 0; z-index: -3; transition: background 2s ease, opacity 1s ease; transform: translateZ(0); }
.bg-morning { background: linear-gradient(to top, #ffb347, #ffcc33); }
.bg-day { background: linear-gradient(to top, #56ccf2, #2f80ed); }
.bg-evening { background: linear-gradient(to top, #ff512f, #dd2476); }
.bg-night { background: linear-gradient(to top, #0f2027, #203a43, #2c5364); }

.celestial-body { position: absolute; border-radius: 50%; transition: all 2s ease; filter: blur(8px); will-change: transform; }
.sun { width: 150px; height: 150px; background: #fff5b8; box-shadow: 0 0 100px #ffcc33, 0 0 200px #ffb347; top: 10%; right: 20%; }
.moon { width: 100px; height: 100px; background: #e2e8f0; box-shadow: 0 0 50px #cbd5e1; top: 15%; right: 25%; }

/* --- ANIMATED PARTICLES --- */
#particle-container { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: -1; overflow: hidden; transform: translateZ(0); }

@keyframes fall {
    0% { transform: translateY(-10vh) rotate(0deg); opacity: 0; }
    10% { opacity: 0.8; }
    90% { opacity: 0.5; }
    100% { transform: translateY(110vh) rotate(360deg); opacity: 0; }
}
.animate-fall { animation: fall linear infinite; will-change: transform, opacity; }

/* === 3. ЭФФЕКТ СТЕКЛА === */
.frosted-glass {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur-amount)) saturate(150%);
    -webkit-backdrop-filter: blur(var(--blur-amount)) saturate(150%);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 20px var(--glass-shadow);
    color: var(--text-main);
    transition: background 0.4s, border 0.4s, box-shadow 0.4s;
    transform: translateZ(0);
}

.nav-btn {
    position: relative; color: var(--text-muted); transition: color 0.3s, background-color 0.3s;
    cursor: pointer; padding: 8px 16px; font-size: 0.9rem; font-weight: 600; border-radius: 20px;
    background: transparent; border: none; outline: none;
}
.nav-btn:hover { color: var(--text-main); background: rgba(125, 125, 125, 0.1); }
.nav-btn.active { color: var(--accent); background: var(--glass-bg); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); }

/* === 4. КОНТЕНТ И СЕКЦИИ === */
main { flex: 1; position: relative; overflow: hidden; z-index: 10; display: flex; flex-direction: column; }

.section-view {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0; visibility: hidden; transform: scale(0.98);
    transition: opacity 0.4s, transform 0.4s, visibility 0.4s;
    padding: 1rem; padding-top: 100px; padding-bottom: 60px; /* Увеличили нижний паддинг для мобилки */
    display: flex; flex-direction: column; overflow-y: auto;
    pointer-events: none; /* Защита от перекрытия кнопок на других слоях */
    z-index: 5;
}
@media (min-width: 768px) { .section-view { padding: 2rem; padding-top: 120px; } }

.section-view.active { 
    opacity: 1; visibility: visible; transform: scale(1); 
    pointer-events: auto; /* Включаем клики только для активного слоя */
    z-index: 10;
}

/* Скроллбары */
.custom-scroll::-webkit-scrollbar, .section-view::-webkit-scrollbar { width: 6px; }
.custom-scroll::-webkit-scrollbar-track, .section-view::-webkit-scrollbar-track { background: transparent; }
.custom-scroll::-webkit-scrollbar-thumb, .section-view::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }

/* === 5. АНИМАЦИИ И ЭФФЕКТЫ ПРИ НАВЕДЕНИИ === */
@keyframes slideUpFade { 0% { opacity: 0; transform: translateY(30px); } 100% { opacity: 1; transform: translateY(0); } }
.animate-stagger { opacity: 0; animation: slideUpFade 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

@keyframes spin-vinyl { 100% { transform: rotate(360deg); } }
.vinyl-spin { animation: spin-vinyl 4s linear infinite; animation-play-state: paused; }

.perspective-container { perspective: 1200px; }

/* Улучшенные 3D-карточки (Maximum Cool) */
.tilt-card { 
    transform-style: preserve-3d; 
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s ease, border-color 0.3s; 
    will-change: transform; 
}
.tilt-card:hover {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2), inset 0 0 20px rgba(255, 255, 255, 0.05);
    border-color: var(--accent) !important;
}
.tilt-content { transform: translateZ(30px); }

/* === 6. МОДАЛЬНЫЕ ОКНА === */
.modal-overlay {
    position: fixed; inset: 0; z-index: 10000; background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.3s; padding: 1rem;
}
html.dark .modal-overlay { background: rgba(0, 0, 0, 0.7); }
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-content { 
    width: 100%; max-width: 450px; transform: scale(0.9); 
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1); will-change: transform, opacity; 
}
.modal-overlay.open .modal-content { transform: scale(1); }

/* === 7. СЕТКИ (Bento Grid) === */
.bento-grid { display: grid; grid-template-columns: repeat(1, 1fr); gap: 1rem; }
@media (min-width: 768px) {
    .bento-grid { grid-template-columns: repeat(4, 1fr); grid-auto-rows: minmax(100px, auto); gap: 1.5rem; }
    .col-span-2 { grid-column: span 2; }
    .row-span-2 { grid-row: span 2; }
    .col-span-3 { grid-column: span 3; }
    .col-span-4 { grid-column: span 4; }
}

/* === 8. АДАПТАЦИЯ ПОД МОБИЛЬНЫЕ ТЕЛЕФОНЫ === */
@media (max-width: 768px) {
    header { display: none !important; } 
    
    .mobile-tab-bar {
        display: flex !important; position: fixed; bottom: 10px; left: 10px; right: 10px; height: 70px;
        background: var(--glass-bg); backdrop-filter: blur(15px) saturate(160%); -webkit-backdrop-filter: blur(15px) saturate(160%);
        border: 1px solid var(--glass-border); border-radius: 20px; z-index: 9999;
        box-shadow: 0 10px 30px -5px var(--glass-shadow); padding-bottom: env(safe-area-inset-bottom);
        scrollbar-width: none;
    }
    .mobile-tab-bar::-webkit-scrollbar { display: none; }

    .tab-btn { 
        display: flex; flex-direction: column; align-items: center; justify-content: center; 
        color: var(--text-muted); height: 100%; background: transparent; border: none; outline: none; width: 20%;
    }
    .tab-btn.active { color: var(--accent); transform: translateY(-3px); transition: all 0.3s; }
    .tab-btn i { font-size: 1.3rem; margin-bottom: 4px; }
    .tab-btn span { font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; }
    
    .tilt-card { padding: 1.25rem !important; flex-direction: column !important; text-align: center; transform: none !important; }
    h2, h3 { word-break: break-word; hyphens: auto; }
    .section-view { padding: 1rem !important; padding-top: 1.5rem !important; padding-bottom: 120px !important; }
    
    #tg-chat-window {
        width: 100% !important; height: 80vh !important; bottom: 0 !important; right: 0 !important;
        border-radius: 20px 20px 0 0 !important; margin-bottom: 0 !important;
    }
}

@media (max-width: 400px) {
    .text-9xl { font-size: 4rem; line-height: 1; }
    h1 { font-size: 3rem !important; }
}

html, body { overflow-x: hidden !important; width: 100%; max-width: 100vw; box-sizing: border-box; }
*, *:before, *:after { box-sizing: border-box; }