/* mobile.css - PWA features, mobile controls, and small screen optimizations */

/* --- PWA & UPDATE STYLES --- */
.pwa-install-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin-top: 10px;
}

.update-notification {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ff9800;
    color: #000;
    padding: 15px;
    z-index: 200;
    text-align: center;
    font-family: 'Press Start 2P', cursive;
}

.notification-content {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.notification-content p {
    margin: 0;
    font-size: 0.8rem;
}

.offline {
    filter: grayscale(0.3);
}

/* --- MOBILE GAME FEATURES (Quick Actions) --- */
.quick-actions {
    position: fixed;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 45;
}

.quick-action-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 2px solid rgba(255, 215, 0, 0.7);
    background: rgba(0, 0, 0, 0.7);
    color: #ffd700;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.quick-action-btn:hover, .quick-action-btn:active {
    background: rgba(255, 215, 0, 0.2);
    transform: scale(1.1);
}

/* --- NEW MOBILE CONTROLS (D-Pad and Actions) --- */
#mobile-dpad-container, #mobile-actions-container {
    position: fixed;
    bottom: 15px;
    z-index: 50;
    opacity: 0.8;
    transition: opacity 0.2s ease-in-out;
}

#mobile-dpad-container {
    left: 8px; /* Reduce from 15px → 8px = 7px saved */
}

#mobile-actions-container {
    right: 8px; /* Reduce from 15px → 8px = 7px saved */
}

#mobile-dpad-container:hover, #mobile-actions-container:hover {
    opacity: 1.0;
}

.mobile-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.mobile-dpad {
    display: grid;
    grid-template-columns: repeat(3, 50px);
    grid-template-rows: repeat(3, 50px);
    gap: 5px;
}

.mobile-btn, .mobile-dpad-btn {
    font-family: 'Press Start 2P', cursive;
    background-color: rgba(40, 40, 40, 0.8);
    border: 2px solid var(--grey-border);
    color: var(--main-gold);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    transition: var(--button-transition); /* Restored */
    box-shadow: 0 2px 0 #333; /* Restored */
}

/* Active State (Restored) */
.mobile-btn:active, .mobile-dpad-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #333;
}

.mobile-btn {
    font-size: clamp(8px, 1.8vmin, 0.75rem);
    padding: 10px 5px;
}

#mobile-action-map {
    font-size: 1.2rem;
}

.mobile-dpad-btn {
    font-size: clamp(12px, 3vmin, 1.3rem); /* Icon-style elements */
}

#mobile-dpad-up { grid-area: 1 / 2 / 2 / 3; }
#mobile-dpad-left { grid-area: 2 / 1 / 3 / 2; }
#mobile-dpad-center { grid-area: 2 / 2 / 3 / 3; }
#mobile-dpad-right { grid-area: 2 / 3 / 3 / 4; }
#mobile-dpad-down { grid-area: 3 / 2 / 4 / 3; }

/* Hide quick actions in landscape mode on mobile (Restored) */
body.layout-landscape .quick-actions {
    display: none;
}

/* --- Safe Area Support for Notched Devices (Restored) --- */
@supports (padding: max(0px)) {
    /* Body padding handled in layout.css */
    #mobile-actions-container {
        right: max(8px, env(safe-area-inset-right));
        bottom: max(15px, env(safe-area-inset-bottom));
    }
    #mobile-dpad-container {
        left: max(8px, env(safe-area-inset-left));
        bottom: max(15px, env(safe-area-inset-bottom));
    }
}

/* Responsive adjustments for class selection (Restored) */
@media (max-width: 480px) {
    .sprite-selection-container {
        gap: 10px;
    }

    .sprite-selector {
        padding: 8px;
        min-width: 70px;
    }

    .sprite-placeholder {
        width: 40px;
        height: 40px;
        font-size: 2rem;
    }

    .sprite-label {
        font-size: 0.6rem;
    }

    #class-description {
        font-size: 0.7rem;
    }
}

/* --- Responsive adjustments for very small screens --- */
@media (max-height: 600px) and (orientation: landscape) {
    .game-toast {
        top: 10px;
        font-size: 0.6rem;
        padding: 5px 15px;
    }

    .achievement-popup {
        top: 10px;
        right: -300px;
        max-width: 250px;
    }

    .quick-actions {
        right: 5px;
        gap: 5px;
    }

    .quick-action-btn {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
}

/* --- Mobile optimizations (Small portrait screens) --- */
@media (max-width: 480px) {
    .dialog-content {
        padding: 15px;
        width: 95vw;
        max-width: none;
        overflow-x: hidden !important;
    }

    .game-button {
        font-size: 0.8rem;
        padding: 12px 20px;
    }

    /* Achievements dialog mobile optimizations */
    #achievements-screen .dialog-content {
        width: 98vw;
        height: 95vh;
        padding: 10px;
    }

    .achievements-grid {
        grid-template-columns: 1fr !important;
        gap: 8px;
        margin-top: 8px;
    }

    .achievement-item {
        padding: 8px;
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
    }

    .achievement-info strong {
        font-size: 0.7rem;
    }

    .achievement-info small {
        font-size: 0.5rem;
    }

    /* Character sheet mobile optimizations */
    #character-sheet-screen .dialog-content {
        width: 98vw;
        height: 95vh;
        padding: 8px;
        gap: 10px;
    }

    .character-sheet-container {
        gap: 10px;
    }

    .character-sheet-panel {
        padding: 8px;
        border-width: 1px;
        gap: 8px;
    }

    /* Ensure achievements section is visible on mobile */
    .achievements-section {
        margin-top: 15px;
        padding-top: 15px;
        flex-shrink: 0; /* Don't let it get compressed */
    }

    .achievements-section button {
        width: 100%;
        margin: 0;
        font-size: 0.8rem;
        padding: 10px;
    }

    /* Remove fixed heights from inventory lists on mobile */
    .inventory-list, .equipment-list {
        max-height: none !important;
        height: auto !important;
    }

    /* Ensure inventory controls don't take too much space */
    .inventory-controls {
        margin-bottom: 8px;
    }

    #inventory-filter {
        padding: 6px;
        font-size: 0.7rem;
    }

    #shop-screen .dialog-content {
        width: 98vw;
        height: 95vh;
        max-height: 95vh;
        padding: 8px;
    }

    .shop-panels-container {
        gap: 10px;
    }

    .shop-panel {
        padding: 8px;
        border-width: 1px;
    }

    .shop-list {
        min-height: 120px; /* Ensure adequate scrollable area */
    }

    /* Position close button at bottom for mobile */
    #shop-screen #close-shop-button {
        position: sticky;
        bottom: 0;
        background-color: var(--dark-ui);
        border-top: 2px solid var(--grey-border);
        margin-top: 10px;
        padding: 12px 20px;
        width: 100%;
        box-sizing: border-box;
    }

    .settings-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    #mobile-dpad-container {
        left: 4px; /* Ultra-compact = 11px saved */
    }
    #mobile-actions-container {
        right: 4px; /* Ultra-compact = 11px saved */
    }

    h1, h2 {
        font-size: clamp(10px, 2.8vw, 14px); /* Viewport-width based scaling */
    }
    h3 {
        font-size: clamp(9px, 2.4vw, 12px);
    }

    .stats-box p,
    .log-box p {
        font-size: clamp(8px, 2.2vw, 11px); /* Responsive to screen width */
        line-height: 1.2; /* Tighter line spacing */
    }

    .small-text {
        font-size: clamp(7px, 1.8vw, 9px);
    }

    .mobile-btn {
        font-size: clamp(7px, 2vw, 10px);
        padding: 6px 3px; /* Reduce padding too */
    }

    .mobile-dpad-btn {
        font-size: clamp(10px, 3.5vw, 16px);
    }
}

@media (max-width: 768px) {
    .dialog-content {
        border-width: 6px; /* Mobile-optimized = 28px total saved */
        border-image-slice: 20 fill;
        padding: clamp(6px, 1.5vw, 15px);
    }

    h2 {
        font-size: clamp(12px, 2.5vmin, 1rem);
    }
}

/* --- Mobile Portrait Layout Alignment --- */
@media (max-width: 768px) and (orientation: portrait) {
    body.layout-portrait .ui-container#portrait-ui {
        flex-wrap: nowrap; /* Ensure items stay on one line */
        height: 25vh; /* Constrain UI to 25% of viewport height */
        max-height: 200px; /* Cap maximum height */
        overflow: hidden;
    }

    #portrait-ui > .stats-box,
    #portrait-ui > .log-box {
        width: calc(50% - 5px); /* Adjust width to account for the 10px gap */
        flex-grow: 1; /* Allow items to flexibly grow */
        height: 100%; /* Fill container height */
        max-height: none; /* Remove any max-height constraints */
        overflow-y: auto; /* Allow individual scrolling */
        min-height: 0; /* Allow flex shrinking */
    }

    /* Ensure message log doesn't grow the container */
    #portrait-message-log {
        height: calc(100% - 40px); /* Account for header space */
        max-height: none;
        overflow-y: auto !important;
        overflow-x: hidden;
        flex-grow: 1;
        min-height: 0;
    }
}
