:root {
  color-scheme: dark;
  --bg: #081f33;
  --panel: #102e43;
  --line: #2a485c;
  --ink: #edf5f5;
  --muted: #abc0ce;
  --water: #5bdfde;
  --gold: #ffd092;
  --violet: #b9a4ed;
  --manual: #b4c3cd;
  --warning: #ffad88;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scrollbar-color: #48677b var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select { font: inherit; }
button, a, input, select, summary { -webkit-tap-highlight-color: transparent; }
button { color: inherit; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button, select, summary { transition: background-color .18s, color .18s, border-color .18s; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }
a { color: inherit; text-underline-offset: .25em; }
svg { display: block; }
button svg, summary svg { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.7; }
input { caret-color: var(--water); }
input, output, #clock, .water-readout strong, .flow-readouts strong, td { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
::selection { background: var(--gold); color: var(--bg); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.shell { max-width: 1840px; margin: 0 auto; padding: 0 4vw; }
.skip { position: fixed; z-index: 100; top: 8px; left: 12px; padding: 10px 18px; background: var(--ink); color: var(--bg); transform: translateY(-160%); }
.skip:focus { transform: none; }

.masthead { height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-size: 1.5rem; font-weight: 700; white-space: nowrap; }
.brand svg { width: 38px; height: 38px; fill: none; stroke: var(--water); stroke-width: 2.4; }
.brand .gold { stroke: var(--gold); }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; padding: 10px; border: 1px solid var(--line); border-radius: 50%; background: none; }
.icon-button:hover { background: var(--panel); border-color: #5f7b8b; }
.masthead-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.ui-style-link { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); font-size: 16px; text-decoration: none; white-space: nowrap; }
.ui-style-link:hover { color: var(--ink); background: var(--panel); }
@media (max-width: 600px) {
  .masthead { gap: 10px; }
  .masthead-actions { gap: 8px; }
  .ui-style-link { padding-inline: 8px; }
}
.page-heading { display: flex; align-items: center; justify-content: space-between; min-height: 74px; padding: 18px 0; gap: 20px; }
.page-heading h1 { margin: 0; font-size: clamp(1.75rem, 2.4vw, 2.25rem); font-weight: 600; line-height: 1.2; letter-spacing: -.01em; text-wrap: balance; }
.run-status { display: flex; align-items: center; gap: 9px; color: var(--water); font-size: 1rem; line-height: 1.4; }
.status-dot { display: inline-block; width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--water); }
.status-dot.warning { background: var(--warning); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: "scene controls" "circuit circuit"; border: 1px solid var(--line); border-radius: 16px; }
.scene-panel { grid-area: scene; position: relative; min-width: 0; min-height: 448px; background: radial-gradient(ellipse at 55% 48%, #12344a 0, #0b273c 54%, #0a2236 100%); border-radius: 15px 0 0 0; overflow: hidden; }
.scene-panel canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.scene-top { position: absolute; z-index: 1; top: 19px; left: 26px; right: 26px; display: flex; align-items: center; justify-content: flex-end; gap: 16px; color: var(--muted); pointer-events: none; }
#phaseLabel { margin-right: auto; color: var(--gold); }
.water-readout { position: absolute; top: 44px; left: 26px; pointer-events: none; }
.reading-label { color: #bdd1df; font-size: 1rem; }
.water-readout strong { font-size: 3.5rem; font-weight: 500; line-height: 1.2; letter-spacing: -.03em; }
.water-readout .unit { margin-left: 9px; color: var(--muted); font-size: 1.25rem; }
.flow-readouts { position: absolute; bottom: 17px; left: 26px; display: flex; gap: 32px; pointer-events: none; }
.flow-readouts > div { display: flex; flex-direction: column; gap: 1px; }
.flow-readouts span { color: var(--muted); font-size: 1rem; }
.flow-readouts strong { color: var(--ink); font-size: 1.5rem; font-weight: 500; line-height: 1.3; white-space: nowrap; }
.flow-readouts small { color: var(--muted); font-size: 1rem; font-weight: 400; }
.selection-detail { position: absolute; left: 26px; right: 26px; bottom: 79px; width: fit-content; max-width: calc(100% - 52px); padding: 4px 9px; background: #081f33e8; border-radius: 4px; color: var(--ink); font-size: 1rem; line-height: 1.5; overflow-wrap: anywhere; }
#circuit { grid-area: circuit; min-width: 0; border-top: 1px solid var(--line); border-radius: 0 0 15px 15px; }

.control-panel { grid-area: controls; min-width: 0; padding: 16px 22px; display: flex; flex-direction: column; gap: 8px; border-left: 1px solid var(--line); border-radius: 0 15px 0 0; background: #102c41; }
.panel-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
select { min-width: 0; min-height: 44px; padding: 7px 34px 7px 12px; border: 1px solid #426176; border-radius: 7px; background-color: #092338; color: var(--ink); cursor: pointer; }
select:hover { border-color: #7196a7; }
.panel-heading select { flex: 1; width: 0; }
.text-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 4px 0; border: 0; background: none; color: var(--muted); font-size: 1rem; white-space: nowrap; }
.text-button:hover { color: var(--ink); }
.control-field { min-width: 0; }
.control-field label { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 26px; margin-bottom: 0; font-size: 1rem; }
.control-field output { flex-shrink: 0; color: var(--ink); font-size: 1.5rem; line-height: 1.1; white-space: nowrap; }
.control-field small { color: var(--muted); font-size: 1rem; font-weight: 400; }
input[type="range"] { display: block; width: 100%; height: 24px; margin: 0; appearance: none; -webkit-appearance: none; background: none; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 5px; border-radius: 6px; background: linear-gradient(to right, var(--water) var(--fill, 50%), #3c566b var(--fill, 50%)); }
input[type="range"]::-webkit-slider-thumb { width: 19px; height: 19px; margin-top: -7px; appearance: none; -webkit-appearance: none; border: 4px solid var(--water); border-radius: 50%; background: var(--ink); }
input[type="range"]::-moz-range-track { height: 5px; border-radius: 6px; background: linear-gradient(to right, var(--water) var(--fill, 50%), #3c566b var(--fill, 50%)); }
input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border: 4px solid var(--water); border-radius: 50%; background: var(--ink); }
.surge-button { display: flex; align-items: center; gap: 8px; min-height: 44px; margin-top: 3px; padding: 8px 10px; border: 1px solid #78664e; border-radius: 7px; background: #423c34; color: var(--gold); font-size: 1rem; }
.surge-amount { margin-left: auto; white-space: nowrap; }
.surge-button:hover { background: #554737; }
.feedback-message { color: var(--muted); font-size: 1rem; line-height: 1.5; overflow-wrap: anywhere; }
.feedback-message.fault { color: var(--warning); }
.playback { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-top: auto; padding-top: 12px; }
.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; min-height: 44px; padding: 8px 10px; border-radius: 7px; font-size: 1rem; line-height: 1.4; white-space: nowrap; }
.primary-button { grid-column: 1 / -1; border: 1px solid #d2efeb; background: #d2efeb; color: #153847; font-weight: 600; }
.primary-button:hover { background: #edfafa; border-color: #edfafa; }
.primary-button svg { width: 17px; stroke-width: 2.3; }
.secondary-button { border: 1px solid #426176; background: #17364b; color: #dce8ed; }
.secondary-button:hover { background: #24495f; border-color: #6f8d9f; }

.analysis-row { min-width: 0; margin: 26px 0 30px; }
.chart-panel { min-width: 0; }
.chart-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.chart-heading h2 { margin: 0; font-size: 1.25rem; line-height: 1.3; font-weight: 600; }
.chart-actions { display: flex; align-items: center; gap: 26px; }
.comparison-toggle { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; font-size: 1rem; white-space: nowrap; }
input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--violet); cursor: pointer; }
.chart-legend { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 22px; margin: 0 0 8px; color: var(--muted); font-size: 1rem; }
.chart-legend > span { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.legend { display: inline-block; width: 20px; height: 0; flex: 0 0 20px; border-top: 2px solid; vertical-align: middle; }
.legend.auto { color: var(--water); }
.legend.onoff { color: var(--violet); }
.legend.manual { color: var(--manual); }
.legend.target { color: var(--gold); border-top-style: dashed; }
#chart { display: block; width: 100%; height: 190px; }
.comparison-results { margin-top: 18px; }
table { width: 100%; table-layout: fixed; border-collapse: collapse; color: var(--ink); font-size: 1rem; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); line-height: 1.5; }
thead th { color: var(--muted); font-weight: 400; }
th:first-child { width: 30%; text-align: left; }
tbody th { font-weight: 400; }
tbody th .legend { margin-right: 10px; }
thead th span { margin-left: 4px; white-space: nowrap; }
td { white-space: nowrap; }

.scenario-toolbar { display: flex; align-items: center; gap: 20px; margin-bottom: 16px; }
.scenario-toolbar > .secondary-button { flex-shrink: 0; }
.experiment-toolbar { padding-top: 18px; margin-top: 20px; border-top: 1px solid var(--line); }
.scenario-field { display: flex; align-items: center; gap: 12px; min-width: 0; }
.scenario-toolbar .scenario-field { flex: 0 1 280px; }
.scenario-field label { flex: 0 0 auto; }
.scenario-field select { flex: 1; width: 0; }
.experiment-details { min-width: 0; }
.experiment-details summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: fit-content; min-height: 44px; color: var(--muted); cursor: pointer; list-style: none; }
.experiment-details summary::-webkit-details-marker { display: none; }
.experiment-details summary:hover { color: var(--ink); }
.experiment-details[open] summary { width: fit-content; color: var(--ink); }
.experiment-details[open] summary svg { transform: rotate(180deg); }
.experiment-content { padding: 20px 0 4px; }
.experiment-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px; }
.experiment-grid .control-field label { min-height: 30px; }
.experiment-grid input[type="range"] { height: 32px; }
.fault-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 36px; padding-top: 16px; margin-top: 16px; border-top: 1px solid var(--line); }
.fault-control { display: flex; align-items: center; gap: 16px; }
.switch { position: relative; width: 52px; height: 44px; padding: 0; flex: 0 0 52px; border: 0; background: none; }
.switch::before { content: ""; position: absolute; top: 9px; left: 0; width: 52px; height: 26px; border-radius: 26px; background: #456275; }
.switch span { position: absolute; top: 13px; left: 4px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink); transition: transform .18s; }
.switch[aria-checked="true"]::before { background: #ad724d; }
.switch[aria-checked="true"] span { transform: translateX(26px); }
.fault-status { margin: 0; color: var(--warning); font-size: 1rem; line-height: 1.5; }
.toast { position: fixed; z-index: 100; bottom: 24px; left: 50%; max-width: calc(100vw - 32px); padding: 12px 20px; border-radius: 8px; background: #d2efeb; color: #153847; font-size: 1rem; line-height: 1.5; transform: translateX(-50%); }
.noscript { padding: 20px; background: var(--gold); color: var(--bg); text-align: center; }

@media (min-width: 1600px) {
  .scene-panel { min-height: 460px; }
  .water-readout strong { font-size: 4rem; }
}

@media (max-width: 1100px) {
  .shell { padding: 0 3vw; }
  .workspace { grid-template-columns: minmax(0, 1fr) 280px; }
  .control-panel { padding-right: 18px; padding-left: 18px; }
  .scene-top { left: 22px; right: 22px; }
  .water-readout, .flow-readouts { left: 22px; }
  .flow-readouts { gap: 22px; }
  .selection-detail { left: 22px; right: 22px; max-width: calc(100% - 44px); }
}

@media (max-width: 800px) {
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "scene" "circuit" "controls"; }
  .scene-panel { min-height: 360px; border-radius: 15px 15px 0 0; }
  #circuit { border-radius: 0; }
  .control-panel { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; gap: 20px 28px; padding: 20px 22px; border-left: 0; border-top: 1px solid var(--line); border-radius: 0 0 15px 15px; }
  .panel-heading { grid-column: 1 / -1; margin: 0; }
  .panel-heading select { flex: 0 1 280px; width: 100%; }
  .panel-heading .text-button { margin-left: auto; }
  .surge-button { align-self: end; margin-top: 0; }
  #manualControl { grid-column: 1 / -1; }
  .feedback-message { grid-column: 1 / -1; }
  .playback { grid-column: 1 / -1; grid-template-columns: repeat(3, minmax(0, 1fr)); padding-top: 0; }
  .primary-button { grid-column: auto; }
  .experiment-details summary { width: fit-content; }
  .experiment-grid { grid-template-columns: minmax(0, 1fr); gap: 18px; }
}

@media (max-width: 480px) {
  .shell { padding: 0 14px; }
  .masthead { height: 62px; }
  .brand { gap: 7px; font-size: 1.3rem; }
  .brand svg { width: 34px; height: 34px; }
  .page-heading { min-height: 70px; padding: 18px 0; gap: 10px; }
  .page-heading h1 { font-size: 1.65rem; }
  .run-status { gap: 6px; font-size: 1rem; }
  .workspace { border-radius: 12px; }
  .scene-panel { min-height: 300px; border-radius: 11px 11px 0 0; }
  .scene-top { top: 12px; left: 16px; right: 16px; gap: 10px; }
  .water-readout { top: 39px; left: 16px; }
  .water-readout strong { font-size: 2.75rem; }
  .water-readout .unit { margin-left: 6px; font-size: 1rem; }
  .flow-readouts { bottom: 12px; left: 16px; right: 16px; justify-content: space-between; gap: 10px; }
  .flow-readouts strong { font-size: 1.25rem; }
  .selection-detail { left: 12px; right: 12px; bottom: 72px; max-width: calc(100% - 24px); }
  .control-panel { display: flex; align-items: stretch; gap: 16px; padding: 18px 16px 20px; border-radius: 0 0 11px 11px; }
  .panel-heading select { flex: 1; width: 0; }
  .control-field label { min-height: 30px; }
  input[type="range"] { height: 30px; }
  .playback { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); width: 100%; }
  .primary-button { grid-column: 1 / -1; }
  .analysis-row { margin: 22px 0 24px; }
  .chart-heading { align-items: flex-start; flex-wrap: wrap; gap: 4px 12px; }
  .chart-heading h2 { min-height: 44px; display: flex; align-items: center; }
  .chart-actions { flex: 1 1 auto; justify-content: space-between; gap: 16px; }
  .chart-legend { justify-content: flex-start; gap: 7px 16px; margin: 6px 0 12px; }
  .legend { width: 17px; flex-basis: 17px; }
  #chart { height: 210px; }
  th, td { padding: 9px 4px; }
  th:first-child { width: 28%; }
  thead th span { display: block; margin-left: 0; }
  tbody th .legend { display: none; }
  .experiment-toolbar { margin-top: 16px; padding-top: 16px; }
  .scenario-toolbar { gap: 10px; margin-bottom: 14px; }
  .scenario-toolbar .scenario-field { flex: 1; }
  .scenario-field { gap: 8px; }
  .scenario-field select { padding-left: 9px; padding-right: 26px; }
  .scenario-toolbar > .secondary-button { padding-right: 8px; padding-left: 8px; }
  .fault-controls { display: grid; gap: 8px; }
  .fault-control { justify-content: space-between; }
}

@media (max-width: 360px) {
  .shell { padding: 0 10px; }
  .page-heading { gap: 7px; }
  .page-heading h1 { font-size: 1.5rem; }
  .run-status { max-width: 7em; }
  .control-panel { padding-right: 14px; padding-left: 14px; }
  .scene-top { left: 14px; right: 14px; }
  .water-readout { left: 14px; }
  .flow-readouts { left: 14px; right: 14px; gap: 7px; }
  .scenario-field select { min-height: 44px; }
}

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