﻿/* ===== CSS VARIABLES & DESIGN SYSTEM ===== */

:root {
    /* --- BRAND: EL CIELO (Base) --- */
    --clr-sky-100: #A2D9EF;
    --clr-sky-500: #7EC8E3;
    --clr-sky-900: #4A90A4;

    /* --- SURFACE: TIERRA & PAPEL --- */
    --clr-sand-100: #FAF9F6;
    --clr-sand-300: #E6DCC3;
    --clr-rock-500: #8B7E66;
    --clr-surface-high: #FFFFFF;

    /* --- ACCENT: IDENTIDAD --- */
    --clr-rose-500: #D16BA5;
    --clr-rose-700: #A84B82;

    /* --- FEEDBACK & TEXT --- */
    --clr-gold-500: #DAA520;
    --clr-green-500: #6E8C38;
    --clr-ink-900: #2C241B;
    --clr-ink-100: #4A4A4A;

    /* --- MAPPING --- */
    --bg-primary: var(--clr-surface-high);
    --bg-secondary: var(--clr-sand-100);
    --bg-tertiary: rgba(255, 255, 255, 0.6);

    --text-primary: var(--clr-ink-900);
    --text-secondary: var(--clr-rock-500);
    --text-muted: #666;

    --accent-primary: var(--clr-rose-500);
    --accent-secondary: var(--clr-gold-500);
    --accent-glow: rgba(209, 107, 165, 0.4);

    --success: var(--clr-green-500);
    --error: var(--clr-rose-500);
    --warning: var(--clr-gold-500);

    /* Typography */
    --font-main: 'Nunito', sans-serif;
    --font-display: 'Oswald', sans-serif;
    --font-mono: 'Nunito', sans-serif;

    /* Spacing & Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 50px;

    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    --transition-slow: 0.5s ease;

    --border-light: 1px solid var(--clr-sand-300);
}

/* --- MODO NOCTURNO --- */
[data-theme="dark"] {
    --clr-sky-100: #1e293b;
    --clr-sky-500: #0f172a;
    --clr-sky-900: #020617;
    --clr-sand-100: #1e293b;
    --clr-sand-300: #334155;
    --clr-rock-500: #64748b;
    --clr-surface-high: #0f172a;
    --clr-rose-500: #F472B6;
    --clr-rose-700: #DB2777;
    --clr-gold-500: #FACC15;
    --clr-green-500: #86EFAC;
    --clr-ink-900: #F1F5F9;
    --clr-ink-100: #94a3b8;
}

/* ===== RESET & BASE ===== */

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

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

body {
    font-family: var(--font-main);
    background: var(--clr-surface-high);
    color: var(--clr-ink-900);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== TYPOGRAPHY ===== */

h1,
h2,
h3 {
    font-family: var(--font-display);
    color: var(--clr-rose-500);
    margin-bottom: var(--space-md);
}

h1 {
    font-size: 2.5rem;
}

h2 {
    font-size: 1.75rem;
}

h3 {
    font-size: 1.25rem;
}

/* ===== LAYOUT ===== */

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

/* ===== CONFIG PANEL ===== */

.config-panel {
    background: var(--clr-surface-high);
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    max-width: 600px;
    margin: var(--space-xl) auto;
    box-shadow: 0 20px 40px -5px rgba(74, 144, 164, 0.15);
}

.config-header {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.config-header h1 {
    font-style: italic;
}

.config-header p {
    color: var(--clr-rock-500);
}

/* ===== FORMS ===== */

.form-group {
    margin-bottom: var(--space-lg);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-sm);
    color: var(--clr-rock-500);
    font-weight: 600;
}

input[type="text"],
input[type="number"] {
    width: 100%;
    padding: var(--space-md);
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 1rem;
    background: var(--clr-sand-100);
    color: var(--clr-ink-900);
    transition: all var(--transition-fast);
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: var(--clr-rose-500);
    box-shadow: 0 0 0 3px rgba(209, 107, 165, 0.2);
}

/* ===== MODE SELECTOR ===== */

.mode-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
}

.mode-selector input[type="radio"] {
    display: none;
}

.mode-option {
    background: var(--clr-sand-100);
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: 0 4px 0 var(--clr-sand-300);
}

.mode-option:hover {
    transform: translateY(-2px);
}

.mode-selector input[type="radio"]:checked+.mode-option {
    background: white;
    border-color: var(--clr-rose-500);
    box-shadow: 0 4px 0 var(--clr-rose-500);
}

.mode-icon {
    font-size: 2rem;
    margin-bottom: var(--space-sm);
    color: var(--clr-rose-500);
}

.mode-name {
    font-weight: 700;
    color: var(--clr-ink-900);
    margin-bottom: var(--space-xs);
}

.mode-desc {
    font-size: 0.85rem;
    color: var(--clr-rock-500);
}

/* ===== FACTOR SELECTORS ===== */

.factors-selection-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.factor-selector {
    background: var(--clr-sand-100);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}

.factor-selector h4 {
    color: var(--clr-rock-500);
    margin-bottom: var(--space-sm);
    font-size: 0.9rem;
}

.tables-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--space-xs);
}

.table-btn {
    background: white;
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
    font-weight: 700;
    color: var(--clr-ink-900);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.table-btn:hover {
    border-color: var(--clr-rose-500);
}

.table-btn.active {
    background: var(--clr-rose-500);
    border-color: var(--clr-rose-500);
    color: white;
}

.btn-select-all {
    margin-top: var(--space-sm);
    background: transparent;
    border: 2px solid var(--clr-rose-500);
    color: var(--clr-rose-500);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition-fast);
}

.btn-select-all:hover {
    background: var(--clr-rose-500);
    color: white;
}

/* ===== BUTTONS ===== */

.start-btn,
.btn-primary,
.action-btn {
    background: linear-gradient(to bottom, var(--clr-rose-500), var(--clr-rose-700));
    color: white;
    border: none;
    border-bottom: 4px solid #8B3A62;
    border-radius: var(--radius-full);
    padding: var(--space-md) var(--space-xl);
    font-family: var(--font-main);
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-transform: uppercase;
    letter-spacing: 1px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
}

.start-btn:hover,
.btn-primary:hover,
.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(209, 107, 165, 0.4);
}

.start-btn:active,
.btn-primary:active,
.action-btn:active {
    transform: translateY(2px);
    border-bottom-width: 2px;
}

/* ===== GAME CONTAINER ===== */

.game-container {
    background: var(--clr-surface-high);
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    width: 95%;
    /* Maximizar espacio pero con margen */
    max-width: 1400px;
    /* Limitar ancho en monitores grandes */
    margin: var(--space-md) auto;
    box-shadow: 0 20px 40px -5px rgba(74, 144, 164, 0.15);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.matrix-title {
    font-family: var(--font-display);
    color: var(--clr-ink-900);
}

.progress-counter {
    font-weight: 700;
    color: var(--clr-rose-500);
}

/* ===== GAME GRID ===== */

.matrix-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    padding: var(--space-sm);
    -webkit-overflow-scrolling: touch;
    text-align: center;
}

.game-grid {
    display: inline-grid;
    grid-template-columns: repeat(16, minmax(36px, 1fr));
    gap: 4px;
    min-width: max-content;
    margin: 0 auto;
}

.matrix-cell {
    background: white;
    border: 1px solid var(--clr-sand-300);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-main);
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--clr-ink-900);
    cursor: pointer;
    transition: all var(--transition-fast);
    aspect-ratio: 1;
    min-width: 36px;
    min-height: 36px;
}

.matrix-cell:hover:not(.header):not(.disabled) {
    background: var(--clr-sand-100);
    border-color: var(--clr-rose-500);
    transform: scale(1.05);
    z-index: 5;
}

.matrix-cell.header {
    background: transparent;
    border: none;
    color: var(--clr-rock-500);
    font-weight: 600;
    cursor: default;
}

.matrix-cell.disabled {
    background: var(--clr-sand-100);
    color: #ccc;
    cursor: not-allowed;
}

.matrix-cell.solved {
    background: var(--clr-green-500);
    color: white;
    border-color: var(--clr-green-500);
}

.matrix-cell.active-cell {
    background: var(--clr-sand-300);
    border: 2px solid var(--clr-rose-500);
    color: var(--clr-ink-900);
    transform: scale(1.1);
    z-index: 10;
}

/* ===== OPERATION DISPLAY ===== */

.operation-display {
    text-align: center;
    padding: var(--space-lg);
}

.timer-label {
    font-size: 0.9rem;
    color: var(--clr-rock-500);
    margin-bottom: var(--space-xs);
}

.timer-display {
    font-family: var(--font-display);
    font-size: 3rem;
    color: var(--clr-rose-500);
}

.current-operation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    font-size: 2.5rem;
    font-weight: 700;
    margin: var(--space-lg) 0;
    color: var(--clr-ink-900);
}

.operator {
    color: var(--clr-rose-500);
}

.answer-input {
    width: 120px;
    padding: var(--space-md);
    font-size: 1.5rem;
    text-align: center;
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-md);
    background: white;
    color: var(--clr-ink-900);
}

.answer-input:focus {
    outline: none;
    border-color: var(--clr-rose-500);
}

/* ===== FEEDBACK BUTTONS ===== */

.feedback-buttons {
    display: flex;
    justify-content: center;
    gap: var(--space-lg);
    margin-top: var(--space-lg);
}

.correct-btn {
    color: var(--clr-green-500);
    font-size: 2.5rem;
    background: none;
    border: none;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.wrong-btn {
    color: var(--clr-rose-500);
    font-size: 2.5rem;
    background: none;
    border: none;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.correct-btn:hover,
.wrong-btn:hover {
    transform: scale(1.2);
}

/* ===== MODALS ===== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--clr-surface-high);
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: var(--space-md);
}

.modal-title {
    color: var(--clr-ink-900);
    margin-bottom: var(--space-md);
}

.modal-message {
    color: var(--clr-rock-500);
    margin-bottom: var(--space-lg);
}

/* ===== SPLASH SCREEN ===== */

.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--clr-surface-high);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.8s ease;
}

.aryabhata-logo {
    width: 180px;
    height: auto;
    margin-bottom: var(--space-lg);
    animation: breathe 3s infinite ease-in-out;
}

@keyframes breathe {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.9;
    }

    50% {
        transform: scale(1.05);
        opacity: 1;
    }
}

.splash-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ===== THEME TOGGLE ===== */

.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--clr-sand-100);
    border: 2px solid var(--clr-sand-300);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: all var(--transition-normal);
    color: var(--clr-ink-900);
}

.theme-toggle:hover {
    transform: scale(1.1);
}

/* ===== PHASE INDICATOR ===== */

.phase-indicator {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    background: var(--clr-rose-500);
    color: white;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.9rem;
}

/* ===== VISUAL AID ===== */

.visual-aid-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--clr-surface-high);
    border: 3px solid var(--clr-gold-500);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    z-index: 100;
    text-align: center;
}

.visual-aid-result {
    font-size: 4rem;
    font-weight: 800;
    color: var(--clr-gold-500);
}

/* ===== UTILITIES ===== */

.hidden {
    display: none !important;
}

/* ===== RESPONSIVE ===== */

@media (max-width: 768px) {
    .config-panel {
        margin: var(--space-md);
        padding: var(--space-lg);
    }

    .mode-selector {
        grid-template-columns: 1fr;
    }

    .game-grid {
        gap: 2px;
    }

    .matrix-cell {
        min-width: 28px;
        min-height: 28px;
        font-size: 0.7rem;
    }

    .current-operation {
        font-size: 1.8rem;
    }

    .timer-display {
        font-size: 2rem;
    }
}

/* ===== VIEWS ===== */

.view {
    display: none;
}

.view.active {
    display: block;
}

/* ===== CONFIG CONTAINER ===== */

.config-container {
    max-width: 700px;
    width: 90%;
    /* Margen lateral en móviles */
    margin: 0 auto;
    padding: var(--space-xl);
}

.logo-section {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    background: var(--clr-rose-500);
    border-radius: 50%;
    margin-bottom: var(--space-md);
}

.logo-symbol {
    color: white;
    font-size: 2rem;
    font-weight: 800;
}

.logo-title {
    font-family: var(--font-display);
    font-size: 2.5rem;
    color: var(--clr-rose-500);
    font-style: italic;
    margin-bottom: var(--space-xs);
}

.logo-subtitle {
    color: var(--clr-rock-500);
    font-size: 1rem;
}

.logo-banner {
    width: 100%;
    max-width: 720px;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* ===== CONFIG FORM ===== */

.config-form {
    background: #fdf6b4;
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: 0 10px 40px rgba(126, 200, 227, 0.15);
}

/* ===== TIME SLIDER ===== */

.time-slider-container {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.time-slider-container input[type="range"] {
    flex: 1;
    height: 8px;
    -webkit-appearance: none;
    background: var(--clr-sand-300);
    border-radius: 4px;
    outline: none;
}

.time-slider-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--clr-rose-500);
    border-radius: 50%;
    cursor: pointer;
}

.time-display {
    font-weight: 700;
    color: var(--clr-rose-500);
    min-width: 60px;
}

/* ===== FACTOR HEADER ===== */

.factor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}

.factor-header label {
    font-weight: 600;
    color: var(--clr-rock-500);
    margin: 0;
}

/* ===== TABLES SELECTOR ===== */

.tables-selector {
    background: var(--clr-sand-100);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}

/* ===== ADAPTIVE INFO ===== */

.adaptive-info-card {
    background: linear-gradient(135deg, var(--clr-sky-100), var(--clr-sky-500));
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    display: flex;
    gap: var(--space-md);
    align-items: flex-start;
}

.adaptive-info-icon {
    font-size: 2rem;
}

.adaptive-info-content h4 {
    color: var(--clr-rose-500);
    margin-bottom: var(--space-xs);
}

.adaptive-info-content p {
    color: var(--clr-ink-900);
    font-size: 0.9rem;
    line-height: 1.5;
}

/* ===== START BUTTON CONTAINER ===== */

.start-section {
    text-align: center;
    margin-top: var(--space-xl);
}

/* ===== GAME VIEW ===== */

.game-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: var(--space-lg);
    padding: var(--space-lg);
    max-width: 1400px;
    margin: 0 auto;
}

.matrix-section {
    background: var(--clr-surface-high);
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: 0 10px 40px rgba(126, 200, 227, 0.15);
}

.matrix-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.matrix-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    color: var(--clr-ink-900);
}

.operation-section {
    background: var(--clr-surface-high);
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: 0 10px 40px rgba(126, 200, 227, 0.15);
    text-align: center;
}

/* ===== STATS VIEW ===== */

.stats-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: var(--space-xl);
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.stats-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-family: var(--font-display);
    color: var(--clr-rose-500);
}

.stats-actions {
    display: flex;
    gap: var(--space-sm);
}

.btn-secondary {
    background: var(--clr-sand-100);
    border: 2px solid var(--clr-sand-300);
    color: var(--clr-ink-900);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-secondary:hover {
    background: var(--clr-sand-300);
}

.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.stat-card {
    background: var(--clr-surface-high);
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.stat-icon {
    font-size: 1.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--clr-ink-900);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--clr-rock-500);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-lg);
}

.chart-card {
    background: #fdf6b4;
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
}

.chart-title {
    font-family: var(--font-display);
    color: var(--clr-rose-500);
    margin-bottom: var(--space-md);
}

/* ===== SUMMARY CARDS ===== */

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.summary-card {
    background: #fdf6b4;
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
}

.summary-icon {
    font-size: 1.5rem;
}

.summary-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--clr-ink-900);
}

.summary-label {
    font-size: 0.8rem;
    color: var(--clr-rock-500);
}

/* ===== CHART CONTAINER ===== */

.chart-container {
    position: relative;
    height: 250px;
}

/* ===== MODAL OVERLAY ===== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--clr-surface-high);
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    max-width: 450px;
    width: 90%;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: var(--space-md);
}

.modal-title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    color: var(--clr-ink-900);
    margin-bottom: var(--space-md);
}

.modal-message {
    color: var(--clr-rock-500);
    margin-bottom: var(--space-md);
    line-height: 1.5;
}

.modal-submessage {
    color: var(--clr-rose-500);
    font-weight: 600;
    margin-bottom: var(--space-lg);
}

.btn-modal {
    background: linear-gradient(to bottom, var(--clr-rose-500), var(--clr-rose-700));
    color: white;
    border: none;
    border-bottom: 3px solid #8B3A62;
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-xl);
    font-family: var(--font-main);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-modal:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(209, 107, 165, 0.4);
}

.btn-modal:active {
    transform: translateY(1px);
    border-bottom-width: 1px;
}

/* ===== VICTORY STATS ===== */

.victory-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
    margin: var(--space-lg) 0;
    padding: var(--space-md);
    background: var(--clr-sand-100);
    border-radius: var(--radius-md);
}

.victory-stat {
    text-align: center;
}

.victory-stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--clr-rose-500);
}

.victory-stat-label {
    font-size: 0.75rem;
    color: var(--clr-rock-500);
}

/* ===== WEAKNESSES COUNTER ===== */

.weaknesses-counter {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    background: var(--clr-gold-500);
    color: white;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.9rem;
}

/* ===== RESPONSIVE EXTRA ===== */

@media (max-width: 900px) {
    .game-layout {
        grid-template-columns: 1fr;
    }

    .operation-section {
        order: -1;
    }
}

@media (max-width: 600px) {
    .config-container {
        padding: var(--space-md);
    }

    .config-form {
        padding: var(--space-lg);
    }

    .logo-title {
        font-size: 2rem;
    }

    .tables-grid {
        grid-template-columns: repeat(5, 1fr);
    }

    .victory-stats {
        grid-template-columns: 1fr;
    }

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

/* ===== GAME LAYOUT PANELS ===== */

.game-container {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-lg);
    padding: var(--space-lg);
    max-width: 1400px;
    margin: 0 auto;
    background: transparent;
    border: none;
    box-shadow: none;
    align-items: start;
}

.matrix-panel {
    background: var(--clr-surface-high);
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: 0 10px 40px rgba(126, 200, 227, 0.15);
}

.controls-panel {
    position: sticky;
    top: var(--space-lg);
    background: #fdf6b4;
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: 0 10px 40px rgba(126, 200, 227, 0.15);
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    width: fit-content;
    height: fit-content;
    align-self: start;
}

.matrix-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
}

.matrix-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    color: var(--clr-ink-900);
}

.matrix-progress {
    font-weight: 700;
    color: var(--clr-rose-500);
    font-size: 1.1rem;
}

/* ===== MATRIX GRID ===== */

.matrix-grid {
    display: grid;
    /* grid-template-columns es establecido dinámicamente por JavaScript */
    grid-template-columns: repeat(auto-fit, minmax(32px, 1fr));
    gap: 3px;
}

/* ===== TIMER DISPLAY ===== */

.timer-display {
    text-align: center;
    padding: var(--space-md);
    background: var(--clr-sand-100);
    border-radius: var(--radius-md);
}

.timer-label {
    display: block;
    font-size: 0.85rem;
    color: var(--clr-rock-500);
    margin-bottom: var(--space-xs);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.timer-value {
    display: block;
    font-family: var(--font-display);
    font-size: 2.5rem;
    color: var(--clr-rose-500);
    font-weight: 700;
}

/* ===== OPERATION DISPLAY ===== */

.operation-display {
    text-align: center;
}

.operation-card {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: var(--space-lg);
    color: var(--clr-ink-900);
}

.factor {
    font-size: 3rem;
    font-weight: 800;
    color: var(--clr-ink-900);
}

.operator {
    color: var(--clr-rose-500);
    font-size: 2rem;
}

.equals {
    color: var(--clr-rock-500);
    font-size: 2rem;
}

.answer-input {
    width: 100%;
    max-width: 150px;
    padding: var(--space-md);
    font-size: 2rem;
    text-align: center;
    border: 2px solid var(--clr-sand-300);
    border-radius: var(--radius-md);
    background: white;
    color: var(--clr-ink-900);
    font-weight: 700;
    margin: 0 auto;
    display: block;
}

.answer-input:focus {
    outline: none;
    border-color: var(--clr-rose-500);
    box-shadow: 0 0 0 3px rgba(209, 107, 165, 0.2);
}

/* ===== STATS ROW ===== */

.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.stat-card {
    background: var(--clr-sand-100);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    text-align: center;
}

.stat-card .stat-icon {
    font-size: 1.5rem;
    display: block;
    margin-bottom: var(--space-xs);
}

.stat-correct .stat-icon {
    color: var(--clr-green-500);
}

.stat-wrong .stat-icon {
    color: var(--clr-rose-500);
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--clr-ink-900);
    display: block;
}

.stat-card .stat-label {
    font-size: 0.75rem;
    color: var(--clr-rock-500);
}

/* ===== BTN END ===== */

.btn-end {
    background: var(--clr-sand-100);
    border: 2px solid var(--clr-sand-300);
    color: var(--clr-rock-500);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: auto;
}

.btn-end:hover {
    background: var(--clr-sand-300);
    color: var(--clr-ink-900);
}

/* ===== PHASE BADGE ===== */

.adaptive-phase-indicator {
    margin-bottom: var(--space-md);
}

.phase-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    background: var(--clr-rose-500);
    color: white;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.9rem;
}

.phase-badge.phase-training {
    background: var(--clr-gold-500);
}

/* ===== DASHBOARD ===== */

/* ===== DASHBOARD ===== */

/*#dashboard-view usa el fondo global del body heredado */

.dashboard-container {
    max-width: 1200px;
    width: 90%;
    /* Margen lateral asegurado */
    margin: 24px auto;
    padding: var(--space-xl);

    /* Container Transparente */
    background: transparent;
    border: none;
    box-shadow: none;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.dashboard-title {
    font-family: var(--font-display);
    color: var(--clr-rose-500);
    font-size: 1.75rem;
}

.dashboard-actions {
    display: flex;
    gap: var(--space-sm);
}

.btn-download {
    background: var(--clr-green-500);
    color: white;
    border: none;
    border-bottom: 3px solid #4A6B28;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-download:hover {
    transform: translateY(-1px);
}

/* ===== BTN START ===== */

.btn-start {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    background: linear-gradient(to bottom, var(--clr-rose-500), var(--clr-rose-700));
    color: white;
    border: none;
    border-bottom: 4px solid #8B3A62;
    border-radius: var(--radius-full);
    padding: var(--space-md) var(--space-xl);
    font-family: var(--font-main);
    font-size: 1.2rem;
    font-weight: 800;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: var(--space-xl);
    width: 100%;
}

.btn-start:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(209, 107, 165, 0.4);
}

.btn-start:active {
    transform: translateY(2px);
    border-bottom-width: 2px;
}

.btn-arrow {
    font-size: 1.5rem;
}

/* ===== ADAPTIVE INFO TEXT ===== */

.adaptive-info-text {
    flex: 1;
}

.adaptive-info-text strong {
    color: var(--clr-rose-500);
    font-size: 1rem;
    display: block;
    margin-bottom: var(--space-xs);
}

.adaptive-info-text p {
    color: var(--clr-ink-900);
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 0;
}

/* ===== CONFIG DECORATION (optional) ===== */

.config-decoration {
    display: none;
}

/* ===== RESPONSIVE GAME ===== */

@media (max-width: 900px) {
    .game-container {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        order: -1;
    }

    .matrix-grid {
        /* Mantener gap reducido en tablets */
        gap: 2px;
    }
}

@media (max-width: 600px) {
    .timer-value {
        font-size: 2rem;
    }

    .operation-card {
        font-size: 1.5rem;
    }

    .factor {
        font-size: 2rem;
    }

    .answer-input {
        font-size: 1.5rem;
        padding: var(--space-sm);
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .dashboard-actions {
        width: 100%;
        flex-direction: column;
    }

    .btn-download,
    .btn-secondary {
        width: 100%;
    }
}

/* ===== CELL STATES: CORRECT & WRONG ===== */

.matrix-cell.correct {
    background: var(--clr-green-500) !important;
    color: white !important;
    border-color: var(--clr-green-500) !important;
}

.matrix-cell.wrong {
    background: var(--clr-gold-500) !important;
    color: white !important;
    border-color: var(--clr-gold-500) !important;
    animation: shake 0.3s ease;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-4px);
    }

    75% {
        transform: translateX(4px);
    }
}

/* Mostrar respuesta en celda */
.matrix-cell.show-answer {
    background: white !important;
    color: var(--clr-ink-900) !important;
    border: 2px solid var(--clr-ink-900) !important;
    font-weight: 800;
    z-index: 20;
}

/* ===== ADAPTIVE MODE CELL STATES ===== */

/* Celda de debilidad (a entrenar) */
.matrix-cell.weakness {
    background: var(--clr-gold-500) !important;
    color: white !important;
    border: 2px solid var(--clr-gold-500) !important;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

/* Celda oculta en modo adaptativo (dominada durante diagnóstico) */
.matrix-cell.hidden-adaptive {
    background: var(--clr-sand-100) !important;
    color: #ccc !important;
    border-color: var(--clr-sand-300) !important;
    opacity: 0.4;
    pointer-events: none;
}

/* Celda dominada (completada en entrenamiento) */
.matrix-cell.mastered {
    background: var(--clr-green-500) !important;
    color: white !important;
    border-color: var(--clr-green-500) !important;
}

/* ===== BACKGROUND IMAGE ===== */

/* ===== BACKGROUND IMAGE ===== */

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('../images/baldora_background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.6;
    z-index: -1;
    pointer-events: none;
}

/* Modo oscuro - reducir más la opacidad */
[data-theme="dark"] body::before {
    opacity: 0.2;
}

/* ===== CELDA ACTIVA (OPERACION ACTUAL) ===== */

.matrix-cell.active {
    background-color: var(--clr-sand-300) !important;
    border: 3px solid var(--clr-rose-500) !important;
    color: var(--clr-ink-900) !important;
    transform: scale(1.15);
    z-index: 20;
    box-shadow: 0 0 15px rgba(209, 107, 165, 0.5);
}

/* ===== BTN END POSITION ===== */

.operation-display .btn-end {
    margin-top: var(--space-lg);
    width: 100%;
}

/* ===== AUDIO TOGGLE BUTTON ===== */

.audio-toggle-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--clr-surface-high);
    border: 2px solid var(--clr-sand-300);
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1500;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all var(--transition-fast);
}

.audio-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.audio-toggle-btn:active {
    transform: scale(0.95);
}

.audio-toggle-btn.muted {
    background: var(--clr-sand-300);
    opacity: 0.7;
}

/* ===== DRIVER.JS ONBOARDING STYLES ===== */

/* Popover principal */
.driver-popover {
    background-color: var(--clr-surface-high) !important;
    border: 2px solid var(--clr-sand-300) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: 0 10px 40px rgba(126, 200, 227, 0.25) !important;
    font-family: var(--font-main) !important;
    color: var(--clr-ink-900) !important;
    padding: var(--space-lg) !important;
    max-width: 340px !important;
}

/* Título del popover */
.driver-popover-title {
    font-family: var(--font-display) !important;
    font-size: 1.25rem !important;
    color: var(--clr-rose-700) !important;
    margin-bottom: var(--space-sm) !important;
    line-height: 1.3 !important;
}

/* Descripción del popover */
.driver-popover-description {
    font-size: 0.95rem !important;
    line-height: 1.6 !important;
    color: var(--clr-rock-500) !important;
}

.driver-popover-description strong {
    color: var(--clr-ink-900) !important;
    font-weight: 700 !important;
}

/* Barra de progreso */
.driver-popover-progress-text {
    font-size: 0.8rem !important;
    color: var(--clr-rock-500) !important;
    margin-top: var(--space-sm) !important;
}

/* Footer con botones */
.driver-popover-footer {
    margin-top: var(--space-md) !important;
    padding-top: var(--space-md) !important;
    border-top: 1px solid var(--clr-sand-300) !important;
    gap: var(--space-sm) !important;
}

/* Botón Siguiente / Entendido */
.driver-popover-next-btn,
.driver-popover-done-btn {
    background: var(--clr-rose-500) !important;
    color: white !important;
    border: none !important;
    border-radius: var(--radius-full) !important;
    padding: var(--space-sm) var(--space-md) !important;
    font-family: var(--font-main) !important;
    font-weight: 700 !important;
    font-size: 0.9rem !important;
    text-shadow: none !important;
    cursor: pointer !important;
    transition: all var(--transition-fast) !important;
}

.driver-popover-next-btn:hover,
.driver-popover-done-btn:hover {
    background: var(--clr-rose-700) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(209, 107, 165, 0.4) !important;
}

/* Botón Atrás */
.driver-popover-prev-btn {
    color: var(--clr-rock-500) !important;
    background: transparent !important;
    border: 1px solid var(--clr-sand-300) !important;
    border-radius: var(--radius-full) !important;
    padding: var(--space-sm) var(--space-md) !important;
    font-family: var(--font-main) !important;
    font-weight: 600 !important;
    font-size: 0.9rem !important;
    cursor: pointer !important;
    transition: all var(--transition-fast) !important;
}

.driver-popover-prev-btn:hover {
    background: var(--clr-sand-100) !important;
    border-color: var(--clr-rock-500) !important;
}

/* Botón Cerrar (X) */
.driver-popover-close-btn {
    color: var(--clr-rock-500) !important;
    font-size: 1.2rem !important;
    transition: color var(--transition-fast) !important;
}

.driver-popover-close-btn:hover {
    color: var(--clr-rose-500) !important;
}

/* Flecha del popover */
.driver-popover-arrow {
    border-color: var(--clr-surface-high) !important;
}

.driver-popover-arrow-side-left,
.driver-popover-arrow-side-right {
    border-left-color: var(--clr-surface-high) !important;
    border-right-color: var(--clr-surface-high) !important;
}

.driver-popover-arrow-side-top,
.driver-popover-arrow-side-bottom {
    border-top-color: var(--clr-surface-high) !important;
    border-bottom-color: var(--clr-surface-high) !important;
}

/* Overlay blanco suave */
.driver-overlay {
    background: rgba(255, 255, 255, 0.6) !important;
}

/* Botón de ayuda (repetir tour) */
.btn-help-tour {
    position: fixed;
    top: 76px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--clr-surface-high);
    border: 2px solid var(--clr-sand-300);
    font-size: 1.3rem;
    cursor: pointer;
    z-index: 1400;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all var(--transition-fast);
    color: var(--clr-rock-500);
}

.btn-help-tour:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    border-color: var(--clr-rose-500);
    color: var(--clr-rose-500);
}

/* Modo oscuro para onboarding */
[data-theme="dark"] .driver-popover {
    background-color: var(--clr-surface-high) !important;
    border-color: var(--clr-sand-300) !important;
}

[data-theme="dark"] .driver-popover-title {
    color: var(--clr-rose-500) !important;
}

[data-theme="dark"] .driver-popover-description {
    color: var(--clr-ink-100) !important;
}

[data-theme="dark"] .driver-overlay {
    background: rgba(30, 41, 59, 0.7) !important;
}

/* ===== FOOTER INSTITUCIONAL ===== */

.main-footer {
    width: 100%;
    background-color: var(--clr-sand-100);
    border-top: 2px solid var(--clr-sand-300);
    padding: var(--space-lg) var(--space-xl);
    margin-top: auto;
    font-family: var(--font-main);
    color: var(--clr-rock-500);
    font-size: 0.9rem;
    position: relative;
    overflow: hidden;
    z-index: 5;
    /* Asegurar que el footer esté sobre el fondo global */
}

/* Imagen de fondo desvanecida al 15% */
.main-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('../images/footer_background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.06;
    pointer-events: none;
    z-index: 1;
    /* Sobre el color de fondo */
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-md);
    flex-wrap: wrap;
    position: relative;
    z-index: 2;
    /* Sobre la imagen de fondo */
}

/* --- BLOQUE DE MARCA --- */
.footer-brand {
    display: flex;
    align-items: center;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-decoration: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.brand-link:hover {
    opacity: 0.8;
    transform: translateY(-1px);
}

.brand-logo {
    height: 32px;
    width: auto;
    display: block;
}

.brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 1px;
    color: var(--clr-ink-100);
    transition: color 0.2s ease;
}

.brand-link:hover .brand-name {
    color: var(--clr-rose-500);
}

/* --- BLOQUE LEGAL --- */
.footer-legal {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0;
}

.footer-legal a {
    color: var(--clr-rock-500);
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer-legal a:hover {
    color: var(--clr-rose-500);
}

.footer-legal .separator {
    margin: 0 var(--space-sm);
    opacity: 0.5;
}

/* --- BLOQUE SOCIAL --- */
.footer-social {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.footer-social a {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--clr-rock-500);
    transition: color 0.2s ease, transform 0.2s ease;
}

.footer-social a:hover {
    color: var(--clr-rose-500);
    transform: scale(1.1);
}

.icon-instagram,
.icon-patreon,
.icon-linkedin {
    display: block;
}

/* --- CONTADOR DE VISITAS --- */
.visit-counter {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--clr-rock-500);
    font-size: 0.85rem;
}

.visit-counter .icon-visitors {
    opacity: 0.7;
}

#visit-count {
    font-weight: 600;
    min-width: 30px;
}

/* --- RESPONSIVE FOOTER (Tablet) --- */
@media (max-width: 768px) {
    .main-footer {
        padding: var(--space-md) var(--space-lg);
    }

    .footer-content {
        justify-content: center;
        gap: var(--space-md);
    }

    .brand-logo {
        height: 28px;
    }

    .brand-name {
        font-size: 1rem;
    }
}

/* --- RESPONSIVE FOOTER (Mobile) --- */
@media (max-width: 480px) {
    .main-footer {
        padding: var(--space-md);
    }

    .footer-content {
        flex-direction: column;
        gap: var(--space-sm);
        text-align: center;
    }

    .footer-brand {
        order: 1;
    }

    .footer-legal {
        order: 2;
        flex-direction: column;
        gap: 2px;
    }

    .footer-legal .separator {
        display: none;
    }

    .footer-social {
        order: 3;
    }

    .brand-logo {
        height: 24px;
    }

    .brand-name {
        font-size: 0.95rem;
    }
}

/* --- DARK MODE FOOTER --- */
[data-theme="dark"] .main-footer {
    background-color: var(--clr-surface-high);
    border-color: var(--clr-sand-300);
    color: var(--clr-rock-500);
}

[data-theme="dark"] .brand-name {
    color: var(--clr-ink-900);
}

[data-theme="dark"] .brand-link:hover .brand-name {
    color: var(--clr-rose-500);
}

[data-theme="dark"] .footer-legal a {
    color: var(--clr-rock-500);
}

[data-theme="dark"] .footer-social a {
    color: var(--clr-rock-500);
}

/* ===== PDF EXPORT SYSTEM ===== */

/* --- PDF LETTER LAYOUT --- */
.pdf-letter-container {
    width: 215.9mm;
    height: 279.4mm;
    /* Carta Exacto */
    padding: 15mm;
    background-color: white;
    position: relative;
    font-family: var(--font-main);
    color: var(--clr-ink-900);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow: hidden;
    /* CRÍTICO: Corta cualquier desborde */
}

/* Marca de Agua 9% Opacidad */
.pdf-letter-container::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('../images/baldora_background.png');
    background-size: cover;
    opacity: 0.09;
    z-index: 0;
    pointer-events: none;
}

/* Clase para ocultar marca de agua (usado al generar PDF desde file://) */
.pdf-letter-container.no-watermark::before {
    display: none !important;
    background-image: none !important;
}

/* Elevar contenido sobre la marca de agua */
.pdf-letter-container>* {
    position: relative;
    z-index: 1;
}

/* --- Componentes Internos del PDF --- */

/* Header del PDF */
.pdf-header {
    display: flex;
    align-items: center;
    gap: 20px;
    border-bottom: 2px solid var(--clr-rose-500);
    padding-bottom: 10px;
}

.pdf-logo {
    height: 50px;
}

.pdf-title {
    font-family: var(--font-display);
    color: var(--clr-rose-500);
    font-size: 1.8rem;
    margin: 0;
    line-height: 1;
}

.pdf-subtitle {
    margin: 0;
    color: var(--clr-rock-500);
    font-size: 0.9rem;
}

/* Barra de Metricas del PDF */
.pdf-metrics-bar {
    display: flex;
    justify-content: space-between;
    background: #f0f0f0;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
}

.pdf-metrics-bar .metric-item {
    display: flex;
    flex-direction: column;
}

.pdf-metrics-bar .metric-item .label {
    font-size: 0.7rem;
    color: var(--clr-rock-500);
    font-weight: bold;
}

.pdf-metrics-bar .metric-item .value {
    font-weight: 800;
    font-size: 1.1rem;
}

/* Caja de Analisis AI */
.pdf-ai-insight {
    display: flex;
    gap: 15px;
    background: rgba(209, 107, 165, 0.1);
    border: 1px solid var(--clr-rose-500);
    border-radius: 12px;
    padding: 15px;
    min-height: 70px;
}

.pdf-ai-insight .ai-title {
    margin: 0 0 5px 0;
    font-size: 1rem;
    color: var(--clr-rose-700);
    font-weight: 800;
}

.pdf-ai-insight .ai-text {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.3;
    font-style: italic;
}

.pdf-ai-insight .ai-icon-box {
    font-size: 1.5rem;
    display: flex;
    align-items: center;
}

/* Graficas del PDF (Nucleo Visual) */
.pdf-charts-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 15px;
    flex-grow: 1;
    min-height: 0;
}

.pdf-charts-area .chart-wrapper {
    border: 1px solid var(--clr-sand-300);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.8);
}

.pdf-charts-area .chart-wrapper h4 {
    margin: 0 0 5px 0;
    font-size: 0.8rem;
    text-align: center;
    color: var(--clr-rock-500);
    font-family: var(--font-display);
}

/* Ajuste de imagen para evitar desproporcion */
.pdf-charts-area .img-slot {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.pdf-charts-area .img-slot img {
    max-width: 100%;
    max-height: 140px;
    object-fit: contain;
}

/* Contenedor de canvas para gráficos regenerados */
.pdf-charts-area .canvas-slot {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 120px;
    position: relative;
}

.pdf-charts-area .canvas-slot canvas {
    max-width: 100%;
    max-height: 140px;
}

/* Footer del PDF */
.pdf-footer {
    border-top: 1px solid var(--clr-sand-300);
    padding-top: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--clr-rock-500);
}

.pdf-footer .footer-logo,
.pdf-footer .footer-social-icon {
    height: 16px;
    margin-right: 5px;
    vertical-align: middle;
}

.pdf-footer .footer-left,
.pdf-footer .footer-right {
    display: flex;
    align-items: center;
    gap: 5px;
}

.pdf-footer .footer-center {
    text-align: center;
}

/* --- Modal de Exportacion --- */
#modal-export .export-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

#modal-export .export-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 30px 20px;
    height: auto;
    cursor: pointer;
    transition: all var(--transition-fast);
}

#modal-export .export-btn:hover {
    transform: translateY(-3px);
}

#modal-export .export-icon {
    font-size: 2.5rem;
}

#modal-export .export-title {
    font-size: 1.1rem;
    font-weight: 800;
}

#modal-export .export-desc {
    font-size: 0.8rem;
    opacity: 0.9;
    font-weight: normal;
}

#modal-export .btn-cancel {
    background: none;
    border: none;
    text-decoration: underline;
    cursor: pointer;
    color: var(--clr-rock-500);
    transition: color var(--transition-fast);
}

#modal-export .btn-cancel:hover {
    color: var(--clr-rose-500);
}

/* Botón de opción de exportación (verde) */
.btn-export-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 30px 20px;
    background: var(--clr-green-500);
    color: white;
    border: none;
    border-bottom: 3px solid #4A6B28;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-export-option:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(110, 140, 56, 0.4);
}

.btn-export-option:active {
    transform: translateY(1px);
    border-bottom-width: 1px;
}

.btn-export-option .export-icon {
    font-size: 2.5rem;
}

.btn-export-option .export-title {
    font-size: 1.1rem;
    font-weight: 800;
}

.btn-export-option .export-desc {
    font-size: 0.8rem;
    opacity: 0.9;
    font-weight: normal;
}

/* ===== AI ANALYSIS PANEL ===== */

.ai-panel {
    background: linear-gradient(135deg, #fff 0%, #e8f4fc 100%);
    border: 2px solid var(--clr-sky-500);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    min-height: 180px;
    box-shadow: 0 4px 20px rgba(126, 200, 227, 0.15);
}

.ai-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--clr-sand-300);
}

.ai-icon {
    font-size: 1.5rem;
}

.ai-title {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: #2980b9;
    margin: 0;
    flex-grow: 1;
}

.ai-model-badge {
    background: var(--clr-rose-500);
    color: white;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-content-layout {
    display: flex;
    gap: var(--space-lg);
    align-items: flex-start;
}

.ai-character-col {
    flex-shrink: 0;
}

.character-avatar-wrapper {
    width: 150px;
    height: auto;
    overflow: visible;
    background: transparent;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.character-avatar-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-placeholder {
    font-size: 2.5rem;
}

.ai-text-col {
    flex-grow: 1;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.ai-state-box {
    width: 100%;
}

.ai-prompt-text {
    color: var(--clr-rock-500);
    font-size: 1rem;
    margin-bottom: var(--space-sm);
    line-height: 1.5;
}

.ai-action-btn {
    font-size: 0.95rem !important;
    padding: 12px 24px !important;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%) !important;
    border-color: #2471a3 !important;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
    transition: all var(--transition-fast);
}

.ai-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
}

/* Loading State */
#ai-state-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md);
}

.ai-loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-loading-spinner .pulse-ring {
    width: 40px;
    height: 40px;
    border: 3px solid #3498db;
    border-radius: 50%;
    animation: ai-pulse-ring 1.5s ease-out infinite;
}

@keyframes ai-pulse-ring {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }

    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

.ai-loading-text {
    font-style: italic;
    color: #2980b9;
    font-size: 0.95rem;
    text-align: center;
}

/* Success State - Text Bubble */
.ai-text-bubble {
    background: rgba(255, 255, 255, 0.9);
    padding: var(--space-md);
    border-radius: 0 var(--radius-lg) var(--radius-lg) var(--radius-lg);
    border: 1px dashed #3498db;
    font-family: var(--font-main);
    line-height: 1.6;
    font-size: 0.95rem;
    color: var(--clr-ink-900);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    position: relative;
}

.ai-text-bubble::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 0;
    width: 0;
    height: 0;
    border-top: 10px solid #3498db;
    border-left: 10px solid transparent;
}

/* Chart Visibility States */
.charts-grid.charts-hidden {
    display: none !important;
}

.charts-grid.charts-visible {
    display: grid !important;
    animation: slideUpFade 0.8s ease-out;
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive AI Panel */
@media (max-width: 600px) {
    .ai-content-layout {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .character-avatar-wrapper {
        width: 60px;
        height: 60px;
    }

    .character-placeholder {
        font-size: 2rem;
    }

    .ai-text-bubble {
        border-radius: var(--radius-lg);
    }

    .ai-text-bubble::before {
        display: none;
    }
}

/* ===== API RESULTS VISUALIZATION ===== */
/* Contenedor de la grilla de resultados */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-lg);
    margin-top: var(--space-xl);
    width: 100%;
}

/* Tarjeta General de Resultados */
.result-card {
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    border: 2px solid var(--clr-sand-300);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
    /* Sombra suave */
    transition: transform var(--transition-normal);
    display: flex;
    flex-direction: column;
}

.result-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
}

/* Tema Azul Suave (Solicitado) */
.result-card.blue-theme {
    background-color: #e3f2fd;
    /* Azul muy suave */
    border-color: #bbdefb;
    color: var(--clr-ink-900);
}

.result-card h3 {
    color: var(--clr-sky-900);
    /* Azul más oscuro para títulos */
    border-bottom: 2px solid rgba(74, 144, 164, 0.2);
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-md);
}

/* Estilos internos del contenido */
.stats-grid {
    display: grid;
    gap: var(--space-sm);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
}

.stat-item .label {
    color: var(--clr-rock-500);
    font-weight: 600;
}

.stat-item .value {
    font-weight: 700;
    color: var(--clr-ink-900);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px dashed rgba(0, 0, 0, 0.1);
}

.stat-row .success {
    color: var(--clr-green-500);
}

.stat-row .danger {
    color: var(--clr-rose-500);
}

.result-text {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--clr-ink-900);
    font-weight: 400;
    /* Asegurar que no haya negrita */
}

/* ===== DUAL MOBILE VIEW IMPLEMENTATION (Docs: f12) ===== */
@media (max-width: 768px) {

    /* 1. Ocultar Panel Matriz */
    .matrix-panel {
        display: none !important;
    }

    /* 2. Ajustar Contenedor Principal */
    .game-container {
        display: block;
        /* Cambiar de grid a bloque para centrado simple */
        border: none;
        /* Opcional: limpiar bordes si queda solo el control */
        box-shadow: none;
        background: transparent;
        padding: 0;
        margin-top: var(--space-xl);
    }

    /* 3. Centrar y ajustar Panel de Controles */
    .controls-panel {
        width: 100%;
        max-width: 100%;
        /* Ocupar todo el ancho disponible */
        margin: 0 auto;
        position: static;
        /* Quitar sticky */
        background: var(--clr-surface-high);
        /* Asegurar fondo visible */

        /* Mejorar experiencia táctil */
        padding: var(--space-lg);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    }

    /* Ajustes específicos para elementos internos en móvil */
    .operation-display {
        padding: var(--space-md) 0;
    }

    .answer-input {
        width: 100%;
        /* Input grande para fácil toque */
        max-width: 200px;
        font-size: 2rem;
    }
}

/* ============================================================
   FEATURE 13: Botón Compartir Instagram - NUEVO
   ============================================================ */

/* Botón Instagram - Estilo unificado VERDE */
.export-button-instagram {
    background: var(--clr-green-500);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    border: none;
    border-bottom: 3px solid #4A6B28;
    /* Mismo borde oscuro que otros botones */
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-size: 16px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    min-width: 180px;
    justify-content: center;
}

.export-button-instagram:hover {
    transform: translateY(-1px);
    /* Eliminada sombra de color para mantener consistencia */
}

.export-button-instagram:active {
    transform: translateY(1px);
    border-bottom-width: 1px;
}

.export-button-instagram .icon-instagram {
    width: 20px;
    height: 20px;
}

/* Responsive */
@media (max-width: 768px) {
    .export-button-instagram {
        min-width: 100%;
        margin-top: 10px;
    }
}