/* Base variables */
:root {
    --primary-color: #4a66a0;
    --secondary-color: #1e2027;
    --background-color: #13151a;
    --surface-color: #1a1c23;
    --text-color: #e8e3d7;
    /* Ajusté pour meilleure lisibilité */
    --accent-color: #e9dbbb;
    /* pièces blanches */
    --dark-piece-color: #000000;
    /* pièces noires */
    --light-square-color: #eeeed2;
    --dark-square-color: #769656;
    --highlight-move-color: rgba(168, 171, 179, 0.9);
    --highlight-capture-color: rgba(0, 0, 0, 0.7);
    --highlight-selected-color: rgba(74, 102, 160, 0.4);
    --highlight-check-color: rgba(255, 0, 0, 0.5);
    --highlight-last-move-color: #b2c717;
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --learn-color: #4caf50; /* Green for learning */

    /* Light theme variables */
    --light-primary-color: #5b7bb7;
    --light-secondary-color: #e0e0e0;
    --light-background-color: #f5f5f5;
    --light-surface-color: #ffffff;
    --light-text-color: #333333;
    --light-light-square-color: #f0d9b5;
    --light-dark-square-color: #b58863;
    --light-highlight-move-color: #d3d6bc;
    --light-highlight-capture-color: rgba(200, 60, 60, 0.6);
    --light-learn-color: #66bb6a;
}

/* Global reset & body */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.square img.piece {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.square::after {
    z-index: 0; /* Doit être derrière les pièces */
}

/* Les images ou éléments représentant les pièces */
.square .piece {
    position: relative;
    z-index: 1; /* Au-dessus du highlight */
}

body {
    background-color: var(--background-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    /* Police plus standard */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* Centre le contenu principal */
    align-items: center;
    padding: 20px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Light theme */
body.light-theme {
    background-color: var(--light-background-color);
    color: var(--light-text-color);
    --primary-color: var(--light-primary-color);
    --secondary-color: var(--light-secondary-color);
    --background-color: var(--light-background-color);
    --surface-color: var(--light-surface-color);
    --text-color: var(--light-text-color);
    --light-square-color: var(--light-light-square-color);
    --dark-square-color: var(--light-dark-square-color);
    --highlight-move-color: var(--light-highlight-move-color);
    --highlight-capture-color: var(--light-highlight-capture-color);
    --learn-color: var(--light-learn-color);
}

body.light-theme .menu-container,
body.light-theme .board-wrapper,
body.light-theme .player-info,
body.light-theme .modal-content,
body.light-theme .moves-container,
body.light-theme .game-controls,
body.light-theme .stats-container,
body.light-theme .toast,
body.light-theme .control-button {
    background: var(--light-surface-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 1px solid #ddd;
    color: var(--light-text-color);
}

body.light-theme .mode-button,
body.light-theme .time-button, /* Added */
body.light-theme .difficulty-button,
body.light-theme .time-display,
body.light-theme .captured-pieces,
body.light-theme .stat-item,
body.light-theme .player-avatar,
body.light-theme .game-controls button,
body.light-theme .moves-container ol li { /* Adjusted */
    background: var(--light-secondary-color);
    color: var(--light-text-color);
}

body.light-theme .primary-btn {
    background: var(--light-primary-color);
    color: white;
}

body.light-theme .secondary-btn { /* Added */
    background: var(--light-secondary-color);
    color: var(--light-text-color);
    border: 1px solid #ccc;
}
body.light-theme .secondary-btn:hover {
    background: #d5d5d5;
}

body.light-theme .logo i,
body.light-theme .mode-button i,
body.light-theme .time-button i, /* Added */
body.light-theme .game-status,
body.light-theme .stat-value,
body.light-theme .move-number,
body.light-theme .moves-container h3 { /* Added */
    color: var(--light-primary-color);
}

body.light-theme .move-white:hover,
body.light-theme .move-black:hover {
    background: rgba(0, 0, 0, 0.05);
}

body.light-theme #progress-bar {
    background: var(--light-secondary-color);
}

body.light-theme .square.light {
    background-color: var(--light-light-square-color);
}

body.light-theme .square.dark {
    background-color: var(--light-dark-square-color);
}

body.light-theme .difficulty-button.difficulty-learn .level-bar {
    background: var(--light-learn-color);
}

/* Layout Principal du Jeu */
.game-layout {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    /* Colonnes flexibles */
    gap: 20px;
    width: 100%;
    max-width: 1200px;
    /* Augmenté pour accueillir les sidebars */
    margin-top: 20px;
}

.left-sidebar,
.right-sidebar {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.game-center {
    display: flex;
    justify-content: center;
}

/* Application Container */
.app-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Header & Logo */
header {
    width: 100%;
    text-align: center;
    margin-bottom: 20px;
}

.logo {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

.logo i {
    font-size: 2em;
    color: var(--primary-color);
}

h1 {
    font-size: 1.8em;
}

/* Controles Flottants */
.controls-container {
    position: fixed;
    top: 15px;
    right: 15px;
    display: flex;
    gap: 10px;
    z-index: 100;
}

.control-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-color);
    color: var(--text-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    font-size: 0.8em; /* Slightly smaller for text */
}

.control-button i {
    font-size: 1.1em; /* Icon size */
}

.control-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Menus (Mode, Time, Difficulty) */
.menu-container {
    background: var(--surface-color);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 700px;
    text-align: center;
    margin-bottom: 30px;
}

.mode-options,
.time-options { /* Added time-options */
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 20px;
}

.mode-button,
.time-button, /* Added time-button */
.difficulty-button {
    background: var(--secondary-color);
    border: none;
    padding: 15px;
    border-radius: 8px;
    color: var(--text-color);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    position: relative;
    overflow: hidden;
    width: clamp(150px, 30%, 200px); /* Common width */
}

.mode-button i,
.time-button i { /* Added time-button */
    font-size: 2em;
    color: var(--primary-color);
}

.mode-button span,
.time-button span { /* Added time-button */
    font-size: 1em;
    font-weight: 500;
}

.mode-button:hover,
.time-button:hover { /* Added time-button */
    background: var(--primary-color);
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.mode-button:hover i,
.time-button:hover i, /* Added time-button */
.mode-button:hover span,
.time-button:hover span { /* Added time-button */
    color: white;
}


/* Shine effect */
.mode-button::before,
.time-button::before, /* Added time-button */
.difficulty-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -75%;
    width: 50%;
    height: 100%;
    background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0) 100%);
    transform: skewX(-25deg);
    transition: left 0.5s ease;
}

.mode-button:hover::before,
.time-button:hover::before, /* Added time-button */
.difficulty-button:hover::before {
    left: 125%;
}

/* Style for SVG icons in time selection menu */
.time-button svg {
    width: 35px;
    height: 35px;
    fill: var(--primary-color); /* Match the color of fas icons */
    transition: fill 0.3s ease; /* Smooth color transition */
}

.time-button:hover svg {
    fill: white; /* Match hover effect of fas icons */
}

/* Difficulty Selection */
.difficulty-options {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

#ai-vs-ai-difficulty-selection .ai-difficulty-options {
    display: flex;
    justify-content: space-around;
    gap: 20px;
    flex-wrap: wrap;
}

#ai-vs-ai-difficulty-selection .ai-diff-group {
    width: 45%;
    min-width: 250px;
    display: flex; /* Use flexbox for buttons inside */
    flex-wrap: wrap; /* Allow wrapping */
    justify-content: center; /* Center buttons */
    gap: 10px; /* Gap between buttons */
}
#ai-vs-ai-difficulty-selection h3 {
    width: 100%; /* Make heading span full width */
    margin-bottom: 10px;
    text-align: center;
}

.difficulty-button {
    width: 45%;
    min-width: 180px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    padding: 10px; /* Adjust padding */
    gap: 5px; /* Adjust gap */
}


.difficulty-button span {
    font-size: 0.9em;
}

.level-indicator {
    width: 80%;
    height: 6px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 5px;
}

.level-bar {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

/* Learn Difficulty Styling */
.difficulty-button.difficulty-learn .level-bar {
    background: var(--learn-color);
}
/* Removed empty ruleset for .difficulty-button.difficulty-learn span */
.difficulty-button.difficulty-learn:hover {
    background: var(--learn-color);
}


.level-bar.adaptive {
    background: linear-gradient(90deg, var(--primary-color) 0%, #7b97d4 50%, var(--primary-color) 100%);
    background-size: 200% 100%;
    animation: gradient-shift 2s linear infinite;
}

/* Hide puzzle controls by default */
#hint-button, #next-puzzle-button, #exit-puzzle-button {
    display: none;
}

/* Show puzzle controls when puzzle mode is active */
body.puzzle-mode-active .game-controls #hint-button,
body.puzzle-mode-active .game-controls #next-puzzle-button,
body.puzzle-mode-active .game-controls #exit-puzzle-button {
    display: flex; /* Or inline-flex, block, etc. depending on layout */
}

/* Hide standard game controls during puzzle mode */
body.puzzle-mode-active .game-controls #undo-button,
body.puzzle-mode-active .game-controls #analyze-button,
body.puzzle-mode-active .game-controls #export-button,
body.puzzle-mode-active .game-controls #resign-button {
    display: none;
}

/* Style for hint highlight */
.square.hint-from::after {
    content: '';
    position: absolute;
    inset: 3px;
    border: 3px solid rgba(255, 165, 0, 0.8); /* Orange border */
    border-radius: 50%; /* Circle */
    pointer-events: none;
    z-index: 2;
    animation: pulse-suggest 1.5s infinite ease-in-out; /* Reuse pulse animation */
}
 .square.hint-to::after {
    content: '';
    position: absolute;
    width: 30%; height: 30%; top: 35%; left: 35%; /* Small circle like normal moves */
    border-radius: 50%;
    background-color: rgba(255, 165, 0, 0.7); /* Orange dot */
    pointer-events: none;
    z-index: 2;
    opacity: 0.8;
 }

@keyframes gradient-shift {
    0% {
        background-position: 100% 0;
    }

    100% {
        background-position: -100% 0;
    }
}

.difficulty-button:hover:not(.difficulty-learn) {
    background: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.difficulty-button:hover .level-bar:not(.adaptive) {
    background: white;
}

.difficulty-button.selected {
    background-color: var(--primary-color);
    border: 2px solid var(--accent-color);
    color: white;
}
.difficulty-button.difficulty-learn.selected {
    background-color: var(--learn-color);
    border: 2px solid var(--accent-color);
}

body.light-theme .difficulty-button.selected {
    border-color: var(--light-primary-color);
}
body.light-theme .difficulty-button.difficulty-learn.selected {
     background-color: var(--light-learn-color);
     border-color: var(--light-primary-color);
}


/* Board Area */
.board-wrapper {
    position: relative;
    width: 100%;
    max-width: 600px;
    /* Limite la taille max */
    background: var(--surface-color);
    padding: 15px;
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

#chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    aspect-ratio: 1 / 1;
    width: 100%;
    background: var(--secondary-color);
    border-radius: 8px;
    /* Bordure interne */
    overflow: hidden;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
    margin: 0 auto;
}

/* Squares */
.square {
    aspect-ratio: 1 / 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(20px, 7vw, 50px);
    /* Taille de pièce responsive */
    cursor: pointer;
    position: relative;
    transition: background-color 0.1s ease;
}

.square.light {
    background-color: var(--light-square-color);
}

.square.dark {
    background-color: var(--dark-square-color);
}

.square-label {
    position: absolute;
    bottom: 1px;
    right: 2px;
    font-size: clamp(6px, 1.5vw, 10px);
    color: rgba(0, 0, 0, 0.4);
    pointer-events: none;
    font-weight: bold;
}

.square.light .square-label {
    color: rgba(139, 107, 87, 0.7);
}

/* Dark label on light square */
.square.dark .square-label {
    color: rgba(232, 227, 215, 0.7);
}

/* Light label on dark square */

/* Pieces */
.piece {
    -webkit-user-select: none;
    user-select: none;
    /* Prevent text selection */
    transition: transform 0.15s ease;
}

.white-piece {
    color: var(--accent-color);
}

.black-piece {
    color: var(--dark-piece-color);
}

body.light-theme .white-piece {
    color: #fff;
}

/* Pièces blanches sur thème clair */
body.light-theme .black-piece {
    color: #444;
}

/* Pièces noires sur thème clair */
.square.selected .piece {
    transform: scale(1.1);
    filter: brightness(1.2);
}

/* Square Highlights */
.square::after {
    /* General highlight pseudo-element */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    border-radius: 2px;
    /* Slight rounding */
    transition: background-color 0.1s, box-shadow 0.1s;
}

/* Hover effect */
.square:hover::after {
    background: rgba(255, 255, 255, 0.1);
}

/* Selected square */
.square.selected::after {
    background-color: var(--highlight-selected-color);
}

/* Possible move (empty square) */
.square.highlight::after {
    background-color: var(--highlight-move-color);
    width: 30%;
    height: 30%;
    top: 35%;
    left: 35%;
    border-radius: 50%;
    opacity: 0.7;
}

/* Possible capture */
.square.capture::after {
    box-shadow: inset 0 0 0 4px var(--highlight-capture-color);
}

/* King in Check */
.square.in-check::after {
    background-color: var(--highlight-check-color);
}

/* Last Move */
.square.last-move::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--highlight-last-move-color);
    z-index: 0; /* Derrière la pièce qui a z-index: 1 */
    opacity: 0.6; /* Ajustez l'opacité selon vos préférences */
}

/* Player Info & Captured Pieces */
.player-info {
    width: 100%;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--surface-color);
    border-radius: 8px;
    border: 2px solid transparent;
    transition: border-color 0.3s ease, background-color 0.3s ease;
}

.player-info.active-player {
    border-color: var(--primary-color);
    box-shadow: 0 0 8px var(--primary-color);
}

.player-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: var(--secondary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
}

.player-details {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-weight: 600;
}

.player-rating {
    font-size: 0.85em;
    opacity: 0.7;
}

.time-display {
    font-family: 'Roboto Mono', monospace;
    font-size: 1.1em;
    font-weight: 600;
    padding: 6px 10px;
    background: var(--secondary-color);
    border-radius: 6px;
    text-align: center;
}

.time-display.urgent {
    animation: urgent-pulse 1s infinite;
    background: #ff4d4d !important;
    color: white !important;
}

@keyframes urgent-pulse {
    0% {
        box-shadow: 0 0 5px #ff4d4d;
    }

    50% {
        box-shadow: 0 0 10px #ff7070;
    }

    100% {
        box-shadow: 0 0 5px #ff4d4d;
    }
}

.captured-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    /* Reduced gap */
    padding: 5px;
    background: var(--secondary-color);
    border-radius: 6px;
    min-height: 30px;
    font-size: 0.8em;
    /* Smaller captured pieces */
    align-items: center;
}

/* Progress Bar & Game Status */
.game-status {
    font-size: 1em;
    font-weight: 600;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 8px;
    min-height: 1.2em;
}

.progress-container {
    position: relative;
    width: 100%;
}

/* Needed for score overlay */
#progress-bar {
    width: 100%;
    height: 10px;
    background: var(--secondary-color);
    border-radius: 5px;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
    display: flex;
    /* Use flex for bars */
}

#white-progress,
#black-progress {
    height: 100%;
    transition: width 0.4s ease;
}

#white-progress {
    background: #eee;
}

/* Simple white */
#black-progress {
    background: #555;
}

/* Simple dark gray */
#score-advantage {
    position: absolute;
    right: 5px;
    top: -2px;
    /* Position over the bar */
    font-size: 0.8em;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.score-white {
    color: white;
}

.score-black {
    color: white;
}

/* Keep white for contrast on dark bar */

/* Right Sidebar Components */
.game-controls {
    display: flex;
    justify-content: space-between; /* Space out buttons */
    gap: 5px; /* Reduced gap */
    margin-top: 15px;
}

.game-controls button {
    flex-grow: 1; /* Distribute space */
    flex-basis: 0; /* Allow equal shrinking/growing */
    padding: 8px 5px; /* Adjusted padding */
    font-size: 0.9em;
    background: var(--secondary-color);
    color: var(--text-color);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.game-controls button i {
    font-size: 1.1em; /* Make icons slightly bigger */
}


.game-controls button:hover:not(:disabled) {
    background: var(--primary-color);
}

.game-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #444;
}

body.light-theme .game-controls button {
    background: var(--light-secondary-color);
    color: var(--light-text-color);
}

body.light-theme .game-controls button:hover:not(:disabled) {
    background: var(--light-primary-color);
}

body.light-theme .game-controls button:disabled {
    background: #ccc;
}

.review-controls button {
    background-color: var(--primary-color, #1976d2);
    border: none;
    color: #fff;
    padding: 8px 16px;
    font-size: 1em;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
    margin: 4px;
}

.review-controls button:hover {
    background-color: #1565c0; /* couleur légèrement plus foncée */
}

.review-controls button:active {
    transform: scale(0.98);
}

.review-controls button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.moves-container {
    background: var(--surface-color);
    border-radius: 8px;
    padding: 10px;
    margin-top: 15px;
    max-height: 300px;
    /* Limit height */
    overflow-y: auto;
}

.moves-container h3 {
    text-align: center;
    margin-bottom: 10px;
    font-size: 1.1em;
    color: var(--primary-color);
}

#move-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.85em;
    font-family: 'Roboto Mono', monospace;
}

#move-list li {
    padding: 3px 5px;
    border-bottom: 1px solid var(--secondary-color);
    display: flex;
    /* Align items nicely */
    align-items: baseline;
}

#move-list li:last-child {
    border-bottom: none;
}

.move-number {
    color: var(--primary-color);
    font-weight: bold;
    width: 25px;
    text-align: right;
    margin-right: 5px;
    flex-shrink: 0;
    /* Prevent shrinking */
}

.move-white,
.move-black {
    padding: 2px 5px;
    border-radius: 3px;
    cursor: default;
    /* No hover effect needed? */
}

.move-white {
    font-weight: 500;
    margin-right: 5px;
}

/* Add margin */
.move-black {
    font-weight: 500;
}

/* Stats Container */
.stats-container {
    width: 100%;
    max-width: 600px;
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-top: 30px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    background: var(--secondary-color);
    border-radius: 8px;
}

.stat-label {
    font-size: 0.8em;
    opacity: 0.7;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.3em;
    font-weight: 600;
    color: var(--primary-color);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    display: none; /* Changed to none */
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0; /* Start hidden */
    transition: opacity 0.3s ease; /* Fade effect */
    pointer-events: none; /* Allow clicking through when hidden */
}

.modal.show { /* Class to display modal */
    display: flex;
    opacity: 1;
    pointer-events: auto;
}


body.light-theme .modal {
    background: rgba(255, 255, 255, 0.7);
}

.modal-content {
    position: relative;
    background: var(--surface-color);
    padding: 25px;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 450px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    text-align: center;
    transform: scale(0.95); /* Start slightly smaller */
    transition: transform 0.3s ease; /* Scale effect */
}
.modal.show .modal-content {
    transform: scale(1); /* Scale in when shown */
}


.modal-header h3 {
    margin-bottom: 20px;
    font-size: 1.3em;
    color: var(--primary-color);
}

.promotion-options {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.promotion-piece {
    width: 65px;
    height: 65px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5em;
    background: var(--secondary-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-color);
    /* Ensure piece color is visible */
}
.promotion-piece img { /* Style images within promotion */
    max-width: 80%;
    max-height: 80%;
    object-fit: contain;
}

.promotion-piece:hover {
    background: var(--primary-color);
    transform: scale(1.05);
    color: white;
}

.modal-footer {
    margin-top: 25px;
    text-align: center;
    display: flex; /* Use flex for better button alignment */
    justify-content: center; /* Center buttons */
    gap: 10px; /* Space between buttons */
    flex-wrap: wrap; /* Allow wrapping on small screens */
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center; /* Center content */
    gap: 8px;
    text-decoration: none; /* Remove underline if used as link */
    line-height: 1.2; /* Ensure consistent height */
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    position: relative;
    overflow: hidden;
}

.primary-btn:hover {
    background: #5b7bb7;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.secondary-btn { /* Style for secondary buttons */
    background: var(--secondary-color);
    color: var(--text-color);
    border: 1px solid #555; /* Add subtle border */
}

.secondary-btn:hover {
    background: #33363f; /* Darken slightly on hover */
    border-color: #777;
}


.primary-btn::before {
    /* Shine */
    content: '';
    position: absolute;
    top: 0;
    left: -75%;
    width: 50%;
    height: 100%;
    background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0) 100%);
    transform: skewX(-25deg);
    transition: left 0.5s ease;
}

.primary-btn:hover::before {
    left: 125%;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    align-items: center;
    pointer-events: none;
}

.toast {
    background: rgba(30, 32, 39, 0.9);
    color: #eee;
    padding: 10px 18px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0; /* Start hidden */
    transform: translateY(15px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    max-width: 80%;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    pointer-events: auto; /* Allow interaction if needed */
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast i {
    font-size: 1.1em;
}

/* Confetti */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden; /* Prevent scrollbars */
}

.confetti {
    position: absolute;
    width: 8px;
    height: 12px;
    /* More rectangular */
    background: var(--primary-color);
    opacity: 0.9;
    animation: confetti-fall 4s linear forwards;
    border-radius: 2px;
    will-change: transform, opacity; /* Optimize animation */
}

/* Styles pour la suggestion dans le module Apprendre */
.square.suggested-move-from::after {
    content: '';
    position: absolute;
    inset: 4px; /* Légèrement à l'intérieur */
    border: 3px dashed rgba(40, 180, 40, 0.8); /* Tirets verts */
    border-radius: 4px;
    pointer-events: none;
    z-index: 2; /* Au-dessus des highlights normaux mais sous la pièce */
    animation: pulse-suggest 1.5s infinite ease-in-out;
}

.square.suggested-move-to::after {
    content: '';
    position: absolute;
    inset: 4px;
    border: 3px solid rgba(40, 180, 40, 0.8); /* Solide vert */
    border-radius: 4px;
    pointer-events: none;
    z-index: 2;
     animation: pulse-suggest 1.5s infinite ease-in-out;
}

@keyframes pulse-suggest {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

/* Styles pour le texte du coach */
#coach-advice {
    /* Styles existants */
    transition: background-color 0.3s, color 0.3s; /* Animation douce */
}
#coach-advice.thinking {
    background-color: var(--secondary-color); /* Peut-être un fond légèrement différent */
    color: #999; /* Texte grisé */
    font-style: italic;
}

/* --- Styles pour Coach & Chat IA --- */

/* Boîte du Coach */
#coach-box {
    background: rgba(var(--surface-rgb, 26, 28, 35), 0.9); /* Utiliser var() ou couleur par défaut */
    border: 1px solid var(--primary-color);
    border-radius: var(--border-radius);
    padding: 15px;
    margin-top: 15px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
    -webkit-backdrop-filter: blur(3px); /* Effet verre dépoli for Safari */
    backdrop-filter: blur(3px); /* Effet verre dépoli */
}
#coach-box h2 {
    color: var(--primary-color);
    margin-top: 0;
    margin-bottom: 10px;
    text-align: center;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
#coach-advice {
    font-size: 0.95em;
    line-height: 1.5;
    min-height: 3em;
    background-color: rgba(var(--secondary-rgb, 30, 32, 39), 0.7); /* Plus transparent */
    padding: 10px;
    border-radius: 6px;
    transition: background-color 0.3s, color 0.3s;
}
#coach-advice.thinking { font-style: italic; color: #aaa; }
#coach-advice strong { color: var(--accent-color); font-weight: 600; } /* Conseil mis en évidence */

/* Thème Clair */
body.light-theme #coach-box {
     background: rgba(var(--light-surface-rgb, 255, 255, 255), 0.9);
     border-color: var(--light-primary-color);
 }
 body.light-theme #coach-advice {
      background-color: rgba(var(--light-secondary-rgb, 224, 224, 224), 0.8);
      color: var(--light-text-color);
 }
 body.light-theme #coach-advice.thinking { color: #666; }
 body.light-theme #coach-advice strong { color: var(--light-primary-color); }


/* Bulles de Chat */
.chat-bubble {
    position: absolute; /* Positionner par rapport à .player-info */
    background-color: var(--secondary-color);
    color: var(--text-color);
    padding: 8px 12px;
    border-radius: 15px;
    font-size: 0.85em;
    max-width: 80%;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.4s ease;
    z-index: 10;
    pointer-events: none; /* Ne pas interférer avec les clics */
    white-space: normal; /* Permettre le retour à la ligne */
    word-wrap: break-word;
}
.chat-bubble::after { /* Petit triangle pour la bulle */
    content: '';
    position: absolute;
    border-style: solid;
}

/* Positionnement spécifique (ajuster selon votre layout exact) */
.chat-bubble-black { /* Pour l'adversaire (Noir) en haut */
    bottom: 105%; /* Au-dessus de la boîte player-info */
    left: 10%;
    transform: translateY(10px) scale(0.9); /* Commence légèrement décalé et petit */
    border-bottom-left-radius: 3px; /* Pointe en bas à gauche */
}
.chat-bubble-black::after {
    top: 100%; /* Pointe vers le bas */
    left: 15px;
    border-width: 8px 8px 0 8px;
    border-color: var(--secondary-color) transparent transparent transparent;
}

.chat-bubble-white { /* Pour le joueur (Blanc) en bas */
    top: 105%; /* En dessous de la boîte player-info */
    left: 10%;
    transform: translateY(-10px) scale(0.9);
    border-top-left-radius: 3px; /* Pointe en haut à gauche */
}
.chat-bubble-white::after {
    bottom: 100%; /* Pointe vers le haut */
    left: 15px;
    border-width: 0 8px 8px 8px;
    border-color: transparent transparent var(--secondary-color) transparent;
}

.chat-bubble.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Thème Clair pour Bulles */
body.light-theme .chat-bubble {
     background-color: var(--light-secondary-color);
     color: var(--light-text-color);
     box-shadow: 0 2px 5px rgba(0,0,0,0.15);
 }
 body.light-theme .chat-bubble-black::after { border-color: var(--light-secondary-color) transparent transparent transparent; }
 body.light-theme .chat-bubble-white::after { border-color: transparent transparent var(--light-secondary-color) transparent; }


/* Highlighting pour les suggestions (adapté de learn.css) */
.square.suggested-move-from::after {
    content: '';
    position: absolute;
    inset: 4px;
    border: 3px dashed rgba(40, 180, 40, 0.8); /* Tirets verts */
    border-radius: 4px;
    pointer-events: none;
    z-index: 2;
    animation: pulse-suggest 1.5s infinite ease-in-out;
}

.square.suggested-move-to::after {
    content: '';
    position: absolute;
    inset: 4px;
    border: 3px solid rgba(40, 180, 40, 0.8); /* Solide vert */
    border-radius: 4px;
    pointer-events: none;
    z-index: 2;
     animation: pulse-suggest 1.5s infinite ease-in-out;
}

@keyframes pulse-suggest {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

/* Ajuster z-index si nécessaire pour que les highlights soient visibles */
.square::after { z-index: 1; } /* Mettre les highlights standard en dessous */
.piece { z-index: 3; } /* Pièces au-dessus de tout */

@keyframes confetti-fall {
    0% {
        transform: translateY(-20px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(105vh) rotate(720deg);
        opacity: 0;
    }
}

/* Responsive Adjustments */
@media (max-width: 992px) {

    /* Tablet and below */
    .game-layout {
        grid-template-columns: 1fr;
        /* Stack columns */
        max-width: 600px;
        /* Limit width */
        margin: 20px auto;
    }

    .left-sidebar,
    .right-sidebar {
        order: 3;
        /* Move sidebars below board */
        width: 100%;
    }

    .game-center {
        order: 2;
    }

    .right-sidebar {
        display: grid;
        /* Use grid for better layout */
        grid-template-columns: 1fr 1fr;
        /* Side-by-side controls and history */
        gap: 15px;
    }
    .player-info-white { /* Player info above controls/history */
        grid-column: 1 / -1;
        order: -2;
    }
     .captured-black {
         grid-column: 1 / -1;
         order: -1;
     }

    .game-controls {
        grid-column: 1 / 2;
        margin-top: 0;
        flex-direction: column; /* Stack control buttons */
    }

    .moves-container {
        grid-column: 2 / 3;
        margin-top: 0;
        max-height: 200px;
    }
     #statistics {
         margin-top: 20px;
     }
}

@media (max-width: 768px) { /* Adjust breakpoint slightly */
    .right-sidebar {
        grid-template-columns: 1fr; /* Stack everything in right sidebar */
    }
    .game-controls, .moves-container {
        grid-column: 1 / -1; /* Span full width */
    }
    .moves-container {
        max-height: 180px; /* Adjust height */
    }
     #ai-vs-ai-difficulty-selection .ai-diff-group {
         width: 80%; /* Make AI groups wider */
         min-width: unset;
     }

}


@media (max-width: 600px) {

    /* Smaller Mobile */
    body {
        padding: 10px;
    }

    .controls-container {
        top: 5px;
        right: 5px;
    }

    .control-button {
        width: 35px;
        height: 35px;
    }
     .control-button i { font-size: 1em; }

    header {
        margin-bottom: 15px;
    }

    .logo i {
        font-size: 1.8em;
    }

    h1 {
        font-size: 1.3em;
    }

    .menu-container {
        padding: 20px;
    }

    .mode-button, .time-button {
        width: 80%;
        padding: 12px;
    }

    .difficulty-button {
        width: 80%;
        padding: 10px;
         min-width: 150px;
    }
     #ai-vs-ai-difficulty-selection .ai-diff-group {
         width: 100%;
     }
      #ai-vs-ai-difficulty-selection .difficulty-button {
          width: 47%; /* Two per row */
          min-width: 130px;
      }


    .board-wrapper {
        padding: 10px;
    }

    .square {
        font-size: clamp(18px, 8vw, 40px);
    }

    .square-label {
        display: none;
    }

    /* Hide labels on small screens */
    .player-info {
        padding: 8px;
        gap: 8px;
        grid-template-columns: auto 1fr auto;
        /* Ensure 3 columns */
    }

    .player-avatar {
        width: 30px;
        height: 30px;
        font-size: 1em;
    }

    .time-display {
        font-size: 1em;
        padding: 5px 8px;
    }

    .captured-pieces {
        font-size: 0.7em;
        min-height: 25px;
        gap: 1px;
    }

    .game-controls {
        flex-direction: row; /* Back to row for small icon buttons */
        gap: 8px;
    }
     .game-controls button {
         padding: 8px;
     }


    .moves-container {
        max-height: 150px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Back to 2 columns if possible */
    .modal-content {
        padding: 15px;
        max-width: 95%;
    }
     .modal-footer {
         gap: 8px;
     }
      .modal-footer .btn {
          padding: 8px 12px;
          font-size: 0.9em;
      }

    .promotion-piece {
        width: 50px;
        height: 50px;
        font-size: 2em;
    }
}

/* Custom Time Modal (coherent with main modal styles) */
#custom-time-modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
#custom-time-modal.show {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}
#custom-time-modal .modal-content {
    background: var(--surface-color);
    padding: 25px;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 450px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    transform: scale(0.95);
    transition: transform 0.3s ease;
}
#custom-time-modal.show .modal-content {
    transform: scale(1);
}
#custom-time-modal h2 {
    font-size: 1.3em;
    margin-bottom: 18px;
    color: var(--primary-color);
    font-weight: 600;
}
#custom-time-modal .custom-time-input-group {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}
#custom-time-modal .custom-time-input-group label {
    font-size: 1em;
    color: var(--text-color);
    font-weight: 500;
}
#custom-time-modal .custom-time-input-group input {
    width: 100%;
    padding: 10px;
    font-size: 1em;
    border: 1px solid var(--secondary-color);
    border-radius: var(--border-radius);
    background: var(--background-color);
    color: var(--text-color);
    outline: none;
    transition: border-color 0.3s;
}
#custom-time-modal .custom-time-input-group input:focus {
    border-color: var(--primary-color);
}
#custom-time-modal .modal-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 18px;
    flex-wrap: wrap;
}
#custom-time-modal .menu-button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1em;
    background: var(--primary-color);
    color: white;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
#custom-time-modal .menu-button:hover {
    background: #5b7bb7;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
#custom-time-modal .secondary-button {
    background: var(--secondary-color);
    color: var(--text-color);
    border: 1px solid #555;
}
#custom-time-modal .secondary-button:hover {
    background: #33363f;
    border-color: #777;
    color: var(--text-color);
}
#custom-time-modal .menu-button::before {
    content: '';
    position: absolute;
    top: 0; left: -75%;
    width: 50%; height: 100%;
    background: linear-gradient(to right,rgba(255,255,255,0) 0%,rgba(255,255,255,0.2) 50%,rgba(255,255,255,0) 100%);
    transform: skewX(-25deg);
    transition: left 0.5s ease;
}
#custom-time-modal .menu-button:hover::before {
    left: 125%;
}

/* Light theme for custom time modal */
body.light-theme #custom-time-modal {
    background: rgba(255,255,255,0.7);
}
body.light-theme #custom-time-modal .modal-content {
    background: var(--light-surface-color);
    color: var(--light-text-color);
}
body.light-theme #custom-time-modal h2 {
    color: var(--light-primary-color);
}
body.light-theme #custom-time-modal .custom-time-input-group label {
    color: var(--light-text-color);
}
body.light-theme #custom-time-modal .custom-time-input-group input {
    background: var(--light-background-color);
    color: var(--light-text-color);
    border: 1px solid var(--light-secondary-color);
}
body.light-theme #custom-time-modal .custom-time-input-group input:focus {
    border-color: var(--light-primary-color);
}
body.light-theme #custom-time-modal .menu-button {
    background: var(--light-primary-color);
    color: white;
}
body.light-theme #custom-time-modal .menu-button:hover {
    background: #4a66a0;
}
body.light-theme #custom-time-modal .secondary-button {
    background: var(--light-secondary-color);
    color: var(--light-text-color);
    border: 1px solid #ccc;
}
body.light-theme #custom-time-modal .secondary-button:hover {
    background: #d5d5d5;
    color: var(--light-text-color);
    border-color: #bbb;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    #custom-time-modal .modal-content {
        padding: 15px;
        max-width: 98%;
    }
    #custom-time-modal .modal-buttons {
        gap: 8px;
    }
    #custom-time-modal .menu-button {
        padding: 8px 12px;
        font-size: 0.95em;
    }
}