:root {
  --color-primary: #2B9BA6;
  --color-primary-dark: #1E5F66;
  --color-primary-light: #4ECDC4;
  --color-accent: #F39C12;
  --color-bg: #F8FAFC;
  --color-bg-white: #FFFFFF;
  --color-text: #1F2937;
  --color-text-light: #6B7280;
  --color-border: #E5E7EB;
  --color-surface: rgba(255, 255, 255, 0.94);
  --color-border-accent: rgba(43, 155, 166, 0.14);
  --font-heading: "Nunito", "Segoe UI", sans-serif;
  --font-body: "Open Sans", "Segoe UI", sans-serif;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-app-card: 0 12px 40px rgba(31, 41, 55, 0.08);
  --bg: var(--color-bg);
  --card: var(--color-bg-white);
  --text: var(--color-text);
  --muted: var(--color-text-light);
  --accent: var(--color-primary);
  --accent-soft: #2b9ba61f;
  --border: var(--color-border);
  --radius: var(--radius-lg);
  --shadow: var(--shadow-app-card);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.2;
}

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* —— Header igual que CNB —— */
.app-header {
  background: #fffffff0;
  border-bottom: 1px solid var(--color-border-accent);
  position: sticky;
  top: 0;
  z-index: 100;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  gap: 1rem;
}
.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
}
.logo-img,
.logo-mark {
  height: 40px;
  width: 40px;
  display: block;
  flex-shrink: 0;
}
.logo-mark svg { display: block; }
.logo-text {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-primary-dark);
}
.nav-desktop {
  display: none;
  gap: 0.5rem;
  align-items: center;
}
.nav-link {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--color-text);
  text-decoration: none;
  transition: all 0.2s ease;
}
.nav-link:hover {
  background: var(--color-bg);
  color: var(--color-primary);
}
.nav-link.active {
  background: var(--color-primary);
  color: #fff;
}
.menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--color-text);
  cursor: pointer;
}
.menu-toggle:hover { background: var(--color-bg); }
.nav-mobile {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0 1rem;
  border-top: 1px solid var(--color-border);
}
.nav-mobile[hidden] { display: none !important; }
.nav-link-mobile {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
}
.nav-link-mobile:hover {
  background: var(--color-bg);
  color: var(--color-primary);
}
.nav-link-mobile.active {
  background: var(--color-primary);
  color: #fff;
}
@media (min-width: 900px) {
  .nav-desktop { display: flex; }
  .menu-toggle { display: none; }
  .nav-mobile { display: none !important; }
}

/* —— Página (como layout-page-shell CNB) —— */
.layout-page-shell {
  min-height: calc(100vh - 64px);
  padding: clamp(2rem, 5vw, 3.5rem) 0 clamp(2.75rem, 8vw, 5rem);
  background:
    radial-gradient(circle at 12% 10%, rgba(243, 156, 18, 0.078), transparent 28%),
    radial-gradient(circle at 88% 6%, rgba(78, 205, 196, 0.11), transparent 32%),
    linear-gradient(to bottom, var(--color-bg-white), var(--color-bg));
}
.main.layout-page-shell.main-reader {
  max-width: 1280px;
  padding-top: 1.25rem;
  background: #eef2f6;
}

.page-intro {
  text-align: center;
  margin-bottom: clamp(1.75rem, 4vw, 3rem);
  max-width: 44rem;
  margin-inline: auto;
}
.ui-eyebrow {
  display: inline-flex;
  align-items: center;
  padding: 0.42rem 0.85rem;
  border-radius: 999px;
  background: #2b9ba61f;
  color: var(--color-primary-dark);
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.085em;
  text-transform: uppercase;
  margin-bottom: 0.85rem;
}
.page-title-main {
  font-size: clamp(2rem, 5vw, 3.15rem);
  font-weight: 800;
  color: var(--color-text);
  font-family: var(--font-heading);
  line-height: 1.15;
  margin: 0 0 0.65rem;
}
.page-lead {
  font-size: 1.05rem;
  color: var(--color-text-light);
  line-height: 1.7;
  margin: 0;
}

.section-header {
  text-align: center;
  margin-bottom: 1.75rem;
}
.section-title {
  margin: 0 0 0.25rem;
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
}
.section-subtitle {
  color: var(--color-text-light);
  font-size: 0.9rem;
  margin: 0;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 1.25rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.breadcrumb a {
  color: var(--color-primary-dark);
  text-decoration: none;
  font-weight: 600;
}
.breadcrumb span.sep { opacity: 0.5; }

/* —— Tarjetas tipo niveles CNB —— */
.niveles-grid,
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}
@media (max-width: 900px) {
  .niveles-grid,
  .grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 500px) {
  .niveles-grid,
  .grid { grid-template-columns: 1fr; }
}

.nivel-card,
.card {
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 1.35rem 1.1rem 1.2rem;
  box-shadow: var(--shadow-app-card);
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  min-height: 100%;
}
.nivel-card:hover,
.card:hover {
  transform: translateY(-3px);
  border-color: rgba(43, 155, 166, 0.35);
  box-shadow: var(--shadow-lg);
}
.nivel-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  margin-bottom: 0.25rem;
}
.nivel-icon svg { width: 26px; height: 26px; }
.nivel-card h3,
.card h3 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--color-text);
  line-height: 1.25;
}
.nivel-card p,
.card p {
  margin: 0;
  color: var(--color-text-light);
  font-size: 0.88rem;
  line-height: 1.45;
  flex: 1;
}
.nivel-badge {
  display: inline-flex;
  align-items: center;
  margin-top: 0.35rem;
  padding: 0.28rem 0.75rem;
  border-radius: 999px;
  font-family: var(--font-heading);
  font-size: 0.78rem;
  font-weight: 800;
  background: var(--accent-soft);
  color: var(--color-primary-dark);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin: 0 auto 1.75rem;
}
.stat {
  background: var(--accent-soft);
  color: var(--color-primary-dark);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
}

.loading, .error {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.error { border-color: #efb8b8; color: #8a1f1f; background: #fff5f5; }
.error .hint { color: var(--muted); margin: 0.5rem 0 0; font-size: 0.9rem; }

/* —— Lector —— */
body.mode-reader { background: #eef2f6; }
.reader-shell { padding-bottom: 2rem; }
.reader-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 900px) {
  .reader-layout { grid-template-columns: 1fr; }
}

.sidebar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  max-height: 80vh;
  overflow: auto;
  position: sticky;
  top: 5rem;
  box-shadow: var(--shadow);
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  padding: 0 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-head h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 800;
}
.sidebar-count {
  background: var(--accent-soft);
  color: var(--color-primary-dark);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 700;
}
.chapter-btn {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 0.55rem;
  align-items: start;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  padding: 0.55rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  margin-bottom: 0.2rem;
}
.chapter-btn:hover { background: var(--accent-soft); }
.chapter-btn.active {
  background: var(--color-primary-dark);
  color: #fff;
  border-color: var(--color-primary-dark);
}
.cap-num {
  font-weight: 700;
  font-size: 0.8rem;
  opacity: 0.75;
  padding-top: 0.1rem;
}
.cap-title { font-size: 0.9rem; line-height: 1.35; }

.reading {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem 1.5rem;
  min-height: 520px;
  box-shadow: var(--shadow);
}
.chapter-article { max-width: 78ch; margin: 0 auto; }
.chapter-header-ui {
  border-bottom: 2px solid var(--border);
  padding-bottom: 1rem;
  margin-bottom: 1.25rem;
}
.chapter-kicker {
  margin: 0 0 0.35rem;
  color: var(--color-primary);
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}
.chapter-header-ui h1 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: clamp(1.35rem, 2.4vw, 1.85rem);
  font-weight: 800;
  line-height: 1.25;
  color: var(--color-text);
}
.chapter-sub {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.chapter-content {
  font-family: var(--font-body);
  color: #1e3a5f;
  line-height: 1.7;
}
.chapter-content[data-font="sm"] { font-size: 0.95rem; }
.chapter-content[data-font="md"] { font-size: 1.05rem; }
.chapter-content[data-font="lg"] { font-size: 1.18rem; }
.chapter-content[data-font="xl"] { font-size: 1.32rem; }
.chapter-content h2 {
  font-family: var(--font-heading);
  color: #1a5276;
  font-size: 1.35rem;
  font-weight: 700;
  margin: 1.75rem 0 0.85rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--border);
  line-height: 1.28;
}
.chapter-content h3 {
  font-family: var(--font-heading);
  color: #2980b9;
  font-size: 1.12rem;
  font-weight: 700;
  margin: 1.25rem 0 0.65rem;
  line-height: 1.28;
}
.chapter-content h4 {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  margin: 1rem 0 0.5rem;
}
.chapter-content p { margin: 0 0 1rem; }
.chapter-content img,
.chapter-content svg { max-width: 100%; height: auto; }
.chapter-content ul,
.chapter-content ol { margin: 0 0 1rem 1.2rem; }
.chapter-content li { margin-bottom: 0.35rem; }

.chapter-content .block {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 1.1rem 0;
  overflow: hidden;
  background: #f8fafc;
}
.chapter-content .block-header {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.85rem;
  padding: 0.55rem 0.85rem;
  background: #e8eef5;
  color: #1a3a5c;
}
.chapter-content .block-body { padding: 0.85rem 1rem 0.2rem; }
.chapter-content .block.definition .block-header { background: #e7f5ef; color: #1d6b45; }
.chapter-content .block.note .block-header { background: #fff4e5; color: #9a5b00; }
.chapter-content .block.example .block-header { background: #e8f1fb; color: #0b5cab; }
.chapter-content .block.warning .block-header { background: #fdecec; color: #9b1c1c; }

.reader-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}
.reader-toolbar.bottom {
  margin: 1.5rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  justify-content: space-between;
}
.toolbar-left,
.toolbar-right { display: flex; gap: 0.4rem; }
.toolbar-center {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}
.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.9rem;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.book-list { display: grid; gap: 0.65rem; }
.book-item {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
}
.book-item:hover {
  border-color: rgba(43, 155, 166, 0.4);
  background: #fbfdff;
}
.book-item strong {
  display: block;
  margin-bottom: 0.15rem;
  font-family: var(--font-heading);
  font-weight: 700;
}
.book-item small { color: var(--muted); }

.chapter-content .cnb-book,
.chapter-content .kid-book,
.chapter-content .uni-basico,
.chapter-content .capitulo,
.chapter-content .lesson,
.chapter-content .unit {
  font-family: var(--font-heading);
}
