/* ===== Variables y tema ===== */
:root {
  --bg: #f4f6f9; --surface: #fff; --text: #18212c; --muted: #5b6776; --line: #e1e6ed;
  --brand: #0f1b2d; --brand-2: #1c3557; --accent: #f5c518; --accent-ink: #231b00;
  --link: #0b5cad; --ok: #177a42; --ok-bg: #e6f5ec; --bad: #b3261e; --bad-bg: #fdecea;
  --warn-bg: #fff6d6; --code-bg: #eef1f5;
  --shadow: 0 1px 2px rgba(15,27,45,.06), 0 10px 28px rgba(15,27,45,.07);
  --r: 14px; --top: 56px; --side: 300px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1118; --surface: #141b25; --text: #e6ebf2; --muted: #9aa7b8; --line: #243041;
    --link: #7db7ff; --ok: #4cc38a; --ok-bg: #11291d; --bad: #ff8a7a; --bad-bg: #331815;
    --warn-bg: #2f2708; --code-bg: #1b2431; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1118; --surface: #141b25; --text: #e6ebf2; --muted: #9aa7b8; --line: #243041;
  --link: #7db7ff; --ok: #4cc38a; --ok-bg: #11291d; --bad: #ff8a7a; --bad-bg: #331815;
  --warn-bg: #2f2708; --code-bg: #1b2431; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.35);
  color-scheme: dark;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--top) + 12px + env(safe-area-inset-top)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 1.0625rem/1.7 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
img, svg, iframe { max-width: 100%; }
a { color: var(--link); }
h1, h2, h3, h4 { line-height: 1.25; }
.muted { color: var(--muted); }
.grow { flex: 1; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: .5rem; top: .5rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.ico { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; flex: none; }

/* ===== Cabecera ===== */
.top {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: .5rem;
  height: calc(var(--top) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(.75rem, env(safe-area-inset-right)) 0 max(.75rem, env(safe-area-inset-left));
  background: var(--brand); color: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; min-width: 0; }
.brand-logo { border-radius: 8px; background: #fff; object-fit: contain; }
.brand-t { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-t b { font-size: 1.05rem; }
.brand-t small { font-size: .72rem; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib { display: inline-grid; place-items: center; width: 2.6rem; height: 2.6rem; border: 0; border-radius: 10px; background: transparent; color: inherit; font-size: 1.15rem; cursor: pointer; }
.ib:hover { background: rgba(255,255,255,.12); }
.btn-pill { display: inline-flex; align-items: center; gap: .4rem; border: 0; border-radius: 999px; padding: .4rem .9rem; background: var(--accent); color: var(--accent-ink); font: 600 .9rem system-ui; cursor: pointer; }
.btn-pill[hidden] { display: none; }
#prog { position: fixed; z-index: 60; left: 0; top: 0; height: 3px; width: 100%; background: var(--accent); transform: scaleX(0); transform-origin: 0 50%; }

/* ===== Estructura ===== */
.shell { display: grid; grid-template-columns: minmax(0, 1fr); min-height: calc(100dvh - var(--top)); }
.col { min-width: 0; display: flex; flex-direction: column; }
main { flex: 1; container-type: inline-size; padding: 1.25rem max(1rem, env(safe-area-inset-right)) 2rem max(1rem, env(safe-area-inset-left)); width: 100%; max-width: 1180px; margin: 0 auto; outline: none; }
.loading { text-align: center; color: var(--muted); padding: 4rem 0; }

/* ===== Índice lateral ===== */
.side {
  position: fixed; z-index: 50; inset: 0 auto 0 0; width: min(88vw, 340px); background: var(--surface);
  border-right: 1px solid var(--line); overflow: auto; transform: translateX(-102%); transition: transform .25s ease;
  padding: calc(var(--top) + env(safe-area-inset-top) + .5rem) .75rem 2rem;
}
body.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
#scrim { position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .2s; }
body.nav-open #scrim { opacity: 1; pointer-events: auto; }
.side a { display: flex; align-items: center; gap: .5rem; padding: .42rem .6rem; border-radius: 8px; color: var(--text); text-decoration: none; font-size: .95rem; line-height: 1.35; }
.side a:hover { background: var(--bg); }
.side a.cur { background: color-mix(in srgb, var(--accent) 28%, transparent); font-weight: 600; }
.side a .tick { margin-left: auto; width: .95rem; height: .95rem; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.side a.done .tick { border-color: var(--ok); background: var(--ok); }
.side a .score { margin-left: auto; font-size: .75rem; font-weight: 700; color: var(--ok); }
.side details { margin: .2rem 0; border-radius: 10px; }
.side summary { cursor: pointer; padding: .55rem .6rem; font-weight: 700; font-size: .95rem; display: flex; gap: .55rem; align-items: baseline; list-style: none; border-radius: 8px; }
.side summary::-webkit-details-marker { display: none; }
.side summary:hover { background: var(--bg); }
.side summary .un { flex: none; display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--brand); color: #fff; font-size: .8rem; }
.side ol { list-style: none; margin: 0 0 .4rem 1rem; padding: 0 0 0 .5rem; border-left: 2px solid var(--line); }
.side .top-link { font-weight: 700; }
@media (min-width: 1000px) {
  .shell { grid-template-columns: var(--side) minmax(0, 1fr); }
  .side { position: sticky; top: var(--top); inset: auto; width: auto; height: calc(100dvh - var(--top)); transform: none; padding-top: 1rem; box-shadow: none !important; z-index: 1; }
  #scrim, .menu-btn { display: none; }
}

/* ===== Texto de las lecciones ===== */
.eyebrow { margin: .2rem 0 0; font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.eyebrow a { color: inherit; text-decoration: none; }
.lesson h1 { margin: .2rem 0 1rem; font-size: clamp(1.6rem, 4.5vw, 2.3rem); }
/* La tarjeta ocupa todo el ancho disponible; solo el texto corrido se limita a una longitud de línea legible.
   Figuras, tablas, vídeos y la línea de tiempo aprovechan el ancho completo. */
.prose { max-width: none; }
.prose > :is(p, ul:not(.timeline), ol:not(.chapters), h2.sec, h3, h4, blockquote, .aviso, details.fuentes) { max-width: 84ch; margin-inline: auto; }
.prose > .btn { display: flex; width: fit-content; margin-inline: auto; }
@media (min-width: 1500px) { main { max-width: 1320px; } body { font-size: 1.15rem; } .prose > :is(p, ul:not(.timeline), ol:not(.chapters), h2.sec, h3, h4, blockquote, .aviso, details.fuentes) { max-width: 90ch; } }
.lesson .prose, .quiz, .card-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: clamp(1rem, 3.5vw, 2.2rem); }
.prose p, .prose ul, .prose ol { margin: .9em 0; }
.prose li { margin: .3em 0; }
.prose h2.sec { font-size: clamp(1.25rem, 3.2vw, 1.6rem); margin: 2.2em 0 .6em; padding-bottom: .3em; border-bottom: 3px solid var(--accent); }
.prose h2.sec:first-child { margin-top: .2em; }
.prose > h2.sec { margin-inline: auto; }
.prose h3, .prose h4 { margin: 1.6em 0 .4em; }
.prose figure { margin: 1.8em auto; text-align: center; }
.prose figure img { max-width: 100%; height: auto; border-radius: 10px; background: #fff; cursor: zoom-in; }
.prose figcaption { margin-top: .6rem; font-size: .92rem; }
.prose figcaption strong { display: block; }
.prose figcaption small { display: block; color: var(--muted); margin-top: .2rem; line-height: 1.4; }
.prose p.src { text-align: right; color: var(--muted); }
.prose img { max-width: 100%; height: auto; }
.prose .text-center { text-align: center; }
.prose .text-right { text-align: right; }
.prose .text-muted { color: var(--muted); }
.prose ul ul { margin: .3em 0; }
.term { background: none; border: 0; padding: 0; font: inherit; color: var(--link); border-bottom: 2px dotted currentColor; cursor: help; }
.term:hover { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.btn { display: inline-flex; align-items: center; gap: .55em; padding: .6em 1.15em; border-radius: 999px; background: var(--brand); color: #fff; text-decoration: none; font-weight: 600; border: 0; cursor: pointer; font-size: 1rem; line-height: 1.3; }
.btn:hover { filter: brightness(1.15); }
.btn.extra { background: var(--accent); color: var(--accent-ink); }
:root[data-theme="dark"] .btn:not(.extra) { background: var(--brand-2); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn:not(.extra) { background: var(--brand-2); } }
.video { position: relative; aspect-ratio: 16 / 9; margin: 1.4em auto; max-width: 920px; border-radius: 12px; overflow: hidden; background: #000; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.table-wrap { overflow-x: auto; margin: 1.2em 0; }
table.data { border-collapse: collapse; width: 100%; font-size: .95rem; }
table.data th, table.data td { border: 1px solid var(--line); padding: .5rem .7rem; text-align: left; }
table.data th { background: var(--code-bg); }
details.fuentes { margin: 1rem 0; border: 1px solid var(--line); border-radius: 10px; padding: .1rem 1rem; font-size: .92rem; background: var(--bg); }
details.fuentes summary { cursor: pointer; font-weight: 600; padding: .5rem 0; }
details.fuentes h3, details.fuentes h4 { margin: .8em 0 .2em; font-size: 1rem; }
.aviso { padding: .8rem 1rem; border-radius: 10px; background: var(--warn-bg); margin: 1rem 0; }
.toc { margin: 0 0 1.2rem; border: 1px solid var(--line); border-radius: 10px; padding: 0 1rem; background: var(--bg); font-size: .95rem; }
.toc summary { cursor: pointer; font-weight: 600; padding: .6rem 0; }
.toc ol { margin: 0 0 .8rem; padding-left: 1.2rem; }
.svc { margin-top: 1rem; }
.chapters { list-style: none; padding: 0; margin: 1.4rem 0; display: grid; gap: .6rem; }
.chapters a { display: flex; gap: .8rem; align-items: center; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text); background: var(--surface); }
.chapters a:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.chapters .n { font-weight: 700; color: var(--muted); min-width: 2.2rem; }
.chapters .tag { margin-left: auto; font-size: .78rem; font-weight: 700; color: var(--ok); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: 1.6rem 0 0; }
.pager a { display: flex; flex-direction: column; gap: .15rem; padding: .9rem 1.1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); text-decoration: none; }
.pager a:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.pager small { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: .72rem; letter-spacing: .05em; }
.pager .next { text-align: right; grid-column: 2; }
.pager .prev { grid-column: 1; }
@media (max-width: 520px) { .pager { grid-template-columns: 1fr; } .pager .next, .pager .prev { grid-column: auto; text-align: left; } }

/* ===== Línea de tiempo ===== */
.timeline { list-style: none; position: relative; padding: .5rem 0; margin: 2rem 0; }
.timeline::before { content: ""; position: absolute; top: 0; bottom: 0; left: 1.25rem; width: 3px; background: var(--line); }
.timeline > li { position: relative; margin: 0 0 1.1rem; padding-left: 3.6rem; }
.timeline-badge { position: absolute; left: 0; top: .5rem; width: 2.5rem; height: 2.5rem; border-radius: 50%; display: grid; place-items: center; background: #7b8794; color: #fff; z-index: 1; border: 3px solid var(--surface); }
.timeline-badge.success { background: #2e9e5b; } .timeline-badge.danger { background: #d64533; }
.timeline-badge.warning { background: #d99a06; } .timeline-badge.info { background: #2f7fd1; }
.timeline-panel { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: .7rem 1rem; }
.timeline-panel p { margin: .4em 0; }
.timeline-title { margin: .1rem 0; font-size: 1.05rem; }
h3.timeline-title { text-transform: uppercase; letter-spacing: .04em; font-size: 1rem; }
.timeline-heading small { color: var(--muted); }
.timeline-body img { display: block; margin: .6rem auto 0; border-radius: 8px; }
@container (min-width: 780px) {
  .timeline::before { left: 50%; margin-left: -1.5px; }
  .timeline > li { width: 50%; padding: 0 3.3rem 0 0; }
  .timeline > li.timeline-inverted { margin-left: 50%; padding: 0 0 0 3.3rem; }
  .timeline > li .timeline-badge { left: auto; right: -1.25rem; }
  .timeline > li.timeline-inverted .timeline-badge { left: -1.25rem; right: auto; }
}

/* ===== Ventanas emergentes ===== */
.pop { position: absolute; z-index: 70; width: min(380px, 92vw); max-height: 70vh; overflow: auto; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 16px 40px rgba(0,0,0,.3); padding: .9rem 2.4rem 1rem 1rem; font-size: .95rem; line-height: 1.55; }
.pop[hidden] { display: none; }
.pop h4 { margin: 0 0 .4rem; font-size: 1rem; }
.pop p { margin: .4em 0; }
.pop img { max-width: 100%; height: auto; border-radius: 8px; margin-top: .4rem; }
.pop .pclose { position: absolute; right: .3rem; top: .3rem; border: 0; background: none; color: var(--muted); cursor: pointer; width: 2rem; height: 2rem; border-radius: 8px; }
@media (max-width: 640px) {
  .pop { position: fixed; left: .5rem; right: .5rem; bottom: max(.5rem, env(safe-area-inset-bottom)); width: auto; max-height: 62vh; top: auto !important; left: .5rem !important; }
}
dialog { border: 0; padding: 0; color: var(--text); background: var(--surface); border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,.45); max-width: min(92vw, 640px); }
dialog::backdrop { background: rgba(0,0,0,.6); }
#lightbox { max-width: 96vw; max-height: 94vh; background: #000; color: #fff; overflow: hidden; }
#lightbox figure { margin: 0; padding: 2.6rem .6rem .6rem; text-align: center; }
#lightbox img { max-width: 92vw; max-height: 78vh; object-fit: contain; background: #fff; }
#lightbox figcaption { padding: .6rem; font-size: .9rem; }
#lightbox .close { position: absolute; right: .3rem; top: .3rem; color: #fff; }
#search { width: min(92vw, 640px); margin-top: 8vh; max-height: 80vh; overflow: hidden; }
#search[open] { display: flex; flex-direction: column; }
.s-head { display: flex; align-items: center; gap: .5rem; padding: .5rem .8rem; border-bottom: 1px solid var(--line); }
.s-head input { flex: 1; border: 0; background: none; font: inherit; color: inherit; padding: .5rem 0; outline: none; }
.s-head .ib:hover { background: var(--bg); }
.s-res { overflow: auto; padding: .4rem; }
.s-res .muted { padding: .8rem; }
.s-res a { display: block; padding: .6rem .8rem; border-radius: 10px; text-decoration: none; color: var(--text); }
.s-res a:hover, .s-res a:focus { background: var(--bg); }
.s-res b { display: block; }
.s-res small { color: var(--muted); display: block; line-height: 1.4; }
.s-res mark { background: color-mix(in srgb, var(--accent) 55%, transparent); color: inherit; border-radius: 3px; }
#ios-hint { padding: 1.4rem; }
#ios-hint h3 { margin-top: 0; }
#toast { position: fixed; z-index: 80; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translate(-50%, 200%); background: var(--brand); color: #fff; padding: .7rem 1rem; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.4); display: flex; gap: .8rem; align-items: center; max-width: 92vw; transition: transform .3s; }
#toast.show { transform: translate(-50%, 0); }
#toast button { border: 0; border-radius: 8px; padding: .3rem .7rem; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; }

/* ===== Portada ===== */
.hero { position: relative; border-radius: 20px; padding: clamp(1.4rem, 5vw, 3rem); color: #fff; background: radial-gradient(1200px 400px at 90% -10%, rgba(245,197,24,.28), transparent 60%), linear-gradient(135deg, #0f1b2d, #1c3557 70%); box-shadow: var(--shadow); }
.hero .kicker { text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; opacity: .8; font-weight: 700; margin: 0; }
.hero-date { position: absolute; top: clamp(.7rem, 2.2vw, 1.1rem); right: clamp(.8rem, 2.5vw, 1.3rem); display: inline-flex; align-items: center; gap: .4rem; padding: .28rem .75rem; border-radius: 999px; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .22); font-size: .76rem; font-weight: 600; letter-spacing: .01em; }
.hero-date .ico { width: 1em; height: 1em; }
@media (max-width: 520px) { .hero-date { position: static; margin-bottom: .8rem; } }
.hero h1 { font-size: clamp(1.8rem, 6vw, 3rem); margin: .3rem 0 .6rem; }
.hero p.lead { font-size: 1.1rem; max-width: 60ch; opacity: .92; margin: 0 0 1.2rem; }
.hero .cta { display: flex; flex-wrap: wrap; gap: .7rem; }
.hero .btn { background: var(--accent); color: var(--accent-ink); }
.hero .btn.ghost { background: rgba(255,255,255,.14); color: #fff; }
.quote { margin: 1.4rem 0; padding: 1.2rem 1.4rem; border-left: 5px solid var(--accent); background: var(--surface); border-radius: 0 var(--r) var(--r) 0; box-shadow: var(--shadow); min-height: 8.5rem; transition: opacity .6s; }
.quote.fade { opacity: 0; }
.quote p { margin: 0 0 .6rem; font-size: 1.15rem; font-style: italic; }
.quote footer { color: var(--muted); font-size: .92rem; }
.feat { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin: 1.4rem 0; }
.feat > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 1.2rem; box-shadow: var(--shadow); text-align: center; }
.feat img { width: 72px; height: 72px; object-fit: contain; }
.feat h3 { margin: .6rem 0 .3rem; }
.feat p { margin: 0; font-size: .95rem; color: var(--muted); }
.card-wrap { margin: 1.4rem auto; max-width: 960px; }
.card-wrap h2 { margin-top: 1.4em; font-size: 1.35rem; }
.card-wrap h2:first-child { margin-top: 0; }
.units { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); margin: 1rem 0 2rem; }
.unit-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .6rem; }
.unit-card h3 { margin: 0; font-size: 1.05rem; display: flex; gap: .6rem; align-items: baseline; }
.unit-card h3 a { color: var(--text); text-decoration: none; }
.unit-card h3 .un { display: inline-grid; place-items: center; flex: none; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: var(--brand); color: #fff; font-size: .85rem; }
.unit-card ul { list-style: none; margin: 0; padding: 0; font-size: .92rem; }
.unit-card li a { display: block; padding: .18rem 0; text-decoration: none; }
.bar { height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); width: 0; transition: width .5s; }
.bar-l { font-size: .8rem; color: var(--muted); margin-top: -.3rem; }
.team { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin: 1.4rem 0; }
.team figure { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.team img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.team figcaption { padding: 1rem 1.2rem; }
.team figcaption b { display: block; }
.team figcaption span { color: var(--muted); }

/* ===== Autoevaluación ===== */
.quiz { margin: 1rem auto; max-width: 900px; }
.q { border: 0; border-bottom: 1px solid var(--line); margin: 0; padding: 1.2rem 0; min-width: 0; }
.q:last-of-type { border-bottom: 0; }
.q legend { padding: 0; font-weight: 600; margin-bottom: .6rem; float: left; width: 100%; }
.q legend + * { clear: both; }
.q legend .n { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; margin-right: .5rem; border-radius: 50%; background: var(--brand); color: #fff; font-size: .85rem; }
.q .hint { color: var(--muted); font-size: .88rem; margin: 0 0 .5rem; clear: both; }
.q img.qimg { display: block; margin: .6rem auto 1rem; border-radius: 10px; max-height: 340px; width: auto; }
.opt { display: flex; gap: .7rem; align-items: flex-start; padding: .65rem .8rem; border: 2px solid var(--line); border-radius: 12px; margin: .45rem 0; cursor: pointer; transition: border-color .15s, background .15s; }
.opt:hover { border-color: var(--accent); }
.opt input { margin-top: .35rem; accent-color: var(--brand-2); flex: none; }
.opt .t { flex: 1; min-width: 0; }
.opt .mark { flex: none; display: none; }
.q.done .opt { cursor: default; }
.q.done .opt.ok { border-color: var(--ok); background: var(--ok-bg); }
.q.done .opt.bad { border-color: var(--bad); background: var(--bad-bg); }
.q.done .opt.miss { border-style: dashed; border-color: var(--ok); }
.q.done .opt.ok .mark, .q.done .opt.bad .mark, .q.done .opt.miss .mark { display: block; }
.q.done .opt.ok .mark, .q.done .opt.miss .mark { color: var(--ok); }
.q.done .opt.bad .mark { color: var(--bad); }
.why { margin: .6rem 0 0; padding: .7rem .9rem; border-radius: 10px; background: var(--ok-bg); font-size: .93rem; }
.why:empty { display: none; }
.res { position: sticky; top: calc(var(--top) + env(safe-area-inset-top) + .5rem); z-index: 5; margin: 0 0 1rem; padding: 1rem 1.2rem; border-radius: var(--r); background: var(--brand); color: #fff; box-shadow: var(--shadow); }
.res[hidden] { display: none; }
.res b { font-size: 1.3rem; }
.res .bar { margin: .6rem 0; background: rgba(255,255,255,.25); }
.actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1rem; }
.btn.sec { background: transparent; color: var(--text); border: 2px solid var(--line); }
.unanswered { color: var(--bad); font-weight: 600; font-size: .88rem; }
.btn.small { padding: .4em .9em; font-size: .88rem; }
.side-foot { margin: 1rem .4rem 0; padding-top: 1rem; border-top: 1px solid var(--line); font-size: .85rem; }
.side-foot p { margin: 0 0 .6rem; }
.reset-row { text-align: center; margin: 1rem 0 2rem; }
#reset { padding: 1.4rem; }
#reset h3 { margin-top: 0; }
.dlg-actions { display: flex; gap: .7rem; justify-content: flex-end; margin-top: 1rem; }

/* ===== Barra inferior de navegación (móvil y tablet) ===== */
.mbar { display: none; position: fixed; z-index: 35; left: 0; right: 0; bottom: 0; grid-template-columns: 1fr auto 1fr; gap: .5rem; align-items: stretch; padding: .5rem max(.6rem, env(safe-area-inset-right)) calc(.5rem + env(safe-area-inset-bottom)) max(.6rem, env(safe-area-inset-left)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(0, 0, 0, .14); }
.mbar[hidden] { display: none !important; }
.mb-btn { display: flex; align-items: center; gap: .4rem; min-width: 0; min-height: 3.1rem; padding: .3rem .7rem; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); text-decoration: none; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.mb-btn:active { filter: brightness(.94); }
.mb-btn .ico { flex: none; width: 1.3em; height: 1.3em; }
.mb-t { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.mb-t small { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.mb-t b { font-size: .84rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mb-next { justify-content: flex-end; text-align: right; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.mb-next .mb-t small { color: inherit; opacity: .75; }
.mb-menu { justify-content: center; padding: .3rem .85rem; }
.mb-btn[aria-disabled="true"] { opacity: .38; pointer-events: none; }
@media (max-width: 999px) {
  body.has-mbar .mbar { display: grid; }
  body.has-mbar .pager { display: none; }
  body.has-mbar .foot { padding-bottom: calc(6rem + env(safe-area-inset-bottom)); }
  body.has-mbar #toast { bottom: calc(5rem + env(safe-area-inset-bottom)); }
  body.has-mbar #prog { top: 0; }
}
@media (max-width: 640px) { body.has-mbar .pop { bottom: calc(5rem + env(safe-area-inset-bottom)); } }
@media print { .mbar { display: none !important; } }

/* ===== Recuadro de actualización de datos ===== */
.update { margin: 0 0 1.6em; padding: .2rem 1.1rem .8rem; border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 12px; background: var(--bg); font-size: .95rem; line-height: 1.6; }
.prose > .update { max-width: none; }
.update h3 { margin: .9rem 0 .4rem; font-size: 1rem; }
.update p, .update ul { margin: .5em 0; }
.update li { margin: .35em 0; }
.update .src { margin: .7em 0 0; font-size: .82rem; color: var(--muted); text-align: left; }
.update .table-wrap { margin: .8em 0; }
.update table.data { font-size: .88rem; }

/* ===== Comentarios y contador de visitas ===== */
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#feedback { width: min(94vw, 540px); padding: 1.3rem; max-height: 92vh; overflow: auto; }
#feedback h3 { margin: 0 0 .3rem; }
#feedback .muted { margin: 0 0 .4rem; font-size: .93rem; }
.fb fieldset { border: 0; padding: 0; margin: .9rem 0 0; min-width: 0; }
.fb legend { padding: 0; font-weight: 600; font-size: .92rem; }
.scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: .25rem; margin-top: .45rem; }
.fb .sc { position: relative; display: block; margin: 0; font-weight: 600; }
.sc span { display: grid; place-items: center; min-height: 2.5rem; border: 2px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); cursor: pointer; font-size: .95rem; transition: background .12s, border-color .12s; }
.sc:hover span { border-color: var(--accent); }
.sc.on span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sc:focus-within span { outline: 3px solid var(--accent); outline-offset: 2px; }
.scale-l { display: flex; justify-content: space-between; margin-top: .3rem; font-size: .75rem; color: var(--muted); }
.fb-f { display: block; margin: .9rem 0 0; font-weight: 600; font-size: .92rem; }
.fb-f textarea, .fb-f input { display: block; width: 100%; margin-top: .3rem; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: 400 1rem/1.4 system-ui, sans-serif; }
.fb-f textarea { resize: vertical; min-height: 6rem; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.fb-msg { min-height: 1.4em; margin: .6rem 0 0; font-size: .9rem; }
.fb-msg.err { color: var(--bad); font-weight: 600; }
.fb-priv { margin: .3rem 0 0; font-size: .78rem; color: var(--muted); line-height: 1.45; }
.fb-done { padding: .3rem 0; }
.fb-done h3 { margin: 0 0 .3rem; }
.foot .btn { background: var(--accent); color: var(--accent-ink); }
.foot .visits { margin: .6rem 0 0; font-size: .95rem; }
.foot .visits b { color: #fff; font-size: 1.15rem; }
.foot .fine { margin: .3rem 0 0; font-size: .78rem; opacity: .75; }
@media (max-width: 460px) { .scale { grid-template-columns: repeat(5, 1fr); } }

/* ===== Animación del tsunami ===== */
.anim-tsunami { --sky1: #bfe3ff; --sky2: #e8f4ff; --tz-ink: #1b2836; margin: 1.6em 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
:root[data-theme="dark"] .anim-tsunami { --sky1: #0d2036; --sky2: #16304d; --tz-ink: #e6ebf2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .anim-tsunami { --sky1: #0d2036; --sky2: #16304d; --tz-ink: #e6ebf2; } }
.anim-tsunami svg:first-child { display: block; width: 100%; height: auto; }
.anim-tsunami .tz-t { fill: var(--tz-ink); font: 500 15px system-ui, sans-serif; }
.anim-tsunami .tz-t.small { font-size: 12px; }
.anim-tsunami .tz-t.bold { font-weight: 700; }
.anim-tsunami .tz-t.w { fill: #fff; }
.anim-ctl { display: flex; align-items: center; gap: .8rem; padding: .7rem 1rem 0; }
.anim-ctl input[type=range] { flex: 1; accent-color: var(--accent); min-width: 0; height: 2rem; }
.anim-ctl .btn { padding: .45em 1em; flex: none; }
.anim .chips, .anim-tsunami .chips { display: flex; flex-wrap: wrap; gap: .4rem; padding: .6rem 1rem 0; }
.anim-tsunami .chips button { border: 2px solid var(--line); background: transparent; color: var(--text); border-radius: 999px; padding: .25rem .7rem; font: 600 .82rem system-ui; cursor: pointer; }
.anim-tsunami .chips button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.anim-tsunami .anim-cap { margin: 0; padding: .7rem 1rem 1rem; font-size: .95rem; min-height: 4.4em; }

/* ===== Pie ===== */
.foot { background: var(--brand); color: #d5dbe5; margin-top: 2rem; padding: 2rem max(1rem, env(safe-area-inset-left)) calc(2rem + env(safe-area-inset-bottom)); font-size: .9rem; line-height: 1.6; }
.foot a { color: #fff; }
.foot h3 { color: #fff; margin: 0 0 .5rem; font-size: 1rem; }
.foot-grid { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); max-width: 980px; margin: 0 auto; }
.foot img { background: #fff; border-radius: 8px; padding: 4px; max-height: 60px; width: auto; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
@media print { .top, .side, #scrim, .pager, .foot, #prog, #toast { display: none !important; } .shell { display: block; } .lesson .prose { border: 0; box-shadow: none; } }
