/* ==========================================================================
   Chess App - Dark Theme Styles
   ========================================================================== */

/* CSS Variables - Color Palette */
:root {
    /* Primary Colors */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f0f23;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --accent-dark: #c73e54;

    /* Text Colors */
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --text-muted: #6c6c6c;

    /* UI Colors */
    --border-color: #2d2d4a;
    --border-light: #3d3d5c;
    --success: #4ade80;
    --warning: #fbbf24;
    --danger: #ef4444;
    --info: #60a5fa;

    /* Analysis Arrow Colors */
    --arrow-best: #22c55e;
    --arrow-alt1: #eab308;
    --arrow-alt2: #f97316;

    /* Board Colors */
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --board-highlight: rgba(233, 69, 96, 0.5);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.6);
    --shadow-board: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

    /* Board Sizes - Responsive */
    --board-size-desktop: min(70vh, 560px);
    --board-size-tablet: min(60vw, 480px);
    --board-size-mobile: min(calc(100vw - 2rem), 400px);

    /* Header Heights */
    --header-height: 56px;
    --header-height-mobile: 48px;
    --nav-height-mobile: 60px;

    /* Glassmorphism */
    --glass-bg: rgba(22, 33, 62, 0.9);
    --glass-border: rgba(255, 255, 255, 0.08);
}

/* ==========================================================================
   Base Styles
   ========================================================================== */

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ==========================================================================
   Typography
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ==========================================================================
   Header - Compacto y Moderno
   ========================================================================== */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 var(--spacing-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 1.25rem;
    font-weight: 700;
}

.logo-icon {
    font-size: 1.5rem;
    color: var(--accent);
}

.logo-text {
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

/* Navigation como tabs */
.nav {
    display: flex;
    gap: 2px;
    background: var(--bg-tertiary);
    padding: 3px;
    border-radius: var(--radius-lg);
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.nav-btn:hover {
    color: var(--text-primary);
}

.nav-btn.active {
    color: var(--text-primary);
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
}

.nav-icon {
    font-size: 1rem;
    line-height: 1;
}

.nav-label {
    font-size: 0.875rem;
}

/* User Section */
.user-section {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

#username-display {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.btn-user {
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-user:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

button {
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm) var(--spacing-lg);
    font-size: 0.9375rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    border: none;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    min-width: 120px;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent) 100%);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm) var(--spacing-lg);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--border-light);
}

.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm) var(--spacing-lg);
    font-size: 0.875rem;
    font-weight: 500;
    color: #fff;
    background: var(--danger);
    border: none;
    border-radius: var(--radius-md);
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

/* ==========================================================================
   Main Content
   ========================================================================== */

.main-content {
    flex: 1;
    padding: var(--spacing-xl);
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.section {
    animation: fadeIn 0.3s ease;
}

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

/* ==========================================================================
   Game Container
   ========================================================================== */

.game-container {
    display: flex;
    gap: var(--spacing-xl);
    align-items: flex-start;
    justify-content: center;
}

.board-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Player Info */
.player-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.player-info.top {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: none;
}

.player-info.bottom {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-top: none;
}

.player-name {
    font-weight: 600;
    color: var(--text-primary);
}

.clock {
    font-family: var(--font-mono);
    font-size: 1.125rem;
    font-weight: 600;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    min-width: 70px;
    text-align: center;
}

.clock.low-time {
    color: var(--danger);
    animation: pulse 1s infinite;
}

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

/* Chess Board */
.board {
    width: 480px;
    height: 480px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-xl);
}

/* ChessboardJS overrides */
.board-b72b1 {
    border-radius: var(--radius-lg);
}

/* Board Controls */
.board-controls {
    display: flex;
    justify-content: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
}

.control-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.control-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-color: var(--accent);
}

/* ==========================================================================
   Side Panel
   ========================================================================== */

.side-panel {
    width: 320px;
    min-height: 500px;
}

.config-panel,
.info-panel,
.analysis-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-md);
}

.config-panel h3,
.info-panel h3,
.analysis-panel h3 {
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

/* Form Groups */
.form-group {
    margin-bottom: var(--spacing-lg);
}

.form-group:last-child {
    margin-bottom: 0;
}

/* Range Input */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    outline: none;
    margin: var(--spacing-sm) 0;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

#skill-display {
    display: inline-block;
    font-weight: 600;
    color: var(--accent);
    margin-left: var(--spacing-sm);
}

/* Select */
select {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.9375rem;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition-fast);
}

select:hover,
select:focus {
    border-color: var(--accent);
}

select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Color Select */
.color-select {
    display: flex;
    gap: var(--spacing-sm);
}

.color-btn {
    flex: 1;
    padding: var(--spacing-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
}

.color-btn:hover {
    border-color: var(--border-light);
}

.color-btn.active {
    color: var(--text-primary);
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
}

/* Game Controls */
.game-controls {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-lg);
}

.game-controls button {
    flex: 1;
}

/* ==========================================================================
   Evaluation Bar
   ========================================================================== */

.evaluation {
    margin-bottom: var(--spacing-lg);
}

.eval-bar {
    height: 24px;
    background: linear-gradient(90deg, #333 0%, #333 50%, #ddd 50%, #ddd 100%);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
}

.eval-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 50%;
    background: #ddd;
    transition: width var(--transition-normal);
}

#eval-value {
    display: block;
    text-align: center;
    font-family: var(--font-mono);
    font-weight: 600;
    margin-top: var(--spacing-xs);
    color: var(--text-secondary);
}

/* ==========================================================================
   Moves List
   ========================================================================== */

.moves-list {
    margin-bottom: var(--spacing-lg);
}

#moves,
#analysis-moves {
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.8;
}

#moves::-webkit-scrollbar,
#analysis-moves::-webkit-scrollbar {
    width: 6px;
}

#moves::-webkit-scrollbar-track,
#analysis-moves::-webkit-scrollbar-track {
    background: transparent;
}

#moves::-webkit-scrollbar-thumb,
#analysis-moves::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}

#moves::-webkit-scrollbar-thumb:hover,
#analysis-moves::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

.move-number {
    color: var(--text-muted);
    margin-right: var(--spacing-xs);
}

.move {
    display: inline-block;
    padding: 2px 6px;
    margin: 2px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.move:hover {
    background: rgba(233, 69, 96, 0.2);
}

.move.active {
    background: var(--accent);
    color: #fff;
}

/* ==========================================================================
   Analysis Layout - Board-Centric Design
   ========================================================================== */

.analysis-layout {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--spacing-md);
}

/* Area principal con lineas + tablero */
.analysis-main {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: var(--spacing-lg);
}

/* Panel de lineas de analisis - a la izquierda del tablero */
.analysis-lines-panel {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

/* Engine badges */
.engine-info {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
}

.engine-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

/* Lista de lineas */
.analysis-lines-list {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 200px;
}

/* Linea individual de analisis */
.analysis-line {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background var(--transition-fast);
    cursor: pointer;
}

.analysis-line:hover {
    background: rgba(255, 255, 255, 0.04);
}

.analysis-line:last-child {
    border-bottom: none;
}

/* Indicador de color de flecha */
.analysis-line .line-color {
    width: 4px;
    align-self: stretch;
    min-height: 28px;
    border-radius: 2px;
    flex-shrink: 0;
}

.analysis-line .line-color.best { background: var(--arrow-best); }
.analysis-line .line-color.alt1 { background: var(--arrow-alt1); }
.analysis-line .line-color.alt2 { background: var(--arrow-alt2); }

/* Badge de evaluacion */
.analysis-line .eval {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 50px;
    padding: 3px 8px;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 700;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

/* Colores de evaluacion */
.eval.eval-winning,
.analysis-line .eval-winning {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.25), rgba(34, 197, 94, 0.1));
    color: #4ade80;
}
.eval.eval-better,
.analysis-line .eval-better {
    background: rgba(34, 197, 94, 0.12);
    color: #86efac;
}
.eval.eval-equal,
.analysis-line .eval-equal {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}
.eval.eval-worse,
.analysis-line .eval-worse {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
}
.eval.eval-losing,
.analysis-line .eval-losing {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.25), rgba(239, 68, 68, 0.1));
    color: #f87171;
}

/* Variante principal */
.analysis-line .pv {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--text-secondary);
    word-break: break-word;
}

.analysis-line .pv strong,
.analysis-line .pv b {
    color: var(--text-primary);
    font-weight: 600;
}

/* Empty state */
.analysis-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    padding: var(--spacing-lg);
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
}

/* ==========================================================================
   Board Area - El Protagonista
   ========================================================================== */

.board-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
}

.board-container {
    position: relative;
    width: 560px;
    height: 560px;
}

/* Tablero con sombra dramatica */
#section-analyze .board {
    width: 100% !important;
    height: 100% !important;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-board);
}

/* Controles de navegacion */
.board-nav {
    display: flex;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.nav-control {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.nav-control svg {
    width: 20px;
    height: 20px;
}

.nav-control:hover {
    color: var(--text-primary);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.nav-control:active {
    transform: translateY(0);
}

/* Arrows overlay */
.arrows-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* ==========================================================================
   Panel Secundario - Movimientos y Carga
   ========================================================================== */

.analysis-secondary {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-md);
    justify-content: center;
}

/* Panel de movimientos */
.moves-panel {
    flex: 1;
    min-width: 280px;
    max-width: 500px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.panel-header h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
}

.moves-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: var(--spacing-sm);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    max-height: 150px;
    overflow-y: auto;
}

#analysis-moves {
    min-height: 60px;
}

.move-number {
    color: var(--text-muted);
    margin-right: 2px;
}

.move {
    display: inline-block;
    padding: 3px 6px;
    margin: 1px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.move:hover {
    background: rgba(233, 69, 96, 0.15);
}

.move.active {
    background: var(--accent);
    color: white;
}

/* Panel colapsable de carga */
.load-position-panel {
    flex: 1;
    min-width: 280px;
    max-width: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.panel-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    list-style: none;
    transition: color var(--transition-fast);
}

.panel-toggle:hover {
    color: var(--text-primary);
}

.panel-toggle::-webkit-details-marker {
    display: none;
}

.toggle-icon {
    width: 20px;
    height: 20px;
    transition: transform var(--transition-fast);
}

.load-position-panel[open] .toggle-icon {
    transform: rotate(180deg);
}

.panel-content {
    padding: 0 var(--spacing-md) var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.input-group label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-row {
    display: flex;
    gap: var(--spacing-xs);
}

.input-row input {
    flex: 1;
}

/* Text Inputs */
input[type="text"],
textarea {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.875rem;
    font-family: var(--font-mono);
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color var(--transition-fast);
    resize: vertical;
}

input[type="text"]:focus,
textarea:focus {
    border-color: var(--accent);
}

input[type="text"]::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

.btn-load {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-load:hover {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
}

/* ==========================================================================
   History Section
   ========================================================================== */

.history-container {
    max-width: 800px;
    margin: 0 auto;
}

.history-container h2 {
    margin-bottom: var(--spacing-xl);
    text-align: center;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.login-prompt {
    text-align: center;
    color: var(--text-secondary);
    padding: var(--spacing-2xl);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.history-item:hover {
    border-color: var(--accent);
    transform: translateX(4px);
}

.history-item .game-info {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.history-item .opponent {
    font-weight: 600;
    color: var(--text-primary);
}

.history-item .date {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.history-item .result {
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: var(--radius-full);
    font-size: 0.8125rem;
    font-weight: 600;
}

.history-item .result.win {
    background: rgba(74, 222, 128, 0.15);
    color: var(--success);
}

.history-item .result.loss {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.history-item .result.draw {
    background: rgba(251, 191, 36, 0.15);
    color: var(--warning);
}

.history-item .actions {
    display: flex;
    gap: var(--spacing-sm);
}

.history-item .btn-analyze {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.75rem;
}

/* ==========================================================================
   Modal
   ========================================================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    width: 100%;
    max-width: 400px;
    position: relative;
    box-shadow: var(--shadow-xl);
    animation: slideUp 0.3s ease;
}

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

.modal-close {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

/* Hide close button when login is required */
.modal.modal-required .modal-close {
    display: none;
}

.modal.modal-required .modal-content::before {
    content: 'Inicia sesion para continuar';
    display: block;
    text-align: center;
    padding: var(--spacing-sm) var(--spacing-md);
    margin: calc(-1 * var(--spacing-lg)) calc(-1 * var(--spacing-lg)) var(--spacing-md);
    background: linear-gradient(135deg, rgba(233, 69, 96, 0.2) 0%, rgba(233, 69, 96, 0.1) 100%);
    border-bottom: 1px solid var(--border-color);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    font-size: 0.875rem;
    color: var(--accent-primary);
    font-weight: 500;
}

.modal h2 {
    margin-bottom: var(--spacing-lg);
    text-align: center;
}

.modal form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.modal .form-group input {
    margin-top: var(--spacing-xs);
}

.modal .btn-primary {
    width: 100%;
    margin-top: var(--spacing-sm);
    padding: var(--spacing-md);
}

.auth-switch {
    text-align: center;
    margin-top: var(--spacing-lg);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.error-message {
    padding: var(--spacing-sm) var(--spacing-md);
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--danger);
    border-radius: var(--radius-md);
    color: var(--danger);
    font-size: 0.875rem;
    text-align: center;
    margin-top: var(--spacing-md);
}

/* ==========================================================================
   Responsive Design - Mobile First
   ========================================================================== */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
    .game-container {
        flex-direction: column;
        align-items: center;
    }

    .side-panel {
        width: 100%;
        max-width: 480px;
    }

    /* Analysis layout en tablet */
    .analysis-main {
        flex-direction: column;
        align-items: center;
    }

    .analysis-lines-panel {
        width: 100%;
        max-width: 480px;
        order: 2;
    }

    .board-container {
        width: 480px;
        height: 480px;
        order: 1;
    }

    #section-analyze .board {
        width: 100% !important;
        height: 100% !important;
    }

    .board-area {
        order: 1;
    }
}

/* Mobile (<768px) */
@media (max-width: 768px) {
    :root {
        --header-height: var(--header-height-mobile);
    }

    /* Header mobile */
    .header {
        padding: 0 var(--spacing-md);
    }

    .logo-text {
        display: none;
    }

    .logo-icon {
        font-size: 1.75rem;
    }

    /* Navegacion inferior estilo app */
    .nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        justify-content: space-around;
        padding: var(--spacing-sm) var(--spacing-md);
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        border-radius: 0;
        z-index: 100;
        gap: 0;
    }

    .nav-btn {
        flex-direction: column;
        gap: 2px;
        padding: var(--spacing-sm);
        flex: 1;
        max-width: 80px;
    }

    .nav-icon {
        font-size: 1.25rem;
    }

    .nav-label {
        font-size: 0.6875rem;
    }

    .nav-btn.active {
        background: transparent;
        color: var(--accent);
    }

    /* Main content con espacio para nav inferior */
    .main-content {
        padding: var(--spacing-md);
        padding-bottom: calc(var(--nav-height-mobile) + var(--spacing-md));
    }

    /* Layout de analisis mobile */
    .analysis-layout {
        gap: var(--spacing-md);
        padding: var(--spacing-sm);
    }

    .analysis-main {
        flex-direction: column;
        gap: var(--spacing-md);
    }

    /* Tablero de analisis en movil - usar calc para ancho de pantalla */
    .board-container {
        width: calc(100vw - 2rem);
        height: calc(100vw - 2rem);
        max-width: 400px;
        max-height: 400px;
    }

    #section-analyze .board {
        width: 100% !important;
        height: 100% !important;
    }

    .analysis-lines-panel {
        width: 100%;
        order: 2;
    }

    /* Engine info como barra horizontal centrada */
    .engine-info {
        justify-content: center;
        padding: var(--spacing-xs) 0;
    }

    /* Lineas como cards */
    .analysis-lines-list {
        background: transparent;
        border: none;
        backdrop-filter: none;
        display: flex;
        flex-direction: column;
        gap: var(--spacing-xs);
        min-height: auto;
    }

    .analysis-line {
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        padding: var(--spacing-sm);
    }

    .analysis-line:last-child {
        border-bottom: 1px solid var(--border-color);
    }

    /* Controles de navegacion mas grandes para touch */
    .nav-control {
        width: 48px;
        height: 48px;
    }

    .nav-control svg {
        width: 22px;
        height: 22px;
    }

    /* Panel secundario en columna */
    .analysis-secondary {
        flex-direction: column;
    }

    .moves-panel,
    .load-position-panel {
        max-width: 100%;
    }

    /* Game section responsive - tablero mas grande en movil */
    #section-play .board {
        width: calc(100vw - 2rem) !important;
        height: calc(100vw - 2rem) !important;
        max-width: 400px !important;
        max-height: 400px !important;
    }

    .board-wrapper {
        width: 100%;
        max-width: 400px;
    }

    .side-panel {
        width: 100%;
    }
}

/* Mobile pequeño (<480px) */
@media (max-width: 480px) {
    .board-nav {
        gap: 2px;
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    .nav-control {
        width: 42px;
        height: 42px;
    }

    /* Tableros en pantallas pequeñas */
    .board-container {
        width: calc(100vw - 1rem);
        height: calc(100vw - 1rem);
        max-width: 340px;
        max-height: 340px;
    }

    #section-analyze .board {
        width: 100% !important;
        height: 100% !important;
    }

    #section-play .board {
        width: 100% !important;
        height: 100% !important;
    }

    .board-wrapper {
        max-width: 340px;
    }

    /* Lineas mas compactas */
    .analysis-line .pv {
        font-size: 0.6875rem;
    }

    .analysis-line .eval {
        min-width: 44px;
        font-size: 0.75rem;
        padding: 2px 6px;
    }

    .config-panel,
    .info-panel {
        padding: var(--spacing-md);
    }

    .modal-content {
        margin: var(--spacing-md);
        padding: var(--spacing-lg);
    }

    /* Engine badges mas compactos */
    .engine-badge {
        font-size: 0.625rem;
        padding: 3px 8px;
    }
}

/* ==========================================================================
   Game Status Messages
   ========================================================================== */

.game-status {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    border: 2px solid var(--accent);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl) var(--spacing-2xl);
    text-align: center;
    z-index: 500;
    box-shadow: var(--shadow-xl);
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.game-status h2 {
    font-size: 1.75rem;
    margin-bottom: var(--spacing-sm);
}

.game-status p {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
}

.game-status .buttons {
    display: flex;
    gap: var(--spacing-md);
    justify-content: center;
}

/* ==========================================================================
   Loading States
   ========================================================================== */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==========================================================================
   Tooltip
   ========================================================================== */

[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    pointer-events: none;
}

[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-4px);
}

/* ==========================================================================
   Focus States (Accessibility)
   ========================================================================== */

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .header,
    .side-panel,
    .modal {
        display: none;
    }

    .main-content {
        padding: 0;
    }

    .board {
        box-shadow: none;
        border: 1px solid #000;
    }
}

/* ==========================================================================
   Piece Selection and Move Highlights
   ========================================================================== */

/* Casilla seleccionada */
.highlight-selected {
    box-shadow: inset 0 0 0 4px var(--accent) !important;
    background-color: rgba(233, 69, 96, 0.3) !important;
}

/* Casillas de movimiento válido (sin pieza) */
.highlight-move {
    position: relative;
}

.highlight-move::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 33%;
    height: 33%;
    background-color: rgba(100, 100, 100, 0.5);
    border-radius: 50%;
    pointer-events: none;
    z-index: 5;
}

/* Casillas de captura (con pieza enemiga) */
.highlight-capture {
    position: relative;
}

.highlight-capture::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    border: 5px solid rgba(233, 69, 96, 0.7);
    pointer-events: none;
    z-index: 5;
    box-sizing: border-box;
}

/* Mejora táctil para móviles - hacer las piezas más fáciles de tocar */
@media (max-width: 768px) {
    .piece-417db {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    /* Hacer los indicadores de movimiento más grandes en móvil */
    .highlight-move::after {
        width: 40%;
        height: 40%;
    }

    .highlight-capture::after {
        border-width: 6px;
    }
}

/* Animación suave para el resaltado */
.highlight-selected,
.highlight-move,
.highlight-capture {
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

/* Cursor pointer para casillas con movimientos válidos */
.highlight-move,
.highlight-capture {
    cursor: pointer !important;
}

/* Mejorar la visibilidad del resaltado en casillas oscuras */
.black-3c85d.highlight-move::after {
    background-color: rgba(140, 140, 140, 0.6);
}

.black-3c85d.highlight-capture::after {
    border-color: rgba(255, 100, 120, 0.8);
}

/* Resaltado de último movimiento */
.highlight-lastmove {
    background-color: rgba(255, 255, 0, 0.3) !important;
}
