/* Knowledge Hub readability repair
   Loaded after the existing site/page styles so every Knowledge page keeps
   the same layout while using reliable contrast in both themes. */

:root {
  --kh-surface: #ffffff;
  --kh-surface-2: #f8fafc;
  --kh-surface-3: #eef2ff;
  --kh-heading: #111827;
  --kh-text: #334155;
  --kh-muted: #64748b;
  --kh-border: #dbe3ef;
  --kh-link: #4338ca;
  --kh-shadow: 0 12px 30px rgba(15, 23, 42, .07);
}

:root[data-theme="dark"] {
  --kh-surface: #18152e;
  --kh-surface-2: #211d3d;
  --kh-surface-3: #29234f;
  --kh-heading: #f8fafc;
  --kh-text: #dbe4f0;
  --kh-muted: #aebbd0;
  --kh-border: rgba(184, 176, 255, .20);
  --kh-link: #a5b4fc;
  --kh-shadow: 0 14px 34px rgba(0, 0, 0, .28);
}

/* ---------- Main Knowledge / Numerical hubs ---------- */
.nm-section-head h2,
.nm-section-head h3,
.section-heading h2,
.section-heading h3,
.left-heading h2,
.left-heading h3 {
  color: var(--kh-heading) !important;
}

.nm-section-head p,
.section-heading p,
.left-heading p {
  color: var(--kh-muted) !important;
}

.nm-stat,
.nm-card,
.lesson-toc,
.lesson-section,
.lesson-nav a,
.knowledge-card,
.knowledge-topic-card,
.related-link,
.article-main,
.article-aside,
.article-section,
.article-box,
.page-panel,
.know-box,
.summary-box,
.decision-card,
.evidence-card,
.library-card,
.transfer-card,
.history-card,
.competition-card,
.article-resource-grid > * {
  background: var(--kh-surface) !important;
  border-color: var(--kh-border) !important;
  box-shadow: var(--kh-shadow) !important;
  color: var(--kh-text) !important;
}

.nm-stat strong,
.nm-card h3,
.nm-card h4,
.lesson-toc strong,
.lesson-section h2,
.lesson-section h3,
.lesson-nav a,
.knowledge-card h2,
.knowledge-card h3,
.knowledge-topic-card h2,
.knowledge-topic-card h3,
.article-main h1,
.article-main h2,
.article-main h3,
.article-aside h2,
.article-aside h3,
.article-section h2,
.article-section h3,
.article-box h2,
.article-box h3,
.page-panel h1,
.page-panel h2,
.related-link,
.decision-card h3,
.evidence-card h3,
.library-card h3,
.transfer-card h3,
.history-card h3,
.competition-card h2,
.competition-card h3 {
  color: var(--kh-heading) !important;
}

.nm-stat span,
.nm-card p,
.nm-level,
.lesson-toc a,
.lesson-section p,
.lesson-section li,
.knowledge-card p,
.knowledge-topic-card p,
.article-main p,
.article-main li,
.article-section p,
.article-section li,
.article-box p,
.article-box li,
.page-panel p,
.article-meta,
.source-meta,
.competition-card p,
.competition-card__meta,
.related-learning p {
  color: var(--kh-muted) !important;
}

.nm-card-footer,
.nm-card-footer > span:first-child,
.text-link,
.toc-list a,
.related-link:hover,
.lesson-toc a:hover {
  color: var(--kh-link) !important;
}

.nm-number,
.icon-badge {
  background: var(--kh-surface-3) !important;
  color: var(--kh-link) !important;
  border-color: var(--kh-border) !important;
}

.nm-status,
.hub-status,
.status-verified_current {
  background: rgba(16, 185, 129, .14) !important;
  color: #059669 !important;
  border-color: rgba(16, 185, 129, .28) !important;
}

:root[data-theme="dark"] .nm-status,
:root[data-theme="dark"] .hub-status,
:root[data-theme="dark"] .status-verified_current {
  color: #6ee7b7 !important;
}

.nm-status.soon,
.hub-status.soon {
  background: rgba(249, 115, 22, .13) !important;
  color: #c2410c !important;
  border-color: rgba(249, 115, 22, .25) !important;
}

:root[data-theme="dark"] .nm-status.soon,
:root[data-theme="dark"] .hub-status.soon {
  color: #fdba74 !important;
}

/* ---------- Article and lesson content ---------- */
.formula-box,
.codex-slot,
.key-idea,
.faq-list,
.quick-facts > div,
.two-column-facts > div,
.center-split > div,
.subject-matrix > div,
.round-flow > div {
  background: var(--kh-surface-2) !important;
  border-color: var(--kh-border) !important;
  color: var(--kh-text) !important;
}

.formula-box,
.formula-box *,
.key-idea,
.key-idea *,
.codex-slot,
.codex-slot * {
  color: var(--kh-text) !important;
}

.faq-list h3,
.quick-facts dt,
.two-column-facts h3,
.subject-matrix strong {
  color: var(--kh-heading) !important;
}

.faq-list p,
.quick-facts dd,
.two-column-facts p,
.subject-matrix p {
  color: var(--kh-muted) !important;
}

.article-aside,
.lesson-toc {
  background: var(--kh-surface-2) !important;
}

.article-aside a,
.lesson-toc a,
.toc-list a {
  color: var(--kh-link) !important;
}

/* ---------- Notes and callouts ---------- */
.nm-note,
.source-note,
.fee-callout,
.caution-section,
.warning-box,
.transfer-panel,
.comparison-note,
.report-panel {
  color: var(--kh-text) !important;
  border-color: var(--kh-border) !important;
}

:root[data-theme="dark"] .nm-note {
  background: #2a2417 !important;
  color: #fde68a !important;
  border-color: rgba(245, 158, 11, .35) !important;
}

:root[data-theme="dark"] .source-note,
:root[data-theme="dark"] .fee-callout,
:root[data-theme="dark"] .caution-section,
:root[data-theme="dark"] .comparison-note {
  background: #1d2945 !important;
  color: #dbeafe !important;
}

/* ---------- Breadcrumbs and metadata ---------- */
.nm-breadcrumb,
.nm-breadcrumb span,
.breadcrumb,
.breadcrumb span,
.article-meta,
.source-meta {
  color: var(--kh-muted) !important;
}

.nm-breadcrumb a,
.breadcrumb a {
  color: var(--kh-link) !important;
}

/* ---------- Tables ---------- */
.competition-table,
.lesson-table,
table {
  color: var(--kh-text) !important;
  border-color: var(--kh-border) !important;
}

.competition-table th,
.lesson-table th,
table th {
  background: var(--kh-surface-3) !important;
  color: var(--kh-heading) !important;
  border-color: var(--kh-border) !important;
}

.competition-table td,
.lesson-table td,
table td {
  background: var(--kh-surface) !important;
  color: var(--kh-text) !important;
  border-color: var(--kh-border) !important;
}

/* ---------- Dark theme: remove pale cards and faint text ---------- */
:root[data-theme="dark"] .nm-card:hover,
:root[data-theme="dark"] .knowledge-card:hover,
:root[data-theme="dark"] .knowledge-topic-card:hover,
:root[data-theme="dark"] .related-link:hover {
  background: #242044 !important;
  border-color: rgba(129, 140, 248, .55) !important;
}

:root[data-theme="dark"] .pill,
:root[data-theme="dark"] .eyebrow {
  color: #e0e7ff !important;
}

/* Cards that are intentionally unavailable must remain readable, not faded. */
.nm-card:not(a),
.knowledge-card[aria-disabled="true"],
.knowledge-topic-card[aria-disabled="true"] {
  opacity: 1 !important;
}

/* ---------- Mobile readability ---------- */
@media (max-width: 640px) {
  .nm-stat,
  .nm-card,
  .knowledge-card,
  .knowledge-topic-card,
  .article-section,
  .article-box,
  .related-link {
    padding: 16px !important;
  }

  .nm-card {
    min-height: 0 !important;
  }

  .nm-card h3,
  .knowledge-card h2,
  .knowledge-card h3,
  .knowledge-topic-card h2,
  .knowledge-topic-card h3 {
    font-size: 1.08rem !important;
  }

  .nm-card p,
  .knowledge-card p,
  .knowledge-topic-card p,
  .article-section p,
  .article-section li {
    font-size: .94rem !important;
    line-height: 1.65 !important;
  }
}
