:root {
  --nm-ink: #17212b;
  --nm-muted: #667281;
  --nm-line: #d8dee7;
  --nm-line-strong: #bdc7d3;
  --nm-paper: #f4f7fa;
  --nm-surface: #ffffff;
  --nm-surface-soft: #f8fafc;
  --nm-shadow: 0 12px 32px rgba(28, 39, 52, 0.075);
  --nm-topbar: #151c27;
  --nm-topbar-line: #2b3543;
  --topic-accent: #176cc2;
  --topic-accent-dark: #105493;
  --topic-accent-soft: #eaf3fc;
}

body.topic-neural {
  --topic-accent: #176cc2;
  --topic-accent-dark: #105493;
  --topic-accent-soft: #eaf3fc;
}

body.topic-immune {
  --topic-accent: #176b63;
  --topic-accent-dark: #10534d;
  --topic-accent-soft: #e4f1ed;
}

body.topic-dna {
  --topic-accent: #9a3f64;
  --topic-accent-dark: #742d4a;
  --topic-accent-soft: #f4e6ec;
}

html,
body {
  min-width: 320px;
  background: var(--nm-paper);
  color: var(--nm-ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body.welcome-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--topic-accent) 30%, transparent);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 46px;
  min-height: 46px;
  padding: 0 20px;
  border-bottom: 1px solid var(--nm-topbar-line);
  background: var(--nm-topbar);
  color: #ffffff;
  backdrop-filter: none;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #ffffff;
  text-decoration: none;
}

.topbar .brand-mark {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--topic-accent);
  color: #ffffff;
  font-size: 10px;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.topbar .brand-text,
.topbar .brand-copy {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.topbar .brand-title,
.topbar .brand-copy strong {
  color: #f8fafc;
  font-size: 13px;
  line-height: 1.1;
  font-weight: 800;
  white-space: nowrap;
}

.topbar .brand-subtitle,
.topbar .brand-copy small {
  margin: 0;
  padding-left: 9px;
  border-left: 1px solid #354052;
  color: #aeb9c7;
  font-size: 10.5px;
  line-height: 1.1;
  white-space: nowrap;
}

.topbar .top-actions,
.topbar .topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.topbar .mode-switch {
  display: flex;
  gap: 4px;
  padding: 0;
  border: 0;
  background: transparent;
}

.topbar .top-button,
.topbar .topics-link,
.topbar .mode-button {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 10px;
  border: 1px solid #354052;
  border-radius: 6px;
  background: #1c2532;
  color: #dce3ec;
  box-shadow: none;
  font-size: 11px;
  font-weight: 750;
  line-height: 1;
  text-decoration: none;
}

.topbar .top-button:hover,
.topbar .topics-link:hover,
.topbar .mode-button:hover {
  border-color: #536074;
  background: #253142;
  color: #ffffff;
}

.topbar .top-button.active,
.topbar .mode-button.active {
  border-color: #ffffff;
  background: #ffffff;
  color: #17212b;
  box-shadow: none;
}

.app,
.app-shell {
  width: min(1240px, calc(100% - 36px));
  max-width: none;
  margin: 0 auto;
  padding: 18px 0 30px;
}

.learning-header,
.page-heading {
  min-height: 0;
  margin: 0 0 12px;
}

.main-title,
.page-heading h1 {
  margin: 0;
  color: var(--nm-ink);
  font-size: 24px;
  line-height: 1.15;
  font-weight: 820;
}

.level-nav,
.level-navigation {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin: 0 0 12px;
  padding: 0;
  border: 0;
  background: transparent;
}

.level-nav::before,
.level-nav-track-active {
  display: none;
}

.level-tab,
.level-button {
  position: relative;
  min-width: 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  padding: 7px 11px;
  overflow: hidden;
  border: 1px solid var(--nm-line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--nm-ink);
  text-align: left;
}

.level-tab:hover,
.level-button:hover {
  border-color: var(--nm-line-strong);
  background: #ffffff;
}

.level-tab.active,
.level-button.active {
  border-color: var(--topic-accent);
  background: var(--topic-accent-soft);
  color: var(--topic-accent-dark);
}

.level-tab.locked {
  opacity: 0.58;
}

.level-tab .number,
.level-number {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: #7c8997;
  color: #ffffff;
  font-size: 11px;
  font-weight: 850;
}

.level-tab.active .number,
.level-button.active .level-number {
  background: var(--topic-accent-dark);
  color: #ffffff;
}

.level-tab .label,
.level-name {
  min-width: 0;
  overflow: hidden;
  color: inherit;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lesson-shell,
.lesson-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(330px, 0.78fr);
  gap: 0;
  min-height: min(650px, calc(100vh - 146px));
  overflow: hidden;
  border: 1px solid var(--nm-line);
  border-radius: 8px;
  background: var(--nm-surface);
  box-shadow: var(--nm-shadow);
}

.visual-stage,
.visual-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 0;
  border-right: 1px solid var(--nm-line);
  border-radius: 0;
  background: #fbfcfd;
  box-shadow: none;
}

.visual-titlebar,
.panel-heading {
  min-height: 52px;
  padding: 0 17px;
  border-bottom: 1px solid var(--nm-line);
  background: rgba(255, 255, 255, 0.94);
}

.visual-title,
.panel-heading h2 {
  color: var(--nm-ink);
  font-size: 14px;
  font-weight: 800;
}

.visual-status,
.panel-heading span {
  border: 0;
  border-radius: 4px;
  background: var(--topic-accent-soft);
  color: var(--topic-accent-dark);
  font-size: 11px;
  font-weight: 760;
}

.visual-status {
  padding: 5px 8px;
}

.visual-wrap,
.visual-canvas {
  min-height: calc(100% - 52px);
  padding: 12px;
}

.lesson-panel {
  min-width: 0;
  min-height: 0;
  padding: clamp(24px, 3vw, 42px);
  border: 0;
  border-radius: 0;
  background: #ffffff;
  box-shadow: none;
}

.lesson-kicker,
.step-label,
.compact-heading p {
  color: var(--topic-accent);
}

.lesson-title,
.lesson-panel h2 {
  color: var(--nm-ink);
  font-size: clamp(24px, 2.35vw, 34px);
  line-height: 1.12;
  font-weight: 820;
}

.lesson-text {
  color: #3f4c59;
  font-size: clamp(15px, 1.15vw, 18px);
  line-height: 1.58;
}

.step-dot,
.step-progress span {
  height: 4px;
  border-radius: 2px;
  background: #e0e5eb;
}

.step-dot.done,
.step-dot.active,
.step-progress span.complete {
  background: var(--topic-accent);
}

.primary-button {
  border-color: var(--topic-accent-dark);
  border-radius: 6px;
  background: var(--topic-accent-dark);
}

.secondary-button {
  border-color: var(--nm-line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: #344252;
}

.welcome-modal {
  background: rgba(15, 23, 34, 0.54);
}

.welcome-card {
  width: min(470px, 100%);
  padding: 20px;
  border: 1px solid #d1d8e1;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 28px 80px rgba(15, 23, 34, 0.25);
}

.welcome-brand {
  width: 34px;
  height: 34px;
  margin: 0 0 15px;
  border-radius: 7px;
  background: var(--topic-accent-dark);
}

.welcome-title,
.welcome-card h1 {
  margin: 0 0 6px;
  color: var(--nm-ink);
  font-size: 24px;
  line-height: 1.15;
  font-weight: 830;
}

.welcome-summary {
  margin: 0 0 15px;
  color: var(--nm-muted);
  font-size: 13px;
  line-height: 1.45;
}

.welcome-options {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.welcome-option {
  min-height: 58px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--nm-line);
  border-radius: 7px;
  background: #fbfcfe;
  text-align: left;
}

.welcome-option.selected {
  border-color: var(--topic-accent);
  background: var(--topic-accent-soft);
}

.welcome-icon {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: var(--topic-accent-soft);
  color: var(--topic-accent-dark);
}

.welcome-option:nth-child(2) .welcome-icon {
  background: #fff0e8;
  color: #a94f28;
}

.welcome-option strong,
.welcome-option h2 {
  margin: 0;
  color: var(--nm-ink);
  font-size: 14px;
  line-height: 1.2;
  font-weight: 800;
}

.welcome-option small,
.welcome-option p {
  margin: 3px 0 0;
  color: var(--nm-muted);
  font-size: 12px;
  line-height: 1.3;
}

.welcome-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.welcome-button,
.welcome-start {
  min-height: 44px;
  margin: 0;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 800;
}

.welcome-button.primary,
.welcome-start {
  border-color: var(--topic-accent-dark);
  background: var(--topic-accent-dark);
  color: #ffffff;
}

body.lab-portal-mode {
  height: 100vh;
  overflow: hidden;
  background: #f6f8fa;
}

body.lab-portal-mode .topbar {
  height: 42px;
  min-height: 42px;
}

body.lab-portal-mode .app,
body.lab-portal-mode .app-shell {
  width: 100%;
  height: calc(100vh - 42px);
  min-height: calc(100vh - 42px);
  margin: 0;
  padding: 0;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .story-strip {
  display: none;
}

body.lab-portal-mode #labView.active {
  display: flex;
  min-height: calc(100vh - 42px);
  flex-direction: column;
  background: #f6f8fa;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-level-navigation {
  height: 48px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  width: 100%;
  margin: 0;
  padding: 5px max(12px, calc((100% - 880px) / 2));
  flex: 0 0 auto;
  border-bottom: 1px solid var(--nm-line);
  background: #ffffff;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-level-navigation .level-button {
  min-height: 36px;
  justify-content: center;
  padding: 4px 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-level-navigation .level-button.active {
  background: var(--topic-accent-soft);
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-level-navigation .level-number {
  width: 22px;
  height: 22px;
  font-size: 10px;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-level-navigation .level-name {
  font-size: 10px;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-layout {
  flex: 1 1 auto;
  min-height: 0;
  height: calc(100vh - 90px);
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 288px;
  grid-template-rows: minmax(0, 1fr) 240px;
  grid-template-areas:
    "questions visual controls"
    "questions graph controls";
  gap: 0;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-question {
  grid-area: questions;
  border-right: 1px solid var(--nm-line);
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-visual {
  grid-area: visual;
  border-bottom: 1px solid var(--nm-line);
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-controls {
  grid-area: controls;
  border-left: 1px solid var(--nm-line);
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-graph {
  grid-area: graph;
}

body.lab-portal-mode .panel,
body.lab-portal-mode .lab-controls,
body.lab-portal-mode .lab-output,
body.lab-portal-mode .lab-guide-panel,
body.lab-portal-mode .lab-bottom-panel {
  border-radius: 0;
  box-shadow: none;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-controls,
body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-question {
  padding: 0;
  background: #ffffff;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .compact-heading {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 10px 15px;
  border-bottom: 1px solid var(--nm-line);
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .compact-heading p {
  display: none;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .compact-heading h2 {
  margin: 0;
  color: #5d6876;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode #labControls,
body:is(.topic-immune, .topic-dna).lab-portal-mode #questionPanel {
  padding: 13px 15px;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .control-group {
  margin: 0 0 11px;
  padding: 10px;
  border-radius: 6px;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .reset-button {
  width: calc(100% - 30px);
  margin: 0 15px 14px;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .panel-heading {
  position: absolute;
  z-index: 3;
  top: 15px;
  left: 22px;
  right: 22px;
  min-height: 0;
  justify-content: flex-start;
  padding: 0;
  border: 0;
  background: transparent;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .panel-heading h2,
body:is(.topic-immune, .topic-dna).lab-portal-mode .panel-heading span {
  padding: 5px 8px;
  border: 1px solid var(--nm-line);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 1px 4px rgba(23, 33, 43, 0.06);
  font-size: 11px;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .panel-heading span {
  max-width: 250px;
  border-color: color-mix(in srgb, var(--topic-accent) 28%, #ffffff);
  background: var(--topic-accent-soft);
  color: var(--topic-accent-dark);
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-canvas {
  height: 100%;
  padding: 24px 24px 8px;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode #labSvg {
  width: 100%;
  height: 100%;
  max-height: none;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-graph {
  grid-template-columns: minmax(195px, 0.25fr) minmax(0, 1fr);
  border: 0;
  background: #ffffff;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .graph-summary {
  padding: 14px 18px;
}

body:is(.topic-immune, .topic-dna).lab-portal-mode .graph-wrap {
  padding: 6px 12px 6px 6px;
}

.situation-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-color: #e4aa73;
  border-radius: 6px;
  background: #fff7ed;
  color: #92451e;
}

.situation-button svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.situation-button:hover,
.situation-button.active {
  border-color: #b85a2f;
  background: #b85a2f;
  color: #ffffff;
}

.situation-stage-track {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 11px;
}

.situation-stage-track span {
  height: 4px;
  border-radius: 2px;
  background: #e1e6ec;
}

.situation-stage-track span.done,
.situation-stage-track span.active {
  background: #b85a2f;
}

body.lab-situation-mode .lab-sim-bar {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

body.lab-situation-mode .lab-sim-button {
  min-height: 27px;
  border: 1px solid var(--nm-line);
  border-radius: 5px;
  background: #ffffff;
  color: #4e5a68;
  padding: 3px 9px;
  font-size: 10px;
  font-weight: 800;
}

body.lab-situation-mode .reset-button {
  display: none;
}

@media (max-width: 900px) {
  .app,
  .app-shell {
    width: min(100% - 22px, 720px);
    padding-top: 14px;
  }

  .lesson-shell,
  .lesson-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .visual-stage,
  .visual-panel {
    border-right: 0;
    border-bottom: 1px solid var(--nm-line);
  }

  body.lab-portal-mode {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  body.lab-portal-mode .app,
  body.lab-portal-mode .app-shell,
  body.lab-portal-mode #labView.active {
    width: 100%;
    height: auto;
    min-height: 0;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-layout {
    height: auto;
    display: flex;
    flex-direction: column;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-visual {
    order: 3;
    min-height: 430px;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-graph {
    order: 4;
    min-height: 300px;
    display: block;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-controls {
    order: 2;
    overflow: visible;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-question {
    order: 1;
    overflow: visible;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 0 10px;
  }

  .topbar .brand-text,
  .topbar .brand-copy {
    display: none;
  }

  .topbar .top-button,
  .topbar .topics-link,
  .topbar .mode-button {
    min-height: 27px;
    padding: 0 7px;
    font-size: 10px;
  }

  .main-title,
  .page-heading h1 {
    font-size: 22px;
  }

  .level-nav,
  .level-navigation {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .level-navigation .level-name {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  .lesson-panel {
    padding: 22px 19px;
  }

  .welcome-card {
    padding: 18px;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-level-navigation {
    height: 60px;
    padding: 5px;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-level-navigation .level-button {
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 2px;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-level-navigation .level-name {
    font-size: 11.5px;
    white-space: normal;
    text-align: center;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-visual {
    min-height: 370px;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode .lab-graph {
    min-height: 340px;
  }

  body:is(.topic-immune, .topic-dna).lab-portal-mode :is(.segment-button, .question-option, .question-tab, .graph-control, .primary-button, .secondary-button) {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

body.figure-review {
  height: 100vh;
  overflow: hidden;
  background: #f8fafc;
}

body.figure-review .topbar,
body.figure-review .lab-portal-progress,
body.figure-review .lab-level-navigation,
body.figure-review .lab-controls,
body.figure-review .lab-guide-panel,
body.figure-review .lab-bottom-panel,
body.figure-review .lab-question,
body.figure-review .lab-graph,
body.figure-review .visual-titlebar,
body.figure-review .panel-heading,
body.figure-review .story-strip {
  display: none !important;
}

body.figure-review .app,
body.figure-review .app-shell,
body.figure-review #labView.active,
body.figure-review .lab-shell,
body.figure-review .lab-layout,
body.figure-review .lab-output,
body.figure-review .lab-visual,
body.figure-review .lab-canvas {
  display: block !important;
  width: 100% !important;
  height: 100vh !important;
  min-height: 100vh !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
}

body.figure-review #labSvg {
  display: block;
  width: 100vw !important;
  height: 100vh !important;
  max-height: none !important;
  padding: 0 !important;
}
