:root {
    --bg: #f3f5f8;
    --card: #ffffff;
    --text: #172033;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --border: #d8dee9;
    --success-bg: #ecfdf5;
    --success-text: #065f46;
    --error-bg: #fef2f2;
    --error-text: #991b1b;
    --warning-bg: #fffbeb;
    --warning-text: #92400e;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
    background: #111827;
    color: #fff;
    padding: 14px 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.brand a { color: #fff; font-weight: 800; font-size: 18px; }
.topbar nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar nav a { color: #dbeafe; }
.topbar .user { color: #cbd5e1; font-weight: 700; }
.container { max-width: 1050px; margin: 24px auto; padding: 0 16px 40px; }
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
    margin-bottom: 18px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
}
.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.hero h1, .card h1 { margin-top: 0; }
.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form { display: grid; gap: 14px; }
.form label { font-weight: 700; color: #374151; display: grid; gap: 6px; }
input, select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    background: #fff;
}
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 10px;
    padding: 11px 16px;
    background: var(--primary);
    color: #fff !important;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none !important;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #475569; }
.btn.small { padding: 7px 10px; font-size: 13px; }
.btn.large { width: 100%; font-size: 18px; padding: 15px 18px; }
.alert { border-radius: 10px; padding: 12px 14px; margin: 12px 0; font-weight: 700; }
.alert.success { background: var(--success-bg); color: var(--success-text); }
.alert.error { background: var(--error-bg); color: var(--error-text); }
.alert.warning { background: var(--warning-bg); color: var(--warning-text); }
.stats { display: flex; gap: 14px; flex-wrap: wrap; margin: 16px 0; }
.stats div {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    min-width: 130px;
}
.stats strong { display: block; font-size: 30px; }
.stats span { color: var(--muted); font-size: 14px; }
.question h2 { margin-top: 0; }
.question h2 span { color: var(--muted); font-size: 15px; font-weight: 600; }
.question-text { font-size: 18px; font-weight: 700; }
.option {
    display: block;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin: 8px 0;
    background: #fbfdff;
}
.option input { width: auto; margin-right: 8px; }
.option.correct { background: #dcfce7; border-color: #86efac; }
.option.wrong { background: #fee2e2; border-color: #fca5a5; }
.question.ok { border-left: 6px solid #22c55e; }
.question.bad { border-left: 6px solid #ef4444; }
.answer-line { font-weight: 800; }
.explanation { background: #eff6ff; padding: 12px; border-radius: 10px; }
.sticky-title { position: sticky; top: 0; z-index: 5; }
.submit-card { text-align: center; }
.result-card { text-align: center; }
.score { font-size: 64px; font-weight: 900; line-height: 1; }
.score span { font-size: 26px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #f8fafc; }
.inline-form { grid-template-columns: repeat(5, minmax(140px, 1fr)); align-items: end; }
.mini-form { display: inline-flex; gap: 6px; margin: 2px; align-items: center; }
.password-form input { width: 170px; padding: 7px; }
pre { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 10px; overflow-x: auto; }
@media (max-width: 760px) {
    .grid.two, .inline-form { grid-template-columns: 1fr; }
    .topbar { align-items: flex-start; }
    .topbar nav { align-items: flex-start; }
    .question-text { font-size: 16px; }
    .score { font-size: 46px; }
}

/* Cronómetro del test */
.test-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.timer-box {
    min-width: 150px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    background: #f8fafc;
    text-align: center;
}
.timer-box span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.timer-box strong {
    display: block;
    font-size: 22px;
    margin-top: 2px;
}
.timer-box.small strong { font-size: 18px; }
.submit-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
@media (max-width: 640px) {
    .timer-box { width: 100%; }
    .submit-row .btn { width: 100%; }
}

/* Modo claro / oscuro */
:root {
    color-scheme: light;
    --topbar: #111827;
    --topbar-link: #dbeafe;
    --input-bg: #ffffff;
    --input-text: #172033;
    --soft-bg: #f8fafc;
    --option-bg: #fbfdff;
    --shadow-card: 0 8px 20px rgba(15, 23, 42, 0.04);
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1120;
    --card: #111827;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --primary: #60a5fa;
    --primary-dark: #3b82f6;
    --border: #334155;
    --success-bg: #062f21;
    --success-text: #86efac;
    --error-bg: #3b0d0d;
    --error-text: #fecaca;
    --warning-bg: #3a2a05;
    --warning-text: #fde68a;
    --topbar: #020617;
    --topbar-link: #bfdbfe;
    --input-bg: #0f172a;
    --input-text: #e5e7eb;
    --soft-bg: #0f172a;
    --option-bg: #0b1220;
    --shadow-card: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.topbar { background: var(--topbar); }
.topbar nav a { color: var(--topbar-link); }
.card { box-shadow: var(--shadow-card); }
.form label { color: var(--text); }
input, select, textarea {
    background: var(--input-bg);
    color: var(--input-text);
    border-color: var(--border);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
.stats div, th, .timer-box { background: var(--soft-bg); }
.option { background: var(--option-bg); }
.explanation {
    background: var(--soft-bg);
    border: 1px solid var(--border);
}
html[data-theme="dark"] .option.correct {
    background: #052e16;
    border-color: #166534;
}
html[data-theme="dark"] .option.wrong {
    background: #450a0a;
    border-color: #991b1b;
}
html[data-theme="dark"] pre {
    background: #020617;
    color: #e5e7eb;
}

.theme-toggle {
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    border-radius: 999px;
    padding: 7px 11px;
    font-weight: 800;
    cursor: pointer;
    line-height: 1;
}
.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.16);
}

@media (max-width: 760px) {
    .theme-toggle { width: 100%; padding: 10px 12px; }
}
.login-logo {
    text-align: center;
    margin-bottom: 20px;
}

.login-logo img {
    max-width: 620px;
    max-height: 320px;
    width: auto;
    height: auto;
    display: inline-block;
}