.pipeline-fluid-readout i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 14px var(--cyan);
  animation: pipeline-live 1.15s ease-in-out infinite alternate;
}

.pipeline-lab__body {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 500px;
}

.pipeline-controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: var(--bg-sunk);
}

.pipeline-control {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  border: 0;
}

.pipeline-control > label,
.pipeline-control > legend {
  width: 100%;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.pipeline-control__value {
  float: right;
  color: var(--accent-strong);
  font: 600 11px/1.6 var(--mono);
}

.pipeline-control select {
  width: 100%;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--bg-panel);
  color: var(--fg-strong);
}

.pipeline-control input[type="range"] {
  width: 100%;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
}

.pipeline-check {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--bg-panel);
  color: var(--fg);
  font-size: 12px;
}

.pipeline-check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.pipeline-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 7px;
  margin-top: auto;
}

.pipeline-actions button {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--bg-panel);
  color: var(--fg);
  font-size: 11px;
  font-weight: 600;
}

.pipeline-actions button:hover,
.pipeline-actions button:focus-visible {
  border-color: var(--accent);
  color: var(--accent-strong);
  outline: 0;
}

.pipeline-actions button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.pipeline-actions button:disabled {
  opacity: .45;
  cursor: default;
}

.pipeline-actions--inline { margin-top: 0; }

/* 揚程ラボで置いたポンプの一覧。行ごとに種別・設置高さ・外すボタンを持つ。 */
.pipeline-pumps {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pipeline-pumps[hidden] { display: none; }

.pipeline-pump {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px 6px 10px;
  border: 1px solid var(--line);
  background: var(--bg-panel);
}

.pipeline-pump__name {
  color: var(--muted);
  font: 600 11px/1.4 var(--mono);
  white-space: nowrap;
}

.pipeline-pump__height { display: block; min-width: 0; }

.pipeline-pump__height input {
  width: 100%;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

.pipeline-pump__value {
  min-width: 44px;
  color: var(--accent-strong);
  font: 600 11px/1.4 var(--mono);
  text-align: right;
}

.pipeline-pump__remove {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--bg-sunk);
  color: var(--muted);
  font: 700 13px/1 var(--mono);
}

.pipeline-pump__remove:hover,
.pipeline-pump__remove:focus-visible {
  border-color: var(--danger);
  color: var(--danger);
  outline: 0;
}

.pipeline-stage {
  min-width: 0;
  padding: clamp(18px, 3vw, 30px);
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    var(--bg-raised);
  background-size: 24px 24px;
}

.pipeline-visual {
  position: relative;
  min-height: 310px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-sunk));
}

.pipeline-visual svg {
  display: block;
  width: 100%;
  height: auto;
}

.pipeline-fluid-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 16px;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--bg-sunk);
  color: var(--muted);
  font: 500 10px/1.45 var(--mono);
}

.pipeline-fluid-readout span:first-child {
  color: var(--fg-strong);
  font-weight: 700;
}

.pipeline-fluid-readout code {
  margin-left: auto;
  color: var(--accent-strong);
  font-size: 10px;
}

.pipeline-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.pipeline-metric {
  min-width: 0;
  padding: 12px 13px;
  border: 1px solid var(--line);
  background: var(--bg-sunk);
}

.pipeline-metric span {
  display: block;
  color: var(--faint);
  font: 500 9px/1.4 var(--mono);
  letter-spacing: .07em;
}

.pipeline-metric strong {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 4px;
  color: var(--fg-strong);
  font: 600 clamp(13px, 2vw, 18px)/1.35 var(--mono);
}

.pipeline-status {
  min-height: 62px;
  margin: 10px 0 0;
  padding: 11px 14px 11px 17px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  background: var(--bg-panel);
  color: var(--muted);
  font-size: 12px;
}

.pipeline-status[data-tone="success"] { border-left-color: var(--cyan); }
.pipeline-status[data-tone="warning"] { border-left-color: var(--accent); }
.pipeline-status[data-tone="danger"] { border-left-color: var(--danger); }

.pipeline-graph {
  margin-top: 10px;
  padding: 8px 10px 10px;
  border: 1px solid var(--line);
  background: var(--bg-sunk);
}

.pipeline-graph__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 6px;
  color: var(--faint);
  font: 500 9px/1.4 var(--mono);
}

.pipeline-graph__legend span::before {
  display: inline-block;
  width: 16px;
  height: 2px;
  margin: 0 5px 2px 0;
  background: currentColor;
  content: "";
}

.pipeline-graph__legend .is-input { color: var(--accent-strong); }
.pipeline-graph__legend .is-output { color: var(--cyan); }
.pipeline-graph svg { display: block; width: 100%; height: 118px; }
.pipeline-graph-grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.pipeline-graph-line { fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.pipeline-graph-line--input { stroke: var(--accent-strong); }
.pipeline-graph-line--output { stroke: var(--cyan); }

/* --- ステージ共通部品（配管ラボの SVG） -----------------------------
   画面は常に暗い計器盤として描く。テーマ変数は使わず固定色の線画にする。 */
.stage-bg { fill: #0a1219; }
.stage-dot { fill: #9bb5bd; fill-opacity: .12; }
.stage-unit-body { fill: #111c25; stroke: #5b727d; stroke-width: 1.5; }
.stage-port { fill: #3a4f5a; }
.stage-screen { fill: #070e13; stroke: #23343e; stroke-width: 1; }
.stage-wave { fill: none; stroke: #57e0cf; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.stage-glyph { fill: none; stroke: #7f949d; stroke-width: 1.5; stroke-linecap: round; }
.stage-glyph-fill { fill: #57e0cf; }
.stage-label { fill: #7f949d; font: 600 10px var(--mono); letter-spacing: .14em; }
.gauge-arc { fill: none; stroke: #3f545f; stroke-width: 3; stroke-linecap: round; }
.gauge-ticks { fill: none; stroke: #7f949d; stroke-width: 1.5; stroke-linecap: round; }
.gauge-needle { fill: none; stroke: #ffa736; stroke-width: 2.5; stroke-linecap: round; transition: transform .18s ease-out; }
.gauge-hub { fill: #ffa736; }
.simulation-floor { fill: none; stroke: #2b3d48; stroke-width: 1.5; }

/* 配管は「壁 → 内側 → 流体 → 流れの粒」の 4 層。流れの粒は生産プランナーの搬送線と同じ表現。 */
.pipe-wall { fill: none; stroke: #3a4f5a; stroke-width: 16; stroke-linecap: round; stroke-linejoin: round; }
.pipe-bore { fill: none; stroke: #0c151c; stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; }
.pipe-fluid { fill: none; stroke: #57e0cf; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.pipe-pulse { fill: none; stroke: #eafffc; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 5 27; --dash-cycle: -32; animation: pipeline-water .9s linear infinite; filter: drop-shadow(0 0 3px #eafffc); }
.pipe-pulse[data-reaches="false"] { display: none; }
.pipe-wall--thin { stroke-width: 12; }
.pipe-bore--thin { stroke-width: 8; }
.pipe-fluid--thin { stroke-width: 4.5; }
.pipe-pulse--thin { stroke-width: 2.5; stroke-dasharray: 4 20; --dash-cycle: -24; }

.pipeline-caption path { fill: none; stroke: #2f424c; stroke-width: 1; }
.pipeline-caption text { fill: #7f949d; font: 600 10px var(--mono); letter-spacing: .06em; }

/* --- 01 fluid box の列 --------------------------------------------- */
.pipe-box-shell { fill: #111c25; stroke: #5b727d; stroke-width: 1.5; }
.pipe-box-inner { fill: #0c151c; stroke: #23343e; stroke-width: 1; }
.pipe-box-level { fill: #2fc9bb; opacity: .85; }
.pipe-box-overfill { fill: #ffa736; opacity: 0; }
.pipe-box-overfill[data-active="true"] { opacity: .9; }
.pipe-box-label { fill: #9fb3ba; font: 600 11px var(--mono); }
.pipe-box-coupling { fill: #22323c; stroke: #5b727d; stroke-width: 1.5; }
.pipe-box-arrow { fill: #57e0cf; }
.pipe-box-arrow[data-direction="reverse"] { fill: #ff6b62; }
.pipe-box-flow { fill: #57e0cf; font: 700 11px var(--mono); }
.pipe-box-flow[data-direction="reverse"] { fill: #ff6b62; }

/* --- 02 揚程の縦断面 ----------------------------------------------- */
.head-ruler-axis,
.head-ruler-tick { fill: none; stroke: #4c626d; stroke-width: 1.5; }
.head-ruler-label { fill: #7f949d; font: 600 10px var(--mono); }
.head-ruler-title { fill: #5f7580; font: 700 9px var(--mono); letter-spacing: .16em; }
.head-ground-band { pointer-events: none; }
.head-ground-line { fill: none; stroke: #4c626d; stroke-width: 1.5; }
.head-source-body,
.head-target-body { fill: #111c25; stroke: #5b727d; stroke-width: 1.5; }
.head-pump-body { fill: #111c25; stroke: #8fa4ad; stroke-width: 1.5; }
.head-pipe-liquid { fill: none; stroke: #57e0cf; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.head-pipe-liquid[data-reaches="false"] { opacity: .55; }
.pipe-pulse[data-filling="true"] { display: none; }
.head-pump-hub { fill: #ffa736; stroke: #ffe3ae; stroke-width: 1; }
.head-pump-label { fill: #cbd9dd; font: 700 10px var(--mono); }
.head-pump-body[data-dry="true"] { stroke-dasharray: 4 3; opacity: .55; }
.head-pump-hub[data-dry="true"] { fill: #4c626d; stroke: none; }
.head-pump-label[data-dry="true"] { fill: #7f949d; }
.head-liquid-label { fill: #cbd9dd; font: 700 10px var(--mono); }
.head-line { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.head-line--design { stroke: #57e0cf; stroke-dasharray: 8 6; }
.head-line--max { stroke: #ffa736; stroke-dasharray: 3 7; }
.head-line-label { font: 700 11px var(--mono); }
.head-line-label--design { fill: #57e0cf; }
.head-line-label--max { fill: #ffa736; }
.head-target-port { fill: #0c151c; stroke: #57e0cf; stroke-width: 2.5; }
.head-target-port[data-reaches="false"] { stroke: #ff6b62; }
.head-legend rect { fill: #0a1219; fill-opacity: .9; stroke: #3f545f; stroke-width: 1; }
.head-legend text { fill: #8fa4ad; font: 600 10px var(--mono); }
.head-legend .is-design { fill: #57e0cf; }
.head-legend .is-max { fill: #ffa736; }

/* --- 03 マニホールド ------------------------------------------------ */
.manifold-supply { fill: #111c25; stroke: #5b727d; stroke-width: 1.5; }
.manifold-endcap { fill: #3a4f5a; stroke: #5b727d; stroke-width: 1.5; }
.manifold-trunk-fluid { opacity: .3; }
.manifold-riser-flow[data-starved="true"] .pipe-fluid { stroke: #ffa736; }
.manifold-junction { fill: #111c25; stroke: #5b727d; stroke-width: 1.5; }
.manifold-junction-inner { fill: #57e0cf; }
.manifold-machine { fill: #111c25; stroke: #5b727d; stroke-width: 1.5; }
.manifold-machine-value { fill: #f2f7f8; font: 700 12px var(--mono); }
.manifold-arrow { fill: #57e0cf; }
.manifold-arrow[data-direction="reverse"] { fill: #ff6b62; }
.manifold-segment-value { fill: #57e0cf; font: 700 11px var(--mono); }
.manifold-segment-value[data-direction="reverse"] { fill: #ff6b62; }

/* --- 04 液体タンク -------------------------------------------------- */
.tank-shell { fill: #111c25; stroke: #8fa4ad; stroke-width: 2; }
.tank-glass { fill: #0c151c; stroke: #23343e; stroke-width: 1; }
.tank-level { fill: #2fc9bb; opacity: .85; }
.tank-tick { fill: none; stroke: #3f545f; stroke-width: 1.5; }
.tank-leg { fill: none; stroke: #5b727d; stroke-linecap: round; stroke-linejoin: round; stroke-width: 3; }
.tank-level-label { fill: #f2f7f8; font: 700 22px var(--mono); }
.tank-head-scale path { fill: none; stroke: #4c626d; stroke-width: 1.5; }
.tank-head-scale text { fill: #8fa4ad; font: 600 10px var(--mono); }
.tank-head-fill { fill: #57e0cf; opacity: .8; }
.tank-head-scale[data-empty="true"] { opacity: .3; }

/* --- 停止中はアニメーションを止める -------------------------------- */
.pipeline-lab[data-motion="paused"] .pipe-pulse,
.pipeline-lab[data-motion="paused"] .pipeline-fluid-readout i {
  animation-play-state: paused;
}

@keyframes pipeline-flow {
  to { stroke-dashoffset: -48; }
}

/* 1 周で進める距離は各要素の破線周期（dasharray の合計）の整数倍にする。
   周期と合わない距離だと、ループの継ぎ目で破線が毎回飛んで見える。 */
@keyframes pipeline-water {
  to { stroke-dashoffset: var(--dash-cycle, -54); }
}

@keyframes pipeline-live {
  from { opacity: .45; transform: scale(.72); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 1000px) {
  .pipeline-lab__body { grid-template-columns: 260px minmax(0, 1fr); }
  .pipeline-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 780px) {
  .pipeline-lab__body { grid-template-columns: 1fr; }
  .pipeline-controls { border-right: 0; border-bottom: 1px solid var(--line); }
  .pipeline-actions { margin-top: 5px; }
  /* 幅に合わせて縮めると区間の数字が読めなくなるので、横スクロールで原寸に近い大きさを保つ。 */
  .pipeline-visual { overflow-x: auto; overflow-y: hidden; }
  .pipeline-visual svg { min-width: 640px; }
}

@media (max-width: 520px) {
  .pipeline-controls,
  .pipeline-stage { padding: 15px; }
  .pipeline-visual { min-height: 0; }
  .pipeline-metrics { grid-template-columns: 1fr 1fr; }
  .pipeline-metric { padding: 10px; }
  .pipeline-status { min-height: 0; }
  .pipeline-fluid-readout code { width: 100%; margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .pipeline-fluid-readout i { animation: none; }
  .pipe-pulse { animation: none; }
}
