@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    background-color: #0c0e14;
    font-family: 'Press Start 2P', monospace, sans-serif;
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-wrapper {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: 1920px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, #181d28 0%, #080a0f 100%);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Orientation Hint for Portrait Mobile */
#orientation-hint {
    display: none;
    width: 100%;
    max-width: 960px;
    background: rgba(14, 28, 48, 0.92);
    border-bottom: 2px solid #00f0ff;
    padding: 6px 12px;
    font-size: 8px;
    text-align: center;
    color: #7dd3fc;
    letter-spacing: 0.5px;
    z-index: 50;
    animation: glowHint 2s infinite alternate;
}

@keyframes glowHint {
    0% { color: #38bdf8; border-color: #0284c7; }
    100% { color: #fef08a; border-color: #f59e0b; }
}

@media (max-width: 850px) and (orientation: portrait) {
    #orientation-hint {
        display: block;
    }
}

/* Canvas Container */
#canvas-container {
    position: relative;
    width: 960px;
    height: 540px;
    max-width: 96vw;
    max-height: calc(96vw * 9 / 16);
    aspect-ratio: 16 / 9;
    box-shadow: 0 0 35px rgba(0, 200, 255, 0.25), 0 0 12px rgba(0, 0, 0, 0.95);
    border: 4px solid #1a2736;
    border-radius: 6px;
    overflow: hidden;
    background-color: #141026;
    touch-action: none;
}

@media (min-height: 600px) and (min-width: 1000px) {
    #canvas-container {
        width: 1152px;
        height: 648px;
    }
}

@media (min-height: 800px) and (min-width: 1360px) {
    #canvas-container {
        width: 1280px;
        height: 720px;
    }
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    touch-action: none;
}

/* CRT Scanline and Bezel Overlay */
.crt-overlay {
    pointer-events: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.28) 50%),
                radial-gradient(ellipse at center, rgba(0,0,0,0) 65%, rgba(0,0,0,0.45) 100%);
    background-size: 100% 4px, 100% 100%;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.crt-overlay.disabled {
    opacity: 0;
}

/* Bottom Arcade Controls Bar (Desktop & Large Screens) */
#arcade-controls-bar {
    width: 100%;
    max-width: 960px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    font-size: 10px;
    color: #7d9cb8;
    text-shadow: 1px 1px 0 #000;
}

#controls-hint-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.control-pill {
    background: #111a26;
    border: 1px solid #23364c;
    border-radius: 4px;
    padding: 6px 12px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.key-tag {
    background: #0088cc;
    color: #fff;
    padding: 3px 6px;
    border-radius: 3px;
    font-size: 9px;
    box-shadow: 0 2px 0 #005580;
}

.toggle-btn {
    background: #162436;
    border: 2px solid #284464;
    color: #4cd4ff;
    font-family: inherit;
    font-size: 9px;
    padding: 6px 10px;
    cursor: pointer;
    border-radius: 4px;
    box-shadow: 0 3px 0 #101c2a;
    transition: all 0.1s ease;
}

.toggle-btn:hover {
    background: #20354e;
    color: #a6ecff;
}

.toggle-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #101c2a;
}

.toggle-btn.active-level {
    background: #006699;
    border-color: #00f0ff;
    color: #ffffff;
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

/* Audio Initialization Splash Badge */
#audio-prompt {
    display: none;
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 30, 56, 0.94);
    border: 2px solid #00f0ff;
    border-radius: 8px;
    padding: 12px 22px;
    font-size: 11px;
    color: #00f0ff;
    cursor: pointer;
    z-index: 25;
    animation: pulse 1.4s infinite alternate;
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
    white-space: nowrap;
}

@keyframes pulse {
    0% { transform: translateX(-50%) scale(0.97); opacity: 0.88; }
    100% { transform: translateX(-50%) scale(1.03); opacity: 1; }
}

/* ==========================================================================
   VIRTUAL TOUCH CONTROLS FOR MOBILE TOUCHSCREENS
   ========================================================================== */
#touch-controls {
    display: none;
    width: 100%;
    max-width: 960px;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 20;
    padding: 8px 16px;
    touch-action: none;
}

/* Show touch controls on touchscreens or narrow screens */
@media (max-width: 900px), (pointer: coarse) {
    #touch-controls {
        display: flex;
    }
}

.touch-cluster {
    display: flex;
    gap: 12px;
    align-items: center;
    pointer-events: auto;
}

/* Virtual Buttons */
.touch-btn {
    position: relative;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.88);
    border: 3px solid #00c3ff;
    color: #ffffff;
    font-family: inherit;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    outline: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7), 0 0 10px rgba(0, 195, 255, 0.25);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.08s ease;
    touch-action: none;
}

.touch-btn .btn-icon {
    font-size: 17px;
    line-height: 1;
}

.touch-btn .btn-lbl {
    font-size: 7px;
    margin-top: 3px;
    letter-spacing: 0.5px;
    color: #94a3b8;
}

.touch-btn:active, .touch-btn.active-pressed {
    transform: scale(0.90);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.9), 0 0 18px #00f0ff;
    background: rgba(0, 200, 255, 0.35);
}

/* Action Button Variants */
.touch-btn.action-attack {
    border-color: #f59e0b;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7), 0 0 10px rgba(245, 158, 11, 0.3);
}

.touch-btn.action-attack .btn-lbl {
    color: #fef08a;
}

.touch-btn.action-attack:active, .touch-btn.action-attack.active-pressed {
    border-color: #fbbf24;
    background: rgba(245, 158, 11, 0.4);
    box-shadow: 0 0 18px #f59e0b;
}

.touch-btn.action-jump {
    border-color: #00f0ff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7), 0 0 10px rgba(0, 240, 255, 0.35);
}

.touch-btn.action-jump .btn-lbl {
    color: #67e8f9;
}

.touch-btn.action-jump:active, .touch-btn.action-jump.active-pressed {
    background: rgba(0, 240, 255, 0.4);
    box-shadow: 0 0 20px #00f0ff;
}

.touch-btn.action-slide {
    border-color: #10b981;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7), 0 0 10px rgba(16, 185, 129, 0.3);
}

.touch-btn.action-slide .btn-lbl {
    color: #a7f3d0;
}

.touch-btn.action-slide:active, .touch-btn.action-slide.active-pressed {
    background: rgba(16, 185, 129, 0.4);
    box-shadow: 0 0 18px #10b981;
}

/* Center Toolbar for Mobile */
.touch-center-bar {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    pointer-events: auto;
}

.m-pill-group {
    display: flex;
    gap: 5px;
}

.m-pill-btn {
    background: #162436;
    border: 1.5px solid #2b4566;
    color: #38bdf8;
    font-family: inherit;
    font-size: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    touch-action: none;
}

.m-pill-btn:active {
    transform: scale(0.92);
    background: #0284c7;
    color: #ffffff;
}

.m-pill-btn.active-level {
    background: #0284c7;
    border-color: #38bdf8;
    color: #ffffff;
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.5);
}

/* ==========================================================================
   MOBILE RESPONSIVENESS: PORTRAIT VS LANDSCAPE
   ========================================================================== */

/* 1. MOBILE LANDSCAPE MODE: Maximize widescreen canvas, float controls */
@media (max-height: 520px) and (orientation: landscape) {
    #game-wrapper {
        justify-content: center;
        padding: 0;
    }

    #canvas-container {
        width: min(98vw, calc((100dvh - 12px) * 16 / 9));
        height: min(calc(98vw * 9 / 16), calc(100dvh - 12px));
        max-width: 100vw;
        max-height: 100dvh;
        border-width: 2px;
        box-shadow: 0 0 15px rgba(0, 200, 255, 0.2);
    }

    #arcade-controls-bar {
        display: none; /* Hide desktop keyboard bar in landscape mobile */
    }

    #touch-controls {
        position: absolute;
        bottom: 8px;
        left: 0;
        width: 100%;
        max-width: 100%;
        padding: 0 max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
        box-sizing: border-box;
    }

    .touch-btn {
        width: 58px;
        height: 58px;
        background: rgba(15, 23, 42, 0.65); /* More translucent for gameplay visibility */
    }

    .touch-center-bar {
        position: absolute;
        top: 8px;
        right: max(12px, env(safe-area-inset-right));
        flex-direction: row;
        gap: 4px;
        background: rgba(10, 18, 30, 0.65);
        padding: 3px 6px;
        border-radius: 6px;
        border: 1px solid rgba(56, 189, 248, 0.25);
    }
}

/* 2. MOBILE PORTRAIT MODE: Game on top, dedicated controls deck below */
@media (max-width: 850px) and (orientation: portrait) {
    #game-wrapper {
        justify-content: flex-start;
        padding-top: max(8px, env(safe-area-inset-top));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        gap: 12px;
    }

    #canvas-container {
        width: 100vw;
        max-width: 100vw;
        height: auto;
        aspect-ratio: 16 / 9;
        border-left: none;
        border-right: none;
        border-radius: 0;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.9);
    }

    #arcade-controls-bar {
        display: none;
    }

    #touch-controls {
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        flex: 1;
        width: 100%;
        padding: 12px 16px;
    }

    .touch-cluster {
        gap: 14px;
    }

    .touch-btn {
        width: 66px;
        height: 66px;
    }

    .touch-center-bar {
        margin: 0 4px;
    }
}
