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

html {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    background: #E6E9F3;
    background: linear-gradient(135deg, #E6E9F3 0%, #ECEEF9 100%);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #E6E9F3;
    background: linear-gradient(135deg, #E6E9F3 0%, #ECEEF9 100%);
    min-height: 100vh;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* Responsive layout classes */
.compact-only {
    display: flex !important;
}

.large-only {
    display: none !important;
}

.container {
    width: 100%;
    max-width: 650px;
    height: calc(100% - 20px);
    background: transparent;
    border-radius: 0;
    padding: 15px;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    touch-action: pan-y;
    position: relative;
}

/* Board Control Bar (top, compact layout) */
.board-control-bar {
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    padding: 8px 0;
    background: transparent;
    border-radius: 0;
    margin-bottom: 8px;
    border: none;
    box-shadow: none;
    position: fixed;
    top: 30px;
    right: 20px;
    left: 20px;
    max-width: 610px;
    margin-left: auto;
    margin-right: auto;
    z-index: 10;
}

.top-controls-container {
    display: flex;
    gap: 0;
    align-items: center;
    background: #E6E9F3;
    border-radius: 24px;
    padding: 3px 6px;
    box-shadow: 
        4px 4px 8px rgba(163, 177, 198, 0.3),
        -4px -4px 8px rgba(255, 255, 255, 0.6);
    position: relative;
}

.top-controls-container::after {
    content: '';
    position: absolute;
    width: 1px;
    height: 20px;
    background: linear-gradient(to bottom, 
        transparent, 
        rgba(163, 177, 198, 0.4) 20%, 
        rgba(163, 177, 198, 0.4) 80%, 
        transparent
    );
    left: 50%;
    transform: translateX(-0.5px);
    top: 50%;
    margin-top: -10px;
}

.control-btn-icon {
    width: 44px;
    height: 36px;
    padding: 0;
    font-size: 19px;
    border: none;
    border-radius: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    color: rgba(163, 177, 198, 0.75);
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    position: relative;
    font-weight: 200;
}

.control-btn-icon i {
    filter: drop-shadow(0 1px 2px rgba(163, 177, 198, 0.3));
}

.control-btn-icon:hover {
    background: rgba(163, 177, 198, 0.12);
    color: #5A6A8A;
}

.control-btn-icon:active {
    background: rgba(163, 177, 198, 0.08);
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.2),
        inset -2px -2px 4px rgba(255, 255, 255, 0.4);
}

.control-btn-icon.active {
    color: #667eea;
}

/* Popup Menu */
.popup-menu {
    position: absolute;
    top: 60px;
    right: 55px;
    background: #E6E9F3;
    border-radius: 16px;
    padding: 8px;
    box-shadow: 
        6px 6px 12px rgba(163, 177, 198, 0.4),
        -6px -6px 12px rgba(255, 255, 255, 0.7);
    z-index: 1000;
    min-width: 180px;
    animation: popupSlideIn 0.2s ease;
}

.popup-menu.hidden {
    display: none;
}

@keyframes popupSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.popup-menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 400;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    color: #6B7A99;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
    margin-bottom: 4px;
}

.popup-menu-item:last-child {
    margin-bottom: 0;
}

.popup-menu-item:hover {
    background: #E6E9F3;
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.3),
        -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.popup-menu-item:active {
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.popup-menu-item i {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

/* Legacy control buttons (kept for board setup bar in edit mode) */
.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 14px;
    font-size: 15px;
    font-weight: 400;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #E6E9F3;
    color: #6B7A99;
    -webkit-tap-highlight-color: transparent;
    flex: 1;
    min-width: 0;
    box-shadow: 
        3px 3px 6px rgba(163, 177, 198, 0.3),
        -3px -3px 6px rgba(255, 255, 255, 0.6);
}

.control-btn:hover {
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.3),
        -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.control-btn:active {
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.control-btn .btn-label {
    font-size: 13px;
}

.control-btn-small {
    width: 48px;
    height: 48px;
    padding: 0;
    font-size: 18px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #E6E9F3;
    color: #6B7A99;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        4px 4px 8px rgba(163, 177, 198, 0.3),
        -4px -4px 8px rgba(255, 255, 255, 0.6);
}

.control-btn-small:hover:not(:disabled) {
    box-shadow: 
        3px 3px 6px rgba(163, 177, 198, 0.3),
        -3px -3px 6px rgba(255, 255, 255, 0.6);
}

.control-btn-small:active:not(:disabled) {
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.control-btn-small:disabled {
    background: #E6E9F3;
    cursor: not-allowed;
    opacity: 0.4;
    color: #A3B1C6;
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.15),
        -2px -2px 4px rgba(255, 255, 255, 0.4);
}

/* Game Control Bar (bottom, compact layout, play mode) */
.game-control-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: #E6E9F3;
    border-radius: 16px;
    margin-top: 16px;
    border: none;
    box-shadow: 
        5px 5px 10px rgba(163, 177, 198, 0.3),
        -5px -5px 10px rgba(255, 255, 255, 0.6);
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    max-width: 610px;
    margin-left: auto;
    margin-right: auto;
}

.turn-display {
    flex: 1;
    text-align: left;
}

.turn-indicator {
    cursor: pointer;
    padding: 10px 16px;
    border-radius: 12px;
    transition: all 0.2s ease;
    user-select: none;
    font-weight: 600;
    font-size: 16px;
    color: #6B7A99;
    display: inline-block;
    background: #E6E9F3;
    box-shadow: 
        3px 3px 6px rgba(163, 177, 198, 0.3),
        -3px -3px 6px rgba(255, 255, 255, 0.6);
}

.turn-indicator:hover {
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.3),
        -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.turn-indicator:active {
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.history-controls {
    display: flex;
    gap: 8px;
}

.engine-score-display {
    flex: 1;
    text-align: right;
}

.engine-score-compact {
    font-size: 18px;
    font-weight: bold;
    color: #6B7A99;
    padding: 10px 16px;
    background: #E6E9F3;
    border-radius: 12px;
    display: inline-block;
    min-width: 70px;
    text-align: center;
    box-shadow: 
        inset 3px 3px 6px rgba(163, 177, 198, 0.25),
        inset -3px -3px 6px rgba(255, 255, 255, 0.5);
}

.engine-score-compact .loading-spinner,
.engine-score-inline .loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: #6B7A99;
    border-right-color: #6B7A99;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Board Setup Bar (bottom, compact layout, edit mode) */
.board-setup-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 14px 12px;
    background: #E6E9F3;
    border-radius: 16px;
    margin-top: 8px;
    border: none;
    gap: 10px;
    box-shadow: 
        5px 5px 10px rgba(163, 177, 198, 0.3),
        -5px -5px 10px rgba(255, 255, 255, 0.6);
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    max-width: 610px;
    margin-left: auto;
    margin-right: auto;
}

/* Media query for large screens (at least 2.5x board width) */
/* Assuming max board width is 600px, 2.5x = 1500px */
@media (min-width: 1500px) {
    .compact-only {
        display: none !important;
    }
    
    .large-only {
        display: flex !important;
    }
    
    body {
        align-items: center;
        padding: 20px;
    }
    
    .container {
        max-width: 1400px;
        height: auto;
        max-height: calc(100% - 40px);
        display: grid;
        grid-template-columns: 600px 1fr;
        grid-template-rows: 1fr;
        gap: 40px;
        padding: 40px;
        align-items: center;
        background: transparent;
    }
    
    #board {
        grid-column: 1;
        grid-row: 1;
        margin: 0 !important;
        width: 100%;
        max-width: 600px;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }
    
    .status {
        grid-column: 2;
        grid-row: 1;
        width: 100%;
        padding: 24px;
        max-width: 600px;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
        text-align: left;
        gap: 20px;
    }
    
    /* Top row: Undo/Redo left, Engine Score center, Toggle right */
    .status-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 20px;
        border-bottom: 2px solid rgba(163, 177, 198, 0.3);
        margin-bottom: 0;
    }
    
    .status-header .history-controls-inline {
        display: flex;
        gap: 12px;
    }
    
    .status-header .history-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
    
    .status-header .mode-section {
        display: flex;
        align-items: center;
        gap: 15px;
    }
    
    /* Engine score in header for large layout */
    .status-header .engine-status-item {
        display: flex;
        align-items: center;
        gap: 8px;
        justify-content: center;
    }
    
    .status-header .engine-score-inline {
        font-size: 20px;
        font-weight: bold;
        color: #6B7A99;
        padding: 8px 16px;
        background: #E6E9F3;
        border-radius: 12px;
        min-width: 80px;
        text-align: center;
        box-shadow: 
            inset 3px 3px 6px rgba(163, 177, 198, 0.25),
            inset -3px -3px 6px rgba(255, 255, 255, 0.5);
    }
    
    /* Two columns below divider */
    .status-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 30px;
        align-items: start;
    }
    
    .status-column-left,
    .status-column-right {
        display: flex;
        flex-direction: column;
        gap: 16px;
        width: 100%;
        min-width: 0;
    }
    
    .status-column-left {
        grid-column: 1;
    }
    
    .status-column-right {
        grid-column: 2;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
        align-items: start;
    }
    
    .status-item {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
    }
    
    /* Remove inline history controls from left column in large layout */
    .status-column-left .history-controls-inline {
        display: none;
    }
    
    .status-item strong {
        min-width: 70px;
    }
    
    .status-item-label {
        margin-top: 0;
        margin-left: 0;
        font-size: 13px;
    }
    
    /* Action buttons in right column */
    .status-column-right .status-item {
        flex-direction: column;
        align-items: center;
        gap: 8px;
        justify-content: flex-start;
    }
    
    .status-column-right .settings-btn {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }
    
    /* Engine score item should be hidden in status-column-right for large layout */
    .status-column-right .engine-status-item {
        display: none;
    }
    
    .engine-toggle-inline {
        width: 40px;
    }
    
    .settings-btn {
        width: 40px;
    }
}

.mode-section {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 15px;
    flex-shrink: 0;
}

.engine-section {
    display: flex;
    justify-content: center;
    margin-bottom: 25px;
}

.engine-toggle-inline {
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 16px;
    border: 2px solid #6c757d;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    color: #6c757d;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.engine-toggle-inline:hover {
    background: #f8f9fa;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.engine-toggle-inline:active {
    transform: translateY(1px);
}

.engine-toggle-inline.active {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

.engine-toggle-inline:disabled {
    background: #e9ecef;
    cursor: not-allowed;
    opacity: 0.6;
}

.engine-score-inline {
    font-size: 16px;
    font-weight: bold;
    color: #6B7A99;
    margin-left: 8px;
    padding: 4px 10px;
    background: #E6E9F3;
    border-radius: 8px;
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.25),
        inset -2px -2px 4px rgba(255, 255, 255, 0.5);
}

.engine-status-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.mode-label {
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #A3B1C6;
}

.mode-label.active {
    color: #6B7A99;
}

.toggle-switch {
    position: relative;
    width: 60px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #E6E9F3;
    transition: 0.4s;
    border-radius: 34px;
    box-shadow: 
        inset 3px 3px 6px rgba(163, 177, 198, 0.25),
        inset -3px -3px 6px rgba(255, 255, 255, 0.5);
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: #E6E9F3;
    transition: 0.4s;
    border-radius: 50%;
    box-shadow: 
        3px 3px 6px rgba(163, 177, 198, 0.3),
        -3px -3px 6px rgba(255, 255, 255, 0.6);
}

input:checked + .slider:before {
    transform: translateX(32px);
}

#board {
    width: 100%;
    max-width: 550px;
    margin: 0 auto;
    flex-shrink: 0;
    touch-action: none;
    border: none !important;
}

/* Reduce board top margin in edit mode to make room for spare pieces */
.edit-mode #board {
    transform: translate(0px, -40px);
    margin-bottom: -40px;
}

/* Remove border from chessboard library */
#board .board-b72b1,
#board > div {
    border: none !important;
}

/* Reduce piece size to fit better in squares - only for pieces on the board, not spare pieces */
#board .board-b72b1 img,
#board [class*="square-"] img {
    width: 80% !important;
    height: 80% !important;
    position: relative !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
}

/* Limit spare pieces size in edit mode */
.spare-pieces-7492f,
.spare-pieces-bottom,
.spare-pieces-top,
[class*="spare-pieces"] {
    max-width: 100% !important;
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    padding: 15px 10px !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 10px auto !important;
    clear: both !important;
    float: none !important;
}

.spare-pieces-top,
[class*="spare-pieces-top"] {
    margin-bottom: 15px !important;
}

.spare-pieces-bottom,
[class*="spare-pieces-bottom"] {
    margin-top: 15px !important;
}

.spare-pieces-7492f img,
.spare-pieces-bottom img,
.spare-pieces-top img,
[class*="spare-pieces"] img {
    max-width: 40px !important;
    max-height: 40px !important;
    width: 40px !important;
    height: 40px !important;
    position: static !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    cursor: pointer !important;
    display: block !important;
}

.engine-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
}

.main-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.main-actions button {
    padding: 16px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #6B7A99;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    -webkit-tap-highlight-color: transparent;
    background: #E6E9F3;
    box-shadow: 
        4px 4px 8px rgba(163, 177, 198, 0.3),
        -4px -4px 8px rgba(255, 255, 255, 0.6);
}

.main-actions button:hover:not(:disabled) {
    box-shadow: 
        3px 3px 6px rgba(163, 177, 198, 0.3),
        -3px -3px 6px rgba(255, 255, 255, 0.6);
}

.main-actions button:active:not(:disabled) {
    box-shadow: 
        inset 3px 3px 6px rgba(163, 177, 198, 0.3),
        inset -3px -3px 6px rgba(255, 255, 255, 0.6);
}

.main-actions button:disabled {
    background: #E6E9F3;
    cursor: not-allowed;
    opacity: 0.4;
    color: #A3B1C6;
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.15),
        -2px -2px 4px rgba(255, 255, 255, 0.4);
}

.edit-only {
    display: flex;
}

.edit-only.hidden {
    display: none !important;
}

.play-only {
    display: flex;
}

.play-only.hidden {
    display: none !important;
}

.history-section {
    display: none; /* Buttons moved to status bar */
}

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

/* Large layout history controls (large screens only) */
.large-only .history-controls {
    gap: 20px;
}
.large-only .history-controls button {
    width: 60px;
    height: 60px;
    padding: 0;
    font-size: 32px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #495057;
    background: #f8f9fa;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.large-only .history-controls button:hover:not(:disabled) {
    background: #e9ecef;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.large-only .history-controls button:active:not(:disabled) {
    transform: scale(1.05);
}

.large-only .history-controls button:disabled {
    background: #f8f9fa;
    cursor: not-allowed;
    opacity: 0.3;
    color: #adb5bd;
}

.status {
    text-align: left;
    padding: 20px;
    background: #E6E9F3;
    border-radius: 20px;
    font-size: 13px;
    color: #6B7A99;
    border: none;
    flex-shrink: 0;
    width: 100%;
    box-shadow: 
        6px 6px 12px rgba(163, 177, 198, 0.3),
        -6px -6px 12px rgba(255, 255, 255, 0.6);
}

.status-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(163, 177, 198, 0.2);
}

.status-row {
    display: flex;
    justify-content: flex-start;
    gap: 20px;
    flex-wrap: nowrap;
    margin-bottom: 8px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status strong {
    color: #4A5568;
    font-weight: 700;
}

.status-value {
    color: #6B7A99;
    font-weight: 600;
}

.turn-indicator-container .turn-indicator {
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 10px;
    transition: all 0.2s ease;
    user-select: none;
    background: #E6E9F3;
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.3),
        -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.turn-indicator-container .turn-indicator:hover {
    box-shadow: 
        1px 1px 2px rgba(163, 177, 198, 0.3),
        -1px -1px 2px rgba(255, 255, 255, 0.6);
}

.turn-indicator-container .turn-indicator:active {
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.25),
        inset -2px -2px 4px rgba(255, 255, 255, 0.5);
}

#gameStatus {
    margin-top: 8px;
    font-size: 16px;
    font-weight: 600;
    color: #667eea;
}

.highlight-square {
    box-shadow: inset 0 0 4px 4px rgba(255, 193, 7, 0.8) !important;
}

.highlight-selected {
    box-shadow: inset 0 0 6px 6px rgba(33, 150, 243, 0.9) !important;
}

.highlight-legal-move {
    box-shadow: inset 0 0 4px 4px rgba(76, 175, 80, 0.6) !important;
}

.highlight-check {
    box-shadow: inset 0 0 5px 5px rgba(244, 67, 54, 0.9) !important;
}

#arrow-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

/* Hide arrows in edit mode */
.edit-mode #arrow-overlay {
    display: none;
}

@media (max-width: 600px) {
    body {
        padding: 5px;
    }

    .container {
        padding: 10px;
        border-radius: 15px;
        height: calc(100% - 10px);
    }

    .board-control-bar,
    .game-control-bar,
    .board-setup-bar {
        padding: 10px;
        margin-bottom: 10px;
        margin-top: 10px;
    }

    .control-btn {
        padding: 8px 10px;
        font-size: 14px;
    }

    .control-btn .btn-label {
        font-size: 12px;
    }

    .control-btn-small {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .turn-indicator {
        font-size: 14px;
        padding: 6px 10px;
    }

    .engine-score-compact {
        font-size: 16px;
        padding: 6px 10px;
        min-width: 50px;
    }

    .status {
        padding: 10px;
        font-size: 12px;
    }

    .status-header {
        margin-bottom: 10px;
        padding-bottom: 10px;
    }

    .mode-label {
        font-size: 11px;
    }

    .toggle-switch {
        width: 50px;
        height: 24px;
    }

    .slider:before {
        height: 18px;
        width: 18px;
    }

    input:checked + .slider:before {
        transform: translateX(26px);
    }

    .status-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        align-items: start;
    }

    .status-column-left {
        grid-column: 1;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .status-column-right {
        grid-column: 2;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .history-controls-inline {
        flex-direction: row;
        gap: 6px;
    }

    #board {
        margin-bottom: 10px;
    }
}

@media (max-width: 400px) {
    .main-actions {
        grid-template-columns: 1fr;
    }

    .control-btn .btn-label {
        display: none;
    }

    .board-setup-bar .btn-label {
        display: none;
    }

    .status-row {
        flex-direction: column;
        gap: 8px;
    }
}

button {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.settings-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 16px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #E6E9F3;
    color: #6B7A99;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        3px 3px 6px rgba(163, 177, 198, 0.3),
        -3px -3px 6px rgba(255, 255, 255, 0.6);
}

.settings-btn:hover {
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.3),
        -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.settings-btn:active {
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.edit-only .settings-btn {
    background: #E6E9F3;
    color: #6B7A99;
}

.edit-only .settings-btn:hover {
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.3),
        -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.status-item button {
    flex-shrink: 0;
}

.status-item-label {
    font-size: 12px;
    color: #6B7A99;
    font-weight: 400;
    margin-top: 4px;
    text-align: left;
    margin-left: 8px;
}

.history-controls-inline {
    display: flex;
    gap: 8px;
    align-items: center;
}

.history-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 16px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #E6E9F3;
    color: #6B7A99;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        3px 3px 6px rgba(163, 177, 198, 0.3),
        -3px -3px 6px rgba(255, 255, 255, 0.6);
}

.history-btn:hover:not(:disabled) {
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.3),
        -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.history-btn:active:not(:disabled) {
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.history-btn:disabled {
    background: #E6E9F3;
    cursor: not-allowed;
    opacity: 0.4;
    color: #A3B1C6;
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.15),
        -2px -2px 4px rgba(255, 255, 255, 0.4);
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: #E6E9F3;
    border-radius: 20px;
    width: 90%;
    max-width: 450px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 
        5px 5px 10px rgba(163, 177, 198, 0.2),
        -5px -5px 10px rgba(255, 255, 255, 0.4);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(163, 177, 198, 0.2);
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
    color: #4A5568;
}

.close-btn {
    background: #E6E9F3;
    border: none;
    font-size: 32px;
    color: #6B7A99;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: all 0.2s ease;
    box-shadow: 
        3px 3px 6px rgba(163, 177, 198, 0.3),
        -3px -3px 6px rgba(255, 255, 255, 0.6);
}

.close-btn:hover {
    box-shadow: 
        2px 2px 4px rgba(163, 177, 198, 0.3),
        -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.close-btn:active {
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.3),
        inset -2px -2px 4px rgba(255, 255, 255, 0.6);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    font-weight: 600;
    color: #4A5568;
    margin-bottom: 8px;
    cursor: pointer;
}

.setting-group label input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

.setting-group input[type="number"] {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: none;
    border-radius: 12px;
    background: #E6E9F3;
    color: #4A5568;
    transition: all 0.2s ease;
    box-shadow: 
        inset 3px 3px 6px rgba(163, 177, 198, 0.25),
        inset -3px -3px 6px rgba(255, 255, 255, 0.5);
}

.setting-group input[type="number"]:focus {
    outline: none;
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.25),
        inset -2px -2px 4px rgba(255, 255, 255, 0.5);
}

.setting-group select.theme-select {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: none;
    border-radius: 12px;
    background: #E6E9F3;
    color: #4A5568;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 
        inset 3px 3px 6px rgba(163, 177, 198, 0.25),
        inset -3px -3px 6px rgba(255, 255, 255, 0.5);
}

.setting-group select.theme-select:focus {
    outline: none;
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.25),
        inset -2px -2px 4px rgba(255, 255, 255, 0.5);
}

.piece-preview {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    padding: 16px;
    background: #E6E9F3;
    border-radius: 12px;
    flex-wrap: wrap;
    box-shadow: 
        inset 3px 3px 6px rgba(163, 177, 198, 0.2),
        inset -3px -3px 6px rgba(255, 255, 255, 0.4);
}

.preview-piece {
    width: 48px;
    height: 48px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(163, 177, 198, 0.3));
}

@media (max-width: 400px) {
    .preview-piece {
        width: 40px;
        height: 40px;
    }
}

.setting-hint {
    display: block;
    font-size: 13px;
    color: #A3B1C6;
    margin-top: 6px;
}

.modal-footer {
    display: flex;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid rgba(163, 177, 198, 0.2);
    flex-shrink: 0;
}

.btn-primary, .btn-secondary {
    flex: 1;
    padding: 14px 20px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: #E6E9F3;
    color: #6B7A99;
    box-shadow: 
        4px 4px 8px rgba(163, 177, 198, 0.3),
        -4px -4px 8px rgba(255, 255, 255, 0.6);
}

.btn-primary:hover {
    box-shadow: 
        3px 3px 6px rgba(163, 177, 198, 0.3),
        -3px -3px 6px rgba(255, 255, 255, 0.6);
}

.btn-secondary {
    background: #E6E9F3;
    color: #A3B1C6;
    box-shadow: 
        inset 3px 3px 6px rgba(163, 177, 198, 0.25),
        inset -3px -3px 6px rgba(255, 255, 255, 0.5);
}

.btn-secondary:hover {
    box-shadow: 
        inset 2px 2px 4px rgba(163, 177, 198, 0.25),
        inset -2px -2px 4px rgba(255, 255, 255, 0.5);
}

.btn-primary:active, .btn-secondary:active {
    box-shadow: 
        inset 3px 3px 6px rgba(163, 177, 198, 0.25),
        inset -3px -3px 6px rgba(255, 255, 255, 0.5);
}

/* Board Themes */
.board-theme-classic .white-1e1d7 {
    background-color: #f0d9b5;
    color: #b58863;
}

.board-theme-classic .black-3c85d {
    background-color: #b58863;
    color: #f0d9b5;
}

.board-theme-gray .white-1e1d7 {
    background-color: #e8e8e8;
    color: #888888;
}

.board-theme-gray .black-3c85d {
    background-color: #888888;
    color: #e8e8e8;
}

.board-theme-blue .white-1e1d7 {
    background-color: #dee3e6;
    color: #8ca2ad;
}

.board-theme-blue .black-3c85d {
    background-color: #8ca2ad;
    color: #dee3e6;
}

.board-theme-green .white-1e1d7 {
    background-color: #ffffdd;
    color: #86a666;
}

.board-theme-green .black-3c85d {
    background-color: #86a666;
    color: #ffffdd;
}

.board-theme-brown .white-1e1d7 {
    background-color: #f0ead6;
    color: #9b7653;
}

.board-theme-brown .black-3c85d {
    background-color: #9b7653;
    color: #f0ead6;
}

.board-theme-purple .white-1e1d7 {
    background-color: #e4d4e7;
    color: #9370db;
}

.board-theme-purple .black-3c85d {
    background-color: #9370db;
    color: #e4d4e7;
}

.board-theme-wood .white-1e1d7 {
    background-color: #f4e4bc;
    color: #8b6f47;
}

.board-theme-wood .black-3c85d {
    background-color: #8b6f47;
    color: #f4e4bc;
}

.board-theme-marble .white-1e1d7 {
    background-color: #e0e0e0;
    color: #6d6d6d;
}

.board-theme-marble .black-3c85d {
    background-color: #6d6d6d;
    color: #e0e0e0;
}

.board-theme-neumorphic .white-1e1d7 {
    background-color: #E6E9F3;
    color: #C8CFE0;
}

.board-theme-neumorphic .black-3c85d {
    background-color: #C8CFE0;
    color: #E6E9F3;
}

/* Page Loading Overlay */
.page-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #E6E9F3 0%, #ECEEF9 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.page-loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.neumorphic-spinner {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #E6E9F3;
    box-shadow: 
        8px 8px 16px rgba(163, 177, 198, 0.4),
        -8px -8px 16px rgba(255, 255, 255, 0.8);
    position: relative;
    animation: pulse 2s ease-in-out infinite;
}

.neumorphic-spinner::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    border-radius: 50%;
    border: 4px solid transparent;
    border-top-color: #6B7A99;
    border-right-color: #6B7A99;
    animation: spin 1s linear infinite;
}

.neumorphic-spinner::after {
    content: '';
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    border-radius: 50%;
    background: #E6E9F3;
    box-shadow: 
        inset 4px 4px 8px rgba(163, 177, 198, 0.3),
        inset -4px -4px 8px rgba(255, 255, 255, 0.6);
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 
            8px 8px 16px rgba(163, 177, 198, 0.4),
            -8px -8px 16px rgba(255, 255, 255, 0.8);
    }
    50% {
        box-shadow: 
            12px 12px 24px rgba(163, 177, 198, 0.5),
            -12px -12px 24px rgba(255, 255, 255, 0.9);
    }
}
