/* =========================================================
   OpoCitores — sistema de diseño compartido
   Idea: calma y confianza. Papel cálido, verde profundo como único
   color de marca, tipografía grande y legible, mucho aire.
   ========================================================= */

/* ---------- Tipografías (alojadas aquí: sin peticiones externas) ---------- */
@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/sourcesans3.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Serif 4";
  src: url("../fonts/sourceserif4.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #16231f;
  --muted: #55625c;
  --border: #dedacd;
  --border-strong: #c3bead;

  --primary: #0b5c4a;
  --primary-hover: #084838;
  --primary-soft: #e2efe9;
  --on-primary: #ffffff;

  --ok: #1c7a45;
  --ok-soft: #e3f1e7;
  --ko: #b3342f;
  --ko-soft: #f8e4e1;
  --warn: #8a5a0b;
  --warn-soft: #f6ead0;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(22, 35, 31, .05);
  --shadow-lift: 0 6px 24px rgba(22, 35, 31, .08);

  --font: "Source Sans 3", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
}

:root[data-theme="dark"] {
  --bg: #0f1714;
  --surface: #16211d;
  --surface-2: #1d2b26;
  --text: #e8efeb;
  --muted: #a3b1aa;
  --border: #2a3a34;
  --border-strong: #3a4f47;

  --primary: #5fc9a8;
  --primary-hover: #7fd8bc;
  --primary-soft: #14312a;
  --on-primary: #08201a;

  --ok: #56c487;
  --ok-soft: #153325;
  --ko: #ef8078;
  --ko-soft: #3a1f1d;
  --warn: #e3b25a;
  --warn-soft: #36290f;

  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lift: 0 8px 28px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

/* El atributo hidden siempre oculta, aunque el elemento tenga su propio display */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; font-size: 106.25%; } /* 17 px base */

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.08rem;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--primary); text-underline-offset: 3px; }

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 .5rem;
  letter-spacing: -.01em;
  text-wrap: balance;
}
h1, .as-h1 { font-size: clamp(1.9rem, 4.4vw, 2.7rem); }
h2 { font-size: clamp(1.4rem, 3vw, 1.8rem); }
h3 { font-size: 1.15rem; }
p { text-wrap: pretty; }

.container {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 20px;
}

main.container { flex: 1; padding-top: 32px; padding-bottom: 56px; }

.muted { color: var(--muted); }
.small { font-size: .92rem; }

.eyebrow {
  margin: 0 0 .5rem;
  font-size: .92rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--primary);
}

/* ---------- Accesibilidad ---------- */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  background: var(--primary);
  color: var(--on-primary);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 700;
}
.skip-link:focus { top: 12px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
}

a.brand, .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 500;
  letter-spacing: -.01em;
}
.brand strong { font-weight: 700; color: var(--primary); }

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--on-primary);
  font-family: var(--font);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .04em;
}

.topnav { display: flex; align-items: center; gap: 2px; }

.topnav button,
.topnav summary,
.topnav a {
  background: none;
  border: 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 700;
  font-size: .98rem;
  text-decoration: none;
  min-height: 44px;
}

.topnav button:hover,
.topnav summary:hover,
.topnav a:hover { background: var(--surface-2); color: var(--text); }

#themeToggle { font-size: 1.1rem; min-width: 44px; }

/* Desplegable «Guías de Estudio» (js/menu.js lo cierra al pulsar fuera o con Escape) */
.nav-menu { position: relative; }
.topnav summary {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.15;
  cursor: pointer;
  list-style: none;
}
.topnav summary::-webkit-details-marker { display: none; }
.topnav summary::after {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: translateY(-2px) rotate(45deg);
  transition: transform .15s;
}
.nav-menu[open] summary { background: var(--surface-2); color: var(--text); }
.nav-menu[open] summary::after { transform: translateY(2px) rotate(225deg); }
.nav-menu ul {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 230px;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
}
.topnav .nav-menu li a {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  font-size: 1rem;
  white-space: nowrap;
}

/* Enlaces a los silos del temario: en pantallas estrechas no caben y se llega a ellos
   desde la portada y las migas de pan */
@media (max-width: 960px) {
  .topnav .nav-silo { display: none; }
}

/* ---------- Vistas ---------- */
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Tarjetas y botones ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 11px 22px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.2;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: none; border-color: var(--ko); color: var(--ko); margin-top: 32px; }
.btn-danger:hover { background: var(--ko-soft); }
.btn-block { width: 100%; margin-top: 20px; }

.link-back {
  background: none;
  border: 0;
  padding: 8px 0;
  margin-bottom: 12px;
  color: var(--primary);
  font-weight: 700;
}
.link-back:hover { text-decoration: underline; text-underline-offset: 3px; }

.section-title { font-size: 1.3rem; margin: 40px 0 14px; }

/* ---------- Inicio de la app de tests ---------- */
.hero p { color: var(--muted); max-width: 60ch; margin: 0; }
.hero h1 { margin-bottom: .6rem; }

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 28px;
}

.action {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 16px;
  align-items: center;
  padding: 18px 20px;
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
}

.action:hover { border-color: var(--primary); box-shadow: var(--shadow-lift); }
.action:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; border-color: var(--border); }

.action-icon {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 1.35rem;
}

.action-title { font-weight: 700; font-size: 1.05rem; }
.action-text { color: var(--muted); font-size: .95rem; }

.topic-list { display: grid; gap: 14px; }

.topic { overflow: hidden; }

.topic > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  cursor: pointer;
  min-height: 64px;
}

.topic > summary::-webkit-details-marker { display: none; }

.topic > summary::after {
  content: "›";
  font-size: 1.6rem;
  color: var(--muted);
  transition: transform .2s;
}

.topic[open] > summary::after { transform: rotate(90deg); }

.topic-name { font-weight: 700; font-size: 1.05rem; }
.topic-meta { color: var(--muted); font-size: .95rem; }

.topic-body { border-top: 1px solid var(--border); }

.test-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 13px 20px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

a.test-row { color: inherit; text-decoration: none; }
.test-row:last-child { border-bottom: 0; }
.test-row:hover { background: var(--surface-2); }
.test-row.all { font-weight: 700; color: var(--primary); }

.test-info { display: flex; flex-direction: column; min-width: 0; }
.test-sub { color: var(--muted); font-size: .92rem; }

.badge {
  flex-shrink: 0;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: .92rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
}

.badge.good { background: var(--ok-soft); color: var(--ok); }
.badge.mid { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--ko-soft); color: var(--ko); }

.group-title {
  margin: 28px 0 10px;
  font-family: var(--font);
  font-size: .92rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--primary);
}
.group-title:first-child { margin-top: 0; }

/* Vista de un solo apartado (tests.html#tema-<id>) */
.topic-header { margin-bottom: 24px; }
.topic-header .as-h1 { margin-bottom: 6px; }
.topic-header p.muted { margin: 0; max-width: 62ch; }
.topic-flat .test-row { padding-top: 15px; padding-bottom: 15px; }

/* ---------- Configuración ---------- */
#view-setup, #view-quiz { max-width: 720px; margin-inline: auto; }

/* Página propia de cada test: introducción y lista de preguntas con respuesta */
.test-page { max-width: 720px; margin-inline: auto; }
.test-page .lead { margin: 0 0 24px; }
.q-list { padding-left: 1.6rem; margin: 20px 0 0; }
.q-list > li { padding: 18px 0; border-bottom: 1px solid var(--border); }
.q-list > li::marker { font-weight: 700; color: var(--primary); }
.q-text { margin: 0 0 8px; font-weight: 700; white-space: pre-line; overflow-wrap: anywhere; }
.q-options { margin: 0 0 8px; padding-left: 1.6rem; }
.q-list summary { display: inline-block; padding: 8px 0; color: var(--primary); font-weight: 700; cursor: pointer; }
.q-list details p { margin: 4px 0 0; }

.setup { padding: 28px; }
.setup h2 { font-size: 1.6rem; }

.field { display: block; margin-top: 20px; }
.field span { display: block; font-weight: 700; margin-bottom: 8px; }

select {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.check {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin-top: 6px;
  cursor: pointer;
}

.check input { width: 22px; height: 22px; accent-color: var(--primary); flex-shrink: 0; }

/* ---------- Test ---------- */
.quiz-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.quiz-counter { margin: 0; color: var(--muted); }
.quiz-counter strong { color: var(--text); }
.quiz-tools { display: flex; align-items: center; gap: 10px; }

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.timer.low { background: var(--ko-soft); color: var(--ko); }

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 20px;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: 999px;
  transition: width .25s ease;
}

.question-card { padding: 28px; }

.question-text {
  font-family: var(--font);
  font-size: 1.28rem;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0;
  margin-bottom: 22px;
  white-space: pre-line; /* respeta los saltos de línea (afirmaciones I, II, III; columnas a relacionar) */
}

.feedback-why {
  display: block;
  margin-top: 6px;
  font-weight: 400;
  color: var(--text);
}

.review-why {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: .97rem;
}

.options {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 14px 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  line-height: 1.5;
  transition: border-color .12s, background .12s;
}

.option:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.option:disabled { cursor: default; }

.option-letter {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  font-weight: 700;
  font-size: .95rem;
}

.option.selected { border-color: var(--primary); background: var(--primary-soft); }
.option.selected .option-letter { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

.option.correct { border-color: var(--ok); background: var(--ok-soft); }
.option.correct .option-letter { background: var(--ok); border-color: var(--ok); color: #fff; }

.option.wrong { border-color: var(--ko); background: var(--ko-soft); }
.option.wrong .option-letter { background: var(--ko); border-color: var(--ko); color: #fff; }

.feedback {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 10px;
  font-weight: 700;
}

.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.ko { background: var(--ko-soft); color: var(--ko); }

.quiz-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.quiz-nav #btnNext { margin-left: auto; }
#btnFlag.active { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }

.navigator { margin-top: 24px; padding: 16px 20px; }
.navigator summary { cursor: pointer; font-weight: 700; min-height: 32px; }

.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.nav-cell {
  position: relative;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  font-weight: 700;
  font-size: .95rem;
}

.nav-cell.answered { background: var(--primary-soft); border-color: var(--primary); }
.nav-cell.correct { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.nav-cell.wrong { background: var(--ko-soft); border-color: var(--ko); color: var(--ko); }
.nav-cell.current { outline: 3px solid var(--text); outline-offset: 2px; }
.nav-cell.flagged::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}

/* ---------- Resultados ---------- */
.results { padding: 36px 28px; text-align: center; }

.score-ring {
  --pct: 0;
  --ring: var(--primary);
  width: 168px;
  height: 168px;
  margin: 16px auto;
  border-radius: 50%;
  display: grid;
  place-content: center;
  background:
    radial-gradient(closest-side, var(--surface) 80%, transparent 81%),
    conic-gradient(var(--ring) calc(var(--pct) * 1%), var(--border) 0);
}

.score-ring span { font-family: var(--serif); font-size: 3.2rem; font-weight: 700; line-height: 1; }
.score-ring small { color: var(--muted); }

.verdict { font-family: var(--serif); font-weight: 600; font-size: 1.3rem; margin: 6px 0 22px; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat {
  padding: 16px 8px;
  border-radius: var(--radius);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat strong { font-family: var(--serif); font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { font-size: .92rem; color: var(--muted); }
.stat.ok strong { color: var(--ok); }
.stat.ko strong { color: var(--ko); }
.stats-row.big .stat { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 22px 8px; }

.results-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
}

.review-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 40px 0 14px;
}

.review-head .section-title { margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 40px;
  padding: 6px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  font-size: .95rem;
  font-weight: 700;
}

.chip:hover { border-color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

.review-list { display: grid; gap: 14px; }

.review-item { padding: 20px; border-left: 5px solid var(--border-strong); }
.review-item.ok { border-left-color: var(--ok); }
.review-item.ko { border-left-color: var(--ko); }
.review-item.blank { border-left-color: var(--warn); }

.review-item h3 { font-family: var(--font); font-size: 1.05rem; font-weight: 700; white-space: pre-line; }
.review-item .options { gap: 8px; margin-top: 12px; }
.review-item .option { min-height: 0; padding: 10px 14px; font-size: .97rem; }
.review-tag { font-size: .92rem; color: var(--muted); margin: 0 0 6px; }

.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Progreso ---------- */
.topic-stats, .history { padding: 8px 20px; }

.ts-row, .h-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.ts-row:last-child, .h-row:last-child { border-bottom: 0; }

.ts-bar {
  flex: 1;
  max-width: 220px;
  height: 10px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.ts-bar div { height: 100%; background: var(--primary); border-radius: 999px; }
.ts-name { flex: 1.4; min-width: 0; }
.ts-pct { width: 52px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.h-main { min-width: 0; }
.h-main small { display: block; color: var(--muted); }

.backup { padding: 22px; }
.backup p { margin: 0 0 16px; }
.backup .backup-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.backup #backupMsg { margin: 16px 0 0; }

/* Registro opcional (nombre y email, solo en el navegador) en «Mi progreso» */
.profile { padding: 22px; margin-bottom: 24px; }
.profile p { margin: 0 0 16px; }
.profile .backup-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.profile-title { margin: 0 0 8px; font-size: 1.25rem; }
.profile .opt { font-weight: 400; font-size: 1rem; color: var(--muted); }
.profile .profile-hello { font-size: 1.25rem; margin-bottom: 4px; }
.profile-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; margin-bottom: 20px; }
.profile .form-field > label { display: block; font-weight: 700; margin-bottom: 8px; }
.profile input[type="text"],
.profile input[type="email"] {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
}
.profile input:focus-visible { border-color: var(--primary); }
.profile [aria-invalid="true"] { border-color: var(--ko); }
.profile .form-error { margin: 6px 0 0; font-size: .95rem; color: var(--ko); font-weight: 600; }
.profile #profileMsg { margin: 16px 0 0; }
.profile #profileMsg:empty { display: none; }

/* ---------- Pie ---------- */
.footer {
  padding-top: 24px;
  padding-bottom: 32px;
  color: var(--muted);
  font-size: .95rem;
  text-align: center;
  border-top: 1px solid var(--border);
}
.footer p { margin: 4px 0; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .topbar-inner { height: 60px; }
  .topnav a, .topnav button, .topnav summary { padding: 10px; font-size: .95rem; }
  .brand > span:last-child { display: none; }
  .question-card, .setup, .results { padding: 20px; }
  .question-text { font-size: 1.15rem; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .quiz-nav .btn { flex: 1 1 45%; padding: 10px; }
  .quiz-nav #btnNext { margin-left: 0; flex-basis: 100%; }
  .ts-bar { display: none; }
}

#view-stats .as-h1 { margin-bottom: 22px; }

/* Menú en móvil: «Guías de Estudio» y «Mi progreso» se parten en dos líneas dentro de la cabecera */
@media (max-width: 480px) {
  .topbar-inner { gap: 8px; }
  .topnav a, .topnav button, .topnav summary { display: flex; align-items: center; justify-content: center; line-height: 1.15; text-align: left; }
  .topnav .nav-silo { display: none; }
  .topnav .nav-menu li a { justify-content: flex-start; }
  .topnav summary { width: min-content; min-width: 92px; }
}

/* ---------- Móviles muy estrechos (≤ 400 px) ---------- */
@media (max-width: 400px) {
  .container { padding: 0 16px; }
  .topnav { gap: 0; }
  .topnav a, .topnav button, .topnav summary { padding: 6px; font-size: .92rem; }
  .stats-row.big .stat strong { font-size: 1.45rem; }
  .btn-lg { padding-inline: 18px; }
}

/* El encabezado del test se reparte en dos filas cuando falta sitio */
@media (max-width: 600px) {
  .quiz-head { flex-wrap: wrap; align-items: center; }
  .quiz-head > div:first-child { flex: 1 1 100%; }
  .quiz-tools { width: 100%; justify-content: space-between; }
  .eyebrow { letter-spacing: .04em; }
}

/* ---------- Móvil en horizontal (poca altura): aprovechar cada píxel ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .topbar { position: relative; } /* no fija, pero con su z-index para el desplegable */
  .topbar-inner { height: 52px; }
  .brand-mark { width: 34px; height: 34px; }
  main.container { padding-top: 16px; padding-bottom: 32px; }
  h1, .as-h1 { font-size: 1.6rem; }
  .quiz-head { flex-wrap: nowrap; align-items: center; margin-bottom: 8px; }
  .quiz-head > div:first-child { flex: 1 1 auto; min-width: 0; }
  .quiz-head .eyebrow { margin: 0; font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .quiz-tools { width: auto; }
  .progress { margin-bottom: 12px; }
  .question-card { padding: 16px 20px; }
  .question-text { font-size: 1.1rem; margin-bottom: 14px; }
  .options { gap: 8px; }
  .option { min-height: 48px; padding: 9px 14px; }
  .feedback { margin-top: 12px; padding: 10px 14px; }
  .quiz-nav { margin-top: 12px; }
  .quiz-nav #btnNext { margin-left: auto; flex-basis: auto; }
  .quiz-nav .btn { flex: 0 1 auto; padding: 8px 16px; }
  .setup, .results { padding: 20px; }
  .section-title { margin-top: 28px; }
}

/* ---------- Aviso de cookies (js/cookies.js) ---------- */
/* Barra fija abajo; no tapa el contenido: el body reserva su altura */
body.has-cookie-banner { padding-bottom: var(--cookie-banner-h, 0px); }

.cookie-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface);
  border-top: 3px solid var(--primary);
  box-shadow: 0 -8px 28px rgba(22, 35, 31, .14);
  animation: cookie-in .25s ease-out;
}
:root[data-theme="dark"] .cookie-banner { box-shadow: 0 -8px 28px rgba(0, 0, 0, .45); }
@keyframes cookie-in { from { transform: translateY(100%); } to { transform: none; } }

.cookie-banner-inner {
  display: flex;
  align-items: center;
  gap: 18px 36px;
  padding-top: 20px;
  padding-bottom: 20px;
}
.cookie-banner-text { flex: 1 1 auto; min-width: 0; }
.cookie-banner-text p { margin: 0; max-width: 92ch; }
.cookie-banner-text p + p { margin-top: 4px; }
.cookie-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--text);
}

/* Aceptar y Rechazar: mismo tamaño, mismo estilo y en la misma capa */
.cookie-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 10px;
}
.cookie-actions .btn { min-width: 132px; }

/* Panel de configuración */
.cookie-dialog {
  width: min(640px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lift);
}
.cookie-dialog::backdrop { background: rgba(10, 20, 16, .55); }
.cookie-dialog-inner { padding: 24px 26px 26px; }
.cookie-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.cookie-dialog h2 { margin: 0 0 .4rem; font-size: 1.5rem; }
.cookie-close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin: -6px -8px 0 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--muted);
}
.cookie-close:hover { background: var(--surface-2); color: var(--text); }

.cookie-cat {
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.cookie-cat p { margin: 6px 0 0; color: var(--muted); font-size: .98rem; }
.cookie-cat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.cookie-cat-name { font-weight: 700; cursor: pointer; }
span.cookie-cat-name { cursor: default; }
.cookie-always { font-size: .9rem; font-weight: 700; color: var(--ok); white-space: nowrap; }
.cookie-dialog .small { margin: 16px 0 0; }
.cookie-dialog .cookie-actions { margin-top: 18px; }

/* Interruptor accesible (checkbox nativo con role="switch") */
.cookie-switch {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  position: relative;
  width: 52px;
  height: 30px;
  margin: 0;
  border: 1.5px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.cookie-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .15s, background .15s;
}
.cookie-switch:checked { background: var(--primary); border-color: var(--primary); }
.cookie-switch:checked::after { transform: translateX(22px); background: var(--on-primary); }

@media (max-width: 900px) {
  .cookie-banner-inner { flex-direction: column; align-items: stretch; padding-top: 16px; padding-bottom: 16px; }
  .cookie-actions .btn { flex: 1 1 0; }
}
@media (max-width: 520px) {
  .cookie-banner-text { font-size: 1rem; }
  .cookie-actions .btn { flex: 1 1 100%; }
  .cookie-actions .btn-ghost { order: 3; }
  .cookie-dialog-inner { padding: 20px 18px 22px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .cookie-banner { max-height: 60vh; }
  .cookie-banner-inner { flex-direction: row; align-items: center; padding-top: 10px; padding-bottom: 10px; }
  .cookie-banner-text { font-size: .95rem; }
  .cookie-title { font-size: 1.05rem; }
  .cookie-actions { flex-direction: column; }
  .cookie-actions .btn { min-height: 44px; padding: 8px 16px; }
}
@media print {
  .cookie-banner, .cookie-dialog { display: none !important; }
  body.has-cookie-banner { padding-bottom: 0; }
}
