/* Reset */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    min-height: 100vh;
    color: #fff;
}

/* Screens */
.screen { min-height: 100vh; display: flex; flex-direction: column; }
.screen.hidden { display: none !important; }

/* Overlay */
.overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}
.overlay.hidden { display: none !important; }

/* Settings */
.settings-container {
    max-width: 550px;
    margin: auto;
    padding: 40px;
    background: rgba(0,0,0,0.3);
    border-radius: 20px;
    text-align: center;
}
.settings-container h1 { font-size: 3.5rem; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0,0,0,0.5); }
.settings-container h2 { font-size: 2rem; margin-bottom: 40px; font-weight: normal; opacity: 0.9; }

.setting-group { margin-bottom: 30px; }
.setting-group label { display: block; font-size: 1.4rem; margin-bottom: 12px; }

.player-input {
    width: 100%;
    padding: 14px 18px;
    font-size: 1.3rem;
    border: 3px solid #fff;
    border-radius: 10px;
    background: rgba(255,255,255,0.9);
    color: #2c3e50;
    text-align: center;
}
.player-input:focus { outline: 4px solid #f39c12; outline-offset: 2px; }

.button-group { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.setting-btn {
    padding: 14px 22px; font-size: 1.15rem;
    border: 3px solid #fff; background: transparent; color: #fff;
    border-radius: 12px; cursor: pointer; transition: all 0.2s;
    min-width: 130px; min-height: 60px;
    display: inline-flex; align-items: center; justify-content: center;
}
.setting-btn:hover { background: rgba(255,255,255,0.2); transform: scale(1.05); }
.setting-btn:focus { outline: 4px solid #f39c12; outline-offset: 2px; }
.setting-btn.active { background: #fff; color: #2c3e50; font-weight: bold; }

.primary-btn {
    margin-top: 20px;
    padding: 20px 50px;
    font-size: 1.8rem;
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    min-height: 70px;
    display: block;
    width: 100%;
}
.primary-btn:hover { background: #c0392b; transform: scale(1.03); box-shadow: 0 5px 20px rgba(231,76,60,0.5); }
.primary-btn:focus { outline: 4px solid #f39c12; outline-offset: 3px; }
.secondary-btn { margin-top: 15px; background: rgba(255,255,255,0.2); border: 3px solid #fff; }
.secondary-btn:hover { background: rgba(255,255,255,0.35); transform: scale(1.03); box-shadow: none; }

.rules-summary {
    background: rgba(255,255,255,0.1); border-radius: 12px;
    padding: 18px 22px; margin: 20px 0; text-align: left;
}
.rules-summary h3 { font-size: 1.3rem; margin-bottom: 10px; }
.rules-summary ul { list-style: none; }
.rules-summary li { font-size: 1.05rem; padding: 5px 0; opacity: 0.9; }
.rules-summary li::before { content: '• '; color: #f39c12; font-weight: bold; }

/* Game Header */
.game-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 25px;
    background: rgba(0,0,0,0.3);
    flex-wrap: wrap; gap: 10px;
    min-height: 80px;
}
.game-header h1 { font-size: 1.8rem; white-space: nowrap; }
.header-left { display: flex; align-items: center; }
.header-center { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.header-right { display: flex; gap: 12px; flex-wrap: wrap; }

/* Player Indicator */
.player-indicator {
    display: flex; align-items: center; gap: 12px;
    background: rgba(255,255,255,0.15);
    padding: 12px 22px;
    border-radius: 12px;
    font-size: 1.4rem;
    font-weight: bold;
    border: 3px solid rgba(255,255,255,0.3);
    transition: all 0.3s;
}
.player-color-dot {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.6);
    flex-shrink: 0;
    transition: all 0.3s;
}
.player-color-dot.white { background: #fff; border-color: #ccc; }
.player-color-dot.black { background: #1a1a1a; border-color: #fff; }
.turn-label { font-weight: normal; opacity: 0.85; }

.check-indicator {
    background: #e74c3c;
    color: #fff;
    padding: 6px 18px;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: bold;
    letter-spacing: 1px;
    animation: pulse 0.5s infinite alternate;
}
@keyframes pulse { from { opacity: 1; } to { opacity: 0.7; } }

/* Action Buttons */
.action-btn {
    padding: 14px 22px;
    font-size: 1.1rem;
    background: rgba(255,255,255,0.9);
    color: #2c3e50;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    min-height: 52px;
    white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.action-btn:hover { background: #fff; transform: scale(1.05); }
.action-btn:focus { outline: 4px solid #f39c12; outline-offset: 2px; }
a.action-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

/* Game Area */
.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px;
    gap: 10px;
    overflow: auto;
}

/* Player Info Panels */
.player-info {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 18px;
    background: rgba(0,0,0,0.2);
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    border: 3px solid transparent;
    transition: all 0.3s;
    min-height: 56px;
}
.player-info.active {
    border-color: #f39c12;
    background: rgba(243,156,18,0.2);
    box-shadow: 0 0 15px rgba(243,156,18,0.4);
}
.player-dot {
    width: 22px; height: 22px;
    border-radius: 50%;
    flex-shrink: 0;
}
.white-dot { background: #fff; border: 3px solid #bbb; }
.black-dot { background: #1a1a1a; border: 3px solid #fff; }
.player-name-display { font-size: 1.2rem; font-weight: bold; }
.captured-pieces {
    display: flex; flex-wrap: wrap; gap: 2px; margin-left: auto;
}
.captured-piece { font-size: 1.1rem; opacity: 0.8; }

/* Board Wrapper */
.board-wrapper { display: flex; flex-direction: column; align-items: center; }
.board-labels {
    display: flex; align-items: center; gap: 0;
    width: 100%;
}
.corner { width: 28px; flex-shrink: 0; }
.col-labels {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    flex: 1;
    text-align: center;
}
.col-labels span { font-size: 1rem; font-weight: bold; opacity: 0.8; padding: 4px 0; }

.board-with-rows { display: flex; align-items: stretch; }
.row-labels {
    display: flex; flex-direction: column;
    width: 28px;
    justify-content: space-around;
    text-align: center;
}
.row-labels span { font-size: 1rem; font-weight: bold; opacity: 0.8; }

/* Chess Board */
.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    border: 4px solid #8B6914;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

/* Squares */
.square {
    width: clamp(48px, 8vw, 72px);
    height: clamp(48px, 8vw, 72px);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    position: relative;
    transition: all 0.1s;
    user-select: none;
}
.square.light { background: #f0d9b5; }
.square.dark  { background: #b58863; }
.square:hover { filter: brightness(1.15); }
.square:focus { outline: 4px solid #f39c12; outline-offset: -4px; z-index: 2; }
.square.selected { background: #7fc97f !important; box-shadow: inset 0 0 0 4px #27ae60; }
.square.last-move { background: rgba(255, 220, 0, 0.45) !important; }
.square.in-check { background: #e74c3c !important; animation: shake 0.3s; }
@keyframes shake {
    0%,100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* Valid move dots */
.square.valid-move::after {
    content: '';
    position: absolute;
    width: 30%; height: 30%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.2);
    pointer-events: none;
}
.square.valid-move.capturable::after {
    width: 100%; height: 100%;
    border-radius: 0;
    background: transparent;
    border: 6px solid rgba(0,0,0,0.25);
}

/* Pieces */
.piece {
    font-size: clamp(28px, 5vw, 44px);
    line-height: 1;
    pointer-events: none;
    transition: transform 0.1s;
    filter: drop-shadow(1px 1px 1px rgba(0,0,0,0.5));
}
.white-piece { color: #fff; text-shadow: 0 0 3px #000, 0 0 6px rgba(0,0,0,0.5); }
.black-piece { color: #1a1a1a; text-shadow: 0 0 2px rgba(255,255,255,0.5); }
.square:hover .piece { transform: scale(1.1); }
.square.selected .piece { transform: scale(1.15); }

/* Promotion Dialog */
.promotion-container {
    background: #34495e;
    border: 4px solid #f39c12;
    border-radius: 20px;
    padding: 35px;
    text-align: center;
    max-width: 450px;
    width: 90%;
}
.promotion-container h2 { font-size: 2rem; margin-bottom: 10px; }
.promotion-container p { font-size: 1.3rem; margin-bottom: 25px; opacity: 0.9; }
.promotion-choices { display: flex; gap: 15px; justify-content: center; flex-wrap: wrap; }
.promotion-btn {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 18px 22px;
    background: rgba(255,255,255,0.15);
    border: 3px solid rgba(255,255,255,0.4);
    border-radius: 12px;
    color: #fff;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 90px; min-height: 100px;
}
.promotion-btn:hover { background: rgba(255,255,255,0.3); transform: scale(1.05); border-color: #f39c12; }
.promotion-btn:focus { outline: 4px solid #f39c12; outline-offset: 2px; }
.promo-symbol { font-size: 2.8rem; }

/* End Screen */
.result-container {
    max-width: 500px;
    margin: auto;
    padding: 60px 40px;
    background: rgba(0,0,0,0.4);
    border-radius: 20px;
    text-align: center;
}
.result-container h1 { font-size: 3rem; margin-bottom: 20px; }
.result-container p { font-size: 1.6rem; margin-bottom: 15px; opacity: 0.9; }

/* Responsive */
@media (max-width: 768px) {
    .game-header { justify-content: center; text-align: center; }
    .header-left { display: none; }
    .header-center { width: 100%; }
    .header-right { width: 100%; justify-content: center; }
    .player-indicator { font-size: 1.2rem; padding: 10px 15px; }
}

@media (max-width: 520px) {
    .col-labels span, .row-labels span { font-size: 0.75rem; }
    .corner { width: 20px; }
    .row-labels { width: 20px; }
    .piece { font-size: clamp(22px, 7vw, 36px); }
}
