:root {
  --bg: #f4f6f9;
  --card: #fff;
  --text: #1c2430;
  --muted: #6a7686;
  --line: #dde3ea;
  --primary: #0f3d68;
  --primary-2: #1b5fa0;
  --ok: #1f9d55;
  --ok-bg: #e4f6ec;
  --ko: #d64545;
  --ko-bg: #fdeaea;
  --star: #f2a600;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d;
    --card: #1b222c;
    --text: #e7ecf2;
    --muted: #9aa6b5;
    --line: #2c3643;
    --primary: #4d9be6;
    --primary-2: #6fb0f0;
    --ok-bg: #173826;
    --ko-bg: #3d1d1f;
  }
  img.figure { background: #fff; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary-2); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0.4rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.pad { padding: 2rem 1rem; }

.screen {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 0.5rem) 0.85rem calc(var(--safe-bottom) + 2rem);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: calc(-0.5rem - var(--safe-top)) -0.85rem 0.75rem;
  padding: calc(var(--safe-top) + 0.5rem) 0.85rem 0.5rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; font-size: 1.15rem; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--ok); margin: 0 0.4rem; }
.icon-btn {
  min-width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.6rem;
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn:active { background: var(--line); }
.icon-btn.star { color: var(--muted); }
.icon-btn.star.on { color: var(--star); }

.hello { font-size: 1.05rem; margin: 0.25rem 0 0.75rem; }
.section-title { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 1.25rem 0 0.5rem; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 0 0 1px var(--line);
}
.card h3 { font-size: 1.05rem; margin-bottom: 0.3rem; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 11px;
  padding: 0.7rem 1.05rem;
  min-height: 44px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--line);
  color: var(--text);
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.danger { color: var(--ko); }
.btn.link { background: transparent; color: var(--primary-2); font-weight: 500; }
.btn.block { display: block; width: 100%; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:not(:disabled):active { transform: scale(0.98); }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }
.stack { display: grid; gap: 0.5rem; }

.modes { display: grid; gap: 0.75rem; }
@media (min-width: 640px) { .modes { grid-template-columns: repeat(3, 1fr); } }
.mode { display: flex; flex-direction: column; gap: 0.5rem; margin: 0; }
.mode-icon { font-size: 1.8rem; }
.mode-body { flex: 1; }
.mode .btn { align-self: flex-start; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.stat strong { display: block; font-size: 1.35rem; }
.stat span { font-size: 0.8rem; color: var(--muted); }

.attempt-head { display: flex; justify-content: space-between; gap: 0.75rem; align-items: flex-start; }
.score { font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: var(--line); margin: 0.5rem 0 0.25rem; }
.bar .ok { background: var(--ok); }
.bar .ko { background: var(--ko); }

.progress { height: 4px; background: var(--line); border-radius: 99px; margin: -0.5rem 0 0.75rem; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--primary-2); transition: width 0.2s; }
.quiz-top { gap: 0.25rem; }
.quiz-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.quiz-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.question { padding: 1rem 0.9rem; }
.qmeta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.chip { font-size: 0.75rem; font-weight: 700; padding: 0.2rem 0.55rem; border-radius: 99px; text-transform: uppercase; letter-spacing: 0.03em; }
.chip.general { background: #e3eefb; color: #1b5fa0; }
.chip.especifica { background: #f3e8fd; color: #7b3fb5; }
.chip.reserva { background: #fff1d6; color: #9a6400; }
.qtext { font-size: 1.07rem; font-weight: 600; white-space: pre-line; }

img.figure {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.75rem auto;
  border-radius: 8px;
  cursor: zoom-in;
}
img.figure.original { border: 1px solid var(--line); }

.options { display: grid; gap: 0.55rem; margin-top: 0.9rem; }
.option {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.8rem;
  min-height: 48px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.option:not(:disabled):active { background: var(--line); }
.option:disabled { cursor: default; opacity: 1; }
.option .letter {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9rem;
  background: var(--line);
}
.option .otext { padding-top: 0.15rem; }
.option.correct { border-color: var(--ok); background: var(--ok-bg); }
.option.correct .letter { background: var(--ok); color: #fff; }
.option.wrong { border-color: var(--ko); background: var(--ko-bg); }
.option.wrong .letter { background: var(--ko); color: #fff; }

.feedback { margin-top: 0.9rem; padding: 0.7rem 0.9rem; border-radius: 10px; font-weight: 600; }
.feedback.ok { background: var(--ok-bg); color: var(--ok); }
.feedback.ko { background: var(--ko-bg); color: var(--ko); }
.feedback.neutral { background: var(--line); }

details.orig { margin-top: 0.9rem; }
details.orig summary { color: var(--primary-2); cursor: pointer; font-size: 0.9rem; padding: 0.4rem 0; }

.quiz-nav {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5rem;
  margin: 0 -0.85rem;
  padding: 0.6rem 0.85rem calc(var(--safe-bottom) + 0.6rem);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: calc(var(--safe-top) + 1rem) 0.5rem calc(var(--safe-bottom) + 1rem);
}
.overlay[hidden] { display: none; }
.overlay > img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 6px; touch-action: pinch-zoom; }
.overlay .close {
  position: fixed;
  top: calc(var(--safe-top) + 0.5rem);
  right: 0.75rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  font-size: 1.6rem;
  background: rgba(255, 255, 255, 0.9);
}

.grid-sheet {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  width: min(560px, 100%);
  max-height: 85vh;
  overflow: auto;
}
.legend { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; margin: 0.4rem 0 0.8rem; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--line); }
.dot.ok { background: var(--ok); }
.dot.ko { background: var(--ko); }
.dot.star { background: transparent; box-shadow: inset 0 0 0 2px var(--star); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 0.4rem; }
.cell {
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--line);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.cell.ok { background: var(--ok); color: #fff; }
.cell.ko { background: var(--ko); color: #fff; }
.cell.marked { box-shadow: inset 0 0 0 3px var(--star); }
.cell.current { outline: 3px solid var(--primary-2); outline-offset: 1px; }
.cell.break { grid-column-start: 1; }

.result { text-align: center; }
.big-score { font-size: 3.2rem; font-weight: 800; }
.big-score.good { color: var(--ok); }
.big-score.mid { color: var(--star); }
.big-score.bad { color: var(--ko); }
table.sections { width: 100%; border-collapse: collapse; }
table.sections th, table.sections td { padding: 0.45rem 0.3rem; border-bottom: 1px solid var(--line); text-align: right; }
table.sections th:first-child, table.sections td:first-child { text-align: left; }

.auth-wrap { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-top) + 2.5rem) 1rem 2rem; }
.auth-logo { text-align: center; margin-bottom: 1.25rem; }
.auth-logo img { width: 72px; height: 72px; }
.auth-logo h1 { font-size: 1.6rem; margin-top: 0.5rem; }
.auth h2 { font-size: 1.2rem; margin-bottom: 0.75rem; }
label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.75rem; }
input {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.7rem 0.8rem;
  font-size: 16px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
input:focus { outline: none; border-color: var(--primary-2); }
.form-error { color: var(--ko); font-weight: 600; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 5rem);
  transform: translateX(-50%);
  z-index: 60;
  background: #222;
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 99px;
  font-size: 0.92rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
}
.toast.ok { background: var(--ok); }
.toast.error { background: var(--ko); }

.center-msg { min-height: 60vh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary-2); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-block; font-size: 0.72rem; font-weight: 800; padding: 0.15rem 0.5rem; border-radius: 99px; margin-right: 0.4rem; vertical-align: middle; letter-spacing: 0.03em; }
.badge.pass { background: var(--ok-bg); color: var(--ok); }
.badge.fail { background: var(--ko-bg); color: var(--ko); }
.ok-text { color: var(--ok); font-weight: 700; }
.ko-text { color: var(--ko); font-weight: 700; }

.filters { display: grid; gap: 0.6rem; }
.filters input[type="search"], .filters select {
  width: 100%;
  margin: 0;
  padding: 0.65rem 0.75rem;
  font: inherit;
  font-size: 16px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
label.check { display: flex; align-items: center; gap: 0.45rem; margin: 0; font-weight: 500; }
label.check input { width: 20px; height: 20px; margin: 0; flex: none; }
.filter-foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.4rem; }
.filter-foot .row { margin: 0; }
.filter-foot .btn { min-height: 36px; padding: 0.4rem 0.75rem; font-size: 0.88rem; }
.bank-item { display: flex; gap: 0.5rem; align-items: flex-start; cursor: pointer; padding: 0.8rem; }
.bank-item:active { background: var(--line); }
.bank-item.faded { opacity: 0.45; }
.bank-body { flex: 1; min-width: 0; }
.bank-body .qmeta { margin-bottom: 0.3rem; }
.bank-text { margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.option.static { cursor: default; }
.btn.reveal { margin-top: 0.9rem; }
@media (min-width: 640px) { .modes { grid-template-columns: repeat(2, 1fr); } }
