:root {
  color-scheme: light;
  --bg: #f3f4ef;
  --panel: #ffffff;
  --ink: #202421;
  --muted: #66706a;
  --line: #d7ddd5;
  --soft: #eef2ed;
  --green: #3d8b63;
  --green-dark: #1f6f4b;
  --amber: #c98c1d;
  --rust: #a55235;
  --blue: #316c91;
  --shadow: 0 18px 40px rgba(31, 42, 35, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

button:hover {
  border-color: #aab7ad;
  background: #f8faf7;
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green-dark);
}

button.primary:hover {
  background: var(--green-dark);
}

.app {
  min-height: 100vh;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 18px;
  max-width: 1540px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 27px;
  line-height: 1.25;
}

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

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.status-strip span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.status-strip b {
  color: var(--ink);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(440px, 1fr) minmax(300px, 360px);
  gap: 16px;
  max-width: 1540px;
  margin: 0 auto;
}

.panel,
.stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.panel section + section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.controls {
  align-self: start;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-radius: 0;
  min-height: 42px;
  background: #fff;
}

.segmented button.active {
  background: #ddebe1;
  color: var(--green-dark);
  font-weight: 700;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.icon {
  width: 18px;
  text-align: center;
  font-weight: 700;
}

.range-row {
  display: grid;
  grid-template-columns: 82px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.range-row input {
  width: 100%;
  accent-color: var(--green);
}

.range-row output {
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stage {
  min-width: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.stage-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.stage-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend i {
  width: 13px;
  height: 13px;
  border: 1px solid rgba(0, 0, 0, 0.13);
  display: inline-block;
}

.legend-unreacted {
  background: #9fc9b7;
}

.legend-product {
  background: #2f8f5b;
}

.legend-source {
  background: #d79d2a;
}

.legend-boundary {
  background: #222;
}

.canvas-wrap {
  flex: 1;
  min-height: 480px;
  border: 1px solid var(--line);
  background: #f8f7f1;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#simCanvas {
  width: min(100%, 720px);
  aspect-ratio: 1;
  height: auto;
  display: block;
  image-rendering: pixelated;
}

.data-panel {
  align-self: start;
}

#chartCanvas {
  width: 100%;
  height: auto;
  display: block;
  margin-top: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metrics div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--soft);
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metrics b {
  display: block;
  margin-top: 5px;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.note-list {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 280px minmax(420px, 1fr);
  }

  .data-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .stage-head {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .canvas-wrap {
    min-height: auto;
  }
}
