:root {
  --mark-ok: #16a34a;
  --mark-bad: #dc2626;
  --mark-blank: #d97706;
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #17172b;
  --muted: #5c5f73;
  --border: #e5e1d8;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-soft: #ecebfe;
  --primary-text: #ffffff;
  --shadow: 0 1px 2px rgba(23, 23, 43, .05), 0 10px 28px rgba(23, 23, 43, .07);
  --ok: #15803d;
  --ok-bg: #f0fdf4;
  --bad: #b91c1c;
  --bad-bg: #fef2f2;
  --neutral-bg: #f3f4f6;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0e19;
    --card: #171927;
    --text: #e9e9f3;
    --muted: #a0a3b8;
    --border: #2a2d42;
    --primary: #818cf8;
    --primary-2: #a78bfa;
    --primary-soft: #23244a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px rgba(0, 0, 0, .35);
    --ok: #4ade80;
    --ok-bg: #0f2a1a;
    --bad: #f87171;
    --bad-bg: #2c1414;
    --neutral-bg: #22262e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 480px at 88% -8%, rgba(99, 102, 241, .16), transparent 70%),
    radial-gradient(700px 420px at -8% 12%, rgba(22, 163, 74, .08), transparent 70%),
    var(--bg);
  background-repeat: no-repeat;
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
/* Franja superior con el motivo del código de borde de las hojas. */
body::before {
  content: ''; display: block; height: 6px; opacity: .9;
  background: repeating-linear-gradient(90deg,
    var(--text) 0 14px, transparent 14px 20px, var(--text) 20px 25px, transparent 25px 33px,
    var(--text) 33px 38px, transparent 38px 44px, var(--text) 44px 58px, transparent 58px 66px);
}

.wrap { max-width: 860px; margin: 0 auto; padding: 24px 16px 48px; }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.logo { display: inline-flex; align-items: center; gap: 9px; font-weight: 800; font-size: 1.4rem; letter-spacing: -0.03em; }
/* Isotipo: una casilla marcada (assets/logo.svg). */
.logo::before {
  content: ''; width: 28px; height: 28px; border-radius: 7px; flex: none;
  background: url("logo.svg") center / 100% no-repeat;
  box-shadow: 0 4px 10px rgba(79, 70, 229, .35);
}
.brand-sub { color: var(--muted); font-size: 0.95rem; }

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

h1 { font-size: 1.3rem; margin: 0 0 6px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }


label { display: block; font-weight: 600; font-size: 0.9rem; margin: 12px 0 4px; }

input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.04em;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99, 102, 241, .18); }

button {
  margin-top: 18px;
  width: 100%;
  padding: 11px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--primary-text);
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(79, 70, 229, .28);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
button:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); }
button.secondary, button.icon-btn, .pop-nav button, button.chip { box-shadow: none; transform: none; }
button.secondary, .pop-nav button { background: transparent; }
button:disabled { opacity: 0.6; cursor: progress; }
button.secondary {
  width: auto;
  margin: 0;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
}

.error {
  margin: 14px 0 0;
  padding: 10px 12px;
  color: var(--bad);
  background: var(--bad-bg);
  border-radius: 8px;
  font-size: 0.9rem;
}

.result-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.result-head h1 { overflow-wrap: anywhere; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-top: 16px; }
.stat { background: var(--neutral-bg); border-radius: 14px; padding: 14px; }
.stat.with-ring { display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; }
.ring-dial {
  grid-row: span 2; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--primary) calc(var(--pct, 0) * 1%), var(--border) 0);
}
.ring-dial::after { content: ''; width: 40px; height: 40px; border-radius: 50%; background: var(--neutral-bg); }
.stat-label { display: block; color: var(--muted); font-size: 0.8rem; }
.stat-value { display: block; font-size: 1.5rem; font-weight: 700; }
.stat.ok { background: var(--ok-bg); color: var(--ok); }
.stat.bad { background: var(--bad-bg); color: var(--bad); }

.bonus-note { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--neutral-bg); border-left: 4px solid var(--mark-blank); }
.bonus-note[hidden] { display: none; }
.bonus-title { display: block; color: var(--muted); font-size: 0.8rem; }
.bonus-calc { display: block; font-weight: 600; font-variant-numeric: tabular-nums; }
.bonus-reason { margin: 4px 0 0; font-size: 0.9rem; white-space: pre-wrap; overflow-wrap: anywhere; }

.page { padding: 8px; }
.page img { display: block; width: 100%; height: auto; border-radius: 6px; }
.page figcaption { text-align: center; margin-top: 6px; }
figure { margin: 0 0 16px; }

footer { margin-top: 24px; text-align: center; }

/* ---------- Hoja con marcas ---------- */
.sheet { position: relative; line-height: 0; }
.sheet img { display: block; width: 100%; height: auto; border-radius: 6px; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.overlay .q { cursor: pointer; outline: none; }
.overlay .row-hit { fill: transparent; stroke: none; transition: fill .15s; }
.overlay .q:hover .row-hit, .overlay .q:focus-visible .row-hit { fill: rgba(37, 99, 235, .10); }
.overlay .q.selected .row-hit { fill: rgba(37, 99, 235, .18); stroke: #2563eb; stroke-width: 2; }
svg .mark { stroke-width: 3; }
svg .mark.ok { fill: rgba(22, 163, 74, .35); stroke: var(--mark-ok); }
svg .mark.bad { fill: rgba(220, 38, 38, .35); stroke: var(--mark-bad); }
svg .key-ring { fill: none; stroke: var(--mark-ok); stroke-width: 3; stroke-dasharray: 5 4; }
svg .blank-ring { fill: none; stroke: var(--mark-blank); stroke-width: 2; stroke-dasharray: 6 5; }
svg .annulled-line { stroke: #6b7280; stroke-width: 3; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 4px 10px; font-size: .85rem; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid; display: inline-block; }
.legend-dot.ok { border-color: var(--mark-ok); background: rgba(22, 163, 74, .35); }
.legend-dot.bad { border-color: var(--mark-bad); background: rgba(220, 38, 38, .35); }
.legend-dot.key { border-color: var(--mark-ok); border-style: dashed; }
.legend-dot.blank { border-color: var(--mark-blank); border-style: dashed; border-radius: 4px; }

/* ---------- Resumen por pregunta ---------- */
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 8px; margin-top: 12px; }
.chip {
  margin: 0; width: auto; padding: 9px 0; border-radius: 999px; font-weight: 700; font-size: .9rem;
  color: var(--text); background: var(--neutral-bg); border: 2px solid transparent;
}
.chip.st-correct { color: var(--ok); background: var(--ok-bg); border-color: var(--mark-ok); }
.chip.st-incorrect { color: var(--bad); background: var(--bad-bg); border-color: var(--mark-bad); }
.chip.st-blank { border-color: var(--mark-blank); border-style: dashed; }
.chip.st-annulled { color: var(--muted); text-decoration: line-through; }
.chip.st-development { color: var(--muted); }
.chip.st-partial { color: #92600a; background: #fdf3d7; border-color: #e0a422; }

/* ---------- Detalle de una pregunta ---------- */
body.pop-open { overflow: hidden; }
.pop { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.pop[hidden] { display: none; }
.pop-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.pop-card {
  position: relative; width: 100%; max-width: 560px; max-height: 85vh; overflow-y: auto;
  background: var(--card); color: var(--text); border-radius: 16px 16px 0 0; padding: 18px 18px 14px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
}
@media (min-width: 700px) {
  .pop { align-items: center; }
  .pop-card { border-radius: 16px; }
}
.pop-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.pop-head h2 { margin: 0; flex: 1; }
.icon-btn {
  margin: 0; width: 36px; height: 36px; padding: 0; font-size: 1.5rem; line-height: 1;
  color: var(--text); background: transparent; border: 1px solid var(--border); border-radius: 50%;
}
.status-chip { font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--neutral-bg); color: var(--muted); white-space: nowrap; }
.status-chip.st-correct { background: var(--ok-bg); color: var(--ok); }
.status-chip.st-incorrect { background: var(--bad-bg); color: var(--bad); }
.status-chip.st-partial { background: #fdf3d7; color: #92600a; }
.pop-body { line-height: 1.5; }
.row-zoom-wrap { margin: 0 0 12px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; line-height: 0; }
.row-zoom { display: block; width: 100%; height: auto; }
.q-text { margin: 0 0 12px; font-weight: 500; white-space: pre-wrap; }
.q-points { font-weight: 600; }
.alts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.alt { display: flex; align-items: flex-start; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; }
.alt-letter {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; background: var(--neutral-bg);
}
.alt-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.alt-tags { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.tag { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.alt.key { border-color: var(--mark-ok); }
.alt.key .alt-letter { background: var(--mark-ok); color: #fff; }
.alt.mine-ok { border-color: var(--mark-ok); background: var(--ok-bg); }
.alt.mine-ok .alt-letter { background: var(--mark-ok); color: #fff; }
.alt.mine-bad { border-color: var(--mark-bad); background: var(--bad-bg); }
.alt.mine-bad .alt-letter { background: var(--mark-bad); color: #fff; }
.answers { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.answers dt { color: var(--muted); }
.answers dd { margin: 0; font-weight: 600; }
.feedback { margin-top: 14px; padding: 12px; border-radius: 10px; background: var(--neutral-bg); }
.feedback h3 { margin: 0 0 6px; font-size: .9rem; }
.feedback p { margin: 0 0 6px; white-space: pre-wrap; }
.feedback p:last-child { margin-bottom: 0; }

/* ---------- Observaciones ---------- */
textarea {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
textarea[readonly] { opacity: .85; }
.obs-item { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.obs-item h3 { margin: 0 0 6px; font-size: .9rem; }
.obs-mine { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.obs-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.obs-actions button { width: auto; margin: 0; }
.obs-reply { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--neutral-bg); border-left: 4px solid var(--primary); }
.obs-reply-head { display: flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); font-weight: 600; }
.obs-reply p { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.obs-reply-head { flex-wrap: wrap; }
.obs-reply-head .tag:not(.ok):not(.bad) { background: var(--neutral-bg); color: var(--text); border: 1px solid var(--border); }
.credited-note { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--ok-bg); color: var(--ok); font-size: .9rem; }
.chip.has-obs { position: relative; }
.chip.has-obs::after {
  content: ''; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--primary);
}
.pop-nav { display: flex; gap: 10px; margin-top: 16px; }
.pop-nav button { flex: 1; margin: 0; }
.pop-nav button:disabled { opacity: .4; cursor: default; }

/* ---------- Página de inicio ---------- */
.home { max-width: 560px; }
.home h1 { font-size: 1.6rem; margin-bottom: 8px; }
.home .lead { margin: 0 0 20px; color: var(--muted); }
.actions { display: grid; gap: 10px; }
.btn {
  display: block;
  padding: 11px 16px;
  text-align: center;
  font-weight: 600;
  text-decoration: none;
  border-radius: 8px;
  color: var(--primary-text);
  background: var(--primary);
}
.btn.secondary { color: var(--text); background: transparent; border: 1px solid var(--border); }
.home ul { margin: 0; padding-left: 20px; }
.home li { margin: 4px 0; }

@media (prefers-color-scheme: dark) {
  .chip.st-partial { color: #f5c451; background: #33270a; border-color: #b8860b; }
  .status-chip.st-partial { background: #33270a; color: #f5c451; }
}

/* ---------- Entradas (portal y código de captura) ---------- */
a.logo { color: inherit; text-decoration: none; }
a { color: var(--primary); }
.result-head h1 { font-size: 1.5rem; letter-spacing: -.02em; }
#result > .card:first-child { border-top: 4px solid var(--primary); }

.auth {
  display: grid; grid-template-columns: 1fr 1fr; max-width: 900px; margin: 28px auto 0;
  background: var(--card); border: 1px solid var(--border); border-radius: 22px; overflow: hidden; box-shadow: var(--shadow);
}
.auth[hidden] { display: none; }
.auth-side {
  position: relative; padding: 40px 34px 64px; color: #fff; overflow: hidden;
  background: linear-gradient(155deg, #4338ca 0%, #6d28d9 60%, #9333ea 100%);
}
.auth-side::after {
  content: ''; position: absolute; left: 34px; right: 34px; bottom: 28px; height: 8px; opacity: .35;
  background: repeating-linear-gradient(90deg,
    #fff 0 14px, transparent 14px 20px, #fff 20px 25px, transparent 25px 33px,
    #fff 33px 38px, transparent 38px 44px, #fff 44px 58px, transparent 58px 66px);
}
.auth-side h1 { margin: 0 0 22px; font-size: 1.9rem; line-height: 1.12; letter-spacing: -.03em; text-wrap: balance; }
.auth-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.auth-points li { position: relative; padding-left: 34px; color: rgba(255, 255, 255, .92); }
.auth-points li::before {
  content: '✓'; position: absolute; left: 0; top: 0; width: 23px; height: 23px; border-radius: 50%;
  display: grid; place-items: center; font-size: .8rem; font-weight: 800; background: rgba(255, 255, 255, .2);
}
.auth-points.steps-list { counter-reset: s; }
.auth-points.steps-list li { counter-increment: s; }
.auth-points.steps-list li::before { content: counter(s); }
.auth-form { padding: 40px 34px; align-self: center; }
.auth-form .muted { margin: 0 0 8px; }
.auth-form .lock { margin: 16px 0 0; text-align: center; }
@media (max-width: 760px) {
  .auth { grid-template-columns: 1fr; margin-top: 8px; }
  .auth-side { padding: 26px 22px 44px; }
  .auth-side::after { left: 22px; right: 22px; bottom: 18px; }
  .auth-side h1 { font-size: 1.5rem; margin-bottom: 16px; }
  .auth-points { gap: 10px; font-size: .95rem; }
  .auth-form { padding: 24px 22px 28px; }
}
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.4rem; letter-spacing: .12em; text-align: center; text-transform: uppercase; }

/* ---------- Accesibilidad ---------- */
.skip { position: absolute; left: 12px; top: -60px; z-index: 200; padding: 10px 16px; border-radius: 8px; background: var(--card); color: var(--text); border: 2px solid var(--primary); font-weight: 600; }
.skip:focus { top: 12px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
