/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    padding-top: 20px;
    padding-bottom: 20px;
    background-color: #f0f0f0;
    color: #333;
    line-height: 1.6;
}

#setup-screen {
    background-color: #fff;
    border: 1px solid #ccc;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    text-align: center;
    max-width: 500px;
    margin: 20px auto;
}
#setup-screen input { margin: 10px 0; padding: 8px; border-radius: 4px; border: 1px solid #ddd; width: 80%; }
#setup-screen button { padding: 10px 15px; background-color: #5cb85c; color: white; border: none; border-radius: 4px; cursor: pointer; }
#setup-screen button:hover { background-color: #4cae4c; }

#game-screen {
    background-color: #fff;
    border: 1px solid #ccc;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    max-width: 1200px;
    margin: 0 auto;
    overflow: hidden; /* Prevent children from causing body scrollbars if possible */
}

#main-content {
    display: flex;
    flex-direction: row; /* Default for desktop: board left, info right */
    justify-content: space-between; /* Distribute space */
    gap: 20px;
    align-items: flex-start; /* Align items to the top */
}

/* Board Container - Base Desktop Styles */
#board-container {
    width: 720px;
    height: 720px;
    display: grid;
    grid-template-columns: 90px repeat(9, 60px) 90px;
    grid-template-rows: 90px repeat(9, 60px) 90px;
    border: 3px solid black;
    position: relative;
    flex-shrink: 0;
}

#center-logo {
    grid-column: 2 / span 9;
    grid-row: 2 / span 9;
    background-color: #cce8d0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: darkgreen;
    border: 1px dashed #999;
    font-size: 2.5em; /* Desktop font size */
}

.square {
    border: 1px solid #ccc;
    font-size: 10px; /* Was 8px, try 10px or 11px */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    text-align: center;
    padding: 2px; /* Can slightly increase if space allows with new font size */
    box-sizing: border-box;
    position: relative;
    background-color: #f8f8f8;
    overflow: hidden;
}
.square .name {
    font-weight: bold;
    margin-top: 2px;
    line-height: 1.2; /* Desktop line height */
}
.square .price {
    color: #28a745;
    font-size: 0.9em; /* Relative to .square font-size */
}
.square .owner-indicator {
    width: 100%;
    height: 5px; /* Desktop height */
    margin-top: auto;
}

.corner {
    font-size: 14px; /* Desktop font size for corners */
    font-weight: bold;
}
.property-color-band {
    width: 100%;
    height: 18px; /* Desktop height */
    border-bottom: 1px solid #ccc;
}
/* Color definitions for property bands */
.color-brown { background-color: #964B00; }
.color-lightblue { background-color: #ADD8E6; }
.color-pink { background-color: #FFC0CB; }
.color-orange { background-color: #FFA500; }
.color-red { background-color: #FF0000; }
.color-yellow { background-color: #FFFF00; }
.color-green { background-color: #008000; }
.color-darkblue { background-color: #00008B; }

/* Game Info Panel - Base Desktop Styles */
#game-info-panel {
    flex-grow: 1;
    min-width: 300px;
    max-width: 450px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#player-info-container .player-info {
    border: 1px solid #ddd;
    padding: 8px;
    margin-bottom: 8px;
    border-radius: 4px;
    background-color: #f9f9f9;
    font-size: 0.9em; /* Base desktop font size */
}
#player-info-container .player-info.current-turn {
    border-color: gold;
    border-width: 2px;
    background-color: #fffacd;
}
#player-info-container .player-info strong { color: #007bff; }
#player-info-container .player-info br { margin-bottom: 3px; }

#controls-container {
    border: 1px solid #ddd; padding: 10px; border-radius: 4px;
}
#controls-container h2 { margin-top: 0; font-size: 1.1em; }
#dice-container { display: flex; align-items: center; margin-bottom: 10px; }
#dice-display { margin-right: 10px; font-size: 1em; }
#dice-display .die {
    display: inline-block;
    width: 22px; height: 22px;
    border: 1px solid #333;
    text-align: center; line-height: 22px;
    margin: 0 2px; background-color: white;
    border-radius: 3px;
}

#action-buttons button, #roll-dice-btn {
    margin: 3px 1px;
    padding: 6px 10px;
    font-size: 0.85em;
    border: none; border-radius: 4px; cursor: pointer;
    background-color: #007bff; color: white;
}
#action-buttons button:hover, #roll-dice-btn:hover { background-color: #0056b3; }
#action-buttons button:disabled, #roll-dice-btn:disabled { background-color: #ccc; cursor: not-allowed; }
#buy-property-btn { background-color: #28a745; }
#buy-property-btn:hover { background-color: #1e7e34; }
#end-turn-btn { background-color: #dc3545; }
#end-turn-btn:hover { background-color: #c82333; }
#trade-btn { background-color: #5bc0de; }
#trade-btn:hover { background-color: #31b0d5; }

/* Log Container */
#log-container {
    border: 1px solid #ddd; padding: 10px; border-radius: 4px;
    max-height: 180px;
    overflow-y: auto; background-color: #e9ecef;
}
#game-log div { padding: 2px 0; border-bottom: 1px dotted #ccc; font-size: 0.85em; }
#game-log div:last-child { border-bottom: none; }

/* Player Tokens and Buildings - Base Desktop Styles */
.player-token {
    width: 20px; height: 20px;
    border-radius: 50%;
    position: absolute;
    border: 1.5px solid black;
    box-sizing: border-box;
    transition: all 0.3s ease-in-out;
    z-index: 10;
    display: flex; justify-content: center; align-items: center;
    font-size: 10px; color: white; text-shadow: 0 0 1px black;
}
.buildings {
    position: absolute;
    top: 2px;
    left: 2px;
    display: flex;
    flex-wrap: wrap; /* Allow houses to wrap if many */
    gap: 2px;
}
.house-indicator { width: 10px; height: 10px; background-color: green; border: 1px solid darkgreen; }
.hotel-indicator { width: 13px; height: 13px; background-color: red; border: 1px solid darkred; }

/* Popup styles */
.popup {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.6); display: flex;
    justify-content: center; align-items: center; z-index: 1000;
    padding: 15px; /* Padding for small screens */
}
.popup-content {
    background-color: white; padding: 20px; border-radius: 8px;
    text-align: center; box-shadow: 0 0 15px rgba(0,0,0,0.2);
    min-width: 280px;
    max-width: 90vw;
    max-height: 90vh; /* Increased for trade popup */
    overflow-y: auto;
}
.popup-content h3 { margin-top: 0; color: #333; font-size: 1.2em; }
.popup-content p { margin-bottom: 10px; color: #555; font-size: 0.95em; }
.popup-content button {
    padding: 8px 12px; margin: 5px;
    font-size: 0.9em;
    border: none; border-radius: 4px; cursor: pointer;
}
#ai-popup-close, #decision-yes-btn, #submit-auction-bid-btn, #accept-trade-btn { background-color: #5cb85c; color: white; }
#ai-popup-close:hover, #decision-yes-btn:hover, #submit-auction-bid-btn:hover, #accept-trade-btn:hover { background-color: #4cae4c; }
#decision-no-btn, #pass-auction-bid-btn, #close-manage-properties-popup, #cancel-trade-btn, #reject-trade-btn { background-color: #f0ad4e; color: white; }
#decision-no-btn:hover, #pass-auction-bid-btn:hover, #close-manage-properties-popup:hover, #cancel-trade-btn:hover, #reject-trade-btn:hover { background-color: #ec971f; }
#auction-bid-amount { padding: 8px; border-radius: 4px; border: 1px solid #ddd; margin-right: 5px; width: 80px; }

/* Trade Popup Specific Styles */
#trade-popup .popup-content { min-width: 550px; } /* Wider for trade on larger screens */
#trade-interface {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
    margin-bottom: 15px;
}
.trade-player-section {
    border: 1px solid #ddd;
    padding: 10px;
    border-radius: 5px;
    width: 45%;
    background-color: #f9f9f9;
}
.trade-player-section h4 { margin-top: 0; margin-bottom: 10px; font-size: 1.1em; color: #337ab7; }
.trade-player-section label { display: block; margin-top: 8px; margin-bottom: 3px; font-weight: bold; font-size: 0.9em; }
.trade-player-section input[type="number"],
.trade-player-section select { width: 90%; padding: 6px; border-radius: 3px; border: 1px solid #ccc; margin-bottom: 5px; }
.trade-properties-list {
    max-height: 120px; overflow-y: auto; border: 1px solid #eee;
    padding: 5px; background-color: white; font-size: 0.85em;
}
.trade-properties-list label { font-weight: normal; display: block; margin-top: 0; font-size: 1em; }
.trade-properties-list input[type="checkbox"] { margin-right: 5px; vertical-align: middle; }
.trade-arrow { font-size: 2em; font-weight: bold; color: #555; align-self: center; }
#trade-summary { margin-top:15px; font-style: italic; font-size:0.9em; max-height: 60px; overflow-y:auto; text-align: left;}
#trade-response-summary { text-align: left; margin-bottom:15px; padding:10px; border: 1px solid #eee; background-color:#f9f9f9; max-height: 200px; overflow-y:auto; }
#trade-response-summary ul { list-style-type: none; padding-left: 0; }
#trade-response-summary ul li { margin-bottom: 5px; }
#trade-response-summary .giving { color: #c9302c; font-weight:bold; }
#trade-response-summary .receiving { color: #449d44; font-weight:bold; }

/* Manage Properties Popup */
#manage-properties-popup .popup-content { min-width: 400px; }
#owned-properties-list { max-height: 300px; overflow-y: auto; text-align: left; }
#owned-properties-list h5 { margin-top: 10px; border-bottom: 1px solid #ccc; padding-bottom: 3px; font-size: 1em; color: #337ab7; }
#owned-properties-list div { padding: 5px 0; border-bottom: 1px dotted #eee; overflow: hidden; }
#owned-properties-list div:last-child { border-bottom: none; }
#owned-properties-list button { font-size: 0.8em; padding: 3px 6px; margin-left: 5px; }


/* --- Responsive Adjustments --- */

/* For tablets and smaller desktops (board and info panel stack) */
@media (max-width: 1100px) {
    #main-content {
        flex-direction: column;
        align-items: center;
    }
    #board-container {
        width: 100%; /* Takes full width of its column when stacked */
        max-width: 720px; /* But not larger than its original design */
        height: auto; /* Height adjusts to maintain aspect ratio */
        aspect-ratio: 1 / 1; /* Keep it square */
        margin-bottom: 20px;
    }
    #game-info-panel {
        width: 100%;
        max-width: 720px; /* Match board width when stacked */
        min-width: unset;
    }
    #trade-popup .popup-content { min-width: 80vw; } /* Make trade popup wider on tablets */
}

/* For mobile phones - Significant board and font adjustments */
@media (max-width: 750px) {
    body { padding-top: 10px; }
    #game-screen { padding: 10px; }

    /* CSS Variables for responsive grid cells */
    :root { /* Define on root for wider access if needed, or scope to #board-container */
        --corner-cell-mobile: 40px;
        --prop-cell-mobile: 28px;
    }

    #board-container {
        width: 95vw; /* Make board responsive to viewport width */
        height: 95vw; /* Keep it square */
        max-width: 400px; /* Cap responsive width */
        max-height: 400px;/* Cap responsive height */
        margin-left: auto;
        margin-right: auto;

        grid-template-columns: var(--corner-cell-mobile) repeat(9, var(--prop-cell-mobile)) var(--corner-cell-mobile);
        grid-template-rows: var(--corner-cell-mobile) repeat(9, var(--prop-cell-mobile)) var(--corner-cell-mobile);
    }

    #center-logo {
        font-size: clamp(1em, 5vw, 1.8em); /* Responsive font */
    }

    .square {
        font-size: clamp(6px, 1.8vw, 7px); /* Responsive font for square text */
        padding: 0; /* Maximize space for text */
    }
    .square .name {
        line-height: 1.0; /* Tighter line height */
        margin-top: 0;
        word-break: break-word; /* Break long words */
        hyphens: auto;
    }
    .square .price {
        font-size: 0.8em; /* Relative to new .square font-size */
        margin-bottom: 1px;
    }

    .corner {
        font-size: clamp(7px, 2vw, 8px); /* Responsive font for corners */
        padding: 1px; /* Minimal padding */
    }
    .property-color-band {
        height: clamp(6px, 1.8vw, 8px); /* Responsive height */
    }

    .player-token {
        width: clamp(10px, 2.8vw, 12px); /* Responsive token size */
        height: clamp(10px, 2.8vw, 12px);
        font-size: clamp(6px, 1.5vw, 7px); /* Text on token */
        border-width: 1px;
    }
    .house-indicator {
        width: clamp(3px, 0.8vw, 4px);
        height: clamp(3px, 0.8vw, 4px);
    }
    .hotel-indicator {
        width: clamp(5px, 1.1vw, 6px);
        height: clamp(5px, 1.1vw, 6px);
    }

    /* Info panel and controls adjustments for mobile */
    #game-info-panel {
        font-size: 0.9em;
    }
    #player-info-container .player-info {
        font-size: 0.85em;
        padding: 6px;
    }
    #controls-container h2 { font-size: 1em; }
    #dice-display .die { width: 20px; height: 20px; line-height: 20px;}
    #action-buttons button, #roll-dice-btn { padding: 5px 8px; font-size: 0.8em; }
    #log-container { max-height: 150px; }

    /* Popups on mobile */
    .popup-content { padding: 15px; max-width: 95vw; } /* Ensure popups fit */
    .popup-content h3 {font-size: 1.1em;}
    .popup-content p {font-size: 0.9em;}
    #trade-popup .popup-content { min-width: 90vw; } /* Trade popup takes more width */
    #trade-interface { flex-direction: column; align-items: stretch; }
    .trade-player-section { width: 100%; }
    .trade-arrow { text-align: center; transform: rotate(90deg); margin: 10px 0; }
}

/* Very small phones - further fine-tuning */
@media (max-width: 400px) {
    :root { /* Override CSS Variables for even smaller grid */
        --corner-cell-mobile: 35px;
        --prop-cell-mobile: 24px; /* Approx (320 - 70) / 9 = 27.7, use 24 for margins */
    }
    #board-container { /* Board container may become slightly smaller than 95vw due to cell sizes */
        /* Recalculate width based on new cell sizes if fixed: 35 + 9*24 + 35 = 35+216+35 = 286px */
        /* If board-container is 95vw of 320px screen (=304px), the above cell sizes fit. */
        max-width: 304px; /* Max width based on cell sizes */
        max-height: 304px;
    }

    #center-logo { font-size: clamp(0.8em, 4vw, 1.5em); }
    .square { font-size: clamp(5px, 1.5vw, 6px); }
    .square .name { white-space: normal; } /* Allow name to wrap fully */
    .corner { font-size: clamp(6px, 1.8vw, 7px); }
    .player-token {
        width: clamp(8px, 2.5vw, 10px);
        height: clamp(8px, 2.5vw, 10px);
        font-size: clamp(5px, 1.2vw, 6px);
    }

    /* Info panel buttons stack on very small screens */
    #action-buttons button, #roll-dice-btn {
        display: block;
        width: 100%;
        margin-top: 5px;
    }
    #trade-popup .popup-content, #manage-properties-popup .popup-content {
        padding: 10px;
    }
    .trade-properties-list { max-height: 80px; }
}