:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --soft: #f1f5f9;
  --indigo: #4f46e5;
  --indigo-soft: #eef2ff;
  --emerald: #047857;
  --emerald-soft: #ecfdf5;
  --rose: #be123c;
  --rose-soft: #fff1f2;
  --amber: #b45309;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(79, 70, 229, 0.06), rgba(248, 250, 252, 0) 260px),
    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;
}

svg {
  display: block;
}

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

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid #c7d2fe;
  border-radius: 12px;
  background: var(--indigo-soft);
  color: var(--indigo);
  flex: 0 0 auto;
}

.brand-mark svg,
.top-actions svg,
.section-title svg,
.toolbar 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.1;
  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;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #334155;
  background: #fff;
  border: 1px solid var(--line);
  text-decoration: none;
}

.icon-button:hover {
  color: var(--indigo);
  border-color: #c7d2fe;
  background: #f8fafc;
}

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

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

.panel,
.chart-panel {
  background: var(--panel);
  border: 1px solid rgba(226, 232, 240, 0.92);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
}

.intro-panel {
  background:
    linear-gradient(135deg, rgba(79, 70, 229, 0.08), rgba(255, 255, 255, 0) 58%),
    #fff;
}

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

.panel h2,
.chart-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.18;
  letter-spacing: 0;
}

.panel p,
.chart-header p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

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

.mini-stats div {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
}

.mini-stats span {
  display: block;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 20px;
  font-weight: 800;
}

.mini-stats label,
.result-card label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

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

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

.section-title h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.scm-figure {
  margin: 0;
  padding: 10px;
  border-radius: 14px;
  background: var(--soft);
  border: 1px solid var(--line);
}

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

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

.scm-diagram marker path {
  fill: #334155;
}

.scm-node ellipse {
  fill: #fff;
  stroke: #cbd5e1;
  stroke-width: 1.8;
}

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

.math-equations {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

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

.math-row {
  padding: 10px 12px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  overflow-x: auto;
}

.formula {
  display: block;
  color: #334155;
  font-family: "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.6;
  white-space: normal;
  min-width: max-content;
}

.formula var {
  font-style: italic;
}

.formula sub {
  font-size: 0.68em;
  line-height: 0;
}

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

.result-card {
  padding: 15px;
  border-radius: 13px;
  border: 1px solid var(--line);
}

.result-card.good {
  background: var(--emerald-soft);
  border-color: #bbf7d0;
  color: var(--emerald);
}

.result-card.bad {
  background: var(--rose-soft);
  border-color: #fecdd3;
  color: var(--rose);
}

.result-card strong {
  display: block;
  margin-top: 8px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 22px;
}

.result-card span {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  font-weight: 800;
}

.chart-panel {
  padding: 22px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.segmented {
  display: flex;
  padding: 4px;
  border-radius: 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.segmented button,
.toggle {
  appearance: none;
  border: 0;
  font: inherit;
  cursor: pointer;
}

.segmented button {
  padding: 9px 14px;
  border-radius: 9px;
  background: transparent;
  color: #475569;
  font-size: 13px;
  font-weight: 800;
}

.segmented button.active {
  background: #fff;
  color: var(--indigo);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  margin-bottom: 18px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
}

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

.toggle.active {
  color: var(--indigo);
  border-color: #c7d2fe;
  background: var(--indigo-soft);
}

.chart-note {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.note-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 10px;
  color: var(--indigo);
  background: var(--indigo-soft);
}

.note-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-note strong {
  display: block;
  font-size: 13px;
}

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

.plot-wrap {
  position: relative;
  min-height: 500px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
}

.plot {
  width: 100%;
  height: min(64vh, 560px);
  min-height: 500px;
}

.axis {
  stroke: #0f172a;
  stroke-width: 2;
  marker-end: url("#plot-axis-arrow");
}

.tick {
  stroke: #cbd5e1;
  stroke-width: 1;
}

.tick-label,
.axis-label,
.w-label {
  fill: #475569;
  font-size: 13px;
  font-weight: 700;
}

.w-label {
  font-size: 14px;
  font-weight: 850;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 5px;
  stroke-linejoin: round;
}

.axis-label {
  fill: #0f172a;
  font-size: 15px;
}

.point {
  stroke-width: 0.9;
}

.point.subgroup {
  stroke-width: 1;
}

.ellipse {
  fill: none;
  stroke-width: 2.5;
}

.ellipse-area {
  stroke: none;
  fill-opacity: 0.09;
}

.envelope {
  fill: none;
  stroke: #64748b;
  stroke-width: 2;
  stroke-dasharray: 8 8;
}

.global-ellipse {
  fill: rgba(100, 116, 139, 0.06);
  stroke: #64748b;
  stroke-width: 2.4;
  stroke-dasharray: 8 8;
}

.fit-line {
  stroke-width: 3.3;
  stroke-linecap: round;
}

.pooled-line {
  stroke: #334155;
  stroke-width: 4.6;
  stroke-linecap: round;
}

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

.regression-label {
  font-size: 11px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  min-width: 150px;
  padding: 10px 11px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  box-shadow: 0 15px 35px rgba(15, 23, 42, 0.22);
}

.bottom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.classic-examples {
  padding: 22px;
  border: 1px solid rgba(226, 232, 240, 0.92);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}

.section-head.compact {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.section-head.compact h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.section-head.compact p {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.classic-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.classic-disclosure {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdff;
}

.classic-disclosure summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 58px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}

.classic-disclosure summary::-webkit-details-marker {
  display: none;
}

.classic-disclosure summary strong {
  display: block;
  font-size: 14px;
}

.classic-disclosure summary small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.classic-disclosure summary svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: var(--indigo);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.18s ease;
}

.classic-disclosure[open] summary {
  border-bottom: 1px solid var(--line);
}

.classic-disclosure[open] summary svg {
  transform: rotate(180deg);
}

.classic-disclosure .classic-grid {
  padding: 14px;
}

.classic-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.classic-head {
  min-height: 106px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.classic-domain {
  display: block;
  margin-bottom: 7px;
  color: var(--indigo);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.classic-head h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: 0;
}

.classic-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.reversal-badge {
  flex: 0 0 auto;
  padding: 5px 7px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: #475569;
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  white-space: nowrap;
}

.reversal-badge.strict_reversal {
  color: var(--rose);
  border-color: #fecdd3;
  background: var(--rose-soft);
}

.reversal-badge.composition_warning {
  color: var(--amber);
  border-color: #fde68a;
  background: #fffbeb;
}

.pooled-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 12px;
}

.pooled-metric {
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.pooled-metric label {
  display: block;
  min-height: 30px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  line-height: 1.35;
  text-transform: uppercase;
}

.pooled-metric strong {
  display: block;
  margin-top: 6px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 18px;
}

.pooled-metric span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.classic-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 11px;
}

.classic-table th,
.classic-table td {
  padding: 7px 5px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.classic-table th {
  color: #475569;
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
}

.classic-table td {
  color: #334155;
}

.classic-table .pooled-summary-row td {
  background: #f8fafc;
  font-weight: 850;
}

.classic-lesson {
  margin: 12px 0 0;
  color: #475569;
  font-size: 12px;
  line-height: 1.58;
}

.source-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 13px;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 5px 7px;
  border: 1px solid #c7d2fe;
  border-radius: 7px;
  background: var(--indigo-soft);
  color: var(--indigo);
  text-decoration: none;
  font-size: 10px;
  font-weight: 850;
}

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

.diagnosis-panel,
.model-panel,
.principle-panel {
  background: #fff;
  border: 1px solid rgba(226, 232, 240, 0.92);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 22px;
}

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

.diagnosis-panel {
  background:
    linear-gradient(135deg, rgba(245, 158, 11, 0.13), rgba(255, 255, 255, 0) 58%),
    #fff;
  border-color: #fde68a;
}

.diagnosis-panel .section-title svg {
  color: var(--amber);
}

.diagnosis-panel p,
.principle-panel p,
.model-panel p {
  margin: 0;
  color: #475569;
  font-size: 13px;
  line-height: 1.65;
}

.model-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

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

.model-head strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
}

.model-head code,
.principle-panel code {
  width: fit-content;
  padding: 4px 7px;
  border-radius: 7px;
  background: #f8fafc;
  color: #334155;
  border: 1px solid var(--line);
  font-size: 11px;
  white-space: nowrap;
}

.model-head .formula,
.principle-panel mjx-container {
  width: fit-content;
  max-width: 100%;
  padding: 4px 7px;
  border-radius: 7px;
  background: #f8fafc;
  color: #334155;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  overflow-x: auto;
}

.model-values {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.model-values div {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.model-values label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.model-values strong {
  display: block;
  margin-top: 7px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 17px;
}

.naive-model {
  border-color: #fecdd3;
}

.naive-model .model-values strong {
  color: var(--rose);
}

.adjusted-model {
  border-color: #bbf7d0;
}

.adjusted-model .model-values strong {
  color: var(--emerald);
}

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

.source-list {
  padding: 0;
  margin: 0;
  list-style: none;
  display: grid;
  gap: 12px;
  color: #475569;
  font-size: 13px;
  line-height: 1.5;
}

.source-list li {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.source-list li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.source-list code {
  color: var(--indigo);
  background: var(--indigo-soft);
  border-radius: 6px;
  padding: 2px 5px;
  overflow-wrap: anywhere;
}

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

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

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

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

  .main-stage {
    order: -1;
  }

  .left-rail,
  .bottom-grid,
  .explanation-grid,
  .classic-grid {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .plot-wrap,
  .plot {
    min-height: 430px;
  }

  .plot {
    height: 430px;
  }
}

@media (max-width: 520px) {
  .brand h1 {
    font-size: 18px;
  }

  .brand p {
    display: none;
  }

  .panel,
  .chart-panel,
  .classic-examples {
    padding: 16px;
    border-radius: 14px;
  }

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

  .classic-head {
    min-height: 0;
    flex-direction: column;
  }
}
