/* Dormir 2.0 shell: the sidebar, the live room view, section pages and the phone bars.
   The room picture keeps its own shape and LED coordinates; only its frame changes. */

/* ---------- The live room picture ---------- */
.room {
  --view-w: 100vw;
  --view-h: 100vh;
  --focus-x: 0.46;
  --focus-y: 0.72;
  --ratio: 1.7778;
  --room-w: max(var(--view-w), calc(var(--view-h) * var(--ratio)));
  --room-h: calc(var(--room-w) / var(--ratio));
  position: absolute;
  z-index: 0;
  top: calc((var(--view-h) - var(--room-h)) * var(--focus-y));
  left: calc((var(--view-w) - var(--room-w)) * var(--focus-x));
  width: var(--room-w);
  height: var(--room-h);
  overflow: hidden;
  isolation: isolate;
  background: #000;
  transition: opacity 0.35s ease;
}
.room.changing { opacity: 0.2; }
.room img, .room canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
/* Reveal only a rendered frame of the current room. A still is an explicit graphics
   fallback, never a loading image from a different or older room. */
.room img[hidden] { display: none; }
.room canvas { visibility: hidden; opacity: 0; transition: opacity 0.8s; }
.room.lit canvas { visibility: visible; opacity: 1; }

/* Outside the editor the whole room stays in view at its own proportions */
body:not(.editing) .room {
  --room-w: min(var(--view-w), calc(var(--view-h) * var(--ratio)));
  left: calc((var(--view-w) - var(--room-w)) / 2);
  top: calc((var(--view-h) - var(--room-h)) / 2);
}

.room-stage {
  position: absolute;
  overflow: hidden;
  isolation: isolate;
  background: var(--bg);
}
/* The room's own light, bleeding out around its picture (colours set by shell.js) */
.room-stage::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -12%;
  background:
    radial-gradient(40% 55% at 22% 50%, var(--bleed-a, transparent), transparent 70%),
    radial-gradient(45% 50% at 50% 46%, var(--bleed-b, transparent), transparent 70%),
    radial-gradient(40% 55% at 78% 50%, var(--bleed-c, transparent), transparent 70%);
  filter: blur(70px);
  opacity: 0.38;
  pointer-events: none;
}
body.editing .room-stage::before { display: none; }
/* A soft floor so the deck and title read over any light */
.room-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(5, 6, 10, 0.55)), linear-gradient(0deg, rgba(5, 6, 10, 0.35), transparent 28%);
}

/* ---------- Glass material ---------- */
.top, .panel, .cinema-bar, .bottom-nav {
  background: var(--glass);
  border: 1px solid var(--edge);
  box-shadow: var(--sheen), var(--lift);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}

/* ---------- Navigation ---------- */
.top { position: fixed; z-index: 6; display: flex; }
.nav-head { display: flex; align-items: center; gap: 8px; min-width: 0; }

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
  font: 680 1.18rem var(--display);
  letter-spacing: -0.03em;
  text-decoration: none;
}
.logo img { flex: none; width: 32px; height: 32px; padding: 4px; background: #f5f7ff; border-radius: 10px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2), 0 6px 16px -8px rgba(0, 0, 0, 0.8); }

.nav-collapse, .menu-toggle {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  min-height: 0;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
}
.nav-collapse:hover, .menu-toggle:hover { color: var(--text); background: var(--surface-hover); }
.nav-collapse svg, .menu-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.menu-toggle { display: none; }

.nav-tools { display: flex; flex-direction: column; gap: 2px; }
.nav-group { margin: 18px 12px 6px; color: var(--faint); font-size: 0.72rem; font-weight: 600; }
.nav-group:first-child { margin-top: 6px; }

.nav-item {
  position: relative;
  justify-content: flex-start;
  gap: 12px;
  min-height: 40px;
  padding: 0 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 520;
  background: transparent;
  border-color: transparent;
  border-radius: var(--r-sm);
  overflow: hidden;
}
.nav-item:hover:not(:disabled) { color: var(--text); background: var(--surface-hover); border-color: transparent; }
.nav-item .nav-icon { width: 18px; height: 18px; }
/* The page you're on: lit from the room's own colour */
.nav-item[aria-current="page"] {
  color: var(--text);
  background: radial-gradient(140% 180% at 0% 50%, color-mix(in srgb, var(--live) 30%, transparent), transparent 62%), var(--surface-press);
  border-color: var(--edge);
}
.nav-item[aria-current="page"] .nav-icon { color: color-mix(in srgb, var(--live) 55%, #fff); }
#cinema[aria-pressed="true"] { color: var(--text); background: var(--surface-press); }

.nav-icon, .tabs .ed-icon { flex: none; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* Rooms, as a sub-list under "Rooms" in the sidebar and a strip on phones */
.rooms { display: flex; gap: 4px; min-width: 0; }
.room-card {
  position: relative;
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 5px 8px 5px 5px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  transition: background var(--fast), border-color var(--fast), transform var(--fast) var(--ease);
}
.room-card img { display: block; flex: none; width: 34px; height: 26px; object-fit: cover; background: var(--elevated); border-radius: 7px; }
.room-card:hover { background: var(--surface-hover); }
.room-card:active { transform: scale(0.98); }
.room-card[aria-selected="true"] { background: var(--surface); border-color: var(--edge); }
body[data-route="room"] .room-card[aria-selected="true"], body[data-route="scenes"] .room-card[aria-selected="true"],
body[data-route="effects"] .room-card[aria-selected="true"], body[data-route="sync"] .room-card[aria-selected="true"] {
  background:
    radial-gradient(90% 160% at 0% 50%, color-mix(in srgb, var(--bleed-a, var(--live)) 34%, transparent), transparent 70%),
    radial-gradient(90% 160% at 100% 50%, color-mix(in srgb, var(--bleed-c, var(--live)) 22%, transparent), transparent 70%),
    var(--surface-press);
  border-color: var(--edge-strong);
}
.room-text { display: grid; gap: 1px; min-width: 0; line-height: 1.2; }
.room-text b { overflow: hidden; font-size: 0.82rem; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.room-text .row { gap: 6px; min-width: 0; }
.room-status { overflow: hidden; color: var(--muted); font-size: 0.7rem; white-space: nowrap; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.room-dot { flex: none; width: 7px; height: 7px; background: var(--dot, #3a3f52); border-radius: 50%; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1); }

/* The room's hardware state, in one capsule */
.mode {
  --state: var(--faint);
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 14px 0 12px;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 560;
  white-space: nowrap;
  background: color-mix(in srgb, var(--state) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--state) 36%, transparent);
  border-radius: 999px;
  transition: background var(--fast), transform var(--fast) var(--ease);
}
.mode::before { content: ""; flex: none; width: 7px; height: 7px; background: var(--state); border-radius: 50%; }
.mode:hover { background: color-mix(in srgb, var(--state) 20%, transparent); }
.mode:active { transform: scale(0.97); }
.mode[data-mode="hardware"] { --state: var(--ok); }
.mode[data-mode="partial"] { --state: var(--warn); }
.mode[data-mode="offline"] { --state: var(--bad); }

/* The room's devices, compact, under the navigation */
.device-rail { display: flex; flex-direction: column; min-height: 0; }
.rail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; padding: 0 4px 8px; }
.rail-head h2 { margin: 0; color: var(--faint); font-size: 0.72rem; font-weight: 600; letter-spacing: 0; }
.rail-count { order: 2; flex-basis: 100%; color: var(--muted); font-size: 0.7rem; }
.rail-head .mini { margin-left: auto; min-height: 26px; }
.rail-list { display: grid; gap: 4px; min-height: 0; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.rail-group { margin: 8px 4px 2px; color: var(--faint); font-size: 0.7rem; }
.rail-device {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.rail-device.off .rail-text b { color: var(--muted); }
.rail-dot { width: 8px; height: 8px; background: var(--ok); border: 1.5px solid var(--ok); border-radius: 50%; }
.rail-dot[data-status="simulation"], .rail-dot[data-status="unlinked"] { background: transparent; border-color: var(--faint); }
.rail-dot[data-status="connecting"] { background: transparent; border-color: var(--warn); animation: breathe 1.2s ease-in-out infinite; }
.rail-dot[data-status="error"], .rail-dot[data-status="failed"] { background: var(--bad); border-color: var(--bad); }
.rail-dot[data-status="offline"] { background: transparent; border-color: var(--bad); }
.rail-text { display: grid; min-width: 0; line-height: 1.25; }
.rail-text b { overflow: hidden; font-size: 0.78rem; font-weight: 560; white-space: nowrap; text-overflow: ellipsis; }
.rail-text small { overflow: hidden; color: var(--muted); font-size: 0.68rem; white-space: nowrap; text-overflow: ellipsis; }
.rail-link { display: grid; place-items: center; width: 28px; height: 28px; padding: 0; color: var(--muted); background: transparent; border: 0; border-radius: var(--r-xs); }
.rail-link:hover:not(:disabled) { color: var(--text); background: var(--surface-hover); }
.rail-link:disabled { opacity: 0.4; cursor: not-allowed; }
.rail-link svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.rail-link[aria-pressed="true"] { color: var(--cyan); }
.rail-power { min-height: 0; }
.rail-power i { width: 34px; height: 20px; }
.rail-power i::after { top: 2px; left: 2px; width: 16px; height: 16px; }
.rail-power input:checked + i::after { transform: translateX(14px); }
.rail-empty { padding: 4px; }
.rail-empty p { margin: 0 0 8px; color: var(--muted); font-size: 0.76rem; }

/* ---------- Room view ---------- */
.hero { position: relative; }
h1 { margin: 0; font: 640 2rem/1.08 var(--display); letter-spacing: -0.03em; }
.tagline { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.placeholder-note {
  display: inline-block;
  margin: 10px 0 0;
  padding: 5px 10px;
  color: var(--warn);
  font-size: 0.78rem;
  background: rgba(255, 191, 90, 0.1);
  border: 1px solid rgba(255, 191, 90, 0.3);
  border-radius: 999px;
}

.panel {
  display: flex;
  flex-direction: column;
  border-radius: var(--r-lg);
  transition: opacity var(--slow), transform var(--slow) var(--ease), width var(--slow) var(--ease);
}
.intro { transition: opacity var(--slow), transform var(--slow) var(--ease); }

/* ---------- Section pages ---------- */
.pages { position: relative; }
.page { min-height: 100svh; }

/* An existing dialog shown as a page: it keeps its own code and lifecycle */
dialog.sheet.as-page {
  position: fixed;
  z-index: 3;
  inset: 0 0 0 var(--sidebar-width);
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--text);
  background: radial-gradient(70% 50% at 100% 0%, color-mix(in srgb, var(--live) 9%, transparent), transparent 70%), var(--bg);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  animation: page-in var(--slow) var(--ease) both;
}
dialog.sheet.as-page > .sheet-head {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: none;
  margin: 0;
  padding: 28px max(40px, calc((100% - 1040px) / 2)) 16px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  border: 0;
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: var(--blur-light);
  backdrop-filter: var(--blur-light);
}
dialog.sheet.as-page > .sheet-head h2 { margin: 0; font-size: 1.75rem; font-weight: 640; letter-spacing: -0.03em; }
dialog.sheet.as-page > .sheet-body { max-width: 1120px; max-height: none; margin: 0 auto; padding: 20px 40px 64px; overflow: visible; }

/* The All rooms controls, set into the Dashboard */
dialog.sheet.as-panel {
  position: static;
  display: block;
  width: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: visible;
  color: var(--text);
  background: transparent;
  border: 0;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  animation: none;
}
dialog.sheet.as-panel > .sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 0 4px; border: 0; background: none; }
dialog.sheet.as-panel > .sheet-head h2 { margin: 0; font-size: 1rem; font-weight: 620; letter-spacing: -0.01em; }
dialog.sheet.as-panel > .sheet-head .ghost { min-height: 30px; padding: 0 10px; font-size: 0.76rem; color: var(--muted); }
dialog.sheet.as-panel > .sheet-body { max-height: none; padding: 0; overflow: visible; }

/* What each route shows */
/* The room keeps rendering (other copies and streams depend on it), just out of sight */
body:not([data-route="room"]):not([data-route="scenes"]):not([data-route="effects"]):not([data-route="sync"]) .room-stage { z-index: -1; opacity: 0; pointer-events: none; }
[tabindex="-1"]:focus { outline: none; }
body:not([data-route="room"]):not([data-route="scenes"]):not([data-route="effects"]):not([data-route="sync"]) :is(.hero, main, footer) { display: none; }
body[data-route="room"] .pages, body[data-route="scenes"] .pages, body[data-route="effects"] .pages, body[data-route="sync"] .pages { display: none; }

/* ---------- Cinema ---------- */
.cinema-bar {
  position: fixed;
  z-index: 7;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 6px 6px 18px;
  color: var(--text);
  font-size: 0.86rem;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--slow);
}
body.watching .cinema-bar { opacity: 1; pointer-events: auto; }
body.watching :is(.intro, .panel, .device-rail, .top, .bottom-nav) { opacity: 0; pointer-events: none; }
body.watching .top { transform: translateX(-12px); }
body.watching .panel { transform: translateX(16px); }
body.watching :is(main, footer, .pages) { display: none; }
body.watching { overflow: hidden; }
body.watching .room-stage, body.editing .room-stage { position: fixed; inset: 0; width: 100vw; height: 100vh; border: 0; border-radius: 0; visibility: visible; }
body.watching .room, body.editing .room { --view-w: 100vw; --view-h: 100vh; }
body.watching .hero { pointer-events: none; }
body.editing .room-stage::after { display: none; }
body.editing :is(.bottom-nav, .pages, dialog.sheet.as-page) { display: none; }

/* ---------- Below the room: gallery and notes ---------- */
main { position: relative; padding-block: 56px 24px; background: var(--bg); border-top: 1px solid var(--line); }
section { margin-block: 0 72px; }
.pages section { margin: 0; }
footer { padding-block: 28px 40px; color: var(--muted); text-align: center; background: var(--bg); }
footer a { color: var(--muted); }
.about h2 { margin: 0 0 14px; font-size: 1.5rem; }
.about p { max-width: 38em; margin: 0 0 1em; color: var(--muted); }
.js .rise { opacity: 0; transform: translateY(16px); transition: opacity 0.7s var(--ease), transform 0.7s var(--ease); }
.js .rise.seen { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .js .rise { opacity: 1; transform: none; } }

/* ---------- Tours ---------- */
.tour {
  position: fixed;
  z-index: 8;
  bottom: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 14px 14px 20px;
  background: var(--glass-strong);
  border: 1px solid var(--edge);
  border-radius: var(--r-lg);
  box-shadow: var(--sheen), var(--lift);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  animation: rise var(--med) var(--ease);
}
.tour-main { flex: 1; min-width: 0; }
.tour-text { margin: 0; font-size: 0.98rem; font-weight: 560; line-height: 1.4; }
.tour-progress { display: block; height: 3px; margin-top: 10px; overflow: hidden; background: rgba(255, 255, 255, 0.1); border-radius: 2px; }
.tour-progress i { display: block; height: 100%; background: var(--violet); transform: scaleX(0); transform-origin: left; }
.panel .greeting { position: static; inset: auto; flex: none; width: auto; min-width: 0; margin: 0 0 12px; padding: 10px 12px; box-shadow: none; animation: none; }
.greeting .tour-text { font-size: 0.85rem; }
.greeting .tour-progress { margin-top: 6px; height: 2px; }
.greeting[hidden] { display: none; }

.bottom-nav { display: none; }
@media (max-width: 1100px) { .deck-expand { display: none; } }

@keyframes breathe { 50% { opacity: 0.45; } }
@keyframes page-in { from { opacity: 0; transform: translateY(8px); } }

/* ================= Desktop: sidebar, room in the centre, deck on the right ================= */
@media (min-width: 1101px) {
  .top {
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    flex-direction: column;
    gap: 0;
    padding: 18px 12px 14px;
    overflow-x: hidden;
    overflow-y: auto;
    background: radial-gradient(120% 40% at 0% 0%, color-mix(in srgb, var(--live) 10%, transparent), transparent 70%), var(--sidebar);
    border: 0;
    border-right: 1px solid var(--edge);
    border-radius: 0;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    transition: width var(--slow) var(--ease);
  }
  .nav-head { justify-content: space-between; padding: 0 2px 0 6px; }
  .top > .nav-tools { flex: none; margin-top: 6px; }
  .top .rooms { flex-direction: column; gap: 2px; margin: 2px 0 4px 18px; padding-left: 8px; border-left: 1px solid var(--line); }
  .top .room-card { width: 100%; }
  .top > .mode { order: 3; margin: 14px 0 0; justify-content: center; }
  .top > .device-rail { order: 2; flex: 1 0 auto; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

  .room-stage { top: 0; left: var(--sidebar-width); right: calc(var(--control-width) + 40px); height: 100svh; transition: left var(--slow) var(--ease), right var(--slow) var(--ease); }
  .room { --view-w: calc(100vw - var(--sidebar-width) - var(--control-width) - 40px); --view-h: 100svh; }
  .hero { margin-left: var(--sidebar-width); height: 100svh; min-height: 560px; transition: margin-left var(--slow) var(--ease); }
  .intro { position: absolute; z-index: 1; top: 28px; left: 32px; max-width: calc(100% - var(--control-width) - 120px); text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8); }
  .panel { position: absolute; z-index: 2; top: 20px; right: 20px; bottom: 20px; width: var(--control-width); margin: 0; padding: 20px; }
  main, footer, .pages { margin-left: var(--sidebar-width); transition: margin-left var(--slow) var(--ease); }
  footer.wrap { width: auto; }
  .tour { left: calc(var(--sidebar-width) + 32px); width: min(520px, calc(100vw - var(--sidebar-width) - var(--control-width) - 120px)); min-width: 0; }

  /* The deck widens into a studio from the handle on its left edge, and back */
  body.deck-wide { --control-width: clamp(460px, 42vw, 640px); }
  .deck-expand {
    position: absolute;
    z-index: 3;
    top: 50%;
    left: -13px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 56px;
    padding: 0;
    color: var(--muted);
    background: var(--glass-raised);
    border: 1px solid var(--edge-strong);
    border-radius: 999px;
    box-shadow: var(--sheen), 0 6px 16px -6px rgba(0, 0, 0, 0.7);
    -webkit-backdrop-filter: var(--blur-light);
    backdrop-filter: var(--blur-light);
    transform: translateY(-50%);
    transition: color var(--fast), background var(--fast), border-color var(--fast);
  }
  .deck-expand:hover { color: var(--text); background: var(--elevated); border-color: color-mix(in srgb, var(--violet) 55%, var(--edge-strong)); }
  .deck-expand svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform var(--med) var(--ease); }
  .deck-expand[aria-pressed="true"] svg { transform: scaleX(-1); }

  /* Collapsed: an icon rail */
  body.nav-collapsed { --sidebar-width: var(--sidebar-rail); }
  body.nav-collapsed .top { padding-inline: 10px; }
  body.nav-collapsed .nav-head { flex-direction: column; gap: 10px; padding: 0; }
  body.nav-collapsed .logo span, body.nav-collapsed .nav-group, body.nav-collapsed .room-text, body.nav-collapsed .top > .device-rail { display: none; }
  body.nav-collapsed .nav-item { justify-content: center; padding: 0; font-size: 0; }
  body.nav-collapsed .top .rooms { margin: 2px 0 4px; padding: 0; border: 0; align-items: center; }
  body.nav-collapsed .top .room-card { width: auto; padding: 4px; }
  body.nav-collapsed .top > .mode { width: 34px; padding: 0; font-size: 0; justify-content: center; gap: 0; }
  body.nav-collapsed .nav-collapse svg { transform: scaleX(-1); }
}

@media (min-width: 1101px) and (max-height: 760px) {
  .top > .device-rail { display: none; }
}

/* ================= Tablets and phones ================= */
@media (max-width: 1100px) {
  :root { --top-h: 120px; }
  body:not([data-route="room"]):not([data-route="scenes"]):not([data-route="effects"]):not([data-route="sync"]) { --top-h: 64px; }

  .top {
    inset: 0 0 auto;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--edge);
    border-radius: 0;
    box-shadow: none;
    /* A blur on the bar itself would make it the frame of the fixed menu below it,
       squeezing the menu into the bar; the glass lives on a layer behind instead */
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .top::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 0;
    background: var(--glass-strong);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
  }
  .nav-head { flex: 1; height: 44px; }
  .nav-collapse { display: none; }
  .menu-toggle { display: inline-grid; width: 44px; height: 44px; color: var(--text); border-color: var(--line); background: var(--surface); }
  .menu-toggle[aria-expanded="true"] { background: var(--surface-press); border-color: var(--edge-strong); }
  .top > .mode { order: 1; min-height: 38px; }
  .top > .menu-toggle { order: 2; }
  .top > .rooms { order: 3; width: 100%; height: 48px; overflow-x: auto; scrollbar-width: none; gap: 6px; }
  body:not([data-route="room"]):not([data-route="scenes"]):not([data-route="effects"]):not([data-route="sync"]) .top > .rooms { display: none; }
  .top .room-card { min-height: 46px; padding-right: 12px; }
  .room-status { max-width: 110px; }

  .nav-tools {
    position: fixed;
    z-index: 9;
    top: var(--top-h);
    right: 0;
    bottom: calc(var(--bottom-nav) + env(safe-area-inset-bottom));
    left: 0;
    display: none;
    flex-direction: column;
    gap: 2px;
    padding: 8px 16px 24px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--glass-strong);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
  }
  .top.menu-open .nav-tools { display: flex; animation: page-in var(--med) var(--ease); }
  .nav-item { min-height: 48px; font-size: 0.95rem; }
  .nav-tools > .device-rail { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
  .nav-tools .rail-list { max-height: none; }

  :root { --stage-h: clamp(200px, calc((100vw - 32px) * 0.5625), 46svh); }
  .room-stage { top: calc(var(--top-h) + 10px); left: 16px; right: 16px; height: var(--stage-h); border: 1px solid var(--edge); border-radius: var(--r-lg); }
  .room { --view-w: calc(100vw - 32px); --view-h: var(--stage-h); }
  .hero { display: block; padding: calc(var(--top-h) + 10px + var(--stage-h) + 14px) 16px 24px; }
  .intro { padding: 2px 4px 14px; }
  h1 { font-size: 1.6rem; }
  .tagline { display: none; }
  .panel { width: 100%; padding: 18px; }
  dialog.sheet.as-page { inset: var(--top-h) 0 calc(var(--bottom-nav) + env(safe-area-inset-bottom)) 0; }
  dialog.sheet.as-page > .sheet-head { padding: 16px 16px 12px; }
  dialog.sheet.as-page > .sheet-head h2 { font-size: 1.4rem; }
  dialog.sheet.as-page > .sheet-body { padding: 4px 16px 32px; }
  .pages { padding-top: var(--top-h); }
  body { padding-bottom: calc(var(--bottom-nav) + env(safe-area-inset-bottom)); }

  .bottom-nav {
    position: fixed;
    z-index: 8;
    inset: auto 0 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: calc(var(--bottom-nav) + env(safe-area-inset-bottom));
    padding: 6px 8px env(safe-area-inset-bottom);
    background: var(--glass-strong);
    border: 0;
    border-top: 1px solid var(--edge);
    border-radius: 0;
    box-shadow: 0 -12px 30px -18px rgba(0, 0, 0, 0.8);
  }
  .bottom-nav button {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 3px;
    min-width: 0;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 560;
    background: none;
    border: 0;
    border-radius: var(--r-sm);
  }
  .bottom-nav button .nav-icon { width: 22px; height: 22px; }
  .bottom-nav button[aria-current="page"] { color: var(--text); }
  .bottom-nav button[aria-current="page"] .nav-icon { color: color-mix(in srgb, var(--live) 55%, #fff); }
  .toasts { bottom: calc(var(--bottom-nav) + 16px + env(safe-area-inset-bottom)); right: 16px; }
  .tour { left: 12px; right: 12px; bottom: calc(var(--bottom-nav) + 12px); }
  .cinema-bar { bottom: calc(16px + env(safe-area-inset-bottom)); }
  .wrap { padding-inline: 16px; }
  section { margin-bottom: 48px; }
}

@media (max-width: 480px) {
  :root { --stage-h: clamp(190px, calc((100vw - 20px) * 0.5625), 46svh); }
  .room-stage { left: 10px; right: 10px; }
  .room { --view-w: calc(100vw - 20px); }
  .hero { padding-inline: 10px; }
  .panel { padding: 16px; }
  .logo span { font-size: 1.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  .mode[data-mode="hardware"]::before, .rail-dot[data-status="connecting"] { animation: none; }
  dialog.sheet.as-page { animation: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .top, .panel, .cinema-bar, .bottom-nav, .tour, .nav-tools, .top::before { background: var(--glass-solid); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .room-stage::before { display: none; }
}
