@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* {
    box-sizing: border-box;
    image-rendering: pixelated;
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    line-height: 1.4;
    margin: 0;
    padding: 0;
}

body, html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background: #2a2a2a;
    overflow: hidden;
}

#game {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #f8f4e8;
    overflow: hidden;
}

.screen {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.screen.active {
    display: flex;
}

/* Главное меню с фоном */
#mainMenu {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    justify-content: center;
    align-items: center;
}

.menu-content {
    background: rgba(248, 244, 232, 0.9);
    border: 4px solid #8b7a6a;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 300px;
    box-shadow: 8px 8px 0 #5a4a3a;
}

.menu-content h1 {
    font-size: 18px;
    text-align: center;
    margin-bottom: 15px;
    color: #3a2a1a;
    text-shadow: 2px 2px 0 #b5a89a;
}

/* Общие элементы */
.screen-header {
    background: #d4c8b8;
    border-bottom: 4px solid #8b7a6a;
    padding: 8px 15px;
    text-align: center;
    flex-shrink: 0;
}

.screen-header h2 {
    color: #3a2a1a;
    font-size: 14px;
}

.screen-content {
    flex: 1;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow: hidden;
}

.screen-footer {
    background: #d4c8b8;
    border-top: 4px solid #8b7a6a;
    padding: 8px 15px;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-shrink: 0;
}

button {
    background: #e8dccc;
    border: 4px solid #8b7a6a;
    border-style: outset;
    color: #2a1a0a;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 10px;
    text-transform: uppercase;
    box-shadow: inset -2px -2px #b5a89a;
}

button:hover {
    background: #d8ccbc;
    border-style: inset;
    box-shadow: inset 2px 2px #8b7a6a;
}

/* Карта уровней */
#levelMap {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    background: #e8dccc;
    border: 4px solid #8b7a6a;
    padding: 20px;
}

#levelDisplay {
    font-size: 16px;
    color: #3a2a1a;
}

/* Подготовка и битва */
.preparation-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 15px;
    gap: 15px;
    overflow: hidden;
}

.battlefield-wrapper, .battlefield-container {
    background: #d4c8b8;
    border: 4px solid #8b7a6a;
    padding: 15px;
    flex-shrink: 0;
}

.battlefield-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.side-label {
    font-size: 10px;
    color: #3a2a1a;
    background: #e8dccc;
    padding: 4px 12px;
    border: 2px solid #8b7a6a;
}

#preparationBattlefield, #battlefield {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    min-height: 240px;
}

.player-side, .enemy-side {
    display: grid;
    grid-template-rows: repeat(3, 1fr);
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    flex: 1;
    justify-items: center;
}

.position {
    background: #c6b5a5;
    border: 4px solid #6b5a4a;
    width: 85px;
    height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px;
    cursor: pointer;
    transition: all 0.1s;
    position: relative;
}

.enemy-side .position {
    background: #b85c5c;
    border-color: #8b3a3a;
}

.position.selected-for-placement {
    border: 4px solid #ffaa33;
    box-shadow: 0 0 0 3px #ffdd88;
}

.position.selected {
    border: 4px solid #ffaa33;
}

.position:hover {
    filter: brightness(1.1);
}

.position .sprite {
    width: 48px;
    height: 48px;
    image-rendering: pixelated;
    background: #9a8a7a;
}

.enemy-side .position .sprite {
    background: #7a4a4a;
}

.position .unit-name {
    font-size: 7px;
    text-align: center;
    margin-top: 2px;
    color: #1a1a1a;
    max-width: 75px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.enemy-side .position .unit-name {
    color: #ffdddd;
}

.position .hp-bar {
    width: 100%;
    height: 4px;
    background: #4a3a2a;
    margin-top: 2px;
}

.enemy-side .position .hp-bar {
    background: #3a1a1a;
}

.position .hp-bar-fill {
    height: 100%;
    background: #c44;
}

.position .class-indicator {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 8px;
    height: 8px;
    border-radius: 0;
    border: 2px solid #333;
}

/* Ростер */
.roster-wrapper {
    background: #d4c8b8;
    border: 4px solid #8b7a6a;
    padding: 10px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.roster-wrapper h3 {
    font-size: 10px;
    margin-bottom: 8px;
    color: #3a2a1a;
    flex-shrink: 0;
}

#roster {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-content: flex-start;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding: 5px;
}

.roster-unit {
    background: #e8dccc;
    border: 4px solid #8b7a6a;
    padding: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 85px;
    transition: all 0.1s;
}

.roster-unit:hover {
    background: #d8ccbc;
    border-color: #ffaa33;
}

.roster-unit img {
    width: 48px;
    height: 48px;
    background: #9a8a7a;
}

.roster-unit span {
    margin-top: 3px;
    font-size: 7px;
    text-align: center;
}

/* Боевой интерфейс - без прокрутки */
.battle-top-bar {
    background: #e4d8c8;
    border-bottom: 4px solid #8b7a6a;
    padding: 6px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    height: 50px;
}

#turnOrderContainer {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

#turnOrderLabel {
    font-size: 8px;
    color: #3a2a1a;
}

#turnOrder {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    flex: 1;
    min-height: 30px;
}

.turn-order-icon {
    width: 28px;
    height: 28px;
    background: #9a8a7a;
    border: 3px solid #5a4a3a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
    position: relative;
    flex-shrink: 0;
}

.turn-order-icon.current {
    border: 3px solid #ffaa33;
    background: #c6a87a;
    transform: scale(1.05);
    margin: 0 2px;
}

#battleLog {
    background: #d4c8b8;
    border: 4px solid #8b7a6a;
    width: 250px;
    height: 38px;
    overflow-y: auto;
    padding: 4px 8px;
    font-size: 8px;
    color: #2a1a0a;
}

.battle-main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 12px;
    overflow: hidden;
    min-height: 0;
}

.battlefield-container {
    flex-shrink: 0;
}

.battle-bottom-panel {
    background: #e4d8c8;
    border-top: 4px solid #8b7a6a;
    padding: 8px 15px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    height: 160px;
}

#selectedUnitInfo {
    display: flex;
    gap: 20px;
    background: #d4c8b8;
    border: 4px solid #8b7a6a;
    padding: 6px 15px;
    color: #2a1a0a;
    font-size: 9px;
    flex-shrink: 0;
}

#abilitiesPanel {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-height: 0;
}

.ability-btn {
    background: #c6b5a5;
    border: 4px solid #6b5a4a;
    width: 80px;
    height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    padding: 4px;
}

.ability-btn .ability-icon {
    width: 40px;
    height: 40px;
    background: #9a8a7a;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 4px;
}

.ability-btn span {
    font-size: 7px;
    text-align: center;
    color: #1a1a1a;
}

.ability-btn:hover {
    background: #b5a494;
}

.ability-btn:hover::after {
    content: attr(data-description);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #2a1a0a;
    color: #e8dccc;
    padding: 6px 10px;
    white-space: nowrap;
    z-index: 1000;
    font-size: 8px;
    border: 2px solid #8b7a6a;
    margin-bottom: 3px;
}

.ability-btn.disabled {
    opacity: 0.4;
    pointer-events: none;
}

#battleControls {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-shrink: 0;
}

/* Архив */
#archiveTabs {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

#archiveContent {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    background: #e8dccc;
    border: 4px solid #8b7a6a;
    padding: 15px;
    min-height: 200px;
    overflow-y: auto;
    flex: 1;
}

.archive-card {
    background: #d4c8b8;
    border: 3px solid #8b7a6a;
    padding: 8px;
    width: 150px;
    color: #2a1a0a;
}

.archive-card img {
    width: 48px;
    height: 48px;
    display: block;
    margin: 0 auto 8px;
    background: #9a8a7a;
}

/* Настройки */
#settingsScreen .screen-content {
    align-items: center;
    justify-content: center;
}

#settingsScreen label {
    color: #2a1a0a;
    font-size: 10px;
    display: flex;
    gap: 15px;
    align-items: center;
}