/* ── Touch Device Base Fixes ─────────────────────────────── */

@media (pointer: coarse) {
    body {
        cursor: default;
        /* Prevent text selection, callout menus, etc. */
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    #game-canvas {
        cursor: default;
    }

    /* Prevent iOS rubber-band scrolling */
    html, body {
        position: fixed;
        overflow: hidden;
        width: 100%;
        height: 100%;
    }
}

/* ── Touch Control Elements ──────────────────────────────── */

.touch-joystick-base {
    position: fixed;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 2px solid rgba(0, 255, 255, 0.25);
    background: rgba(0, 255, 255, 0.05);
    transform: translate(-50%, -50%);
    display: none;
    pointer-events: none;
    z-index: 16;
}

.touch-joystick-thumb {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 255, 255, 0.5);
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.4), inset 0 0 8px rgba(0, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.touch-aim-indicator {
    position: fixed;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 2px solid rgba(255, 136, 0, 0.25);
    background: rgba(255, 136, 0, 0.05);
    transform: translate(-50%, -50%);
    display: none;
    pointer-events: none;
    z-index: 16;
}

.touch-bomb-btn {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid rgba(255, 68, 68, 0.5);
    background: rgba(255, 68, 68, 0.15);
    color: rgba(255, 68, 68, 0.9);
    font-family: 'Courier New', monospace;
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: pointer;
    z-index: 16;
    box-shadow: 0 0 12px rgba(255, 68, 68, 0.2);
    -webkit-tap-highlight-color: transparent;
    bottom: calc(30px + env(safe-area-inset-bottom, 0px));
}

.touch-bomb-btn:active {
    background: rgba(255, 68, 68, 0.4);
    box-shadow: 0 0 20px rgba(255, 68, 68, 0.5);
}

.touch-pause-btn {
    position: fixed;
    top: 12px;
    right: 12px;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
    font-family: 'Courier New', monospace;
    font-size: 16px;
    font-weight: bold;
    letter-spacing: 2px;
    cursor: pointer;
    z-index: 16;
    -webkit-tap-highlight-color: transparent;
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
}

.touch-pause-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

/* ── Portrait Rotation Warning ───────────────────────────── */

#rotate-device-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 9999;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    color: #0ff;
    font-family: 'Courier New', monospace;
    text-align: center;
}

#rotate-device-overlay .rotate-icon {
    font-size: 64px;
    margin-bottom: 20px;
    animation: rotate-pulse 2s ease-in-out infinite;
}

#rotate-device-overlay .rotate-text {
    font-size: 18px;
    letter-spacing: 3px;
    text-transform: uppercase;
}

@keyframes rotate-pulse {
    0%, 100% { opacity: 0.5; transform: rotate(0deg); }
    50% { opacity: 1; transform: rotate(90deg); }
}

/* Only show portrait warning on touch devices in portrait */
@media (orientation: portrait) and (pointer: coarse) {
    #rotate-device-overlay {
        display: flex;
    }

    #game-container {
        display: none;
    }
}

/* ── Responsive HUD ─────────────────────────────────────── */

/* Start screen scrollable on small screens */
@media (max-height: 500px) {
    #start-screen {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        padding: 20px 0;
    }
}

@media (max-width: 900px) {
    #score {
        font-size: 28px;
    }

    #combo, #multiplier {
        font-size: 16px;
    }

    #hud-bottom {
        font-size: 12px;
    }

    .title-main {
        font-size: clamp(28px, 8vw, 48px);
    }

    .title-tagline {
        font-size: clamp(10px, 2.5vw, 14px);
    }

    .menu-start {
        font-size: clamp(12px, 3vw, 16px);
    }

    .menu-controls {
        font-size: clamp(8px, 2vw, 11px);
    }
}

@media (max-width: 600px) {
    #score {
        font-size: 22px;
    }

    #combo, #multiplier {
        font-size: 13px;
    }

    #hud-top {
        padding: 6px 10px;
    }

    #hud-bottom {
        padding: 4px 10px;
        font-size: 11px;
        gap: 12px;
    }

    #game-over h1 {
        font-size: 28px;
    }

    #game-over .subtitle {
        font-size: 12px;
    }

    #run-stats {
        font-size: 11px;
        gap: 8px;
    }

    #pause-screen h1 {
        font-size: 28px;
    }

    /* Settings screen on small screens */
    #settings-screen {
        padding: 15px;
        overflow-y: auto;
    }

    #settings-screen h1 {
        font-size: 24px;
    }

    .setting-row label {
        font-size: 11px;
    }

    /* Start screen scores */
    #start-scores,
    #leaderboard-panel {
        font-size: 11px;
    }

    #cosmetics-panel {
        transform: scale(0.85);
    }
}

/* ── Touch Targets ───────────────────────────────────────── */

@media (pointer: coarse) {
    /* Ensure all interactive elements meet 48px minimum */
    .action-btn,
    .daily-btn,
    .wave-btn,
    .settings-btn,
    .toggle-btn,
    .rebind-btn {
        min-height: 48px;
        min-width: 48px;
    }

    /* Larger slider touch targets */
    input[type="range"] {
        height: 32px;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
    }

    /* Larger cosmetic swatches */
    .cosmetic-swatch {
        min-width: 40px;
        min-height: 40px;
    }

    /* Larger menu items */
    .menu-achievements,
    .menu-settings,
    .pause-settings,
    .pause-quit {
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Leaderboard tabs */
    .lb-tab {
        min-height: 44px;
        padding: 8px 12px;
    }

    /* Settings close */
    .settings-close {
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Hide keyboard controls section on touch devices */
    .controls-display {
        display: none;
    }

    #reset-bindings {
        display: none;
    }
}

/* ── Safe Area Insets ────────────────────────────────────── */

@supports (padding: env(safe-area-inset-top)) {
    #hud-top {
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
        padding-left: calc(15px + env(safe-area-inset-left, 0px));
        padding-right: calc(15px + env(safe-area-inset-right, 0px));
    }

    #hud-bottom {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        padding-left: calc(15px + env(safe-area-inset-left, 0px));
        padding-right: calc(15px + env(safe-area-inset-right, 0px));
    }
}
