* {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
}

body {
    color: rgb(233, 236, 239);
    background:
        radial-gradient(ellipse at 50% 0%, rgba(80, 105, 150, 0.18) 0%, transparent 60%),
        linear-gradient(160deg, rgb(38, 42, 50) 0%, rgb(24, 27, 32) 100%);
    min-height: 100vh;
}

/* ── Layout principal ───────────────────────────────────────── */

.layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    width: 100vw;
    gap: 1vh;
}

.top-bar {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 1vh 1.5rem 0;
    flex-shrink: 0;
}

.home-btn {
    justify-self: start;
    color: rgb(160, 165, 170);
    text-decoration: none;
    font-size: 1.4vh;
    padding: 0.35rem 0.8rem;
    border: 1px solid rgb(70, 75, 82);
    border-radius: 5px;
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.home-btn:hover {
    color: rgb(233, 236, 239);
    border-color: rgb(120, 125, 132);
}


.game-container {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 1.5rem;
    padding-bottom: 1rem;
    margin-block: auto;
}

/* ── Colonne plateau ────────────────────────────────────────── */

.board-area {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    flex-shrink: 0;
}

#echiquier {
    display: grid;
    border: 0.4vh solid black;
    /* Taille explicite : carré de 75vh */
    width: 75vh;
    height: 75vh;
    flex-shrink: 0;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
}

/* ── Barre joueur (timer + pièces capturées) ────────────────── */

.player-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.player-label {
    font-size: 1.4vh;
    font-weight: bold;
    color: rgb(180, 180, 180);
    min-width: 3.5rem;
}

.captured-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 1px;
    flex: 1;
    min-height: 2.4vh;
}

.captured-piece {
    height: 2.4vh;
    width: auto;
    opacity: 0.85;
}

.timer-box {
    font-size: 2vh;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    background: rgb(50, 55, 60);
    border-radius: 6px;
    padding: 0.3rem 0.7rem;
    min-width: 5.5rem;
    text-align: center;
    border: 2px solid transparent;
    transition: border-color 0.2s, color 0.2s;
}

.timer-box.timer-active {
    border-color: rgba(255, 215, 0, 0.7);
}

.timer-box.timer-low {
    color: rgb(220, 53, 69);
}

/* ── Cases du plateau ───────────────────────────────────────── */

.caseBlanche, .caseNoire {
    position: relative;
    container-type: size;
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.caseBlanche { background-color: beige; }
.caseNoire   { background-color: rgb(157, 113, 83); }

.letterInCase, .numberInCase {
    color: black;
    position: absolute;
    font-size: 20cqw;
}

.letterInCase {
    bottom: 2cqw;
    right: 5cqw;
    user-select: none;
    -webkit-user-select: none;
}

.numberInCase {
    top: 5cqw;
    left: 2.5cqw;
    user-select: none;
    -webkit-user-select: none;
}

/* ── Pièces ─────────────────────────────────────────────────── */

.piece {
    transition: transform 0.15s;
    height: 80%;
    cursor: pointer;
}

.piece:hover {
    transform: scale(1.2);
}

@keyframes piece-arrive {
    0%   { transform: scale(1.25); }
    100% { transform: scale(1); }
}

.piece-arriving {
    animation: piece-arrive 0.15s ease-out forwards;
}

/* ── Highlights ─────────────────────────────────────────────── */

.selected {
    box-shadow: inset 0 0 0 0.6vh rgba(255, 215, 0, 0.85);
}

.king-in-check {
    box-shadow: inset 0 0 0 0.7vh rgba(220, 53, 69, 0.95);
}

.hint {
    position: absolute;
    width: 33%;
    height: 33%;
    background-color: rgba(0, 0, 0, 0.14);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1;
}

.hint-capture {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, transparent 55%, rgba(0, 0, 0, 0.14) 56%);
    pointer-events: none;
    z-index: 1;
}

/* ── Panneau latéral ────────────────────────────────────────── */

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: 14rem;
    flex-shrink: 0;
    /* la hauteur est calée automatiquement sur board-area via align-items: stretch */
}

/* Contrôle du temps */
.time-controls {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.time-btn {
    flex: 1;
    background: rgb(50, 55, 60);
    color: rgb(233, 236, 239);
    border: 1px solid rgb(80, 85, 90);
    border-radius: 4px;
    padding: 0.25rem 0;
    font-size: 1.2vh;
    cursor: pointer;
    transition: background 0.15s;
}

.time-btn:hover {
    background: rgb(70, 75, 80);
}

.time-btn.active {
    background: rgb(255, 215, 0);
    color: rgb(33, 37, 41);
    border-color: rgb(255, 215, 0);
    font-weight: bold;
}

.time-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Historique des coups */
#move-history {
    flex: 1;
    overflow-y: auto;
    background: rgb(44, 49, 54);
    border-radius: 6px;
    padding: 0.4rem;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: rgb(80, 85, 90) transparent;
}

.history-row {
    display: grid;
    grid-template-columns: 2rem 1fr 1fr;
    gap: 0.2rem;
    padding: 0.1rem 0.2rem;
    border-radius: 3px;
}

.history-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

.move-number {
    color: rgb(140, 145, 150);
    font-size: 1.3vh;
    text-align: right;
    padding-right: 0.2rem;
    line-height: 2;
}

.move-entry {
    font-size: 1.3vh;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    cursor: pointer;
    line-height: 1.6;
    transition: background 0.1s;
}

.move-entry:hover {
    background: rgba(255, 255, 255, 0.1);
}

.move-entry.active {
    background: rgba(255, 215, 0, 0.25);
    color: rgb(255, 215, 0);
    font-weight: bold;
}

/* Bannière de révision */
#review-banner {
    background: rgba(255, 165, 0, 0.15);
    border: 1px solid rgba(255, 165, 0, 0.4);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 1.2vh;
    text-align: center;
    color: rgb(255, 200, 100);
    flex-shrink: 0;
}

/* Boutons de navigation */
.nav-buttons {
    display: flex;
    gap: 0.3rem;
    flex-shrink: 0;
}

.nav-buttons button {
    flex: 1;
    background: rgb(50, 55, 60);
    color: rgb(233, 236, 239);
    border: 1px solid rgb(80, 85, 90);
    border-radius: 4px;
    padding: 0.4rem;
    font-size: 1.4vh;
    cursor: pointer;
    transition: background 0.15s;
}

.nav-buttons button:hover:not(:disabled) {
    background: rgb(70, 75, 80);
}

.nav-buttons button:disabled {
    opacity: 0.3;
    cursor: default;
}

/* ── Modal promotion du pion ────────────────────────────────── */

#promotion-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

#promotion-modal.active { display: flex; }

.promotion-choices {
    background: rgb(33, 37, 41);
    border: 2px solid rgb(233, 236, 239);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    gap: 0.5rem;
}

.promotion-piece {
    background: none;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    padding: 0.25rem;
    width: 10vh;
    height: 10vh;
}

.promotion-piece:hover {
    border-color: rgba(255, 215, 0, 0.85);
    background: rgba(255, 255, 255, 0.1);
}

.promotion-piece img {
    width: 100%;
    height: 100%;
}

/* ── Overlay fin de partie ──────────────────────────────────── */

#game-over-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

#game-over-overlay.active { display: flex; }

.game-over-content {
    background: rgb(33, 37, 41);
    border: 2px solid rgb(233, 236, 239);
    border-radius: 8px;
    padding: 2rem 3rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.game-over-content h2 {
    font-size: 3vh;
}

.game-over-buttons {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
}

.game-over-content button {
    background: rgb(233, 236, 239);
    color: rgb(33, 37, 41);
    border: none;
    border-radius: 4px;
    padding: 0.6rem 1.5rem;
    font-size: 2vh;
    cursor: pointer;
    font-weight: bold;
    flex: 1;
}

.game-over-content button:hover {
    background: rgba(255, 215, 0, 0.85);
}

.game-over-content button.btn-secondary {
    background: rgb(60, 65, 72);
    color: rgb(233, 236, 239);
}

.game-over-content button.btn-secondary:hover {
    background: rgb(80, 85, 95);
}

/* ── Overlay config bot ─────────────────────────────────────────── */

#bot-setup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.bot-setup-content {
    background: rgb(33, 37, 41);
    border: 2px solid rgb(233, 236, 239);
    border-radius: 12px;
    padding: 2rem 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.8rem;
    min-width: 320px;
    align-items: center;
    text-align: center;
}

.bot-setup-content h2 {
    font-size: 2.8vh;
}

.bot-setup-section {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    width: 100%;
}

.bot-setup-label {
    font-size: 1.1vh;
    color: rgb(160, 165, 170);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.bot-difficulty-btns {
    display: flex;
    gap: 0.5rem;
}

.bot-diff-btn {
    flex: 1;
    background: rgb(50, 55, 60);
    color: rgb(233, 236, 239);
    border: 1px solid rgb(80, 85, 90);
    border-radius: 6px;
    padding: 0.5rem;
    font-size: 1.4vh;
    cursor: pointer;
    transition: background 0.15s;
}

.bot-diff-btn:hover {
    background: rgb(70, 75, 80);
}

.bot-diff-btn.active {
    background: rgba(255, 215, 0, 0.9);
    color: rgb(33, 37, 41);
    border-color: rgb(255, 215, 0);
    font-weight: bold;
}

.bot-color-btns {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.bot-color-btn {
    background: rgb(50, 55, 60);
    border: 2px solid rgb(80, 85, 90);
    border-radius: 8px;
    padding: 1rem 1.8rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: border-color 0.15s, background 0.15s, transform 0.15s;
    color: rgb(233, 236, 239);
    font-size: 1.4vh;
    font-weight: bold;
}

.bot-color-btn img {
    height: 7vh;
    width: 7vh;
}

.bot-color-btn:hover {
    border-color: rgba(255, 215, 0, 0.7);
    background: rgb(65, 70, 78);
    transform: translateY(-3px);
}

.stockfish-loading {
    font-size: 1.1vh;
    color: rgb(120, 125, 130);
    font-style: italic;
}

/* ── Overlay En Ligne ───────────────────────────────────────────── */

#online-setup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.online-room-code {
    font-size: 3.5vh;
    font-weight: bold;
    letter-spacing: 0.3em;
    color: rgb(255, 215, 0);
    margin: 0.2rem 0;
}

.online-code-input {
    background: rgb(50, 55, 60);
    color: rgb(233, 236, 239);
    border: 1px solid rgb(80, 85, 90);
    border-radius: 6px;
    padding: 0.5rem;
    font-size: 2vh;
    text-align: center;
    letter-spacing: 0.2em;
    width: 100%;
    outline: none;
}

.online-code-input:focus {
    border-color: rgba(255, 215, 0, 0.6);
}

.online-error {
    font-size: 1.1vh;
    color: rgb(220, 53, 69);
    margin-top: 0.3rem;
}

/* ── Plateau retourné (joueur noir) ─────────────────────────────── */

#echiquier.board-flipped {
    transform: rotate(180deg);
}

#echiquier.board-flipped .piece,
#echiquier.board-flipped .letterInCase,
#echiquier.board-flipped .numberInCase {
    transform: rotate(180deg);
}

/* L'animation d'arrivée doit inclure la rotation pour le plateau retourné */
@keyframes piece-arrive-flipped {
    0%   { transform: rotate(180deg) scale(1.25); }
    100% { transform: rotate(180deg) scale(1); }
}

#echiquier.board-flipped .piece-arriving {
    animation-name: piece-arrive-flipped;
}
