:root {
  --bg: #f6f4fb;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-2: #f2eefb;
  --text: #2a2540;
  --text-soft: #6b6486;
  --line: #e6e0f2;
  --brand: #7c5cde;
  --brand-soft: #efe9fd;
  --accent: #16a085;
  --accent-soft: #e2f6f0;
  --warn: #e67e22;
  --danger: #e74c3c;
  --danger-soft: #fdecea;
  --ok: #16a34a;
  --ok-soft: #e6f5ec;
  --shadow: 0 6px 24px rgba(60, 40, 120, .08);
  --radius: 18px;
  --radius-sm: 12px;
}
[data-theme="dark"] {
  --bg: #16131f;
  --bg-soft: #1e1a2b;
  --card: #211c30;
  --card-2: #2a2440;
  --text: #ece8f7;
  --text-soft: #a79fc2;
  --line: #322b47;
  --brand: #a98cff;
  --brand-soft: #2c2447;
  --accent: #33d6ac;
  --accent-soft: #17352e;
  --warn: #f0a35a;
  --danger: #ff6b6b;
  --danger-soft: #3a2224;
  --ok: #4ade80;
  --ok-soft: #1e3626;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background .25s, color .25s;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
a { color: var(--brand); }
button { font-family: inherit; cursor: pointer; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 12px clamp(14px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { font-size: 26px; }
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: .2px; }
.brand-sub { font-size: 11px; color: var(--text-soft); font-weight: 600; letter-spacing: .3px; text-transform: uppercase; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  border: 0; background: transparent; color: var(--text-soft);
  padding: 9px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  transition: .18s;
}
.tab:hover { color: var(--text); background: var(--card-2); }
.tab.is-active { color: #fff; background: var(--brand); box-shadow: 0 4px 14px color-mix(in srgb, var(--brand) 40%, transparent); }
.theme-toggle {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; font-size: 18px; line-height: 1;
}

/* ---------- Layout ---------- */
main { max-width: 940px; margin: 0 auto; padding: clamp(18px, 4vw, 34px) clamp(14px, 4vw, 24px) 120px; }
.view { animation: fade .3s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(16px, 3vw, 26px);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }

/* ---------- Inicio / Hero ---------- */
.hero {
  background: linear-gradient(135deg, var(--brand), #b06ab3);
  color: #fff; border-radius: var(--radius); padding: clamp(24px, 5vw, 42px);
  box-shadow: var(--shadow); margin-bottom: 22px;
}
.hero h1 { font-size: clamp(24px, 5vw, 36px); font-weight: 800; }
.hero p { font-size: clamp(15px, 2.4vw, 18px); opacity: .95; max-width: 60ch; }
.hero-stats { display: flex; gap: 24px; margin-top: 20px; flex-wrap: wrap; }
.hero-stat b { display: block; font-size: 26px; font-weight: 800; }
.hero-stat span { font-size: 13px; opacity: .9; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.topic-card {
  text-align: left; border: 1px solid var(--line); background: var(--card);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  transition: .18s; display: flex; flex-direction: column; gap: 8px;
}
.topic-card:hover { transform: translateY(-3px); border-color: var(--brand); }
.topic-emoji { font-size: 30px; }
.topic-card h3 { font-size: 17px; margin: 0; color: var(--text); }
.topic-card p { margin: 0; font-size: 13px; color: var(--text-soft); }
.topic-card .go { margin-top: auto; color: var(--brand); font-weight: 800; font-size: 13px; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-soft); font-weight: 800; margin: 26px 4px 12px; }

/* ---------- Estudiar ---------- */
.topic-nav { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--text-soft);
  padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 13px; transition: .16s;
}
.chip:hover { color: var(--text); }
.chip.is-active { background: var(--brand); color: #fff; border-color: var(--brand); }

.prose h2 { font-size: 22px; color: var(--brand); }
.prose p { margin: 0 0 14px; }
.lead { font-size: 16px; }

.concepts { display: grid; gap: 12px; margin-top: 8px; }
.concept {
  background: var(--card-2); border-radius: var(--radius-sm); padding: 14px 16px;
  border-left: 4px solid var(--brand);
}
.concept b { color: var(--text); }
.concept .ej { display: block; margin-top: 6px; font-size: 13px; color: var(--text-soft); font-style: italic; }

.formulas { display: grid; gap: 12px; margin-top: 8px; }
.formula {
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.formula .fname { font-weight: 800; font-size: 14px; }
.formula .fbody {
  font-family: "DejaVu Sans Mono", ui-monospace, monospace; font-size: 15px;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; margin: 8px 0; display: inline-block; color: var(--text);
}
.formula .fnote { font-size: 13px; color: var(--text-soft); }

/* ---------- Notas importantes ---------- */
.notas { display: grid; gap: 10px; margin-top: 8px; }
.nota {
  background: color-mix(in srgb, var(--warn) 12%, var(--card));
  border-left: 4px solid var(--warn); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 14px; color: var(--text);
}

/* ---------- Explicación para mortales ---------- */
.mortales {
  margin-top: 8px; background: var(--brand-soft);
  border: 1px dashed color-mix(in srgb, var(--brand) 45%, transparent);
  border-radius: var(--radius); padding: 16px 18px;
}
.mortales > p { margin: 0 0 12px; font-size: 15px; color: var(--text); }
.mortal-block {
  background: var(--bg-soft); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-top: 10px; border-left: 4px solid var(--brand);
}
.mortal-block.ml-exp { border-left-color: var(--accent); }
.mortal-block p { margin: 6px 0 0; font-size: 14px; color: var(--text); }
.mortal-block .ml {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
  color: var(--brand);
}
.mortal-block.ml-exp .ml { color: var(--accent); }

/* ---------- Chuleta ---------- */
.cheat-group { margin-bottom: 22px; }
.cheat-group h3 { color: var(--brand); font-size: 16px; }
.cheat-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.cheat-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.cheat-table td:first-child { font-weight: 700; width: 34%; }
.cheat-table td:nth-child(2) { font-family: "DejaVu Sans Mono", ui-monospace, monospace; color: var(--accent); }

/* ---------- Calculadora 2x2 ---------- */
.calc-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.matrix { border-collapse: collapse; margin: 6px auto 18px; }
.matrix th, .matrix td { border: 1px solid var(--line); padding: 6px; text-align: center; }
.matrix th { background: var(--card-2); font-size: 12px; color: var(--text-soft); font-weight: 700; padding: 8px 12px; }
.matrix input {
  width: 78px; padding: 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg-soft); color: var(--text); font-size: 16px; text-align: center; font-weight: 700;
}
.matrix input:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.results { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 8px; }
.rescard { background: var(--card-2); border-radius: var(--radius-sm); padding: 14px; text-align: center; }
.rescard .rv { font-size: 26px; font-weight: 800; color: var(--brand); }
.rescard .rl { font-size: 12px; color: var(--text-soft); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.rescard .rf { font-size: 11px; color: var(--text-soft); margin-top: 4px; font-family: ui-monospace, monospace; }
.muted { color: var(--text-soft); font-size: 14px; }

/* ---------- Práctica / Quiz ---------- */
.quiz-setup { text-align: center; }
.quiz-setup .grid { margin-top: 18px; }
.mode-card { cursor: pointer; }
.progress-wrap { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.progress-bar { flex: 1; height: 10px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--brand); transition: width .3s; }
.progress-txt { font-weight: 800; font-size: 13px; color: var(--text-soft); white-space: nowrap; }
.q-origin { font-size: 12px; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .4px; }
.q-text { font-size: 18px; font-weight: 700; margin: 6px 0 18px; white-space: pre-wrap; }
.options { display: grid; gap: 10px; }
.opt {
  text-align: left; border: 1.5px solid var(--line); background: var(--card);
  color: var(--text); padding: 14px 16px; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; transition: .14s; white-space: pre-wrap;
}
.opt:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-soft); }
.opt:disabled { cursor: default; }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--danger); background: var(--danger-soft); }
.opt .mark { float: right; font-weight: 800; }
.explain {
  margin-top: 16px; padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--card-2); border-left: 4px solid var(--brand); font-size: 14px;
  animation: fade .25s;
}
.explain b { color: var(--brand); }
.quiz-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 20px; gap: 10px; }
.btn {
  border: 0; background: var(--brand); color: #fff; padding: 12px 22px;
  border-radius: 999px; font-weight: 800; font-size: 15px; transition: .16s;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }

.result-big { text-align: center; padding: 20px 0; }
.result-score { font-size: 56px; font-weight: 800; color: var(--brand); }
.result-msg { font-size: 18px; font-weight: 700; margin: 6px 0 4px; }
.review-item { border-top: 1px solid var(--line); padding: 14px 0; }
.review-item .ri-q { font-weight: 700; }
.badge { display: inline-block; font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 999px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.no { background: var(--danger-soft); color: var(--danger); }

/* ---------- Bottom nav (mobile) ---------- */
.bottombar { display: none; }

@media (max-width: 720px) {
  .tabs { display: none; }
  .brand-sub { display: none; }
  .bottombar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: color-mix(in srgb, var(--bg-soft) 94%, transparent);
    backdrop-filter: blur(12px); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bt {
    flex: 1; border: 0; background: transparent; color: var(--text-soft);
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; font-weight: 800; padding: 6px 2px; border-radius: 12px;
  }
  .bt span { font-size: 20px; }
  .bt.is-active { color: var(--brand); }
}
