:root {
  --bg: #08111f;
  --bg-soft: #101d31;
  --card: rgba(255, 255, 255, 0.08);
  --card-strong: rgba(255, 255, 255, 0.13);
  --text: #f7fbff;
  --muted: #9eb0c7;
  --line: rgba(255, 255, 255, 0.12);
  --primary: #6ee7ff;
  --primary-2: #8b5cf6;
  --danger: #ff5c7a;
  --success: #49f2a8;
  --warning: #ffd166;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  --radius: 24px;
  --radius-sm: 16px;
  --nav-height: 82px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(110, 231, 255, 0.18), transparent 34%),
    radial-gradient(circle at top right, rgba(139, 92, 246, 0.22), transparent 32%),
    linear-gradient(180deg, #07101d, #0b1220 45%, #060a12);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 16px;
  padding: 14px 14px;
  outline: none;
}

select option {
  color: #111827;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--primary);
}

input[type="color"] {
  height: 54px;
  padding: 6px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

label strong {
  color: var(--text);
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  max-width: 920px;
  margin: 0 auto;
  position: relative;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 18px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(18px);
  background: linear-gradient(180deg, rgba(8, 17, 31, 0.92), rgba(8, 17, 31, 0.55));
}

.eyebrow,
.small-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.5rem, 8vw, 2.4rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0;
}

h3 {
  margin-bottom: 14px;
}

.content {
  padding: 8px 16px calc(var(--nav-height) + 28px);
}

.page {
  display: none;
  animation: pageIn 0.28s ease both;
}

.page.active {
  display: block;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.glass,
.panel,
.room-card,
.light-card,
.scene-card,
.sync-card,
.favorite-card {
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.status-card {
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pulse-dot {
  width: 16px;
  height: 16px;
  background: var(--success);
  border-radius: 999px;
  box-shadow: 0 0 0 0 rgba(73, 242, 168, 0.8);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 16px rgba(73, 242, 168, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(73, 242, 168, 0);
  }
}

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  display: grid;
  place-items: center;
  transition: transform 0.18s ease, background 0.18s ease;
}

.icon-btn:active,
.action-btn:active,
.full-btn:active,
.nav-btn:active,
.scene-card:active,
.room-card:active,
.light-card:active {
  transform: scale(0.97);
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0 24px;
}

.action-btn,
.full-btn,
.mode-btn,
.chip,
.text-btn,
.integration {
  min-height: 48px;
  border-radius: 18px;
  color: var(--text);
  background: var(--card-strong);
  border: 1px solid var(--line);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.action-btn {
  padding: 14px;
  font-weight: 800;
  display: grid;
  place-items: center;
  gap: 5px;
}

.action-btn span {
  font-size: 1.5rem;
}

.action-btn.primary,
.full-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: rgba(255, 255, 255, 0.25);
  color: #06101f;
}

.action-btn.danger {
  background: linear-gradient(135deg, #ff5c7a, #ff9f6e);
  color: #16070b;
}

.full-btn {
  width: 100%;
  padding: 15px 18px;
  font-weight: 900;
}

.full-btn.secondary {
  color: var(--text);
  background: rgba(255, 255, 255, 0.12);
}

.text-btn {
  padding: 9px 12px;
  color: var(--primary);
  font-weight: 800;
  min-height: auto;
}

.section-block {
  margin-top: 24px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.horizontal-scroll {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(145px, 42%);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.horizontal-scroll::-webkit-scrollbar {
  display: none;
}

.favorite-card,
.scene-card {
  min-height: 132px;
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  position: relative;
}

.favorite-card::after,
.scene-card::after {
  content: "";
  position: absolute;
  inset: auto -30px -45px auto;
  width: 105px;
  height: 105px;
  border-radius: 999px;
  background: var(--scene-color, #ffd166);
  filter: blur(8px);
  opacity: 0.75;
}

.favorite-card h3,
.scene-card h3,
.favorite-card p,
.scene-card p {
  position: relative;
  z-index: 1;
}

.favorite-card p,
.scene-card p {
  margin-bottom: 0;
  color: var(--muted);
}

.room-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.room-card {
  min-height: 128px;
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.room-meta p {
  margin: 4px 0 0;
  color: var(--muted);
}

.room-icons {
  display: flex;
  gap: 6px;
}

.mini-bulb {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--bulb-color, #ffd166);
  box-shadow: 0 0 24px var(--bulb-color, #ffd166);
  opacity: var(--bulb-opacity, 1);
}

.room-power {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
}

.room-power button {
  flex: 1;
}

.lights-list,
.automation-list,
.mini-list {
  display: grid;
  gap: 12px;
}

.light-card {
  border-radius: var(--radius-sm);
  padding: 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}

.light-bulb {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--light-color);
  box-shadow: 0 0 28px var(--light-color);
  opacity: var(--light-opacity);
}

.light-card.off .light-bulb,
.large-bulb.off {
  filter: grayscale(1);
  opacity: 0.35;
  box-shadow: none;
}

.light-info h3 {
  margin: 0 0 3px;
  font-size: 1rem;
}

.light-info p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.toggle {
  width: 56px;
  height: 34px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  position: relative;
  transition: background 0.2s ease;
}

.toggle::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  left: 4px;
  top: 4px;
  border-radius: 999px;
  background: white;
  transition: transform 0.2s ease;
}

.toggle.on {
  background: linear-gradient(135deg, var(--primary), var(--success));
}

.toggle.on::after {
  transform: translateX(22px);
}

.page-title {
  margin: 8px 0 18px;
}

.page-title p {
  color: var(--muted);
  margin-bottom: 0;
}

.scene-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.panel {
  margin-top: 16px;
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Automations */
.automation-toolbar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.chip {
  padding: 10px 14px;
  white-space: nowrap;
  color: var(--muted);
  font-weight: 800;
}

.chip.active {
  color: #06101f;
  background: linear-gradient(135deg, var(--primary), var(--success));
}

.automation-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 8px;
}

.automation-card .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.automation-card p {
  margin: 0;
  color: var(--muted);
}

/* Sync */
.sync-card {
  min-height: 260px;
  border-radius: 32px;
  padding: 22px;
  display: grid;
  place-items: center;
  text-align: center;
  overflow: hidden;
}

.sync-orb {
  width: 145px;
  height: 145px;
  border-radius: 999px;
  background: conic-gradient(from 120deg, #6ee7ff, #8b5cf6, #ff5c7a, #ffd166, #49f2a8, #6ee7ff);
  box-shadow: 0 0 80px rgba(110, 231, 255, 0.55);
  animation: orbFloat 4s ease-in-out infinite;
}

.sync-orb.running {
  animation: orbFloat 2s ease-in-out infinite, spin 1.8s linear infinite;
}

@keyframes orbFloat {
  50% {
    transform: translateY(-8px) scale(1.04);
  }
}

@keyframes spin {
  to {
    rotate: 360deg;
  }
}

.mode-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode-btn {
  padding: 15px;
  font-weight: 900;
  color: var(--text);
}

.mode-btn.active {
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  color: #06101f;
}

/* Advanced */
.rule-builder {
  display: grid;
  gap: 10px;
}

.integration-list {
  display: grid;
  gap: 10px;
}

.integration {
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  font-weight: 850;
}

.integration span {
  font-size: 0.82rem;
  color: var(--muted);
}

.integration.connected {
  border-color: rgba(73, 242, 168, 0.45);
}

.integration.connected span {
  color: var(--success);
}

.rule-item {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 30;
  width: min(calc(100% - 22px), 900px);
  height: var(--nav-height);
  padding: 9px;
  border-radius: 28px;
  background: rgba(8, 17, 31, 0.78);
  border: 1px solid var(--line);
  backdrop-filter: blur(22px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  box-shadow: var(--shadow);
}

.nav-btn {
  background: transparent;
  color: var(--muted);
  border-radius: 20px;
  display: grid;
  place-items: center;
  gap: 3px;
  font-size: 0.72rem;
  font-weight: 800;
}

.nav-btn span {
  font-size: 1.22rem;
}

.nav-btn.active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.12);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: end;
  background: rgba(0, 0, 0, 0.55);
}

.modal-backdrop.active {
  display: flex;
}

.sheet {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  border-radius: 30px 30px 0 0;
  background: rgba(12, 22, 38, 0.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 12px 18px 24px;
  animation: sheetIn 0.25s ease both;
}

@keyframes sheetIn {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0);
  }
}

.modal-handle {
  width: 48px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  margin: 0 auto 14px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.large-bulb {
  width: 172px;
  height: 172px;
  border-radius: 999px;
  margin: 20px auto;
  background: var(--modal-color, #ffd166);
  box-shadow: 0 0 100px var(--modal-color, #ffd166);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.modal {
  display: grid;
  gap: 14px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Toast */
.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: 108px;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(247, 251, 255, 0.95);
  color: #08111f;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Desktop/tablet */
@media (min-width: 680px) {
  .content {
    padding-inline: 22px;
  }

  .room-grid {
    grid-template-columns: 1fr 1fr;
  }

  .lights-list {
    grid-template-columns: 1fr 1fr;
  }

  .scene-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .horizontal-scroll {
    grid-auto-columns: minmax(180px, 24%);
  }
}

@media (min-width: 900px) {
  .bottom-nav {
    bottom: 18px;
  }

  .content {
    padding-bottom: 120px;
  }
}
