:root {
  color-scheme: light;
  --ink: #1b2a35;
  --muted: #6d7d88;
  --soft: #eff3f5;
  --line: #d8e1e5;
  --panel: #ffffff;
  --canvas: #edf2f4;
  --navy: #173549;
  --teal: #1c8790;
  --teal-strong: #0b6974;
  --orange: #d9763b;
  --yellow: #e4b94f;
  --red: #c45049;
  --green: #2d9274;
  --shadow: 0 12px 30px rgba(19, 43, 56, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft Yahei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; min-height: 100%; background: #e7edef; color: var(--ink); }
body { min-height: 100vh; }
button, input { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  min-height: 76px; padding: 14px 22px; display: flex; align-items: center; justify-content: space-between; gap: 24px;
  background: rgba(255, 255, 255, .96); border-bottom: 1px solid var(--line); box-shadow: 0 2px 12px rgba(13, 39, 51, .05);
}
.brand-lockup { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; background: var(--navy); color: #fff;
  font: 700 16px Georgia, serif; letter-spacing: -.5px; box-shadow: inset 0 -5px 0 rgba(28, 135, 144, .75);
}
.eyebrow { margin: 0 0 4px; color: var(--teal-strong); font-size: 10px; font-weight: 800; letter-spacing: .12em; }
h1, h2, p { margin: 0; }
h1 { font-size: 20px; line-height: 1.1; font-weight: 760; letter-spacing: 0; }
h2 { font-size: 14px; line-height: 1.2; font-weight: 750; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.status-badge, .state-chip, .count-pill, .tiny-label {
  border-radius: 999px; white-space: nowrap; font-size: 11px; font-weight: 700;
}
.status-badge { padding: 7px 10px; background: #eaf4f2; color: var(--green); }
.status-neutral { background: #edf2f4; color: var(--muted); }
.icon-text-button, .icon-button, .text-button, .primary-button {
  border: 1px solid var(--line); background: #fff; color: var(--ink); transition: .18s ease;
}
.icon-text-button { padding: 8px 11px; border-radius: 8px; font-size: 12px; font-weight: 700; }
.icon-text-button:hover, .icon-button:hover, .text-button:hover { border-color: var(--teal); color: var(--teal-strong); }
.icon-button { width: 32px; height: 32px; border-radius: 8px; font-size: 14px; font-weight: 800; }
.icon-button.is-active { background: #e7f3f3; color: var(--teal-strong); border-color: #a6d3d5; }

.workspace {
  width: 100%; max-width: 1900px; margin: 0 auto; padding: 16px; display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(420px, 1fr) minmax(300px, 360px); gap: 16px; flex: 1;
}
.left-rail, .right-rail, .center-column { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--panel); border: 1px solid rgba(188, 204, 210, .85); border-radius: 10px; box-shadow: var(--shadow); }
.system-panel, .control-panel, .chart-panel, .explanation-panel, .comparison-panel { padding: 16px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.tiny-label { color: var(--muted); padding-top: 4px; font-size: 10px; }
.count-pill { padding: 5px 8px; color: var(--teal-strong); background: #e7f3f3; }

.segmented-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-bottom: 12px; }
.system-option {
  min-height: 42px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafb; color: var(--muted); padding: 6px 8px;
  text-align: left; font-size: 12px; font-weight: 760;
}
.system-option small { display: block; margin-top: 3px; color: inherit; font-size: 10px; font-weight: 550; opacity: .8; }
.system-option.is-selected { color: #fff; background: var(--navy); border-color: var(--navy); }
.equation-card { padding: 13px; border: 1px solid #d8e6e8; border-radius: 8px; background: #f4f8f8; }
.equation-main { color: var(--navy); font: 700 16px Georgia, "Times New Roman", serif; text-align: center; line-height: 1.4; }
.equation-note { margin-top: 10px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.constant-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 11px; }
.constant-cell { padding: 7px 8px; border-top: 1px solid #d8e6e8; }
.constant-cell span { display: block; color: var(--muted); font-size: 10px; }
.constant-cell strong { display: block; margin-top: 2px; font-size: 12px; color: var(--ink); }

.control-stack { display: grid; gap: 9px; }
.control-card { display: block; padding: 11px 12px; background: #f8fafb; border: 1px solid var(--line); border-radius: 8px; }
.control-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; font-weight: 700; }
.control-card output { color: var(--teal-strong); font-size: 12px; font-variant-numeric: tabular-nums; }
.control-icon { display: inline-grid; place-items: center; width: 24px; height: 24px; margin-right: 5px; border-radius: 6px; color: white; font-size: 10px; font-weight: 800; }
.control-icon.temp { background: var(--orange); }
.control-icon.water { background: var(--teal); }
input[type="range"] { width: 100%; margin: 12px 0 0; accent-color: var(--teal); }
.range-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 9px; }
.perturbation-stack { display: grid; gap: 8px; }
.perturb-card { padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.perturb-card .control-card-head { margin-bottom: 9px; }
.perturb-description { color: var(--muted); font-size: 10px; line-height: 1.45; margin-bottom: 9px; }
.perturb-row { display: grid; grid-template-columns: 1fr 58px 48px; gap: 7px; align-items: center; }
.perturb-row input[type="number"] { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px 6px; font-size: 11px; color: var(--ink); }
.small-button { border: 0; border-radius: 6px; padding: 7px 5px; background: #e7f3f3; color: var(--teal-strong); font-size: 11px; font-weight: 800; }
.small-button:hover { background: #cde8e8; }

.scene-panel { flex: 1; min-height: 500px; padding: 16px 16px 12px; display: flex; flex-direction: column; overflow: hidden; }
.scene-toolbar { display: flex; justify-content: space-between; gap: 12px; }
.scene-actions { display: flex; gap: 6px; }
.scene-state-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; }
.scene-caption { color: var(--muted); font-size: 11px; }
.state-chip { padding: 6px 9px; color: var(--green); background: #eaf6f1; }
.state-chip.state-shift { color: var(--orange); background: #fff1e8; }
.state-chip.state-precip { color: var(--red); background: #fff0ef; }
.particle-stage { position: relative; flex: 1; min-height: 410px; overflow: hidden; border-radius: 8px; background: linear-gradient(150deg, #eef5f6, #dce8eb); border: 1px solid #d0dfe3; }
.particle-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; pointer-events: none; }
.stage-overlay { position: absolute; z-index: 2; padding: 5px 8px; border-radius: 5px; background: rgba(255,255,255,.66); color: #69808a; font-size: 10px; pointer-events: none; }
.stage-overlay.top-left { top: 10px; left: 10px; }
.stage-overlay.bottom-right { bottom: 10px; right: 10px; }
.particle-legend { min-height: 29px; display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 12px; padding-top: 10px; color: var(--muted); font-size: 10px; }
.legend-dot { display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 50%; vertical-align: -1px; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.metric-card { min-width: 0; padding: 12px 13px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 5px 16px rgba(21, 52, 65, .05); }
.metric-card.accent { background: #f4f8f8; border-color: #b7dada; }
.metric-label { display: block; color: var(--muted); font-size: 10px; font-weight: 700; }
.metric-card strong { display: block; margin: 5px 0 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--navy); font-size: 17px; font-variant-numeric: tabular-nums; }
.metric-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 10px; }

.chart-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 7px; }
.chart-tab { border: 1px solid var(--line); border-radius: 6px; padding: 7px 4px; background: #f8fafb; color: var(--muted); font-size: 10px; font-weight: 700; }
.chart-tab.is-selected { background: #e7f3f3; border-color: #a6d3d5; color: var(--teal-strong); }
.chart-wrap { height: 220px; border: 1px solid #e0e8eb; border-radius: 7px; background: #fcfdfd; overflow: hidden; }
#chart-svg { width: 100%; height: 100%; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 5px 10px; min-height: 28px; padding-top: 9px; color: var(--muted); font-size: 10px; }
.chart-legend-item { white-space: nowrap; }
.chart-legend-line { display: inline-block; width: 17px; height: 2px; margin-right: 4px; vertical-align: 3px; background: currentColor; }
.chart-legend-line.dashed { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px); }

.explanation-content { display: grid; gap: 10px; }
.explanation-hero { padding: 11px 12px; border-left: 3px solid var(--teal); background: #f2f8f8; border-radius: 0 7px 7px 0; color: var(--navy); font-size: 13px; line-height: 1.5; font-weight: 750; }
.explanation-row { display: grid; grid-template-columns: 70px 1fr; gap: 8px; padding-top: 8px; border-top: 1px solid #e8edef; font-size: 11px; line-height: 1.5; }
.explanation-row strong { color: var(--muted); font-size: 10px; }
.explanation-row span { color: var(--ink); }
.warning-note { padding: 8px 10px; border-radius: 6px; background: #fff8e8; color: #8a6a2b; font-size: 10px; line-height: 1.5; }

.text-button { border: 0; padding: 3px 0; color: var(--teal-strong); font-size: 11px; font-weight: 800; }
.comparison-actions { display: flex; gap: 8px; }
.primary-button { width: 100%; padding: 8px 10px; border-radius: 7px; border-color: var(--navy); background: var(--navy); color: #fff; font-size: 11px; font-weight: 800; }
.primary-button:hover { background: #224d66; }
.comparison-content { margin-top: 10px; min-height: 70px; }
.empty-state { color: var(--muted); font-size: 10px; line-height: 1.5; }
.comparison-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.comparison-table th, .comparison-table td { padding: 6px 4px; border-bottom: 1px solid #e8edef; text-align: right; font-variant-numeric: tabular-nums; }
.comparison-table th:first-child, .comparison-table td:first-child { text-align: left; }
.comparison-table th { color: var(--muted); font-weight: 700; }

.footer-note { display: flex; justify-content: space-between; gap: 18px; padding: 9px 20px 12px; color: var(--muted); font-size: 10px; }

body.classroom-mode .topbar, body.classroom-mode .footer-note { display: none; }
body.classroom-mode .workspace { max-width: 2100px; padding: 10px; grid-template-columns: minmax(280px, 340px) minmax(520px, 1fr) minmax(340px, 410px); }
body.classroom-mode h1 { font-size: 24px; }
body.classroom-mode .scene-panel { min-height: calc(100vh - 40px); }
body.classroom-mode .particle-stage { min-height: 570px; }
body.classroom-mode .chart-wrap { height: 270px; }

@media (max-width: 1200px) {
  .workspace { grid-template-columns: 260px minmax(360px, 1fr); }
  .right-rail { grid-column: 1 / -1; display: grid; grid-template-columns: 1.1fr .9fr .9fr; align-items: start; }
}
@media (max-width: 820px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 12px; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
  .workspace { display: flex; flex-direction: column; padding: 10px; }
  .left-rail, .right-rail { display: contents; }
  .system-panel { order: 1; }
  .scene-panel { order: 2; min-height: 520px; }
  .metrics-grid { order: 3; grid-template-columns: repeat(2, 1fr); }
  .control-panel { order: 4; }
  .right-rail { order: 5; display: flex; }
  .particle-stage { min-height: 390px; }
  .footer-note { flex-direction: column; gap: 3px; }
}
@media (max-width: 520px) {
  h1 { font-size: 17px; }
  .topbar-actions .status-badge { display: none; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .scene-state-row { align-items: flex-start; flex-direction: column; }
  .scene-panel { min-height: 480px; }
  .particle-stage { min-height: 330px; }
  .chart-wrap { height: 205px; }
}
