* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%; /* Ensure body takes full height */
    overflow: hidden; /* Prevent scrollbars on body */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1a1a1a;
    color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px; /* Add some padding around the container */
}

.game-container {
    width: 100%;
    height: 100%;
    max-width: 1200px; /* Max width for large screens */
    max-height: 95vh; /* Limit height */
    background-color: #2c2c2c;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.7);
    padding: 15px;
    display: flex;
    flex-direction: column; /* Stack header and game-area */
    overflow: hidden; /* Prevent internal overflow */
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 2px solid #444;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.header h1 {
    color: #e0e0e0;
    text-shadow: 1px 1px 2px #000;
}

.turn-indicator {
    font-size: 1.2em;
    font-weight: bold;
}

#turn-indicator.light-turn { /* Renamed */
    color: #ffffff; /* White for Light */
    text-shadow: 0 0 5px #eee;
}

#turn-indicator.dark-turn { /* Renamed */
    color: #ff4500; /* Orange-red for Dark */
    text-shadow: 0 0 5px #cc0000;
}

.game-area {
    display: flex;
    gap: 15px;
    flex-grow: 1; /* Allow game area to fill remaining space */
    overflow: hidden; /* Prevent overflow within game area */
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

.board-container {
    flex-basis: 60%; /* Suggest initial size */
    flex-grow: 1; /* Allow growing */
    position: relative;
    aspect-ratio: 1 / 1; /* Maintain square aspect ratio */
    max-width: calc(95vh - 100px); /* Limit size based on viewport height minus header/padding */
    max-height: calc(100% - 10px); /* Ensure it fits vertically */
    min-width: 280px; /* Minimum size */
    background-color: #3a3a3a;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid #111;
    margin: auto; /* Center if space allows */
}

#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none; /* Allow clicks to pass through to the board */
}

#chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
    transition: transform 0.5s ease-in-out; /* Add transition for rotation */
}

/* Class to rotate the board */
#chess-board.board-rotated {
    transform: rotate(180deg);
}

.board-cell {
    position: relative;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5em, 4vw, 2.5em); /* Responsive font size for pieces */
    user-select: none;
}

.cell-light {
    background-color: #b5b5b5; /* Lighter grey */
}

.cell-dark {
    background-color: #6a6a6a; /* Darker grey */
}

.cell-selected {
    outline: 3px solid #4a90e2;
    outline-offset: -3px;
}

/* Add prominent check indicator - pulsing effect for better visibility */
.king-in-check {
    animation: check-pulse 1.5s infinite;
    box-shadow: 0 0 15px 5px rgba(255, 0, 0, 0.7);
    border-radius: 50%;
    position: relative;
}

/* Pulsing animation for kings in check */
@keyframes check-pulse {
    0% { box-shadow: 0 0 15px 5px rgba(255, 0, 0, 0.7); }
    50% { box-shadow: 0 0 25px 8px rgba(255, 0, 0, 0.9); }
    100% { box-shadow: 0 0 15px 5px rgba(255, 0, 0, 0.7); }
}

/* Add text indicator under king */
.king-in-check::after {
    content: "CHECK!";
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(255, 0, 0, 0.8);
    color: white;
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.6em;
    font-weight: bold;
    white-space: nowrap;
    pointer-events: none;
}

.cell-movable::after {
    content: '';
    position: absolute;
    width: 25%;
    height: 25%;
    background-color: rgba(74, 144, 226, 0.5); /* Blueish */
    border-radius: 50%;
    pointer-events: none;
}

.cell-attackable::after {
    content: '';
    position: absolute;
    width: 85%;
    height: 85%;
    border: 4px solid rgba(208, 2, 27, 0.6); /* Reddish */
    border-radius: 4px;
    pointer-events: none;
    box-sizing: border-box;
}

.cell-ability-targetable::after { /* Style for highlighting ability targets */
    content: '';
    position: absolute;
    width: 85%;
    height: 85%;
    border: 4px solid rgba(74, 170, 74, 0.7); /* Greenish */
    border-radius: 4px;
    pointer-events: none;
    box-sizing: border-box;
}

.piece {
    width: 100%; /* Use full cell width for better alignment */
    height: 100%; /* Use full cell height */
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
    z-index: 5;
    font-weight: bold; /* Make symbols bolder */
    position: relative; /* Needed for pseudo-elements if added later */
    -webkit-text-stroke: 0.5px rgba(0,0,0,0.5); /* Slightly stronger outline */
    text-stroke: 0.5px rgba(0,0,0,0.5);
    transition: transform 0.5s ease-in-out; /* Add transition for rotation */
}

/* Rotate pieces back when the board is rotated */
.board-rotated .piece {
    transform: rotate(180deg);
}

.light-piece { /* Renamed from .angel */
    color: #f0f0f0; /* Slightly off-white for better contrast on pure white glow */
    text-shadow: 0 0 10px #ffffff, 0 0 5px #ffffff, 1px 1px 3px rgba(0, 0, 0, 0.6); /* Enhanced glow */
}

.dark-piece { /* Renamed from .demon */
    color: #cc0000; /* Darker Red */
    text-shadow: 0 0 8px #ff4500, 1px 1px 3px rgba(0, 0, 0, 0.6);
}

.side-panel {
    flex-basis: 35%; /* Suggest initial size */
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 250px; /* Minimum width */
    max-height: 100%; /* Ensure it fits */
    overflow-y: auto; /* Allow scrolling if content overflows */
}

.selected-piece-info {
    background-color: #3a3a3a;
    padding: 15px;
    border-radius: 4px;
    flex-shrink: 0; /* Prevent panels from shrinking excessively */
    display: flex; /* Use flexbox */
    flex-direction: column; /* Stack vertically */
}

#piece-details {
    min-height: 50px;
    color: #ddd;
    margin-bottom: 10px; /* Add space below details */
}

.abilities-container {
    margin-top: 10px;
    border-top: 1px solid #555;
    padding-top: 10px;
    display: flex;
    flex-direction: column; /* Stack buttons */
    gap: 8px;
}

.ability-button {
    background-color: #4a7a4a; /* Greenish */
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
    text-align: left;
}

.ability-button:hover {
    background-color: #5a9a5a;
}

.ability-button strong {
    display: block;
    font-size: 1.05em;
}

.ability-button span {
    font-size: 0.85em;
    opacity: 0.8;
}

.action-panel, .log-panel {
    background-color: #3a3a3a;
    padding: 15px;
    border-radius: 4px;
    flex-shrink: 0; /* Prevent panels from shrinking excessively */
}

.action-panel {
    display: flex; /* Use flexbox for buttons */
    flex-direction: column; /* Stack buttons */
    gap: 10px; /* Add space between buttons */
}

h2 {
    color: #ccc;
    margin-bottom: 10px;
    font-size: 1.3em;
    border-bottom: 1px solid #555;
    padding-bottom: 5px;
}

button {
    background-color: #5a5a5a;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
    width: 100%;
}

button:hover {
    background-color: #7a7a7a;
}

#game-log {
    height: 200px;
    overflow-y: auto;
    background-color: #222;
    padding: 8px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
    color: #ccc;
    border: 1px solid #444;
    flex-grow: 1; /* Allow log to fill remaining space in side panel */
    min-height: 100px; /* Ensure it's always somewhat visible */
}

.log-entry {
    margin-bottom: 4px;
    padding-bottom: 4px;
    border-bottom: 1px dashed #444;
}

.log-light { color: #ffffff; } /* Renamed */
.log-dark { color: #ff4500; } /* Renamed */
.log-system { color: #87ceeb; } /* Sky blue */

/* Game Over Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    pointer-events: none; /* Initially ignore clicks */
}

.overlay.visible {
    opacity: 1;
    pointer-events: auto; /* Allow clicks when visible */
}

.overlay-content {
    background-color: #2c2c2c;
    padding: 30px 40px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
    border: 1px solid #555;
}

.overlay-content h2 {
    margin-bottom: 20px;
    font-size: 1.8em;
    color: #eee;
}

#overlay-restart-btn {
    background-color: #4a90e2; /* Blue */
    padding: 12px 25px;
    font-size: 1.1em;
}

#overlay-restart-btn:hover {
    background-color: #5aa1f2;
}

/* --- Media Queries for Responsiveness --- */

/* Medium screens / Tablets */
@media (max-width: 850px) {
    .game-area {
        flex-direction: column; /* Stack board and side panel */
        align-items: center; /* Center items */
        overflow-y: auto; /* Allow scrolling for the whole area */
    }

    .board-container {
        flex-basis: auto; /* Reset basis */
        width: 90%; /* Take most of the width */
        max-width: 500px; /* Limit max size */
        max-height: none; /* Remove height constraint */
        margin-bottom: 15px;
    }

    .side-panel {
        flex-basis: auto; /* Reset basis */
        width: 90%; /* Take most of the width */
        max-width: 500px;
        max-height: 40vh; /* Limit side panel height */
        overflow-y: auto; /* Ensure side panel itself can scroll */
    }

     #game-log {
        height: 150px; /* Adjust height */
        flex-grow: 0; /* Don't let it grow excessively */
    }
}

/* Small screens / Mobile */
@media (max-width: 480px) {
    body {
        padding: 5px; /* Reduce padding */
    }

    .game-container {
        padding: 10px;
    }

    .header h1 {
        font-size: 1.5em;
    }

    .turn-indicator {
        font-size: 1em;
    }

    .board-container {
        width: 100%;
        min-width: unset; /* Remove min-width */
    }

    .side-panel {
         width: 100%;
         min-width: unset;
         max-height: 50vh; /* Allow slightly more height */
    }

    h2 {
        font-size: 1.1em;
    }

    button {
        padding: 8px 12px;
        font-size: 0.9em;
    }

    #game-log {
        font-size: 0.8em;
    }

    .overlay-content {
        padding: 20px;
    }
    .overlay-content h2 {
        font-size: 1.5em;
    }
    #overlay-restart-btn {
        padding: 10px 20px;
        font-size: 1em;
    }
}