:root {
  --ink: #faf5ec;
  --surface: #ffffff;
  --surface-2: #f1e6d2;
  --surface-3: #e9dcc2;
  --line: #e2d2b2;
  --text: #241c12;
  --text-dim: #7c6d57;
  --warm: #d9791f;
  --warm-soft: #f0c894;
  --warm-track: #e9d4ae;
  --cool: #2f6fb8;
  --danger: #b5432f;
  --shadow: 0 1px 2px rgba(36,28,18,0.06), 0 12px 28px -14px rgba(36,28,18,0.28);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #171310;
    --surface: #221b14;
    --surface-2: #2b2219;
    --surface-3: #362b1f;
    --line: #3d3121;
    --text: #f5ecdd;
    --text-dim: #a99878;
    --warm: #ffab4c;
    --warm-soft: #6e4a22;
    --warm-track: #493a24;
    --cool: #8fc4ff;
    --danger: #e8836d;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 20px 40px -20px rgba(0,0,0,0.6);
  }
}

:root[data-theme="dark"] {
  --ink: #171310;
  --surface: #221b14;
  --surface-2: #2b2219;
  --surface-3: #362b1f;
  --line: #3d3121;
  --text: #f5ecdd;
  --text-dim: #a99878;
  --warm: #ffab4c;
  --warm-soft: #6e4a22;
  --warm-track: #493a24;
  --cool: #8fc4ff;
  --danger: #e8836d;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 20px 40px -20px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--ink);
  color: var(--text);
  margin: 0;
  min-height: 100%;
  font-family: "Archivo", -apple-system, BlinkMacSystemFont, sans-serif;
}

h1, h2, h3, .display {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 460;
  letter-spacing: -0.01em;
  margin: 0;
}

.mono, .num {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

button { font-family: inherit; }

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 620;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.6rem 1.4rem 6rem;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.9rem;
  gap: 1rem;
}
.topbar .brand { display: flex; align-items: baseline; gap: 0.55rem; }
.topbar h1 { font-size: 1.7rem; }
.topbar .brand-mark {
  width: 0.55rem; height: 0.55rem; border-radius: 50%;
  background: var(--warm); box-shadow: 0 0 0 5px var(--warm-soft); align-self: center;
}
.topbar-actions { display: flex; align-items: center; gap: 0.8rem; }

.pill-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 0.5rem 1.05rem;
  font-size: 0.8rem;
  font-weight: 620;
  cursor: pointer;
}
.pill-btn:hover { border-color: var(--danger); color: var(--danger); }

.link-button {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  text-decoration: underline; font-size: 0.8rem; padding: 0;
}

button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--cool);
  outline-offset: 2px;
}

.empty { color: var(--text-dim); }

/* ---------- room grid (home) ---------- */

.room-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
@media (max-width: 560px) { .room-grid { grid-template-columns: 1fr; } }

.room-card {
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 1.3rem 1.3rem 1.15rem;
  min-height: 168px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease;
  text-align: left;
  text-decoration: none;
  color: var(--text);
}
.room-card:hover { transform: translateY(-2px); }

.room-card .glow {
  position: absolute;
  inset: -40% -40% auto auto;
  width: 75%; height: 75%;
  border-radius: 50%;
  filter: blur(30px);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.room-card.lit .glow { opacity: 0.55; }

.room-card .row-top { display: flex; justify-content: space-between; align-items: flex-start; position: relative; z-index: 1; }
.room-card h2 { font-size: 1.32rem; }

.power-toggle {
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-dim);
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex: none;
}
.power-toggle svg { width: 1.05rem; height: 1.05rem; }
.power-toggle.on { background: var(--warm); border-color: var(--warm); color: #241505; }

.room-card .stat-row { display: flex; align-items: flex-end; justify-content: space-between; position: relative; z-index: 1; }
.room-card .bulb-count { font-size: 0.78rem; color: var(--text-dim); }
.brightness-pill { font-size: 1.5rem; font-weight: 560; }
.brightness-pill .unit { font-size: 0.85rem; color: var(--text-dim); margin-left: 0.15rem; }

/* ---------- room / bulb detail pages ---------- */

.back-row { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 1.4rem; }
.back-btn {
  width: 2.3rem; height: 2.3rem; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: flex; align-items: center; justify-content: center; text-decoration: none;
}
.back-btn svg { width: 1.05rem; height: 1.05rem; }

.room-header { margin-bottom: 1.3rem; }
.room-header h1 { font-size: 1.85rem; }
.room-header .room-sub { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.2rem; }

.control-card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 1.4rem 1.5rem 1.6rem;
  margin-bottom: 1.6rem;
}
.control-card .dial-wrap { margin-bottom: 1.8rem; }
.control-subhead { margin: 0 0 0.7rem 0.1rem; text-align: center; }

.bulb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.9rem; }

.bulb-tile {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 1.05rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s ease;
}
.bulb-tile:hover { transform: translateY(-2px); }

.bulb-tile .ring-wrap { align-self: center; position: relative; width: 4.4rem; height: 4.4rem; }
.bulb-tile .ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { stroke: var(--warm-track); }
.ring-fill { transition: stroke-dashoffset 0.25s ease, stroke 0.25s ease; }
.ring-pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.92rem; font-weight: 560; }

.bulb-tile .name-row { display: flex; justify-content: space-between; align-items: center; }
.bulb-tile .name-row .name { font-weight: 620; font-size: 0.92rem; }
.bulb-tile .brand { font-size: 0.68rem; color: var(--text-dim); letter-spacing: 0.04em; text-transform: uppercase; }

.mini-power {
  width: 1.9rem; height: 1.9rem; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-dim);
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex: none;
}
.mini-power svg { width: 0.8rem; height: 0.8rem; }
.mini-power.on { background: var(--warm); border-color: var(--warm); color: #241505; }
.mini-power:disabled, .power-toggle:disabled { cursor: not-allowed; opacity: 0.6; }

.badge { font-size: 0.7rem; padding: 0.15rem 0.5rem; border-radius: 999px; }
.badge-offline { background: var(--warm-soft); color: var(--warm); }

/* dial */

.dial-wrap { display: flex; flex-direction: column; align-items: center; user-select: none; }
[data-dial] { width: 190px; height: 190px; touch-action: none; cursor: grab; }
[data-dial]:active { cursor: grabbing; }
.dial-readout { margin-top: -6.6rem; text-align: center; pointer-events: none; }
.dial-readout .pct { font-size: 2.5rem; font-weight: 460; font-family: "Fraunces", serif; }
.dial-readout .pct .sign { font-size: 1.2rem; color: var(--text-dim); }
.dial-readout .label { font-size: 0.72rem; color: var(--text-dim); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 0.15rem; }

/* mode tabs */

.mode-tabs { display: flex; background: var(--surface-2); border-radius: 999px; padding: 0.25rem; margin-bottom: 1.5rem; gap: 0.2rem; }
.mode-tab { flex: 1; border: none; background: transparent; color: var(--text-dim); padding: 0.5rem 0.6rem; border-radius: 999px; font-size: 0.82rem; font-weight: 620; cursor: pointer; }
.mode-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.mode-panel { display: none; }
.mode-panel.active { display: block; }

/* white gauge */

.white-track {
  position: relative; height: 14px; border-radius: 999px;
  background: linear-gradient(90deg, #ffb454, #fff3df 45%, #cfe8ff 100%);
  touch-action: none; cursor: grab;
}
.white-track .puck {
  position: absolute; top: 50%; width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--text); transform: translate(-50%, -50%); box-shadow: var(--shadow);
}
.white-labels { display: flex; justify-content: space-between; margin-top: 0.6rem; font-size: 0.72rem; color: var(--text-dim); }
.kelvin-readout { text-align: center; margin-top: 0.9rem; font-size: 1.15rem; }
.kelvin-readout .unit { font-size: 0.78rem; color: var(--text-dim); }

/* color wheel */

.wheel-wrap { display: flex; justify-content: center; margin-bottom: 0.4rem; }
[data-wheel] { width: 210px; height: 210px; border-radius: 50%; touch-action: none; cursor: crosshair; box-shadow: var(--shadow); }

/* mood presets */

.mood-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; }
.mood-chip {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 0.75rem 0.5rem; display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  cursor: pointer; font-size: 0.78rem; font-weight: 560; color: var(--text);
}
.mood-chip.active { border-color: var(--warm); }
.mood-swatch { width: 2.1rem; height: 2.1rem; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08); }
.mood-swatch-party {
  background: conic-gradient(from 0deg, #ff3b6b, #ffd23b, #3bff9c, #3bb7ff, #b13bff, #ff3b6b);
}
.mood-chip[data-party-btn].party-active {
  border-color: var(--warm);
  animation: party-pulse 0.6s ease-in-out infinite alternate;
}
@keyframes party-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

/* power row */

.control-power-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 1.6rem; padding-top: 1.2rem; border-top: 1px solid var(--line);
}
.control-power-row .label { font-size: 0.9rem; color: var(--text-dim); }
.big-power {
  display: flex; align-items: center; gap: 0.6rem;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 0.55rem 1.1rem; font-weight: 620; font-size: 0.85rem; cursor: pointer;
}
.big-power.on { background: var(--warm); border-color: var(--warm); color: #241505; }
.big-power svg { width: 1rem; height: 1rem; }

/* banner */

.banner { padding: 0.75rem 1rem; border-radius: var(--radius-md); margin-bottom: 1rem; }
.banner-warning { background: var(--warm-soft); color: var(--warm); border: 1px solid var(--line); }

/* ---------- login ---------- */

.login-page { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 2rem; width: 280px; display: flex; flex-direction: column; gap: 0.9rem; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 0.5rem; text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text-dim); }
.login-card input { padding: 0.5rem; border-radius: 8px; border: 1px solid var(--line); background: var(--ink); color: var(--text); }
.login-card button { padding: 0.6rem; border-radius: 8px; border: none; background: var(--warm); color: #241505; font-weight: 620; cursor: pointer; }
.login-card .error { color: var(--danger); font-size: 0.85rem; margin: 0; }

/* ---------- install banner ---------- */

.install-banner {
  position: fixed;
  left: 1rem; right: 1rem; bottom: 1rem;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 0.7rem 0.9rem;
  max-width: 420px;
  margin: 0 auto;
}
.install-banner[hidden] { display: none; }
.install-banner-icon img { display: block; border-radius: 7px; }
.install-banner-text { flex: 1; font-size: 0.85rem; color: var(--text); }
.install-banner-accept { flex-shrink: 0; }
.install-banner-dismiss {
  flex-shrink: 0;
  font-size: 1.2rem;
  line-height: 1;
  text-decoration: none;
  color: var(--text-dim);
  padding: 0.2rem;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
