/* Arcana Studio NLE — Mobile Responsive Layout (<= 768px) · Desktop (> 768px) preserved */

/* Desktop defaults for mobile-only elements */
.st-ratio-select-mobile,
.st-drawer-backdrop,
.st-close-mobile {
  display: none;
}

@media (max-width: 768px) {
  html,
  body.studio-nle-active {
    overflow: hidden !important;
    overflow-x: hidden !important;
    max-width: 100vw;
    width: 100vw;
  }
  body.studio-nle-active > .main,
  body.studio-nle-active > .sidebar {
    display: none !important;
  }

  #studioWorkspace {
    width: 100vw;
    max-width: 100vw;
    overflow: hidden;
    --st-mobile-nav-h: calc(58px + env(safe-area-inset-bottom, 0px));
  }

  /* ── 1. Compact Non-Overlapping Top Header Bar ─────────────────────────── */
  .st-topbar {
    height: 50px;
    padding: 0 52px 0 8px; /* preserves clean room for fixed #arcane-avatar-btn */
    gap: 4px;
    max-width: 100vw;
    overflow: hidden;
  }
  .st-top-left,
  .st-top-center,
  .st-top-right {
    gap: 4px;
    flex-shrink: 0;
  }
  .st-brand-pill,
  .st-title-input,
  #stDraftBadge,
  #stBetaBadge,
  #stPlanLimitsPill,
  #stYoutubeBtn,
  #stThumbBtn,
  #stShortcutsBtn,
  .st-topbar .st-seg {
    display: none !important;
  }

  .st-back-btn {
    height: 32px;
    padding: 0 8px;
    font-size: 11.5px;
    border-radius: 8px;
    white-space: nowrap;
  }

  .st-topbar .st-icon-btn {
    height: 32px;
    min-width: 32px;
    padding: 0 6px;
    font-size: 12px;
    border-radius: 8px;
  }

  .st-ratio-select-mobile {
    display: inline-flex;
    height: 32px;
    padding: 0 6px;
    border-radius: 8px;
    border: 1px solid var(--st-border-strong);
    background: var(--st-card);
    color: var(--st-text);
    font-size: 11.5px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    outline: none;
  }
  .st-ratio-select-mobile:focus-visible {
    border-color: var(--st-accent-2);
  }

  #stCopilotToggleBtn {
    min-width: 44px;
    padding: 0 9px;
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
    border-color: rgba(124, 92, 255, 0.5);
    color: #ddd6fe;
  }

  .st-export-btn {
    height: 32px;
    padding: 0 10px;
    font-size: 11.5px;
    border-radius: 8px;
    white-space: nowrap;
    gap: 4px;
  }

  #stRenderPill,
  #stUploadPill,
  #stExportReadyPill {
    font-size: 10px !important;
    padding: 3px 7px !important;
    height: 30px;
  }

  /* ── 2. Workspace Body + Preview Stage ─────────────────────────────────── */
  .st-body {
    flex-direction: column;
    padding-bottom: var(--st-mobile-nav-h);
    max-width: 100vw;
    overflow: hidden;
  }

  .st-center-col {
    width: 100%;
    max-width: 100vw;
    flex: 1;
    min-height: 0;
  }

  .st-stage-wrap {
    min-height: 150px;
    flex: 1;
  }

  .st-stage-viewport {
    padding: 8px 10px 6px;
  }

  .st-canvas-frame {
    max-width: calc(100cqw - 12px);
    max-height: calc(100cqh - 10px);
    border-radius: 10px;
  }
  .st-canvas-frame[data-ratio="16:9"] {
    width: min(calc(100cqw - 12px), calc((100cqh - 10px) * 16 / 9));
    height: min(calc(100cqh - 10px), calc((100cqw - 12px) * 9 / 16));
  }
  .st-canvas-frame[data-ratio="9:16"] {
    width: min(calc(100cqw - 12px), calc((100cqh - 10px) * 9 / 16));
    height: min(calc(100cqh - 10px), calc((100cqw - 12px) * 16 / 9));
  }
  .st-canvas-frame[data-ratio="1:1"] {
    width: min(calc(100cqw - 12px), calc(100cqh - 10px));
    height: min(calc(100cqw - 12px), calc(100cqh - 10px));
  }

  .st-stage-empty {
    padding: 12px;
    gap: 6px;
  }
  .st-stage-empty h3 { font-size: 13.5px; }
  .st-stage-empty p { font-size: 11px; line-height: 1.4; }

  /* ── 3. Fixed Mobile Bottom Navigation Bar (48px+ touch targets) ───────── */
  .st-left-rail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5500;
    width: 100%;
    height: var(--st-mobile-nav-h);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
    border-right: none;
    border-top: 1px solid var(--st-border-strong);
    background: rgba(17, 19, 24, 0.97);
    backdrop-filter: blur(12px);
    display: grid !important;
    flex-direction: initial !important;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    align-items: center;
    gap: 2px;
  }

  .st-rail-tab {
    width: 100%;
    min-height: 46px;
    height: 48px;
    border-radius: 10px;
    gap: 3px;
    font-size: 9.5px;
    padding: 4px 2px;
  }
  .st-rail-tab svg {
    width: 18px;
    height: 18px;
  }

  /* ── 4. Dismissible Slide-Up Bottom Sheet Drawer & Copilot ─────────────── */
  .st-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    bottom: var(--st-mobile-nav-h);
    z-index: 5300;
    background: rgba(5, 7, 11, 0.56);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms var(--st-ease-out);
  }
  .st-drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .st-drawer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--st-mobile-nav-h);
    top: auto;
    z-index: 5400;
    width: 100%;
    max-width: 100vw;
    height: auto;
    max-height: min(66dvh, calc(100dvh - 118px));
    border-right: none;
    border-top: 1px solid var(--st-border-strong);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.72);
    transform: translateY(0);
    opacity: 1;
    transition: transform 220ms var(--st-ease-out), opacity 180ms var(--st-ease-out);
  }
  .st-drawer::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    margin: 7px auto 1px;
    flex-shrink: 0;
  }
  .st-drawer.collapsed {
    width: 100%;
    transform: translateY(105%);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
  }

  .st-drawer-head {
    height: 40px;
    padding: 0 12px 2px;
  }
  .st-close-desktop { display: none; }
  .st-close-mobile { display: inline; font-size: 13px; }
  .st-drawer-close-btn {
    height: 32px !important;
    min-width: 32px !important;
    border-radius: 8px;
  }

  .st-copilot {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--st-mobile-nav-h);
    top: auto;
    z-index: 5450;
    width: 100%;
    max-width: 100vw;
    height: min(68dvh, calc(100dvh - 118px));
    border-left: none;
    border-top: 1px solid var(--st-border-strong);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.75);
    transform: translateY(0);
    opacity: 1;
    transition: transform 220ms var(--st-ease-out), opacity 180ms var(--st-ease-out);
  }
  .st-copilot.collapsed {
    width: 100%;
    transform: translateY(105%);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
  }

  /* ── 5. Single-Row Transport Bar & Timeline Toolbar ────────────────────── */
  .st-transport {
    height: 44px;
    padding: 0 8px;
    gap: 6px;
    justify-content: space-between;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .st-transport::-webkit-scrollbar { display: none; }
  .st-transport-group {
    gap: 5px;
    flex-shrink: 0;
  }
  .st-transport .st-icon-btn {
    height: 32px;
    min-width: 32px;
    padding: 0 7px;
    font-size: 11.5px;
    white-space: nowrap;
  }
  .st-play-btn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
  }
  .st-timecode {
    font-size: 11px;
    padding: 4px 7px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  #stVolumeSlider,
  #stStageZoom {
    display: none;
  }

  /* ── 6. Compact Non-Overlapping Timeline & Track Headers ───────────────── */
  .st-timeline {
    height: 204px;
    min-height: 188px;
    max-width: 100vw;
  }

  .st-tl-toolbar {
    height: 38px;
    padding: 0 8px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }
  .st-tl-toolbar::-webkit-scrollbar { display: none; }
  .st-tl-title-group {
    flex-shrink: 0;
    gap: 4px !important;
  }
  #stTlSummary,
  #stTlZoomRange {
    display: none;
  }
  .st-tl-actions-group {
    gap: 4px !important;
    margin-left: auto;
    flex-shrink: 0;
  }
  .st-tl-actions-group .st-icon-btn {
    height: 28px !important;
    padding: 0 7px !important;
    font-size: 11px !important;
    white-space: nowrap;
  }

  .st-tl-headers {
    width: 78px;
  }
  .st-tl-ruler-corner {
    height: 22px;
    padding: 0 6px;
    font-size: 9.5px;
  }
  .st-ruler {
    height: 22px;
  }
  .st-track-head {
    height: 36px;
    padding: 0 5px;
    gap: 3px;
  }
  .st-track-name,
  .st-track-clear-btn {
    display: none !important;
  }
  .st-track-tag {
    margin-right: 0;
    font-size: 9.5px;
    padding: 2px 4px;
  }
  .st-track-btns .st-icon-btn {
    height: 22px !important;
    min-width: 22px !important;
    font-size: 10.5px !important;
  }

  .st-track-lane {
    height: 36px;
  }
  .st-tl-scroll {
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
  }

  /* Mobile modal safe width & 44px touch targets */
  .st-modal {
    max-width: calc(100vw - 20px);
    max-height: 86dvh;
    overflow-y: auto;
    padding: 14px;
  }
  .st-modal .st-export-footer .st-icon-btn,
  .st-modal .st-export-footer .st-export-btn,
  .st-export-quick-btn,
  .st-export-save-btn {
    min-height: 44px;
    padding: 0 14px;
    font-size: 13px;
  }
  .st-export-footer {
    flex-wrap: wrap;
  }
  .st-export-quick-dl {
    flex-wrap: wrap;
  }
  .st-export-quick-btn {
    width: 100%;
  }
  .st-card-dl-btn {
    min-width: 30px;
    height: 28px;
    font-size: 12px;
  }
  .st-toast {
    bottom: calc(var(--st-mobile-nav-h) + 12px);
    max-width: calc(100vw - 24px);
    text-align: center;
  }
}

@media (max-width: 420px) {
  .st-topbar {
    padding: 0 50px 0 6px;
    gap: 3px;
  }
  .st-top-left,
  .st-top-center,
  .st-top-right {
    gap: 3px;
  }
  .st-back-btn {
    padding: 0 6px;
    font-size: 11px;
  }
  .st-topbar .st-icon-btn {
    min-width: 28px;
    padding: 0 5px;
    font-size: 11.5px;
  }
  .st-ratio-select-mobile {
    padding: 0 4px;
    font-size: 11px;
    max-width: 58px;
  }
  #stCopilotToggleBtn {
    min-width: 38px;
    padding: 0 7px;
    font-size: 11px;
  }
  .st-export-btn {
    padding: 0 8px;
    font-size: 11px;
  }
  #stRenderPill,
  #stUploadPill,
  #stExportReadyPill {
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 2px 6px !important;
  }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  .st-drawer,
  .st-drawer-backdrop,
  .st-copilot {
    transition-duration: 0.01ms !important;
  }
}
