:root {
  color-scheme: light dark;
  --paper: #f4efe2;
  --paper-deep: #e8e0cf;
  --ink: #172127;
  --muted: #59676d;
  --rule: #87979a;
  --grid: rgba(45, 66, 72, 0.11);
  --trace-a: #006f78;
  --trace-b: #ad4f16;
  --mark: #5d4b8c;
  --danger: #8e2f31;
  --focus: #005fcc;
  --field: rgba(255, 255, 255, 0.62);
  --panel: color-mix(in srgb, var(--paper-deep) 52%, transparent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #11191c;
    --paper-deep: #192428;
    --ink: #e8eee8;
    --muted: #aebcb9;
    --rule: #607076;
    --grid: rgba(187, 218, 211, 0.1);
    --trace-a: #65d7dc;
    --trace-b: #ffad6f;
    --mark: #c6b2ff;
    --danger: #ff8f97;
    --focus: #8ac7ff;
    --field: rgba(255, 255, 255, 0.06);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 48px);
}

header {
  border-top: 4px solid var(--ink);
  border-bottom: 1px solid var(--rule);
  padding: 14px 0 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font: 600 12px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: "Songti SC", "STSong", Georgia, serif;
  font-size: clamp(27px, 5vw, 48px);
  font-weight: 500;
  letter-spacing: -0.025em;
}

.lede {
  max-width: 820px;
  margin: 8px 0 0;
  color: var(--muted);
}

.method {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--mark);
  background: color-mix(in srgb, var(--paper-deep) 66%, transparent);
  font-size: 13px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 13px 16px;
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--rule);
}

label {
  display: grid;
  align-content: start;
  gap: 6px;
  font-weight: 600;
}

label span {
  display: block;
}

label small {
  float: right;
  margin-left: 8px;
  color: var(--muted);
  font: 400 11px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
}

input,
select {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: 2px;
  font: 550 15px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}

input:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

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

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  border-bottom: 1px solid var(--rule);
}

.metric {
  min-width: 0;
  padding: 14px 14px 12px 0;
}

.metric + .metric {
  padding-left: 14px;
  border-left: 1px solid var(--rule);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.07em;
}

.metric strong {
  display: block;
  margin-top: 2px;
  font: 550 clamp(15px, 2.6vw, 21px)/1.25 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}

.detail {
  min-height: 1.55em;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.detail.is-warning {
  color: var(--danger);
  font-weight: 600;
}

.plot-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 390px), 1fr));
}

figure {
  min-width: 0;
  margin: 12px 0 0;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.lab-plot {
  display: block;
  width: 100%;
  height: auto;
  min-height: 360px;
  overflow: hidden;
  background: var(--panel);
  border-block: 1px solid var(--rule);
}

.axis,
.tick {
  stroke: var(--rule);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.gridline {
  stroke: var(--grid);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.trace-a,
.trace-b,
.trace-c,
.candidate {
  fill: none;
  vector-effect: non-scaling-stroke;
}

.trace-a {
  stroke: var(--trace-a);
  stroke-width: 2.5;
}

.trace-b {
  stroke: var(--trace-b);
  stroke-width: 3;
}

.trace-c {
  stroke: var(--mark);
  stroke-width: 2.2;
}

.candidate {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 7 5;
}

.guide {
  stroke: var(--mark);
  stroke-width: 1.4;
  stroke-dasharray: 3 5;
  vector-effect: non-scaling-stroke;
}

.danger-guide {
  stroke: var(--danger);
  stroke-width: 1.5;
  stroke-dasharray: 3 5;
  vector-effect: non-scaling-stroke;
}

.conduction {
  fill: color-mix(in srgb, var(--mark) 14%, transparent);
}

.charge-dot {
  fill: var(--mark);
}

.label,
.tick-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.label {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 600;
  paint-order: stroke;
  stroke: var(--paper);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.tick-label {
  fill: var(--muted);
  font-size: 10.5px;
}

figcaption,
footer {
  color: var(--muted);
  font-size: 12px;
}

figcaption {
  margin-top: 9px;
}

.formula {
  margin: 15px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  font: 400 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}

footer {
  margin-top: 18px;
}

@media (max-width: 560px) {
  main {
    padding: 14px 12px 28px;
  }

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

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

  .metric {
    padding: 9px 0;
  }

  .metric + .metric {
    padding-left: 0;
    border-left: 0;
    border-top: 1px solid var(--rule);
  }

}

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

@media (max-width: 760px) {
  .lab-plot {
    width: 60rem;
    min-width: 60rem;
    min-height: 0;
  }

  #stepPlot {
    width: 42rem;
    min-width: 42rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
