/* ────────────────────────────────────────────────────────────
   PULSE — studio v3.3
   Fixed-height layout · no page scroll · collapsible right rail
   ────────────────────────────────────────────────────────── */

/* prevent body scroll while in studio */
html.st-mounted, html.st-mounted body { overflow: hidden; height: 100%; }
html.st-mounted #root { height: 100%; overflow: hidden; }

.st {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr 56px;
  height: calc(100vh - 64px - 51px); /* nav + studio-tabs */
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}
.st.right-open { grid-template-columns: 320px 1fr 360px; }

/* ── LEFT RAIL ──────────────────────────────────────────── */
.st-l {
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
.st-l-head {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 12px;
}
.st-l-character { display: flex; align-items: center; gap: 12px; }
.st-l-av { width: 38px; height: 38px; border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.st-l-av img { width: 100%; height: 100%; object-fit: cover; }
.st-l-name {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.012em;
  line-height: 1.1;
}
.st-l-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 3px;
}

.st-l-search {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 12.5px;
  color: var(--ink);
  outline: none;
  font-family: var(--font-ui);
}
.st-l-search:focus { border-color: var(--pulse); }

.st-l-crumbs {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
}
.st-l-crumb {
  padding: 3px 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-3);
  transition: all 0.15s;
}
.st-l-crumb:hover { color: var(--ink); background: var(--panel-2); }
.st-l-crumb.is-current {
  background: var(--pulse-soft);
  color: var(--pulse-hi);
  border-color: var(--pulse);
}
.st-l-crumb-sep { color: var(--ink-4); }

.st-l-body {
  flex: 1; overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.st-l-body::-webkit-scrollbar { width: 5px; }
.st-l-body::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }

.st-l-group { margin-bottom: 18px; }
.st-l-group-head {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-3);
}
.st-l-group-head .n { margin-left: auto; color: var(--ink-4); }

/* scene row */
.st-scene {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s var(--ease);
  border: 1px solid transparent;
  position: relative;
}
.st-scene:hover { background: var(--surface-2); }
.st-scene.is-active {
  background: oklch(from var(--pulse) l c h / 0.10);
  border-color: oklch(from var(--pulse) l c h / 0.35);
}
.st-scene-thumb {
  width: 36px; height: 36px;
  border-radius: 7px;
  overflow: hidden;
  background: var(--surface-2);
  flex-shrink: 0;
}
.st-scene-thumb.sm { width: 28px; height: 28px; border-radius: 5px; }
.st-scene-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.st-scene-meta { flex: 1; min-width: 0; }
.st-scene-name {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 12.5px;
  letter-spacing: -0.005em;
  line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.st-scene-cat {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 2px;
}
.st-scene-pool-dot {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--pulse);
  flex-shrink: 0;
  box-shadow: 0 0 6px oklch(from var(--pulse) l c h / 0.6);
}
.st-scene-del {
  width: 22px; height: 22px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px;
  background: oklch(0.74 0.20 28 / 0.14);
  border: 1px solid oklch(0.74 0.20 28 / 0.36);
  color: oklch(0.82 0.20 28);
  transition: all 0.15s;
}
.st-scene-del:hover { background: oklch(0.74 0.20 28 / 0.28); }
.st-r-rule-add { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.st-r-sel {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; font-size: 12px; color: var(--ink);
  outline: none; font-family: var(--font-ui);
}
.st-r-sel:focus { border-color: var(--pulse); }

/* sub-machine nested children with connecting line */
.st-scene-sub {
  margin-left: 22px;
  padding-left: 12px;
  border-left: 1.5px solid oklch(from var(--cat-twopart) l c h / 0.4);
  position: relative;
  padding-top: 4px; padding-bottom: 8px;
  margin-bottom: 4px;
}
.st-scene-sub-head {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px;
  margin-bottom: 2px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--cat-twopart);
  transition: background 0.15s;
}
.st-scene-sub-head:hover { background: oklch(from var(--cat-twopart) l c h / 0.08); }
.st-scene-sub-arrow { margin-left: auto; color: var(--ink-3); }
.st-scene-sub-line {
  position: absolute;
  left: -13px;
  width: 12px; height: 1px;
  background: oklch(from var(--cat-twopart) l c h / 0.4);
}
.st-scene-sub-item {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 8px;
  border-radius: 6px;
  position: relative;
  cursor: pointer;
  transition: background 0.12s;
}
.st-scene-sub-item:hover { background: var(--surface-2); }
.st-scene-sub-more {
  display: block;
  width: 100%;
  padding: 5px 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  text-align: left;
  position: relative;
  border-radius: 6px;
}
.st-scene-sub-more:hover { color: var(--pulse); background: oklch(from var(--pulse) l c h / 0.06); }

/* ── CENTER ─────────────────────────────────────────────── */
.st-c {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  position: relative;
  background:
    radial-gradient(ellipse at center, oklch(from var(--pulse) l c h / 0.04), transparent 60%),
    var(--surface);
}

.st-c-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
  flex-shrink: 0;
}
.st-c-bar-l { display: flex; align-items: center; gap: 14px; }
.st-c-bar-now {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 10.5px; letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--ink-3);
}
.st-c-bar-now .st-c-bar-state {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 12.5px;
  letter-spacing: -0.005em;
  text-transform: none;
  color: var(--pulse-hi);
  margin-left: 4px;
}
.st-c-bar-r { display: flex; align-items: center; gap: 12px; }
.st-c-bar-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-3);
}
.st-c-bar-expand {
  width: 30px; height: 30px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-2);
  margin-left: 6px;
  transition: all 0.15s;
}
.st-c-bar-expand:hover { background: var(--panel-2); color: var(--ink); }

/* stage with ambient rings */
.st-c-stage-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: hidden;
  min-height: 0;
}
.st-c-rings {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.st-c-rings span {
  position: absolute;
  width: 380px; height: 380px;
  border-radius: 999px;
  border: 1px solid oklch(from var(--pulse) l c h / 0.20);
  animation: st-c-ring 5s var(--ease) infinite;
}
.st-c-rings span:nth-child(2) { animation-delay: 1.6s; }
.st-c-rings span:nth-child(3) { animation-delay: 3.3s; }
@keyframes st-c-ring {
  0%   { transform: scale(0.5); opacity: 0.7; }
  100% { transform: scale(1.8); opacity: 0; }
}

.st-c-stage {
  position: relative; z-index: 1;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 0 0 1px oklch(from var(--pulse) l c h / 0.15), 0 30px 90px -24px oklch(from var(--pulse) l c h / 0.30), 0 30px 90px -24px oklch(0 0 0 / 0.5);
  transition: width 0.3s var(--ease), height 0.3s var(--ease), border-radius 0.3s var(--ease);
}
.st-c-stage .avatar-live { border-radius: 22px !important; width: 100% !important; height: 100% !important; }
.st-c-stage.shape-circle, .st-c-stage.shape-circle .avatar-live { border-radius: 999px !important; }
.st-c-stage.shape-pill, .st-c-stage.shape-pill .avatar-live { border-radius: 999px !important; }
.st-c-stage.shape-square, .st-c-stage.shape-square .avatar-live { border-radius: 0 !important; }
.st-c-stage.shape-wide, .st-c-stage.shape-wide .avatar-live { border-radius: 14px !important; }

/* controls */
.st-c-controls {
  display: flex; align-items: center; justify-content: center;
  gap: 24px; padding: 16px 24px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.ctl-group { display: flex; align-items: center; gap: 8px; }
.ctl-label {
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-3);
}
.shape-bar, .size-bar {
  display: flex; gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.shape-bar button, .size-bar button {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--ink-3);
  transition: all 0.15s;
}
.shape-bar button:hover, .size-bar button:hover { color: var(--ink); }
.shape-bar button.is-on, .size-bar button.is-on {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.3);
}

/* stepper + toggle (reused) */
.stepper { display: inline-flex; align-items: center; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.stepper button { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; border-radius: 999px; color: var(--ink-2); font-size: 13px; }
.stepper button:hover { background: var(--panel-2); color: var(--ink); }
.stepper .v { font-family: var(--font-mono); font-size: 11.5px; min-width: 16px; text-align: center; }

.toggle {
  position: relative;
  width: 32px; height: 18px;
  background: var(--panel-hi);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s;
}
.toggle::after {
  content: ""; position: absolute; left: 2px; top: 2px;
  width: 14px; height: 14px; border-radius: 999px;
  background: var(--ink); transition: transform 0.18s var(--ease);
}
.toggle.is-on { background: var(--pulse); }
.toggle.is-on::after { transform: translateX(14px); background: oklch(0.12 0.01 250); }

/* ── RIGHT RAIL — collapsed by default ──────────────────── */
.st-r {
  border-left: 1px solid var(--line);
  background: var(--surface);
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
  transition: width 0.3s var(--ease);
}
.st-r.is-collapsed { background: oklch(from var(--surface) l c h / 0.6); }
.st-r-handle {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 18px 0;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.st-r-handle:hover { color: var(--ink); background: var(--surface-2); }
.st-r-handle-lbl {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  margin-top: 8px;
}

.st-r-inner {
  display: flex; flex-direction: column;
  height: 100%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.st-r-inner::-webkit-scrollbar { width: 5px; }
.st-r-inner::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }

.st-r-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.st-r-head h3 {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.st-r-close {
  width: 24px; height: 24px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-3);
}
.st-r-close:hover { color: var(--ink); background: var(--panel-hi); }

.st-r-section { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.st-r-section h4 {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 12px;
}
.st-r-empty {
  font-size: 11.5px;
  color: var(--ink-4);
  font-style: italic;
  margin-bottom: 8px;
}
.st-r-pool { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.pool-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 8px 4px 10px;
  background: oklch(from var(--pulse) l c h / 0.12);
  border: 1px solid oklch(from var(--pulse) l c h / 0.30);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--pulse-hi);
}
.pool-chip button { width: 14px; height: 14px; display: flex; align-items: center; justify-content: center; border-radius: 999px; color: inherit; opacity: 0.5; }
.pool-chip button:hover { opacity: 1; background: oklch(from var(--pulse) l c h / 0.15); }
.st-r-add { display: flex; flex-wrap: wrap; gap: 4px; }

.st-r-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
  padding: 8px 0;
}
.st-r-row .lbl { font-size: 12.5px; color: var(--ink); }
.st-r-row .val { font-family: var(--font-mono); font-size: 12px; color: var(--ink); }

.st-r-sub-card {
  margin-top: 12px;
  padding: 12px 14px;
  background: oklch(from var(--cat-twopart) l c h / 0.08);
  border: 1px solid oklch(from var(--cat-twopart) l c h / 0.30);
  border-radius: 10px;
}
.st-r-sub-head {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cat-twopart);
  margin-bottom: 8px;
}
.st-r-sub-card p { font-size: 11.5px; color: var(--ink-3); line-height: 1.5; margin-bottom: 10px; }

.st-r-rule {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 11px;
}
.st-r-rule .from, .st-r-rule .to {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-2);
}
.st-r-rule .arr { color: var(--pulse); }
.st-r-rule button { margin-left: auto; color: var(--ink-3); display: flex; align-items: center; justify-content: center; }

@media (max-width: 1100px) {
  .st { grid-template-columns: 280px 1fr 48px; }
  .st.right-open { grid-template-columns: 280px 1fr 320px; }
}
@media (max-width: 800px) {
  .st { grid-template-columns: 1fr; }
  .st-l, .st-r { display: none; }
}
