/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
    --primary:         #1565C0;
    --primary-dark:    #0D47A1;
    --primary-mid:     #1976D2;
    --primary-light:   #E3F0FF;
    --primary-xlight:  #F0F6FF;

    --success:         #2E7D32;
    --success-bg:      #E8F5E9;
    --warning:         #F57F17;
    --warning-bg:      #FFFDE7;
    --danger:          #C62828;
    --danger-bg:       #FFEBEE;

    --text:            #0D1B38;
    --text-secondary:  #475569;
    --text-muted:      #8898AA;
    --surface:         #FFFFFF;
    --bg:              #F2F6FB;
    --border:          #DDE4EF;
    --border-strong:   #B0BCCE;
    --input-bg:        #F8FAFD;

    --font:            'Inter', Arial, sans-serif;
    --radius-sm:       6px;
    --radius-md:       10px;
    --radius-lg:       16px;
    --radius-xl:       22px;
    --radius-full:     9999px;

    --shadow-xs:  0 1px 2px rgba(13,27,56,0.06);
    --shadow-sm:  0 2px 6px rgba(13,27,56,0.08);
    --shadow-md:  0 4px 16px rgba(13,27,56,0.10);
    --shadow-lg:  0 8px 28px rgba(13,27,56,0.13);
    --shadow-xl:  0 16px 48px rgba(13,27,56,0.16);

    --ease:        200ms ease;
    --ease-slow:   320ms ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 8px rgba(13,27,56,0.22);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
}

.header-logo {
    height: 32px;
    width: auto;
    display: block;
    object-fit: contain;
}

.header-divider {
    width: 1px;
    height: 18px;
    background: rgba(255,255,255,0.35);
}

.header-subtitle {
    font-size: 0.8125rem;
    color: rgba(255,255,255,0.78);
    font-weight: 400;
}

/* ============================================================
   MAIN CONTAINER
   ============================================================ */
.app-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.25rem 3rem;
}

.hidden { display: none !important; }

/* ============================================================
   START SCREEN
   ============================================================ */
.start-screen {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 3rem 2.5rem;
    box-shadow: var(--shadow-md);
}

.start-hero {
    display: flex;
    align-items: center;
    gap: 3.5rem;
}

.start-text { flex: 1; }

.start-title {
    font-size: clamp(1.5rem, 3vw, 2.1rem);
    font-weight: 700;
    color: var(--primary-dark);
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin-bottom: 1.5rem;
}

.start-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.start-desc {
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 0.875rem;
}

.start-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 1.75rem;
}

.start-stats {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.stat-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.6rem 1.1rem;
    background: var(--primary-xlight);
    border: 1px solid rgba(21,101,192,0.15);
    border-radius: var(--radius-md);
    min-width: 72px;
}

.stat-num {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary-dark);
    line-height: 1;
}

.stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
    letter-spacing: 0.04em;
}

.start-image-wrap {
    flex: 1.3;
    max-width: 50%;
}

.start-img {
    width: 100%;
    height: auto;
    object-fit: contain;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    font-family: var(--font);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.7rem 1.75rem;
    min-height: 46px;
    transition: background var(--ease), transform var(--ease), box-shadow var(--ease);
    box-shadow: 0 3px 10px rgba(21,101,192,0.32);
    letter-spacing: 0.01em;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(21,101,192,0.38);
}

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

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-secondary);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-full);
    font-family: var(--font);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.7rem 1.75rem;
    min-height: 46px;
    transition: all var(--ease);
}

.btn-secondary:hover {
    border-color: var(--text-secondary);
    background: var(--bg);
    color: var(--text);
}

.btn-lg { padding: 0.875rem 2.25rem; font-size: 1rem; min-height: 52px; }
.btn-full { width: 100%; }

.start-cta { margin-top: 0.25rem; }

/* ============================================================
   QUIZ SCREEN
   ============================================================ */
.quiz-screen { padding-top: 0.5rem; }

/* --- Progress --- */
.progress-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem 0.875rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-xs);
}

@media (max-width: 768px) {
    .progress-wrap {
        position: sticky;
        top: 56px;
        z-index: 50;
        border-radius: 0;
        margin-bottom: 1rem;
        margin-left: -1.25rem;
        margin-right: -1.25rem;
        border-left: none;
        border-right: none;
    }
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
}

.progress-cat-label {
    font-size: 0.85rem;
    font-weight: 600;
    transition: color var(--ease);
}

.progress-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.progress-track {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-mid), var(--primary));
    border-radius: var(--radius-full);
    width: 0%;
    transition: width var(--ease-slow);
}

/* Category dots */
.category-dots {
    display: flex;
    gap: 0.45rem;
    align-items: center;
}

.cat-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--border);
    transition: all var(--ease);
    cursor: default;
}

.cat-dot.done {
    background: var(--cat-color, var(--primary));
    border-color: var(--cat-color, var(--primary));
    opacity: 0.55;
}

.cat-dot.active {
    background: var(--cat-color, var(--primary));
    border-color: var(--cat-color, var(--primary));
    transform: scale(1.35);
    box-shadow: 0 0 0 3px rgba(var(--cat-color-rgb, 21,101,192), 0.18);
}

/* --- Quiz layout --- */
.quiz-layout {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.question-area { flex: 3; min-width: 0; }

.quiz-sidebar {
    flex: 2.5;
    position: sticky;
    top: 72px;
    background: var(--primary-xlight);
    border: 1px solid rgba(21,101,192,0.12);
    border-radius: var(--radius-lg);
    padding: 1rem;
    overflow: hidden;
}

.sidebar-img {
    width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    object-fit: contain;
    max-height: 430px;
}

/* --- Question card --- */
.question-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-top: 4px solid var(--cat-color, var(--primary));
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    animation: slideInRight 0.26s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.question-card.slide-back {
    animation: slideInLeft 0.26s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(36px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-36px); }
    to   { opacity: 1; transform: translateX(0); }
}

.question-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    margin-bottom: 1rem;
}

.question-text {
    font-size: 1.025rem;
    font-weight: 500;
    color: var(--text);
    line-height: 1.6;
    margin-bottom: 1.25rem;
}

/* --- Options --- */
.options-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.option-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.8rem 1rem;
    background: var(--input-bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--ease), border-color var(--ease), transform var(--ease), box-shadow var(--ease);
    min-height: 48px;
    user-select: none;
}

.option-card:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    transform: translateX(4px);
}

.option-card input[type="radio"] { display: none; }

.option-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border-strong);
    flex-shrink: 0;
    transition: all var(--ease);
}

.option-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.option-card.selected {
    background: var(--sel-color, var(--primary));
    border-color: var(--sel-color, var(--primary-dark));
    color: #fff;
    transform: translateX(4px);
    box-shadow: 0 3px 10px rgba(21,101,192,0.28);
}

.option-card.selected .option-dot {
    border-color: rgba(255,255,255,0.6);
    background: rgba(255,255,255,0.3);
    box-shadow: inset 0 0 0 3px rgba(255,255,255,0.8);
}

.option-card.selected .option-text { color: #fff; font-weight: 500; }

/* --- Back button --- */
.btn-back {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 1.25rem;
    padding: 0.55rem 1.1rem;
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--ease);
    min-height: 40px;
}

.btn-back:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--border-strong);
    background: var(--bg);
}

.btn-back:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ============================================================
   RESULTS SCREEN
   ============================================================ */
.results-screen { animation: fadeUp 0.3s ease both; }

.results-header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.75rem;
}

.results-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    margin: 0;
}

.results-score-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avg-badge {
    font-size: 1rem;
    font-weight: 700;
    padding: 0.25rem 0.875rem;
    border-radius: var(--radius-full);
    border: 1.5px solid transparent;
    letter-spacing: 0.01em;
    flex-shrink: 0;
}

.level-label {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

/* --- Results layout --- */
.results-layout {
    display: flex;
    gap: 1.75rem;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.chart-wrap {
    flex: 3;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    min-height: 420px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-wrap canvas { max-height: 400px; }

/* --- Scores panel --- */
.scores-panel {
    flex: 2;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.25rem 1.25rem 1rem;
    box-shadow: var(--shadow-sm);
}

.scores-panel-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.score-row {}

.score-row-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

.score-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

.score-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}

.score-pct {
    font-size: 0.82rem;
    font-weight: 700;
}

.score-bar-track {
    height: 6px;
    background: var(--border);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.8s cubic-bezier(0.34,1.4,0.64,1);
}

/* --- Results footer --- */
.results-footer {
    text-align: center;
    padding: 2rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}

.results-hint {
    font-size: 0.95rem;
    color: var(--text-secondary);
    max-width: 520px;
    margin: 0 auto 1.5rem;
    line-height: 1.65;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(13,27,56,0.52);
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    z-index: 1;
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 2rem 2rem 1.75rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-xl);
    animation: fadeUp 0.2s ease both;
}

.modal-header { margin-bottom: 1.5rem; }

.modal-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.modal-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.modal-form { display: flex; flex-direction: column; gap: 0.875rem; }

.form-field { display: flex; flex-direction: column; gap: 0.35rem; }

.form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.03em;
}

.form-input {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--input-bg);
    transition: border-color var(--ease), box-shadow var(--ease);
    min-height: 48px;
}

.form-input::placeholder { color: var(--text-muted); }

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(21,101,192,0.12);
    background: var(--surface);
}

.form-input.has-error {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(198,40,40,0.10);
}

.form-error {
    display: block;
    font-size: 0.78rem;
    color: var(--danger);
    min-height: 1em;
    margin-top: 0.25rem;
    animation: fadeIn 0.15s ease both;
}

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

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 600;
    background: rgba(13,27,56,0.55);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.loading-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 2.25rem 2rem;
    text-align: center;
    box-shadow: var(--shadow-xl);
    max-width: 360px;
    width: 100%;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    margin: 0 auto 1rem;
}

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

.loading-msg {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin-bottom: 0;
}

.status-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 auto 1rem;
}

.success-icon { background: var(--success-bg); color: var(--success); }
.error-icon   { background: var(--danger-bg);  color: var(--danger); }

/* ============================================================
   RESPONSIVE — TABLET 768px
   ============================================================ */
@media (max-width: 768px) {
    .app-main { padding: 1.25rem 1rem 2.5rem; }

    .start-screen { padding: 2rem 1.5rem; }

    .start-hero {
        flex-direction: column;
        gap: 1.75rem;
    }

    .start-image-wrap {
        max-width: 85%;
        margin: 0 auto;
    }

    .start-title { font-size: 1.5rem; }

    .quiz-layout {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .quiz-sidebar { display: none; }

    .sidebar-img { max-height: 200px; width: auto; }

    .results-layout {
        flex-direction: column;
        align-items: stretch;
        gap: 1.25rem;
    }

    .chart-wrap {
        min-height: 300px;
        padding: 0.5rem;
        background: transparent;
        border: none;
        box-shadow: none;
    }

    .chart-wrap canvas { max-height: 300px; }

    .scores-panel {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem 1.25rem;
        padding: 1rem;
        border-radius: var(--radius-xl);
    }

    .scores-panel-title {
        grid-column: 1 / -1;
        margin-bottom: 0;
    }

    .results-header { gap: 0.4rem; }

    /* Botón de descarga sticky en mobile */
    .results-footer {
        position: sticky;
        bottom: 0;
        background: var(--surface);
        border-top: 1px solid var(--border);
        border-radius: 0;
        box-shadow: 0 -4px 16px rgba(13,27,56,0.10);
        padding: 1rem 1.25rem;
        margin-left: -1rem;
        margin-right: -1rem;
        display: flex;
        align-items: center;
        gap: 1rem;
        z-index: 50;
    }

    .results-hint {
        font-size: 0.8rem;
        margin: 0;
        text-align: left;
        flex: 1;
    }

    .results-footer .btn-primary {
        width: auto;
        white-space: nowrap;
        flex-shrink: 0;
    }
}

/* ============================================================
   RESPONSIVE — MOBILE 480px
   ============================================================ */
@media (max-width: 480px) {
    .app-header { height: 50px; }
    .header-subtitle { display: none; }

    .app-main { padding: 1rem 0.75rem 2rem; }

    .start-screen { padding: 1.5rem 1.125rem; border-radius: var(--radius-lg); }
    .start-title { font-size: 1.3rem; }
    .start-image-wrap { max-width: 100%; }

    .start-stats { gap: 0.5rem; }
    .stat-chip { padding: 0.5rem 0.75rem; min-width: 60px; }

    .question-card { padding: 1.125rem 1rem; }
    .question-text { font-size: 0.9375rem; }
    .option-card { padding: 0.7rem 0.875rem; }

    .option-card:hover { transform: none; }
    .option-card.selected { transform: none; }

    .chart-wrap { min-height: 240px; }

    .scores-panel {
        grid-template-columns: 1fr;
        padding: 1rem 0.75rem;
        border-radius: var(--radius-xl);
    }

    .scores-panel-title { grid-column: 1; }

    .results-footer {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.875rem 1rem;
    }

    .results-hint { text-align: center; }

    .results-footer .btn-primary { width: 100%; }

    .modal-card { padding: 1.5rem 1.25rem; border-radius: var(--radius-lg); }

    .btn-lg { font-size: 0.9375rem; padding: 0.8rem 1.5rem; }

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

    .category-dots { gap: 0.35rem; }
    .cat-dot { width: 8px; height: 8px; }
}
