/* Reset and Base Styling */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: #111;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: white;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Header Area for Back Button to prevent overlap */
#header-area {
    width: 100%;
    padding: 15px 20px 0px 20px;
}

/* Universal Back Button */
.universal-back-btn {
    display: inline-block;
    color: #ffffff;
    text-decoration: none;
    background: rgba(44, 62, 80, 0.9);
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Portrait Banner */
#portrait-banner {
    display: none;
    background-color: rgba(255, 255, 255, 0.9);
    color: #333;
    z-index: 9000;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 10px;
    font-weight: bold;
    font-size: 14px;
}

/* --- MAIN LAYOUT: DESKTOP --- */
#game-container {
    display: grid;
    grid-template-columns: 300px 1fr;
    grid-template-rows: 1fr auto;
    grid-template-areas: 
        "panel canvas"
        "controls canvas";
    gap: 20px;
    flex-grow: 1;
    padding: 20px;
    height: 85vh; 
}

/* Part 1: Stats Panel */
#left-panel {
    grid-area: panel;
    background-color: #2c3e50;
    padding: 20px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.stats-area { display: flex; flex-direction: column; gap: 5px; }
.stats-area h3 { text-transform: uppercase; letter-spacing: 1px; }

/* Buttons & Bars */
.ability-btn {
    color: white; border: none; padding: 12px; border-radius: 6px;
    cursor: pointer; font-weight: bold; text-transform: uppercase; width: 100%; text-align: center;
}
#slow-trigger { background-color: #e67e22; }
#slow-bar-bg { background-color: rgba(255,255,255,0.1); height: 8px; border-radius: 4px; }
#slow-bar { background-color: #e67e22; height: 100%; width: 0; border-radius: 4px; transition: width 0.1s linear;}
#fix-trigger { background-color: #e74c3c; }
#btn-pause { background-color: #3498db; }

/* Global Red Button Styling for Intros */
.red-btn {
    background-color: #c0392b; /* Deep Red */
    color: #ffffff;
    border: 1px solid #000000; /* Thin black outline */
    width: 200px;
    margin-top: 20px;
    transition: background-color 0.2s ease;
}
.red-btn:hover { background-color: #922b21; }

/* Part 2: Canvas Protection */
#canvas-container {
    grid-area: canvas;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #95a5a6; /* Light/Medium Grey instead of Black */
    border-radius: 8px;
    overflow: hidden; 
}

canvas {
    width: 100%;
    height: 100%;
    object-fit: contain; 
}

#pause-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); display: none; align-items: center; justify-content: center;
}

/* Part 3: The Fixed Center D-Pad */
#controls {
    grid-area: controls;
    background-color: #2c3e50;
    padding: 20px;
    border-radius: 8px;
    display: grid;
    /* Explicitly sizing the grid columns/rows to lock the layout */
    grid-template-columns: 65px 65px 65px;
    grid-template-rows: 65px 65px 65px;
    grid-template-areas: 
        ". up ."
        "left action right"
        ". down .";
    gap: 10px;
    justify-content: center;
    align-content: center;
}

#btn-up { grid-area: up; } 
#btn-left { grid-area: left; } 
#btn-right { grid-area: right; } 
#btn-down { grid-area: down; }

/* The Action Button (Perfectly Centered) */
#btn-action { 
    grid-area: action; 
    background-color: #f1c40f; 
    color: #2c3e50;
    border: none;
    border-radius: 8px;
    font-size: 12px; 
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.1;
    padding: 2px;
}

.ctrl-btn {
    background-color: #ecf0f1; color: #2c3e50; border: none; border-radius: 8px;
    font-size: 24px; font-weight: bold; cursor: pointer;
    width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
}


/* --- OVERLAYS & ALIGNMENT --- */
#intro-overlay, #transition-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    display: flex; align-items: center; justify-content: center; flex-direction: column;
    z-index: 5000;
    background-color: #d3d3d3; /* Light grey background for all intro/transition screens */
}

.intro-box, .transition-content {
    background: #ecf0f1; color: #000000; padding: 30px; border-radius: 12px;
    width: 90%; max-width: 650px; text-align: center;
    display: flex; flex-direction: column; align-items: center;
    max-height: 85vh; 
    overflow-y: auto; 
    border: 2px solid #bdc3c7;
}

.intro-desc {
    margin: 15px 0;
    font-size: 18px;
    line-height: 1.5;
    color: #000000;
}

.bad-guy-showcase { display: flex; gap: 15px; justify-content: center; margin: 20px 0; width: 100%; }

/* Card Layout Overhaul */
.bg-card { 
    border: 2px solid #7f8c8d; 
    border-radius: 8px; 
    padding: 15px 10px; 
    width: 33%; 
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center; /* Centers everything */
    background-color: #ffffff;
}

.card-header {
    min-height: 45px; /* Keeps headers uniformly sized */
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin-bottom: 10px;
}

/* Scaled down enemies for Meet Your Enemies & Transition Screen */
.bg-card canvas, #trans-enemies-preview canvas {
    width: 25px; 
    height: 33px;
    margin-bottom: 15px;
    image-rendering: pixelated; /* Keeps the art crisp when scaled down */
}

/* Keep the horizontal alignment for transition previews */
#trans-enemies-preview {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 15px 0;
    width: 100%;
}

/* Ensure no margin pushing happens inside the row */
#trans-enemies-preview canvas {
    margin-bottom: 0; 
}

.bg-card p {
    color: #000000;
    line-height: 1.4;
}

.block-demo { display: flex; justify-content: center; gap: 10px; margin: 15px 0; }
.demo-b { padding: 15px 20px; font-weight: bold; border-radius: 4px; color: white; }

#trans-lvl-text { 
    font-size: 36px; margin: 0 0 10px 0; text-align: center; width: 100%; 
    color: #000000; /* Black text for Level */
}


/* --- MOBILE LAYOUT: LANDSCAPE --- */
@media screen and (max-width: 800px) and (orientation: landscape) {
    #header-area { padding: 5px 10px; }
    .universal-back-btn { font-size: 12px; padding: 6px 10px; }
    
    #game-container {
        grid-template-columns: 200px 1fr;
        height: auto; flex-grow: 1; padding: 10px; gap: 10px;
    }
    #left-panel { padding: 10px; gap: 10px; }
    
    /* Shrink the D-Pad correctly for landscape */
    #controls { 
        padding: 10px; 
        display: grid;
        grid-template-columns: 50px 50px 50px; 
        grid-template-rows: 50px 50px 50px; 
        grid-template-areas: 
            ". up ."
            "left action right"
            ". down .";
        gap: 5px; 
    }
    #btn-action { font-size: 10px; }
    .ability-btn { padding: 8px; font-size: 12px; }
}

/* --- MOBILE LAYOUT: PORTRAIT --- */
@media screen and (max-width: 800px) and (orientation: portrait) {
    #portrait-banner { display: flex; } 
    
    #header-area { padding: 10px; text-align: center; }
    .universal-back-btn { font-size: 12px; padding: 6px 10px; margin: 0; }

    #game-container {
        display: flex; 
        flex-direction: column;
        height: auto;
        padding: 10px;
        gap: 15px;
    }

    #left-panel {
        order: 1; 
        width: 100%; padding: 10px;
        flex-direction: row; flex-wrap: wrap; justify-content: space-between; align-items: center;
    }
    .stats-area { width: 100%; flex-direction: row; justify-content: space-around; margin-bottom: 10px; }
    
    #slow-trigger, #fix-trigger, #btn-pause { width: 32%; padding: 6px 2px; font-size: 10px; line-height: 1.2; white-space: normal;}
    #slow-bar-bg { width: 100%; margin-top: 5px; }

    #canvas-container {
        order: 2; 
        width: 100%; min-height: 40vh; max-height: 50vh;
    }

    /* Hardened D-Pad structure for mobile portrait */
    #controls {
        order: 3; 
        width: 100%; 
        max-width: 350px; 
        align-self: center; 
        padding: 15px;
        display: grid;
        grid-template-columns: 65px 65px 65px;
        grid-template-rows: 65px 65px 65px;
        grid-template-areas: 
            ". up ."
            "left action right"
            ". down .";
        justify-content: center;
        gap: 10px;
    }
    #btn-action { font-size: 11px; }
    
    /* Fixes Intro Screen Crowding */
    .bad-guy-showcase { flex-direction: column; align-items: center; gap: 10px; }
    .bg-card { width: 100%; padding: 10px; min-height: auto; }
    .card-header { min-height: auto; margin-bottom: 5px; }
    .bg-card canvas { margin-bottom: 5px; }
}


/* Footer styling */
.site-footer {
    background-color: #cbd5e1; padding: 15px 20px; text-align: center;
    border-top: 2px solid #94a3b8; display: flex; flex-direction: column; align-items: center; justify-content: center;
    margin-top: auto;
}
.legal-text { font-size: 11px; color: #475569; margin: 0 0 10px 0; max-width: 900px; line-height: 1.4; }
.contact-btn { background-color: #2563eb; color: white; padding: 8px 20px; text-decoration: none; border-radius: 4px; font-weight: bold; font-size: 14px; }
