:root {
    --primary: #FF4757;
    --primary-alt: #2F3542;
    --secondary: #747D8C;
    --accent: #ECCC68;
    --bg: #F1F2F6;
    --text: #2F3542;
    --text-muted: #747D8C;
    --font-main: 'Rajdhani', sans-serif;
    --font-title: 'Orbitron', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { 
    background: var(--bg); 
    color: var(--text); 
    font-family: var(--font-main); 
    overflow: hidden; 
}

#game-wrapper {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Compact Header */
#game-header {
    background: #FFF;
    border-bottom: 2px solid #EDF2F7;
    height: 40px; /* Fixed height */
    padding: 0 20px;
    display: flex;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    z-index: 100;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 15px;
    max-width: 1200px;
    margin: 0 auto;
}

.mini-logo {
    height: 35px;
    width: auto;
}

.header-title h1 {
    font-family: var(--font-title);
    font-size: 1.2rem;
    font-weight: 900;
    color: var(--primary-alt);
    letter-spacing: 1px;
}

.header-title h1 span {
    color: var(--primary);
}

/* Battle Screen Layout */
#battle-screen {
    height: calc(100vh - 40px);
    display: flex;
    padding: 10px;
    overflow: hidden;
}

.layout-container {
    display: flex;
    gap: 15px;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    overflow: hidden;
}

main {
    flex: 1;
    background: #FFF;
    border-radius: 24px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    overflow: hidden;
    position: relative;
}

#phaser-game-container {
    width: 100%;
    max-width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Sidebar */
#sidebar {
    width: 260px;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative; /* For absolute button */
    padding-bottom: 60px; /* Space for the fixed button at bottom */
    flex-shrink: 0;
}

#game-stats-vertical {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    padding-right: 5px;
}

/* Home Screen & Selection */
#home-screen {
    position: absolute;
    top: 50px;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
}

.home-content {
    width: 100%;
    max-width: 800px;
    padding: 20px;
    text-align: center;
}

.logo-huge {
    margin-bottom: 20px;
}

.main-logo-img {
    height: 150px;
    width: auto;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.1));
}

.title-gradient {
    font-family: var(--font-title);
    font-weight: 900;
    background: linear-gradient(45deg, var(--primary-alt), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 20px;
    font-size: 1.8rem;
}

/* Hero Selection Grid */
.hero-selection-large {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin: 15px 0;
    max-height: calc(100vh - 350px); /* Limit height to fit screen */
    overflow-y: auto;
    padding: 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

.hero-card-large {
    background: #FFF;
    border: 3px solid transparent;
    border-radius: 18px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.hero-card-large:hover {
    transform: translateY(-5px);
    border-color: var(--accent);
}

.hero-card-large.selected {
    border-color: var(--primary);
    background: #FFF5F5;
    box-shadow: 0 0 20px rgba(255, 71, 87, 0.2);
}

.hero-preview-xl {
    width: 65px;
    height: 65px;
    margin: 0 auto 8px;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}

.hero-card-large h3 {
    font-family: var(--font-title);
    font-size: 0.9rem;
    font-weight: 700;
}

/* Selection Flow UI */
.selection-header-split {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #EDF2F7;
    padding-bottom: 15px;
    margin-bottom: 15px;
}

.p1-choice-display {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #FFF;
    padding: 8px 15px;
    border-radius: 50px;
    border: 2px solid var(--primary);
}

.p1-choice-display span {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--primary);
}

.hero-preview-small {
    width: 30px;
    height: 30px;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}

/* Previews Mapping */
.hero-preview-xl.soldier, .hero-preview-large.soldier, .hero-preview-small.soldier { background-image: url('assets/units/soldier_rifle.png'); }
.hero-preview-xl.ninja, .hero-preview-large.ninja, .hero-preview-small.ninja { background-image: url('assets/units/ninja_sword.png'); }
.hero-preview-xl.samurai, .hero-preview-large.samurai, .hero-preview-small.samurai { background-image: url('assets/units/samurai_katana.png'); }
.hero-preview-xl.muaythai, .hero-preview-large.muaythai, .hero-preview-small.muaythai { background-image: url('assets/units/muaythai_punch.png'); }
.hero-preview-xl.viking, .hero-preview-large.viking, .hero-preview-small.viking { background-image: url('assets/units/viking_axe.png'); }
.hero-preview-xl.cyber, .hero-preview-large.cyber, .hero-preview-small.cyber { background-image: url('assets/units/cyber_android.png'); }
.hero-preview-xl.knight, .hero-preview-large.knight, .hero-preview-small.knight { background-image: url('assets/units/knight_sword.png'); }

/* Level Selection Grid */
.level-selection-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin: 20px 0;
}

@media (max-width: 768px) {
    .level-selection-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.level-card {
    background: #FFF;
    border-radius: 12px;
    padding: 15px 10px;
    cursor: pointer;
    border: 2px solid #EDF2F7;
    transition: all 0.2s;
    text-align: center;
}

.level-card span {
    display: block;
    font-family: var(--font-title);
    font-weight: 900;
    font-size: 1.2rem;
    margin-bottom: 5px;
}

.level-card p {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Level Colors */
.level-card[data-level="1"] span { color: #27ae60; }
.level-card[data-level="2"] span { color: #2ecc71; }
.level-card[data-level="3"] span { color: #f1c40f; }
.level-card[data-level="4"] span { color: #f39c12; }
.level-card[data-level="5"] span { color: #e67e22; }
.level-card[data-level="6"] span { color: #d35400; }
.level-card[data-level="7"] span { color: #e74c3c; }
.level-card[data-level="8"] span { color: #c0392b; }
.level-card[data-level="9"] span { color: #8e44ad; }
.level-card[data-level="10"] span { color: #2c3e50; font-size: 1.4rem; text-shadow: 0 0 10px rgba(44, 62, 80, 0.3); }

.level-card:hover { transform: scale(1.05); border-color: var(--accent); }
.level-card.selected { border-color: var(--primary); background: #FFF5F5; box-shadow: 0 0 15px rgba(255, 71, 87, 0.1); }

/* Map Cards */
.map-selection {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.map-card {
    background: #FFF;
    padding: 20px;
    border-radius: 15px;
    border: 2px solid transparent;
    font-family: var(--font-title);
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.map-card.selected {
    border-color: var(--primary);
    background: #FFF5F5;
}

/* Buttons */
.primary-btn {
    background: var(--primary);
    color: #FFF;
    border: none;
    padding: 15px 30px;
    border-radius: 12px;
    font-family: var(--font-title);
    font-weight: 900;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 0 #D63031;
    transition: all 0.1s;
    width: 100%;
}

.btn-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 20px;
}

.primary-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #D63031; }

/* Summary Box */
.summary-box {
    background: #FFF;
    border-radius: 20px;
    padding: 20px;
    margin: 20px 0;
    border: 2px solid #EDF2F7;
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 15px;
}

.summary-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.summary-item label {
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.summary-item span {
    font-family: var(--font-title);
    font-weight: 900;
    font-size: 0.9rem;
    color: var(--primary-alt);
}

@media (max-width: 768px) {
    .summary-box { flex-direction: column; gap: 10px; }
}

#back-btn {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 10;
    background: var(--primary-alt);
    color: #FFF;
    border: none;
    padding: 12px;
    border-radius: 10px;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    box-shadow: 0 4px 0 #1A1A1A;
    transition: all 0.1s;
}

.back-step, .secondary-btn {
    background: var(--primary-alt);
    color: #FFF;
    border: none;
    padding: 12px;
    border-radius: 10px;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    box-shadow: 0 4px 0 #1A1A1A;
    transition: all 0.1s;
    width: 100%;
    margin-top: 15px;
}

#back-btn:hover {
    background: #3E4451;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #1A1A1A;
}

#back-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #1A1A1A;
}

/* Modals */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(47, 53, 66, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
}

.modal {
    background: #FFF;
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    animation: zoomIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes zoomIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Sidebar Stats Details */
.player-stat-v { 
    background: #FFF; 
    border: 2px solid #EDF2F7; 
    border-radius: 15px; 
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.player-stat-v.active { border-color: var(--primary); box-shadow: 0 10px 20px rgba(255, 71, 87, 0.1); }

.hero-preview-large { width: 50px; height: 50px; background-size: contain; background-position: center; background-repeat: no-repeat; }

.health-bar { height: 8px; background: #EDF2F7; border-radius: 4px; overflow: hidden; margin: 8px 0; }
.black .health-bar .fill { background: var(--primary-alt); }
.white .health-bar .fill { background: var(--primary); }

.score-row .score { font-size: 2rem; font-weight: 900; }
.vs-divider { font-family: var(--font-title); font-weight: 900; color: #EDF2F7; font-size: 2rem; text-align: center; }

#main-footer {
    display: none; /* Removed completely to save space */
}

.hidden { display: none !important; }

/* Mobile Responsive */
@media (max-width: 768px) {
    #game-header {
        height: 35px;
        padding: 0 10px;
    }
    .header-title h1 { font-size: 0.9rem; }
    .mini-logo { height: 25px; }

    .layout-container {
        flex-direction: column;
        gap: 10px;
        padding: 5px;
    }

    main {
        order: 1; /* Game first */
        border-radius: 15px;
    }

    #sidebar {
        order: 2; /* Stats below game */
        width: 100%;
        height: auto;
        padding-bottom: 70px; /* Space for the absolute button */
    }

    #game-stats-vertical {
        flex-direction: row; /* Horizontal stats on mobile */
        justify-content: space-around;
        gap: 5px;
    }

    .player-stat-v {
        flex: 1;
        padding: 8px;
        font-size: 0.8rem;
    }

    .hero-preview-large { width: 35px; height: 35px; }
    .score-row .score { font-size: 1.2rem; }
    .vs-divider { font-size: 1.2rem; margin: 0 5px; }

    /* Hero Selection Mobile */
    .hero-selection-large {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        max-height: calc(100vh - 250px);
    }
    .hero-card-large { padding: 8px; border-radius: 12px; }
    .hero-preview-xl { width: 50px; height: 50px; }
    .hero-card-large h3 { font-size: 0.75rem; }

    .selection-header-split { flex-direction: column; gap: 10px; }
    .title-gradient { font-size: 1.4rem; }

    #back-btn {
        position: fixed; /* Keep it fixed at the very bottom on mobile */
        bottom: 10px;
        right: 10px;
        width: calc(100% - 20px);
        left: 10px;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--secondary); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }
