/* CertQuiz — mobile-first, variables de tema claro/oscuro */
:root {
  --bg: #f3efe6;
  --bg-2: #ebe5d8;
  --surface: #fffdf8;
  --surface-2: #f6f1e6;
  --text: #1a1d21;
  --muted: #5d6168;
  --border: #d9d1c0;
  --accent: #0d6b5f;
  --accent-ink: #f3efe6;
  --accent-soft: #d7ebe6;
  --amber: #b86e0a;
  --ok: #157347;
  --ok-bg: #dcf2e4;
  --bad: #b42318;
  --bad-bg: #fbe1dd;
  --focus: #c27a00;
  --shadow: 0 1px 0 rgba(26, 29, 33, .04), 0 10px 30px -18px rgba(26, 29, 33, .35);
  --radius: 14px;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-body: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", "Helvetica Neue", Ubuntu, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0e1215;
  --bg-2: #131a1e;
  --surface: #151c21;
  --surface-2: #1b242a;
  --text: #ebe7de;
  --muted: #9aa3a8;
  --border: #2a363d;
  --accent: #3fc9b3;
  --accent-ink: #062b25;
  --accent-soft: #143a35;
  --amber: #f0a83c;
  --ok: #4ad68a;
  --ok-bg: #12352a;
  --bad: #ff7b6b;
  --bad-bg: #3d1a17;
  --focus: #f0a83c;
  --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 14px 34px -20px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 16px/1.55 var(--font-body);
  background-image: radial-gradient(circle at 100% 0, var(--accent-soft) 0, transparent 38rem);
  background-attachment: fixed;
}
::selection { background: var(--accent); color: var(--accent-ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; margin: 0 0 .5rem; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: .5rem 1rem; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
[hidden] { display: none !important; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .75rem;
  padding: .65rem clamp(.9rem, 4vw, 2.5rem);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-family: var(--font-display); font-size: 1.2rem; letter-spacing: -.01em; }
.brand b { color: var(--accent); }
.nav { display: flex; gap: .25rem; justify-content: center; }
.nav button {
  font: inherit; font-size: .92rem; color: var(--muted); background: none; border: 0;
  padding: .45rem .8rem; border-radius: 999px; cursor: pointer;
  transition: background-color .2s, color .2s;
}
.nav button:hover { color: var(--text); background: var(--surface-2); }
.nav button[aria-current="page"] { color: var(--accent-ink); background: var(--accent); }
.top-actions { display: flex; gap: .4rem; align-items: center; }
.icon-btn {
  width: 2.4rem; height: 2.4rem; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 1.05rem; cursor: pointer;
  transition: transform .25s, background-color .2s;
}
.icon-btn:hover { transform: rotate(-18deg); }
@media (max-width: 640px) {
  .topbar { grid-template-columns: 1fr auto; }
  .nav { grid-column: 1 / -1; grid-row: 2; justify-content: stretch; }
  .nav button { flex: 1; }
  .brand span { font-size: 1.05rem; }
}

/* Layout */
.view { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: clamp(1rem, 4vw, 2.5rem) clamp(.9rem, 4vw, 2.5rem) 3rem; outline: none; }
.view > * { animation: rise .45s cubic-bezier(.2, .7, .2, 1) both; }
.view > *:nth-child(2) { animation-delay: .05s; }
.view > *:nth-child(3) { animation-delay: .1s; }
.view > *:nth-child(4) { animation-delay: .15s; }
.view > *:nth-child(5) { animation-delay: .2s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.footer {
  display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; justify-content: space-between;
  padding: 1.1rem clamp(.9rem, 4vw, 2.5rem); border-top: 1px solid var(--border);
  color: var(--muted); font-size: .85rem;
}

.hero { margin: .5rem 0 2rem; max-width: 46rem; }
.hero h1 { font-size: clamp(2.1rem, 6vw, 3.6rem); letter-spacing: -.02em; font-weight: 600; }
.hero h1 em { color: var(--accent); font-style: italic; }
.lead { font-size: 1.05rem; color: var(--muted); margin: 0; max-width: 36rem; }
.eyebrow { margin: 0 0 .35rem; font: 600 .72rem/1.3 var(--font-mono); text-transform: uppercase; letter-spacing: .14em; color: var(--amber); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: clamp(1rem, 3vw, 1.6rem); margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.card-title { font-size: 1.15rem; margin-bottom: 1rem; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }
.page-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.page-head h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0; }

/* Controles */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: 600 .95rem/1 var(--font-body); padding: .8rem 1.2rem; border-radius: 999px;
  border: 1px solid transparent; cursor: pointer; text-decoration: none; min-height: 2.75rem;
  transition: transform .15s, background-color .2s, border-color .2s, color .2s, opacity .2s;
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 86%, var(--text)); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.danger-text { color: var(--bad); }
.btn-sm { padding: .45rem .8rem; min-height: 2.1rem; font-size: .85rem; }
.btn-lg { width: 100%; padding: 1rem 1.4rem; font-size: 1.02rem; margin-top: .5rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1.25rem; }
.card .btn-row:last-child { margin-bottom: 0; }
.link-btn { background: none; border: 0; color: var(--accent); font: 600 .8rem var(--font-body); cursor: pointer; text-decoration: underline; padding: 0 .25rem; }

.input {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: .7rem .85rem; min-height: 2.75rem; width: 100%;
  transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.input:disabled { opacity: .5; }
.select { appearance: none; padding-right: 2.2rem; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 12px) 55%; background-size: 6px 6px; background-repeat: no-repeat; }
.num { max-width: 9rem; }
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.field label { font-size: .88rem; font-weight: 600; }
.field-row { display: grid; gap: 0 1.25rem; }
@media (min-width: 640px) { .field-row { grid-template-columns: 1fr 1fr; } }
.hint { font-size: .8rem; color: var(--muted); }
.check { display: flex; align-items: center; gap: .65rem; padding: .45rem 0; cursor: pointer; }
.check input, .mode input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); flex: none; }
fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
legend { font-weight: 600; font-size: .88rem; margin-bottom: .5rem; padding: 0; }

/* Inicio */
.picker-row { display: grid; gap: .6rem; }
@media (min-width: 720px) { .picker-row { grid-template-columns: 1fr auto auto; } }
.dropzone {
  margin-top: .9rem; display: flex; align-items: center; gap: .8rem; padding: 1rem 1.1rem;
  border: 2px dashed var(--border); border-radius: 12px; cursor: pointer; color: var(--text);
  transition: border-color .2s, background-color .2s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { font-size: 1.4rem; color: var(--accent); }
.warn { color: var(--amber); font-size: .88rem; margin: .8rem 0 0; }
.errors { background: var(--bad-bg); border: 1px solid var(--bad); color: var(--text); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1.25rem; }
.error-title { color: var(--bad); font-weight: 700; margin: 0 0 .4rem; }
.errors ul { margin: 0 0 .5rem; padding-left: 1.2rem; font: .85rem/1.5 var(--font-mono); max-height: 16rem; overflow: auto; }
.resume { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: center; border-left: 5px solid var(--amber); }
.resume .btn-row { margin: 0; }
.resume-title { font-family: var(--font-display); font-size: 1.15rem; margin: 0; }
.resume p { margin: 0; }
.home-grid { display: grid; gap: 0 1.25rem; align-items: start; }
@media (min-width: 900px) { .home-grid { grid-template-columns: 1.15fr 1fr; } }
.bank-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .8rem; margin-bottom: 1.2rem; }
.bank-name { font-size: clamp(1.35rem, 3vw, 1.8rem); margin: 0; }
.bank-meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: flex-start; }
.code { font: 700 .9rem var(--font-mono); background: var(--text); color: var(--bg); padding: .3rem .6rem; border-radius: 6px; }
.pill, .chip { font-size: .78rem; padding: .25rem .65rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.chip { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.chip-warn { background: color-mix(in srgb, var(--amber) 18%, transparent); border-color: var(--amber); }
.domain { border-top: 1px solid var(--border); padding: .7rem 0; }
.domain .check-label { flex: 1; }
.count { font: 600 .8rem var(--font-mono); color: var(--muted); }
.modes { display: grid; gap: .5rem; }
.mode {
  display: grid; grid-template-columns: auto 1fr; gap: .1rem .65rem; align-items: center;
  padding: .7rem .85rem; border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
  transition: border-color .2s, background-color .2s;
}
.mode:hover { border-color: var(--accent); }
.mode:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.mode-name { font-weight: 600; }
.mode-count { grid-column: 2; font: .78rem var(--font-mono); color: var(--muted); }

/* Pregunta */
.quiz { max-width: 820px; margin: 0 auto; }
.quiz-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: .7rem; }
.quiz-meta { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; min-width: 0; }
.quiz-tools { display: flex; gap: .4rem; }
.progress-text { font: 700 .9rem var(--font-mono); }
.timer { font: 600 .85rem var(--font-mono); color: var(--muted); }
.timer.low { color: var(--bad); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 1.2rem; border: 1px solid var(--border); }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--amber)); transition: width .4s cubic-bezier(.2, .7, .2, 1); }
.question-card { padding: clamp(1.1rem, 4vw, 2rem); }
.q-id { font: .72rem var(--font-mono); color: var(--muted); margin: 0 0 .5rem; }
.q-text { font-family: var(--font-body); font-size: clamp(1.02rem, 2.4vw, 1.15rem); font-weight: 500; line-height: 1.6; margin-bottom: 1.1rem; }
.hint-multi { display: inline-block; font: 700 .8rem var(--font-mono); color: var(--amber); background: color-mix(in srgb, var(--amber) 12%, transparent); padding: .3rem .7rem; border-radius: 6px; margin: 0 0 1rem; }
.options { display: grid; gap: .6rem; margin-bottom: 1.2rem; }
.option {
  display: grid; grid-template-columns: auto auto 1fr auto; gap: .75rem; align-items: start;
  padding: .85rem 1rem; border: 1.5px solid var(--border); border-radius: 12px; cursor: pointer;
  background: var(--surface); transition: border-color .18s, background-color .18s, transform .18s;
}
.option:hover:has(input:not(:disabled)) { border-color: var(--accent); transform: translateX(3px); }
.option input { margin: .2rem 0 0; width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.option:has(input:disabled) { cursor: default; }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.opt-key { font: 700 .8rem/1.6rem var(--font-mono); width: 1.6rem; height: 1.6rem; text-align: center; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
.opt-text { white-space: pre-wrap; overflow-wrap: anywhere; padding-top: .1rem; }
.opt-mark { font-weight: 800; font-size: 1.05rem; padding-top: .05rem; }
.option.correct { border-color: var(--ok); background: var(--ok-bg); }
.option.correct .opt-mark, .option.correct .opt-key { color: var(--ok); }
.option.missed { border-style: dashed; }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option.wrong .opt-mark, .option.wrong .opt-key { color: var(--bad); }
.feedback { border-radius: 12px; padding: 1rem 1.1rem; margin-bottom: 1.2rem; border-left: 5px solid; animation: rise .35s both; outline: none; }
.feedback.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok-bg) 60%, transparent); }
.feedback.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad-bg) 60%, transparent); }
.verdict { font: 700 1.2rem var(--font-display); margin: 0 0 .3rem; }
.feedback.ok .verdict { color: var(--ok); }
.feedback.bad .verdict { color: var(--bad); }
.feedback > .muted { margin: 0 0 .5rem; }
.explanation { margin-top: .7rem; }
.explanation h3 { font: 700 .75rem var(--font-mono); text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: .9rem 0 .35rem; }
.explanation p { margin: 0; }
.refs { margin: 0; padding-left: 1.1rem; font-size: .88rem; overflow-wrap: anywhere; }
.quiz-actions { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: flex-end; }
.quiz-actions .btn-primary { min-width: 12rem; }
@media (max-width: 520px) { .quiz-actions .btn { flex: 1; min-width: 0; } }
.kbd-hint { text-align: center; color: var(--muted); font-size: .8rem; }
kbd { font: .75rem var(--font-mono); padding: .1rem .35rem; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); }
.qgrid-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .5rem; }
.qgrid-legend { font-size: .8rem; margin: 0 0 .8rem; display: flex; align-items: center; gap: .35rem; }
.qdot { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; border: 1px solid var(--border); background: var(--surface-2); }
.qdot.answered { background: var(--accent); border-color: var(--accent); }
.qgrid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr)); gap: .4rem; }
.qcell {
  width: 100%; aspect-ratio: 1; min-height: 2.6rem; border-radius: 8px; cursor: pointer;
  font: 700 .85rem var(--font-mono); color: var(--text); background: var(--surface-2); border: 1.5px solid var(--border);
  transition: transform .15s, background-color .2s, border-color .2s;
}
.qcell:hover { border-color: var(--accent); transform: translateY(-2px); }
.qcell.answered { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.qcell.current { outline: 3px solid var(--amber); outline-offset: 2px; }
.fav.on { color: var(--amber); border-color: var(--amber); }

/* Resultados */
.score-card { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: center; }
.ring { width: 9rem; height: 9rem; flex: none; }
.ring circle { fill: none; stroke-width: 11; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke-linecap: round; transition: stroke-dasharray .8s; }
.ring-fg.pass { stroke: var(--ok); }
.ring-fg.fail { stroke: var(--amber); }
.ring-text { font: 700 24px var(--font-display); fill: var(--text); }
.score-body { flex: 1; min-width: 14rem; }
.score-title { font-size: clamp(1.6rem, 4vw, 2.3rem); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: .6rem; margin: 1rem 0 0; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem; }
.stat dt { font: .7rem var(--font-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.stat dd { margin: .15rem 0 0; font-weight: 700; font-size: 1.05rem; }
.kpis { margin-bottom: 1.25rem; }
.kpis .stat { background: var(--surface); }
.kpis dd { font: 700 1.5rem var(--font-display); }
.bar-row { margin-bottom: .9rem; }
.bar-label { display: flex; justify-content: space-between; gap: 1rem; font-size: .9rem; margin-bottom: .3rem; }
.bar-val { font: .8rem var(--font-mono); color: var(--muted); white-space: nowrap; }
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.bar span { display: block; height: 100%; border-radius: 999px; transition: width .6s; }
.bar .pass { background: var(--ok); }
.bar .fail { background: var(--amber); }
.review { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.review details { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.review summary { cursor: pointer; padding: .8rem 1rem; display: flex; gap: .6rem; align-items: center; list-style: none; }
.review summary::-webkit-details-marker { display: none; }
.review summary::before { content: '▸'; color: var(--accent); transition: transform .2s; }
.review details[open] summary::before { transform: rotate(90deg); }
.review .chip { flex: none; max-width: 10rem; }
.sum-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-body { padding: 0 1rem 1rem; }
.q-review { margin-top: 0; }
.ans { border-left: 4px solid; padding: .4rem .8rem; margin: .6rem 0; border-radius: 0 8px 8px 0; }
.ans ul { margin: .2rem 0 0; padding-left: 1.1rem; }
.ans p { margin: .2rem 0 0; }
.ans.bad { border-color: var(--bad); background: var(--bad-bg); }
.ans.ok { border-color: var(--ok); background: var(--ok-bg); }

/* Historial */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .goal { stroke: var(--amber); stroke-dasharray: 5 5; }
.chart .axis { font: 11px var(--font-mono); fill: var(--muted); }
.chart .area { fill: var(--accent); opacity: .12; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th { text-align: left; font: 600 .7rem var(--font-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); padding: .5rem; border-bottom: 1px solid var(--border); }
.table td { padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.history .field { max-width: 26rem; }

/* Ajustes */
.settings { max-width: 760px; }
.danger-zone { border-color: var(--bad); background: color-mix(in srgb, var(--bad-bg) 35%, var(--surface)); }
.danger-zone .card-title { color: var(--bad); }

/* Modal y toasts */
.modal {
  border: 1px solid var(--border); border-radius: 16px; padding: 1.5rem; width: min(92vw, 28rem);
  background: var(--surface); color: var(--text); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .5);
}
.modal[open] { animation: rise .25s both; }
.modal::backdrop { background: rgba(10, 14, 16, .55); backdrop-filter: blur(4px); }
.modal-msg { color: var(--muted); }
.modal .input { margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: .5rem; z-index: 100; width: min(92vw, 26rem); }
.toast {
  background: var(--text); color: var(--bg); padding: .75rem 1rem; border-radius: 10px; font-size: .9rem;
  box-shadow: var(--shadow); animation: rise .25s both; transition: opacity .3s, transform .3s;
}
.toast-error { background: var(--bad); color: #fff; }
.toast-success { border-left: 5px solid var(--ok); }
.toast.out { opacity: 0; transform: translateY(8px); }
