:root {
  --bg: #0f172a;
  --card: #1e293b;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --on: #22c55e;
  --off: #64748b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) 16px 96px;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 12px;
}
h1 { font-size: 24px; margin: 0; letter-spacing: 0.5px; }
.pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.pill-on { background: rgba(34,197,94,.15); color: var(--on); }
.pill-off { background: rgba(100,116,139,.2); color: var(--off); }

.empty { color: var(--muted); text-align: center; margin-top: 40px; }

#units {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 16px;
  align-items: start;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.name {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
}
.name:focus { outline: none; border-bottom: 1px solid var(--accent); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--off); flex: none; }
.dot.live { background: var(--on); box-shadow: 0 0 8px var(--on); }

.row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.power .chip.sel { background: var(--on); color: #04210f; border-color: var(--on); }
.power .chip.off-sel { background: var(--off); color: #0b1220; border-color: var(--off); }
.chip {
  flex: 1 0 auto;
  padding: 9px 0;
  min-width: 64px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.chip.sel { background: var(--accent); color: #052230; border-color: var(--accent); font-weight: 700; }

.ctrl-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); margin: 22px 4px 6px;
}
.card-head + .ctrl-title { margin-top: 8px; }
.range { position: relative; height: 44px; margin: 26px 6px 18px; touch-action: none; }
.ticks {
  position: absolute; top: 50%; left: 0; right: 0; height: 14px;
  transform: translateY(-50%); pointer-events: none;
}
.tick {
  position: absolute; top: 3px; width: 1px; height: 8px;
  background: rgba(148,163,184,.45); transform: translateX(-50%);
}
.tick.major { top: 0; height: 14px; width: 2px; background: rgba(148,163,184,.8); }
.bub {
  position: absolute; bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%);
  font-size: 12px; font-weight: 700; color: var(--text);
  background: #0b1220; border: 1px solid var(--line);
  padding: 2px 7px; border-radius: 7px; white-space: nowrap; pointer-events: none;
}
.range-scale {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted); margin: 2px 6px 10px;
}
.track {
  position: absolute; top: 50%; left: 0; right: 0; height: 6px;
  transform: translateY(-50%); background: var(--line);
  border-radius: 3px; overflow: hidden;
}
.zone { position: absolute; top: 0; bottom: 0; }
.zone.heat { left: 0; background: linear-gradient(90deg, #ea580c, #fb923c); }
.zone.cool { right: 0; background: linear-gradient(90deg, #38bdf8, #0284c7); }
.handle {
  position: absolute; top: 50%; width: 28px; height: 28px;
  margin-left: -14px; transform: translateY(-50%);
  border-radius: 50%; border: 3px solid #0b1220; padding: 0;
  cursor: grab; touch-action: none; box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.handle.heat { background: #fb923c; }
.handle.cool { background: #38bdf8; }
.range-labels {
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--muted); margin-bottom: 12px; padding: 0 4px;
}
.range-labels b { color: var(--text); font-size: 16px; }
.range-note { color: var(--muted); font-size: 13px; margin: 4px 4px 6px; display: none; }

.readout {
  display: flex; justify-content: space-around;
  color: var(--muted); font-size: 14px;
  border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px;
}
.readout b { color: var(--text); }

footer { position: fixed; bottom: 0; left: 0; right: 0; padding: 12px; text-align: center; }
footer button {
  background: var(--card); color: var(--muted);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 16px; cursor: pointer;
}
.disabled { opacity: .4; pointer-events: none; }
