/* —— Studio —— */
body.is-studio {
  overflow: hidden;
  height: 100%;
}

.shell.is-studio {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.shell.is-studio .main {
  max-width: none;
  height: 100%;
  min-height: 0;
  padding-top: 16px;
  padding-bottom: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.shell.is-studio .topbar {
  margin-bottom: 10px;
  flex: 0 0 auto;
}

.shell.is-studio .topbar .sub {
  display: none;
}

.shell.is-studio #view-studio.active {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 0;
  overflow: hidden;
}

.studio {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.studio-panel {
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 4px;
}

.studio-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.studio-block h2 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.studio-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.studio-clips {
  display: grid;
  gap: 6px;
  max-height: 180px;
  overflow: auto;
}

.studio-clip {
  position: relative;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 6px 28px 6px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  width: 100%;
}

.studio-clip:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.studio-clip.is-active {
  border-color: rgba(91, 140, 255, 0.55);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.studio-clip-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
  color: var(--muted, #9aa3b5);
  background: transparent;
  cursor: pointer;
  opacity: 0.7;
}

.studio-clip:hover .studio-clip-del,
.studio-clip.is-active .studio-clip-del {
  opacity: 1;
}

.studio-clip-del:hover {
  color: #fff;
  background: rgba(220, 60, 70, 0.85);
}

.studio-clip img,
.studio-clip-thumb {
  width: 40px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  background: #090a0d;
  display: block;
}

.studio-clip-meta {
  min-width: 0;
}

.studio-clip-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.studio-clip-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.studio-trim {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.studio-range {
  width: 100%;
  accent-color: var(--accent);
}

.studio-text-form {
  display: grid;
  gap: 8px;
}

.studio-text-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.studio-text-row:has(.mini-field:nth-child(3)) {
  grid-template-columns: 1fr 1fr 1fr;
}

.studio-layers {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.studio-layer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  font-size: 13px;
  width: 100%;
  text-align: left;
  color: inherit;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.studio-layer:hover {
  border-color: rgba(91, 140, 255, 0.35);
}

.studio-layer.is-active {
  border-color: rgba(91, 140, 255, 0.55);
  background: color-mix(in srgb, var(--accent-dim) 55%, var(--input-bg));
  box-shadow: 0 0 0 1px var(--accent-dim);
}

.studio-layer strong {
  display: block;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.studio-layer small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 550;
}

.studio-stage {
  display: grid;
  place-items: stretch;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 0 8px 4px;
}

/* Phone + trim tracks: under area always reserved for 3 equal strips when editing */
.studio-stage-stack {
  --studio-track-h: 44px;
  --studio-main-strip-h: var(--studio-track-h);
  --studio-tracks-gap: 8px;
  --studio-clock-h: 14px;
  --studio-under-primary-h: calc(var(--studio-clock-h) + 4px + var(--studio-main-strip-h));
  --studio-under-tracks-gap: var(--studio-tracks-gap);
  --studio-under-tracks-h: calc(var(--studio-track-h) * 2 + var(--studio-tracks-gap));
  --studio-under-h: calc(
    var(--studio-under-primary-h) + var(--studio-under-tracks-gap) + var(--studio-under-tracks-h)
  );

  container-type: size;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 6px;
  height: 100%;
  max-height: 100%;
  width: 100%;
  min-width: 0;
  justify-items: center;
  align-content: stretch;
}

.studio-stage-stack:has(#studioUnderTools:not([hidden])) {
  grid-template-rows: minmax(0, 1fr) var(--studio-under-h);
}

.phone-slot {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 4px 0;
  overflow: hidden;
}

.phone-frame {
  /* fallback: fill height, keep 9:16 (1080×1920) */
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  height: calc(100% - 8px);
  width: auto;
  aspect-ratio: 9 / 16;
  max-width: 100%;
  max-height: calc(100% - 8px);
  border-radius: clamp(18px, 3.5cqh, 28px);
  padding: clamp(5px, 1cqh, 8px);
  background: linear-gradient(160deg, #2a2e36, #12141a 45%, #0a0b0e);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  position: relative;
  margin: 0;
  overflow: hidden; /* keep bezel corners round — clip screen/video */
}

@supports (width: 1cqh) {
  .phone-frame {
    height: auto;
    width: min(100cqw, calc((100cqh - 56px) * 9 / 16));
    max-height: calc(100cqh - 56px);
  }

  .studio-stage-stack:has(#studioUnderTools:not([hidden])) .phone-frame {
    /* Shrink phone so 3 track slots always fit under the canvas */
    width: min(100cqw, calc((100cqh - var(--studio-under-h) - 20px) * 9 / 16));
    max-height: calc(100cqh - var(--studio-under-h) - 20px);
  }
}

.phone-notch {
  display: none;
}

.phone-screen {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  height: auto;
  align-self: stretch;
  border-radius: clamp(12px, 2.8cqh, 22px);
  overflow: hidden;
  background: #050607;
  isolation: isolate;
}

.phone-screen video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  background: #000;
  border-radius: inherit;
}

.phone-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 20px;
  z-index: 1;
}

.phone-empty.is-hidden {
  display: none;
}

.studio-under {
  /* Strip ≈ phone width; side rails for mute/volume sit outside the canvas */
  --studio-sound-rail: 148px;
  width: min(
    100%,
    calc(var(--studio-canvas-w, 280px) + (var(--studio-sound-rail) * 2) + 12px)
  );
  max-width: 100%;
  justify-self: center;
  display: grid;
  gap: 0;
  margin-top: 0;
  align-content: start;
  overflow: visible;
}

.studio-stage-stack:has(#studioUnderTools:not([hidden])) .studio-under {
  height: var(--studio-under-h);
  min-height: var(--studio-under-h);
  max-height: var(--studio-under-h);
}

@supports (width: 1cqh) {
  .studio-under {
    width: min(
      100cqw,
      calc(
        var(
            --studio-canvas-w,
            min(100cqw, calc((100cqh - var(--studio-under-h) - 14px) * 9 / 16))
          ) + (var(--studio-sound-rail) * 2) + 12px
      )
    );
  }
}

.studio-under-empty {
  margin: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.35;
  padding: 6px 12px 2px;
}

.studio-under-empty[hidden],
.studio-under-tools[hidden] {
  display: none !important;
}

.studio-under-tools {
  display: grid;
  grid-template-rows: var(--studio-under-primary-h) var(--studio-under-tracks-h);
  gap: var(--studio-under-tracks-gap);
  height: 100%;
  min-height: 0;
  align-content: start;
}

.studio-under-primary {
  display: grid;
  grid-template-rows: var(--studio-clock-h) var(--studio-main-strip-h);
  gap: 4px;
  align-content: start;
  min-height: 0;
}

.studio-under-tracks {
  display: grid;
  grid-template-rows: var(--studio-track-h) var(--studio-track-h);
  gap: var(--studio-tracks-gap);
  align-content: start;
  min-height: var(--studio-under-tracks-h);
}

.studio-under-primary .studio-trim-row,
.studio-under-tracks .studio-trim-row {
  height: var(--studio-track-h);
  min-height: var(--studio-track-h);
}

.studio-clock {
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  padding: 0;
  margin: 0;
}

.studio-play-fab {
  appearance: none;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  z-index: 5;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 999px;
  padding: 0;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: rgba(12, 14, 18, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.22s var(--ease),
    transform 0.22s var(--ease),
    background 0.2s ease;
}

.phone-screen:hover .studio-play-fab:not([hidden]),
.phone-screen:focus-within .studio-play-fab:not([hidden]),
.studio-play-fab:focus-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.studio-play-fab:hover {
  background: rgba(18, 22, 30, 0.72);
  transform: translate(-50%, -50%) scale(1.05);
}

.studio-play-fab svg {
  display: block;
  grid-area: 1 / 1;
}

.studio-play-fab .ico-pause {
  opacity: 0;
  pointer-events: none;
}

.studio-play-fab .ico-play {
  opacity: 1;
  margin-left: 2px;
}

.studio-play-fab.is-playing .ico-play {
  opacity: 0;
}

.studio-play-fab.is-playing .ico-pause {
  opacity: 1;
}

.studio-text-area {
  resize: vertical;
  min-height: 72px;
  font-weight: 600;
}

