/* --- [NEW] Palace Square Style --- */
.square.palace-square {
    /* A color between the normal square and sanctuary */
    background-color: #f2c96c !important;
}
/* --- [END NEW] --- */

/* You can place this rule anywhere, for example, after the .sanctuary-square rule */

/* ... (rest of your existing CSS) ... */

:root {
    /* Define a variable for square size. On desktop, it's based on viewport height. */
    --square-size: min(4.5vh, 40px);
    /* [NEW] Size for the notation markers */
    --notation-size: calc(var(--square-size) * 0.75);
}

body {
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    /* [REMOVED] background-color: #333; */
    color: #eee;
    margin: 0;
    padding: 10px;
    box-sizing: border-box;
    min-height: 100vh;

    /* --- [NEW] --- */
    /* Set the background image on the html/body */
    background-image: url('sprites/lobby_background.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    /* Ensures the background stays fixed during scroll */
    background-attachment: fixed;
    /* Required for the overlay */
    position: relative;
}

/* --- [NEW] --- */
/* This creates a dark, semi-transparent overlay
   that sits *behind* your content but *on top*
   of the background image, ensuring text is readable. */
body::before {
    content: "";
    position: fixed; /* Covers the whole screen */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Maybe try a lighter tint, like 0.5 or 0.4 if needed */
    background-color: rgba(0, 0, 0, 0.6);
    z-index: -1; /* Puts it behind all your content */
}


#game-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
}

#board-container {
    /* [MODIFIED] Changed to a grid to hold notation markers */
    display: grid;
    grid-template-columns: var(--notation-size) calc(var(--square-size) * 10) var(--notation-size);
    grid-template-rows: var(--notation-size) calc(var(--square-size) * 16) var(--notation-size);
    border: 5px solid #4a2a00;
}

#game-board {
    display: grid;
    /* Use the CSS variable to set the size dynamically */
    grid-template-columns: repeat(10, var(--square-size));
    grid-template-rows: repeat(16, var(--square-size));
    width: calc(var(--square-size) * 10);
    height: calc(var(--square-size) * 16);
    /* [MODIFIED] Position in the new grid */
    grid-column: 2;
    grid-row: 2;
    /* * [CHANGE 1]
     * Set the main, solid board color. A traditional shogi board is a lighter wood color.
     */
    background-color: #d6b36b; /* A light, wood-like color */

    /* --- [NEW] ---
       Required for positioning the animated clone on top.
    */
    position: relative;
}

.square {
    width: var(--square-size);
    height: var(--square-size);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    /* * [CHANGE 2]
     * Apply a border to all four sides to create the grid outline.
     * This border will appear *inside* the main #game-board color due to the grid layout.
     */
    border: 1px solid #4a2a00; /* Darker brown for the grid lines */
    box-sizing: border-box; /* Ensures the border is included in the square's dimensions */
    /* * [CHANGE 3]
     * Set a uniform background for all squares.
     * This will match the main board color from #game-board, making the border the visual separator.
     */
    background-color: #f9d892;
}

/* * [CHANGE 4]
 * REMOVE the checkerboard pattern (light/dark) styles
 */
/* .square.light { background-color: #f0d9b5; } */
/* .square.dark { background-color: #b58863; } */

.square.invalid {
    /* The invalid corners can still have a distinct background if needed */
    background-color: #555;
    border-color: #555; /* Hide the grid line on invalid squares */
}
.sanctuary-square {
    /* Still apply a distinct background for sanctuary squares */
    background-color: #e5b045 !important; /* A slightly darker golden yellow */
}

/* --- [NEW] Palace Square Style --- */
.square.palace-square {
    /* A color between the normal square and sanctuary */
    background-color: #f2c96c !important;
}
/* --- [END NEW] --- */


.piece {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.piece img {
    width: 90%;
    height: 90%;
    object-fit: contain;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* --- [NEW] ---
   Styles for the animated "clone" piece.
*/
.flying-piece {
    position: absolute;
    z-index: 1001; /* Must be on top of other pieces */
    pointer-events: none; /* So it doesn't block clicks */
    transition: all 0.25s ease-out; /* Animation speed */
}

/* For drops, we fade in instead of flying */
.flying-piece.drop {
    opacity: 0;
    transition: opacity 0.25s ease-out;
}
/* --- [END NEW] --- */


#create-game-btn,
#single-player-btn,
#play-bot-btn {
    /* Use the same sizing properties as the original #create-game-btn */
    padding: 10px 20px;
    font-size: 16px;
    /* Optional: Ensure they all have the same width for uniformity */
    min-width: 200px; /* Adjust this value as needed */
    box-sizing: border-box; /* Necessary if you set a width */
    margin: 5px 0; /* Add a bit of vertical spacing between the buttons */
}

/* Selection and Move Highlights */
/* NOTE: The !important is often needed to override the single square background from .square. */
.square.selected {
    background-color: #6a9cff !important;
}

.square.preview-selected {
    background-color: rgba(150, 150, 150, 0.5) !important;
}

/* --- [NEW] Last Move Highlighting --- */
.square.last-move-from {
    background-color: rgba(255, 255, 0, 0.3) !important;
}
.square.last-move-to {
    background-color: rgba(255, 255, 0, 0.6) !important;
}
/* --- [END NEW] --- */


.move-plate {
    position: absolute;
    width: 70%;
    height: 70%;
    border-radius: 50%;
    background-color: rgba(4, 255, 0, 0.4);
    pointer-events: all;
    cursor: pointer;
}

.move-plate.attack {
    background-color: rgba(255, 20, 20, 0.5);
}

.move-plate.drop {
    background-color: rgba(255, 242, 0, 0.4);
}

.move-plate.preview {
    background-color: rgba(128, 128, 128, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.4);
}

.move-plate.preview.attack {
    background-color: rgba(80, 80, 80, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.4);
}

/* Captured Pieces Area */
.captured-area {
    width: calc(var(--square-size) * 4); /* Adjust width relative to square size */
    text-align: center;
    display: flex;
    flex-direction: column;
}

.captured-pieces-box {
    background-color: #4a4a4a;
    border: 2px solid #888;
    min-height: calc(var(--square-size) * 5);
    padding: 5px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-content: flex-start;
    flex-grow: 1;
}

.captured-piece {
    width: var(--square-size);
    height: var(--square-size);
    border: 1px solid #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.captured-piece.white { background-color: #f0d9b5; }
.captured-piece.black { background-color: #b58863; }

/* Turn Indicator & Winner Text */
/* Style for the container holding turn/winner text */
#turn-indicator-container {
    background-color: rgba(30, 30, 30, 0.8); /* Dark semi-transparent */
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #777;
    margin-top: 20px;
    text-align: center;
    /* Limit width so it doesn't look too wide */
    max-width: 500px;
    /* Center the box itself */
    margin-left: auto;
    margin-right: auto;
}

/* Ensure winner text doesn't have extra top margin */
#turn-indicator-container p#winner-text {
    margin-top: 5px;
    font-size: 1.5em; /* Moved from #winner-text */
    color: #4CAF50;    /* Moved from #winner-text */
    font-weight: bold; /* Moved from #winner-text */
}

/* Lobby Styles */
#lobby {
    background-color: #444;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 20px;
}



#game-list {
    max-height: 200px;
    overflow-y: auto;
}

.game-item {
    background-color: #555;
    padding: 10px;
    margin: 5px 0;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.join-btn {
    padding: 5px 10px;
    cursor: pointer;
}

/* ----- NEW STYLES ----- */

#time-controls {
    margin-bottom: 20px;
    padding: 15px;
    border: 1px solid #666;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    gap: 25px;
    flex-wrap: wrap;
}
#time-controls div {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}
#time-controls label {
    font-weight: bold;
}
#time-controls select {
    padding: 5px;
    background-color: #555;
    color: #eee;
    border: 1px solid #777;
}

/* Timer Display Styling in Game */
/* Style specifically for the hand label text within the captured area */
.captured-area h3 {
    background-color: rgba(30, 30, 30, 0.8); /* Dark semi-transparent */
    padding: 5px 10px;
    border-radius: 5px;
    border: 1px solid #666;
    margin-bottom: 10px; /* Space between label and captured box */
    /* Prevent the box from stretching full width of the area */
    display: inline-block;
    font-weight: normal;
}
/* Adjust timer alignment slightly now that h3 has padding */
#white-time, #black-time {
    vertical-align: middle; /* Helps align with text */
    margin-left: 5px; /* Add a little space */
    font-size: 1.2em;
    font-weight: bold;
    font-family: 'Courier New', Courier, monospace;
    background-color: #222;
    color: #ddd;
    padding: 3px 8px;
    border-radius: 5px;
    border: 2px solid #555;
    transition: background-color 0.3s, border-color 0.3s;
}

#white-time.active, #black-time.active {
    background-color: #4a2a00;
    color: #fff;
    border-color: #ff9800;
}

/* --- Board Notation Styles --- */
.notation-files {
    grid-column: 2;
    display: flex;
    background-color: #d6b36b; /* Match board color */
}
.notation-files-top { grid-row: 1; }
.notation-files-bottom { grid-row: 3; }

.notation-ranks {
    grid-row: 2;
    display: flex;
    flex-direction: column;
    background-color: #d6b36b; /* Match board color */
}
.notation-ranks-left { grid-column: 1; }
.notation-ranks-right { grid-column: 3; }

.notation-files > div {
    width: var(--square-size);
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: calc(var(--notation-size) * 0.7);
    color: #4a2a00;
    font-weight: bold;
    box-sizing: border-box;
}
.notation-ranks > div {
    width: 100%;
    height: var(--square-size);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: calc(var(--notation-size) * 0.7);
    color: #4a2a00;
    font-weight: bold;
    box-sizing: border-box;
}

/* --- Move History Styles --- */
#move-history-container {
    width: 200px;
    height: calc(var(--square-size) * 16 + var(--notation-size) * 2); /* Match board height + notation */
    display: flex;
    flex-direction: column;
    background-color: #444;
    border: 2px solid #888;
    border-radius: 5px;
    box-sizing: border-box;
}
#move-history-container h3 {
    text-align: center;
    margin: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid #777;
}
#move-history {
    flex-grow: 1;
    overflow-y: auto;
    padding: 5px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}
#move-history div {
    padding: 2px 5px;
    border-radius: 3px;
}
#move-history div:nth-child(even) {
    background-color: #3a3a3a;
}

/* Main Title Style */
h1 {
    background-color: rgba(30, 30, 30, 0.8); /* Dark semi-transparent */
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid #777;
    display: inline-block; /* Prevent stretching full width */
    margin-bottom: 20px; /* Add some space below */
}


/* =================================== */
/* == MOBILE RESPONSIVE STYLES HERE == */
/* =================================== */
@media (orientation: portrait) {
    :root {
        /* On mobile, base the square size on the screen width */
        --square-size: 9vw;
        /* [MODIFIED] Re-declare notation size for mobile */
        --notation-size: calc(var(--square-size) * 0.75);
    }

    body {
        justify-content: flex-start; /* Align content to the top */
    }

    #game-container {
        /* Change to a vertical layout */
        flex-direction: column;
        align-items: center; /* Center the items vertically */
        gap: 10px;
    }

    /* Use CSS order property to rearrange elements for mobile */
    #black-captured-area { order: 1; }
    #board-container { order: 2; }
    #white-captured-area { order: 3; }
    #move-history-container { order: 4; } /* [NEW] */

    .captured-area {
        /* Make the captured area wider on mobile */
        width: 90vw;
    }

    /* [NEW] Resize move history for mobile */
    #move-history-container {
        width: 90vw;
        height: 150px; /* Fixed height for mobile */
    }

    /* [MODIFIED] Re-declare grid for mobile var size */
    #board-container {
        grid-template-columns: var(--notation-size) calc(var(--square-size) * 10) var(--notation-size);
        grid-template-rows: var(--notation-size) calc(var(--square-size) * 16) var(--notation-size);
    }

    .captured-pieces-box {
        /* Let the box grow as needed and align pieces in a row */
        min-height: auto;
        flex-wrap: nowrap; /* Don't wrap pieces to the next line */
        overflow-x: auto; /* Allow horizontal scrolling if many pieces */
        justify-content: flex-start;
    }

    .timer {
        margin-top: 0;
        margin-bottom: 5px; /* Add space below timer on mobile */
        font-size: 1.5em;
        padding: 5px;
    }
}

/* =================================== */
/* ==     RULES MODAL STYLES      == */
/* =================================== */

#rules-btn {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
    width: 90%;
    max-width: 250px;
}

.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1000; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.6); /* Black w/ opacity */
}

.modal-content {
    background-color: #2c2c2c;
    margin: 5% auto; /* 5% from the top and centered */
    padding: 25px;
    border: 1px solid #888;
    width: 90%;
    max-width: 800px;
    border-radius: 10px;
    position: relative;
    color: #eee;
    max-height: 85vh; /* Max height is 85% of the viewport height */
    overflow-y: auto; /* Enable vertical scrolling */
}

.close-btn {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-btn:hover,
.close-btn:focus {
    color: #fff;
    text-decoration: none;
}

#rules-body h2 {
    color: #ffc107;
    border-bottom: 2px solid #ffc107;
    padding-bottom: 5px;
}

#rules-body h3 {
    color: #4CAF50;
    margin-top: 20px;
}

#rules-body p, #rules-body li {
    line-height: 1.6;
}

.piece-list {
    margin-top: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.piece-entry {
    background-color: #444;
    padding: 15px;
    border-radius: 5px;
    border-left: 5px solid #666;
}

.piece-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2em;
    font-weight: bold;
}

.piece-header img {
    width: 40px;
    height: 40px;
}

#game-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
}

#main-menu-btn,
#rules-btn-ingame {
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    border-radius: 5px;
    border: none;
    background-color: #555;
    color: #eee;
    border: 1px solid #777;
}

#main-menu-btn:hover,
#rules-btn-ingame:hover {
    background-color: #666;
}

#main-menu-btn {
    background-color: #a13a3a; /* A reddish color to signify leaving */
}

#main-menu-btn:hover {
    background-color: #c04848;
}