/**
 * Studio i Mario Game — Mobile & Responsive Stylesheet
 * Handles touch controls, orientation overlays, HUD scaling, and Mushroom Info Modal reflow.
 */

/* ==========================================================
   1. PORTRAIT ROTATION WARNING OVERLAY
   ========================================================== */
#rotate-device-overlay {
    position: fixed;
    inset: 0;
    background: rgba(8, 6, 16, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 24px;
    box-sizing: border-box;
    text-align: center;
}

.rotate-card {
    background: rgba(30, 20, 45, 0.85);
    border: 2px solid rgba(236, 72, 153, 0.6);
    border-radius: 20px;
    padding: 28px 24px;
    max-width: 320px;
    width: 100%;
    box-shadow: 0 0 35px rgba(236, 72, 153, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.rotate-icon {
    font-size: 48px;
    animation: rotatePhone 2s ease-in-out infinite;
    display: inline-block;
}

@keyframes rotatePhone {
    0%, 20% { transform: rotate(0deg); }
    50%, 70% { transform: rotate(90deg); }
    100% { transform: rotate(0deg); }
}

.rotate-card h2 {
    font-family: var(--arcade-font, 'Press Start 2P', monospace);
    font-size: 13px;
    color: #f472b6;
    margin: 0;
    line-height: 1.5;
    letter-spacing: 0.5px;
}

.rotate-card p {
    font-size: 12px;
    color: #cbd5e1;
    margin: 0;
    line-height: 1.5;
}

/* Activate rotation prompt ONLY on small portrait viewports */
@media (orientation: portrait) and (max-width: 900px) {
    #rotate-device-overlay.show-portrait-warning {
        display: flex !important;
    }
}

/* ==========================================================
   2. TOUCH CONTROLS (ON-SCREEN D-PAD & ACTION BUTTONS)
   ========================================================== */
#touch-controls {
    display: none;
    position: absolute;
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
    left: 0;
    right: 0;
    padding: 0 max(20px, env(safe-area-inset-left, 20px)) 0 max(20px, env(safe-area-inset-right, 20px));
    justify-content: space-between;
    align-items: flex-end;
    z-index: 45;
    pointer-events: none;
    box-sizing: border-box;
}

.touch-dpad, .touch-actions {
    display: flex;
    gap: 10px;
    pointer-events: auto;
    align-items: center;
}

.touch-btn {
    width: 54px;
    height: 54px;
    min-width: 48px;
    min-height: 48px;
    background: rgba(255, 255, 255, 0.18);
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    color: #ffffff;
    font-family: var(--arcade-font, monospace);
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    outline: none;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.08s ease, border-color 0.08s ease;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn:active, .touch-btn.touch-active {
    background: rgba(236, 72, 153, 0.65);
    border-color: #fbcfe8;
    transform: scale(0.90);
    box-shadow: 0 0 16px rgba(236, 72, 153, 0.8);
}

.btn-jump-action {
    background: rgba(236, 72, 153, 0.38);
    border-color: #f472b6;
    width: 62px;
    height: 62px;
    font-size: 18px;
}

.btn-jump-action:active, .btn-jump-action.touch-active {
    background: linear-gradient(135deg, #f43f5e, #db2777);
    border-color: #ffffff;
    transform: scale(0.92);
}

/* Show touch controls on touch-enabled or small devices */
body.is-touch-device #touch-controls {
    display: flex;
}

@media (max-width: 960px) and (orientation: landscape) {
    #touch-controls {
        display: flex;
    }
}

/* ==========================================================
   3. HUD RESPONSIVE SCALING ON MOBILE
   ========================================================== */
@media (max-width: 820px), (max-height: 500px) {
    #hud-overlay {
        padding: 4px 10px;
        gap: 6px;
    }

    .hud-group {
        gap: 1px;
    }

    .hud-label {
        font-size: 7px;
    }

    .hud-value {
        font-size: 9px;
    }

    .hud-btn {
        padding: 3px 6px;
        font-size: 8px;
        border-radius: 4px;
    }

    .hud-controls {
        gap: 4px;
    }
}

/* ==========================================================
   4. MUSHROOM INFO MODAL REFLOW (HIGH PRIORITY)
   ========================================================== */
/* Vertical / Stacked Reflow for Narrow Viewports */
@media (max-width: 768px) {
    #venture-modal .modal-card {
        flex-direction: column !important;
        width: 94vw !important;
        max-width: 94vw !important;
        min-height: auto !important;
        max-height: 90vh !important;
        padding: 20px 18px !important;
        gap: 14px !important;
        border-radius: 20px !important;
        border-width: 3px !important;
    }

    .modal-mushroom-container {
        width: 100px !important;
        height: 100px !important;
        margin: 0 auto;
    }

    #modal-mushroom-img {
        max-width: 95px !important;
        max-height: 95px !important;
        transform: scale(1.05) !important;
    }

    .modal-body {
        width: 100%;
        gap: 12px;
    }

    #modal-venture-text {
        font-size: clamp(9px, 2.8vw, 11px) !important;
        line-height: 1.8 !important;
        max-height: 150px !important;
        padding-right: 4px;
        text-align: center;
        justify-content: center;
    }

    .modal-footer {
        width: 100%;
        justify-content: center !important;
        margin-top: 4px;
    }

    #modal-close-btn {
        width: 100% !important;
        max-width: 280px !important;
        min-height: 48px !important;
        padding: 12px 20px !important;
        font-size: 11px !important;
        display: flex;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
}

/* Landscape Phone Viewport Reflow (e.g. 375px–480px height) */
@media (max-height: 500px) and (orientation: landscape) {
    #venture-modal .modal-card {
        flex-direction: row !important;
        width: 92vw !important;
        max-width: 740px !important;
        min-height: auto !important;
        max-height: 88vh !important;
        padding: 14px 20px !important;
        gap: 18px !important;
        border-radius: 18px !important;
        border-width: 2.5px !important;
    }

    .modal-mushroom-container {
        width: 110px !important;
        height: 110px !important;
    }

    #modal-mushroom-img {
        max-width: 105px !important;
        max-height: 105px !important;
        transform: scale(1.05) !important;
    }

    .modal-body {
        gap: 8px;
    }

    #modal-venture-text {
        font-size: 9.5px !important;
        line-height: 1.75 !important;
        max-height: 125px !important;
        text-align: left;
        justify-content: flex-start;
    }

    .modal-footer {
        margin-top: 2px;
    }

    #modal-close-btn {
        min-height: 42px !important;
        padding: 8px 18px !important;
        font-size: 10px !important;
    }
}

/* ==========================================================
   5. START / GAME OVER / VICTORY MENUS MOBILE POLISH & SCROLL
   ========================================================== */
@media (max-width: 850px), (max-height: 550px) {
    .overlay-screen {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        justify-content: flex-start !important;
        padding: 20px 12px 48px 12px !important;
        box-sizing: border-box !important;
    }

    .card-menu {
        margin: auto auto !important; /* Centered when content fits; scrollable top-to-bottom when taller */
        padding: 16px 20px 24px 20px !important;
        max-width: 92vw !important;
        border-radius: 18px !important;
        box-sizing: border-box !important;
    }

    .game-title {
        font-size: 16px !important;
        margin-bottom: 4px !important;
    }

    .game-subtitle {
        font-size: 10.5px !important;
        margin-bottom: 10px !important;
    }

    .name-entry-box {
        margin-bottom: 10px !important;
        gap: 6px !important;
    }

    #player-name-input {
        padding: 8px 14px !important;
        font-size: 11px !important;
        max-width: 240px !important;
    }

    .leaderboard-section {
        padding: 8px 12px !important;
        margin-bottom: 12px !important;
    }

    .leaderboard-title {
        font-size: 9px !important;
        margin-bottom: 6px !important;
    }

    .leaderboard-row {
        font-size: 8px !important;
        padding: 3px 6px !important;
    }

    .controls-hint {
        font-size: 8px !important;
        margin-bottom: 10px !important;
    }

    .button-group {
        margin-top: 10px !important;
        margin-bottom: 6px !important;
        padding-bottom: 8px !important;
        gap: 8px !important;
    }

    .join-us-container {
        margin: 8px auto !important;
    }

    .join-us-img {
        max-width: 170px !important;
    }

    .retro-btn {
        padding: 10px 22px !important;
        font-size: 10.5px !important;
        min-height: 46px !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
    }
}
