/* ================= GLOBAL RESETS & THEME ================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

header {
    height: 6vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #222;
    border-bottom: solid 2px #111;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    flex-shrink: 0;
}

header h1 {
    font-size: 1.6rem;
    color: #00bcd4;
    letter-spacing: 1px;
}

body {
    height: 100vh;
    max-height: 100vh;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: #2c2c2c;
    color: #eee;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

footer {
    height: 4vh;
    width: 100vw;
    position: fixed;
    bottom: 0;
    left: 0;
    font-size: 0.75rem;
    background: #222;
    color: #777;
    display: flex;
    justify-content: center;
    align-items: center;
    border-top: solid 2px #111;
    z-index: 10;
    flex-shrink: 0;
}

/* ================= COMPACT ONE-COLUMN LAYOUT ================= */
.game-container {
    display: flex;
    flex-direction: column; 
    align-items: center;    
    gap: 10px;              
    width: 100%;
    max-width: 460px;       
    height: calc(100vh - 10vh - 40px); 
    margin: 10px auto;
    padding: 0 10px;
}

.top-bar {
    width: 100%;
    display: flex;
    flex-direction: column;
    background: #1e1e1e;
    padding: 8px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.controls {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

/* ================= DROP-DOWN & QUADRATIC BUTTONS ================= */
#difficulty {
    height: 38px; /* Identische Höhe wie die Buttons */
    padding: 0 8px;
    background: #333;
    color: #fff;
    border: 1px solid #555;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    outline: none;
}

button {
    height: 38px;
    width: 38px; /* Breite gleich Höhe zwingt Quadrat-Form */
    aspect-ratio: 1 / 1;
    border: none;
    background: #333;
    color: #fff;
    font-size: 1.2rem; /* Symbole etwas größer für bessere Erkennbarkeit */
    font-weight: bold;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #444;
}

button:hover {
    background: #444;
    border-color: #666;
    transform: translateY(-1px);
}

button:active {
    transform: translateY(1px);
}

/* Spezial-Stile für "New Game" Icon */
#new-game-btn {
    background: #00bcd4;
    border: none;
}
#new-game-btn:hover {
    background: #0097a7;
    box-shadow: 0 0 8px rgba(0, 188, 212, 0.4);
}

/* ================= COMPACT INFO BAR ================= */
.game-info {
    background: #1e1e1e;
    padding: 8px 12px;
    border-radius: 6px;
    display: flex;
    flex-direction: row; 
    justify-content: space-between;
    align-items: center;
    border: 1px solid #333;
    width: 100%;
    flex-shrink: 0;
}

#current-turn, #game-status {
    font-size: 0.9rem;
    font-weight: 600;
}
#game-status {
    color: #00bcd4;
    text-transform: uppercase;
}

/* ================= CHESSBOARD WRAPPER ================= */
.board-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    flex-shrink: 0;
}

#chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    aspect-ratio: 1 / 1;
    border: 6px solid #1a1a1a;
    border-radius: 4px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.square {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    font-size: clamp(18px, 6vw, 36px); 
}

.light-square { background-color: #f0d9b5; }
.dark-square { background-color: #b58863; }
.square:hover { filter: brightness(1.08); }

.white-piece { color: #ffffff; text-shadow: 0 2px 4px rgba(0,0,0,0.5); }
.black-piece { color: #111; }

.selected {
    outline: 4px solid #00bcd4;
    outline-offset: -4px;
}

#chessboard.flipped { transform: rotate(180deg); }
#chessboard.flipped .piece { transform: rotate(180deg); }

/* ================= SUB-SECTIONS ================= */
h2 {
    font-size: 0.8rem;
    color: #777;
    border-bottom: 1px solid #333;
    padding-bottom: 2px;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    width: 100%;
}

.captured-pieces {
    width: 100%;
    flex-shrink: 0;
}

#white-captured, #black-captured {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    padding: 2px 0;
    min-height: 30px;
    overflow: hidden;
}

.captured-item {
    font-size: 22px;
    line-height: 1;
    display: inline-block;
    width: 12px;
}
.white-captured-piece { color: #ffffff; text-shadow: 0 0 2px #000; }
.black-captured-piece { color: #111; text-shadow: 0 0 2px #fff; }

.move-history {
    display: flex;
    flex-direction: column;
    width: 100%;
    flex-grow: 1; 
    min-height: 0; 
    margin-bottom: 10px;
}

#move-list {
    width: 100%;
    height: 100%;
    max-height: 140px; 
    overflow-y: auto;   
    overflow-x: hidden;
    padding: 6px 10px;
    background: #151515;
    border: 1px solid #333;
    border-radius: 6px;
}

.move-row {
    display: flex;
    padding: 3px 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    border-bottom: 1px solid #222;
}
.move-number { width: 35px; color: #666; }
.move-text { width: 80px; color: #fff; }
.move-text.black { color: #aaa; }

#move-list::-webkit-scrollbar { width: 6px; }
#move-list::-webkit-scrollbar-track { background: transparent; }
#move-list::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
#move-list::-webkit-scrollbar-thumb:hover { background: #00bcd4; }

/* ================= GAME OVER OVERLAY ================= */
#game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}
#game-over-overlay.hidden { display: none; }

.overlay-content {
    background-color: #222;
    padding: 30px 40px;
    border-radius: 12px;
    border: 1px solid #444;
    text-align: center;
}

#game-message { font-size: 1.4rem; color: #fff; margin-bottom: 20px; }

/* Spezial-Klasse für den Overlay-Button, damit er seine Textbreite behält */
.overlay-content button { 
    background-color: #00bcd4; 
    padding: 10px 20px; 
    font-size: 0.95rem; 
    width: auto; 
    aspect-ratio: auto;
}

/* ================= SPECIAL EFFECTS ================= */
.square.check-king {
    background-color: #b71c1c !important;
    animation: pulse-check 1.5s infinite alternate;
}
@keyframes pulse-check {
    0% { background-color: #b71c1c !important; box-shadow: inset 0 0 10px #000; }
    100% { background-color: #d32f2f !important; box-shadow: inset 0 0 15px #000; }
}

/* ================= AI THINKING ANIMATION ================= */
/* ================= STATUS TEXT ANIMATIONS ================= */
#ai-thinking {
    font-weight: bold;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: color 0.2s ease;
}

/* Rote Schrift mit Warn-Pulsieren, wenn die KI rechnet */
#ai-thinking.ai-mode {
    color: #f44336;
    animation: pulse-text 1s infinite alternate;
}

/* Ruhige, grüne Schrift, wenn der menschliche Spieler am Zug ist */
#ai-thinking.player-mode {
    color: #4caf50;
}

#ai-thinking.hidden {
    display: none;
}

@keyframes pulse-text {
    0% { opacity: 0.7; }
    100% { opacity: 1; }
}