:root {
  --primary: #5b4bdb; --primary-dark: #4335b8; --primary-soft: #eeebff;
  --accent: #ff7a59; --bg: #f6f5ff; --card: #ffffff; --text: #1f2133; --muted: #6b6f85;
  --ok: #2b8a3e; --ok-soft: #e6f7ea; --bad: #d6336c; --bad-soft: #fff0f4; --mid: #f59f00;
  --radius: 18px; --shadow: 0 6px 20px rgba(60, 50, 140, .10);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px; line-height: 1.55;
}
a { color: var(--primary); }
.container { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); font-size: .9rem; }

/* barra superior */
.topbar {
  position: relative; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: linear-gradient(90deg, var(--primary), #8b5cf6); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 800; font-size: 1.25rem; }
.logo { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: #fff; color: var(--primary); font-size: 1.3rem; }
.tagline { font-size: .85rem; opacity: .9; text-align: right; }

/* inicio */
.hero { margin: 24px 0 16px; }
.hero h1 { margin: 0 0 6px; font-size: clamp(1.45rem, 4.5vw, 2rem); line-height: 1.2; }
.hero p { margin: 0; color: var(--muted); }
.grade-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #fff; padding: 6px; border-radius: 999px; box-shadow: var(--shadow); max-width: 480px; }
.grade-switch button {
  border: 0; background: transparent; padding: 10px 12px; border-radius: 999px; font: inherit; font-weight: 700; color: var(--muted); cursor: pointer;
}
.grade-switch button.active { background: var(--primary); color: #fff; box-shadow: 0 3px 10px rgba(91,75,219,.35); }
.grade-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.grade-summary > div { background: #fff; border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.big-num { font-size: 1.4rem; font-weight: 800; color: var(--primary); }
.grade-summary span:last-child { font-size: .8rem; color: var(--muted); }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; margin-bottom: 30px; }
.topic-card {
  display: flex; gap: 14px; padding: 16px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  text-decoration: none; color: inherit; border: 2px solid transparent; transition: transform .15s, border-color .15s;
}
.topic-card:hover, .topic-card:focus-visible { transform: translateY(-2px); border-color: var(--primary); outline: none; }
.tc-icon { flex: 0 0 52px; height: 52px; display: grid; place-items: center; font-size: 1.6rem; background: var(--primary-soft); border-radius: 14px; }
.tc-body { flex: 1; min-width: 0; }
.tc-eje { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); font-weight: 800; }
.tc-body h3 { margin: 2px 0 4px; font-size: 1.05rem; line-height: 1.25; }
.tc-body p { margin: 0 0 10px; font-size: .88rem; color: var(--muted); }
.bar { height: 8px; background: #ecebf5; border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 99px; background: var(--primary); }
.bar.good span { background: var(--ok); } .bar.mid span { background: var(--mid); } .bar.low span { background: var(--bad); }
.tc-stats { margin-top: 6px; font-size: .82rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge { background: #fff3bf; color: #8a6100; border-radius: 99px; padding: 1px 8px; font-weight: 700; font-size: .75rem; }

/* tema */
.crumbs { margin: 18px 0 6px; }
.crumbs a { text-decoration: none; font-weight: 700; }
.topic-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.th-icon { font-size: 2rem; width: 58px; height: 58px; display: grid; place-items: center; background: #fff; border-radius: 16px; box-shadow: var(--shadow); flex: 0 0 58px; }
.topic-head h2 { margin: 0; font-size: clamp(1.3rem, 4vw, 1.75rem); line-height: 1.2; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab { flex: 1; text-align: center; padding: 10px; border-radius: 12px; background: #fff; text-decoration: none; font-weight: 700; color: var(--muted); box-shadow: var(--shadow); }
.tab.active { background: var(--primary); color: #fff; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.theory h3 { color: var(--primary-dark); margin: 18px 0 6px; font-size: 1.1rem; }
.theory ul, .theory ol { padding-left: 22px; }
.theory li { margin: 4px 0; }
.theory .big { text-align: center; font-size: 1.3rem; }
.example { background: #fff9e6; border-left: 5px solid #fcc419; border-radius: 10px; padding: 10px 14px; margin: 12px 0; }
.actions { display: flex; gap: 10px; margin-top: 14px; }
.actions.wrap { flex-wrap: wrap; justify-content: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 20px; min-height: 48px; border-radius: 14px; border: 2px solid var(--primary);
  background: #fff; color: var(--primary); font: inherit; font-weight: 800; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(91,75,219,.3); }
.btn.primary:hover { background: var(--primary-dark); }
.btn:focus-visible, .option:focus-visible, input:focus-visible { outline: 3px solid #ffd43b; outline-offset: 2px; }

/* práctica */
.practice-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.counter { font-weight: 600; }
.dots { display: flex; gap: 6px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: #dcdaf0; }
.dot.cur { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }
.q { font-size: 1.08rem; overflow-x: auto; }
.q .katex-display { margin: .7em 0; }
.fig { display: block; width: 100%; max-width: 300px; margin: 10px auto; font-family: system-ui, sans-serif; font-size: 15px; font-weight: 700; fill: #1f2133; }
.fig .svg-ang { fill: #e8590c; }
.tbl { border-collapse: collapse; margin: 10px 0; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { border: 1px solid #d0cfe6; padding: 6px 12px; text-align: center; }
.tbl th { background: var(--primary-soft); }
.sys { display: inline-block; border-left: 3px solid var(--primary); padding: 4px 0 4px 12px; margin: 10px 0 4px 6px; line-height: 2; }
.options { display: grid; gap: 10px; margin-top: 14px; }
.option {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; min-height: 52px; border-radius: 14px;
  border: 2px solid #dcdaf0; background: #fff; font: inherit; color: inherit; cursor: pointer; transition: border-color .12s, background .12s;
}
.option:hover:not(:disabled) { border-color: var(--primary); }
.option.selected { border-color: var(--primary); background: var(--primary-soft); }
.option.correct { border-color: var(--ok); background: var(--ok-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option:disabled { cursor: default; color: inherit; }
.opt-letter { flex: 0 0 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-weight: 800; }
.option.correct .opt-letter { background: var(--ok); color: #fff; }
.option.wrong .opt-letter { background: var(--bad); color: #fff; }
.fields { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.field { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.field input {
  width: 160px; max-width: 60vw; padding: 12px 14px; font: inherit; font-size: 1.15rem; border-radius: 12px; border: 2px solid #c9c6e8; background: #fff;
}
.field input:focus { border-color: var(--primary); outline: none; }
.field input.invalid { border-color: var(--mid); }
.field input.correct { border-color: var(--ok); background: var(--ok-soft); }
.field input.wrong { border-color: var(--bad); background: var(--bad-soft); }
.note { font-size: .85rem; color: var(--muted); margin: 8px 0 0; }
.warn { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: #fff4e6; color: #a35200; font-weight: 600; }
.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 14px; animation: pop .25s ease-out; }
.feedback.ok { background: var(--ok-soft); border: 2px solid #8ce99a; }
.feedback.bad { background: var(--bad-soft); border: 2px solid #faa2c1; }
.fb-title { font-weight: 800; font-size: 1.1rem; }
.feedback.ok .fb-title { color: var(--ok); } .feedback.bad .fb-title { color: var(--bad); }
.fb-answer { margin-top: 6px; }
.feedback details { margin-top: 10px; background: rgba(255,255,255,.7); border-radius: 10px; padding: 8px 12px; }
.feedback summary { cursor: pointer; font-weight: 700; color: var(--primary-dark); }
.steps { margin: 8px 0 0; padding-left: 22px; }
.steps li { margin: 6px 0; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.summary { text-align: center; }
.score-ring { width: 110px; height: 110px; border-radius: 50%; margin: 6px auto 10px; display: grid; place-items: center; font-size: 1.6rem; font-weight: 800; border: 10px solid var(--primary); }
.score-ring.good { border-color: var(--ok); color: var(--ok); } .score-ring.mid { border-color: var(--mid); color: #b26b00; } .score-ring.low { border-color: var(--bad); color: var(--bad); }
.math-fallback { font-family: "Cambria Math", "STIX Two Math", Georgia, serif; white-space: nowrap; }
.math-fallback.display { display: block; text-align: center; margin: 10px 0; font-size: 1.15em; white-space: normal; }
.katex { font-size: 1.08em; }

.footer { padding: 18px 16px 40px; text-align: center; }
.link-btn { background: none; border: 0; color: var(--bad); text-decoration: underline; cursor: pointer; font: inherit; font-size: .85rem; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .tagline { display: none; }
  .card { padding: 14px; }
  .grade-summary { gap: 6px; }
  .big-num { font-size: 1.15rem; }
  .actions .btn { flex: 1; }
}
