:root {
  --bg: #f5f7fb; --surface: #ffffff; --text: #14202e; --muted: #4b5a6b; --border: #c9d3df;
  --primary: #1456b8; --primary-text: #ffffff; --primary-soft: #e2edff;
  --ok: #0b7a3b; --ok-soft: #dff5e7; --bad: #b3261e; --bad-soft: #fde6e4; --warn: #8a5a00; --warn-soft: #fff1cc;
  --focus: #ff9f1c; --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1620; --surface: #17222f; --text: #eaf0f7; --muted: #aebccb; --border: #3a4b5e;
    --primary: #6ea8ff; --primary-text: #08203f; --primary-soft: #1c3355;
    --ok: #5ddc90; --ok-soft: #12361f; --bad: #ff8a80; --bad-soft: #3d1a18; --warn: #ffd166; --warn-soft: #3a2f0e;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
small { color: var(--muted); font-weight: 400; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.topbar { display: flex; align-items: center; gap: .5rem; padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); margin-right: auto; display: flex; align-items: center; gap: .5rem; }
.brand img { width: 28px; height: 28px; border-radius: 6px; }
.topbar nav { display: flex; gap: .25rem; align-items: center; }
main { max-width: 760px; margin: 0 auto; padding: 1rem; }
main.wide { max-width: 1100px; }
footer#legal { max-width: 760px; margin: 1.5rem auto 2rem; padding: 0 1rem; color: var(--muted); font-size: .8rem; }
footer#legal p { margin: .25rem 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.stack > * + * { margin-top: .9rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; min-width: 48px; padding: .6rem 1.1rem; border-radius: var(--radius); border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 40px; padding: .35rem .8rem; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; font-size: 1.1rem; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0; }
legend { font-weight: 700; padding: 0 .4rem; }
.choices { display: flex; flex-wrap: wrap; gap: .5rem; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.choice span { display: inline-flex; align-items: center; min-height: 48px; padding: .5rem 1rem; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); font-weight: 600; }
.choice input:checked + span { background: var(--primary-soft); border-color: var(--primary); }
.choice input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.choices.col { flex-direction: column; }
.choices.col .choice span { width: 100%; }
label { display: block; font-weight: 600; }
input[type=number], input[type=text], input[type=search], select, textarea { width: 100%; min-height: 48px; padding: .5rem .75rem; font: inherit; color: var(--text); background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); }
input[type=number] { max-width: 9rem; }

.notice { padding: .7rem 1rem; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); border: 1px solid currentColor; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }

/* Quiz */
.qhead { position: sticky; top: 53px; z-index: 5; background: var(--bg); padding: .5rem 0; }
.qmeta { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.25rem; padding: .2rem .7rem; border-radius: 999px; background: var(--surface); border: 2px solid var(--border); }
.timer.low { color: var(--bad); border-color: var(--bad); }
progress { width: 100%; height: 12px; accent-color: var(--primary); }
.question { font-size: 1.15rem; font-weight: 600; margin: .5rem 0 1rem; }
.options { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.opt { display: flex; gap: .75rem; align-items: flex-start; width: 100%; text-align: left; min-height: 56px; padding: .7rem 1rem; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.opt:hover { border-color: var(--primary); }
.opt .ltr { flex: none; width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--primary-soft); }
.opt[aria-checked=true] { border-color: var(--primary); background: var(--primary-soft); }
.opt[aria-checked=true] .ltr { background: var(--primary); color: var(--primary-text); }
.navrow { display: flex; gap: .5rem; margin-top: 1rem; }
.navrow .btn { flex: 1; }
.qmap { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: .4rem; }
.qmap button { min-height: 44px; border-radius: 8px; border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; position: relative; }
.qmap button.answered { background: var(--primary-soft); border-color: var(--primary); }
.qmap button.flagged::after { content: "⚑"; position: absolute; top: -2px; right: 2px; font-size: .75rem; color: var(--warn); }
.qmap button.current { outline: 3px solid var(--focus); }

/* Resultados */
.score { text-align: center; }
.score .pct { font-size: 3rem; font-weight: 800; line-height: 1.1; }
.badge { display: inline-block; padding: .25rem .9rem; border-radius: 999px; font-weight: 800; }
.badge.pass { background: var(--ok-soft); color: var(--ok); }
.badge.fail { background: var(--bad-soft); color: var(--bad); }
.bar { height: 10px; background: var(--border); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); }
.secrow { display: grid; grid-template-columns: 1fr auto; gap: .25rem .75rem; margin-bottom: .75rem; }
.secrow .bar { grid-column: 1 / -1; }
.wrong h3 { font-size: 1rem; }
.ans { padding: .4rem .7rem; border-radius: 8px; margin: .3rem 0; }
.ans.yours { background: var(--bad-soft); color: var(--bad); }
.ans.right { background: var(--ok-soft); color: var(--ok); }
.ans.yours.isright { background: var(--ok-soft); color: var(--ok); }
.expl { border-left: 4px solid var(--primary); padding-left: .75rem; margin-top: .5rem; }

/* Review */
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: .5rem .6rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface); cursor: pointer; user-select: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.q { cursor: pointer; }
tr.q:hover { background: var(--primary-soft); }
tr.low td.pct { background: var(--bad-soft); color: var(--bad); font-weight: 700; }
tr.high td.pct { background: var(--warn-soft); color: var(--warn); font-weight: 700; }
td.gapneg { color: var(--bad); font-weight: 700; } td.gapok { color: var(--ok); }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .6rem; }
.detail td { white-space: normal; background: var(--bg); }
.langs { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem; }
.langs section { border: 1px solid var(--border); border-radius: 8px; padding: .6rem; background: var(--surface); }
.langs ol { margin: .3rem 0; padding-left: 1.4rem; list-style: upper-alpha; }
.langs li.correct { color: var(--ok); font-weight: 700; }

dialog.modal { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(92vw, 460px); width: 100%; padding: 1.1rem; }
dialog.modal::backdrop { background: rgba(0, 0, 0, .55); }
.toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translate(-50%, 150%); background: var(--text); color: var(--bg); padding: .7rem 1.2rem; border-radius: 999px; transition: transform .25s; z-index: 50; max-width: 90vw; }
.toast.show { transform: translate(-50%, 0); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (min-width: 640px) { body { font-size: 18px; } main { padding: 1.5rem; } }
