:root {
  --bg: #eef3f7;
  --card: #ffffff;
  --text: #1f2d3a;
  --muted: #5b6b78;
  --line: #dbe3ea;
  --volume: #2f7fd8;
  --inflow: #1f9d6b;
  --outflow: #e07a2e;
  --danger: #d64545;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

h1, h2 { margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 32px;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 0;
}
.brand p { margin: 2px 0 0; color: var(--muted); max-width: 440px; }

.stats { display: flex; flex-wrap: wrap; gap: 10px; }
.stat {
  background: var(--card);
  border-radius: 10px;
  padding: 8px 14px;
  min-width: 104px;
  box-shadow: 0 1px 2px rgba(20, 40, 60, 0.08);
}
.stat .label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat .value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .value.in { color: var(--inflow); }
.stat .value.out { color: var(--outflow); }
.meter { height: 4px; border-radius: 2px; background: var(--line); margin-top: 4px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--volume); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  padding: 16px 20px 20px;
}
.left, .right { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(20, 40, 60, 0.08);
}

.scene-card { position: relative; padding: 0; overflow: hidden; }
#scene { display: block; width: 100%; aspect-ratio: 900 / 470; }
.status {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(20, 40, 60, 0.12);
}
.status.warn { background: var(--danger); color: #fff; }

.chart-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; list-style: none; margin: 0; padding: 0; color: var(--muted); font-size: 12px; }
.swatch { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.swatch.volume { background: var(--volume); height: 8px; opacity: 0.6; }
.swatch.inflow { background: var(--inflow); }
.swatch.outflow { background: var(--outflow); }
#chart { display: block; width: 100%; height: 170px; }

.valve-head { display: flex; align-items: center; justify-content: space-between; }
.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--line);
  color: var(--muted);
}
#tap-card .badge.open { background: #d8f1e6; color: var(--inflow); }
#drain-card .badge.open { background: #fbe6d6; color: var(--outflow); }

.readout { display: flex; align-items: baseline; gap: 4px; margin: 12px 0 6px; }
.readout .big { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.readout .of { color: var(--muted); }
.readout .rate { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

input[type="range"] { width: 100%; margin: 6px 0 12px; }
#tap-slider { accent-color: var(--inflow); }
#drain-slider { accent-color: var(--outflow); }

.buttons { display: grid; grid-template-columns: 1fr 44px 44px 1fr; gap: 8px; }
.buttons.two { grid-template-columns: 1fr 1fr; margin-top: 12px; }

button {
  font: inherit;
  font-weight: 600;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f9fb;
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled) { background: #eaf1f6; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible { outline: 2px solid var(--volume); outline-offset: 2px; }

.pending { margin: 10px 0 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pending.active { color: var(--text); font-weight: 600; }
.delay { display: block; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.delay-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.delay-head span { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.delay input[type="range"] { margin: 6px 0 0; accent-color: var(--muted); }
#sim-capacity { accent-color: var(--volume); }

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

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