/* ============================================
   Geometría - Libro digital
   Eduardo Espinoza Ramos
   ============================================ */

:root {
  --bg: #fafaf7;
  --bg-elev: #ffffff;
  --ink: #1b1b1f;
  --ink-soft: #4a4a52;
  --ink-mute: #82828a;
  --rule: #e5e3dc;
  --accent: #1f4b8e;
  --accent-soft: #e7eef9;
  --warn: #b56500;
  --code-bg: #f3f1ea;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --serif: "Iowan Old Style", "Source Serif Pro", "Charter", Cambria, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --maxw: 760px;
}

/* Modo auto: sigue al sistema SOLO si theme.js no fijó un tema manual
   (html.theme-light/sepia/dark). Sin JS, el selector equivale a :root. */
@media (prefers-color-scheme: dark) {
  html:not(.theme-light):not(.theme-sepia):not(.theme-dark) {
    --bg: #15161a;
    --bg-elev: #1c1d22;
    --ink: #e9e9ec;
    --ink-soft: #c2c2c8;
    --ink-mute: #8a8a94;
    --rule: #2e2f36;
    --accent: #6ea2ff;
    --accent-soft: #1d2840;
    --warn: #e2a04a;
    --code-bg: #22232a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app {
  display: grid;
  grid-template-columns: 280px minmax(0,1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--rule);
  padding: 28px 22px 60px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  font-family: var(--sans);
  font-size: 14px;
}

.sidebar .brand {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .2px;
  margin-bottom: 4px;
  color: var(--ink);
}
.sidebar .brand small {
  display: block;
  font-family: var(--sans);
  font-size: 11px;
  color: var(--ink-mute);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-top: 2px;
}

.sidebar .toc-title {
  margin-top: 28px;
  margin-bottom: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-mute);
  font-weight: 600;
}

.sidebar ol, .sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.sidebar li a {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--ink-soft);
  text-decoration: none;
  transition: background .15s, color .15s;
}
.sidebar li a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.sidebar li a.section-num::before {
  content: attr(data-num) " ";
  color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
  margin-right: 6px;
}

.main {
  min-width: 0; /* grid item: sin esto no encoge bajo el min-content de la fórmula más ancha */
  padding: 56px 48px 120px;
  max-width: calc(var(--maxw) + 96px);
}

.crumbs {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-mute);
  margin-bottom: 24px;
}
.crumbs a { color: var(--ink-mute); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

.chapter-label {
  font-family: var(--sans);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 6px;
}

h1.chapter-title {
  font-size: 42px;
  line-height: 1.1;
  margin: 0 0 36px 0;
  letter-spacing: -.4px;
  font-weight: 700;
}

h2 {
  font-size: 26px;
  margin: 48px 0 14px;
  letter-spacing: -.2px;
  font-weight: 600;
  scroll-margin-top: 20px;
}
h2 .num {
  color: var(--ink-mute);
  font-weight: 500;
  margin-right: 8px;
  font-variant-numeric: tabular-nums;
}

h3 {
  font-size: 19px;
  margin: 28px 0 10px;
  font-weight: 600;
  color: var(--ink-soft);
}

p { margin: 0 0 14px; max-width: var(--maxw); }

.lead {
  font-size: 19px;
  color: var(--ink-soft);
  margin-bottom: 26px;
}

ul.objs {
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
}
ul.objs li {
  position: relative;
  padding-left: 24px;
  margin-bottom: 10px;
  max-width: var(--maxw);
}
ul.objs li::before {
  content: "";
  position: absolute;
  left: 4px; top: 12px;
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
}

ol.concepts {
  counter-reset: c;
  list-style: none;
  padding: 0;
}
ol.concepts > li {
  counter-increment: c;
  position: relative;
  padding-left: 42px;
  margin-bottom: 22px;
  max-width: var(--maxw);
}
ol.concepts > li::before {
  content: counter(c);
  position: absolute;
  left: 0; top: 1px;
  width: 28px; height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 50%;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
}
ol.concepts strong.term {
  color: var(--ink);
  font-weight: 700;
}

figure {
  margin: 22px 0;
  text-align: center;
}
figure img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  background: white;
}
figure.diagram {
  margin: 18px auto;
  max-width: var(--maxw);
}
figure.diagram img {
  max-width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--rule);
  background: white;
  border-radius: 6px;
}
figure.diagram.tight img {
  padding: 6px 14px;
}
figure.facsimile img {
  max-width: 100%;
  box-shadow: var(--shadow);
  border: 1px solid var(--rule);
}
figcaption {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-mute);
  margin-top: 8px;
  letter-spacing: .2px;
}

.callout {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 14px 18px;
  margin: 18px 0;
  border-radius: 0 6px 6px 0;
  max-width: var(--maxw);
}
.callout.theorem {
  background: #fdf5e6;
  border-left-color: var(--warn);
}
@media (prefers-color-scheme: dark) {
  html:not(.theme-light):not(.theme-sepia) .callout.theorem { background: #2a2417; }
}
.callout .label {
  display: inline-block;
  font-family: var(--sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
}
.callout.theorem .label { color: var(--warn); }

.notation {
  display: inline-block;
  background: var(--code-bg);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: .92em;
}

/* facsimile sections — rendered PDF pages */
.facsimile-section {
  margin-top: 36px;
}
.facsimile-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr);
  gap: 28px;
  margin-top: 18px;
}
.facsimile-grid figure {
  margin: 0;
}
.facsimile-grid figcaption {
  text-align: left;
  padding-left: 4px;
}
.facsimile-note {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-mute);
  background: var(--code-bg);
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  max-width: var(--maxw);
}

.proof {
  border-left: 2px solid var(--ink-mute);
  padding-left: 18px;
  margin: 16px 0;
  color: var(--ink-soft);
}
.proof .qed::after {
  content: " ∎";
  color: var(--ink-mute);
}

/* ============================================
   MEJORAS PEDAGÓGICAS
   ============================================ */

/* "Por qué importa" — callout al inicio del capítulo */
.why-matters {
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border-left: 3px solid var(--accent);
  padding: 16px 20px;
  margin: 24px 0 32px;
  border-radius: 0 8px 8px 0;
  max-width: var(--maxw);
}
.why-matters .label {
  display: block;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
  margin-bottom: 6px;
}
.why-matters p { margin: 0; font-size: 16px; }

/* "Errores frecuentes" — callout en color advertencia */
.common-error {
  background: #fff8ec;
  border-left: 3px solid var(--warn);
  padding: 14px 18px;
  margin: 18px 0;
  border-radius: 0 6px 6px 0;
  max-width: var(--maxw);
}
@media (prefers-color-scheme: dark) {
  html:not(.theme-light):not(.theme-sepia) .common-error { background: #2a2417; }
}
.common-error .label {
  display: inline-block;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--warn);
  margin-bottom: 6px;
}
.common-error .label::before { content: "⚠ "; }

/* "Resumen del capítulo" — caja sticky-feel al final de teoría */
.chapter-summary {
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 24px 28px;
  margin: 48px 0;
  max-width: var(--maxw);
  box-shadow: var(--shadow);
}
.chapter-summary h3 {
  margin: 0 0 14px;
  font-family: var(--sans);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  font-weight: 700;
}
.chapter-summary h3::before { content: "📋 "; }
.chapter-summary .formulas {
  display: grid;
  grid-template-columns: minmax(0,1fr);
  gap: 10px;
  margin-top: 14px;
}
.chapter-summary .formula-item {
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--rule);
  font-size: 15px;
}
.chapter-summary .formula-item .label {
  display: block;
  font-family: var(--sans);
  font-size: 11px;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 4px;
}

/* Indicador de dificultad — estrellitas */
.difficulty {
  display: inline-flex;
  gap: 2px;
  margin-left: auto;
  margin-right: 8px;
  font-size: 13px;
  letter-spacing: 1px;
}
.difficulty .star { color: var(--ink-mute); }
.difficulty .star.filled { color: var(--accent); }

/* "Pista" antes de "Ver solución" */
.ex-hint {
  background: var(--code-bg);
  border-radius: 6px;
  padding: 10px 14px;
  margin: 10px 0;
  font-family: var(--serif);
  font-size: 14px;
  color: var(--ink-soft);
}
.ex-hint summary {
  cursor: pointer;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  list-style: none;
  user-select: none;
  margin: 0;
}
.ex-hint summary::-webkit-details-marker { display: none; }
.ex-hint summary::before {
  content: "💡 ";
  margin-right: 4px;
}
.ex-hint[open] summary {
  margin-bottom: 6px;
  color: var(--accent);
}
.ex-hint p { margin: 0; }

/* Tabla de notación del capítulo */
.notation-table {
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
  margin: 24px 0;
  max-width: var(--maxw);
}
.notation-table .row {
  display: grid;
  grid-template-columns: 80px minmax(0,1fr);
  align-items: baseline;
  padding: 10px 16px;
  border-bottom: 1px solid var(--rule);
  font-size: 15px;
}
.notation-table .row:last-child { border-bottom: none; }
.notation-table .row .sym {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}
.notation-table .row .desc {
  color: var(--ink-soft);
}

/* Glosario — términos con tooltip */
.glosa {
  border-bottom: 1px dotted var(--accent);
  cursor: help;
  position: relative;
}
.glosa:hover { color: var(--accent); }
.glosa[data-def]:hover::after {
  content: attr(data-def);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 8px 12px;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 13px;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  pointer-events: none;
  line-height: 1.4;
  font-weight: 400;
}
.glosa[data-def]:hover::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--ink);
  z-index: 10;
}

/* Tarjetas con respuesta de baja confianza (resolvedor algorítmico, no clave del libro) */
.ex-card.low-confidence {
  border-color: var(--warn);
  position: relative;
}
.ex-card.low-confidence::before {
  content: "Respuesta calculada · verificar";
  position: absolute;
  top: -10px;
  right: 14px;
  background: var(--warn);
  color: white;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 3px;
}

/* answer key */
.answers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 6px;
  font-family: var(--mono);
  font-size: 14px;
  max-width: var(--maxw);
  margin-top: 14px;
}
.answers-grid .ans {
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.answers-grid .ans .n {
  color: var(--ink-mute);
  font-size: 12px;
}
.answers-grid .ans .v {
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
}

/* footer */
.nav-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 80px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 14px;
}
.nav-foot a {
  color: var(--accent);
  text-decoration: none;
}
.nav-foot a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 880px) {
  html { overflow-x: hidden; overflow-x: clip; }
  .app { grid-template-columns: minmax(0,1fr); }
  main table { display: block; width: max-content; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  main img { max-width: 100%; height: auto; }
  main pre { max-width: 100%; overflow-x: auto; }
  main mjx-container:not([display="true"]) { display: inline-block; max-width: 100%; overflow-x: auto; overflow-y: hidden; vertical-align: middle; }
  /* Sidebar off-canvas (patrón AM3/AM2): fuera del flujo, entra desde la
     izquierda con el botón "Índice" (.toc-fab) que inyecta theme.js. */
  aside.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1200;
    width: min(320px, 86vw);
    height: 100%;
    transform: translateX(-104%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 36px rgba(0,0,0,.35);
    border-right: 1px solid var(--rule);
  }
  body.sidebar-open aside.sidebar { transform: translateX(0); }
  body.sidebar-open { overflow: hidden; }
  .main { padding: 32px 22px 80px; }
  h1.chapter-title { font-size: 32px; }
}

/* Botón "Índice" + telón del sidebar móvil (los inyecta theme.js). */
.toc-fab {
  position: fixed;
  bottom: 18px;
  left: 14px;
  z-index: 1180;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 2px 12px rgba(0,0,0,.22);
  cursor: pointer;
}
.toc-fab:hover { border-color: var(--accent); color: var(--accent); }
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1190;
  background: rgba(0,0,0,.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
@media (min-width: 881px) {
  .toc-fab, .sidebar-backdrop { display: none; }
}

/* Index page */
.cover {
  max-width: 720px;
  margin: 80px auto;
  padding: 0 24px;
}
.cover h1 {
  font-size: 56px;
  letter-spacing: -.8px;
  margin: 0 0 4px;
  line-height: 1.05;
}
.cover .author {
  font-family: var(--sans);
  font-size: 16px;
  color: var(--ink-mute);
  margin-bottom: 36px;
}
.cover .toc-h {
  font-family: var(--sans);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  font-weight: 700;
  margin-top: 48px;
  margin-bottom: 12px;
}
.cover ol.chapters {
  list-style: none;
  padding: 0;
  counter-reset: ch;
}
.cover ol.chapters li {
  counter-increment: ch;
  border-bottom: 1px solid var(--rule);
  padding: 18px 0;
}
.cover ol.chapters a {
  display: flex;
  align-items: baseline;
  gap: 16px;
  text-decoration: none;
  color: var(--ink);
  font-size: 22px;
  font-weight: 600;
}
.cover ol.chapters a::before {
  content: counter(ch, decimal-leading-zero);
  font-family: var(--mono);
  font-size: 14px;
  color: var(--ink-mute);
  font-weight: 400;
}
.cover ol.chapters a:hover { color: var(--accent); }
.cover ol.chapters .status {
  margin-left: auto;
  font-family: var(--sans);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-mute);
  font-weight: 500;
}
.cover ol.chapters .status.ready { color: var(--accent); }

mjx-container { font-size: 1.02em !important; }
mjx-container[display="true"] {
  margin: 1em 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ============================================
   Exercise cards (section 1.17)
   ============================================ */

.ex-cards {
  display: grid;
  grid-template-columns: minmax(0,1fr);
  gap: 22px;
  margin-top: 22px;
}

.ex-card {
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: var(--shadow);
  scroll-margin-top: 20px;
}

.ex-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.ex-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.ex-resp {
  margin-left: auto;
  font-family: var(--sans);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--ink-mute);
}
.ex-resp strong {
  color: var(--accent);
  margin-left: 6px;
  font-weight: 700;
}

.ex-body {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  margin: 0 0 14px;
}

.ex-opts {
  list-style: none;
  counter-reset: none;
  padding: 0;
  margin: 0 0 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}
.ex-opts .ex-opt {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
  font-family: var(--sans);
  font-size: 14px;
}
.ex-opts .ex-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  background: var(--code-bg);
  border-radius: 50%;
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-soft);
  flex-shrink: 0;
}
.ex-opts .ex-opt.is-correct {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.ex-opts .ex-opt.is-correct .ex-letter {
  background: var(--accent);
  color: white;
}
.ex-opts .ex-val {
  font-variant-numeric: tabular-nums;
}

.ex-solucion {
  border-top: 1px solid var(--rule);
  padding-top: 12px;
  margin-top: 4px;
}
.ex-solucion summary {
  cursor: pointer;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  list-style: none;
  padding: 4px 0;
  user-select: none;
}
.ex-solucion summary::-webkit-details-marker { display: none; }
.ex-solucion summary::before {
  content: "▸ ";
  display: inline-block;
  margin-right: 4px;
  transition: transform .15s;
}
.ex-solucion[open] summary::before {
  transform: rotate(90deg);
}
.ex-sol-fig {
  margin: 14px 0 0;
  text-align: center;
}
.ex-sol-fig img {
  max-width: 100%;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: white;
}

.ex-toc {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 6px;
  margin: 14px 0 28px;
  font-family: var(--sans);
  font-size: 13px;
}
.ex-toc a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  text-decoration: none;
  color: var(--ink-soft);
  background: var(--bg-elev);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.ex-toc a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* New (rewritten) solutions inside ex-solucion details */
.ex-solucion p {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.6;
  margin: 10px 0;
}
.ex-solucion .sol-fig {
  margin: 18px auto;
  text-align: center;
}
.ex-solucion .sol-fig img {
  max-width: 100%;
  background: white;
  padding: 8px 14px;
  border: 1px solid var(--rule);
  border-radius: 6px;
}
@media (prefers-color-scheme: dark) {
  html:not(.theme-light):not(.theme-sepia) .ex-solucion .sol-fig img {
    background: #f4f4f0;
  }
}
.ex-solucion .sol-final {
  margin-top: 16px;
  padding: 10px 14px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  font-size: 17px;
  font-weight: 500;
}

/* Section 1.18 — toggle + ocultar respuestas correctas */
.prop-controls {
  margin: 18px 0;
}
.prop-toggle {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 9px 18px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.prop-toggle:hover { filter: brightness(1.06); }
.prop-cards-hidden .ex-resp { visibility: hidden; }
.prop-cards-hidden .ex-opt.is-correct {
  border-color: var(--rule);
  background: var(--bg);
}
.prop-cards-hidden .ex-opt.is-correct .ex-letter {
  background: var(--code-bg);
  color: var(--ink-soft);
}

/* ============================================
   UX globals — scroll-spy + sticky toolbar + print
   ============================================ */

/* Scroll-spy active link in sidebar */
.sidebar li a.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* Sticky toggle wrapper for proposed exercises */
.prop-sticky {
  position: sticky;
  top: 12px;
  z-index: 5;
  background: var(--bg);
  padding: 12px 0;
  margin-bottom: 8px;
}

/* Bulk controls for developed exercises */
.ex-bulk-controls {
  margin: 14px 0 22px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Print styles */
@media print {
  .sidebar,
  .crumbs,
  .nav-foot,
  .prop-controls,
  .ex-bulk-controls,
  .prop-sticky,
  .prop-toggle {
    display: none !important;
  }
  details.ex-solucion > summary { display: none; }
  .ex-solucion[open] > *:not(summary) { display: block; }
  .ex-solucion { display: block !important; }
  .main { padding: 0; max-width: 100%; }
  .app { display: block; }
  .ex-card { break-inside: avoid; page-break-inside: avoid; }
  .prop-cards-hidden .ex-opt.is-correct {
    border-color: var(--accent);
    background: var(--accent-soft);
  }
  .prop-cards-hidden .ex-resp { visibility: visible !important; }
}

/* =========================================================
   Temas manuales (theme.js pone html.theme-light/sepia/dark;
   "auto" no añade overrides y hereda el media query de arriba)
   ========================================================= */

/* --- Claro (forzado, ignora prefers-color-scheme) --- */
html.theme-light {
  color-scheme: light;
  /* paleta :root explícita para pisar al sistema en modo oscuro */
  --bg: #fafaf7;
  --bg-elev: #ffffff;
  --ink: #1b1b1f;
  --ink-soft: #4a4a52;
  --ink-mute: #82828a;
  --rule: #e5e3dc;
  --accent: #1f4b8e;
  --accent-soft: #e7eef9;
  --warn: #b56500;
  --code-bg: #f3f1ea;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
}

/* --- Sepia --- */
html.theme-sepia {
  color-scheme: light;
  --bg: #f4ead6;
  --bg-elev: #faf3e3;
  --ink: #3d3424;
  --ink-soft: #5d543f;
  --ink-mute: #8a7f63;
  --rule: #ddd0b4;
  --accent: #8a5a2b;
  --accent-soft: #efe1c6;
  --warn: #8f6a14;
  --code-bg: #ece0c2;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.08);
}
html.theme-sepia .callout.theorem { background: #f3e7c0; }
html.theme-sepia .common-error { background: #f3e7c0; }

/* --- Oscuro (forzado) --- */
html.theme-dark {
  color-scheme: dark;
  --bg: #15161a;
  --bg-elev: #1c1d22;
  --ink: #e9e9ec;
  --ink-soft: #c2c2c8;
  --ink-mute: #8a8a94;
  --rule: #2e2f36;
  --accent: #6ea2ff;
  --accent-soft: #1d2840;
  --warn: #e2a04a;
  --code-bg: #22232a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}
html.theme-dark .callout.theorem { background: #2a2417; }
html.theme-dark .common-error { background: #2a2417; }
html.theme-dark .ex-solucion .sol-fig img { background: #f4f4f0; }

/* =========================================================
   GP-SEARCH-LINK-STYLES — links Buscar/Glosario del sidebar
   (portado del bloque AM3-SEARCH-LINK-STYLES; también aplica
   a la portada index.html, que no tiene sidebar)
   ========================================================= */
aside.sidebar .sidebar-search-link,
aside.sidebar .sidebar-glossary-link,
.cover .sidebar-search-link,
.cover .sidebar-glossary-link {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 13.5px;
  border: 1px dashed var(--rule);
  text-decoration: none;
  line-height: 1.4;
}
aside.sidebar .sidebar-glossary-link,
.cover .sidebar-glossary-link { margin-top: 6px; }
aside.sidebar .sidebar-search-link:hover,
aside.sidebar .sidebar-glossary-link:hover,
.cover .sidebar-search-link:hover,
.cover .sidebar-glossary-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  border-color: color-mix(in srgb, var(--accent) 50%, var(--rule));
}
aside.sidebar .sidebar-search-link.current,
aside.sidebar .sidebar-glossary-link.current {
  background: var(--accent);
  color: #fff;
  border-style: solid;
  border-color: transparent;
}
.cover .cover-tools {
  max-width: 320px;
  margin-top: 6px;
}

/* ===== GP-QUIZ-CAS-STYLES — retrieval practice y verificación CAS
   (portado de AM3-QUIZ-CAS-STYLES; --rule-strong → --rule) ===== */
.retrieval{
  margin: 22px 0; padding: 16px 18px;
  border: 1px solid var(--rule); border-left: 4px solid var(--accent);
  border-radius: 8px; background: var(--bg-elev);
  font-family: var(--sans);
}
.retrieval .q-kicker{
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-mute); margin-bottom: 6px; font-weight: 600;
}
.retrieval .q-text{ font-weight: 600; margin-bottom: 10px; color: var(--ink); }
.retrieval .choices{ display: grid; gap: 7px; }
.retrieval .choice{
  text-align: left; padding: 9px 12px;
  border: 1px solid var(--rule); border-radius: 6px;
  background: var(--bg); color: var(--ink);
  font: inherit; font-size: 14.5px; cursor: pointer;
}
.retrieval .choice:hover{ border-color: var(--accent); }
.retrieval .choice.ok{ border-color: #1d7a3c; background: color-mix(in srgb, #1d7a3c 12%, var(--bg)); }
.retrieval .choice.wrong{ border-color: #b3372f; background: color-mix(in srgb, #b3372f 12%, var(--bg)); }
.retrieval .choice.reveal:not(.ok):not(.wrong){ border-color: #1d7a3c; }
.retrieval .q-feedback{
  margin-top: 10px; padding: 9px 12px; border-radius: 6px; font-size: 14px;
}
.retrieval .q-feedback.is-ok{ background: color-mix(in srgb, #1d7a3c 10%, var(--bg-elev)); color: var(--ink); border-left: 3px solid #1d7a3c; }
.retrieval .q-feedback.is-no{ background: color-mix(in srgb, #b3372f 8%, var(--bg-elev)); color: var(--ink); border-left: 3px solid #b3372f; }

.cas-verify{
  margin: 22px 0; padding: 16px 18px;
  border: 1px dashed var(--rule); border-radius: 8px;
  background: var(--bg-elev); font-family: var(--sans);
}
.cas-verify .cas-label{ font-weight: 600; margin-bottom: 10px; color: var(--ink); }
.cas-verify .cas-row{ display: flex; gap: 8px; flex-wrap: wrap; }
.cas-verify input{
  flex: 1 1 220px; padding: 8px 11px;
  border: 1px solid var(--rule); border-radius: 6px;
  background: var(--bg); color: var(--ink);
  font-family: var(--mono); font-size: 14px;
}
.cas-verify button{
  padding: 8px 16px; border: 1px solid var(--accent); border-radius: 6px;
  background: var(--accent); color: #fff; font: inherit; font-size: 14px; cursor: pointer;
}
.cas-verify button:hover{ filter: brightness(1.1); }
.cas-verify .result{ margin-top: 10px; padding: 8px 12px; border-radius: 6px; font-size: 14px; }
.cas-verify .result.is-ok{ background: color-mix(in srgb, #1d7a3c 10%, var(--bg-elev)); border-left: 3px solid #1d7a3c; }
.cas-verify .result.is-no{ background: color-mix(in srgb, #b3372f 8%, var(--bg-elev)); border-left: 3px solid #b3372f; }
.cas-verify .cas-help{ margin-top: 7px; font-size: 12.5px; color: var(--ink-mute); }
