/* Homebase — glass UI.
   Glass = backdrop blur + saturation, a gradient rim, a specular top edge and a
   layered shadow stack, over a slowly moving colour field that reflects the
   house: warm when home, cool blue when away. Works in Safari (no SVG
   displacement filters, which WebKit doesn't support in backdrop-filter). */

:root {
  --bg: #0a0c13;
  --text: rgba(255, 255, 255, .96);
  --muted: rgba(255, 255, 255, .58);
  --faint: rgba(255, 255, 255, .34);
  --hair: rgba(255, 255, 255, .12);
  --fill: rgba(255, 255, 255, .08);
  --fill-strong: rgba(255, 255, 255, .16);
  --heat-1: #ffb057;
  --heat-2: #ff6a3d;
  --ok: #4cd97b;
  --danger: #ff5a5f;
  --warn: #ffc44d;
  --radius: 28px;
  --blob-1: #ff7a3c;
  --blob-2: #ff3d7f;
  --blob-3: #7b5cff;
  --blob-4: #ffb23f;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.4, .5, 1);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body[data-mode="away"] {
  --blob-1: #2a63ff;
  --blob-2: #13b5d4;
  --blob-3: #5a3cff;
  --blob-4: #1d3fb8;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100dvh; overflow-x: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid rgba(255, 255, 255, .75); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }

/* ── Ambient colour field ─────────────────────────────────────────────────── */

.ambient { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: var(--bg); }
.ambient::after {           /* fine grain keeps the gradients from banding */
  content: ""; position: absolute; inset: 0; opacity: .07; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.ambient i {
  position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%;
  filter: blur(80px); opacity: .55; transition: background-color 1.6s var(--ease);
  animation: drift 26s ease-in-out infinite alternate;
}
.ambient i:nth-child(1) { background: var(--blob-1); top: -20vmax; left: -15vmax; }
.ambient i:nth-child(2) { background: var(--blob-2); top: 10vmax; right: -25vmax; animation-duration: 32s; animation-delay: -8s; }
.ambient i:nth-child(3) { background: var(--blob-3); bottom: -30vmax; left: 5vmax; animation-duration: 38s; animation-delay: -16s; }
.ambient i:nth-child(4) { background: var(--blob-4); bottom: -10vmax; right: 0; width: 35vmax; height: 35vmax; opacity: .35; animation-duration: 22s; }

@keyframes drift {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(6vmax, 4vmax) scale(1.08); }
  100% { transform: translate(-4vmax, 8vmax) scale(.95); }
}

/* ── Glass ────────────────────────────────────────────────────────────────── */

.glass {
  position: relative;
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, .05) 55%, rgba(255, 255, 255, .08));
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  backdrop-filter: blur(30px) saturate(180%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .38),      /* specular top edge */
    inset 0 -1px 0 rgba(255, 255, 255, .05),
    inset 0 0 0 1px rgba(255, 255, 255, .05),
    0 1px 2px rgba(0, 0, 0, .18),
    0 12px 32px -10px rgba(0, 0, 0, .45),
    0 40px 80px -30px rgba(0, 0, 0, .5);
}
.glass::before {            /* gradient rim: bright where light hits */
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(160deg, rgba(255, 255, 255, .55), rgba(255, 255, 255, .1) 30%, rgba(255, 255, 255, 0) 55%, rgba(255, 255, 255, .22));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

/* ── Views ────────────────────────────────────────────────────────────────── */

.login, .app { display: none; }
body[data-view="login"] .login { display: grid; }
body[data-view="app"] .app { display: block; }

.login { min-height: 100dvh; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%); padding: 40px 28px 28px; text-align: center;
  display: grid; gap: 14px; animation: rise .6s var(--ease) both;
}
.login-card h1 { font-size: 30px; letter-spacing: -.02em; font-weight: 700; }
.login-card .muted { margin-bottom: 8px; }
.logo {
  width: 64px; height: 64px; margin: 0 auto 6px; border-radius: 20px;
  background: url("icon.svg") center / cover;
  box-shadow: 0 10px 30px -8px rgba(255, 106, 61, .6);
}
.field {
  width: 100%; height: 52px; padding: 0 18px; border-radius: 16px; font: inherit; font-size: 17px;
  color: var(--text); background: rgba(0, 0, 0, .22); border: 1px solid var(--hair);
  transition: border-color .2s, background .2s;
}
.field::placeholder { color: var(--faint); }
.field:focus { outline: none; border-color: rgba(255, 255, 255, .45); background: rgba(0, 0, 0, .3); }
.btn {
  height: 52px; border-radius: 16px; font-weight: 600; font-size: 17px;
  background: var(--fill-strong); transition: transform .15s var(--ease), filter .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--heat-1), var(--heat-2)); color: #1d0c03; box-shadow: 0 8px 24px -8px rgba(255, 106, 61, .8); }
.btn[aria-busy="true"] { opacity: .6; }
.error { color: #ff9a9d; min-height: 20px; font-size: 15px; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(.98); } }

.app {
  width: min(1040px, 100%); margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.app > * { animation: rise .6s var(--ease) both; }
.app > *:nth-child(2) { animation-delay: .05s; }
.app > *:nth-child(3) { animation-delay: .1s; }

/* ── Hero / presence ──────────────────────────────────────────────────────── */

.hero { padding: 26px; margin-bottom: 14px; }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.hero h1 { font-size: clamp(32px, 7vw, 44px); font-weight: 700; letter-spacing: -.03em; line-height: 1.05; margin: 6px 0 8px; }
.hero-sub { color: var(--muted); font-size: 16px; }
.hero-sub b { color: var(--text); font-weight: 600; }

.segmented {
  --w: 116px;
  position: relative; display: grid; grid-template-columns: repeat(2, var(--w));
  padding: 5px; border-radius: 999px; background: rgba(0, 0, 0, .25);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(255, 255, 255, .06);
}
.segmented button {
  position: relative; z-index: 1; height: 50px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; font-size: 16px; color: var(--muted); transition: color .3s;
}
.segmented svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.segmented button[aria-checked="true"] { color: var(--text); }
.segmented .thumb {
  position: absolute; top: 5px; left: 5px; width: var(--w); height: 50px; border-radius: 999px;
  background: linear-gradient(145deg, rgba(255, 255, 255, .34), rgba(255, 255, 255, .14));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55), 0 6px 18px -6px rgba(0, 0, 0, .5);
  transition: transform .5s var(--spring);
}
body[data-mode="away"] .segmented .thumb { transform: translateX(var(--w)); }

.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.checklist:not(:empty) { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--hair); }
.checklist li { display: flex; align-items: center; gap: 12px; padding: 7px 0; font-size: 15px; animation: rise .35s var(--ease) both; }
.checklist .detail { color: var(--muted); font-size: 13px; margin-left: auto; text-align: right; }
.check {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--fill); box-shadow: inset 0 0 0 1px var(--hair);
}
.check svg { width: 13px; height: 13px; fill: none; stroke: #0b0d14; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.check.working::after {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .25); border-top-color: var(--text); animation: spin .8s linear infinite;
}
.check.ok { background: var(--ok); box-shadow: 0 0 12px -2px var(--ok); }
.check.settling { background: transparent; box-shadow: inset 0 0 0 2px var(--ok); animation: breathe 1.6s ease-in-out infinite; }
.check.settling svg { stroke: var(--ok); }
@keyframes breathe { 50% { opacity: .45; } }
.check.failed { background: var(--danger); box-shadow: 0 0 12px -2px var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alerts ───────────────────────────────────────────────────────────────── */

.alerts { display: grid; gap: 10px; margin-bottom: 14px; }
.alerts:empty { display: none; }
.alert {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; padding: 16px 18px; border-radius: 22px;
  background: linear-gradient(145deg, rgba(255, 70, 80, .32), rgba(255, 70, 80, .12));
  animation: rise .4s var(--ease) both;
}
.alert.warning { background: linear-gradient(145deg, rgba(255, 190, 70, .28), rgba(255, 190, 70, .1)); }
.alert .icon {
  grid-row: span 3; width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center;
  background: var(--danger); box-shadow: 0 0 22px -4px var(--danger);
  animation: pulse 2s ease-in-out infinite;
}
.alert.warning .icon { background: var(--warn); box-shadow: 0 0 22px -4px var(--warn); animation: none; }
.alert .icon svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.alert.warning .icon svg { stroke: #2a1a00; }
.alert h3 { font-size: 16px; font-weight: 650; }
.alert p { font-size: 14px; color: rgba(255, 255, 255, .78); }
.alert .row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.alert .note { font-size: 12px; color: var(--muted); margin-left: auto; }
.chip {
  height: 32px; padding: 0 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: rgba(255, 255, 255, .16); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform .15s var(--ease), background .2s;
}
.chip:active { transform: scale(.95); }
.chip.solid { background: rgba(255, 255, 255, .9); color: #111; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 90, 95, .15), 0 0 26px -4px var(--danger); } }

/* ── Sections & rooms ─────────────────────────────────────────────────────── */

.section { margin-top: 26px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 6px 12px; }
.section-head h2 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.section-head .muted { font-size: 14px; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

.room { padding: 20px; display: flex; flex-direction: column; gap: 18px; transition: box-shadow .5s var(--ease), opacity .3s; overflow: hidden; }
.room.wide { grid-column: 1 / -1; }
.room::after {              /* warm glow behind heating cards */
  content: ""; position: absolute; inset: auto -30% -60% -30%; height: 120%; pointer-events: none; z-index: -1;
  background: radial-gradient(closest-side, rgba(255, 120, 50, .55), transparent);
  opacity: 0; transition: opacity .8s var(--ease);
}
.room.heating::after { opacity: .9; }
.room.idle::after { opacity: .3; }
.room.locked { opacity: .62; }
.room.attention { opacity: 1; }
.room.attention::before { padding: 1.5px; background: linear-gradient(160deg, var(--danger), rgba(255, 90, 95, .25) 50%, var(--danger)); }

.room-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.room-head h3 { font-size: 19px; font-weight: 650; letter-spacing: -.01em; }
.status { display: flex; align-items: center; gap: 7px; margin-top: 4px; font-size: 14px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.heating .status .dot, .unit.heating .dot { background: var(--heat-2); box-shadow: 0 0 10px var(--heat-2); animation: glow 2s ease-in-out infinite; }
.idle .status .dot, .unit.idle .dot { background: var(--heat-1); }
.offline .status .dot, .unit.offline .dot { background: var(--danger); }
@keyframes glow { 50% { opacity: .55; } }

.head-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--fill); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), inset 0 0 0 1px rgba(255, 255, 255, .06);
  transition: transform .2s var(--spring), background .3s, box-shadow .3s, color .3s;
  color: var(--muted);
}
.icon-btn:active:not(:disabled) { transform: scale(.88); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on {
  color: #2a0f00;
  background: linear-gradient(145deg, var(--heat-1), var(--heat-2));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 6px 20px -6px rgba(255, 106, 61, .9);
}
.icon-btn.linked { color: var(--text); background: var(--fill-strong); }
.icon-btn.small { width: 38px; height: 38px; }
.icon-btn.small svg { width: 17px; height: 17px; }

.readout { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.label { display: block; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); margin-bottom: 2px; }
.big { font-size: 58px; font-weight: 300; letter-spacing: -.04em; line-height: .95; font-variant-numeric: tabular-nums; }
.big sup { font-size: .45em; font-weight: 400; vertical-align: top; position: relative; top: .25em; margin-left: 2px; color: var(--muted); }

.stepper {
  display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 999px;
  background: rgba(0, 0, 0, .22); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .3), inset 0 0 0 1px rgba(255, 255, 255, .06);
}
.stepper button {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--fill); transition: transform .15s var(--spring), background .2s;
}
.stepper button:active:not(:disabled) { transform: scale(.85); background: var(--fill-strong); }
.stepper button:disabled { opacity: .35; }
.stepper svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.stepper .target { min-width: 66px; text-align: center; }
.stepper .target .label { margin: 0; font-size: 10px; }
.stepper .target b { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stepper.pending .target b { color: var(--heat-1); }
.stepper.small button { width: 36px; height: 36px; }
.stepper.small .target { min-width: 54px; }
.stepper.small .target b { font-size: 17px; }
.off-room .stepper .target b, .unit.off .stepper .target b { color: var(--muted); }

.room-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); margin-top: -6px; }

.units { display: grid; gap: 10px; }
.unit {
  display: grid; grid-template-columns: 1fr auto auto; grid-template-areas: "info step power"; align-items: center; gap: 12px;
  padding: 12px 12px 12px 16px; border-radius: 20px; background: rgba(255, 255, 255, .06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
}
.unit .name { font-weight: 600; font-size: 15px; }
.unit .meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.unit .meta .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.unit .info { grid-area: info; min-width: 0; }
.unit .stepper { grid-area: step; }
.unit .icon-btn { grid-area: power; }

/* ── Footer & toast ───────────────────────────────────────────────────────── */

.foot { display: flex; justify-content: space-between; align-items: center; margin-top: 30px; padding: 0 6px; font-size: 13px; color: var(--faint); }
.foot #conn { display: flex; align-items: center; gap: 8px; }
.foot .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.foot.down .dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.link { color: var(--muted); font-size: 13px; padding: 8px 0; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 10;
  transform: translate(-50%, 140%); opacity: 0; padding: 14px 20px; border-radius: 18px;
  font-size: 15px; max-width: min(440px, calc(100% - 32px)); text-align: center;
  transition: transform .45s var(--spring), opacity .3s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 520px) {
  .hero { padding: 22px 18px; }
  .hero-top { flex-direction: column; align-items: stretch; }
  .segmented { --w: calc((100vw - 32px - 36px - 10px) / 2); }
  .big { font-size: 52px; }
  .unit { grid-template-columns: 1fr auto; grid-template-areas: "info power" "step step"; }
  .unit .stepper { justify-content: space-between; }
}

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