/* ========================================
   THE DUNGEON'S GUARDIAN - STYLES
   ======================================== */

/* === BASE & FOUNDATION === */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700;900&family=MedievalSharp&display=swap');

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

:root {
    /* Stone Colors */
    --stone-dark: #1a1a1a;
    --stone-medium: #2d2d2d;
    --stone-light: #3d3d3d;
    --stone-border: #4a4a4a;
    
    /* Dungeon Colors */
    --dungeon-bg: #0d0d0d;
    --dungeon-wall: #1f1f1f;
    --torch-glow: rgba(255, 183, 0, 0.3);
    --torch-core: rgba(255, 200, 50, 0.5);
    
    /* Metal Colors */
    --metal-dark: #2a2a2a;
    --metal-medium: #4a4a4a;
    --metal-light: #6a6a6a;
    
    /* Gold Colors */
    --gold-dark: #b8860b;
    --gold-medium: #daa520;
    --gold-light: #ffd700;
    
    /* UI Colors */
    --panel-bg: rgba(20, 20, 20, 0.95);
    --panel-border: #3d3d3d;
    --text-primary: #d4d4d4;
    --text-secondary: #888;
    --text-accent: #ffd700;
}

body {
    font-family: 'Cinzel', serif;
    background: var(--dungeon-bg);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden; /* Prevent scrolling */
    position: relative;
    display: flex;
    flex-direction: column;
}

/* === TORCHLIGHT EFFECTS === */
.torchlight {
    position: fixed;
    top: 0;
    width: 300px;
    height: 100vh;
    pointer-events: none;
    z-index: 1;
    opacity: 0.4;
    mix-blend-mode: screen;
    filter: blur(60px);
}

.torch-left {
    left: -150px;
    background: radial-gradient(ellipse at center, var(--torch-core) 0%, var(--torch-glow) 40%, transparent 70%);
    animation: torchFlicker 4s ease-in-out infinite;
}

.torch-right {
    right: -150px;
    background: radial-gradient(ellipse at center, var(--torch-core) 0%, var(--torch-glow) 40%, transparent 70%);
    animation: torchFlicker 5s ease-in-out infinite reverse;
}

@keyframes torchFlicker {
    0%, 100% { opacity: 0.3; transform: translateX(0); }
    25% { opacity: 0.4; transform: translateX(5px); }
    50% { opacity: 0.35; transform: translateX(-3px); }
    75% { opacity: 0.45; transform: translateX(4px); }
}

/* === STONE TEXTURE OVERLAY === */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    background-image: 
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 50px,
            rgba(0, 0, 0, 0.03) 50px,
            rgba(0, 0, 0, 0.03) 51px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 50px,
            rgba(0, 0, 0, 0.03) 50px,
            rgba(0, 0, 0, 0.03) 51px
        );
}

/* === MAIN SCROLL CONTAINER === */
.main-scroll {
    position: relative;
    z-index: 3;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    animation: fadeIn 1s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === HEADER WITH PARCHMENT STYLE === */
.parchment-header {
    text-align: center;
    padding: 30px 20px;
    margin-bottom: 30px;
    background: linear-gradient(135deg, var(--stone-dark) 0%, var(--stone-medium) 50%, var(--stone-dark) 100%);
    border: 2px solid var(--stone-border);
    position: relative;
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        0 8px 32px rgba(0, 0, 0, 0.8);
}

.parchment-header::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    pointer-events: none;
}

.ornament {
    font-size: 2rem;
    color: var(--gold-dark);
    text-shadow: 0 0 10px var(--gold-medium);
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

.ornament-left { left: 20px; }
.ornament-right { right: 20px; }

.title-container {
    display: inline-block;
    padding: 0 60px;
}

.title {
    font-family: 'MedievalSharp', cursive;
    font-size: 2.8rem;
    font-weight: 900;
    margin-bottom: 8px;
    background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold-medium) 50%, var(--gold-dark) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
    letter-spacing: 3px;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-style: italic;
    letter-spacing: 2px;
}

/* === DUNGEON INFO CRYSTALS === */
.dungeon-info {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 20px;
}

.info-crystal {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--stone-border);
    border-radius: 4px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.8);
}

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

.crystal-phase .crystal-icon { color: #9370db; }
.crystal-wave .crystal-icon { color: #dc143c; }

/* === RESOURCES BAR === */
.resources-bar {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, rgba(20, 20, 20, 0.9) 0%, rgba(30, 30, 30, 0.9) 100%);
    border: 2px solid var(--stone-border);
    border-radius: 8px;
    box-shadow: 
        0 4px 16px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.resource-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 25px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--stone-border);
    border-radius: 6px;
    min-width: 160px;
}

.resource-icon {
    font-size: 1.8rem;
    filter: drop-shadow(0 0 8px currentColor);
}

.resource-container {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.resource-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.resource-value {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-accent);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

/* === MAIN CONTENT LAYOUT === */
.main-content {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 25px;
    align-items: start;
}

/* === CHAMBER WRAPPER (GAME GRID) === */
.chamber-wrapper {
    display: flex;
    justify-content: center;
}

.chamber-frame {
    position: relative;
    padding: 20px;
    background: linear-gradient(135deg, var(--stone-dark) 0%, var(--stone-medium) 100%);
    border: 3px solid var(--stone-border);
    border-radius: 12px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.8),
        inset 0 2px 0 rgba(255, 255, 255, 0.05);
}

.chamber-decor {
    position: absolute;
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, var(--metal-dark) 0%, var(--metal-light) 100%);
    border: 2px solid var(--stone-border);
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    z-index: 5;
}

.chamber-decor-tl { top: -8px; left: -8px; border-radius: 4px 0 8px 0; }
.chamber-decor-tr { top: -8px; right: -8px; border-radius: 0 4px 0 8px; }
.chamber-decor-bl { bottom: -8px; left: -8px; border-radius: 0 8px 0 4px; }
.chamber-decor-br { bottom: -8px; right: -8px; border-radius: 8px 0 4px 0; }

#game-grid {
    display: block;
    border-radius: 6px;
    cursor: crosshair;
    box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.8);
}

/* === COLLAPSE OVERLAY (Full-screen Dungeon Collapse Animation) === */
.collapse-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.collapse-overlay.active {
    opacity: 1;
}

#collapse-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* === CONTROLS SCROLL === */
.controls-scroll {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* === DARK PANEL STYLE === */
.dark-panel {
    background: var(--panel-bg);
    border: 2px solid var(--panel-border);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 
        0 4px 16px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    position: relative;
    overflow: hidden;
}

.dark-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--stone-border), transparent);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--stone-border);
}

.panel-icon {
    font-size: 1.4rem;
    filter: drop-shadow(0 0 5px currentColor);
}

.panel-header h3 {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.1rem;
    color: var(--text-accent);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.2);
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* === CONSTRUCTION BUTTONS === */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.construction-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 15px 10px;
    background: linear-gradient(135deg, rgba(40, 40, 40, 0.8) 0%, rgba(25, 25, 25, 0.8) 100%);
    border: 2px solid var(--stone-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.construction-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent);
    transition: left 0.5s ease;
}

.construction-btn:hover::before {
    left: 100%;
}

.construction-btn:hover {
    border-color: var(--gold-medium);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
    transform: translateY(-2px);
}

.construction-btn.active {
    background: linear-gradient(135deg, rgba(218, 165, 32, 0.2) 0%, rgba(184, 134, 11, 0.2) 100%);
    border-color: var(--gold-medium);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.btn-icon {
    font-size: 1.8rem;
    filter: drop-shadow(0 0 3px currentColor);
}

.btn-label {
    font-weight: 600;
    letter-spacing: 0.5px;
}

.btn-cost {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.wall-btn .btn-icon { color: #8b4513; }
.trap-btn .btn-icon { color: #dc143c; }
.remove-btn .btn-icon { color: #808080; }

.remove-btn.active {
    border-color: #e74c3c !important;
    background: rgba(231, 76, 60, 0.2) !important;
}

.upgrade-btn.active {
    border-color: #3498db !important;
    background: rgba(52, 152, 219, 0.2) !important;
}

/* V2 Tool Button Colors */
.portal-btn .btn-icon { color: #00ced1; text-shadow: 0 0 8px rgba(0, 206, 209, 0.5); }
.wolf_trap-btn .btn-icon { color: #8b4513; text-shadow: 0 0 8px rgba(139, 69, 19, 0.4); }
.sticky-btn .btn-icon { color: #32cd32; text-shadow: 0 0 8px rgba(50, 205, 50, 0.4); }
.push_up-btn .btn-icon { color: #87ceeb; text-shadow: 0 0 8px rgba(135, 206, 235, 0.4); }
.push_down-btn .btn-icon { color: #87ceeb; text-shadow: 0 0 8px rgba(135, 206, 235, 0.4); }
.push_left-btn .btn-icon { color: #87ceeb; text-shadow: 0 0 8px rgba(135, 206, 235, 0.4); }
.push_right-btn .btn-icon { color: #87ceeb; text-shadow: 0 0 8px rgba(135, 206, 235, 0.4); }
.fog-btn .btn-icon { color: #d3d3d3; text-shadow: 0 0 8px rgba(211, 211, 211, 0.4); }
.mine-btn .btn-icon { color: #ff0000; text-shadow: 0 0 8px rgba(255, 0, 0, 0.5); }
.bleed-btn .btn-icon { color: #dc143c; text-shadow: 0 0 8px rgba(220, 20, 60, 0.5); }
.turret-btn .btn-icon { color: #708090; text-shadow: 0 0 8px rgba(112, 128, 144, 0.4); }
.golem-btn .btn-icon { color: #808080; text-shadow: 0 0 8px rgba(128, 128, 128, 0.4); }
.totem-btn .btn-icon { color: #9932cc; text-shadow: 0 0 8px rgba(153, 50, 204, 0.4); }
.banner-btn .btn-icon { color: #800000; text-shadow: 0 0 8px rgba(128, 0, 0, 0.4); }
.chest-btn .btn-icon { color: #daa520; text-shadow: 0 0 8px rgba(218, 165, 32, 0.4); }
.beacon-btn .btn-icon { color: #4834d4; text-shadow: 0 0 8px rgba(72, 52, 212, 0.4); }

/* === HORIZONTAL SELECTOR === */
.selector-container {
    margin-bottom: 12px;
}

.selector-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding-left: 4px;
}

.horizontal-selector {
    display: flex;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--stone-border);
    border-radius: 6px;
    overflow: hidden;
    padding: 2px;
}

.selector-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 4px;
    font-family: 'Cinzel', serif;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 4px;
}

.selector-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.selector-btn.active {
    background: var(--gold-dark);
    color: #000;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* === STRATEGY DROPDOWN === */
.strategy-dropdown {
    width: 100%;
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(40, 40, 40, 0.8) 0%, rgba(25, 25, 25, 0.8) 100%);
    border: 2px solid var(--stone-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    cursor: pointer;
    outline: none;
    transition: all 0.3s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffd700' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
    padding-right: 40px;
}

.strategy-dropdown:hover {
    border-color: var(--gold-medium);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.15);
}

.strategy-dropdown:focus {
    border-color: var(--gold-medium);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.25);
}

.strategy-dropdown option {
    background: var(--stone-dark);
    color: var(--text-primary);
}

/* === COMMAND BUTTONS === */
.command-grid {
    display: grid;
    gap: 10px;
}

.command-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 20px;
    border: 2px solid var(--stone-border);
    border-radius: 8px;
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.command-btn .btn-icon {
    font-size: 1.4rem;
}

.attack-btn {
    background: linear-gradient(135deg, #8b0000 0%, #660000 100%);
    border-color: #a52a2a;
    color: #ffd700;
    box-shadow: 0 4px 16px rgba(139, 0, 0, 0.4);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.attack-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #a52a2a 0%, #8b0000 100%);
    border-color: #dc143c;
    box-shadow: 0 0 20px rgba(220, 20, 60, 0.5);
    transform: translateY(-2px);
}

.step-btn {
    background: linear-gradient(135deg, #2f4f4f 0%, #1a2f2f 100%);
    border-color: #3d5c5c;
    color: var(--text-primary);
}

.step-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #3d5c5c 0%, #2f4f4f 100%);
    border-color: #4a6b6b;
    transform: translateY(-2px);
}

.auto-btn {
    background: linear-gradient(135deg, #4b0082 0%, #2d0052 100%);
    border-color: #5b1a8a;
    color: #e0e0e0;
}

.auto-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #5b1a8a 0%, #4b0082 100%);
    border-color: #6b2a9a;
    transform: translateY(-2px);
}

.recap-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(135deg, #1a1a1a 0%, #000 100%);
    border: 2px solid var(--gold-dark);
    border-radius: 8px;
    color: var(--gold-light);
    font-family: 'MedievalSharp', cursive;
    font-size: 0.95rem;
    font-weight: 700;
    grid-column: span 2;
    margin-top: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    padding: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
}

.recap-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #333 0%, #1a1a1a 100%);
    border-color: var(--gold-light);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
    transform: translateY(-2px);
    color: #fff;
}

.recap-btn .btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    flex-shrink: 0;
    filter: drop-shadow(0 0 5px rgba(255, 215, 0, 0.3));
}

.recap-btn .btn-text {
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: inherit;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.recap-btn svg {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
}

.recap-btn:hover svg {
    transform: rotate(-10deg) scale(1.1);
}

.command-btn:disabled, .command-btn-compact:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* === SAVE BUTTONS === */
.save-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.save-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: linear-gradient(135deg, rgba(40, 40, 40, 0.8) 0%, rgba(25, 25, 25, 0.8) 100%);
    border: 2px solid var(--stone-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-btn:hover {
    border-color: var(--gold-medium);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
    transform: translateY(-2px);
}

.save-btn .btn-icon {
    font-size: 1.5rem;
    filter: drop-shadow(0 0 3px currentColor);
}

.save-btn.danger {
    background: linear-gradient(135deg, rgba(139, 0, 0, 0.3) 0%, rgba(102, 0, 0, 0.3) 100%);
}

.save-btn.danger:hover {
    background: linear-gradient(135deg, rgba(220, 20, 60, 0.4) 0%, rgba(139, 0, 0, 0.4) 100%);
    border-color: #dc143c;
}

/* === LEGEND PANEL === */
.legend-panel {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 30px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--stone-border);
    border-radius: 8px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(20, 20, 20, 0.6);
    border-radius: 4px;
}

.legend-icon {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid var(--stone-border);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.icon-empty {
    background: linear-gradient(135deg, #1a1a1a 0%, #0d0d0d 100%);
}

.icon-wall {
    background: linear-gradient(135deg, #8b4513 0%, #654321 100%);
    border: 2px solid #a0522d;
}

.icon-trap {
    background: linear-gradient(135deg, #dc143c 0%, #8b0000 100%);
    border: 2px solid #ff0000;
}

.icon-treasure {
    background: linear-gradient(135deg, #ffd700 0%, #daa520 100%);
    border: 2px solid #ffed4e;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.icon-start {
    background: linear-gradient(135deg, #228b22 0%, #006400 100%);
    border: 2px solid #32cd32;
}

.icon-hero {
    background: linear-gradient(135deg, #4169e1 0%, #000080 100%);
    border: 2px solid #6495ed;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(65, 105, 225, 0.5);
}

/* === NOTIFICATIONS === */
.notification {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 16px 32px;
    border-radius: 8px;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1000;
    border: 2px solid var(--stone-border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
}

.notification.show {
    opacity: 1;
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.notification.success {
    background: linear-gradient(135deg, rgba(34, 139, 34, 0.9) 0%, rgba(0, 100, 0, 0.9) 100%);
    border-color: #32cd32;
    color: #ffd700;
    box-shadow: 0 8px 32px rgba(50, 205, 50, 0.3);
}

.notification.error {
    background: linear-gradient(135deg, rgba(220, 20, 60, 0.9) 0%, rgba(139, 0, 0, 0.9) 100%);
    border-color: #ff0000;
    color: #ffd700;
    box-shadow: 0 8px 32px rgba(255, 0, 0, 0.3);
}

.notification.info {
    background: linear-gradient(135deg, rgba(65, 105, 225, 0.9) 0%, rgba(0, 0, 128, 0.9) 100%);
    border-color: #6495ed;
    color: #ffd700;
    box-shadow: 0 8px 32px rgba(100, 149, 237, 0.3);
}

/* === MODAL === */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.modal.show {
    display: flex;
    animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* === ENTITY TOOLTIP === */
.entity-tooltip {
    position: fixed;
    display: none;
    z-index: 9999 !important;
    pointer-events: none;
    background: rgba(20, 20, 20, 0.95);
    border: 2px solid var(--gold-medium);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    font-family: 'Cinzel', serif;
    color: var(--text-primary);
    transform: translate(15px, 15px);
}

.tooltip-container {
    display: flex;
    flex-direction: row;
    gap: 0;
}

.tooltip-entity-section {
    padding: 15px;
    min-width: 250px;
}

.tooltip-entity-section:not(:last-child) {
    border-right: 1px dashed rgba(255, 215, 0, 0.3);
}

.entity-tooltip.show {
    display: block !important;
    animation: modalFadeIn 0.1s ease-out;
}

.tooltip-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--stone-border);
}

.tooltip-icon {
    font-size: 1.5rem;
    filter: drop-shadow(0 0 5px currentColor);
}

.tooltip-title {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.2rem;
    color: var(--text-accent);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tooltip-stats {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.stat-label {
    color: var(--text-secondary);
}

.stat-value {
    color: #fff;
    font-weight: 700;
}

.stat-value.highlight {
    color: var(--gold-light);
}

.upgrade-row {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed rgba(255, 215, 0, 0.3);
}

.stat-value.gold {
    color: var(--gold-light);
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
}

.status-active {
    color: #4ade80 !important; /* Green */
}

.status-inactive {
    color: #f87171 !important; /* Red */
    text-decoration: line-through;
    opacity: 0.8;
}

.tooltip-desc {
    margin-top: 10px;
    font-size: 0.8rem;
    color: #aaa;
    font-style: italic;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 8px;
}

.modal-content {
    background: linear-gradient(135deg, var(--stone-dark) 0%, var(--stone-medium) 100%);
    padding: 40px;
    border: 3px solid var(--gold-medium);
    border-radius: 12px;
    max-width: 550px;
    width: 90%;
    box-shadow: 
        0 16px 48px rgba(0, 0, 0, 0.8),
        0 0 30px rgba(255, 215, 0, 0.2);
    position: relative;
}

.modal-content::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    border: 1px solid rgba(255, 215, 0, 0.2);
    border-radius: 8px;
    pointer-events: none;
}

.modal-content h2 {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.8rem;
    margin-bottom: 25px;
    color: var(--gold-light);
    text-align: center;
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
    letter-spacing: 2px;
}

#modal-body {
    margin-bottom: 30px;
    line-height: 1.8;
    color: var(--text-primary);
}

/* Load Game Modal Styles */
.load-game-container {
    padding: 10px 0;
}

.modal-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 1rem;
}

.saves-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
}

/* Custom scrollbar for saves list */
.saves-list::-webkit-scrollbar {
    width: 10px;
}

.saves-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
}

.saves-list::-webkit-scrollbar-thumb {
    background: var(--gold-dark);
    border-radius: 5px;
    border: 1px solid var(--gold-medium);
}

.saves-list::-webkit-scrollbar-thumb:hover {
    background: var(--gold-medium);
}

/* Firefox scrollbar for saves list */
.saves-list {
    scrollbar-width: thin;
    scrollbar-color: var(--gold-dark) rgba(0, 0, 0, 0.3);
}

.save-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: rgba(45, 45, 45, 0.6);
    border: 2px solid var(--metal-medium);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.save-item:hover {
    background: rgba(45, 45, 45, 0.8);
    border-color: var(--gold-light);
}

.save-item input[type="radio"] {
    margin-right: 12px;
    cursor: pointer;
    width: 18px;
    height: 18px;
    accent-color: var(--gold-light);
}

.save-item input[type="radio"]:checked ~ .save-item-name {
    color: var(--gold-light);
    font-weight: 700;
}

.save-item-name {
    flex: 1;
    font-size: 1.1rem;
    color: var(--text-primary);
    transition: color 0.2s ease;
}

.save-item-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.save-item-wrapper .save-item {
    flex: 1;
    margin-bottom: 0;
}

.delete-save-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: rgba(220, 20, 60, 0.2);
    border: 2px solid rgba(220, 20, 60, 0.5);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.delete-save-btn:hover {
    background: rgba(220, 20, 60, 0.4);
    border-color: #dc143c;
    box-shadow: 0 0 10px rgba(220, 20, 60, 0.3);
    transform: scale(1.05);
}

.delete-save-btn:active {
    transform: scale(0.95);
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.modal-actions.dual {
    gap: 15px;
}

.modal-actions .action-btn {
    padding: 14px 40px;
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold-medium) 100%);
    border: 2px solid var(--gold-light);
    color: var(--stone-dark);
    font-weight: 700;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.modal-actions .action-btn.primary {
    background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold-medium) 100%);
    border-color: var(--gold-light);
}

.modal-actions .action-btn:not(.primary) {
    background: linear-gradient(135deg, var(--metal-medium) 0%, var(--metal-dark) 100%);
    border-color: var(--metal-light);
    color: var(--text-primary);
}

.modal-actions .action-btn:hover {
    background: linear-gradient(135deg, var(--gold-medium) 0%, var(--gold-light) 100%);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
    transform: translateY(-2px);
    border-color: var(--gold-light);
}

.modal-actions .action-btn:not(.primary):hover {
    background: linear-gradient(135deg, var(--metal-light) 0%, var(--metal-medium) 100%);
    box-shadow: 0 0 20px rgba(100, 100, 100, 0.5);
    border-color: var(--stone-border);
}

/* Input Modal Styles */
.input-group {
    margin: 20px 0;
}

.save-name-field {
    width: 100%;
    padding: 14px 16px;
    background: rgba(45, 45, 45, 0.6);
    border: 2px solid var(--metal-medium);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.save-name-field:focus {
    outline: none;
    background: rgba(45, 45, 45, 0.8);
    border-color: var(--gold-light);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
}

.save-name-field::placeholder {
    color: var(--text-secondary);
}

/* === RESPONSIVE DESIGN === */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        justify-items: center;
    }
    
    .controls-scroll {
        width: 100%;
        max-width: 580px;
    }
}

@media (max-width: 768px) {
    .title {
        font-size: 2rem;
    }
    
    .subtitle {
        font-size: 0.9rem;
    }
    
    .ornament {
        display: none;
    }
    
    .title-container {
        padding: 0 20px;
    }
    
    .resources-bar {
        flex-direction: column;
        align-items: center;
    }
    
    .resource-item {
        width: 100%;
        max-width: 300px;
    }
    
    .dungeon-info {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    
    .legend-panel {
        flex-direction: column;
        align-items: center;
    }
    
    #game-grid {
        width: 100%;
        height: auto;
    }
}

@media (max-width: 480px) {
    .main-scroll {
        padding: 10px;
    }
    
    .tools-grid,
    .save-grid {
        grid-template-columns: 1fr;
    }
    
    .command-btn {
        flex-direction: column;
        gap: 5px;
        padding: 12px 15px;
    }
}

.tool-buttons,
.action-buttons,
.save-load-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.tool-btn,
.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.tool-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #eee;
    border: 2px solid transparent;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.tool-btn.active {
    border-color: #f39c12;
    background: rgba(243, 156, 18, 0.2);
}

.action-btn {
    background: rgba(255, 255, 255, 0.15);
    color: #eee;
}

.action-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.action-btn.primary {
    background: #e74c3c;
}

.action-btn.primary:hover:not(:disabled) {
    background: #c0392b;
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.legend-color.empty {
    background: #2c3e50;
}

.legend-color.wall {
    background: #8b4513;
}

.legend-color.trap {
    background: #c0392b;
}

.legend-color.treasure {
    background: #f39c12;
}

.legend-color.start {
    background: #27ae60;
}

.legend-color.hero {
    background: #3498db;
    border-radius: 50%;
}

.notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.notification.show {
    opacity: 1;
}

.notification.success { background: rgba(39, 174, 96, 0.9); }
.notification.error { background: rgba(231, 76, 60, 0.9); }
.notification.info { background: rgba(52, 152, 219, 0.9); }

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.82);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-actions, .defeat-actions {
    margin-top: 0;
    padding: 20px 30px 30px 30px;
    flex-shrink: 0;
    z-index: 2;
    background: rgba(0, 0, 0, 0.4);
    border-top: 1px solid var(--gold-dark);
    display: flex;
    justify-content: center;
}

.modal-actions.dual {
    justify-content: space-between;
    gap: 15px;
}

.action-btn {
    padding: 12px 30px;
    font-family: 'MedievalSharp', cursive;
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--stone-dark);
    background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold-medium) 50%, var(--gold-dark) 100%);
    border: 2px solid var(--gold-light);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.action-btn:hover:not(:disabled) {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 6px 18px rgba(184, 134, 11, 0.4);
    filter: brightness(1.1);
}

.action-btn.primary, .action-btn.continue-btn {
    background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold-medium) 50%, var(--gold-dark) 100%);
    border-color: var(--gold-light);
    color: var(--dungeon-bg);
    box-shadow: 0 4px 15px rgba(184, 134, 11, 0.4);
    font-weight: 900;
}

.action-btn.continue-btn:hover {
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.6);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
}

/* Harmonized Modal Styles */
.modal-content, .parchment-modal {
    background: radial-gradient(circle at center, var(--stone-dark) 0%, var(--dungeon-bg) 100%) !important;
    border: 3px solid var(--gold-dark) !important;
    box-shadow:
        0 0 40px rgba(0, 0, 0, 0.8),
        inset 0 0 30px rgba(0, 0, 0, 0.9),
        0 0 0 2px rgba(184, 134, 11, 0.3) !important;
    max-width: 650px !important;
    width: 90%;
    margin: 30px auto;
    padding: 0;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    animation: modalSlideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex !important;
    flex-direction: column !important;
    max-height: calc(100vh - 60px);
}

/* Add noise texture to match defeat modal */
.modal-content::before, .parchment-modal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E"),
        linear-gradient(135deg, rgba(184, 134, 11, 0.05) 0%, rgba(0, 0, 0, 0.1) 100%);
    opacity: 0.1;
    pointer-events: none;
    mix-blend-mode: overlay;
    z-index: 0;
}

/* Inner Gold Border (like defeat modal) */
.modal-content::after, .parchment-modal::after {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border: 1px solid rgba(184, 134, 11, 0.2);
    border-radius: 4px;
    pointer-events: none;
    z-index: 2;
}

.modal-content h2 {
    margin: 0;
    padding: 25px 0;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 2px solid var(--gold-dark);
    font-family: 'MedievalSharp', cursive;
    color: var(--gold-medium);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 4px;
    font-size: 2rem;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.8), 0 0 20px rgba(184, 134, 11, 0.4);
    position: relative;
    z-index: 1;
}

/* Ornamental H2 */
.modal-content h2::before, .modal-content h2::after {
    content: '⚜';
    color: var(--gold-dark);
    font-size: 1.2rem;
    vertical-align: middle;
    margin: 0 15px;
    opacity: 0.8;
}


#wave-summary-content {
    padding: 25px;
    z-index: 1;
}

#modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 1;
    padding: 0; /* Reset padding, inner containers will handle it */
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: scale(0.8) translateY(30px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-content h2 {
    margin: 0;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 2px solid var(--gold-dark);
    font-family: 'MedievalSharp', cursive;
    color: var(--gold-light);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#wave-summary-content {
    padding: 25px;
    line-height: 1.6;
}

@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }

    .stats-panel {
        flex-direction: column;
        gap: 10px;
        align-items: center;
    }

    .main-content {
        flex-direction: column;
        align-items: center;
    }

    #game-grid {
        width: 100%;
        height: auto;
    }
}

/* ========================================
   SINGLE WINDOW LAYOUT COMPONENT
   ======================================== */


/* ========================================
   SINGLE WINDOW CHAMPION LAYOUT
   ======================================== */

.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
    z-index: 10;
}

/* === HEADER: The Command Bridge === */
.app-header {
    height: 70px;
    background: linear-gradient(180deg, var(--stone-dark) 0%, #151515 100%);
    border-bottom: 3px solid var(--stone-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    position: relative;
    z-index: 20;
}

.app-header::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-dark), transparent);
    box-shadow: 0 0 10px var(--gold-medium);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 15px;
}

.ornament-mini {
    font-size: 1.8rem;
    color: var(--gold-dark);
    text-shadow: 0 0 10px var(--gold-medium);
    animation: pulse 3s infinite;
}

.app-title {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.4rem;
    letter-spacing: 2px;
    background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold-medium) 50%, var(--gold-dark) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
    margin: 0;
}

.header-info {
    display: flex;
    gap: 20px;
    background: rgba(0,0,0,0.3);
    padding: 8px 12px;
    border-radius: 30px;
    border: 1px solid rgba(255,255,255,0.05);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5), 0 5px 15px rgba(0,0,0,0.3);
    pointer-events: auto;
    z-index: 10;
}

.compact-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.header-resources {
    display: flex;
    gap: 15px;
}

.trophy-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, rgba(40, 40, 40, 0.6) 0%, rgba(20, 20, 20, 0.8) 100%);
    border: 1px solid var(--gold-medium);
    padding: 8px 15px;
    border-radius: 6px;
    min-width: 90px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.1);
}

.trophy-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--gold-dark), transparent);
}

.resource-icon-mini {
    font-size: 1rem;
}

.resource-val {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-accent);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.2);
}

/* === WORKSPACE: The Dungeon Floor === */
.game-workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.viewport-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, rgba(30, 30, 30, 0.5) 0%, rgba(10, 10, 10, 0.8) 100%);
    padding: 20px;
    position: relative;
}

/* === SIDEBAR: The Control Monolith === */
.controls-sidebar {
    width: 340px;
    background: linear-gradient(270deg, var(--stone-dark) 0%, #111 100%);
    border-left: 3px solid var(--stone-border);
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 20px;
    box-shadow: -10px 0 30px rgba(0,0,0,0.8);
    overflow-y: auto;
    z-index: 15;
}

.control-group {
    background: var(--panel-bg);
    border: 2px solid var(--panel-border);
    border-radius: 8px;
    padding: 15px;
    position: relative;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
}

.control-group::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 10%;
    width: 80%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--stone-border), transparent);
}

.group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.group-header h4 {
    font-family: 'MedievalSharp', cursive;
    color: var(--text-accent);
    margin: 0;
    font-size: 1.1rem;
    letter-spacing: 1px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.1);
}

/* --- Improved Buttons --- */
.tools-compact {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 80px;
    background: linear-gradient(135deg, rgba(50,50,50,0.6) 0%, rgba(30,30,30,0.8) 100%);
    border: 1px solid var(--stone-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.tool-btn:hover {
    transform: translateY(-3px);
    border-color: var(--gold-medium);
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

.tool-btn.active {
    background: linear-gradient(135deg, rgba(184, 134, 11, 0.2) 0%, rgba(139, 69, 19, 0.2) 100%);
    border-color: var(--gold-light);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2), inset 0 0 10px rgba(255, 215, 0, 0.1);
}

.tool-btn .btn-icon {
    font-size: 1.8rem;
    margin-bottom: 5px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
    transition: transform 0.3s;
}

.tool-btn:hover .btn-icon {
    transform: scale(1.1);
}

.cost-badge {
    background: rgba(0,0,0,0.6);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    color: var(--gold-light);
    border: 1px solid rgba(184, 134, 11, 0.3);
}

/* --- Battle Controls --- */
.battle-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.command-btn-compact {
    padding: 12px;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    border: 2px solid;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    background-size: 200% auto;
}

.command-btn-compact.attack-btn {
    background-image: linear-gradient(45deg, #8b0000 0%, #a52a2a 50%, #8b0000 100%);
    border-color: #dc143c;
    color: #ffd700;
    box-shadow: 0 4px 15px rgba(139, 0, 0, 0.4);
    background-size: 200% auto;
}

.command-btn-compact.attack-btn:hover:not(:disabled) {
    background-position: right center;
    box-shadow: 0 0 20px rgba(220, 20, 60, 0.6);
}

.sub-controls {
    display: flex;
    gap: 10px;
}

.sub-controls .command-btn {
    flex: 1;
    padding: 12px 16px;
    font-size: 0.9rem;
    gap: 6px;
}

.sub-controls .command-btn-compact {
    flex: 1;
    background: transparent;
    border-color: var(--stone-border);
    color: var(--text-secondary);
}

.sub-controls .command-btn-compact:hover:not(:disabled) {
    border-color: var(--text-primary);
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}

.speed-control {
    display: flex;
    gap: 10px;
}

.speed-control .command-btn-compact {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 5px;
    height: auto;
    min-height: 40px;
}

.speed-control .command-btn-compact .btn-icon {
    margin-bottom: 0;
    font-size: 1.2rem;
}

.speed-control .command-btn-compact .btn-text {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0;
}

.command-btn-compact.speed-btn {
    background-image: linear-gradient(45deg, #daa520 0%, #ffd700 50%, #daa520 100%);
    border-color: var(--gold-light);
    color: var(--stone-dark);
    box-shadow: 0 4px 15px rgba(218, 165, 32, 0.4);
    background-size: 200% auto;
}

.command-btn-compact.speed-btn:hover:not(:disabled) {
    background-position: right center;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

.command-btn-compact.speed-btn.fast-speed {
    background-image: linear-gradient(45deg, #ff6b35 0%, #ff8c42 50%, #ff6b35 100%);
    border-color: #ff8c42;
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 107, 53, 0.5);
}

/* --- Legend Bar --- */
/* --- Avant-Garde Resource Bar --- */
.premium-resource-bar {
    margin-top: 25px;
    display: flex;
    align-items: center;
    background: rgba(15, 15, 15, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 215, 0, 0.2);
    border-radius: 50px;
    padding: 6px 12px;
    gap: 0;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.7),
        inset 0 0 20px rgba(255, 215, 0, 0.03);
    position: relative;
    overflow: visible;
}

.premium-resource-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.3), transparent);
}

.resource-segment {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 8px 25px;
    position: relative;
    z-index: 1;
}

.segment-icon {
    font-size: 1.2rem;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.2));
}

.segment-value {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.budget-segment .segment-value {
    color: var(--gold-medium);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.life-segment .segment-value {
    color: #00d2ff;
    text-shadow: 0 0 10px rgba(0, 210, 255, 0.3);
}

.resource-divider {
    width: 1px;
    height: 30px;
    background: linear-gradient(to bottom, transparent, var(--gold-medium), transparent);
    opacity: 0.3;
    align-self: center;
}

.premium-resource-bar:hover {
    border-color: rgba(255, 215, 0, 0.4);
    background: rgba(20, 20, 20, 0.9);
}

.premium-resource-bar.shake {
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

/* Life segment uses base .resource-segment styles for consistency */

.health-bar-container {
    width: 120px;
    height: 10px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid rgba(0, 210, 255, 0.2);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
    position: relative;
}

.health-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #00d2ff, #3a7bd5, #00d2ff);
    background-size: 200% 100%;
    animation: liquid-flow 2s linear infinite;
    box-shadow: 0 0 15px rgba(0, 210, 255, 0.6);
    transition: width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-radius: 20px;
}

.particle-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.damage-diamond {
    position: absolute;
    font-size: 1.2rem;
    animation: diamond-fall var(--duration, 3s) cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    opacity: 0;
    pointer-events: none;
    z-index: 100;
}

@keyframes liquid-flow {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

@keyframes diamond-fall {
    0% {
        transform: translateY(0) translateX(0) scale(var(--scale, 1)) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    20% {
        /* Initial "pop" or kinetic impact effect */
        transform: translateY(-20px) translateX(calc(var(--x-drift) * 0.05)) scale(var(--scale, 1)) rotate(calc(var(--rotation) * 0.1));
    }
    100% {
        transform: translateY(110vh) translateX(var(--x-drift)) scale(0.3) rotate(var(--rotation));
        opacity: 0;
    }
}

/* --- Reward & Gain Animations (Premium UX) --- */
.reward-particle {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    font-size: 1.5rem;
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.5));
    animation: reward-fly var(--duration, 1s) cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes reward-fly {
    0% {
        transform: translate(0, 0) scale(0) rotate(0deg);
        opacity: 0;
    }
    20% {
        transform: translate(var(--pop-x), var(--pop-y)) scale(1.5) rotate(45deg);
        opacity: 1;
    }
    100% {
        transform: translate(var(--target-x), var(--target-y)) scale(0.5) rotate(720deg);
        opacity: 0;
    }
}

/* Impact effects on counters */
.gain-impact {
    animation: counter-pulse 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes counter-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); filter: brightness(1.5) drop-shadow(0 0 15px currentColor); }
    100% { transform: scale(1); }
}

/* Prestigious glow for trophies */
.prestige-glow {
    position: relative;
}

.prestige-glow::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.3) 0%, transparent 70%);
    animation: prestige-shine 1s ease-out forwards;
    pointer-events: none;
}

@keyframes prestige-shine {
    0% { transform: scale(0); opacity: 0; }
    50% { opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* --- Save/Load Minis --- */
.save-row {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.save-btn-mini {
    flex: 1;
    padding: 10px;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--stone-border);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.3s;
}

.save-btn-mini:hover {
    border-color: var(--gold-medium);
    color: var(--text-primary);
    background: rgba(255, 215, 0, 0.05);
}

.save-btn-mini.danger:hover {
    border-color: #dc143c;
    background: rgba(220, 20, 60, 0.1);
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 0.8; }
}


.compact-select {
    padding: 10px;
    font-size: 0.9rem;
    height: 45px;
}

.save-btn-mini .btn-icon {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

/* ========================================
   DUAL SIDEBAR LAYOUT ADJUSTMENTS
   ======================================== */

.controls-sidebar {
    width: 320px; /* Increased from 280px to fit 3 columns */
    padding: 15px; 
    gap: 12px;     
    display: flex;
    flex-direction: column;
    z-index: 15;
    background: linear-gradient(180deg, var(--stone-dark) 0%, #111 100%);
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
}

.sidebar-left {
    border-right: 3px solid var(--stone-border);
    border-left: none;
    order: 1; /* Ensure it stays on left */
}

.sidebar-right {
    border-left: 3px solid var(--stone-border);
    order: 3; /* Ensure it stays on right */
    padding: 15px; /* Added back a bit of air */
    gap: 12px;
}

.sidebar-right .control-group {
    padding: 12px; /* Increased from 10px */
}

.sidebar-right .group-header {
    margin-bottom: 10px;  /* Slightly increased */
    padding-bottom: 8px;
}

.sidebar-right .selector-container {
    margin-bottom: 10px;  /* Slightly increased */
}

.sidebar-right .selector-label {
    margin-bottom: 6px;
    font-size: 0.65rem;
}

.sidebar-right .selector-btn {
    padding: 8px 4px;
}

.sidebar-right .battle-controls {
    gap: 10px; /* Slightly more air */
}

.sidebar-right .sub-controls {
    gap: 8px;
}

.sidebar-right .save-row {
    margin-top: 0;
    gap: 8px;
}

.sidebar-right .save-row .save-btn-mini {
    min-height: 52px;
    padding: 10px 4px;
}

.sidebar-right .command-btn-compact {
    padding: 10px; /* Reduced further */
}

.sidebar-right .group-header h4 {
    font-size: 0.95rem;
}

.viewport-area {
    order: 2; /* Middle */
    border-left: 1px solid rgba(255,255,255,0.05);
    border-right: 1px solid rgba(255,255,255,0.05);
}

/* Adjust button grids for narrower sidebar */
.tools-compact {
    grid-template-columns: 1fr; /* Stack vertically for better look in narrow col */
    gap: 12px;
}

.tool-btn {
    flex-direction: row; /* Horizontal layout for tools */
    height: 50px;
    gap: 15px;
    padding: 0 20px;
    justify-content: flex-start;
}

.tool-btn .btn-icon {
    font-size: 1.4rem;
    margin-bottom: 0;
}

.tool-btn .cost-badge {
    margin-left: auto;
}

/* Battle controls adjustment */
.battle-controls {
    gap: 15px;
}

.command-btn-compact {
    padding: 15px;
}

.game-workspace {
    justify-content: space-between;
}


.tool-label {
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Text labels for small buttons */
.btn-text {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* Ensure horizontal layout for save/sub-controls */
.sub-controls .command-btn-compact,
.save-row .save-btn-mini {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 5px;
    height: auto;
    min-height: 55px;
}

.sub-controls .command-btn-compact .btn-icon,
.save-row .save-btn-mini .btn-icon {
    margin-bottom: 0;
    font-size: 1.2rem;
}


/* --- Tools Group: Horizontal Layout for Demolish/Upgrade --- */
.tools-row {
    display: flex;
    flex-direction: row;
    gap: 15px;
    margin-top: 10px;
}

.tools-row .tool-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 75px; /* Reduced from 85px to tighten space */
    padding: 6px;
    background: linear-gradient(135deg, rgba(45, 45, 45, 0.9) 0%, rgba(20, 20, 20, 0.95) 100%);
    border: 2px solid var(--stone-border);
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    gap: 2px;
}

.tools-row .tool-btn:hover {
    transform: translateY(-3px);
    border-color: var(--gold-medium);
    box-shadow: 0 6px 12px rgba(0,0,0,0.5);
}

.tools-row .remove-btn .btn-icon {
    color: #ff6666;
    text-shadow: 0 0 10px rgba(255, 50, 50, 0.4);
}

.tools-row .upgrade-btn .btn-icon {
    color: #2ecc71;
    text-shadow: 0 0 10px rgba(46, 204, 113, 0.4);
}

.tools-row .tool-btn .btn-icon {
    font-size: 2rem;
    margin-bottom: 0px; /* Removed margin as gap handles it now */
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
    transition: transform 0.3s ease;
}

.tools-row .tool-btn:hover .btn-icon {
    transform: scale(1.1) rotate(5deg);
}

.tools-row .tool-btn .tool-label {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-primary);
    font-family: 'MedievalSharp', cursive;
}

/* V2 Tools Grid Layout - 3 columns, optimized for 320px sidebar */
.tools-compact {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px; /* Slightly tighter gap */
    padding: 6px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.v2-tools .tool-btn {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important; /* Center instead of space-between */
    min-height: 95px !important; /* Reduced from 110px */
    height: auto !important;
    padding: 8px 4px !important; /* Tightened padding */
    background: linear-gradient(135deg, rgba(45, 45, 45, 0.9) 0%, rgba(20, 20, 20, 0.95) 100%) !important;
    border: 1px solid var(--stone-border) !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 8px rgba(0,0,0,0.4) !important;
    transition: all 0.25s ease !important;
    overflow: visible !important;
    gap: 2px !important; /* Add small explicit gap */
}

.v2-tools .tool-btn:hover {
    transform: translateY(-3px) !important;
    border-color: var(--gold-medium) !important;
    background: linear-gradient(135deg, rgba(60, 60, 60, 0.9) 0%, rgba(30, 30, 30, 0.95) 100%) !important;
    box-shadow: 0 6px 15px rgba(0,0,0,0.5) !important;
}

.v2-tools .tool-btn.active {
    border-color: var(--gold-light) !important;
    background: linear-gradient(135deg, rgba(184, 134, 11, 0.2) 0%, rgba(0, 0, 0, 0.5) 100%) !important;
    box-shadow: 0 0 15px rgba(218, 165, 32, 0.25), inset 0 0 10px rgba(255, 215, 0, 0.05) !important;
}

.v2-tools .tool-btn .btn-icon {
    margin-bottom: 2px !important;
    font-size: 1.8rem !important; /* Back to original size */
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.7)) !important;
}

.v2-tools .tool-btn .tool-label {
    font-size: 0.75rem !important;
    font-weight: 700 !important;
    letter-spacing: 0.8px !important;
    text-transform: uppercase !important;
    color: var(--text-primary) !important;
    margin: 2px 0 !important;
    text-align: center !important;
}

.v2-tools .tool-btn .cost-badge {
    display: inline-block !important;
    padding: 2px 8px !important;
    background: rgba(0, 0, 0, 0.7) !important;
    color: var(--gold-medium) !important;
    font-size: 0.65rem !important;
    font-weight: 900 !important;
    border-radius: 4px !important;
    border: 1px solid rgba(184, 134, 11, 0.2) !important;
    letter-spacing: 0.5px !important;
}
/* --- Game Over (Elite Defeat) UI --- */
.defeat-modal {
    background: radial-gradient(circle at center, var(--stone-dark) 0%, var(--dungeon-bg) 100%) !important;
    border: 3px solid var(--gold-dark) !important;
    box-shadow:
        0 0 40px rgba(0, 0, 0, 0.8),
        inset 0 0 30px rgba(0, 0, 0, 0.9),
        0 0 0 2px rgba(184, 134, 11, 0.3) !important;
    max-width: 650px !important;
    max-height: calc(100vh - 60px);
    margin: 30px auto !important;
    padding: 0 !important;
    text-align: center;
    overflow: hidden;
    position: relative;
    border-radius: 8px;
    display: flex !important;
    flex-direction: column !important;
}

/* Custom scrollbar for defeat modal stats */
.recap-container::-webkit-scrollbar {
    width: 10px;
}

.recap-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
}

.recap-container::-webkit-scrollbar-thumb {
    background: var(--gold-dark);
    border-radius: 5px;
    border: 1px solid var(--gold-medium);
}

.recap-container::-webkit-scrollbar-thumb:hover {
    background: var(--gold-medium);
}

/* Firefox scrollbar */
.recap-container {
    scrollbar-width: thin;
    scrollbar-color: var(--gold-dark) rgba(0, 0, 0, 0.3);
}

/* Custom scrollbar for controls sidebar */
.controls-sidebar::-webkit-scrollbar {
    width: 10px;
}

.controls-sidebar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
}

.controls-sidebar::-webkit-scrollbar-thumb {
    background: var(--gold-dark);
    border-radius: 5px;
    border: 1px solid var(--gold-medium);
}

.controls-sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--gold-medium);
}

/* Firefox scrollbar for controls sidebar */
.controls-sidebar {
    scrollbar-width: thin;
    scrollbar-color: var(--gold-dark) rgba(0, 0, 0, 0.3);
}

/* Texture overlay */
.defeat-modal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E"),
        linear-gradient(135deg, 
            rgba(139, 69, 19, 0.05) 0%, 
            rgba(139, 69, 19, 0.02) 50%, 
            rgba(139, 69, 19, 0.05) 100%);
    opacity: 0.15;
    pointer-events: none;
    mix-blend-mode: overlay;
    border-radius: 8px;
    z-index: 0;
}

/* Gold border ornament */
.defeat-modal::after {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border: 1px solid rgba(184, 134, 11, 0.2);
    border-radius: 4px;
    pointer-events: none;
}

/* Corner ornaments - General */
.corner-ornament {
    position: absolute;
    width: 20px;
    height: 20px;
    color: var(--gold-medium);
    font-size: 16px;
    opacity: 0.6;
    z-index: 2;
}

/* Hiding corner ornaments as per user request to keep only best ones */
.corner-ornament.top-left { display: none; }
.corner-ornament.top-right { display: none; }
.corner-ornament.bottom-left { display: none; }
.corner-ornament.bottom-right { display: none; }

.defeat-header {
    margin: 0;
    position: relative;
    padding: 20px 80px 15px 80px;
    border-bottom: 2px solid var(--gold-dark);
    flex-shrink: 0;
    z-index: 2;
    text-align: center;
}

.defeat-header::before,
.defeat-header::after {
    content: '⚜';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gold-medium);
    font-size: 2.5rem;
    opacity: 0.6;
}

.defeat-header::before {
    left: 40px;
}

.defeat-header::after {
    right: 40px;
}

.defeat-title {
    font-family: 'MedievalSharp', cursive;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--gold-medium);
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 
        2px 2px 0 rgba(0, 0, 0, 0.8),
        0 0 30px rgba(184, 134, 11, 0.4);
    animation: medieval-flicker 3s ease-in-out infinite;
}

@keyframes medieval-flicker {
    0%, 100% { 
        opacity: 1; 
        text-shadow: 
            2px 2px 0 rgba(0, 0, 0, 0.8),
            0 0 30px rgba(184, 134, 11, 0.4);
    }
    50% { 
        opacity: 0.95; 
        text-shadow: 
            2px 2px 0 rgba(0, 0, 0, 0.8),
            0 0 20px rgba(184, 134, 11, 0.6);
    }
}

.defeat-subtitle {
    color: var(--text-secondary);
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-top: 10px;
    opacity: 0.7;
}

.recap-container, .recap-ui {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 20px;
    border: 1px solid rgba(184, 134, 11, 0.3);
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
}

.recap-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 25px;
}

.recap-title-line {
    flex-grow: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-dark), transparent);
}

.medieval-header {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.8rem;
    color: var(--gold-light);
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    margin: 0;
}

.recap-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 30px;
    z-index: 2;
    min-height: 0;
}

.recap-main-stats {
    display: flex;
    justify-content: space-around;
    padding-bottom: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(184, 134, 11, 0.2);
}

.recap-stat.big {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.recap-stat.big .recap-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.recap-stat.big .recap-sublabel {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-family: 'Cinzel', serif;
    margin-top: 5px;
    font-weight: normal;
}

.recap-stat.big .recap-value.gold-text {
    font-family: 'MedievalSharp', cursive;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--gold-medium);
    text-shadow: 0 0 20px rgba(184, 134, 11, 0.3);
}

.recap-stat.big .recap-value:not(.gold-text) {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.recap-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 30px;
}

.recap-item {
    display: flex;
    flex-direction: column;
    align-items: center; /* Center content horizontally */
    text-align: center; /* Center text */
    padding: 18px 12px;
    background: rgba(184, 134, 11, 0.05);
    border-radius: 6px;
    border: 1px solid rgba(184, 134, 11, 0.1);
    transition: all 0.3s ease;
}

.recap-item:hover {
    transform: translateY(-3px);
    background: rgba(184, 134, 11, 0.1);
    border-color: rgba(184, 134, 11, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.recap-icon {
    font-size: 1.3rem;
    margin-bottom: 8px;
    opacity: 0.8;
}

.recap-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.recap-value {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
}

.recap-highlights {
    margin-top: 25px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.highlight-tag {
    background: rgba(184, 134, 11, 0.15);
    color: var(--gold-medium);
    padding: 6px 14px;
    border-radius: 15px;
    font-size: 0.8rem;
    border: 1px solid rgba(184, 134, 11, 0.3);
    font-family: 'Cinzel', serif;
    letter-spacing: 1px;
}

.defeat-actions {
    margin-top: 0;
    padding: 20px 30px 30px 30px;
    flex-shrink: 0;
    z-index: 2;
}

.elite-restart {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100% !important;
    background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold-medium) 50%, var(--gold-dark) 100%) !important;
    color: var(--dungeon-bg) !important;
    font-family: 'MedievalSharp', cursive !important;
    font-weight: 700 !important;
    letter-spacing: 3px !important;
    height: 60px !important;
    font-size: 1.15rem !important;
    border: 2px solid var(--gold-light) !important;
    border-radius: 6px !important;
    position: relative;
    overflow: hidden;
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.6),
        0 0 30px rgba(184, 134, 11, 0.3) !important;
    transition: all 0.3s ease !important;
    text-transform: uppercase;
}

.elite-restart:hover {
    transform: scale(1.02) translateY(-2px);
    box-shadow: 
        0 8px 30px rgba(0, 0, 0, 0.8),
        0 0 40px rgba(184, 134, 11, 0.5) !important;
    filter: brightness(1.1);
}

.elite-restart:active {
    transform: scale(0.98);
}

.btn-shine {
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        120deg,
        transparent,
        rgba(255, 215, 0, 0.4),
        transparent
    );
    transition: all 0.5s;
    animation: shine-sweep 4s infinite;
}

@keyframes shine-sweep {
    0% { left: -100%; }
    20% { left: 100%; }
    100% { left: 100%; }
}

/* --- Leaderboard Modal --- */
.leaderboard-modal {
    background: radial-gradient(circle at center, var(--stone-dark) 0%, var(--dungeon-bg) 100%) !important;
    border: 3px solid var(--gold-dark) !important;
    box-shadow:
        0 0 40px rgba(0, 0, 0, 0.8),
        inset 0 0 30px rgba(0, 0, 0, 0.9),
        0 0 0 2px rgba(184, 134, 11, 0.3) !important;
    max-width: 600px !important;
    max-height: calc(100vh - 60px);
    margin: 30px auto !important;
    padding: 0 !important;
    text-align: center;
    overflow: hidden;
    position: relative;
    border-radius: 8px;
    display: flex !important;
    flex-direction: column !important;
}

/* Texture overlay */
.leaderboard-modal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E"),
        linear-gradient(135deg, 
            rgba(139, 69, 19, 0.05) 0%, 
            rgba(139, 69, 19, 0.02) 50%, 
            rgba(139, 69, 19, 0.05) 100%);
    opacity: 0.15;
    pointer-events: none;
    mix-blend-mode: overlay;
    border-radius: 8px;
    z-index: 0;
}

/* Corner ornaments */
.leaderboard-modal .corner-ornament {
    position: absolute;
    width: 20px;
    height: 20px;
    color: var(--gold-medium);
    font-size: 16px;
    opacity: 0.6;
    z-index: 2;
}

.leaderboard-modal .corner-ornament.top-left { top: 15px; left: 15px; }
.leaderboard-modal .corner-ornament.top-right { top: 15px; right: 15px; }
.leaderboard-modal .corner-ornament.bottom-left { bottom: 15px; left: 15px; }
.leaderboard-modal .corner-ornament.bottom-right { bottom: 15px; right: 15px; }

/* Header */
.leaderboard-header {
    margin: 0;
    position: relative;
    padding: 30px 30px 20px 30px;
    border-bottom: 2px solid var(--gold-dark);
    flex-shrink: 0;
    z-index: 2;
}

/* Medieval-style header with ornamental line */
.leaderboard-header::before,
.leaderboard-header::after {
    content: '⚜';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gold-medium);
    font-size: 3rem;
    opacity: 0.8;
}

.leaderboard-header::before {
    left: 20px;
}

.leaderboard-header::after {
    right: 20px;
}

.leaderboard-title {
    font-family: 'MedievalSharp', cursive;
    font-size: 2.8rem;
    font-weight: 700;
    color: var(--gold-medium);
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 
        2px 2px 0 rgba(0, 0, 0, 0.8),
        0 0 30px rgba(184, 134, 11, 0.4);
    animation: medieval-flicker 3s ease-in-out infinite;
}

.leaderboard-subtitle {
    color: var(--text-secondary);
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-top: 10px;
    opacity: 0.7;
}

/* Container */
.leaderboard-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 30px;
    z-index: 2;
    min-height: 0;
}

/* Custom scrollbar */
.leaderboard-container::-webkit-scrollbar {
    width: 10px;
}

.leaderboard-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
}

.leaderboard-container::-webkit-scrollbar-thumb {
    background: var(--gold-dark);
    border-radius: 5px;
    border: 1px solid var(--gold-medium);
}

.leaderboard-container::-webkit-scrollbar-thumb:hover {
    background: var(--gold-medium);
}

/* List */
.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Leaderboard item */
.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    background: rgba(184, 134, 11, 0.05);
    border-radius: 6px;
    border: 1px solid rgba(184, 134, 11, 0.1);
    transition: all 0.3s ease;
}

.leaderboard-item:hover {
    transform: translateX(5px);
    background: rgba(184, 134, 11, 0.1);
    border-color: rgba(184, 134, 11, 0.3);
}

.leaderboard-item.current-run {
    background: rgba(255, 215, 0, 0.15);
    border-color: rgba(255, 215, 0, 0.5);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.2);
}

.leaderboard-item.active {
    background: linear-gradient(135deg, rgba(218, 165, 32, 0.3) 0%, rgba(184, 134, 11, 0.3) 100%);
    border-color: var(--gold-medium);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
    transform: translateX(5px);
}

.leaderboard-item {
    cursor: pointer; /* Ensure pointer cursor */
}

.leaderboard-item.rank-1 {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 215, 0, 0.1));
    border-color: rgba(255, 215, 0, 0.5);
}

.leaderboard-item.rank-2 {
    background: linear-gradient(135deg, rgba(192, 192, 192, 0.2), rgba(192, 192, 192, 0.1));
    border-color: rgba(192, 192, 192, 0.4);
}

.leaderboard-item.rank-3 {
    background: linear-gradient(135deg, rgba(205, 127, 50, 0.2), rgba(205, 127, 50, 0.1));
    border-color: rgba(205, 127, 50, 0.4);
}

/* Rank badge */
.leaderboard-rank {
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-family: 'MedievalSharp', cursive;
    font-size: 1.3rem;
    font-weight: 700;
    margin-right: 16px;
    flex-shrink: 0;
}

.leaderboard-item.rank-1 .leaderboard-rank {
    background: linear-gradient(135deg, var(--gold-light), var(--gold-medium));
    color: var(--dungeon-bg);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
}

.leaderboard-item.rank-2 .leaderboard-rank {
    background: linear-gradient(135deg, #e8e8e8, #c0c0c0);
    color: var(--dungeon-bg);
}

.leaderboard-item.rank-3 .leaderboard-rank {
    background: linear-gradient(135deg, #e8d0b0, #cd7f32);
    color: var(--dungeon-bg);
}

.leaderboard-item:not(.rank-1):not(.rank-2):not(.rank-3) .leaderboard-rank {
    background: rgba(184, 134, 11, 0.2);
    color: var(--gold-medium);
    border: 1px solid rgba(184, 134, 11, 0.3);
}

/* Score */
.leaderboard-score {
    flex: 1;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'MedievalSharp', cursive;
}

.leaderboard-item.current-run .leaderboard-score {
    color: var(--gold-light);
}

/* Details */
.leaderboard-details {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.leaderboard-waves {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'Cinzel', serif;
    letter-spacing: 1px;
}

.leaderboard-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.6;
}

/* Current run indicator */
.current-run-indicator {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(255, 215, 0, 0.2);
    color: var(--gold-light);
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 10px;
    border: 1px solid rgba(255, 215, 0, 0.4);
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Actions */
.leaderboard-actions {
    margin-top: 0;
    padding: 20px 30px 30px 30px;
    flex-shrink: 0;
    z-index: 2;
}

/* Empty state */
.leaderboard-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.leaderboard-empty .empty-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

.leaderboard-empty .empty-text {
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    letter-spacing: 2px;
    color: var(--gold-medium);
}

/* Summary statistics */
.leaderboard-summary {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(184, 134, 11, 0.2);
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.summary-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.summary-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    font-family: 'Cinzel', serif;
}

.summary-value {
    font-size: 1.3rem;
    color: var(--gold-medium);
    font-weight: 700;
    font-family: 'MedievalSharp', cursive;
}

/* Reset button */
.reset-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: auto !important;
    min-width: 150px;
    background: linear-gradient(135deg, #8b0000 0%, #b22222 50%, #8b0000 100%) !important;
    color: white !important;
    font-family: 'Cinzel', serif !important;
    font-weight: 700 !important;
    letter-spacing: 2px !important;
    height: 50px !important;
    font-size: 1rem !important;
    border: 2px solid #ff4444 !important;
    border-radius: 6px !important;
    position: relative;
    overflow: hidden;
    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(139, 0, 0, 0.3) !important;
    transition: all 0.3s ease !important;
    text-transform: uppercase;
}

.reset-btn:hover {
    transform: scale(1.02) translateY(-2px);
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.7),
        0 0 30px rgba(139, 0, 0, 0.5) !important;
    filter: brightness(1.1);
}

.reset-btn:active {
    transform: scale(0.98);
}

/* Leaderboard actions container */
.leaderboard-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

/* === SCREEN SHAKE ANIMATION === */
@keyframes shake-intense {
    0% { transform: translate(0, 0) rotate(0deg); }
    10% { transform: translate(-5px, -5px) rotate(-1deg); }
    20% { transform: translate(5px, 5px) rotate(1deg); }
    30% { transform: translate(-10px, 5px) rotate(0deg); }
    40% { transform: translate(10px, -5px) rotate(1deg); }
    50% { transform: translate(-5px, 10px) rotate(-1deg); }
    60% { transform: translate(5px, -10px) rotate(0deg); }
    70% { transform: translate(-10px, 0px) rotate(-1deg); }
    80% { transform: translate(10px, 5px) rotate(1deg); }
    90% { transform: translate(-5px, -5px) rotate(0deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

.screen-shake-intense {
    animation: shake-intense 0.5s cubic-bezier(.36,.07,.19,.97) both infinite;
    transform-origin: center center;
}

