/* === ГЛОБАЛЬНЫЕ СТИЛИ И ФОН === */
body {
    /* ИСПОЛЬЗУЕМ ПЕРЕМЕННЫЕ ИЗ themes.css */
    background: linear-gradient(-45deg, var(--bg-grad-1), var(--bg-grad-2), var(--bg-grad-3), var(--bg-grad-4));
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    color: var(--text-main); /* Тоже переменная */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    position: relative;
    transition: color 0.5s, background 1s ease; /* Плавный переход тем */
}

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

/* === ЭФФЕКТ МОЛНИЙ (ОБНОВЛЕННЫЙ) === */
#thor-lightning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none; /* Пропускаем клики сквозь молнии */
    z-index: 1; /* Подняли выше (было 0), чтобы фон не перекрывал */
    background-color: rgba(255, 255, 255, 0.3); /* Чуть прозрачнее база */
    opacity: 0;
    mix-blend-mode: screen; /* "screen" делает белую вспышку ярче */
    
    /* ЗДЕСЬ МЕНЯЕМ СКОРОСТЬ: 5s = каждые 5 секунд */
    animation: lightningFlash 5s infinite; 
}

@keyframes lightningFlash {
    0% { opacity: 0; }
    92% { opacity: 0; }
    93% { opacity: 0.8; }   /* Первая резкая вспышка */
    94% { opacity: 0.2; }   /* Затухание */
    96% { opacity: 1; }     /* Вторая мощная вспышка (двойной удар) */
    100% { opacity: 0; }
}

/* Кастомный скроллбар (тонкий и темный) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.5); 
}
::-webkit-scrollbar-thumb {
    background: #475569; 
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color); 
}

/* === СТЕКЛЯННЫЕ ПАНЕЛИ (Glassmorphism) === */
.glass-panel {
    background: rgba(30, 41, 59, 0.7) !important; /* Полупрозрачный фон */
    backdrop-filter: blur(10px); /* Размытие фона позади */
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

/* === РУНЫ НА ХОЛСТЕ (ИСПРАВЛЕНО) === */
.rune-instance {
    position: absolute;
    top: 50%; 
    left: 50%;
    width: 100px; 
    height: 100px;
    cursor: grab;
    user-select: none;
    transform-origin: center center;
    /* Начальная позиция, дальше управляет JS. Анимацию отсюда УБРАЛИ. */
    transform: translate(-50%, -50%);
    z-index: 10; /* Выше молний */
}

/* Анимация перенесена на SVG внутри контейнера */
.rune-instance svg {
    width: 100%;
    height: 100%;
    overflow: visible;
    /* Анимация появления */
    animation: runeAppear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes runeAppear {
    from { 
        opacity: 0; 
        transform: scale(0.1) rotate(-45deg); 
    }
    to { 
        opacity: 1; 
        transform: scale(1) rotate(0deg); 
    }
}

.rune-instance:active {
    cursor: grabbing;
}

/* === МАГИЧЕСКОЕ СВЕЧЕНИЕ (Активная руна) === */
.rune-instance.active svg {
    filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.6)) drop-shadow(0 0 15px rgba(245, 158, 11, 0.3));
    transition: filter 0.3s ease;
    /* Убрали анимацию pulseGlow для SVG, чтобы не дергалась трансформация, оставили тень */
}
.rune-instance.active path {
    stroke: var(--accent-color) !important; /* Яркое золото */
    stroke-width: 8px; /* Чуть жирнее при выделении */
    transition: stroke 0.3s ease;
    /* Пульсация цвета линий */
    animation: pulseStroke 2s infinite ease-in-out;
}

@keyframes pulseStroke {
    0% { stroke: var(--accent-color); filter: drop-shadow(0 0 2px rgba(245, 158, 11, 0.5)); }
    50% { stroke: #fffbeb; filter: drop-shadow(0 0 8px rgba(245, 158, 11, 1)); } /* Белое золото в пике */
    100% { stroke: var(--accent-color); filter: drop-shadow(0 0 2px rgba(245, 158, 11, 0.5)); }
}

/* === СПИСОК СЛОЕВ === */
.layer-item {
    cursor: grab;
    transition: all 0.2s ease;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.layer-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Активный слой в списке */
.layer-item.active {
    background: linear-gradient(90deg, rgba(245, 158, 11, 0.1), transparent);
    border-left: 3px solid var(--accent-color);
}

.layer-item .layer-id {
    color: #94a3b8;
    transition: color 0.2s;
}
.layer-item.active .layer-id {
    color: var(--accent-color) !important;
    text-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
}
.layer-thumb {
    width: 24px;
    height: 24px;
    filter: invert(1) opacity(0.7);
    object-fit: contain;
    transition: transform 0.2s;
}
.layer-item:hover .layer-thumb {
    transform: scale(1.2) rotate(5deg);
    opacity: 1;
}

/* === КНОПКИ БИБЛИОТЕКИ === */
.lib-btn {
    background: rgba(30, 41, 59, 0.4);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.05);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.lib-btn:hover {
    background: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.lib-btn img {
    transition: transform 0.3s;
}
.lib-btn:hover img {
    transform: scale(1.1);
    filter: invert(1) drop-shadow(0 0 5px rgba(255,255,255,0.5));
}
.lib-btn.lib-btn-locked {
    opacity: 0.45;
    border-color: rgba(148, 163, 184, 0.25);
    cursor: not-allowed;
}
.lib-btn.lib-btn-locked:hover {
    background: rgba(30, 41, 59, 0.4);
    border-color: rgba(148, 163, 184, 0.25);
    transform: none;
    box-shadow: none;
}
.lib-btn.lib-btn-locked:hover img {
    transform: none;
    filter: invert(1) opacity(0.55);
}

/* === СТИЛИ ПЕЧАТИ (Оставляем чистыми) === */
/* === СТИЛИ ПЕЧАТИ (ИСПРАВЛЕНО) === */
@media print {
    @page { 
        margin: 1cm; 
        size: A4; 
    }
    
    /* Скрываем интерфейс */
    body > header, 
    body > main, 
    .no-print,
    #thor-lightning, /* Скрываем молнии */
    #rune-particles, /* Скрываем летающие частицы */
    .glass-panel { 
        display: none !important; 
    }
    
    body { 
        background: white !important; 
        color: black !important; 
        height: auto; 
        overflow: visible; 
        animation: none !important; 
    }

    /* Показываем область печати */
    #printArea { 
        display: block !important; 
    }

    /* === ГЛАВНОЕ ИСПРАВЛЕНИЕ === */
    /* Отключаем анимацию появления SVG, чтобы они не были прозрачными */
    .rune-instance svg {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important; /* Убираем начальный масштаб анимации */
        filter: none !important;
    }
    
    /* Делаем линии черными и убираем анимацию пульсации */
    .rune-instance path { 
        stroke: black !important; 
        stroke-width: 6px !important; /* Фиксированная толщина для бумаги */
        animation: none !important; 
        filter: none !important;
    }

    /* Убедимся, что контейнер руны стоит правильно */
    .rune-instance { 
        animation: none !important; 
        /* Оставляем позиционирование, которое задал JS, но убираем лишние эффекты */
        filter: none !important;
    }

    /* Миниатюры в списке состава */
    .print-rune-thumb { 
        display: inline-block; 
        width: 30px; 
        height: 30px; 
        margin-right: 5px; 
        vertical-align: middle; 
    }
}
/* === ПАРЯЩИЕ ФОНОВЫЕ РУНЫ (Particles) === */

/* Сам контейнер для частиц */
#rune-particles {
    z-index: 5; /* Выше молний (1), но ниже холста (10) */
    width: 100%;
    height: 100%;
}

/* Стиль отдельной частицы */
.bg-particle-rune {
    position: absolute;
    opacity: 0;
    filter: invert(1) drop-shadow(0 0 5px rgba(255, 255, 255, 0.5)); /* Белые светящиеся */
    animation-name: floatParticle;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}

/* Анимация жизни частицы */
@keyframes floatParticle {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.8) rotate(var(--r-start));
    }
    20% {
        opacity: 0.15; /* Максимальная яркость (не слишком ярко, чтобы не мешать) */
    }
    80% {
        opacity: 0.15;
    }
    100% {
        opacity: 0;
        transform: translateY(-100px) scale(1.2) rotate(var(--r-end));
    }
}

/* === Подсказки Методологии === */
.method-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
    color: #94a3b8;
}

.method-help-btn {
    width: 20px;
    height: 20px;
    border-radius: 999px;
    border: 1px solid rgba(251, 191, 36, 0.45);
    background: rgba(251, 191, 36, 0.12);
    color: #fde68a;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
}

.method-help-btn:hover {
    background: rgba(251, 191, 36, 0.25);
    border-color: rgba(251, 191, 36, 0.8);
    color: #fff7d1;
}

.method-help-backdrop {
    position: fixed;
    inset: 0;
    z-index: 12000;
    background: rgba(2, 6, 23, 0.84);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.method-help-backdrop.hidden {
    display: none;
}

.method-help-modal {
    width: min(720px, 92vw);
    max-height: 80vh;
    overflow: hidden;
    border-radius: 14px;
    border: 1px solid rgba(251, 191, 36, 0.3);
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(30, 41, 59, 0.98));
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
}

.method-help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(251, 191, 36, 0.2);
}

.method-help-title {
    margin: 0;
    color: #fbbf24;
    font-size: 16px;
    font-weight: 700;
}

.method-help-close {
    border: 0;
    background: transparent;
    color: #cbd5e1;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.method-help-body {
    padding: 14px 16px 6px;
    overflow: auto;
    color: #dbeafe;
    font-size: 14px;
    line-height: 1.55;
}

.method-help-body p {
    margin: 0 0 12px;
}

.method-help-footer {
    padding: 12px 16px 16px;
    border-top: 1px solid rgba(251, 191, 36, 0.15);
    display: flex;
    justify-content: flex-end;
}

.method-help-ok {
    border: 1px solid rgba(251, 191, 36, 0.35);
    background: rgba(251, 191, 36, 0.2);
    color: #fff7d1;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.method-help-ok:hover {
    background: rgba(251, 191, 36, 0.35);
}

/* Правая колонка: общая прокрутка и корректное сжатие flex-элементов */
.right-sidebar {
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Панель методологии: ограничение высоты и внутренняя прокрутка */
.methodology-panel {
    max-height: min(66vh, 820px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

@media (max-height: 820px) {
    .methodology-panel {
        max-height: 58vh;
    }
}
