/* ═══════════════════════════════════════════════════════════════════
   THEORY COMMON – Shared styles for all teoria.html pages
   ═══════════════════════════════════════════════════════════════════

   Each page sets CSS custom properties on .theory-page:

     --theory-accent       Main accent colour  (hero gradient, em, toc, widgets)
     --theory-badge-bg     Badge background     (module-level colour)
     --theory-badge-color  Badge text colour

   Fundamentos default:   accent-2 · badge purple
   Técnicas default:      accent-2 · badge green

   Include this file BEFORE the page's own <style> block so that
   page-specific overrides win by source order.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Layout ─────────────────────────────────────────────── */
.theory-page {
  max-width: 860px; margin: 0 auto; padding: 0 1.5rem 4rem;
}

/* ── Breadcrumb (hidden inline – moved to navbar via JS) ───── */
.theory-breadcrumb {
  display: none;
}

/* ── Hero header ────────────────────────────────────────── */
.theory-hero {
  padding: 2rem 0 2.5rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 2.5rem;
}
.theory-hero .badge {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .3rem .9rem; border-radius: 50px; font-size: .75rem; font-weight: 600;
  background: var(--theory-badge-bg); color: var(--theory-badge-color);
  margin-bottom: 1rem;
}
.theory-hero h1 {
  font-size: clamp(2rem, 5vw, 2.8rem); font-weight: 800;
  letter-spacing: -.03em; line-height: 1.15; margin-bottom: .6rem;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--theory-accent) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.theory-hero .subtitle {
  color: var(--text-secondary); font-size: 1.1rem; max-width: 640px; line-height: 1.7;
}

/* ── Table of contents ──────────────────────────────────── */
.toc {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 1.5rem 2rem; margin-bottom: 3rem;
  position: relative; overflow: hidden;
}
.toc::before {
  content: ''; position: absolute; top: 0; left: 0; width: 3px; height: 100%;
  background: linear-gradient(180deg, var(--theory-accent), var(--accent-1));
}
.toc h3 {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-muted); margin-bottom: 1rem; font-weight: 600;
}
.toc ol { list-style: none; counter-reset: toc; padding: 0; }
.toc li { counter-increment: toc; margin-bottom: .5rem; }
.toc li a {
  color: var(--text-secondary); text-decoration: none; font-size: .92rem;
  display: flex; align-items: center; gap: .6rem; padding: .25rem 0;
  transition: var(--transition);
}
.toc li a::before {
  content: counter(toc, decimal-leading-zero);
  font-family: var(--font-mono); font-size: .75rem; font-weight: 600;
  color: var(--theory-accent); min-width: 1.8rem;
}
.toc li a:hover { color: var(--theory-accent); padding-left: .5rem; }

/* ── Sections ───────────────────────────────────────────── */
.theory-section { margin-bottom: 3.5rem; scroll-margin-top: 80px; }
.theory-section > h2 {
  font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em;
  padding-bottom: .75rem; border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem; display: flex; align-items: center; gap: .6rem;
}
.theory-section > h2 .section-icon {
  width: 36px; height: 36px; border-radius: 10px; display: grid;
  place-items: center; font-size: 1.1rem; flex-shrink: 0;
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--theory-accent) 20%, transparent),
    rgba(9,132,227,.1));
}
.theory-section h3 {
  font-size: 1.15rem; font-weight: 600; margin: 2rem 0 .8rem;
  color: var(--text-primary);
}
.theory-section h4 {
  font-size: 1rem; font-weight: 600; margin: 1.5rem 0 .6rem;
  color: var(--text-secondary);
}
.theory-section p,
.theory-section li {
  color: var(--text-secondary); line-height: 1.85; font-size: .95rem;
}
.theory-section p { margin-bottom: 1rem; }
.theory-section ul,
.theory-section ol { padding-left: 1.5rem; margin-bottom: 1.2rem; }
.theory-section li { margin-bottom: .4rem; }
.theory-section strong { color: var(--text-primary); font-weight: 600; }
.theory-section em { color: var(--theory-accent); font-style: normal; }
.theory-section code {
  font-family: var(--font-mono); font-size: .85em;
  background: var(--bg-secondary); padding: .15rem .4rem; border-radius: 4px;
  color: var(--theory-accent);
}
.theory-section pre { margin: 0; }
.theory-section pre code {
  display: block; padding: 1.2rem 1.5rem; background: var(--bg-secondary);
  overflow-x: auto; line-height: 1.7; border-radius: 0; color: var(--text-secondary);
}

/* ── Math blocks (KaTeX) ────────────────────────────────── */
.math-block {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 1.5rem 2rem; margin: 1.5rem 0;
  text-align: center; overflow-x: auto; position: relative;
}
.math-block .math-label {
  position: absolute; top: .5rem; right: .75rem;
  font-size: .7rem; color: var(--text-muted); font-family: var(--font-mono);
  background: var(--bg-secondary); padding: .15rem .5rem; border-radius: 4px;
}
.math-block .katex { font-size: 1.15em; }

/* ── Callouts ───────────────────────────────────────────── */
.callout {
  border-radius: var(--radius-md); padding: 1.2rem 1.5rem; margin: 1.5rem 0;
  display: flex; gap: 1rem; align-items: flex-start; font-size: .9rem; line-height: 1.7;
}
.callout .callout-icon { font-size: 1.4rem; flex-shrink: 0; margin-top: .1rem; }
.callout p { margin-bottom: .3rem; }
.callout-info    { background: rgba(9,132,227,.08);   border: 1px solid rgba(9,132,227,.2);   color: var(--text-secondary); }
.callout-warning { background: rgba(225,112,85,.08);  border: 1px solid rgba(225,112,85,.2);  color: var(--text-secondary); }
.callout-key     { background: rgba(108,92,231,.08);  border: 1px solid rgba(108,92,231,.2);  color: var(--text-secondary); }
.callout-success { background: rgba(0,184,148,.08);   border: 1px solid rgba(0,184,148,.2);   color: var(--text-secondary); }

/* ── Interactive widgets ────────────────────────────────── */
.interactive-widget {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 2rem; margin: 2rem 0;
  position: relative; overflow: hidden;
}
.interactive-widget::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--theory-accent), var(--accent-1), var(--accent-5));
}
.interactive-widget h4 {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--theory-accent); margin-bottom: 1rem; font-weight: 600;
}
.widget-controls {
  display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; align-items: end;
}
.widget-control { display: flex; flex-direction: column; gap: .3rem; }
.widget-control label { font-size: .78rem; color: var(--text-muted); font-weight: 500; }
.widget-control input[type="range"] {
  accent-color: var(--theory-accent); width: 140px; cursor: pointer;
}
.widget-control select,
.widget-control input[type="number"],
.widget-control input[type="text"],
.widget-control textarea {
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  color: var(--text-primary); padding: .4rem .6rem; border-radius: var(--radius-sm);
  font-family: var(--font-sans); font-size: .85rem;
}
.widget-control .value-display {
  font-family: var(--font-mono); font-size: .85rem; color: var(--theory-accent);
  font-weight: 600; min-width: 3rem; text-align: center;
}
.widget-output {
  background: var(--bg-secondary); border-radius: var(--radius-md);
  padding: 1rem; min-height: 200px;
}
.widget-output-col {
  background: var(--bg-secondary); border-radius: var(--radius-md);
  padding: 1.5rem; min-height: 200px; display: flex; flex-direction: column; gap: 1rem;
}
.widget-btn {
  padding: .45rem 1rem; border: none; border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--font-sans); font-size: .82rem; font-weight: 600;
  transition: var(--transition);
}
.widget-btn-primary { background: var(--theory-accent); color: white; }
.widget-btn-primary:hover { filter: brightness(1.1); }
.widget-btn-secondary {
  background: var(--bg-secondary); color: var(--text-secondary);
  border: 1px solid var(--border-color);
}
.widget-btn-secondary:hover {
  border-color: var(--theory-accent); color: var(--text-primary);
}

/* ── Compare table ──────────────────────────────────────── */
.compare-table { width: 100%; border-collapse: collapse; margin: 1.5rem 0; font-size: .88rem; }
.compare-table table { width: 100%; border-collapse: collapse; }
.compare-table th {
  background: var(--bg-card); color: var(--text-muted);
  text-transform: uppercase; font-size: .75rem; letter-spacing: .06em;
  padding: .8rem 1rem; text-align: left; border-bottom: 2px solid var(--border-color);
}
.compare-table td {
  padding: .7rem 1rem; border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary); vertical-align: top;
}
.compare-table tr:hover td {
  background: color-mix(in srgb, var(--theory-accent) 4%, transparent);
}
.compare-table code {
  font-family: var(--font-mono); font-size: .82rem; color: var(--theory-accent);
  background: color-mix(in srgb, var(--theory-accent) 8%, transparent);
  padding: .1rem .4rem; border-radius: 3px;
}

/* ── Diagram container ──────────────────────────────────── */
.diagram-container {
  background: rgba(8,8,18,.85); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 2rem 2.5rem; margin: 2rem 0;
  text-align: center; cursor: zoom-in; transition: var(--transition);
  position: relative;
}
.diagram-container:hover {
  border-color: rgba(255,255,255,.12);
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
}
.diagram-container::after {
  content: '🔍';
  position: absolute; top: .6rem; right: .8rem;
  font-size: .7rem; opacity: 0; transition: opacity .2s ease;
  background: rgba(255,255,255,.06); padding: .2rem .5rem; border-radius: 4px;
  color: var(--text-muted); font-family: var(--font-sans);
}
.diagram-container:hover::after { opacity: 1; }
.diagram-container svg { max-width: 100%; height: auto; min-height: 120px; }
.diagram-container .caption {
  font-size: .82rem; color: var(--text-muted); margin-top: 1rem; font-style: italic;
}

/* ── Diagram modal (click to expand) ────────────────────── */
.diagram-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.82);
  backdrop-filter: blur(8px); z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  padding: 2rem; opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.diagram-modal-overlay.open { opacity: 1; pointer-events: all; }
.diagram-modal-content {
  background: rgba(12,12,22,.95); border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius-lg); padding: 2.5rem 3rem;
  max-width: 95vw; max-height: 90vh; overflow: auto;
  position: relative; text-align: center;
  transform: scale(.92); transition: transform .3s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
}
.diagram-modal-overlay.open .diagram-modal-content { transform: scale(1); }
.diagram-modal-content svg {
  max-width: 100%; height: auto;
  min-width: min(800px, 85vw);
}
.diagram-modal-close {
  position: absolute; top: .8rem; right: .8rem;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1);
  color: var(--text-secondary); width: 34px; height: 34px; border-radius: 50%;
  font-size: 1.1rem; cursor: pointer; display: grid; place-items: center;
  transition: var(--transition); z-index: 10; line-height: 1;
}
.diagram-modal-close:hover {
  background: rgba(255,255,255,.12); color: var(--text-primary);
}

/* ── Algorithm / step blocks ────────────────────────────── */
.algo-steps {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 1.5rem; margin: 1.5rem 0;
  counter-reset: algo-step;
}
.algo-step {
  counter-increment: algo-step;
  padding: .8rem 0 .8rem 2.5rem; position: relative;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.algo-step:last-child { border-bottom: none; }
.algo-step::before {
  content: counter(algo-step);
  position: absolute; left: 0; top: .8rem;
  width: 24px; height: 24px; border-radius: 50%;
  background: color-mix(in srgb, var(--theory-accent) 15%, transparent);
  color: var(--theory-accent);
  font-size: .75rem; font-weight: 700; font-family: var(--font-mono);
  display: grid; place-items: center;
}
.algo-step p { margin-bottom: .4rem; }

/* ── Flow diagram ───────────────────────────────────────── */
.flow-diagram {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  justify-content: center; margin: 1.5rem 0;
}
.flow-box {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: .6rem 1rem;
  font-size: .85rem; font-weight: 600; color: var(--text-primary);
  text-align: center; min-width: 100px;
}
.flow-box.highlight {
  border-color: var(--theory-accent);
  background: color-mix(in srgb, var(--theory-accent) 8%, transparent);
  color: var(--theory-accent);
}
.flow-arrow { color: var(--text-muted); font-size: 1.2rem; }

/* ── Timeline ───────────────────────────────────────────── */
.timeline {
  position: relative; padding-left: 2.5rem; margin: 1.5rem 0;
}
.timeline::before {
  content: ''; position: absolute; left: .75rem; top: 0; bottom: 0;
  width: 2px; background: linear-gradient(180deg, var(--theory-accent), var(--accent-1));
}
.timeline-item {
  position: relative; margin-bottom: 1.5rem; padding: 1rem 1.5rem;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}
.timeline-item::before {
  content: ''; position: absolute; left: -2rem; top: 1.3rem;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--theory-accent); border: 2px solid var(--bg-primary);
}
.timeline-item .year,
.timeline-item .tl-year {
  font-family: var(--font-mono); font-size: .8rem;
  color: var(--theory-accent); font-weight: 600; margin-bottom: .3rem;
}
.timeline-item .event,
.timeline-item .tl-text {
  font-size: .9rem; color: var(--text-secondary); line-height: 1.6;
}
.timeline-item .event strong { color: var(--text-primary); }

/* ── Pros / Cons ────────────────────────────────────────── */
.pros-cons {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1.5rem 0;
}
.pros, .cons {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 1.2rem;
}
.pros { border-top: 3px solid var(--accent-2); }
.cons { border-top: 3px solid var(--accent-4); }
.pros h5, .cons h5 {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: .6rem;
}
.pros h5 { color: var(--accent-2); }
.cons h5 { color: var(--accent-4); }
.pros li, .cons li {
  font-size: .85rem; color: var(--text-secondary);
  margin-bottom: .3rem; line-height: 1.6;
}

/* ── Inline code block ──────────────────────────────────── */
.code-block {
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 1rem 1.2rem; margin: 1rem 0;
  font-family: var(--font-mono); font-size: .82rem; color: var(--text-secondary);
  overflow-x: auto; line-height: 1.7; white-space: pre;
}
.code-block .kw  { color: var(--accent-1); }
.code-block .fn  { color: var(--accent-2); }
.code-block .str { color: var(--accent-4); }
.code-block .cmt { color: var(--text-muted); font-style: italic; }

/* ── Content navigation ─────────────────────────────────── */
.content-nav {
  display: flex; justify-content: space-between; align-items: center;
  padding: 2rem 0; border-top: 1px solid var(--border-color);
  margin-top: 3rem; flex-wrap: wrap; gap: 1rem;
}
.content-nav a {
  color: var(--text-secondary); text-decoration: none; padding: .6rem 1.2rem;
  border-radius: var(--radius-sm); border: 1px solid var(--border-color);
  transition: var(--transition); font-size: .9rem;
  display: flex; align-items: center; gap: .4rem;
}
.content-nav a:hover { border-color: var(--theory-accent); color: var(--theory-accent); }

/* ── Cross-link buttons ─────────────────────────────────── */
.tool-link {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .6rem 1.2rem;
  background: linear-gradient(135deg, rgba(0,184,148,.08), rgba(108,92,231,.08));
  border: 1px solid rgba(0,184,148,.25); border-radius: var(--radius-md);
  color: var(--accent-2); text-decoration: none; font-weight: 600;
  font-size: .88rem; transition: var(--transition); margin: .75rem 0;
}
.tool-link:hover {
  background: linear-gradient(135deg, rgba(0,184,148,.15), rgba(108,92,231,.15));
  transform: translateX(4px); box-shadow: 0 2px 12px rgba(0,184,148,.15);
}
.demo-link {
  background: linear-gradient(135deg, var(--theory-accent), var(--accent-3));
  color: white !important; border: none !important; font-weight: 600;
  padding: .7rem 1.5rem !important; border-radius: var(--radius-md) !important;
  text-decoration: none; display: inline-flex; align-items: center; gap: .5rem;
  transition: var(--transition); font-size: .92rem;
}
.demo-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--theory-accent) 30%, transparent);
}

/* ══════════════════════════════════════════════════════════════
   COLLAPSIBLE CODE BLOCKS
   Two naming conventions supported:
     A) trigger / cc-chevron / code-collapse-body   (regularización, tensores…)
     B) toggle  / toggle-icon / collapsible-content  (estabilidad, inicialización…)
   ══════════════════════════════════════════════════════════════ */
.code-collapse {
  border: 1px solid var(--border-color); border-radius: var(--radius-md);
  margin: 1rem 0; overflow: hidden;
}
.code-collapse-trigger,
.code-collapse-toggle {
  width: 100%; padding: .8rem 1.2rem; background: var(--bg-card); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; font-size: .88rem; color: var(--text-primary);
  border: none; font-family: var(--font-sans); user-select: none;
  transition: var(--transition);
}
.code-collapse-trigger:hover,
.code-collapse-toggle:hover { background: var(--bg-card-hover, var(--bg-card)); }
.code-collapse-trigger .cc-lang,
.code-collapse-toggle .cc-lang {
  font-size: .72rem; padding: .15rem .6rem; border-radius: 50px;
  font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.cc-lang-pytorch { background: rgba(225,112,85,.15); color: #fab1a0; }
.cc-lang-tf      { background: rgba(255,165,2,.15);  color: #ffc048; }
.cc-lang-numpy   { background: rgba(9,132,227,.15);  color: #74b9ff; }
.code-collapse-trigger .cc-chevron,
.code-collapse-toggle .toggle-icon {
  transition: transform .3s ease; font-size: .75rem; color: var(--text-muted);
}
.code-collapse.open .cc-chevron { transform: rotate(180deg); }
.code-collapse.open .toggle-icon { transform: rotate(90deg); }
/* Pattern A body */
.code-collapse-body {
  max-height: 0; overflow: hidden;
  transition: max-height .5s cubic-bezier(.4,0,.2,1);
}
.code-collapse.open .code-collapse-body { max-height: 4000px; }
/* Pattern B body */
.code-collapse .collapsible-content,
.code-collapse-content {
  max-height: 0; overflow: hidden;
  transition: max-height .5s cubic-bezier(.4,0,.2,1);
}
.code-collapse.open .collapsible-content,
.code-collapse.open .code-collapse-content { max-height: 4000px; }
/* Shared pre/code */
.code-collapse-body pre,
.code-collapse .collapsible-content pre,
.code-collapse-content pre {
  margin: 0; padding: 1.2rem 1.5rem; background: var(--bg-secondary);
  overflow-x: auto; border-top: 1px solid var(--border-color);
}
.code-collapse-body code,
.code-collapse .collapsible-content code,
.code-collapse-content code {
  font-family: var(--font-mono); font-size: .82rem;
  color: var(--text-secondary); line-height: 1.7; white-space: pre;
}

/* Manual syntax highlighting classes */
.code-comment { color: var(--text-muted); }
.code-keyword { color: #a29bfe; }
.code-string  { color: #55efc4; }
.code-number  { color: #fab1a0; }
.code-func    { color: #74b9ff; }

/* ══════════════════════════════════════════════════════════════
   EXPANDABLE DETAIL ELEMENTS
   ══════════════════════════════════════════════════════════════ */

/* ── Accordion ──────────────────────────────────────────── */
.detail-accordion {
  border: 1px solid var(--border-color); border-radius: var(--radius-md);
  margin: 1.5rem 0; overflow: hidden;
}
.detail-accordion-trigger {
  width: 100%; padding: 1rem 1.3rem; background: var(--bg-card); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; font-size: .9rem; color: var(--theory-accent);
  border: none; font-family: var(--font-sans); user-select: none;
  transition: var(--transition);
}
.detail-accordion-trigger:hover { background: var(--bg-card-hover, var(--bg-card)); }
/* supports both .chevron and .acc-icon for the toggle icon */
.detail-accordion-trigger .chevron,
.detail-accordion-trigger .acc-icon {
  transition: transform .3s ease; font-size: .8rem; color: var(--text-muted);
}
.detail-accordion.open .chevron,
.detail-accordion.open .acc-icon { transform: rotate(180deg); }
/* Pattern A – .detail-accordion-content is the expand wrapper (perceptron, mlp…) */
.detail-accordion > .detail-accordion-content {
  max-height: 0; overflow: hidden;
  transition: max-height .5s cubic-bezier(.4,0,.2,1), padding .3s ease;
  padding: 0 1.3rem; background: var(--bg-secondary);
}
.detail-accordion.open > .detail-accordion-content {
  max-height: 5000px; padding: 1.3rem;
}
/* Pattern B – .detail-accordion-body wraps .detail-accordion-content (tensores) */
.detail-accordion-body {
  max-height: 0; overflow: hidden;
  transition: max-height .5s cubic-bezier(.4,0,.2,1);
}
.detail-accordion.open .detail-accordion-body { max-height: 3000px; }
.detail-accordion-body .detail-accordion-content {
  padding: 1.2rem 1.4rem;
}
/* Shared content text */
.detail-accordion-content p,
.detail-accordion-content li {
  color: var(--text-secondary); font-size: .9rem; line-height: 1.8;
}
.detail-accordion-content p { margin-bottom: .8rem; }
.detail-accordion-content code {
  font-family: var(--font-mono); font-size: .82rem; color: var(--theory-accent);
  background: color-mix(in srgb, var(--theory-accent) 8%, transparent);
  padding: .1rem .4rem; border-radius: 3px;
}

/* ── Slide drawer ───────────────────────────────────────── */
.detail-drawer-trigger {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
  color: var(--accent-3); font-weight: 600; font-size: .88rem;
  padding: .5rem 1rem; border-radius: var(--radius-sm);
  background: rgba(9,132,227,.08); border: 1px solid rgba(9,132,227,.2);
  transition: var(--transition); margin: .5rem 0; font-family: var(--font-sans);
}
.detail-drawer-trigger:hover { background: rgba(9,132,227,.15); transform: translateX(2px); }
.detail-drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 999;
  opacity: 0; pointer-events: none; transition: opacity .3s ease;
}
.detail-drawer-backdrop.open { opacity: 1; pointer-events: all; }
.detail-drawer-panel {
  position: fixed; top: 0; right: -440px; width: 420px; max-width: 90vw;
  height: 100vh; background: var(--bg-card);
  border-left: 1px solid var(--border-color); z-index: 1000;
  transition: right .4s cubic-bezier(.4,0,.2,1);
  padding: 2rem; overflow-y: auto;
  box-shadow: -8px 0 40px rgba(0,0,0,.5);
}
.detail-drawer-panel.open { right: 0; }
.detail-drawer-close {
  position: absolute; top: 1rem; right: 1rem;
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  color: var(--text-muted); width: 32px; height: 32px; border-radius: 50%;
  font-size: 1.1rem; cursor: pointer; display: grid; place-items: center;
  transition: var(--transition);
}
.detail-drawer-close:hover { color: var(--text-primary); border-color: var(--accent-1); }
.detail-drawer-panel h3 {
  font-size: 1.15rem; font-weight: 700; margin-bottom: 1rem;
  padding-right: 2rem; color: var(--text-primary);
}
.detail-drawer-panel p {
  color: var(--text-secondary); font-size: .9rem; line-height: 1.8; margin-bottom: 1rem;
}
.detail-drawer-panel pre {
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 1rem; overflow-x: auto; margin: 1rem 0;
}
.detail-drawer-panel code {
  font-family: var(--font-mono); font-size: .82rem;
  color: var(--theory-accent); line-height: 1.7;
}

/* ── Modal overlay ──────────────────────────────────────── */
/* Two trigger styles: button-style (tensores) and link-style (perceptron) */
.detail-modal-trigger {
  background: none; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: .4rem .9rem;
  color: var(--text-secondary); cursor: pointer; font-size: .82rem;
  font-family: var(--font-sans); font-weight: 500;
  transition: var(--transition);
  display: inline-flex; align-items: center; gap: .3rem;
}
.detail-modal-trigger:hover {
  border-color: var(--theory-accent); color: var(--theory-accent);
  background: color-mix(in srgb, var(--theory-accent) 5%, transparent);
}
.detail-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 2rem;
  opacity: 0; pointer-events: none; transition: opacity .3s ease;
}
.detail-modal-overlay.open { opacity: 1; pointer-events: all; }
/* supports both .detail-modal-panel (tensores) and .detail-modal-box (perceptron) */
.detail-modal-panel,
.detail-modal-box {
  background: var(--bg-primary); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); max-width: 700px; width: 100%;
  max-height: 80vh; overflow-y: auto; padding: 2rem; position: relative;
  transform: translateY(20px) scale(.97); transition: transform .3s ease;
}
.detail-modal-overlay.open .detail-modal-panel,
.detail-modal-overlay.open .detail-modal-box {
  transform: translateY(0) scale(1);
}
.detail-modal-close {
  position: absolute; top: 1rem; right: 1rem;
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  border-radius: 50%; width: 32px; height: 32px;
  display: grid; place-items: center; cursor: pointer;
  color: var(--text-muted); font-size: .9rem; transition: var(--transition);
}
.detail-modal-close:hover { background: var(--bg-card); color: var(--text-primary); }
.detail-modal-panel h3,
.detail-modal-box h3 {
  font-size: 1.15rem; font-weight: 700; margin-bottom: 1rem; padding-right: 2rem;
}
.detail-modal-panel p, .detail-modal-panel li,
.detail-modal-box p,   .detail-modal-box li {
  font-size: .9rem; color: var(--text-secondary); line-height: 1.8;
}
.detail-modal-panel p, .detail-modal-box p { margin-bottom: .8rem; }

/* ── Inline reveal ──────────────────────────────────────── */
/* Pattern A – blur-based (perceptron, mlp…) */
.detail-reveal {
  position: relative; cursor: pointer; border-radius: var(--radius-sm);
  padding: 1rem 1.2rem; margin: 1rem 0; background: var(--bg-card);
  border: 1px solid var(--border-color); transition: var(--transition);
}
.detail-reveal::before {
  content: '🔍 Click para revelar'; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  background: color-mix(in srgb, var(--theory-accent) 85%, black);
  color: white; padding: .4rem 1.2rem; border-radius: 50px;
  font-size: .8rem; font-weight: 600; z-index: 2;
  pointer-events: none; transition: opacity .3s ease; white-space: nowrap;
}
.detail-reveal-content {
  filter: blur(4px); user-select: none; transition: filter .4s ease;
}
.detail-reveal.revealed::before { opacity: 0; }
.detail-reveal.revealed .detail-reveal-content { filter: none; user-select: auto; }
.detail-reveal.revealed { cursor: default; }
/* Pattern B – prompt/hidden (tensores) */
.detail-reveal .reveal-hidden { display: none; text-align: left; }
.detail-reveal .reveal-prompt { display: block; }
.detail-reveal.revealed .reveal-hidden {
  display: block; color: var(--text-secondary); line-height: 1.8;
}
.detail-reveal.revealed .reveal-prompt { display: none; }

/* ── Canvas for widgets ─────────────────────────────────── */
.widget-canvas {
  width: 100%; height: 320px; border-radius: var(--radius-md);
  background: var(--bg-secondary); border: 1px solid var(--border-color);
}

/* ══════════════════════════════════════════════════════════════
   EMBEDDED MODE (submodule landing page)
   ══════════════════════════════════════════════════════════════ */
.theory-collapsible,
.theory-collapsible-embed {
  position: relative; max-height: 280px; overflow: hidden;
  transition: max-height 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.theory-collapsible.expanded,
.theory-collapsible-embed.expanded { max-height: none; }
.theory-collapsible:not(.expanded)::after,
.theory-collapsible-embed:not(.expanded)::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 200px;
  background: linear-gradient(to bottom, transparent, var(--bg-primary));
  pointer-events: none; z-index: 2;
}

/* Collapsible theory sections (derivations, proofs) */
.theory-collapsible > .show-more-btn {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem 1.2rem; background: var(--bg-card);
  border: 1px solid var(--border-color); border-radius: var(--radius-md);
  color: var(--theory-accent); font-size: .88rem; font-weight: 600;
  font-family: var(--font-sans); cursor: pointer;
  transition: var(--transition); margin-bottom: .5rem;
}
.theory-collapsible > .show-more-btn:hover {
  border-color: var(--theory-accent);
  background: color-mix(in srgb, var(--theory-accent) 8%, transparent);
}
.theory-collapsible > .show-more-btn .toggle-icon {
  transition: transform 0.3s ease; font-size: .8rem;
}

.show-more-btn,
.show-more-btn-embed {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  margin: 1.5rem auto 3rem; padding: .8rem 2rem;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); color: var(--accent-1);
  font-size: .92rem; font-weight: 600; font-family: var(--font-sans);
  cursor: pointer; transition: var(--transition);
  position: relative; z-index: 3;
}
.show-more-btn:hover,
.show-more-btn-embed:hover {
  border-color: var(--accent-1);
  background: rgba(108,92,231,.08);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(108,92,231,.2);
}
.show-more-btn .chevron,
.show-more-btn-embed .chevron {
  transition: transform 0.3s ease; font-size: .8rem;
}
.show-more-btn.expanded .chevron { transform: rotate(180deg); }

/* ── Content cards for embedded mode ────────────────────── */
.embedded-tools-section { margin-bottom: 2.5rem; }
.embedded-tools-title {
  font-size: .85rem; font-weight: 600; color: var(--text-secondary);
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: 1rem; padding-bottom: .5rem;
  border-bottom: 1px solid var(--border-color);
}
.embedded-content-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.embedded-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 1.5rem;
  text-decoration: none; color: var(--text-primary);
  transition: var(--transition); position: relative; overflow: hidden;
}
.embedded-card::before {
  content: ''; position: absolute; top: 0; left: 0; width: 3px; height: 100%;
}
.embedded-card[data-type="demo"]::before       { background: var(--accent-2); }
.embedded-card[data-type="ejemplo"]::before     { background: var(--accent-3); }
.embedded-card[data-type="caso-de-uso"]::before { background: var(--accent-4, var(--accent-3)); }
.embedded-card:hover {
  border-color: var(--border-hover); transform: translateY(-2px);
  box-shadow: var(--shadow-sm); background: var(--bg-card-hover, var(--bg-card));
}
.embedded-card .ec-title { font-weight: 600; font-size: 1.05rem; margin-bottom: .4rem; }
.embedded-card .ec-desc  { font-size: .85rem; color: var(--text-secondary); line-height: 1.5; }
.embedded-card .ec-footer {
  display: flex; justify-content: flex-end; margin-top: 1rem;
  color: var(--text-muted); font-size: .9rem; transition: var(--transition);
}
.embedded-card:hover .ec-footer { color: var(--text-secondary); }

/* ── Highlight.js overrides ─────────────────────────────── */
.hljs { background: var(--bg-secondary) !important; color: var(--text-secondary) !important; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .theory-page { padding: 0 1rem 3rem; }
  .toc { padding: 1rem 1.2rem; }
  .interactive-widget { padding: 1.2rem; }
  .widget-controls { flex-direction: column; }
  .math-block { padding: 1rem; }
  .compare-table { font-size: .8rem; }
  .compare-table th, .compare-table td { padding: .5rem .6rem; }
  .flow-diagram { flex-direction: column; }
  .flow-arrow { transform: rotate(90deg); }
  .pros-cons { grid-template-columns: 1fr; }
  .detail-drawer-panel { width: 92vw; }
}
