* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}
body {
    background: #0a0b0c;
    overflow: hidden;
    font-family: 'Cinzel', 'Segoe UI', serif;
}
canvas {
    display: block;
    width: 100vw;
    height: 100vh;
    cursor: crosshair;
}

/* Контейнер для статистики справа */
.stats-container {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    transition: opacity 0.3s;
}
.stats-toggle {
    background: #332918;
    border: 3px solid #d4a448;
    border-radius: 50px 50px 0 0;
    color: #ffdb8e;
    font-size: 24px;
    padding: 8px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: none;
    box-shadow: 0 -5px 20px black;
    transition: 0.3s;
    margin-bottom: -3px;
}
.stats-toggle:hover {
    background: #4a3a28;
}
.stats-toggle .burger-icon {
    font-size: 28px;
    line-height: 1;
}
.stats-toggle .stats-title-mini {
    font-size: 18px;
    font-weight: bold;
    color: gold;
}
.stats-panel {
    background: rgba(10, 8, 6, 0.95);
    border: 3px solid #d4a448;
    border-radius: 30px 0 30px 30px;
    padding: 20px;
    color: #f0d5b0;
    width: 350px;
    backdrop-filter: blur(8px);
    transition: 0.3s;
    border-top: 3px solid #d4a448;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.stats-panel.collapsed {
    display: none;
}
.stats-title {
    font-size: 24px;
    text-align: center;
    margin-bottom: 5px;
    color: gold;
    border-bottom: 2px solid #aa7a55;
    padding-bottom: 10px;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 15px;
}
.stat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #2f2720;
    border: 2px solid #6b4f38;
    border-radius: 20px;
    padding: 10px;
}
.stat-icon {
    font-size: 28px;
    min-width: 40px;
    text-align: center;
}
.stat-info {
    display: flex;
    flex-direction: column;
    font-size: 14px;
}
.stat-label {
    color: #b8a88b;
}
.stat-value {
    color: gold;
    font-size: 18px;
    font-weight: bold;
}

/* Кнопка выхода */
.logout-container {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 300;
    margin-top: 70px; /* чтобы не перекрывать статистику */
    display: none; /* скрыта по умолчанию */
}
.logout-btn {
    background: #332918;
    border: 2px solid #d4a448;
    border-radius: 30px;
    color: #ffdb8e;
    font-size: 18px;
    padding: 8px 15px;
    cursor: pointer;
    transition: 0.3s;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
.logout-btn:hover {
    background: #4a3a28;
    transform: translateY(-2px);
}

/* Нижняя панель */
#ui {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    margin: auto;
    width: 1400px;
    background: rgba(10, 8, 6, 0.95);
    backdrop-filter: blur(8px);
    border: 3px solid #d4a448;
    border-radius: 50px;
    padding: 5px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #f0d5b0;
    font-size: 20px;
    font-weight: bold;
    z-index: 100;
    box-shadow: 0 10px 30px black;
    transition: opacity 0.3s;
}
.stats {
    display: flex;
    gap: 30px;
}
.hp-mana {
    display: flex;
    min-width: 345px;
    gap: 20px;
    align-items: center;
}
.bar-container {
    width: 200px;
    height: 25px;
    background: #2e1d14;
    border: 2px solid #6b3c25;
    border-radius: 15px;
    overflow: hidden;
}
.hp-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #c92f0a, #ec7e5a);
}
.mana-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #286bb8, #6bb1ff);
}
.gold-box {
    background: #332918;
    border: 2px solid #d4a448;
    border-radius: 50px;
    padding: 8px 30px;
    color: #ffdb8e;
    font-size: 24px;
    transition: opacity 0.3s;
}
.attack-buttons {
    display: flex;
    gap: 8px;
    pointer-events: auto !important;
}
.attack-btn {
    background: #2a2a2a;
    border: 2px solid #d4a448;
    border-radius: 15px;
    color: #f0d5b0;
    font-size: 13px;
    cursor: pointer;
    transition: 0.1s;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 70px;
    box-shadow: 0 5px 10px black;
    position: relative;
    pointer-events: auto !important;
    -webkit-tap-highlight-color: rgba(255, 215, 0, 0.3);
}
.attack-btn.pressed {
    border-color: gold;
    box-shadow: 0 0 15px gold;
    transition: 0.05s;
}
.attack-btn .key {
    color: gold;
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 2px;
}
.attack-btn .name {
    font-size: 11px;
    color: #ffdb8e;
}
.attack-btn .cost {
    color: #6bb1ff;
    font-size: 10px;
    margin-top: 2px;
}
.attack-btn .cooldown {
    font-size: 9px;
    color: #aaa;
    margin-top: 2px;
}

/* Магазин */
.shop-container {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    transition: opacity 0.3s;
}
.shop-toggle {
    background: #332918;
    border: 3px solid #d4a448;
    border-radius: 50px 50px 0 0;
    color: #ffdb8e;
    font-size: 24px;
    padding: 8px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: none;
    box-shadow: 0 -5px 20px black;
    transition: 0.3s;
    margin-bottom: -3px;
}
.shop-toggle:hover {
    background: #4a3a28;
}
.shop-toggle .burger-icon {
    font-size: 28px;
    line-height: 1;
}
.shop-toggle .shop-title-mini {
    font-size: 18px;
    font-weight: bold;
    color: gold;
}
.shop {
    background: rgba(10, 8, 6, 0.95);
    border: 3px solid #d4a448;
    border-radius: 0 30px 30px 30px;
    padding: 20px;
    color: #f0d5b0;
    width: 350px;
    backdrop-filter: blur(8px);
    transition: 0.3s;
    border-top: 3px solid #d4a448;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.shop.collapsed {
    display: none;
}
.shop.inactive {
    opacity: 0.6;
    border-color: #6b4f38;
    filter: grayscale(0.5);
}
.shop-title {
    font-size: 24px;
    text-align: center;
    margin-bottom: 15px;
    color: gold;
    border-bottom: 2px solid #aa7a55;
    padding-bottom: 10px;
}
.shop-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: #2f2720;
    border-radius: 20px;
    border: 2px solid #6b4f38;
}
.shop-item button {
    background: #6d3c2b;
    color: white;
    border: none;
    border-bottom: 4px solid #3f241b;
    padding: 8px 20px;
    border-radius: 30px;
    font-size: 16px;
    cursor: pointer;
    transition: 0.07s;
}
.shop-item button:hover:not(:disabled) {
    background: #8b5a3c;
    transform: translateY(-2px);
}
.shop-item button:active:not(:disabled) {
    transform: translateY(2px);
    border-bottom-width: 2px;
}
.shop-item button:disabled {
    background: #444;
    border-bottom-color: #222;
    cursor: not-allowed;
    transform: none;
    opacity: 0.5;
}
.shop-item span {
    font-size: 18px;
}

/* Лог */
#log {
    position: absolute;
    top: 20px;
    right: 400px;
    min-width: 300px;
    max-width: 400px;
    background: rgba(0,0,0,0.85);
    border: 2px solid gold;
    border-radius: 20px;
    padding: 0;
    color: gold;
    font-size: 20px;
    font-weight: bold;
    z-index: 100;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 15px;
    background: rgba(0,0,0,0.3);
    border-bottom: 1px solid #d4a448;
    cursor: pointer;
}
.log-current {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 10px;
}
.log-burger {
    font-size: 24px;
    line-height: 1;
    color: gold;
    transition: transform 0.2s;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0 5px;
}
.log-burger:hover {
    transform: scale(1.2);
    color: #ffaa00;
}
.log-history {
    max-height: 0;
    overflow-y: auto;
    transition: max-height 0.3s ease-out;
    background: rgba(20, 15, 10, 0.95);
    border-top: 1px solid #aa7a55;
}
.log-history.expanded {
    max-height: 300px;
}
.log-entry {
    padding: 6px 12px;
    font-size: 14px;
    border-bottom: 1px solid #3f2e1e;
    color: #e0c8a8;
    word-wrap: break-word;
    white-space: normal;
}
.log-entry.good {
    color: #e0c8a8;
}
.log-entry.bad {
    color: #ff7b6b;
}

/* Кнопки действий */
.action-buttons {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 100;
    flex-wrap: wrap;
    justify-content: center;
    width: 1500px;
    transition: opacity 0.3s;
}
.action-btn {
    background: #6d3c2b;
    color: white;
    border: none;
    border-bottom: 5px solid #3f241b;
    font-size: 12px;
    border-radius: 50px;
    cursor: pointer;
    transition: 0.07s;
    box-shadow: 0 10px 20px black;
    min-width: 180px;
}
.action-btn:hover:not(:disabled) {
    background: #8b5a3c;
    transform: translateY(-2px);
}
.action-btn:active:not(:disabled) {
    transform: translateY(3px);
    border-bottom-width: 2px;
}
.action-btn:disabled {
    background: #3a2a20;
    border-bottom-color: #1f150f;
    color: #7a6a5a;
    cursor: not-allowed;
    opacity: 0.7;
}
#nextLevelBtn {
    background: #2a5f7a;
    border-bottom-color: #1a3a4a;
}
#nextLevelBtn:hover:not(:disabled) {
    background: #3a7f9a;
}
#prevLevelBtn {
    background: #7a4f2a;
    border-bottom-color: #4a2f1a;
}
#prevLevelBtn:hover:not(:disabled) {
    background: #9a6f3a;
}
#saveJsonGameBtn {
    background: #2a5f7a;
    border-bottom-color: #1a3a4a;
}
#saveJsonGameBtn:hover:not(:disabled) {
    background: #3a7f9a;
}

/* Информационные панели */
.distance-info {
    position: absolute;
    bottom: 110px;
    right: 20px;
    background: rgba(0,0,0,0.7);
    border: 2px solid #6b4f38;
    border-radius: 20px;
    padding: 10px 20px;
    color: #b8a88b;
    font-size: 16px;
    z-index: 100;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s;
}
.enemy-count {
    position: absolute;
    bottom: 110px;
    left: 20px;
    background: rgba(0,0,0,0.7);
    border: 2px solid #6b4f38;
    border-radius: 20px;
    padding: 10px 20px;
    color: #b8a88b;
    font-size: 16px;
    z-index: 100;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s;
}
.level-info {
    position: absolute;
    top: 20px;
    left: 400px;
    min-width: 360px;
    background: rgba(0,0,0,0.7);
    border: 2px solid gold;
    border-radius: 20px;
    padding: 5px 20px;
    color: gold;
    font-size: 20px;
    font-weight: bold;
    z-index: 100;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s;
}
.selected-enemy {
    position: absolute;
    top: 20px;
    left: 870px;
    background: rgba(0,0,0,0.7);
    border: 2px solid #ffaa00;
    border-radius: 20px;
    padding: 8px 20px;
    color: #ffaa00;
    font-size: 14px;
    z-index: 100;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s;
}

/* Кнопка выбора ближайшего врага */
.select-enemy-btn {
    position: absolute;
    bottom: 280px;
    left: 50%;
    transform: translateX(-50%);
    background: #332918;
    border: 3px solid #d4a448;
    border-radius: 50px;
    color: #ffdb8e;
    font-size: 18px;
    padding: 12px 30px;
    cursor: pointer;
    z-index: 200;
    box-shadow: 0 10px 20px black;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    backdrop-filter: blur(4px);
}
.select-enemy-btn:hover {
    background: #4a3a28;
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 15px 25px black;
}
.select-enemy-btn:active {
    transform: translateX(-50%) translateY(2px);
}
.select-enemy-btn.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .select-enemy-btn {
        bottom: 140px;
        font-size: 16px;
        padding: 10px 25px;
    }
    .select-enemy-btn.mobile-only {
        display: flex;
    }
    .select-enemy-btn.pc-only {
        display: none;
    }
    #log {
        right: 5px;
        min-width: 220px;
        max-width: 280px;
    }
}

/* Класс для скрытия интерфейса */
.hide-interface .gold-box,
.hide-interface .action-buttons,
.hide-interface .shop-container,
.hide-interface .stats-container,
.hide-interface #log,
.hide-interface .distance-info,
.hide-interface .enemy-count,
.hide-interface .level-info,
.hide-interface .selected-enemy,
.hide-interface .zone-status,
.hide-interface .save-info,
.hide-interface #ui .stats .hp-mana,
.hide-interface #ui .stats .attack-buttons .attack-btn .name,
.hide-interface #ui .stats .attack-buttons .attack-btn .cost,
.hide-interface #ui .stats .attack-buttons .attack-btn .cooldown,
.hide-interface .select-enemy-btn {
    opacity: 0 !important;
    pointer-events: none !important;
}
.hide-interface #ui .stats .hp-mana,
.hide-interface .gold-box,
.hide-interface #ui .stats .attack-buttons,
.hide-interface #ui .stats .attack-buttons .attack-btn,
.hide-interface #ui .stats .attack-buttons .attack-btn .key,
.hide-interface #ui .stats .attack-buttons .attack-btn .name,
.hide-interface #ui .stats .attack-buttons .attack-btn .cost,
.hide-interface #ui .stats .attack-buttons .attack-btn .cooldown {
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Мобильная адаптация */
@media (max-width: 768px) {
    .stats-container {
        top: 5px;
        right: 5px;
    }
    .stats-toggle {
        font-size: 20px;
        padding: 5px 15px;
    }
    .stats-toggle .burger-icon { font-size: 24px; }
    .stats-toggle .stats-title-mini { font-size: 16px; }
    .stats-panel {
        width: 280px;
        padding: 15px;
    }
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .stat-item {
        padding: 8px;
    }
    .stat-icon { font-size: 24px; }
    .stat-value { font-size: 16px; }
    
    #ui {
        width: 98%;
        bottom: 5px;
        padding: 5px 8px;
        font-size: 14px;
        border-radius: 30px;
        flex-wrap: wrap;
        justify-content: center;
    }
    .stats {
        gap: 8px;
        flex-wrap: wrap;
        justify-content: center;
    }
    .hp-mana { gap: 5px; }
    .bar-container {
        width: 80px;
        height: 16px;
    }
    .gold-box {
        padding: 4px 15px;
        font-size: 18px;
    }
    .attack-buttons {
        margin-left: 0;
        gap: 3px;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }
    .attack-btn {
        width: 70px;
        font-size: 9px;
        padding: 5px 0;
        min-height: 50px;
        touch-action: manipulation;
    }
    .attack-btn .key { font-size: 14px; }
    .attack-btn .name { font-size: 8px; }
    .attack-btn .cost { font-size: 7px; }
    .attack-btn .cooldown { font-size: 6px; }
    
    .action-buttons {
        bottom: 140px;
        width: 500px;
        gap: 5px;
    }
    .action-btn {
        min-width: 30px;
        font-size: 10px;
        padding: 5px 8px;
        border-bottom-width: 3px;
    }
    
    .shop-container {
        top: 5px;
        left: 5px;
    }
    .shop-toggle {
        font-size: 20px;
        padding: 5px 15px;
    }
    .shop-toggle .burger-icon { font-size: 24px; }
    .shop-toggle .shop-title-mini { font-size: 16px; }
    .shop {
        width: 280px;
        padding: 15px;
    }
    
    .level-info {
        top: 45px;
        right: 5px;
        font-size: 12px;
        padding: 4px 12px;
    }
    .selected-enemy {
        top: 45px;
        left: 150px;
        font-size: 10px;
        padding: 4px 8px;
    }
}

/* Экран входа */
#loginOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: black;
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    color: gold;
    font-family: 'Cinzel', serif;
}
.login-box {
    background: rgba(20, 15, 10, 0.95);
    border: 4px solid #d4a448;
    border-radius: 40px;
    padding: 40px;
    width: 500px;
    backdrop-filter: blur(10px);
    box-shadow: 0 0 50px gold;
    text-align: center;
}
.login-box h2 {
    font-size: 32px;
    margin-bottom: 30px;
    border-bottom: 2px solid #aa7a55;
    padding-bottom: 15px;
}
.login-box input {
    width: 100%;
    padding: 15px;
    margin: 10px 0;
    background: #2f2720;
    border: 2px solid #6b4f38;
    border-radius: 30px;
    color: #f0d5b0;
    font-size: 18px;
    outline: none;
}
.login-box input:focus {
    border-color: gold;
}
.login-box button {
    background: #6d3c2b;
    color: white;
    border: none;
    border-bottom: 5px solid #3f241b;
    padding: 15px 20px;
    border-radius: 50px;
    font-size: 20px;
    margin: 15px 5px;
    cursor: pointer;
    transition: 0.1s;
    min-width: 120px;
}
.login-box button:hover {
    background: #8b5a3c;
    transform: translateY(-2px);
}
.login-box button:active {
    transform: translateY(3px);
    border-bottom-width: 2px;
}
.login-box .error {
    color: #ff7b6b;
    margin-top: 15px;
    font-size: 16px;
}
.json-controls {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    justify-content: center;
}
.json-controls button {
    background: #2a5f7a;
    border-bottom-color: #1a3a4a;
    font-size: 16px;
    padding: 10px;
    min-width: 100px;
}