:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #1b2230;
  --muted: #5d6779;
  --border: #d5dbe6;
  --accent: #2457c5;
  --accent-text: #ffffff;
  --accent-soft: #e3ebfb;
  --ok: #1d7a46;
  --ok-soft: #e1f4e8;
  --bad: #b3261e;
  --bad-soft: #fbe4e2;
  --warn: #8a5a00;
  --warn-soft: #fff1d1;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .05);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151c;
    --surface: #1a2029;
    --surface-2: #232b37;
    --text: #e6eaf1;
    --muted: #9aa5b8;
    --border: #2f3947;
    --accent: #7ba2ff;
    --accent-text: #0b1220;
    --accent-soft: #1f2d4d;
    --ok: #5fd08f;
    --ok-soft: #173826;
    --bad: #ff8a80;
    --bad-soft: #43201e;
    --warn: #f3c562;
    --warn-soft: #3a2e12;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  --bg: #11151c;
  --surface: #1a2029;
  --surface-2: #232b37;
  --text: #e6eaf1;
  --muted: #9aa5b8;
  --border: #2f3947;
  --accent: #7ba2ff;
  --accent-text: #0b1220;
  --accent-soft: #1f2d4d;
  --ok: #5fd08f;
  --ok-soft: #173826;
  --bad: #ff8a80;
  --bad-soft: #43201e;
  --warn: #f3c562;
  --warn-soft: #3a2e12;
  --shadow: none;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
}

a { color: var(--accent); }

button, select, input { font: inherit; color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}

.brand span { color: var(--muted); font-weight: 500; }

.topnav { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.topnav a {
  text-decoration: none;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 15px;
}

.topnav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 64px;
  outline: none;
}

.loading { color: var(--muted); text-align: center; padding: 40px 0; }

h1 { font-size: 1.6rem; margin: 0 0 4px; line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }

.lead { color: var(--muted); margin: 0 0 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.stat .num { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: .9rem; }
.stat.ok .num { color: var(--ok); }
.stat.bad .num { color: var(--bad); }

.progressbar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  display: flex;
}
.progressbar span { display: block; height: 100%; }
.progressbar .p-ok { background: var(--ok); }
.progressbar .p-bad { background: var(--bad); }
.progressbar .p-rev { background: var(--warn); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.actions.end { justify-content: flex-end; }
.actions.spread { justify-content: space-between; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.btn.ghost { background: transparent; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.menu-grid .card { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.menu-grid .card p { margin: 0; color: var(--muted); flex: 1; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.toolbar label { color: var(--muted); font-size: .95rem; display: flex; gap: 8px; align-items: center; max-width: 100%; min-width: 0; }
.toolbar label select { min-width: 0; flex: 1 1 auto; }

select.field {
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  max-width: 100%;
}

.qhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.qid { font-weight: 700; color: var(--accent); }
.qmeta { color: var(--muted); font-size: .9rem; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: .8rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.rev { background: var(--warn-soft); color: var(--warn); }

.stem p { margin: 0 0 10px; }
.stem ul { margin: 0 0 10px; padding-left: 22px; }
.stem li { margin-bottom: 4px; }

details.case {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
details.case summary { cursor: pointer; font-weight: 600; }
details.case p { margin: 8px 0 0; }

.hint { color: var(--muted); font-size: .92rem; margin: 6px 0 10px; }

.options { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.option {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
}
.option input { margin: 3px 0 0; width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.option .letter { font-weight: 700; color: var(--muted); flex: none; min-width: 1.2em; }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option.locked { cursor: default; }
.option.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.option.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.option .mark { margin-left: auto; font-weight: 700; flex: none; }
.option.is-correct .mark { color: var(--ok); }
.option.is-wrong .mark { color: var(--bad); }

/* Ordenar */
.order-wrap { display: grid; gap: 14px; }
@media (min-width: 720px) { .order-wrap { grid-template-columns: 1fr 1fr; } }

.panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2);
}
.panel h4 { margin: 2px 4px 8px; font-size: .95rem; }
.panel .empty { color: var(--muted); font-size: .92rem; padding: 6px 4px; }

.olist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.oitem {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 8px 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.oitem .txt { flex: 1; }
.oitem .pos { font-weight: 700; color: var(--accent); min-width: 1.4em; }
.oitem .ctrls { display: flex; gap: 4px; flex: none; }
.oitem.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.oitem.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.oitem.dragging { opacity: .5; }
.oitem .mark { font-weight: 700; flex: none; }
.oitem.is-correct .mark { color: var(--ok); }
.oitem.is-wrong .mark { color: var(--bad); }

.iconbtn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.iconbtn:disabled { opacity: .35; cursor: not-allowed; }
.iconbtn.add { width: auto; padding: 0 12px; font-weight: 600; font-size: 14px; }

/* Asignar / listas desplegables */
.matrix { display: grid; gap: 10px; }
.matrix .mhead {
  display: none;
  font-weight: 700;
  color: var(--muted);
  font-size: .9rem;
}
.mrow {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.mrow .mlabel { font-weight: 500; }
.mrow select { width: 100%; min-height: 44px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.mrow.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.mrow.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.mrow .verdict { font-size: .92rem; }
.mrow .verdict .ok { color: var(--ok); font-weight: 600; }
.mrow .verdict .bad { color: var(--bad); font-weight: 600; }
@media (min-width: 720px) {
  .matrix .mhead { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 0 12px; }
  .mrow { grid-template-columns: 1fr 1fr; gap: 14px; align-items: center; }
  .mrow .verdict { grid-column: 1 / -1; }
}
.mtitle { font-weight: 700; margin: 0 0 8px; }
.pool { color: var(--muted); font-size: .92rem; margin: 0 0 10px; }
.pool ul { margin: 4px 0 0; padding-left: 20px; }

.feedback {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  font-weight: 600;
}
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback.rev { background: var(--warn-soft); color: var(--warn); }

.solution {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px dashed var(--ok);
}
.solution h4 { margin: 0 0 6px; color: var(--ok); }
.solution ol, .solution ul { margin: 0; padding-left: 22px; }

.qnav { margin-top: 16px; }

.grid-nav {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 6px;
}
.grid-nav button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.grid-nav button.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid-nav button.answered { background: var(--accent-soft); border-color: var(--accent); }
.grid-nav button.st-correct { background: var(--ok-soft); border-color: var(--ok); }
.grid-nav button.st-wrong { background: var(--bad-soft); border-color: var(--bad); }
.grid-nav button.st-revealed { background: var(--warn-soft); border-color: var(--warn); }
.grid-nav button.flagged { box-shadow: inset 0 -3px 0 var(--warn); }

.legend { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: .85rem; margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; border: 1px solid var(--border); }

.exambar {
  position: sticky;
  top: 57px;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 12px;
}
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.timer.low { color: var(--bad); }

.choice-group { border: 0; margin: 0 0 16px; padding: 0; }
.choice-group legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.choice-group .option { margin-bottom: 8px; }

.result-hero { text-align: center; padding: 26px 18px; }
.result-hero .score { font-size: 3rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.result-hero.pass .score { color: var(--ok); }
.result-hero.fail .score { color: var(--bad); }
.result-hero .verdict { font-size: 1.2rem; font-weight: 700; margin-top: 6px; }

.review-item { border-top: 1px solid var(--border); padding: 12px 0; }
.review-item:first-child { border-top: 0; }
.review-item > summary { cursor: pointer; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; list-style: none; }
.review-item > summary::-webkit-details-marker { display: none; }
.review-item > summary .rtext { flex: 1; min-width: 200px; color: var(--muted); font-size: .92rem; }
.review-item[open] > summary { margin-bottom: 12px; }

table.hist { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.hist th, table.hist td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
table.hist th { color: var(--muted); font-weight: 600; }
.table-scroll { overflow-x: auto; }

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.dialog {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 440px;
  width: 100%;
  padding: 20px;
  border: 1px solid var(--border);
}
.dialog p { margin: 0 0 16px; }

.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 520px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 14px; }
  .topnav a { padding: 6px 7px; font-size: 14px; }
  .brand span { display: none; }
  .actions .btn { flex: 1 1 auto; }
  .exambar { top: 53px; }
}
