/* =========================
   READER
========================= */
.reader-shell { display: grid; grid-template-columns: 312px minmax(0, 1fr) 420px; gap: 32px; padding: 24px; align-items: start; }
.reader-sidebar { display: flex; flex-direction: column; gap: 18px; }
.reader-main { min-width: 0; background: #ffffff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; max-width: 1014px; width: 100%; }
.reader-title { margin: 0 0 8px 0; font-size: 2rem; font-weight: 800; color: var(--text); }
.reader-meta { color: var(--muted); font-size: 0.9375rem; margin-bottom: 12px; font-style: italic; }
.reader-separator { border: none; border-top: 1px solid var(--line); margin: 0 0 22px 0; }
.reader-body { line-height: 1.7; counter-reset: h2; display: flow-root; }
.reader-main .reader-body { max-width: 120ch; }
.reader-body h2, .reader-body h3, .reader-body h4, .reader-heading { font-weight: 800; color: var(--text); clear: both; line-height: 1.35; }
.reader-body h2, .reader-heading { font-size: 1.5rem; margin: 22px 0 10px 0; padding-left: 0; counter-reset: h3; }
.reader-body h3 { font-size: 1.25rem; margin: 14px 0 8px 0; padding-left: 18px; counter-reset: h4; }
.reader-body h4 { font-size: 1.0625rem; margin: 10px 0 6px 0; padding-left: 36px; }
.reader-body h2::before { counter-increment: h2; content: counter(h2) ". "; }
.reader-body h3::before { counter-increment: h3; content: counter(h2) "." counter(h3) " "; }
.reader-body h4::before { counter-increment: h4; content: counter(h2) "." counter(h3) "." counter(h4) " "; }
.reader-body p, .reader-paragraph { margin: 0 0 18px 0; line-height: 1.68; text-align: justify; color: #2b3240; font-size: 1rem; max-width: none; }
.reader-body a { color: var(--accent); text-decoration: underline; cursor: pointer; }
.reader-body::after { content: ""; display: block; clear: both; }

/* =========================
   READER: COVER / INFOBOX / TOC
========================= */
.cover-card, .wiki-box, .toc-card { background: #ffffff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 18px; }
.cover-image-large, .cover-image { width: 100%; display: block; border-radius: 12px; }
.cover-image-caption, .cover-caption { margin-top: 10px; text-align: center; color: var(--muted); font-style: italic; font-size: 0.8125rem; }
.wiki-box-inner { display: flex; flex-direction: column; }
.wiki-box-section, .wiki-section-title, .wiki-box-title { text-align: center; font-weight: 800; font-size: 1.125rem; color: var(--text); padding: 12px 8px; border-bottom: 1px solid var(--line); background: #f7f8fb; }
.wiki-box-row, .wiki-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px 8px; border-bottom: 1px solid var(--line); }
.wiki-box-row:last-child, .wiki-row:last-child { border-bottom: none; }
.wiki-box-label, .wiki-label { font-weight: 700; color: var(--text); }
.wiki-box-value, .wiki-value { color: #344054; word-break: break-word; }
.toc-card { margin-bottom: 28px; }
.toc-title { font-size: 1.125rem; font-weight: 800; margin-bottom: 10px; }
#readerTocItems { display: flex; flex-direction: column; gap: 8px; }
.toc-link { display: block; width: 100%; border: none; background: transparent; text-align: left; padding: 4px 0; color: #344054; cursor: pointer; font: inherit; }
.toc-link:hover { text-decoration: underline; }
.toc-link.level-2 { padding-left: 0; font-weight: 600; }
.toc-link.level-3 { padding-left: 18px; font-weight: 400; }
.toc-link.level-4 { padding-left: 36px; font-weight: 400; }

/* =========================
   READER: EMBEDDED IMAGES
========================= */
.reader-media { margin: 18px 0 22px 0; clear: both; text-align: center; }
.reader-media img, .reader-float img { display: block; width: 100%; height: auto; border-radius: 12px; }
.reader-media figcaption, .reader-float figcaption { margin-top: 8px; font-size: 0.875rem; color: var(--muted); font-style: italic; text-align: center; }
.reader-media-center { width: min(520px, 100%); margin: 18px auto 22px auto; }
.reader-float { width: 180px; margin-top: 6px; margin-bottom: 14px; }
.reader-main .reader-float { width: 234px; }
.reader-float-left { float: left; margin: 0 24px 14px 0; }
.reader-float-right { float: right; margin: 0 0 14px 24px; }

/* =========================
   READER: RELATED SIDEBAR
========================= */
.reader-related { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.reader-related-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 14px; min-width: 0; }
.reader-related-title { font-size: 1rem; font-weight: 800; color: var(--text); margin-bottom: 12px; }
.reader-related-list { display: flex; flex-direction: column; gap: 10px; }
.reader-related-item { width: 100%; border: 1px solid var(--line); border-radius: 14px; background: #ffffff; padding: 10px; display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 10px; align-items: start; text-align: left; cursor: pointer; transition: 0.18s ease; box-sizing: border-box; }
.reader-related-item:hover { background: #fafcff; border-color: #b7c6df; transform: translateY(-1px); }
.reader-related-thumb-wrap { width: 84px; height: 110px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #f7f8fb; flex-shrink: 0; }
.reader-related-thumb-wrap.empty { display: flex; align-items: center; justify-content: center; background: #f7f8fb; }
.reader-related-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.reader-related-thumb-empty { padding: 8px; text-align: center; font-size: 0.78rem; line-height: 1.25; color: var(--muted); font-weight: 600; }
.reader-related-item-body { min-width: 0; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.reader-related-item-title { font-size: 0.95rem; font-weight: 700; color: var(--text); line-height: 1.35; word-break: break-word; }
.reader-related-item-meta { font-size: 0.82rem; color: var(--muted); line-height: 1.3; }

/* Overrides de Tema (Dark) */
:root.dark .reader-main, :root.dark .cover-card, :root.dark .wiki-box, :root.dark .toc-card, :root.dark .reader-related-card { background: var(--panel); border-color: var(--line); color: var(--text); }
:root.dark .reader-title, :root.dark .toc-title, :root.dark .reader-body p, :root.dark .reader-paragraph, :root.dark .wiki-box-label, :root.dark .wiki-label, :root.dark .toc-link, :root.dark .wiki-box-section, :root.dark .wiki-section-title, :root.dark .wiki-box-title { color: var(--text); }
:root.dark .reader-meta, :root.dark .wiki-box-value, :root.dark .wiki-value { color: var(--muted); }
:root.dark .reader-separator, :root.dark .wiki-box-row, :root.dark .wiki-row { border-color: var(--line); }
:root.dark .wiki-box-section, :root.dark .wiki-section-title, :root.dark .wiki-box-title { background: #202634; border-bottom-color: var(--line); }
:root.dark .reader-related-item { background: #1b2130; border-color: var(--line); }
:root.dark .reader-related-item:hover { background: #22293a; border-color: #3c4961; }
:root.dark .reader-related-thumb-wrap, :root.dark .reader-related-thumb-wrap.empty { background: #161c28; border-color: var(--line); }
:root.dark .reader-related-thumb-empty { color: var(--muted); }

/* Overrides de Tema (Crema) */
:root.crema .reader-main, :root.crema .cover-card, :root.crema .wiki-box, :root.crema .toc-card, :root.crema .reader-related-card { background: var(--panel); border-color: var(--line); color: var(--text); }
:root.crema .reader-related-item { background: #fff8ee; border-color: var(--line); }
:root.crema .reader-related-item:hover { background: #fff3e4; border-color: #d6b78f; }
:root.crema .reader-related-thumb-wrap, :root.crema .reader-related-thumb-wrap.empty { background: #f8efe3; border-color: var(--line); }

/* Responsive */
@media (max-width: 1100px) {
  .reader-shell { grid-template-columns: 1fr; }
  .reader-sidebar { order: 2; }
  .reader-main { order: 1; }
  .reader-related { order: 3; }
}
@media (max-width: 900px) {
  .reader-media-left, .reader-media-right { display: block; }
  .reader-image { width: min(320px, 100%); margin-bottom: 14px; }
  .reader-media-center .reader-image { width: min(420px, 100%); }
}
@media (max-width: 640px) {
  .reader-related-item { grid-template-columns: 72px minmax(0, 1fr); gap: 8px; }
  .reader-related-thumb-wrap { width: 72px; height: 96px; }
}
