:root {
  --bg: #f1f4f9;
  --card: #ffffff;
  --primary: #2f54eb;
  --primary-dark: #1d39c4;
  --primary-soft: #eef1fd;
  --ink: #1a2030;
  --muted: #5b6478;
  --border: #e3e8f2;
  --ok: #18a058;
  --ok-soft: #eafaf1;
  --ko: #e03131;
  --ko-soft: #fdecec;
  --radius: 16px;
  --shadow: 0 2px 6px rgba(26, 32, 48, .05), 0 10px 30px rgba(26, 32, 48, .08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap { width: 100%; max-width: 880px; margin: 0 auto; padding: 0 16px; }

.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.brand {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand .logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #36cfc9);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: .95rem;
  font-weight: 800;
}
.brand span { color: var(--primary); }

.nav { display: flex; gap: 2px; align-items: center; }
.nav-link {
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}
.nav-link:hover { background: var(--primary-soft); color: var(--primary); }

main { flex: 1; padding: 20px 0 90px; }

.hidden { display: none !important; }

/* ---------- HERO ---------- */
.hero {
  text-align: center;
  padding: 26px 8px 22px;
}
.hero h1 {
  font-size: 1.75rem;
  letter-spacing: -.02em;
  margin-bottom: 10px;
}
.hero h1 em { font-style: normal; color: var(--primary); }
.hero p {
  color: var(--muted);
  font-size: 1.02rem;
  max-width: 540px;
  margin: 0 auto 20px;
}

/* ---------- BOTONES ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  padding: 13px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
  min-height: 46px;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(47, 84, 235, .28); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-secondary:hover { background: #e0e6fa; }
.btn-ghost { background: #fff; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f6f8fc; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; transform: none; }

/* ---------- CATEGORIAS ---------- */
.categorias {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 640px) {
  .categorias { grid-template-columns: repeat(3, 1fr); gap: 18px; }
}
.cat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}
.cat-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), #36cfc9);
}
.cat-card h3 { font-size: 1.12rem; }
.cat-card p { color: var(--muted); font-size: .92rem; flex: 1; }
.cat-card .meta {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
  background: var(--bg);
  border-radius: 8px;
  padding: 6px 10px;
  align-self: flex-start;
}
.cat-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.cat-actions .btn { padding: 12px 8px; font-size: .9rem; min-height: 44px; }

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

/* ---------- SECCIÓN LEYES ---------- */
.seccion-titulo { margin: 30px 0 14px; }
.seccion-titulo h2 { font-size: 1.35rem; }
.seccion-titulo p { color: var(--muted); font-size: .92rem; margin-top: 4px; }
.leyes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 640px) {
  .leyes { grid-template-columns: repeat(2, 1fr); gap: 18px; }
}
.ley-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ley-card h3 { font-size: 1.05rem; }
.ley-card p { color: var(--muted); font-size: .9rem; flex: 1; }
.ley-card .meta {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
  background: var(--bg);
  border-radius: 8px;
  padding: 6px 10px;
  align-self: flex-start;
}

/* ---------- INSTRUCCIONES SIMULACRO ---------- */
.instrucciones {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px;
}
.instrucciones h2 { margin-bottom: 18px; }
.instr-datos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}
.instr-dato {
  background: var(--primary-soft);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}
.instr-num { display: block; font-size: 1.9rem; font-weight: 800; color: var(--primary); }
.instr-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.instr-lista { margin: 0 0 22px 18px; display: flex; flex-direction: column; gap: 8px; color: var(--muted); }
.instr-lista li::marker { color: var(--primary); }
.instr-btns { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) {
  .instr-btns { grid-template-columns: 1fr 1fr; }
}

/* ---------- TEMPORIZADOR ---------- */
.test-right { display: flex; align-items: center; gap: 8px; }
.timer-pill {
  font-size: .9rem;
  font-weight: 800;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.timer-pill.timer-warn {
  color: #fff;
  background: var(--ko);
  border-color: var(--ko);
  animation: timer-blink 1s steps(2, start) infinite;
}
@keyframes timer-blink { to { background: #b02a2a; } }

.spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto 10px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- CABECERA DE TEST ---------- */
.test-head { margin-bottom: 14px; }
.btn-volver-test { margin-bottom: 12px; padding: 8px 14px; min-height: 40px; font-size: .9rem; }
.test-head .topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.test-head h2 { font-size: 1.15rem; line-height: 1.3; }
.counter-pill {
  font-size: .82rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 99px;
  padding: 6px 12px;
  white-space: nowrap;
}
.progress {
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
#progress-bar {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary), #36cfc9);
  border-radius: 99px;
  transition: width .25s ease;
}

/* ---------- PREGUNTA ---------- */
.pregunta {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.q-text { font-size: 1.05rem; font-weight: 700; line-height: 1.45; margin-bottom: 18px; }

.opciones { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }

.opcion {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 13px 14px;
  font-size: .98rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.opcion:active { background: var(--primary-soft); }
.opcion .letra {
  flex: 0 0 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
  font-size: .9rem;
}
.opcion .txt { flex: 1; }

.opcion.sel { border-color: var(--primary); background: var(--primary-soft); }
.opcion.sel .letra { background: var(--primary); color: #fff; }

.opcion.ok { border-color: var(--ok); background: var(--ok-soft); }
.opcion.ok .letra { background: var(--ok); color: #fff; }
.opcion.ko { border-color: var(--ko); background: var(--ko-soft); }
.opcion.ko .letra { background: var(--ko); color: #fff; }
.opcion.ok .letra::after,
.opcion.ko .letra::after {
  content: "";
  position: absolute;
}
.opcion.estado {
  position: relative;
}
.opcion .marca {
  font-size: 1.05rem;
  font-weight: 800;
  color: #fff;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: none;
  align-items: center;
  justify-content: center;
}
.opcion.ok .marca, .opcion.ko .marca { display: inline-flex; }
.opcion.ok .marca { background: var(--ok); }
.opcion.ko .marca { background: var(--ko); }

.explicacion {
  border-left: 4px solid var(--primary);
  background: var(--primary-soft);
  border-radius: 0 12px 12px 0;
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: .94rem;
}
.explicacion .expl-title { font-weight: 800; display: block; margin-bottom: 4px; color: var(--primary-dark); }

/* ---------- NAV DE PREGUNTAS ---------- */
.q-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.q-nav .btn { width: 100%; }

/* ---------- STICKY BAR INFERIOR (movil) ---------- */
.sticky-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(241, 244, 249, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.sticky-actions .wrap { padding: 0; }

/* ---------- RESULTADO ---------- */
.resultado { text-align: center; padding-top: 16px; }
.resultado-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 22px;
}
.resultado-circ {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  margin: 0 auto 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: conic-gradient(var(--primary) calc(var(--pct) * 1%), var(--border) 0);
}
.resultado-circ::before {
  content: "";
  position: absolute;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: var(--card);
}
.resultado-circ > * { position: relative; }
.resultado-num { font-size: 2rem; font-weight: 800; color: var(--primary); }
.resultado-pct { font-size: 1.05rem; font-weight: 700; color: var(--muted); }
.resultado-msg { font-size: 1.02rem; color: var(--muted); margin: 4px 0 10px; }
.resultado-info {
  font-size: .88rem;
  font-weight: 600;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 0 0 22px;
}
.resultado-btns { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) {
  .resultado-btns { grid-template-columns: 1fr 1fr; }
}

/* ---------- ACERCA ---------- */
.acerca {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
}
.acerca h2 { margin-bottom: 14px; }
.acerca p { color: var(--muted); margin-bottom: 12px; }
.acerca .btn { margin-top: 12px; }

/* ---------- FOOTER ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--card);
  padding: 16px 0;
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
}

/* ---------- DONAR ---------- */
.donar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  margin-top: 30px;
  background: linear-gradient(135deg, #fff7ed, #fff);
  border: 1px solid #f3d9b5;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px;
}
.donar-icon {
  font-size: 2.2rem;
  line-height: 1;
}
.donar-texto h2 { font-size: 1.2rem; margin-bottom: 6px; }
.donar-texto p { color: var(--muted); font-size: .92rem; max-width: 520px; margin: 0 auto; }
.donar-opciones {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.btn-donar {
  background: linear-gradient(135deg, #ffb03a, #f5962e);
  color: #4a2c00;
  box-shadow: 0 6px 16px rgba(245, 150, 46, .35);
  text-decoration: none;
}
.btn-donar:hover { background: linear-gradient(135deg, #f5a52b, #e98a1f); }
.btn-bizum { background: linear-gradient(135deg, #28b4ea, #1d9ad6); color: #fff; box-shadow: 0 6px 16px rgba(40, 180, 234, .35); font-weight: 700; }
.btn-bizum:hover { background: linear-gradient(135deg, #1fa8de, #168bc2); }
.donar-bizum-ayuda {
  font-size: .85rem;
  color: var(--muted);
  background: #fff;
  border: 1px solid #bfe6f7;
  border-radius: 10px;
  padding: 10px 14px;
  max-width: 520px;
}
.acerca .btn-donar { margin-right: 10px; }
.acerca .btn-bizum { margin-right: 10px; }
.bizum-link { cursor: pointer; font-weight: 600; color: var(--primary); }
.bizum-link:hover { text-decoration: underline; }

/* ---------- FOOTER ---------- */
.site-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }
.site-footer a:hover { text-decoration: underline; }

/* ---------- ACCESIBILIDAD ---------- */
:focus-visible {
  outline: 3px solid rgba(47, 84, 235, .45);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
