:root {
  color-scheme:light;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;
  background:var(--paper);
  color:var(--ink);
  font-synthesis:none;
}

* {
  box-sizing:border-box;
}

body {
  margin:0;
  background:var(--paper);
}

a {
  color:inherit;
  text-decoration:none;
}

a:hover {
  text-decoration:underline;
}

button,select,input {
  font:inherit;
}

button {
  font-weight:600;
  font-size:13px;
  border:1px solid var(--line-strong);
  border-radius:7px;
  background:var(--surface);
  color:var(--ink);
  padding:9px 13px;
  cursor:pointer;
}

button:hover:not(:disabled) {
  background:var(--line);
}

button:disabled {
  cursor:not-allowed;
  opacity:.45;
}

button.primary {
  background:var(--ink);
  color:var(--on-ink);
  border-color:var(--ink);
}

button.primary:hover:not(:disabled) {
  background:var(--teal-solid);
}

button.quiet {
  background:transparent;
}

button:focus-visible,a:focus-visible,select:focus-visible,input:focus-visible,summary:focus-visible {
  outline:3px solid var(--blue-mid);
  outline-offset:3px;
}

select {
  border:1px solid var(--line-strong);
  border-radius:7px;
  background:var(--surface);
  padding:8px 10px;
  font-size:13px;
  color:var(--ink);
}

[hidden] {
  display:none!important;
}

.skip-link {
  position:absolute;
  top:-100px;
  left:20px;
  background:var(--surface);
  padding:12px;
  z-index:10;
}

.skip-link:focus {
  top:8px;
}







main {
  max-width:1560px;
  margin:auto;
  padding:30px 24px 28px;
}

.eyebrow {
  font-size:11px;
  letter-spacing:1.6px;
  font-weight:650;
  color:var(--muted);
  margin:0 0 8px;
}

h1 {
  font-size:clamp(24px,2.6vw,36px);
  font-weight:650;
  letter-spacing:-1.1px;
  margin:0 0 10px;
}

h2 {
  font-size:18px;
  margin:0;
  font-weight:650;
  letter-spacing:-.3px;
}

h3 {
  font-size:14px;
  margin:0 0 8px;
}

h4 {
  font-size:13px;
  margin:0 0 8px;
}

.mg-intro {
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  gap:28px;
  margin-bottom:20px;
}

.mg-intro p:not(.eyebrow) {
  font-size:14px;
  line-height:1.7;
  color:var(--muted);
  margin:0;
  max-width:820px;
}

.progress-card {
  min-width:210px;
  text-align:right;
}

.progress-card>span {
  font-size:12px;
  color:var(--muted);
}

.progress-card strong {
  display:block;
  font-size:21px;
  font-variant-numeric:tabular-nums;
  font-weight:600;
  margin:5px 0 9px;
}

.progress-card small {
  display:block;
  color:var(--muted);
  font-size:10px;
  margin-top:7px;
}

.progress-track {
  height:4px;
  background:var(--line);
  border-radius:4px;
  overflow:hidden;
}

.progress-track span {
  display:block;
  height:100%;
  width:0;
  background:var(--world);
}

.error-banner {
  padding:13px 16px;
  border:1px solid var(--red-line);
  color:var(--danger);
  background:var(--orange-soft);
  border-radius:8px;
  margin-bottom:14px;
  font-size:13px;
}

.mg-controls {
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  gap:12px 18px;
  background:var(--line);
  border:1px solid var(--line);
  border-radius:10px;
  padding:12px 14px;
  margin-bottom:16px;
}

.mode-switch {
  display:inline-flex;
  border:1px solid var(--line-strong);
  border-radius:9px;
  overflow:hidden;
  background:var(--surface);
}

.mode-switch button {
  border:0;
  border-radius:0;
  padding:9px 15px;
}

.mode-switch button[aria-selected="true"] {
  background:var(--ink);
  color:var(--on-ink);
}

.bar {
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  gap:10px;
  flex:1;
}

.bar label {
  display:flex;
  align-items:center;
  gap:7px;
  font-size:12px;
  color:var(--muted);
}

.scrub {
  flex:1;
  min-width:260px;
}

.scrub input {
  flex:1;
  accent-color:var(--world);
}

.scrub span {
  min-width:92px;
  font-variant-numeric:tabular-nums;
  color:var(--ink);
}

.scrub b {
  font-size:12px;
  font-variant-numeric:tabular-nums;
  color:var(--ink);
  white-space:nowrap;
}

.panel {
  background:var(--card);
  border:1px solid var(--line);
  border-radius:12px;
  padding:18px;
}

.section-heading {
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  gap:18px;
  margin-bottom:14px;
}

.section-heading>p {
  font-size:12px;
  color:var(--muted);
  margin:0;
  max-width:440px;
  text-align:right;
}

.mg-stage {
  display:grid;
  grid-template-columns:300px minmax(0,1fr) 350px;
  gap:16px;
  margin-bottom:16px;
  align-items:start;
}

.loading,.muted {
  color:var(--muted);
  font-size:13px;
}

/* console */
.mg-console {
  border-top:3px solid var(--world);
}

.mg-console header h2 {
  margin-bottom:6px;
}

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

.presets {
  display:grid;
  gap:7px;
  margin-bottom:12px;
}

.preset {
  text-align:left;
  display:flex;
  flex-direction:column;
  gap:3px;
  padding:9px 11px;
  border-color:var(--line);
  background:var(--surface);
}

.preset b {
  font-size:12.5px;
}

.preset small {
  font-weight:400;
  font-size:11px;
  color:var(--muted);
}

.preset:hover:not(:disabled) {
  border-color:var(--danger);
  background:var(--orange-soft);
}

fieldset {
  border:0;
  padding:0;
  margin:10px 0 0;
}

legend {
  font-size:11px;
  font-weight:650;
  color:var(--muted);
  letter-spacing:.8px;
  margin-bottom:4px;
}

fieldset label {
  display:flex;
  flex-direction:column;
  gap:2px;
  font-size:12px;
  margin-bottom:6px;
}

fieldset label span {
  display:flex;
  justify-content:space-between;
}

fieldset output {
  font-variant-numeric:tabular-nums;
  font-weight:650;
}

fieldset input[type=range] {
  accent-color:var(--danger);
}

.god {
  border-top:1px dashed var(--line);
  padding-top:10px;
  margin-top:4px;
}

.god h3,.ledger h3 {
  font-size:12px;
  color:var(--muted);
  font-weight:650;
}

.god .hint {
  font-size:11.5px;
  line-height:1.55;
  color:var(--muted);
  margin:2px 0 4px;
}

.god fieldset.knobs {
  margin:8px 0 0;
}

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

.god label.knob {
  display:flex;
  flex-direction:column;
  gap:1px;
  margin:0;
  padding:4px 6px 2px;
  border-radius:6px;
  font-size:11.5px;
  min-width:0;
}

.god label.knob span {
  display:flex;
  justify-content:space-between;
  align-items:baseline;
  gap:4px;
}

.god label.knob i {
  font-style:normal;
  color:var(--muted);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.god label.knob output {
  font-weight:700;
  font-variant-numeric:tabular-nums;
  color:var(--ink);
}

.god label.knob input[type=range] {
  width:100%;
  margin:2px 0 0;
  accent-color:var(--danger);
}

.god label.knob input[type=range]:disabled {
  accent-color:var(--line-strong);
  opacity:.75;
}

.god label.knob.wide {
  grid-column:1/-1;
}

.god label.knob select {
  margin-top:3px;
  font-size:12px;
}

.god label.knob.changed {
  background:var(--red-soft);
}

.god label.knob.changed i,.god label.knob.changed output {
  color:var(--danger);
}

.god label.knob.pending {
  outline:1.5px dashed var(--danger);
  outline-offset:-1.5px;
}

.god label.knob.pending output::after {
  content:' · 待注入';
  font-weight:500;
  font-size:10px;
}

.god .go-live {
  width:100%;
  margin-top:10px;
}

.ledger {
  margin-top:12px;
}

.ledger ul {
  list-style:none;
  margin:0;
  padding:0;
  display:grid;
  gap:6px;
}

.ledger li {
  font-size:12px;
  line-height:1.5;
  padding:6px 8px;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:7px;
}

.ledger li small {
  display:block;
  color:var(--muted);
}

.ledger li.muted {
  border-style:dashed;
}

.bolt {
  color:var(--danger);
  margin-right:4px;
}

.sig {
  display:block;
  color:var(--muted);
  font-size:10px;
  margin-top:6px;
  overflow-wrap:anywhere;
}

/* center */
.mg-center {
  border-top:3px solid var(--sandbox);
}

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

.track-toggle {
  display:inline-flex;
  gap:6px;
}

.track-toggle button {
  padding:7px 11px;
  font-size:12px;
}

.track-toggle button[aria-pressed="true"] {
  background:var(--sandbox);
  color:var(--on-solid);
  border-color:var(--sandbox);
}

.mg-topology svg {
  width:100%;
  height:auto;
  display:block;
}

.mg-topology .bus {
  stroke:var(--ink);
  stroke-width:4;
  stroke-linecap:round;
}

.flow-base {
  stroke:var(--line);
  stroke-linecap:round;
}

.flow-base.pv {
  stroke:var(--amber-line);
}

.flow-base.batt {
  stroke:var(--orange-line);
}

.flow {
  stroke:var(--teal-mid);
  stroke-linecap:round;
  stroke-dasharray:4 12;
}

.flow.fwd {
  animation:dash 1.2s linear infinite;
}

.flow.rev {
  animation:dash 1.2s linear infinite reverse;
}

.flow.pv {
  stroke:var(--amber-mid);
}

.flow.batt {
  stroke:var(--agent);
}

.flow.load {
  stroke:var(--muted);
}

@keyframes dash {
  to {
    stroke-dashoffset:-36;
  }
}

@media (prefers-reduced-motion:reduce) {
  .flow.fwd,.flow.rev {
    animation:none;
  }
}

.mg-topology text {
  text-anchor:middle;
  font-size:11px;
  fill:var(--ink);
}

.mg-topology .name {
  font-weight:650;
  font-size:11.5px;
}

.mg-topology .value {
  font-weight:650;
  font-variant-numeric:tabular-nums;
}

.mg-topology .sub {
  fill:var(--muted);
  font-size:10px;
}

.mg-topology .glyph {
  font-size:18px;
  fill:var(--ink);
}

.mg-topology .warn {
  fill:var(--danger);
  font-weight:650;
}

.mg-topology .big {
  font-size:13px;
}

.mg-topology .feeder-label {
  text-anchor:start;
  font-size:11px;
  fill:var(--teal-solid);
  font-weight:600;
}

.mg-topology .feeder-label.alert {
  fill:var(--danger);
}

.pcc {
  fill:var(--surface);
  stroke:var(--ink);
  stroke-width:1.5;
}

.pcc.alert {
  stroke:var(--danger);
  fill:var(--red-soft);
  stroke-width:2.5;
}

.battery .shell {
  fill:var(--surface);
  stroke:var(--muted);
  stroke-width:1.5;
}

.battery .fill {
  fill:var(--green-line);
}

.battery .fill.low {
  fill:var(--red-line);
}

.pv-icon {
  fill:var(--amber-soft);
  stroke:var(--amber-mid);
  stroke-width:1.5;
}

.load-icon,.hvac-icon {
  fill:var(--surface);
  stroke:var(--muted);
  stroke-width:1.5;
}

.load-icon.alert,.hvac-icon.alert {
  stroke:var(--danger);
  fill:var(--red-soft);
  stroke-width:2.5;
}

.thermo rect:first-child {
  fill:var(--surface);
  stroke:var(--muted);
}

.thermo .mercury {
  fill:var(--red-line);
}

.thermo.alert rect:first-child {
  stroke:var(--danger);
  stroke-width:2;
}

.thermo text {
  text-anchor:start!important;
}

.topo-empty {
  display:grid;
  place-items:center;
  min-height:260px;
  color:var(--muted);
}

.lamps {
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:8px;
  margin-top:8px;
}

.lamp {
  border:1px solid var(--line);
  border-radius:9px;
  padding:9px 10px;
  background:var(--surface);
  display:grid;
  grid-template-columns:auto 1fr;
  gap:2px 7px;
  align-items:center;
}

.lamp .dot {
  width:10px;
  height:10px;
  border-radius:50%;
  background:var(--ok);
  grid-row:span 2;
}

.lamp b {
  font-size:12px;
}

.lamp .val {
  grid-column:2;
  font-variant-numeric:tabular-nums;
  font-size:13px;
  font-weight:650;
}

.lamp small {
  grid-column:1/-1;
  font-size:10.5px;
  color:var(--muted);
}

.lamp.over .dot {
  background:var(--warn);
}

.lamp.over {
  border-color:var(--orange-line);
}

.lamp.collect .dot,.lamp.validate .dot {
  background:var(--sandbox);
}

.lamp.collect,.lamp.validate {
  border-color:var(--blue-line);
  background:var(--blue-soft);
}

.lamp.accepted .dot {
  background:var(--ok);
}

.lamp.accepted {
  border-color:var(--green-line);
  background:var(--surface-2);
}

.lamp.rejected .dot {
  background:var(--muted);
}

.lamp.quarantined .dot {
  background:var(--danger);
}

.lamp.quarantined {
  border-color:var(--red-line);
  background:var(--red-soft);
}

/* right */
.mg-right {
  border-top:3px solid var(--agent);
}

.duel {
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
}

.duel-card {
  border:1px solid var(--line);
  border-radius:9px;
  padding:10px;
  background:var(--surface);
}

.duel-card.evolving {
  border-color:var(--teal-line);
  background:var(--surface-2);
}

.duel-card header small {
  font-size:10px;
  color:var(--muted);
}

.duel-card h3 {
  font-size:12.5px;
  margin:2px 0 6px;
}

.duel-card dl {
  margin:0;
  display:grid;
  gap:3px;
}

.duel-card dl div {
  display:flex;
  justify-content:space-between;
  gap:6px;
  font-size:11.5px;
}

.duel-card dt {
  color:var(--muted);
}

.duel-card dd {
  margin:0;
  font-weight:650;
  font-variant-numeric:tabular-nums;
  text-align:right;
}

.duel-card dd small {
  font-weight:400;
  color:var(--muted);
}

.pick,.ver {
  font-size:11px;
  margin:7px 0 0;
  line-height:1.45;
}

.ver {
  color:var(--muted);
}

.diff {
  font-size:11px;
  display:flex;
  flex-wrap:wrap;
  gap:4px 10px;
  margin:9px 0 0;
  color:var(--muted);
}

.diff b {
  color:var(--ink);
  width:100%;
}

.final {
  margin-top:12px;
  border-top:1px dashed var(--line);
  padding-top:10px;
}

.final table {
  width:100%;
  border-collapse:collapse;
  font-size:11.5px;
  font-variant-numeric:tabular-nums;
}

.final th,.final td {
  padding:4px 3px;
  text-align:right;
  border-bottom:1px solid var(--line);
}

.final th:first-child {
  text-align:left;
}

.final small {
  display:block;
  font-size:10px;
  color:var(--muted);
  margin-top:6px;
}

.mg-events {
  margin-top:14px;
  border-top:1px solid var(--line);
  padding-top:12px;
}

.events {
  list-style:none;
  margin:0;
  padding:0;
  display:grid;
  gap:6px;
  max-height:420px;
  overflow:auto;
}

.ev {
  border-left:3px solid var(--line);
  padding:4px 0 4px 9px;
  cursor:pointer;
  font-size:11.5px;
}

.ev:hover {
  background:var(--surface-3);
}

.ev .when {
  font-variant-numeric:tabular-nums;
  font-weight:650;
  margin-right:6px;
}

.ev .tag {
  font-weight:650;
  margin-right:6px;
}

.ev .who {
  color:var(--muted);
  font-size:10.5px;
}

.ev p {
  margin:3px 0 0;
  line-height:1.5;
  color:var(--ink-2);
}

.ev.inject {
  border-color:var(--danger);
}

.ev.inject .tag {
  color:var(--danger);
}

.ev.residual_detected {
  border-color:var(--warn);
}

.ev.model_accepted {
  border-color:var(--ok);
}

.ev.model_rejected,.ev.model_retained {
  border-color:var(--muted);
}

.ev.meter_quarantined,.ev.honest_alarm {
  border-color:var(--danger);
}

.ev.limit_inferred,.ev.derate_inferred {
  border-color:var(--sandbox);
}

/* timeline */
.mg-timeline-panel {
  margin-bottom:16px;
}

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

.timeline-head h3 {
  margin:0;
}

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

.lg::before {
  content:"";
  display:inline-block;
  width:14px;
  height:3px;
  margin-right:5px;
  vertical-align:middle;
  background:currentColor;
}

.lg.frozen {
  color:var(--frozen);
}

.lg.evolving {
  color:var(--evolving);
}

.lg.peak::before {
  height:10px;
  background:var(--orange-soft);
}

.lg.detect::before,.lg.accept::before,.lg.alarm::before {
  width:8px;
  height:8px;
  border-radius:50%;
}

.lg.detect::before {
  background:var(--warn);
}

.lg.accept::before {
  background:var(--ok);
}

.lg.alarm::before {
  background:var(--danger);
}

svg.timeline {
  width:100%;
  height:150px;
  display:block;
  cursor:crosshair;
}

.timeline .peak {
  fill:var(--orange-soft);
}

.timeline .limit {
  stroke:var(--danger);
  stroke-dasharray:5 5;
  stroke-width:1;
  opacity:.55;
}

.s-frozen {
  fill:none;
  stroke:var(--frozen);
  stroke-width:1.4;
  stroke-dasharray:4 3;
}

.s-evolving {
  fill:none;
  stroke:var(--evolving);
  stroke-width:1.8;
}

.m-inject {
  stroke:var(--danger);
  stroke-width:1.5;
}

.m-bolt {
  font-size:12px;
  fill:var(--danger);
  text-anchor:middle;
}

.m-detect {
  fill:var(--warn);
}

.m-accept {
  fill:var(--ok);
}

.m-reject {
  fill:var(--muted);
}

.m-meter,.m-alarm {
  fill:var(--danger);
}

.m-limit {
  fill:var(--sandbox);
}

.m-decision {
  stroke:var(--ink);
  stroke-width:1.2;
}

.timeline .cursor {
  stroke:var(--ink);
  stroke-width:1.5;
}

.timeline .future {
  fill:var(--surface-3);
  opacity:.65;
}

/* funnel */
.decision-nav {
  display:flex;
  gap:6px;
  overflow-x:auto;
  padding-bottom:6px;
  margin-bottom:10px;
}

.decision-nav button {
  flex:none;
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  gap:2px;
  padding:7px 10px;
  font-size:12px;
}

.decision-nav small {
  font-weight:400;
  font-size:10px;
  color:var(--muted);
  max-width:180px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.decision-nav button[aria-selected="true"] {
  background:var(--ink);
  color:var(--on-ink);
  border-color:var(--ink);
}

.decision-nav button[aria-selected="true"] small {
  color:var(--faint);
}

.decision-nav button.has-alarm {
  border-color:var(--danger);
}

.decision-head {
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:16px;
  flex-wrap:wrap;
  margin-bottom:12px;
}

.decision-head h3 {
  font-size:15px;
  margin:0 0 4px;
}

.decision-head p {
  margin:0;
  font-size:12px;
  color:var(--muted);
}

.metrics {
  display:flex;
  flex-wrap:wrap;
  gap:6px;
}

.metrics span {
  font-size:11.5px;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:7px;
  padding:5px 8px;
  color:var(--muted);
}

.metrics b {
  color:var(--ink);
  font-variant-numeric:tabular-nums;
}

.ok {
  color:var(--ok)!important;
}

.bad {
  color:var(--danger)!important;
}

.funnel {
  display:grid;
  grid-template-columns:1fr 1fr 1.35fr;
  gap:12px;
}

.funnel section {
  border:1px solid var(--line);
  border-radius:10px;
  padding:12px;
  background:var(--surface);
  min-width:0;
}

.col-list {
  list-style:none;
  margin:0;
  padding:0;
  display:grid;
  gap:5px;
  max-height:520px;
  overflow:auto;
}

.col-list li {
  font-size:11.5px;
  line-height:1.45;
  padding:6px 8px;
  border-radius:7px;
  background:var(--surface-2);
}

.col-list li.cut {
  background:var(--red-soft);
}

.col-list li.picked {
  outline:2px solid var(--world);
  background:var(--green-soft);
}

.chips {
  display:flex;
  flex-wrap:wrap;
  gap:3px;
  margin-top:3px;
}

.chip {
  font-size:9.5px;
  padding:1px 5px;
  border-radius:9px;
  background:var(--line);
  color:var(--ink-2);
}

.cause {
  display:block;
  margin-top:3px;
  font-size:10.5px;
  font-weight:650;
}

.cause.structural {
  color:var(--danger);
}

.cause.model {
  color:var(--warn);
}

.flag.fp {
  display:inline-block;
  margin-top:3px;
  font-size:10px;
  color:var(--sandbox);
  font-weight:650;
}

table.rank {
  width:100%;
  border-collapse:collapse;
  font-size:11.5px;
  font-variant-numeric:tabular-nums;
}

.rank th,.rank td {
  padding:5px 4px;
  border-bottom:1px solid var(--line);
  text-align:right;
}

.rank th:nth-child(2),.rank td:nth-child(2) {
  text-align:left;
}

.rank thead th {
  color:var(--muted);
  font-weight:600;
  font-size:10.5px;
}

.rank tr.picked {
  background:var(--green-soft);
  outline:2px solid var(--world);
}

.rank tr.best td:nth-child(2)::after {
  content:" · 真值最优安全";
  color:var(--ok);
  font-size:10px;
  font-weight:650;
}

.alarm-box {
  border:1px solid var(--red-line);
  background:var(--red-soft);
  border-radius:9px;
  padding:11px;
  font-size:12px;
  line-height:1.55;
}

.alarm-box small {
  display:block;
  color:var(--muted);
  margin-top:5px;
}

.alarm-box p {
  margin:6px 0 0;
}

.m0-compare {
  margin-top:12px;
  border:1px solid var(--blue-line);
  background:var(--surface-2);
  border-radius:9px;
  padding:10px 12px;
  font-size:12px;
  line-height:1.55;
}

.m0-compare p {
  margin:4px 0 0;
}

.foot {
  font-size:11px;
  color:var(--muted);
  line-height:1.6;
  margin:12px 0 0;
}

/* bench */
.table-wrap {
  overflow-x:auto;
  margin-bottom:18px;
}

table.bench {
  width:100%;
  border-collapse:collapse;
  font-size:12px;
  font-variant-numeric:tabular-nums;
  min-width:1080px;
}

.bench th,.bench td {
  padding:7px 6px;
  border-bottom:1px solid var(--line);
  text-align:right;
  white-space:nowrap;
}

.bench thead th {
  font-size:10.5px;
  color:var(--muted);
  font-weight:600;
  white-space:normal;
  vertical-align:bottom;
}

.bench tbody th {
  text-align:left;
  font-weight:600;
  white-space:normal;
  max-width:260px;
}

code {
  font-size:12px;
  background:var(--line);
  padding:1px 5px;
  border-radius:4px;
}

footer {
  display:flex;
  justify-content:space-between;
  gap:14px;
  font-size:11px;
  color:var(--muted);
  padding:18px 2px 0;
  line-height:1.6;
}

footer p {
  margin:0;
}

section.panel+section.panel {
  margin-top:16px;
}

@media (max-width:1280px) {
  .mg-stage {
    grid-template-columns:280px minmax(0,1fr);
  }
  .mg-right {
    grid-column:1/-1;
  }
  .mg-right .duel {
    grid-template-columns:repeat(2,minmax(0,1fr));
  }
}

@media (max-width:900px) {
  main {
    padding:20px 16px;
  }
  .mg-intro {
    flex-direction:column;
    align-items:flex-start;
  }
  .progress-card {
    text-align:left;
  }
  .mg-stage {
    grid-template-columns:1fr;
  }
  .funnel {
    grid-template-columns:1fr;
  }
  .lamps {
    grid-template-columns:repeat(2,1fr);
  }
  .section-heading {
    flex-direction:column;
    align-items:flex-start;
  }
  .section-heading>p {
    text-align:left;
  }
  .center-head {
    flex-direction:column;
    align-items:flex-start;
  }
}

@media (max-width:520px) {
  .duel,.mg-right .duel {
    grid-template-columns:1fr;
  }
  .scrub {
    min-width:0;
    width:100%;
    flex-wrap:wrap;
  }
  .scrub input {
    order:3;
    flex:1 1 100%;
    min-width:0;
    width:100%;
  }
  .bar {
    gap:8px;
    min-width:0;
  }
  .mg-controls {
    padding:10px;
  }
  .mode-switch {
    width:100%;
  }
  .mode-switch button {
    flex:1;
  }
}

/* Agent engine panel (rules / real Jev routing, merged from the codex variant) */
.mg-engine {
  margin-bottom:12px;
}

.engine {
  border:1px solid var(--line);
  border-radius:9px;
  padding:10px;
  background:var(--surface);
}

.engine.jev {
  border-color:var(--orange-line);
  background:var(--orange-soft);
}

.engine h3 {
  font-size:12.5px;
  margin:0 0 4px;
  color:var(--agent);
}

.engine p {
  font-size:11.5px;
  margin:0 0 6px;
  color:var(--ink);
}

.engine small {
  display:block;
  font-size:10.5px;
  color:var(--muted);
}

.engine dl {
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:6px;
  margin:6px 0;
}

.engine dl div {
  display:grid;
}

.engine dt {
  font-size:10.5px;
  color:var(--muted);
}

.engine dd {
  margin:0;
  font-weight:650;
  font-variant-numeric:tabular-nums;
}

.engine .calls {
  list-style:none;
  margin:6px 0;
  padding:0;
  display:grid;
  gap:4px;
  max-height:180px;
  overflow:auto;
}

.engine .call {
  font-size:11.5px;
  border-left:3px solid var(--line);
  padding-left:6px;
}

.engine .call.completed {
  border-color:var(--ok);
}

.engine .call.failed,.engine .call.interrupted {
  border-color:var(--danger);
}

.engine .call .when {
  color:var(--muted);
  margin-right:4px;
  font-variant-numeric:tabular-nums;
}

.m-jev {
  fill:var(--agent);
}

.mg-controls .notice {
  margin:8px 0 0;
  font-size:12px;
  color:var(--warn);
}

/* ---- VPP merge (2026-10-29): attribution matrix, statement duel, timeline tabs, equation trees ---- */
:root {
}

.preset.rule {
  border-style:dashed;
}

.preset.rule:hover:not(:disabled) {
  border-color:var(--agent);
  background:var(--orange-soft);
}

.truth-rule {
  font-size:11.5px;
  margin:8px 0 0;
  color:var(--world);
}

.mg-topology .pcc-flow {
  font-size:13px;
}

.mg-topology .pl {
  font-size:10.5px;
  font-weight:650;
  text-anchor:middle;
  font-variant-numeric:tabular-nums;
}

.mg-topology .pl.pos {
  fill:var(--pos);
}

.mg-topology .pl.neg {
  fill:var(--neg);
}

.mg-topology .badge rect {
  fill:var(--orange-soft);
  stroke:var(--orange-line);
}

.mg-topology .badge text {
  font-size:10.5px;
  fill:var(--agent);
  font-weight:650;
}

/* attribution matrix */
.mg-causal {
  margin-top:10px;
}

table.causal {
  width:100%;
  border-collapse:separate;
  border-spacing:0 4px;
  font-size:11.5px;
  table-layout:fixed;
}

.causal thead th {
  font-size:10.5px;
  color:var(--muted);
  font-weight:600;
  text-align:left;
  padding:0 8px 2px;
}

.causal thead th:first-child {
  width:104px;
}

.causal thead th:nth-child(3) {
  width:23%;
}

.causal thead th:nth-child(4) {
  width:27%;
}

.causal tbody th,.causal td {
  background:var(--surface);
  border-top:1px solid var(--line);
  border-bottom:1px solid var(--line);
  padding:7px 8px;
  vertical-align:top;
  text-align:left;
}

.causal tbody th {
  border-left:1px solid var(--line);
  border-radius:8px 0 0 8px;
  font-weight:400;
}

.causal tbody th b {
  display:block;
  font-size:12px;
}

.causal tbody th small {
  color:var(--muted);
  font-family:"JetBrains Mono",ui-monospace,monospace;
  font-size:10px;
}

.causal td:last-child {
  border-right:1px solid var(--line);
  border-radius:0 8px 8px 0;
}

.causal td small {
  display:block;
  line-height:1.45;
  margin-top:3px;
}

.causal .muted {
  color:var(--muted);
  font-size:10.5px;
}

.causal tr.settle th,.causal tr.settle td {
  background:var(--orange-soft);
  border-color:var(--orange-line);
}

/* residual strip in the attribution matrix (not the control bar's .bar) */
.rbar {
  position:relative;
  height:6px;
  background:var(--surface-3);
  border-radius:4px;
  overflow:hidden;
}

.rbar span {
  display:block;
  height:100%;
  background:var(--teal-line);
  border-radius:4px;
}

.rbar.over span {
  background:var(--warn);
}

.rbar i {
  position:absolute;
  top:0;
  bottom:0;
  width:1px;
  background:var(--muted);
}

.state {
  display:inline-block;
  font-size:10.5px;
  font-weight:650;
  padding:2px 7px;
  border-radius:9px;
  background:var(--surface-3);
  color:var(--ink-2);
  margin-bottom:5px;
}

.state.collect,.state.validate {
  background:var(--blue-soft);
  color:var(--sandbox);
}

.state.accepted {
  background:var(--green-soft);
  color:var(--ok);
}

.state.rejected {
  background:var(--surface-3);
  color:var(--muted);
}

.state.quarantined {
  background:var(--red-soft);
  color:var(--danger);
}

.state.frozen {
  background:var(--surface-3);
  color:var(--frozen);
}

.causal code {
  display:block;
  font-size:10.5px;
  background:transparent;
  padding:0;
  color:var(--teal-fg);
  font-family:"JetBrains Mono",ui-monospace,monospace;
  white-space:normal;
}

.culprit span {
  display:inline-block;
  margin:0 4px 4px 0;
  font-size:10.5px;
  padding:2px 6px;
  border-radius:9px;
  font-variant-numeric:tabular-nums;
  white-space:nowrap;
}

.est,.culprit .est {
  background:var(--blue-soft);
  color:var(--est);
}

.tru,.culprit .tru {
  background:var(--teal-soft);
  color:var(--true);
}

thead .est,thead .tru {
  font-size:10px;
  padding:1px 6px;
  border-radius:9px;
}

.gates,.chain {
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  gap:6px 8px;
  margin-top:8px;
  font-size:11.5px;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:9px;
  padding:8px 10px;
}

.gates>b,.chain>b {
  font-size:11.5px;
  margin-right:4px;
}

.gates small {
  flex-basis:100%;
  color:var(--muted);
  font-size:10.5px;
}

.gate {
  padding:3px 8px;
  border-radius:9px;
  font-weight:600;
  font-size:11px;
}

.gate.pass {
  background:var(--green-soft);
  color:var(--ok);
}

.gate.block {
  background:var(--red-soft);
  color:var(--danger);
}

.gate.idle {
  background:var(--surface-3);
  color:var(--muted);
}

.chain .node {
  padding:4px 9px;
  font-size:11px;
  border-radius:14px;
  font-weight:600;
  background:var(--blue-soft);
  border-color:var(--blue-line);
  color:var(--sandbox);
}

.chain .node.settle {
  background:var(--orange-soft);
  border-color:var(--orange-line);
  color:var(--agent);
}

.chain .node small {
  font-weight:400;
  color:var(--muted);
}

.chain .arrow {
  color:var(--muted);
}

/* statement duel */
.duel-head {
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
}

.duel-head .net {
  border:1px solid var(--line);
  border-radius:9px;
  padding:9px 10px;
  background:var(--surface);
}

.duel-head .net.evolving {
  border-color:var(--teal-line);
  background:var(--surface-2);
}

.duel-head .net small {
  display:block;
  font-size:10.5px;
  color:var(--muted);
}

.duel-head .net b {
  font-size:19px;
  font-variant-numeric:tabular-nums;
  color:var(--pos);
}

.duel-head .net b.neg {
  color:var(--neg);
}

.gain {
  grid-column:1/-1;
  margin:0;
  padding:8px 10px;
  border-radius:9px;
  font-size:12px;
}

.gain.up {
  background:var(--green-soft);
  color:var(--ok);
}

.gain.down {
  background:var(--red-soft);
  color:var(--danger);
}

.gain b {
  font-size:15px;
  margin-left:4px;
  font-variant-numeric:tabular-nums;
}

.gain small {
  display:block;
  color:var(--muted);
  font-size:10px;
  margin-top:2px;
}

.mg-duel h4 {
  font-size:11.5px;
  color:var(--muted);
  margin:12px 0 4px;
}

table.ledger-table {
  width:100%;
  border-collapse:collapse;
  font-size:11.5px;
  font-variant-numeric:tabular-nums;
}

.ledger-table th,.ledger-table td {
  padding:4px 3px;
  border-bottom:1px solid var(--line);
  text-align:right;
}

.ledger-table th:first-child,.ledger-table tbody th {
  text-align:left;
  font-weight:400;
}

.ledger-table thead th {
  color:var(--muted);
  font-size:10.5px;
  font-weight:600;
}

.ledger-table tr.sum th,.ledger-table tr.sum td {
  font-weight:700;
  border-top:1px solid var(--line);
}

/* timeline tabs */
.tabs {
  display:inline-flex;
  border:1px solid var(--line-strong);
  border-radius:9px;
  overflow:hidden;
  background:var(--surface);
}

.tabs button {
  border:0;
  border-radius:0;
  padding:6px 11px;
  font-size:12px;
}

.tabs button[aria-selected="true"] {
  background:var(--ink);
  color:var(--on-ink);
}

svg.timeline {
  height:160px;
}

.timeline .zero {
  stroke:var(--ink);
  stroke-width:1.2;
}

.timeline .axis {
  font-size:10px;
  fill:var(--muted);
}

.timeline .cap {
  fill:none;
  stroke:var(--agent);
  stroke-width:1.2;
  stroke-dasharray:6 4;
}

.timeline.net .s-evolving {
  stroke-width:2.4;
}

.lg.cap {
  color:var(--agent);
}

/* equation drawer */
.eq-toggle {
  background:var(--surface);
  border-color:var(--blue-line);
  color:var(--sandbox);
}

.eq-toggle[aria-expanded="true"] {
  background:var(--sandbox);
  color:var(--on-solid);
  border-color:var(--sandbox);
}

.eq-toggle kbd {
  font-family:"JetBrains Mono",ui-monospace,monospace;
  font-size:10px;
  border:1px solid currentColor;
  border-radius:4px;
  padding:0 4px;
  margin-left:4px;
  opacity:.75;
}

.mg-equations {
  margin-bottom:16px;
  border-top:3px solid var(--sandbox);
}

.mg-equations:not([hidden]) {
  animation:eqopen .22s ease-out;
}

@keyframes eqopen {
  from {
    opacity:0;
    transform:translateY(-4px);
  }
  to {
    opacity:1;
    transform:none;
  }
}

@media (prefers-reduced-motion:reduce) {
  .mg-equations:not([hidden]) {
    animation:none;
  }
}

.eq-head p {
  font-size:12px;
  color:var(--muted);
  margin:0 0 10px;
}

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

.trees details {
  border:1px solid var(--line);
  border-radius:10px;
  background:var(--surface);
  padding:10px 12px;
}

.trees summary {
  cursor:pointer;
  font-weight:650;
  font-size:12.5px;
}

.trees ul {
  list-style:none;
  margin:8px 0 0;
  padding:0 0 0 10px;
  border-left:2px solid var(--line);
  display:grid;
  gap:9px;
}

.trees li code {
  display:block;
  font-family:"JetBrains Mono",ui-monospace,monospace;
  font-size:11px;
  background:var(--surface-3);
  padding:4px 6px;
  border-radius:5px;
  white-space:normal;
  color:var(--ink);
}

.trees li small {
  display:block;
  color:var(--muted);
  font-size:10.5px;
  margin-top:3px;
}

.vals {
  display:flex;
  flex-wrap:wrap;
  gap:4px 8px;
  margin-top:5px;
  font-size:11px;
}

.vals .v {
  font-variant-numeric:tabular-nums;
  color:var(--ink-2);
}

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

.src {
  display:inline-block;
  font-size:9.5px;
  font-weight:700;
  border-radius:8px;
  padding:0 5px;
  margin-right:3px;
  line-height:15px;
}

.src.true {
  background:var(--teal-soft);
  color:var(--true);
}

.src.est {
  background:var(--blue-soft);
  color:var(--est);
}

.src.meas {
  background:var(--orange-soft);
  color:var(--meas);
}

/* bench history */
.bench td small {
  display:block;
  font-size:10px;
  color:var(--muted);
}

h3.hist {
  margin-top:18px;
  color:var(--muted);
}

details.history {
  border:1px solid var(--line);
  border-radius:9px;
  padding:8px 12px;
  margin-bottom:8px;
  background:var(--surface);
}

details.history summary {
  cursor:pointer;
  font-size:12.5px;
  font-weight:650;
}

table.bench.legacy {
  min-width:760px;
}

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

@media (max-width:900px) {
  .trees {
    grid-template-columns:1fr;
  }
  table.causal {
    table-layout:auto;
  }
  .causal thead {
    display:none;
  }
  .causal tbody tr {
    display:grid;
    grid-template-columns:1fr;
    margin-bottom:6px;
    border:1px solid var(--line);
    border-radius:8px;
    overflow:hidden;
  }
  .causal tbody th,.causal td {
    border:0!important;
    border-radius:0!important;
  }
  .duel-head {
    grid-template-columns:1fr;
  }
}

/* continuous playback: dash phase follows the wall clock so re-rendering never restarts the flow animation */
.flow.fwd,.flow.rev {
  animation-delay:var(--phase,0s);
}

.mg-controls .end-note {
  flex-basis:100%;
  margin:2px 0 0;
  font-size:12px;
  color:var(--muted);
}

.mg-controls .end-note b {
  color:var(--ink);
}

.mg-topology .cont-note {
  text-anchor:end;
  font-size:9.5px;
  fill:var(--line-strong);
}

/* revenue explanation in the statement duel */
.mg-duel .explain {
  font-size:11.5px;
  line-height:1.6;
  color:var(--muted);
  margin:0 0 6px;
}

.ledger-table tr.subtotal th,.ledger-table tr.subtotal td {
  font-weight:700;
  border-top:1px dashed var(--line);
}

/* ==================================================================
   Guided layout (v2): guide → controls → stage + score → tabbed panels.
   Desktop ≥1101px · tablet 761–1100px · phone ≤760px with a bottom mini-player.
   ================================================================== */
.mg-main {
  max-width: 1560px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

.intro-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.t-frozen { color: var(--muted); }
.t-evolving { color: var(--evolving); }

/* ---------- guide */
.mg-guide {
  margin-bottom: 14px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--elev-1);
}

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

.guide-head h2 { font-size: 14px; }

.guide-close { min-height: 28px; padding: 0 10px; color: var(--muted); }

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.step {
  display: flex;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  transition: background-color .2s, border-color .2s;
}

.step .num {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.step b { font-size: 13px; color: var(--ink); }

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

.step.current {
  border-color: var(--blue-mid);
  background: var(--blue-soft);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue-mid) 14%, transparent);
}

.step.current .num { background: var(--blue-solid); color: var(--on-solid); }

.step.done .num { background: var(--green-soft); color: var(--green-fg); }

.step.done b { color: var(--muted); }

/* ---------- controls: one toolbar, pinned under the app bar on desktop */
.mg-controls {
  position: sticky;
  top: 64px;
  z-index: 20;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 12px;
}

.mg-controls .end-note, .mg-controls .eq-toggle { display: none; }

.mg-controls .bar { gap: 8px 12px; }

.mg-controls .scenario select { max-width: 340px; }

/* ---------- stage + scoreboard */
.mg-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
  margin-bottom: 18px;
}

.mg-scene { padding: 16px; }

.mg-scene .center-head { margin-bottom: 12px; }

.mg-scene h2 { font-size: 15px; }

.scene-hint { margin: 2px 0 0; font-size: 12px; color: var(--faint); }

.mg-topology { padding: 6px 4px; }

.swipe-hint { display: none; }

.mg-story {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.story-badge {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-fg);
  font-size: 11px;
  font-weight: 700;
}

.story-text { flex: 1; margin: 0; font-size: 13px; line-height: 1.65; color: var(--ink-2); }

.story-text b { color: var(--ink); }

.story-actions { display: flex; flex: none; gap: 8px; }

.mg-side { display: grid; gap: 14px; }

.mg-score { padding: 18px; }

.score-label { margin: 0 0 8px; font-size: 12px; font-weight: 650; color: var(--muted); }

.score-label small { margin-left: 6px; font-weight: 400; color: var(--faint); }

.score-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.score-row .who b { display: block; font-size: 13px; color: var(--ink); }

.score-row .who small { font-size: 11.5px; color: var(--faint); }

.score-row .amount {
  align-self: center;
  font-size: 26px;
  font-weight: 720;
  letter-spacing: -.02em;
  color: var(--muted);
}

.score-row.evolving .amount { color: var(--evolving); }

.score-row .amount.neg { color: var(--red-fg); }

.score-bar {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-3);
  overflow: hidden;
}

.score-bar i { display: block; height: 100%; border-radius: 2px; background: var(--faint); transition: width .3s var(--ease); }

.score-row.evolving .score-bar i { background: var(--evolving); }

.score-bar i.neg { background: var(--red-mid); }

.score-gap { margin: 8px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }

.score-gap b { font-size: 16px; }

.score-gap.up { background: var(--green-soft); color: var(--green-fg); }

.score-gap.down { background: var(--red-soft); color: var(--red-fg); }

.score-note { margin: 8px 0 0; font-size: 11px; color: var(--faint); }

.mg-engine.panel { padding: 14px 16px; }

.mg-engine .engine { margin: 0; padding: 0; border: 0; background: none; }

/* ---------- panels behind tabs */
#mg-tabs.mg-tabs {
  display: flex;
  width: 100%;
  max-width: 100%;
  margin: 0 0 12px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  scroll-margin-top: 140px;
}

#mg-tabs.mg-tabs button { scroll-snap-align: start; }

.mg-tabs::-webkit-scrollbar { display: none; }

.mg-tabs button { flex: 1 0 auto; min-height: 34px; }

.mg-tabs .badge {
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--orange-soft);
  color: var(--orange-fg);
  font-size: 10.5px;
  font-weight: 650;
}

.tab-panel { margin-bottom: 14px; padding: 18px; }

.tab-panel.mg-equations { border-top: 1px solid var(--line); }

.panel-intro {
  margin: 0 0 14px;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}

.agent-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }

/* The console now has the full width: lay its groups out in columns. */
.tab-panel .mg-console { border: 0; }

.tab-panel .presets { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }

.tab-panel #mg-truth {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 4px 20px;
}

.tab-panel #mg-truth > :not(fieldset) { grid-column: 1 / -1; }

.mg-mini { display: none; }

/* ---------- tablet */
@media (max-width: 1100px) {
  .mg-hero { grid-template-columns: 1fr; }
  .mg-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .agent-grid { grid-template-columns: 1fr; }
}

/* ---------- phone */
@media (max-width: 760px) {
  .mg-main { padding: 14px 14px 112px; }
  .mg-intro { flex-direction: column; align-items: stretch; gap: 12px; }
  main .page-head h1 { font-size: 21px; }
  .intro-side { align-items: stretch; }
  .progress-card { text-align: left; min-width: 0; }

  .mg-guide { padding: 14px; }
  .steps {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 82%;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .steps::-webkit-scrollbar { display: none; }
  .step { scroll-snap-align: start; }

  .mg-controls { position: static; scroll-margin-top: 110px; }
  .mg-controls .mode-switch { display: flex; width: 100%; }
  .mg-controls .mode-switch button { flex: 1; }
  .mg-controls .bar { flex-direction: column; align-items: stretch; }
  .mg-controls .bar > * { width: 100%; }
  .mg-controls .scenario { flex-direction: column; align-items: stretch; gap: 4px; }
  .mg-controls .scenario select, .mg-controls .speed select { width: 100%; max-width: none; }
  .mg-controls .speed { justify-content: space-between; }
  .mg-controls .bar > button { min-height: 40px; }

  .mg-scene { padding: 12px; }
  .mg-scene .center-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .track-toggle { display: flex; }
  .track-toggle button { flex: 1; }
  .topo-scroll { margin: 0 -12px; padding: 0 12px; overflow-x: auto; scroll-snap-type: x proximity; }
  .topo-scroll .mg-topology { min-width: 600px; }
  .swipe-hint { display: block; margin: 6px 0 0; text-align: center; font-size: 11px; color: var(--faint); }
  .mg-story { flex-direction: column; align-items: stretch; }
  .story-actions { flex-wrap: wrap; }
  .story-actions button { flex: 1; min-height: 40px; }
  .mg-side { grid-template-columns: 1fr; }
  .score-row .amount { font-size: 24px; }

  .mg-tabs { scroll-margin-top: 120px; }
  .mg-tabs button { flex: 0 0 auto; }
  .tab-panel { padding: 14px; }
  .tab-panel #mg-truth { grid-template-columns: 1fr; }
  .mg-timeline-panel .timeline-head { flex-wrap: wrap; }

  .mg-mini:not(:empty) {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: saturate(160%) blur(16px);
    -webkit-backdrop-filter: saturate(160%) blur(16px);
    box-shadow: var(--elev-2);
  }
  .mini-play {
    flex: none;
    width: 46px;
    height: 46px;
    padding: 0;
    border-radius: 50%;
    background: var(--ink);
    border-color: var(--ink);
    color: var(--on-ink);
  }
  .mini-play:hover:not(:disabled) { background: var(--ink); }
  .mini-play svg { width: 18px; height: 18px; fill: currentColor; }
  .mini-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .mini-time { font-size: 14px; color: var(--ink); }
  .mini-info small { font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mini-track { height: 3px; margin-top: 6px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
  .mini-track i { display: block; height: 100%; background: var(--evolving); }
  .mini-more { flex: none; min-height: 36px; }
}

/* Keep the diagram a readable size on wide screens. */
.mg-hero .mg-topology svg { max-height: 520px; }

/* Grid children must be allowed to shrink, or the scrollable diagram widens the whole page. */
.mg-hero > *, .mg-side > *, .mg-panels > *, .agent-grid > *, .mg-scene { min-width: 0; }

.mg-panels, .mg-main { min-width: 0; }

.mg-controls label { white-space: nowrap; }

@media (max-width: 760px) {
  .mg-controls .speed { display: flex; align-items: center; gap: 8px; }
  .mg-controls .speed select { flex: 1; }
  .mg-controls .scrub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
  .progress-card strong { font-size: 18px; }
}

/* ---------- Agent report card */
.verdict {
  display: grid;
  gap: 4px;
  margin-bottom: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}
.verdict-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.verdict strong { font-size: 22px; letter-spacing: -.01em; }
.verdict p { margin: 2px 0 0; font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.verdict.effective { background: var(--green-soft); border-color: var(--green-line); }
.verdict.effective strong { color: var(--green-fg); }
.verdict.partial, .verdict.watching { background: var(--amber-soft); border-color: var(--amber-line); }
.verdict.partial strong, .verdict.watching strong { color: var(--amber-fg); }
.verdict.ineffective { background: var(--red-soft); border-color: var(--red-line); }
.verdict.ineffective strong { color: var(--red-fg); }

.report-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 24px; }
.report-grid h3 { margin: 0 0 8px; font-size: 13px; }
.report-grid h3 small { margin-left: 6px; font-weight: 400; color: var(--faint); }
.expect { margin: 0 0 18px; padding: 10px 12px; border-left: 3px solid var(--blue-mid); background: var(--blue-soft); border-radius: 0 8px 8px 0; font-size: 13px; line-height: 1.6; color: var(--ink-2); }

.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.check { display: flex; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.check .mark { flex: none; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; font-weight: 800; background: var(--surface-3); color: var(--muted); }
.check b { font-size: 13px; }
.check .check-status { margin-left: 8px; font-size: 11px; font-weight: 650; color: var(--faint); }
.check p { margin: 3px 0 0; font-size: 12.5px; line-height: 1.55; color: var(--muted); }
.check.pass .mark { background: var(--green-soft); color: var(--green-fg); }
.check.pass .check-status { color: var(--green-fg); }
.check.fail { border-color: var(--red-line); background: var(--red-soft); }
.check.fail .mark { background: var(--red-solid); color: var(--on-solid); }
.check.fail .check-status { color: var(--red-fg); }
.check.pending .mark { background: var(--amber-soft); color: var(--amber-fg); }
.check.pending .check-status { color: var(--amber-fg); }
.check.na { opacity: .7; }

.report-table { width: 100%; }
.report-table tr.ok td:last-child { color: var(--green-fg); font-weight: 650; }
.report-table tr.bad td:last-child { color: var(--red-fg); font-weight: 650; }
.report-table tr.ref { color: var(--faint); }
.report-table th small { display: block; font-weight: 400; color: var(--faint); font-size: 11px; }
.caveat { margin: 10px 0 0; font-size: 12px; line-height: 1.6; color: var(--muted); }

.glossary { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.glossary summary { font-size: 13px; font-weight: 600; color: var(--blue-fg); }
.glossary dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px 20px; margin: 12px 0 0; }
.glossary dt { font-size: 12.5px; font-weight: 650; }
.glossary dt small { font-weight: 400; color: var(--faint); margin-left: 4px; }
.glossary dd { margin: 2px 0 0; font-size: 12px; line-height: 1.55; color: var(--muted); }

.verdict-chip {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  min-height: 40px;
  justify-content: flex-start;
}
.verdict-chip span { font-size: 12px; color: var(--muted); font-weight: 500; }
.verdict-chip small { margin-left: auto; font-size: 12px; color: var(--blue-fg); }
.verdict-chip.effective b { color: var(--green-fg); }
.verdict-chip.partial b, .verdict-chip.watching b { color: var(--amber-fg); }
.verdict-chip.ineffective b { color: var(--red-fg); }
.engine-opt { font-size: 11.5px; color: var(--faint); }

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

/* ---------- stability while playing: regions keep their size so nothing jumps under the pointer */
.mg-controls .scrub-time { display: inline-block; min-width: 7.5em; }
.mg-controls .scrub-count { display: inline-block; min-width: 8.5em; text-align: right; }
.mg-story { min-height: 84px; }
.story-text { min-height: calc(1.65em * 2); }
@media (min-width: 1101px) { .mg-score { min-height: 352px; } }
.mg-hero, .mg-panels { overflow-anchor: auto; }

/* ---------- decision settings (cadence / strategy space) */
.decision-settings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  flex-basis: 100%;
  margin-top: 2px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.ds-group { display: inline-flex; align-items: center; gap: 8px; }
.ds-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ds-seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--surface-3); }
.ds-seg button {
  min-height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-weight: 560;
}
.ds-seg button:hover:not(:disabled) { background: transparent; color: var(--ink); }
.ds-seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--elev-1); }
.ds-pending { font-size: 12px; color: var(--amber-fg); }
.ds-fixed { flex-basis: 100%; margin: 2px 0 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.ds-fixed b { color: var(--ink-2); }

/* ---------- searched candidates in the decision funnel */
.origin { margin-left: 6px; padding: 0 6px; border-radius: 4px; font-size: 10.5px; font-weight: 650; vertical-align: 1px; }
.origin.catalog { background: var(--surface-3); color: var(--muted); }
.origin.search { background: var(--blue-soft); color: var(--blue-fg); }
.origin.previous { background: var(--violet-soft); color: var(--violet-fg); }
.search-meta, .scope-note { margin: 0 0 10px; padding: 8px 12px; border-radius: 8px; font-size: 12.5px; line-height: 1.6; }
.search-meta { background: var(--blue-soft); color: var(--ink-2); }
.scope-note { background: var(--surface-2); color: var(--muted); }

@media (max-width: 760px) {
  .decision-settings { flex-direction: column; align-items: stretch; }
  .ds-group { justify-content: space-between; }
  .ds-seg { flex: 1; max-width: 260px; }
  .ds-seg button { flex: 1; min-height: 36px; }
}

/* ------------------------------------------------------------ spot market + thousand-household VPP panel */
.mg-market { display:grid; gap:16px; }
.mk-head p { margin:0 0 10px; color:var(--muted); font-size:13px; display:flex; gap:8px; flex-wrap:wrap; align-items:baseline; }
.mk-head .mk-time { margin-left:auto; font-variant-numeric:tabular-nums; color:var(--ink-2); }
.mk-kpis { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:10px; }
.mk-kpis > div { background:var(--surface-2); border:1px solid var(--line); border-radius:10px; padding:10px 12px; display:grid; gap:2px; min-width:0; }
.mk-kpis span { font-size:12px; color:var(--muted); }
.mk-kpis b { font-size:20px; font-variant-numeric:tabular-nums; color:var(--ink); }
.mk-kpis small { font-size:12px; color:var(--faint); overflow-wrap:anywhere; }
.mk-kpis .score b { color:var(--evolving); }
.mk-block { border:1px solid var(--line); border-radius:12px; padding:14px; background:var(--surface); min-width:0; }
.mk-block h3 { margin:0 0 10px; font-size:15px; display:flex; gap:8px; align-items:baseline; }
.mk-block h3 small { font-weight:400; color:var(--faint); font-size:12px; }
.mk-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(320px,1fr)); gap:16px; }
.mk-chart { width:100%; height:auto; display:block; }
.mk-chart .g { stroke:var(--line); stroke-width:1; }
.mk-chart .day { stroke:var(--line-strong); stroke-dasharray:2 4; }
.mk-chart .ax { fill:var(--faint); font-size:11px; }
.mk-chart path { fill:none; stroke-width:2; stroke-linejoin:round; }
.mk-chart .da { stroke:var(--grid); }
.mk-chart .rt { stroke:var(--orange-mid); stroke-width:1.6; }
.mk-chart .fc { stroke:var(--grid); stroke-dasharray:5 4; opacity:.6; }
.mk-chart .neg { fill:var(--red-soft); }
.mk-chart .cursor { stroke:var(--ink); stroke-width:1.2; opacity:.5; }
.mk-chart .band { fill:var(--blue-soft); stroke:none; }
.mk-chart .qda { stroke:var(--grid); stroke-width:1.4; stroke-dasharray:3 2; }
.mk-chart .next { stroke:var(--grid); stroke-width:1.2; stroke-dasharray:2 3; opacity:.55; }
.mk-chart .q { stroke:var(--ink); stroke-width:2; }
.mk-chart .campus { stroke:var(--storage); stroke-width:1.2; opacity:.8; }
.mk-chart .fleet { stroke:var(--load); stroke-width:1.2; opacity:.8; }
.mk-legend { margin:6px 0 0; font-size:12px; color:var(--muted); line-height:1.7; }
.mk-legend .k { display:inline-block; width:16px; height:3px; border-radius:2px; vertical-align:middle; margin:0 4px 0 8px; background:var(--ink); }
.mk-legend .k.da,.mk-legend .k.qda { background:var(--grid); }
.mk-legend .k.rt { background:var(--orange-mid); }
.mk-legend .k.fc,.mk-legend .k.next { background:repeating-linear-gradient(90deg,var(--grid) 0 4px,transparent 4px 7px); }
.mk-legend .k.neg { height:9px; background:var(--red-soft); border:1px solid var(--red-line); }
.mk-legend .k.band { height:9px; background:var(--blue-soft); }
.mk-legend .k.campus { background:var(--storage); }
.mk-legend .k.fleet { background:var(--load); }
.mk-stack { position:relative; height:46px; margin-top:12px; border-radius:8px; overflow:hidden; background:var(--surface-3); }
.mk-stack .blk { position:absolute; top:0; bottom:0; border-right:1px solid var(--surface);
  background:color-mix(in srgb, var(--orange-mid) calc(var(--p) * 70%), var(--teal-soft)); display:grid; align-content:center; padding:0 4px; overflow:hidden; }
.mk-stack .blk b { font-size:11px; font-weight:600; color:var(--ink); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.mk-stack .blk small { font-size:10px; color:var(--ink-2); }
.mk-stack .net { position:absolute; top:0; bottom:0; border-left:2px solid var(--ink); padding-left:4px; font-size:11px; font-weight:700; color:var(--ink);
  display:flex; align-items:flex-end; white-space:nowrap; background:linear-gradient(90deg,var(--surface),transparent); }
.mk-map { width:100%; max-width:460px; height:auto; display:block; image-rendering:pixelated; }
.mk-map .m-idle { fill:var(--surface-3); }
.mk-map .m-ev { fill:var(--blue-mid); }
.mk-map .m-v2g { fill:var(--violet-mid); }
.mk-map .m-chg { fill:var(--teal-mid); }
.mk-map .m-dis { fill:var(--green-mid); }
.mk-map .m-ac { fill:var(--orange-mid); }
.mk-map .m-opt { fill:var(--red-mid); }
.mk-map .m-off { fill:var(--faint); opacity:.5; }
.mk-maplegend { display:flex; flex-wrap:wrap; gap:6px 12px; font-size:12px; color:var(--muted); margin:8px 0 0; }
.mk-maplegend i { display:inline-block; width:10px; height:10px; border-radius:2px; vertical-align:-1px; margin-right:4px; }
.mk-maplegend i.m-idle { background:var(--surface-3); border:1px solid var(--line-strong); }
.mk-maplegend i.m-ev { background:var(--blue-mid); }
.mk-maplegend i.m-v2g { background:var(--violet-mid); }
.mk-maplegend i.m-chg { background:var(--teal-mid); }
.mk-maplegend i.m-dis { background:var(--green-mid); }
.mk-maplegend i.m-ac { background:var(--orange-mid); }
.mk-maplegend i.m-opt { background:var(--red-mid); }
.mk-maplegend i.m-off { background:var(--faint); }
.mk-maplegend b { color:var(--ink); font-variant-numeric:tabular-nums; }
.mk-brain { display:grid; gap:10px; }
.mk-rho,.mk-ledger { width:100%; border-collapse:collapse; font-size:13px; font-variant-numeric:tabular-nums; }
.mk-rho caption,.mk-ledger caption { text-align:left; color:var(--muted); font-size:12px; padding-bottom:6px; }
.mk-rho th,.mk-rho td,.mk-ledger th,.mk-ledger td { padding:5px 6px; border-bottom:1px solid var(--line); text-align:right; }
.mk-rho th:first-child,.mk-ledger th { text-align:left; font-weight:500; }
.mk-rho .god,.mk-ledger .ref td { color:var(--world); }
.mk-rho small { display:block; font-size:10px; color:var(--faint); font-weight:400; }
.mk-ledger .gain { color:var(--pos); }
.mk-ledger .cost { color:var(--warn); }
.mk-ledger tbody.phys th,.mk-ledger tbody.phys td { color:var(--ink-2); background:var(--surface-2); }
.mk-ledger tfoot th,.mk-ledger tfoot td { font-weight:700; border-bottom:none; }
.mk-ledger tfoot .ref th,.mk-ledger tfoot .ref td { font-weight:400; font-size:12px; }
.mk-model { display:grid; grid-template-columns:repeat(auto-fit,minmax(130px,1fr)); gap:8px; margin:0; }
.mk-model div { background:var(--surface-2); border-radius:8px; padding:8px 10px; }
.mk-model dt { font-size:12px; color:var(--muted); }
.mk-model dd { margin:2px 0 0; font-variant-numeric:tabular-nums; }
.mk-bias { font-size:12px; color:var(--muted); }
.mk-bias div { display:grid; grid-template-columns:repeat(24,1fr); gap:2px; height:36px; align-items:end; margin-top:4px; }
.mk-bias i { display:block; height:var(--h); min-height:1px; background:var(--evolving); border-radius:2px 2px 0 0; }
.mk-bias i.neg { background:var(--orange-mid); }
.mk-lp { margin:0; font-size:12px; color:var(--muted); line-height:1.6; }
.mk-envs { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:8px; }
.mk-env { margin:0; }
.mk-env figcaption { font-size:12px; color:var(--ink-2); display:grid; }
.mk-env figcaption small { color:var(--faint); font-size:10.5px; }
.mk-env svg { width:100%; height:auto; display:block; }
.mk-env .band { fill:var(--teal-soft); stroke:var(--teal-line); }
.mk-env .plan { fill:none; stroke:var(--sandbox); stroke-width:2; }
.mk-presets { display:grid; gap:8px; }
.mk-preset { text-align:left; display:grid; gap:2px; font-weight:400; }
.mk-preset b { font-size:13px; }
.mk-preset small { color:var(--muted); font-size:12px; line-height:1.5; }
.mk-events { list-style:none; margin:12px 0 0; padding:0; display:grid; gap:6px; font-size:12px; color:var(--ink-2); }
.mk-events li { display:grid; grid-template-columns:auto auto 1fr; gap:6px; align-items:baseline; }
.mk-events time { color:var(--faint); font-variant-numeric:tabular-nums; white-space:nowrap; }
.mk-events .tag { font-size:11px; border:1px solid var(--line-strong); border-radius:999px; padding:0 6px; color:var(--muted); }
.mk-empty,.mk-note { color:var(--muted); font-size:13px; }
.mk-off { max-width:760px; display:grid; gap:10px; }
.mk-off h3 { margin:0; font-size:17px; }
.mk-off p,.mk-off li { color:var(--ink-2); line-height:1.7; font-size:14px; }
.mk-off ul { margin:0; padding-left:20px; }
.mk-off button { justify-self:start; }
.mk-score { margin-top:12px; padding-top:10px; border-top:1px dashed var(--line-strong); display:grid; gap:2px; }
.mk-score span { font-size:12px; color:var(--muted); }
.mk-score b { font-size:20px; font-variant-numeric:tabular-nums; }
.mk-score small { font-size:12px; color:var(--faint); }
@media (max-width:640px) {
  .mk-kpis { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .mk-events li { grid-template-columns:1fr; }
  .mk-stack .blk b { font-size:9px; }
}
