:root {
  color-scheme: light;
  --paper: #edf0ee;
  --panel: #f8f9f5;
  --ink: #1d2422;
  --muted: #747d78;
  --line: #d8ddd8;
  --line-strong: #bac2bc;
  --stage: #101718;
  --stage-text: #f2f4ed;
  --stage-muted: #98a5a2;
  --aqua: #73dbc5;
  --gold: #efc65f;
  --coral: #ef796a;
  --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; display: grid; grid-template-columns: repeat(3, 5px); grid-auto-rows: 5px; align-content: center; justify-content: center; width: 42px; height: 42px; flex: 0 0 42px; gap: 3px; background: var(--ink); border-radius: 50%; }
.brand-mark i { width: 5px; height: 5px; background: var(--aqua); border-radius: 1px; }
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(6) { background: var(--gold); }
.brand-mark i:nth-child(4) { grid-column: 1; }
.brand-mark i:nth-child(7) { background: 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; }

.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; }
.density-control { margin-top: 18px; }
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%; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; 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: 2px; }
.legend .newborn { background: var(--aqua); }
.legend .stable { background: var(--gold); }
.legend .elder { background: var(--coral); }

.boundary-label { margin-top: 19px; }
.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); }
.tool-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.tool-actions button { display: flex; align-items: center; justify-content: center; height: 34px; gap: 7px; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: var(--radius); font-size: 10px; font-weight: 600; }
.tool-actions button:hover { color: var(--ink); border-color: var(--line-strong); }
.tool-actions span { font-size: 15px; font-weight: 400; }

.rule-strip { display: flex; justify-content: space-between; gap: 12px; padding: 16px 28px; color: var(--muted); border-bottom: 1px solid var(--line); font-size: 9px; }
.rule-strip span { display: grid; gap: 3px; }
.rule-strip b { color: var(--ink); font: 600 11px ui-monospace, SFMono-Regular, Consolas, monospace; }
.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: 32px 32px; content: ""; pointer-events: none; }
#simulation { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; touch-action: none; cursor: cell; image-rendering: pixelated; }

.stage-header { position: absolute; top: 0; right: 0; left: 0; z-index: 2; display: grid; grid-template-columns: minmax(140px, 1fr) auto minmax(220px, 1fr); align-items: center; min-height: 92px; padding: 0 34px; color: var(--stage-text); background: linear-gradient(to bottom, rgba(16, 23, 24, 0.76), 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: 2px; box-shadow: 0 0 0 5px rgba(115, 219, 197, 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: 79px; gap: 5px; padding: 0 17px; 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: 72px; height: 38px; padding: 0 12px; gap: 7px; 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,
.rule-note { position: absolute; bottom: 26px; z-index: 2; display: flex; align-items: center; color: var(--stage-muted); font: 9px ui-monospace, SFMono-Regular, Consolas, monospace; pointer-events: none; }
.canvas-note { left: 34px; gap: 10px; }
.canvas-note i { width: 42px; height: 1px; background: rgba(255, 255, 255, 0.2); }
.rule-note { right: 34px; gap: 8px; opacity: 0.7; }
.rule-note i { width: 4px; height: 4px; background: var(--stage-muted); border-radius: 50%; }

@media (max-width: 1180px) {
  .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; }
  .rule-note { 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: 94px; 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; }
}
