:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b6f76;
  --border: #e2ded5;
  --accent: #2f5d8a;
  --accent-text: #ffffff;
  --ok: #2e7d4f;
  --ok-soft: #e3f2e8;
  --bad: #b3413b;
  --bad-soft: #f8e4e2;
  --answer-bg: #f8f6f1;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --text: #e6e6e3;
    --muted: #9a9ea5;
    --border: #2e3237;
    --accent: #6fa3d6;
    --accent-text: #0f1419;
    --ok: #6cc190;
    --ok-soft: #1c3226;
    --bad: #e2837c;
    --bad-soft: #3a2221;
    --answer-bg: #191b1f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.top, main, .panel {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 20px;
  padding-bottom: 12px;
}
.top h1 { font-size: 1.1rem; margin: 0; }
.top h1 span { color: var(--muted); font-weight: 400; }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel h2 { font-size: 1rem; margin: 0 0 8px; }

.chip-actions { display: flex; gap: 12px; margin-bottom: 8px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }

.chapter-list { display: grid; gap: 6px; }
.chapter-list label {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: .95rem;
  padding: 4px 0;
}
.chapter-list input { margin-top: 5px; accent-color: var(--accent); }
.chapter-list small { color: var(--muted); }

.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.status {
  display: flex;
  justify-content: space-between;
  font-size: .9rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.mode { font-weight: 600; }
.mode.review { color: var(--bad); }

.progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 16px;
}
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .25s; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.chapter {
  margin: 0 0 8px;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.question { font-size: 1.35rem; line-height: 1.4; margin: 0 0 20px; }

.answer {
  background: var(--answer-bg);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 4px 18px;
  margin-bottom: 20px;
  animation: fade .2s ease-out;
}
.answer p, .answer ul, .answer ol { margin: 12px 0; }
.answer ul, .answer ol { padding-left: 22px; }
.answer li { margin: 4px 0; }
.answer li > ul, .answer li > ol { margin: 4px 0; }
.ref { font-size: .85rem; color: var(--muted); }
.ref::before { content: "📖 "; }

.table-wrap { overflow-x: auto; margin: 12px 0; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
th { background: var(--surface); }

@keyframes fade { from { opacity: 0; transform: translateY(-4px); } }

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.main-action { flex: 1; display: flex; }
.main-action .btn.primary { width: 100%; }
.grade { display: flex; gap: 8px; width: 100%; }
.grade .btn { flex: 1; }
.sm { display: none; }

/* Arrastre de la tarjeta al deslizar */
.card { overflow: hidden; }
.card-content { touch-action: pan-y; }
.card-content.snap { transition: transform .2s ease-out, opacity .2s ease-out; }

.btn { flex: 1; }


.btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 600;
  min-height: 44px;
}
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.btn.bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.btn.danger { background: none; color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: none; color: var(--text); border-color: var(--border); }
.btn:disabled { opacity: .4; cursor: default; }

.done { text-align: center; }
.done .panel-actions { justify-content: center; }

.footer { margin: 20px 0 40px; font-size: .9rem; }
.stats, .footer-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.stat { padding: 2px 10px; border-radius: 99px; font-weight: 600; }
.stat.ok { background: var(--ok-soft); color: var(--ok); }
.stat.bad { background: var(--bad-soft); color: var(--bad); }
.keys, .swipe-hint { color: var(--muted); font-size: .8rem; }
.swipe-hint { display: none; }
@media (hover: none) {
  .keys { display: none; }
  .swipe-hint { display: block; }
}
kbd {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  font-family: inherit;
  font-size: .78rem;
  background: var(--surface);
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .card { padding: 18px; }
  .question { font-size: 1.18rem; }

  /* Barra de controles fija abajo, al alcance del pulgar */
  .controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    margin: 0;
    padding: 10px max(12px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .08);
  }
  .nav-btn { width: 48px; padding: 0; flex: none; font-size: 1.2rem; }
  .nav-label { display: none; }
  .grade .btn { padding: 10px 8px; }
  .lg { display: none; }
  .sm { display: inline; }
}

.options { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 8px; }
.options li {
  display: flex; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
}
.options li b { color: var(--muted); min-width: 1.2em; }
.options li.right { background: var(--ok-soft); border-color: var(--ok); }
.options li.right b { color: var(--ok); }
.correct-label { margin: 0; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ok); font-weight: 600; }
.correct-text { margin: 6px 0 12px; }
.answer { animation: flip .35s ease; transform-origin: top; }
@keyframes flip { from { opacity: 0; transform: rotateX(-70deg); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .answer { animation: none; } }
