:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --line: #e2e8f0;
  --soft: #f1f5f9;
  --axis: #334155;
  --accent: #0f766e;
  --accent-soft: #ecfdf5;
  --danger: #be123c;
  --danger-soft: #fff1f2;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --shadow: 0 18px 42px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

svg {
  display: block;
}

code,
var {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #f1f5f9;
  color: #0f172a;
  font-size: 0.92em;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(16px, 4vw, 48px);
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid rgba(226, 232, 240, 0.94);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark,
.icon-button {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: #ffffff;
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 12px;
  color: var(--accent);
  background: var(--accent-soft);
}

.brand svg,
.top-actions svg,
.section-title svg,
.toolbar svg,
.note-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.12;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.icon-button {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 10px;
  color: #334155;
  text-decoration: none;
}

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--accent);
  background: #f8fafc;
  outline: none;
}

.shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 42px) 52px;
  display: grid;
  grid-template-columns: minmax(290px, 370px) minmax(0, 1fr);
  gap: 26px;
  align-items: start;
}

.left-rail,
.main-stage {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel,
.chart-panel,
.diagnosis-panel,
.model-panel,
.principle-panel {
  background: var(--panel);
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.panel,
.diagnosis-panel,
.model-panel,
.principle-panel {
  padding: 22px;
}

.intro-panel {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(255, 255, 255, 0) 58%), #ffffff;
}

.panel-label {
  width: fit-content;
  margin-bottom: 10px;
  padding: 4px 8px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h2,
h3,
p {
  margin-top: 0;
}

h2,
h3 {
  margin-bottom: 0;
  letter-spacing: 0;
}

h2 {
  font-size: 22px;
  line-height: 1.18;
}

h3 {
  font-size: 15px;
  line-height: 1.3;
}

p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

p:last-child {
  margin-bottom: 0;
}

.mini-stats,
.result-grid,
.model-values {
  display: grid;
  gap: 10px;
}

.mini-stats,
.result-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.model-values {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 18px 0 14px;
}

.mini-stats div,
.result-card,
.model-values div {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
}

.mini-stats span,
.result-card strong,
.model-values strong {
  display: block;
  color: #0f172a;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
}

.model-values strong {
  font-size: 18px;
}

.mini-stats label,
.result-card label,
.model-values label {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.result-card span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.result-card.bad,
.selected-model .model-values div:first-child {
  background: var(--danger-soft);
  border-color: #fecdd3;
}

.result-card.bad strong,
.selected-model .model-values div:first-child strong {
  color: var(--danger);
}

.result-card.neutral strong,
.population-model .model-values div:first-child strong {
  color: #334155;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 14px;
}

.section-title svg {
  flex: 0 0 auto;
  color: var(--accent);
}

.scm-figure {
  margin: 0 0 12px;
}

.scm-diagram {
  width: 100%;
  height: auto;
}

.scm-edge {
  marker-end: url("#scm-arrow");
  stroke: #475569;
  stroke-width: 2.1;
  fill: none;
}

.scm-node ellipse {
  fill: #ffffff;
  stroke: #0f766e;
  stroke-width: 2;
}

.scm-node text {
  fill: #0f172a;
  font-size: 18px;
  font-weight: 800;
}

.collider-node ellipse {
  fill: var(--accent-soft);
}

.scm-caption {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.math-equations {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
}

.math-row,
.formula {
  min-width: 0;
}

.formula {
  color: #0f172a;
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-size: 12px;
  line-height: 1.5;
}

.formula mjx-container {
  margin: 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
}

.chart-panel {
  overflow: hidden;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 22px;
  padding: 24px 24px 0;
}

.chart-header p {
  max-width: 680px;
  margin: 8px 0 0;
}

.segmented,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.segmented {
  justify-content: flex-end;
}

.segmented button,
.toggle {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: #334155;
  font-weight: 800;
  cursor: pointer;
}

.segmented button {
  min-height: 38px;
  padding: 0 14px;
  font-size: 12px;
}

.segmented button.active {
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
}

.segmented button:focus-visible,
.toggle:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 2px;
}

.toolbar {
  padding: 18px 24px 0;
}

.toggle {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  gap: 7px;
  padding: 0 12px;
  font-size: 12px;
}

.toggle svg {
  width: 17px;
  height: 17px;
}

.toggle.active {
  color: var(--accent);
  border-color: rgba(15, 118, 110, 0.28);
  background: var(--accent-soft);
}

.chart-note {
  display: flex;
  gap: 12px;
  margin: 18px 24px 0;
  padding: 14px;
  border: 1px solid #fed7aa;
  border-radius: 12px;
  background: var(--amber-soft);
}

.note-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  color: var(--amber);
  background: #ffffff;
}

.chart-note strong {
  display: block;
  color: #78350f;
  font-size: 13px;
}

.chart-note p {
  margin: 4px 0 0;
  color: #854d0e;
}

.plot-wrap {
  position: relative;
  min-height: 440px;
  padding: 8px 14px 18px;
}

.plot {
  width: 100%;
  height: auto;
  aspect-ratio: 840 / 520;
}

.plot-bg {
  fill: #ffffff;
}

.grid-line {
  stroke: #e2e8f0;
  stroke-width: 1;
}

.axis {
  stroke: var(--axis);
  stroke-width: 1.6;
}

.axis-label,
.tick-label,
.legend text,
.fit-label,
.frontier-label {
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0;
}

.axis-label {
  fill: #0f172a;
  font-size: 14px;
  font-weight: 800;
}

.tick-label {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.point {
  vector-effect: non-scaling-stroke;
  transition: opacity 0.18s ease, r 0.18s ease;
}

.point.unselected {
  fill: #cbd5e1;
  opacity: 0.46;
}

.point.selected {
  fill: #0f766e;
  opacity: 0.78;
  stroke: #064e3b;
  stroke-width: 0.4;
}

.point.selected.focus {
  fill: #0f766e;
  opacity: 0.92;
}

.fit-line {
  vector-effect: non-scaling-stroke;
  fill: none;
  stroke-width: 3;
}

.fit-line.population {
  stroke: #334155;
}

.fit-line.selected {
  stroke: var(--danger);
}

.fit-label {
  font-size: 12px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 4px;
}

.fit-label.population {
  fill: #334155;
}

.fit-label.selected {
  fill: var(--danger);
}

.frontier {
  vector-effect: non-scaling-stroke;
  fill: none;
  stroke: var(--amber);
  stroke-width: 2.2;
  stroke-dasharray: 7 7;
}

.frontier-band {
  fill: rgba(251, 191, 36, 0.11);
}

.frontier-label {
  fill: #92400e;
  font-size: 12px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 4px;
}

.legend {
  font-size: 12px;
  font-weight: 800;
}

.legend-pill {
  fill: rgba(255, 255, 255, 0.92);
  stroke: var(--line);
}

.legend text {
  fill: #334155;
  dominant-baseline: central;
}

.tooltip {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  min-width: 158px;
  padding: 10px 12px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.16);
  color: #0f172a;
  font-size: 12px;
  line-height: 1.45;
}

.tooltip strong {
  display: block;
  margin-bottom: 4px;
}

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

.diagnosis-panel,
.principle-panel {
  grid-column: span 2;
}

.model-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.model-head span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.model-head strong {
  display: block;
  margin-top: 4px;
  font-size: 17px;
  line-height: 1.25;
}

.model-head code {
  max-width: 46%;
  white-space: normal;
  text-align: right;
}

.principle-panel {
  background: linear-gradient(135deg, rgba(190, 18, 60, 0.06), rgba(15, 118, 110, 0.06)), #ffffff;
}

.bottom-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(260px, 0.75fr);
  gap: 18px;
  align-items: start;
}

.asset-panel img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
}

.source-list {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.source-list li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.source-list strong {
  color: #0f172a;
}

@media (max-width: 1040px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .left-rail {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
  }

  .left-rail .panel {
    min-width: 0;
  }

  .bottom-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .topbar,
  .chart-header,
  .model-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    position: static;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .left-rail,
  .explanation-grid {
    display: flex;
    flex-direction: column;
  }

  .diagnosis-panel,
  .principle-panel {
    grid-column: auto;
  }

  .segmented {
    justify-content: flex-start;
  }

  .model-head code {
    max-width: none;
    text-align: left;
  }

  .plot-wrap {
    min-height: 340px;
    padding-left: 6px;
    padding-right: 6px;
  }
}

@media (max-width: 560px) {
  .shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand h1 {
    font-size: 17px;
  }

  .brand p {
    font-size: 11px;
  }

  .mini-stats,
  .result-grid,
  .model-values {
    grid-template-columns: 1fr;
  }

  .panel,
  .diagnosis-panel,
  .model-panel,
  .principle-panel {
    padding: 18px;
  }

  .chart-header {
    padding: 20px 18px 0;
  }

  .toolbar {
    padding: 16px 18px 0;
  }

  .chart-note {
    margin-left: 18px;
    margin-right: 18px;
  }

  .segmented button,
  .toggle {
    flex: 1 1 auto;
    justify-content: center;
  }
}
