/* ============================================================================
   BIA Learn — Quantum Mechanics Course UX, Focus Mode, Mobile Zero-Overflow,
   Personalized Tracks, Biochemical Spotlights & Unified Studio Footer (v2.0)
   ============================================================================ */

/* 1. GLOBAL ZERO-OVERFLOW & MOBILE SAFETY (390px+ GUARANTEED, VERTICAL SCROLL + STICKY PRESERVED) */
html {
  max-width: 100%;
  overflow-y: auto;
}

body {
  max-width: 100%;
  overflow-x: clip;
}

section[id^="ch"],
section[id^="sec-"],
.study-body,
.chapter-section,
.book-chapter,
.qm-lab-card,
.qm-widget,
.textbook-pedagogy-panel,
.hero {
  max-width: 100%;
  box-sizing: border-box;
}

.book-layout,
.container,
main.container {
  width: 100%;
  max-width: var(--read-width, 1320px);
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

.hero-content {
  width: 100%;
  max-width: 1180px;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

section[id^="ch"],
section[id^="sec-"],
.hero,
.qm-hub-dashboard,
.qm-luso-bridge,
.studio-footer {
  overflow-x: clip;
}

.katex-mathml {
  width: 1px !important;
  max-width: 1px !important;
  overflow: hidden !important;
}

select,
input[type="text"],
input[type="search"],
textarea {
  max-width: 100%;
  box-sizing: border-box;
}

.book-layout img,
.book-chapter img,
.study-body img,
.qm-figure-card img,
figure img {
  max-width: 100%;
  height: auto !important;
  max-height: none !important;
  object-fit: contain !important;
}


/* Preserve crisp aspect ratios on pioneer portraits (never stretch circles into ovals) */
.textbook-pedagogy-panel img {
  width: 54px !important;
  height: 54px !important;
  object-fit: cover !important;
  object-position: center 20% !important;
}
.qm-giant-mini-img,
.bio-portrait-img,
.pioneer-photo,
.m0-pioneer-img {
  height: 100% !important;
  object-fit: cover !important;
  object-position: center 18% !important;
}

.book-layout figure img,
.qm-figure-card img {
  cursor: zoom-in;
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.book-layout figure img:hover,
.qm-figure-card img:hover {
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
}

.book-layout svg:not(.katex svg),
.book-chapter svg:not(.katex svg),
.qm-widget svg:not(.katex svg),
.qm-lab-card svg:not(.katex svg),
.book-layout canvas,
.qm-widget canvas {
  max-width: 100%;
  height: auto;
}

/* [CYCLE 4 P0-1] Preserve native KaTeX SVG dimensions (radicals, underbrace, overbrace, stretchy arrows) */
.katex svg,
.katex-display svg,
.book-layout .katex svg,
.book-chapter .katex svg,
.qm-widget .katex svg,
.qm-lab-card .katex svg {
  max-width: none !important;
  height: inherit !important;
}

.book-layout pre,
.book-chapter pre,
.study-body pre {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* KaTeX Display Math Scroll Safety on Narrow Screens */
.katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0.1rem 0.45rem;
  -webkit-overflow-scrolling: touch;
}

.katex-display > .katex {
  white-space: nowrap;
}

/* Responsive Scroll Wrapper for All Tables */
.qm-table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
  border-radius: 10px;
}

.qm-table-scroll > table {
  margin: 0 !important;
  min-width: 100%;
}

/* Fallback if a table is not yet wrapped */
.book-layout table,
.study-body table,
.container table {
  max-width: 100%;
}

/* 2. UNIFIED SLEEK TOP NAVBAR REFINEMENTS */
header.navbar {
  position: sticky;
  top: 0;
  z-index: 950;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

header.navbar .nav-container {
  max-width: 1320px;
  gap: 0.55rem;
}

header.navbar .nav-links {
  gap: 0.16rem;
  flex-wrap: nowrap;
}

header.navbar .nav-links a {
  white-space: nowrap;
  font-size: 0.81rem;
  padding: 0.32rem 0.52rem;
  border-radius: 8px;
}

/* 3. STICKY CHAPTER / SECTION FOCUS SWITCHER BAR */
body[data-qm-focus-active="1"] nav.Quick-nav,
body[data-qm-focus-active="1"] .Quick-nav,
body[data-qm-focus-active="1"] .chapter-pager {
  display: none !important;
}

.qm-focus-bar {
  position: sticky;
  top: 66px;
  z-index: 820;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 16px;
  padding: 0.8rem 1rem;
  margin: 0 auto 1.4rem;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

html[data-theme="dark"] .qm-focus-bar {
  background: rgba(15, 23, 42, 0.94);
  border-color: rgba(71, 85, 105, 0.55);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.38);
}

.qm-focus-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.qm-focus-pills {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.42rem;
}

.qm-ch-pill {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(248, 250, 252, 0.95);
  color: #1e293b;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.42rem 0.78rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.16s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  line-height: 1.2;
}

html[data-theme="dark"] .qm-ch-pill {
  background: rgba(30, 41, 59, 0.9);
  color: #e2e8f0;
  border-color: rgba(100, 116, 139, 0.45);
}

.qm-ch-pill:hover {
  border-color: #2563eb;
  color: #2563eb;
  transform: translateY(-1px);
}

html[data-theme="dark"] .qm-ch-pill:hover {
  border-color: #38bdf8;
  color: #38bdf8;
}

.qm-ch-pill.is-active {
  background: linear-gradient(135deg, #0369a1, #1d4ed8);
  color: #ffffff !important;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.32);
}

.qm-ch-pill.is-done::after {
  content: "✓";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #10b981;
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 900;
}

.qm-ch-pill.is-active.is-done::after {
  background: rgba(255, 255, 255, 0.25);
}

.qm-focus-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.qm-mode-toggle {
  appearance: none;
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: rgba(99, 102, 241, 0.08);
  color: #4f46e5;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.38rem 0.72rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

html[data-theme="dark"] .qm-mode-toggle {
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.16);
  border-color: rgba(129, 140, 248, 0.4);
}

.qm-mode-toggle:hover {
  background: rgba(99, 102, 241, 0.18);
}

.qm-progress-mini {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.76rem;
  font-weight: 700;
  color: #475569;
}

html[data-theme="dark"] .qm-progress-mini {
  color: #94a3b8;
}

.qm-progress-track {
  flex: 1;
  min-width: 90px;
  height: 7px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.28);
  overflow: hidden;
}

.qm-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0ea5e9, #10b981);
  transition: width 0.35s ease;
}

/* Hidden non-active chapters in Focus Mode */
.qm-focus-hidden {
  display: none !important;
}

/* 4. BOTTOM-OF-CHAPTER MASTERY & PREV/NEXT PAGER */
.qm-ch-pager {
  margin: 2.25rem 0 1.25rem;
  padding: 1.25rem 1.35rem;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.07), rgba(16, 185, 129, 0.06));
  border: 1px solid rgba(14, 165, 233, 0.25);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

html[data-theme="dark"] .qm-ch-pager {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.12), rgba(16, 185, 129, 0.09));
  border-color: rgba(56, 189, 248, 0.28);
}

.qm-ch-pager-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.qm-complete-btn {
  appearance: none;
  border: 1.5px solid #10b981;
  background: rgba(16, 185, 129, 0.1);
  color: #047857;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 800;
  padding: 0.56rem 1.05rem;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.18s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

html[data-theme="dark"] .qm-complete-btn {
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.15);
}

.qm-complete-btn.is-done {
  background: #10b981;
  color: #ffffff !important;
  border-color: #10b981;
}

.qm-ch-pager-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.qm-pager-card {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  padding: 0.9rem 1.05rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.34);
  text-decoration: none;
  color: #0f172a;
  cursor: pointer;
  transition: all 0.18s ease;
  text-align: left;
  font-family: inherit;
}

html[data-theme="dark"] .qm-pager-card {
  background: rgba(15, 23, 42, 0.85);
  border-color: rgba(71, 85, 105, 0.55);
  color: #f1f5f9;
}

.qm-pager-card:hover {
  border-color: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.14);
}

.qm-pager-card.is-next {
  text-align: right;
  border-color: rgba(37, 99, 235, 0.35);
}

.qm-pager-dir {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #0284c7;
}

html[data-theme="dark"] .qm-pager-dir {
  color: #38bdf8;
}

.qm-pager-title {
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.35;
}

/* 5. COLLAPSIBLE BLOCK PEDAGOGY ACCORDION */
.qm-pedagogy-accordion {
  margin: 0 0 1.4rem;
  border-radius: 16px;
  border: 1px solid rgba(99, 102, 241, 0.28);
  background: rgba(248, 250, 252, 0.88);
  overflow: hidden;
}

html[data-theme="dark"] .qm-pedagogy-accordion {
  background: rgba(15, 23, 42, 0.72);
  border-color: rgba(129, 140, 248, 0.32);
}

.qm-pedagogy-accordion > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.95rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-weight: 800;
  font-size: 0.94rem;
  color: #312e81;
  user-select: none;
}

html[data-theme="dark"] .qm-pedagogy-accordion > summary {
  color: #c7d2fe;
}

.qm-pedagogy-accordion > summary::-webkit-details-marker {
  display: none;
}

.qm-pedagogy-accordion > summary::after {
  content: "▾";
  font-size: 1rem;
  transition: transform 0.2s ease;
  opacity: 0.75;
}

.qm-pedagogy-accordion[open] > summary::after {
  transform: rotate(180deg);
}

.qm-pedagogy-accordion .textbook-pedagogy-panel {
  margin: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  border-top: 1px solid rgba(148, 163, 184, 0.25) !important;
}

/* 6. BIOCHEMICAL & DRUG DISCOVERY SPOTLIGHT BOXES */
.qm-bio-spotlight {
  margin: 1.6rem 0;
  padding: 1.25rem 1.45rem;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(6, 182, 212, 0.06));
  border: 1px solid rgba(16, 185, 129, 0.32);
  border-left: 5px solid #059669;
}

html[data-theme="dark"] .qm-bio-spotlight {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.13), rgba(6, 182, 212, 0.09));
  border-color: rgba(52, 211, 153, 0.35);
  border-left-color: #10b981;
}

.qm-bio-spotlight-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.55rem;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #047857;
}

html[data-theme="dark"] .qm-bio-spotlight-head {
  color: #34d399;
}

.qm-bio-spotlight h4 {
  margin: 0 0 0.55rem;
  font-size: 1.04rem;
  font-weight: 800;
  color: #0f172a;
}

html[data-theme="dark"] .qm-bio-spotlight h4 {
  color: #f8fafc;
}

.qm-bio-spotlight p {
  margin: 0 0 0.55rem;
  font-size: 0.94rem;
  line-height: 1.68;
  text-align: justify;
}

.qm-bio-spotlight p:last-child {
  margin-bottom: 0;
}

/* 7. GUIDED INDIVIDUAL EXPERIMENTATION CHALLENGE BOX */
.qm-challenge-box {
  margin: 1rem 0 1.25rem;
  padding: 0.95rem 1.15rem;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.09), rgba(139, 92, 246, 0.07));
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-left: 4px solid #d97706;
}

html[data-theme="dark"] .qm-challenge-box {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.13), rgba(139, 92, 246, 0.11));
  border-color: rgba(251, 191, 36, 0.35);
}

.qm-challenge-title {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #b45309;
  margin-bottom: 0.38rem;
}

html[data-theme="dark"] .qm-challenge-title {
  color: #fbbf24;
}

.qm-challenge-box p {
  margin: 0;
  font-size: 0.89rem;
  line-height: 1.58;
}

/* 8. COURSE HUB: PERSONALIZED TRACKS, LIVE PROGRESS & LUSOPHONE BRIDGE */
.qm-hub-dashboard {
  max-width: 1180px;
  margin: 0 auto 2rem;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.qm-hub-progress-card {
  background: linear-gradient(135deg, rgba(2, 132, 199, 0.08), rgba(16, 185, 129, 0.08));
  border: 1px solid rgba(14, 165, 233, 0.28);
  border-radius: 18px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.1rem;
}

html[data-theme="dark"] .qm-hub-progress-card {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.13), rgba(16, 185, 129, 0.1));
  border-color: rgba(56, 189, 248, 0.3);
}

.qm-hub-progress-left {
  flex: 1 1 320px;
}

.qm-hub-progress-title {
  font-size: 0.96rem;
  font-weight: 800;
  margin-bottom: 0.45rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.qm-tracks-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.qm-track-card {
  border-radius: 16px;
  padding: 1.2rem 1.25rem;
  background: var(--bg-secondary, #ffffff);
  border: 1.5px solid rgba(148, 163, 184, 0.3);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  transition: all 0.2s ease;
  cursor: pointer;
}

html[data-theme="dark"] .qm-track-card {
  background: rgba(15, 23, 42, 0.85);
  border-color: rgba(71, 85, 105, 0.5);
}

.qm-track-card:hover,
.qm-track-card.is-selected {
  border-color: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.14);
}

.qm-track-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: fit-content;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.24rem 0.66rem;
  border-radius: 999px;
}

.qm-track-badge.is-t1 { background: rgba(14, 165, 233, 0.14); color: #0369a1; }
.qm-track-badge.is-t2 { background: rgba(16, 185, 129, 0.15); color: #047857; }
.qm-track-badge.is-t3 { background: rgba(124, 58, 237, 0.14); color: #6d28d9; }

html[data-theme="dark"] .qm-track-badge.is-t1 { background: rgba(56, 189, 248, 0.18); color: #7dd3fc !important; }
html[data-theme="dark"] .qm-track-badge.is-t2 { background: rgba(52, 211, 153, 0.18); color: #6ee7b7 !important; }
html[data-theme="dark"] .qm-track-badge.is-t3 { background: rgba(167, 139, 250, 0.2); color: #ddd6fe !important; }

.qm-track-link {
  font-weight: 800;
  text-decoration: none;
}
.qm-track-link.is-t1 { color: #0284c7; }
.qm-track-link.is-t2 { color: #047857; }
.qm-track-link.is-t3 { color: #6d28d9; }

html[data-theme="dark"] .qm-track-link.is-t1 { color: #38bdf8 !important; }
html[data-theme="dark"] .qm-track-link.is-t2 { color: #34d399 !important; }
html[data-theme="dark"] .qm-track-link.is-t3 { color: #c4b5fd !important; }

.qm-track-feedback {
  display: none;
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.1);
  border: 1px solid rgba(37, 99, 235, 0.32);
  font-size: 0.86rem;
  font-weight: 700;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.65rem;
}

html[data-theme="dark"] .qm-track-feedback {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.35);
  color: #e0f2fe;
}

.qm-track-feedback.is-visible {
  display: flex;
}

.qm-track-card h3 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
  line-height: 1.3;
}

.qm-track-card p {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--text-secondary, #475569);
  flex: 1;
}

.qm-track-meta {
  font-size: 0.78rem;
  font-weight: 700;
  color: #0284c7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px dashed rgba(148, 163, 184, 0.35);
}

.qm-track-highlight {
  outline: 2.5px solid #2563eb !important;
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.12) !important;
}

.qm-luso-bridge {
  max-width: 1180px;
  margin: 2rem auto;
  padding: 1.4rem 1.55rem;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.06), rgba(16, 185, 129, 0.07));
  border: 1px solid rgba(37, 99, 235, 0.24);
}

html[data-theme="dark"] .qm-luso-bridge {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(16, 185, 129, 0.1));
  border-color: rgba(56, 189, 248, 0.28);
}

.qm-luso-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
  margin-top: 0.85rem;
}

.qm-luso-table th,
.qm-luso-table td {
  padding: 0.58rem 0.78rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  text-align: left;
}

.qm-luso-table th {
  font-weight: 800;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(148, 163, 184, 0.12);
}

/* 9. UNIFIED 3-COLUMN STUDIO FOOTER (MATCHING INDEX.HTML) */
.studio-footer {
  margin-top: 4rem;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  padding: 3rem 1.5rem 2rem;
  color: #475569;
}

html[data-theme="dark"] .studio-footer {
  background: #0b1120;
  border-top-color: #1e293b;
  color: #94a3b8;
}

.studio-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.studio-footer-grid {
  display: grid;
  grid-template-columns: 1.55fr 1fr 1.15fr;
  gap: 2.5rem;
  align-items: start;
}

.studio-footer-brand {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.studio-footer-logo {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: #0f172a;
  font-size: 1.16rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

html[data-theme="dark"] .studio-footer-logo {
  color: #f8fafc;
}

.studio-footer-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #2563eb;
  background: rgba(37, 99, 235, 0.09);
  border: 1px solid rgba(37, 99, 235, 0.22);
  padding: 0.22rem 0.62rem;
  border-radius: 999px;
  width: fit-content;
}

html[data-theme="dark"] .studio-footer-tag {
  color: #60a5fa;
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(96, 165, 250, 0.3);
}

.studio-footer-desc {
  margin: 0;
  font-size: 0.87rem;
  line-height: 1.65;
  color: #64748b;
  max-width: 370px;
}

html[data-theme="dark"] .studio-footer-desc {
  color: #94a3b8;
}

.studio-footer-col h4 {
  margin: 0 0 0.82rem;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #0f172a;
}

html[data-theme="dark"] .studio-footer-col h4 {
  color: #e2e8f0;
}

.studio-footer-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.48rem;
}

.studio-footer-links a {
  color: #475569;
  text-decoration: none;
  font-size: 0.87rem;
  font-weight: 500;
  transition: color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

html[data-theme="dark"] .studio-footer-links a {
  color: #94a3b8;
}

.studio-footer-links a:hover {
  color: #2563eb;
}

html[data-theme="dark"] .studio-footer-links a:hover {
  color: #38bdf8;
}

.studio-footer-bottom {
  margin-top: 2.2rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e2e8f0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.82rem;
  color: #64748b;
}

html[data-theme="dark"] .studio-footer-bottom {
  border-top-color: #1e293b;
  color: #94a3b8;
}

.studio-footer-bottom a {
  color: inherit;
  text-decoration: none;
  font-weight: 600;
}

/* 10. IMAGE LIGHTBOX OVERLAY */
.qm-lightbox-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(2, 6, 23, 0.92);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  cursor: zoom-out;
}

.qm-lightbox-backdrop.is-open {
  display: flex;
}

.qm-lightbox-inner {
  max-width: 96vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  cursor: default;
}

.qm-lightbox-inner img {
  max-width: 94vw;
  max-height: 82vh;
  border-radius: 12px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
  background: #0b1120;
}

.qm-lightbox-caption {
  color: #e2e8f0;
  font-size: 0.9rem;
  text-align: center;
  max-width: 900px;
  line-height: 1.45;
}

.qm-lightbox-close {
  position: fixed;
  top: 18px;
  right: 22px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  font-size: 1.35rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 11. MOBILE RESPONSIVE BREAKPOINTS (390px STRICT ZERO-OVERFLOW) */
@media (max-width: 900px) {
  .qm-tracks-grid {
    grid-template-columns: 1fr;
  }
  .studio-footer-grid {
    grid-template-columns: 1fr;
    gap: 1.75rem;
  }
}

@media (max-width: 768px) {
  header.navbar .nav-container {
    padding: 0.55rem 0.75rem !important;
    flex-wrap: wrap;
    row-gap: 0.45rem;
  }
  header.navbar .bialab-pill {
    display: none !important;
  }
  header.navbar .nav-links {
    order: 3;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }
  header.navbar .nav-links a {
    font-size: 0.78rem;
    padding: 0.3rem 0.58rem;
    flex: 0 0 auto;
  }
  .hero {
    padding: 1.5rem 0.9rem 1.35rem !important;
  }
  .hero h1 {
    font-size: clamp(1.5rem, 6.5vw, 2.1rem) !important;
    line-height: 1.18 !important;
  }
  .chapter-nav-pill {
    font-size: 0.74rem !important;
    padding: 0.4rem 0.65rem !important;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
    box-sizing: border-box;
  }
  .book-layout,
  .container,
  .qm-hub-dashboard {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }
  .qm-focus-bar {
    top: 0;
    position: relative;
    padding: 0.7rem 0.75rem;
  }
  .qm-ch-pager-nav {
    grid-template-columns: 1fr;
  }
  .qm-pager-card.is-next {
    text-align: left;
  }
  .textbook-pedagogy-panel,
  .qm-bio-spotlight,
  .qm-luso-bridge {
    padding: 1rem !important;
  }
  .textbook-pedagogy-panel > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  .qm-lab-grid,
  .qm-control-grid,
  .qm-readout-grid,
  .dft-grid,
  .dft-visual-grid,
  .dft-ing-grid,
  .atlas-controls,
  .lab-grid {
    grid-template-columns: 1fr !important;
  }
  .dft-visual-grid > *,
  .dft-viz-panel,
  .interactive-box,
  .simulator-card,
  .simulator-canvas-wrapper,
  .qm-lab-widget,
  .book-toc,
  .book-layout > *,
  .container > * {
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  .dft-viz-panel,
  .simulator-canvas-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .hero-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .hero-actions a,
  .hero-actions button {
    text-align: center;
    justify-content: center;
  }
}

/* ============================================================================
   12. WORLD-CLASS POLISH: COLLAPSIBLE TOC/HUB ACCORDIONS, 30-SEC TLDR CARDS,
       MID-CHAPTER MICRO-CHECKS, GLOBAL SEARCH (⌘K), QUANTUM UNIT CONVERTER
       & INSTITUTIONAL PRINT STYLESHEET (v3.0)
   ============================================================================ */

/* Collapsible TOC & Hub Accordions (eliminates vertical bloat above Ch. 1) */
.qm-toc-accordion,
.qm-hub-accordion {
  margin: 0 0 1rem;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.34);
  background: rgba(255, 255, 255, 0.9);
  overflow: hidden;
}

html[data-theme="dark"] .qm-toc-accordion,
html[data-theme="dark"] .qm-hub-accordion {
  background: rgba(15, 23, 42, 0.78);
  border-color: rgba(71, 85, 105, 0.52);
}

.qm-toc-accordion > summary,
.qm-hub-accordion > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.85rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-weight: 800;
  font-size: 0.92rem;
  color: #0f172a;
  user-select: none;
}

html[data-theme="dark"] .qm-toc-accordion > summary,
html[data-theme="dark"] .qm-hub-accordion > summary {
  color: #e2e8f0;
}

.qm-toc-accordion > summary::-webkit-details-marker,
.qm-hub-accordion > summary::-webkit-details-marker {
  display: none;
}

.qm-toc-accordion > summary::after,
.qm-hub-accordion > summary::after {
  content: "▾";
  font-size: 1rem;
  opacity: 0.7;
  transition: transform 0.2s ease;
}

.qm-toc-accordion[open] > summary::after,
.qm-hub-accordion[open] > summary::after {
  transform: rotate(180deg);
}

.qm-toc-accordion .book-toc {
  margin: 0 !important;
  border: none !important;
  border-top: 1px solid rgba(148, 163, 184, 0.24) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.qm-hub-accordion-body {
  padding: 0 1.25rem 1.25rem;
  border-top: 1px solid rgba(148, 163, 184, 0.22);
}

/* Compact Hero on Block Pages so Chapter 1 starts much higher */
body[data-qm-focus-active="1"] header.hero {
  padding: 1.75rem 1.5rem 1.55rem !important;
}

body[data-qm-focus-active="1"] header.hero .hero-actions {
  display: none !important;
}

/* 30-Second Intuition Card + Classic Pitfall Warning at Top of Every Chapter */
.qm-tldr-card {
  margin: 1.15rem 0 1.5rem;
  padding: 1.15rem 1.35rem;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.065), rgba(99, 102, 241, 0.055));
  border: 1px solid rgba(59, 130, 246, 0.28);
  border-left: 5px solid #2563eb;
}

html[data-theme="dark"] .qm-tldr-card {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.14), rgba(99, 102, 241, 0.11));
  border-color: rgba(96, 165, 250, 0.34);
  border-left-color: #38bdf8;
}

.qm-tldr-head {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #1d4ed8;
  margin-bottom: 0.55rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

html[data-theme="dark"] .qm-tldr-head {
  color: #60a5fa;
}

.qm-tldr-list {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  font-size: 0.92rem;
  line-height: 1.56;
}

.qm-tldr-pitfall {
  padding: 0.62rem 0.9rem;
  border-radius: 10px;
  background: rgba(245, 158, 11, 0.11);
  border: 1px solid rgba(245, 158, 11, 0.32);
  font-size: 0.86rem;
  line-height: 1.5;
  color: #92400e;
}

html[data-theme="dark"] .qm-tldr-pitfall {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(251, 191, 36, 0.34);
  color: #fde68a;
}

/* Mid-Chapter Interactive Micro-Check ("Paragem Rápida de Intuição") */
.qm-microcheck {
  margin: 1.65rem 0;
  padding: 1.15rem 1.35rem;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.08), rgba(14, 165, 233, 0.06));
  border: 1.5px solid rgba(139, 92, 246, 0.32);
}

html[data-theme="dark"] .qm-microcheck {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.14), rgba(14, 165, 233, 0.1));
  border-color: rgba(167, 139, 250, 0.36);
}

.qm-microcheck-badge {
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6d28d9;
  margin-bottom: 0.4rem;
}

html[data-theme="dark"] .qm-microcheck-badge {
  color: #c4b5fd;
}

.qm-microcheck-q {
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.52;
  margin: 0 0 0.75rem;
}

.qm-microcheck-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.qm-mc-btn {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(255, 255, 255, 0.92);
  color: #0f172a;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 0.88rem;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: left;
}

html[data-theme="dark"] .qm-mc-btn {
  background: rgba(15, 23, 42, 0.88);
  color: #f1f5f9;
  border-color: rgba(100, 116, 139, 0.55);
}

.qm-mc-btn:hover {
  border-color: #6366f1;
  transform: translateY(-1px);
}

.qm-mc-btn.is-correct {
  background: #10b981 !important;
  color: #ffffff !important;
  border-color: #059669 !important;
}

.qm-mc-btn.is-wrong {
  background: #ef4444 !important;
  color: #ffffff !important;
  border-color: #dc2626 !important;
}

.qm-microcheck-fb {
  display: none;
  margin-top: 0.72rem;
  padding: 0.72rem 0.95rem;
  border-radius: 10px;
  font-size: 0.87rem;
  line-height: 1.56;
  background: rgba(16, 185, 129, 0.11);
  border: 1px solid rgba(16, 185, 129, 0.34);
}

html[data-theme="dark"] .qm-microcheck-fb {
  background: rgba(16, 185, 129, 0.16);
  color: #d1fae5;
}

.qm-microcheck-fb.is-show {
  display: block;
}

/* Navbar Global Search Trigger Pill (⌘K) */
.qm-search-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid rgba(148, 163, 184, 0.42);
  background: rgba(248, 250, 252, 0.9);
  color: #334155;
  font-family: inherit;
  font-size: 0.79rem;
  font-weight: 700;
  padding: 0.34rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

html[data-theme="dark"] .qm-search-btn {
  background: rgba(30, 41, 59, 0.9);
  color: #e2e8f0;
  border-color: rgba(100, 116, 139, 0.5);
}

.qm-search-btn:hover {
  border-color: #2563eb;
  color: #2563eb;
}

html[data-theme="dark"] .qm-search-btn:hover {
  border-color: #38bdf8;
  color: #38bdf8;
}

.qm-search-kbd {
  font-size: 0.68rem;
  padding: 0.08rem 0.35rem;
  border-radius: 5px;
  background: rgba(148, 163, 184, 0.22);
  font-family: ui-monospace, SFMono-Regular, monospace;
}

/* Global Search Modal */
.qm-search-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9950;
  background: rgba(2, 6, 23, 0.66);
  backdrop-filter: blur(8px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 9vh 1rem 1rem;
}

.qm-search-backdrop.is-open {
  display: flex;
}

.qm-search-dialog {
  width: 100%;
  max-width: 660px;
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.35);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 76vh;
}

html[data-theme="dark"] .qm-search-dialog {
  background: #0f172a;
  border-color: #334155;
  color: #f1f5f9;
}

.qm-search-input-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.95rem 1.15rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.qm-search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 1rem;
  color: inherit;
}

.qm-search-results {
  overflow-y: auto;
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.qm-search-item {
  display: flex;
  flex-direction: column;
  gap: 0.16rem;
  padding: 0.68rem 0.85rem;
  border-radius: 11px;
  text-decoration: none;
  color: inherit;
  border: 1px solid transparent;
  transition: all 0.14s ease;
}

.qm-search-item:hover,
.qm-search-item:focus {
  background: rgba(37, 99, 235, 0.08);
  border-color: rgba(37, 99, 235, 0.28);
  outline: none;
}

html[data-theme="dark"] .qm-search-item:hover {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.32);
}

.qm-search-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.qm-search-tag {
  font-size: 0.69rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.12);
  color: #4f46e5;
  white-space: nowrap;
}

html[data-theme="dark"] .qm-search-tag {
  background: rgba(129, 140, 248, 0.2);
  color: #a5b4fc;
}

.qm-search-sub {
  font-size: 0.79rem;
  color: #64748b;
}

html[data-theme="dark"] .qm-search-sub {
  color: #94a3b8;
}

/* Floating Pocket Quantum Unit Converter (bottom-left, symmetric to bia-wayfinder) */
.qm-unit-fab {
  position: fixed;
  left: 18px;
  right: auto;
  bottom: 18px;
  z-index: 940;
  appearance: none;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: linear-gradient(135deg, #0f172a, #1e3a8a);
  color: #f8fafc;
  font-family: inherit;
  font-size: 0.81rem;
  font-weight: 800;
  padding: 0.58rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.32);
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.qm-unit-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.38);
}

.qm-unit-popover {
  position: fixed;
  left: 18px;
  right: auto;
  bottom: 68px;
  z-index: 945;
  width: min(360px, calc(100vw - 24px));
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 16px;
  padding: 1rem 1.1rem;
  box-shadow: 0 20px 52px rgba(15, 23, 42, 0.28);
  display: none;
  flex-direction: column;
  gap: 0.65rem;
}

html[data-theme="dark"] .qm-unit-popover {
  background: #0f172a;
  border-color: #334155;
  color: #f1f5f9;
}

.qm-unit-popover.is-open {
  display: flex;
}

.qm-unit-row {
  display: grid;
  grid-template-columns: 1fr 122px;
  gap: 0.45rem;
}

.qm-unit-row input,
.qm-unit-row select {
  padding: 0.46rem 0.6rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
}

.qm-unit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.qm-unit-cell {
  padding: 0.42rem 0.58rem;
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.11);
  font-size: 0.78rem;
}

.qm-unit-cell strong {
  display: block;
  font-size: 0.86rem;
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: #0284c7;
}

html[data-theme="dark"] .qm-unit-cell strong {
  color: #38bdf8;
}

.qm-unit-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.32rem;
}

.qm-unit-preset {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.38);
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 0.71rem;
  font-weight: 700;
  padding: 0.22rem 0.48rem;
  border-radius: 999px;
  cursor: pointer;
}

.qm-unit-preset:hover {
  border-color: #2563eb;
  color: #2563eb;
}

/* Institutional Print Stylesheet (@media print — clean PDF sebenta export) */
@media print {
  header.navbar,
  .qm-focus-bar,
  .qm-ch-pager,
  .qm-unit-fab,
  .qm-unit-popover,
  .qm-search-backdrop,
  .qm-lightbox-backdrop,
  .qm-toggle-all-help-btn,
  .qm-microcheck-opts,
  .hero-actions,
  .chapter-nav-pill,
  .qm-hub-dashboard,
  .studio-footer-links {
    display: none !important;
  }

  html, body {
    background: #ffffff !important;
    color: #0f172a !important;
    font-size: 11pt !important;
    overflow: visible !important;
  }

  .qm-tldr-card,
  .qm-bio-spotlight,
  .qm-challenge-box,
  figure,
  .formula-box {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none !important;
  }

  body::after {
    content: "BIA Learn — Dinâmica Molecular | Prof. Sérgio F. Sousa · BIA Lab · Universidade de Coimbra (www.bialearn.com)";
    display: block;
    margin-top: 2rem;
    padding-top: 0.75rem;
    border-top: 1px solid #cbd5e1;
    font-size: 9pt;
    color: #475569;
    text-align: center;
  }
}


/* SURGICAL_MOBILE_ZERO_OVERFLOW_2026 */
.katex-mathml {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  width: 1px !important;
  height: 1px !important;
  max-width: 1px !important;
  max-height: 1px !important;
  overflow: hidden !important;
  clip: rect(1px, 1px, 1px, 1px) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

main.container,
.book-layout {
  width: 100%;
  max-width: var(--read-width, 1320px);
  overflow-x: clip;
}

.book-chapter,
.chapter-section,
.study-body,
article.bio-card,
.interactive-box,
.simulator-card {
  max-width: 100%;
  overflow-x: clip;
}

.formula-box,
.equation-box,
.math-block,
.katex-display {
  max-width: 100% !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

@media (max-width: 768px) {
  header.navbar {
    max-width: 100vw;
    overflow-x: clip;
  }
  header.navbar .nav-container {
    max-width: 100%;
    overflow-x: clip;
  }
  header.navbar .nav-links {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  header.navbar .nav-links::-webkit-scrollbar {
    display: none;
  }
}

@media (max-width: 640px) {
  .qm-unit-fab {
    padding: 0;
    width: 42px;
    height: 42px;
    justify-content: center;
    border-radius: 50%;
    left: 12px;
    bottom: 12px;
    font-size: 1.05rem;
  }
  .qm-unit-fab .lang-pt,
  .qm-unit-fab .lang-en {
    display: none !important;
  }
}


/* PHASE2_UX_DARK_MOBILE_PRECISION_2026 */
/* 1. Fix Dark Mode active Focus/Atlas/Giants tab specificity (beats html[data-theme="dark"] .qm-ch-pill!) */
html[data-theme="dark"] .qm-ch-pill.is-active,
[data-theme="dark"] .qm-ch-pill.is-active {
  background: linear-gradient(135deg, #0369a1, #1d4ed8) !important;
  color: #ffffff !important;
  border-color: transparent !important;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.45) !important;
}

/* 2. Prevent sticky navbar (64px) + sticky focus bar (~96px) from occluding anchored targets */
section[id],
article[id],
h2[id],
h3[id],
h4[id],
div[id^="ch"],
div[id^="sec-"],
.book-chapter-section[id],
.book-subcard[id],
.interactive-box[id],
.simulator-card[id],
.bio-card[id] {
  scroll-margin-top: 176px;
}

/* 3. Improve Dark Mode sub-AA badge & bibliography publisher pill contrast */
html[data-theme="dark"] .bio-portrait-nobel,
html[data-theme="dark"] .pioneer-nobel-badge,
html[data-theme="dark"] [id*="synthesis"] [style*="b45309"] {
  color: #fbbf24 !important;
}
html[data-theme="dark"] #ponte-lusofona [style*="047857"],
html[data-theme="dark"] .qm-luso-bridge [style*="047857"] {
  color: #34d399 !important;
}
html[data-theme="dark"] #b1-phase-label {
  color: #a78bfa !important;
}
html[data-theme="dark"] .bib-card span[style*="#f0f9ff"],
html[data-theme="dark"] #bib-accordion span[style*="#f0f9ff"],
html[data-theme="dark"] details span[style*="background:#f0f9ff"] {
  background: rgba(56, 189, 248, 0.16) !important;
  color: #7dd3fc !important;
  border-color: rgba(56, 189, 248, 0.35) !important;
}

/* 4. Fix squished oval pills in qm-labs.html directory table */
#labs-dir-tbody .badge,
#labs-dir-tbody .qm-review-pill,
#labs-dir-tbody span[style*="border-radius:999px"],
#labs-dir-tbody span[style*="border-radius: 999px"] {
  white-space: nowrap;
  display: inline-block;
  border-radius: 8px !important;
}

/* 5. Give footer subtle bottom breathing room so #qm-unit-fab never obscures copyright text */
.studio-footer {
  padding-bottom: 4.5rem;
}

/* 6. Prevent 'Expandir / Recolher' summary toggle from wrapping awkwardly onto 3 lines */
.qm-toc-accordion > summary > span:last-child,
details.book-toc-details > summary > span:last-child,
details > summary span[style*="font-size"] {
  white-space: nowrap;
  flex-shrink: 0;
}

/* 7. Mobile (<= 640px): Full-width .qm-tldr-card (no 92px dead left margin!), hide desktop ⌘K chip, better touch targets */
@media (max-width: 640px) {
  .section-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.65rem !important;
  }
  .section-header > div {
    width: 100% !important;
    max-width: 100% !important;
  }
  .qm-tldr-card {
    width: 100% !important;
    margin-left: 0 !important;
    box-sizing: border-box !important;
  }
  .qm-search-kbd {
    display: none !important;
  }
  header.navbar .nav-links a {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }
  .qm-unit-fab {
    opacity: 0.92;
  }
}


/* === FINAL WCAG 2.1 AA CONTRAST HARDENING (DARK + LIGHT) === */
html[data-theme="dark"] .qm-readout-card .ro-val[style*="#2563eb"],
html[data-theme="dark"] .qm-readout-card .ro-val[style*="37, 99, 235"] { color: #60a5fa !important; }
html[data-theme="dark"] .qm-readout-card .ro-val[style*="#dc2626"],
html[data-theme="dark"] .qm-readout-card .ro-val[style*="220, 38, 38"] { color: #f87171 !important; }
html[data-theme="dark"] .qm-readout-card .ro-val[style*="#7c3aed"],
html[data-theme="dark"] .qm-readout-card .ro-val[style*="124, 58, 237"] { color: #c4b5fd !important; }
html[data-theme="dark"] .qm-readout-card .ro-val[style*="#059669"],
html[data-theme="dark"] .qm-readout-card .ro-val[style*="5, 150, 105"] { color: #34d399 !important; }
html[data-theme="dark"] .qm-readout-card .ro-val[style*="#0d9488"],
html[data-theme="dark"] .qm-readout-card .ro-val[style*="13, 148, 136"] { color: #2dd4bf !important; }
html[data-theme="dark"] .qm-readout-card .ro-val[style*="#d97706"],
html[data-theme="dark"] .qm-readout-card .ro-val[style*="217, 119, 6"] { color: #fbbf24 !important; }

html:not([data-theme="dark"]) .qm-review-pill { color: #0369a1 !important; }
html:not([data-theme="dark"]) .qm-track-link.is-t1 { color: #0369a1 !important; }
html:not([data-theme="dark"]) .qm-track-badge.is-t2 { color: #065f46 !important; }
html:not([data-theme="dark"]) .qm-complete-btn:not(.is-done) { color: #065f46 !important; }
html:not([data-theme="dark"]) .qm-complete-btn.is-done { background: #047857 !important; border-color: #047857 !important; color: #ffffff !important; }
html:not([data-theme="dark"]) .bio-portrait-nobel { color: #92400e !important; }
html:not([data-theme="dark"]) .studio-footer-tag { color: #334155 !important; }


/* ============================================================================
   BIA LEARN — MOLECULAR DYNAMICS (MD) COURSE UX EXTENSIONS (CYCLE 3)
   ============================================================================ */

/* Fix smashed readout label + value on md-labs.html & inline MD widgets */
.qm-readout-card,
.qm-readout-box {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.qm-readout-label {
  display: block;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-muted, #475569);
  line-height: 1.3;
}
.qm-readout-value {
  display: block;
  font-size: 1.04rem;
  font-weight: 800;
  line-height: 1.25;
}
html[data-theme="dark"] .qm-readout-label {
  color: #94a3b8;
}

/* Fix dark-mode 1.7:1 dark-red preset buttons in md-block1 & md-block4 */
html[data-theme="dark"] .qm-preset-btn[style*="#b91c1c"],
html[data-theme="dark"] .qm-preset-btn[style*="185, 28, 28"],
html[data-theme="dark"] .qm-preset-btn[style*="#dc2626"],
html[data-theme="dark"] .qm-preset-btn[style*="220, 38, 38"] {
  color: #fca5a5 !important;
  border-color: rgba(248, 113, 113, 0.55) !important;
  background: rgba(127, 29, 29, 0.35) !important;
}
html[data-theme="dark"] .qm-preset-btn[style*="#0369a1"],
html[data-theme="dark"] .qm-preset-btn[style*="#1d4ed8"],
html[data-theme="dark"] .qm-preset-btn[style*="#2563eb"] {
  color: #93c5fd !important;
  border-color: rgba(96, 165, 250, 0.55) !important;
}
html[data-theme="dark"] .qm-preset-btn[style*="#047857"],
html[data-theme="dark"] .qm-preset-btn[style*="#059669"] {
  color: #6ee7b7 !important;
  border-color: rgba(52, 211, 153, 0.55) !important;
}

/* Light-mode WCAG 2.1 AA contrast for md-atlases inline amber/emerald callouts */
html:not([data-theme="dark"]) main.container p[style*="color:#f59e0b"],
html:not([data-theme="dark"]) main.container p[style*="color: #f59e0b"] {
  color: #92400e !important;
}
html:not([data-theme="dark"]) main.container p[style*="color:#10b981"],
html:not([data-theme="dark"]) main.container p[style*="color: #10b981"] {
  color: #065f46 !important;
}
html[data-theme="dark"] main.container p[style*="color:#f59e0b"],
html[data-theme="dark"] main.container p[style*="color: #f59e0b"] {
  color: #fbbf24 !important;
}
html[data-theme="dark"] main.container p[style*="color:#10b981"],
html[data-theme="dark"] main.container p[style*="color: #10b981"] {
  color: #34d399 !important;
}

/* Dark-mode readability for textbook-pedagogy-panel inline light bg */
html[data-theme="dark"] .textbook-pedagogy-panel {
  background: rgba(15, 23, 42, 0.82) !important;
  border-color: rgba(148, 163, 184, 0.25) !important;
}

/* Cosmetic dark-mode readability for bia-auth-gate header & badge (auth logic untouched) */
html[data-theme="dark"] #bia-auth-nav-pill,
html[data-theme="dark"] .bia-auth-user-pill {
  background: rgba(16, 185, 129, 0.16) !important;
  color: #a7f3d0 !important;
  border-color: rgba(52, 211, 153, 0.45) !important;
}
#bia-auth-gate-overlay .bia-gate-header,
#bia-auth-gate-overlay .bia-gate-header * {
  color: #f8fafc !important;
}

/* Unified 1320px container alignment & zero mobile horizontal overflow on all 12 MD pages */
.md-page-wrap,
main.container,
.book-layout {
  width: 100%;
  max-width: var(--read-width, 1320px) !important;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

/* Clean desktop navbar fit without clipping right-most links */
header.navbar .nav-links {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  flex-wrap: nowrap;
}
header.navbar .nav-links::-webkit-scrollbar { display: none; }
header.navbar .nav-links a {
  white-space: nowrap;
  flex-shrink: 0;
}

/* Mobile 390px safety for MD sub-nav strips, pill rows, pre blocks & grids */
@media (max-width: 768px) {
  .book-layout,
  main.container,
  .book-chapter-section,
  .book-subcard,
  .interactive-box,
  .concept-card,
  .eq-anatomy-card,
  .formula-box {
    max-width: 100% !important;
    overflow-x: clip;
  }
  .chapter-nav-pill,
  .md-quick-bar,
  .hero-actions,
  .filter-bar {
    max-width: 100%;
    flex-wrap: wrap !important;
  }
  pre {
    max-width: 100%;
    overflow-x: auto !important;
    white-space: pre;
    font-size: 0.74rem !important;
  }
}


/* === CYCLE 4 MD ZERO-DEFECT UX & CONTRAST OVERRIDES === */

/* [P0-5] Depth bar must NEVER be sticky if present anywhere */
.qm-depth-bar {
  position: static !important;
  top: auto !important;
}

/* [P0-3] Mobile <= 768px: Focus Bar flows naturally (never slides behind 147px navbar) */
@media (max-width: 768px) {
  .qm-focus-bar {
    position: static !important;
    top: auto !important;
    margin: 0 auto 1rem !important;
    padding: 0.7rem 0.85rem !important;
  }
}

/* [P2-3] Mobile FAB >= 44x44px touch target (WCAG 2.5.8 / Apple HIG) */
@media (max-width: 640px) {
  .qm-unit-fab {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 0.55rem 0.8rem !important;
  }
}

/* [P1-1] Alias .qm-accordion cleanly to .qm-toc-accordion card styling */
details.qm-toc-accordion,
details.qm-accordion {
  margin: 0 auto 1rem !important;
  background: rgba(248, 250, 252, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.34);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05);
}
html[data-theme="dark"] details.qm-toc-accordion,
html[data-theme="dark"] details.qm-accordion {
  background: rgba(15, 23, 42, 0.78);
  border-color: rgba(71, 85, 105, 0.55);
}
details.qm-toc-accordion > summary,
details.qm-accordion > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.78rem 1.05rem;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-primary, #0f172a);
  list-style: none;
  user-select: none;
}
details.qm-toc-accordion > summary::-webkit-details-marker,
details.qm-accordion > summary::-webkit-details-marker {
  display: none;
}
details.qm-toc-accordion > summary .qm-acc-hint,
details.qm-accordion > summary .qm-acc-hint {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.1);
  color: #1d4ed8;
  white-space: nowrap;
  flex-shrink: 0;
}
html[data-theme="dark"] details.qm-toc-accordion > summary .qm-acc-hint,
html[data-theme="dark"] details.qm-accordion > summary .qm-acc-hint {
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
}
details.qm-toc-accordion .qm-accordion-body,
details.qm-accordion .qm-accordion-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid rgba(148, 163, 184, 0.22);
}

/* [P1-2] Unified desktop navbar fit (zero clipping at 1440px & 1728px) & wrapped md.html Block Strip */
header.navbar .nav-container {
  max-width: 1320px !important;
  padding-left: 1rem !important;
  padding-right: 1rem !important;
  gap: 0.45rem !important;
}
header.navbar .nav-links {
  gap: 0.14rem !important;
  justify-content: center;
}
header.navbar .nav-links a {
  font-size: 0.79rem !important;
  padding: 0.3rem 0.46rem !important;
}
body[data-md-hub="1"] nav.Quick-nav,
nav.Quick-nav[aria-label*="Dinâmica Molecular"],
main.container > nav.Quick-nav,
.hero + nav.Quick-nav,
header + nav.Quick-nav {
  position: static !important;
  flex-wrap: wrap !important;
  justify-content: center !important;
  gap: 0.45rem !important;
  overflow: visible !important;
  max-width: 1320px !important;
  margin: 0 auto 1.6rem !important;
  padding: 0.7rem 1rem !important;
  border-radius: 14px;
}
nav.Quick-nav[aria-label*="Dinâmica Molecular"] .btn-primary {
  margin-left: 0 !important;
}

/* [P1-4] Dark Mode: verified auth pill, guide toggle button, and pedagogy sub-headings */
html[data-theme="dark"] #bia-user-verified-pill,
html[data-theme="dark"] #bia-auth-nav-pill,
html[data-theme="dark"] .bia-auth-user-pill {
  background: rgba(16, 185, 129, 0.18) !important;
  color: #a7f3d0 !important;
  border-color: rgba(52, 211, 153, 0.5) !important;
}
html[data-theme="dark"] #bia-user-verified-pill span,
html[data-theme="dark"] #bia-user-verified-pill strong {
  color: #a7f3d0 !important;
}
html[data-theme="dark"] .qm-help-toggle-btn,
html[data-theme="dark"] .qm-toggle-all-help-btn {
  background: rgba(30, 41, 59, 0.92) !important;
  color: #e0f2fe !important;
  border: 1px solid rgba(56, 189, 248, 0.48) !important;
}
html[data-theme="dark"] .qm-help-toggle-btn:hover,
html[data-theme="dark"] .qm-toggle-all-help-btn:hover {
  background: rgba(51, 65, 85, 0.95) !important;
  color: #ffffff !important;
}
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color:#c2410c"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color: #c2410c"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color:#9a3412"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color: #9a3412"] {
  color: #fdba74 !important;
}
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color:#047857"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color: #047857"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color:#065f46"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color: #065f46"] {
  color: #6ee7b7 !important;
}
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color:#0369a1"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color: #0369a1"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color:#1d4ed8"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color: #1d4ed8"] {
  color: #7dd3fc !important;
}

/* [P1-5] Light Mode WCAG AA Contrast (>= 4.5:1) for Readouts, Labels & MD LAB Tags */
html:not([data-theme="dark"]) .ro-label,
html:not([data-theme="dark"]) .qm-readout-label {
  color: #334155 !important;
}
html:not([data-theme="dark"]) .qm-readout-value[style*="f59e0b"],
html:not([data-theme="dark"]) .qm-readout-value[style*="d97706"],
html:not([data-theme="dark"]) .ro-val[style*="f59e0b"],
html:not([data-theme="dark"]) .ro-val[style*="d97706"] {
  color: #92400e !important;
}
html:not([data-theme="dark"]) .qm-readout-value[style*="10b981"],
html:not([data-theme="dark"]) .qm-readout-value[style*="059669"],
html:not([data-theme="dark"]) .ro-val[style*="10b981"],
html:not([data-theme="dark"]) .ro-val[style*="059669"] {
  color: #065f46 !important;
}
html:not([data-theme="dark"]) .qm-lab-tag,
html:not([data-theme="dark"]) .qm-lab-badge,
html:not([data-theme="dark"]) .md-lab-num {
  color: #0e7490 !important;
}
html[data-theme="dark"] .qm-readout-value[style*="f59e0b"],
html[data-theme="dark"] .qm-readout-value[style*="d97706"],
html[data-theme="dark"] .ro-val[style*="f59e0b"],
html[data-theme="dark"] .ro-val[style*="d97706"] {
  color: #fbbf24 !important;
}
html[data-theme="dark"] .qm-readout-value[style*="10b981"],
html[data-theme="dark"] .qm-readout-value[style*="059669"],
html[data-theme="dark"] .ro-val[style*="10b981"],
html[data-theme="dark"] .ro-val[style*="059669"] {
  color: #34d399 !important;
}

/* [P1-3] Dark Mode Inline SVG High-Contrast Pass (excluding KaTeX SVGs) */
html[data-theme="dark"] svg:not(.katex svg) text[fill="#0f172a"]:not([data-keep-ink]),
html[data-theme="dark"] svg:not(.katex svg) text[fill="#1e293b"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#334155"] {
  fill: #e2e8f0 !important;
}
html[data-theme="dark"] svg:not(.katex svg) text[fill="#475569"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#64748b"] {
  fill: #cbd5e1 !important;
}
html[data-theme="dark"] svg:not(.katex svg) rect[fill="#ffffff"],
html[data-theme="dark"] svg:not(.katex svg) rect[fill="#fff"],
html[data-theme="dark"] svg:not(.katex svg) rect[fill="white"],
html[data-theme="dark"] svg:not(.katex svg) rect[fill="#f8fafc"],
html[data-theme="dark"] svg:not(.katex svg) rect[fill="#f1f5f9"] {
  fill: rgba(15, 23, 42, 0.88) !important;
}
html[data-theme="dark"] svg:not(.katex svg) rect[fill="#e2e8f0"] {
  fill: #1e293b !important;
}
html[data-theme="dark"] svg:not(.katex svg) [stroke="#1e293b"],
html[data-theme="dark"] svg:not(.katex svg) [stroke="#334155"],
html[data-theme="dark"] svg:not(.katex svg) [stroke="#0f172a"] {
  stroke: #94a3b8 !important;
}


/* === CYCLE 7 WCAG AA CONTRAST & DARK PEDAGOGY / SVG POLISH === */

/* Dark Mode .textbook-pedagogy-panel high-contrast headings (> 8:1 AA/AAA) */
html[data-theme="dark"] .textbook-pedagogy-panel {
  background: rgba(15, 23, 42, 0.88) !important;
  border-color: rgba(56, 189, 248, 0.34) !important;
  color: #e2e8f0 !important;
}
html[data-theme="dark"] .textbook-pedagogy-panel h3,
html[data-theme="dark"] .textbook-pedagogy-panel h4,
html[data-theme="dark"] .textbook-pedagogy-panel strong[style*="color:#0284c7"],
html[data-theme="dark"] .textbook-pedagogy-panel strong[style*="color: #0284c7"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color:#0284c7"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color: #0284c7"] {
  color: #38bdf8 !important;
}
html[data-theme="dark"] .textbook-pedagogy-panel strong[style*="color:#b45309"],
html[data-theme="dark"] .textbook-pedagogy-panel strong[style*="color: #b45309"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color:#b45309"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color: #b45309"] {
  color: #fbbf24 !important;
}
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color:#059669"],
html[data-theme="dark"] .textbook-pedagogy-panel [style*="color: #059669"] {
  color: #34d399 !important;
}
html[data-theme="dark"] .textbook-pedagogy-panel p,
html[data-theme="dark"] .textbook-pedagogy-panel li {
  color: #cbd5e1 !important;
}

/* Light Mode WCAG AA (>= 4.5:1) for MD LAB #1..24 tags, #pdb-case-output, and inline .ro-val colors */
html:not([data-theme="dark"]) [id^="mdlab"] span[style*="accent-cyan"],
html:not([data-theme="dark"]) [id^="mdlab"] .qm-lab-tag,
html:not([data-theme="dark"]) #pdb-case-output h4,
html:not([data-theme="dark"]) #pdb-case-output [style*="accent-cyan"],
html:not([data-theme="dark"]) #pdb-case-output [style*="0891b2"] {
  color: #0e7490 !important;
}
html:not([data-theme="dark"]) .ro-val[style*="0d9488"],
html:not([data-theme="dark"]) .ro-val[style*="14b8a6"] {
  color: #0f766e !important;
}
html:not([data-theme="dark"]) .ro-val[style*="0284c7"],
html:not([data-theme="dark"]) .ro-val[style*="0891b2"] {
  color: #0369a1 !important;
}
html:not([data-theme="dark"]) .ro-val[style*="64748b"] {
  color: #334155 !important;
}
html:not([data-theme="dark"]) .ro-val[style*="d97706"],
html:not([data-theme="dark"]) .ro-val[style*="f59e0b"] {
  color: #92400e !important;
}

/* Dark Mode WCAG AA (>= 7:1) for .ro-val slate/emerald/blue and #ion-readouts / #ion-svg-wrap */
html[data-theme="dark"] .ro-val[style*="64748b"] {
  color: #cbd5e1 !important;
}
html[data-theme="dark"] .ro-val[style*="0d9488"],
html[data-theme="dark"] .ro-val[style*="059669"],
html[data-theme="dark"] .ro-val[style*="047857"],
html[data-theme="dark"] .qm-readout-value[style*="047857"],
html[data-theme="dark"] .qm-readout-value[style*="059669"] {
  color: #34d399 !important;
}
html[data-theme="dark"] .ro-val[style*="2563eb"],
html[data-theme="dark"] .ro-val[style*="0284c7"],
html[data-theme="dark"] .qm-readout-value[style*="2563eb"] {
  color: #60a5fa !important;
}
html[data-theme="dark"] .qm-readout-value[style*="b45309"],
html[data-theme="dark"] .qm-readout-value[style*="92400e"] {
  color: #fbbf24 !important;
}
html[data-theme="dark"] #ion-svg-wrap text[fill="#2563eb"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#2563eb"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#1e40af"] {
  fill: #60a5fa !important;
}
html[data-theme="dark"] #ion-svg-wrap text[fill="#059669"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#059669"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#0f766e"] {
  fill: #34d399 !important;
}
html[data-theme="dark"] svg:not(.katex svg) text[fill="#5b21b6"] {
  fill: #c4b5fd !important;
}
html[data-theme="dark"] svg:not(.katex svg) text[fill="#b45309"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#d97706"] {
  fill: #fbbf24 !important;
}
html[data-theme="dark"] svg:not(.katex svg) text[fill="#dc2626"] {
  fill: #f87171 !important;
}
html[data-theme="dark"] svg:not(.katex svg) rect[fill="#eff6ff"] {
  fill: rgba(30, 58, 138, 0.28) !important;
}
html[data-theme="dark"] svg:not(.katex svg) circle[fill="#ede9fe"] {
  fill: rgba(91, 33, 182, 0.32) !important;
}

/* ============================================================================
   CYCLE 8 — MD ATLASES INTERACTIVE SUITE (LIGHT + DARK WCAG AA >= 7:1)
   ============================================================================ */
.atlas-badge-cyan {
  font-size: 0.8rem;
  font-weight: 700;
  color: #0e7490;
  padding: 0.24rem 0.65rem;
  border-radius: 999px;
  background: rgba(14, 116, 144, 0.12);
}
html[data-theme="dark"] .atlas-badge-cyan {
  color: #67e8f9;
  background: rgba(6, 182, 212, 0.18);
  border: 1px solid rgba(34, 211, 238, 0.3);
}
.atlas-badge-rose {
  font-size: 0.8rem;
  font-weight: 700;
  color: #be123c;
  padding: 0.24rem 0.65rem;
  border-radius: 999px;
  background: rgba(244, 63, 94, 0.12);
}
html[data-theme="dark"] .atlas-badge-rose {
  color: #fda4af;
  background: rgba(244, 63, 94, 0.2);
  border: 1px solid rgba(251, 113, 133, 0.35);
}
.atlas-ts-id-pill {
  font-size: 0.76rem;
  font-weight: 800;
  padding: 0.16rem 0.52rem;
  border-radius: 6px;
  background: rgba(244, 63, 94, 0.14);
  color: #be123c;
  border: 1px solid rgba(244, 63, 94, 0.35);
}
html[data-theme="dark"] .atlas-ts-id-pill {
  background: rgba(244, 63, 94, 0.24);
  color: #fda4af;
  border-color: rgba(251, 113, 133, 0.45);
}
.atlas-verdict-ok { color: #047857; }
html[data-theme="dark"] .atlas-verdict-ok { color: #34d399; }
.atlas-verdict-warn { color: #92400e; }
html[data-theme="dark"] .atlas-verdict-warn { color: #fbbf24; }
.atlas-verdict-forbid { color: #b91c1c; }
html[data-theme="dark"] .atlas-verdict-forbid { color: #f87171; }
.rosetta-card-title {
  font-weight: 800;
  font-size: 0.84rem;
  color: #0e7490;
  margin-bottom: 0.5rem;
}
html[data-theme="dark"] .rosetta-card-title {
  color: #38bdf8;
}

/* ============================================================================
   CYCLE 9 — WCAG AA LIGHT/DARK POLISH FOR MD ATLASES & MODULE 0
   ============================================================================ */
.m0-btn-next {
  border-color: #0284c7 !important;
  color: #0369a1 !important;
}
html[data-theme="dark"] .m0-btn-next {
  border-color: #38bdf8 !important;
  color: #7dd3fc !important;
}
html:not([data-theme="dark"]) .concept-card p[style*="f59e0b"],
html:not([data-theme="dark"]) .concept-card span[style*="f59e0b"] {
  color: #92400e !important;
}
html:not([data-theme="dark"]) .concept-card p[style*="10b981"],
html:not([data-theme="dark"]) .concept-card span[style*="10b981"] {
  color: #047857 !important;
}
html[data-theme="dark"] .m0-card strong[style*="b45309"] {
  color: #fbbf24 !important;
}
html[data-theme="dark"] .m0-card strong[style*="0284c7"] {
  color: #38bdf8 !important;
}
html[data-theme="dark"] .m0-card span[style*="0369a1"] {
  color: #7dd3fc !important;
  background: rgba(56, 189, 248, 0.16) !important;
}

/* ============================================================================
   CYCLE 10 — FINAL 20/20 UX, MOBILE NAV, SIM CONTROLS & WCAG AA (>= 4.8:1)
   ============================================================================ */

/* D-03: Mobile navbar flex-start so Início & Cursos are never clipped off-screen left */
@media (max-width: 768px) {
  header.navbar .nav-links {
    justify-content: flex-start !important;
    padding-left: 0.25rem;
    padding-right: 0.5rem;
  }
}

/* D-10: Reposition #qm-unit-fab to bottom-right so left headings & ← Anterior are never occluded */
.qm-unit-fab {
  left: auto !important;
  right: 18px !important;
  bottom: 18px !important;
}
.qm-unit-drawer {
  left: auto !important;
  right: 18px !important;
}
@media (max-width: 640px) {
  .qm-unit-fab {
    left: auto !important;
    right: 12px !important;
    bottom: 12px !important;
  }
  .qm-unit-drawer {
    left: 10px !important;
    right: 10px !important;
  }
}

/* D-11: Flush Focus Bar top edge so scrolled text never peeks above the 2px gap */
.qm-focus-bar {
  top: 64px !important;
  box-shadow: 0 -10px 0 0 var(--bg-primary, #ffffff), 0 10px 28px rgba(15, 23, 42, 0.08) !important;
}
html[data-theme="dark"] .qm-focus-bar {
  box-shadow: 0 -10px 0 0 var(--bg-primary, #0b1120), 0 12px 30px rgba(0, 0, 0, 0.38) !important;
}

/* D-05: Full flagship styling for Block 8 Sim 30.1 & Sim 32.1 (.controls-grid / .select-input / .readout-strip) */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1rem;
  align-items: end;
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border-color, rgba(148,163,184,0.32));
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}
html[data-theme="dark"] .control-group {
  background: rgba(15, 23, 42, 0.72);
  border-color: rgba(71, 85, 105, 0.5);
}
.control-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary, #0f172a);
}
html[data-theme="dark"] .control-label {
  color: #e2e8f0;
}
.select-input {
  width: 100%;
  padding: 0.5rem 0.72rem;
  border-radius: 8px;
  border: 1px solid var(--border-color, #cbd5e1);
  background: var(--bg-primary, #ffffff);
  color: var(--text-primary, #0f172a);
  font-size: 0.84rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
html[data-theme="dark"] .select-input {
  background: #0f172a;
  color: #f1f5f9;
  border-color: #475569;
}
.readout-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 0.65rem;
  margin: 0.85rem 0 1rem;
}
.readout-item {
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border-color, rgba(148,163,184,0.32));
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}
html[data-theme="dark"] .readout-item {
  background: rgba(15, 23, 42, 0.75);
  border-color: rgba(71, 85, 105, 0.5);
}
.readout-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary, #475569);
}
html[data-theme="dark"] .readout-label {
  color: #cbd5e1;
}
.readout-value {
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.3;
  color: var(--text-primary, #0f172a);
}
html[data-theme="dark"] .readout-value {
  color: #f8fafc;
}

/* D-06: Universal Light Mode WCAG AA (>= 4.8:1) across Pedagogy Panels, Atlases & Readouts */
html:not([data-theme="dark"]) .textbook-pedagogy-panel span[style*="0284c7"],
html:not([data-theme="dark"]) .textbook-pedagogy-panel strong[style*="0284c7"] {
  color: #0369a1 !important;
}
html:not([data-theme="dark"]) .atlas-badge-cyan {
  color: #155e75 !important;
  background: rgba(14, 116, 144, 0.08) !important;
  border: 1px solid rgba(14, 116, 144, 0.25);
}
html:not([data-theme="dark"]) #atlas-forcefields .concept-card h3[style*="0891b2"],
html:not([data-theme="dark"]) #atlas-forcefields .concept-card h4[style*="0891b2"],
html:not([data-theme="dark"]) #atlas-algorithms .concept-card h3[style*="0891b2"],
html:not([data-theme="dark"]) #atlas-analysis .concept-card h3[style*="0891b2"],
html:not([data-theme="dark"]) .concept-card h3[style*="0891b2"] {
  color: #0e7490 !important;
}
html:not([data-theme="dark"]) .md-ts-card h3[style*="f43f5e"],
html:not([data-theme="dark"]) .md-ts-card h4[style*="f43f5e"] {
  color: #be123c !important;
}
html[data-theme="dark"] .md-ts-card h3[style*="f43f5e"],
html[data-theme="dark"] .md-ts-card h4[style*="f43f5e"] {
  color: #fb7185 !important;
}
html:not([data-theme="dark"]) .readout-value[style*="d97706"],
html:not([data-theme="dark"]) .readout-value[style*="f59e0b"],
html:not([data-theme="dark"]) .ro-val[style*="d97706"] {
  color: #92400e !important;
}
html:not([data-theme="dark"]) .readout-value[style*="059669"],
html:not([data-theme="dark"]) .readout-value[style*="10b981"],
html:not([data-theme="dark"]) .ro-val[style*="059669"] {
  color: #047857 !important;
}
html:not([data-theme="dark"]) .readout-value[style*="0d9488"],
html:not([data-theme="dark"]) .ro-val[style*="0d9488"] {
  color: #0f766e !important;
}
html:not([data-theme="dark"]) .readout-value[style*="0284c7"],
html:not([data-theme="dark"]) .ro-val[style*="0284c7"] {
  color: #0369a1 !important;
}

/* D-06 & D-07: Universal Dark Mode WCAG AA (>= 6.5:1) for Lab tags, Readouts & Inline Slider Values */
html[data-theme="dark"] [id^="mdlab"] [style*="0e7490"],
html[data-theme="dark"] [id^="mdlab"] [style*="0891b2"] {
  color: #22d3ee !important;
}
html[data-theme="dark"] .readout-value[style*="2563eb"],
html[data-theme="dark"] .readout-value[style*="0284c7"],
html[data-theme="dark"] span[id$="-label"][style*="2563eb"],
html[data-theme="dark"] span[id$="-val"][style*="2563eb"] {
  color: #60a5fa !important;
}
html[data-theme="dark"] .readout-value[style*="7c3aed"],
html[data-theme="dark"] .ro-val[style*="7c3aed"],
html[data-theme="dark"] span[id$="-label"][style*="7c3aed"],
html[data-theme="dark"] span[id$="-val"][style*="7c3aed"] {
  color: #c084fc !important;
}
html[data-theme="dark"] .readout-value[style*="dc2626"],
html[data-theme="dark"] .ro-val[style*="dc2626"],
html[data-theme="dark"] span[id$="-label"][style*="dc2626"],
html[data-theme="dark"] span[id$="-val"][style*="dc2626"] {
  color: #f87171 !important;
}
html[data-theme="dark"] .readout-value[style*="d97706"],
html[data-theme="dark"] .readout-value[style*="b45309"] {
  color: #fbbf24 !important;
}
html[data-theme="dark"] .readout-value[style*="059669"],
html[data-theme="dark"] .readout-value[style*="0d9488"],
html[data-theme="dark"] .readout-value[style*="047857"] {
  color: #34d399 !important;
}

/* D-07 & D-09: Universal SVG Text Contrast Overrides (Light >= 4.8:1, Dark >= 6.8:1) */
html[data-theme="dark"] svg:not(.katex svg) text[fill="#6d28d9"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#7c3aed"] {
  fill: #c084fc !important;
}
html[data-theme="dark"] svg:not(.katex svg) text[fill="#047857"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#0d9488"] {
  fill: #34d399 !important;
}
html[data-theme="dark"] svg:not(.katex svg) text[fill="#475569"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#334155"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#1e293b"] {
  fill: #e2e8f0 !important;
}
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#059669"] {
  fill: #047857 !important;
}
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#d97706"],
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#f59e0b"] {
  fill: #92400e !important;
}
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#0d9488"] {
  fill: #0f766e !important;
}
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#dc2626"] {
  fill: #b91c1c !important;
}
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#64748b"] {
  fill: #334155 !important;
}

/* ============================================================================
   CYCLE 10C — ZERO-RESIDUAL WCAG AA COMPUTED CONTRAST (>= 4.8:1 ALL MODES)
   ============================================================================ */
/* UX-3: Atlas 1 cyan spans (3.52 -> 5.1:1) & Light Pedagogy Panel h3 (3.91 -> 5.8:1) */
html:not([data-theme="dark"]) #atlas-forcefields .concept-card span[style*="accent-cyan"],
html:not([data-theme="dark"]) #atlas-algorithms .concept-card span[style*="accent-cyan"],
html:not([data-theme="dark"]) #atlas-analysis .concept-card span[style*="accent-cyan"],
html:not([data-theme="dark"]) .concept-card h3 span[style*="accent-cyan"] {
  color: #0e7490 !important;
}
html:not([data-theme="dark"]) .textbook-pedagogy-panel h3,
html:not([data-theme="dark"]) .textbook-pedagogy-panel h3 span,
html:not([data-theme="dark"]) .textbook-pedagogy-panel h4 {
  color: #0369a1 !important;
}

/* UX-4: Block 7 Light .ro-val, Block 8 Light red .readout-value, Block 4 teal sliders */
html:not([data-theme="dark"]) .ro-val[style*="d97706"],
html:not([data-theme="dark"]) .ro-val[style*="b45309"],
html:not([data-theme="dark"]) #b7-s28-verdict {
  color: #92400e !important;
}
html:not([data-theme="dark"]) .ro-val[style*="0284c7"],
html:not([data-theme="dark"]) #b7-s26-diag {
  color: #0369a1 !important;
}
html:not([data-theme="dark"]) .readout-value[style*="dc2626"],
html:not([data-theme="dark"]) .ro-val[style*="dc2626"] {
  color: #b91c1c !important;
}
html:not([data-theme="dark"]) span[id$="-label"][style*="0d9488"],
html:not([data-theme="dark"]) span[id$="-val"][style*="0d9488"] {
  color: #0f766e !important;
}
html[data-theme="dark"] span[id$="-label"][style*="0d9488"],
html[data-theme="dark"] span[id$="-val"][style*="0d9488"] {
  color: #2dd4bf !important;
}

/* UX-5: Light SVG blues/emeralds/ambers >= 5.1:1 (covers #b3-sim9/11, #md-b1-sim4, #md-b2-sim6a, #ch17, #ch21) */
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#2563eb"],
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#0284c7"] {
  fill: #1d4ed8 !important;
}
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#059669"],
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#047857"] {
  fill: #065f46 !important;
}
html:not([data-theme="dark"]) svg:not(.katex svg) text[fill="#b45309"] {
  fill: #92400e !important;
}
/* Protect data-keep-ink dark text on bright amber circles in Dark Mode (8.31:1) */
html[data-theme="dark"] svg:not(.katex svg) text[data-keep-ink="1"] {
  fill: #0f172a !important;
}


/* ============================================================================
   DVS COURSE CYCLE 3 — UNIFIED WIDTH, 7-LINK NAVBAR, BLOCK STRIP, DARK/LIGHT
   WCAG AA (>= 4.8:1), SIMULATOR STAGES, READOUT CARDS & 390px ZERO-OVERFLOW
   ============================================================================ */

/* Unified 1320px container width across all 10 DVS pages (incl. Module 0, Labs & Atlas) */
.m0-wrap,
.m0-hero-inner,
.dvs-wrap,
.book-layout,
.container,
main.container {
  max-width: 1320px !important;
  width: 100%;
  box-sizing: border-box;
}

/* Prevent horizontal overflow on 390px mobile across ALL 10 DVS pages */
.book-main,
.book-chapter-section,
.book-subcard,
.worked-step,
.eq-anatomy-grid,
.eq-anatomy-item,
.qm-sim-box,
.qm-sim-controls,
.qm-live-diag-box,
.quiz-wrapper,
.quiz-scoreboard,
.md-concept-svg-card,
.concept-grid,
.concept-card,
.m0-card,
.m0-hero,
.dvs-sim-svg-stage {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.book-main p,
.book-main li,
.book-subcard,
.worked-step,
.concept-card {
  overflow-wrap: break-word;
  word-break: break-word;
}

.book-main code,
.concept-card code,
.worked-step code {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Crisp single-row 7-link navbar on desktop (0px clip at 1440px & 1728px) */
header.navbar .nav-container {
  max-width: 1320px !important;
  padding-left: 1rem;
  padding-right: 1rem;
  gap: 0.5rem;
}

header.navbar .nav-links {
  display: flex;
  align-items: center;
  gap: 0.16rem;
  flex-wrap: nowrap;
  min-width: 0;
}

header.navbar .nav-links a {
  white-space: nowrap;
  font-size: 0.80rem;
  padding: 0.32rem 0.50rem;
  border-radius: 8px;
}

/* Compact Block I-VI Quick-Switch Strip inside Focus Bar */
.dvs-block-strip {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
  padding: 0.18rem 0.42rem;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.28);
}

.dvs-blk-lbl {
  font-size: 0.70rem;
  font-weight: 800;
  color: #475569;
  padding-right: 0.15rem;
}

html[data-theme="dark"] .dvs-blk-lbl {
  color: #cbd5e1;
}

.dvs-blk-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 0.34rem;
  border-radius: 999px;
  font-size: 0.70rem;
  font-weight: 800;
  text-decoration: none;
  color: #1e293b;
  transition: all 0.14s ease;
}

html[data-theme="dark"] .dvs-blk-chip {
  color: #e2e8f0;
}

.dvs-blk-chip:hover {
  background: rgba(3, 105, 161, 0.16);
  color: #0369a1;
}

html[data-theme="dark"] .dvs-blk-chip:hover {
  background: rgba(56, 189, 248, 0.2);
  color: #7dd3fc;
}

.dvs-blk-chip.is-curr {
  background: #0369a1;
  color: #ffffff !important;
}

/* Mobile 390px compact header, non-sticky filter-bar & static Focus Bar */
@media (max-width: 768px) {
  header.navbar .nav-container {
    padding: 0.45rem 0.65rem;
    gap: 0.35rem;
  }
  header.navbar .brand-sub,
  header.navbar .bialab-pill {
    display: none !important;
  }
  header.navbar .nav-links {
    justify-content: flex-start !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    max-width: 100%;
    padding: 0.15rem 0.1rem;
  }
  header.navbar .nav-links::-webkit-scrollbar {
    display: none;
  }
  .qm-focus-bar {
    position: static !important;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08) !important;
    padding: 0.65rem 0.75rem;
  }
  .filter-bar,
  .quiz-scoreboard .filter-bar {
    position: static !important;
    top: auto !important;
    max-height: none !important;
    gap: 0.32rem !important;
  }
  .filter-bar .chip {
    font-size: 0.72rem !important;
    padding: 0.28rem 0.55rem !important;
  }
  .eq-anatomy-grid {
    grid-template-columns: 1fr !important;
  }
  .book-layout {
    padding-left: 0.65rem !important;
    padding-right: 0.65rem !important;
  }
  .book-subcard,
  .qm-sim-box,
  .m0-card {
    padding: 0.9rem 0.8rem !important;
  }
  .qm-ch-pager-nav {
    grid-template-columns: 1fr !important;
  }
}

/* Eradicate blinding white simulator boxes in Dark Mode (Blocks 3 & 4) */
.dvs-sim-svg-stage {
  background: #f8fafc !important;
  border: 1px solid rgba(148, 163, 184, 0.35) !important;
  border-radius: 10px;
  padding: 0.5rem;
  overflow: hidden;
}

html[data-theme="dark"] .dvs-sim-svg-stage {
  background: #0b1222 !important;
  border-color: rgba(71, 85, 105, 0.6) !important;
}

html[data-theme="dark"] .dvs-sim-svg-stage svg rect[fill="#f8fafc"],
html[data-theme="dark"] .dvs-sim-svg-stage svg rect[fill="#ffffff"],
html[data-theme="dark"] .dvs-sim-svg-stage svg rect[fill="#fff"],
html[data-theme="dark"] .dvs-sim-svg-stage svg ellipse[fill="#ffffff"] {
  fill: #0f172a !important;
}

html[data-theme="dark"] .dvs-sim-svg-stage svg rect[stroke="#cbd5e1"],
html[data-theme="dark"] .dvs-sim-svg-stage svg line[stroke="#cbd5e1"] {
  stroke: #334155 !important;
}

/* Clean stacked layout & WCAG AA contrast for .qm-readout-card in dvs-labs.html */
.qm-readout-card {
  display: flex !important;
  flex-direction: column !important;
  gap: 0.28rem !important;
  padding: 0.72rem 0.88rem !important;
  border-radius: 10px;
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border-color, rgba(148, 163, 184, 0.32));
}

html[data-theme="dark"] .qm-readout-card {
  background: rgba(15, 23, 42, 0.78);
  border-color: rgba(71, 85, 105, 0.55);
}

.qm-readout-label {
  display: block !important;
  font-size: 0.74rem !important;
  font-weight: 700 !important;
  line-height: 1.3;
  color: #475569 !important;
}

html[data-theme="dark"] .qm-readout-label {
  color: #cbd5e1 !important;
}

.qm-readout-value {
  display: block !important;
  font-family: "JetBrains Mono", "Inter", monospace;
  font-size: 0.94rem !important;
  font-weight: 800 !important;
  line-height: 1.35;
  color: #0f172a;
}

html[data-theme="dark"] .qm-readout-value {
  color: #f8fafc;
}

/* Primary Buttons & Module 0 Active Buttons WCAG AA (>= 5.8:1) */
.btn-primary,
a.btn-primary,
button.btn-primary {
  background: linear-gradient(135deg, #1d4ed8, #0369a1) !important;
  color: #ffffff !important;
  border-color: transparent !important;
}

.btn-primary:hover,
a.btn-primary:hover,
button.btn-primary:hover {
  background: linear-gradient(135deg, #1e40af, #075985) !important;
  color: #ffffff !important;
}

.m0-btn.active {
  background: #0369a1 !important;
  color: #ffffff !important;
  border-color: #0369a1 !important;
}

/* dvs-atlas.html & dvs-labs.html Light Mode WCAG AA (>= 4.8:1) */
html:not([data-theme="dark"]) .concept-card h3[style*="accent-cyan"],
html:not([data-theme="dark"]) .concept-card h4[style*="accent-cyan"],
html:not([data-theme="dark"]) .concept-card span[style*="accent-cyan"],
html:not([data-theme="dark"]) .qm-readout-value[style*="accent-cyan"],
html:not([data-theme="dark"]) [id^="dvslab"] span[style*="accent-cyan"] {
  color: #0e7490 !important;
}

html:not([data-theme="dark"]) .concept-card p[style*="f87171"],
html:not([data-theme="dark"]) .concept-card span[style*="f87171"],
html:not([data-theme="dark"]) .concept-card p[style*="ef4444"],
html:not([data-theme="dark"]) .qm-readout-value[style*="ef4444"] {
  color: #b91c1c !important;
}

html:not([data-theme="dark"]) .concept-card p[style*="10b981"],
html:not([data-theme="dark"]) .concept-card span[style*="10b981"],
html:not([data-theme="dark"]) .qm-readout-value[style*="10b981"],
html:not([data-theme="dark"]) .qm-readout-value[style*="accent-emerald"] {
  color: #047857 !important;
}

html:not([data-theme="dark"]) .concept-card p[style*="f59e0b"],
html:not([data-theme="dark"]) .concept-card span[style*="f59e0b"],
html:not([data-theme="dark"]) .qm-readout-value[style*="f59e0b"] {
  color: #92400e !important;
}

html:not([data-theme="dark"]) .m0-pill[style*="e11d48"] {
  color: #be123c !important;
}

/* Dark Mode WCAG AA (>= 6.5:1) for Atlas, Labs & ALL Simulator/Chapter SVGs */
html[data-theme="dark"] .concept-card h3[style*="accent-cyan"],
html[data-theme="dark"] .concept-card h4[style*="accent-cyan"],
html[data-theme="dark"] .qm-readout-value[style*="accent-cyan"] {
  color: #38bdf8 !important;
}

html[data-theme="dark"] .concept-card p[style*="f87171"] {
  color: #fca5a5 !important;
}

html[data-theme="dark"] .concept-card p[style*="10b981"],
html[data-theme="dark"] .qm-readout-value[style*="10b981"],
html[data-theme="dark"] .qm-readout-value[style*="accent-emerald"] {
  color: #34d399 !important;
}

html[data-theme="dark"] .concept-card p[style*="f59e0b"],
html[data-theme="dark"] .qm-readout-value[style*="f59e0b"] {
  color: #fbbf24 !important;
}

html[data-theme="dark"] svg:not(.katex svg) text[fill="#0f172a"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#1e293b"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#334155"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#475569"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#64748b"] {
  fill: #e2e8f0 !important;
}

html[data-theme="dark"] svg:not(.katex svg) text[fill="#b91c1c"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#be123c"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#dc2626"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#e11d48"] {
  fill: #fca5a5 !important;
}

html[data-theme="dark"] svg:not(.katex svg) text[fill="#047857"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#059669"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#065f46"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#0d9488"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#0f766e"] {
  fill: #6ee7b7 !important;
}

html[data-theme="dark"] svg:not(.katex svg) text[fill="#1d4ed8"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#2563eb"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#0284c7"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#0369a1"] {
  fill: #7dd3fc !important;
}

html[data-theme="dark"] svg:not(.katex svg) text[fill="#b45309"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#d97706"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#92400e"] {
  fill: #fcd34d !important;
}

html[data-theme="dark"] svg:not(.katex svg) text[fill="#7c3aed"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#6d28d9"],
html[data-theme="dark"] svg:not(.katex svg) text[fill="#5b21b6"] {
  fill: #d8b4fe !important;
}

html[data-theme="dark"] svg:not(.katex svg) text[data-keep-ink="1"] {
  fill: #0f172a !important;
}

/* Protect dark-background inline conceptual SVGs (.md-concept-svg-card) in Light Mode */
html:not([data-theme="dark"]) .md-concept-svg-card svg text[fill="#94a3b8"] {
  fill: #cbd5e1 !important;
}

/* Unit Converter Popover Bottom-Right Anchor */
.qm-unit-popover {
  left: auto !important;
  right: 18px !important;
  bottom: 68px !important;
}
@media (max-width: 640px) {
  .qm-unit-popover {
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
  }
}


/* ============================================================================
   DVS CYCLE 4A — ZERO-RESIDUAL GATE-1 LAYOUT & WCAG AA (>= 4.8:1 ALL MODES)
   ============================================================================ */

/* 1. Fix dvs.html nav.Quick-nav horizontal clipping (wrap & center cleanly) */
nav.Quick-nav,
.Quick-nav {
  flex-wrap: wrap !important;
  justify-content: center !important;
  gap: 0.45rem !important;
  overflow: visible !important;
}
nav.Quick-nav .btn-primary,
.Quick-nav .btn-primary {
  margin-left: 0 !important;
}

/* 2. Fix dvs-labs.html .qm-readout-grid 4-card full-width fill (auto-fit instead of auto-fill) */
.qm-readout-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) !important;
}

/* 3. Fix mobile .badge pill corner pinching multi-line hero text */
@media (max-width: 768px) {
  .hero .badge,
  .badge {
    border-radius: 16px !important;
    padding: 0.5rem 0.9rem !important;
    line-height: 1.4 !important;
  }
}

/* 4. P0/P1 Dark Mode Hero .gradient-text (2.19:1 -> >= 6.5:1 luminous cyan-to-lavender) */
html[data-theme="dark"] .gradient-text {
  background: linear-gradient(135deg, #38bdf8 0%, #818cf8 55%, #c4b5fd 100%) !important;
  -webkit-background-clip: text !important;
  background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
}

/* 5. P0 .dvs-sousa-card strong in Light Mode (1.19:1 -> 14.2:1) */
.dvs-sousa-reviews-banner strong,
.dvs-sousa-card strong {
  color: #f8fafc !important;
}

/* 6. P1 Light Mode dark-navy SVGs (#dvs-m0-svg & .md-concept-svg-card) amber protection (2.52:1 -> 10.7:1) */
html:not([data-theme="dark"]) #dvs-m0-svg text[fill="#f59e0b"],
html:not([data-theme="dark"]) #dvs-m0-svg text[fill="#d97706"],
html:not([data-theme="dark"]) .md-concept-svg-card svg text[fill="#f59e0b"],
html:not([data-theme="dark"]) .md-concept-svg-card svg text[fill="#d97706"] {
  fill: #fbbf24 !important;
}
html:not([data-theme="dark"]) .md-concept-svg-card svg text[fill="#059669"] {
  fill: #34d399 !important;
}
html:not([data-theme="dark"]) .md-concept-svg-card svg text[fill="#dc2626"] {
  fill: #fca5a5 !important;
}

/* 7. P1/P2 Rose #e11d48 -> #be123c (Light >= 5.5:1) & #fda4af (Dark >= 8.5:1) */
html:not([data-theme="dark"]) .m0-card .m0-pill,
html:not([data-theme="dark"]) .hist-card > a,
html:not([data-theme="dark"]) .hist-card a[style*="e11d48"],
html:not([data-theme="dark"]) :not(.btn):not(.btn-primary)[style*="color:#e11d48"],
html:not([data-theme="dark"]) :not(.btn):not(.btn-primary)[style*="color: #e11d48"] {
  color: #be123c !important;
}
html[data-theme="dark"] .m0-card .m0-pill,
html[data-theme="dark"] .hist-card > a,
html[data-theme="dark"] .hist-card a[style*="e11d48"],
html[data-theme="dark"] details summary[style*="e11d48"],
html[data-theme="dark"] :not(.btn):not(.btn-primary)[style*="color:#e11d48"],
html[data-theme="dark"] :not(.btn):not(.btn-primary)[style*="color: #e11d48"] {
  color: #fda4af !important;
}
/* Protect always-dark .m0-hero badge & primary buttons from rose text override */
.m0-hero .m0-pill {
  color: #bae6fd !important;
  background: rgba(56, 189, 248, 0.16) !important;
}
a.btn-primary, button.btn-primary, .btn-primary, .btn.btn-primary {
  color: #ffffff !important;
}

/* 8. P1/P2 Sky Blue #0284c7 / #0891b2 / #2563eb across Light & Dark Modes (>= 5.5:1) */
html:not([data-theme="dark"]) details.qm-ctrl-help > summary,
html:not([data-theme="dark"]) details.qm-ctrl-help > summary > span,
html:not([data-theme="dark"]) .toc-block-badge,
html:not([data-theme="dark"]) .quiz-score-badge,
html:not([data-theme="dark"]) .qm-ch-pager-top a,
html:not([data-theme="dark"]) .qm-ch-pager-top a span,
html:not([data-theme="dark"]) .toc-featured-top-label,
html:not([data-theme="dark"]) .toc-num,
html:not([data-theme="dark"]) .qm-pager-dir,
html:not([data-theme="dark"]) .qm-pager-dir span,
html:not([data-theme="dark"]) [style*="color:#0284c7"],
html:not([data-theme="dark"]) [style*="color: #0284c7"] {
  color: #0369a1 !important;
}
html:not([data-theme="dark"]) [id^="dvslab"] a[style*="0891b2"],
html:not([data-theme="dark"]) [id^="dvslab"] a,
html:not([data-theme="dark"]) [style*="color:#0891b2"],
html:not([data-theme="dark"]) [style*="color: #0891b2"] {
  color: #0e7490 !important;
}
html:not([data-theme="dark"]) .step-badge-inline,
html:not([data-theme="dark"]) .step-badge-inline span {
  color: #1d4ed8 !important;
}
html[data-theme="dark"] #dvs-24-progress-grid [style*="color:#2563eb"],
html[data-theme="dark"] #dvs-24-progress-grid [style*="color: #2563eb"],
html[data-theme="dark"] .step-badge-inline,
html[data-theme="dark"] .step-badge-inline span {
  color: #60a5fa !important;
}

/* 9. P1/P2 Green, Amber, Red, Orange brand & slider labels (Light & Dark >= 5.2:1) */
html:not([data-theme="dark"]) .brand-title .bia-highlight {
  color: #c2410c !important;
}
html:not([data-theme="dark"]) [style*="color:#059669"],
html:not([data-theme="dark"]) [style*="color: #059669"],
html:not([data-theme="dark"]) [id^="dvslab"] p[style*="059669"] {
  color: #047857 !important;
}
html[data-theme="dark"] [style*="color:#059669"],
html[data-theme="dark"] [style*="color: #059669"],
html[data-theme="dark"] #b5-s17-verdict {
  color: #34d399 !important;
}
html:not([data-theme="dark"]) [style*="color:#d97706"],
html:not([data-theme="dark"]) [style*="color: #d97706"],
html:not([data-theme="dark"]) #dvs-b1-s4-rot-label,
html:not([data-theme="dark"]) #dvs-b3-s11-diag strong,
html:not([data-theme="dark"]) .m0-card [style*="color:#b45309"],
html:not([data-theme="dark"]) .m0-card [style*="color: #b45309"] {
  color: #92400e !important;
}
html:not([data-theme="dark"]) .key-message-title,
html:not([data-theme="dark"]) [style*="color:#dc2626"],
html:not([data-theme="dark"]) [style*="color: #dc2626"] {
  color: #b91c1c !important;
}
html:not([data-theme="dark"]) .chapter-nav-pill > span {
  opacity: 1 !important;
  color: #334155 !important;
}
html[data-theme="dark"] .chapter-nav-pill > span {
  opacity: 1 !important;
  color: #cbd5e1 !important;
}

/* 10. P2 White-on-sky #0284c7 pills -> #0369a1 (5.93:1) & Verified pill -> #047857 (5.5:1) */
.sec-num,
.chip.active,
.btn-quiz-action.primary,
.step-dot.current,
.m0-btn.active {
  background-color: #0369a1 !important;
  background-image: linear-gradient(135deg, #0369a1, #1d4ed8) !important;
  color: #ffffff !important;
}
.m0-btn:not(.active) {
  color: #0f172a;
}
html[data-theme="dark"] .m0-btn:not(.active) {
  color: #e2e8f0;
}
button#bia-user-verified-pill > span {
  background: #047857 !important;
  color: #ffffff !important;
}
html[data-theme="dark"] button#bia-user-verified-pill > span {
  background: #047857 !important;
  color: #ffffff !important;
}

/* 11. P1 Leaflet attribution link contrast on gray strip (>= 5.1:1) */
.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.92) !important;
  color: #1e293b !important;
}
.leaflet-control-attribution a {
  color: #0369a1 !important;
  font-weight: 600;
}

/* 12. P2 Module 0 synthesis/curiosity callout headings on soft-tinted backgrounds (>= 5.5:1) */
html:not([data-theme="dark"]) .m0-card [style*="background:rgba(2,132,199"],
html:not([data-theme="dark"]) .m0-card [style*="background: rgba(2,132,199"] {
  color: #075985 !important;
}
html:not([data-theme="dark"]) .m0-card [style*="color:#0369a1"] {
  color: #075985 !important;
}


/* ============================================================================
   DVS CYCLE 4B — RUNNABLE CLI/PYTHON WORKFLOW CARDS & BILINGUAL CONCEPT SVGS
   ============================================================================ */
.dvs-cli-card {
  margin: 1.45rem 0;
  border-radius: 14px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: #0b1120;
  color: #e2e8f0;
  overflow: hidden;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.16);
}
.dvs-cli-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  background: #111c33;
  border-bottom: 1px solid rgba(148, 163, 184, 0.22);
}
.dvs-cli-title {
  font-size: 0.86rem;
  font-weight: 800;
  color: #7dd3fc;
}
.dvs-cli-copy {
  appearance: none;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: #0369a1;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.28rem 0.68rem;
  border-radius: 7px;
  cursor: pointer;
}
.dvs-cli-copy:hover {
  background: #0284c7;
}
.dvs-cli-card pre {
  margin: 0 !important;
  padding: 1rem 1.1rem !important;
  background: #0b1120 !important;
  color: #e2e8f0 !important;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.80rem;
  line-height: 1.58;
  overflow-x: auto;
  border: none !important;
}
.dvs-cli-card pre code {
  background: transparent !important;
  color: #e2e8f0 !important;
  padding: 0 !important;
  border: none !important;
  white-space: pre !important;
  word-break: normal !important;
}
.dvs-cli-note {
  padding: 0.65rem 1rem;
  font-size: 0.81rem;
  line-height: 1.5;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.78);
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}
.dvs-cli-note strong {
  color: #6ee7b7 !important;
}

/* Bilingual inline SVG switching */
html[data-lang="pt"] svg.lang-en,
html[data-lang="pt-br"] svg.lang-en,
html:not([data-lang="en"]) svg.lang-en {
  display: none !important;
}
html[data-lang="en"] svg.lang-pt {
  display: none !important;
}

/* Clean Block Pedagogy Panel (Light & Dark WCAG AA >= 6:1) */
.dvs-ped-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 270px), 1fr));
  gap: 0.9rem;
  margin: 0.85rem 0;
}
.dvs-ped-box {
  background: var(--bg-primary, #ffffff);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 12px;
  padding: 0.95rem 1.05rem;
}
html[data-theme="dark"] .dvs-ped-box {
  background: rgba(15, 23, 42, 0.78);
  border-color: rgba(71, 85, 105, 0.55);
}
.dvs-ped-box h4 {
  margin: 0 0 0.45rem;
  font-size: 0.92rem;
  font-weight: 800;
  color: #0369a1;
}
html[data-theme="dark"] .dvs-ped-box h4 {
  color: #7dd3fc;
}
.dvs-ped-portraits {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 0.75rem;
  margin-top: 0.9rem;
}
.dvs-ped-person {
  display: flex;
  align-items: center;
  gap: 0.72rem;
  padding: 0.65rem 0.75rem;
  border-radius: 11px;
  background: var(--bg-primary, #ffffff);
  border: 1px solid rgba(148, 163, 184, 0.28);
}
html[data-theme="dark"] .dvs-ped-person {
  background: rgba(15, 23, 42, 0.78);
  border-color: rgba(71, 85, 105, 0.5);
}
.dvs-ped-person img {
  width: 54px !important;
  height: 54px !important;
  border-radius: 50%;
  object-fit: cover !important;
  object-position: center 20% !important;
  flex-shrink: 0;
  border: 2px solid rgba(3, 105, 161, 0.45);
}
.dvs-ped-person-name {
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--text-primary, #0f172a);
}
.dvs-ped-person-role {
  font-size: 0.75rem;
  line-height: 1.38;
  color: var(--text-secondary, #475569);
}
html[data-theme="dark"] .dvs-ped-person-name { color: #f8fafc; }
html[data-theme="dark"] .dvs-ped-person-role { color: #cbd5e1; }


/* ============================================================================
   DVS CYCLE 7A — ZERO-RESIDUAL GATE-2 P0/P1/P2 CONTRAST, GRID & CLI POLISH
   ============================================================================ */

/* P0-1 & P0-2 guaranteed protection */
a.btn-primary, button.btn-primary, .btn-primary, .btn.btn-primary {
  color: #ffffff !important;
}
.m0-hero .m0-pill {
  color: #bae6fd !important;
}

/* P0-3 Specificity win (0,4,4) over generic svg:not(.katex svg) Light amber rule */
html:not([data-theme="dark"]) .md-concept-svg-card svg:not(.katex svg) text[fill="#f59e0b"],
html:not([data-theme="dark"]) .md-concept-svg-card svg:not(.katex svg) text[fill="#d97706"],
html:not([data-theme="dark"]) #dvs-m0-svg:not(.katex svg) text[fill="#f59e0b"],
html:not([data-theme="dark"]) #dvs-m0-svg:not(.katex svg) text[fill="#d97706"] {
  fill: #fbbf24 !important;
}

/* P0-4 & P1-4 Catch JS-applied rgb(...) inline styles, --accent-emerald & verdict IDs in Light Mode (>= 5.5:1) */
html:not([data-theme="dark"]) [style*="rgb(217, 119, 6)"],
html:not([data-theme="dark"]) [style*="color:#d97706"],
html:not([data-theme="dark"]) [style*="color: #d97706"] {
  color: #92400e !important;
}
html:not([data-theme="dark"]) [style*="rgb(5, 150, 105)"],
html:not([data-theme="dark"]) [style*="accent-emerald"],
html:not([data-theme="dark"]) [style*="color:#059669"],
html:not([data-theme="dark"]) [style*="color: #059669"] {
  color: #047857 !important;
}
html:not([data-theme="dark"]) [style*="rgb(220, 38, 38)"],
html:not([data-theme="dark"]) [style*="color:#dc2626"],
html:not([data-theme="dark"]) [style*="color: #dc2626"] {
  color: #b91c1c !important;
}
/* Restore Dark Mode luminous colors on JS-applied rgb(...) verdicts */
html[data-theme="dark"] [style*="rgb(217, 119, 6)"] { color: #fde68a !important; }
html[data-theme="dark"] [style*="rgb(220, 38, 38)"] { color: #fca5a5 !important; }
html[data-theme="dark"] [style*="rgb(5, 150, 105)"],
html[data-theme="dark"] [style*="accent-emerald"] { color: #34d399 !important; }

/* P1-3 Lift ALL 80/80 .dvs-prog-logo badges to pure #ffffff (>= 5.31:1 over darkened gradients) */
.dvs-prog-atlas .dvs-prog-logo,
.dvs-prog-logo {
  color: #ffffff !important;
}

/* P1-1 Fix dvs-labs.html .qm-readout-grid 5-column dead right gap -> exact 4-column desktop grid */
.qm-readout-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
}
@media (max-width: 900px) {
  .qm-readout-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}
@media (max-width: 520px) {
  .qm-readout-grid {
    grid-template-columns: 1fr !important;
  }
}

/* P2-1 Deepen 3 Light-mode simulator SVG text fills (>= 5.2:1) */
html:not([data-theme="dark"]) #dvs-b2-sim5-svg text[fill="#b91c1c"] {
  fill: #991b1b !important;
}
html:not([data-theme="dark"]) #dvs-b3-sim10-svg text[fill="#0f766e"],
html:not([data-theme="dark"]) #dvs-b3-sim10-svg text[fill="#0d9488"] {
  fill: #115e59 !important;
}
html:not([data-theme="dark"]) #dvs-b4-sim14-svg text[fill="#3b82f6"] {
  fill: #1d4ed8 !important;
}

/* P2-2 Preserve exact scientific unit case (μM vs mM, pH, pKa) — NEVER uppercase! */
.qm-readout-label,
.ro-label,
.readout-label {
  text-transform: none !important;
  letter-spacing: 0.01em !important;
}

/* Sleek dark-slate inline code badges inside dark .dvs-cli-note footer */
.dvs-cli-note code {
  background: rgba(56, 189, 248, 0.16) !important;
  color: #7dd3fc !important;
  border: 1px solid rgba(56, 189, 248, 0.32) !important;
  padding: 0.1rem 0.35rem !important;
  border-radius: 5px !important;
}


/* ============================================================================
   DVS CYCLE 8 — ATLAS INTERACTIVE SUITE, MATRIX, ROSETTA & WCAG AA CONTRAST
   ============================================================================ */

/* Semantic WCAG AA (>= 5.5:1 Light & >= 8.5:1 Dark) card text classes */
.dvs-atlas-warn { color: #92400e !important; }
html[data-theme="dark"] .dvs-atlas-warn { color: #fcd34d !important; }

.dvs-atlas-ok { color: #047857 !important; }
html[data-theme="dark"] .dvs-atlas-ok { color: #6ee7b7 !important; }

.dvs-atlas-err { color: #b91c1c !important; }
html[data-theme="dark"] .dvs-atlas-err { color: #fca5a5 !important; }

.dvs-atlas-symptom { color: #991b1b !important; }
html[data-theme="dark"] .dvs-atlas-symptom { color: #fca5a5 !important; }
.dvs-atlas-symptom code {
  color: inherit !important;
  background: rgba(220, 38, 38, 0.08) !important;
  border: 1px solid rgba(220, 38, 38, 0.25) !important;
  padding: 0.14rem 0.42rem !important;
  border-radius: 6px !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  display: inline;
  white-space: normal;
  word-break: break-word;
}
html[data-theme="dark"] .dvs-atlas-symptom code {
  background: rgba(248, 113, 113, 0.14) !important;
  border-color: rgba(248, 113, 113, 0.34) !important;
}

.dvs-atlas-head-accent { color: #0369a1 !important; }
html[data-theme="dark"] .dvs-atlas-head-accent { color: #38bdf8 !important; }

/* KaTeX Equation Box inside Atlas Cards */
.dvs-atlas-eq {
  background: rgba(2, 132, 199, 0.065);
  border: 1px solid rgba(2, 132, 199, 0.24);
  border-left: 3px solid #0284c7;
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
  margin: 0.45rem 0;
  color: #0c4a6e;
  font-size: 0.9rem;
  overflow-x: auto;
  max-width: 100%;
  box-sizing: border-box;
}
html[data-theme="dark"] .dvs-atlas-eq {
  background: rgba(14, 165, 233, 0.12);
  border-color: rgba(56, 189, 248, 0.3);
  border-left-color: #38bdf8;
  color: #e0f2fe;
}
.dvs-atlas-eq .katex { font-size: 1.02em; }

/* Quick-Jump Navigation Strip */
.dvs-atlas-jumpbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.25rem 0 1.75rem;
  padding: 0.75rem 0.9rem;
  border-radius: 14px;
  background: rgba(248, 250, 252, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.35);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05);
}
html[data-theme="dark"] .dvs-atlas-jumpbar {
  background: rgba(15, 23, 42, 0.85);
  border-color: rgba(71, 85, 105, 0.5);
}
.dvs-atlas-jump-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.82rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
  color: #0f172a;
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.45);
  transition: all 0.16s ease;
}
.dvs-atlas-jump-pill:hover {
  background: #0369a1;
  color: #ffffff !important;
  border-color: #0369a1;
  transform: translateY(-1px);
}
html[data-theme="dark"] .dvs-atlas-jump-pill {
  color: #e2e8f0;
  background: rgba(30, 41, 59, 0.95);
  border-color: rgba(100, 116, 139, 0.55);
}
html[data-theme="dark"] .dvs-atlas-jump-pill:hover {
  background: #0369a1;
  color: #ffffff !important;
  border-color: #38bdf8;
}

/* Shared Filter Chips & Search Bar (Matrix, Atlas 2/3 & 18 Forensic Cases) */
.dvs-atlas-filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.75rem 0 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: rgba(248, 250, 252, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.35);
}
html[data-theme="dark"] .dvs-atlas-filterbar {
  background: rgba(15, 23, 42, 0.86);
  border-color: rgba(71, 85, 105, 0.52);
}
.dvs-atlas-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.dvs-atlas-chip {
  appearance: none;
  font-family: inherit;
  font-size: 0.79rem;
  font-weight: 700;
  padding: 0.4rem 0.78rem;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid rgba(100, 116, 139, 0.42);
  background: #ffffff;
  color: #1e293b;
  transition: all 0.15s ease;
}
.dvs-atlas-chip:hover {
  border-color: #0369a1;
  color: #0369a1;
}
.dvs-atlas-chip.is-active {
  background: #0369a1;
  color: #ffffff !important;
  border-color: #0369a1;
  box-shadow: 0 3px 10px rgba(3, 105, 161, 0.25);
}
html[data-theme="dark"] .dvs-atlas-chip {
  background: #1e293b;
  color: #e2e8f0;
  border-color: rgba(100, 116, 139, 0.55);
}
html[data-theme="dark"] .dvs-atlas-chip:hover {
  border-color: #38bdf8;
  color: #7dd3fc;
}
html[data-theme="dark"] .dvs-atlas-chip.is-active {
  background: #0369a1;
  color: #ffffff !important;
  border-color: #38bdf8;
}
.dvs-atlas-search-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 220px;
  max-width: 380px;
}
.dvs-atlas-search {
  width: 100%;
  padding: 0.48rem 0.85rem;
  border-radius: 10px;
  border: 1px solid rgba(100, 116, 139, 0.45);
  background: #ffffff;
  color: #0f172a;
  font-family: inherit;
  font-size: 0.84rem;
  box-sizing: border-box;
}
.dvs-atlas-search:focus {
  outline: 2px solid #0284c7;
  outline-offset: 1px;
}
html[data-theme="dark"] .dvs-atlas-search {
  background: #0f172a;
  color: #f1f5f9;
  border-color: rgba(100, 116, 139, 0.6);
}
.dvs-atlas-count {
  font-size: 0.77rem;
  font-weight: 800;
  white-space: nowrap;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: rgba(3, 105, 161, 0.12);
  color: #0369a1;
}
html[data-theme="dark"] .dvs-atlas-count {
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
}

/* Target x Engine Compatibility Matrix Table */
.dvs-matrix-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.38);
  background: #ffffff;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
}
html[data-theme="dark"] .dvs-matrix-wrap {
  background: #0f172a;
  border-color: rgba(71, 85, 105, 0.55);
}
.dvs-matrix-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.84rem;
  text-align: left;
}
.dvs-matrix-table thead th {
  background: #0f172a;
  color: #f8fafc;
  font-weight: 800;
  padding: 0.78rem 0.9rem;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  border-bottom: 2px solid #0284c7;
}
html[data-theme="dark"] .dvs-matrix-table thead th {
  background: #1e293b;
  color: #f8fafc;
}
.dvs-matrix-table tbody td {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  color: #1e293b;
  vertical-align: top;
  line-height: 1.5;
}
html[data-theme="dark"] .dvs-matrix-table tbody td {
  color: #e2e8f0;
  border-bottom-color: rgba(71, 85, 105, 0.45);
}
.dvs-matrix-table tbody tr:nth-child(even) {
  background: rgba(248, 250, 252, 0.85);
}
html[data-theme="dark"] .dvs-matrix-table tbody tr:nth-child(even) {
  background: rgba(30, 41, 59, 0.45);
}
.dvs-matrix-pill {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.16rem 0.5rem;
  border-radius: 6px;
  margin: 0.1rem 0.15rem 0.1rem 0;
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid rgba(3, 105, 161, 0.28);
}
html[data-theme="dark"] .dvs-matrix-pill {
  background: rgba(14, 165, 233, 0.2);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.38);
}

/* Interactive CLI Rosetta Stone */
.dvs-rosetta-card {
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: #ffffff;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}
html[data-theme="dark"] .dvs-rosetta-card {
  background: #0f172a;
  border-color: rgba(71, 85, 105, 0.55);
}
.dvs-rosetta-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.85rem 1rem;
  background: #f1f5f9;
  border-bottom: 1px solid rgba(148, 163, 184, 0.35);
}
html[data-theme="dark"] .dvs-rosetta-tabs {
  background: #1e293b;
  border-bottom-color: rgba(71, 85, 105, 0.55);
}
.dvs-rosetta-tab {
  appearance: none;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.45rem 0.85rem;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid rgba(100, 116, 139, 0.4);
  background: #ffffff;
  color: #1e293b;
  transition: all 0.15s ease;
}
.dvs-rosetta-tab.is-active {
  background: #0f172a;
  color: #ffffff !important;
  border-color: #0f172a;
}
html[data-theme="dark"] .dvs-rosetta-tab {
  background: #0f172a;
  color: #cbd5e1;
  border-color: rgba(100, 116, 139, 0.5);
}
html[data-theme="dark"] .dvs-rosetta-tab.is-active {
  background: #0369a1;
  color: #ffffff !important;
  border-color: #38bdf8;
}
.dvs-rosetta-pane {
  display: none;
  padding: 1rem 1.15rem 1.15rem;
}
.dvs-rosetta-pane.is-active {
  display: block;
}
.dvs-rosetta-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.7rem;
}
.dvs-rosetta-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: #0f172a;
}
html[data-theme="dark"] .dvs-rosetta-title { color: #f8fafc; }
.dvs-rosetta-copy {
  appearance: none;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.36rem 0.78rem;
  border-radius: 8px;
  cursor: pointer;
  background: #0369a1;
  color: #ffffff !important;
  border: 1px solid #0369a1;
  transition: opacity 0.15s ease;
}
.dvs-rosetta-copy:hover { opacity: 0.9; }
.dvs-rosetta-pre {
  margin: 0;
  padding: 0.95rem 1.05rem;
  border-radius: 10px;
  background: #0b1120 !important;
  color: #e2e8f0 !important;
  border: 1px solid rgba(56, 189, 248, 0.25);
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.56;
  max-width: 100%;
  box-sizing: border-box;
}
.dvs-rosetta-pre code {
  background: transparent !important;
  color: #e2e8f0 !important;
  border: none !important;
  padding: 0 !important;
  font-size: inherit;
}
.dvs-rosetta-note {
  margin: 0.65rem 0 0;
  font-size: 0.82rem;
  line-height: 1.5;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  background: rgba(14, 165, 233, 0.08);
  border-left: 3px solid #0284c7;
  color: #0c4a6e;
}
html[data-theme="dark"] .dvs-rosetta-note {
  background: rgba(14, 165, 233, 0.14);
  color: #bae6fd;
}
.dvs-rosetta-note code {
  background: rgba(15, 23, 42, 0.1);
  color: inherit;
  padding: 0.08rem 0.32rem;
  border-radius: 4px;
  font-size: 0.79rem;
}
html[data-theme="dark"] .dvs-rosetta-note code {
  background: rgba(56, 189, 248, 0.18);
  color: #e0f2fe;
}

/* Re-assert .btn-primary protection at bottom of cascade */
a.btn-primary, button.btn-primary, .btn-primary, .btn.btn-primary {
  color: #ffffff !important;
}


/* ============================================================================
   DVS CYCLE 10 — ZERO-RESIDUAL WCAG AA & SVG THEME-AWARE CONTRAST POLISH
   ============================================================================ */

/* P1-8 Theme-aware SVG labels for DScore & simulator charts (>= 6.8:1 Light & Dark) */
.dvs-svg-danger-txt { fill: #991b1b !important; }
html[data-theme="dark"] .dvs-svg-danger-txt { fill: #fca5a5 !important; }

.dvs-svg-warn-txt { fill: #92400e !important; }
html[data-theme="dark"] .dvs-svg-warn-txt { fill: #fde68a !important; }

.dvs-svg-ok-txt { fill: #047857 !important; }
html[data-theme="dark"] .dvs-svg-ok-txt { fill: #6ee7b7 !important; }

/* P2-12 Hero inline <code> high contrast (>= 8.5:1) in Light & Dark on dark hero */
.m0-hero code,
html[data-theme="dark"] .m0-hero code {
  background: rgba(15, 23, 42, 0.62) !important;
  color: #e0f2fe !important;
  border: 1px solid rgba(125, 211, 252, 0.38) !important;
  padding: 0.08rem 0.36rem !important;
  border-radius: 5px !important;
}

/* P2-14 Comfortable bottom clearance above floating #qm-unit-fab */
main.container {
  padding-bottom: 4.5rem;
}

/* Re-assert .btn-primary & active CTA contrast at bottom of cascade */
a.btn-primary, button.btn-primary, .btn-primary, .btn.btn-primary {
  color: #ffffff !important;
}


/* ============================================================================
   DVS CYCLE 10 — ZERO-RESIDUAL WCAG AA & SVG THEME-AWARE CONTRAST POLISH
   ============================================================================ */

/* P1-8 Theme-aware SVG labels for DScore & simulator charts (>= 6.8:1 Light & Dark) */
.dvs-svg-danger-txt { fill: #991b1b !important; }
html[data-theme="dark"] .dvs-svg-danger-txt { fill: #fca5a5 !important; }

.dvs-svg-warn-txt { fill: #92400e !important; }
html[data-theme="dark"] .dvs-svg-warn-txt { fill: #fde68a !important; }

.dvs-svg-ok-txt { fill: #047857 !important; }
html[data-theme="dark"] .dvs-svg-ok-txt { fill: #6ee7b7 !important; }

/* P2-12 Hero inline <code> high contrast (>= 8.5:1) in Light & Dark on dark hero */
.m0-hero code,
html[data-theme="dark"] .m0-hero code {
  background: rgba(15, 23, 42, 0.62) !important;
  color: #e0f2fe !important;
  border: 1px solid rgba(125, 211, 252, 0.38) !important;
  padding: 0.08rem 0.36rem !important;
  border-radius: 5px !important;
}

/* P2-14 Comfortable bottom clearance above floating #qm-unit-fab */
main.container {
  padding-bottom: 4.5rem;
}

/* Re-assert .btn-primary & active CTA contrast at bottom of cascade */
a.btn-primary, button.btn-primary, .btn-primary, .btn.btn-primary {
  color: #ffffff !important;
}

/* Cycle 10-C: BEDROC SVG badge pill high contrast in Dark Mode (11.5:1 vs #7dd3fc text) */
.dvs-bedroc-pill {
  fill: rgba(241, 245, 249, 0.94);
  stroke: #93c5fd;
}
html[data-theme="dark"] .dvs-bedroc-pill,
html[data-theme="dark"] #dvslab-bedroc-widget svg rect[fill="rgba(241,245,249,0.92)"] {
  fill: rgba(15, 23, 42, 0.94) !important;
  stroke: #38bdf8 !important;
}

/* === PHASE 4 DVS LAB BADGE & INTERACTIVE SIMULATOR POLISH === */
.qm-lab-widget {
  background: var(--bg-card, #ffffff);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 16px;
  padding: 1.25rem 1.35rem;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
}
html[data-theme="dark"] .qm-lab-widget {
  background: rgba(15, 23, 42, 0.72);
  border-color: rgba(148, 163, 184, 0.22);
}
.qm-lab-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}
.qm-lab-header h4 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.35;
}
.qm-lab-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.24rem 0.68rem;
  border-radius: 999px;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: rgba(2, 132, 199, 0.12);
  color: #0369a1;
  border: 1px solid rgba(2, 132, 199, 0.28);
  white-space: nowrap;
}
html[data-theme="dark"] .qm-lab-badge {
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.34);
}
.dvs-live-svg-wrap svg {
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.22);
}

/* === PHASE 5 INTERACTIVE 3DMOL.JS WEBGL STUDIO === */
.dvs-3d-shell {
  margin: 1.4rem 0;
  padding: 1.15rem 1.25rem;
  border-radius: 16px;
  background: linear-gradient(180deg, #0b1120 0%, #0f172a 100%);
  border: 1px solid rgba(56, 189, 248, 0.34);
  box-shadow: 0 12px 34px rgba(2, 6, 23, 0.28);
  color: #f8fafc;
}
.dvs-3d-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.dvs-3d-title {
  font-size: 0.98rem;
  font-weight: 800;
  color: #f8fafc;
  letter-spacing: -0.01em;
}
.dvs-3d-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(56, 189, 248, 0.14);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.32);
}
.dvs-3d-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.7rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}
.dvs-3d-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  margin-bottom: 0.7rem;
}
.dvs-3d-ctrls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.42rem;
}
.dvs-3d-btn {
  appearance: none;
  cursor: pointer;
  padding: 0.36rem 0.78rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.34);
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  transition: all 0.16s ease;
}
.dvs-3d-btn:hover {
  border-color: #38bdf8;
  color: #ffffff;
  background: rgba(2, 132, 199, 0.28);
}
.dvs-3d-btn.is-active {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  border-color: #38bdf8;
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.4);
}
.dvs-3d-slider-lbl {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: #e2e8f0;
  background: rgba(30, 41, 59, 0.75);
  padding: 0.32rem 0.72rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.28);
}
.dvs-3d-slider-lbl input[type="range"] {
  width: 145px;
  accent-color: #38bdf8;
}
.dvs-3d-status {
  margin-top: 0.7rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.24);
  font-size: 0.84rem;
  line-height: 1.5;
  color: #e2e8f0;
}
.dvs-3d-slider-lbl strong {
  color: #38bdf8 !important;
  font-weight: 800;
}
.dvs-3d-status strong {
  color: #f8fafc !important;
}
@media (max-width: 640px) {
  .dvs-3d-shell { padding: 0.9rem; }
  .dvs-3d-stage { height: 300px !important; }
  .dvs-3d-slider-lbl { flex-wrap: wrap; }
}

/* === CYCLE 1 SURGICAL UX, CONTRAST, FAB & SLIDER HARDENING === */
/* P2-7: Light Mode .qm-lab-badge WCAG AA/AAA contrast (> 6.8:1) */
.qm-lab-badge {
  background: #e0f2fe !important;
  color: #075985 !important;
  border-color: rgba(3, 105, 161, 0.34) !important;
}
html[data-theme="dark"] .qm-lab-badge {
  background: rgba(56, 189, 248, 0.18) !important;
  color: #bae6fd !important;
  border-color: rgba(56, 189, 248, 0.38) !important;
}

/* P1-8: Prevent decimal slider readout numbers from fracturing across lines */
.qm-control-group label,
.qm-control-item label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}
.qm-control-group label > span:last-child,
.qm-control-item label > span[id$="-val"],
span[id$="-label"] {
  white-space: nowrap !important;
  flex-shrink: 0 !important;
}

/* P1-7: Dark Mode WCAG AAA contrast for Ch. 16 Modern Benchmarks table */
.dvs-bm-rose { color: #be123c; font-weight: 800; }
.dvs-bm-blue { color: #0369a1; font-weight: 800; }
.dvs-bm-purple { color: #6d28d9; font-weight: 800; }
.dvs-bm-emerald { color: #047857; font-weight: 800; }
html[data-theme="dark"] .dvs-bm-rose { color: #fda4af !important; }
html[data-theme="dark"] .dvs-bm-blue { color: #7dd3fc !important; }
html[data-theme="dark"] .dvs-bm-purple { color: #c4b5fd !important; }
html[data-theme="dark"] .dvs-bm-emerald { color: #6ee7b7 !important; }

/* P1-5: Compact non-intrusive floating DVS Affinity FAB (zero content intrusion!) */
.qm-unit-fab {
  right: 12px !important;
  bottom: 12px !important;
  padding: 0.45rem 0.62rem !important;
  font-size: 0.78rem !important;
  border-radius: 999px !important;
  opacity: 0.90;
  z-index: 900 !important;
}
@media (max-width: 1580px) {
  .qm-unit-fab {
    width: 42px !important;
    height: 42px !important;
    padding: 0 !important;
    justify-content: center !important;
    overflow: hidden !important;
  }
  .qm-unit-fab .lang-pt,
  .qm-unit-fab .lang-en {
    display: none !important;
  }
}

/* P2-4: Clean #qm-unit-popover header close alignment & unclipped select */
.qm-unit-head {
  display: flex !important;
  align-items: flex-start !important;
  justify-content: space-between !important;
  flex-wrap: nowrap !important;
  gap: 0.55rem !important;
}
#qm-unit-close {
  flex-shrink: 0 !important;
  margin-left: auto !important;
  line-height: 1 !important;
  padding: 0.15rem 0.3rem !important;
}
#qm-unit-type {
  min-width: 0 !important;
  max-width: 100% !important;
  font-size: 0.8rem !important;
  padding: 0.35rem 1.45rem 0.35rem 0.45rem !important;
  text-overflow: ellipsis !important;
}
.qm-unit-popover {
  width: min(360px, calc(100vw - 24px)) !important;
  right: 12px !important;
  bottom: 62px !important;
}

/* P2-7: Left-align narrow mobile card prose for crisp reading rhythm */
@media (max-width: 480px) {
  .portal-card p,
  .concept-card p {
    text-align: left !important;
  }
}
