/* Scoped styles for Chess Analysis Widget */
:root {
    --widget-bg-panel: rgba(22, 26, 37, 0.95);
    --widget-primary: #4cc9f0;
    --widget-text-main: #ffffff;
    --widget-text-muted: #94a3b8;
    --widget-glass-border: rgba(255, 255, 255, 0.1);
}

.chess-analysis-widget {
    font-family: 'Outfit', system-ui, sans-serif;
    background-color: #0f111a !important;
    color: var(--widget-text-main);
    border-radius: 12px;
    padding: 16px;
    margin-top: 24px;
    display: flex;
    flex-direction: column-reverse;
    gap: 16px;
    width: 100%;
}

@media (max-width: 768px) {
    .chess-analysis-widget {
        border-radius: 0;
        padding: 4px 0;
        margin-top: 0;
        gap: 6px;
    }
}

@media (min-width: 768px) {
    .chess-analysis-widget {
        flex-direction: row;
        align-items: flex-start;
    }
}

.chess-analysis-widget .widget-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 250px;
}

@media (max-width: 768px) {
    .chess-analysis-widget .widget-panel {
        min-width: 0;
        padding: 0 8px;
    }
}

.chess-analysis-widget .glass-card {
    background: var(--widget-bg-panel);
    border: 1px solid var(--widget-glass-border);
    border-radius: 12px;
    padding: 12px;
}

.chess-analysis-widget .eval-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(135deg, rgba(30, 34, 45, 0.9), rgba(20, 22, 30, 0.9));
}

.chess-analysis-widget .eval-score {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--widget-primary);
    margin-bottom: 4px;
}

.chess-analysis-widget .eval-meta {
    display: flex;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--widget-text-muted);
    margin-bottom: 8px;
}

.chess-analysis-widget .eval-best {
    font-family: 'Consolas', monospace;
    font-size: 0.9rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px 10px;
    border-radius: 4px;
    margin-bottom: 12px;
    color: #ffd700;
}

.chess-analysis-widget .engine-controls {
    width: 100%;
    border-top: 1px solid var(--widget-glass-border);
    padding-top: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.chess-analysis-widget .engine-controls label {
    font-size: 0.75rem;
    color: var(--widget-text-muted);
}

.chess-analysis-widget .depth-select {
    background: #1e293b;
    color: #fff;
    border: 1px solid #475569;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    width: 100%;
    cursor: pointer;
}

.chess-analysis-widget .btn {
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    transition: background 0.2s;
}

.chess-analysis-widget .btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chess-analysis-widget .engine-log {
    font-family: 'Consolas', monospace;
    font-size: 0.75rem;
    color: #888;
    background: #0a0b10;
    height: 120px;
    overflow-y: auto;
    white-space: pre-wrap;
    padding: 8px;
    border-radius: 4px;
}

.chess-analysis-widget .board-wrapper {
    flex: 2;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Center the board-main-area vertically */
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 12px;
    min-height: 320px;
}

@media (max-width: 768px) {
    .chess-analysis-widget .board-wrapper {
        border-radius: 0;
        padding: 2px;
        min-height: auto;
        background: transparent;
    }
}

.chess-analysis-widget .board-main-area {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    /* Bar stretches to board height */
    width: 100%;
    max-width: 600px;
    justify-content: center;
}

@media (max-width: 768px) {
    .chess-analysis-widget .board-main-area {
        max-width: 100%;
        width: calc(100vw - 4px);
    }
}

.chess-analysis-widget .chess-board {
    flex: 1;
    min-width: 0;
}

/* Eval Bar */
.chess-analysis-widget .eval-bar-container {
    width: 20px;
    min-width: 20px;
    height: auto;
    background: #404040;
    border-radius: 4px;
    overflow: hidden;
    margin-left: 10px;
    display: flex;
    flex-direction: column-reverse;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.chess-analysis-widget .eval-bar-fill {
    width: 100%;
    background: #ebecd0;
    /* White piece side */
    transition: height 0.4s ease-out;
}

.chess-analysis-widget .eval-bar-zero {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 1px;
    background: rgba(255, 0, 85, 0.4);
    /* Subtle red line for 0 */
    z-index: 2;
}

/* Hide the default tan border fill */
.chess-analysis-widget .cm-chessboard .board .border {
    fill: none !important;
}

/* 
   ULTRA SPECIFIC BOARD THEME 
   Targets rect elements inside the board group by their class.
*/
.chess-analysis-widget .cm-chessboard .board .square.white,
.chess-analysis-widget .cm-chessboard .board .square.light,
.chess-analysis-widget .cm-chessboard .board rect.square.white,
.chess-analysis-widget .cm-chessboard .board rect.white {
    fill: #ebecd0 !important;
}

.chess-analysis-widget .cm-chessboard .board .square.black,
.chess-analysis-widget .cm-chessboard .board .square.dark,
.chess-analysis-widget .cm-chessboard .board rect.square.black,
.chess-analysis-widget .cm-chessboard .board rect.black {
    fill: #779556 !important;
}

/* 
   Pieces FIX:
   Reset any global fills that might silhouette the pieces. 
*/
/* .chess-analysis-widget .cm-chessboard .pieces-layer * {
    fill: initial;
    stroke: initial;
} */

/* Modal Fix */
.chess-analysis-widget .turn-selection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    backdrop-filter: blur(6px);
    border-radius: 12px;
}

.chess-analysis-widget .turn-modal {
    background: #1e222d;
    padding: 32px;
    border-radius: 16px;
    border: 2px solid var(--widget-primary);
    color: white;
    text-align: center;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.8);
    max-width: 90%;
}

.chess-analysis-widget .btn-white {
    background: #fff !important;
    color: #000 !important;
}

.chess-analysis-widget .btn-black {
    background: #333 !important;
    color: #fff !important;
    border: 1px solid #555 !important;
}