:root {
  --bg: #EEECE7;
  --surface: rgba(255, 255, 255, 0.7);
  --surface-solid: #FFFFFF;
  --surface-2: rgba(20, 21, 24, 0.05);
  --text: #141518;
  --text-2: #6E717A;
  --text-3: #A9ACB3;
  --line: rgba(20, 21, 24, 0.07);
  --shadow: 0 1px 1px rgba(20, 21, 24, 0.03), 0 14px 34px -14px rgba(20, 21, 24, 0.2);
  --glow-a: rgba(255, 186, 140, 0.55);
  --glow-b: rgba(150, 190, 255, 0.45);
  --heat: #FF6B3D;  --heat-2: #FFA54C;
  --cool: #3D86FF;  --cool-2: #5ED2FF;
  --auto: #7C6CFF;  --auto-2: #B49CFF;
  --dry: #12A99A;   --dry-2: #5EDFC6;
  --fan: #7D8695;   --fan-2: #AEB6C2;
  --off: #B4B7BE;
  --radius: 30px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --num: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B0C0E;
    --surface: rgba(30, 31, 36, 0.62);
    --surface-solid: #1B1C20;
    --surface-2: rgba(255, 255, 255, 0.06);
    --text: #F4F4F6;
    --text-2: #9A9DA6;
    --text-3: #5D6068;
    --line: rgba(255, 255, 255, 0.07);
    --shadow: 0 14px 34px -14px rgba(0, 0, 0, 0.7);
    --glow-a: rgba(255, 120, 60, 0.22);
    --glow-b: rgba(70, 120, 255, 0.2);
    --off: #50535B;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* No scrollbars anywhere; the page still scrolls. */
html { scrollbar-width: none; }
html::-webkit-scrollbar, body::-webkit-scrollbar, *::-webkit-scrollbar { display: none; width: 0; height: 0; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  font: 17px/1.35 -apple-system, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Ambient light behind everything, tinted by what the house is doing. */
body::before {
  content: "";
  position: fixed; inset: -25%;
  z-index: -1;
  background:
    radial-gradient(38% 32% at 18% 12%, var(--glow-a), transparent 70%),
    radial-gradient(42% 36% at 88% 34%, var(--glow-b), transparent 70%),
    radial-gradient(40% 30% at 40% 92%, color-mix(in srgb, var(--glow-a) 60%, transparent), transparent 70%);
  transition: background 1.2s ease;
  animation: drift 26s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes drift {
  from { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
  to { transform: translate3d(3%, -2%, 0) rotate(8deg) scale(1.06); }
}

button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
button:focus-visible, a:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--cool); outline-offset: 3px; }

main {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 18px calc(env(safe-area-inset-bottom) + 112px);
}

.glass {
  background: var(--surface);
  -webkit-backdrop-filter: blur(26px) saturate(1.6);
  backdrop-filter: blur(26px) saturate(1.6);
  box-shadow: var(--shadow), inset 0 0 0 1px var(--line);
  border-radius: var(--radius);
}

/* Smooth screen changes (View Transitions where supported). */
::view-transition-old(root) { animation: 180ms var(--ease) both fade-out; }
::view-transition-new(root) { animation: 320ms var(--ease) both rise-in; }
@keyframes fade-out { to { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(10px) scale(0.99); } }
.enter > * { animation: rise-in 420ms var(--ease) both; }
.enter > *:nth-child(2) { animation-delay: 40ms; }
.enter > *:nth-child(3) { animation-delay: 80ms; }
.enter > *:nth-child(4) { animation-delay: 120ms; }
.enter > *:nth-child(5) { animation-delay: 160ms; }

/* MARK: Headers */

.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 10px 4px 22px; }
.eyebrow { font-size: 14px; font-weight: 600; color: var(--text-2); letter-spacing: 0.01em; }
.eyebrow::first-letter { text-transform: uppercase; }
.head h1 { margin: 2px 0 0; font-size: 36px; line-height: 1.05; font-weight: 700; letter-spacing: -0.035em; }
.head .summary { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  background: var(--surface-2);
}
.pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--off)); }

.round-btn {
  display: grid; place-items: center; flex: none;
  width: 46px; height: 46px; border-radius: 50%;
  color: var(--text-2);
  transition: transform 0.2s var(--ease);
}
.round-btn:active { transform: scale(0.92); }
.round-btn svg { width: 22px; height: 22px; }

/* MARK: Rooms */

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.unit {
  --c: var(--off); --c2: var(--off);
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 186px; padding: 18px;
  text-align: left;
  transition: transform 0.25s var(--ease);
}
.unit::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(120% 90% at 100% 0%, color-mix(in srgb, var(--c) 26%, transparent), transparent 60%);
  opacity: 0; transition: opacity 0.6s ease;
}
.unit.on { --c: var(--mc); --c2: var(--mc2); }
.unit.on::after { opacity: 1; }
.unit:active { transform: scale(0.97); }
.unit.offline { opacity: 0.5; }

.unit .icon {
  position: relative; z-index: 1;
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 14px;
  background: var(--surface-2); color: var(--text-3);
  transition: background 0.4s ease, color 0.4s ease;
}
.unit.on .icon { background: linear-gradient(140deg, var(--c), var(--c2)); color: #fff; box-shadow: 0 6px 16px -6px var(--c); }
.unit .icon svg { width: 21px; height: 21px; }
.unit .body { position: relative; z-index: 1; }
.unit .temp { font: 300 46px/1 var(--num); letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.unit .temp sup { font-size: 22px; font-weight: 400; top: -0.75em; margin-left: 1px; }
.unit .name { font-weight: 650; font-size: 16px; margin-top: 8px; letter-spacing: -0.01em; }
.unit .status { color: var(--text-2); font-size: 13.5px; margin-top: 2px; }

.switch {
  position: absolute; top: 16px; right: 16px; z-index: 2;
  width: 46px; height: 28px; border-radius: 14px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background 0.3s var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.35s var(--ease);
}
.unit.on .switch { background: linear-gradient(120deg, var(--c), var(--c2)); box-shadow: none; }
.unit.on .switch::after { transform: translateX(18px); }

/* MARK: Detail */

.bar { display: flex; align-items: center; gap: 10px; margin: 2px 0 10px; min-height: 46px; }
.bar h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.025em; flex: 1; }
.bar .state { font-size: 14px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.bar .state i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 10px var(--c); }

.detail { --c: var(--off); --c2: var(--off); }
.detail.on { --c: var(--mc); --c2: var(--mc2); }

.dial-card { padding: 18px 16px 22px; text-align: center; transition: opacity 0.3s ease; }
.dial { position: relative; width: min(80vw, 300px); aspect-ratio: 1; margin: 0 auto; touch-action: none; cursor: grab; }
.dial svg { width: 100%; height: 100%; display: block; overflow: visible; }
.dial .tick { stroke: var(--text-3); opacity: 0.35; stroke-width: 0.9; stroke-linecap: round; transition: stroke 0.25s ease, opacity 0.25s ease; }
.dial .tick.on { stroke: var(--c); opacity: 1; }
.dial .tick.major { stroke-width: 1.3; }
.dial .knob { fill: var(--surface-solid); stroke: var(--c); stroke-width: 2.6; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25)); transition: stroke 0.3s ease; }
.dial-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.dial-center .mode-label { font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--c); }
.detail:not(.on) .dial-center .mode-label { color: var(--text-3); }
.dial-center .target { font: 200 96px/0.95 var(--num); letter-spacing: -0.05em; font-variant-numeric: tabular-nums; margin-top: 4px; }
.dial-center .target sup { font-size: 36px; font-weight: 300; top: -1.1em; margin-left: 2px; }
.detail:not(.on) .dial-center .target { color: var(--text-3); }
.dial-center .now { margin-top: 8px; color: var(--text-2); font-size: 15px; font-weight: 500; }
.bump { animation: bump 0.28s var(--ease); }
@keyframes bump { 40% { transform: scale(1.04); } }

.steppers { display: flex; justify-content: center; gap: 40px; margin-top: -6px; }
.step {
  display: grid; place-items: center;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--surface-2);
  font: 300 32px/1 var(--num);
  transition: transform 0.15s var(--ease), background 0.2s ease;
}
.step:active { transform: scale(0.9); background: color-mix(in srgb, var(--c) 22%, var(--surface-2)); }
.step:disabled { opacity: 0.3; }

.section { margin-top: 12px; padding: 16px; }
.section h2 { margin: 0 0 12px 4px; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }

.modes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.mode {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 13px 2px 11px; border-radius: 20px;
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
  transition: background 0.3s var(--ease), color 0.3s ease, transform 0.15s var(--ease);
}
.mode:active { transform: scale(0.94); }
.mode svg { width: 24px; height: 24px; }
.mode[aria-pressed="true"] { background: linear-gradient(150deg, var(--m), var(--m2)); color: #fff; box-shadow: 0 8px 20px -10px var(--m); }

.segmented { position: relative; display: grid; grid-template-columns: repeat(var(--n, 4), 1fr); padding: 4px; border-radius: 18px; background: var(--surface-2); }
.segmented .thumb {
  position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc((100% - 8px) / var(--n, 4));
  border-radius: 14px; background: var(--surface-solid);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transform: translateX(calc(100% * var(--i, 0)));
  transition: transform 0.4s var(--ease);
}
.segmented button { position: relative; z-index: 1; padding: 12px 0; font-size: 15px; font-weight: 600; color: var(--text-2); transition: color 0.25s ease; }
.segmented button[aria-pressed="true"] { color: var(--text); }

.cta {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; margin-top: 14px; padding: 19px;
  border-radius: 24px;
  font-size: 17px; font-weight: 650;
  background: var(--text); color: var(--bg);
  transition: transform 0.15s var(--ease), background 0.3s ease;
}
.cta svg { width: 21px; height: 21px; }
.cta:active { transform: scale(0.98); }
.cta.quiet { background: var(--surface); color: var(--text); box-shadow: var(--shadow), inset 0 0 0 1px var(--line); -webkit-backdrop-filter: blur(26px); backdrop-filter: blur(26px); }

.locked { opacity: 0.4; pointer-events: none; }
.note { color: var(--text-2); margin: 0 4px 10px; font-size: 15px; }

/* MARK: Door */

.video-card { position: relative; overflow: hidden; aspect-ratio: 4 / 3; border-radius: 32px; background: #000; box-shadow: var(--shadow); }
.video-host, .video-host canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.video-host canvas { object-fit: cover; display: block; }
.door-video-src { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.video-card::after { content: ""; position: absolute; inset: auto 0 0 0; height: 40%; background: linear-gradient(transparent, rgba(0, 0, 0, 0.55)); pointer-events: none; }
.video-badge {
  position: absolute; left: 14px; top: 14px; z-index: 2;
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.42); color: #fff;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  font-size: 13px; font-weight: 650;
}
.video-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: #F5C26B; animation: pulse 1.1s infinite; }
.video-badge[data-state="live"] .dot { background: #34C759; box-shadow: 0 0 8px #34C759; animation: none; }
.video-badge[data-state="error"] .dot { background: #FF453A; animation: none; }
@keyframes pulse { 50% { opacity: 0.3; } }
.video-title { position: absolute; left: 18px; bottom: 16px; z-index: 2; color: #fff; font-weight: 650; font-size: 17px; letter-spacing: -0.01em; }
.video-sound {
  position: absolute; right: 12px; bottom: 12px; z-index: 2;
  display: grid; place-items: center;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.42); color: #fff;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.video-sound svg { width: 22px; height: 22px; }

/* Slide to open */
.slider {
  --p: 0;
  position: relative; overflow: hidden;
  height: 74px; margin-top: 14px; border-radius: 37px;
  touch-action: none;
}
.slider-fill {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, var(--heat), var(--heat-2));
  transform-origin: left; transform: scaleX(calc(0.17 + var(--p) * 0.83));
  opacity: calc(0.25 + var(--p) * 0.75);
  border-radius: inherit;
}
.slider.release .slider-fill, .slider.release .slider-knob { transition: transform 0.45s var(--ease), opacity 0.45s ease; }
.slider-text {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding-left: 60px; font-weight: 650; font-size: 17px;
  opacity: calc(1 - var(--p) * 1.6);
  background: linear-gradient(100deg, var(--text-2) 40%, var(--text) 50%, var(--text-2) 60%) 0 0 / 300% 100%;
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  animation: shimmer 2.6s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }
.slider-knob {
  position: absolute; top: 6px; left: 6px;
  width: 62px; height: 62px; border-radius: 50%;
  display: grid; place-items: center;
  background: #fff; color: var(--heat);
  box-shadow: 0 6px 16px -4px rgba(0, 0, 0, 0.3);
  transform: translateX(calc(var(--p) * (var(--w, 300px) - 74px)));
  cursor: grab;
}
.slider-knob svg { width: 26px; height: 26px; }
.slider.done .slider-fill { background: linear-gradient(90deg, #22B573, #4CD98E); opacity: 1; transform: scaleX(1); }
.slider.done .slider-knob { color: #22B573; }
.slider.done .slider-text { opacity: 1; -webkit-text-fill-color: #fff; background: none; animation: none; padding-left: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.chip { padding: 13px 18px; border-radius: 18px; font-size: 15px; font-weight: 650; }

/* MARK: Tab bar */

.tabbar {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 14px); transform: translateX(-50%);
  display: grid; grid-template-columns: 1fr 1fr;
  width: min(280px, calc(100% - 72px)); padding: 6px;
  border-radius: 28px; z-index: 10;
}
.tabbar[hidden] { display: none; }
.tabbar .indicator {
  position: absolute; top: 6px; bottom: 6px; left: 6px; width: calc(50% - 6px);
  border-radius: 22px; background: var(--text);
  transform: translateX(calc(100% * var(--i, 0)));
  transition: transform 0.45s var(--ease);
}
.tabbar a {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 0;
  color: var(--text-2); font-weight: 650; font-size: 15px;
  transition: color 0.3s ease;
}
.tabbar a svg { width: 21px; height: 21px; }
.tabbar a[aria-current="page"] { color: var(--bg); }

/* MARK: Settings & login */

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px; }
.muted { color: var(--text-2); }
.small { font-size: 13.5px; margin: 12px 4px 0; line-height: 1.4; }
.center { text-align: center; padding: 30px 22px; }
.center p { margin: 0 0 6px; }
.field {
  width: 100%; padding: 16px 18px; border: 0; border-radius: 18px;
  background: var(--surface-2); color: var(--text); font: inherit;
  user-select: text; -webkit-user-select: text;
}
.stack { display: grid; gap: 10px; }

.login { display: flex; flex-direction: column; justify-content: center; min-height: calc(100dvh - 100px); }
.login .card { padding: 28px 22px 22px; }
.login .logo {
  width: 64px; height: 64px; border-radius: 20px; margin-bottom: 22px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(140deg, var(--heat), var(--heat-2));
  box-shadow: 0 10px 24px -10px var(--heat);
}
.login .logo svg { width: 32px; height: 32px; }
.login h1 { margin: 0; font-size: 32px; letter-spacing: -0.035em; }
.login p { margin: 6px 0 22px; color: var(--text-2); }
.login .error { color: #E5484D; margin-top: 12px; min-height: 20px; font-size: 15px; }

.empty { text-align: center; color: var(--text-2); padding: 56px 16px; }

#toast {
  position: fixed; left: 18px; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 92px);
  max-width: 484px; margin: 0 auto; z-index: 20;
  padding: 14px 18px; border-radius: 20px;
  background: var(--text); color: var(--bg);
  font-size: 15px; font-weight: 600; text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  animation: rise-in 0.35s var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* MARK: Rename */

.bar .pencil { width: 38px; height: 38px; color: var(--text-3); margin-left: -4px; }
.bar .pencil svg { width: 18px; height: 18px; }
.rename { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; animation: rise-in 0.3s var(--ease); }
.rename .field { flex: 1; min-width: 0; padding: 11px 14px; font-size: 18px; font-weight: 650; }
.rename .round-btn { width: 42px; height: 42px; background: var(--surface-2); }
.rename .round-btn.ok { background: var(--text); color: var(--bg); }

/* MARK: Airflow, sleep, eco */

.positions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px; animation: rise-in 0.3s var(--ease); }
.position {
  display: grid; place-items: center; padding: 12px 0; border-radius: 16px;
  color: var(--text-3); background: var(--surface-2);
  transition: background 0.3s var(--ease), color 0.3s ease, transform 0.15s var(--ease);
}
.position svg { width: 26px; height: 26px; }
.position:active { transform: scale(0.94); }
.position[aria-pressed="true"] { background: linear-gradient(150deg, var(--c), var(--c2)); color: #fff; box-shadow: 0 8px 18px -10px var(--c); }

.toggle-row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 10px 4px; text-align: left;
}
.toggle-row + .toggle-row { border-top: 1px solid var(--line); }
.toggle-row:disabled { opacity: 0.45; }
.t-icon { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 14px; background: var(--surface-2); color: var(--text-2); transition: background 0.3s ease, color 0.3s ease; }
.t-icon svg { width: 21px; height: 21px; }
.toggle-row.on .t-icon { background: linear-gradient(140deg, var(--c), var(--c2)); color: #fff; }
.t-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.t-title { font-weight: 650; font-size: 16px; }
.t-sub { font-size: 13.5px; color: var(--text-2); margin-top: 1px; }
.toggle {
  position: relative; flex: none; width: 50px; height: 30px; border-radius: 15px;
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line);
  transition: background 0.3s var(--ease);
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); transition: transform 0.35s var(--ease);
}
.toggle-row.on .toggle { background: linear-gradient(120deg, var(--c), var(--c2)); box-shadow: none; }
.toggle-row.on .toggle::after { transform: translateX(20px); }
.detail:not(.on) .toggle-row.on .t-icon, .detail:not(.on) .toggle-row.on .toggle { background: var(--text-3); }
