/* ============ Tokens ============ */
:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f3f0e9;
  --text: #1f2328;
  --muted: #5b6370;
  --border: #e3ded3;
  --accent: #0f766e;
  --accent-strong: #0b5c56;
  --accent-soft: #dcf1ed;
  --think: #6d3fd6;
  --think-soft: #f0e9fd;
  --trap: #b42318;
  --trap-soft: #fdecea;
  --key: #9a5800;
  --key-soft: #fdf1da;
  --ok: #15803d;
  --ok-soft: #e2f5e7;
  --bad: #c0262d;
  --bad-soft: #fde8e8;
  --mat: #d6456b;
  --pat: #2f6fd6;
  --neutral-chr: #8a8f98;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131519;
    --surface: #1b1e23;
    --surface-2: #23272e;
    --text: #e9e7e2;
    --muted: #a2a9b4;
    --border: #323740;
    --accent: #2ec4b0;
    --accent-strong: #5fd9c8;
    --accent-soft: #12332f;
    --think: #b69cff;
    --think-soft: #2a2240;
    --trap: #ff8f86;
    --trap-soft: #3a1e1c;
    --key: #f2b45a;
    --key-soft: #382b15;
    --ok: #5fd68a;
    --ok-soft: #153020;
    --bad: #ff8a8a;
    --bad-soft: #3a1c1c;
    --mat: #ff7aa0;
    --pat: #72a9ff;
    --neutral-chr: #8d939c;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131519;
  --surface: #1b1e23;
  --surface-2: #23272e;
  --text: #e9e7e2;
  --muted: #a2a9b4;
  --border: #323740;
  --accent: #2ec4b0;
  --accent-strong: #5fd9c8;
  --accent-soft: #12332f;
  --think: #b69cff;
  --think-soft: #2a2240;
  --trap: #ff8f86;
  --trap-soft: #3a1e1c;
  --key: #f2b45a;
  --key-soft: #382b15;
  --ok: #5fd68a;
  --ok-soft: #153020;
  --bad: #ff8a8a;
  --bad-soft: #3a1c1c;
  --mat: #ff7aa0;
  --pat: #72a9ff;
  --neutral-chr: #8d939c;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.65;
}
h1, h2, h3, h4 {
  font-family: "Fraunces", Georgia, serif;
  line-height: 1.25;
  font-weight: 650;
  margin: 1.6em 0 .5em;
}
h1 { font-size: clamp(1.8rem, 5vw, 2.5rem); margin-top: .3em; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
p { margin: .7em 0; }
a { color: var(--accent); }
strong { font-weight: 650; }
sup { font-size: .7em; line-height: 0; }
code, .g {
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: .92em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 .3em;
  white-space: nowrap;
}
ul, ol { padding-left: 1.3em; }
li { margin: .3em 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ============ Layout ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 920px; margin: 0 auto;
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem 16px;
}
.brand { font-family: "Fraunces", Georgia, serif; font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--text); }
.brand span { color: var(--accent); }
.spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: .3rem .7rem; cursor: pointer; font-size: .9rem;
}
.chips {
  max-width: 920px; margin: 0 auto;
  display: flex; gap: .4rem; overflow-x: auto; padding: 0 16px .6rem;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips a {
  flex: none; text-decoration: none; color: var(--muted);
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: .25rem .75rem; font-size: .85rem; white-space: nowrap;
}
.chips a[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .chips a[aria-current="page"] { color: #0c1a18; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chips a[aria-current="page"] { color: #0c1a18; } }
.chips a.done::after { content: " ✓"; }

main { max-width: 760px; margin: 0 auto; padding: 1rem 16px 5rem; }
.page { outline: none; }
.page[hidden] { display: none; }

.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; color: var(--accent); font-weight: 700; margin: 1.2rem 0 0; }
.lead { font-size: 1.12rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

/* ============ Callouts ============ */
.box {
  border-radius: var(--radius); padding: .9rem 1.1rem; margin: 1.2rem 0;
  border: 1px solid var(--border); background: var(--surface);
}
.box > :first-child { margin-top: 0; }
.box > :last-child { margin-bottom: 0; }
.box-title { font-weight: 700; display: block; margin-bottom: .3rem; }
.think { background: var(--think-soft); border-color: color-mix(in srgb, var(--think) 30%, transparent); }
.think .box-title { color: var(--think); }
.trap { background: var(--trap-soft); border-color: color-mix(in srgb, var(--trap) 30%, transparent); }
.trap .box-title { color: var(--trap); }
.key { background: var(--key-soft); border-color: color-mix(in srgb, var(--key) 30%, transparent); }
.key .box-title { color: var(--key); }
.goal { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.goal .box-title { color: var(--accent-strong); }

details.check {
  border: 1px dashed var(--accent); border-radius: var(--radius);
  padding: .7rem 1rem; margin: 1.2rem 0; background: var(--surface);
}
details.check summary { cursor: pointer; font-weight: 650; color: var(--accent-strong); }
details.check ol { margin-bottom: 0; }
details.check .ans { color: var(--muted); font-size: .95rem; display: block; margin-top: .2rem; }
details.check[open] summary { margin-bottom: .5rem; }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; margin: 1rem 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.t { border-collapse: collapse; width: 100%; font-size: .93rem; }
table.t th, table.t td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.t thead th { background: var(--surface-2); font-weight: 650; }
table.t tr:last-child td { border-bottom: 0; }

/* Punnett */
.punnett-wrap { display: flex; justify-content: center; margin: 1rem 0; }
table.punnett { border-collapse: separate; border-spacing: 4px; }
table.punnett th, table.punnett td {
  min-width: 64px; height: 52px; text-align: center; border-radius: 10px; padding: .25rem .4rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
table.punnett th { background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: .95rem; }
table.punnett th.corner { background: transparent; font-family: inherit; font-size: .7rem; font-weight: 500; }
table.punnett td { background: var(--accent-soft); font-weight: 700; font-size: 1.02rem; }
table.punnett td small { display: block; font-family: "Inter", sans-serif; font-weight: 500; font-size: .7rem; color: var(--muted); line-height: 1.2; }

/* ============ Figures ============ */
figure { margin: 1.4rem 0; }
figure svg { width: 100%; height: auto; display: block; }
figcaption { font-size: .85rem; color: var(--muted); text-align: center; margin-top: .4rem; }
.fig-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
svg text { fill: var(--text); font-family: "Inter", sans-serif; }
svg .lbl { font-size: 13px; }
svg .lbl-s { font-size: 11px; fill: var(--muted); }
svg .lbl-b { font-size: 14px; font-weight: 700; }
svg .line { stroke: var(--muted); stroke-width: 1.2; fill: none; }
svg .mat { fill: var(--mat); }
svg .pat { fill: var(--pat); }
svg .neu { fill: var(--neutral-chr); }
svg .cell { fill: var(--surface-2); stroke: var(--border); stroke-width: 2; }
svg .band { fill: var(--key); }
svg .tel { fill: var(--text); opacity: .55; }
svg .arrow { stroke: var(--accent); stroke-width: 2; fill: none; marker-end: url(#arrowhead); }
svg .on-chr { fill: #fff; font-weight: 700; font-size: 12px; }

/* ============ Cards / buttons ============ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 1rem 0; box-shadow: var(--shadow); }
.btn {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: 10px; padding: .55rem 1rem; font-weight: 600; font-size: .95rem;
  text-decoration: none;
}
:root[data-theme="dark"] .btn:not(.ghost) { color: #0c1a18; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn:not(.ghost) { color: #0c1a18; } }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--accent-strong); }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0 .3rem; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .1rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); margin-right: .3rem; }
.badge.lv-Básico { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.lv-Intermedio { background: var(--key-soft); color: var(--key); border-color: transparent; }
.badge.lv-Desafío { background: var(--trap-soft); color: var(--trap); border-color: transparent; }

.pager { display: flex; justify-content: space-between; gap: .5rem; margin-top: 2.5rem; flex-wrap: wrap; }
.pager a { text-decoration: none; }
.done-btn { margin-top: 2rem; }

/* Timeline */
.plan { list-style: none; padding: 0; margin: 1rem 0; counter-reset: s; }
.plan li { position: relative; padding: .2rem 0 .9rem 2.6rem; margin: 0; border-left: 2px solid var(--border); margin-left: .9rem; }
.plan li:last-child { border-left-color: transparent; }
.plan li::before {
  counter-increment: s; content: counter(s);
  position: absolute; left: -0.95rem; top: .1rem;
  width: 1.8rem; height: 1.8rem; border-radius: 50%;
  background: var(--accent); color: var(--surface); font-weight: 700; font-size: .85rem;
  display: grid; place-items: center;
}
.plan b { display: block; }
.plan .time { font-size: .8rem; color: var(--muted); }

/* Semáforo */
.sem-row { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sem-row:last-child { border-bottom: 0; }
.sem-name { flex: 1 1 200px; font-size: .95rem; }
.sem-btns { display: flex; gap: .3rem; }
.sem-btns button {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px;
  padding: .2rem .55rem; cursor: pointer; font-size: .85rem;
}
.sem-btns button[aria-pressed="true"].r { background: var(--bad-soft); border-color: var(--bad); }
.sem-btns button[aria-pressed="true"].y { background: var(--key-soft); border-color: var(--key); }
.sem-btns button[aria-pressed="true"].v { background: var(--ok-soft); border-color: var(--ok); }
.sem-before { font-size: .78rem; color: var(--muted); width: 100%; }

/* Problems */
.prob-index { display: grid; gap: .4rem; margin: 1rem 0; }
.prob-index a { text-decoration: none; display: flex; gap: .5rem; align-items: baseline; padding: .4rem .6rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: .93rem; }
.prob-index a .n { color: var(--accent); font-weight: 700; min-width: 1.6rem; }
.step { border-left: 3px solid var(--accent); padding: .4rem 0 .4rem 1rem; margin: 1rem 0; animation: fadein .3s ease; }
.step h4 { margin: 0 0 .4rem; font-family: "Inter", sans-serif; font-size: 1rem; }
.step .row { margin: .35rem 0; }
.step .row b { display: inline; }
.step .tag { font-weight: 700; }
.step .tag.p { color: var(--think); }
.step .tag.w { color: var(--key); }
.step .tag.c { color: var(--accent-strong); }
.final { background: var(--ok-soft); border-radius: 12px; padding: .8rem 1rem; margin-top: 1rem; animation: fadein .3s ease; }
.final b:first-child { color: var(--ok); }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Quiz */
.tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin: 1rem 0; }
.tabs button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: .3rem .85rem; cursor: pointer; font-size: .88rem; }
.tabs button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.q-meta { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .4rem; font-size: .82rem; color: var(--muted); }
.q-text { font-size: 1.05rem; margin: .6rem 0 1rem; }
.opts { display: grid; gap: .5rem; }
.opt {
  text-align: left; cursor: pointer; border: 1.5px solid var(--border); background: var(--surface);
  border-radius: 12px; padding: .65rem .85rem; display: flex; gap: .65rem; align-items: flex-start; line-height: 1.45;
}
.opt .l { font-weight: 700; color: var(--muted); min-width: 1.1rem; }
.opt[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt:disabled { cursor: default; color: var(--text); }
.conf { margin: 1rem 0 .2rem; }
.conf-label { font-size: .88rem; color: var(--muted); display: block; margin-bottom: .35rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: var(--surface); padding: .4rem .8rem; cursor: pointer; font-size: .88rem; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--think-soft); color: var(--think); font-weight: 700; }
.feedback { margin-top: 1rem; border-radius: 12px; padding: .8rem 1rem; animation: fadein .3s ease; }
.feedback.ok { background: var(--ok-soft); }
.feedback.bad { background: var(--bad-soft); }
.feedback .meta { margin-top: .6rem; padding-top: .6rem; border-top: 1px solid color-mix(in srgb, var(--text) 12%, transparent); font-size: .92rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin: 1rem 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .6rem .8rem; }
.stat .v { font-size: 1.5rem; font-weight: 700; font-family: "Fraunces", serif; }
.stat .k { font-size: .78rem; color: var(--muted); }

/* Punnett trainer */
.trainer-grid { border-collapse: separate; border-spacing: 5px; margin: 0 auto; }
.trainer-grid input {
  width: 64px; height: 48px; text-align: center; font-size: 1.1rem; font-weight: 700;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  border: 1.5px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
.trainer-grid input.gam { background: var(--surface-2); }
.trainer-grid input.ok { border-color: var(--ok); background: var(--ok-soft); }
.trainer-grid input.bad { border-color: var(--bad); background: var(--bad-soft); }
.trainer-grid th { font-size: .7rem; color: var(--muted); font-weight: 500; }
.parents { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin: 1rem 0; }
.parent { background: var(--surface-2); border-radius: 12px; padding: .6rem .8rem; font-size: .92rem; }
.parent b { font-family: "JetBrains Mono", monospace; font-size: 1.1rem; }

/* Simulacro */
.timer {
  position: sticky; top: 92px; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .5rem .9rem; box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.timer .clock { font-weight: 700; font-size: 1.15rem; }
.timer.low .clock { color: var(--bad); }
.dots { display: flex; gap: .35rem; flex-wrap: wrap; }
.dots button { width: 2rem; height: 2rem; border-radius: 50%; border: 1.5px solid var(--border); background: var(--surface); cursor: pointer; font-size: .8rem; font-weight: 700; }
.dots button.ans { background: var(--accent-soft); border-color: var(--accent); }
.dots button.cur { outline: 2px solid var(--text); outline-offset: 1px; }
.review-item { border-top: 1px solid var(--border); padding: 1rem 0; }

.two-col { display: grid; gap: 1rem; }
@media (min-width: 640px) { .two-col { grid-template-columns: 1fr 1fr; } }
.cycle-legend dt { font-weight: 700; margin-top: .5rem; }
.cycle-legend dd { margin: 0 0 0 0; color: var(--muted); font-size: .93rem; }

footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 16px 3rem; }

@media (max-width: 480px) {
  body { font-size: 16px; }
  table.punnett th, table.punnett td { min-width: 56px; height: 48px; }
  .trainer-grid input { width: 54px; height: 44px; }
  .timer { top: 88px; }
}
@media print {
  .topbar, .pager, .done-btn, .btn-row { display: none !important; }
  .page[hidden] { display: block !important; }
}
