:root {
  color-scheme: dark;
  --bg: #0b0b0d;
  --panel: #16161a;
  --panel-2: #1e1e24;
  --border: #2a2a31;
  --text: #f2ede6;
  --text-dim: #9a948c;
  --accent: #ff7a3d;
  --accent-dim: #6b3a24;
  --good: #4caf6f;
  --bad: #e0525a;
  --warn: #e0b04a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}

main {
  max-width: 460px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  font-size: 1.15rem;
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.01em;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.dot.good { background: var(--good); }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.btn-primary {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  font-weight: 600;
  font-size: 0.95rem;
  background: var(--accent);
  color: #1a0f08;
}
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn-primary.disconnect { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }

section.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.card h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 12px;
  font-weight: 650;
}

.device-info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  font-size: 0.85rem;
}
.device-info dt { color: var(--text-dim); }
.device-info dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.battery-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.battery-bars {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  height: 16px;
}
.battery-bars .bar {
  width: 6px;
  border-radius: 2px;
  background: var(--border);
}
.battery-bars .bar:nth-child(1) { height: 25%; }
.battery-bars .bar:nth-child(2) { height: 45%; }
.battery-bars .bar:nth-child(3) { height: 65%; }
.battery-bars .bar:nth-child(4) { height: 85%; }
.battery-bars .bar:nth-child(5) { height: 100%; }
.battery-bars .bar.on { background: var(--good); }
.battery-bars.redline .bar.on { background: var(--bad); }

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.profile-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.profile-btn .deg { font-weight: 650; font-size: 1rem; }
.profile-btn .name { font-size: 0.75rem; color: var(--text-dim); }
.profile-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.profile-btn.active .name { color: #f0c9b0; }
.profile-btn:disabled { opacity: 0.4; }

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.segmented button {
  flex: 1;
  appearance: none;
  border: none;
  background: var(--panel-2);
  color: var(--text-dim);
  padding: 10px 4px;
  font-size: 0.78rem;
  border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--accent-dim); color: var(--text); }
.segmented button:disabled { opacity: 0.4; }

.heat-btn {
  width: 100%;
  appearance: none;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 10px;
  padding: 13px;
  font-weight: 650;
  font-size: 0.95rem;
}
.heat-btn:disabled { opacity: 0.4; border-color: var(--border); color: var(--text-dim); }
.heat-btn:active:not(:disabled) { background: var(--accent-dim); }

.unverified-note {
  font-size: 0.72rem;
  color: var(--warn);
  margin-top: 8px;
  line-height: 1.4;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.slider-row input[type="range"] { flex: 1; }
.slider-row output { font-variant-numeric: tabular-nums; width: 2.4em; text-align: right; color: var(--text-dim); }

.lock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.switch {
  appearance: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s, background 0.15s;
}
.switch.on { background: var(--accent-dim); border-color: var(--accent); }
.switch.on::after { transform: translateX(18px); background: var(--accent); }
.switch:disabled { opacity: 0.4; }

details.debug summary {
  cursor: pointer;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 650;
}
.log {
  margin-top: 10px;
  max-height: 220px;
  overflow-y: auto;
  font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-all;
}
.log .tx { color: var(--accent); }
.log .rx { color: var(--good); }
.log .err { color: var(--bad); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.empty-state p { margin: 8px 0 0; font-size: 0.85rem; }

[hidden] { display: none !important; }
