@font-face {
  font-family: 'Material Symbols Outlined';
  font-style: normal;
  font-weight: 400;
  src: url('material-symbols.woff2') format('woff2');
  font-display: block;
}
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  vertical-align: middle;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  font-size: 1.2em;
}

:root {
  --navy: #0b1d3a;
  --red: #dc2626;
  --accent: #dc2626;
  --amber: #f59e0b;
  --concrete: #f1f5f9;
  --slate: #1e293b;
  --green: #059669;
  --sky: #0ea5e9;
  --emerald: #10b981;
  --violet: #8b5cf6;
  --rose: #f43f5e;
  --cyan: #06b6d4;
  --lime: #65a30d;

  --bg: #f1f5f9;
  --card: #f8fafc;
  --card-hover: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-soft: #475569;
  --text-dim: #94a3b8;
  --primary: #0b1d3a;
  --primary-hover: #14305c;
  --primary-light: #e2e8f0;
  --border: #e2e8f0;
  --success: #059669;
  --success-bg: #ecfdf5;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --btn-bg: var(--accent);
  --btn-hover: #b91c1c;
  --btn-eval-bg: var(--success);
  --btn-eval-hover: #047857;
  --btn-sm-bg: #e2e8f0;
  --btn-sm-text: #1e293b;
  --btn-sm-hover: #cbd5e1;
  --modal-overlay: rgba(0,0,0,0.4);
  --badge-bg: #e2e8f0;
  --road-bg: #cbd5e1;
  --road-fill: #94a3b8;
  --radius: 10px;
  --radius-sm: 6px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --card-hover: #253248;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-soft: #cbd5e1;
  --text-dim: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #1e293b;
  --border: #334155;
  --success: #34d399;
  --success-bg: #0a2a1a;
  --danger: #ef4444;
  --danger-bg: #2a0a0a;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
  --btn-hover: #991b1b;
  --btn-eval-hover: #059669;
  --btn-sm-bg: #334155;
  --btn-sm-text: #e2e8f0;
  --btn-sm-hover: #475569;
  --modal-overlay: rgba(0,0,0,0.7);
  --badge-bg: #253248;
  --road-bg: #334155;
  --road-fill: #475569;
}

[data-book="I"] { --book-color: var(--sky); }
[data-book="II"] { --book-color: var(--amber); }
[data-book="III"] { --book-color: var(--emerald); }
[data-book="IV"] { --book-color: var(--violet); }
[data-book="V"] { --book-color: var(--rose); }
[data-book="VI"] { --book-color: var(--cyan); }
[data-book="VII"] { --book-color: var(--lime); }

.question[data-book] { border-left-color: var(--book-color); }
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Rubik', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s, color 0.25s;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 60px 20px 20px;
}

/* Entrance animations */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: no-preference) {
  .hero-logo { opacity: 0; animation: fadeUp 0.5s ease both; animation-delay: 0.05s; }
  .hero h1 { opacity: 0; animation: fadeUp 0.5s ease both; animation-delay: 0.15s; }
  .hero-sub { opacity: 0; animation: fadeUp 0.5s ease both; animation-delay: 0.25s; }
  .preview-card { opacity: 0; animation: fadeUp 0.5s ease both; animation-delay: 0.35s; }
  .hero .btn-start { opacity: 0; animation: fadeUp 0.4s ease both; animation-delay: 0.5s; }
  .stats-wrap { opacity: 0; animation: fadeUp 0.4s ease both; animation-delay: 0.6s; }
  .install-btn { opacity: 0; animation: fadeUp 0.4s ease both; animation-delay: 0.7s; }
}

/* Tab bar */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  height: 56px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  transition: color 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.tab:hover { color: var(--text-soft); }
.tab.active { color: var(--primary); }
.tab-icon { font-size: 1.25rem; line-height: 1; display: flex; }
.tab-icon .material-symbols-outlined { font-size: 1.35rem; }
.tab-label { font-size: 0.8rem; margin-top: 2px; font-weight: 500; }
#tab-bar.hidden { display: none; }

#screen-home, #screen-results {
  padding-bottom: calc(56px + env(safe-area-inset-bottom, 0) + 20px);
}

/* Modals */
#modal-about, #modal-close, #modal-help, #modal-install, #modal-ley {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
#modal-about.visible, #modal-close.visible, #modal-help.visible, #modal-install.visible, #modal-ley.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: var(--card);
  border-radius: 14px;
  padding: 28px 32px;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  transition-delay: 0.05s;
}
.visible .modal-box {
  opacity: 1;
  transform: translateY(0);
}
.modal-box p { margin-bottom: 16px; font-size: 0.95rem; line-height: 1.6; color: var(--text-soft); }
.modal-box h2 { font-size: 1.25rem; margin-bottom: 12px; font-family: 'Archivo Black', sans-serif; letter-spacing: 0.02em; }
.modal-box hr { border: none; border-top: 1px solid var(--border); margin-bottom: 16px; }
.modal-box .btns { display: flex; gap: 12px; justify-content: center; }
.modal-box .btns .btn { padding: 10px 28px; font-size: 0.9rem; }

/* Home */
#screen-home {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 56px - env(safe-area-inset-bottom, 0));
}

.hero { text-align: center; padding: 12px 16px; }

.hero-logo {
  width: 100px;
  height: 100px;
  margin-bottom: 8px;
}

.hero h1 {
  font-family: 'Archivo Black', sans-serif;
  font-size: 2.4rem;
  letter-spacing: 0.03em;
  color: var(--primary);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.hero-sub {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 24px;
  font-weight: 400;
}

/* Preview card */
.preview-card {
  text-align: left;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left: 4px solid var(--sky);
  padding: 20px;
  margin-bottom: 28px;
  box-shadow: var(--shadow);
}
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.book-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sky);
  padding: 2px 10px;
  border-radius: 20px;
  background: rgba(14, 165, 233, 0.1);
  font-family: 'JetBrains Mono', monospace;
}
.preview-text {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 14px;
  color: var(--text);
}
.preview-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.preview-opt {
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-soft);
}
.preview-opt .opt-letter {
  font-weight: 600;
  color: var(--primary);
  margin-right: 4px;
}
.preview-correct {
  font-size: 0.8rem;
  color: var(--success);
  font-weight: 500;
}

/* Buttons */
.btn {
  background: var(--btn-bg);
  color: #fff;
  border: none;
  padding: 14px 48px;
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  font-family: 'Rubik', sans-serif;
}
.btn:hover { background: var(--btn-hover); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-sm {
  padding: 8px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--btn-sm-bg);
  color: var(--btn-sm-text);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  font-family: 'Rubik', sans-serif;
}
.btn-sm:hover { background: var(--btn-sm-hover); }

.btn-eval {
  background: var(--btn-eval-bg);
  font-weight: 600;
}
.btn-eval:hover { background: var(--btn-eval-hover); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 6px 16px;
  margin: 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
}
.btn-danger:hover { background: var(--danger-bg); }

/* Theme toggle */
#theme-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 60;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  transition: background 0.2s;
}
#theme-btn:hover { background: var(--badge-bg); }
#theme-btn .material-symbols-outlined {
  color: var(--primary);
  font-size: 1.3rem;
}

/* Stats */
.stats-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 20px;
}
.stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  font-size: 0.9rem;
  color: var(--text-soft);
}
.stats span { display: inline-flex; align-items: center; gap: 4px; }
.stats .ok { color: var(--success); }
.stats .ko { color: var(--danger); }

.stats-reset {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.stats-reset:hover { color: var(--danger); }

.install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-soft);
  font-size: 0.875rem;
  cursor: pointer;
  font-weight: 500;
  transition: border-color 0.2s, background 0.2s;
}
.install-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.install-btn .material-symbols-outlined { font-size: 1.1rem; }

/* Exam header */
.exam-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
}
.exam-header .title {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text);
  font-family: 'Archivo Black', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.exam-header .right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Sticky exam header */
.exam-sticky {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 8px 0 4px;
}

/* Progress bar */
.progress-wrap {
  margin: 4px 24px 10px;
}
.progress-bar-bg {
  height: 4px;
  background: var(--road-bg);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  width: 0%;
}
.progress-text {
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-dim);
  margin-top: 4px;
  text-align: center;
}

/* Road progress */
#exam-dots {
  position: relative;
  padding: 2px 0 10px;
  margin: 0 12px;
}
#exam-dots::before {
  content: '';
  position: absolute;
  left: 16px;
  right: 16px;
  top: 50%;
  height: 2px;
  background: var(--road-bg);
  transform: translateY(-50%);
  z-index: 0;
  border-radius: 1px;
}
.road-track {
  display: flex;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}
.dot {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: var(--road-bg);
  color: var(--text-dim);
  font-size: 0.65rem;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s, color 0.3s;
  position: relative;
  flex-shrink: 0;
}
.dot.done {
  background: var(--primary);
  color: #fff;
}
/* Questions */
.question {
  background: var(--card);
  border-radius: var(--radius);
  border-left: 4px solid var(--border);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.q-num {
  font-weight: 500;
  font-size: 0.95rem;
  margin-bottom: 14px;
  color: var(--text);
  line-height: 1.5;
}
.option {
  display: block;
  padding: 12px 14px;
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--bg);
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  font-size: 0.9rem;
}
.option:hover { background: var(--card-hover); border-color: var(--border); }
.option.selected {
  background: var(--primary-light);
  border-color: var(--primary);
}
.option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.opt-letter {
  font-weight: 600;
  color: var(--primary);
  margin-right: 4px;
}

/* Exam footer */
.exam-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
.exam-footer .page-info {
  font-size: 0.8rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-dim);
  flex-shrink: 0;
}
.exam-footer .btn-eval {
  padding: 8px 20px;
  font-size: 0.875rem;
  font-weight: 600;
}

/* Results */
.result-box { text-align: center; padding: 36px 20px; }
.result-box .score {
  font-size: 3.2rem;
  font-weight: 400;
  font-family: 'Archivo Black', sans-serif;
  margin-bottom: 4px;
  color: var(--primary);
}
.result-box .pass { color: var(--success); font-weight: 600; font-size: 1.1rem; }
.result-box .fail { color: var(--danger); font-weight: 600; font-size: 1.1rem; }
.result-box .label { font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.result-box .sub { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 4px; }
.result-stats {
  font-size: 0.9rem;
  color: var(--text-soft);
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
  gap: 20px;
}
.result-stats .ok { color: var(--success); }
.result-stats .ko { color: var(--danger); }

.result-row {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
  border-left: 4px solid var(--border);
  box-shadow: var(--shadow);
}
.result-row.ok {
  border-left-color: var(--success);
  background: var(--success-bg);
}
.result-row.err { border-left-color: var(--danger); background: var(--danger-bg); }
.result-row.none { border-left-color: var(--text-dim); }
.r-h { font-weight: 500; font-size: 0.9rem; margin-bottom: 6px; }
.r-num { color: var(--text-muted); margin-right: 4px; }
.r-label { font-size: 0.8rem; color: var(--text-dim); font-weight: 500; }
.r-correct, .r-your { font-size: 0.85rem; margin-top: 2px; color: var(--text-soft); }

.sub { font-size: 0.85rem; color: var(--text-muted); }

/* Share card (resultados) */
.share-card {
  text-align: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 6px 0 0;
  box-shadow: var(--shadow);
  display: none;
}
.share-card.show { display: block; }
.share-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}
.share-title .material-symbols-outlined { color: var(--amber); }
.share-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-soft);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  font-family: 'Rubik', sans-serif;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.share-btn:hover { border-color: var(--primary); background: var(--primary-light); transform: translateY(-1px); }
.share-btn .material-symbols-outlined { font-size: 1.1rem; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(64px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%) translateY(12px);
  background: var(--primary);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  font-family: 'Rubik', sans-serif;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast .material-symbols-outlined { font-size: 1.1rem; }

/* Book legend */
.book-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  text-align: left;
  margin: 16px 0 8px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}
.legend-label {
  grid-column: 1 / -1;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-soft);
}
.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* Ley modal */
.ley-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.ley-meta {
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-dim);
  margin-bottom: 16px;
}
.ley-book-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  margin-bottom: 20px;
  padding: 0;
}
.ley-book-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.ley-book-item:last-child { border-bottom: none; }
.ley-book-num {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 0.7rem;
  color: var(--text-dim);
  min-width: 18px;
}
.ley-book-name {
  flex: 1;
  color: var(--text-soft);
}
.ley-book-arts {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.ley-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

@media (max-width: 480px) {
  .container { padding: 48px 12px 12px; }
  .hero h1 { font-size: 1.8rem; }
  .hero-logo { width: 80px; height: 80px; }
  .btn { padding: 12px 36px; font-size: 0.95rem; }
  .dot { width: 16px; height: 16px; font-size: 0.55rem; }
  #exam-dots { margin: 0 4px; }
  #exam-dots::before { left: 10px; right: 10px; }
  .question { padding: 14px; }
  .preview-card { padding: 14px; }
}
