/* =========================================
           1. GLOBAL STYLES
           ========================================= */
body {
    background-color: #050505;
    background-image: radial-gradient(circle at center, #111 0%, #000 100%);
    color: #eee;
    font-family: 'Courier New', monospace;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    user-select: none;
    outline: none;
}

/* =========================================
           MOBILE / RESPONSIVE STYLES (FIXED)
           ========================================= */
#mobile-rules-btn,
#mobile-rules-modal,
#mobile-config,
#mobile-controls {
    display: none;
}

@media (max-width: 1024px) {

    body {
        justify-content: flex-start;
        align-items: center;
        padding-top: 0;
        background: #000;
        height: 100vh;
        overflow: hidden;
    }

    .arcade-header {
        display: none !important;
    }

    .info,
    .panel-id {
        display: none !important;
    }

    #mobile-rules-btn {
        display: flex;
        position: absolute;
        top: 10px;
        left: 10px;
        width: 50px;
        height: 40px;
        background: rgba(255, 255, 255, 0.1);
        border: 2px solid rgba(255, 255, 255, 0.4);
        border-radius: 10px;
        color: #fff;
        justify-content: center;
        align-items: center;
        font-weight: bold;
        font-size: 20px;
        z-index: 20000;
        backdrop-filter: blur(4px);
        cursor: pointer;
    }

    #mobile-rules-modal {
        display: none;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.85);
        z-index: 20001;
        justify-content: center;
        align-items: center;
        backdrop-filter: blur(5px);
    }

    .modal-content {
        background: #111;
        border: 2px solid #444;
        padding: 20px;
        border-radius: 8px;
        width: 80%;
        max-width: 400px;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.9);
        text-align: left;
    }

    .m-rule {
        margin: 8px 0;
        font-size: 0.9em;
        border-bottom: 1px dashed #222;
        padding-bottom: 4px;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .m-rule .icon {
        font-size: 1.2em;
        width: 20px;
        text-align: center;
    }

    .close-btn {
        margin-top: 15px;
        background: #333;
        color: #fff;
        text-align: center;
        padding: 10px;
        border-radius: 4px;
        cursor: pointer;
        font-weight: bold;
        border: 1px solid #555;
    }

    .close-btn:active {
        background: #555;
    }

    .console-case {
        margin-top: 5px;
        width: 98vw;
        max-width: 100%;
        padding: 0;
        border: none;
        background: transparent;
        box-shadow: none;
    }

    canvas {
        width: 100% !important;
        height: auto !important;
        max-height: 75vh;
        object-fit: contain;
    }

    .touch-area.config {
        pointer-events: auto;
        display: grid;
        gap: 7px;
        align-content: center;
        grid-template-columns: 40px;
        grid-template-rows: 40px 40px 40px;
        margin-left: 5px;
    }

    #mobile-config {
        display: flex;
        position: absolute;
        top: 10px;
        left: 10px;
        width: 100%;
        justify-content: space-between;
        padding: 0;
        box-sizing: border-box;
        z-index: 9999;
        pointer-events: none;
    }

    .btn[data-key="KeySelect"] {
        border-radius: 10px;
        width: 80px;
        height: 40px;
        grid-column: 1;
        grid-row: 3;
    }

    .btn[data-key="KeyStart"] {
        border-radius: 10px;
        width: 80px;
        height: 40px;
        grid-column: 1;
        grid-row: 2;
    }

    .btnInfo {
        width: 80px;
        height: 40px;
        background: rgba(255, 255, 255, 0.1);
        border: 2px solid rgba(255, 255, 255, 0.4);
        border-radius: 30%;
        color: #fff;
        display: flex;
        justify-content: center;
        align-items: center;
        font-weight: bold;
        font-size: 11px;
        border-radius: 10px;
        grid-column: 1;
        grid-row: 1;
    }

    .btnInfo:active {
        background: rgba(255, 0, 0, 0.5);
    }

    .touch-area.actions {
        pointer-events: auto;
        display: grid;
        gap: 7px;
        align-content: center;
        grid-template-columns: 55px 55px;
        grid-template-rows: 55px 55px 55px;
        margin-right: 10px;
        margin-bottom: 10px;
    }

    #mobile-controls {
        display: flex;
        position: absolute;
        bottom: 10px;
        left: 0;
        width: 100%;
        justify-content: space-between;
        padding: 0;
        box-sizing: border-box;
        z-index: 9999;
        pointer-events: none;
    }

    #joystick-zone {
        width: 17%;
        /* height: 100%; */
        pointer-events: auto;
        position: relative;
    }

    .touch-area.actions {
        pointer-events: auto;
        display: grid;
        gap: 7px;
        align-content: center;
        grid-template-columns: 55px 55px;
        grid-template-rows: 55px 55px 55px;
        margin-right: 10px;
    }

    .btn {
        /* Layout */
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;

        /* Typography */
        font-family: 'Courier New', monospace;
        font-weight: 900;
        font-size: 14px;
        /* Larger text */
        letter-spacing: 1px;
        text-shadow: 0 0 5px currentColor;
        /* Text glows with its own color */

        /* Glassmorphism & Shape */
        background: rgba(20, 20, 20, 0.4);
        /* Dark semi-transparent background */
        backdrop-filter: blur(4px);
        border-radius: 50%;
        /* Make them perfectly round for an arcade feel */
        border: 2px solid rgba(255, 255, 255, 0.2);
        /* Subtle base border */

        /* Effects */
        box-shadow:
            0 4px 10px rgba(0, 0, 0, 0.6),
            /* Drop shadow */
            inset 0 0 15px rgba(255, 255, 255, 0.05);
        /* Inner metallic shine */
        transition: all 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        /* Bouncy transition */
        user-select: none;
        cursor: pointer;
        position: relative;
        overflow: hidden;
        -webkit-tap-highlight-color: transparent !important;
        /* iOS/Android removal of grey box */
        touch-action: manipulation !important;
        /* Improves tap response time */
    }

    .btn:active, .btn.manual-active {
        transform: scale(0.9) !important;
        /* Physically shrink */
        background: rgba(255, 255, 255, 0.1) !important;
        /* Flash white */
        box-shadow:0 0 25px currentColor, inset 0 0 10px currentColor !important;
        /* Inner glow */
        border-color: #fff !important;
    }

    /* SHIELD (Cyan) */
    .btn[data-key="KeyR"] {
        grid-column: 2;
        grid-row: 3;
        border-color: #55ffff !important;
        color: #55ffff !important;
        box-shadow: 0 0 10px rgba(85, 255, 255, 0.2), inset 0 0 10px rgba(85, 255, 255, 0.1);
    }

    /* BOOST (Green) */
    .btn[data-key="KeyG"] {
        grid-column: 1;
        grid-row: 3;
        border-color: #00ff00 !important;
        color: #00ff00 !important;
        box-shadow: 0 0 10px rgba(0, 255, 0, 0.2), inset 0 0 10px rgba(0, 255, 0, 0.1);
    }

    /* BEAM (Gold) - The Long Button */
    .btn[data-key="KeyF"] {
        grid-column-start: 1;
        grid-column-end: 2;
        /* Keep it 1x1 if you want circle, or span 2 for pill */
        grid-row: 2;

        /* Let's make the beam button unique (Pill shape) to stand out */
        width: 125px;
        /* Spanning width */
        border-radius: 30px;
        border-color: #ffd700 !important;
        color: #ffd700 !important;
        box-shadow: 0 0 10px rgba(255, 215, 0, 0.2), inset 0 0 10px rgba(255, 215, 0, 0.1);
    }

    /* MINE (Magenta) */
    .btn[data-key="KeyE"] {
        grid-column: 1;
        grid-row: 1;
        border-color: #ff55ff !important;
        color: #ff55ff !important;
        box-shadow: 0 0 10px rgba(255, 85, 255, 0.2), inset 0 0 10px rgba(255, 85, 255, 0.1);
    }

    /* BOOM (Red) - The Big Danger Button */
    .btn[data-key="Space"] {
        grid-column: 2;
        grid-row: 1;
        border-color: #ff5555 !important;
        color: #ff5555 !important;
        background: rgba(255, 85, 85, 0.1);
        /* Slight red tint always */
        box-shadow: 0 0 15px rgba(255, 85, 85, 0.3), inset 0 0 10px rgba(255, 85, 85, 0.1);
        animation: pulse-red 2s infinite;
        /* Subtle danger pulse */
    }

    @keyframes pulse-red {
        0% {
            box-shadow: 0 0 10px rgba(255, 85, 85, 0.3);
        }

        50% {
            box-shadow: 0 0 20px rgba(255, 85, 85, 0.6);
        }

        100% {
            box-shadow: 0 0 10px rgba(255, 85, 85, 0.3);
        }
    }
}

@media (max-width: 900px) and (orientation: portrait) {
    body::before {
        content: "PLEASE ROTATE YOUR DEVICE ↻";
        position: absolute;
        top: 40%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: yellow;
        font-size: 20px;
        background: rgba(0, 0, 0, 0.8);
        padding: 10px;
        z-index: 10000;
        pointer-events: none;
    }
}

/* =========================================
           2. UI COMPONENTS
           ========================================= */
.arcade-header {
    width: 960px;
    background: #0b0b0b;
    border: 2px solid #333;
    border-bottom: 4px solid #444;
    border-radius: 6px;
    margin-bottom: 10px;
    padding: 8px;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(90deg, #111 0%, #1a1a1a 50%, #111 100%);
    padding: 4px 12px;
    border: 1px solid #333;
    border-radius: 4px;
}

.game-title {
    font-size: 1.3em;
    color: #fff;
    letter-spacing: 3px;
    font-weight: 900;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    font-style: italic;
    text-transform: uppercase;
}

.round-info {
    font-size: 0.8em;
    color: #ffd700;
    font-weight: bold;
    letter-spacing: 1px;
    background: rgba(255, 215, 0, 0.1);
    padding: 2px 6px;
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 3px;
}

/* --- DASHBOARD --- */
.dashboard {
    display: grid;
    grid-template-columns: 1fr 1.3fr 1fr;
    gap: 8px;
    height: 110px;
}

.panel {
    background: rgba(20, 20, 20, 0.6);
    border-radius: 4px;
    padding: 5px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.rules-panel {
    border: 1px solid #333;
    background: #080808;
}

.panel-header {
    font-size: 0.75em;
    font-weight: 900;
    text-align: center;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 2px;
    padding-bottom: 2px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-shadow: 0 0 5px currentColor;
}

.control-group {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
}

.c-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.65em;
    color: #aaa;
    background: rgba(255, 255, 255, 0.03);
    padding: 1px 4px;
    border-radius: 2px;
}

.key-cap {
    background: #222;
    color: #fff;
    padding: 0px 5px;
    border-radius: 2px;
    border-bottom: 1px solid #444;
    border-top: 1px solid #333;
    border-left: 1px solid #333;
    border-right: 1px solid #333;
    font-family: monospace;
    font-weight: bold;
    font-size: 1em;
    min-width: 14px;
    text-align: center;
    display: inline-block;
    line-height: 1.2;
}

.action-name {
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 0.5px;
}

.act-atk {
    color: #ff5555;
}

.act-def {
    color: #55ffff;
}

.act-mov {
    color: #55ff55;
}

/* --- LEGEND --- */
.legend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 8px;
    font-size: 0.65em;
    color: #ccc;
    height: 100%;
    align-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    border-bottom: 1px dashed #222;
    padding-bottom: 1px;
}

.l-icon {
    width: 10px;
    text-align: center;
    font-size: 1.1em;
}

.l-text {
    display: flex;
    flex-direction: column;
    line-height: 1.0;
}

.l-title {
    font-weight: bold;
    font-size: 0.95em;
}

.l-desc {
    font-size: 0.85em;
    opacity: 0.7;
}

.hl-red {
    color: #ff5555;
}

.hl-blue {
    color: #55ffff;
}

.hl-gold {
    color: #ffd700;
}

.hl-purple {
    color: #ff55ff;
}

/* --- CANVAS --- */
.console-case {
    background: #111;
    padding: 8px;
    border-radius: 2px;
    border: 1px solid #333;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: fit-content;
}

.screen-bezel {
    background: #000;
    padding: 0;
    box-shadow: inset 0 0 10px #000;
    z-index: 10;
    position: relative;
}

canvas {
    width: 960px;
    aspect-ratio: 2 / 1;
    background-color: #000;
    display: block;
    image-rendering: pixelated;
}

.info {
    position: absolute;
    bottom: 5px;
    text-align: center;
    color: #555;
    width: 100%;
    font-size: 0.7em;
}

.panel-id {
    position: absolute;
    bottom: -20px;
    right: 0;
    color: #333;
    font-size: 9px;
    font-family: Arial, sans-serif;
}