/* House: the home's own control app. Warm night palette; the only color that carries meaning is light itself
   (each row glows in its lamp's own white or color), plus one amber for "on". */
:root {
  --bg: #12100e;
  --surface: #1a1714;
  --raise: #221e1a;
  --line: #2c2723;
  --text: #f2ede6;
  --muted: #9b9188;
  --faint: #6b625a;
  --amber: #f2b35b;
  --danger: #e2735a;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --r: 18px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.35 var(--sans); }
body { min-height: 100dvh; -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }

main {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 18px calc(env(safe-area-inset-bottom) + 40px);
}

/* ---------- header ---------- */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 2px 18px; }
.mark { font: italic 400 40px/1 var(--serif); letter-spacing: -0.01em; margin: 0; }
.mark span { color: var(--amber); font-style: normal; }
.me { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.me button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; color: var(--text); }
.me svg { width: 18px; height: 18px; }

.sub { color: var(--muted); font-size: 14px; margin: -10px 2px 18px; display: flex; gap: 10px; flex-wrap: wrap; }
.sub .dot { color: var(--faint); }

/* ---------- section headings ---------- */
h2 { font: 400 24px/1.1 var(--serif); margin: 28px 2px 12px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
h2 small { font: 13px var(--sans); color: var(--muted); }
h2 .roomall { font: 500 13px var(--sans); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; }
h2 .roomall:active { background: var(--raise); }

/* ---------- wake card ---------- */
.wake {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px 12px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px;
}
.wake .k { color: var(--muted); font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; }
.wake .t { font: 400 34px/1 var(--serif); font-variant-numeric: tabular-nums; }
.wake .note { color: var(--muted); font-size: 14px; grid-column: 1 / -1; }
.wake .note b { color: var(--amber); font-weight: 500; }
.wake svg { width: 18px; height: 18px; color: var(--muted); }

/* ---------- scenes ---------- */
.scenes { display: flex; gap: 10px; overflow-x: auto; margin: 0 -18px; padding: 2px 18px 6px; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding-inline: 18px; }
.scenes::-webkit-scrollbar { display: none; }
.scene {
  flex: 0 0 auto; min-width: 112px; height: 76px; padding: 12px 14px; border-radius: 16px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; justify-content: space-between;
  scroll-snap-align: start; transition: transform 0.12s, background 0.2s, border-color 0.2s;
}
.scene .n { font-weight: 600; font-size: 15px; }
.scene .s { font-size: 12px; color: var(--muted); }
.scene:active { transform: scale(0.97); }
.scene.on, .scene.ran { border-color: rgba(242, 179, 91, 0.55); background: #241d14; }
.scene.on .s, .scene.ran .s { color: var(--amber); }

/* ---------- light rows ---------- */
.rows { display: grid; gap: 8px; }
.row {
  position: relative; overflow: hidden; height: 64px; border-radius: 16px; background: var(--surface);
  border: 1px solid var(--line); display: flex; align-items: center; touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.row .fill {
  position: absolute; inset: 0 auto 0 0; width: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(var(--glow), 0.10), rgba(var(--glow), 0.30));
  border-right: 1px solid rgba(var(--glow), 0.55); transition: width 0.25s ease;
}
.row.dragging .fill { transition: none; }
.row:not(.on) .fill { border-right-color: transparent; }
.row.plug.on .fill { width: 100%; border-right: 0; background: linear-gradient(90deg, rgba(var(--glow), 0.08), rgba(var(--glow), 0.20)); }
.row .tap { position: relative; flex: 1; height: 100%; display: flex; align-items: center; gap: 12px; padding: 0 0 0 16px; text-align: left; min-width: 0; }
.row .bulb { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; background: var(--faint); box-shadow: none; transition: background 0.2s, box-shadow 0.2s; }
.row.on .bulb { background: rgb(var(--glow)); box-shadow: 0 0 12px rgba(var(--glow), 0.8); }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .lvl { margin-left: auto; padding-right: 6px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 15px; }
.row.on .lvl { color: var(--text); }
.row .more { position: relative; width: 48px; height: 100%; display: grid; place-items: center; color: var(--muted); }
.row .more svg { width: 18px; height: 18px; }
.row.off-line { opacity: 0.45; }
.row.off-line .lvl { color: var(--danger); }
.row.busy .lvl { opacity: 0.5; }

/* ---------- skip once ---------- */
.skips { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.skip { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); }
.skip:first-child { border-top: 0; }
.skip .l { flex: 1; min-width: 0; }
.skip .l div:first-child { font-weight: 600; }
.skip .l div:last-child { color: var(--muted); font-size: 13px; }
.skip .l .held { color: var(--amber); }
.pill { border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 500; white-space: nowrap; }
.pill:active { background: var(--raise); }
.pill.amber { border-color: rgba(242, 179, 91, 0.6); color: var(--amber); }
.pill.solid { background: var(--text); color: var(--bg); border-color: var(--text); }
.pill.danger { color: var(--danger); border-color: rgba(226, 115, 90, 0.5); }
.fold { color: var(--muted); font-size: 14px; padding: 10px 2px; }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); opacity: 0; transition: opacity 0.2s; z-index: 20; }
.scrim.in { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border-top: 1px solid var(--line); border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 24px); transform: translateY(100%); transition: transform 0.26s cubic-bezier(.2, .8, .2, 1);
  max-width: 560px; margin: 0 auto;
}
.sheet.in { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h3 { font: 400 26px/1.1 var(--serif); margin: 0 0 4px; }
.sheet .hint { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.sheet .lab { color: var(--muted); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; margin: 20px 0 10px; }

.slider { position: relative; height: 56px; border-radius: 16px; background: var(--raise); border: 1px solid var(--line); overflow: hidden; touch-action: none; }
.slider .fill { position: absolute; inset: 0 auto 0 0; background: rgba(var(--glow), 0.35); border-right: 2px solid rgb(var(--glow)); }
.slider .v { position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; font-variant-numeric: tabular-nums; pointer-events: none; }
.slider .v b { font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.chip i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.chip.sel { border-color: var(--text); }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.sw { aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; }
.sw.sel { border-color: var(--text); }
.btnrow { display: flex; gap: 10px; margin-top: 22px; }
.btnrow .pill { flex: 1; text-align: center; padding: 12px; }

.field { display: flex; align-items: center; gap: 10px; background: var(--raise); border: 1px solid var(--line); border-radius: 14px; padding: 4px 6px 4px 14px; }
.field input { flex: 1; background: none; border: 0; outline: 0; padding: 10px 0; min-width: 0; }
.field input[type=time] { font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 12px; color: var(--muted); font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--amber); }

.person { border-top: 1px solid var(--line); padding: 14px 0; }
.person:first-of-type { border-top: 0; }
.person .pn { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.person .pn b { font-weight: 600; }
.person .pn em { font-style: normal; color: var(--amber); font-size: 12px; margin-left: 6px; }
.dev { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 14px; padding: 8px 0 0; gap: 10px; }
.link { word-break: break-all; background: var(--raise); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 13px; color: var(--text); margin: 12px 0 0; user-select: all; -webkit-user-select: all; }

/* ---------- welcome / join ---------- */
.hello { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.hello .mark { font-size: 56px; }
.hello p { color: var(--muted); margin: 0; max-width: 32ch; }
.hello .pill.solid { align-self: flex-start; padding: 13px 22px; margin-top: 8px; }
.steps { color: var(--muted); padding-left: 20px; margin: 4px 0 0; }
.steps li { margin: 6px 0; }
.steps b { color: var(--text); font-weight: 600; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 18px); transform: translate(-50%, 140%);
  background: var(--text); color: var(--bg); border-radius: 14px; padding: 12px 14px 12px 16px; display: flex; gap: 14px; align-items: center;
  max-width: calc(100vw - 32px); font-size: 14px; font-weight: 500; z-index: 30; opacity: 0; pointer-events: none;
  transition: transform 0.25s cubic-bezier(.2, .8, .2, 1), opacity 0.2s;
}
#toast.in { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
#toast button { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
#toast.err { background: var(--danger); color: #1a0d09; }

.empty { color: var(--muted); padding: 40px 4px; }
@media (min-width: 700px) { main { padding-top: 48px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
