:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --ink: #111827;
    --muted: #64748b;
    --line: #e2e8f0;
    --primary: #2563eb;
    --primary-strong: #1d4ed8;
    --dark: #0f172a;
    --success: #15803d;
    --success-bg: #ecfdf3;
    --success-line: #bbf7d0;
    --danger: #b91c1c;
    --danger-bg: #fff1f2;
    --danger-line: #fecdd3;
    --warning: #b45309;
    --radius-lg: 24px;
    --radius-md: 16px;
    --shadow: 0 24px 70px rgba(15, 23, 42, .10);
    --focus: 0 0 0 4px rgba(37, 99, 235, .15);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 0%, rgba(37, 99, 235, .10), transparent 34rem),
        radial-gradient(circle at 92% 12%, rgba(14, 165, 233, .08), transparent 28rem),
        var(--bg);
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.hidden { display: none !important; }

.page-shell {
    width: min(100% - 32px, 920px);
    margin: 0 auto;
    padding: clamp(24px, 4vw, 52px) 0 28px;
}

.site-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
}

.brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 48px;
    height: 48px;
    border-radius: 15px;
    background: var(--dark);
    color: #fff;
    font-weight: 800;
    font-size: 1.25rem;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .18);
}

.site-header h1 {
    margin: 2px 0 0;
    font-size: clamp(1rem, 2.5vw, 1.35rem);
    line-height: 1.2;
    letter-spacing: -.02em;
}

.eyebrow, .kicker {
    margin: 0;
    color: var(--primary);
    font-size: .77rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .11em;
}

.app-card {
    position: relative;
    overflow: hidden;
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(226, 232, 240, .92);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.view { padding: clamp(24px, 5vw, 48px); }

.hero-icon, .result-badge {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin-bottom: 20px;
    border-radius: 20px;
    background: #dbeafe;
    color: var(--primary);
    font-size: 1.8rem;
    font-weight: 900;
}

.view h2 {
    margin: 9px 0 12px;
    font-size: clamp(1.65rem, 4vw, 2.35rem);
    line-height: 1.1;
    letter-spacing: -.04em;
}

.lead {
    margin: 0;
    max-width: 680px;
    color: var(--muted);
    font-size: clamp(1rem, 2vw, 1.08rem);
    line-height: 1.7;
}

.exam-rules {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 30px 0 22px;
}

.rule {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface-soft);
}

.rule strong { display: block; font-size: 1.45rem; }
.rule span { color: var(--muted); font-size: .88rem; }

.timer-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 20px;
    margin-bottom: 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #fff;
    cursor: pointer;
}

.timer-option strong, .timer-option small { display: block; }
.timer-option small { margin-top: 4px; color: var(--muted); }

.switch { position: relative; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
    display: block;
    width: 50px;
    height: 28px;
    padding: 3px;
    border-radius: 999px;
    background: #cbd5e1;
    transition: .2s ease;
}
.switch-track::after {
    content: "";
    display: block;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .22);
    transition: transform .2s ease;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(22px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }

.btn {
    min-height: 52px;
    padding: 0 22px;
    border: 0;
    border-radius: 14px;
    font-weight: 800;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease, background .15s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .48; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 10px 22px rgba(37, 99, 235, .22); }
.btn-primary:hover:not(:disabled) { background: var(--primary-strong); }
.btn-dark { background: var(--dark); color: #fff; }
.btn-block { width: 100%; }

.privacy-note {
    margin: 14px 0 0;
    text-align: center;
    color: var(--muted);
    font-size: .78rem;
}

.question-topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 20px;
    margin-bottom: 26px;
}

.progress {
    width: min(100%, 360px);
    height: 7px;
    margin-top: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #e2e8f0;
}
.progress span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
    transition: width .3s ease;
}

.timer {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 94px;
    justify-content: center;
    padding: 10px 12px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1e40af;
    font-variant-numeric: tabular-nums;
    font-weight: 800;
}
.timer-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.timer-warning { color: var(--warning); background: #fffbeb; }

.question-text {
    margin: 0 0 22px !important;
    font-size: clamp(1.28rem, 3vw, 1.7rem) !important;
    line-height: 1.38 !important;
    letter-spacing: -.02em !important;
}

.question-image-wrap {
    display: flex;
    justify-content: center;
    padding: 14px;
    margin-bottom: 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface-soft);
}
.question-image {
    display: block;
    width: auto;
    max-width: 100%;
    max-height: 420px;
    object-fit: contain;
    border-radius: 10px;
}

.answers { display: grid; gap: 12px; margin: 0 0 20px; }
.answer-option {
    display: grid;
    grid-template-columns: 42px 1fr;
    align-items: center;
    gap: 14px;
    min-height: 66px;
    padding: 12px 16px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-md);
    background: #fff;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.answer-option:hover { border-color: #93c5fd; transform: translateY(-1px); }
.answer-option input { position: absolute; opacity: 0; }
.answer-option.selected { border-color: var(--primary); background: #eff6ff; }
.answer-option:has(input:focus-visible) { box-shadow: var(--focus); }
.answer-marker {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: #f1f5f9;
    color: #475569;
    font-weight: 800;
}
.answer-text { line-height: 1.45; }
.answer-option.is-correct { border-color: #86efac; background: var(--success-bg); }
.answer-option.is-correct .answer-marker { background: #dcfce7; color: var(--success); }
.answer-option.is-wrong { border-color: #fda4af; background: var(--danger-bg); }
.answer-option.is-wrong .answer-marker { background: #ffe4e6; color: var(--danger); }
.answer-option:has(input:disabled) { cursor: default; transform: none; }

.feedback {
    display: grid;
    gap: 4px;
    padding: 16px 18px;
    margin-bottom: 18px;
    border-radius: 14px;
    border: 1px solid;
}
.feedback strong { font-size: 1rem; }
.feedback span { font-size: .92rem; line-height: 1.5; }
.feedback-success { background: var(--success-bg); border-color: var(--success-line); color: #166534; }
.feedback-error { background: var(--danger-bg); border-color: var(--danger-line); color: #9f1239; }

.actions { display: grid; gap: 10px; }

.result-badge { margin-left: auto; margin-right: auto; }
.result-pass { background: #dcfce7; color: var(--success); }
.result-fail { background: #ffe4e6; color: var(--danger); }
#result-view { text-align: center; }
#result-view .lead { margin-left: auto; margin-right: auto; }
.result-score { margin: 16px 0 10px; font-size: clamp(2.4rem, 7vw, 4rem); font-weight: 900; letter-spacing: -.06em; }
.result-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 30px 0 22px;
}
.result-grid div { padding: 16px 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-soft); }
.result-grid span, .result-grid strong { display: block; }
.result-grid span { color: var(--muted); font-size: .78rem; }
.result-grid strong { margin-top: 4px; font-size: 1.25rem; }

.loading {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,.62);
    backdrop-filter: blur(2px);
}
.loading span {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 4px solid #dbeafe;
    border-top-color: var(--primary);
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.global-error {
    position: fixed;
    left: 50%;
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 20;
    width: min(calc(100% - 32px), 620px);
    transform: translateX(-50%);
    padding: 14px 16px;
    border: 1px solid var(--danger-line);
    border-radius: 14px;
    background: #fff1f2;
    color: var(--danger);
    box-shadow: 0 16px 40px rgba(15,23,42,.16);
    font-size: .92rem;
}

.site-footer { padding: 18px 4px 0; text-align: center; color: #94a3b8; font-size: .78rem; }

@media (max-width: 640px) {
    .page-shell { width: min(100% - 20px, 920px); padding-top: 16px; }
    .site-header { align-items: flex-start; }
    .brand-mark { flex-basis: 42px; height: 42px; border-radius: 12px; }
    .app-card { border-radius: 20px; }
    .view { padding: 22px 18px; }
    .exam-rules { grid-template-columns: 1fr; gap: 8px; margin-top: 24px; }
    .rule { display: flex; align-items: baseline; gap: 8px; padding: 13px 14px; }
    .rule strong { font-size: 1.18rem; }
    .timer-option { padding: 15px; }
    .question-topbar { gap: 12px; }
    .timer { min-width: 84px; padding: 9px 10px; }
    .answer-option { grid-template-columns: 38px 1fr; min-height: 62px; padding: 10px 12px; }
    .answer-marker { width: 34px; height: 34px; border-radius: 10px; }
    .result-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Imagen ampliable */
.question-image-button {
    position: relative;
    display: block;
    max-width: 100%;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    cursor: zoom-in;
}

.question-image-button:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}


body.modal-open {
    overflow: hidden;
}

.image-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: clamp(12px, 3vw, 32px);
}

.image-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, .78);
    backdrop-filter: blur(5px);
}

.image-modal-panel {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(96vw, 1180px);
    max-height: 94vh;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 32px 90px rgba(2, 6, 23, .4);
}

.image-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px 12px 20px;
    border-bottom: 1px solid var(--line);
}

.image-modal-header h2 {
    margin: 0;
    font-size: clamp(1rem, 2.4vw, 1.2rem);
    letter-spacing: -.02em;
}

.image-modal-close {
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #f1f5f9;
    color: var(--ink);
    font-size: 1.7rem;
    line-height: 1;
    cursor: pointer;
}

.image-modal-close:hover {
    background: #e2e8f0;
}

.image-modal-close:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}

.image-modal-content {
    display: grid;
    place-items: center;
    min-height: 0;
    padding: clamp(12px, 2vw, 24px);
    overflow: auto;
    background: #f8fafc;
}

.image-modal-content img {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: calc(94vh - 100px);
    object-fit: contain;
}

/* Segundo nivel de ampliación: click directo sobre la imagen = 2x. */
.image-modal-content img {
    cursor: zoom-in;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: pan-x pan-y;
}

.image-modal-content.is-zoomed {
    display: block;
    place-items: initial;
}

.image-modal-content img.is-zoomed {
    margin: 0 auto;
    cursor: zoom-out;
    object-fit: initial;
}

@media (max-width: 640px) {
    .image-modal { padding: 8px; }
    .image-modal-panel { width: 100%; max-height: 96vh; border-radius: 16px; }
    .image-modal-header { padding: 10px 10px 10px 14px; }
    .image-modal-content { padding: 8px; }
    .image-modal-content img { max-height: calc(96vh - 78px); }
}
