:root {
  --bg: #0d0e10;
  --panel: #121316;
  --card: #1a1c20;
  --card2: #202328;
  --line: rgba(255,255,255,.07);
  --text: #f2f3f5;
  --dim: #8d939c;
  --faint: #5a6068;
  --accent: #8fd3ff;
  --accent-rgb: 143,211,255;
  --warm: #ff9d6c;
  --danger: #ff6b6b;
  --r: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --round: -apple-system-ui-rounded, ui-rounded, "SF Pro Rounded", var(--font);
  color-scheme: dark;
}
.panel[data-mode="AIR_DRY"] { --accent: #6fe0c8; --accent-rgb: 111,224,200; }
.panel[data-mode="FAN"]     { --accent: #c9d3df; --accent-rgb: 201,211,223; }
.panel[data-mode="AUTO"]    { --accent: #b9a6ff; --accent-rgb: 185,166,255; }
.panel[data-mode="HEAT"]    { --accent: #ffb46b; --accent-rgb: 255,180,107; }
.panel[data-power="off"]    { --accent: #7d838c; --accent-rgb: 125,131,140; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
body { min-height: 100dvh; display: flex; justify-content: center; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
b { font-weight: 600; }

.panel {
  width: 100%; max-width: 480px; min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 14px) 18px calc(env(safe-area-inset-bottom) + 18px);
  display: flex; flex-direction: column; gap: 16px;
  background:
    radial-gradient(120% 50% at 50% 0%, rgba(var(--accent-rgb), .10), transparent 70%),
    var(--panel);
  transition: background .6s;
}
@media (min-width: 520px) { body { padding: 24px 0; } .panel { min-height: auto; border-radius: 28px; border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0,0,0,.5); } }

/* Mac popover embed */
body.mac { background: var(--panel); padding: 0; display: block; }
body.mac .panel { max-width: none; min-height: 100vh; border: 0; border-radius: 0; box-shadow: none; padding: 14px 16px 12px; gap: 13px; }
body.mac .hero { height: 158px; }
body.mac .big { font-size: 58px; }
body.mac #chart { height: 108px; }

/* top */
.top { display: flex; align-items: center; justify-content: space-between; }
.dev { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); margin-top: 3px; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.status.live i { background: #4cd38a; box-shadow: 0 0 0 3px rgba(76,211,138,.15); }
.status.busy i { background: var(--accent); animation: pulse 1s infinite; }
.status.bad i { background: var(--danger); }
.status.demo i { background: #f5c451; }
@keyframes pulse { 50% { opacity: .3; } }

.power {
  width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line);
  transition: background .3s, box-shadow .3s, transform .1s;
}
.power svg { width: 22px; height: 22px; fill: none; stroke: var(--dim); stroke-width: 2.2; stroke-linecap: round; transition: stroke .3s; }
.power[aria-pressed="true"] { background: rgba(var(--accent-rgb), .16); border-color: rgba(var(--accent-rgb), .45); box-shadow: 0 0 24px rgba(var(--accent-rgb), .25); }
.power[aria-pressed="true"] svg { stroke: var(--accent); }
.power:active { transform: scale(.94); }

/* hero */
.hero { position: relative; height: 168px; display: flex; justify-content: center; }
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
.roomtag { z-index: 3; }
.unit { position: relative; width: min(100%, 440px); aspect-ratio: 5 / 2; align-self: flex-start; margin-top: -12px; }
.unit { isolation: isolate; z-index: 1; }
.unit img { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; user-select: none; }
.unit img.on { opacity: 1; }
.led { z-index: 1000; position: absolute; left: 76.4%; width: 5.0%; top: 23.6%; height: 9.4%; display: flex; flex-direction: column; align-items: center; gap: 9%;
  opacity: 0; transition: opacity .7s; pointer-events: none;
  filter: drop-shadow(0 0 .5px rgba(70,76,84,.55)) drop-shadow(0 0 1.5px rgba(255,255,255,.95)) drop-shadow(0 0 5px rgba(255,255,255,.6)); }

.led .digits { width: 100%; overflow: visible; }
.led .digits rect { fill: #fff; }
.led .wifi { width: 34%; overflow: visible; fill: #fff; }
.led .wifi path { fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; }
.panel[data-power="on"] .led { opacity: 1; }
.roomtag { position: absolute; left: 0; bottom: 0; font-size: 13px; color: var(--dim); display: flex; gap: 4px; align-items: baseline; }
.roomtag b { color: var(--text); font-variant-numeric: tabular-nums; }
.roomtag .dot { color: var(--faint); }

/* temperature */
.temp { display: flex; flex-direction: column; gap: 10px; }
.readout { display: flex; align-items: center; justify-content: space-between; }
.big { font: 300 72px/1 var(--round); letter-spacing: -.045em; font-variant-numeric: tabular-nums; outline: none; transition: color .3s; }
.big sup { font-size: 20px; letter-spacing: 0; color: var(--dim); vertical-align: top; position: relative; top: 10px; margin-left: 2px; }
.panel[data-power="off"] .big { color: #9aa0a8; }
.step { width: 52px; height: 52px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); font-size: 26px; font-weight: 300; color: var(--text); transition: transform .1s, background .2s; }
.step:active { transform: scale(.92); background: var(--card2); }
.ctx { text-align: center; font-size: 13px; color: var(--dim); min-height: 17px; margin-top: -4px; }
.ctx b { color: var(--text); font-weight: 500; }

.track { position: relative; height: 44px; border-radius: 22px; background: var(--card); border: 1px solid var(--line); touch-action: none; cursor: pointer; outline: none; overflow: visible; }
.track:focus-visible { box-shadow: 0 0 0 2px rgba(var(--accent-rgb), .5); }
.fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 22px; background: linear-gradient(90deg, rgba(var(--accent-rgb), .05), rgba(var(--accent-rgb), .38)); transition: width .25s; }
.ticks { position: absolute; inset: 0 22px; display: flex; justify-content: space-between; align-items: center; pointer-events: none; }
.ticks i { width: 1px; height: 8px; background: rgba(255,255,255,.08); }
.thumb { position: absolute; top: 5px; width: 34px; height: 34px; margin-left: -17px; border-radius: 50%; background: #f4f5f7; box-shadow: 0 4px 14px rgba(0,0,0,.45), 0 0 0 4px rgba(var(--accent-rgb), .18); transition: left .25s; pointer-events: none; }
.track.drag .thumb, .track.drag .fill { transition: none; }
.roommark { position: absolute; top: -7px; bottom: -7px; width: 0; transition: left .6s; pointer-events: none; }
.roommark i { position: absolute; left: -1px; top: 0; bottom: 0; width: 2px; border-radius: 1px; background: var(--warm); opacity: .9; }
.roommark span { position: absolute; bottom: -16px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--warm); letter-spacing: .04em; text-transform: uppercase; }
.range { display: flex; margin-top: 2px !important; justify-content: space-between; font-size: 11px; color: var(--faint); padding: 0 6px; margin-top: -4px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 11px 11px 10px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); text-align: left; transition: background .2s, border-color .2s, opacity .3s, transform .1s; min-width: 0; }
.tile:active { transform: scale(.97); }
.tile .ic { width: 20px; height: 20px; margin-bottom: 6px; color: var(--accent); }
.tile .k { font-size: 11px; color: var(--dim); }
.tile .v { font-size: 13px; font-weight: 600; line-height: 1.2; max-width: 100%; overflow-wrap: anywhere; }
.tile.toggle[aria-pressed="true"] { background: rgba(var(--accent-rgb), .12); border-color: rgba(var(--accent-rgb), .35); }
.tile.busy { animation: pulse 1s infinite; }
.panel[data-power="off"] .tile { opacity: .55; }
.tile[disabled] { opacity: .3 !important; cursor: default; }

/* sleep */
.sleepcard { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 9px; }
.sc-top { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.sc-top .ic { width: 16px; height: 16px; color: var(--accent); }
.sc-t { color: var(--dim); flex: 1; }
.sc-bar { height: 4px; border-radius: 2px; background: var(--card2); overflow: hidden; }
.sc-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.link { color: var(--accent); font-size: 13px; }

/* scenes */
.scenes { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 0 18px; }
.scenes::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 7px; padding: 9px 13px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; transition: background .2s, transform .1s; }
.chip .ic { width: 15px; height: 15px; color: var(--accent); }
.chip:active { transform: scale(.96); background: var(--card2); }
.chip.on { border-color: rgba(var(--accent-rgb), .5); }

/* trend */
.trend { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 12px 10px; }
.tr-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin-bottom: 6px; }
.seg { display: flex; background: var(--panel); border-radius: 8px; padding: 2px; }
.seg button { font-size: 11px; padding: 3px 8px; border-radius: 6px; color: var(--dim); }
.seg button.on { background: var(--card2); color: var(--text); }
.tr-stats { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin: 2px 0 6px; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.tr-stats .now { font: 400 22px/1 var(--round); color: var(--text); letter-spacing: -.02em; }
.tr-stats b { color: var(--text); font-weight: 500; }
.tr-plot { position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
#chart { width: 100%; height: 132px; display: block; overflow: visible; }
#chart .grid { stroke: rgba(255,255,255,.06); stroke-width: 1; shape-rendering: crispEdges; }
#chart .axis { font-size: 10px; fill: var(--faint); font-variant-numeric: tabular-nums; }
#chart .room { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
#chart .room.draw { animation: draw 1.1s cubic-bezier(.4,.1,.2,1) forwards; }
#chart .area { opacity: 1; transition: opacity .9s .3s; }
#chart .area.pre { opacity: 0; }
#chart .tgt { fill: none; stroke: #c5cad2; stroke-opacity: .5; stroke-width: 1.5; stroke-dasharray: 4 3; }
#chart .runtrack { fill: rgba(255,255,255,.05); }
#chart .run { fill: rgba(143,211,255,.7); }
#chart .end-label { font-size: 11px; font-weight: 600; fill: var(--text); font-variant-numeric: tabular-nums; }
#chart .halo { transform-box: fill-box; transform-origin: center; animation: halo 2.4s ease-out infinite; }
#chart .xhair { stroke: rgba(255,255,255,.35); stroke-width: 1; shape-rendering: crispEdges; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes halo { from { transform: scale(1); opacity: .55; } to { transform: scale(3.2); opacity: 0; } }
.tr-tip { position: absolute; top: 0; pointer-events: none; background: rgba(14,15,18,.92); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 9px; font-size: 11.5px; line-height: 1.5; color: var(--dim); white-space: nowrap; box-shadow: 0 8px 24px rgba(0,0,0,.35); backdrop-filter: blur(6px); }
.tr-tip .when { color: var(--faint); font-size: 10.5px; }
.tr-tip b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tr-tip .k { display: inline-block; width: 10px; height: 2px; border-radius: 1px; margin-right: 6px; vertical-align: middle; }
.tr-legend { display: flex; gap: 16px; font-size: 11px; color: var(--dim); margin-top: 6px; }
.lg i { display: inline-block; width: 14px; height: 2px; border-radius: 1px; margin-right: 6px; vertical-align: middle; }
.lg-room i { background: linear-gradient(90deg, #3a8fd6, #8a9099, #d9703f); }
.lg-tgt i { background: repeating-linear-gradient(90deg, rgba(197,202,210,.6) 0 4px, transparent 4px 7px); }
.lg-on i { height: 4px; border-radius: 2px; background: rgba(143,211,255,.7); }

.foot { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--faint); }
.fbtns { display: flex; gap: 4px; }
.fbtns button { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--dim); }
.fbtns button:active { background: var(--card); }
.fbtns .ic { width: 18px; height: 18px; }

.ic { display: inline-block; }
.ic svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); backdrop-filter: blur(2px); z-index: 10; animation: fade .2s; }
.sheet { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 480px; max-height: 86dvh; overflow-y: auto; z-index: 11;
  background: #17191d; border-top: 1px solid var(--line); border-radius: 22px 22px 0 0; padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px); animation: up .25s cubic-bezier(.2,.9,.3,1); }
.grab { width: 36px; height: 4px; border-radius: 2px; background: #3a3e45; margin: 0 auto 12px; }
@keyframes up { from { transform: translate(-50%, 100%); } }
@keyframes fade { from { opacity: 0; } }
.sheet h3 { margin: 4px 0 14px; font-size: 17px; font-weight: 600; }
.sheet h4 { margin: 18px 0 8px; font-size: 12px; font-weight: 500; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.opts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.opt { display: flex; align-items: center; gap: 10px; padding: 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); font-size: 14px; text-align: left; }
.opt .ic { width: 20px; height: 20px; color: var(--accent); }
.opt.sel { border-color: rgba(var(--accent-rgb), .6); background: rgba(var(--accent-rgb), .1); }
.opt small { display: block; color: var(--dim); font-size: 11px; margin-top: 2px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.row:last-child { border-bottom: 0; }
.row small { color: var(--dim); display: block; font-size: 12px; margin-top: 2px; }
.sw { width: 44px; height: 26px; border-radius: 13px; background: #3a3e45; position: relative; flex: none; transition: background .2s; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; }
.sw[aria-pressed="true"] { background: var(--accent); }
.sw[aria-pressed="true"]::after { transform: translateX(18px); }
.btn { display: block; width: 100%; padding: 14px; border-radius: 14px; background: var(--accent); color: #0b0c0e; font-weight: 600; font-size: 15px; margin-top: 16px; text-align: center; }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid rgba(255,107,107,.3); }
input, select { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
input[type="time"] { min-width: 110px; }
.days { display: flex; gap: 5px; }
.days button { width: 34px; height: 34px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); font-size: 12px; color: var(--dim); }
.days button.on { background: rgba(var(--accent-rgb), .18); border-color: rgba(var(--accent-rgb), .5); color: var(--text); }
.num { display: flex; align-items: center; gap: 10px; }
.num button { width: 32px; height: 32px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); font-size: 18px; }
.num b { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; }
.curve { width: 100%; height: 90px; margin-top: 6px; }
.curve path { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.curve .ar { fill: rgba(var(--accent-rgb), .12); stroke: none; }
.curve text { font-size: 9px; fill: var(--dim); }
.note { font-size: 12.5px; color: var(--dim); line-height: 1.5; }
.empty { padding: 18px 0; text-align: center; color: var(--dim); font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%); z-index: 20; max-width: min(92vw, 440px);
  background: #2a1a1c; border: 1px solid rgba(255,107,107,.35); color: #ffd9d9; padding: 11px 15px; border-radius: 14px; font-size: 13px; line-height: 1.4; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: fade .2s; }
.toast.ok { background: #18241e; border-color: rgba(76,211,138,.35); color: #d4f5e2; }

@media (max-width: 360px) { .tiles { grid-template-columns: repeat(2, 1fr); } .big { font-size: 60px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
