/* ============================================================
   GEOMETRIC PANIC — styles.css
   Desktop: full-screen canvas. Mobile: canvas + side touch controls
   ============================================================ */

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #020204;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    font-family: "Courier New", monospace;
}

/* ---- Game wrapper ---- */
#game-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---- Canvas (desktop: fills viewport) ---- */
canvas#game {
    display: block;
    cursor: crosshair;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
}

/* ---- Touch controls (hidden on desktop) ---- */
#touch-controls {
    display: none;
}

/* ===========================================================
   MOBILE LAYOUT — landscape preferred
   [joystick zone] [game canvas] [button zone]
   =========================================================== */
@media (pointer: coarse) {
    html, body {
        overscroll-behavior: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
        position: fixed;
        width: 100%;
        height: 100%;
    }

    canvas#game {
        cursor: none;
    }

    #game-wrapper {
        flex-direction: row;
        gap: 0;
    }

    /* Touch controls container — flex wrapper for left + right zones */
    #touch-controls {
        display: contents; /* lets children participate in the flex row */
    }

    /* ---- Joystick zone (left) ---- */
    .touch-zone-left {
        flex: 0 0 25vw;
        min-width: 120px;
        max-width: 200px;
        height: 100%;
        position: relative;
        background: rgba(0, 229, 255, 0.03);
        border-right: 1px solid rgba(0, 229, 255, 0.08);
        order: -1; /* before canvas */
        touch-action: none;
    }

    /* ---- Button zone (right) ---- */
    .touch-zone-right {
        flex: 0 0 25vw;
        min-width: 120px;
        max-width: 200px;
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background: rgba(255, 0, 200, 0.03);
        border-left: 1px solid rgba(255, 0, 200, 0.08);
        order: 1; /* after canvas */
        touch-action: none;
    }

    /* Canvas takes remaining middle space */
    canvas#game {
        flex: 1 1 auto;
        min-width: 0;
        height: 100%;
        order: 0;
    }

    /* ---- Joystick ---- */
    .joystick-base {
        position: absolute;
        width: 140px;
        height: 140px;
        border-radius: 50%;
        border: 2px solid rgba(0, 229, 255, 0.2);
        background: rgba(0, 229, 255, 0.04);
        /* Default center position — use margins since JS overrides left/top */
        left: 50%;
        top: 50%;
        margin-left: -70px;
        margin-top: -70px;
        transition: opacity 0.15s;
        opacity: 0.5;
    }

    .joystick-base.active {
        opacity: 1;
        border-color: rgba(0, 229, 255, 0.5);
        background: rgba(0, 229, 255, 0.08);
    }

    .joystick-knob {
        position: absolute;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: rgba(0, 229, 255, 0.35);
        border: 2px solid rgba(255, 255, 255, 0.3);
        left: 50%;
        top: 50%;
        margin-left: -28px;
        margin-top: -28px;
        transition: background 0.1s;
        will-change: transform;
    }

    .joystick-base.active .joystick-knob {
        background: rgba(0, 229, 255, 0.6);
        border-color: rgba(255, 255, 255, 0.6);
    }

    /* ---- Action buttons grid ---- */
    .touch-btn-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 10px;
        width: 100%;
        max-width: 180px;
    }

    /* ---- Pause button (top of right zone) ---- */
    .touch-btn-pause {
        width: 40px !important;
        height: 40px !important;
        font-size: 14px !important;
        border-radius: 8px !important;
        margin: 6px auto 4px auto;
        opacity: 0.35;
        letter-spacing: 2px;
    }

    .touch-btn-pause.active {
        opacity: 0.8;
    }

    .touch-btn {
        width: 64px;
        height: 64px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        justify-self: center;
        font-size: 22px;
        font-weight: bold;
        color: #fff;
        background: rgba(255, 255, 255, 0.05);
        border: 2px solid var(--btn-color, #888);
        opacity: 0.45;
        transition: opacity 0.1s, background 0.1s, transform 0.1s;
        touch-action: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .touch-btn.active {
        opacity: 1;
        background: var(--btn-color);
        transform: scale(1.1);
        box-shadow: 0 0 20px var(--btn-color);
    }

    /* Hide yellow button (toggled via JS) */
    .touch-btn-yellow[style*="display: none"] {
        /* handled by JS */
    }

    /* ---- Portrait fallback: stack vertically ---- */
    @media (orientation: portrait) {
        #game-wrapper {
            flex-direction: column;
        }

        .touch-zone-left {
            flex: 0 0 20vh;
            min-width: unset;
            max-width: unset;
            width: 50%;
            height: auto;
            min-height: 120px;
            max-height: 180px;
            order: 1; /* below canvas */
            border-right: none;
            border-top: 1px solid rgba(0, 229, 255, 0.08);
            position: absolute;
            bottom: 0;
            left: 0;
        }

        .touch-zone-right {
            flex: 0 0 20vh;
            min-width: unset;
            max-width: unset;
            width: 50%;
            height: auto;
            min-height: 120px;
            max-height: 180px;
            order: 2;
            border-left: none;
            border-top: 1px solid rgba(255, 0, 200, 0.08);
            position: absolute;
            bottom: 0;
            right: 0;
        }

        canvas#game {
            height: calc(100% - 20vh);
            max-height: calc(100% - 120px);
        }
    }
}

/* ---- Mobile start screen difficulty selector ---- */
.mobile-difficulty-bar {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 10;
}

.mobile-diff-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid rgba(0, 229, 255, 0.4);
    background: rgba(0, 229, 255, 0.08);
    color: #00E5FF;
    font-size: 24px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}

.mobile-diff-btn:active {
    background: rgba(0, 229, 255, 0.3);
}

.mobile-diff-label {
    color: #00E5FF;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    min-width: 100px;
}
