/* ============================================
   Game Responsive CSS
   Responsive HUD redesign for ALL ScaryGamesAI games
   Covers phone, tablet, landscape, and desktop
   ============================================ */

/* ── CSS Custom Properties for game HUD ───── */
:root {
    --hud-font: 'Inter', system-ui, sans-serif;
    --hud-bg: rgba(0, 0, 0, 0.55);
    --hud-border: rgba(255, 255, 255, 0.1);
    --hud-text: #fff;
    --hud-accent: #cc1122;
    --hud-radius: 12px;
    --hud-blur: 12px;
    --hud-gap: 10px;
    --hud-pad: 12px 16px;
    --hud-font-size: 0.92rem;
    --hud-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* ── Game HUD Redesign ────────────────────── */
.game-hud {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: var(--hud-gap);
    z-index: 100;
    pointer-events: none;
    font-family: var(--hud-font);
}

.game-hud>* {
    pointer-events: auto;
}

/* ── HUD Score Elements ───────────────────── */
.hud-score {
    background: var(--hud-bg);
    backdrop-filter: blur(var(--hud-blur));
    -webkit-backdrop-filter: blur(var(--hud-blur));
    border: 1px solid var(--hud-border);
    border-radius: var(--hud-radius);
    padding: var(--hud-pad);
    color: var(--hud-text);
    font-family: var(--hud-font);
    font-size: var(--hud-font-size);
    font-weight: 600;
    letter-spacing: 0.3px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    box-shadow: var(--hud-shadow);
    white-space: nowrap;
    max-width: calc(50vw - 20px);
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.2s ease;
    line-height: 1.3;
}

.hud-score:empty {
    display: none;
}

/* ── HUD Buttons ──────────────────────────── */
.hud-btn {
    background: var(--hud-bg);
    backdrop-filter: blur(var(--hud-blur));
    -webkit-backdrop-filter: blur(var(--hud-blur));
    border: 1px solid var(--hud-border);
    border-radius: var(--hud-radius);
    padding: 8px 14px;
    color: var(--hud-text);
    font-family: var(--hud-font);
    font-size: 0.8rem;
    font-weight: 500;
    box-shadow: var(--hud-shadow);
    transition: all 0.2s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.hud-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.12);
}

/* ── Back Link ────────────────────────────── */
.back-link {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 500;
    background: var(--hud-bg);
    backdrop-filter: blur(var(--hud-blur));
    -webkit-backdrop-filter: blur(var(--hud-blur));
    border: 1px solid var(--hud-border);
    border-radius: var(--hud-radius);
    padding: 8px 14px;
    color: var(--hud-text);
    font-family: var(--hud-font);
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    box-shadow: var(--hud-shadow);
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.back-link:active {
    transform: scale(0.95);
}

/* ── Start Screen Responsive ──────────────── */
.start-screen {
    padding: 20px;
    padding-top: env(safe-area-inset-top, 20px);
    padding-bottom: env(safe-area-inset-bottom, 20px);
    box-sizing: border-box;
}

.start-screen h1 {
    font-size: clamp(1.5rem, 6vw, 3.5rem);
    text-align: center;
    word-break: break-word;
}

.start-screen .game-desc {
    font-size: clamp(0.82rem, 2.5vw, 1rem);
    max-width: min(400px, 90vw);
    text-align: center;
    line-height: 1.6;
    padding: 0 10px;
}

.start-btn {
    min-width: 180px;
    min-height: 52px;
    font-size: clamp(1rem, 3vw, 1.5rem);
    padding: 14px 36px;
    border-radius: 14px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ── Controls Overlay Responsive ──────────── */
.controls-overlay {
    padding: 20px;
    box-sizing: border-box;
}

.controls-content {
    max-width: min(500px, 90vw);
}

.controls-content h2 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
}

.control-item {
    font-size: clamp(0.85rem, 2.5vw, 1rem);
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.control-key {
    font-size: clamp(0.75rem, 2vw, 0.85rem);
    padding: 4px 10px;
    min-width: 40px;
}

/* ── Game End Screens ─────────────────────── */
.game-end-screen {
    padding: 24px;
    padding-top: env(safe-area-inset-top, 24px);
    padding-bottom: env(safe-area-inset-bottom, 24px);
    box-sizing: border-box;
    text-align: center;
}

.game-end-screen h1 {
    font-size: clamp(1.8rem, 7vw, 3.5rem);
    word-break: break-word;
}

.game-end-screen p {
    font-size: clamp(0.85rem, 2.5vw, 1.2rem);
    max-width: min(500px, 90vw);
    margin-left: auto;
    margin-right: auto;
    word-break: break-word;
}

.game-end-screen .play-btn {
    min-width: 160px;
    min-height: 48px;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ── Minimap Responsive ───────────────────── */
.minimap-container {
    max-width: 25vw;
    max-height: 25vw;
}

/* ── Difficulty Selector Responsive ───────── */
.difficulty-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 20px;
}

.difficulty-selector button {
    min-height: 40px;
    min-width: 80px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ── Pause Screen Responsive ──────────────── */
.pause-overlay {
    padding: 20px;
    box-sizing: border-box;
}

.pause-overlay h1 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
}

.pause-overlay button {
    min-height: 44px;
    min-width: 120px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ── Dynamic HUD message overlay ──────────── */
#hud-msg {
    position: fixed;
    top: 18%;
    left: 50%;
    transform: translateX(-50%);
    color: #ffcc44;
    font: 700 clamp(14px, 3vw, 18px) var(--hud-font);
    text-align: center;
    pointer-events: none;
    text-shadow: 0 0 12px rgba(255, 136, 0, 0.7);
    z-index: 999;
    max-width: 90vw;
    word-break: break-word;
    padding: 0 10px;
}

/* ══════════════════════════════════════════════
   PHONE (≤480px)
   ══════════════════════════════════════════════ */
@media (max-width: 480px) {
    :root {
        --hud-pad: 8px 10px;
        --hud-font-size: 0.78rem;
        --hud-radius: 8px;
        --hud-gap: 6px;
        --hud-blur: 8px;
    }

    .game-hud {
        padding: 6px 8px;
        padding-top: max(6px, env(safe-area-inset-top, 6px));
        flex-direction: row;
        flex-wrap: wrap;
    }

    .hud-score {
        max-width: calc(50vw - 12px);
        font-size: 0.72rem;
        padding: 6px 8px;
    }

    .back-link {
        top: 6px;
        left: 6px;
        font-size: 0.72rem;
        padding: 5px 10px;
        border-radius: 8px;
    }

    .minimap-container {
        max-width: 20vw;
        max-height: 20vw;
        transform: scale(0.65);
        transform-origin: bottom left;
    }

    .start-screen .game-desc {
        font-size: 0.78rem;
        max-width: 85vw;
    }

    .game-end-screen h1 {
        font-size: clamp(1.4rem, 7vw, 2.5rem);
    }

    .game-end-screen p {
        font-size: 0.8rem;
    }

    #hud-msg {
        top: 15%;
        font-size: 13px;
        max-width: 85vw;
    }
}

/* ══════════════════════════════════════════════
   PHONE LANDSCAPE
   ══════════════════════════════════════════════ */
@media (max-height: 480px) and (orientation: landscape) {
    :root {
        --hud-pad: 6px 10px;
        --hud-font-size: 0.72rem;
        --hud-gap: 4px;
    }

    .game-hud {
        padding: 4px 8px;
        padding-left: max(8px, env(safe-area-inset-left, 8px));
        padding-right: max(8px, env(safe-area-inset-right, 8px));
    }

    .hud-score {
        font-size: 0.68rem;
        padding: 4px 8px;
        border-radius: 6px;
    }

    .back-link {
        top: 4px;
        left: max(4px, env(safe-area-inset-left, 4px));
        font-size: 0.68rem;
        padding: 4px 8px;
    }

    .start-screen h1 {
        font-size: clamp(1.2rem, 4vw, 1.8rem);
        margin-bottom: 6px;
    }

    .start-screen .game-desc {
        font-size: 0.72rem;
        margin-bottom: 12px;
    }

    .start-btn {
        padding: 10px 28px;
        font-size: 0.9rem;
        min-height: 40px;
    }

    .game-end-screen h1 {
        font-size: clamp(1.2rem, 5vw, 2rem);
    }

    #hud-msg {
        top: 8%;
        font-size: 12px;
    }

    .controls-overlay {
        padding: 10px;
    }

    .controls-content h2 {
        font-size: 1.2rem;
        margin-bottom: 10px;
    }

    .control-item {
        margin-bottom: 6px;
        font-size: 0.75rem;
    }

    .minimap-container {
        max-width: 15vh;
        max-height: 15vh;
    }
}

/* ══════════════════════════════════════════════
   TABLET (481px – 1024px)
   ══════════════════════════════════════════════ */
@media (min-width: 481px) and (max-width: 1024px) {
    :root {
        --hud-pad: 10px 14px;
        --hud-font-size: 0.85rem;
        --hud-radius: 10px;
    }

    .game-hud {
        padding: 10px 14px;
    }

    .minimap-container {
        max-width: 22vw;
        max-height: 22vw;
    }
}

/* ══════════════════════════════════════════════
   LARGE DESKTOP (>1400px)
   ══════════════════════════════════════════════ */
@media (min-width: 1400px) {
    :root {
        --hud-font-size: 1rem;
        --hud-pad: 14px 20px;
    }
}

/* ══════════════════════════════════════════════
   SAFE AREA AWARE (notched phones)
   ══════════════════════════════════════════════ */
@supports (padding: env(safe-area-inset-top)) {
    .game-hud {
        padding-top: max(12px, env(safe-area-inset-top, 12px));
        padding-left: max(12px, env(safe-area-inset-left, 12px));
        padding-right: max(12px, env(safe-area-inset-right, 12px));
    }

    .start-screen,
    .game-end-screen,
    .controls-overlay {
        padding-top: env(safe-area-inset-top, 20px);
        padding-bottom: env(safe-area-inset-bottom, 20px);
        padding-left: env(safe-area-inset-left, 20px);
        padding-right: env(safe-area-inset-right, 20px);
    }
}

/* ══════════════════════════════════════════════
   TOUCH-SPECIFIC ENHANCEMENTS
   ══════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {

    /* Enlarge touch targets */
    .hud-btn,
    .back-link {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .start-btn,
    .play-btn {
        min-height: 52px;
        font-size: 1.1rem;
    }

    .game-end-screen a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 10px 16px;
    }

    /* Remove hover effects on touch */
    .hud-btn:hover,
    .back-link:hover,
    .start-btn:hover,
    .play-btn:hover {
        transform: none;
    }

    /* Hide keyboard hints on touch devices */
    .control-key {
        display: none;
    }

    .control-item {
        justify-content: center;
    }
}

/* ══════════════════════════════════════════════
   HIGH DPI
   ══════════════════════════════════════════════ */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {

    .hud-score,
    .hud-btn,
    .back-link {
        border-width: 0.5px;
    }
}

/* ══════════════════════════════════════════════
   REDUCED MOTION
   ══════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {

    .start-btn,
    .controls-start-hint {
        animation: none !important;
    }

    .hud-score,
    .hud-btn,
    .back-link,
    .mc-btn,
    .mc-joystick-thumb {
        transition: none !important;
    }
}

/* ══════════════════════════════════════════════
   DARK MODE ADJUSTMENTS (forced)
   ══════════════════════════════════════════════ */
@media (prefers-color-scheme: dark) {
    :root {
        --hud-bg: rgba(0, 0, 0, 0.6);
        --hud-border: rgba(255, 255, 255, 0.08);
    }
}