:root {
  --bg: #f3f4f8;
  --card: #ffffff;
  --ink: #1a1d29;
  --muted: #6b7280;
  --line: #e4e6ee;
  --brand: #d6122b;        /* rojo Plaza Vea */
  --brand-dark: #a60d20;
  --brand-soft: #fdeaec;
  --ok: #16a34a;
  --ok-soft: #e9f7ee;
  --warn: #d97706;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --focus: rgba(214, 18, 43, 0.18);
  --radius: 14px;
  --shadow: 0 10px 30px rgba(20, 24, 40, 0.08);
}

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

[hidden] { display: none !important; }

html, body { overflow-x: hidden; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  padding: 1.5rem 1rem 4rem;
}

.wrap { max-width: 820px; margin: 0 auto; }

/* ---------- Topbar ---------- */
.topbar { margin-bottom: 1.25rem; }
.topbar h1 {
  font-size: clamp(1.3rem, 4vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
/* Barra FIJA superior (título + progreso) durante el cuestionario */
.sticky-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 80;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(20, 24, 40, 0.07);
}
.sticky-header__inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 0.7rem 1rem 0.85rem;
}
.sticky-header__title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--ink);
}
.sticky-header .progress { margin-top: 0; }

/* Cuando la barra fija está activa, se reserva espacio arriba */
body.con-sticky { padding-top: 92px; }
.progress__bar {
  flex: 1;
  height: 8px;
  background: var(--line);
  border-radius: 100px;
  overflow: hidden;
}
.progress__bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--brand), var(--brand-dark));
  border-radius: 100px;
  transition: width 0.4s ease;
}
.progress__label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 38px;
  text-align: right;
}

/* ---------- Card ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 4vw, 2rem);
  margin-bottom: 1.5rem;
  animation: fade 0.4s ease;
}
.card__head { margin-bottom: 1.5rem; }
.card__head h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0.35rem 0;
}
.step {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-soft);
  padding: 0.25rem 0.65rem;
  border-radius: 100px;
}
.muted { color: var(--muted); font-size: 0.92rem; }

/* ---------- Form header (grid) ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem 1.25rem;
}
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field--full { grid-column: 1 / -1; }
.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
}
.field label .req { color: var(--brand); margin-left: 2px; }

.field input {
  font: inherit;
  padding: 0.7rem 0.85rem;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--focus);
}
.field input[readonly] { background: #f6f7fb; color: var(--muted); cursor: not-allowed; }

.field.error input { border-color: var(--bad); background: var(--bad-soft); }
.field .msg { font-size: 0.78rem; color: var(--bad); min-height: 0; display: none; }
.field.error .msg { display: block; }

/* ---------- Declaración ---------- */
.declaracion {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  margin-top: 1.5rem;
  padding: 1rem;
  background: #f8f9fc;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}
.declaracion input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--brand); flex-shrink: 0; }
.declaracion.error { border-color: var(--bad); background: var(--bad-soft); }

/* ---------- Preguntas ---------- */
.pregunta {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.1rem 1.2rem;
  margin-bottom: 1.1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.pregunta.error { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.pregunta__nro {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  background: var(--brand);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 50%;
  margin-right: 0.5rem;
  flex-shrink: 0;
}
.pregunta__titulo {
  display: flex;
  align-items: flex-start;
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.9rem;
}

/* Opciones simples */
.opciones { display: flex; flex-direction: column; gap: 0.55rem; }
.opcion {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.65rem 0.8rem;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.92rem;
  transition: border-color 0.15s, background 0.15s;
}
.opcion:hover { border-color: #c9ccd8; background: #fafbfe; }
.opcion input { margin-top: 3px; accent-color: var(--brand); width: 17px; height: 17px; flex-shrink: 0; }
.opcion:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
}

/* Cuadrícula / multipregunta */
.subpreg { margin-top: 0.4rem; }
.subpreg__item {
  padding: 0.85rem 0;
  border-top: 1px dashed var(--line);
}
.subpreg__item:first-child { border-top: none; }
.subpreg__enun { font-size: 0.92rem; margin-bottom: 0.6rem; font-weight: 500; }
.subpreg__opts { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  border: 1.5px solid var(--line);
  border-radius: 100px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.15s;
  user-select: none;
}
.chip input { accent-color: var(--brand); width: 16px; height: 16px; }
.chip:hover { border-color: #c9ccd8; }
.chip:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}
.chip:has(input:checked) input { accent-color: #fff; }

/* ---------- Botones ---------- */
.actions { margin-top: 1.75rem; display: flex; justify-content: flex-end; }
.actions--split { justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.btn {
  font: inherit;
  font-weight: 600;
  padding: 0.8rem 1.5rem;
  border-radius: 10px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, box-shadow 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 6px 16px rgba(214, 18, 43, 0.25);
}
.btn--primary:hover { background: var(--brand-dark); }
.btn--ghost {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}
.btn--ghost:hover { background: #f6f7fb; }

/* ---------- Modal ---------- */
.overlay[hidden] { display: none; }
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 30, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  animation: fade 0.25s ease;
}
.modal {
  background: #fff;
  border-radius: 18px;
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.3);
  animation: pop 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.modal__hero {
  text-align: center;
  padding: 2rem 1.5rem 1.5rem;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  border-radius: 18px 18px 0 0;
}
.modal__hero.is-ok { background: linear-gradient(135deg, #16a34a, #047857); }
.modal__hero.is-bad { background: linear-gradient(135deg, #dc2626, #991b1b); }
.modal__score {
  font-size: 3.4rem;
  font-weight: 800;
  line-height: 1;
}
.modal__score small { font-size: 1.3rem; font-weight: 600; opacity: 0.8; }
.modal__hero h2 { margin-top: 0.5rem; font-size: 1.4rem; }
.modal__sub { opacity: 0.92; font-size: 0.95rem; margin-top: 0.25rem; }

.modal__body { padding: 1.5rem; }
.modal__h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.modal__h3:not(:first-child) { margin-top: 1.4rem; }

.resumen, .datos { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; }
.resumen li, .datos li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
  padding: 0.55rem 0.75rem;
  background: #f8f9fc;
  border-radius: 8px;
}
.resumen li span:last-child, .datos li span:last-child { font-weight: 600; text-align: right; }
.resumen li.correcta span:last-child { color: var(--ok); }
.resumen li.incorrecta span:last-child { color: var(--bad); }

.modal__foot {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ---------- Carnet ---------- */
.carnet-wrap { margin-top: 1.4rem; }
.carnet-canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  display: block;
  margin-bottom: 0.9rem;
}
.btn--block { width: 100%; }

/* ---------- Mensaje cuando no aprueba (sin carnet) ---------- */
.no-carnet {
  background: var(--bad-soft);
  border: 1px solid #f3c2c2;
  border-radius: 10px;
  padding: 1rem 1.1rem;
  color: #8a1f1f;
  font-size: 0.92rem;
  line-height: 1.5;
}

/* ---------- Mini popup (guardando / reintentar) ---------- */
.modal--mini { max-width: 380px; text-align: center; }
.mini { padding: 2rem 1.5rem; }
.mini p { color: var(--muted); font-size: 0.95rem; margin-top: 0.75rem; }
.mini h3 { font-size: 1.15rem; margin-top: 0.5rem; }
.mini__icon { font-size: 2.4rem; }
.mini__actions { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 0.6rem; }
.spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border: 4px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal validar carnet ---------- */
.modal--validar { max-width: 600px; }
.input-row { display: flex; gap: 0.6rem; align-items: stretch; }
.input-row input { flex: 1; }
.btn--sm { padding: 0.55rem 1rem; font-size: 0.88rem; white-space: nowrap; }
.validar__titulo { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.35rem; }
.modal--validar .field { margin-top: 1.1rem; }
.validar__estado {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.validar__estado .spinner { width: 22px; height: 22px; border-width: 3px; margin: 0; }
.validar__mensaje {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border-radius: 10px;
  font-size: 0.92rem;
  line-height: 1.5;
}
.validar__mensaje.is-error {
  background: var(--bad-soft);
  border: 1px solid #f3c2c2;
  color: #8a1f1f;
}
.validar__mensaje.is-ok {
  background: var(--ok-soft);
  border: 1px solid #b6e3c4;
  color: #176235;
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  padding: 1.5rem 1rem 0.5rem;
  line-height: 1.5;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  body { padding: 1rem 0.75rem 3rem; }
  .grid { grid-template-columns: 1fr; }
  .actions--split { flex-direction: column-reverse; }
  .actions--split .btn { width: 100%; }
  .modal__foot .btn { flex: 1; }
}

/* ---------- Impresión ---------- */
@media print {
  body { background: #fff; padding: 0; }
  .overlay { position: static; background: none; backdrop-filter: none; padding: 0; }
  .modal { box-shadow: none; max-height: none; max-width: 100%; }
  .modal__foot { display: none; }
}
