
/* ── tokens ─────────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Jakarta';
  src: url('/assets/jakarta.woff2') format('woff2');
  font-weight: 400 800;
  font-display: swap;
}

:root {
  /* surfaces: a deliberate ramp, each step ~4% lighter, single light source */
  --bg:            #07090D;
  --surface-1:     #0D1117;
  --surface-2:     #141A22;
  --surface-3:     #1C242E;
  --surface-hi:    #26303C;
  --line:          #232C38;
  --line-soft:     #1A222C;

  --text:          #EEF2F7;
  --text-2:        #9AA7B8;
  --text-3:        #7C8AA0;

  /* Never overridden. Used by anything that is not the climate control itself,
     so switching a unit off cannot grey out the tab bar, the pairing code or
     the primary buttons. */
  --brand:         #38BDF8;

  /* mode accents */
  --accent:        #38BDF8;
  --accent-deep:   #0EA5E9;
  --accent-glow:   rgba(56, 189, 248, .16);
  --accent-ink:    #04121C;

  --danger:        #F87171;
  --ok:            #4ADE80;
  --warn:          #FBBF24;

  --r-sm: 10px;  --r-md: 16px;  --r-lg: 22px;  --r-xl: 30px;  --r-full: 999px;

  /* one elevation scale, used consistently */
  --e1: 0 1px 2px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.03);
  --e2: 0 4px 16px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.045);
  --e3: 0 18px 48px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.06);

  --dur-fast: 140ms;
  --dur:      220ms;
  --dur-slow: 380ms;
  --ease:     cubic-bezier(.32, .72, 0, 1);
  --spring:   cubic-bezier(.34, 1.4, .64, 1);

  --tap: 44px;                      /* minimum touch target */
}

[data-mode="COOL"] { --accent:#38BDF8; --accent-deep:#0284C7; --accent-glow:rgba(56,189,248,.17); --accent-ink:#04121C }
[data-mode="HEAT"] { --accent:#FB923C; --accent-deep:#EA580C; --accent-glow:rgba(251,146,60,.17); --accent-ink:#1C0A02 }
[data-mode="DRY"]  { --accent:#2DD4BF; --accent-deep:#0D9488; --accent-glow:rgba(45,212,191,.16); --accent-ink:#021513 }
[data-mode="FAN"]  { --accent:#A8B6C8; --accent-deep:#64748B; --accent-glow:rgba(168,182,200,.13); --accent-ink:#0B0F14 }
[data-mode="AUTO"] { --accent:#A78BFA; --accent-deep:#7C3AED; --accent-glow:rgba(167,139,250,.16); --accent-ink:#0F0720 }
/* Light ink, because the grey this pairs with is too dark to carry dark text. */
[data-off="true"]  { --accent:#5A6779; --accent-deep:#3B4757; --accent-glow:rgba(90,103,121,.10); --accent-ink:#EEF2F7 }

* , *::before, *::after { box-sizing: border-box; margin: 0; padding: 0 }

html { -webkit-text-size-adjust: 100% }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Jakarta', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  /* atmosphere: one soft pool of light behind the active device */
  background-image: radial-gradient(120% 60% at 50% -10%, var(--accent-glow), transparent 62%);
  transition: background-image var(--dur-slow) var(--ease);
}

/* honour the OS setting rather than animating regardless */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

button, input, select { font: inherit; color: inherit }
button { background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
         touch-action: manipulation }

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}
/* The dial is a circle, so its ring must be too. */
.dial:focus-visible { border-radius: 50% }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── layout ─────────────────────────────────────────────────────────────── */
.app {
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 18px)
    calc(env(safe-area-inset-right) + 18px)
    calc(env(safe-area-inset-bottom) + 84px)
    calc(env(safe-area-inset-left) + 18px);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 24px; min-height: var(--tap);
}
.brand { display: flex; align-items: center; gap: 10px }
.brand h1 {
  font-size: 17px; font-weight: 700; letter-spacing: -.02em;
}
/* Reports whether anything at all is running, so it must not follow the
   selected unit either. */
.brand .dot {
  width: 8px; height: 8px; border-radius: var(--r-full);
  background: var(--text-3); box-shadow: none;
  transition: background var(--dur), box-shadow var(--dur);
}
.brand .dot[data-any-on="true"] {
  background: #38BDF8; box-shadow: 0 0 12px #38BDF8;
}
.brand .sub { font-size: 12px; color: var(--text-3); font-weight: 500 }

.icon-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-2);
  box-shadow: var(--e1);
  transition: transform var(--dur-fast) var(--spring),
              background var(--dur-fast), color var(--dur-fast);
}
.icon-btn:active { transform: scale(.93); background: var(--surface-3) }
.icon-btn svg { width: 20px; height: 20px }
/* Re-reading the units takes a moment, so say so rather than looking dead. */
.icon-btn.busy { color: var(--accent); pointer-events: none }
.icon-btn.busy svg { animation: spin .8s linear infinite }

/* ── room selector (horizontal, scrolls when there are many) ────────────── */
.rooms {
  display: flex; gap: 8px; overflow-x: auto;
  /* Padding, not just margin: overflow-x makes this a scroll container on both
     axes, which was clipping the focus ring and the lit dot off the top edge. */
  padding: 6px 0; margin: -6px 0 18px;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.rooms::-webkit-scrollbar { display: none }

.room-chip {
  flex: 0 0 auto; scroll-snap-align: start;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 15px; min-height: var(--tap);
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: transform var(--dur-fast) var(--spring), background var(--dur),
              color var(--dur), border-color var(--dur);
}
.room-chip:active { transform: scale(.96) }
.room-chip[aria-selected="true"] {
  background: var(--surface-hi); color: var(--text); border-color: var(--accent);
}
/* Each dot reports its OWN unit, using that unit's mode colour. It must not
   read the global --accent: that is driven by whichever unit is selected, so
   selecting an idle unit would grey out the dots of units that are running. */
.room-chip { --led: var(--text-3) }
.room-chip[data-devmode="COOL"] { --led: #38BDF8 }
.room-chip[data-devmode="HEAT"] { --led: #FB923C }
.room-chip[data-devmode="DRY"]  { --led: #2DD4BF }
.room-chip[data-devmode="FAN"]  { --led: #A8B6C8 }
.room-chip[data-devmode="AUTO"] { --led: #A78BFA }

.room-chip .led {
  width: 7px; height: 7px; border-radius: var(--r-full);
  background: var(--text-3); flex: 0 0 auto;
  transition: background var(--dur), box-shadow var(--dur);
}
.room-chip[data-on="true"] .led {
  background: var(--led);
  box-shadow: 0 0 8px var(--led), 0 0 2px var(--led);
}
.room-chip[data-offline="true"] { opacity: .45 }
.room-chip[data-offline="true"] .led { background: var(--danger); box-shadow: none }

/* ── the dial: the signature control ────────────────────────────────────── */
.dial-wrap { display: grid; place-items: center; margin: 4px 0 20px }

.dial {
  position: relative;
  width: min(310px, 78vw);
  aspect-ratio: 1;
  display: grid; place-items: center;
  touch-action: none;                 /* we own the drag gesture */
  user-select: none; -webkit-user-select: none;
}
.dial svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible }

.dial-track { stroke: var(--surface-3); stroke-width: 12; fill: none; stroke-linecap: round }
.dial-fill {
  stroke: var(--accent); stroke-width: 12; fill: none; stroke-linecap: round;
  filter: drop-shadow(0 0 14px var(--accent-glow));
  transition: stroke-dashoffset var(--dur) var(--ease), stroke var(--dur-slow);
}
.dial-ticks line { stroke: var(--line); stroke-width: 2; stroke-linecap: round }
.dial-ticks line.on { stroke: var(--accent); opacity: .55 }

.dial-face {
  position: relative; z-index: 2;
  width: 74%; aspect-ratio: 1; border-radius: var(--r-full);
  background:
    radial-gradient(120% 120% at 30% 22%, var(--surface-3), var(--surface-1) 62%);
  border: 1px solid var(--line);
  box-shadow: var(--e3);
  display: grid; place-items: center; align-content: center; gap: 2px;
  text-align: center;
}

.temp {
  font-size: clamp(56px, 19vw, 78px);
  font-weight: 700; letter-spacing: -.045em; line-height: 1;
  font-variant-numeric: tabular-nums;   /* digits never shift width */
  display: flex; align-items: flex-start; justify-content: center;
}
.temp .deg { font-size: .36em; font-weight: 600; margin-top: .42em; color: var(--text-2) }
.temp[data-off="true"] { color: var(--text-3) }

.dial-mode {
  font-size: 11px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--accent);
}
.dial-room {
  font-size: 12.5px; color: var(--text-3); font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.dial-knob {
  position: absolute; z-index: 3; width: 26px; height: 26px; border-radius: var(--r-full);
  background: var(--accent);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 14px rgba(0,0,0,.7);
  pointer-events: none;
  transition: transform var(--dur-fast) var(--ease);
}
.dial.dragging .dial-knob { transform: scale(1.22) }
.dial.dragging .dial-fill { transition: none }
.dial[aria-disabled="true"] { opacity: .5; pointer-events: none }

/* ── power ──────────────────────────────────────────────────────────────── */
.power-row { display: flex; justify-content: center; margin: 0 0 20px }
.power {
  display: inline-flex; align-items: center; gap: 10px;
  height: 50px; padding: 0 24px; border-radius: var(--r-full);
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text-2); font-weight: 650; font-size: 14.5px;
  letter-spacing: .01em; box-shadow: var(--e1);
  transition: transform var(--dur-fast) var(--spring), background var(--dur),
              color var(--dur), border-color var(--dur);
}
.power:active { transform: scale(.96) }
.power[data-on="true"] {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); box-shadow: var(--e2), 0 0 26px var(--accent-glow);
}
.power svg { width: 18px; height: 18px }

/* ── segmented controls ─────────────────────────────────────────────────── */
.group { margin-bottom: 20px }
.group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: 10px; padding-left: 2px;
}
/* a heading that starts a new block further down the page */
.spaced-label { margin-top: 26px }

/* an action that belongs to the list above it, but is not part of it */
.btn.spaced { margin-top: 22px }

/* explanatory text under a section */
.note {
  font-size: 12.5px; line-height: 1.6; color: var(--text-3);
  margin-top: 12px; padding: 0 2px;
}

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: 4px; padding: 4px;
  background: var(--surface-1); border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
}
.seg button {
  min-height: 40px; border-radius: 11px;
  display: grid; place-items: center; gap: 3px;
  color: var(--text-3); font-size: 11.5px; font-weight: 650;
  transition: background var(--dur-fast), color var(--dur-fast),
              transform var(--dur-fast) var(--spring);
}
.seg button svg { width: 17px; height: 17px }
.seg button:active { transform: scale(.94) }
.seg button[aria-pressed="true"] {
  background: var(--surface-hi); color: var(--text);
  box-shadow: var(--e1);
}
.seg button[aria-pressed="true"] svg { color: var(--accent) }

/* ── toggles ────────────────────────────────────────────────────────────── */
/* Row gap larger than the column gap, so the destructive All off below reads
   as its own thing rather than as a fourth comfort setting. */
.toggles { display: grid; grid-template-columns: repeat(3, 1fr);
           column-gap: 8px; row-gap: 14px }
.toggle {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 11px 14px;
  background: var(--surface-1); border: 1px solid var(--line);
  border-radius: var(--r-md); color: var(--text-2);
  font-size: 13.5px; font-weight: 600; justify-content: center;
  transition: background var(--dur-fast), color var(--dur-fast),
              border-color var(--dur-fast), transform var(--dur-fast) var(--spring);
}
.toggle:active { transform: scale(.97) }
.toggle svg { width: 17px; height: 17px; flex: 0 0 auto }
/* Only the narrowest phones need this. At 400px it was shrinking the type on
   375, 390 and 393 wide screens, which have room to spare. */
@media (max-width: 350px) {
  .toggle { gap: 6px; padding: 11px 8px; font-size: 12px }
}
.toggle[aria-pressed="true"] {
  background: var(--surface-hi); color: var(--text); border-color: var(--accent);
}
.toggle[aria-pressed="true"] svg { color: var(--accent) }
/* Acts on every unit rather than the selected one, so it gets its own row and
   is coloured as the destructive action it is. */
.toggle.wide {
  grid-column: 1 / -1; justify-content: center;
  color: var(--danger); border-color: color-mix(in srgb, var(--danger) 32%, transparent);
}
.toggle.wide svg { color: var(--danger) }

/* A control that does nothing must not look identical to one that works. */
.toggle[disabled], .power[disabled] {
  opacity: .38; pointer-events: none; box-shadow: none;
  border-color: var(--line-soft);
}

/* ── cards / sheets ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface-1); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: 16px; box-shadow: var(--e1);
}
.card + .card { margin-top: 12px }
.card h3 { font-size: 14.5px; font-weight: 700; margin-bottom: 4px; letter-spacing: -.01em }
.card p  { font-size: 13.5px; color: var(--text-2); line-height: 1.55;
           overflow-wrap: anywhere }

/* a proposed multi-rule plan, numbered so the order of thresholds reads clearly */
.plan { margin-top: 14px; border-left: 2px solid var(--line); padding-left: 0 }
.plan-step {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 11px 0 11px 13px; position: relative;
}
.plan-step + .plan-step { border-top: 1px solid var(--line-soft) }
.plan-num {
  flex: 0 0 auto; width: 21px; height: 21px; border-radius: var(--r-full);
  display: grid; place-items: center; margin-top: 1px;
  background: var(--surface-hi); color: var(--brand);
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.plan-step .t { font-size: 13.5px; font-weight: 650; margin-bottom: 3px;
                overflow-wrap: anywhere }
.plan-step .s { font-size: 12.5px; color: var(--text-3); line-height: 1.5;
                overflow-wrap: anywhere }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 20px }
.stat {
  background: var(--surface-1); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: 12px 10px; text-align: center;
}
.stat .k {
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: 4px;
}
.stat .v {
  font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.stat .v small { font-size: .6em; color: var(--text-3); font-weight: 600 }

/* ── bottom navigation (max 5, icon + label) ────────────────────────────── */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px);
}
.nav button {
  display: grid; place-items: center; gap: 4px; min-height: var(--tap);
  color: var(--text-3); font-size: 10.5px; font-weight: 650; letter-spacing: .01em;
  border-radius: var(--r-md); transition: color var(--dur-fast), transform var(--dur-fast) var(--spring);
}
.nav button:active { transform: scale(.93) }
/* The selected tab used to be signalled by the mode accent alone, which greys
   out when the unit is off: the tab bar then lost its selected state entirely.
   Now it is a fixed colour, a heavier weight and a rail, so it never depends on
   colour alone. */
.nav button { position: relative }
.nav button[aria-current="page"] { color: var(--text); font-weight: 700 }
.nav button[aria-current="page"] svg { color: var(--brand) }
.nav button[aria-current="page"]::before {
  content: ''; position: absolute; top: -8px;
  width: 24px; height: 2px; border-radius: 0 0 2px 2px; background: var(--brand);
}
.nav button svg { width: 21px; height: 21px }

/* ── forms ──────────────────────────────────────────────────────────────── */
.field { margin-bottom: 14px }
.field label {
  display: block; font-size: 12.5px; font-weight: 650; color: var(--text-2);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; min-height: var(--tap); padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-md); color: var(--text); font-size: 16px; /* 16px stops iOS zoom */
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.field textarea { min-height: 88px; resize: vertical; line-height: 1.5 }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent); background: var(--surface-3);
}
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 6px }
.field .err  { font-size: 12.5px; color: var(--danger); margin-top: 6px; font-weight: 600 }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 12px 20px; width: 100%;
  border-radius: var(--r-md); font-weight: 700; font-size: 14.5px;
  background: var(--brand); color: #04121C;
  box-shadow: var(--e2);
  transition: transform var(--dur-fast) var(--spring), opacity var(--dur-fast);
}
.btn:active { transform: scale(.975) }
/* Fading it to 45% made the label unreadable. An inert control should look
   inert, not blurred. */
.btn[disabled] {
  background: var(--surface-3); color: var(--text-3);
  box-shadow: none; opacity: 1; pointer-events: none;
}
.btn.secondary { background: var(--surface-3); color: var(--text); box-shadow: var(--e1) }
.btn.danger    { background: none; color: var(--danger); border: 1px solid var(--danger);
                 box-shadow: none }
.btn svg { width: 18px; height: 18px }
/* Also used on the sign-in page, which has no .btn around it. Scoped to .btn
   it rendered as a 0 by 0 box: the one screen whose job is to say "something is
   happening" showed nothing at all. */
.spin {
  width: 16px; height: 16px; border-radius: var(--r-full);
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ── list rows ──────────────────────────────────────────────────────────── */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; background: var(--surface-1);
  border: 1px solid var(--line-soft); border-radius: var(--r-md);
}
.row + .row { margin-top: 8px }
.row .grow { flex: 1; min-width: 0 }
.row .t { font-size: 14px; font-weight: 650; margin-bottom: 2px }
.row .s { font-size: 12.5px; color: var(--text-3) }
.row .s b { color: var(--text-2); font-weight: 650 }

.switch {
  position: relative; width: 46px; height: 28px; border-radius: var(--r-full);
  background: var(--surface-hi); flex: 0 0 auto; transition: background var(--dur);
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: var(--r-full); background: #8996A8;
  transition: transform var(--dur) var(--spring), background var(--dur);
}
.switch[aria-pressed="true"] { background: color-mix(in srgb, var(--brand) 40%, transparent) }
.switch[aria-pressed="true"]::after { transform: translateX(18px); background: var(--brand) }

/* ── empty / offline states ─────────────────────────────────────────────── */
.empty {
  text-align: center; padding: 46px 22px; color: var(--text-3);
}
.empty svg { width: 40px; height: 40px; margin-bottom: 14px; color: var(--surface-hi) }
.empty h3 { font-size: 15px; color: var(--text-2); margin-bottom: 6px; font-weight: 650 }
.empty p { font-size: 13.5px; line-height: 1.6; max-width: 34ch; margin: 0 auto }

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--r-md); margin-bottom: 14px;
  font-size: 13px; line-height: 1.5;
  background: color-mix(in srgb, var(--warn) 10%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  color: var(--text-2);
}
.banner svg { width: 17px; height: 17px; color: var(--warn); flex: 0 0 auto; margin-top: 1px }
.banner.err { background: color-mix(in srgb, var(--danger) 10%, var(--surface-1));
              border-color: color-mix(in srgb, var(--danger) 32%, transparent) }
.banner.err svg { color: var(--danger) }

/* ── views ──────────────────────────────────────────────────────────────── */
.view { display: none; animation: viewin var(--dur) var(--ease) }
.view.active { display: block }
@keyframes viewin { from { opacity: 0; transform: translateY(7px) } to { opacity: 1; transform: none } }

/* ── toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; z-index: 60;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translate(-50%, 14px);
  padding: 11px 18px; border-radius: var(--r-full);
  background: var(--surface-hi); border: 1px solid var(--line);
  color: var(--text); font-size: 13.5px; font-weight: 600;
  box-shadow: var(--e3); opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--spring);
  max-width: calc(100vw - 40px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) }
.toast.err { border-color: var(--danger); color: var(--danger) }

/* ── skeleton (avoids layout shift while loading) ───────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 37%, var(--surface-1) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
  border-radius: var(--r-md);
}
@keyframes shimmer { from { background-position: 100% 0 } to { background-position: -100% 0 } }

/* ── login ──────────────────────────────────────────────────────────────── */
.auth {
  min-height: 100dvh; display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top) + 24px) 22px calc(env(safe-area-inset-bottom) + 24px);
}
.auth-card { width: 100%; max-width: 380px; text-align: center }
.auth-mark {
  width: 68px; height: 68px; margin: 0 auto 22px; border-radius: 21px;
  display: grid; place-items: center;
  background: radial-gradient(120% 120% at 30% 22%, var(--surface-3), var(--surface-1) 65%);
  border: 1px solid var(--line); box-shadow: var(--e3);
}
.auth-mark svg { width: 31px; height: 31px; color: var(--accent) }
.auth h1 { font-size: 25px; font-weight: 700; letter-spacing: -.03em; margin-bottom: 8px }
.auth .lede { font-size: 14px; color: var(--text-2); line-height: 1.6; margin-bottom: 26px }
.auth .alt {
  margin-top: 18px; font-size: 13px; color: var(--text-3);
  background: none; width: auto; padding: 12px; font-weight: 600;
}
.auth .alt:hover { color: var(--text-2) }

/* pairing code: big, unambiguous, easy to read aloud */
.paircode {
  font-size: 44px; font-weight: 700; letter-spacing: .22em;
  font-variant-numeric: tabular-nums;
  color: var(--accent); text-align: center;
  padding: 20px 10px 20px 22px;
  background: radial-gradient(120% 120% at 30% 22%, var(--surface-3), var(--surface-1) 68%);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--e2); margin-bottom: 18px;
  user-select: all;
}
.waitrow {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 13.5px; color: var(--text-2); font-weight: 600;
}
.okmark {
  width: 62px; height: 62px; margin: 0 auto 18px; border-radius: var(--r-full);
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--ok) 16%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--ok) 42%, transparent);
  color: var(--ok);
}
.okmark svg { width: 30px; height: 30px }

.pending-code {
  font-size: 20px; font-weight: 700; letter-spacing: .12em;
  color: var(--brand); font-variant-numeric: tabular-nums;
  flex: 0 0 auto; padding-right: 4px;
}
.row.pending { border-color: color-mix(in srgb, var(--accent) 45%, transparent) }
.row-actions { display: flex; gap: 6px; flex: 0 0 auto }
.mini {
  min-height: 38px; padding: 0 13px; border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 700;
  background: var(--surface-3); color: var(--text);
  transition: transform var(--dur-fast) var(--spring), background var(--dur-fast);
}
.mini:active { transform: scale(.94) }
.mini.go { background: var(--brand); color: #04121C }
.mini.no { background: transparent; color: var(--danger);
           border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent) }

.help { margin-top: 26px; text-align: left }
.help summary {
  cursor: pointer; list-style: none; text-align: center;
  font-size: 13px; font-weight: 650; color: var(--text-3);
  padding: 12px; min-height: var(--tap);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.help summary::-webkit-details-marker { display: none }
.help summary::after { content: '+'; font-weight: 700; opacity: .7 }
.help[open] summary::after { content: '\2212' }
.help summary:hover { color: var(--text-2) }
.help-body {
  background: var(--surface-1); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: 15px 16px; margin-top: 4px;
}
.help-body p { font-size: 13px; color: var(--text-2); line-height: 1.6 }
.help-body p + p, .help-body ol { margin-top: 11px }
.help-body b { color: var(--text); font-weight: 650 }
.help-body ol { padding-left: 19px }
.help-body li {
  font-size: 13px; color: var(--text-2); line-height: 1.6; margin-bottom: 7px;
}

@media (min-width: 700px) {
  .app { max-width: 620px }
  .toggle { padding: 12px 16px; font-size: 14px }
}


/* ── the language sheet ─────────────────────────────────────────────────── */
.editor {
  background: var(--surface-1); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: 16px; box-shadow: var(--e1);
  margin-top: 12px;
}
.editor h3 { font-size: 14.5px; font-weight: 700; margin-bottom: 4px }
.editor .muted { font-size: 13.5px; color: var(--text-2); line-height: 1.55 }
.checks { margin: 14px 0 4px }
.check {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap); padding: 10px 12px;
  border-radius: var(--r-md); background: var(--surface-2);
  border: 1px solid var(--line); font-size: 14px; cursor: pointer;
}
.check + .check { margin-top: 8px }
.check input { accent-color: var(--brand); width: 20px; height: 20px; flex: 0 0 auto }

/* ── odds and ends ──────────────────────────────────────────────────────── */
/* Long room names used to paint across the dial ring instead of truncating. */
.dial-room {
  max-width: 74%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-2);
}
.dial-mode { max-width: 82%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
/* An address or a joined list of room names has no break opportunities, so it
   used to paint straight over the buttons at the end of the row. */
.row .t, .row .s, .card h3 { overflow-wrap: anywhere }
.icon-btn { flex: 0 0 auto }
.room-chip .room-name {
  max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Offline used to be signalled by dimming alone, which took the label under the
   readable threshold. A dashed edge says it without hiding the text. */
.room-chip[data-offline="true"] {
  opacity: 1; color: var(--text-3); background: var(--surface-1);
  border-style: dashed; border-color: var(--line-soft);
}
/* The suffix used to stay bright while the number it belongs to dimmed. */
.temp .deg { color: currentColor; opacity: .72 }
/* The fan reads a word, not a number, so it needs its own size to sit on the
   same baseline as the two figures beside it. */
.stat .v.word { font-size: 15px; line-height: 28.5px }
/* Both segmented rows to one height, with real breathing room. Mode carries an
   icon and a label, so it needs more than the fan row. */
.seg button { min-height: 44px; padding: 6px 4px }
#modeSeg button { min-height: 50px }
/* Line the tab bar up with the content column on a wide screen. */
.nav { padding-inline: max(calc(env(safe-area-inset-left) + 8px),
                           calc((100% - 620px) / 2)) }
/* Stop long-press text selection, which is the clearest tell that something is
   a web page rather than an app. Anything worth copying stays selectable. */
body { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none }
input, textarea, .paircode, .card p, .row .s { -webkit-user-select: text; user-select: text }
/* Nothing responded to a pointer before, so on a desktop or tablet the whole
   interface felt dead until it was clicked. */
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover, .mini:hover { background: var(--surface-3); color: var(--text) }
  .room-chip:hover, .toggle:hover:not([disabled]) { border-color: var(--line); color: var(--text) }
  .seg button:hover:not([aria-pressed="true"]) { color: var(--text-2) }
  .nav button:hover { color: var(--text-2) }
  .btn:hover:not([disabled]) { filter: brightness(1.08) }
  .row:hover { border-color: var(--line) }
}
/* Reduced motion should not remove the only sign that something is loading, so
   the spinners fade instead of turning. */
@media (prefers-reduced-motion: reduce) {
  .icon-btn.busy svg, .spin {
    animation: pulse 1.2s ease-in-out infinite !important;
    animation-duration: 1.2s !important;
  }
}
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }
/* The dot reports whether anything is running, so it belongs on the title line
   rather than floating in the gap between the two lines. */
.brand .dot { align-self: flex-start; margin-top: 9px }
.dial-face { gap: 5px }

/* ── acting on every room at once ───────────────────────────────────────── */
/* Two actions of equal weight, kept out of the three column comfort grid so
   neither reads as a fourth comfort setting. */
.all-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px }
.all-row .btn { padding: 12px 14px; font-size: 14px }

.global {
  margin-top: 14px; padding: 16px;
  background: var(--surface-1); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--e2);
}
.global h3 { font-size: 15px; font-weight: 700; margin-bottom: 4px }
.global .scope {
  font-size: 12.5px; color: var(--text-2); line-height: 1.55; margin-bottom: 16px;
}
.global .group { margin-bottom: 16px }
.global .group:last-of-type { margin-bottom: 0 }
/* Close is a direct child, appended after the last group whose bottom margin is
   zeroed, so without this it sits flush against the comfort toggles above it. */
.global > .btn { margin-top: 18px }
/* The temperature is chosen first and sent once, rather than firing a command
   at every room on each tap of the arrows. */
.temp-set { display: grid; grid-template-columns: var(--tap) 1fr var(--tap); gap: 10px;
            align-items: center; margin-bottom: 10px }
.temp-set .val {
  text-align: center; font-size: 30px; font-weight: 750;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.temp-set .val small { font-size: 14px; font-weight: 650; color: var(--text-2); margin-left: 2px }
.temp-step {
  width: var(--tap); height: var(--tap); display: grid; place-items: center;
  border-radius: var(--r-md); background: var(--surface-2);
  border: 1px solid var(--line); color: var(--text);
  font-size: 22px; font-weight: 600; line-height: 1;
}
.temp-step:active { transform: scale(.94) }
.temp-step[disabled] { opacity: .38; pointer-events: none }

/* ── temperature calibration ────────────────────────────────────────────── */
.cal-row {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px;
  align-items: end; margin: 12px 0 14px;
}
.cal-row .arrow { padding-bottom: 13px; color: var(--text-3); font-size: 16px }
.cal-field label {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-3); margin-bottom: 7px;
}
.cal-field select, .cal-field input {
  width: 100%; min-height: var(--tap); padding: 11px 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-md); color: var(--text);
  font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums;
  text-align: center;
}
.cal-field input:focus-visible, .cal-field select:focus-visible { border-color: var(--brand) }
.cal-done {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 12px;
}
.cal-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 10px 7px 12px; border-radius: var(--r-full);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums;
}
.cal-chip button {
  width: 22px; height: 22px; border-radius: var(--r-full);
  display: grid; place-items: center; color: var(--text-3);
  background: var(--surface-3); font-size: 15px; line-height: 1;
}
.cal-chip button:active { transform: scale(.9) }
