:root {
  --bg: #F2F0EB;
  --tile: #E5E2DA;
  --tile-ink: #5A564E;
  --on: #FFFFFF;
  --on-ink: #1C1B19;
  --ink: #1C1B19;
  --muted: #77726A;
  --line: #DCD7CD;
  --sheet: #FAF9F6;
  --field: #FFFFFF;
  --chip: #E5E2DA;
  --accent: #1F6F66;
  --accent-ink: #FFFFFF;
  --alert: #C2412A;
  --alert-soft: #F5DFD7;
  --shadow: 0 1px 2px rgb(40 30 10 / .06), 0 4px 14px rgb(40 30 10 / .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --tile: #1F1E1C;
    --tile-ink: #A29D94;
    --on: #F1EEE7;
    --on-ink: #1C1B19;
    --ink: #F1EEE7;
    --muted: #8D887F;
    --line: #2E2C29;
    --sheet: #1A1918;
    --field: #232220;
    --chip: #232220;
    --accent: #5BB5A8;
    --accent-ink: #0D1917;
    --alert: #F0775C;
    --alert-soft: #3A211B;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 32px) max(16px, env(safe-area-inset-left));
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ic { flex: none; display: block; }

/* header */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 12px 0 16px; }
.top h1 { margin: 0; font-size: 32px; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; }
.status { margin: 4px 0 0; font-size: 13px; color: var(--muted); min-height: 18px; }
.status.err { color: var(--alert); }
.top-actions { display: flex; gap: 8px; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center; background: var(--chip); color: var(--ink); flex: none;
}
.iconbtn.active { background: var(--accent); color: var(--accent-ink); }
.spin .ic { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { margin: 0 0 14px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 14px; font-size: 14px; color: var(--muted); }
.banner strong { color: var(--ink); }

.alerts { margin: 0 0 16px; padding: 10px 12px; border-radius: 14px; background: var(--alert-soft); display: grid; gap: 6px; }
.alerts p { margin: 0; display: flex; gap: 8px; align-items: center; font-size: 14px; }
.alerts .ic { color: var(--alert); }

/* scenes */
.scenes {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px 8px; padding: 0 16px 8px; scroll-snap-type: x proximity;
}
.scenes::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: flex; align-items: center; gap: 8px; scroll-snap-align: start;
  padding: 10px 14px; border-radius: 14px; border: 0; background: var(--on); color: var(--on-ink);
  font-weight: 600; font-size: 15px; white-space: nowrap; box-shadow: var(--shadow);
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
}
.chip:active { transform: scale(.97); }
.chip.ghost { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
@media (prefers-color-scheme: dark) { .chip { background: var(--chip); color: var(--ink); } }

/* rooms and tiles */
.room { margin-top: 18px; }
.room-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 2px 10px; }
.room-head h2 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.link { border: 0; background: none; padding: 4px 0; color: var(--accent); font-size: 15px; font-weight: 600; }
.link.danger { color: var(--alert); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

.tile {
  display: flex; flex-direction: column; justify-content: space-between; gap: 14px;
  min-height: 108px; padding: 12px; border: 0; border-radius: 18px; text-align: left;
  background: var(--tile); color: var(--tile-ink);
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: background-color .18s ease, color .18s ease, transform .1s ease, opacity .18s ease;
}
.tile:active { transform: scale(.97); }
.tile.on { background: var(--on); color: var(--on-ink); box-shadow: var(--shadow); }
.tile-icon {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, currentColor 11%, transparent);
}
.tile.on .tile-icon { background: var(--glow, var(--accent)); color: #1C1B19; }
.tile.on.kind-switch .tile-icon { color: var(--accent-ink); }
.tile-text { display: grid; gap: 1px; min-width: 0; }
.tile-name { font-size: 15px; font-weight: 600; line-height: 1.25; color: inherit; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile:not(.on) .tile-name { color: var(--ink); }
.tile-sub { font-size: 13px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.alert { box-shadow: inset 0 0 0 2px var(--alert); }
.tile.alert .tile-sub { color: var(--alert); opacity: 1; font-weight: 600; }
.tile.offline { opacity: .55; }
.tile.pending { opacity: .7; }
.tile.is-hidden { opacity: .4; }

.empty { display: grid; place-items: center; gap: 8px; padding: 80px 0; color: var(--muted); text-align: center; }

/* sheets */
dialog.sheet {
  margin: auto auto 0; width: 100%; max-width: 560px; max-height: 90vh; padding: 0; border: 0;
  border-radius: 22px 22px 0 0; background: var(--sheet); color: var(--ink);
}
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 22px; } }
dialog.sheet::backdrop { background: rgb(0 0 0 / .38); }
dialog.sheet[open] { animation: rise .2s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet-body { padding: 18px 18px calc(24px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto; overscroll-behavior: contain; }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.sheet-icon { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--chip); flex: none; }
.sheet-title { flex: 1; min-width: 0; }
.sheet-title h3 { margin: 0; font-size: 20px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-title p { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.sheet-body h4 { margin: 22px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.control { padding: 12px 0; border-top: 1px solid var(--line); }
.control-label { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 15px; }
.control-label output { color: var(--muted); font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; }
input[type=range].warmth { accent-color: var(--muted); }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--line); padding: 0; }
.swatch.white { background: linear-gradient(135deg, #FFD9A0, #FFFFFF 55%, #CFE3FF); }

.readings { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 8px 0; }
.reading { padding: 10px 12px; border-radius: 12px; background: var(--chip); display: grid; gap: 2px; }
.reading span { font-size: 13px; color: var(--muted); }
.reading strong { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }

.note { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; padding: 10px 12px; border-radius: 12px; background: var(--chip); font-size: 14px; color: var(--ink); }
.note .ic { margin-top: 1px; color: var(--muted); }
.fine { margin: 8px 0; font-size: 13px; color: var(--muted); }

.field { margin: 10px 0; display: grid; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=time], select {
  width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--field); color: var(--ink); appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }

.toggle {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0;
  width: 51px; height: 31px; border-radius: 16px; background: var(--line); position: relative; transition: background .18s;
}
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .18s; }
.toggle:checked { background: var(--accent); }
.toggle:checked::after { transform: translateX(20px); }

.icon-pick { display: flex; gap: 8px; flex-wrap: wrap; }
.picks { display: grid; gap: 2px; margin: 8px 0 4px; }
.pick { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.pick input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; margin: 0; }
.pick-icon { width: 32px; height: 32px; border-radius: 50%; background: var(--chip); display: grid; place-items: center; flex: none; }
.pick-text { display: grid; min-width: 0; }
.pick-text small { color: var(--muted); font-size: 13px; }

.sheet-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.sheet-actions .btn:last-child { margin-left: auto; }
.btn { border: 0; border-radius: 12px; padding: 12px 18px; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 16px; }
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.danger { background: transparent; color: var(--alert); padding-left: 0; }

.room-list { display: grid; gap: 8px; }
.room-row { display: flex; gap: 6px; align-items: center; }
.room-row input { flex: 1; }
.add-room { display: flex; gap: 8px; margin-top: 10px; }
.add-room input { flex: 1; }

[hidden] { display: none !important; }
.block { display: block; }
small.block { font-size: 13px; color: var(--muted); font-weight: 400; }
.wide { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pill { border: 0; border-radius: 999px; padding: 8px 14px; background: var(--chip); font-size: 14px; font-weight: 600; }
.pill:active { background: var(--line); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; gap: 3px; border-radius: 12px; background: var(--chip); }
.seg button { border: 0; border-radius: 9px; padding: 9px 6px; background: transparent; font-size: 15px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--field); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day { aspect-ratio: 1; max-height: 44px; border: 0; border-radius: 50%; background: var(--chip); color: var(--muted); font-weight: 650; }
.day.active { background: var(--accent); color: var(--accent-ink); }

.sched-main { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 0; }
.row strong { font-weight: 600; }
.logline { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; font-size: 14px; }
.logline .ic { margin-top: 2px; color: var(--accent); }
.logline.bad .ic, .logline.bad { color: var(--alert); }

.siri { border-radius: 12px; background: var(--chip); padding: 0 12px; }
.siri summary { display: flex; align-items: center; gap: 8px; padding: 12px 0; font-weight: 600; cursor: pointer; list-style: none; }
.siri summary::-webkit-details-marker { display: none; }
.siri ol { margin: 0 0 8px; padding-left: 20px; font-size: 14px; display: grid; gap: 6px; }
.copyrow { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.copyrow code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; padding: 9px 10px; border-radius: 10px; background: var(--field); border: 1px solid var(--line); }
.copyrow:last-child { margin-bottom: 12px; }
.copyrow .iconbtn { background: var(--field); }

/* sign in */
.login { max-width: 360px; margin: 14vh auto 0; display: grid; gap: 12px; text-align: center; }
.login h1 { margin: 0; font-size: 30px; }
.login p { margin: 0; color: var(--muted); }
.login .err { color: var(--alert); }
.login-icon { width: 64px; height: 64px; margin: 0 auto; border-radius: 18px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 14px; z-index: 10;
  background: var(--ink); color: var(--bg); font-size: 15px; box-shadow: 0 6px 24px rgb(0 0 0 / .2);
}
.toast[hidden] { display: none; }

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