/* Variables de colores para temas */
:root {
    /* Tema claro (por defecto) */
    --bg-primary: linear-gradient(0deg, #c7c7c7 0%, #ededed 100%);
    --bg-secondary: #eeeff0;
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    --bg-footer: #f8f9fa;
    --btn-primary: #fff;
    --text-primary: #333;
    --text-secondary: #666;
    --text-muted: #999;
    --text-header: #000000;
    --text-footer: #666;
    --border-primary: #484848;
    --border-secondary: #e9ecef;
    --border-header: rgba(0, 0, 0, 0.1);
    --accent-primary: #2c2c2c;
    --options-hover: #2c2c2c;
    --bg-audio-button: #7ad358;
    --accent-success: #2bbc4d;
    --shadow-primary: rgba(0, 0, 0, 0.1);
    --shadow-success: rgba(40, 167, 69, 0.4);
    --transparent-text: rgba(255, 255, 255, 0.25);
    --full-transparent: rgba(255, 255, 255, 0);
    --theme-icon: #000;
    --btn-a: #4a90e2; /* Azul */
    --btn-b: #e94e77; /* Rosa */
}

[data-theme="dark"] {
    --bg-primary: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    --bg-secondary: #393838;
    --bg-card: #1e1e1e;
    --bg-header: linear-gradient(135deg, #1a1a1a 0%, #342935 100%);
    --bg-footer: #1a1a1a;
    --btn-primary: #000;
    --text-primary: #fff;
    --text-secondary: #ccc;
    --text-muted: #888;
    --text-header: #fff;
    --text-footer: #ccc;
    --border-primary: #404040;
    --border-secondary: #333;
    --border-header: rgba(255, 255, 255, 0.1);
    --accent-primary: #ffffff;
    --options-hover: #404040;
    --accent-success: #10b981;
    --shadow-primary: rgba(0, 0, 0, 0.3);
    --shadow-success: rgba(16, 185, 129, 0.4);
    --theme-icon: #fff;
    --btn-a: #4a90e2; /* Azul */
    --btn-b: #e94e77; /* Rosa */
}

/* Reset y base */
* { margin: 0; padding: 0; box-sizing: border-box; }

h1, h2, h3, h4, h5, h6 {
  margin-bottom: 0;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: background 0.3s, color 0.3s;
}
.main-content, .container {
    flex: 1 0 auto;
}

/* Layout principal */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px;
}

/* Header y Footer */
.main-header {
    position: static;
    background: var(--bg-header);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    border-bottom: 1px solid var(--border-header);
    transition: background 0.3s, border-color 0.3s;
}

.header-container {
    max-width: 1160px;
    margin: 0 auto;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-title {
    flex-grow: 1;
    max-width: none;
    display: flex;
    align-items: center;
    height: 40px;
}

.header-title a {
    color: var(--text-header);
    text-decoration: none;
    font-size: 1.5rem;
    font-weight: 100;
    transition: color 0.3s;
    display: flex;
    align-items: center;
    height: 100%;
}

.header-controls {
    display: flex;
    align-items: center;
    height: 40px;
    gap: 20px;
}

.theme-toggle, .info-toggle{
    background: transparent;
    border: none;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 0;
    font-family: inherit;
}
.theme-toggle:focus { outline: none; }
.theme-toggle:hover .theme-icon .material-icons { transform: rotate(180deg); }
.theme-icon .material-icons {
    font-size: 24px;
    color: var(--theme-icon);
    line-height: 1;
    vertical-align: middle;
    transition: transform 0.3s;
}
.info-toggle i {
    font-size: 18px;
    color: var(--theme-icon, #666);
    vertical-align: middle;
}

/* Hover y focus */
.info-toggle:hover i,
.info-toggle:focus i {
    color: var(--theme-icon, #007bff);
    transform: scale(1.1);
}

/* Para accesibilidad */
.info-toggle:focus {
    outline: none;
}

.popover .popover-body {
  text-align: justify;
}

.main-footer {
    background: var(--bg-footer);
    color: var(--text-footer);
    text-align: center;
    padding: 15px 0;
    border-top: 1px solid var(--border-secondary);
    transition: background 0.3s, color 0.3s, border-color 0.3s;
    flex-shrink: 0;
}
.footer-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}
.footer-container p {
    margin: 3px 0;
    font-size: 0.9rem;
    transition: color 0.3s;
}

/* Tarjetas */
.welcome-card, .calibration-card, .test-card, .results-card {
    background: var(--bg-card);
    border-radius: 15px;
    padding: 40px;
    box-shadow: 0 20px 40px var(--shadow-primary);
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    text-align: center;
    transition: background 0.3s, box-shadow 0.3s;
    min-height: 520px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Títulos */
h2 {
    color: var(--text-primary);
    margin-bottom: 30px;
    font-size: 2rem;
    font-weight: 200;
    transition: color 0.3s;
}
h3 {
    color: var(--text-secondary);
    padding: 10px 0;
    font-size: 1.5rem;
    font-weight: 500;
    transition: color 0.3s;
}

/* Instrucciones */
.instructions {
    text-align: justify;
}
.instructions p {
    margin-bottom: 15px;
    line-height: 1.6;
    color: var(--text-secondary);
    font-size: 1.1rem;
    transition: color 0.3s;
}

/* Formularios */
.form-group { margin-bottom: 20px; text-align: left; }
.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
    transition: color 0.3s;
}
.form-group select, .form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg-card);
    color: var(--text-primary);
    transition: border-color 0.3s, background 0.3s, color 0.3s;
}
.form-group select:focus, .form-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Botones */
.button-group {
    margin-top: 30px;
    display: flex;
    gap: 15px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.btn-primary, .btn-secondary, .btn-audio {
    border: none;
    border-radius: 8px;
    padding: 15px 20px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-block;
    min-width: 80px;
    line-height: 1;
    will-change: transform;
    backface-visibility: hidden;
}
.button-group:has(#start-test-btn) {
    justify-content: center;
}
.btn-primary {
    background: var(--accent-primary);
    border: 2px solid var(--border-primary);
    color: var(--btn-primary);
}
.btn-primary:hover {
    transform: translateY(2px);
    background: var(--accent-primary);
    border: 2px solid var(--border-primary);
    color: var(--btn-primary);
}
.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-primary);
}
.btn-secondary:hover {
    background: var(--options-hover);
    border-color: var(--options-hover);
}

/* Botones deshabilitados con timeout */
.btn-secondary:disabled {
    background: var(--bg-secondary) !important;
    color: var(--text-muted) !important;
    border-color: var(--border-secondary) !important;
    cursor: not-allowed !important;
    transform: none !important;
    opacity: 0.6;
}

.btn-secondary:disabled:hover {
    background: var(--bg-secondary) !important;
    border-color: var(--border-secondary) !important;
    transform: none !important;
}

/* Botones de audio específicos */

.audio-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    /* justify-content se define por contexto */
}
/* Centrado solo para calibración */
.calibration-card .audio-controls {
    justify-content: center;
}

/* Espaciado para el test ABX */
.test-card .audio-controls {
    justify-content: center;
    gap: 20px;
    padding: 20px;
}

.help-text {
    padding: 30px 0;
}

.btn-audio {
    background: var(--bg-audio-button);
    color: #fff;
    font-size: 1.1rem;
    min-width: 100px;
    min-height: 48px;
    padding: 15px 20px;
    border-radius: 8px;
    transition: all 0.3s;
    white-space: normal;
    box-sizing: border-box;
    transform: translateY(0);
    border: 3px solid var(--full-transparent);
}
#btn-a, .btn-audio.btn-a {
    background: var(--btn-a)
}
#btn-b, .btn-audio.btn-b {
    background: var(--btn-b);
}
/* Estilos adicionales para el botón Audio X */
#btn-x, .btn-audio.btn-x {
    background: var(--text-muted);
    color: #fff;
    transform: translateY(0);
}
.btn-audio:hover, #btn-x:hover {
    filter: brightness(1.15);
}   
.btn-audio.current-stimulus, #btn-x.current-stimulus {
    transform: translateY(3px);
    border: 3px solid var(--transparent-text);
}

/* Progreso del test */
.progress-bar {
    background: var(--border-secondary);
    border-radius: 10px;
    height: 8px;
    margin: 20px 0;
    overflow: hidden;
    transition: background 0.3s;
}
.progress-fill {
    background: var(--accent-primary);
    height: 100%;
    transition: width 0.3s, background 0.3s;
}
.progress-text {
    margin: 10px 0;
    color: var(--text-secondary);
    font-weight: 500;
    transition: color 0.3s;
}

/* Opciones de respuesta */
.response-options {
    display: flex;
    gap: 15px;
    justify-content: center;
    padding: 30px 20px;
    flex-wrap: wrap;
    transition: opacity 0.3s ease-in-out;
}
.response-options .btn-secondary {
    min-width: 150px;
    font-size: 1.1rem;
    line-height: 1.2;
    will-change: transform;
}

/* Mensaje de confirmación de respuesta */
.response-confirmation {
    display: none;
    justify-content: center;
    align-items: center;
    margin: 30px 0;
    opacity: 0;
    will-change: transform;
    transition: opacity 0.3s ease-in-out;
}

.response-confirmation.show {
    display: flex;
    opacity: 1;
    will-change: transform;
}

.confirmation-message {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--accent-success);
    color: #fff;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 500;
    box-shadow: 0 4px 12px var(--shadow-success);
    will-change: transform;
    animation: confirmationPulse 0.6s ease-out;
    box-sizing: border-box;
    line-height: 1.2;
}

.confirmation-message i {
    font-size: 1.2rem;
    will-change: transform;
}

@keyframes confirmationPulse {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Calibración */
.calibration-info {
    background: var(--bg-secondary);
    border: 2px solid var(--border-secondary);
    border-radius: 10px;
    padding: 20px;
    margin: 20px 0;
    text-align: left;
    transition: background 0.3s, border-color 0.3s;
}
.calibration-info ul { margin: 15px 0; padding-left: 20px; }
.calibration-info li {
    margin: 8px 0;
    color: var(--text-secondary);
    transition: color 0.3s;
}

/* Resultados */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 20px 0;
}
.stat-item {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 10px;
    text-align: center;
    transition: background 0.3s;
}
.global-stat-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--accent-primary);
    margin-bottom: 5px;
    letter-spacing: 0.5px;
}
.global-stat-label {
    color: var(--text-secondary);
    font-size: 1.05rem;
    font-weight: 400;
    letter-spacing: 0.2px;
}
.stats-scroll-row {
    display: flex;
    flex-direction: row;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-primary) var(--bg-secondary);
}
.stat-item-compact {
    min-width: 50px;
    padding: 12px 8px;
    margin: 0;
    background: var(--bg-secondary);
    border-radius: 10px;
    text-align: center;
    flex: 1 1 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.stat-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: color 0.3s;
}
.stat-percentage {
    font-size: 1rem;
    font-weight: bold;
    color: var(--accent-primary, #007bff);
    margin: 8px 0 4px 0;
    transition: color 0.3s;
}
.additional-info p {
    text-align: justify;
}
.btn-group .btn {
    min-width: 140px;
    font-size: 1.1rem;
    font-weight: 500;
    border-radius: 8px;
    border: none;
    color: var(--text-primary);
    background: var(--bg-card);
    transition: 
        background 0.2s, 
        color 0.2s, 
        box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.btn-group .btn.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    z-index: 2;
}
.btn-group .btn:focus {
    outline: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.btn:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}
/* Tabla de resultados estilo tarjeta */
.abx-table {
    width: 100%;
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: 15px;
    overflow: hidden;
    font-family: inherit;
    box-shadow: none;
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 0;
}
.abx-table th, .abx-table td {
    background: var(--bg-card);
    color: var(--text-primary);
    border: none;
    font-size: 1rem;
    font-weight: 400;
    padding: 10px 8px;
    text-align: center;
    white-space: nowrap;
    
}
.abx-table th {
    font-weight: 600;
    background: var(--bg-secondary);
    color: var(--accent-primary);
    border-bottom: 2px solid var(--border-secondary);
}
.abx-table tr {
    border-radius: 10px;
    transition: background 0.2s;
}
.abx-table tbody tr:hover {
    background: var(--border-secondary);
}
.abx-table td {
    border-bottom: 1px solid var(--border-secondary);
}
.abx-table tr:last-child td {
    border-bottom: none;
}
.results-card {
    border-radius: 15px;
    background: var(--bg-card);
    box-shadow: 0 20px 40px var(--shadow-primary);
    padding: 40px;
    margin: 0 auto 30px auto;
    max-width: 1000px;
    width: 100%;
}

/* Responsive solo para móviles */

@media (max-width: 768px) {
    body { 
        padding: 0;
        background: var(--bg-card);
    }
    .main-header {
        position: static;
    }
    .main-content {
        padding: 40px; 
        min-height: calc(100vh - 110px);
        background-color: var(--bg-card);
        box-sizing: border-box;
        width: 100%;
    }
    .container, .container-fluid {
        padding: 0;
        margin: 0;
        max-width: none;
        width: 100%;
    }
    .welcome-card, .calibration-card, .test-card, .results-card {
        border-radius: 0;
        padding: 0;
        margin: 0;
        box-shadow: none;
        min-height: unset;
        background: transparent;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
    }
    .instructions,
    .form-group,
    .button-group {
        padding-left: 4px;
        padding-right: 4px;
    }

    /* AUDIO CONTROLS: A y B en fila, X debajo */
    .audio-controls {
        display: flex;
        flex-wrap: wrap;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 0;
        width: 100%;
        margin: 0 auto;
    }
    .audio-controls #btn-a,
    .audio-controls #btn-b {
        flex: 1 1 40%;
        max-width: 48%;
        order: 1;
        margin-bottom: 0;
        margin-top: 0;
    }
    .audio-controls #btn-x {
        flex: 1 1 100%;
        max-width: 100%;
        order: 2;
    }

    .stats-grid { grid-template-columns: 1fr; }
    .stat-item-compact {
        min-width: 90px;
        max-width: 100px;
        flex: 0 0 90px;
    }
    .btn-audio, .btn-primary, .btn-secondary {
        width: 100%;
        max-width: none;
        padding: 15px;
        font-size: 1rem;
        box-sizing: border-box;
    }
    .btn-play {
        width: 100%;
        max-width: 300px;
        padding: 16px 30px;
        font-size: 1.2rem;
    }
    .main-footer { 
        padding: 10px 0; 
        position: static;
        background: var(--bg-footer);
        z-index: 1001;
        border-top: 1px solid var(--border-secondary);
    }
    .footer-container { padding: 0 10px; }
    .footer-container p { margin: 2px 0; font-size: 0.8rem; }
    .footer-container p small { display: none; }
    
    /* Responsive styles for confirmation message */
    .response-confirmation {
        margin: 30px 0;
    }
    .confirmation-message {
        padding: 15px 20px;
        font-size: 1rem;
        min-height: 48px;
        text-align: center;
    }
    .confirmation-message i {
        font-size: 1.2rem;
    }
    .btn-group .btn {
        min-width: 100px;
        font-size: 1rem;
        padding: 10px 0;
    }
}


button:disabled,
.btn-audio:disabled,
.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(60%);
}
