:root {
  --bg: rgba(250, 249, 246, 0.92);
  --fg: #1f2421;
  --muted: #5f6b64;
  --line: rgba(31, 36, 33, 0.14);
  --accent: #5b7a5e;
  --accent-fg: #fff;
  --ok: #2f7d4f;
  --warn: #a86b00;
  --bad: #b3261e;
  --water: #2b7bd6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: rgba(24, 27, 25, 0.9);
    --fg: #e8ebe8;
    --muted: #a3ada6;
    --line: rgba(232, 235, 232, 0.16);
    --accent: #8fb592;
    --accent-fg: #102012;
    --ok: #6fcf97;
    --warn: #f2c94c;
    --bad: #ff8a80;
    --water: #6fb2ff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b1e1c; color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.panel { position: fixed; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 4px 18px rgba(0,0,0,.18); }
#top { top: max(10px, env(safe-area-inset-top)); left: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px;
  max-width: calc(100vw - 20px); }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.brand { margin-right: 4px; }
button, select { font: inherit; color: var(--fg); background: transparent; border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 10px; cursor: pointer; min-height: 32px; }
button:hover, select:hover { border-color: var(--accent); }
button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.sm { padding: 3px 8px; min-height: 28px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 7px 0 0 7px; }
.seg button:last-child { border-radius: 0 7px 7px 0; border-left: 0; }
select { background: var(--bg); }
.time input[type=range] { width: 150px; accent-color: var(--accent); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; min-width: 42px; }

#sim { top: 10px; right: 10px; width: 340px; max-height: calc(100vh - 20px); overflow: auto; padding: 10px 12px; }
.simhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sec { border-top: 1px solid var(--line); padding: 7px 0; }
.lbl { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.lbl2 { font-size: 12px; font-weight: 600; margin-top: 6px; }
.btns { display: flex; flex-wrap: wrap; gap: 4px; }
.btns button { padding: 3px 8px; min-height: 28px; font-size: 13px; }
.btns.valves button { min-width: 42px; padding: 3px 4px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.btns.valves button.closed { border-color: var(--bad); color: var(--bad); }
.btns.valves button.open { border-color: var(--ok); color: var(--ok); }
#steps { margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
#readout { display: grid; grid-template-columns: auto auto; gap: 2px 10px; margin: 8px 0; font-size: 13px; }
#readout dt { color: var(--muted); }
#readout dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.msg { font-size: 13px; padding: 5px 8px; border-radius: 6px; margin-top: 4px; border-left: 3px solid var(--ok); background: rgba(127,127,127,.08); }
.msg.warn { border-color: var(--warn); }
.msg.bad { border-color: var(--bad); }

#cross { position: fixed; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; pointer-events: none; }
#cross::before, #cross::after { content: ""; position: absolute; background: #fff; box-shadow: 0 0 2px #000; }
#cross::before { left: 6px; top: 0; width: 2px; height: 14px; }
#cross::after { top: 6px; left: 0; width: 14px; height: 2px; }
#label { position: fixed; pointer-events: none; background: rgba(0,0,0,.72); color: #fff; padding: 4px 9px; border-radius: 6px;
  font-size: 13px; transform: translate(-50%, 18px); white-space: nowrap; }
#hint { position: fixed; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); pointer-events: none;
  background: rgba(0,0,0,.55); color: #fff; padding: 5px 12px; border-radius: 16px; font-size: 13px; max-width: calc(100vw - 20px); text-align: center; }
#joy { position: fixed; left: 24px; bottom: 34px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.35); touch-action: none; }
#joyKnob { position: absolute; left: 40px; top: 40px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.55); }

#loading { position: fixed; inset: 0; display: grid; place-items: center; background: #1b1e1c; z-index: 10; color: #e8ebe8; }
.lbox { width: min(320px, 80vw); }
.ltitle { font-size: 18px; font-weight: 600; margin-bottom: 10px; }
.lbar { height: 6px; background: rgba(255,255,255,.12); border-radius: 3px; overflow: hidden; }
#lfill { height: 100%; width: 0; background: #8fb592; transition: width .2s; }
#ltext { margin-top: 8px; font-size: 13px; color: #a3ada6; }

#menuBtn { display: none; }
@media (max-width: 700px) {
  #menuBtn { display: inline-block; margin-left: auto; }
  #top { right: 10px; }
  #top:not(.open) .row:not(:first-child) { display: none; }
  #goto { max-width: 130px; }
  #sim { top: auto; bottom: 0; right: 0; left: 0; width: auto; max-height: 52vh; border-radius: 12px 12px 0 0; }
  .time input[type=range] { width: 110px; }
}

#dbg { position: fixed; left: 8px; right: 8px; bottom: 70px; max-height: 40vh; overflow: auto; margin: 0; z-index: 20;
  background: rgba(20,0,0,.85); color: #ffd7d2; font: 11px/1.35 ui-monospace, Consolas, monospace; padding: 8px; border-radius: 8px;
  white-space: pre-wrap; word-break: break-word; }
#dbg.info { background: rgba(0,0,0,.75); color: #dfe; }

#hudBtn { position: fixed; z-index: 5; top: max(10px, env(safe-area-inset-top)); right: 10px; min-height: 30px; padding: 3px 9px;
  font-size: 12px; background: rgba(20,22,21,.55); color: #fff; border-color: rgba(255,255,255,.25); }
#hudBtn[aria-pressed="false"] { opacity: .45; }
body.nohud #top, body.nohud #sim, body.nohud #hint, body.nohud #dbg, body.nohud #label { display: none !important; }
@media (max-width: 700px) { #top { right: 64px; } }
@media (min-width: 701px) { #sim { top: 50px; } }
