/* CSS specifically for mobile optimization v3 */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 17, 32, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--accent-primary);
    font-size: 1.5rem;
    font-weight: 700;
    z-index: 9999;
}

/* Base adjustment for App */
@media (max-width: 600px) {
    #app {
        padding: 0.3rem;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
        gap: 0.4rem;
        min-height: 100vh;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Header Compact */
    header {
        padding: 0.5rem 0.8rem;
        gap: 0.4rem;
        border-radius: 12px;
    }

    body.list-mode header {
        flex-direction: column;
        align-items: center;
    }

    .logo-area h1 {
        font-size: 1.1rem;
    }

    .logo-area h1 span {
        display: none;
    }

    .nav-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.7rem;
    }

    .stats {
        gap: 0.8rem;
    }

    .stat-item span:not(.label) {
        font-size: 0.9rem;
    }

    /* List View */
    .challenge-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .challenge-card {
        padding: 0.8rem;
    }

    /* Game View - Portrait */
    .game-layout {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
    }

    .sudoku-grid {
        width: 92vw;
        max-width: 400px;
        /* Limit size for the '50% feel' */
        aspect-ratio: 1;
        margin: 0 auto;
        border-width: 2px;
    }

    .cell-value {
        font-size: 1.8rem !important;
    }

    .game-sidebar {
        width: 100%;
        max-width: 400px;
        gap: 0.4rem;
    }

    /* Compact Numpad (5x2) */
    .numpad {
        gap: 0.3rem;
        grid-template-columns: repeat(5, 1fr);
    }

    .num-btn {
        aspect-ratio: 1;
        border-radius: 8px;
    }

    .num-btn span:first-child {
        font-size: 1.3rem;
    }

    .num-btn .count {
        font-size: 0.55rem;
    }

    #btn-erase {
        grid-column: span 1;
        height: auto;
        aspect-ratio: 1;
        font-size: 0.8rem;
    }

    .primary-btn {
        padding: 0.7rem;
        font-size: 0.9rem;
    }

    /* Replay Bar for Mobile */
    .replay-bar {
        padding: 0.6rem 0.8rem;
        padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
    }

    .replay-content {
        gap: 0.6rem;
    }

    .replay-info-row {
        flex-direction: column;
        /* Stack label above controls */
        align-items: center;
        gap: 0.4rem;
    }

    .replay-info-row>span {
        font-size: 0.7rem;
        font-weight: 600;
        color: var(--accent-primary);
        text-transform: uppercase;
        letter-spacing: 0.1em;
        white-space: nowrap;
        /* Prevent vertical text */
    }

    .replay-controls {
        gap: 0.5rem;
        width: 100%;
        justify-content: center;
    }

    .replay-controls button {
        min-width: 44px;
        min-height: 44px;
        font-size: 1.1rem;
        border-radius: 10px;
        padding: 0;
    }

    #replay-play {
        min-width: 100px;
        font-size: 0.9rem;
    }

    #replay-exit {
        min-width: 60px;
        font-size: 0.85rem;
    }
}

/* Landscape Mobile Fix */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        display: none !important;
    }

    #app {
        padding: 0.3rem;
        height: 100vh;
    }

    .game-layout {
        flex-direction: row;
        justify-content: center;
        align-items: stretch;
        height: 95vh;
        gap: 1rem;
    }

    .game-primary {
        height: 100%;
        display: flex;
        align-items: center;
    }

    .sudoku-grid {
        height: 85vh;
        width: auto;
        aspect-ratio: 1;
    }

    .game-sidebar {
        width: 300px;
        height: 100%;
        overflow-y: auto;
        padding-right: 0.5rem;
        justify-content: flex-start;
    }

    .numpad {
        grid-template-columns: repeat(5, 1fr);
    }

    /* Replay in Landscape */
    .replay-bar {
        padding: 0.2rem 1rem;
    }

    .replay-content {
        flex-direction: row;
        justify-content: space-between;
    }
}