:root {
  --bg: #0b0f14;
  --fg: #eef2f6;
  --muted: #8a96a3;
  --panel: #151b23;
  --line: #243040;
  --accent: #9fb4c8;
  --heat: #ff6a1a;
  --eco: #3fbf6f;
  --face-hi: #1d2631;
  --face-lo: #0e1319;
  color-scheme: dark;
}
body[data-state="heating"] { --accent: var(--heat); --face-hi: #ff8a3d; --face-lo: #d4470b; }
body[data-state="eco"]     { --accent: var(--eco); }
body[data-state="off"],
body[data-state="offline"] { --accent: #4a5563; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
main { max-width: 440px; margin: 0 auto; padding: 12px 20px 32px; }
button { font: inherit; color: inherit; cursor: pointer; }

header { display: flex; align-items: center; gap: 8px; min-height: 52px; }
header h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 600; }
header select { flex: 1; font: inherit; font-size: 18px; font-weight: 600; background: transparent; color: var(--fg); border: 0; }
header select:not([hidden]) + h1 { display: none; }
.icon { background: none; border: 0; padding: 8px; color: var(--muted); border-radius: 50%; }
.icon:hover { color: var(--fg); background: var(--panel); }

/* Dial */
.dial-wrap { position: relative; width: min(100%, 340px); aspect-ratio: 1; margin: 12px auto 8px; }
#dial { width: 100%; height: 100%; touch-action: none; user-select: none; outline: none; }
#dial.disabled { cursor: default; }
#dial:not(.disabled) { cursor: grab; }
.bezel { fill: none; stroke: #2a3441; stroke-width: 8; }
.track, .track-val { fill: none; stroke-width: 12; stroke-linecap: round; }
.track { stroke: rgba(255,255,255,.10); }
.track-val { stroke: #fff; opacity: .9; transition: d .15s; }
body:not([data-state="heating"]) .track-val { stroke: var(--accent); }
.knob { fill: #fff; stroke: rgba(0,0,0,.25); stroke-width: 2; }
.ambient-mark { fill: #fff; opacity: .55; }
#face stop { transition: stop-color .6s; }

.dial-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none;
}
.status { font-size: 13px; letter-spacing: .18em; font-weight: 600; color: rgba(255,255,255,.75); min-height: 18px; }
.setpoint { font-size: clamp(64px, 22vw, 92px); font-weight: 300; line-height: 1; font-variant-numeric: tabular-nums; margin: 6px 0; }
.ambient { font-size: 14px; color: rgba(255,255,255,.7); min-height: 20px; }
body[data-state="eco"] .status { color: var(--eco); }

.stepper { display: flex; justify-content: center; gap: 28px; margin: 8px 0 22px; }
.stepper button {
  width: 68px; height: 68px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); font-size: 32px; line-height: 1;
}
.stepper button:active { transform: scale(.95); background: #1d2530; }
body[data-state="off"] .stepper button,
body[data-state="offline"] .stepper button { opacity: .35; pointer-events: none; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; background: var(--panel); padding: 6px; border-radius: 16px; }
.modes button { border: 0; background: none; padding: 12px 4px; border-radius: 12px; color: var(--muted); font-weight: 600; }
.modes button.active { background: #232d3a; color: var(--fg); }
.modes button[data-mode="HEAT"].active { color: var(--heat); }
.modes button[data-mode="ECO"].active { color: var(--eco); }
.modes button[hidden] { display: none; }

.info { display: flex; justify-content: space-between; margin-top: 16px; color: var(--muted); font-size: 13px; }

/* Setup */
#viewSetup h2 { margin: 8px 0 4px; font-size: 22px; }
.muted { color: var(--muted); font-size: 14px; }
form { display: grid; gap: 14px; margin-top: 18px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input {
  font: inherit; color: var(--fg); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.redirect { display: grid; gap: 4px; }
.redirect code { background: var(--panel); border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; word-break: break-all; user-select: all; }
.primary { background: var(--fg); color: var(--bg); border: 0; border-radius: 12px; padding: 14px; font-weight: 600; }
.setup-msg { margin-top: 16px; padding: 12px; border-radius: 10px; background: #3a1c1c; color: #ffc9c9; font-size: 14px; }
.setup-actions { display: grid; gap: 10px; margin-top: 24px; }
.setup-actions button { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.setup-actions .danger { color: #ff8f8f; }

.eta { font-size: 13px; color: rgba(255,255,255,.85); min-height: 18px; margin-top: 2px; }
.link-btn { display: block; margin: 18px auto 0; background: none; border: 0; color: var(--muted); font-size: 14px; padding: 8px 12px; }
.link-btn:hover { color: var(--fg); }
.link-btn.back { margin: 0 0 8px; padding-left: 0; }
#viewInfo h3 { font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; }
.kv { background: var(--panel); border-radius: 14px; padding: 4px 14px; }
.kv div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv div:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; word-break: break-all; }
.note { font-size: 13px; color: var(--muted); margin: 8px 2px; }
details pre { background: var(--panel); border-radius: 10px; padding: 10px; font-size: 11px; overflow: auto; color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; margin-top: 18px; }

.weather { text-align: center; color: var(--muted); font-size: 14px; min-height: 20px; margin: -2px 0 4px; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.presets button {
  display: flex; justify-content: space-between; align-items: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
}
.presets span { color: var(--muted); font-weight: 600; }
.presets b { font-weight: 600; font-variant-numeric: tabular-nums; }
.presets button.active { border-color: var(--heat); }
.presets button.active span { color: var(--fg); }
.links { display: flex; justify-content: center; gap: 8px; }
.links .link-btn { margin: 14px 0 0; }

#viewSettings h3, #viewHistory h3 { font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 24px 0 10px; }
#viewSettings h2, #viewHistory h2 { margin: 4px 0 0; font-size: 22px; }
#viewSettings label { margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label.check { display: flex; gap: 10px; align-items: center; color: var(--fg); }
label.check input { width: 20px; height: 20px; accent-color: var(--heat); }
#btnSaveSettings { width: 100%; margin-top: 18px; }
.app-only { display: none; }
body.has-android .app-only { display: block; }

.stat { display: flex; justify-content: space-between; align-items: baseline; background: var(--panel); border-radius: 14px; padding: 14px; margin-top: 14px; }
.stat span { color: var(--muted); font-size: 14px; }
.stat b { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--panel); padding: 4px; border-radius: 12px; margin-top: 12px; }
.seg button { border: 0; background: none; padding: 8px; border-radius: 9px; color: var(--muted); font-size: 14px; }
.seg button.active { background: #232d3a; color: var(--fg); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--fg); margin-bottom: 6px; }
.legend span, .tip div { display: inline-flex; align-items: center; gap: 6px; }
.legend i, .tip i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
i.dash { background: repeating-linear-gradient(90deg, #8a96a3 0 4px, transparent 4px 7px); }
i.band { height: 10px !important; background: rgba(231,102,36,.35); }
.chart { position: relative; }
.svgchart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.svgchart .grid { stroke: rgba(255,255,255,.08); stroke-width: 1; }
.svgchart .axis { fill: var(--muted); font-size: 11px; }
.svgchart .lbl { fill: var(--fg); font-size: 11px; }
.svgchart .val { fill: var(--fg); font-size: 11px; font-variant-numeric: tabular-nums; }
.svgchart .crosshair { stroke: rgba(255,255,255,.35); stroke-width: 1; }
.svgchart .ring { stroke: var(--bg); stroke-width: 2; }
.tip {
  position: absolute; top: 0; background: #1d2530; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 12px; pointer-events: none; white-space: nowrap; display: grid; gap: 3px;
}
.tip[hidden] { display: none; }
.tip span { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }

.pair { display: grid; gap: 10px; margin: 18px 0; }
textarea {
  font: 13px/1.4 ui-monospace, Consolas, monospace; color: var(--fg); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; width: 100%; resize: vertical; word-break: break-all;
}
body.in-app .web-only { display: none !important; }

/* Toast */
.msg {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #3a1c1c; color: #ffd6d6; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; max-width: 90vw; text-align: center;
}
.msg.ok { background: #1c3a27; color: #d2ffe0; }
.msg.show { opacity: 1; transform: translate(-50%, 0); }
