/**
 * STOCKFISH PANEL CSS - Estilos para Panel de Análisis
 * Ajedrez de Silicio - Tema rojo/negro/dorado
 * 
 * Panel de análisis Stockfish con diseño consistente
 */

/* ===== PANEL PRINCIPAL ===== */
.stockfish-panel {
    background: var(--theme-button-bg);
    border: 1px solid var(--theme-border);
    border-radius: 12px;
    margin-bottom: 12px;
    box-shadow: 
        0 4px 12px var(--theme-shadow),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    overflow: hidden;
    transition: all var(--transition-normal);
}

.stockfish-panel:hover {
    border-color: var(--theme-accent-primary);
    box-shadow: 
        0 6px 20px var(--theme-shadow),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* ===== HEADER ===== */
.stockfish-header {
    background: var(--theme-bg-tertiary);
    border-bottom: 1px solid var(--theme-border);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stockfish-title {
    color: var(--theme-accent-primary);
    font-size: 0.9rem;
    font-weight: 700;
    font-family: var(--font-main);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: color var(--transition-theme);
}

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

.line-control {
    background: var(--theme-button-hover);
    border: 1px solid var(--theme-accent-primary);
    border-radius: 6px;
    color: var(--theme-button-text-hover);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: 0 2px 6px var(--theme-shadow);
}

.line-control:hover {
    background: var(--theme-button-hover);
    transform: translateY(-1px) scale(1.05);
    box-shadow: 0 4px 12px var(--theme-shadow);
}

.line-control:active {
    transform: translateY(0) scale(0.95);
}

.lines-indicator {
    color: var(--theme-accent-primary);
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 16px;
    text-align: center;
    font-family: var(--font-main);
    transition: color var(--transition-theme);
}

/* ===== CONTENIDO ===== */
/* contenedor flexible con animación suave */
.stockfish-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
    max-height: 0;                    /* parte cerrado hasta que JS mida */
    transition: max-height 220ms ease;
    will-change: max-height;
    padding: 12px 16px;                /* mantener padding actual */
}

/* ===== LÍNEAS DE ANÁLISIS ===== */
.analysis-line {
    background: var(--theme-bg-primary);
    border: 1px solid var(--theme-border);
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    flex-wrap: nowrap;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-height: 75px;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

/* Sólo se muestra si tiene la clase .is-visible */
.analysis-line { 
    display: none; 
}
.analysis-line.is-visible { 
    display: flex; 
}

.analysis-line::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, var(--theme-shadow-glow), transparent);
    transition: left 0.6s ease;
    pointer-events: none;
}

.analysis-line:hover::before {
    left: 100%;
}

.analysis-line:hover {
    border-color: var(--theme-accent-primary);
    transform: translateY(-1px);
}

/* Evaluación con número y símbolo */
.line-evaluation {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    padding: 6px 8px;
    border-radius: 8px;
    transition: all 0.3s ease;
    overflow: hidden;
    flex-shrink: 0;
    text-align: center;
}

.line-evaluation .eval-num {
    font-weight: 700;
    font-size: 14px;
    line-height: 1.0;
    font-family: 'Poppins', 'Segoe UI', sans-serif;
}

.line-evaluation .eval-sym {
    margin-top: 2px;
    font-size: 12px;
    line-height: 1.0;
    opacity: 0.85;
    font-family: 'Poppins', 'Segoe UI', sans-serif;
}

.analysis-line .line-evaluation.equal {
    background: rgba(212, 175, 55, 0.2) !important;
    color: #D4AF37 !important;
    border: 1px solid rgba(212, 175, 55, 0.3) !important;
}

.analysis-line .line-evaluation.slight-advantage-white {
    background: rgba(197, 0, 57, 0.3) !important;
    color: #FFB3C6 !important;
    border: 1px solid rgba(197, 0, 57, 0.5) !important;
}

.analysis-line .line-evaluation.advantage-white {
    background: rgba(197, 0, 57, 0.5) !important;
    color: #FF6B9D !important;
    border: 1px solid rgba(197, 0, 57, 0.7) !important;
}

.analysis-line .line-evaluation.slight-advantage-black {
    background: rgba(100, 100, 100, 0.3) !important;
    color: #CCCCCC !important;
    border: 1px solid rgba(100, 100, 100, 0.5) !important;
}

.analysis-line .line-evaluation.advantage-black {
    background: rgba(100, 100, 100, 0.5) !important;
    color: #AAAAAA !important;
    border: 1px solid rgba(100, 100, 100, 0.7) !important;
}

/* Movimientos */
.line-moves {
    flex: 1 1 auto;
    min-width: 0;
    color: #e8e8e8;
    font-size: 0.8rem;
    font-family: 'Courier New', monospace;
    margin: 0;
    padding: 0 56px 0 8px;  /* reserva espacio para badge flotante */
    text-align: left;
    font-weight: 500;
    letter-spacing: 0.5px;
    display: -webkit-box !important;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    line-height: 1.3;
    max-height: 3.9em;
}

/* Profundidad como badge flotante discreto */
.line-depth {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 10px;
    opacity: 0.7;
    padding: 1px 5px;
    border-radius: 6px;
    border: 1px solid rgba(212, 175, 55, 0.2);
    background: rgba(212, 175, 55, 0.08);
    line-height: 1;
    pointer-events: none;
    white-space: nowrap;
    color: #D4AF37;
    font-weight: 500;
    font-family: 'Poppins', 'Segoe UI', sans-serif;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .stockfish-header {
        padding: 10px 12px;
        flex-direction: column;
        gap: 8px;
    }
    
    .stockfish-title {
        font-size: 0.8rem;
    }
    
    .stockfish-content {
        padding: 10px 12px;
    }
    
    .analysis-line {
        flex-direction: column;
        gap: 6px;
        text-align: center;
    }
    
    .line-moves {
        margin: 0;
        order: 1;
    }
    
    .line-evaluation {
        order: 2;
    }
    
    .line-depth {
        order: 3;
        text-align: center;
        min-width: auto;
    }
    
    .line-control {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
}

/* ===== VISOR DE VARIANTE DEL MOTOR (SOLO WORKBENCH GRANDE) ===== */
.engine-pv-toggle,
.engine-pv-viewer {
    display: none;
}

@media (min-width: 769px) and (orientation: landscape), (min-width: 1181px) {
    html[data-workbench="v3"] #stockfish-panel .engine-pv-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 28px;
        padding: 4px 9px;
        border: 1px solid color-mix(in srgb, var(--theme-accent-primary) 58%, var(--theme-border));
        border-radius: 7px;
        background: color-mix(in srgb, var(--theme-accent-primary) 11%, transparent);
        color: var(--theme-accent-primary);
        font: inherit;
        font-size: 10px;
        font-weight: 700;
        cursor: pointer;
        white-space: nowrap;
    }

    html[data-workbench="v3"] #stockfish-panel .engine-pv-toggle:hover,
    html[data-workbench="v3"] #stockfish-panel .engine-pv-toggle:focus-visible {
        background: color-mix(in srgb, var(--theme-accent-primary) 20%, transparent);
        outline: 2px solid var(--theme-accent-primary);
        outline-offset: 2px;
    }

    html[data-workbench="v3"] #stockfish-panel .line-moves {
        position: relative;
        z-index: 1;
        display: flex !important;
        flex-wrap: wrap;
        align-content: flex-start;
        align-items: center;
        gap: 2px 3px;
        -webkit-line-clamp: unset;
    }

    html[data-workbench="v3"] #stockfish-panel .engine-pv-move {
        appearance: none;
        min-width: 0;
        margin: 0;
        padding: 1px 3px;
        border: 1px solid transparent;
        border-radius: 4px;
        background: transparent;
        color: inherit;
        font: inherit;
        font-weight: inherit;
        letter-spacing: inherit;
        line-height: 1.25;
        cursor: pointer;
    }

    html[data-workbench="v3"] #stockfish-panel .engine-pv-move:hover {
        border-color: color-mix(in srgb, var(--theme-accent-primary) 58%, transparent);
        background: color-mix(in srgb, var(--theme-accent-primary) 14%, transparent);
        color: var(--theme-accent-primary);
    }

    html[data-workbench="v3"] #stockfish-panel .engine-pv-move:focus-visible {
        border-color: var(--theme-accent-primary);
        outline: 2px solid var(--theme-accent-primary);
        outline-offset: 1px;
    }

    html[data-workbench="v3"] #stockfish-panel .engine-pv-move.is-selected {
        border-color: var(--theme-accent-primary);
        background: var(--theme-accent-primary);
        color: var(--theme-bg-primary);
        box-shadow: 0 1px 5px color-mix(in srgb, var(--theme-accent-primary) 38%, transparent);
    }

    html[data-workbench="v3"] #stockfish-panel .engine-pv-move.is-target {
        border-color: color-mix(in srgb, var(--theme-accent-primary) 72%, transparent);
        box-shadow: inset 0 -2px 0 var(--theme-accent-primary);
    }

    html[data-workbench="v3"] #stockfish-panel .engine-pv-viewer:not([hidden]) {
        display: block;
        position: fixed;
        inset: 84px calc(var(--panel-w-desktop, 420px) + 14px) auto auto;
        z-index: 1200;
        width: 294px;
        max-width: calc(100vw - var(--panel-w-desktop, 420px) - 28px);
        max-height: calc(100dvh - 150px);
        padding: 12px;
        border: 1px solid color-mix(in srgb, var(--theme-accent-primary) 38%, var(--theme-border));
        border-radius: 10px;
        background: color-mix(in srgb, var(--theme-bg-tertiary) 96%, var(--theme-bg-primary));
        box-shadow:
            0 18px 48px color-mix(in srgb, var(--theme-shadow) 82%, transparent),
            inset 0 1px 0 rgba(255, 255, 255, 0.05);
        box-sizing: border-box;
        overflow: auto;
        overscroll-behavior: contain;
    }

    .engine-pv-viewer__header,
    .engine-pv-viewer__header > div,
    .engine-pv-viewer__navigation {
        display: flex;
    }

    .engine-pv-viewer__header {
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        margin-bottom: 10px;
        cursor: grab;
        touch-action: none;
        user-select: none;
    }

    html[data-workbench="v3"] #stockfish-panel .engine-pv-viewer.is-dragging,
    html[data-workbench="v3"] #stockfish-panel .engine-pv-viewer.is-dragging .engine-pv-viewer__header {
        cursor: grabbing;
    }

    .engine-pv-viewer__header > div,
    .engine-pv-viewer__navigation {
        min-width: 0;
        flex-direction: column;
    }

    .engine-pv-viewer__title {
        color: var(--theme-text-secondary);
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .engine-pv-viewer__line {
        display: block;
        max-width: 220px;
        color: var(--theme-accent-primary);
        font-size: 13px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .engine-pv-viewer__close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 30px;
        height: 30px;
        padding: 0;
        border: 1px solid var(--theme-accent-primary);
        border-radius: 7px;
        background: color-mix(in srgb, var(--theme-accent-primary) 14%, transparent);
        color: var(--theme-accent-primary);
        font: inherit;
        font-size: 20px;
        line-height: 1;
        cursor: pointer;
    }

    .engine-pv-viewer__body {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .engine-pv-board-shell {
        width: min(238px, 100%);
        margin-inline: auto;
        padding: 5px;
        border: 1px solid color-mix(in srgb, var(--theme-border) 88%, transparent);
        border-radius: 8px;
        background: var(--theme-bg-primary);
        box-sizing: border-box;
    }

    .engine-pv-board {
        position: relative;
        display: block;
        width: 100%;
        height: auto;
        aspect-ratio: 1;
        border-radius: 4px;
        overflow: visible;
        box-sizing: border-box;
    }

    .engine-pv-board silicio-board-surface {
        border-radius: 4px;
        background-color: var(--board-color-light, #f0d9b5) !important;
        background-image: conic-gradient(
            from 90deg,
            var(--board-color-light, #f0d9b5) 0 25%,
            var(--board-color-dark, #b58863) 0 50%,
            var(--board-color-light, #f0d9b5) 0 75%,
            var(--board-color-dark, #b58863) 0
        ) !important;
        background-size: 25% 25% !important;
    }

    html:not([data-piece-theme]) .engine-pv-board.silicio-board-host piece.white,
    html[data-piece-theme="silicio"] .engine-pv-board.silicio-board-host piece.white {
        filter: var(--silicio-piece-white-shadow);
    }

    html:not([data-piece-theme]) .engine-pv-board.silicio-board-host piece.black,
    html[data-piece-theme="silicio"] .engine-pv-board.silicio-board-host piece.black {
        filter: var(--silicio-piece-black-shadow);
    }

    .engine-pv-viewer__navigation {
        align-items: stretch;
        gap: 6px;
    }

    .engine-pv-viewer__status {
        color: var(--theme-text-muted);
        font-size: 10px;
        line-height: 1.35;
    }

    .engine-pv-viewer__move {
        min-height: 34px;
        padding: 7px 8px;
        border: 1px solid var(--theme-border);
        border-radius: 7px;
        background: var(--theme-bg-primary);
        color: var(--theme-text-secondary);
        font-family: 'Courier New', monospace;
        font-size: 12px;
        font-weight: 700;
        line-height: 1.35;
        box-sizing: border-box;
    }

    .engine-pv-viewer__buttons {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 5px;
    }

    .engine-pv-viewer__buttons button {
        min-width: 0;
        min-height: 32px;
        padding: 3px;
        border: 1px solid var(--theme-border);
        border-radius: 7px;
        background: var(--theme-button-bg);
        color: var(--theme-text-secondary);
        font: inherit;
        font-size: 13px;
        cursor: pointer;
    }

    .engine-pv-viewer__buttons button:hover:not(:disabled),
    .engine-pv-viewer__buttons button:focus-visible {
        border-color: var(--theme-accent-primary);
        color: var(--theme-accent-primary);
        outline: 2px solid var(--theme-accent-primary);
        outline-offset: 1px;
    }

    .engine-pv-viewer__buttons button:disabled {
        opacity: 0.34;
        cursor: not-allowed;
    }

    .engine-pv-viewer__add-line {
        width: 100%;
        min-height: 34px;
        padding: 6px 10px;
        border: 1px solid color-mix(in srgb, var(--theme-accent-primary) 72%, var(--theme-border));
        border-radius: 7px;
        background: color-mix(in srgb, var(--theme-accent-primary) 16%, var(--theme-button-bg));
        color: var(--theme-accent-primary);
        font: inherit;
        font-size: 11px;
        font-weight: 800;
        cursor: pointer;
    }

    .engine-pv-viewer__add-line:hover:not(:disabled),
    .engine-pv-viewer__add-line:focus-visible {
        background: color-mix(in srgb, var(--theme-accent-primary) 28%, var(--theme-button-bg));
        outline: 2px solid var(--theme-accent-primary);
        outline-offset: 1px;
    }

    .engine-pv-viewer__add-line:disabled {
        opacity: 0.4;
        cursor: not-allowed;
    }

    .engine-pv-viewer__close:hover,
    .engine-pv-viewer__close:focus-visible {
        border-color: var(--theme-accent-primary);
        color: var(--theme-accent-primary);
        background: color-mix(in srgb, var(--theme-accent-primary) 24%, transparent);
        outline: 2px solid var(--theme-accent-primary);
        outline-offset: 2px;
    }

    .engine-pv-viewer__step {
        color: var(--theme-accent-primary);
        font-size: 11px;
        font-weight: 700;
        text-align: center;
    }

    .engine-pv-viewer__status {
        min-height: 1.35em;
        margin: 0;
        text-align: center;
    }
}

@media (min-width: 1440px) and (max-width: 1599px) and (min-height: 701px) {
    html[data-workbench="v3"] #stockfish-panel .engine-pv-viewer:not([hidden]) {
        width: 278px;
    }

    html[data-workbench="v3"] #stockfish-panel .engine-pv-board-shell {
        width: min(220px, 100%);
    }
}

/* ===== ANIMACIONES ===== */
@keyframes stockfish-thinking {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.analysis-line[data-thinking="true"] .line-moves {
    animation: stockfish-thinking 1.5s ease-in-out infinite;
}

/* ===== ESTADOS ESPECIALES ===== */
.analysis-line[data-line="1"] {
    border-color: rgba(212, 175, 55, 0.4);
}

.analysis-line[data-line="2"] {
    border-color: rgba(197, 0, 57, 0.3);
}

.analysis-line[data-line="3"] {
    border-color: rgba(100, 100, 100, 0.3);
}

/* Efecto de actualización */
.analysis-line.updating {
    background: linear-gradient(145deg, #1f1f1f 0%, #252525 100%);
    border-color: rgba(212, 175, 55, 0.5);
}

.analysis-line.updating .line-moves {
    color: #D4AF37;
}

/* === STOCKFISH: overrides para altura dinámica === */

/* No permitir que el panel se estire por flex ni tenga alturas fijas */
#stockfish-panel {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  flex: 0 0 auto !important;      /* <- evita que rellene el espacio */
  align-self: flex-start !important;
}

/* El contenedor que anima: sin height/min-height fijos */
#stockfish-panel .stockfish-content {
  height: auto !important;
  min-height: 0 !important;
  /* animación real con max-height */
  overflow: hidden;
  max-height: 0;                   /* se abre con JS */
  transition: max-height 220ms ease;
  will-change: max-height;
}

/* Las líneas: controladas por clases */
#stockfish-panel .analysis-line { display: none; }
#stockfish-panel .analysis-line.is-visible { display: flex; }

/* Estado deshabilitado para botones +/- */
.stockfish-controls button:disabled,
.stockfish-controls button.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* === MÓVILES: ancho estable === */
@media (max-width: 768px) {
    #stockfish-panel {
        min-width: 100%;
        width: 100%;
    }
    
    .stockfish-content {
        min-width: 100%;
        width: 100%;
    }
    
    .analysis-line {
        min-width: 100%;
    }
    
    .analysis-line .line-moves {
        min-width: 0;
        flex: 1 1 auto;
        width: 100%;
    }
}
