:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --card: #232d3a;
  --border: #344050;
  --text: #e8eef4;
  --muted: #8b9aab;
  --fuel: #f97316;
  --dirty: #1c1917;
  --purple: #c026d3;
  --helium: #7dd3fc;
  --water: #3b82f6;
  --steam: #d6b48a;
  --gfp: #22c55e;
  --pump: #fbbf24;
  --hebtn: #22d3ee;
  --open: #00e000;
  --closed: #ff6b6b;
  --accent: #3b82f6;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
}

.app {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

#btn-reset {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

#btn-reset:hover {
  background: #2c3848;
  border-color: var(--accent);
}

.main {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.25rem;
  align-items: start;
}

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

.canvas-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  overflow: auto;
  max-height: calc(100vh - 120px);
}

#game {
  display: block;
  width: 100%;
  max-width: 1100px;
  height: auto;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 8px;
  cursor: default;
  touch-action: none;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

.hint {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}
.hint .pump { color: var(--pump); font-weight: 600; }
.hint .he { color: var(--hebtn); font-weight: 600; }
.hint .gfp { color: var(--gfp); font-weight: 600; }

.panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: calc(100vh - 120px);
  overflow: auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}

.earn-sub {
  margin: 0.85rem 0 0.35rem;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted, #94a3b8);
}
.earn-sub:first-of-type {
  margin-top: 0.25rem;
}
.card h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

/* Compact typical sequence */
.card.ops.compact {
  padding: 0.65rem 0.85rem;
}
.card.ops.compact h2 {
  margin-bottom: 0.4rem;
}
.seq-tight {
  margin: 0;
  padding-left: 1.15rem;
  font-size: 0.8rem;
  line-height: 1.35;
}
.seq-tight li {
  margin-bottom: 0.28rem;
}
.seq-tight li:last-child {
  margin-bottom: 0;
}

/* Week number + 7-day progress on one row */
.week-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.45rem;
  margin-bottom: 0.15rem;
}
.week-label {
  flex: 0 0 auto;
  font-size: 0.85rem;
  white-space: nowrap;
}
.week-days {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  min-width: 0;
  height: 14px;
}
.day-seg {
  border-radius: 3px;
  background: #0d1218;
  border: 1px solid var(--border, #2a3544);
  transition: background 0.12s linear;
}
.day-seg.filled {
  background: linear-gradient(180deg, #38bdf8, #0284c7);
  border-color: #0369a1;
}
.day-seg.partial {
  background: linear-gradient(180deg, #7dd3fc, #0ea5e9);
  border-color: #0284c7;
  opacity: 0.85;
}
.week-days.paused {
  opacity: 0.45;
}
.week-days.paused .day-seg.filled,
.week-days.paused .day-seg.partial {
  filter: grayscale(0.35);
}

.auto-sell-row {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin-top: 0.65rem;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
  line-height: 1.35;
  cursor: pointer;
  user-select: none;
}
.auto-sell-row input[type="checkbox"] {
  margin-top: 0.2rem;
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--gfp, #22c55e);
  flex-shrink: 0;
  cursor: pointer;
}
.auto-sell-row.visitors-locked {
  opacity: 0.45;
  cursor: not-allowed;
}
.auto-sell-row.visitors-locked input[type="checkbox"] {
  cursor: not-allowed;
}
.visitor-pass-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.35rem;
  flex-wrap: wrap;
}
.visitor-pass-label {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted, #94a3b8);
  min-width: 4.2rem;
}
.visitor-pass-input {
  flex: 1 1 7rem;
  min-width: 6rem;
  max-width: 11rem;
  background: #0d1218;
  border: 1px solid var(--border, #2a3544);
  border-radius: 6px;
  color: var(--text, #e2e8f0);
  font: inherit;
  font-size: 0.82rem;
  padding: 0.35rem 0.5rem;
}
.visitor-pass-input:focus {
  outline: none;
  border-color: #a855f7;
}
.visitor-pass-btn {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #475569;
  border-radius: 6px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
}
.visitor-pass-btn:hover {
  border-color: #a855f7;
  color: #f3e8ff;
}
.visitor-pass-status {
  margin-top: 0.25rem;
  min-height: 1.1em;
}
.visitor-pass-status.ok {
  color: #4ade80;
}
.visitor-pass-status.bad {
  color: #f87171;
}
.visitor-pass-row.is-unlocked {
  display: none;
}

.inv-row {
  display: grid;
  grid-template-columns: 64px 1fr 44px;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}

.tag {
  font-size: 0.72rem;
  font-weight: 650;
}
.tag.loop { color: #fb923c; }
.tag.hold { color: #fde68a; }
.tag.drain { color: #e879f9; }
.tag.gfp { color: var(--gfp); }

.bar {
  height: 10px;
  background: #0d1218;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 5px;
  transition: width 0.12s linear;
}
.bar-fill.fuel { background: linear-gradient(90deg, #ea580c, var(--fuel)); }
.bar-fill.gfp { background: linear-gradient(90deg, #16a34a, var(--gfp)); }

.pct {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.total { margin-top: 0.5rem; font-size: 0.85rem; }
.muted { color: var(--muted); }
.small { font-size: 0.78rem; margin-bottom: 0.5rem; line-height: 1.4; }

.slider-row {
  display: grid;
  grid-template-columns: 72px 1fr 52px;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.65rem;
  font-size: 0.82rem;
}
.slider-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.slider-row .val {
  font-size: 0.75rem;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.valve-list { list-style: none; }
.valve-list li {
  display: grid;
  grid-template-columns: 1fr 1.15fr auto;
  gap: 0.35rem;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.valve-list li:last-child { border-bottom: none; }
.valve-list .vname { font-weight: 650; }
.valve-list .vpath { color: var(--muted); font-size: 0.72rem; }
.vstate {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  text-align: center;
  min-width: 52px;
}
.vstate.open { background: rgba(0, 224, 0, 0.15); color: var(--open); }
.vstate.closed { background: rgba(255, 0, 0, 0.12); color: var(--closed); }
.vstate.he-on { background: rgba(34, 211, 238, 0.18); color: var(--hebtn); }
.vstate.pump-on { background: rgba(251, 191, 36, 0.22); color: var(--pump); }
.pump-row .vname { color: var(--pump); }
.he-row .vname { color: var(--hebtn); }

.status { font-size: 0.88rem; line-height: 1.45; min-height: 2.8em; }

.legend {
  list-style: none;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.15);
}
.swatch.fuel { background: var(--fuel); }
.swatch.dirty { background: repeating-linear-gradient(90deg, #f97316 0 4px, #1c1917 4px 8px); }
.swatch.purple { background: var(--purple); }
.swatch.helium { background: var(--helium); }
.swatch.water { background: var(--water); }
.swatch.steam { background: var(--steam); }

.ops ol {
  padding-left: 1.15rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.ops li { margin-bottom: 0.45rem; }
.ops strong { color: var(--text); }

/* ── Status / toast / shortcuts / visitor demo (v2.9.021) ─ */
#btn-keys {
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  min-width: 2.4rem;
}
#btn-keys:hover {
  color: var(--text);
  border-color: var(--accent);
}

.plant-status {
  margin: 0.55rem 0 0.15rem;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  color: #cbd5e1;
  min-height: 1.25em;
}
.plant-status.ready {
  color: #4ade80;
}
.plant-status.warn {
  color: #fbbf24;
}

.toast {
  position: sticky;
  bottom: 0.5rem;
  margin: 0.5rem auto 0;
  max-width: 22rem;
  text-align: center;
  padding: 0.45rem 0.85rem;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid #a855f7;
  border-radius: 8px;
  color: #f3e8ff;
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
  z-index: 5;
}
.toast.ok {
  border-color: #22c55e;
  color: #bbf7d0;
}

.keys-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.keys-modal[hidden] {
  display: none !important;
}
.keys-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.15rem 1.1rem;
  max-width: 28rem;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.keys-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.keys-head h2 {
  font-size: 1rem;
  font-weight: 650;
}
.keys-close {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.65rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.keys-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.88rem;
  line-height: 1.55;
}
.keys-list li {
  margin-bottom: 0.35rem;
}
.keys-list kbd,
.keys-note kbd {
  display: inline-block;
  padding: 0.08rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #475569;
  background: #0f172a;
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.keys-note {
  margin-top: 0.85rem;
  margin-bottom: 0;
  line-height: 1.45;
}

/* Visitor row + dev Demo on/off */
.visitors-controls {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.65rem;
  margin-bottom: 0.2rem;
}
.visitors-controls .auto-sell-row {
  margin-top: 0;
  margin-bottom: 0;
  flex: 1 1 auto;
}
.visitor-demo-btn {
  flex: 0 0 auto;
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #475569;
  border-radius: 6px;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.28rem 0.55rem;
  cursor: pointer;
  min-width: 4.6rem;
  letter-spacing: 0.02em;
}
.visitor-demo-btn:hover:not(:disabled) {
  border-color: #a855f7;
  color: #e2e8f0;
}
.visitor-demo-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.visitor-demo-btn.is-on {
  background: #3b0764;
  border-color: #c084fc;
  color: #f3e8ff;
}
