.hidden {
    display: none !important;
}

:root {
    /* === PREMIUM COLOR PALETTE === */
    --gold-base: #f5d742;
    --gold-dark: #c9a42b;
    --gold-darker: #a88a1e;
    --gold-gradient: linear-gradient(135deg, var(--gold-base) 0%, var(--gold-dark) 50%, var(--gold-darker) 100%);
    --gold-glow: 0 0 15px rgba(245, 215, 66, 0.5);
    --gold-text-shadow: 0 0 10px rgba(245, 215, 66, 0.7);

    --danger-base: #ff6b6b;
    --danger-dark: #c0392b;
    --danger-gradient: linear-gradient(135deg, var(--danger-base) 0%, var(--danger-dark) 100%);

    --accent-base: #00d4ff;
    --accent-dark: #0099cc;
    --accent-gradient: linear-gradient(135deg, var(--accent-base) 0%, var(--accent-dark) 100%);
    --accent-glow: 0 0 15px rgba(0, 212, 255, 0.5);

    --panel-bg: linear-gradient(145deg, rgba(30, 30, 40, 0.95), rgba(15, 15, 20, 0.98));
    --panel-border: rgba(255, 215, 0, 0.3);

    --bg-dark: #0a0a0f;
    --text-light: #ffffff;
    --text-muted: #888;
    --font-main: 'Outfit', sans-serif;
    --font-display: 'Outfit', sans-serif;
    --ui-glass: rgba(20, 20, 30, 0.9);
    --border-radius: 8px;
    --border-radius-lg: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    font-family: var(--font-main);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    /* max-width: 1920px; Removed for full width */
    /* max-height: 1080px; Removed for full height */
    background: #000;
    overflow: hidden;
    box-shadow: 0 0 80px rgba(0, 0, 0, 0.8);
    border: 1px solid rgba(255, 215, 0, 0.1);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#headbar,
.screen {
    pointer-events: auto;
}

/* === UNIFIED HEADBAR === */
#headbar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.4) 80%, transparent);
    gap: 20px;
    z-index: 50;
}

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

.headbar-center {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 25px;
    flex: 1;
}

.stat-box {
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    border-radius: var(--border-radius);
    border: 1px solid var(--panel-border);
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-box:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.stat-box .icon {
    font-size: 1.2rem;
    filter: drop-shadow(0 0 5px currentColor);
}

.gold {
    color: var(--gold-base);
    text-shadow: var(--gold-text-shadow);
}

.xp {
    color: var(--accent-base);
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.hp {
    color: var(--danger-base);
}

.age-indicator {
    background: var(--gold-gradient);
    padding: 8px 30px;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    font-weight: 900;
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #1a1a1a;
    box-shadow: 0 4px 20px rgba(245, 215, 66, 0.4), inset 0 2px 0 rgba(255, 255, 255, 0.3);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {

    0%,
    100% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(1.1);
    }
}

/* === ACTION BUTTONS (Headbar) === */
.action-buttons {
    display: flex;
    gap: 8px;
}

.unit-menu {
    display: flex;
    gap: 12px;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--panel-border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* === UNIT BUTTON SYSTEM === */
.unit-btn-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.btn-unit {
    width: 70px;
    height: 80px;
    background: var(--panel-bg);
    border-radius: var(--border-radius-lg);
    border: 2px solid rgba(255, 255, 255, 0.15);
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 0.85rem;
    font-weight: bold;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4), inset 0 -2px 5px rgba(0, 0, 0, 0.3);
}

.btn-plus {
    width: 70px;
    padding: 4px 8px;
    background: var(--gold-gradient);
    border: none;
    border-radius: var(--border-radius);
    color: #1a1a1a;
    font-size: 0.7rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(245, 215, 66, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-plus:hover {
    transform: scale(1.05);
    box-shadow: var(--gold-glow), 0 4px 12px rgba(245, 215, 66, 0.5);
}

.btn-plus:disabled {
    background: #444;
    color: #888;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-unit:hover {
    background: linear-gradient(145deg, rgba(50, 50, 60, 0.95), rgba(30, 30, 40, 0.98));
    border-color: var(--gold-base);
    transform: translateY(-4px) scale(1.02);
    box-shadow: var(--gold-glow), 0 8px 25px rgba(0, 0, 0, 0.5);
}

.btn-unit:active {
    transform: translateY(0) scale(0.98);
}

.unit-preview {
    font-size: 2.2rem;
    margin-bottom: 5px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.unit-cost {
    background: var(--gold-gradient);
    color: #1a1a1a;
    font-size: 0.75rem;
    font-weight: 800;
    padding: 3px 10px;
    border-radius: 10px;
    margin-top: 5px;
}

/* Info Icon */
.btn-info {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    background: var(--accent-gradient);
    border-radius: 50%;
    border: 2px solid white;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    cursor: pointer;
    box-shadow: var(--accent-glow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-info:hover {
    transform: scale(1.15);
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.7);
}

/* === ACTION BUTTONS (Headbar compact) === */
.btn-action {
    padding: 8px 18px;
    border-radius: var(--border-radius);
    font-family: var(--font-main);
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.btn-action.btn-special {
    background: var(--danger-gradient);
    color: white;
    box-shadow: 0 3px 10px rgba(192, 57, 43, 0.4);
}

.btn-action.btn-special:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 18px rgba(255, 107, 107, 0.5);
}

.btn-action.btn-evolve {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 3px 10px rgba(0, 153, 204, 0.4);
}

.btn-action.btn-evolve:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--accent-glow), 0 5px 18px rgba(0, 212, 255, 0.4);
}

.btn-action.btn-credits {
    background: var(--gold-gradient);
    color: #1a1a1a;
    box-shadow: 0 3px 10px rgba(245, 215, 66, 0.4);
}

.btn-action.btn-credits:hover {
    transform: translateY(-2px);
    box-shadow: var(--gold-glow), 0 5px 18px rgba(245, 215, 66, 0.5);
}

.btn-action:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
    box-shadow: none;
    border-color: #444;
}

/* === MODAL SYSTEM === */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--border-radius-lg);
    padding: 25px;
    width: 450px;
    max-width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 40px rgba(245, 215, 66, 0.1);
    animation: modalIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.stats-modal-content {
    width: 900px;
    max-width: 95%;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.6rem;
    background: var(--gold-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
}

.close-btn {
    width: 35px;
    height: 35px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: #999;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.close-btn:hover {
    background: rgba(255, 107, 107, 0.2);
    border-color: var(--danger-base);
    color: var(--danger-base);
}

/* === FACTION SCREEN === */
.faction-carousel {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
}

.faction-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    padding: 15px;
    width: 90px;
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem;
    cursor: pointer;
    transition: all 0.2s;
    filter: grayscale(0.8);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.faction-card:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.1);
    filter: grayscale(0);
}

.faction-card.active {
    border-color: var(--gold-base);
    box-shadow: var(--gold-glow);
    background: linear-gradient(135deg, rgba(245, 215, 66, 0.2), rgba(0, 0, 0, 0.5));
    transform: scale(1.1);
    filter: grayscale(0);
}

.faction-details {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--border-radius-lg);
    padding: 30px;
    width: 600px;
    max-width: 90%;
    margin-bottom: 30px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    position: relative;
    overflow: hidden;
}

#faction-name {
    font-size: 2.2rem;
    color: var(--gold-base);
    margin-bottom: 5px;
    text-shadow: var(--gold-text-shadow);
}

#faction-icon {
    font-size: 6rem;
    margin: 15px 0;
    filter: drop-shadow(0 0 30px rgba(245, 215, 66, 0.3));
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

#faction-desc {
    color: var(--text-muted);
    font-size: 1.2rem;
    margin-bottom: 25px;
    letter-spacing: 2px;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 15px;
    display: inline-block;
}

.faction-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: rgba(0, 0, 0, 0.3);
    padding: 20px;
    border-radius: var(--border-radius);
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 15px;
    border-radius: var(--border-radius);
    font-weight: bold;
    font-size: 1.1rem;
    text-align: left;
}

.stat-row.pro {
    background: rgba(46, 204, 113, 0.1);
    border: 1px solid rgba(46, 204, 113, 0.3);
    color: #2ecc71;
}

.stat-row.con {
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    color: #e74c3c;
}

.stat-row .icon {
    background: rgba(0, 0, 0, 0.3);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* Build Menu Options */
.build-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}

.build-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.build-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--gold-base);
    transform: translateY(-3px);
    box-shadow: var(--gold-glow);
}

.build-card .icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.5));
}

.build-card .name {
    font-weight: bold;
    font-size: 0.95rem;
    margin-bottom: 5px;
}

.build-card .cost {
    background: var(--gold-gradient);
    color: #1a1a1a;
    font-size: 0.8rem;
    font-weight: 800;
    padding: 4px 12px;
    border-radius: 10px;
}

/* Context Info */
.context-info {
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-bottom: 15px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.stats-grid p {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-muted);
}

/* === SCREENS === */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, rgba(20, 20, 30, 0.6) 0%, rgba(5, 5, 10, 0.7) 100%);
    z-index: 100;
    gap: 20px;
}

.screen.hidden {
    display: none;
}

.screen h1 {
    font-size: 5rem;
    font-weight: 900;
    letter-spacing: 8px;
    background: var(--gold-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    animation: titlePulse 2s infinite;
}

@keyframes titlePulse {

    0%,
    100% {
        filter: brightness(1) drop-shadow(0 0 20px rgba(245, 215, 66, 0.3));
    }

    50% {
        filter: brightness(1.1) drop-shadow(0 0 30px rgba(245, 215, 66, 0.5));
    }
}

.screen h2 {
    font-size: 1.8rem;
    font-weight: 400;
    letter-spacing: 15px;
    color: var(--text-muted);
    margin-top: -10px;
}

.menu-options {
    display: flex;
    gap: 20px;
    margin-top: 40px;
}

.btn-menu {
    font-family: var(--font-display);
    font-size: 1.2rem;
    padding: 12px 50px;
    margin: 8px;
    background: var(--gold-gradient);
    border: none;
    border-radius: var(--border-radius);
    color: var(--bg-dark);
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(245, 215, 66, 0.3);
}

.btn-menu.btn-tv {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
}

/* TV Lobby Styles */
.tv-lobby-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(0, 0, 0, 0.6);
    /* Brighter background */
    padding: 30px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.tv-code-display {
    text-align: center;
    margin-bottom: 30px;
}

#room-code-display {
    font-size: 5rem;
    font-family: var(--font-display);
    font-weight: bold;
    letter-spacing: 15px;
    color: var(--gold-base);
    text-shadow: var(--gold-text-shadow), 0 0 30px rgba(245, 215, 66, 0.5);
    margin: 10px 0;
    animation: pulse 2s ease-in-out infinite;
}

.tv-players {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
}

.tv-player {
    background: var(--panel-bg);
    border: 2px solid var(--panel-border);
    border-radius: var(--border-radius-lg);
    padding: 20px 40px;
    text-align: center;
    min-width: 200px;
    transition: all 0.3s;
}

.tv-player.connected {
    border-color: #2ecc71;
    box-shadow: 0 0 20px rgba(46, 204, 113, 0.3);
}

.tv-player.ready {
    border-color: var(--gold-base);
    box-shadow: 0 0 30px rgba(245, 215, 66, 0.5);
    animation: ready-pulse 1.5s ease-in-out infinite;
}

@keyframes ready-pulse {

    0%,
    100% {
        box-shadow: 0 0 20px rgba(245, 215, 66, 0.3);
        transform: scale(1);
    }

    50% {
        box-shadow: 0 0 40px rgba(245, 215, 66, 0.6);
        transform: scale(1.02);
    }
}


/* === NEW MENU LAYOUT (Performance Optimized) === */

/* Top Header */
.menu-header {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    z-index: 10;
}

.menu-header .menu-logo {
    max-width: 200px;
    filter: drop-shadow(0 0 15px rgba(245, 215, 66, 0.4));
}

.menu-header .game-title {
    font-size: 4rem;
    font-weight: 900;
    letter-spacing: 12px;
    background: var(--gold-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    margin: 0;
}

/* Right Panel */
.menu-panel-right {
    position: absolute;
    top: 50%;
    right: 60px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 15px;
    background: rgba(10, 10, 15, 0.95);
    /* backdrop-filter: blur(10px); REMOVED FOR PERFORMANCE */
    padding: 30px;
    border-radius: 16px;
    border: 1px solid rgba(255, 215, 0, 0.2);
    min-width: 280px;
    z-index: 10;
}

.panel-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--gold-base);
    text-align: center;
    margin-bottom: 10px;
}

/* Difficulty Buttons */
.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-difficulty {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    font-family: var(--font-main);
}

.btn-difficulty:hover {
    background: rgba(245, 215, 66, 0.15);
    border-color: var(--gold-base);
    transform: translateX(-5px);
}

.btn-difficulty:active {
    transform: translateX(-5px) scale(0.98);
}

.diff-icon {
    font-size: 1.8rem;
}

.diff-label {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 2px;
}

.diff-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: auto;
}

/* Menu Separator */
.menu-separator {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 10px 0;
}

/* Secondary Buttons */
.secondary-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-secondary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-muted);
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 600;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-secondary span {
    font-size: 1.1rem;
}

/* TV Mode Button - Special Styling */
#btn-tv-mode {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.2), rgba(41, 128, 185, 0.1));
    border: 2px solid rgba(52, 152, 219, 0.5);
    color: #5dade2;
    font-weight: 700;
}

#btn-tv-mode:hover {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.3), rgba(41, 128, 185, 0.2));
    border-color: #5dade2;
    color: white;
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.3);
}

/* Version Container (Bottom Left) */
.version-container {
    position: absolute;
    bottom: 30px;
    left: 40px;
    z-index: 10;
}

.game-version-modern {
    font-family: var(--font-code, monospace);
    font-weight: bold;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 1px;
}

.server-status {
    font-size: 0.75rem;
    color: #2ecc71;
    opacity: 0.7;
    margin-top: 4px;
}

/* Keep old styles for backwards compatibility but hidden */
.main-menu-container {
    display: none;
}

.logo-container {
    position: absolute;
    top: 40px;
    left: 60px;
}

.menu-logo {
    max-width: 250px;
    filter: drop-shadow(0 0 10px rgba(255, 215, 66, 0.3));
}

.menu-options-vertical {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 100px;
    /* Space for logo */
}

.btn-menu-modern {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 320px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0%, transparent 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-left: 4px solid var(--gold-base);
    padding: 15px 20px;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.25, 1, 0.5, 1);
    position: relative;
    overflow: hidden;
    color: white;
    font-family: var(--font-display);
    text-align: left;
}

.btn-menu-modern:hover {
    background: linear-gradient(90deg, rgba(245, 215, 66, 0.2) 0%, transparent 100%);
    padding-left: 40px;
    /* Slide effect */
    border-left-width: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* Icon / Sprite System */
.btn-menu-modern .icon {
    width: 64px;
    height: 64px;
    background-image: url('../assets/images/menu_icons.png');
    background-repeat: no-repeat;
    /* Assumption: Sprite sheet is roughly square or rectangular. 
       Let's assume the generated image is maybe 2 columns x 3 rows.
       Scaling it to fit. If the image is large, we need background-size.
       Assuming a standard grid. Let's try cover or a specific size.
       Safest is to use a large size and offsets. 
       Let's assume the sprite sheet is ~ width/2, height/3 per icon.
    */
    background-size: 200% 300%;
    background-position: var(--bg-pos, 0 0);
    /* Fallback */
    margin-right: 15px;
    image-rendering: pixelated;
    /* Essential for 16-bit look */
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

/* Calculate positions for 2x3 grid */
.btn-menu-modern .icon[style*="--icon-idx: 0"] {
    background-position: 0% 0%;
}

/* Easy */
.btn-menu-modern .icon[style*="--icon-idx: 1"] {
    background-position: 100% 0%;
}

/* Medium */
.btn-menu-modern .icon[style*="--icon-idx: 2"] {
    background-position: 0% 50%;
}

/* Hard */
.btn-menu-modern .icon[style*="--icon-idx: 3"] {
    background-position: 100% 50%;
}

/* TV */
.btn-menu-modern .icon[style*="--icon-idx: 4"] {
    background-position: 0% 100%;
}

/* Stats */
.btn-menu-modern .icon[style*="--icon-idx: 5"] {
    background-position: 100% 100%;
}

/* Patch */


.btn-menu-modern .label {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    transition: color 0.2s;
}

.btn-menu-modern:hover .label {
    color: var(--gold-base);
}

/* Special styling for TV Mode */
.btn-tv-modern {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 20px;
    border-left-color: #3498db;
}

.btn-tv-modern:hover {
    border-left-color: #5dade2;
    background: linear-gradient(90deg, rgba(52, 152, 219, 0.2), transparent);
}

.btn-tv-modern .sub-label {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 2px;
    margin-left: 47px;
    /* Align with text */
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 1px;

    /* Small buttons row */
    .menu-row {
        display: flex;
        gap: 10px;
        width: 100%;
        max-width: 320px;
    }

    .btn-small {
        flex: 1;
        font-size: 0.9rem;
        padding: 10px 15px;
    }

    .btn-small .label {
        font-size: 1rem;
    }

    .btn-small .icon {
        width: 24px;
        height: 24px;
        margin-right: 10px;
    }

    .menu-separator {
        height: 1px;
        background: rgba(255, 255, 255, 0.1);
        margin: 10px 0;
        width: 100%;
        max-width: 320px;
    }

    /* Version Container */
    .version-container {
        position: absolute;
        bottom: 20px;
        left: 30px;
        text-align: left;
        z-index: 20;
    }

    .game-version-modern {
        font-family: var(--font-code, monospace);
        font-weight: bold;
        font-size: 1.2rem;
        color: rgba(255, 255, 255, 0.3);
        letter-spacing: 1px;
    }

    .server-status {
        font-size: 0.8rem;
        color: #2ecc71;
        opacity: 0.8;
        margin-top: 5px;
        font-family: var(--font-main);
    }


    /* Auto-Start Button Animation */
    #btn-start-tv-game.all-ready {
        animation: countdown-pulse 0.5s ease-in-out infinite;
        background: linear-gradient(135deg, #2ecc71, #27ae60);
        border-color: #2ecc71;
    }

    @keyframes countdown-pulse {

        0%,
        100% {
            transform: scale(1);
            box-shadow: 0 0 20px rgba(46, 204, 113, 0.5);
        }

        50% {
            transform: scale(1.05);
            box-shadow: 0 0 40px rgba(46, 204, 113, 0.8);
        }
    }

    .player-badge {
        display: block;
        font-size: 2rem;
        font-weight: bold;
        margin-bottom: 10px;
    }

    #tv-player-1 .player-badge {
        color: #3498db;
    }

    /* Credits Modal */
    .credits-content {
        max-width: 500px;
        text-align: center;
    }

    .credits-content h3 {
        color: var(--gold-base);
        margin-top: 20px;
        margin-bottom: 10px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        padding-bottom: 5px;
    }

    .credits-content p {
        color: var(--text-muted);
        font-size: 0.95rem;
        margin-bottom: 10px;
    }

    .credits-content strong {
        color: white;
    }

    /* Music Player */
    .music-player {
        position: fixed;
        bottom: 20px;
        right: 20px;
        background: rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(10px);
        border: 1px solid var(--gold-base);
        border-radius: 30px;
        display: flex;
        align-items: center;
        padding: 10px;
        transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        z-index: 2000;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
        overflow: hidden;
        max-width: 300px;
    }

    .music-player.collapsed {
        width: 60px;
        height: 60px;
        padding: 0;
        border-radius: 50%;
        justify-content: center;
        cursor: pointer;
    }

    .music-player.collapsed .music-controls {
        display: none;
    }

    .music-icon {
        font-size: 1.5rem;
        cursor: pointer;
        animation: pulse-slow 3s infinite;
        min-width: 40px;
        text-align: center;
    }

    .music-controls {
        display: flex;
        flex-direction: column;
        gap: 10px;
        margin-left: 10px;
        width: 100%;
    }

    .music-info {
        display: flex;
        flex-direction: column;
    }

    #music-track-name {
        font-weight: bold;
        color: var(--gold-base);
        font-size: 0.9rem;
        white-space: nowrap;
    }

    .music-playlist-tag {
        font-size: 0.7rem;
        color: var(--text-muted);
        text-transform: uppercase;
    }

    .music-buttons {
        display: flex;
        gap: 10px;
        justify-content: center;
    }

    .music-buttons button {
        background: none;
        border: none;
        color: white;
        font-size: 1.2rem;
        cursor: pointer;
        transition: transform 0.1s;
    }

    .music-buttons button:hover {
        color: var(--gold-base);
        transform: scale(1.1);
    }

    .playlist-selector {
        display: flex;
        gap: 5px;
        margin-top: 5px;
    }

    .btn-playlist {
        font-size: 0.7rem;
        padding: 4px 8px;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 10px;
        color: white;
        cursor: pointer;
        flex: 1;
    }

    .btn-playlist.active {
        background: var(--gold-base);
        color: black;
        font-weight: bold;
    }

    @keyframes pulse-slow {
        0% {
            transform: scale(1);
            opacity: 1;
        }

        50% {
            transform: scale(1.1);
            opacity: 0.8;
        }

        100% {
            transform: scale(1);
            opacity: 1;
        }
    }

    #tv-player-2 .player-badge {
        color: #e74c3c;
    }

    .player-name {
        color: var(--text-muted);
        font-size: 1.1rem;
    }

    .btn-menu:hover {
        background: var(--gold-gradient);
        border-color: var(--gold-base);
        color: #1a1a1a;
        transform: translateY(-3px);
        box-shadow: var(--gold-glow), 0 10px 30px rgba(0, 0, 0, 0.4);
    }

    /* === UTILITY ANIMATIONS === */
    @keyframes pulse {

        0%,
        100% {
            transform: scale(1);
        }

        50% {
            transform: scale(1.05);
        }
    }

    @keyframes bounce {

        0%,
        100% {
            transform: translateY(0);
        }

        50% {
            transform: translateY(-5px);
        }
    }

    .animate-bounce {
        animation: bounce 0.5s ease;
    }


    /* === BUILD TOOLTIP === */
    .build-tooltip {
        position: absolute;
        background: rgba(10, 10, 15, 0.95);
        backdrop-filter: blur(10px);
        border: 1px solid var(--gold-base);
        border-radius: 12px;
        padding: 15px;
        display: flex;
        flex-direction: row;
        gap: 10px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), 0 0 15px rgba(245, 215, 66, 0.2);
        z-index: 1000;
        transform: translate(-50%, -100%);
        /* Center above slot */
        margin-top: -15px;
        /* Offset from slot */
        animation: fadeIn 0.2s ease-out;
        pointer-events: auto;
        /* Allow clicks */
    }

    .build-tooltip::after {
        content: '';
        position: absolute;
        bottom: -8px;
        left: 50%;
        margin-left: -8px;
        border-width: 8px 8px 0;
        border-style: solid;
        border-color: var(--gold-base) transparent transparent transparent;
    }

    .build-option {
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 8px;
        padding: 10px;
        width: 100px;
        text-align: center;
        cursor: pointer;
        transition: all 0.2s;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .build-option:hover {
        background: rgba(245, 215, 66, 0.1);
        border-color: var(--gold-base);
        transform: translateY(-2px);
    }

    .build-option-icon {
        font-size: 2rem;
        margin-bottom: 5px;
        color: var(--gold-base);
    }

    .build-option-name {
        font-size: 0.8rem;
        color: #fff;
        margin-bottom: 5px;
        font-weight: bold;
    }

    .build-option-cost {
        font-size: 0.85rem;
        color: var(--gold-base);
        background: rgba(0, 0, 0, 0.5);
        padding: 2px 6px;
        border-radius: 4px;
    }

    /* === SLOT VISUALS === */
    .slot-pole {
        /* Used for the vertical tower pole visual */
        fill: #4a3b2a;
        /* Wood color */
        stroke: #2a2118;
        stroke-width: 2;
    }

    @keyframes fadeIn {
        from {
            opacity: 0;
            transform: translate(-50%, -90%);
        }

        to {
            opacity: 1;
            transform: translate(-50%, -100%);
        }
    }

    /* === ACCESSIBILITY FOCUS STATES === */
    /* Visible focus for keyboard navigation */
    .btn-menu:focus-visible,
    .btn-unit:focus-visible,
    .btn-special:focus-visible,
    .btn-evolve:focus-visible,
    .btn-info:focus-visible,
    .faction-card:focus-visible,
    .build-card:focus-visible,
    .close-btn:focus-visible {
        outline: 3px solid var(--accent-base);
        outline-offset: 2px;
        box-shadow: 0 0 0 5px rgba(0, 212, 255, 0.3);
    }

    /* Remove default outline on mouse click */
    .btn-menu:focus:not(:focus-visible),
    .btn-unit:focus:not(:focus-visible),
    .btn-special:focus:not(:focus-visible),
    .btn-evolve:focus:not(:focus-visible) {
        outline: none;
    }

    /* Disabled button clarity */
    button:disabled,
    .btn-menu:disabled,
    .btn-special:disabled,
    .btn-evolve:disabled {
        opacity: 0.5;
        cursor: not-allowed;
        pointer-events: none;
    }

    /* === RESPONSIVE BREAKPOINTS === */

    /* Large screens (1280px and below) */
    @media (max-width: 1280px) {
        #headbar {
            padding: 12px 20px;
            gap: 15px;
        }

        .stat-box {
            padding: 6px 12px;
            font-size: 1rem;
        }

        .age-indicator {
            padding: 6px 20px;
            font-size: 0.95rem;
        }

        .btn-action {
            padding: 6px 14px;
            font-size: 0.8rem;
        }

        .unit-btn-container {
            width: 70px;
            height: 80px;
        }
    }

    /* Medium screens (1024px and below) */
    @media (max-width: 1024px) {
        #headbar {
            padding: 10px 15px;
            gap: 10px;
        }

        .headbar-center {
            gap: 6px;
        }

        .stat-box {
            padding: 5px 10px;
            font-size: 0.9rem;
        }

        .stat-box .icon {
            font-size: 1rem;
        }

        .age-indicator {
            padding: 5px 15px;
            font-size: 0.85rem;
            letter-spacing: 1px;
        }

        .unit-menu {
            gap: 8px;
        }

        .unit-btn-container {
            width: 60px;
            height: 70px;
        }
    }

    /* Small screens (768px and below) */
    @media (max-width: 768px) {
        #headbar {
            flex-wrap: wrap;
            padding: 8px 10px;
        }

        .headbar-left,
        .headbar-right {
            flex: 1 1 auto;
        }

        .headbar-center {
            flex: 1 1 100%;
            order: 3;
            flex-direction: row;
            justify-content: center;
        }

        .age-indicator {
            padding: 4px 12px;
            font-size: 0.8rem;
        }

        .action-buttons {
            flex-wrap: wrap;
            gap: 4px;
        }

        .btn-action {
            padding: 5px 10px;
            font-size: 0.75rem;
        }

        .unit-btn-container {
            width: 50px;
            height: 60px;
        }

        .unit-preview {
            font-size: 1.5rem;
        }

        .unit-cost {
            font-size: 0.65rem;
            padding: 2px 6px;
        }
    }

    /* Music player - ensure no overlap with headbar */
    @media (max-height: 700px) {
        .music-player {
            bottom: auto;
            top: 100px;
        }
    }

    /* === TV MODE === */
    /* Hide desktop controls when in TV Mode (host screen) */
    body.tv-mode #unit-menu,
    body.tv-mode .action-buttons,
    body.tv-mode .stat-box.xp {
        display: none !important;
    }

    body.tv-mode #headbar {
        display: none !important;
    }

    body.tv-mode .headbar-left,
    body.tv-mode .headbar-right {
        display: none !important;
    }

    body.tv-mode .headbar-center {
        display: none !important;
    }

    body.tv-mode .age-indicator {
        font-size: 1.5rem;
        padding: 12px 50px;
    }

    /* === VERSION DISPLAY === */
    .game-version {
        position: fixed;
        bottom: 15px;
        left: 15px;
        font-size: 0.75rem;
        color: rgba(255, 255, 255, 0.4);
        font-family: var(--font-main);
        letter-spacing: 1px;
        z-index: 50;
        pointer-events: none;
    }

    /* === CHANGELOG STYLES === */
    .changelog-list {
        color: var(--text-light);
    }

    .changelog-entry {
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .changelog-entry:last-child {
        border-bottom: none;
    }

    .changelog-entry h3 {
        color: var(--gold-base);
        margin-bottom: 10px;
        font-size: 1.1rem;
    }

    .changelog-entry .date {
        color: var(--text-muted);
        font-size: 0.8rem;
        font-weight: normal;
        margin-left: 10px;
    }

    .changelog-entry ul {
        list-style: none;
        padding-left: 0;
    }

    .changelog-entry li {
        padding: 4px 0;
        padding-left: 20px;
        position: relative;
        color: var(--text-muted);
        font-size: 0.9rem;
    }

    .changelog-entry li::before {
        content: '•';
        position: absolute;
        left: 0;
        color: var(--accent-base);
    }
}