:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eff2f9;
  color: #1f2843;
  font-synthesis: none;
  --muted: #505a72;
  --purple: #543b9e;
  --line: #d5dbea;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(ellipse at 80% 0%, #e0ddf7, transparent 58%), #eff2f9; }
button, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 3px solid #8a60e8; outline-offset: 3px; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.lab { max-width: 1520px; margin: 0 auto; padding: clamp(22px, 3vw, 48px); }
.mast { margin-bottom: 1.35rem; }
.serial { display: flex; align-items: center; gap: 11px; color: #523d93; font: 650 .75rem var(--mono); }
.serial svg { fill: none; stroke: currentColor; stroke-width: 1.2; flex: none; }
.serial-rule { width: 27px; border-top: 1px solid #aaa0c7; }
.isotope { font-size: .92rem; }
h1, h2, h3, p, figure { margin: 0; }
h1 { font: 600 clamp(2rem, 3.65vw, 3.6rem)/1.04 Georgia, "Songti SC", "Noto Serif CJK SC", serif; letter-spacing: -.04em; margin: .6rem 0 .65rem; text-wrap: balance; }
.mast p { font-size: clamp(.93rem, 1.25vw, 1.08rem); color: var(--muted); max-width: 80ch; line-height: 1.5; }
.presets, .channel, .actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.presets button, .actions button {
  color: #313a58; border-radius: 8px; border: 1px solid #c9cfe3; background: #fbfcff;
  font-size: .82rem; font-weight: 620; padding: .55rem .82rem; min-height: 38px;
}
.presets button:hover, .actions button:hover { border-color: #765abd; background: #f8f5ff; }
.presets button[aria-pressed="true"], #scan[data-scanning] { color: white; border-color: #574099; background: #5b43a0; }
.scenario {
  min-height: 2.9rem; display: flex; align-items: center; color: var(--muted);
  font-size: .84rem; line-height: 1.42; padding: .55rem 0;
}
#load-error { color: #95271d; }
.workbench { display: grid; grid-template-columns: minmax(0, 1.67fr) minmax(0, 1fr); gap: clamp(12px, 1.25vw, 20px); }
.observation, .phase, .inputs { border-radius: 15px; min-width: 0; padding: clamp(13px, 1.4vw, 22px); }
.observation {
  color: #f0f3ff; background: linear-gradient(150deg, #25294d, #171c37 62%, #212747);
  border: 1px solid #323a65; box-shadow: 0 12px 27px -20px #222a51;
}
.phase { background: #fcfbff; border: 1px solid #d2ccea; box-shadow: 0 12px 27px -21px #513b97; }
.inputs { grid-column: 1 / -1; border: 1px solid var(--line); background: #f9fbff; box-shadow: 0 12px 20px -22px #28324e; }
.panel-head, .phase-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.step { display: block; font: 650 .68rem var(--mono); padding-bottom: 4px; color: #5e4a90; letter-spacing: .045em; }
.observation .step { color: #b6c4fb; }
h2 { font-size: clamp(1rem, 1.55vw, 1.34rem); line-height: 1.14; letter-spacing: -.017em; }
h3 { font-size: .8rem; line-height: 1.24; padding-bottom: 5px; font-weight: 650; color: #d5ddf7; }
.channel { gap: 2px; background: #161b35; border: 1px solid #464f7b; border-radius: 8px; padding: 2px; }
.channel button { min-height: 32px; border: 0; border-radius: 5px; padding: .32rem .58rem; color: #d1d8f2; background: transparent; font-size: .76rem; font-weight: 620; }
.channel button:hover { color: #fff; }
.channel button[aria-pressed="true"] { background: #4a497b; color: #fff; }
.observation-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.03fr); grid-template-areas: "detector cut" "quick quick"; align-items: stretch; gap: 11px; margin: 12px 0 7px; }
.detector { grid-area: detector; }
.cut { grid-area: cut; }
.quick { grid-area: quick; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.quick .range { background: #303756; border-color: #444d75; }
.quick .range label { color: #e5eaff; }
.quick .range output { color: #d9caff; }
.quick input { accent-color: #b6a4f5; }
.detector, .cut { display: flex; flex-direction: column; justify-content: space-between; min-width: 0; background: #141a32; padding: 10px; border-radius: 9px; border: 1px solid #3d466a; }
canvas { display: block; width: 100%; }
#image, #profile { height: clamp(195px, 17.9vw, 282px); }
#phase-plot { height: clamp(170px, 17vw, 268px); }
figcaption { min-height: 1.55rem; display: flex; flex-wrap: wrap; column-gap: 10px; row-gap: 3px; align-items: center; padding-top: 4px; }
.legend { display: inline-flex; gap: 4px; align-items: center; font-size: .71rem; color: #d4ddf7; }
.legend::before { content: ""; width: 13px; border-top: 2px solid #f9a991; flex: none; }
.legend.thermal::before { border-top: 2px dashed #95e7fb; }
.legend.total::before { border-color: #f2f1ff; }
.obs-note { color: #c2cbee; font-size: .72rem; line-height: 1.45; }
.state { font-size: .78rem; color: #473385; background: #eee8ff; border-radius: 99px; padding: .38rem .63rem; max-width: 100%; }
.state[data-kind="normal"] { color: #294f6c; background: #e5f2ff; }
.state[data-kind="threshold"] { color: #793527; background: #fcebe4; }
.fraction-readout { display: flex; align-items: baseline; gap: .7rem; padding: .5rem 0 .05rem; color: #5a3ba8; font-variant-numeric: tabular-nums; }
.fraction-readout output { font: 650 clamp(2rem, 3.65vw, 3.35rem)/1 var(--mono); letter-spacing: -.07em; }
.fraction-readout span { font: 600 .8rem var(--mono); color: #614f91; }
.stats, .aux { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stats { padding-top: 8px; }
.stats > div { background: #f0effa; border-radius: 7px; padding: 7px; }
.stats span, .aux span { color: #505a72; display: block; font-size: .70rem; line-height: 1.28; }
.stats output, .aux output { display: block; margin-top: 3px; font: 650 clamp(.75rem, 1.1vw, .94rem) var(--mono); color: #21304b; overflow-wrap: anywhere; }
.actions { margin-top: 10px; }
.actions button { min-height: 35px; padding: .38rem .67rem; }
.scan-icon { display: inline-block; width: 8px; height: 10px; vertical-align: -1px; margin-right: .38rem; background: currentColor; clip-path: polygon(0 0, 100% 50%, 0 100%); }
#scan[data-scanning] .scan-icon { clip-path: polygon(0 0, 33% 0, 33% 100%, 67% 100%, 67% 0, 100% 0, 100% 100%, 0 100%); }
.ranges { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-top: 10px; }
.range { min-width: 0; background: #eaeefa; border: 1px solid #e1e5f2; border-radius: 8px; padding: 7px 9px 3px; }
.range-head { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 8px; flex-wrap: wrap; min-height: 1.3rem; }
.range label { color: #292f4b; font-size: .76rem; font-weight: 640; }
.range output { font: 650 .76rem var(--mono); color: #533c90; font-variant-numeric: tabular-nums; }
.range input { width: 100%; margin: 0; height: 27px; display: block; accent-color: #6b4cbd; cursor: ew-resize; }
.aux { border-top: 1px solid #e0e4ee; padding: 9px 1px 0; margin: 9px 0 0; }
.model-warning { font-size: .76rem; color: #813224; background: #fff1e8; margin-top: 8px; padding: 6px 8px; border-radius: 6px; }
footer { margin-top: 12px; color: #4b566e; font-size: .77rem; line-height: 1.45; }
@media (max-width: 850px) {
  .workbench { grid-template-columns: minmax(0, 1fr); }
  .inputs { grid-column: auto; }
  #image, #profile { height: clamp(200px, 33vw, 290px); }
  #phase-plot { height: clamp(190px, 34vw, 250px); }
}
@media (max-width: 520px) {
  .lab { padding: 16px 11px; }
  h1 { font-size: clamp(1.6rem, 7.1vw, 2rem); }
  .presets button { padding: .42rem .55rem; min-height: 36px; }
  .scenario { min-height: 0; }
  .observation-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "detector" "quick" "cut"; }
  #image { height: min(68vw, 275px); }
  #profile { height: 174px; }
  .channel button { min-height: 36px; }
  .ranges { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .range:first-child { grid-column: 1 / -1; }
  .stats > div { padding: 6px; }
}
