:root {
  color-scheme: light;
  --bg: #efeae3;
  --ink: #1c1c1e;
  --muted: rgba(60, 60, 67, 0.62);
  --faint: rgba(60, 60, 67, 0.36);
  --card: rgba(255, 255, 255, 0.58);
  --card-strong: rgba(255, 255, 255, 0.78);
  --stroke: rgba(255, 255, 255, 0.72);
  --stroke-soft: rgba(255, 255, 255, 0.38);
  --shadow: 0 18px 40px rgba(84, 58, 28, 0.1);
  --shadow-soft: 0 8px 24px rgba(84, 58, 28, 0.06);
  --field: rgba(255, 255, 255, 0.66);
  --button: #1c1c1e;
  --button-ink: #fff;
  --amber: #ff9f0a;
  --green: #28a745;
  --teal: #32ade6;
  --danger: #ff3b30;
  --tile: rgba(255, 255, 255, 0.46);
  --tile-on: rgba(255, 255, 255, 0.86);
  --icon-off: #8e8e93;
  --ring: rgba(255, 159, 10, 0.45);
  --theme-color: #f3efe8;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #09090b;
    --ink: #f5f5f7;
    --muted: rgba(235, 235, 245, 0.6);
    --faint: rgba(235, 235, 245, 0.38);
    --card: rgba(44, 44, 46, 0.62);
    --card-strong: rgba(58, 58, 60, 0.78);
    --stroke: rgba(255, 255, 255, 0.14);
    --stroke-soft: rgba(255, 255, 255, 0.08);
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.28);
    --field: rgba(44, 44, 46, 0.8);
    --button: #f5f5f7;
    --button-ink: #1c1c1e;
    --tile: rgba(44, 44, 46, 0.55);
    --tile-on: rgba(72, 72, 74, 0.9);
    --icon-off: #aeaeb2;
    --theme-color: #09090b;
    --green: #30d158;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #09090b;
  --ink: #f5f5f7;
  --muted: rgba(235, 235, 245, 0.6);
  --faint: rgba(235, 235, 245, 0.38);
  --card: rgba(44, 44, 46, 0.62);
  --card-strong: rgba(58, 58, 60, 0.78);
  --stroke: rgba(255, 255, 255, 0.14);
  --stroke-soft: rgba(255, 255, 255, 0.08);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.28);
  --field: rgba(44, 44, 46, 0.8);
  --button: #f5f5f7;
  --button-ink: #1c1c1e;
  --tile: rgba(44, 44, 46, 0.55);
  --tile-on: rgba(72, 72, 74, 0.9);
  --icon-off: #aeaeb2;
  --theme-color: #09090b;
  --green: #30d158;
}

:root[data-theme="light"] {
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { position: relative; z-index: 1; }

.ambient { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.85;
}
.blob-a { width: 420px; height: 420px; background: #ffd7a8; top: -120px; right: -80px; }
.blob-b { width: 360px; height: 360px; background: #c9e7ff; bottom: -80px; left: -100px; }
.blob-c { width: 240px; height: 240px; background: #ffe1ef; top: 40%; left: 30%; opacity: 0.7; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .blob { opacity: 0.28; }
  :root:not([data-theme="light"]) .blob-a { background: #8a4b12; }
  :root:not([data-theme="light"]) .blob-b { background: #123a66; }
  :root:not([data-theme="light"]) .blob-c { background: #5c2348; }
}
:root[data-theme="dark"] .blob { opacity: 0.28; }
:root[data-theme="dark"] .blob-a { background: #8a4b12; }
:root[data-theme="dark"] .blob-b { background: #123a66; }
:root[data-theme="dark"] .blob-c { background: #5c2348; }

.screen {
  width: min(480px, 100%);
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
}

.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.mark {
  width: 84px;
  height: 84px;
  border-radius: 28px;
  display: grid;
  place-items: center;
  background: var(--card-strong);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(180%);
  margin-bottom: 22px;
  color: var(--amber);
}
.mark svg { width: 40px; height: 40px; }

h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1.05;
  letter-spacing: -0.035em;
  font-weight: 700;
}
.lede {
  margin: 8px 0 28px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.35;
}

.glass {
  background: var(--card);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border-radius: 28px;
  padding: 18px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 12px 4px 8px;
}
label:first-child { margin-top: 0; }

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--field);
  border: 1px solid var(--stroke-soft);
  border-radius: 16px;
  min-height: 52px;
  padding: 0 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 16px;
  padding: 14px 0;
}
.ghost {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 0;
}

.primary, .secondary {
  width: 100%;
  border: 0;
  border-radius: 16px;
  min-height: 52px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.primary {
  margin-top: 16px;
  background: var(--button);
  color: var(--button-ink);
  box-shadow: var(--shadow-soft);
}
.primary:disabled { opacity: 0.55; }
.secondary {
  margin-top: 10px;
  background: transparent;
  color: var(--muted);
}
.danger {
  width: 100%;
  margin-top: 8px;
  border: 0;
  border-radius: 16px;
  min-height: 52px;
  background: var(--danger);
  color: #fff;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 6;
  background: rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: min(480px, 100%);
  margin: 0;
  border-radius: 28px 28px 0 0;
  padding: 10px 20px calc(22px + env(safe-area-inset-bottom));
  max-height: min(86dvh, 760px);
  overflow: auto;
}
.sheet h2 {
  margin: 8px 0 0;
  font-size: 28px;
  letter-spacing: -0.03em;
}
.sheet .lede { margin: 6px 0 4px; }
.sheet-label {
  margin: 18px 0 6px;
  font-size: 15px;
  letter-spacing: -0.02em;
}
.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 999px;
  margin: 4px auto 8px;
  background: var(--faint);
}
.room-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.room-row, .room-add { display: flex; gap: 8px; align-items: center; }
.room-row input, .room-add input, .tile-alias, .tile-room {
  width: 100%;
  border: 0;
  border-radius: 14px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  min-height: 44px;
}
.room-add { margin-top: 10px; }
.text-btn {
  border: 0;
  background: transparent;
  color: var(--danger);
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  padding: 8px 4px;
  white-space: nowrap;
}
.room-add .text-btn { color: var(--ink); }
.edit-toggle { min-height: 40px; padding: 8px 12px; }
.actions { display: flex; gap: 8px; align-items: center; }
.error {
  margin: 12px 4px 0;
  color: var(--danger);
  font-size: 14px;
  line-height: 1.35;
}
.hint {
  margin: 14px 6px 0;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.4;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: var(--card);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px) saturate(160%);
  display: grid;
  place-items: center;
  color: var(--ink);
}
.icon-btn svg { width: 18px; height: 18px; }

.stats {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(148px, 1fr);
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin: 0 -20px 18px;
  padding-left: 20px;
  padding-right: 20px;
  scroll-snap-type: x mandatory;
}
.stats::-webkit-scrollbar { display: none; }
.stat {
  scroll-snap-align: start;
  min-height: 86px;
  border-radius: 24px;
  padding: 14px 14px 12px;
  background: var(--card);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(22px) saturate(170%);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.stat-kicker {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.stat-kicker svg { width: 16px; height: 16px; }
.stat strong {
  font-size: 22px;
  letter-spacing: -0.03em;
  font-weight: 680;
}

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 16px;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--stroke-soft);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 620;
  white-space: nowrap;
}
.chip.active {
  background: var(--button);
  color: var(--button-ink);
  border-color: transparent;
}

.section { margin-bottom: 18px; }
.section h2 {
  margin: 0 0 10px;
  font-size: 20px;
  letter-spacing: -0.03em;
}
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tile {
  aspect-ratio: 2 / 1;
  border: 1px solid var(--stroke);
  background: var(--tile);
  border-radius: 22px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px) saturate(160%);
  padding: 12px 14px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  text-align: left;
  transform: translate3d(0, 0, 0);
  will-change: transform;
  backface-visibility: hidden;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.tile.is-toggle { cursor: pointer; }
.tile.is-toggle:active { transform: scale(0.97); }
.tile.is-editing {
  aspect-ratio: auto;
  min-height: 210px;
  cursor: default;
  flex-direction: column;
  align-items: stretch;
}
.tile-edit { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.tile-origin {
  color: var(--faint);
  font-size: 11px;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile.is-on { background: var(--tile-on); box-shadow: var(--shadow); }
.tile.is-on.domain-light { box-shadow: 0 12px 32px rgba(255, 159, 10, 0.16), var(--shadow-soft); }
.tile.is-busy { opacity: 0.72; }
.tile.is-dead { opacity: 0.48; }
.tile-icon {
  width: 36px;
  height: 36px;
  color: var(--icon-off);
}
.tile.is-on.domain-light .tile-icon { color: var(--amber); }
.tile.is-on.domain-switch .tile-icon { color: var(--green); }
.domain-climate .tile-icon, .domain-sensor .tile-icon, .domain-media .tile-icon { color: var(--teal); }
.tile-icon svg { width: 32px; height: 32px; }
.tile-name {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile-state {
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 550;
  line-height: 1.15;
}
.tile-metric .tile-state {
  color: var(--ink);
  font-size: 20px;
  font-weight: 680;
  letter-spacing: -0.04em;
  margin: 0;
}
.tile-metric .tile-name { font-size: 12px; font-weight: 600; color: var(--muted); }

.banner {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--card-strong);
  border: 1px solid var(--stroke);
  color: var(--muted);
  font-size: 14px;
}
.empty {
  padding: 28px 8px;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  background: var(--button);
  color: var(--button-ink);
  border-radius: 16px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: 0.2s ease;
  z-index: 5;
  max-width: min(420px, calc(100% - 32px));
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.filters.rooms { margin-top: -8px; }
button.stat { color: inherit; text-align: left; }
.tile-copy { min-width: 0; }
.tile-state {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile-thermo {
  grid-column: 1 / -1;
  aspect-ratio: auto;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 12px 16px 12px;
}
.thermo-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.thermo-head .tile-copy { flex: 1; }
.tile-thermo .tile-name { font-size: 15px; }
.tile-thermo .tile-state { font-size: 12px; }
.thermo-status { color: var(--muted); font-size: 12px; font-weight: 650; }
.thermo-arc { width: 100%; height: auto; display: block; touch-action: none; overflow: visible; }
.tile.is-editing .thermo-arc,
.tile.is-editing .thermo-modes,
.tile.is-editing .thermo-stepper { pointer-events: none; }
.thermo-arc .track,
.thermo-arc .value { fill: none; stroke-width: 14; stroke-linecap: round; }
.thermo-arc .track { stroke: color-mix(in srgb, var(--ink) 14%, transparent); }
.thermo-arc .value { stroke: var(--amber); }
.tile-thermo.is-cool .thermo-arc .value { stroke: #3b8beb; }
.tile-thermo.is-off .thermo-arc .value { stroke: color-mix(in srgb, var(--ink) 28%, transparent); }
.thermo-arc .knob { fill: var(--card-strong); stroke: var(--ink); stroke-width: 3; }
.thermo-arc text { font-family: inherit; }
.thermo-arc .target { fill: var(--ink); font-size: 32px; font-weight: 680; }
.thermo-arc .now,
.thermo-arc .end { fill: var(--muted); font-size: 12px; font-weight: 600; }
.thermo-stepper { display: flex; justify-content: center; gap: 10px; margin: 0 0 8px; }
.thermo-step {
  width: 48px;
  height: 36px;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.28);
  color: var(--ink);
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
  backdrop-filter: blur(16px) saturate(160%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), var(--shadow-soft);
}
.thermo-step:active { transform: scale(0.96); }
.thermo-modes { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.thermo-mode {
  border: 1px solid var(--stroke);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  min-height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 650;
}
.thermo-mode.active { background: var(--button); color: var(--button-ink); border-color: transparent; }
.thermo-note { margin: 4px 0 0; text-align: center; color: var(--faint); font-size: 11px; }
.tile-media {
  grid-column: 1 / -1;
  aspect-ratio: auto;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 14px 16px;
  cursor: pointer;
}
.media-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.media-head .tile-copy { flex: 1; }
.tile-media .tile-name { font-size: 16px; }
.media-power, .media-gear, .media-step, .media-open, .remote-key {
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.28);
  color: var(--ink);
  backdrop-filter: blur(16px) saturate(160%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), var(--shadow-soft);
}
.media-power, .media-gear {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding: 0;
}
.media-power svg, .media-gear svg { width: 18px; height: 18px; }
.tile-media.is-on .media-power { background: var(--ink); color: var(--button-ink); border-color: transparent; }
.media-now { min-width: 0; }
.media-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.media-artist { color: var(--muted); font-size: 12px; font-weight: 600; }
.media-volume {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
}
.media-volume-label {
  text-align: center;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.media-step, .media-open {
  min-height: 44px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 650;
}
.media-step { width: 100%; padding: 0; }
.media-open { width: 100%; }
.source-picker { max-height: 46dvh; overflow: auto; margin-top: 8px; }
.tile.is-editing .media-power,
.tile.is-editing .media-gear,
.tile.is-editing .media-volume,
.tile.is-editing .media-open { pointer-events: none; }
.media-sheet-now { margin: 8px 0 0; font-size: 17px; font-weight: 650; }
.remote-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}
.remote-key { min-height: 48px; border-radius: 16px; font-size: 14px; font-weight: 650; }
.source-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.source-list .field-label { width: 100%; margin: 0; }
.thermo-config { display: flex; flex-direction: column; gap: 14px; }
.thermo-config[hidden] { display: none !important; }
.field-hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.35; }
.thermo-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 18px;
  border: 1px solid var(--stroke);
  background: color-mix(in srgb, var(--tile) 88%, transparent);
  backdrop-filter: blur(18px) saturate(160%);
  box-shadow: var(--shadow-soft);
}
.thermo-search {
  width: 100%;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.28);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  min-height: 40px;
  padding: 0 12px;
  backdrop-filter: blur(12px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.thermo-sensors {
  max-height: 180px;
  overflow: auto;
  padding: 0 2px;
}
.thermo-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 2px;
  border-bottom: 1px solid var(--stroke-soft);
}
.thermo-row:last-child { border-bottom: 0; }
.thermo-row[hidden] { display: none !important; }
.thermo-row-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thermo-empty { padding: 8px 2px 4px; }
.active-list, .manage-list { max-height: 46dvh; overflow: auto; margin-top: 8px; }
.active-row, .manage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--stroke-soft);
}
.manage-row { justify-content: flex-start; }
.sheet input[type="range"] { width: 100%; accent-color: var(--amber); }
.sheet input[type="color"] {
  width: 100%;
  height: 48px;
  border: 0;
  background: transparent;
  padding: 0;
}
.wall-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.swatch {
  width: 72px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 16px;
  border: 2px solid transparent;
  box-shadow: var(--shadow-soft);
}
.swatch.active { border-color: var(--ink); }
body[data-wall="custom"] {
  background-image: var(--wall-image);
  background-size: cover;
  background-position: center;
}
body[data-wall="custom"] .blob { opacity: 0.22; }
body[data-wall="dusk"] .blob-a { background: #f3b6d0; }
body[data-wall="dusk"] .blob-b { background: #7a5cff; }
body[data-wall="dusk"] .blob-c { background: #ffd6a5; }
body[data-wall="sea"] .blob-a { background: #9ad7ff; }
body[data-wall="sea"] .blob-b { background: #d8fff2; }
body[data-wall="sea"] .blob-c { background: #b8c0ff; }
body[data-wall="forest"] .blob-a { background: #b7e4c7; }
body[data-wall="forest"] .blob-b { background: #40916c; }
body[data-wall="forest"] .blob-c { background: #d8f3dc; }
body[data-wall="night"] .blob-a,
body[data-wall="ink"] .blob-a { background: #243b55; }
body[data-wall="night"] .blob-b,
body[data-wall="ink"] .blob-b { background: #141e30; }
body[data-wall="night"] .blob-c,
body[data-wall="ink"] .blob-c { background: #3d5a80; }
body[data-wall="night"],
body[data-wall="ink"] {
  color-scheme: dark;
  --bg: #10141c;
  --ink: #f5f5f7;
  --muted: rgba(235, 235, 245, 0.68);
  --faint: rgba(235, 235, 245, 0.42);
  --card: rgba(28, 28, 30, 0.72);
  --card-strong: rgba(44, 44, 46, 0.86);
  --stroke: rgba(255, 255, 255, 0.16);
  --stroke-soft: rgba(255, 255, 255, 0.1);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.32);
  --field: rgba(44, 44, 46, 0.82);
  --button: #f5f5f7;
  --button-ink: #1c1c1e;
  --tile: rgba(44, 44, 46, 0.62);
  --tile-on: rgba(72, 72, 74, 0.92);
  --icon-off: #d1d1d6;
  color: var(--ink);
}
body[data-wall="ink"] { --bg: #050506; }
body[data-wall="night"] .blob,
body[data-wall="ink"] .blob { opacity: 0.35; }

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 2px 8px;
}
.label-row label {
  margin: 0;
  flex: 1;
  min-width: 0;
}
.help-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  margin: 0;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: var(--field);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}
.help-steps {
  margin: 16px 0 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.help-steps li { line-height: 1.4; }

.editor-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 18px 0 4px;
}
.field-block { display: flex; flex-direction: column; gap: 8px; }
.field-block[hidden] { display: none !important; }
.field-label {
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}
.editor-stack input:not(.glass-check),
.editor-stack select,
.sheet > .tile-alias,
.sheet > input[type="search"],
.sheet > .tile-alias {
  display: block;
  width: 100%;
  margin: 0;
}
.icon-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-option {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  border: 1px solid var(--stroke-soft);
  background: var(--field);
  color: var(--ink);
  display: grid;
  place-items: center;
  padding: 0;
}
.icon-option.active { outline: 2px solid var(--ink); outline-offset: 1px; }
.icon-option svg { width: 26px; height: 26px; }

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  margin: 0;
  border-radius: 14px;
  background: var(--field);
  color: var(--ink);
  font-size: 15px;
  font-weight: 650;
}
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.manage-row[hidden],
.manage-row.is-hidden,
.manage-group[hidden] { display: none !important; }
.integration-filter { margin: 14px 0 10px; }
.integration-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0 2px;
}
.integration-chips::-webkit-scrollbar { display: none; }
.integration-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 12px 0 8px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.28);
  color: var(--ink);
  font-size: 14px;
  font-weight: 620;
  backdrop-filter: blur(16px) saturate(160%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), var(--shadow-soft);
}
button.integration-chip { padding: 0 14px; }
.integration-chip.is-filtering {
  background: var(--button);
  color: var(--button-ink);
  border-color: transparent;
}
.integration-chip .count { color: var(--muted); font-size: 12px; font-weight: 650; }
.integration-chip.is-filtering .count { color: inherit; opacity: 0.72; }
.manage-bulk { display: flex; gap: 8px; margin: 2px 0 8px; }
.manage-bulk-btn {
  flex: 1;
  min-height: 40px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.28);
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  backdrop-filter: blur(16px) saturate(160%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), var(--shadow-soft);
}
.manage-bulk-btn:active { transform: scale(0.98); }
.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 14px;
  background: var(--field);
  color: var(--ink);
  display: grid;
  place-items: center;
  padding: 0;
}
.icon-btn svg { width: 22px; height: 22px; }

.slider-field { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.slider-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}
.apple-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.16), 0 8px 20px rgba(0, 0, 0, 0.06);
  background: linear-gradient(90deg, #3a3a3c, #fff6d8);
}
.apple-slider.slider-temp {
  background: linear-gradient(90deg, #ff9f43, #fff1d0 46%, #d7e6ff);
}
.apple-slider.slider-hue {
  background: linear-gradient(90deg, #ff3b30, #ffcc00, #34c759, #32ade6, #5856d6, #ff2d55);
}
.apple-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  border: 0.5px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
}
.apple-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  border: 0.5px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
}

.titles { flex: 1; min-width: 0; }
.eyebrow, h1.fit-line { cursor: pointer; }
.fit-line {
  display: block;
  width: 100%;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
}

.tile-icon {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  color: var(--icon-off);
  transition: color 0.28s ease, transform 0.28s ease, filter 0.28s ease;
}
.tile.is-on .tile-icon { transform: scale(1.06); }

body.is-editing .tile,
body.is-jiggling .tile {
  animation: jiggle 0.48s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
  transform: translate3d(0, 0, 0);
  will-change: transform;
  backface-visibility: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
body.is-editing .tile:nth-child(2n),
body.is-jiggling .tile:nth-child(2n) { animation-duration: 0.56s; animation-delay: -0.18s; }
body.is-editing .tile:nth-child(3n),
body.is-jiggling .tile:nth-child(3n) { animation-duration: 0.42s; animation-delay: -0.08s; }
@keyframes jiggle {
  0% { transform: translate3d(0, 0, 0) rotate(-0.85deg); }
  20% { transform: translate3d(0.2px, -0.2px, 0) rotate(0.35deg); }
  50% { transform: translate3d(0, 0.25px, 0) rotate(0.9deg); }
  75% { transform: translate3d(-0.2px, 0, 0) rotate(-0.25deg); }
  100% { transform: translate3d(0, 0, 0) rotate(-0.85deg); }
}
body.is-dragging-card, body.is-dragging-card * { user-select: none; -webkit-user-select: none; }
.tile.is-dragging {
  animation: none !important;
  opacity: 1;
  z-index: 30;
  margin: 0;
  pointer-events: none;
  will-change: transform;
  backface-visibility: hidden;
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.22);
}
.tile-gap {
  border-radius: 22px;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
  pointer-events: none;
}
.temp-tools { display: flex; gap: 8px; margin: 8px 0; }
.temp-tools .text-btn { min-height: 36px; }
.bell { position: relative; overflow: visible; }
.bell-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--card);
}
.confirm-actions { display: flex; gap: 10px; margin-top: 18px; }
.confirm-actions .primary,
.confirm-actions .secondary { margin-top: 0; }
.inbox-list { margin-top: 8px; }
.inbox-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--stroke-soft);
}
.inbox-card .primary { margin-top: 0; min-height: 44px; }
.inbox-card .primary:disabled { opacity: 0.45; }
.device-meta {
  margin: 16px 2px 0;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.4;
  word-break: break-all;
}
.tile.is-on.domain-light .tile-icon { filter: drop-shadow(0 0 10px rgba(255, 159, 10, 0.45)); }
.tile.is-on.domain-switch .tile-icon { filter: drop-shadow(0 0 8px rgba(48, 209, 88, 0.4)); }
.tile.is-on.domain-cover .tile-icon,
.tile.is-on.domain-lock .tile-icon { color: var(--teal); }

.stat.tone-light.is-live .stat-kicker svg { color: var(--amber); }
.stat.tone-switch.is-live .stat-kicker svg { color: var(--green); }
.stat.tone-open.is-live .stat-kicker svg { color: var(--danger); }
.stat.tone-open.is-clear .stat-kicker svg { color: var(--green); }
.stat.tone-light:not(.is-live) .stat-kicker svg,
.stat.tone-switch:not(.is-live) .stat-kicker svg { color: var(--faint); }
.icon-btn.is-alert { color: var(--danger); }
.icon-btn.is-clear { color: var(--green); }

input, select, textarea { font-family: var(--font); color: var(--ink); }
input::placeholder { color: var(--faint); font-family: var(--font); }

input.glass-check {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin: 0;
  flex: 0 0 auto;
  border-radius: 8px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 6px 16px rgba(0, 0, 0, 0.04);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
}
input.glass-check:checked {
  background: color-mix(in srgb, var(--ink) 88%, transparent);
  border-color: transparent;
}
input.glass-check:checked::after {
  content: "";
  width: 5px;
  height: 9px;
  border: solid var(--button-ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}
input.glass-check:indeterminate::after {
  content: "";
  width: 10px;
  height: 2px;
  border-radius: 2px;
  background: var(--ink);
}
.manage-group { margin-top: 8px; }
.manage-head { position: sticky; top: 0; }
.manage-title {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 720;
  padding: 0;
  text-align: left;
}
.manage-count { margin-left: auto; color: var(--muted); font-size: 13px; }
.manage-sub { padding-left: 28px; }
.manage-sub[hidden],
.manage-group[hidden] { display: none !important; }

.grip, .move-btn {
  border: 0;
  background: transparent;
  color: var(--ink);
  min-width: 28px;
  padding: 0;
}
.grip { color: var(--faint); letter-spacing: -2px; cursor: grab; touch-action: none; }
.room-row.is-drop, .section.is-drop, .chip.is-drop { outline: 2px solid var(--amber); outline-offset: 2px; }
.tile.is-dragging { opacity: 0.45; }

.slide-track {
  position: relative;
  height: 64px;
  margin-top: 18px;
  border-radius: 999px;
  background: var(--field);
  border: 1px solid var(--stroke);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.slide-label { color: var(--muted); font-weight: 680; pointer-events: none; }
.slide-knob {
  position: absolute;
  left: 6px;
  top: 6px;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #1c1c1e;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  touch-action: none;
  padding: 0;
}
.slide-knob svg { width: 22px; height: 22px; }

body[data-wall="night"] h1,
body[data-wall="night"] h2,
body[data-wall="night"] h3,
body[data-wall="night"] .tile-name,
body[data-wall="night"] .stat strong,
body[data-wall="night"] .manage-title,
body[data-wall="ink"] h1,
body[data-wall="ink"] h2,
body[data-wall="ink"] h3,
body[data-wall="ink"] .tile-name,
body[data-wall="ink"] .stat strong,
body[data-wall="ink"] .manage-title,
body[data-wall="night"] input,
body[data-wall="night"] select,
body[data-wall="ink"] input,
body[data-wall="ink"] select {
  color: var(--ink);
}
