:root {
    --bg-primary: #0A0C10;
    --bg-secondary: #111827;
    --grid-line: #1F2937;
    --grid-line-thick: #374151;
    --accent-orange: #FF6B35;
    --accent-cyan: #00F2FF;
    --accent-gold: #FFD700;
    --error: #FF3131;
    --text-primary: #F9FAFB;
    --text-secondary: #9CA3AF;
}

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

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'SF Mono', 'Fira Code', monospace;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--grid-line);
    border-radius: 10px;
}

header h1 {
    font-size: 1.8rem;
    color: var(--accent-orange);
    text-shadow: 0 0 10px rgba(255, 107, 53, 0.5);
    letter-spacing: 2px;
}

.header-controls {
    display: flex;
    gap: 20px;
    align-items: center;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.control-group select {
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--grid-line);
    color: var(--text-primary);
    border-radius: 5px;
    cursor: pointer;
    font-family: inherit;
}

.control-group select:focus {
    outline: none;
    border-color: var(--accent-orange);
}

.sound-group label {
    font-size: 1.2rem;
}

#soundToggle {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.header-corner {
    display: flex;
    align-items: center;
    gap: 10px;
}

#language {
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--grid-line);
    color: var(--text-primary);
    border-radius: 5px;
    cursor: pointer;
    font-family: inherit;
}

.btn-small {
    background: transparent;
    border: 1px solid var(--grid-line);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.2s;
}

.btn-small:hover {
    border-color: var(--accent-orange);
    color: var(--accent-orange);
}

.version {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

main {
    display: grid;
    grid-template-columns: 180px 1fr 180px;
    gap: 15px;
    align-items: start;
}

.history-panel,
.control-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--grid-line);
    border-radius: 10px;
    padding: 15px;
    min-height: 380px;
}

.history-panel h3,
.control-panel h3 {
    text-align: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--grid-line);
    color: var(--accent-cyan);
    font-size: 0.9rem;
}

#moveHistory {
    max-height: 260px;
    overflow-y: auto;
    margin-bottom: 10px;
}

.move-item {
    padding: 4px 8px;
    margin: 2px 0;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    display: flex;
    gap: 8px;
    font-size: 0.8rem;
}

.move-item .move-number {
    color: var(--text-secondary);
    min-width: 25px;
}

.move-item .move-white,
.move-item .move-black {
    flex: 1;
}

.move-item .move-black:empty::before {
    content: "...";
    color: var(--text-secondary);
}

.status {
    padding: 8px;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    font-weight: bold;
    color: var(--accent-gold);
    font-size: 0.85rem;
}

.board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#board {
    width: 100%;
    max-width: 480px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5), 0 0 0 2px var(--grid-line);
}

#board .white-1e1d7 {
    background: #1a1a2e;
}

#board .black-3c85d {
    background: #0d0d1a;
}

#board img {
    filter: drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.8));
}

.highlight {
    box-shadow: inset 0 0 10px 3px rgba(0, 242, 255, 0.6);
}

#board .selected {
    background: rgba(0, 242, 255, 0.4) !important;
}

#board .last-move {
    background: rgba(255, 215, 0, 0.2) !important;
}

#board .valid-move {
    position: relative !important;
}

#board .valid-move::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30%;
    height: 30%;
    background: rgba(0, 242, 255, 0.6);
    border-radius: 50%;
    pointer-events: none;
}

#board .valid-move.castling {
    background: rgba(255, 107, 53, 0.4) !important;
}

.thinking {
    margin-top: 15px;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-orange);
    border-radius: 20px;
    font-size: 0.95rem;
    color: var(--accent-orange);
    animation: pulse 1.5s ease-in-out infinite;
}

.thinking.hidden {
    display: none;
}

.toast {
    position: fixed;
    bottom: 20%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--accent-orange);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.95rem;
    z-index: 1000;
    animation: toastFade 1.5s ease-in-out forwards;
}

.toast.hidden {
    display: none;
}

@keyframes toastFade {
    0% { opacity: 0; transform: translateX(-50%) translateY(20px); }
    15% { opacity: 1; transform: translateX(-50%) translateY(0); }
    85% { opacity: 1; transform: translateX(-50%) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

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

.btn {
    width: 100%;
    padding: 10px 12px;
    margin: 5px 0;
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: bold;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--grid-line);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn:hover {
    border-color: var(--accent-orange);
    color: var(--accent-orange);
}

.btn:active {
    transform: translateY(0);
}

.btn.primary {
    background: var(--accent-orange);
    color: #000;
    border-color: var(--accent-orange);
    padding: 12px 16px;
}

.btn.primary:hover {
    background: #ff8555;
    box-shadow: 0 0 15px rgba(255, 107, 53, 0.5);
}

.game-info {
    margin-top: 15px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--grid-line);
    font-size: 0.85rem;
}

.info-row:last-child {
    border-bottom: none;
}

.info-row span:first-child {
    color: var(--text-secondary);
}

.info-row span:last-child {
    color: var(--accent-cyan);
    font-weight: bold;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    border: 2px solid var(--accent-orange);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 107, 53, 0.3);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-content h2 {
    color: var(--accent-gold);
    margin-bottom: 15px;
    font-size: 1.5rem;
}

.modal-content p {
    font-size: 1rem;
    margin-bottom: 20px;
    color: var(--text-secondary);
}

.promotion-content {
    padding: 20px;
    min-width: 220px;
}

.promotion-content h3 {
    color: var(--accent-gold);
    margin-bottom: 15px;
    text-align: center;
}

#promotionOptions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.promotion-btn {
    width: 50px;
    height: 50px;
    padding: 5px;
    background: var(--bg-primary);
    border: 1px solid var(--grid-line);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.promotion-btn:hover {
    border-color: var(--accent-orange);
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255, 107, 53, 0.5);
}

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

@media (max-width: 900px) {
    main {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .board-section {
        order: 1;
    }
    
    .history-panel,
    .control-panel {
        order: 2;
        padding: 10px;
        min-height: auto;
    }
    
    #board {
        max-width: 350px;
    }
    
    header {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }
    
    header h1 {
        font-size: 1.4rem;
    }
    
    .header-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .control-group select {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
}

@media (max-width: 500px) {
    .container {
        padding: 8px;
    }
    
    header {
        padding: 8px;
    }
    
    header h1 {
        font-size: 1.2rem;
    }
    
    .header-controls {
        gap: 8px;
    }
    
    .control-group label {
        font-size: 0.75rem;
    }
    
    .control-group select {
        padding: 4px 8px;
        font-size: 0.7rem;
    }
    
    #board {
        max-width: calc(100vw - 16px);
    }
    
    .history-panel,
    .control-panel {
        padding: 8px;
    }
    
    .history-panel h3,
    .control-panel h3 {
        font-size: 0.8rem;
    }
    
    #moveHistory {
        max-height: 60px;
    }
    
    .move-item {
        font-size: 0.75rem;
    }
    
    .btn {
        padding: 8px 10px;
        font-size: 0.75rem;
    }
    
    .btn.primary {
        padding: 10px 12px;
    }
    
    .info-row {
        font-size: 0.75rem;
    }
}
