@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Lato:wght@400;700&display=swap');

:root {
    /* --- THEME: ROYAL ARMOR --- */
    --bg-color: #050505;          
    --ui-bg: #101216;             
    --panel-bg: #1a1d23;          
    
    --gold: #c5a059;              
    --gold-bright: #ffd700;       
    --red: #a93226;               
    --green: #229954;             
    --blue: #2471a3;              
    
    --border-color: #c5a059;      
    --text: #e5e0d8;              
    
    /* Rarity Colors */
    --common: #aab7b8;
    --rare: #5dade2;
    --epic: #af7ac5;
    --legendary: #f4d03f;
    
    /* Fonts */
    --font-header: 'Cinzel', serif;
    --font-body: 'Lato', sans-serif;
    --font-mono: 'Courier New', monospace;
}

/* =========================================
   CORE LAYOUT (Updated for 16:9 Fix)
   ========================================= */

body {
    margin: 0; padding: 0;
    background-color: var(--bg-color); color: var(--text);
    font-family: var(--font-body);
    display: flex; justify-content: center; align-items: center;
    height: 100vh; overflow: hidden; user-select: none; position: relative;
}

body::before {
    content: ""; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1;
    background-image: url('assets/battle_left.png'), url('assets/battle_right.png');
    background-position: -40px center, right center; background-repeat: no-repeat;
    background-size: auto 100%; filter: blur(2px); transform: scale(1.02);
}

#game-container {
    display: flex; 
    width: 100vw;       /* Full Screen Width */
    height: 100vh;      /* Full Screen Height */
    background: #000; 
    /* Deep cinematic shadow */
    box-shadow: 0 0 80px rgba(0,0,0,1), 0 0 20px rgba(0,0,0,0.8);
    position: relative; 
    box-sizing: border-box; 
    margin: 0;
    overflow: hidden;
}

/* NEW: Wraps the canvas to handle centering and scaling */
#canvas-wrapper {
    flex-grow: 1;           /* Take all space not used by sidebar */
    height: 100%;
    display: flex;
    justify-content: center; /* Center horizontally */
    align-items: center;     /* Center vertically */
    background-color: #050505; /* Letterbox color (dark gray/black) */
    position: relative;
    overflow: hidden;
}

canvas {
    background-color: #080808; 
    cursor: crosshair; 
    /* Crisper rendering */
    image-rendering: -webkit-optimize-contrast;
    
    /* FORCE 16:9 ASPECT RATIO */
    aspect-ratio: 16 / 9;
    
    /* Scale to fit wrapper without stretching */
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    
    display: block;
    box-shadow: 0 0 20px rgba(0,0,0,0.5); /* Subtle shadow to separate from letterbox */
}

h1, h2, h3 { font-family: var(--font-header); letter-spacing: 1px; }

/* =========================================
   SIDEBAR (THE WARDROBE)
   ========================================= */

#sidebar {
    background: #0b0d10;
    border-left: 3px solid var(--gold);
    box-shadow: -10px 0 50px rgba(0,0,0,0.8);
    display: flex; flex-direction: column;
    
    /* WIDTH: 460px (Fixed) */
    width: 460px; 
    flex-shrink: 0; /* PREVENTS SQUASHING */
    
    z-index: 100; font-family: var(--font-body); user-select: none; height: 100vh;
}

/* --- HEADER --- */
.sidebar-header {
    background: linear-gradient(to bottom, #16120e, #0b0d10);
    border-bottom: 1px solid var(--border-color);
    padding: 10px; 
    text-align: center; box-shadow: 0 5px 20px rgba(0,0,0,0.5);
    flex-shrink: 0; z-index: 2;
}

.sidebar-header h1 {
    margin: 0; color: var(--text); font-family: var(--font-header);
    font-size: 20px; letter-spacing: 2px; text-transform: uppercase;
    text-shadow: 0 2px 10px rgba(0,0,0,1);
}

#display-commander {
    font-size: 10px; color: var(--gold); opacity: 0.8; margin-top: 1px;
    text-transform: uppercase; letter-spacing: 1px; font-family: var(--font-mono);
}

.level-container { width: 90%; margin: 4px auto; display: flex; flex-direction: column; gap: 2px; }
.level-text-row { display: flex; justify-content: space-between; font-size: 9px; color: #888; font-weight: bold; }
.xp-track { width: 100%; height: 4px; background: #000; border: 1px solid #333; border-radius: 2px; overflow: hidden; }
.xp-fill { height: 100%; background: var(--gold); width: 0%; box-shadow: 0 0 5px var(--gold); }
#online-count { font-size:9px; color:#2ecc71; margin-top:2px; font-family:'Courier New', monospace; opacity: 0.7; }

/* --- CONTENT AREA (SCROLLABLE) --- */
.sidebar-content {
    padding: 10px; 
    overflow-y: auto; flex: 1; display: flex; flex-direction: column;
    gap: 8px; /* Compact spacing */
    background-color: rgba(0,0,0,0.2);
    /* Ensure flex calculation handles overflow gracefully */
    min-height: 0; 
    justify-content: flex-start;
}

.sidebar-content::-webkit-scrollbar { width: 5px; }
.sidebar-content::-webkit-scrollbar-track { background: #080808; }
.sidebar-content::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }
.sidebar-content::-webkit-scrollbar-thumb:hover { background: var(--gold); }

/* --- RESOURCE GRID --- */
.stat-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
    background: rgba(0, 0, 0, 0.3); padding: 5px;
    border: 1px solid #333; border-radius: 4px;
}
.stat-cell {
    display: flex; justify-content: space-between; align-items: center;
    background: linear-gradient(to bottom, #1a1a1a, #111);
    padding: 4px 8px; border: 1px solid #2a2a2a; border-radius: 2px; font-size: 10px;
}
.stat-cell span:first-child { color: #888; text-transform: uppercase; font-weight: bold; letter-spacing: 0.5px; }
.stat-cell span:last-child { font-weight: bold; font-size: 12px; font-family: var(--font-mono); color: #fff; }

/* --- CONTROLS --- */
.controls-row { display: flex; gap: 4px; height: 32px; }
.controls-row button {
    background: linear-gradient(to bottom, #2a2a2a, #151515);
    border: 1px solid #444; color: #ccc; font-family: var(--font-header);
    font-size: 10px; text-transform: uppercase; cursor: pointer; flex: 1;
    transition: all 0.2s; font-weight: bold; display: flex; align-items: center; justify-content: center;
}
.controls-row button:hover { border-color: var(--gold); color: var(--gold); background: #333; }
#start-wave-btn {
    flex: 1.5; background: linear-gradient(to bottom, #3e2723, #1b100a);
    border: 1px solid var(--gold); color: var(--gold); font-size: 11px; letter-spacing: 1px;
}

.sub-controls-row {
    display: flex;
    gap: 8px; /* Increased gap for better separation */
    margin-top: 8px;
    padding: 0 2px;
}

/* Base Styles */
.sub-controls-row button {
    flex: 1;
    height: 38px; /* Taller, more clickable */
    font-family: var(--font-header);
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
.sub-controls-row button:hover { border-color: #555; color: #ccc; }

/* --- TOWER GRID --- */
.section-title {
    text-align: center; color: var(--gold); font-family: var(--font-header);
    font-size: 11px; letter-spacing: 2px; margin: 6px 0 3px 0; opacity: 0.9;
}
.section-title::before, .section-title::after {
    content: ""; display: inline-block; width: 25px; height: 1px; 
    background: var(--gold); vertical-align: middle; margin: 0 8px; opacity: 0.5;
}

#build-menu {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px; 
    padding: 0 2px;
}

/* Tower Button Container */
.tower-btn {
    position: relative;
    display: flex; 
    align-items: center; 
    justify-content: center;
    height: 60px;
    padding: 0 4px;
    background: #08090a;
    border: 1px solid #2a2a2a; 
    border-radius: 2px; 
    cursor: pointer; 
    transition: all 0.2s ease; 
    overflow: hidden;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

.tower-btn:hover {
    transform: translateY(-1px); 
    border-color: var(--gold); 
    background: linear-gradient(to bottom, #111, #08090a);
    box-shadow: 0 2px 8px rgba(0,0,0,0.8);
}

/* Icon Frame - Watermark Style */
.tower-icon-frame {
    position: absolute;
    top: 50%;
    right: -2px;
    transform: translateY(-50%);
    width: 60px; 
    height: 60px;
    background: transparent;
    border: none;
    box-shadow: none;
    display: flex; 
    justify-content: center; 
    align-items: center;
    pointer-events: none; 
    opacity: 0.6;
    filter: grayscale(0);
    z-index: 0; 
    transition: all 0.2s ease;
}

.tower-btn:hover .tower-icon-frame {
    opacity: 1.0;          
    transform: translateY(-50%) scale(1.1); 
}

.tower-icon-frame canvas {
    width: 48px !important; 
    height: 48px !important; 
}

/* Text Column */
.tower-info-col { 
    position: relative; 
    z-index: 2;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.tower-name { 
    color: #e5e0d8; 
    font-family: var(--font-header); 
    font-size: 11px; 
    font-weight: bold; 
    letter-spacing: 0.5px;
    text-transform: uppercase;
    text-shadow: 0 0 4px #000, 0 0 4px #000, 0 1px 2px black;
    white-space: normal;
    line-height: 1.1;
}

.tower-cost { 
    font-family: var(--font-mono); 
    font-size: 10px; 
    color: #aaa;
    margin-top: 2px;
    font-weight: bold;
    text-shadow: 0 1px 2px black;
}
.tower-cost::before { content: "● "; font-size: 8px; color: var(--gold); vertical-align: middle; }

/* Status Classes */
.tower-btn.cant-afford { opacity: 0.6; }
.tower-btn.cant-afford .tower-name { color: #666; }
.tower-btn.cant-afford .tower-cost { color: #c0392b; }

.tower-btn.locked { 
    opacity: 0.2; 
    filter: grayscale(1); 
    cursor: not-allowed;
    background: #000;
}

/* --- SELECTION & UPGRADES --- */
#selection-panel, #preview-panel {
    position: relative;
    border: 1px solid var(--gold);
    background: #110e0c;
    padding: 4px;
    padding-bottom: 1px;
    margin-top: 4px;
    display: none; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    border-radius: 2px;
}

#selected-info, #prev-name {
    background: #080605; 
    padding: 5px;
    padding-right: 90px; 
    color: var(--gold);
    font-family: var(--font-header); 
    text-align: left; 
    padding-left: 10px;
    font-size: 13px; 
    letter-spacing: 1px; 
    border-bottom: 1px solid #333; 
    font-weight: bold;
    line-height: 1.2;
    min-height: 16px;
}

/* THE DISMISS BUTTON */
.sell-btn {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 10;
    width: auto; 
    margin: 0;
    padding: 0 10px;
    height: 28px;
    background: #1a0505; 
    border: none;
    border-left: 1px solid #500; 
    border-bottom: 1px solid #500;
    color: #e74c3c;
    font-family: var(--font-header); 
    font-size: 9px; 
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 0 0 4px; 
}
.sell-btn:hover { background: #300; border-color: #f00; color: #fff; }

.action-bar { 
    display: flex; 
    gap: 3px; 
    background: transparent; 
    border: none; 
    margin: 3px 0;
}

.action-bar button {
    flex: 1; 
    height: 24px;
    padding: 0;
    font-family: var(--font-header);
    font-size: 10px; 
    font-weight: bold;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(0, 0, 0, 0.6);
    border-width: 1px;
    border-style: solid;
    border-radius: 2px;
}

/* Lore & Target Buttons */
.action-bar .info-btn { border-color: #2471a3; color: #5dade2; box-shadow: inset 0 0 5px rgba(36, 113, 163, 0.2); }
.action-bar .info-btn:hover { background: rgba(36, 113, 163, 0.2); border-color: #5dade2; color: #fff; text-shadow: 0 0 8px cyan; }

.action-bar .priority-btn { border-color: #a93226; color: #e74c3c; box-shadow: inset 0 0 5px rgba(169, 50, 38, 0.2); }
.action-bar .priority-btn:hover { background: rgba(169, 50, 38, 0.2); border-color: #e74c3c; color: #fff; text-shadow: 0 0 8px red; }

.action-bar button:active { transform: translateY(1px); filter: brightness(1.2); }

#current-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 2px;
    margin: 2px 0;
    background: #333; 
    padding: 2px;
    border-bottom: 1px solid #333;
}

.stat-box { 
    background: #151515; 
    padding: 3px; 
    text-align: center; 
    font-size: 10px; 
    color: #aaa; 
    line-height: 1.2;
}

.stat-box span { display: block; font-size: 11px; font-weight: bold; margin-top: 1px; }

.specials-list { 
    grid-column: 1 / -1; 
    display: flex; 
    flex-wrap: wrap; 
    gap: 3px; 
    background: #151515; 
    padding: 2px;
    justify-content: center; 
}

.special-tag { 
    background: #2c2018; 
    border: 1px solid #5d4037; 
    padding: 1px 5px; 
    font-size: 9px; 
    color: #d7ccc8; 
    border-radius: 2px;
    line-height: 14px;
}

/* --- UPGRADE ROWS --- */
.upgrade-row {
    margin-bottom: 2px;
    padding: 2px 6px;
    background: #080605;
    border: 1px solid #333;
    display: flex;
    align-items: center;
    min-height: 34px; 
    border-radius: 2px;
}
.upgrade-row:last-child { margin-bottom: 0; }

.upgrade-info { flex: 1; display: flex; align-items: center; padding-right: 6px; width: 100%; }
.upgrade-left { display: flex; flex-direction: column; justify-content: center; width: 130px; min-width: 130px; flex-shrink: 0; margin-right: 5px; }
.upgrade-left div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.path-name { font-family: var(--font-header); font-size: 10px; letter-spacing: 0.5px; }
.milestone-list { flex-grow: 1; margin: 0; display: flex; flex-direction: column; justify-content: center; }

.pip-row { display: flex; width: 100%; gap: 2px; margin: 2px 0; }
.pip { flex: 1; height: 6px; background: #222; border: 1px solid #444; cursor: help; box-sizing: border-box; }

.row-0 .pip.filled { background: cyan; border-color: #fff; }
.row-1 .pip.filled { background: orange; border-color: #fff; }
.row-2 .pip.filled { background: lime; border-color: #fff; }
.pip.locked { background: #000; border-color: #222; opacity: 0.3; }

.upgrade-btn { padding: 0; height: 24px; font-size: 10px; width: 45px; flex-shrink: 0; }

#prev-icon-container canvas { margin-bottom: 5px; border: 1px solid #333; background: #000; border-radius: 50%; }
#prev-desc { padding: 10px; font-style: italic; color: #888; font-size: 11px; text-align: center; line-height: 1.3; }

/* =========================================
   MODALS
   ========================================= */

.modal-overlay, .identity-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); backdrop-filter: blur(2px);
    display: none; justify-content: center; align-items: center;
    z-index: 5000; flex-direction: column;
}

.identity-box {
    background: #101216; border: 2px solid var(--border-color);
    box-shadow: 0 0 60px rgba(0,0,0,0.9), 0 0 20px rgba(197, 160, 89, 0.1);
    border-radius: 4px; padding: 0; overflow: hidden; position: relative;
    max-width: 900px; min-width: 300px; text-align: center;
}

.identity-box h1, .identity-box h2 {
    background: linear-gradient(to bottom, #1a1d23, #101216);
    border-bottom: 1px solid var(--border-color); margin: 0; padding: 20px;
    font-family: var(--font-header); color: var(--border-color); text-align: center; letter-spacing: 4px;
}

.identity-box > div:not(.level-container) { padding: 20px; }

.identity-input {
    background: #080a0c; border: 1px solid #444; color: white;
    font-family: var(--font-mono); padding: 12px; font-size: 16px;
    display: block; margin: 10px auto; width: 220px; text-align: center;
    text-transform: uppercase; transition: border 0.3s;
}
.identity-input:focus { border-color: var(--border-color); box-shadow: 0 0 8px rgba(197, 160, 89, 0.3); outline: none; }

.identity-box button {
    background: var(--border-color); color: #000; border: none;
    font-family: var(--font-header); font-weight: bold; font-size: 14px;
    letter-spacing: 1px; padding: 12px; width: 100%; margin-top: 10px; cursor: pointer;
}
.identity-box button:hover { background: #ffd700; box-shadow: 0 0 15px rgba(255, 215, 0, 0.4); }

/* =========================================
   CUSTOM MENU BACKGROUNDS
   ========================================= */

#login-screen::before, #main-menu-screen::before, 
#armory-screen::before, #mastery-screen::before, 
#ascension-screen::before, #stats-screen::before,
#leaderboard-screen::before, #settings-screen::before {
    content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: -1;
    background-size: cover; background-position: center; filter: blur(2px); transform: scale(1.02);
}

#login-screen::before { background-image: url('assets/background_login.png'); }
#main-menu-screen::before { background-image: url('assets/background_mainmenu.png'); }
#armory-screen::before { background-image: url('assets/background_armory.png'); }
#mastery-screen::before { background-image: url('assets/background_towermastery.png'); }
#ascension-screen::before { background-image: url('assets/background_ascension.png'); }
#stats-screen::before { background-image: url('assets/background_records.png'); }
#leaderboard-screen::before { background-image: url('assets/background_leaderboards.png'); }
#settings-screen::before { background-image: url('assets/background_settings.png'); }

/* =========================================
   MASTERY SCREEN
   ========================================= */

#mastery-screen .identity-box { width: 1400px !important; max-width: 95vw !important; height: 85vh !important; display: flex; flex-direction: column; padding: 0 !important; overflow: hidden; }
#mastery-screen .identity-box > div:nth-child(2) { display: flex; flex: 1; overflow: hidden; width: 100%; }
#mastery-tower-list { width: 280px !important; background: #0f0a08; border-right: 2px solid var(--gold); padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex-shrink: 0; }
#mastery-tower-list::-webkit-scrollbar { width: 4px; }
#mastery-tower-list::-webkit-scrollbar-track { background: #000; }
#mastery-tower-list::-webkit-scrollbar-thumb { background: #333; }

.mastery-tower-btn {
    display: flex; align-items: center; gap: 15px; width: 100%; height: 60px;
    padding: 0 15px; background: linear-gradient(to right, #1a1510, #110e0c);
    border: 1px solid #444; border-left: 4px solid #333; box-sizing: border-box;
    color: #888; font-family: var(--font-header); font-size: 14px;
    text-transform: uppercase; cursor: pointer; transition: all 0.2s ease;
}
.mastery-tower-btn:hover { background: #2c1e14; border-color: #666; color: #ccc; }
.mastery-tower-btn.active { background: #2e2210; border-color: var(--gold); border-left-color: var(--gold); color: var(--gold); font-weight: bold; }
.mastery-tower-btn.locked { filter: grayscale(1); opacity: 0.6; }
.mastery-btn-icon { width: 40px; height: 40px; display: flex; justify-content: center; align-items: center; background: rgba(0,0,0,0.3); border-radius: 4px; border: 1px solid #333; }

#mastery-details { flex: 1; background: #15181e; padding: 25px; display: flex; flex-direction: column; overflow: hidden; }
#mastery-columns-container { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; flex: 1; min-height: 0; padding-top: 10px; }
.mastery-col { background: rgba(0, 0, 0, 0.25); border: 1px solid #333; display: flex; flex-direction: column; border-radius: 4px; overflow: hidden; height: 100%; }
.mastery-col-header { background: #120e0b; padding: 10px 15px; font-family: var(--font-header); font-weight: bold; font-size: 14px; text-transform: uppercase; border-bottom: 1px solid #333; }
.mastery-col.col-0 { border-top: 3px solid cyan; } .mastery-col.col-0 .mastery-col-header { color: cyan; }
.mastery-col.col-1 { border-top: 3px solid orange; } .mastery-col.col-1 .mastery-col-header { color: orange; }
.mastery-col.col-2 { border-top: 3px solid lime; } .mastery-col.col-2 .mastery-col-header { color: lime; }
.mastery-col-list { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.mastery-node { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 0 15px; border-bottom: 1px solid #333; min-height: 0; }
.mastery-node.locked { opacity: 0.4; filter: grayscale(1); background: rgba(0,0,0,0.2); }
.mastery-node.unlocked { background: rgba(255, 255, 255, 0.02); border-left: 3px solid #444; }
.mastery-node.next-available { background: rgba(255, 255, 255, 0.05); border-left: 3px solid var(--gold); }
.mn-top-row { display: flex; justify-content: space-between; margin-bottom: 2px; }
.mn-title { font-weight: bold; font-size: 13px; color: #e5e0d8; }
.mn-cost { font-family: var(--font-mono); font-size: 11px; color: var(--gold); }
.mn-desc { font-size: 11px; color: #888; font-style: italic; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mn-action { margin-top: 4px; text-align: right; height: 22px; display: flex; justify-content: flex-end; }
.mn-btn { background: #000 !important; border: 1px solid #444 !important; color: #888 !important; font-size: 9px !important; padding: 2px 8px !important; height: auto !important; min-width: 50px; }
.mn-btn.buy { border-color: var(--gold) !important; color: var(--gold) !important; background: rgba(20, 10, 5, 0.8) !important; }
.mn-btn.buy:hover { background: var(--gold) !important; color: #000 !important; }

/* =========================================
   ARMORY
   ========================================= */

#armory-screen .identity-box { width: 1600px !important; max-width: 98vw !important; height: 90vh !important; max-height: none !important; display: flex; flex-direction: column; }
.armory-container { display: flex; gap: 20px; height: 100%; width: 100%; flex: 1; overflow: hidden; }
.paper-doll { width: 340px; background: radial-gradient(circle at top, #1b2029 0%, #0e1014 100%); border: 2px solid var(--border-color); box-shadow: inset 0 0 40px rgba(0,0,0,0.8); display: flex; flex-direction: column; align-items: center; padding: 20px; flex-shrink: 0; position: relative; }
.doll-head, .doll-torso, .doll-legs { display: flex; justify-content: center; gap: 15px; margin-bottom: 15px; width: 100%; }
.gear-slot { width: 80px; height: 80px; background: #08090b; border: 1px solid #333; border-radius: 6px; display: flex; flex-direction: column; justify-content: center; align-items: center; font-family: var(--font-header); font-size: 10px; color: #444; }
.gear-slot.equipped { background: linear-gradient(145deg, #232730, #15181e); border: 1px solid var(--border-color); color: #e5e0d8; cursor: pointer; font-size: 11px; }
.gear-slot.equipped:hover { border-color: var(--gold-bright); transform: translateY(-3px); }
.stash-panel { flex: 1; background: #110e0c; border: 2px solid var(--border-color); padding: 15px; overflow: hidden; display: flex; flex-direction: column; }
.stash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; flex: 1; overflow-y: auto; padding-right: 20px; }
.item-card { background: #1a1510; border: 1px solid #444; padding: 15px; font-size: 13px; cursor: pointer; display: flex; flex-direction: column; gap: 5px; }
.item-card:hover { transform: scale(1.02); background: #251d18; border-color: var(--border-color); }
.item-card.equipped { border: 2px solid var(--gold); background: #201a10; }
.item-Common { color: var(--common); border-color: #555; }
.item-Rare { color: var(--rare); border-color: #2e6ea5; }
.item-Epic { color: var(--epic); border-color: #7d3c98; }
.item-Legendary { color: var(--legendary); border-color: #d4ac0d; }


/* STYLE FOR THE NEW ITEM ICON PLACEHOLDER */
.gear-slot .item-icon {
    width: 48px;
    height: 48px;
    background: #222;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    /* A subtle pattern to make it look like an empty item slot */
    background-image: linear-gradient(45deg, #1a1a1a 25%, transparent 25%, transparent 75%, #1a1a1a 75%, #1a1a1a), 
                      linear-gradient(45deg, #1a1a1a 25%, transparent 25%, transparent 75%, #1a1a1a 75%, #1a1a1a);
    background-size: 10px 10px;
    background-position: 0 0, 5px 5px;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}

/* =========================================
   SKILL TREE
   ========================================= */

/* =========================================
   SKILL TREE
   ========================================= */

/* Fix: Limit height and enable internal scrolling */
#ascension-screen .identity-box {
    width: 900px; 
    max-width: 95%;
    max-height: 90vh; /* Don't exceed screen height */
    display: flex;
    flex-direction: column;
}

.skill-tree-container {
    display: flex; 
    justify-content: space-around; 
    gap: 20px; 
    padding: 20px; 
    background: #080605; 
    border: 2px solid #333;
    
    /* Scroll Logic: Takes available space and scrolls internally */
    overflow-y: auto; 
    flex: 1;          
    min-height: 0;    
}

/* Custom Scrollbar for the Tree */
.skill-tree-container::-webkit-scrollbar { width: 8px; }
.skill-tree-container::-webkit-scrollbar-track { background: #000; }
.skill-tree-container::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
.skill-tree-container::-webkit-scrollbar-thumb:hover { background: var(--gold); }

.tree-column { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    gap: 25px; 
    position: relative; 
}

.col-header { 
    font-family: var(--font-header); 
    font-weight: bold; 
    letter-spacing: 2px; 
    margin-bottom: 15px; 
    font-size: 14px; 
    border-bottom: 1px solid #333; 
    width: 100%; 
    text-align: center; 
    padding-bottom: 5px; 
}

.skill-node { 
    width: 60px; 
    height: 60px; 
    border-radius: 50%; 
    background: #15110e; 
    border: 2px solid #444; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    cursor: pointer; 
    position: relative; 
    z-index: 2; 
    transition: all 0.2s; 
    flex-shrink: 0; 
}

.skill-node::after { 
    content: ''; 
    position: absolute; 
    top: 100%; 
    left: 50%; 
    width: 4px; 
    height: 25px; 
    background: #222; 
    z-index: -1; 
    transform: translateX(-50%); 
}

.tree-column .skill-node:last-child::after { display: none; }

.skill-node.locked { opacity: 0.4; filter: grayscale(1); }
.skill-node.unlocked { border-color: var(--gold); background: #2e2210; color: var(--gold); box-shadow: 0 0 15px rgba(197, 160, 89, 0.4); }
.skill-node.unlocked::after { background: var(--gold); }

.skill-icon { font-size: 28px; pointer-events: none; }

.skill-cost { 
    position: absolute; 
    bottom: -8px; 
    left: 50%; 
    transform: translateX(-50%); 
    background: #000; 
    border: 1px solid #555; 
    border-radius: 10px; 
    padding: 2px 6px; 
    font-family: var(--font-mono); 
    font-size: 9px; 
    color: var(--gold); 
    z-index: 5; 
    white-space: nowrap; 
}

/* =========================================
   LEADERBOARD & MISC
   ========================================= */

#leaderboard-screen .identity-box { width: 600px; height: 700px; display: flex; flex-direction: column; }
.lb-tabs-container { display: flex; background: #0f0a08; border-bottom: 1px solid #333; padding: 10px; gap: 5px; }
.lb-tab { flex: 1; background: #1a1510; border: 1px solid #444; color: #888; padding: 8px; cursor: pointer; text-align: center; text-transform: uppercase; }
.lb-tab.active { background: var(--gold); color: #000; font-weight: bold; }
.lb-grid-header { display: grid; grid-template-columns: 60px 1fr 120px; padding: 10px 20px; background: rgba(255,255,255,0.05); border-bottom: 1px solid var(--gold); color: var(--gold); font-weight: bold; }
.lb-list-container { flex: 1; overflow-y: auto; background: rgba(0,0,0,0.2); }
.lb-row { display: grid; grid-template-columns: 60px 1fr 120px; padding: 12px 20px; border-bottom: 1px solid #333; }
.lb-rank.rank-1 { color: #ffd700; } .lb-score { color: cyan; text-align: right; }

#intel-popup { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 900px; background: #101216; border: 2px solid var(--gold); z-index: 6000; display: none; flex-direction: column; }
.intel-header { background: #080a0c; padding: 15px; border-bottom: 1px solid var(--gold); display: flex; justify-content: space-between; }
.intel-list { padding: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.intel-row { display: flex; align-items: center; background: rgba(30,30,40,0.4); border: 1px solid #333; padding: 10px; }
.intel-icon-box { width: 50px; height: 50px; background: #000; border: 1px solid #444; margin-right: 15px; display: flex; justify-content: center; align-items: center; }

#tooltip { position: absolute; background: rgba(16, 18, 22, 0.98); border: 2px solid var(--gold); padding: 10px; pointer-events: none; display: none; font-size: 11px; max-width: 250px; z-index: 6000; color: var(--text); }
.tooltip-title { font-family: var(--font-header); font-weight: bold; font-size: 13px; color: var(--gold); border-bottom: 1px solid #555; margin-bottom: 5px; }

.game-notification { position: absolute; top: 120px; left: 50%; transform: translateX(-50%); background: rgba(16, 18, 22, 0.95); border: 2px solid var(--gold); color: var(--gold); padding: 20px 40px; font-family: var(--font-header); font-size: 20px; pointer-events: none; z-index: 3000; transition: opacity 0.2s; }

#boss-hud { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); width: 600px; display: none; flex-direction: column; align-items: center; z-index: 1000; pointer-events: none; }
#boss-name { color: var(--red); font-size: 24px; font-weight: bold; text-shadow: 0 2px 4px black; font-family: var(--font-header); }
#boss-health-track { width: 100%; height: 20px; background: #111; border: 2px solid #5d4037; position: relative; }
#boss-health-fill { width: 100%; height: 100%; background: linear-gradient(90deg, #800000, #c0392b); }
#boss-health-text { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #fff; font-size: 10px; font-weight: bold; }

#game-over { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: none; flex-direction: column; justify-content: center; align-items: center; background: rgba(5, 0, 0, 0.9); z-index: 4000; backdrop-filter: blur(5px); }
#pause-menu { position: absolute; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 3000; }

#tower-detail-content { background: #101216; border: 2px solid var(--gold); width: 1100px; max-width: 95vw; max-height: 85vh; overflow-y: auto; padding: 25px; display: flex; flex-direction: column; }
#lore-columns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-top: 10px; }
.detail-row { background: rgba(0,0,0,0.3); padding: 15px; border-radius: 4px; }

/* --- SPECIAL FEATURE BUTTONS (REFINED) --- */

/* 1. DEEP MAGIC BUTTON (Cyan/Arcane Theme) */
#deep-magic-btn {
    justify-content: center; 
    padding: 0;
    background: linear-gradient(160deg, #08141c 0%, #102030 50%, #050a0f 100%);
    border: 1px solid #2a4d69;
    color: #4db8ff; 
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), inset 0 -1px 5px rgba(0,0,0,0.5), 0 2px 5px rgba(0,0,0,0.3);
    text-shadow: 0 0 8px rgba(77, 184, 255, 0.5); 
}
#deep-magic-btn::before { content: none; display: none; }
#deep-magic-btn:hover {
    background: linear-gradient(160deg, #0c2438 0%, #1c3a55 50%, #08141c 100%);
    border-color: #00ffff; 
    color: #fff;
    box-shadow: inset 0 0 15px rgba(0, 255, 255, 0.25), 0 0 10px rgba(0, 255, 255, 0.3);
    text-shadow: 0 0 12px cyan;
}

/* 2. TOWER MASTERY BUTTON (Gold/Antique Theme) */
#ingame-mastery-btn {
    justify-content: center;
    padding: 0;
    background: linear-gradient(160deg, #1c1208 0%, #2e2214 50%, #140d08 100%);
    border: 1px solid #6d4c35;
    color: #e2c07a; 
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), inset 0 -1px 5px rgba(0,0,0,0.5), 0 2px 5px rgba(0,0,0,0.3);
    text-shadow: 0 0 5px rgba(226, 192, 122, 0.4);
}
#ingame-mastery-btn::before { content: none; display: none; }
#ingame-mastery-btn:hover {
    background: linear-gradient(160deg, #2e2014 0%, #46331f 50%, #1c1208 100%);
    border-color: #ffd700; 
    color: #fff;
    box-shadow: inset 0 0 15px rgba(255, 215, 0, 0.25), 0 0 10px rgba(255, 215, 0, 0.3);
    text-shadow: 0 0 12px gold;
}

/* --- NEW DEEP MAGIC (ROGUE) UI --- */

#rogue-modal {
    backdrop-filter: blur(8px);
    background: rgba(5, 5, 10, 0.9);
}

#rogue-cards {
    display: flex;
    gap: 30px;
    justify-content: center;
    perspective: 1000px; 
    padding: 20px;
}

.rogue-card {
    width: 220px;
    height: 340px;
    background: linear-gradient(145deg, #1a1a1a, #0d0d0d);
    border: 1px solid #333;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    animation: dealCard 0.5s ease-out backwards;
}

.rogue-card:nth-child(1) { animation-delay: 0.1s; }
.rogue-card:nth-child(2) { animation-delay: 0.2s; }
.rogue-card:nth-child(3) { animation-delay: 0.3s; }

@keyframes dealCard {
    from { opacity: 0; transform: translateY(50px) rotateX(10deg); }
    to { opacity: 1; transform: translateY(0) rotateX(0); }
}

.rogue-card:hover {
    transform: translateY(-15px) scale(1.05);
    z-index: 10;
    box-shadow: 0 20px 40px rgba(0,0,0,0.8);
    border-color: var(--gold);
}

.card-header {
    width: 100%;
    padding: 15px 0;
    background: rgba(0,0,0,0.3);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 15px;
}

.card-title {
    font-family: var(--font-header);
    font-size: 18px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0;
    padding: 0 10px;
    line-height: 1.2;
}

.card-rarity { font-size: 10px; text-transform: uppercase; letter-spacing: 2px; margin-top: 5px; opacity: 0.8; }
.card-body { flex: 1; display: flex; align-items: center; justify-content: center; padding: 0 20px; font-size: 13px; line-height: 1.5; color: #ccc; font-style: italic; }
.card-footer { width: 100%; padding: 15px; font-size: 10px; color: #555; border-top: 1px solid rgba(255,255,255,0.05); background: rgba(0,0,0,0.2); }

/* Rarity Themes */
.card-Common { border-top: 4px solid #95a5a6; } .card-Common .card-title { color: #bdc3c7; } .card-Common:hover { box-shadow: 0 0 20px rgba(189, 195, 199, 0.2); }
.card-Rare { border-top: 4px solid #3498db; } .card-Rare .card-title { color: #5dade2; } .card-Rare:hover { box-shadow: 0 0 25px rgba(52, 152, 219, 0.3); }
.card-Epic { border-top: 4px solid #9b59b6; } .card-Epic .card-title { color: #af7ac5; } .card-Epic:hover { box-shadow: 0 0 30px rgba(155, 89, 182, 0.4); }
.card-Legendary { border-top: 4px solid #f1c40f; background: linear-gradient(145deg, #252010, #0d0d0d); } .card-Legendary .card-title { color: #f1c40f; text-shadow: 0 0 10px rgba(241, 196, 15, 0.5); } .card-Legendary:hover { box-shadow: 0 0 40px rgba(241, 196, 15, 0.5); border-color: #f1c40f; }

#rogue-modal button {
    margin-top: 20px;
    background: transparent;
    border: 1px solid #555;
    color: #888;
    padding: 10px 30px;
    font-family: var(--font-header);
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.3s;
}
#rogue-modal button:hover { border-color: #fff; color: #fff; background: rgba(255,255,255,0.1); }

/* --- ACTIVE MAGIC (LOG) UI --- */

#stc-log-modal { backdrop-filter: blur(5px); background: rgba(0, 0, 0, 0.85); z-index: 6000; }
#stc-log-modal .identity-box { background: linear-gradient(180deg, #0b1016, #05080a) !important; border: 2px solid cyan !important; box-shadow: 0 0 40px rgba(0, 255, 255, 0.15) !important; width: 500px !important; max-width: 95%; padding: 0 !important; }
#stc-log-modal h2 { background: rgba(0, 255, 255, 0.05) !important; border-bottom: 1px solid cyan !important; color: cyan !important; padding: 15px; font-size: 18px; text-shadow: 0 0 10px rgba(0, 255, 255, 0.5); letter-spacing: 2px; margin: 0 !important; }
#stc-list-container { padding: 15px; display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
#stc-list-container::-webkit-scrollbar { width: 6px; }
#stc-list-container::-webkit-scrollbar-track { background: #000; }
#stc-list-container::-webkit-scrollbar-thumb { background: #2c3e50; border-radius: 3px; }
#stc-list-container::-webkit-scrollbar-thumb:hover { background: cyan; }

.stc-entry { background: linear-gradient(90deg, rgba(255,255,255,0.03), transparent); border: 1px solid #333; padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; transition: all 0.2s ease; position: relative; overflow: hidden; }
.stc-entry:hover { background: linear-gradient(90deg, rgba(255,255,255,0.08), transparent); transform: translateX(2px); border-color: #555; box-shadow: inset 0 0 20px rgba(0,0,0,0.5); }
.stc-entry-left { display: flex; flex-direction: column; gap: 2px; }
.stc-name { font-family: var(--font-header); font-size: 12px; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; }
.stc-desc { font-size: 10px; color: #888; font-style: italic; }
.stc-wave { font-size: 9px; color: #666; font-family: var(--font-mono); border: 1px solid #333; padding: 2px 6px; border-radius: 2px; background: #000; }

#stc-log-modal button { background: transparent !important; border: 1px solid #2c3e50 !important; color: #5d6d7e !important; margin: 15px; width: auto !important; transition: all 0.2s; font-family: var(--font-header); letter-spacing: 2px; }
#stc-log-modal button:hover { border-color: cyan !important; color: cyan !important; background: rgba(0, 255, 255, 0.05) !important; box-shadow: 0 0 10px rgba(0, 255, 255, 0.2); }

/* --- DEEP MAGIC PENDING STATE --- */
@keyframes magicPulse {
    0% { box-shadow: 0 0 5px #00ffff; border-color: #0088ff; color: #00ffff; }
    50% { box-shadow: 0 0 20px #00ffff; border-color: #ffffff; color: #ffffff; }
    100% { box-shadow: 0 0 5px #00ffff; border-color: #0088ff; color: #00ffff; }
}

#deep-magic-btn.magic-pending {
    animation: magicPulse 1.5s infinite ease-in-out;
    background: linear-gradient(160deg, #002b36 0%, #004d66 100%);
    text-shadow: 0 0 8px cyan;
    font-weight: bold;
}

/* Manage Mode Visuals */
.item-card.selected-for-manage {
    border: 2px solid #e67e22 !important; 
    background: linear-gradient(135deg, #2d1b0e, #1a1008) !important;
    box-shadow: 0 0 15px rgba(230, 126, 34, 0.6), inset 0 0 20px rgba(230, 126, 34, 0.2);
    transform: scale(0.95); 
    position: relative;
}

.item-card.selected-for-manage::after {
    content: "✔"; position: absolute; top: 5px; right: 5px;
    background: #e67e22; color: #000; font-weight: bold; font-size: 12px;
    width: 20px; height: 20px; border-radius: 50%;
    display: flex; justify-content: center; align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}


/* --- LOOT SCREEN STYLES --- */

.loot-stage {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    background: radial-gradient(circle, rgba(50,50,50,0.3) 0%, rgba(0,0,0,0) 70%);
}

.chest-container {
    width: 200px;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 100px; /* For the emoji */
    position: relative;
    cursor: pointer;
    transition: transform 0.2s;
}

.chest-container:hover {
    transform: scale(1.05);
}

/* Shake Animation for opening */
@keyframes shake {
  0% { transform: translate(1px, 1px) rotate(0deg); }
  10% { transform: translate(-1px, -2px) rotate(-1deg); }
  20% { transform: translate(-3px, 0px) rotate(1deg); }
  30% { transform: translate(3px, 2px) rotate(0deg); }
  40% { transform: translate(1px, -1px) rotate(1deg); }
  50% { transform: translate(-1px, 2px) rotate(-1deg); }
  60% { transform: translate(-3px, 1px) rotate(0deg); }
  70% { transform: translate(3px, 1px) rotate(-1deg); }
  80% { transform: translate(-1px, -1px) rotate(1deg); }
  90% { transform: translate(1px, 2px) rotate(0deg); }
  100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.chest-container.shaking {
    animation: shake 0.5s;
    animation-iteration-count: infinite;
}

.chest-glow {
    position: absolute;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, gold 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.5s;
    z-index: -1;
}

.chest-container:hover .chest-glow {
    opacity: 0.2;
}

#loot-result {
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    80% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* --- ARMORY FILTER TABS --- */
.armory-filters {
    display: flex;
    gap: 4px;
}

.filter-tab {
    background: #08090a;
    border: 1px solid #333;
    color: #666;
    font-size: 9px;
    padding: 4px 8px;
    cursor: pointer;
    font-family: var(--font-header);
    text-transform: uppercase;
    transition: all 0.2s;
    border-radius: 2px;
}

.filter-tab:hover {
    background: #222;
    color: #ccc;
    border-color: #555;
}

.filter-tab.active {
    background: var(--gold);
    color: #000;
    border-color: var(--gold);
    font-weight: bold;
    box-shadow: 0 0 5px rgba(197, 160, 89, 0.4);
}