* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    overflow-x: hidden;
    overflow-y: auto;
}

.container {
    max-width: 1400px;
    width: 100%;
    min-height: 95vh;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: visible;
    display: flex;
    flex-direction: column;
    margin: 20px 0;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.9;
}

.screen {
    display: none;
    padding: 20px;
    flex: 1;
    overflow: visible;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* Prevent auto-scroll on content changes */
.screen.active * {
    scroll-margin-top: 0;
}

/* Mode Selection */
#mode-selection h2,
#difficulty-selection h2,
#timer-selection h2 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 1.8em;
}

.mode-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
}

.mode-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 15px;
    padding: 40px;
    width: 280px;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.mode-btn:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
}

.mode-btn .icon {
    font-size: 4em;
}

.mode-btn .mode-title {
    font-size: 1.5em;
    font-weight: bold;
}

.mode-btn .mode-desc {
    font-size: 1em;
    opacity: 0.9;
}

/* Timer Options */
.timer-options {
    display: flex;
    flex-direction: column;
    gap: 30px;
    align-items: center;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

.timer-preset-buttons {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.preset-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 20px 25px;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 100px;
}

.preset-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.preset-btn:active {
    transform: translateY(0);
}

.time-value {
    font-size: 1.5em;
    font-weight: bold;
}

.time-desc {
    font-size: 0.9em;
    opacity: 0.9;
}

.custom-timer-input {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 15px;
    padding: 30px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.custom-timer-input h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.2em;
}

.time-input-group {
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: center;
    margin-bottom: 20px;
}

.time-input-group input {
    width: 120px;
    padding: 15px;
    font-size: 1.3em;
    border: 2px solid #667eea;
    border-radius: 10px;
    text-align: center;
    font-weight: bold;
    transition: border-color 0.3s;
}

.time-input-group input:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.3);
}

.time-input-group label {
    font-size: 1.1em;
    color: #2c3e50;
    font-weight: 500;
}

/* Player Names Screen */
.player-name-form {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 15px;
    padding: 30px;
    width: 100%;
    max-width: 450px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.name-input-group {
    margin-bottom: 25px;
}

.name-input-group label {
    display: block;
    font-size: 1.1em;
    color: #2c3e50;
    font-weight: 600;
    margin-bottom: 10px;
    text-align: left;
}

.name-setup-input {
    width: 100%;
    padding: 15px;
    font-size: 1.1em;
    border: 2px solid #667eea;
    border-radius: 10px;
    text-align: center;
    background: white;
    color: #2c3e50;
    font-weight: 500;
    transition: all 0.3s ease;
    outline: none;
}

.name-setup-input:focus {
    border-color: #764ba2;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.4);
    transform: scale(1.02);
}

.name-setup-input::placeholder {
    color: #95a5a6;
    font-weight: 400;
}

.name-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
}

.name-buttons .control-btn {
    flex: 1;
    max-width: 180px;
}

/* Game Screen */
#game-screen {
    padding: 15px !important;
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 15px;
}

.turn-indicator {
    font-size: 1.5em;
    font-weight: bold;
    color: #667eea;
    padding: 15px 30px;
    background: #f0f0f0;
    border-radius: 10px;
}

.game-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.control-btn {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    cursor: pointer;
    font-size: 1em;
    transition: background 0.3s, transform 0.2s;
}

.control-btn:hover {
    background: #764ba2;
    transform: scale(1.05);
}

.control-btn:active {
    transform: scale(0.95);
}

/* Game Container */
.game-container {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: nowrap;
    flex: 1;
    overflow: visible;
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 180px;
    max-width: 220px;
}

.timer-section {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.timer-section h3 {
    color: #2c3e50;
    margin-bottom: 12px;
    font-size: 1em;
    text-align: center;
    font-weight: 600;
}

.player-info {
    margin: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.player-name-input {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid #667eea;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 500;
    text-align: center;
    background: white;
    color: #2c3e50;
    transition: all 0.3s ease;
    outline: none;
}

.player-name-input:focus {
    border-color: #764ba2;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.3);
    transform: scale(1.02);
}

.player-name-input::placeholder {
    color: #95a5a6;
    font-weight: 400;
}

.timer {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px;
    border-radius: 10px;
    font-size: 1.3em;
    font-weight: bold;
    text-align: center;
    font-family: 'Courier New', monospace;
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
    transition: all 0.3s ease;
}

.timer.active {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    box-shadow: 0 0 25px rgba(245, 87, 108, 0.6);
    transform: scale(1.05);
}

.move-history {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    border-radius: 12px;
    padding: 15px;
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    scroll-behavior: smooth;
}

/* Custom scrollbar for move history */
.move-history::-webkit-scrollbar {
    width: 6px;
}

.move-history::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

.move-history::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 10px;
}

.move-history::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.8);
}

.move-history h3 {
    color: #2c3e50;
    margin-bottom: 12px;
    font-size: 1em;
    text-align: center;
    font-weight: 600;
}

#move-history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-row {
    display: grid;
    grid-template-columns: 35px 1fr 1fr;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 6px;
    font-size: 0.9em;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.history-row:hover {
    background: white;
    border-left-color: #667eea;
    transform: translateX(3px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.move-num {
    font-weight: bold;
    color: #667eea;
}

.move-white {
    color: #333;
}

.move-black {
    color: #666;
}

.captured-pieces {
    background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.captured-pieces h3 {
    color: #2c3e50;
    margin-bottom: 12px;
    font-size: 1em;
    font-weight: 600;
}

#black-captured-list,
#white-captured-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 1.3em;
    min-height: 25px;
    background: rgba(255, 255, 255, 0.5);
    padding: 8px;
    border-radius: 6px;
}

/* Chess Board */
.chess-board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 70px);
    grid-template-rows: repeat(8, 70px);
    border: 3px solid #333;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    border-radius: 5px;
    overflow: hidden;
}

/* Pause Overlay */
.pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    border-radius: 5px;
    backdrop-filter: blur(5px);
}

.pause-overlay.active {
    display: flex;
}

.pause-message {
    background: white;
    padding: 30px 50px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.pause-message h2 {
    font-size: 2.5em;
    margin-bottom: 10px;
    color: #667eea;
}

.pause-message p {
    font-size: 1.2em;
    color: #666;
}

.square {
    width: 70px;
    height: 70px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3em;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.square.light {
    background: #f0d9b5;
}

.square.dark {
    background: #b58863;
}

.square:hover {
    opacity: 0.8;
}

.square.selected {
    background: #7fc97f !important;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
}

.square.valid-move {
    background: #ffd700 !important;
}

.square.valid-move::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: rgba(0, 128, 0, 0.5);
    border-radius: 50%;
}

.square.last-move {
    background: #aaffaa !important;
}

.coordinates {
    margin-top: 10px;
}

.coord-row {
    display: flex;
    gap: 0;
}

.coord-row span {
    width: 70px;
    text-align: center;
    font-weight: bold;
    color: #333;
    font-size: 1.1em;
}

/* Message Box */
.message-box {
    margin-top: 30px;
    padding: 20px;
    background: #f0f0f0;
    border-radius: 10px;
    min-height: 60px;
    font-size: 1.1em;
    color: #333;
    text-align: center;
}

.message-box.success {
    background: #d4edda;
    color: #155724;
}

.message-box.error {
    background: #f8d7da;
    color: #721c24;
}

.message-box.info {
    background: #d1ecf1;
    color: #0c5460;
}

.message-box.warning {
    background: #fff3cd;
    color: #856404;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 15px;
    max-width: 600px;
    width: 90%;
    position: relative;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    color: #333;
    margin-bottom: 20px;
    text-align: center;
}

.modal-content p {
    color: #666;
    margin-bottom: 30px;
    text-align: center;
    font-size: 1.1em;
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 2em;
    cursor: pointer;
    color: #999;
}

.close:hover {
    color: #333;
}

/* Promotion Modal */
.promotion-choices {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.promotion-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 20px;
    cursor: pointer;
    transition: transform 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-width: 100px;
}

.promotion-btn:hover {
    transform: scale(1.1);
}

.piece-large {
    font-size: 3em;
}

/* Score Modal */
#score-content {
    color: #333;
    line-height: 1.8;
}

#score-content h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: #667eea;
}

/* Difficulty buttons */
.difficulty-btn {
    max-width: 250px;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .game-container {
        flex-direction: column;
        align-items: center;
    }
    
    .side-panel {
        flex-direction: row;
        max-width: 100%;
        width: 100%;
        justify-content: space-around;
    }
    
    .timer-section,
    .move-history,
    .captured-pieces {
        flex: 1;
        min-width: 150px;
    }
}

@media (max-width: 768px) {
    .chess-board {
        grid-template-columns: repeat(8, 50px);
        grid-template-rows: repeat(8, 50px);
    }
    
    .square {
        width: 50px;
        height: 50px;
        font-size: 2.5em;
    }
    
    .coord-row span {
        width: 50px;
    }
    
    .game-container {
        flex-direction: column;
        align-items: center;
    }
    
    .side-panel {
        flex-direction: column;
        width: 100%;
        max-width: 400px;
    }
    
    .captured-pieces {
        width: 100%;
    }
    
    header h1 {
        font-size: 2em;
    }
    
    .mode-btn {
        width: 100%;
        max-width: 300px;
    }
    
    .game-controls {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .chess-board {
        grid-template-columns: repeat(8, 45px);
        grid-template-rows: repeat(8, 45px);
    }
    
    .square {
        width: 45px;
        height: 45px;
        font-size: 2.2em;
    }
    
    .coord-row span {
        width: 40px;
        font-size: 0.9em;
    }
    
    .screen {
        padding: 20px;
    }
    
    .game-controls {
        justify-content: center;
    }
    
    .control-btn {
        padding: 10px 15px;
        font-size: 0.9em;
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.square.check {
    animation: pulse 1s infinite;
    background: #ff6b6b !important;
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}