/* ==========================================================================
   Obsidian & Emerald Cyber Theme - Stockfish Chess Arena
   ========================================================================== */

:root {
    --bg-page: #060908;
    --bg-card: rgba(13, 20, 16, 0.85);
    --bg-card-border: rgba(16, 185, 129, 0.2);
    --bg-panel: rgba(10, 16, 13, 0.92);
    --bg-terminal-header: #0f1713;

    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --text-dim: #64748b;

    --primary-green: #10b981;
    --emerald-glow: #00ff9d;
    --emerald-dark: #047857;
    --emerald-soft: #34d399;

    --term-error: #f43f5e;
    --term-warning: #fbbf24;

    /* Tablero de Torneo Clásico */
    --sq-light: #ececd0;
    --sq-dark: #739552;
    --sq-selected: rgba(0, 255, 157, 0.45);
    --sq-highlight: rgba(255, 255, 60, 0.42);
    --sq-hint: rgba(16, 185, 129, 0.55);
    --sq-check: radial-gradient(ellipse at center, rgba(244, 63, 94, 0.85) 0%, rgba(225, 29, 72, 0.4) 60%, rgba(200, 0, 0, 0) 90%);

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-page);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Background Cyber Grid Overlay */
.bg-grid-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-image: 
        linear-gradient(to right, rgba(16, 185, 129, 0.04) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(16, 185, 129, 0.04) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
}

/* Navigation Header */
header.arena-header {
    position: relative;
    z-index: 10;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--bg-card-border);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    font-size: 26px;
    filter: drop-shadow(0 0 8px var(--emerald-glow));
}

.header-brand h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-main);
}

.engine-badge {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(0, 255, 157, 0.15));
    border: 1px solid rgba(16, 185, 129, 0.4);
    color: var(--emerald-soft);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

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

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--primary-green);
    box-shadow: 0 0 10px var(--emerald-glow);
    transition: background-color 0.3s, box-shadow 0.3s;
}

.status-dot.thinking {
    background-color: var(--term-warning);
    box-shadow: 0 0 12px var(--term-warning);
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(0.9); opacity: 0.6; }
    100% { transform: scale(1.3); opacity: 1; }
}

.nav-back-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--bg-card-border);
    transition: var(--transition);
}

.nav-back-btn:hover {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--primary-green);
    color: var(--emerald-soft);
    transform: translateX(-2px);
}

/* Main Arena Layout */
main.arena-main {
    position: relative;
    z-index: 1;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px;
    gap: 24px;
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
}

/* Área del Tablero y Barra de Evaluación */
.game-area {
    display: flex;
    gap: 16px;
    align-items: center;
}

/* Barra de Evaluación */
.eval-bar-container {
    width: 32px;
    height: min(100%, 70dvh);
    max-height: 600px;
    background-color: #1e2420;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column-reverse; /* El llenado blanco crece desde abajo */
    position: relative;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    border: 1px solid var(--bg-card-border);
}

.eval-bar-fill {
    width: 100%;
    background: #ffffff;
    transition: height 0.4s cubic-bezier(0.2, 0.8, 0.3, 1);
    height: 50%;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.eval-text {
    position: absolute;
    width: 100%;
    text-align: center;
    font-size: 11px;
    font-weight: 800;
    font-family: var(--font-mono);
    pointer-events: none;
    z-index: 2;
}

.eval-text.white-text {
    bottom: 6px;
    color: #0f1713;
}

.eval-text.black-text {
    top: 6px;
    color: #e2e8f0;
}

/* Tablero de Ajedrez */
.board-container {
    position: relative;
    width: min(100%, 70dvh);
    max-width: 600px;
    aspect-ratio: 1 / 1;
    touch-action: none;
    -webkit-touch-callout: none;
    user-select: none;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    overflow: hidden;
    background-color: var(--sq-dark);
    border: 1px solid var(--bg-card-border);
}

.chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
    touch-action: none;
}

.square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.square.light {
    background-color: var(--sq-light);
}

.square.dark {
    background-color: var(--sq-dark);
}

/* Coordenadas en los bordes */
.coord {
    position: absolute;
    font-size: 11px;
    font-weight: 700;
    font-family: var(--font-mono);
    pointer-events: none;
}

.coord.file {
    bottom: 2px;
    right: 4px;
}

.coord.rank {
    top: 2px;
    left: 4px;
}

.square.light .coord {
    color: var(--sq-dark);
}

.square.dark .coord {
    color: var(--sq-light);
}

/* Resaltados */
.square.selected {
    background-color: var(--sq-selected) !important;
    box-shadow: inset 0 0 12px rgba(0, 255, 157, 0.6);
}

.square.last-move {
    background-color: var(--sq-highlight) !important;
}

.square.in-check {
    background: var(--sq-check) !important;
}

.square.hint {
    background-color: var(--sq-hint) !important;
    box-shadow: inset 0 0 14px rgba(0, 255, 157, 0.7);
}

/* Indicadores de movimientos legales */
.legal-dot {
    position: absolute;
    width: 28%;
    height: 28%;
    background-color: rgba(6, 9, 8, 0.35);
    border-radius: 50%;
    pointer-events: none;
    z-index: 5;
}

.legal-capture-ring {
    position: absolute;
    width: 86%;
    height: 86%;
    border: 5px solid rgba(6, 9, 8, 0.4);
    border-radius: 50%;
    pointer-events: none;
    z-index: 5;
}

/* Piezas SVG */
.piece {
    width: 90%;
    height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4;
    transition: transform 0.1s ease;
    cursor: grab;
}

.piece:active {
    cursor: grabbing;
}

.piece.dragging {
    opacity: 0.1;
}

.chess-piece-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.45));
}

/* Pieza fantasma durante drag & drop */
.ghost-piece {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    width: 68px;
    height: 68px;
    transform: translate(-50%, -50%);
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.7));
}

/* Panel Lateral (Sidebar) */
.sidebar {
    width: 380px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--bg-card-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
}

.player-info-card {
    padding: 14px 18px;
    background: rgba(16, 25, 20, 0.7);
    border-bottom: 1px solid var(--bg-card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.player-details {
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid var(--bg-card-border);
}

.player-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
}

.player-elo {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.captured-pieces {
    display: flex;
    align-items: center;
    gap: 2px;
    min-height: 22px;
}

.captured-mini {
    width: 18px;
    height: 18px;
    display: inline-block;
}

.captured-mini svg {
    width: 100%;
    height: 100%;
}

.material-diff {
    font-size: 11px;
    font-weight: 700;
    font-family: var(--font-mono);
    margin-left: 4px;
    color: var(--primary-green);
}

/* Tabs */
.tab-header {
    display: flex;
    border-bottom: 1px solid var(--bg-card-border);
    background: rgba(10, 16, 13, 0.6);
}

.tab-btn {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn.active {
    color: var(--emerald-soft);
    border-bottom: 2px solid var(--primary-green);
    background: rgba(16, 185, 129, 0.08);
}

.tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow-y: auto;
    max-height: 340px;
}

/* Historial de Movimientos */
.moves-list {
    display: grid;
    grid-template-columns: 36px 1fr 1fr;
    font-size: 13px;
    line-height: 26px;
    gap: 2px;
}

.move-num {
    color: var(--text-dim);
    font-family: var(--font-mono);
    text-align: right;
    padding-right: 8px;
}

.move-san {
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-main);
    transition: var(--transition);
}

.move-san:hover {
    background: rgba(16, 185, 129, 0.15);
}

.move-san.active {
    background: rgba(16, 185, 129, 0.3);
    color: var(--emerald-glow);
    font-weight: 700;
}

/* Form Groups */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-family: var(--font-mono);
}

select, input[type="range"] {
    width: 100%;
    padding: 10px 12px;
    background: rgba(10, 16, 13, 0.8);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-size: 13px;
    outline: none;
    transition: var(--transition);
}

select:focus {
    border-color: var(--primary-green);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.3);
}

.color-selector {
    display: flex;
    gap: 8px;
}

.color-btn {
    flex: 1;
    padding: 10px;
    background: rgba(10, 16, 13, 0.8);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--transition);
}

.color-btn.active {
    border-color: var(--primary-green);
    background: rgba(16, 185, 129, 0.2);
    color: var(--emerald-glow);
}

/* Action Buttons */
.actions-container {
    padding: 14px 16px;
    border-top: 1px solid var(--bg-card-border);
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    background: rgba(10, 16, 13, 0.6);
}

.btn {
    padding: 10px 14px;
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    grid-column: span 2;
    background: var(--primary-green);
    color: #060908;
    border-color: var(--emerald-glow);
    font-weight: 700;
}

.btn-primary:hover {
    background: var(--emerald-soft);
    box-shadow: 0 0 14px var(--emerald-glow);
}

.btn-secondary {
    background: rgba(20, 32, 26, 0.8);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: rgba(28, 45, 36, 0.9);
    border-color: var(--primary-green);
}

.btn-hint {
    background: rgba(2, 136, 209, 0.2);
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.4);
}

.btn-hint:hover {
    background: rgba(2, 136, 209, 0.35);
    border-color: #38bdf8;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

/* Game Over Banner */
.game-over-banner {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.3), rgba(4, 120, 87, 0.3));
    border: 1px solid var(--primary-green);
    color: var(--emerald-glow);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    display: none;
    box-shadow: 0 0 14px rgba(16, 185, 129, 0.3);
}

.game-over-banner.draw {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.25), rgba(217, 119, 6, 0.25));
    border-color: var(--term-warning);
    color: #fde68a;
    box-shadow: 0 0 14px rgba(251, 191, 36, 0.3);
}

.game-over-banner.defeat {
    background: linear-gradient(135deg, rgba(244, 63, 94, 0.25), rgba(190, 18, 60, 0.25));
    border-color: var(--term-error);
    color: #fecdd3;
    box-shadow: 0 0 14px rgba(244, 63, 94, 0.3);
}

/* Pawn Promotion Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(6, 9, 8, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--primary-green);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 20px rgba(0, 255, 157, 0.2);
    text-align: center;
}

.modal-content h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--emerald-glow);
}

.promo-pieces {
    display: flex;
    gap: 12px;
}

.promo-piece-btn {
    width: 68px;
    height: 68px;
    background: rgba(16, 25, 20, 0.9);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    transition: var(--transition);
}

.promo-piece-btn:hover {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--primary-green);
    transform: scale(1.1);
    box-shadow: 0 0 12px var(--emerald-glow);
}

/* Responsive Breakpoints - Gemini 4 Argon Standard */
@media (max-width: 1023px) {
    main.arena-main {
        flex-direction: column;
        align-items: center;
        padding: 16px;
    }

    .board-container {
        width: min(100%, 70dvh);
        aspect-ratio: 1 / 1;
        touch-action: none;
    }

    .eval-bar-container {
        height: min(100%, 70dvh);
        width: 28px;
    }

    .sidebar {
        width: 100%;
        max-width: 600px;
    }
}

@media (max-width: 639px) {
    main.arena-main {
        min-height: 72dvh;
        padding: 12px 8px;
        gap: 16px;
    }

    .game-area {
        width: 100%;
        justify-content: center;
        gap: 10px;
    }

    .board-container {
        width: min(100%, 70dvh);
        aspect-ratio: 1 / 1;
        touch-action: none;
    }

    .eval-bar-container {
        height: min(100%, 70dvh);
        width: 20px;
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
    }

    .actions-container {
        grid-template-columns: repeat(2, 1fr);
    }

    header.arena-header {
        padding: 12px 14px;
    }

    .header-brand h1 {
        font-size: 15px;
    }

    .engine-badge {
        font-size: 10px;
        padding: 3px 6px;
    }
}
