:root {
  --bg: #101918; --card: #1a2523; --text: #edf3ed; --muted: #a8bab3; --line: #34463e;
  --accent: #c7ef93; --accent-text: #18251b; --on: #334b32; --on-text: #d6f4b7;
  --danger: #ff9c95; --radius: 20px; color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text); padding-bottom: env(safe-area-inset-bottom); }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.2; }
h1 { font-size: 1.3rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }

.bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
       gap: 1rem; padding: .7rem 1rem; padding-top: max(.7rem, env(safe-area-inset-top));
       background: var(--card); border-bottom: 1px solid var(--line); }
.bar h1 { margin: 0; }
nav { display: flex; gap: .25rem; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.narrow { max-width: 380px; margin: 12vh auto; }
.room { margin-bottom: 1.5rem; }
.grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.device { margin: 0; transition: opacity .2s; }
.device.busy { opacity: .55; pointer-events: none; }
.device.offline { opacity: .7; }

label { display: block; margin-bottom: .8rem; font-size: .9rem; color: var(--muted); }
input, select { display: block; width: 100%; margin-top: .3rem; padding: .65rem .75rem; font: inherit; color: var(--text);
                background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
input[type=range] { padding: 0; border: 0; background: none; accent-color: var(--accent); }

button { font: inherit; padding: .6rem .9rem; min-height: 44px; border-radius: 10px; border: 1px solid var(--line);
         background: var(--bg); color: var(--text); cursor: pointer; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; width: 100%; }
button.on { background: var(--on); color: var(--on-text); border-color: transparent; }
button.danger { color: var(--danger); }
button.link { background: none; border: 0; color: var(--muted); padding: .5rem .6rem; }
button.link.active { color: var(--text); font-weight: 600; }
button.small { min-height: 36px; padding: .35rem .7rem; font-size: .85rem; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.row { display: flex; gap: .5rem; margin-top: .6rem; }
.row > button { flex: 1; }
.row.wrap { flex-wrap: wrap; }
.row.wrap > button { flex: 1 1 30%; }
.big { font-size: 2rem; font-weight: 600; margin: .2rem 0; }
.big.small-big { font-size: 1.2rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; font-weight: 400; }
.error { color: var(--danger); min-height: 1.2em; margin: .4rem 0 0; }
.meter { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.meter > div { height: 100%; background: var(--accent); transition: width .3s; }
.slider { margin-top: .8rem; color: var(--text); }
details { margin-top: .8rem; border-top: 1px solid var(--line); padding-top: .6rem; }
summary { cursor: pointer; font-weight: 600; padding: .3rem 0; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .2rem .6rem; margin: .4rem 0; }
.check { display: flex; align-items: center; gap: .5rem; color: var(--text); margin: 0; font-size: .95rem; }
.check input { width: auto; margin: 0; }
img.map { display: block; width: 100%; height: auto; margin: .5rem 0; border-radius: 8px; background: var(--bg);
          min-height: 60px; cursor: zoom-in; image-rendering: pixelated; }

#viewer { position: fixed; inset: 0; z-index: 20; background: rgba(10, 12, 16, .96); }
#viewer-stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; }
#viewer-stage:active { cursor: grabbing; }
#viewer-img { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; user-select: none;
              image-rendering: pixelated; will-change: transform; }
#viewer-tools { position: absolute; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); display: flex; gap: .5rem; }
#viewer-tools button { min-width: 48px; background: rgba(32, 35, 42, .9); color: #eceef2; border-color: #3a3f4a; font-size: 1.05rem; }
.remote { margin-top: .8rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; max-width: 220px; margin: 0 auto; }

.choices { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.choice { display: flex; flex-direction: column; align-items: flex-start; gap: .2rem; text-align: left; padding: .8rem; }
.help { display: block; margin-top: .3rem; font-size: .8rem; }
#passkey-login { margin-top: .4rem; text-align: center; }
#passkey-login button { width: 100%; }
.or-sep { margin: .2rem 0 .6rem; }
img.qr { display: block; width: 220px; height: 220px; margin: .6rem 0; border-radius: 8px; background: #fff; }
code.secret { display: inline-block; margin: .4rem 0; padding: .4rem .6rem; border-radius: 8px; background: var(--bg);
              font-size: 1rem; letter-spacing: .05em; user-select: all; }
a.button { display: inline-block; padding: .6rem .9rem; border-radius: 10px; background: var(--accent);
           color: var(--accent-text); text-decoration: none; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .6rem 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }

#toast { position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
         background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 10px; max-width: 90vw; z-index: 10; }
#toast.error { background: var(--danger); color: #fff; }
[hidden] { display: none !important; }

/* Domo — a quiet, botanical control room. */
body { background: radial-gradient(ellipse at 75% 0, #24392b66, transparent 50%), var(--bg); }
.bar { padding: 1.1rem max(1.5rem, calc((100vw - 1280px) / 2)); background: #101918f2; backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: .6rem; font-size: 1.65rem; letter-spacing: -.08em; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; background: var(--accent); color: var(--accent-text); border-radius: 12px; letter-spacing: -.1em; }
.brand-dot { color: var(--accent); margin-left: -.6rem; }
nav { gap: .5rem; } button.link { padding: .65rem 1rem; }
button.link.active { background: #c7ef9314; color: var(--accent); }
main { max-width: 1280px; padding: 2.5rem 1.5rem 4rem; }
h1 { font-size: clamp(1.8rem, 3vw, 2.6rem); font-weight: 600; letter-spacing: -.045em; }
h2 { font-size: 1.35rem; letter-spacing: -.025em; }
h3 { font-size: 1.05rem; }
.eyebrow { font-size: .75rem; font-weight: 600; letter-spacing: .17em; color: var(--muted); margin: 0 0 .8rem; }
.page-heading, .section-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.7rem; }
.page-heading p.muted { margin: .6rem 0 0; }
.overview { display: grid; grid-template-columns: 1.25fr 1fr; gap: 1.2rem; margin-bottom: 2.8rem; }
.welcome-panel { position: relative; overflow: hidden; isolation: isolate; background: #c7ef93; color: #20351e; padding: 2rem; border-radius: 24px; min-height: 280px; }
.welcome-panel .eyebrow { color: #3d5535; }
.welcome-panel h2 { font-size: 2.3rem; font-weight: 500; line-height: 1.1; letter-spacing: -.05em; }
.welcome-panel p { font-size: .9rem; line-height: 1.6; }
.welcome-panel button { background: #21351f; color: #edf9df; border: 0; }
.house-art { position: absolute; width: 160px; height: 170px; right: 2rem; bottom: 2rem; transform: rotate(-12deg); z-index: -1; opacity: .65; }
.house-roof { position: absolute; width: 110px; height: 110px; border: 2px solid #365c32; transform: rotate(45deg); left: 25px; top: 0; border-radius: 18px; }
.house-body { position: absolute; inset: 47px 5px 0; background: #b4d784; border: 2px solid #365c32; border-radius: 10px 10px 20px 20px; display: flex; align-items: center; justify-content: center; gap: 12px; }
.house-body i { width: 22px; height: 42px; border: 2px solid #365c32; border-radius: 20px; }
.house-orbit { position: absolute; inset: -40px; border: 1px solid #365c3233; border-radius: 50%; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.stat { border: 1px solid var(--line); border-radius: 20px; padding: 1.35rem; background: #1a252399; display: flex; flex-direction: column; justify-content: space-between; gap: .65rem; }
.stat strong { font-size: 2.2rem; letter-spacing: -.06em; font-weight: 500; }
.stat span { font-size: .85rem; color: var(--muted); }
.stat:first-child strong { color: var(--accent); }
.device-toolbar { display: flex; gap: .7rem; align-items: center; }
.device-toolbar label { margin: 0; } .device-toolbar input, .device-toolbar select { margin: 0; min-height: 46px; }
.search-label { flex: 1; }
.room-filters { display: flex; gap: .5rem; overflow-x: auto; padding: 1rem 0 1.8rem; }
.room-filters button { white-space: nowrap; border-radius: 30px; font-size: .9rem; }
.room > h2 { margin-bottom: 1rem; font-size: 1.1rem; color: var(--muted); }
.grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; align-items: start; }
.card { padding: 1.4rem; box-shadow: 0 8px 30px #0000000a; }
.device { min-width: 0; min-height: 175px; transition: border-color .2s, opacity .2s; }
.device:hover { border-color: #69845d; }
.device.is-on { background: linear-gradient(135deg, #2a3c2a, var(--card)); }
.device-heading { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.device-heading h3 { flex: 1; margin: 0; }
.device-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; background: #c7ef9314; color: var(--accent); font-size: 1.3rem; }
.favorite { background: transparent; border: 0; font-size: 1.3rem; padding: .3rem; color: var(--muted); }
.favorite[aria-pressed=true] { color: var(--accent); }
.device-meta { color: var(--muted); font-size: .8rem; margin: -.5rem 0 1rem; }
button { transition: background .15s, border-color .15s; } button:hover { border-color: var(--accent); }
button.primary:hover { background: #daf7b5; }
input, select { background: #101918; }
.empty-state { border: 1px dashed var(--line); border-radius: 20px; text-align: center; padding: 3rem 1.5rem; color: var(--muted); }
#routine-list { margin-bottom: 2rem; } #routine-form { max-width: 820px; }
.routine-step { border: 1px solid var(--line); border-radius: 14px; padding: 1rem; margin-bottom: 1rem; }
.schedule-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.5rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.narrow { max-width: 420px; padding: 2.5rem; } .login-title { color: var(--accent); font-size: 3rem; }
@media (max-width: 800px) {
 .overview { grid-template-columns: 1fr; } .welcome-panel { min-height: 260px; }
 .bar { flex-direction: column; align-items: stretch; gap: .8rem; padding: .9rem 1rem; }
 .brand { justify-content: center; } nav { overflow-x: auto; justify-content: flex-start; } nav button { white-space: nowrap; flex: 1; }
 main { padding: 1.5rem 1rem 3rem; } .page-heading { align-items: flex-start; }
 .page-heading > button { font-size: .85rem; } .device-toolbar { flex-wrap: wrap; } .search-label { flex-basis: 100%; }
 .stat { padding: 1rem; } .stat strong { font-size: 1.8rem; }
}
@media (max-width: 400px) { .house-art { right: -2rem; opacity: .25; } .schedule-fields { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; } }

/* Shared pictograms and collective controls. */
.icon { width: 1.2rem; height: 1.2rem; flex-shrink: 0; vertical-align: middle; }
button > .icon { margin-right: .45rem; }
.device-icon .icon { width: 1.5rem; height: 1.5rem; }
.favorite .icon { margin: 0; }
.favorite[aria-pressed=true] .icon { fill: currentColor; }
.icon-label { display: flex; gap: .6rem; align-items: center; }
.organize-bar { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-top: 1.3rem; }
.organize-bar label { display: flex; align-items: center; gap: .8rem; margin: 0; }
.organize-bar select { width: auto; margin: 0; }
#group-list { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }
#group-form { max-width: 850px; margin-bottom: 2rem; }
.group-card .device-heading h2 { flex: 1; overflow-wrap: anywhere; margin: 0; }
.group-count { background: var(--on); color: var(--on-text); padding: .25rem .65rem; border-radius: 30px; }
.member-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1rem 0; }
.member-chips span { padding: .25rem .6rem; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.group-controls { border: 0; padding: 0; margin: 1.5rem 0 0; min-width: 0; }
.group-controls legend { font-size: .9rem; color: var(--muted); }
.group-action { display: flex; align-items: end; flex-wrap: wrap; gap: .6rem; padding-top: 1rem; }
.group-action label { flex: 1 1 130px; margin: 0; }
.group-action button { flex: 1 1 140px; }
.group-action input, .group-action select { min-height: 44px; }
.group-management { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 1.5rem; }
.group-report { overflow-wrap: anywhere; } .success { color: var(--accent); }
.group-member-room { padding: 1rem 0; border-top: 1px solid var(--line); }
.group-member-room .section-heading { margin-bottom: .6rem; }
.group-member-room .checks { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.group-member-room .check { min-height: 44px; } .group-member-room input { accent-color: var(--accent); }
@media (max-width: 600px) {
 nav button.link { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .5rem .65rem; font-size: .85rem; }
 nav button > .icon { margin: 0; }
 .organize-bar { align-items: stretch; flex-wrap: wrap; }
 .organize-bar label { flex: 1; flex-wrap: wrap; font-size: .85rem; }
 .organize-bar select { flex: 1; }
}

.schedule-button { display: flex; align-items: center; justify-content: center; width: 100%; margin-top: 1.2rem; border-color: #69845d; color: var(--accent); }
.schedule-target-label { max-width: 600px; }
.schedule-layout { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 1.5rem; align-items: start; margin-top: 1.5rem; }
.schedule-layout .schedule-fields { margin-top: 1rem; }
.schedule-time { font-size: 2rem; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.schedule-entry .section-heading { margin-bottom: .5rem; }
#schedule-days { grid-template-columns: repeat(4,1fr); margin: 1rem 0; }
#schedule-days .check { min-height: 44px; }
.day-presets button { font-size: .85rem; }
@media (max-width: 800px) { .schedule-layout { grid-template-columns: 1fr; } }
