/* ==================== БАЗОВЫЕ СТИЛИ ==================== */
:root {
    --card-w: 115px;
    --card-h: 173px;
    --slot-w: 122px;
    --slot-h: 183px;
    --deck-w: 115px;
    --deck-h: 173px;
    --slot-gap: 12px;
    --zone-gap: 20px;
}
@media (max-width: 680px) {
    :root {
        /* Размер карт рассчитан на 5 колонок поля боя + боковые отступы */
        --card-w: clamp(42px, calc((100vw - 80px) / 5), 115px);
        --card-h: calc(var(--card-w) * 1.504);
        --slot-w: calc(var(--card-w) + 7px);
        --slot-h: calc(var(--card-h) + 10px);
        --deck-w: var(--card-w);
        --deck-h: var(--card-h);
        --slot-gap: max(4px, calc(var(--card-w) * 0.15));
        --zone-gap: max(6px, calc(var(--card-w) * 0.2));
    }
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: url('../battleground.jpg') center/cover no-repeat fixed;
    background-color: #2c3e50;
    min-height: 100vh;
    padding: 0px;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
}

/* ==================== УТИЛИТЫ ==================== */
.hidden { display: none !important; }

/* ==================== ГЛАВНОЕ МЕНЮ ==================== */
#main-menu { text-align: center; padding: 60px 20px; }
.main-menu-title { color: #ffd700; font-size: 2.8em; margin-bottom: 40px; text-shadow: 0 2px 10px rgba(0,0,0,0.8); }
.main-menu-buttons { display: flex; flex-direction: column; align-items: center; gap: 18px; max-width: 420px; margin: 0 auto; }
.menu-btn {
    width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 18px 24px; border-radius: 14px; border: 3px solid rgba(255,255,255,0.2);
    background: rgba(0,0,0,0.5); cursor: pointer; transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
    position: relative; text-align: center;
}
.menu-btn:hover:not(:disabled) { transform: translateY(-4px) scale(1.02); border-color: #ffd700; box-shadow: 0 8px 30px rgba(255,215,0,0.3); }
.menu-btn:active:not(:disabled) { transform: scale(0.98); }
.menu-btn-icon { font-size: 2em; }
.menu-btn-label { font-size: 1.3em; font-weight: bold; color: #ffd700; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.menu-btn-desc { font-size: 0.85em; color: #aaa; }
.menu-btn-primary { border-color: rgba(255,215,0,0.4); box-shadow: 0 4px 20px rgba(255,215,0,0.15); }
.menu-btn-primary:hover:not(:disabled) { box-shadow: 0 8px 35px rgba(255,215,0,0.4); }
.menu-btn-locked { opacity: 0.5; cursor: not-allowed; }
.menu-btn-lock { position: absolute; top: 10px; right: 14px; font-size: 1.1em; }

/* ==================== ЭКРАН 1: ВЫБОР ФРАКЦИИ ==================== */
#selection-screen { text-align: center; padding: 60px 20px; position: relative; }
#selection-screen h1 { color: #ffd700; font-size: 2.8em; margin-bottom: 15px; text-shadow: 0 2px 10px rgba(0,0,0,0.8); }
.selection-subtitle { color: #ddd; font-size: 1.5em; margin-bottom: 35px; text-shadow: 0 1px 5px rgba(0,0,0,0.8); font-weight: 300; }
.faction-choices {
    display: flex; flex-direction: column; align-items: center;
    gap: 16px; max-width: 680px; margin: 0 auto;
}
.faction-card {
    width: 100%; cursor: pointer; transition: transform 0.25s, box-shadow 0.25s;
    border-radius: 12px; overflow: hidden; background: rgba(0,0,0,0.5);
    border: 3px solid rgba(255,255,255,0.2); box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    position: relative; display: flex; flex-direction: row;
}
.faction-card:hover { transform: translateY(-4px) scale(1.01); border-color: #ffd700; box-shadow: 0 8px 30px rgba(255,215,0,0.4); }
.faction-card.faction-selected { border-color: #ffd700; box-shadow: 0 0 30px rgba(255,215,0,0.6); transform: scale(1.02); }
.faction-pattern { width: 160px; min-height: 120px; flex-shrink: 0; background-size: cover; background-position: center; }
.faction-card-info { padding: 16px 20px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; text-align: left; }
.faction-name { font-size: 1.3em; font-weight: bold; color: #ffd700; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.faction-desc { margin-top: 6px; font-size: 0.9em; color: #ccc; line-height: 1.5; }
.faction-stats { display: flex; gap: 16px; margin-top: 10px; }
.faction-stat { display: flex; align-items: center; gap: 5px; font-size: 0.85em; color: #b0b0b0; }
.faction-stat-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* Заблокированная фракция */
.faction-card.faction-locked {
    cursor: default;
    border-color: rgba(100,100,100,0.3);
    box-shadow: none;
}
.faction-card.faction-locked:hover {
    transform: none;
    border-color: rgba(100,100,100,0.3);
    box-shadow: none;
}
.faction-card.faction-locked .faction-pattern {
    filter: grayscale(100%);
    opacity: 0.4;
}
.faction-card.faction-locked .faction-name {
    color: #666;
}
.faction-card.faction-locked .faction-desc {
    color: #555;
}
.faction-card.faction-locked .faction-stat {
    color: #555;
}
.faction-card.faction-locked .faction-stat-icon {
    opacity: 0.4;
}
.faction-lock-overlay {
    position: absolute;
    top: 50%;
    left: 80px;
    transform: translate(-50%, -50%);
    font-size: 2em;
    text-shadow: 0 2px 8px rgba(0,0,0,0.8);
    pointer-events: none;
    z-index: 10;
}

/* ==================== ЗАБЛОКИРОВАННАЯ КАРТА АРМИИ ==================== */
.army-card-item.army-card-locked {
    opacity: 0.7;
    filter: grayscale(100%);
    cursor: default;
    border-color: rgba(100,100,100,0.3) !important;
    box-shadow: none !important;
}
.army-card-item.army-card-locked .card-bg-troop {
    opacity: 0.3;
}
.army-card-item.army-card-locked .army-card-name {
    color: #2a2118;
}
.army-card-item.army-card-locked .army-card-cost {
    color: #2a2118;
}
.army-card-lock {
    text-align: center;
    font-size: 1.5em;
    padding: 4px 0;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* ==================== КНОПКА НАЗАД (экран найма армии) ==================== */
.back-to-factions-btn {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 100;
    padding: 6px 16px;
    font-size: 0.9em;
    font-weight: bold;
    color: #ddd;
    background: rgba(0,0,0,0.5);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s, border-color 0.15s;
}
.back-to-factions-btn:hover {
    background: rgba(255,255,255,0.15);
    border-color: #ffd700;
    transform: scale(1.03);
}

/* ==================== ЭКРАН 2: НАЙМ АРМИИ ==================== */
#army-screen { max-width: 1100px; margin: 0 auto; padding: 30px 20px; position: relative; }
.army-header { display: flex; justify-content: center; align-items: center; margin-bottom: 15px; flex-wrap: wrap; gap: 15px; }
.army-header h2 { color: #ffd700; font-size: 1.8em; text-shadow: 0 2px 8px rgba(0,0,0,0.8); margin: 0; text-align: center; }
.army-points { font-size: 1.4em; background: rgba(0,0,0,0.5); border: 2px solid #ffd700; border-radius: 10px; padding: 8px 20px; }
.army-points-label { color: #ccc; margin-right: 8px; }
.army-points-spent { color: #ffd700; font-weight: bold; font-size: 1.3em; }
.army-points-spent.army-over { color: #ff4444; }
.army-points-sep { color: #888; margin: 0 4px; }
.army-points-total { color: #aaa; }

/* ==================== АВТОСБОРКА КОЛОДЫ ==================== */
.autodraft-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 8px 16px 16px;
    flex-wrap: wrap;
}
.autodraft-card {
    width: 150px;
    background: linear-gradient(145deg, #3a3028, #2a2118);
    border: 2px solid #6b5a40;
    border-radius: 12px;
    padding: 14px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
}
.autodraft-card:hover {
    border-color: #c9a84c;
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(201, 168, 76, 0.3);
}
.autodraft-card.active {
    border-color: #ffd700;
    background: linear-gradient(145deg, #b8860b, #8b6914);
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.autodraft-icon {
    font-size: 2em;
    margin-bottom: 6px;
}
.autodraft-card.active .autodraft-icon {
    filter: brightness(1.2);
}
.autodraft-name {
    font-size: 1.1em;
    font-weight: bold;
    color: #e8d5b0;
    margin-bottom: 6px;
}
.autodraft-card.active .autodraft-name {
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.autodraft-desc {
    font-size: 0.75em;
    color: #a89070;
    line-height: 1.3;
}
.autodraft-card.active .autodraft-desc {
    color: #ffe066;
}

/* ==================== ВКЛАДКИ МАСТЕЙ ==================== */
.suit-tabs {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.suit-tab {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 14px;
    border-radius: 10px;
    border: 2px solid rgba(180, 150, 100, 0.5);
    background: linear-gradient(180deg, #d4c4a0, #b8a880);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.suit-tab:hover {
    border-color: #c9a84c;
    background: linear-gradient(180deg, #e0d0b0, #c8b890);
    box-shadow: 0 3px 10px rgba(0,0,0,0.4);
}
.suit-tab.active {
    border-width: 4px;
    background: linear-gradient(180deg, #e8d8b8, #d0c098);
}
.suit-tab-icon {
    width: 24px;
    height: 24px;
}
.suit-tab-beats {
    display: flex;
    align-items: center;
    gap: 3px;
    color: #222;
    font-weight: bold;
    font-size: 0.85em;
}
.suit-tab-beats img {
    width: 18px;
    height: 18px;
}

/* ==================== СЕТКА НАЙМА (карточки в стиле game) ==================== */
.army-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 25px;
}
.army-suit-section {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}
.army-suit-section.hidden {
    display: none;
}
.army-card-item {
    background: rgba(40, 28, 18, 0.7);
    border: 2px solid rgba(180, 130, 70, 0.35);
    border-radius: 8px;
    padding: 6px 6px 8px;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    position: relative;
}
.army-card-item.army-card-active {
    border-color: #ffd700;
    background: rgba(80, 50, 20, 0.8);
    box-shadow: 0 0 14px rgba(255, 215, 0, 0.25);
}
.army-card-item:not(.army-card-active) {
    background: rgba(50, 50, 50, 0.5) !important;
    border-color: rgba(100, 100, 100, 0.3) !important;
    box-shadow: none !important;
}
.army-card-item:not(.army-card-active) .card-bg-troop {
    filter: grayscale(100%);
    opacity: 0.5;
}
.army-card-item:not(.army-card-active) .army-card-name {
    color: #2a2118;
}
.army-card-item:not(.army-card-active) .army-card-cost {
    color: #2a2118;
}
/* Цвета рамок по масти */
.army-card-item[data-suit="spear"] { border-color: rgba(74, 144, 226, 0.5); }
.army-card-item[data-suit="sword"] { border-color: rgba(149, 165, 166, 0.5); }
.army-card-item[data-suit="bow"]   { border-color: rgba(0, 105, 45, 0.5); }
.army-card-item[data-suit="horse"] { border-color: rgba(243, 156, 18, 0.5); }
.army-card-item[data-suit="spear"].army-card-active { border-color: #4A90E2; box-shadow: 0 0 12px rgba(74, 144, 226, 0.4); }
.army-card-item[data-suit="sword"].army-card-active { border-color: #95A5A6; box-shadow: 0 0 12px rgba(149, 165, 166, 0.4); }
.army-card-item[data-suit="bow"].army-card-active   { border-color: #2ECC71; box-shadow: 0 0 12px rgba(0, 105, 45, 0.4); }
.army-card-item[data-suit="horse"].army-card-active { border-color: #F39C12; box-shadow: 0 0 12px rgba(243, 156, 18, 0.4); }

.army-card-preview {
    width: 100%;
    padding-top: 140%;
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 6px;
}
.army-card-preview .card-bg-base {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: url('../card_background.jpg') center/cover no-repeat;
    border-radius: 6px; z-index: 0; pointer-events: none;
}
.army-card-preview .card-bg-troop {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background-size: cover; background-position: center; background-repeat: no-repeat;
    z-index: 1; pointer-events: none;
    -webkit-mask-image: radial-gradient(ellipse at center, black 15%, transparent 90%);
    mask-image: radial-gradient(ellipse at center, black 15%, transparent 90%);
}
.army-card-corner {
    position: absolute; display: flex; flex-direction: row; align-items: center; gap: 2px;
    font-weight: bold; z-index: 10; background: rgba(255,255,255,0.8);
    padding: 2px 4px; border-radius: 3px; font-size: 10px;
}
.army-card-corner.top-left { top: 3px; left: 3px; }
.army-card-number { color: #222; font-weight: 900; line-height: 1; }
.army-card-suit { width: 11px; height: 11px; }
.army-card-suit-secondary { width: 8px; height: 8px; }
.army-card-prey { width: 8px; height: 8px; }
.army-card-arrow { font-size: 7px; color: #555; font-weight: bold; }
.army-card-shield {
    position: absolute; bottom: 3px; right: 3px; z-index: 10;
    width: 18px; height: 18px; pointer-events: none;
}
.army-card-shield img { width: 100%; height: 100%; filter: drop-shadow(0 0 2px rgba(0,0,0,0.8)); }
/* Бейджи трейтов на карте армии */
.army-card-traits {
    position: absolute; bottom: 3px; left: 3px; z-index: 10;
    display: flex; flex-direction: row; gap: 2px; pointer-events: none;
}
.army-trait-icon {
    width: 16px; height: 16px;
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.8));
}
.army-card-info { margin-bottom: 4px; }
.army-card-name { color: #eee; font-size: 0.7em; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.army-card-cost { color: #aaa; font-size: 0.65em; display: inline-flex; align-items: center; white-space: nowrap; }
.army-card-controls { display: flex; align-items: center; justify-content: center; gap: 8px; }
.army-card-controls button {
    width: 28px; height: 28px; border-radius: 50%; border: 2px solid #ffd700;
    background: rgba(0,0,0,0.5); color: #ffd700; font-size: 1.2em; font-weight: bold;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, transform 0.1s; line-height: 1; padding: 0;
}
.army-card-controls button:hover { background: rgba(255,215,0,0.2); transform: scale(1.1); }
.army-card-controls button:active { transform: scale(0.95); }
.army-count { color: #ffd700; font-weight: bold; font-size: 1.1em; min-width: 24px; text-align: center; }

/* ==================== DIVIDER МЕЖДУ ФРАКЦИЯМИ В АРМИИ ==================== */
.army-section-divider {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0 4px;
    font-size: 0.65em;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #2a2118;
    white-space: nowrap;
    user-select: none;
}
.army-section-divider::before,
.army-section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(42, 33, 24, 0.4), transparent);
}

/* ==================== TIER DIVIDERS ==================== */
.army-section-divider.tier-0 { color: #2a2118; }
.army-section-divider.tier-0::before,
.army-section-divider.tier-0::after {
    background: linear-gradient(to right, transparent, rgba(42, 33, 24, 0.4), transparent);
}

.army-section-divider.tier-1 { color: #5a7a3a; }
.army-section-divider.tier-1::before,
.army-section-divider.tier-1::after {
    background: linear-gradient(to right, transparent, rgba(90, 122, 58, 0.5), transparent);
}

.army-section-divider.tier-2 { color: #3a5a8a; }
.army-section-divider.tier-2::before,
.army-section-divider.tier-2::after {
    background: linear-gradient(to right, transparent, rgba(58, 90, 138, 0.5), transparent);
}

.army-section-divider.tier-3 { color: #8a6a2a; }
.army-section-divider.tier-3::before,
.army-section-divider.tier-3::after {
    background: linear-gradient(to right, transparent, rgba(138, 106, 42, 0.6), transparent);
}

.army-section-divider.tier-4 { color: #7a2a7a; }
.army-section-divider.tier-4::before,
.army-section-divider.tier-4::after {
    background: linear-gradient(to right, transparent, rgba(122, 42, 122, 0.6), transparent);
}

.army-section-divider.tier-neutral { color: #6a4a2a; font-style: italic; }
.army-section-divider.tier-neutral::before,
.army-section-divider.tier-neutral::after {
    background: linear-gradient(to right, transparent, rgba(106, 74, 42, 0.5), transparent);
}

.army-footer { display: flex; justify-content: center; gap: 20px; }
.army-btn {
    padding: 12px 35px; font-size: 1.15em; border-radius: 8px; cursor: pointer;
    font-weight: bold; transition: transform 0.15s, box-shadow 0.15s; border: none;
}
.army-btn-reset {
    background: rgba(255,255,255,0.15); color: #ddd; border: 2px solid rgba(255,255,255,0.3);
}
.army-btn-reset:hover { background: rgba(255,255,255,0.25); transform: scale(1.03); }
.army-btn-start {
    background: #ffd700; color: #333; box-shadow: 0 4px 15px rgba(255,215,0,0.4);
}
.army-btn-start:hover:not(:disabled) { transform: scale(1.05); box-shadow: 0 6px 25px rgba(255,215,0,0.6); }
.army-btn-start:disabled { background: #666; color: #999; cursor: not-allowed; box-shadow: none; }

@media (max-width: 900px) {
    .army-grid { grid-template-columns: repeat(4, 1fr); }
    .army-suit-section { grid-template-columns: repeat(4, 1fr); }
    .suit-tab { padding: 6px 10px; }
    .suit-tab-icon { width: 20px; height: 20px; }
    .suit-tab-beats img { width: 14px; height: 14px; }
}
@media (max-width: 650px) {
    #army-screen { padding: 15px 8px; }
    .army-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .army-suit-section { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .faction-card { flex-direction: column; }
    .faction-pattern { width: 100%; height: 120px; min-height: auto; }
    .faction-card-info { align-items: center; text-align: center; }
    .faction-stats { justify-content: center; }
    .suit-tabs { gap: 4px; }
    .suit-tab { padding: 5px 8px; gap: 4px; }
    .suit-tab-icon { width: 18px; height: 18px; }
    .suit-tab-beats img { width: 14px; height: 14px; }
    .army-card-item { padding: 4px 4px 6px; }
    .army-card-name { font-size: 0.6em; }
    .army-card-cost { font-size: 0.6em; }
    .army-card-controls button { width: 22px; height: 22px; font-size: 0.85em; }
    .army-count { font-size: 0.9em; min-width: 18px; }
}

/* ==================== ПАНЕЛЬ ПОЛЬЗОВАТЕЛЯ (игровой экран) ==================== */
.user-bar {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 300;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 215, 0, 0.3);
    border-radius: 8px;
}

#user-display {
    color: #ffd700;
    font-weight: bold;
    font-size: 0.9em;
}

.logout-btn {
    padding: 4px 12px;
    font-size: 0.8em;
    font-weight: bold;
    color: #ddd;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.logout-btn:hover {
    background: rgba(255, 50, 50, 0.2);
    border-color: rgba(255, 50, 50, 0.4);
    color: #ff6666;
}

/* ==================== КНОПКА ВОЗВРАТА В МЕНЮ (игровой экран) ==================== */
.back-to-menu-btn {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 300;
    padding: 6px 16px;
    font-size: 0.9em;
    font-weight: bold;
    color: #ddd;
    background: rgba(0,0,0,0.5);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s, border-color 0.15s;
}
.back-to-menu-btn:hover {
    background: rgba(255,255,255,0.15);
    border-color: #ffd700;
    transform: scale(1.03);
}

/* ==================== ИГРОВОЙ ЭКРАН ==================== */
#game-screen { max-width: 1400px; margin: 0 auto; position: relative; }
.battlefield { display: flex; flex-direction: column; gap: var(--zone-gap); background: transparent; }
.player-zone { margin: 0px 0; padding: 12px 5px 10px; background: rgba(0,0,0,0.3); border-radius: 10px; border: 2px solid rgba(255,255,255,0.2); position: relative; overflow: visible; }

/* ==================== ИНФОРМАЦИЯ ИГРОКА ==================== */
.army-strength {
    background: rgba(0,0,0,0.5);
    border: 2px solid #ffd700;
    border-radius: 14px;
    padding: 4px 16px;
    font-weight: bold;
    font-size: 1.1em;
    color: #ffd700;
    white-space: nowrap;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
    min-width: 70px;
    text-align: center;
}
/* ==================== ЦЕНТР: ПОЛЕ + ЖЕТОН ==================== */
.battle-center {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

/* ==================== ЗОНА БОЯ (центр) ==================== */
.battle-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ==================== ЖЕТОН ПЕРВОГО ХОДА ==================== */
.turn-token {
    position: absolute;
    z-index: 200;
    pointer-events: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: radial-gradient(circle, #ffd700 0%, #b8960f 100%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.5), 0 0 12px rgba(255,215,0,0.3);
    opacity: 0;
    transition: opacity 0.4s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.turn-token.visible {
    opacity: 1;
}
/* Нижний правый угол зоны AI */
.turn-token.on-top {
    bottom: 8px;
    right: 8px;
    top: auto;
    left: auto;
    transform: none;
}
/* Нижний правый угол зоны Human */
.turn-token.on-bottom {
    bottom: 8px;
    right: 8px;
    top: auto;
    left: auto;
    transform: none;
}
.turn-token::after {
    display: none;
}
.token-crown {
    display: none;
}
.token-label {
    display: none;
}
.token-icon {
    width: 32px;
    height: 32px;
    object-fit: contain;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

/* ==================== ЗОНА КАРТ ИГРОКА ==================== */
.player-cards-area {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 0;
    min-height: calc(var(--deck-h) + 8px);
    padding: 4px 6px;
    flex-wrap: nowrap;
    position: relative;
}

/* Стопки — фиксируем по бокам через absolute, чтобы веер был по центру */
.deck-pile {
    width: calc(var(--deck-w) + 10px);
    height: var(--deck-h);
    position: absolute;
    flex-shrink: 0;
    flex-grow: 0;
    bottom: 4px;
    z-index: 10;
}
/* Стопки сброса — прижимаем к левому краю зоны с отступом */
#p1-discard-pile,
#p2-discard-pile {
    left: 15px;
}
/* Стопки добора — прижимаем к правому краю зоны с отступом */
#p1-deck-pile,
#p2-deck-pile {
    right: 15px;
}
.deck-pile-label {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7em;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    white-space: nowrap;
}

/* ==================== ВЕЕР КАРТ ==================== */
.hand {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    flex-wrap: nowrap;
    padding: 0;
    position: relative;
    min-width: 0;
    z-index: 20;
}

/* Карты в руке игрока (face-up) — веерная раскладка */
#p2-hand .card {
    position: relative;
    margin-left: calc(var(--card-w) * -0.55);
    transform-origin: bottom center;
}
#p2-hand .card:first-child { margin-left: 0; }

/* Лёгкий поворот для веерного эффекта: крайние карты чуть повёрнуты */
#p2-hand .card:nth-child(1) { transform: rotate(-4deg); }
#p2-hand .card:nth-child(2) { transform: rotate(-2deg); }
#p2-hand .card:nth-child(3) { transform: rotate(0deg); }
#p2-hand .card:nth-child(4) { transform: rotate(2deg); }
#p2-hand .card:nth-child(5) { transform: rotate(4deg); }

/* Карты в руке AI (face-down) — компактный веер, основание вверх */
#p1-hand .card {
    position: relative;
    margin-left: calc(var(--card-w) * -0.65);
    transform-origin: top center;
}
#p1-hand .card:first-child { margin-left: 0; }

/* AI: веер «вверх ногами» — карты выглядывают за верхнюю границу */
#p1-hand .card:nth-child(1) { transform: rotate(3deg); }
#p1-hand .card:nth-child(2) { transform: rotate(1.5deg); }
#p1-hand .card:nth-child(3) { transform: rotate(0deg); }
#p1-hand .card:nth-child(4) { transform: rotate(-1.5deg); }
#p1-hand .card:nth-child(5) { transform: rotate(-3deg); }

/* ==================== ПОДЪЁМ КАРТЫ ПРИ ВЫБОРЕ ==================== */
#p2-hand .card.card-selected {
    transform: translateY(-18px) scale(1.05) rotate(0deg) !important;
    z-index: 100;
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.5), 0 0 12px rgba(255, 215, 0, 0.3);
}

/* Hover для карт в руке игрока (только когда ход игрока) */
#p2-hand .card:not(.disabled):not(.card-selected):hover {
    transform: translateY(-12px) scale(1.03);
    z-index: 50;
}

/* ==================== TRANSITION ТОЛЬКО ПОСЛЕ ЗАГРУЗКИ ==================== */
/* Класс .hand-ready добавляется JS после инициализации — включает transition */
.hand-ready .card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Начальное состояние руки — невидимая, чтобы не было "прыжка" веера */
.hand {
    opacity: 0;
    transition: opacity 0.15s ease;
}
.hand.hand-ready {
    opacity: 1;
}

/* ==================== РЯДЫ СЛОТОВ ==================== */
.battle-row {
    display: flex;
    flex-direction: row;
    gap: var(--slot-gap);
    margin: calc(var(--slot-gap) * 1.2) 0;
    justify-content: center;
    flex-wrap: nowrap;
}
.field-slot {
    width: var(--slot-w);
    min-width: var(--slot-w);
    height: var(--slot-h);
    min-height: var(--slot-h);
    background: rgba(0,0,0,0.4);
    border: 2px dashed rgba(255,255,255,0.4);
    border-radius: 8px;
    position: relative;
    transition: border-color 0.2s, box-shadow 0.2s;
    cursor: default;
    flex-shrink: 0;
}
.field-slot.available {
    border-color: #ffd700 !important;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6) !important;
    cursor: pointer !important;
}

/* ==================== КАРТЫ ==================== */
.card {
    width: var(--card-w);
    height: var(--card-h);
    position: relative;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
.card.disabled {
    transform: none !important;
}

/* Цвета рамок по типу юнита */
.card-spear { border-color: #4A90E2; box-shadow: 0 0 8px rgba(74, 144, 226, 0.4), 0 4px 12px rgba(0,0,0,0.6); }
.card-sword { border-color: #95A5A6; box-shadow: 0 0 8px rgba(149, 165, 166, 0.4), 0 4px 12px rgba(0,0,0,0.6); }
.card-bow   { border-color: #2ECC71; box-shadow: 0 0 8px rgba(0, 105, 45, 0.4), 0 4px 12px rgba(0,0,0,0.6); }
.card-horse { border-color: #F39C12; box-shadow: 0 0 8px rgba(243, 156, 18, 0.4), 0 4px 12px rgba(0,0,0,0.6); }

/* Фоны карт */
.card-bg-base {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: url('../card_background.jpg') center/cover no-repeat;
    border-radius: 6px;
    z-index: 0;
    pointer-events: none;
}
.card-bg-troop {
    position: absolute;
    top: 0%; left: 0%;
    width: 100%; height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 1;
    pointer-events: none;
    -webkit-mask-image: radial-gradient(ellipse at center, black 15%, transparent 90%);
    mask-image: radial-gradient(ellipse at center, black 15%, transparent 90%);
}
.card-bg-pattern {
    position: absolute;
    top: 10%; left: 5%;
    width: 90%; height: 80%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 1;
    pointer-events: none;
    -webkit-mask-image: radial-gradient(ellipse at center, black 45%, transparent 100%);
    mask-image: radial-gradient(ellipse at center, black 45%, transparent 100%);
}

/* Угловые метки карты */
.card-corner {
    position: absolute;
    display: flex; flex-direction: row; align-items: center; gap: calc(var(--card-w) * 0.028);
    font-weight: bold; z-index: 10;
    background: rgba(255,255,255,0.7);
    padding: calc(var(--card-w) * 0.042) calc(var(--card-w) * 0.056); border-radius: calc(var(--card-w) * 0.028);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.card-corner.top-left { top: calc(var(--card-w) * 0.035); left: calc(var(--card-w) * 0.035); }

/* Панель статусов (внизу карты) */
.card-status-bar {
    position: absolute;
    bottom: calc(var(--card-w) * 0.035);
    left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: calc(var(--card-w) * 0.052);
    background: rgba(0, 0, 0, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: calc(var(--card-w) * 0.035);
    padding: calc(var(--card-w) * 0.026) calc(var(--card-w) * 0.07);
    pointer-events: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.status-fatigue {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: calc(var(--card-w) * 0.017);
}
.status-fatigue-icon {
    width: calc(var(--card-w) * 0.157);
    height: calc(var(--card-w) * 0.157);
    filter: drop-shadow(0 0 3px rgba(255, 50, 50, 0.6));
}
.status-fatigue-count {
    color: #ff3333;
    font-size: calc(var(--card-w) * 0.113);
    font-weight: 900;
    line-height: 1;
}
.status-shield-icon {
    width: calc(var(--card-w) * 0.174);
    height: calc(var(--card-w) * 0.174);
    filter: drop-shadow(0 0 3px rgba(70, 130, 255, 0.7));
}
.status-shield-depleted {
    opacity: 0.3;
    filter: grayscale(100%);
}
.status-award {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: calc(var(--card-w) * 0.017);
}
.status-award-icon {
    width: calc(var(--card-w) * 0.157);
    height: calc(var(--card-w) * 0.157);
    filter: drop-shadow(0 0 3px rgba(50, 255, 50, 0.7));
}
.status-award-count {
    color: #33ff33;
    font-size: calc(var(--card-w) * 0.113);
    font-weight: 900;
    line-height: 1;
}
/* Бейджи трейтов на карте */
.status-trait-icon {
    width: calc(var(--card-w) * 0.14);
    height: calc(var(--card-w) * 0.14);
    filter: drop-shadow(0 0 2px rgba(255, 200, 50, 0.6));
}
.status-trait-icon.status-trait-used {
    opacity: 0.3;
    filter: grayscale(100%);
}
/* Иконки трейтов в админке (таблица и модалка) */
.trait-icon-img {
    width: 18px;
    height: 18px;
    vertical-align: middle;
    filter: drop-shadow(0 0 1px rgba(0,0,0,0.5));
}
.trait-checkbox .trait-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
}
.trait-checkbox-modal {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.card-number {
    color: #222;
    font-size: calc(var(--card-w) * 0.139);
    font-weight: 900;
    line-height: 1;
}
.card-suit {
    width: calc(var(--card-w) * 0.153);
    height: calc(var(--card-w) * 0.153);
}
.card-suit-secondary {
    width: calc(var(--card-w) * 0.096);
    height: calc(var(--card-w) * 0.096);
}
.card-prey {
    width: calc(var(--card-w) * 0.077);
    height: calc(var(--card-w) * 0.077);
}
.arrow {
    font-size: calc(var(--card-w) * 0.098);
    color: #555;
    font-weight: bold;
}

/* Усталость на метке ранга */
.card-number-fatigued {
    color: #ff3333 !important;
    text-shadow: 0 0 6px rgba(255, 50, 50, 0.7), 0 0 12px rgba(255, 50, 50, 0.3);
}

/* Award-бафф на метке ранга (зелёное свечение) */
.card-number-award {
    color: #2d8a4e !important;
    text-shadow: 0 0 4px rgba(45, 138, 78, 0.5), 0 0 8px rgba(45, 138, 78, 0.2);
}

/* ==================== AWARD В СБРОСЕ ==================== */
.status-award-discard {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 3px;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(50, 255, 50, 0.5);
    border-radius: 4px;
    padding: 3px 8px;
    pointer-events: none;
}

/* ==================== АНИМАЦИИ БОЯ ==================== */
@keyframes winGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0,255,0,0); transform: scale(1); border: 2px solid transparent; }
    50% { box-shadow: 0 0 25px 8px rgba(0,255,0,0.6); transform: scale(1.08); border: 2px solid #0f0; }
}
@keyframes winGlowBase {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0,255,100,0); transform: scale(1); border: 2px solid transparent; }
    50% { box-shadow: 0 0 35px 12px rgba(0,255,100,0.9); transform: scale(1.15); border: 3px solid #0f0; }
}
@keyframes loseBlink {
    0%, 100% { border: 2px solid transparent; }
    50% { border: 2px solid #f00; }
}
.card-win { animation: winGlow 1.2s ease-in-out 2; z-index: 50 !important; }
.card-win.base-attack { animation: winGlowBase 1.2s ease-in-out 2; }
.card-lose { animation: loseBlink 1.2s ease-in-out 2; z-index: 50 !important; }

/* ==================== ШТРАФ ЗА ОТКРЫТЫЙ ФЛАНГ ==================== */
@keyframes penaltyShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px) rotate(-2deg); }
    40% { transform: translateX(8px) rotate(2deg); }
    60% { transform: translateX(-5px) rotate(-1deg); }
    80% { transform: translateX(5px) rotate(1deg); }
}
.card-penalty {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    border: 3px solid #ff3333 !important;
    box-shadow: 0 0 20px 5px rgba(255, 0, 0, 0.5), 0 4px 12px rgba(0,0,0,0.6);
    animation: penaltyShake 0.4s ease-in-out;
}

/* ==================== СТОПКИ И ПОЛЁТ ==================== */
.stacked-card {
    position: absolute;
    transition: all 0.3s;
    transform: translateZ(0);
    backface-visibility: hidden;
    pointer-events: none;
}
.card-flying {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    filter: drop-shadow(0 5px 15px rgba(0,0,0,0.5));
    opacity: 1 !important;
}

/* ==================== АНИМАЦИИ ТРЕЙТОВ ==================== */

/* --- Лечение: зелёное свечение --- */
.card-heal-fx .card-heal-glow {
    position: absolute;
    inset: -4px;
    border-radius: 10px;
    background: radial-gradient(ellipse at center, rgba(80, 220, 120, 0.6) 0%, transparent 70%);
    animation: heal-pulse 0.6s ease-out forwards;
    pointer-events: none;
    z-index: 2;
}
@keyframes heal-pulse {
    0%   { opacity: 0; transform: scale(0.8); }
    50%  { opacity: 1; transform: scale(1.1); }
    100% { opacity: 0; transform: scale(1.3); }
}

/* --- Засада: красная метка черепа --- */
.card-ambush-fx .card-ambush-skull {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    pointer-events: none;
}
.card-ambush-fx .card-ambush-skull::before {
    content: '💀';
    font-size: 2.2em;
    animation: ambush-skull-pop 0.6s ease-out forwards;
    filter: drop-shadow(0 0 8px rgba(255, 60, 60, 0.8));
}
@keyframes ambush-skull-pop {
    0%   { opacity: 0; transform: scale(0.3) rotate(-20deg); }
    40%  { opacity: 1; transform: scale(1.2) rotate(5deg); }
    100% { opacity: 0; transform: scale(0.8) rotate(0deg); }
}

/* --- Устрашение: эффект тряски и затемнения --- */
.card-intimidation-fx {
    filter: drop-shadow(0 5px 15px rgba(0,0,0,0.5)) brightness(0.7);
}

/* Паттерн фракции для рубашки в анимациях */
.card-flying .card-bg-pattern {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    border-radius: 8px;
    opacity: 0.85;
}

/* ==================== ТАЙМЕР ХОДА (полоска сверху player2-zone) ==================== */
.turn-timer {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 6px;
    display: none;
    z-index: 5;
    pointer-events: none;
    background: rgba(255,255,255,0.08);
    border-radius: 0 0 3px 3px;
    overflow: hidden;
}
.timer-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ffd700, #ffaa00);
    border-radius: 0 0 3px 3px;
    transition: width 0.3s linear;
}
.timer-text {
    position: absolute;
    top: 10px;
    right: 12px;
    font-size: 1.1em;
    font-weight: bold;
    color: rgba(255,255,255,0.7);
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    pointer-events: none;
}
.timer-warning .timer-bar {
    background: linear-gradient(90deg, #ff4444, #cc0000);
}
.timer-warning .timer-text {
    color: rgba(255,100,100,0.9);
}

/* ==================== ЗОНА КОММЕНТАРИЕВ БОЯ ==================== */
.commentary-zone {
    height: 0;
    overflow: hidden;
    transition: height 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.commentary-zone.commentary-active {
    height: 48px;           /* место под 1–2 строки комментария */
    margin-bottom: 8px;     /* отступ до зоны игрока */
}

/* ==================== ПОЛОСКА КОММЕНТАРИЯ ==================== */
.battle-commentary {
    display: none;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 6px 24px;
    min-height: 32px;
    line-height: 1.35;
    background: rgba(0, 0, 0, 0.75);
    border: 2px solid rgba(255, 215, 0, 0.5);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), 0 0 10px rgba(255, 215, 0, 0.12);
    color: #fff;
    font-size: 0.92em;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    text-align: center;
    pointer-events: none;
    width: fit-content;
    max-width: calc(100% - 48px);
    will-change: transform, opacity;
    /* Анимация: за правым краем зоны */
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 50;
}
.battle-commentary.commentary-visible {
    transform: translateX(0);
}
.battle-commentary.commentary-exit {
    transition: transform 0.35s cubic-bezier(0.55, 0, 1, 0.45), opacity 0.3s ease;
    transform: translateX(-100%);
    opacity: 0;
}

/* Элементы внутри комментария */
.cm-header {
    color: #ffd700;
    font-weight: bold;
}
.cm-card {
    color: #fff;
    font-weight: 600;
}
.cm-card.cm-buffed {
    color: #00ff66;
    font-weight: 700;
}
.cm-award {
    font-size: 13px;
    color: #00ff66;
}
.cm-card.cm-fatigued {
    color: #ff6666;
}
.cm-rank {
    color: #ffd700;
    font-weight: bold;
    font-size: 0.9em;
}
.cm-ultra {
    color: #c9a84c;
    font-size: 0.75em;
    font-weight: normal;
    opacity: 0.9;
}
.cm-vs {
    color: #aaa;
    font-style: italic;
}
.cm-action {
    color: #88ccff;
}
.cm-note {
    color: #aaa;
    font-size: 0.85em;
    font-style: italic;
}

/* ==================== КНОПКА ПЕРЕКЛЮЧЕНИЯ КОММЕНТАРИЕВ ==================== */
#commentary-toggle-btn {
    display: none;
    padding: 6px 20px;
    font-size: 0.88em;
    font-weight: bold;
    color: #fff;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 215, 0, 0.6);
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4), 0 0 8px rgba(255, 215, 0, 0.15);
    cursor: pointer;
    transition: background 0.15s, transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
    pointer-events: auto;
}
#commentary-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.85);
    border-color: #ffd700;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.5), 0 0 14px rgba(255, 215, 0, 0.3);
    transform: scale(1.03);
}
#commentary-toggle-btn.commentary-btn-off {
    opacity: 0.55;
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: none;
}

/* ==================== АДАПТИВНОСТЬ ==================== */
@media (max-width: 760px) {
    #game-screen { max-width: 100%; }
    .battlefield { padding: 0 6px; }
    .player-cards-area { gap: 6px; padding: 8px 0; }
    .deck-pile { margin: 0 2px; }
    .army-strength { font-size: 0.95em; padding: 3px 12px; }
    .timer-text { font-size: 0.95em; top: 8px; right: 8px; }
    .commentary-zone.commentary-active { height: 40px; margin-bottom: 6px; }
    .battle-commentary { font-size: 0.75em; padding: 4px 14px; min-height: 24px; height: auto; width: fit-content; }
    #commentary-toggle-btn { font-size: 0.75em; padding: 5px 14px; }
}

/* На очень маленьких экранах: рука сверху (в ряд), колоды снизу (в ряд) */
@media (max-width: 440px) {
    .battlefield { padding: 0 2px; }
    .player-zone { padding: 8px 4px 6px; overflow: visible; }
    /* Строгая вертикальная структура: рука → divider → колоды в ряд */
    .player-cards-area {
        display: grid !important;
        grid-template-columns: 1fr auto auto 1fr !important;
        grid-template-rows: auto auto !important;
        align-items: center !important;
        gap: 4px !important;
        padding: 4px 2px !important;
        min-height: auto !important;
    }
    /* Рука — первый ряд, все 3 колонки */
    .hand {
        grid-column: 1 / -1 !important;
        grid-row: 1 !important;
        width: 100% !important;
        min-height: auto !important;
        justify-content: center !important;
        /* Горизонтальный разделитель под рукой */
        border-left: none !important;
        border-right: none !important;
        border-bottom: 2px solid rgba(255,255,255,0.3) !important;
        padding: 0 12px 4px !important;
        margin-bottom: 2px !important;
    }
    /* Колоды — второй ряд, по центру рядом */
    #p2-discard-pile, #p1-discard-pile {
        grid-column: 2 !important;
        grid-row: 2 !important;
        justify-self: end !important;
    }
    #p2-deck-pile, #p1-deck-pile {
        grid-column: 3 !important;
        grid-row: 2 !important;
        justify-self: start !important;
    }
}


/* ==================== ВСТРОЕННЫЙ ВЫБОР СЛОЖНОСТИ (на экране армии) ==================== */
.difficulty-inline {
    margin: 0 auto 20px;
    max-width: 900px;
}

.difficulty-inline-title {
    text-align: center;
    color: #c9a84c;
    font-size: 1.1em;
    margin-bottom: 12px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    font-weight: 400;
}

.difficulty-inline .difficulty-choices {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin: 0;
}

.difficulty-inline .difficulty-card {
    width: 130px;
    padding: 12px 10px;
}

.difficulty-inline .difficulty-level {
    font-size: 1.5em;
    margin-bottom: 2px;
}

.difficulty-inline .difficulty-name {
    font-size: 0.9em;
    margin-bottom: 4px;
}

.difficulty-inline .difficulty-desc {
    font-size: 0.65em;
}

@media (max-width: 768px) {
    .difficulty-inline .difficulty-choices {
        gap: 6px;
    }
    .difficulty-inline .difficulty-card {
        width: calc(50% - 6px);
        padding: 8px 6px;
    }
    .difficulty-inline .difficulty-card:last-child {
        width: 100%;
    }
    .difficulty-inline .difficulty-level {
        font-size: 1.2em;
        margin-bottom: 1px;
    }
    .difficulty-inline .difficulty-name {
        font-size: 0.75em;
        margin-bottom: 2px;
    }
    .difficulty-inline .difficulty-desc {
        font-size: 0.55em;
    }
}

/* ==================== ЭКРАН ВЫБОРА СЛОЖНОСТИ ==================== */
#difficulty-screen {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    overflow-y: auto;
    padding: 20px;
}

.difficulty-title {
    text-align: center;
    color: #f0e6d3;
    font-size: 1.8em;
    margin: 20px 0 30px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}

.difficulty-choices {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    max-width: 900px;
    margin: 0 auto 30px;
}

.difficulty-card {
    width: 160px;
    background: linear-gradient(145deg, #3a3028, #2a2118);
    border: 2px solid #6b5a40;
    border-radius: 12px;
    padding: 18px 14px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
}

.difficulty-card:hover {
    border-color: #c9a84c;
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(201, 168, 76, 0.3);
}

.difficulty-card.difficulty-selected {
    border-color: #ffd700;
    background: linear-gradient(145deg, #b8860b, #8b6914);
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.difficulty-card.difficulty-selected .difficulty-name {
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.difficulty-card.difficulty-selected .difficulty-desc {
    color: #ffe066;
}

.difficulty-level {
    font-size: 2em;
    font-weight: bold;
    color: #c9a84c;
    margin-bottom: 6px;
    font-family: 'Georgia', serif;
}

.difficulty-card.difficulty-selected .difficulty-level {
    color: #ffd700;
}

.difficulty-name {
    font-size: 1.1em;
    font-weight: bold;
    color: #e8d5b0;
    margin-bottom: 8px;
}

.difficulty-desc {
    font-size: 0.78em;
    color: #a09080;
    line-height: 1.3;
}

.confirm-difficulty-btn {
    display: block;
    margin: 0 auto;
    padding: 14px 48px;
    font-size: 1.3em;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(145deg, #8b6914, #6b4f10);
    border: 2px solid #c9a84c;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s ease;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.confirm-difficulty-btn:hover:not(:disabled) {
    background: linear-gradient(145deg, #a88018, #8b6914);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(201, 168, 76, 0.4);
}

.confirm-difficulty-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.back-to-army-btn {
    position: absolute;
    top: 16px;
    left: 16px;
    padding: 8px 18px;
    font-size: 0.95em;
    color: #c9a84c;
    background: rgba(0,0,0,0.5);
    border: 1px solid #6b5a40;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

.back-to-army-btn:hover {
    background: rgba(0,0,0,0.7);
    border-color: #c9a84c;
}

/* ==================== TOPBAR ==================== */
.topbar {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: linear-gradient(180deg, rgba(30, 22, 12, 0.97), rgba(30, 22, 12, 0.85));
    border-bottom: 2px solid #6b5a40;
    backdrop-filter: blur(4px);
    min-height: 48px;
    gap: 12px;
    box-sizing: border-box;
}

.topbar-left,
.topbar-center,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-left  { flex: 0 0 auto; }
.topbar-center { flex: 1 1 auto; justify-content: center; }
.topbar-right { flex: 0 0 auto; justify-content: flex-end; }

.topbar-login {
    color: #c9a84c;
    font-size: 0.9em;
    font-weight: bold;
    white-space: nowrap;
}

.topbar-logout {
    background: none;
    border: none;
    color: #c9a84c;
    font-size: 1.3em;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    line-height: 1;
}

.topbar-logout:hover {
    background: rgba(201, 168, 76, 0.15);
    color: #ffd700;
}

.topbar-title {
    color: #e8d5b0;
    font-size: 1em;
    font-weight: bold;
    text-align: center;
    white-space: nowrap;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.topbar-title br {
    display: none;
}

.topbar-vs {
    color: #c9a84c;
    font-size: 0.85em;
    margin: 0 6px;
}

.topbar-back {
    padding: 6px 14px;
    font-size: 0.9em;
    color: #c9a84c;
    background: rgba(0,0,0,0.4);
    border: 1px solid #6b5a40;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.topbar-back:hover {
    background: rgba(0,0,0,0.6);
    border-color: #c9a84c;
}

.topbar-btn {
    padding: 6px 18px;
    font-size: 0.9em;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(145deg, #5a4a30, #3a2a18);
    border: 1px solid #6b5a40;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.topbar-btn:hover:not(:disabled) {
    border-color: #c9a84c;
    background: linear-gradient(145deg, #6b5a40, #4a3a28);
}

.topbar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.topbar-btn-primary {
    background: linear-gradient(145deg, #8b6914, #6b4f10);
    border-color: #c9a84c;
}

.topbar-btn-primary:hover:not(:disabled) {
    background: linear-gradient(145deg, #a88018, #8b6914);
    box-shadow: 0 2px 10px rgba(201, 168, 76, 0.3);
}

.topbar-points {
    font-size: 0.95em;
    color: #c9a84c;
    font-weight: bold;
    white-space: nowrap;
}

.topbar-points-over {
    color: #ff4444;
}

/* Очки славы в заголовке "Набор армии": 🌟 93 — Набор армии — Faction */
.army-title-fame {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #ffd700;
    font-weight: 900;
    font-size: 1.15em;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.7), 2px 2px 4px rgba(0, 0, 0, 0.8);
    filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.5));
    white-space: nowrap;
}

.army-title-fame-icon {
    width: 28px;
    height: 28px;
    vertical-align: middle;
    filter: drop-shadow(0 0 4px rgba(255, 215, 0, 0.6));
}

/* Иконка fame_points в стоимости карточки юнита */
.army-card-cost-icon {
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    vertical-align: middle;
    margin-right: 3px;
    object-fit: contain;
    flex-shrink: 0;
    filter: drop-shadow(0 0 3px rgba(255, 215, 0, 0.5));
}

/* Компактная кнопка-стрелка (без текста) */
.topbar-back-icon {
    padding: 6px 10px;
    font-size: 1.1em;
    line-height: 1;
}

/* Компактная кнопка-иконка (корзинка и т.п.) */
.topbar-icon-btn {
    padding: 6px 10px;
    font-size: 1.1em;
    line-height: 1;
    min-width: auto;
}

/* Адаптивность topbar */
@media (max-width: 768px) {
    .topbar { padding: 6px 8px; gap: 6px; }
    .topbar-title {
        font-size: 0.75em;
        white-space: normal;
        line-height: 1.3;
        max-height: 2.6em;
        overflow: hidden;
    }
    .topbar-title br {
        display: inline;
    }
    .topbar-login { font-size: 0.8em; }
    .topbar-btn { padding: 5px 10px; font-size: 0.8em; }
    .topbar-back { padding: 5px 8px; font-size: 0.8em; }
    .topbar-back-icon { padding: 5px 8px; font-size: 1em; }
    .topbar-icon-btn { padding: 5px 8px; font-size: 1em; }
    .topbar-left, .topbar-right { gap: 6px; }
    .topbar-center { gap: 6px; }
}

/* ==================== МОДАЛКА РЕЗУЛЬТАТА БОЯ ==================== */
.battle-result-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(30, 20, 10, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 12px;
}
.battle-result-overlay:not(.hidden) {
    opacity: 1;
}
.battle-result-modal {
    background: url('../card_background.jpg') center/cover no-repeat;
    border: 3px solid #8b7355;
    border-radius: 16px;
    padding: 24px 20px;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.6), inset 0 0 60px rgba(0, 0, 0, 0.15);
    transform: scale(0.85);
    transition: transform 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}
/* Полупрозрачный тёмный слой поверх фона для читаемости */
.battle-result-modal::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(40, 28, 16, 0.72);
    border-radius: 13px;
    z-index: 0;
    pointer-events: none;
}
.battle-result-header,
.battle-result-stats,
.battle-result-buttons {
    position: relative;
    z-index: 1;
}
.battle-result-overlay:not(.hidden) .battle-result-modal {
    transform: scale(1);
}
.battle-result-header {
    text-align: center;
    margin-bottom: 16px;
}
.battle-result-header h2 {
    font-size: 1.6em;
    font-weight: 900;
    margin: 0 0 4px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}
.battle-result-header h2.result-win {
    color: #e8c840;
    text-shadow: 0 0 20px rgba(232, 200, 64, 0.5);
}
.battle-result-header h2.result-lose {
    color: #cc5544;
    text-shadow: 0 0 20px rgba(204, 85, 68, 0.5);
}
.battle-result-header h2.result-draw {
    color: #b0a090;
    text-shadow: 0 0 20px rgba(176, 160, 144, 0.4);
}
.battle-result-subtitle {
    color: #a89070;
    font-size: 0.8em;
}
.battle-result-stats {
    margin-bottom: 20px;
}
.battle-result-table {
    width: 100%;
    border-collapse: collapse;
}
.battle-result-table th {
    padding: 6px 8px;
    font-size: 0.75em;
    font-weight: bold;
    text-align: center;
    border-bottom: 1px solid rgba(139, 115, 85, 0.4);
}
.battle-result-table td {
    padding: 8px 8px;
    text-align: center;
    font-size: 0.85em;
}
.stat-name-col {
    width: 38%;
    text-align: left !important;
    color: #9a8060;
    font-size: 0.75em;
}
.stat-player-col {
    color: #c9a84c;
}
.stat-enemy-col {
    color: #b07844;
}
.stat-label {
    color: #a89070;
    text-align: left !important;
}
.stat-player-val {
    color: #d8d0c0;
    font-weight: bold;
}
.stat-enemy-val {
    color: #c8c0b0;
    font-weight: bold;
}
.battle-result-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.battle-result-btn {
    padding: 10px 20px;
    font-size: 0.9em;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid;
    transition: transform 0.15s, box-shadow 0.15s;
    flex: 1;
}
.battle-result-btn:hover {
    transform: scale(1.03);
}
.battle-result-btn:active {
    transform: scale(0.97);
}
.btn-retry {
    background: linear-gradient(135deg, #4a4030, #5a5040);
    border-color: #8a7a60;
    color: #e0d8c8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.btn-retry:hover {
    box-shadow: 0 4px 16px rgba(138, 122, 96, 0.4);
    border-color: #a09080;
}
.btn-menu {
    background: linear-gradient(135deg, #3a3028, #4a4038);
    border-color: #6a5a48;
    color: #c8b8a0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.btn-menu:hover {
    box-shadow: 0 4px 16px rgba(106, 90, 72, 0.4);
    border-color: #8a7860;
}

/* ==================== АДАПТИВ ВЕЕРА НА МАЛЕНЬКИХ ЭКРАНАХ ==================== */
@media (max-width: 680px) {
    /* На мобильных — меньше перекрытие и меньше повороты */
    #p2-hand .card {
        margin-left: calc(var(--card-w) * -0.6);
    }
    #p2-hand .card:nth-child(1) { transform: rotate(-2deg); }
    #p2-hand .card:nth-child(2) { transform: rotate(-1deg); }
    #p2-hand .card:nth-child(3) { transform: rotate(0deg); }
    #p2-hand .card:nth-child(4) { transform: rotate(1deg); }
    #p2-hand .card:nth-child(5) { transform: rotate(2deg); }
    #p2-hand .card.card-selected {
        transform: translateY(-18px) scale(1.05) rotate(0deg) !important;
    }
    #p1-hand .card {
        margin-left: calc(var(--card-w) * -0.7);
    }
    #p1-hand .card:nth-child(1) { transform: rotate(2deg); }
    #p1-hand .card:nth-child(2) { transform: rotate(1deg); }
    #p1-hand .card:nth-child(3) { transform: rotate(0deg); }
    #p1-hand .card:nth-child(4) { transform: rotate(-1deg); }
    #p1-hand .card:nth-child(5) { transform: rotate(-2deg); }
    /* Стопки на мобильных — фиксированный размер, без сжатия */
    .deck-pile {
        width: calc(var(--deck-w) + 4px);
    }
    .player-cards-area {
        padding: 2px 4px;
        gap: 0;
        min-height: calc(var(--deck-h) + 8px);
    }
    .hand {
        margin: 0 calc(var(--card-w) * 0.1);
    }
    /* На мобильных — колоды в потоке по бокам от веера (не absolute) */
    .deck-pile {
        position: relative !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        flex-shrink: 0 !important;
    }
}

/* На очень маленьких экранах: колоды по бокам от веера */
@media (max-width: 440px) {
    .battlefield { padding: 0 2px; }
    .player-zone { padding: 8px 4px 6px; overflow: visible; }
    /* Возвращаем flex, но с колодами по бокам */
    .player-cards-area {
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        align-items: flex-end !important;
        gap: 2px !important;
        padding: 4px 2px !important;
        min-height: auto !important;
    }
    /* Рука — по центру, занимает доступное место */
    .hand {
        flex: 1 1 auto !important;
        width: auto !important;
        min-height: auto !important;
        justify-content: center !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
    }
    /* Колоды — фиксированные по бокам (переопределяем absolute из десктопа) */
    .deck-pile {
        position: relative !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        flex-shrink: 0 !important;
    }
}

/* ==================== АДАПТИВ МОДАЛКИ ДЛЯ МАЛЕНЬКИХ ЭКРАНОВ ==================== */
@media (max-width: 480px) {
    .battle-result-overlay {
        padding: 8px;
        align-items: center;
    }
    .battle-result-modal {
        padding: 18px 14px;
        border-radius: 12px;
        max-height: 85vh;
    }
    .battle-result-header h2 {
        font-size: 1.3em;
    }
    .battle-result-subtitle {
        font-size: 0.7em;
    }
    .battle-result-table th {
        padding: 4px 4px;
        font-size: 0.65em;
    }
    .battle-result-table td {
        padding: 6px 4px;
        font-size: 0.75em;
    }
    .stat-name-col {
        font-size: 0.65em;
    }
    .battle-result-buttons {
        flex-direction: column;
        gap: 8px;
    }
    .battle-result-btn {
        padding: 12px 16px;
        font-size: 0.85em;
    }
    .autodraft-bar {
        gap: 6px;
        padding: 6px 8px 12px;
    }
    .autodraft-card {
        width: 100px;
        padding: 10px 8px;
    }
    .autodraft-icon {
        font-size: 1.5em;
    }
    .autodraft-name {
        font-size: 0.85em;
    }
    .autodraft-desc {
        font-size: 0.6em;
    }
}
