/* Layout: one-screen app shell (top bar, a scrolling view, bottom tabs). Devices are
   drawn as glass keypad buttons whose LED ring glows lamp-amber when on. */
:root {
  --accent: #e8a23a;            /* replaced at runtime by the user's colour */
  --bg: #ecede9;                /* plaster */
  --surface: #f8f8f5;
  --surface-2: #e2e4df;
  --line: #cdd1cb;
  --fg: #1b2125;
  --muted: #5b646a;
  --accent-ink: color-mix(in oklab, var(--accent) 58%, #000);
  --accent-soft: color-mix(in oklab, var(--accent) 22%, var(--surface));
  --cool: #2a7fb2;
  --heat: #c9562a;
  --grass: #a9c79b;
  --wood: #c8a983;
  --fabric: #9aa7ae;
  --fixture: #fbfbf8;
  --water: #6fbfdf;
  --leaf: #5f9a5a;
  --screen: #23292d;
  --ok: #3b8757;
  --danger: #b83c2b;
  --scrim: rgb(18 22 25 / 0.45);
  --shadow: 0 1px 2px rgb(20 26 30 / 0.08), 0 8px 24px rgb(20 26 30 / 0.08);
  --font-display: "Secular One", "IBM Plex Sans Hebrew", system-ui, "Segoe UI", Arial, sans-serif;
  --font-body: "IBM Plex Sans Hebrew", system-ui, "Segoe UI", Arial, sans-serif;
  --radius: 14px;
  --tap: 48px;
  --font-scale: 1;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111518;
    --surface: #191f23;
    --surface-2: #222a2f;
    --line: #2e373d;
    --fg: #e9e7e2;
    --muted: #9aa3a8;
    --accent-ink: color-mix(in oklab, var(--accent) 80%, #fff);
    --accent-soft: color-mix(in oklab, var(--accent) 20%, var(--surface));
    --cool: #6bc0ea;
    --heat: #f08a5a;
    --grass: #2e4632;
    --wood: #6e5a44;
    --fabric: #4d585e;
    --fixture: #8b959a;
    --water: #2d6f8f;
    --leaf: #3c6a3f;
    --screen: #0c0f11;
    --ok: #6cc08a;
    --danger: #ef7a66;
    --scrim: rgb(0 0 0 / 0.55);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 10px 28px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111518;
  --surface: #191f23;
  --surface-2: #222a2f;
  --line: #2e373d;
  --fg: #e9e7e2;
  --muted: #9aa3a8;
  --accent-ink: color-mix(in oklab, var(--accent) 80%, #fff);
  --accent-soft: color-mix(in oklab, var(--accent) 20%, var(--surface));
  --cool: #6bc0ea;
  --heat: #f08a5a;
  --grass: #2e4632;
  --wood: #6e5a44;
  --fabric: #4d585e;
  --fixture: #8b959a;
  --water: #2d6f8f;
  --leaf: #3c6a3f;
  --screen: #0c0f11;
  --ok: #6cc08a;
  --danger: #ef7a66;
  --scrim: rgb(0 0 0 / 0.55);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 10px 28px rgb(0 0 0 / 0.3);
  color-scheme: dark;
}
:root.high-contrast { --line: var(--fg); --muted: var(--fg); --surface-2: var(--surface); }

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
html { font-size: calc(16px * var(--font-scale)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 1.2em; height: 1.2em; flex: none; vertical-align: -0.2em; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; line-height: 1.2; text-wrap: balance; margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after { transition: none !important; animation: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--bg);
}
.topbar h1 { font-size: 1.45rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 0.8rem; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--heat); }
.pill.demo { color: var(--accent-ink); }
.view { overflow-y: auto; min-height: 0; padding-inline: 16px; padding-block: 4px 24px; }
.view.full { padding: 0; overflow: hidden; position: relative; }

.tabbar {
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: var(--tap); border: 0; background: none; color: var(--muted);
  font-size: 0.75rem; border-radius: 10px; padding: 4px 2px;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent-ink); }
.tab[aria-current="page"] svg { filter: drop-shadow(0 0 6px color-mix(in oklab, var(--accent) 60%, transparent)); }

/* ------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 500;
}
.btn svg { width: 20px; height: 20px; flex: none; }
a.btn { text-decoration: none; color: inherit; }
.btn.primary { background: var(--accent); border-color: transparent; color: #1b1406; }
.btn.quiet { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn { width: var(--tap); padding: 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-block: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented .chip { min-height: 44px; }

input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 36px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 0.9rem; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}
textarea.input { min-height: 120px; resize: vertical; }

/* The glass key: a device button with an LED ring. */
.key {
  position: relative; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  width: 100%; min-height: 64px; padding: 10px 14px; text-align: start;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: linear-gradient(160deg, color-mix(in oklab, var(--surface) 92%, #fff), var(--surface));
}
.key .led {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; padding: 0;
  border: 2px solid var(--line); background: transparent; color: var(--muted); transition: all 0.25s ease;
}
.key .title { min-width: 0; min-height: 44px; padding: 0; border: 0; background: none; text-align: start; display: grid; align-content: center; }
.key .led svg { width: 22px; height: 22px; }
.key[data-on="true"] .led {
  border-color: var(--accent); color: var(--accent-ink);
  background: var(--accent-soft);
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--accent) 18%, transparent), 0 0 18px color-mix(in oklab, var(--accent) 45%, transparent);
}
.key[data-kind="ac"][data-on="true"] .led { border-color: var(--cool); color: var(--cool); background: color-mix(in oklab, var(--cool) 15%, var(--surface)); box-shadow: 0 0 16px color-mix(in oklab, var(--cool) 40%, transparent); }
.key[data-kind="ac"][data-mode="heat"][data-on="true"] .led { border-color: var(--heat); color: var(--heat); background: color-mix(in oklab, var(--heat) 15%, var(--surface)); box-shadow: 0 0 16px color-mix(in oklab, var(--heat) 40%, transparent); }
.key .title strong { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key .title small { color: var(--muted); font-size: 0.85rem; }
.key .value { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.95rem; }
.key .star { position: absolute; inset-block-start: 6px; inset-inline-start: 6px; width: 12px; height: 12px; color: var(--accent); }
.key.pending { opacity: 0.7; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.section { display: grid; gap: 12px; padding-block: 12px; }
.section > header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section h2 { font-size: 1.25rem; }
.section h3 { font-size: 1.05rem; }
.eyebrow { font-size: 0.78rem; letter-spacing: 0.06em; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 10px; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }
.banner { position: relative; z-index: 5; margin: 12px 16px; gap: 4px; }
.placing { gap: 8px; background: color-mix(in oklab, var(--surface) 92%, transparent); backdrop-filter: blur(10px); }
.placing .chip svg { width: 14px; height: 14px; color: var(--ok); }
progress { width: 100%; height: 8px; accent-color: var(--accent); }

/* ------------------------------------------------------------- 3D house */
.stage { position: absolute; inset: 0; }
.stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.overlay-top { position: absolute; inset-inline: 0; top: 0; padding: 8px 16px; display: grid; gap: 8px; pointer-events: none; }
.overlay-top > * { pointer-events: auto; }
.summary { display: flex; flex-wrap: wrap; gap: 8px; }
.summary .pill { background: color-mix(in oklab, var(--surface) 86%, transparent); backdrop-filter: blur(8px); color: var(--fg); }
.summary .pill::before { display: none; }
.summary .pill svg { width: 16px; height: 16px; color: var(--accent-ink); }
.overlay-bottom { position: absolute; inset-inline: 0; bottom: 0; padding: 8px 16px 12px; pointer-events: none; }
.overlay-bottom .chips { pointer-events: auto; }
.fav {
  flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px 0 10px;
  border-radius: 999px; border: 1px solid var(--line);
  background: color-mix(in oklab, var(--surface) 88%, transparent); backdrop-filter: blur(8px);
}
.fav svg { width: 20px; height: 20px; color: var(--muted); }
.fav[data-on="true"] { border-color: var(--accent); }
.fav[data-on="true"] svg { color: var(--accent-ink); }
.hint { font-size: 0.8rem; color: var(--muted); text-align: center; }

/* ---------------------------------------------------------------- sheet */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 20; animation: fade 0.2s ease; }
.sheet {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 21; max-height: 88%; overflow-y: auto;
  background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  animation: rise 0.25s ease;
}
.sheet .grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet header h2 { flex: 1; font-size: 1.3rem; min-width: 0; }
@media (min-width: 720px) { .sheet { inset-inline: auto 24px; bottom: 24px; width: 420px; border-radius: 22px; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.big-toggle {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  min-height: 64px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface-2);
  font-size: 1.1rem; font-weight: 600;
}
.big-toggle svg { width: 26px; height: 26px; }
.big-toggle[aria-checked="true"] { background: var(--accent); border-color: transparent; color: #1b1406; }
.temp { display: flex; align-items: center; justify-content: center; gap: 18px; }
.temp output { font-family: var(--font-display); font-size: 3rem; min-width: 3ch; text-align: center; font-variant-numeric: tabular-nums; }
.temp .btn { width: 56px; height: 56px; border-radius: 50%; font-size: 1.6rem; padding: 0; }
.blind-visual { width: 64px; height: 80px; border: 3px solid var(--line); border-radius: 6px; position: relative; overflow: hidden; background: color-mix(in oklab, var(--cool) 25%, var(--surface)); flex: none; }
.blind-visual i { position: absolute; inset-inline: 0; top: 0; background: repeating-linear-gradient(to bottom, var(--muted) 0 5px, var(--surface-2) 5px 8px); transition: height 0.4s ease; }

/* ----------------------------------------------------------------- chat */
.chat { display: grid; grid-template-rows: 1fr auto; height: 100%; min-height: 0; }
.messages { overflow-y: auto; padding: 8px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-start; background: var(--accent); color: #1b1406; border-end-start-radius: 4px; }
.msg.bot { align-self: flex-end; background: var(--surface); border: 1px solid var(--line); border-end-end-radius: 4px; }
.msg.notice { align-self: center; background: none; color: var(--muted); font-size: 0.85rem; }
.msg .did { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.msg .did span { display: inline-flex; align-items: center; gap: 4px; font-size: 0.8rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); }
.msg .did svg { width: 14px; height: 14px; color: var(--ok); }
.composer { display: grid; gap: 8px; padding: 8px 16px 12px; border-top: 1px solid var(--line); background: var(--bg); }
.composer form { display: flex; gap: 8px; }
.composer .input { flex: 1; min-width: 0; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; } .typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 50% { opacity: 0.25; } }
.mic[aria-pressed="true"] { background: var(--danger); color: #fff; border-color: transparent; }

/* ------------------------------------------------------------- settings */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--fg); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); }
.switch { appearance: none; width: 52px; height: 30px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); position: relative; flex: none; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--fg); transition: inset-inline-start 0.2s ease; }
.switch:checked { background: var(--accent); border-color: transparent; }
.switch:checked::after { inset-inline-start: 25px; background: #1b1406; }
.device-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding-block: 8px; border-bottom: 1px solid var(--line); }
.device-row:last-child { border-bottom: 0; }
.device-row .room-field { grid-column: 2; grid-row: 2; }
.room-pick { min-height: 36px; padding-block: 4px; font-size: 0.9rem; }
.icon-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.icon-pick button { height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; }
.icon-pick button svg { width: 24px; height: 24px; }
.icon-pick button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
details.card > summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }

.planner { width: 100%; height: auto; touch-action: none; background: var(--surface-2); border-radius: var(--radius); }
.planner .room rect.body { fill: var(--surface); stroke: var(--muted); stroke-width: 0.04; }
.planner .room.outdoor rect.body { fill: var(--grass); }
.planner .room.active rect.body { stroke: var(--accent); stroke-width: 0.08; }
.planner text { fill: var(--fg); font-family: var(--font-body); font-size: 0.42px; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.planner .handle { fill: var(--accent); }
.planner .gridline { stroke: var(--line); stroke-width: 0.02; }
.planner .piece { fill: color-mix(in oklab, var(--wood) 55%, var(--surface)); stroke: var(--muted); stroke-width: 0.03; }
.planner .piece.selected { stroke: var(--accent); stroke-width: 0.09; }
.planner .piece-back { stroke: var(--fg); stroke-width: 0.07; stroke-linecap: round; pointer-events: none; }
.planner.rooms-mode .furniture { pointer-events: none; opacity: 0.5; }
.planner.furniture-mode .room { pointer-events: none; }
.planner.furniture-mode .handle { display: none; }

.toast {
  position: fixed; inset-inline: 16px; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 30;
  margin-inline: auto; max-width: 480px; padding: 12px 16px; border-radius: 12px;
  background: var(--fg); color: var(--bg); box-shadow: var(--shadow); animation: rise 0.2s ease;
}
.toast.error { background: var(--danger); color: #fff; }

.login { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; }
.login form { width: min(380px, 100%); display: grid; gap: 14px; }
.login-box { width: min(380px, 100%); display: grid; gap: 14px; text-align: center; }
.login-box .field { text-align: start; }
.login-box h1 { margin: 0; }
.login-mark { justify-self: center; display: grid; place-items: center; width: 72px; height: 72px; border-radius: 22px;
  background: color-mix(in oklab, var(--accent) 18%, var(--surface)); color: var(--accent-ink, var(--fg)); }
.login-mark svg { width: 40px; height: 40px; }
.login-error { color: var(--danger); margin: 0; }
.btn.face-id { min-height: 60px; font-size: 1.1rem; }
.btn.face-id svg { width: 26px; height: 26px; }
.input.code { font-size: 1.4rem; letter-spacing: 0.4em; text-align: center; direction: ltr; }
.phone-row { justify-content: space-between; flex-wrap: nowrap; }
.phone-name { display: inline-flex; align-items: center; gap: 10px; }
.phone-name > span { display: grid; }
.phone-row svg { width: 22px; height: 22px; flex: none; }
.invite { display: grid; gap: 6px; padding: 12px; border-radius: 12px; border: 1px dashed var(--accent); text-align: center; }
.btn.google { background: #fff; color: #1f1f1f; border-color: #747775; font-weight: 500; }
.google-mark { width: 20px; height: 20px; flex: none; }
.login-or { display: grid; gap: 8px; margin-top: 6px; }
.family-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.family-list li { padding: 8px 12px; border-radius: 10px; background: color-mix(in oklab, var(--fg) 6%, transparent); }
.phone-name small { display: block; }
.invite-code { font-size: 2rem; letter-spacing: 0.3em; font-variant-numeric: tabular-nums; }
.inside-bar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 6px 6px 12px; box-shadow: var(--shadow); padding-inline-start: 14px; }
.enter-room { justify-self: start; width: auto; min-height: 40px; padding-block: 6px; font-size: 0.9rem; }
.overlay-top > .view-actions { gap: 8px; flex-wrap: wrap; justify-content: flex-start; pointer-events: none; }
.view-actions > * { pointer-events: auto; }
.view-actions .btn { min-height: 40px; padding-block: 6px; font-size: 0.9rem; }
.edit-bar { pointer-events: auto; display: grid; gap: 10px; }
.nudge { gap: 6px; }
.nudge .btn { min-width: 56px; justify-content: center; }
.btn.choice { width: 100%; justify-content: flex-start; text-align: start; gap: 12px; min-height: 56px; }
.btn.choice small { display: block; color: var(--muted); font-weight: 400; }
.btn.choice[data-on="true"] svg { color: var(--accent-ink); }
.planner .device-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 0.05; }
.planner .device-dot.kind-blind { fill: var(--cool); }
.planner .device-dot.kind-ac { fill: var(--heat); }
.planner .device-dot.moved { stroke: var(--fg); stroke-width: 0.07; }
.planner .device-dot.selected { stroke: var(--fg); stroke-width: 0.12; r: 0.3; }
.planner .device-facing { stroke: var(--fg); stroke-width: 0.05; pointer-events: none; }
.planner.devices-mode .room, .planner.devices-mode .furniture { pointer-events: none; }
.planner.devices-mode .furniture { opacity: 0.6; }
.planner.devices-mode .handle { display: none; }

/* The walking stick, bottom-left over the 3D view inside a room. */
.joystick {
  position: absolute; inset-inline-end: 18px; bottom: calc(100% + 10px);
  width: 108px; height: 108px; border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 70%, transparent); border: 2px solid var(--line);
  box-shadow: var(--shadow); display: grid; place-items: center; touch-action: none; pointer-events: auto;
}
.joystick .knob {
  width: 46px; height: 46px; border-radius: 50%; background: var(--accent); box-shadow: var(--shadow);
  pointer-events: none;
}
.chip.floor-chip { border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip.floor-chip svg { width: 16px; height: 16px; }
.btn.room-off { min-height: 38px; padding-block: 6px; font-size: 0.9rem; }
