.studio-body {
  height: 100vh; height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--bg-0);
}

/* ── Top bar ── */
.studio-bar {
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem .75rem;
  padding-top: calc(.5rem + var(--safe-top));
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  z-index: 30;
  min-height: 56px;
}
.studio-bar .brand-text { font-size: .95rem; }
.studio-bar .brand-mark { width: 26px; height: 26px; }
@media (max-width: 640px) { .studio-bar .brand-text { display: none; } .studio-bar { gap: .5rem; } }

.task-tabs {
  display: flex; gap: .2rem;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px; margin-left: .5rem;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; max-width: 100%; flex: 1 1 auto;
}
.task-tabs::-webkit-scrollbar { display: none; }
.task-tabs button {
  border: none; background: transparent; color: var(--fg-2);
  font-size: .8rem; font-weight: 600; padding: .4rem .8rem;
  border-radius: 999px; cursor: pointer; flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: .35rem;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.task-tabs button:hover { color: var(--fg-0); }
.task-tabs button.active { background: linear-gradient(100deg, var(--violet), var(--cyan)); color: #fff; box-shadow: 0 6px 20px -8px rgba(124,92,255,.8); }
.task-tabs button svg { width: 14px; height: 14px; }
@media (max-width: 640px) {
  .task-tabs button span { display: none; }
  .task-tabs button { padding: .5rem .7rem; }
}

.studio-bar-right { margin-left: auto; display: flex; align-items: center; gap: .4rem; flex: 0 0 auto; }
.hud-chip { display: inline-flex; align-items: center; gap: .45rem; padding: .32rem .65rem; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); font-family: var(--mono); font-size: .7rem; color: var(--fg-1); }
.hud-chip b { color: var(--fg-0); font-weight: 600; }
.hud-chip .led { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px var(--green); }
.hud-chip .led.warn { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.hud-chip .led.err  { background: var(--red);   box-shadow: 0 0 6px var(--red); }
@media (max-width: 900px) { .hud-chip.hide-sm { display: none; } }
@media (max-width: 480px) { .studio-bar-right .btn.primary span { display: none; } }

/* ── Mobile panel tabs ── */
.mobile-panel-tabs {
  display: none;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  padding: .35rem .5rem;
  gap: .25rem;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  z-index: 25;
}
.mobile-panel-tabs::-webkit-scrollbar { display: none; }
.mobile-panel-tabs button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--bg-1);
  color: var(--fg-2);
  padding: .4rem .85rem;
  font-size: .8rem;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.mobile-panel-tabs button.active {
  background: linear-gradient(100deg, var(--violet), var(--cyan));
  color: #fff;
  border-color: transparent;
}

/* ── Grid ── */
.studio-main {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  gap: 0;
  min-height: 0;
  background: var(--bg-0);
}
@media (max-width: 1180px) { .studio-main { grid-template-columns: 260px minmax(0,1fr) 260px; } }

/* ── Sidebars / panels ── */
.sidebar {
  background: var(--bg-1); border-right: 1px solid var(--line);
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: .9rem; display: flex; flex-direction: column; gap: .9rem; min-width: 0;
}
.sidebar-right { border-right: none; border-left: 1px solid var(--line); }
.panel { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r); padding: .9rem; }
.panel-title { display: flex; align-items: center; gap: .5rem; font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--fg-2); margin-bottom: .75rem; }
.panel-title svg { width: 13px; height: 13px; color: var(--cyan); }

.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .75rem; }
.field:last-child { margin-bottom: 0; }
.field label { font-size: .78rem; color: var(--fg-2); font-weight: 500; display: flex; align-items: center; }
.field select,
.field input[type=text] {
  width: 100%;
  background: var(--bg-0);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: .6rem .65rem;
  color: var(--fg-0);
  font-size: .86rem;
}
.field select {
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237b8296' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem;
}
.field select:focus,
.field input[type=text]:focus { outline: none; border-color: var(--violet); }

.field input[type=range] { width: 100%; padding: 0; height: 22px; -webkit-appearance: none; appearance: none; background: transparent; }
.field input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--bg-0); border: 1px solid var(--line-2); }
.field input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%; background: linear-gradient(140deg, var(--violet), var(--cyan)); cursor: pointer; border: 2px solid var(--bg-2); margin-top: -7px; }
.field input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--bg-0); border: 1px solid var(--line-2); }
.field input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--violet); cursor: pointer; border: 2px solid var(--bg-2); }
.field .val { font-family: var(--mono); font-size: .74rem; color: var(--cyan); margin-left: auto; }

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: .5rem 0; font-size: .86rem; color: var(--fg-1); min-height: 40px; }
.switch { position: relative; width: 40px; height: 22px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track { position: absolute; inset: 0; background: var(--bg-4); border-radius: 999px; transition: background var(--dur) var(--ease); }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--fg-1); transition: transform var(--dur) var(--ease), background var(--dur) var(--ease); }
.switch input:checked + .track { background: linear-gradient(100deg, var(--violet), var(--cyan)); }
.switch input:checked ~ .thumb { transform: translateX(18px); background: #fff; }
@media (pointer: coarse) { .switch { width: 46px; height: 26px; } .switch .thumb { width: 20px; height: 20px; } .switch input:checked ~ .thumb { transform: translateX(20px); } }

.btn-block { width: 100%; justify-content: center; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.source-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
.source-row .btn { padding: .6rem .3rem; font-size: .78rem; border-radius: var(--r-sm); }

/* Memory */
.memory-section { border-top: 1px dashed var(--line); padding-top: .75rem; }
.memory-section:first-of-type { border-top: none; padding-top: 0; }
.memory-head { display: flex; justify-content: space-between; align-items: center; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--fg-2); margin-bottom: .55rem; }
.memory-count { color: var(--cyan); font-family: var(--mono); font-size: .72rem; background: rgba(34,211,238,.1); border: 1px solid rgba(34,211,238,.28); padding: 0 .45rem; border-radius: 999px; }
.memory-list { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.memory-list:empty::after { content: "No entries yet"; display: block; font-size: .72rem; color: var(--fg-3); font-style: italic; }
.memory-chip { display: inline-flex; align-items: center; gap: .4rem; padding: .25rem .4rem .25rem .25rem; background: var(--bg-0); border: 1px solid var(--line); border-radius: 999px; font-size: .76rem; max-width: 100%; }
.memory-chip img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; background: var(--bg-3); }
.memory-chip .name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.memory-chip .remove { background: none; border: none; color: var(--fg-3); cursor: pointer; padding: 0 .25rem; font-size: 1rem; line-height: 1; }
.memory-chip .remove:hover { color: var(--err); }

/* ── Stage ── */
.stage {
  position: relative;
  min-width: 0; min-height: 0;
  padding: 1rem;
  overflow: hidden;
  display: flex;
  background: radial-gradient(circle at 50% 30%, var(--bg-3), var(--bg-0) 70%), var(--bg-0);
}
.stage-inner { position: relative; flex: 1; min-width: 0; min-height: 0; display: flex; }
.stage-canvas-wrap {
  position: relative; flex: 1;
  min-width: 0; min-height: 0;
  background: #000;
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.9), 0 0 0 1px var(--line-2);
}
.stage-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.stage-video.mirrored { transform: scaleX(-1); }
.stage-overlay { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
.stage-overlay.mirrored { transform: scaleX(-1); }

.stage-placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: var(--bg-1); text-align: center; padding: 2rem;
  z-index: 5; transition: opacity .3s var(--ease);
}
.stage-placeholder.hidden { display: none; }
.stage-placeholder h3 { margin-bottom: .5rem; }
.stage-placeholder p { font-size: .9rem; max-width: 400px; margin-inline: auto; margin-bottom: 1.2rem; }
.stage-placeholder .ph-icon { color: var(--violet); margin-bottom: 1rem; }
.stage-placeholder .ph-icon svg { width: 52px; height: 52px; margin-inline: auto; }
@media (max-width: 640px) {
  .stage-placeholder { padding: 1rem; }
  .stage-placeholder h3 { font-size: 1rem; }
  .stage-placeholder p { font-size: .82rem; margin-bottom: .9rem; }
  .stage-placeholder .ph-icon svg { width: 36px; height: 36px; }
}

.stage-badge {
  position: absolute; top: .75rem; left: .75rem;
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .35rem .7rem; border-radius: 999px;
  background: rgba(6,7,11,.78); border: 1px solid var(--line-2);
  font-family: var(--mono); font-size: .68rem; color: var(--fg-1);
  backdrop-filter: blur(10px); z-index: 6;
}
.stage-badge .rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: rec-pulse 1.2s ease-in-out infinite; }
@keyframes rec-pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* Telemetry / log */
.telemetry { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.tm-item { background: var(--bg-0); border: 1px solid var(--line); border-radius: var(--r-sm); padding: .55rem .65rem; }
.tm-item span { font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-3); display: block; margin-bottom: 2px; }
.tm-item b { font-family: var(--mono); font-size: .95rem; color: var(--fg-0); font-variant-numeric: tabular-nums; }
.log { font-family: var(--mono); font-size: .72rem; background: var(--bg-0); border: 1px solid var(--line); border-radius: var(--r-sm); padding: .55rem .65rem; height: 150px; overflow-y: auto; color: var(--fg-1); line-height: 1.6; overscroll-behavior: contain; }
.log-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-line .t { color: var(--fg-3); margin-right: .4rem; }
.log-line .l-info { color: var(--cyan); }
.log-line .l-ok { color: var(--ok); }
.log-line .l-warn { color: var(--warn); }
.log-line .l-err { color: var(--err); }

.gesture-list { display: flex; flex-direction: column; gap: .4rem; }
.gesture-item { display: flex; align-items: center; gap: .6rem; padding: .5rem .65rem; background: var(--bg-0); border: 1px solid var(--line); border-radius: var(--r-sm); font-size: .8rem; }
.gesture-item .gdot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-3); flex: 0 0 auto; }
.gesture-item.active .gdot { background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.gesture-item .gname { flex: 1; color: var(--fg-1); }
.gesture-item .gcount { font-family: var(--mono); font-size: .72rem; color: var(--fg-2); }
@media (pointer: coarse) { .gesture-item { min-height: 44px; } }

/* ── Mobile layout ── */
@media (max-width: 1024px) {
  .studio-body { height: auto; min-height: 100dvh; overflow: visible; display: block; }
  .studio-bar { position: sticky; top: 0; }
  .mobile-panel-tabs { display: flex; position: sticky; top: var(--safe-top, 0); }

  .studio-main { display: block; min-height: 0; }

  /* Stage pinned at top */
  .stage {
    position: sticky; top: 0; z-index: 20;
    height: 44dvh; min-height: 220px; max-height: 460px;
    padding: .5rem;
    border-bottom: 1px solid var(--line);
    background: var(--bg-0);
  }
  .stage-canvas-wrap { border-radius: var(--r); }

  /* Sidebars flatten; only the active panel shows */
  .sidebar {
    display: block;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: .75rem;
    overflow: visible;
  }
  .sidebar-right { border-left: none; border-bottom: none; }
  .sidebar .panel { display: none; margin-bottom: .75rem; }
  .sidebar .panel.active-mobile { display: block; }
}
@media (max-width: 560px) {
  .stage { height: 40dvh; min-height: 200px; }
  .memory-chip .name { max-width: 70px; }
}
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .stage { height: 62dvh; max-height: none; }
  .studio-bar { min-height: 44px; padding-block: .25rem; }
  .mobile-panel-tabs { padding-block: .2rem; }
}

/* Scrollbar polish */
.sidebar::-webkit-scrollbar, .log::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb, .log::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track, .log::-webkit-scrollbar-track { background: transparent; }