/* mobile-styles.css */

/* --- PRIMARY BREAKPOINT FOR MOBILE/TABLET --- */
@media (max-width: 1050px) {
    /* Remove the minimum width constraint that causes horizontal scrolling */
    body {
        min-width: unset !important;
    }

    /* Stack the main game elements vertically */
    #game-board-and-controls {
        flex-direction: column;
        align-items: center;
        gap: 0;
    }

    /* This wrapper will define the final size of the scaled board */
    .board-scaler-wrapper {
        width: 95vw;
        height: 95vw; /* Maintain square aspect ratio */
        max-width: 500px; /* Cap the size on larger tablets */
        max-height: 500px;
        position: relative;
    }

    /* This scales the original, large board down to fit the wrapper */
    #board {
        transform-origin: top left;
        /* The board's natural width is ~983px. We scale it down to fit 95% of the viewport width. */
        transform: scale(calc(95vw / 983px));
        max-width: 500px; /* Corresponds to the wrapper's max-width */
        margin: 0; /* Reset original margin */
        position: absolute;
        top: 0;
        left: 0;
    }

    /* Reposition the game control panel to appear below the board */
    #control {
        position: relative !important; /* Override absolute positioning */
        top: auto !important;
        left: auto !important;
        margin-top: 20px;
        width: 100%;
        max-width: 450px;
        box-sizing: border-box;
    }

    /* Reposition the player money bar to be a full-width element */
    #moneybarwrap {
        position: relative;
        width: 100%;
        margin-top: 10px;
    }
    #moneybar {
        float: none;
        margin: 0 auto; /* Center the table within the wrapper */
        width: auto;
    }

    /* Make the game setup screen mobile-friendly */
    #setup {
        width: 95%;
        box-sizing: border-box;
    }
    .player-input {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
        margin-bottom: 15px;
        padding: 10px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
    }
    .player-input input[type="text"],
    .player-input select {
        width: 100%;
        box-sizing: border-box;
    }

    /* Adjust popups for mobile screens */
    #popupwrap, #statswrap {
        top: 80px; /* Position below the mobile header */
        width: 100%;
        left: 0;
    }
    #popup, #stats {
        width: 90%;
        box-sizing: border-box;
    }

    /* Adjust trade window */
    #trade {
        width: 95%;
        box-sizing: border-box;
        margin: 15px auto;
    }
    .trade-cell {
        width: 50%;
    }
}

/* Specific adjustments for very small screens */
@media (max-width: 400px) {
    .game-title {
        font-size: 1.5rem;
    }
    .board-scaler-wrapper, #board {
        transform: scale(calc(92vw / 983px));
    }
    #control {
        padding: 5px;
    }
    #control table {
        width: 100%;
    }
    #menu {
        width: 100%;
        margin: 0;
    }
    #menutable {
        width: 100%;
    }
}