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

body {
    background: #1a1a2e;
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
    color: #e0e0e0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    overflow-x: hidden;
}

.container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    align-items: start;
}

.game-history {
    background: #16213e;
    border-radius: 20px;
    padding: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    overflow-x: auto;
}

.game-history h3 {
    font-size: 1.2rem;
    margin-bottom: 12px;
    color: #e2b04a;
    display: flex;
    align-items: center;
    gap: 8px;
    border-left: 3px solid #e2b04a;
    padding-left: 12px;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.history-table th,
.history-table td {
    padding: 6px 8px;
    text-align: center;
    border-bottom: 1px solid #2a2a4a;
}

.history-table th {
    color: #c0c0e0;
    font-weight: 500;
    background: #0f0f2a;
}

.history-table td {
    font-family: monospace;
    letter-spacing: 0.5px;
}

.move-white {
    color: #f0f0f0;
    font-weight: 500;
}

.move-black {
    color: #b0b0d0;
}

.game-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
}

.bot-selector-panel {
    background: #16213e;
    border-radius: 20px;
    padding: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.bot-selector-panel h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: #e2b04a;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.depth-select {
    width: 100%;
    background: #0f0f2a;
    border: 1px solid #2e3a5e;
    color: white;
    padding: 10px 12px;
    border-radius: 40px;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: 0.2s;
}

.depth-select:hover {
    border-color: #e2b04a;
}

.info-panel {
    background: #16213e;
    border-radius: 20px;
    padding: 12px 20px;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    width: 100%;
    max-width: 560px;
}

.status {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    color: #e2b04a;
}

.status.check {
    color: #ff5252;
    animation: pulse 0.8s infinite;
}

.status.mate {
    color: #4caf50;
}

.status.draw {
    color: #ff9800;
}

.subtitle {
    font-size: 0.85rem;
    color: #a0a0b8;
    margin-top: 4px;
}

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

.board-wrapper {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
    width: min(70vmin, 560px);
    height: min(70vmin, 560px);
    flex-shrink: 0;
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(min(70vmin, 560px) / 8 * 0.68);
    transition: background 0.12s;
    aspect-ratio: 1;
}

.cell.light { background-color: #f0d9b5; }
.cell.dark { background-color: #b58863; }
.cell.selected { background-color: rgba(255, 215, 0, 0.7) !important; }
.cell.last-move-from, .cell.last-move-to { background-color: rgba(255, 255, 100, 0.5) !important; }
.cell.valid-move::after {
    content: '';
    position: absolute;
    width: 28%;
    height: 28%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.3);
    pointer-events: none;
}
.cell.valid-capture::after {
    content: '';
    position: absolute;
    width: 86%;
    height: 86%;
    border-radius: 50%;
    border: 4px solid rgba(220, 50, 50, 0.7);
    pointer-events: none;
}
.cell.in-check {
    background: rgba(255, 60, 60, 0.8) !important;
    animation: checkGlow 1s infinite;
}

@keyframes checkGlow {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.2); }
}

.piece {
    pointer-events: none;
    line-height: 1;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4));
}

.piece-white { color: #ffffff; text-shadow: 0 0 4px #000; }
.piece-black { color: #1a1a1a; text-shadow: 0 0 3px #fff; }

.controls {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    max-width: 560px;
}

.btn {
    padding: 10px 22px;
    border: none;
    border-radius: 40px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-new {
    background: #e2b04a;
    color: #1a1a2e;
}
.btn-new:hover { background: #f0c860; transform: translateY(-2px); }
.btn-undo {
    background: transparent;
    color: #e0e0e0;
    border: 2px solid #444;
}
.btn-undo:hover { border-color: #aaa; background: rgba(255,255,255,0.05); }
.btn-undo:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

.promotion-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
    border-radius: 16px;
}

.promotion-box {
    background: #16213e;
    border-radius: 30px;
    padding: 20px 28px;
    display: flex;
    gap: 20px;
    box-shadow: 0 20px 40px black;
}

.promo-btn {
    font-size: 2.5rem;
    background: none;
    border: 2px solid transparent;
    border-radius: 16px;
    cursor: pointer;
    padding: 8px 14px;
    transition: 0.1s;
    color: #eee;
}
.promo-btn:hover { border-color: #e2b04a; transform: scale(1.1); }

.offline-badge {
    font-size: 0.7rem;
    padding: 3px 12px;
    border-radius: 20px;
    background: #2a2a4a;
    color: #aaa;
    display: none;
}
.offline-badge.visible { display: inline-block; }

@media (min-width: 901px) {
    .container {
        grid-template-columns: 280px minmax(380px, 580px) 260px;
        gap: 24px;
    }
    .game-history { order: 1; }
    .game-center { order: 2; }
    .bot-selector-panel { order: 3; }
}

@media (max-width: 900px) {
    .container {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }
    .game-history { order: 3; width: 100%; }
    .bot-selector-panel { order: 1; width: 100%; }
    .game-center { order: 2; }
    .board-wrapper {
        width: min(92vmin, 480px);
        height: min(92vmin, 480px);
    }
    .status { font-size: 1.1rem; }
    .btn { padding: 8px 16px; }
    .history-table th, .history-table td {
        padding: 4px 6px;
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    .promo-btn { font-size: 1.8rem; padding: 4px 10px; }
}