/* ================================================================
   CCSE — hoja de estilos compartida
   Paleta: papel cálido + rojo ladrillo español + ocre, tinta cálida.
   Tema claro/oscuro por tokens.
   ================================================================ */

:root {
  --bg: #FBF8F3;
  --surface: #FFFFFF;
  --surface-2: #F5EEE4;
  --ink: #201A18;
  --muted: #6B5F5A;
  --faint: #8C8079;
  --line: #E7DDD0;
  --line-strong: #D8CBB9;
  --red: #B81D24;
  --red-soft: #F3E0DF;
  --gold: #A9760A;
  --gold-soft: #F3E7CE;
  --navy: #23283F;
  --green: #2F7D52;
  --green-soft: #E1F0E7;

  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --maxw: 54rem;
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151C; --surface: #1D1F29; --surface-2: #242634;
    --ink: #F1EBE3; --muted: #A99E95; --faint: #877C73;
    --line: #2F313D; --line-strong: #3B3D4C;
    --red: #EA6067; --red-soft: #3A2226; --gold: #E3B24E; --gold-soft: #362E1B;
    --navy: #2B3150; --green: #58B183; --green-soft: #1E2E25;
  }
}
:root[data-theme="dark"] {
  --bg: #14151C; --surface: #1D1F29; --surface-2: #242634;
  --ink: #F1EBE3; --muted: #A99E95; --faint: #877C73;
  --line: #2F313D; --line-strong: #3B3D4C;
  --red: #EA6067; --red-soft: #3A2226; --gold: #E3B24E; --gold-soft: #362E1B;
  --navy: #2B3150; --green: #58B183; --green-soft: #1E2E25;
}
:root[data-theme="light"] {
  --bg: #FBF8F3; --surface: #FFFFFF; --surface-2: #F5EEE4;
  --ink: #201A18; --muted: #6B5F5A; --faint: #8C8079;
  --line: #E7DDD0; --line-strong: #D8CBB9;
  --red: #B81D24; --red-soft: #F3E0DF; --gold: #A9760A; --gold-soft: #F3E7CE;
  --navy: #23283F; --green: #2F7D52; --green-soft: #E1F0E7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body.has-actionbar { padding-bottom: 5.5rem; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 1.3rem; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; margin: 0; text-wrap: balance; }
a { color: var(--red); }

.eyebrow {
  font-family: var(--font-body); text-transform: uppercase; letter-spacing: 0.14em;
  font-size: 0.72rem; font-weight: 700; color: var(--red);
}

/* ---------- Cabecera ---------- */
header.hero {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-2), transparent 80%);
  position: relative;
}
header.hero::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px;
  background: linear-gradient(90deg, var(--red), var(--gold) 70%);
}
.hero-inner { max-width: var(--maxw); margin: 0 auto; padding: 2.3rem 1.3rem 1.9rem; }
.hero h1 {
  font-size: clamp(1.85rem, 5.5vw, 2.8rem); line-height: 1.06;
  letter-spacing: -0.02em; margin: 0.45rem 0 0.65rem;
}
.hero .lede { color: var(--muted); max-width: 48ch; margin: 0 0 1.3rem; font-size: 1.02rem; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 0.45rem 1.4rem; font-size: 0.85rem; color: var(--muted); }
.hero-meta b { color: var(--ink); font-family: var(--font-display); }

.backlink {
  display: inline-block; font-size: 0.82rem; color: var(--muted);
  text-decoration: none; margin-bottom: 0.2rem;
}
.backlink:hover { color: var(--red); }

/* ---------- Botones ---------- */
.btn {
  font-family: var(--font-body); font-size: 0.88rem; font-weight: 600;
  border-radius: 99px; padding: 0.5rem 1rem; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn.ghost { color: var(--muted); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; font-size: 0.95rem; padding: 0.6rem 1.4rem; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

/* ---------- Barra de herramientas / cronómetro ---------- */
.toolbar { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; margin-top: 1.3rem; }
.timer {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-display); font-variant-numeric: tabular-nums;
  font-size: 1.05rem; font-weight: 700;
  background: var(--surface); border: 1px solid var(--line); border-radius: 99px;
  padding: 0.4rem 0.9rem;
}
.timer.low { color: var(--red); border-color: var(--red); }
.timer .dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--faint); }
.timer.running .dot { background: var(--green); }

/* ---------- Medidor de progreso ---------- */
.meter {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.15rem; display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap;
  margin-top: 1.3rem;
}
.meter-main { flex: 1 1 15rem; min-width: 13rem; }
.meter-top { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 0.45rem; }
.meter-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--faint); font-weight: 700; }
.meter-pct { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.bar { height: 9px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--red), var(--gold)); border-radius: 99px; transition: width 0.35s ease; }
.meter-sub { font-size: 0.82rem; color: var(--muted); margin-top: 0.45rem; }

/* ---------- Bloques y preguntas ---------- */
.bloque { margin-top: 2.4rem; }
.bloque-head {
  display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.9rem;
  padding-bottom: 0.55rem; border-bottom: 2px solid var(--line);
}
.bloque-head h2 { font-size: 1.1rem; }
.bloque-head .fmt { margin-left: auto; font-size: 0.78rem; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }

.ttag {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--red); background: var(--red-soft); padding: 0.24rem 0.6rem;
  border-radius: 6px; white-space: nowrap;
}

.q {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.15rem; margin-bottom: 0.85rem; transition: border-color 0.15s ease;
}
.q.correct { border-color: var(--green); }
.q.wrong { border-color: var(--red); }
.q-prompt { display: flex; gap: 0.7rem; font-weight: 600; margin-bottom: 0.8rem; align-items: baseline; }
.q-prompt .num {
  font-family: var(--font-mono); font-size: 0.74rem; color: var(--faint);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px;
  padding: 0.1rem 0.4rem; flex: none;
}
.opts { display: grid; gap: 0.45rem; }
label.opt {
  display: flex; gap: 0.7rem; align-items: flex-start;
  padding: 0.55rem 0.75rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; transition: background 0.12s ease, border-color 0.12s ease;
}
label.opt:hover { background: var(--surface-2); }
label.opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
label.opt .mark {
  flex: none; width: 1.3rem; height: 1.3rem; border: 1.5px solid var(--line-strong);
  border-radius: 50%; display: grid; place-items: center; font-size: 0.76rem; font-weight: 700;
  color: var(--muted); background: var(--surface); transition: all 0.12s ease;
}
label.opt input:checked ~ .mark { border-color: var(--red); background: var(--red); color: #fff; }
label.opt input:focus-visible ~ .mark { outline: 2px solid var(--gold); outline-offset: 2px; }
label.opt .otext { flex: 1; padding-top: 0.05rem; }
label.opt input:checked ~ .otext { font-weight: 600; }

/* estados corregidos */
.q.graded label.opt { cursor: default; }
.q.graded label.opt:hover { background: none; }
.q.graded label.opt.is-correct { border-color: var(--green); background: var(--green-soft); }
.q.graded label.opt.is-correct .mark { border-color: var(--green); background: var(--green); color: #fff; }
.q.graded label.opt.is-wrong { border-color: var(--red); background: var(--red-soft); }
.q.graded label.opt.is-wrong .mark { border-color: var(--red); background: var(--red); color: #fff; }

.explain {
  display: none; margin-top: 0.8rem; padding: 0.65rem 0.85rem; border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 0.88rem; color: var(--muted); border-left: 3px solid var(--gold);
}
.q.graded .explain { display: block; }
.explain b { color: var(--ink); }
.ref {
  display: inline-block; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--green); background: var(--green-soft);
  border-radius: 5px; padding: 0.14rem 0.45rem;
}

/* ---------- Referencia al manual (popover) ---------- */
.refline { display: none; margin-top: 0.6rem; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.q.graded.wrong .refline { display: flex; }
.refbtn {
  font: inherit; font-size: 0.78rem; font-weight: 700; cursor: pointer;
  color: var(--red); background: var(--red-soft);
  border: 1px solid transparent; border-radius: 6px; padding: 0.32rem 0.7rem;
  transition: border-color 0.12s ease;
}
.refbtn:hover { border-color: var(--red); }
.refbtn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.refsec { font-size: 0.78rem; color: var(--faint); }

.refpop { display: none; } /* oculto también en navegadores sin Popover API */
.refpop:popover-open {
  display: block; position: fixed; inset: 0; margin: auto;
  width: min(92vw, 520px); height: fit-content; max-height: 80vh; overflow: auto;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 1.15rem 1.3rem; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}
.refpop::backdrop { background: rgba(10, 10, 16, 0.45); }
.refpop-close {
  position: absolute; top: 0.5rem; right: 0.6rem;
  font: inherit; font-size: 1.25rem; line-height: 1; cursor: pointer;
  color: var(--faint); background: none; border: none; padding: 0.25rem 0.4rem;
}
.refpop-close:hover { color: var(--ink); }
.refpop-head { font-weight: 700; font-size: 0.95rem; padding-right: 2rem; margin-bottom: 0.55rem; }
.refpop-x { margin: 0; font-size: 0.92rem; line-height: 1.6; color: var(--muted); }
.refpop-src {
  margin-top: 0.8rem; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint);
}
/* sin soporte de popover, el botón no haría nada: se oculta y queda la sección */
@supports not selector(:popover-open) {
  .refbtn { display: none; }
}

/* ---------- Resultado ---------- */
.result { display: none; margin-top: 2.4rem; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.result.show { display: block; }
.result-top { padding: 1.5rem 1.3rem; text-align: center; }
.result-top.apto { background: var(--green-soft); }
.result-top.noapto { background: var(--red-soft); }
.verdict { font-family: var(--font-display); font-size: 2rem; font-weight: 700; letter-spacing: -0.01em; }
.result-top.apto .verdict { color: var(--green); }
.result-top.noapto .verdict { color: var(--red); }
.score { font-family: var(--font-display); font-size: 1.08rem; margin-top: 0.25rem; font-variant-numeric: tabular-nums; }
.result-sub { color: var(--muted); font-size: 0.89rem; margin-top: 0.35rem; }
.breakdown { display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); }
.bd { padding: 0.85rem 0.5rem; text-align: center; border-left: 1px solid var(--line); }
.bd:first-child { border-left: none; }
.bd-n { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.bd-l { font-size: 0.63rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); margin-top: 0.15rem; }

/* ---------- Barra fija inferior ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--line);
}
.actionbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 0.7rem 1.3rem;
  display: flex; align-items: center; gap: 0.8rem;
}
.actionbar .spacer { flex: 1; }
.answered { font-size: 0.84rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.answered b { color: var(--ink); }

/* ---------- Tarjetas del índice ---------- */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.9rem; margin-top: 1.4rem; }
.card {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; transition: border-color 0.15s ease, transform 0.15s ease;
}
.card:hover { border-color: var(--red); transform: translateY(-2px); }
.card h3 { font-size: 1.05rem; margin-bottom: 0.3rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.card .card-meta {
  display: flex; align-items: center; gap: 0.5rem; margin-top: 0.7rem;
  font-size: 0.75rem; color: var(--faint); font-variant-numeric: tabular-nums;
}
.card .count {
  font-family: var(--font-display); font-weight: 700; color: var(--gold);
  background: var(--gold-soft); border-radius: 99px; padding: 0.15rem 0.55rem;
}
.card .card-bar { height: 5px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 0.6rem; border: 1px solid var(--line); }
.card .card-bar > i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--red), var(--gold)); }

footer {
  margin-top: 3rem; padding: 1.4rem 0 3rem;
  border-top: 1px solid var(--line); color: var(--faint); font-size: 0.84rem;
}
footer b { color: var(--muted); }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .cards { grid-template-columns: 1fr; }
  .bd-l { font-size: 0.56rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }


/* ================================================================
   Historial de simulacros (index.html)
   ================================================================ */
.hist-empty {
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  font-size: 0.95rem;
}
.hist-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 0.8rem;
}
.hs {
  flex: 1 1 7rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.8rem;
  text-align: center;
}
.hs-n {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
}
.hs-l {
  color: var(--muted);
  font-size: 0.78rem;
}
.hist-list {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.hist-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem 0.9rem;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
}
.hist-row:first-child { border-top: 0; }
.hr-date { color: var(--muted); min-width: 8.5rem; }
.hr-mode { font-weight: 600; min-width: 6rem; }
.hr-per {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  flex: 1;
}
.hr-score {
  font-family: var(--font-mono);
  font-weight: 700;
}
.hr-verdict {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  white-space: nowrap;
}
.hist-row.apto .hr-verdict { background: var(--green-soft); color: var(--green); }
.hist-row.noapto .hr-verdict { background: var(--red-soft); color: var(--red); }
.hist-more {
  color: var(--faint);
  font-size: 0.82rem;
  margin: 0.5rem 0 0;
}
.count.is-apto { color: var(--green); }
.count.is-noapto { color: var(--red); }
@media (max-width: 600px) {
  .hr-per { display: none; }
  .hr-date { min-width: 0; }
}
