/* Spaces playground. Panels float over a full-bleed canvas; every size is tuned so the
   camera's free area (see layout() in main.js) stays generous at 1440, 1024 and 390. */
html, body { margin: 0; height: 100%; }
body { background: #efe9e1; }
#spaces { position: fixed; inset: 0; }

.sp {
  --accent: #b4532a;
  --ink: #24211e;
  --muted: #7a726a;
  --line: rgba(60, 45, 30, 0.1);
  --panel: rgba(255, 253, 250, 0.84);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 18px 40px -18px rgba(70, 50, 30, 0.28), 0 2px 6px rgba(70, 50, 30, 0.06);
  --gap: 16px;
  --sum-w: 284px;
  --insp-w: 344px;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font: 14px/1.4 ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  background: radial-gradient(110% 85% at 55% 45%, #f8f5f0 0%, #f0eae2 58%, #e7dfd4 100%);
  user-select: none;
}
.sp *, .sp *::before, .sp *::after { box-sizing: border-box; }
.sp button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.sp button:focus-visible, .sp input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sp-stage, .sp-canvas, .sp-labels { position: absolute; inset: 0; }
.sp-canvas { display: block; touch-action: none; }
.sp-labels { pointer-events: none; }

/* ---------- floating labels (CSS2D owns transform + display on .sp-tag) ---------- */
.sp-tag { pointer-events: none; }
.sp-tag-in {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 8px 3px 6px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.93);
  box-shadow: 0 1px 2px rgba(40, 30, 20, 0.12), 0 4px 10px -4px rgba(40, 30, 20, 0.2);
  font-size: 11px; line-height: 1; white-space: nowrap;
  transform: translateY(-4px);
}
.sp-tag-in::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #7fbf9c; }
.sp-tag-in[data-state="in-use"]::before { background: #e7855f; }
.sp-tag-in[data-state="reserved"]::before { background: #8b98e3; }
.sp-tag-in[data-state="attention"]::before { background: #eeb948; }
.sp-tag-in[data-state="disabled"]::before { background: #bab4ab; }
.sp-tag-in b { font-weight: 650; letter-spacing: -0.01em; }
.sp-tag-in span { color: var(--muted); font-variant-numeric: tabular-nums; }
.sp[data-mode="design"] .sp-tag-in::before { display: none; }
.sp[data-mode="design"] .sp-tag-in { padding: 3px 8px; }

/* Component display rules (flex/grid) must never beat the hidden attribute (lock=1, tabs=0). */
.sp [hidden] { display: none !important; }

/* ---------- top bar ---------- */
.sp-top {
  position: absolute; top: var(--gap); left: var(--gap); right: var(--gap);
  display: flex; align-items: center; gap: 12px; pointer-events: none; z-index: 4;
}
.sp-top > * { pointer-events: auto; }
.sp-brand { display: flex; align-items: baseline; gap: 6px; padding: 0 6px 0 4px; flex: none; }
.sp-mark {
  align-self: center; width: 22px; height: 22px; border-radius: 7px; margin-right: 4px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 82%, white), var(--accent));
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.16), 0 3px 8px -3px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: background 0.4s;
}
.sp-brand b { font-size: 17px; font-weight: 700; letter-spacing: -0.03em; }
.sp-brand i { font-style: normal; color: var(--muted); font-size: 12.5px; }
.sp-packs, .sp-seg {
  display: flex; gap: 2px; padding: 4px; border-radius: 999px;
  background: var(--panel); backdrop-filter: blur(18px) saturate(1.25); -webkit-backdrop-filter: blur(18px) saturate(1.25);
  box-shadow: var(--shadow);
}
.sp-packs { margin: 0 auto; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
.sp-top:has(.sp-packs[hidden]) .sp-seg { margin-left: auto; }
.sp-packs::-webkit-scrollbar { display: none; }
.sp-packs button, .sp-seg button {
  display: flex; align-items: center; gap: 7px; flex: none;
  height: 34px; padding: 0 14px; border-radius: 999px;
  font-size: 13px; font-weight: 550; color: var(--muted);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.sp-packs button:hover, .sp-seg button:hover { color: var(--ink); }
.sp-packs button[aria-selected="true"], .sp-seg button[aria-pressed="true"] {
  background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(40, 30, 20, 0.14);
}
.sp-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dot); opacity: 0.55; transition: opacity 0.2s; }
.sp-packs button[aria-selected="true"] .sp-dot { opacity: 1; }
.sp--embed .sp-brand { display: none; }

/* ---------- panels ---------- */
.sp-panel {
  position: absolute; z-index: 3;
  background: var(--panel); backdrop-filter: blur(20px) saturate(1.25); -webkit-backdrop-filter: blur(20px) saturate(1.25);
  border-radius: 18px; box-shadow: var(--shadow);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.25s;
}
.sp-kicker { margin: 0 0 4px; font-size: 12px; font-weight: 600; color: var(--accent); letter-spacing: 0.01em; transition: color 0.4s; }
.sp h1, .sp h2 { margin: 0; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.sp h1 { font-size: 26px; }
.sp h2 { font-size: 24px; }
.sp h3 { margin: 18px 0 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.sp-tagline { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.sp-sub { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--muted); }

.sp-summary, .sp-library { top: 80px; left: var(--gap); width: var(--sum-w); padding: 20px; }
.sp-library { max-height: calc(100% - 96px); overflow-y: auto; scrollbar-width: thin; }
.sp-summary[data-on="0"], .sp-library[data-on="0"] { transform: translateX(-16px); opacity: 0; pointer-events: none; visibility: hidden; }

.sp-util { display: flex; align-items: center; gap: 14px; margin: 18px 0 12px; }
.sp-util b { font-size: 44px; font-weight: 700; letter-spacing: -0.05em; line-height: 1; font-variant-numeric: tabular-nums; }
.sp-util small { font-size: 22px; font-weight: 600; color: var(--muted); margin-left: 1px; }
.sp-util span { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.sp-bar { display: flex; gap: 3px; height: 8px; margin-bottom: 14px; }
.sp-bar i { border-radius: 4px; transition: flex 0.4s; }
.sp-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sp-legend li { display: flex; align-items: center; gap: 9px; padding: 5px 0; font-size: 13px; }
.sp-legend li::before { content: ""; width: 9px; height: 9px; border-radius: 3px; background: var(--c); }
.sp-legend span { flex: 1; }
.sp-legend b { font-weight: 600; font-variant-numeric: tabular-nums; }
.sp-wire {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.sp-wire svg { width: 22px; height: 10px; color: var(--accent); }
.sp-wire b { color: var(--ink); font-weight: 600; }

.sp-lib-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.sp-lib-item {
  position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  padding: 6px 6px 9px; border-radius: 14px; text-align: left;
  background: rgba(255, 255, 255, 0.7); box-shadow: 0 0 0 1px var(--line) inset;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}
.sp-lib-item:hover { background: #fff; transform: translateY(-1px); box-shadow: 0 0 0 1px var(--line) inset, 0 8px 18px -10px rgba(60, 40, 20, 0.35); }
.sp-lib-item img { width: 100%; aspect-ratio: 168 / 120; border-radius: 10px; background: #f3eee7; }
.sp-lib-item span { padding: 0 4px; font-size: 12.5px; font-weight: 600; letter-spacing: -0.01em; }
.sp-lib-item small {
  position: absolute; top: 10px; right: 10px; min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center; border-radius: 10px;
  background: rgba(255, 255, 255, 0.9); font-size: 11px; font-weight: 600; color: var(--muted);
}
.sp-hint { margin: 16px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.sp kbd { padding: 1px 5px; border-radius: 5px; background: #fff; box-shadow: 0 0 0 1px var(--line); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- inspector ---------- */
.sp-inspector {
  top: 80px; right: var(--gap); width: var(--insp-w); max-height: calc(100% - 96px);
  padding: 20px; overflow-y: auto; scrollbar-width: thin;
  transform: translateX(24px); opacity: 0; pointer-events: none; visibility: hidden;
}
.sp.has-inspector .sp-inspector { transform: none; opacity: 1; pointer-events: auto; visibility: visible; }
.sp[data-mode="operate"] .sp-inspector { max-height: calc(100% - 196px); }
.sp-insp-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.sp-x { width: 30px; height: 30px; margin: -6px -6px 0 0; display: grid; place-items: center; border-radius: 10px; color: var(--muted); }
.sp-x:hover { background: rgba(0, 0, 0, 0.05); color: var(--ink); }
.sp-x svg { width: 16px; height: 16px; }
.sp-status {
  display: inline-flex; align-items: center; gap: 8px; margin: 12px 0 4px;
  padding: 6px 12px 6px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 18%, white);
  font-size: 13px; font-weight: 600;
}
.sp-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.sp-status span { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.sp-facts { margin: 14px 0 0; }
.sp-facts div { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 13px; }
.sp-facts dt { color: var(--muted); flex: none; }
.sp-facts dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

.sp-tl { margin-top: 16px; }
.sp-tl-track { position: relative; height: 36px; border-radius: 10px; background: rgba(60, 45, 30, 0.06); overflow: hidden; }
.sp-tl-b {
  position: absolute; top: 4px; bottom: 4px; min-width: 4px; padding: 0 6px; border-radius: 6px;
  background: color-mix(in srgb, var(--c) 72%, white); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7) inset;
  font-size: 10.5px; font-weight: 600; text-align: left; overflow: hidden;
}
.sp-tl-b span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-tl-b:hover { filter: brightness(0.96); }
.sp-tl-now { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--ink); border-radius: 1px; pointer-events: none; }
.sp-tl-ticks { position: relative; height: 18px; margin-top: 4px; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sp-tl-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.sp-tl-ticks span:first-child { transform: none; }
.sp-tl-ticks span:last-child { transform: translateX(-100%); }

.sp-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.sp-actions--row { grid-template-columns: repeat(3, 1fr); }
.sp-actions button {
  min-height: 40px; padding: 8px 12px; border-radius: 12px;
  background: #fff; box-shadow: 0 0 0 1px var(--line) inset, 0 1px 2px rgba(40, 30, 20, 0.06);
  font-size: 13px; font-weight: 600; line-height: 1.2;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
}
.sp-actions button:hover { box-shadow: 0 0 0 1px rgba(60, 45, 30, 0.2) inset, 0 4px 10px -6px rgba(40, 30, 20, 0.35); }
.sp-actions button:active { transform: scale(0.98); }
.sp-actions .is-primary { background: var(--accent); color: #fff; box-shadow: 0 6px 14px -8px var(--accent); }
.sp-actions .is-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); box-shadow: 0 8px 16px -8px var(--accent); }
.sp-actions .is-quiet { grid-column: 1 / -1; background: transparent; box-shadow: none; color: var(--muted); min-height: 32px; font-weight: 550; }
.sp-actions .is-quiet:hover { color: var(--ink); box-shadow: none; background: rgba(0, 0, 0, 0.04); }
.sp-actions .is-danger { color: #a63a2b; }
.sp-link { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); line-height: 1.5; }
.sp-link b { color: var(--ink); font-weight: 600; }
.sp code, .sp-toast code { font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; }

.sp-field { display: grid; gap: 6px; margin-top: 16px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.sp-field span { display: flex; justify-content: space-between; }
.sp-field output { color: var(--ink); font-variant-numeric: tabular-nums; }
.sp-field input[type="text"], .sp-field input:not([type]) {
  height: 40px; padding: 0 12px; border-radius: 11px; border: 0;
  background: #fff; box-shadow: 0 0 0 1px var(--line) inset;
  font: 600 14px/1 inherit; color: var(--ink); user-select: text;
}
.sp-field input[type="range"] { accent-color: var(--accent); width: 100%; }

/* ---------- view rail ---------- */
.sp-rail {
  position: absolute; z-index: 3; top: 80px; right: var(--gap);
  display: flex; flex-direction: column; gap: 2px; padding: 4px; border-radius: 14px;
  background: var(--panel); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); box-shadow: var(--shadow);
  transition: right 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sp.has-inspector .sp-rail { right: calc(var(--insp-w) + var(--gap) * 2); }
.sp-rail button { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); }
.sp-rail button:hover { background: #fff; color: var(--ink); }
.sp-rail svg { width: 18px; height: 18px; }
.sp-rail-txt { font-size: 12px !important; font-weight: 700; }

/* ---------- time dock ---------- */
.sp-dock {
  left: calc(var(--sum-w) + var(--gap) * 2); right: var(--gap); bottom: var(--gap);
  display: flex; align-items: center; gap: 14px; padding: 12px 14px 12px 12px;
  transition: transform 0.35s, opacity 0.25s;
}
.sp[data-mode="design"] .sp-dock { transform: translateY(24px); opacity: 0; pointer-events: none; visibility: hidden; }
.sp-play {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 50%;
  background: var(--accent) !important; color: #fff !important; box-shadow: 0 8px 18px -10px var(--accent);
}
.sp-play svg { width: 18px; height: 18px; }
.sp-clock { display: grid; min-width: 92px; flex: none; }
.sp-clock b { font-size: 20px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.sp-clock span { font-size: 12px; color: var(--muted); }
.sp-scrub { flex: 1; min-width: 0; display: grid; gap: 8px; }
.sp-days { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.sp-days::-webkit-scrollbar { display: none; }
.sp-days button {
  flex: 1 0 auto; min-width: 40px; display: grid; justify-items: center; padding: 4px 6px; border-radius: 9px;
  font-size: 10.5px; color: var(--muted); line-height: 1.2;
}
.sp-days button b { font-weight: 600; }
.sp-days button span { font-size: 13px; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.sp-days button:hover { background: rgba(0, 0, 0, 0.04); }
.sp-days button[aria-pressed="true"] { background: var(--ink); color: rgba(255, 255, 255, 0.7); }
.sp-days button[aria-pressed="true"] span { color: #fff; }
.sp-track { position: relative; height: 40px; cursor: ew-resize; touch-action: none; border-radius: 8px; }
.sp-track svg { position: absolute; inset: 0; width: 100%; height: 100%; color: var(--accent); }
.sp-track rect { fill: currentColor; opacity: 0.3; }
.sp-track-now { position: absolute; top: -2px; bottom: -2px; width: 0; border-left: 1.5px dashed color-mix(in srgb, var(--accent) 70%, transparent); }
.sp-thumb { position: absolute; top: -4px; bottom: -4px; width: 3px; margin-left: -1.5px; border-radius: 2px; background: var(--ink); pointer-events: none; }
.sp-thumb::after { content: ""; position: absolute; left: 50%; top: -3px; width: 11px; height: 11px; margin-left: -5.5px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 2px #fff; }
.sp-now { flex: none; height: 32px; padding: 0 12px; border-radius: 10px; font-size: 12.5px; font-weight: 600; color: var(--muted); box-shadow: 0 0 0 1px var(--line) inset; }
.sp-now:hover { color: var(--ink); background: #fff; }

/* ---------- toasts ---------- */
.sp-toasts { position: absolute; z-index: 6; top: 80px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.sp-toast {
  display: grid; gap: 3px; padding: 10px 16px; border-radius: 14px; max-width: min(440px, 90vw);
  background: rgba(36, 33, 30, 0.94); color: #fff; box-shadow: 0 14px 30px -14px rgba(0, 0, 0, 0.5);
  font-size: 13px; opacity: 0; transform: translateY(-6px); transition: opacity 0.25s, transform 0.25s;
}
.sp-toast.is-in { opacity: 1; transform: none; }
.sp-toast b { font-weight: 600; }
.sp-toast code { color: #f2c9a4; }
.sp-toast.is-warn { background: #fff; color: var(--ink); box-shadow: 0 0 0 1px var(--line), 0 14px 30px -14px rgba(0, 0, 0, 0.35); }

/* ---------- compact desktop ---------- */
@media (max-width: 1180px) {
  .sp { --sum-w: 244px; --insp-w: 304px; }
  .sp h1 { font-size: 22px; }
  .sp-util b { font-size: 36px; }
  .sp-tagline { font-size: 12.5px; }
  .sp-brand i { display: none; }
}

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .sp { --gap: 10px; }
  .sp-top { flex-wrap: wrap; gap: 8px; }
  .sp-brand { flex: 1; }
  .sp-brand i { display: none; }
  .sp-packs { order: 3; width: 100%; margin: 0; }
  .sp-packs button { height: 32px; padding: 0 12px; font-size: 12.5px; }
  .sp-seg button { height: 30px; padding: 0 12px; font-size: 12.5px; }
  .sp--embed .sp-packs { order: 0; width: auto; flex: 1; }

  .sp-summary { top: 104px; left: var(--gap); right: auto; width: auto; padding: 10px 14px; display: flex; align-items: center; gap: 12px; }
  .sp-summary > :not(.sp-util) { display: none; }
  .sp-util { margin: 0; gap: 10px; }
  .sp-util b { font-size: 26px; }
  .sp-util small { font-size: 14px; }
  .sp-util span { font-size: 11.5px; }

  .sp-rail { top: 104px; }
  .sp.has-inspector .sp-rail { right: var(--gap); }
  .sp-summary { max-width: calc(100% - 76px); }
  .sp-rail button { width: 34px; height: 34px; }

  .sp-dock { left: var(--gap); right: var(--gap); flex-wrap: wrap; gap: 10px; padding: 10px; }
  .sp-scrub { order: 3; flex-basis: 100%; }
  .sp-clock { flex: 1; }

  .sp-inspector, .sp-library {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 58%;
    border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
    transform: translateY(32px);
  }
  .sp.has-inspector .sp-inspector { z-index: 5; }
  .sp[data-mode="operate"] .sp-inspector { max-height: 58%; }
  .sp-inspector[data-kind="room"] { display: none; }
  .sp-library { max-height: 196px; padding-bottom: 14px; transform: none; }
  .sp-library[data-on="0"] { transform: translateY(24px); }
  .sp-library h2, .sp-library h3, .sp-library .sp-kicker, .sp-library .sp-hint { display: none; }
  .sp-library { display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; }
  .sp-lib-grid { display: contents; }
  .sp-lib-item { flex: 0 0 116px; }
  .sp h2 { font-size: 21px; }
  .sp-toasts { top: 104px; width: calc(100% - 20px); }
  /* Embedded, the top bar is a single row: pull the floating panels up under it. */
  .sp--embed .sp-summary, .sp--embed .sp-rail, .sp--embed .sp-toasts { top: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  .sp *, .sp *::before, .sp *::after { transition-duration: 0.01ms !important; }
}
