:root {
  --primary: #1f4e79;
  --primary-ink: #ffffff;
  --primary-soft: #dce6f1;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --ink: #1d2733;
  --muted: #5b6573;
  --border: #bfc9d6;
  --line: #e3e8ef;
  --zebra: #f3f6fa;
  --caution-fill: #fff4e5;
  --caution: #b36b00;
  --caution-bar: #e8a33d;
  --note-fill: #eef1f4;
  --ok: #2e7d4f;
  --ok-soft: #e3f3ea;
  --danger: #b3261e;
  --mark: #fff0b3;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 35, 60, .06), 0 2px 8px rgba(20, 35, 60, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #7fb2e5; --primary-ink: #0d1b2a; --primary-soft: #1d3247;
    --bg: #11161d; --surface: #182029; --ink: #e4e9f0; --muted: #9aa6b5; --border: #34414f; --line: #26313d;
    --zebra: #1c252f; --caution-fill: #33270f; --caution: #f0b35a; --caution-bar: #c98a2b; --note-fill: #1f2731;
    --ok: #6fcf97; --ok-soft: #173325; --danger: #f28b82; --mark: #5a4a12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
code { font: .88em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--zebra); padding: .1em .35em; border-radius: 4px; }
h1, h2, h3 { line-height: 1.25; color: var(--primary); }
h1 { font-size: 1.75rem; margin: .2em 0 .3em; }
h2 { font-size: 1.3rem; margin: 1.8em 0 .6em; padding-bottom: .3em; border-bottom: 2px solid var(--primary); }
h3 { font-size: 1.08rem; margin: 1.4em 0 .5em; }
mark { background: var(--mark); color: inherit; padding: 0 .1em; border-radius: 2px; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--primary); color: var(--primary-ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .topbar { background: #0e2236; color: #e4e9f0; } }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; margin-right: auto; }
.brand svg { width: 22px; height: 22px; }
.topbar select, .topbar input {
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .28); color: inherit;
  border-radius: 6px; padding: 6px 10px; min-height: 36px;
}
.topbar select option { color: #1d2733; }
.topbar input::placeholder { color: rgba(255, 255, 255, .7); }
.topbar form { display: flex; flex: 1 1 220px; max-width: 360px; }
.topbar form input { width: 100%; }
.topnav { display: flex; gap: 4px; }
.topnav a, .topnav button {
  color: inherit; text-decoration: none; background: none; border: 0; cursor: pointer;
  padding: 6px 10px; border-radius: 6px; min-height: 36px; display: inline-flex; align-items: center;
}
.topnav a:hover, .topnav button:hover, .topnav a.active { background: rgba(255, 255, 255, .16); }

/* ---------- layout ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 24px 16px 64px; }
main.narrow { max-width: 460px; padding-top: 8vh; }
.crumbs { font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.subtitle { color: var(--muted); font-size: 1.05rem; margin: 0 0 1.2em; }
.meta { color: var(--muted); font-size: .93rem; margin: 0 0 1em; }
.meta b { font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.prose p { margin: 0 0 .9em; max-width: 80ch; }
.prose ul { padding-left: 1.3em; max-width: 90ch; }
.prose li { margin-bottom: .4em; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px;
  border-radius: 6px; border: 1px solid var(--primary); background: var(--primary); color: var(--primary-ink);
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.secondary { background: transparent; color: var(--primary); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .88rem; font-weight: 500; }
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
label.field { display: block; margin-bottom: 14px; font-weight: 600; font-size: .93rem; }
label.field input, label.field select {
  display: block; width: 100%; margin-top: 4px; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); font-weight: 400; min-height: 42px;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 14px; align-items: end; }
.msg { padding: 10px 14px; border-radius: 6px; margin: 0 0 14px; font-size: .93rem; }
.msg.error { background: #fdecea; color: var(--danger); }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .msg.error { background: #3a1c1a; } }
.copy { display: flex; gap: 8px; margin-top: 8px; }
.copy input { flex: 1; min-width: 0; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); font: .85rem ui-monospace, Menlo, monospace; }

/* checkbox */
.check { appearance: none; -webkit-appearance: none; width: 22px; height: 22px; margin: 0; border: 2px solid var(--border); border-radius: 5px; cursor: pointer; background: var(--surface); display: inline-grid; place-content: center; flex: none; }
.check::after { content: ""; width: 11px; height: 6px; border: solid var(--primary-ink); border-width: 0 0 2.5px 2.5px; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
.check:checked { background: var(--ok); border-color: var(--ok); }
.check:checked::after { opacity: 1; border-color: #fff; }
.check:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.check.partial { border-color: var(--ok); background: linear-gradient(var(--ok-soft), var(--ok-soft)); }

/* progress */
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .25s; }
.row > .bar { flex: 1; min-width: 80px; }
.pct { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- tables (index, glossary, steps) ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .95rem; }
.table th { background: var(--primary); color: var(--primary-ink); text-align: left; font-weight: 600; padding: 9px 12px; }
.table td { border: 1px solid var(--border); padding: 10px 12px; vertical-align: top; }
.table tr:nth-child(even) td { background: var(--zebra); }
.table tr.section td { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.table td.c { text-align: center; width: 52px; }
.table-wrap { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }

.steps td.menu { width: 24%; }
.steps td.pasos { width: 36%; }
.steps ol { margin: 0; padding-left: 1.3em; }
.steps ol li { margin-bottom: 4px; }
.steps tr.done td { background: var(--ok-soft) !important; }
.steps tr:target td { box-shadow: inset 0 0 0 9999px rgba(255, 220, 0, .12); }

@media (max-width: 760px) {
  .steps thead { display: none; }
  .steps, .steps tbody, .steps tr, .steps td { display: block; width: 100% !important; }
  .steps tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; background: var(--surface); }
  .steps td { border: 0; border-top: 1px solid var(--line); }
  .steps td:first-child { border-top: 0; display: flex; align-items: center; gap: 10px; text-align: left; }
  .steps td:first-child::after { content: "Paso " attr(data-n); font-weight: 600; color: var(--muted); }
  .steps td[data-label]::before { content: attr(data-label); display: block; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; }
  .table-wrap.steps-wrap { box-shadow: none; overflow: visible; }
  .index .hide-sm { display: none; }
  .topbar { position: static; }
}

/* callouts */
.callout { border-left: 5px solid var(--muted); background: var(--note-fill); padding: 12px 16px; border-radius: 0 var(--radius) var(--radius) 0; margin: 18px 0; }
.callout > strong:first-child { display: block; margin-bottom: 4px; }
.callout ul { margin: 0; padding-left: 1.2em; }
.callout.caution { border-color: var(--caution-bar); background: var(--caution-fill); }
.callout.caution > strong:first-child { color: var(--caution); }
.callout.goal { border-color: var(--primary); background: var(--primary-soft); }
.callout.goal > strong:first-child { color: var(--primary); }
.callout.conclusion { border-color: var(--ok); background: var(--ok-soft); }
.callout.conclusion > strong:first-child { color: var(--ok); }
.checklist { list-style: none; padding-left: 0; }
.checklist li::before { content: "☐"; margin-right: 8px; color: var(--muted); }

/* series cards */
.serie-card { display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: inherit; }
.serie-card:hover { border-color: var(--primary); }
.serie-card h3 { margin: 0; }
.serie-card p { margin: 0; font-size: .92rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.guide-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.guide-head > div:first-child { flex: 1 1 420px; }
.guide-progress { min-width: 220px; flex: 0 1 280px; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.pager a { max-width: 48%; }

.result { padding: 14px 0; border-bottom: 1px solid var(--line); }
.result a { font-weight: 600; text-decoration: none; }
.result p { margin: 4px 0 0; color: var(--muted); font-size: .93rem; }
.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); margin-right: 6px; vertical-align: 1px; }
.tag.off { background: var(--line); color: var(--muted); }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: min(760px, calc(100vw - 32px)); width: 100%; background: var(--surface); color: var(--ink); box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(10, 20, 30, .45); }
dialog .dlg { padding: 20px; max-height: 80vh; overflow: auto; }
.users td, .users th { white-space: nowrap; }
.users td.wrap { white-space: normal; }
.scroll-x { overflow-x: auto; }

/* rendered Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7em; }
.prose.md table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .93rem; margin: 12px 0; box-shadow: var(--shadow); }
.prose.md th { background: var(--primary); color: var(--primary-ink); text-align: left; padding: 9px 12px; }
.prose.md td { border: 1px solid var(--border); padding: 9px 12px; vertical-align: top; }
.prose.md tr:nth-child(even) td { background: var(--zebra); }
@media (max-width: 760px) { .prose.md table { display: block; overflow-x: auto; } }
