:root {
  color-scheme: light;
  --paper: #edf0ee;
  --panel: #f8f9f5;
  --ink: #1d2422;
  --muted: #747d78;
  --line: #d8ddd8;
  --line-strong: #b9c1bb;
  --stage: #101718;
  --stage-text: #f2f4ed;
  --stage-muted: #98a5a2;
  --aqua: #77ddca;
  --gold: #f3c65c;
  --coral: #f17b6b;
  --radius: 6px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
}

button,
input,
select { font: inherit; }

button,
select,
input[type="range"] { cursor: pointer; }

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--coral);
  outline-offset: 2px;
}

.lab-shell {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  min-height: 100svh;
}

.control-panel {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  height: 100svh;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 104px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  position: relative;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  overflow: hidden;
  background: var(--ink);
  border-radius: 50%;
}

.brand-mark i {
  position: absolute;
  border: 1px solid var(--aqua);
  border-radius: 50%;
}

.brand-mark i:nth-child(1) { inset: 9px; }
.brand-mark i:nth-child(2) { inset: 14px 6px 6px 14px; border-color: var(--gold); }
.brand-mark i:nth-child(3) { inset: 20px 11px 5px 18px; border-color: var(--coral); }

.brand span,
.brand h1 { display: block; margin: 0; letter-spacing: 0; }
.brand span { margin-bottom: 5px; color: var(--muted); font-size: 9px; font-weight: 700; }
.brand h1 { font-size: 18px; font-weight: 650; }

.control-section {
  padding: 22px 28px 24px;
  border-bottom: 1px solid var(--line);
}

.compact-section { padding-top: 18px; padding-bottom: 20px; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 26px;
  margin-bottom: 16px;
}

.section-heading h2 { margin: 0; font-size: 13px; font-weight: 700; }
.section-index { color: var(--line-strong); font: 10px ui-monospace, SFMono-Regular, Consolas, monospace; }
.select-label,
.field-label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 11px; font-weight: 650; }
.select-wrap { position: relative; }

.select-wrap::after {
  position: absolute;
  top: 50%;
  right: 13px;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
  content: "";
  pointer-events: none;
  transform: translateY(-70%) rotate(45deg);
}

select {
  width: 100%;
  height: 40px;
  padding: 0 38px 0 12px;
  appearance: none;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 12px;
}

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; color: var(--muted); font-size: 9px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; }
.legend-a { background: #162426; }
.legend-front { background: var(--aqua); }
.legend-b { background: var(--coral); }

.range-control { display: block; }
.range-control + .range-control { margin-top: 18px; }
.range-control > span { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.range-control b { font-size: 11px; font-weight: 600; }
.range-control output { color: var(--muted); font: 11px ui-monospace, SFMono-Regular, Consolas, monospace; font-variant-numeric: tabular-nums; }

input[type="range"] { width: 100%; height: 14px; margin: 0; appearance: none; background: transparent; }
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: linear-gradient(to right, var(--ink) var(--progress, 50%), var(--line) var(--progress, 50%)); }
input[type="range"]::-webkit-slider-thumb { width: 13px; height: 13px; margin-top: -5.5px; appearance: none; background: var(--panel); border: 2px solid var(--ink); border-radius: 50%; }
input[type="range"]::-moz-range-track { height: 2px; background: var(--line); }
input[type="range"]::-moz-range-progress { height: 2px; background: var(--ink); }
input[type="range"]::-moz-range-thumb { width: 10px; height: 10px; background: var(--panel); border: 2px solid var(--ink); border-radius: 50%; }

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.segmented button { min-width: 0; height: 32px; padding: 0 6px; color: var(--muted); background: transparent; border: 0; border-radius: 3px; font-size: 10px; font-weight: 600; }
.segmented button[aria-pressed="true"] { color: var(--stage-text); background: var(--ink); }
.brush-range { margin-top: 18px; }

.panel-footer { display: flex; justify-content: space-between; margin-top: auto; padding: 18px 28px; color: var(--line-strong); font: 9px ui-monospace, SFMono-Regular, Consolas, monospace; }

.simulation-stage {
  position: relative;
  min-width: 0;
  min-height: 540px;
  overflow: hidden;
  background: var(--stage);
}

.simulation-stage::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: radial-gradient(circle at center, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 28px 28px;
  content: "";
  pointer-events: none;
}

#simulation { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

.stage-header {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto minmax(160px, 1fr);
  align-items: center;
  min-height: 92px;
  padding: 0 34px;
  color: var(--stage-text);
  background: linear-gradient(to bottom, rgba(16, 23, 24, 0.7), rgba(16, 23, 24, 0.12));
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  pointer-events: none;
}

.scene-title { display: flex; align-items: center; gap: 12px; justify-self: start; }
.live-dot { width: 8px; height: 8px; background: var(--aqua); border-radius: 50%; box-shadow: 0 0 0 5px rgba(119, 221, 202, 0.1); }
.scene-title div { display: grid; gap: 4px; }
.scene-title span,
.metrics span,
.metrics small { color: var(--stage-muted); font-size: 9px; font-weight: 600; }
.scene-title strong { font-size: 13px; font-weight: 600; }

.metrics { display: flex; align-items: stretch; justify-content: center; }
.metrics > div { display: grid; min-width: 96px; gap: 5px; padding: 0 22px; border-left: 1px solid rgba(255, 255, 255, 0.11); }
.metrics > div:last-child { border-right: 1px solid rgba(255, 255, 255, 0.11); }
.metrics strong { font: 500 15px ui-monospace, SFMono-Regular, Consolas, monospace; font-variant-numeric: tabular-nums; }
.metrics strong b { font: inherit; }
.metrics small { font-size: 8px; }

.stage-actions { display: flex; justify-self: end; gap: 8px; pointer-events: auto; }
.stage-actions button { display: inline-flex; align-items: center; justify-content: center; min-width: 82px; height: 38px; padding: 0 14px; gap: 8px; color: var(--stage-text); background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.16); border-radius: var(--radius); font-size: 11px; }
.stage-actions button b { font-weight: 600; }
.stage-actions button:hover { background: rgba(255, 255, 255, 0.1); }
.stage-actions .primary-action { color: var(--stage); background: var(--aqua); border-color: var(--aqua); }
.stage-actions .primary-action:hover { background: #a9eadc; }

.canvas-note,
.equation { position: absolute; bottom: 26px; z-index: 2; display: flex; color: var(--stage-muted); font: 9px ui-monospace, SFMono-Regular, Consolas, monospace; pointer-events: none; }
.canvas-note { left: 34px; align-items: center; gap: 10px; }
.canvas-note i { width: 42px; height: 1px; background: rgba(255, 255, 255, 0.2); }
.equation { right: 34px; align-items: flex-end; flex-direction: column; gap: 4px; opacity: 0.75; }

@media (max-width: 1120px) {
  .lab-shell { grid-template-columns: 292px minmax(0, 1fr); }
  .brand,
  .control-section { padding-right: 22px; padding-left: 22px; }
  .stage-header { grid-template-columns: 1fr auto; padding: 0 24px; }
  .metrics { display: none; }
  .stage-actions { grid-column: 2; }
  .equation { display: none; }
}

@media (max-width: 760px) {
  .lab-shell { display: flex; flex-direction: column; }
  .simulation-stage { order: 1; min-height: 58svh; }
  .control-panel { order: 2; width: 100%; height: auto; overflow: visible; border-top: 1px solid var(--line); border-right: 0; }
  .brand { min-height: 84px; }
  .stage-header { min-height: 74px; padding: 0 16px; }
  .stage-actions button { min-width: 42px; width: 42px; padding: 0; }
  .stage-actions button b { display: none; }
  .canvas-note { left: 16px; }
  .panel-footer { margin-top: 0; }
}

@media (max-width: 430px) {
  .scene-title strong { display: block; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .brand,
  .control-section { padding-right: 20px; padding-left: 20px; }
  .canvas-note i { width: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { transition-duration: 0.01ms !important; }
}
