:root {
  --bg: #0b0e14;
  --panel: rgba(18, 22, 32, 0.72);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf4;
  --text-dim: #8a93a6;
  --accent: #ffb648;
  --accent2: #4da3ff;
  --danger: #ff5d5d;
  --ok: #3ddc84;
  --radius: 18px;
  font-size: 15px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Manrope', system-ui, sans-serif;
}

#app { position: relative; width: 100%; height: 100%; }
#scene { position: absolute; inset: 0; display: block; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.glass {
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}

/* ── Шапка ─────────────────────────── */
.topbar {
  position: absolute; top: 16px; left: 16px; right: 16px;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 20px;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 46px; height: 46px; display: grid; place-items: center;
  font-size: 24px; border-radius: 14px;
  background: linear-gradient(135deg, #ffb648 0%, #ff7e47 100%);
  box-shadow: 0 4px 18px rgba(255, 150, 60, .4);
}
.brand h1 { font-size: 17px; font-weight: 800; letter-spacing: .3px; }
.brand p { font-size: 12px; color: var(--text-dim); }

.topbar-stats { display: flex; gap: 22px; margin-left: auto; }
.stat { text-align: center; }
.stat span { font-size: 16px; font-weight: 800; color: var(--accent); display: block; white-space: nowrap; }
.stat label { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }

.topbar-actions { display: flex; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 12px; border: 1px solid var(--panel-border);
  background: rgba(255,255,255,.05); color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .2s;
}
.chip:hover { background: rgba(255,255,255,.12); }
.chip.active { background: var(--accent); color: #1a1205; border-color: transparent; }
.chip.danger:hover { background: var(--danger); color: #fff; }

/* ── Сценарии ──────────────────────── */
.scenarios {
  position: absolute; left: 16px; top: 96px;
  width: 250px; padding: 16px;
  z-index: 9;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
}
.scenarios h2 { font-size: 14px; margin-bottom: 12px; letter-spacing: .3px; }
.scenario-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; margin-bottom: 6px;
  border-radius: 12px; border: 1px solid transparent;
  background: rgba(255,255,255,.04); color: var(--text);
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: all .2s; text-align: left;
}
.scenario-btn .s-icon { font-size: 19px; }
.scenario-btn small { display: block; font-weight: 500; font-size: 11px; color: var(--text-dim); }
.scenario-btn:hover { background: rgba(255,255,255,.1); transform: translateX(3px); }
.scenario-btn.active {
  background: linear-gradient(135deg, rgba(255,182,72,.22), rgba(255,126,71,.14));
  border-color: rgba(255,182,72,.5);
}
.scenario-desc {
  margin-top: 10px; padding: 12px; border-radius: 12px;
  background: rgba(77,163,255,.08); border: 1px solid rgba(77,163,255,.2);
  font-size: 12.5px; line-height: 1.55; color: #c4d4ec;
  display: none;
}
.scenario-desc.show { display: block; }
.scenario-desc b { color: var(--accent2); }

/* ── Панель комнаты ────────────────── */
.room-panel {
  position: absolute; right: 16px; top: 96px;
  width: 300px; padding: 18px;
  z-index: 9;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  transition: transform .35s cubic-bezier(.2,.9,.3,1), opacity .3s;
}
.room-panel.hidden { transform: translateX(120%); opacity: 0; pointer-events: none; }
.close-btn {
  position: absolute; top: 12px; right: 12px;
  width: 28px; height: 28px; border-radius: 8px;
  border: none; background: rgba(255,255,255,.07); color: var(--text-dim);
  cursor: pointer; font-size: 13px;
}
.close-btn:hover { background: rgba(255,93,93,.25); color: #fff; }
.room-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.room-big-icon {
  width: 52px; height: 52px; display: grid; place-items: center; font-size: 27px;
  border-radius: 14px; background: rgba(255,255,255,.06);
}
.room-head h2 { font-size: 18px; }
.room-head p { font-size: 12px; color: var(--text-dim); }

.room-controls { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.control-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: 12px; background: rgba(255,255,255,.04);
  font-size: 13.5px; font-weight: 600;
}
.control-row.column { flex-direction: column; align-items: stretch; gap: 8px; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.row-between b { color: var(--accent); font-size: 13px; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, #333a4a, #ffb648);
  outline: none; cursor: pointer;
}
input[type=range].kelvin-slider {
  background: linear-gradient(90deg, #ff9d3f, #fff3d6, #bcd8ff);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,.5); cursor: grab;
}
.kelvin-hints { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-dim); font-weight: 500; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-sw {
  position: absolute; inset: 0; border-radius: 13px;
  background: #2a3040; transition: .25s; cursor: pointer;
}
.slider-sw::before {
  content: ''; position: absolute; width: 20px; height: 20px;
  left: 3px; top: 3px; border-radius: 50%; background: #79839a; transition: .25s;
}
.switch input:checked + .slider-sw { background: var(--accent); }
.switch input:checked + .slider-sw::before { transform: translateX(20px); background: #fff; }

.room-panel h3 { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .6px; }
.devices { display: flex; flex-direction: column; gap: 6px; }
.device {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 11px; background: rgba(255,255,255,.04);
  font-size: 13px;
}
.device .d-icon { font-size: 17px; width: 24px; text-align: center; }
.device .d-name { flex: 1; font-weight: 600; }
.device .d-state { font-size: 11.5px; color: var(--text-dim); font-weight: 600; }
.device .d-state.on { color: var(--ok); }
.device .d-dot { width: 8px; height: 8px; border-radius: 50%; background: #3a4256; }
.device .d-dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.room-tip {
  margin-top: 14px; padding: 12px; border-radius: 12px;
  background: rgba(255,182,72,.08); border: 1px solid rgba(255,182,72,.22);
  font-size: 12.5px; line-height: 1.5; color: #ecd9b0;
}
.room-tip b { color: var(--accent); }

/* ── Практики ──────────────────────── */
.practices {
  position: absolute; left: 16px; bottom: 16px;
  width: 460px; max-width: calc(100vw - 32px);
  z-index: 9;
  overflow: hidden;
}
.practices-head {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; padding: 14px 18px;
  border: none; background: transparent; color: var(--text);
  font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
}
.practices-head .chev { transition: transform .3s; color: var(--text-dim); }
.practices.collapsed .chev { transform: rotate(180deg); }
.practices-body {
  max-height: 42vh; overflow-y: auto;
  padding: 0 18px 16px;
  transition: max-height .35s ease, padding .35s ease;
}
.practices.collapsed .practices-body { max-height: 0; padding: 0 18px; overflow: hidden; }
.practice {
  padding: 11px 0; border-top: 1px solid rgba(255,255,255,.06);
  font-size: 12.8px; line-height: 1.55; color: #c9d2e2;
}
.practice b { color: var(--accent); display: block; margin-bottom: 3px; font-size: 13px; }

/* ── Лента событий ─────────────────── */
.narration {
  position: absolute; bottom: 76px; left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 40px));
  padding: 13px 22px;
  z-index: 11;
  font-size: 14.5px; font-weight: 600; line-height: 1.45;
  text-align: center;
  border-color: rgba(255,182,72,.35);
  box-shadow: 0 12px 40px rgba(0,0,0,.55), 0 0 24px rgba(255,182,72,.12);
  transition: opacity .3s, transform .3s;
}
.narration.hidden { opacity: 0; transform: translateX(-50%) translateY(14px); pointer-events: none; }
.narration b { color: var(--accent); }

/* ── Подсказка ─────────────────────── */
.hint {
  position: absolute; bottom: 16px; right: 16px;
  padding: 10px 16px; font-size: 12px; color: var(--text-dim);
  z-index: 8; border-radius: 12px;
}

/* ── 3D-метки комнат ───────────────── */
.room-label {
  pointer-events: auto; cursor: pointer;
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 30px;
  background: rgba(12, 15, 22, 0.78);
  border: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(8px);
  font-family: 'Manrope', sans-serif;
  font-size: 12.5px; font-weight: 700; color: #e8ecf4;
  white-space: nowrap;
  transition: all .2s;
  user-select: none;
}
.room-label:hover { border-color: var(--accent); box-shadow: 0 0 16px rgba(255,182,72,.35); }
.room-label .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #3a4256; transition: all .25s;
}
.room-label.lit .dot { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.room-label.selected { border-color: var(--accent2); box-shadow: 0 0 16px rgba(77,163,255,.4); }

/* ── Мобильная адаптация ───────────── */
@media (max-width: 900px) {
  .topbar { gap: 12px; padding: 10px 14px; }
  .topbar-stats { display: none; }
  .scenarios { width: 200px; top: 86px; padding: 12px; }
  .scenario-btn small { display: none; }
  .room-panel { width: calc(100vw - 32px); top: auto; bottom: 16px; max-height: 55vh; }
  .practices { display: none; }
  .hint { display: none; }
}
