body {
    font-family: 'Arial', sans-serif;
    background-color: #f4f4f9;
    color: #333;
    margin: 0; /* Ensure no unexpected margins cause shifts */
    padding: 0; /* Ensure no unexpected padding causes shifts */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

header {
    width: 100%; /* Ensure header spans full width */
    height: 60px; /* Reduced height for a slimmer header */
    padding: 10px 20px; /* Adjusted padding for balanced spacing */
    background-color: #333; /* Consistent background color */
    display: flex;
    align-items: center;
    justify-content: space-between; /* Space between title and any header elements */
    box-sizing: border-box;
    font-size: 24px; /* Adjust font size as needed */
}

nav {
    width: 100%; /* Make nav span full width below the header */
    background-color: #444; /* Background color for navigation bar */
    padding: 10px 0; /* Vertical padding */
    text-align: center;
    box-sizing: border-box;
    margin-top: 0; /* Remove top margin to align correctly below header */
}

nav ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: inline-flex;
}

nav ul li {
    margin: 0 15px; /* Spacing between navigation items */
}

nav ul li a {
    color: #fff;
    text-decoration: none;
    font-size: 18px; /* Increased font size for better visibility */
    cursor: pointer;
}

nav ul li a:hover {
    color: #ffd700; /* Optional: Change color on hover */
}

/* Removed empty ruleset */
header nav ul li a:hover {
    /* ...existing styles if any... */
    color: #fff; /* Ensure title is visible */
}

main {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    width: 100%;
    text-align: center;
}

#chessboard-container {
    position: relative; /* Ensure labels can be placed absolutely */
    /* Allow board to scale while maintaining a square shape */
    width: 100%;
    max-width: 600px; /* Adjust as desired */
    aspect-ratio: 1 / 1; /* Keeps the board square */
    margin: 0 auto; /* Center horizontally */
    border-width: var(--board-border-width);
    border-style: solid;
    border-color: var(--board-border-color);
    box-sizing: border-box;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1px;
    /* Remove the fixed height */
    /* height: 600px; */
}

#chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%; /* Fill the container */
    height: 100%; /* Fill the container */
    box-sizing: border-box;
    transition: transform 0.3s ease; /* Smooth scaling if needed */
    position: absolute;
    top: -1px;
    left: -1px;
    border: none; /* Remove the inner border */
}

#row-labels-left {
    position: absolute;
    left: -2.5em; /* Move numbers further left */
    top: 0;
    height: 100%; /* Match the board’s height */
    display: grid;
    grid-template-rows: repeat(8, 1fr);
    align-items: center;
    justify-items: end;
    pointer-events: none; /* Prevent interfering with clicks on the board */
    width: 2em; /* Set a fixed width for labels */
    text-align: center;
    font-size: 18px;
    line-height: 50px; /* Match the tile size */
}

#col-labels {
    position: absolute;
    bottom: -1.5em; /* Bring letters up */
    left: 0;
    width: 100%; /* Match the board’s width */
    display: grid; /* Use grid for horizontal alignment */
    grid-template-columns: repeat(8, 1fr); /* Each column is 50px wide */
    align-items: center;
    justify-items: center;
    height: 2em;
    text-align: center;
    font-size: 18px;
    line-height: 20px;
    pointer-events: none;
}

#hint-container {
    text-align: center;
    margin-top: 10px; /* Small gap between the button and the board */
}

button {
    background-color: #333;
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    border-radius: 4px;
    margin: 5px;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #555;
}

:root {
    --white-tile-color: #f0d9b5;
    --black-tile-color: #b58863;
    --white-piece-color: #ffffff;
    --black-piece-color: #000000;
    --potential-move-color: #ad81fe53; /* Default soft yellow */
    --board-border-width: 3px;
    --board-border-color: #333333;
}

.white-tile {
    background-color: var(--white-tile-color);
    width: 100%;
    height: 100%;
    box-sizing: border-box; /* Ensure padding and border are included in the element's total width and height */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px; /* Fixed width */
    height: 60px; /* Fixed height to maintain aspect ratio */
    position: relative; /* For positioning pieces */
}

.black-tile {
    background-color: var(--black-tile-color);
    width: 100%;
    height: 100%;
    box-sizing: border-box; /* Ensure padding and border are included in the element's total width and height */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px; /* Fixed width */
    height: 60px; /* Fixed height to maintain aspect ratio */
    position: relative; /* For positioning pieces */
}

.white-piece {
    color: var(--white-piece-color);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: top 0.3s ease, left 0.3s ease; /* Smooth movement */
}

.black-piece {
    color: var(--black-piece-color);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: top 0.3s ease, left 0.3s ease; /* Smooth movement */
}

.white-piece,
.black-piece {
    font-size: clamp(1rem, 4vw, 3rem); /* Scale the font based on viewport size, with min/max bounds */
    line-height: 1;
    max-width: 80%; /* Keep piece width/height within tile bounds */
    max-height: 80%;
    margin: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; /* Black outline */
    cursor: grab; /* Show grab cursor */
}

.white-piece:active,
.black-piece:active {
    cursor: grabbing; /* Show grabbing cursor when dragging */
}

/* Remove piece highlight */
.white-piece.selected,
.black-piece.selected {
    box-shadow: none;
    border: none;
}

/* Ensure tile is highlighted instead */
.white-tile.selected,
.black-tile.selected {
    position: relative;
    z-index: 10;
}

.white-tile.selected::after,
.black-tile.selected::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 2px solid red;
    box-sizing: border-box;
    pointer-events: none;
}

.white-tile:focus,
.black-tile:focus {
    outline: none; /* Remove focus outline */
}

.hint-from {
    border: 4px solid blue; /* Increased border width */
}

.hint-to {
    border: 4px solid green; /* Increased border width */
}

.potential-move {
    background-color: var(--potential-move-color, rgba(255, 255, 0, 0.1)); /* Softer yellow highlight */
    border: 1px solid rgba(255, 255, 0, 0.5); /* Soft yellow border */
}

/* Optional: Highlight squares involved in castling */
.castling-square {
    background-color: rgba(0, 255, 0, 0.3); /* Light green to indicate castling paths */
    border: 1px dashed rgba(0, 128, 0, 0.7); /* Green dashed border */
}

#game-over-modal {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
    justify-content: center;
    align-items: center;
    z-index: 1000; /* Ensure it is above other elements */
}

#game-over-content {
    background-color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
}

#game-over-message {
    font-size: 24px;
    margin-bottom: 20px;
}

#restart-button {
    padding: 10px 20px;
    font-size: 18px;
    cursor: pointer;
    background-color: #333;
    color: #fff;
    border: none;
    border-radius: 4px;
    transition: background-color 0.3s;
}


#restart-button:hover {
    background-color: #555;
}

.king-in-check {
    background-color: rgba(255, 0, 0, 0.4) !important;
    animation: check-pulse 1s infinite;
}

@keyframes check-pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(255, 0, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0); }
}

#settings-container {
        margin-top: 20px;
        text-align: left;
        display: none; /* Hidden by default */
}

#settings-container h2 {
    font-size: 20px;
    margin-bottom: 10px;
}

#settings-container div {
    margin-bottom: 10px;
}

#settings-container label {
    margin-right: 10px;
}

#settings-container input[type="color"] {
    border: none;
    padding: 5px;
    cursor: pointer;
}

#apply-settings {
    background-color: #333;
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    border-radius: 4px;
    margin-top: 10px;
    transition: background-color 0.3s;
}

#apply-settings:hover {
    background-color: #555;
}

.hidden {
    display: none;
}

#settings-overlay {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
    justify-content: center;
    align-items: center;
    z-index: 1000; /* Ensure it is above other elements */
}

#settings-content {
    background-color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
}

#settings-content h2 {
    font-size: 20px;
    margin-bottom: 10px;
}

#settings-content div {
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

#settings-content label {
    margin-right: 10px;
}

#settings-content input[type="color"] {
    border: none;
    padding: 5px;
    cursor: pointer;
}

#apply-settings,
#save-preset,
#close-settings {
    background-color: #333;
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    border-radius: 4px;
    margin-top: 10px;
    transition: background-color 0.3s;
}

#apply-settings:hover,
#save-preset:hover,
#close-settings:hover {
    background-color: #555;
}

#preset-select {
    padding: 5px;
    margin-right: 5px;
    min-width: 150px;
}

#preset-name {
    padding: 5px;
    margin-right: 5px;
    width: 150px;
}

#load-preset,
#delete-preset {
    padding: 5px 10px;
    font-size: 14px;
}

#move-history-container {
    max-height: 150px; /* Limit the height */
    overflow-y: auto; /* Enable vertical scrolling */
    margin-top: 30px; /* Increased space above move history */
    border: 1px solid #ccc; /* Add a border for better visibility */
    padding: 10px; /* Add some padding */
    border-radius: 4px; /* Add rounded corners */
}

#move-history {
    list-style: none;
    padding: 0;
    margin: 0;
}

#move-history li {
    margin-bottom: 5px;
}

#history-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#history-content {
    background-color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    max-width: 1000px;
    width: 90%;
}

.history-layout {
    display: flex;
    gap: 20px;
    margin: 20px 0;
}

.history-controls {
    flex: 1;
    text-align: left;
}

.history-board {
    flex: 2;
    display: none; /* Hide by default */
    padding: 20px; /* Add some padding around the board */
    background-color: #f5f5f5; /* Light background to distinguish the board area */
    border-radius: 8px;
}

#replay-board-container {
    position: relative;
    width: 400px; /* Reduced from 404px to match board size */
    height: 400px; /* Reduced from 404px to match board size */
    margin: 0 auto;
    border: 2px solid #333;
    background-color: #fff;
}

#replay-board {
    width: 400px;
    height: 400px;
    display: grid;
    grid-template-columns: repeat(8, 50px); /* Explicit column sizes */
    grid-template-rows: repeat(8, 50px); /* Explicit row sizes */
    position: absolute;
    top: -1px; /* Adjust for border */
    left: -1px; /* Adjust for border */
    border: 1px solid #333;
}

#replay-board .white-piece,
#replay-board .black-piece {
    font-size: 36px;
    text-align: center;
    line-height: 50px;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: default;
}

#replay-board .white-tile,
#replay-board .black-tile {
    width: 50px;
    height: 50px;
    box-sizing: border-box;
    border: none;
}

#replay-row-labels {
    position: absolute;
    left: -25px; /* Adjusted position */
    top: -1px; /* Align with board */
    display: grid;
    grid-template-rows: repeat(8, 50px); /* Match tile size */
    height: 400px;
    width: 20px;
    text-align: right;
    font-size: 14px;
    padding-right: 5px;
}

#replay-col-labels {
    position: absolute;
    bottom: -25px; /* Adjusted position */
    left: -1px; /* Align with board */
    display: grid;
    grid-template-columns: repeat(8, 50px); /* Match tile size */
    width: 400px;
    height: 20px;
    text-align: center;
    font-size: 14px;
}

#replay-move-list {
    margin-top: 20px;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #ccc;
    padding: 10px;
    background-color: #fff;
}

.replay-move {
    padding: 8px;
    margin: 2px 0;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.replay-move:hover {
    background-color: #f0f0f0;
}

.replay-move.current {
    background-color: #ffeb3b;
    font-weight: bold;
}

#game-select {
    padding: 5px;
    margin-right: 5px;
    min-width: 200px;
}

#replay-controls {
    margin-top: 15px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

#replay-controls button {
    padding: 5px 10px;
    font-size: 14px;
}

.white-turn .white-piece {
    text-shadow: 0 0 4px #ff8080b3;
    margin-top: 2px; /* Add some space for the turn indicator */
}

.black-turn .black-piece {
    text-shadow: 0 0 4px #ff8080b3;
    margin-top: 2px; /* Add some space for the turn indicator */
}

/* Styles for Game History Page */
/* Styles for Game History Page */
#game-history-container {
    padding: 20px;
}

#game-history-list {
    list-style-type: none;
    padding: 0;
}

#game-history-list li {
    padding: 10px;
    border-bottom: 1px solid #ccc;
}

#clear-history {
    margin-top: 20px;
    padding: 10px 20px;
    background-color: #f44336;
    color: white;
    border: none;
    cursor: pointer;
}

#clear-history:hover {
    background-color: #d32f2f;
}

#game-history-container {
    padding: 20px;
}

#game-history-list {
    list-style-type: none;
    padding: 0;
}

#game-history-list li {
    padding: 10px;
    border-bottom: 1px solid #ccc;
}

#clear-history {
    margin-top: 20px;
    padding: 10px 20px;
    background-color: #f44336;
    color: white;
    border: none;
    cursor: pointer;
}

#clear-history:hover {
    background-color: #d32f2f;
}

/* Styles for Game Selection */
#game-selection {
    margin: 20px 0;
}

#game-selection label {
    font-weight: bold;
    margin-right: 10px;
}

#select-game {
    padding: 5px;
    font-size: 16px;
}

/* Styles for Game Details */
#game-details {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 20px;
}

#move-list-container, #simulated-board-container {
    flex: 1 1 300px;
    background-color: #f9f9f9;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#move-list-container h2, #simulated-board-container h2 {
    margin-bottom: 10px;
}

#move-list {
    list-style-type: decimal;
    padding-left: 20px;
}

#simulated-chessboard {
    width: 400px;
    height: 400px;
    aspect-ratio: 1 / 1;
    margin-bottom: 10px;
    border: 2px solid #333;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    background-color: #fff;
}

#start-simulation, #reset-simulation {
    padding: 10px 15px;
    margin-right: 10px;
    font-size: 16px;
    cursor: pointer;
    border: none;
    border-radius: 4px;
    background-color: #4CAF50;
    color: white;
}

#reset-simulation {
    background-color: #f44336;
}

#start-simulation:hover {
    background-color: #45a049;
}

#reset-simulation:hover {
    background-color: #d32f2f;
}

/* Simulated Chessboard Tiles */
#simulated-chessboard .white-tile, #simulated-chessboard .black-tile {
    width: 100%;
    height: 100%;
}

#simulated-chessboard .white-piece, #simulated-chessboard .black-piece {
    font-size: clamp(1rem, 4vw, 3rem);
    line-height: 1;
    max-width: 80%;
    max-height: 80%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Highlight squares in the simulation */
.move-from {
    background-color: rgba(255, 255, 0, 0.3) !important;
    border: 2px solid #ffd700 !important;
}

.move-to {
    background-color: rgba(0, 255, 0, 0.3) !important;
    border: 2px solid #32cd32 !important;
}

#move-list {
    font-family: monospace;
    font-size: 14px;
    line-height: 1.5;
}

#move-list li {
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.3s;
}

#move-list li.current-move {
    background-color: #fff3cd;
    font-weight: bold;
}

/* Add styles for move list */
#move-list li.checkmate {
    background-color: #ffe6e6;
    font-weight: bold;
    padding: 6px 10px;
    border-radius: 4px;
    margin: 4px 0;
    border-left: 3px solid red;
}

/* Enhance the checkmate move display */
#move-list li.checkmate::after {
    content: " ♔";
    color: red;
}

/* Add styles for the navigation controls */
.simulation-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
}

.simulation-controls button {
    padding: 8px 15px;
    font-size: 14px;
    cursor: pointer;
    border: none;
    border-radius: 4px;
    background-color: #4CAF50;
    color: white;
    transition: opacity 0.3s;
}

.simulation-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#prev-move, #next-move {
    background-color: #2196F3;
}

#reset-simulation {
    background-color: #f44336;
}

#simulated-board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

#turn {
    margin-top: 40px; /* Add more space above the turn indicator */
    font-size: 18px;
    color: #333;
}

#message {
    margin-top: 10px; /* Space between turn indicator and message */
    margin-bottom: 20px; /* Space below message */
    min-height: 24px; /* Maintain consistent height even when empty */
    color: #d32f2f; /* Red color for error messages */
    font-weight: bold;
}
