/* Installed / phone app shell. Class is set before paint by mobile.js. */
#appMenuBtn,
#appLibraryTabs,
#appLibraryBackdrop,
.s5-mobile-tools,
.s5-mobile-more,
.s5-sheet-backdrop,
.s5-phone-ico { display: none; }

html.app-phone {
  --studio-rail-width: 0px;
  --studio-dock: calc(58px + env(safe-area-inset-bottom, 0px));
  --app-composer: 92px;
  --phone-header: calc(56px + env(safe-area-inset-top, 0px));
  --keyboard-inset: 0px;

  html, body {
    height: 100%;
    min-height: 100dvh;
  }

  /* ===== Studio shell: left rail becomes the bottom dock ===== */
  body.studio-app {
    height: 100dvh;
    overflow: hidden;
  }
  body.studio-app .studio-shell {
    display: block;
    height: 100dvh;
    max-height: 100dvh;
    width: 100%;
    overflow: hidden;
  }
  body.studio-app .studio-workspace,
  body.studio-app .studio-workspace > .app-wrapper,
  body.studio-app .main-container {
    height: 100%;
    min-height: 0;
  }
  body.studio-app .studio-workspace {
    padding-bottom: var(--studio-dock);
  }

  .studio-rail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 80;
    width: 100%;
    height: var(--studio-dock);
    flex-direction: row;
    align-items: stretch;
    justify-content: space-around;
    gap: 0;
    padding: 4px 4px env(safe-area-inset-bottom, 0px);
    border-right: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(8, 8, 8, 0.94);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }
  .studio-rail-gap,
  .studio-rail-rule,
  .studio-rail-home {
    display: none;
  }
  .studio-rail-btn {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 48px;
    padding: 6px 2px 4px;
    gap: 3px;
    font-size: 9px;
    border-radius: 12px;
  }
  .studio-rail-btn svg {
    width: 20px;
    height: 20px;
  }
  .studio-rail-btn span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.05;
  }
  .studio-rail-btn[data-rail="agent"] {
    display: flex !important;
  }
  .studio-rail-btn[data-rail="projects"],
  .studio-rail-btn[data-rail="chats"],
  .studio-rail-btn[data-rail="projects"]::after,
  .studio-rail-btn[data-rail="chats"]::after {
    display: none !important;
  }
  .studio-rail-btn.active {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #fff;
  }

  /* Projects and chats share one left drawer, like chat. */
  .projects-sidebar,
  .chats-sidebar {
    position: fixed !important;
    left: 0 !important;
    top: 0;
    bottom: var(--studio-dock);
    width: min(320px, 86vw);
    height: auto !important;
    border-radius: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    border-top: 0;
    box-shadow: 18px 0 40px rgba(0, 0, 0, 0.45);
    transform: translateX(-105%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 95;
    padding-top: 8px;
    background: #09090a;
    overflow: hidden;
  }
  body.app-library-open .projects-sidebar.open {
    top: var(--phone-header) !important;
    bottom: auto !important;
    height: calc(50dvh - var(--phone-header)) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 12px !important;
  }
  body.app-library-open .chats-sidebar.open {
    top: 50dvh !important;
    bottom: var(--studio-dock) !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
  }
  body.app-library-open .chats-sidebar.open .chats-sidebar-list,
  body.app-library-open .projects-sidebar.open .sidebar-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .chats-history-item {
    flex: 0 0 auto;
    min-height: 36px;
    height: auto;
  }
  body.app-library-open .projects-sidebar.open,
  body.app-library-open .chats-sidebar.open {
    left: 0;
    transform: none;
  }
  .projects-sidebar.no-anim,
  .chats-sidebar.no-anim {
    transition: none !important;
  }
  .projects-sidebar-top { display: none; }
  .projects-sidebar-label { display: block; padding-top: 8px; }
  #appMenuBtn,
  .app-menu-btn {
    position: relative;
    top: auto;
    left: auto;
    z-index: 3;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent !important;
    color: #fff;
    box-shadow: none !important;
    transform: none !important;
  }
  .app-menu-btn svg { width: 22px; height: 22px; }
  .app-library-tabs {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 96;
    width: min(320px, 86vw);
    height: 52px;
    align-items: center;
    gap: 6px;
    padding: 8px;
    background: #09090a;
  }
  body.app-library-open .app-library-tabs { display: none !important; }
  .app-library-tabs button {
    flex: 1;
    height: 36px;
    border: 0;
    border-radius: 999px;
    background: transparent !important;
    color: #8e8e93;
    font: 650 13px/1 var(--font-main, system-ui);
    box-shadow: none !important;
    transform: none !important;
  }
  .app-library-tabs button.is-on {
    background: rgba(255, 255, 255, 0.12) !important;
    color: #fff;
  }
  #appLibraryBackdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 94;
    border: 0;
    background: rgba(0, 0, 0, 0.45);
  }
  body.app-library-open #appLibraryBackdrop { display: block; }
  body.studio-app header#mainHeader {
    position: relative;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    min-height: 52px;
    padding: 6px 8px 6px 4px;
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
    background: #0c0c0e;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    transform: none !important;
  }
  #appMenuBtn { position: relative; z-index: 3; }
  .phone-header-lead {
    position: relative;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 0;
    min-width: 0;
    flex: 0 0 auto;
  }
  .phone-header-lead #appMenuBtn {
    grid-area: auto;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
  }
  body.studio-app header .phone-header-lead .studio-rail-btn[data-rail="movie"] {
    display: inline-flex !important;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 36px;
    min-width: 36px;
    min-height: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08) !important;
    color: #fff;
    font: 650 12px/1 var(--font-main, system-ui);
    box-shadow: none !important;
    transform: none !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  body.studio-app header .phone-header-lead .studio-rail-btn[data-rail="movie"] svg {
    display: none;
  }
  body.studio-app header .phone-header-lead .studio-rail-btn[data-rail="movie"] .phone-movie-mark {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    display: block;
    object-fit: cover;
    flex: 0 0 auto;
  }
  body.studio-app header .phone-header-lead .studio-rail-btn[data-rail="movie"] span {
    display: none !important;
  }
  body.studio-app header .phone-header-lead .studio-rail-btn[data-rail="movie"].active {
    background: rgba(255, 255, 255, 0.16) !important;
    color: #fff;
  }
  body.studio-app header .header-brand {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    flex: 0 1 auto;
  }
  body.studio-app header .logo {
    text-align: center;
    white-space: nowrap;
  }
  body.studio-app .header-right {
    position: relative;
    z-index: 3;
    margin-left: 0;
    flex: 0 0 auto;
  }
  body.studio-app .project-title {
    order: 2;
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }

  .seq-engine-row { display: none !important; }
  html.app-phone,
  body.studio-app {
    overflow: hidden !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
  }
  #stage-1.active,
  #stage1-flow,
  #s1-dynamic:has(.s1-home-workspace) {
    height: 100%;
    min-height: 0;
    overflow: hidden !important;
  }
  #s1-dynamic:has(.s1-home-workspace) { justify-content: flex-start !important; }
  .s1-home-workspace {
    height: 100% !important;
    min-height: 0 !important;
    max-height: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: stretch !important;
    padding: 4px 16px 0 !important;
    box-sizing: border-box !important;
  }
  .s1-home-prompt { display: contents !important; }
  h1.seq-header {
    order: 2;
    position: fixed !important;
    left: 16px;
    right: 16px;
    bottom: calc(var(--studio-dock) + 78px + var(--keyboard-inset, 0px));
    margin: 0 !important;
    z-index: 61;
    font-size: clamp(1.35rem, 5.4vw, 1.7rem) !important;
    line-height: 1.15;
    text-align: center;
    pointer-events: none;
  }
  /* The headline is fixed above the ~78px-tall prompt box. As soon as the
     box grows (typing, newline, attachments) or gets focus, the fixed
     headline would float on top of the textarea — hide it while the
     composer is active. */
  .s1-home-workspace:has(.prompt-box:focus-within) h1.seq-header,
  .s1-home-workspace:has(.prompt-box.is-multiline) h1.seq-header,
  .s1-home-workspace:has(.prompt-attach-row:not([hidden])) h1.seq-header {
    opacity: 0 !important;
    visibility: hidden !important;
    transition: opacity 0.18s ease, visibility 0.18s ease;
  }
  .seq-bottom {
    order: 1;
    flex: 1 1 auto;
    min-height: 0;
    width: 100% !important;
    max-width: none !important;
    overflow: auto;
    padding-bottom: calc(var(--studio-dock) + 150px) !important;
  }
  .s1-home-workspace .prompt-box {
    position: fixed !important;
    left: 12px;
    right: 12px;
    bottom: calc(var(--studio-dock) + 10px + var(--keyboard-inset, 0px));
    z-index: 60;
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
    opacity: 1;
    /* Same surface as the chat composer. The field itself stays clear. */
    background: rgba(18, 18, 18, 0.72) !important;
    background-image: none !important;
    border: 1px solid rgba(255, 255, 255, 0.14) !important;
    border-radius: 28px !important;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.05),
      0 12px 40px rgba(0, 0, 0, 0.35) !important;
    backdrop-filter: blur(24px) saturate(160%) !important;
    -webkit-backdrop-filter: blur(24px) saturate(160%) !important;
    color-scheme: dark;
  }
  .s1-home-workspace .prompt-box .main-textarea,
  .s1-home-workspace .prompt-box .main-textarea:hover,
  .s1-home-workspace .prompt-box .main-textarea:focus,
  .s1-home-workspace .prompt-box .main-textarea:focus-visible,
  .s1-home-workspace .prompt-box .main-textarea:active {
    background: transparent !important;
    background-color: transparent !important;
    background-image: none !important;
    border: 0 !important;
    outline: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    color-scheme: dark;
  }
  #s1-recent-projects-grid {
    display: flex !important;
    flex-direction: column;
    grid-template-columns: none !important;
    gap: 10px;
  }
  #s1-recent-projects-grid .project-card {
    align-items: center;
    gap: 14px;
    padding: 10px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid rgba(255, 255, 255, 0.07);
  }
  #s1-recent-projects-grid .project-card-thumb {
    width: 92px !important;
    height: 92px !important;
    border-radius: 16px;
  }
  #s1-recent-projects-grid .project-card-title {
    font-size: 16px;
    font-weight: 600;
    color: #f5f5f7;
  }
  #s1-recent-projects-grid .project-card-type {
    font-size: 13px;
    margin-top: 4px;
  }
  #stage-1:has(.s1-home-workspace) { padding-bottom: 0; }
  #chatBar:not(.show),
  #stage-1:has(.s1-home-workspace) #chatBar {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  /* ===== Header ===== */
  body.studio-app header,
  body.account-page header,
  body.pricing-page header,
  body.settings-page header,
  body.chat-page header {
    transform: none !important;
    opacity: 1;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    min-height: 52px;
    padding: 6px 10px;
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
    background: #0c0c0e;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
  body.studio-app .logo,
  body.account-page .logo,
  body.pricing-page .logo,
  body.settings-page .logo {
    font-size: 15px;
    font-weight: 650;
    letter-spacing: -0.02em;
  }
  body.account-page .profile-wrapper,
  body.pricing-page .profile-wrapper,
  body.settings-page .profile-wrapper,
  body.chat-page .profile-wrapper {
    margin-left: auto;
    flex: 0 0 auto;
    gap: 6px;
  }
  body.account-page .project-title,
  body.pricing-page .project-title,
  body.settings-page .project-title {
    order: 0;
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    justify-content: center;
    overflow: hidden;
  }
  body.studio-app .project-title {
    order: 2;
    flex: 1 1 auto;
    width: auto;
    justify-content: flex-start;
    min-width: 0;
    overflow: hidden;
  }
  .pipeline:not(.show-pipeline) { display: none; }
  .pipeline-phone { display: none !important; }
  body.studio-app .project-title:not(:has(.show-pipeline)) { display: none; }
  .pipeline {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    justify-content: flex-start;
    scrollbar-width: none;
    padding: 0;
    gap: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    touch-action: pan-x;
  }
  .pipeline::-webkit-scrollbar { display: none; }
  .pipeline span {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 6px 11px;
    border: 0;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
    color: rgba(255, 255, 255, 0.42);
  }
  .pipeline::after {
    content: "";
    flex: 0 0 40px;
    width: 40px;
  }
  .pipeline span.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
    border: 0;
    box-shadow: none;
  }
  body.studio-app .project-title {
    align-items: center;
    gap: 6px;
    overflow: hidden;
  }
  body.studio-app .project-title .pipeline {
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
  }
  #main-pipeline > .pipeline-generate-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    min-height: 36px;
    padding: 6px 12px;
    border: 0;
    box-shadow: none;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: rgba(255, 255, 255, 0.42);
  }
  #main-pipeline > .pipeline-generate-btn.is-on {
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
    border: 0;
    box-shadow: none;
  }
  .header-right {
    margin-left: auto;
    gap: 8px;
  }
  .profile-dropdown,
  .studio-hub-dropdown {
    position: fixed !important;
    top: calc(var(--phone-header) + 8px) !important;
    right: 12px !important;
    bottom: auto !important;
    left: 12px !important;
    width: auto !important;
    max-height: min(68dvh, 520px);
    overflow: auto;
    z-index: 4000 !important;
    transform: none !important;
  }
  #profileToggle {
    position: relative;
    z-index: 5;
    pointer-events: auto;
  }
  body.account-page .profile-dropdown,
  body.pricing-page .profile-dropdown,
  body.settings-page .profile-dropdown,
  body.chat-page .profile-dropdown,
  body.account-page .studio-hub-dropdown,
  body.pricing-page .studio-hub-dropdown,
  body.settings-page .studio-hub-dropdown,
  body.chat-page .studio-hub-dropdown {
    bottom: 12px;
  }

  .stages-container,
  .stage.active {
    min-height: 0;
  }
  .stage {
    padding-bottom: 8px;
  }

  /* Stage 1 */
  .action-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .action-btn { padding: 18px 10px; }
  .recent-grid { grid-template-columns: 1fr; }
  .workspace-title { font-size: 24px; }
  #s1-text { font-size: 22px; letter-spacing: 1px; width: calc(100% - 32px); text-align: center; }
  .s1-make-idea {
    left: 0;
    right: 0;
    top: 72px;
    bottom: calc(var(--studio-dock) + 88px);
    padding: 0 18px;
    font-size: 1.25rem;
  }
  .idea-card.idea-card-focused {
    left: 50% !important;
    width: min(100% - 24px, 700px) !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - var(--studio-dock) - 96px);
  }
  body.studio-app .chat-container,
  body.studio-app #ideas-container {
    left: 0;
    right: 0;
  }
  body.studio-app .chat-container {
    bottom: var(--studio-dock);
    padding-bottom: 10px;
  }
  #ideas-container:not(.vertical):not(.masonry) .idea-card {
    min-width: min(78vw, 260px);
  }
  #ideas-container.vertical .idea-card {
    width: calc(100% - 24px);
  }
  .content-constrained {
    padding-left: 12px;
    padding-right: 12px;
  }

  /* Stage 2 editor: groups stay in a row; the phone rules below wrap those groups. */
  .ql-toolbar.ql-snow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    overflow: visible;
    padding: 6px 8px !important;
  }
  .ql-editor { padding: 16px; }
  #stage-2 #stage2-flow { padding-bottom: 12px !important; }

  /* Stage 3 */
  #stage-3 .s3-stage { padding: 8px 12px; max-width: none; }
  #stage-3 .s3-header-actions {
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    flex-wrap: nowrap;
  }
  #stage-3 .s3-style-rail { max-width: 100%; }
  #stage-3 .s3-style-tile,
  #stage-3 .s3-style-cover { width: 60px; }
  #stage-3 .s3-style-cover { height: 60px; border-radius: 16px; }

  /* Stage 4 shots: one scrolling tool row, never a second header band. */
  .s4-header-controls {
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    padding: 2px 10px 8px;
    margin: 0;
    gap: 8px;
    touch-action: pan-x;
  }
  .s4-header-controls::-webkit-scrollbar { display: none; }
  .s4-header-left,
  .s4-header-right {
    width: auto;
    flex: 0 0 auto;
    overflow: visible;
    flex-wrap: nowrap;
  }
  .s4-grid-view,
  .s4-grid-view .s4-multishot-group {
    grid-template-columns: 1fr !important;
  }
  #stage-4.active {
    justify-content: flex-start;
  }
  #stage-4.active #s4-scroll {
    flex: 1 1 auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  #stage-4 .s4-grid-view .img-wrapper {
    flex: 0 0 auto;
    width: 100%;
  }
  #stage-4 .s4-grid-view .image-container,
  #stage-4 .s4-grid-view .empty-img-placeholder {
    width: 100%;
    height: auto !important;
    aspect-ratio: var(--s4-shot-aspect, 16 / 9);
    min-height: 0;
  }
  #stage-4 .s4-grid-view .image-container .story-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  /* List rows: a small still, with the description beside it. */
  .s4-list-view .storyboard-row {
    align-items: flex-start;
    gap: 10px;
    padding: 10px 10px 12px;
  }
  .s4-list-view .img-wrapper {
    flex: 0 0 84px !important;
    width: 84px !important;
    height: 64px;
    align-self: flex-start;
  }
  .s4-list-view .img-wrapper .image-container,
  .s4-list-view .img-wrapper .empty-img-placeholder,
  .s4-list-view .img-wrapper .story-img {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    object-fit: cover;
  }
  .s4-list-view .s4-shot-body {
    flex: 1 1 auto;
    min-width: 0;
    gap: 6px;
  }
  .s4-list-view .storyboard-text-edit {
    field-sizing: content;
    min-height: 8.5em;
    max-height: 46dvh;
    height: auto;
    overflow-y: auto;
    padding: 0 2px 2px;
    font-size: 14px;
    line-height: 1.5;
  }
  .s4-list-view .s4-shot-assets {
    flex-wrap: wrap;
  }
  .s4-list-view .s4-shot-meta {
    position: static;
    flex: 0 0 auto;
    align-self: flex-end;
    margin: 0;
  }

  /* ===== Stage 5 generate: Flow-style gallery + bottom composer ===== */
  #stage-5 .s5-workspace {
    flex-direction: column;
    gap: 0;
    padding: 0;
    overflow: visible;
  }
  #stage-5 .s5-panel-drag-handle,
  #stage-5 .s5-splitter,
  #stage-5 .s5-panel-handle-slot {
    display: none !important;
  }

  #stage-5.s5-gallery-mode .s5-gallery-pane,
  body.ai-generate-mode #stage-5 .s5-gallery-pane {
    order: 0;
    flex: 1 1 auto;
    width: 100% !important;
    min-height: 0;
    padding: 8px 8px 280px;
  }
  #stage-5.s5-gallery-mode .s5-gallery-pane::before { display: none; }
  .s5-gallery-type-menu.is-anchored,
  .s5-gallery-zoom-pop.is-anchored {
    position: fixed;
    z-index: 5000;
    margin: 0;
    overflow: visible;
    touch-action: manipulation;
  }
  .s5-gallery-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    position: relative;
    z-index: 6;
    gap: 6px;
    margin: 0 0 8px;
    padding: 2px 2px 0;
    touch-action: pan-x;
  }
  .s5-gallery-toolbar::-webkit-scrollbar { display: none; }
  .s5-gallery-filter { flex: 0 0 auto; height: 34px; padding: 0 12px; }
  .s5-gallery-toolbar-end { margin-left: auto; }
  .s5-gallery-type-wrap {
    position: relative;
    flex: 0 0 auto;
    z-index: 8;
  }
  .s5-gallery-type-menu {
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 148px;
    padding: 6px;
    border-radius: 16px;
    background: rgba(22, 22, 24, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.5);
  }
  .s5-gallery-type-menu[hidden] { display: none !important; }
  .s5-gallery-type-menu .s5-gallery-filter {
    width: 100%;
    justify-content: flex-start;
    border-radius: 12px;
  }
  .s5-gallery-zoom-wrap {
    position: relative;
    z-index: 7;
  }
  .s5-gallery-zoom-pop {
    z-index: 50;
  }
  .s5-gallery-zoom-pop:not([hidden]) {
    display: flex !important;
  }
  .s5-gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--s5-gallery-tile, 290px)), 1fr)) !important;
    gap: 8px !important;
  }
  .s5-gallery-masonry {
    gap: 16px !important;
  }
  .s5-gallery-col {
    gap: 0 !important;
  }
  .s5-gallery-col > .s5-gallery-card + .s5-gallery-card {
    margin-top: 16px;
  }
  .s5-gallery-actions {
    left: 4px;
    right: 4px;
    gap: 3px;
    flex-wrap: nowrap;
  }
  .s5-gallery-actions button {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    border-radius: 8px;
  }
  .s5-gallery-actions button svg {
    width: 13px;
    height: 13px;
  }
  .s5-gallery-actions button.s5-gallery-timeline {
    padding: 0;
    gap: 0;
  }
  .s5-gallery-actions button.s5-gallery-timeline svg {
    display: none;
  }
  .s5-gallery-actions button.s5-gallery-timeline span {
    display: inline !important;
    font-size: 0 !important;
    line-height: 0;
  }
  .s5-gallery-actions button.s5-gallery-timeline span::after {
    content: "T";
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
  }
  /* Touch phones have no hover, so card chrome stays off until a short press. */
  @media (hover: none) {
    .s5-gallery-type,
    .s5-gallery-play {
      transition: opacity 0.2s ease;
    }
    .s5-gallery-card:not(.is-phone-actions):not(.is-generating):not(.is-failed) .s5-gallery-type {
      opacity: 0;
    }
    .s5-gallery-card:not(.is-phone-actions):not(.is-playing) .s5-gallery-play {
      opacity: 0;
      pointer-events: none;
    }
    .s5-gallery-card:not(.is-phone-actions) .s5-gallery-actions,
    .s5-gallery-card:not(.is-phone-actions):hover .s5-gallery-actions,
    .s5-gallery-card:not(.is-phone-actions):focus-within .s5-gallery-actions {
      opacity: 0;
      transform: translateY(6px);
      pointer-events: none;
    }
    .s5-gallery-card:not(.is-phone-actions) .s5-gallery-actions button {
      pointer-events: none;
    }
    .s5-gallery-card.is-phone-actions .s5-gallery-actions,
    .s5-gallery-card.is-phone-actions:hover .s5-gallery-actions,
    .s5-gallery-card.is-phone-actions:focus-within .s5-gallery-actions {
      opacity: 1;
      transform: none;
      pointer-events: none;
    }
    .s5-gallery-card.is-phone-actions .s5-gallery-actions button,
    .s5-gallery-card.is-phone-actions .s5-gallery-play,
    .s5-gallery-card.is-playing .s5-gallery-play {
      pointer-events: auto;
    }
    .s5-gallery-card.is-phone-actions .s5-gallery-type,
    .s5-gallery-card.is-phone-actions .s5-gallery-play,
    .s5-gallery-card.is-playing .s5-gallery-play {
      opacity: 1;
    }
  }
  .s5-gallery-grid.is-folders {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--s5-gallery-folder-tile, 116px)), 1fr)) !important;
  }
  .s5-gallery-card,
  .s5-gallery-card img,
  .s5-gallery-card video {
    border-radius: 12px;
  }
  .s5-gallery-card,
  .s5-gallery-card img,
  .s5-gallery-card video {
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
    user-select: none;
  }
  html.app-phone.is-gallery-drag-lock,
  html.app-phone.is-gallery-drag-lock body {
    overflow: hidden !important;
  }
  html.app-phone.is-gallery-drag-lock .s5-gallery-scroll {
    overflow: hidden !important;
    touch-action: none !important;
    overscroll-behavior: none;
  }
  html.app-phone.is-gallery-drag-lock .s5-gallery-card {
    touch-action: none !important;
  }

  #stage-5.s5-gallery-mode .s5-settings-panel,
  body.ai-generate-mode #stage-5 .s5-settings-panel {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--studio-dock) + 8px);
    z-index: 70;
    width: auto !important;
    height: auto !important;
    max-height: min(58dvh, 460px);
    margin: 0;
    padding: 12px 12px 10px;
    border-radius: 22px;
    background: #141414;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55);
    overflow: auto;
  }
  #stage-5.s5-gallery-mode .s5-history-list,
  body.ai-generate-mode #stage-5 .s5-history-list,
  #stage-5.active .s5-history-list,
  #stage-5.s5-gallery-mode .s5-section-title,
  body.ai-generate-mode #stage-5 .s5-section-title,
  #stage-5.active .s5-section-title {
    display: none !important;
  }
  #stage-5.s5-gallery-mode .s5-settings-panel > .s5-tab-content[style*="display: block"],
  body.ai-generate-mode #stage-5 .s5-settings-panel > .s5-tab-content[style*="display: block"],
  #stage-5.active .s5-settings-panel > .s5-tab-content[style*="display: block"] {
    display: flex !important;
    flex-direction: column;
    order: 1;
    gap: 8px;
  }
  #stage-5.s5-gallery-mode .s5-prompt-container,
  body.ai-generate-mode #stage-5 .s5-prompt-container,
  #stage-5.active .s5-prompt-container { order: 1; margin: 0; }
  #stage-5.s5-gallery-mode .s5-controls-row,
  body.ai-generate-mode #stage-5 .s5-controls-row,
  #stage-5.active .s5-controls-row {
    order: 2;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    margin: 0;
    overflow: visible;
    position: relative;
    z-index: 8;
  }
  #stage-5.active .s5-control-btn-dropdown,
  #stage-5.active .s5-controls-row .s5-model-selector {
    position: relative;
    z-index: 2;
    overflow: visible;
    pointer-events: auto;
    cursor: pointer;
  }
  #stage-5.active .s5-control-dropdown {
    top: auto !important;
    bottom: calc(100% + 8px);
    z-index: 40;
    max-height: min(220px, 42dvh);
  }
  #stage-5.s5-gallery-mode .s5-controls-row::-webkit-scrollbar,
  body.ai-generate-mode #stage-5 .s5-controls-row::-webkit-scrollbar { display: none; }
  #stage-5.s5-gallery-mode .s5-control-btn,
  body.ai-generate-mode #stage-5 .s5-control-btn,
  #stage-5.active .s5-control-btn,
  #stage-5.s5-gallery-mode .s5-controls-row .s5-model-selector,
  body.ai-generate-mode #stage-5 .s5-controls-row .s5-model-selector,
  #stage-5.active .s5-controls-row .s5-model-selector {
    flex: 1 1 0;
    align-self: center;
    min-width: 0;
    width: auto;
    height: 36px;
    min-height: 36px;
    max-height: 36px;
    margin: 0 !important;
    padding: 6px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    box-sizing: border-box;
  }
  #stage-5.s5-gallery-mode .s5-controls-row .s5-model-selector,
  body.ai-generate-mode #stage-5 .s5-controls-row .s5-model-selector,
  #stage-5.active .s5-controls-row .s5-model-selector { order: -1; }
  #stage-5.s5-gallery-mode .s5-controls-row .s5-model-left,
  body.ai-generate-mode #stage-5 .s5-controls-row .s5-model-left {
    min-width: 0;
  }
  #stage-5.s5-gallery-mode .s5-controls-row [data-smp-label],
  body.ai-generate-mode #stage-5 .s5-controls-row [data-smp-label] {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #stage-5.s5-gallery-mode .s5-ref-grid-2,
  #stage-5.s5-gallery-mode .s5-ref-grid-4,
  body.ai-generate-mode #stage-5 .s5-ref-grid-2,
  body.ai-generate-mode #stage-5 .s5-ref-grid-4,
  #stage-5.active .s5-ref-grid-2,
  #stage-5.active .s5-ref-grid-4 {
    order: 0;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin: 0 0 12px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #stage-5 .s5-style-picker { order: 0; }
  #stage-5 .s5-ref-box,
  #stage-5 .s5-add-media-bar,
  #stage-5 .s5-ref-thumb {
    width: 64px;
    height: 64px;
    flex: 0 0 auto;
  }
  #stage-5 .s5-ref-tag-label {
    display: block;
  }
  #stage-5.s5-gallery-mode .s5-mobile-more,
  body.ai-generate-mode #stage-5 .s5-mobile-more {
    display: none !important;
  }
  #stage-5.s5-gallery-mode .s5-tabs,
  body.ai-generate-mode #stage-5 .s5-tabs,
  #stage-5.active .s5-tabs {
    display: flex !important;
    order: 2;
    margin: 8px 0 0;
    padding: 0;
    gap: 4px;
  }
  #stage-5.active .s5-tab,
  #stage-5.s5-gallery-mode .s5-tab,
  body.ai-generate-mode #stage-5 .s5-tab {
    height: 34px;
    padding: 0 6px;
    border-radius: 12px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
  }
  #stage-5.active .s5-tab.active,
  #stage-5.s5-gallery-mode .s5-tab.active,
  body.ai-generate-mode #stage-5 .s5-tab.active {
    background: #2a2a2e;
    color: #fff;
  }
  body.ai-generate-mode #stage-5 .s5-tabs {
    display: none !important;
  }
  #stage-5 .s5-settings-panel.is-agent-tab {
    height: min(78dvh, 720px) !important;
    max-height: min(78dvh, 720px) !important;
  }
  #s5-phone-sheet-toggle {
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 12;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #d0d0d4;
    display: grid;
    place-items: center;
    box-shadow: none;
  }
  #s5-phone-sheet-toggle svg {
    width: 16px;
    height: 16px;
  }
  body:not(.ai-generate-mode) #stage-5.active.is-phone-collapsed .s5-tabs,
  #stage-5.is-phone-collapsed .s5-ref-grid-2,
  #stage-5.is-phone-collapsed .s5-ref-grid-4,
  #stage-5.is-phone-collapsed .s5-ref-thumb,
  #stage-5.is-phone-collapsed .s5-controls-row,
  #stage-5.is-phone-collapsed .s5-tabs,
  #stage-5.is-phone-collapsed .s5-style-picker,
  #stage-5.is-phone-collapsed .s5-section-title,
  #stage-5.is-phone-collapsed .s5-add-media-bar {
    display: none !important;
  }
  #stage-5.is-phone-collapsed .s5-prompt-container {
    padding: 8px 52px 8px 46px;
    margin: 0 !important;
    min-height: 52px;
    border-radius: 28px;
    background: rgba(18, 18, 18, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.05),
      0 12px 40px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
  }
  #stage-5.is-phone-collapsed #s5-phone-sheet-toggle {
    top: 50%;
    right: auto;
    left: 18px;
    width: 28px;
    height: 28px;
    background: transparent;
    color: #8e8e93;
    transform: translateY(-50%);
  }
  #stage-5.is-phone-collapsed #s5-phone-sheet-toggle svg {
    transform: rotate(180deg);
  }
  #stage-5.is-phone-collapsed .s5-settings-panel:not(.is-agent-tab) #s5-phone-sheet-toggle {
    display: none !important;
  }
  #stage-5.is-phone-collapsed .s5-prompt-container .s5-prompt-tools,
  #stage-5 .s5-prompt-container:not(.is-phone-open) .s5-prompt-tools {
    display: none !important;
  }
  #stage-5.is-phone-collapsed .s5-prompt-container > #s5-generate-btn {
    inset: 0;
    right: 0;
    top: 0;
    width: auto !important;
    height: auto !important;
    transform: none !important;
    pointer-events: none;
  }
  #stage-5.is-phone-collapsed .s5-prompt-container > #s5-generate-btn .s5-generate-credits {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
  }
  #stage-5.is-phone-collapsed .s5-prompt-container > #s5-generate-btn .s5-generate-arrow {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: auto;
  }
  #stage-5.is-phone-collapsed .s5-gallery-pane,
  #stage-5.is-phone-collapsed.s5-gallery-mode .s5-gallery-pane {
    padding-bottom: 0 !important;
  }
  #stage-5 .s5-controls-row > .s5-model-selector .ai-model-logo,
  #stage-5 .s5-controls-row > .s5-model-selector .smp-logo-fallback {
    width: 18px;
    height: 18px;
    border-radius: 6px;
  }
  #stage-5 .s5-prompt-container {
    display: flex;
    flex-direction: column;
    height: auto !important;
    min-height: 56px !important;
    max-height: none !important;
    margin: 0 0 12px !important;
    padding: 12px 112px 12px 14px;
    border-radius: 26px;
    background: rgba(18, 18, 18, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  }
  #stage-5 .s5-prompt-container .s5-prompt-highlight-wrap {
    min-height: 24px;
    max-height: 44px;
    margin: 0;
  }
  #stage-5 .s5-prompt-container .s5-prompt-editor {
    min-height: 24px;
    max-height: 44px;
    height: auto;
    padding: 2px 0;
    font-size: 16px !important;
    line-height: 1.6;
  }
  #stage-5 .s5-prompt-container.is-phone-open {
    padding: 8px 12px 48px 14px !important;
    min-height: 168px !important;
  }
  #stage-5 .s5-prompt-container.is-phone-open .s5-prompt-highlight-wrap {
    flex: 1 1 auto;
    align-items: stretch;
    justify-content: flex-start;
    align-self: stretch;
    min-height: 104px;
    max-height: 34dvh;
  }
  #stage-5 .s5-prompt-container.is-phone-open .s5-prompt-editor {
    box-sizing: border-box;
    align-self: stretch;
    height: auto !important;
    min-height: 104px;
    max-height: 34dvh;
    padding: 0 128px 0 0 !important;
  }
  .s5-prompt-library-list {
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
  }
  #stage-5 .s5-prompt-footer,
  #stage-5 .s5-prompt-expand-btn { display: none !important; }
  #stage-5 .s5-settings-panel .s5-prompt-tools {
    display: none !important;
    top: 8px;
    right: 8px;
    bottom: auto;
    transform: none;
  }
  #stage-5 .s5-prompt-container.is-phone-open .s5-prompt-tools,
  #stage-5 .s5-prompt-container.is-phone-open .s5-prompt-clear-btn {
    display: inline-flex !important;
  }
  #stage-5.is-phone-collapsed .s5-prompt-container.is-phone-open .s5-prompt-tools,
  #stage-5.is-phone-collapsed .s5-prompt-container.is-phone-open .s5-prompt-clear-btn {
    display: none !important;
  }
  #stage-5 .s5-prompt-container.is-phone-open > #s5-generate-btn {
    top: auto !important;
    bottom: 8px !important;
    right: 8px !important;
    transform: none !important;
  }
  #stage-5 .s5-prompt-container > #s5-generate-btn {
    position: absolute !important;
    top: 50%;
    right: 8px;
    bottom: auto;
    left: auto;
    transform: translateY(-50%) !important;
    z-index: 7;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    background-image: none !important;
    color: inherit !important;
    font-size: inherit !important;
    box-shadow: none !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
  }
  #stage-5 .s5-prompt-container > #s5-generate-btn .s5-generate-label { display: none !important; }
  #stage-5 .s5-prompt-container > #s5-generate-btn .s5-generate-credits {
    display: inline-flex !important;
    align-items: center;
    padding: 0 !important;
    background: transparent !important;
    color: #f0b429 !important;
    font-size: 13px !important;
    font-weight: 650;
    line-height: 1;
    letter-spacing: 0;
  }
  #stage-5 .s5-prompt-container > #s5-generate-btn .s5-generate-arrow {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f5f5f7;
    color: #111;
    flex: 0 0 auto;
  }
  #stage-5 .s5-prompt-container > #s5-generate-btn .s5-generate-arrow svg {
    width: 16px;
    height: 16px;
    display: block;
  }
  #stage-5.is-phone-collapsed .s5-prompt-container > #s5-generate-btn .s5-generate-arrow {
    background: transparent;
    color: #8e8e93;
    border: 1px solid rgba(255, 255, 255, 0.14);
  }
  #stage-5.is-phone-collapsed .s5-prompt-container > #s5-generate-btn.is-ready .s5-generate-arrow {
    background: #f5f5f7;
    color: #111;
    border-color: #f5f5f7;
  }
  #stage-5:not(.active) .s5-settings-panel,
  #stage-5:not(.active) .s5-right-panel,
  #stage-5:not(.active) .s5-mobile-tools {
    display: none !important;
  }
  .s5-mobile-more { display: none !important; }

  /* Stage 5 editor: preview over timeline, panels as sheets */
  #stage-5:not(.s5-gallery-mode) .s5-editor-container {
    order: 1;
    display: flex !important;
    flex-direction: column;
    flex: 1 1 auto;
    gap: 0;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 0;
    height: 100% !important;
    overflow: hidden;
  }
  #stage-5:not(.s5-gallery-mode) .s5-preview-area {
    --s5-preview-ratio: 16 / 9;
    --s5-preview-w: 16;
    --s5-preview-h: 9;
    flex: 1 1 auto !important;
    align-self: stretch;
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: auto;
    min-height: 0 !important;
    max-height: none;
    margin: 0;
    border-radius: 0;
    background: #000;
    overflow: hidden;
  }
  #stage-5:not(.s5-gallery-mode) .s5-timeline-layout {
    flex: 0 1 200px;
    width: 100% !important;
    min-height: 148px;
    max-height: 220px;
    height: auto !important;
    overflow: hidden;
    border-radius: 0;
    --s5-track-height: 52px;
  }
  #stage-5:not(.s5-gallery-mode) .s5-timeline-tracks-scroll {
    flex: 0 1 auto;
    height: auto;
    min-height: 0;
    max-height: 36dvh;
    overflow-x: hidden;
    overflow-y: auto;
    flex-wrap: wrap;
  }
  #stage-5:not(.s5-gallery-mode) .s5-timeline-inner,
  #stage-5:not(.s5-gallery-mode) .s5-fixed-headers {
    min-height: 0;
    height: auto;
  }
  #stage-5:not(.s5-gallery-mode) .s5-timeline-container {
    min-height: 0;
    height: auto;
  }
  #stage-5:not(.s5-gallery-mode) .s5-fixed-tails {
    order: 3;
    flex: 1 0 100%;
    width: 100%;
    height: auto;
    max-height: none;
    position: static;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(12, 12, 14, 0.96);
  }
  #stage-5:not(.s5-gallery-mode) .s5-timeline-tools {
    position: static;
    flex-direction: row;
    padding: 4px 8px;
    gap: 6px;
  }
  #stage-5:not(.s5-gallery-mode) .s5-tl-vzoom {
    flex-direction: row;
    margin: 0;
    padding: 4px 8px;
  }
  #stage-5:not(.s5-gallery-mode) .s5-tl-add-menu {
    right: 0;
    top: auto;
    bottom: calc(100% + 6px);
  }
  #stage-5:not(.s5-gallery-mode) .s5-top-gutter-end,
  #stage-5:not(.s5-gallery-mode) .s5-hscroll-gutter-end {
    width: 8px;
  }
  .s5-phone-track-hidden { display: none !important; }
  #stage-5:not(.s5-gallery-mode) .s5-settings-panel,
  #stage-5:not(.s5-gallery-mode) .s5-right-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--studio-dock);
    z-index: 75;
    width: 100% !important;
    height: min(72dvh, 620px) !important;
    max-height: min(72dvh, 620px);
    margin: 0;
    padding: 14px 12px 18px;
    border-radius: 22px 22px 0 0;
    background: #141414;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.5);
    transform: translateY(110%);
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
    overflow: auto;
  }
  #stage-5.s5-gen-open:not(.s5-gallery-mode) .s5-settings-panel,
  #stage-5.s5-clip-open:not(.s5-gallery-mode) .s5-right-panel {
    transform: translateY(0);
  }
  #stage-5:not(.s5-gallery-mode) .s5-right-panel {
    display: flex !important;
  }
  #stage-5:not(.active) .s5-mobile-tools,
  #stage-5.s5-gallery-mode .s5-mobile-tools,
  body.ai-generate-mode #stage-5 .s5-mobile-tools { display: none !important; }
  #stage-5.active:not(.s5-gallery-mode) .s5-mobile-tools {
    display: flex !important;
    position: absolute;
    right: 10px;
    bottom: 10px;
    z-index: 30;
    gap: 8px;
  }
  .s5-mobile-tools button {
    height: 36px;
    padding: 0 14px;
    border-radius: 999px;
    background: rgba(20, 20, 22, 0.92) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    color: #fff;
    font-size: 12px;
    font-weight: 650;
    box-shadow: none !important;
    transform: none !important;
  }
  .s5-sheet-backdrop {
    display: none;
  }
  #stage-5.s5-gen-open:not(.s5-gallery-mode) .s5-sheet-backdrop,
  #stage-5.s5-clip-open:not(.s5-gallery-mode) .s5-sheet-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.35);
  }

  /* Agent panel becomes a sheet above the dock */
  body.studio-app.studio-agent-entering:not(.ai-generate-mode) .studio-agent-panel,
  body.studio-app.studio-agent-open.studio-agent-available:not(.ai-generate-mode) .studio-agent-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--studio-dock);
    top: auto;
    width: 100% !important;
    flex-basis: auto !important;
    height: min(78dvh, 680px);
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 22px 22px 0 0;
    transform: none;
    z-index: 85;
  }

  /* Concept generator modal */
  .s3-layout-container {
    flex-direction: column;
    padding: 12px;
    overflow: auto;
  }
  .s3-center-area {
    order: 1;
    width: 100%;
    height: auto;
    flex: 0 0 auto;
    min-height: 0;
  }
  #s5-gallery-modal,
  #stage3-modal,
  #s5-gallery-modal .s3-modal-content,
  #stage3-modal .s3-modal-content {
    height: 100dvh;
    max-height: 100dvh;
  }
  #s5-gallery-modal .s3-layout-container,
  #stage3-modal .s3-layout-container {
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  }
  #s5-gallery-modal .s3-layout-container {
    overflow-anchor: none;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
  }
  #s5-gallery-modal .s3-center-area {
    order: 1 !important;
  }
  #s5-gallery-modal #s5g-left-panel {
    order: 2 !important;
    margin-top: 0 !important;
  }
  #s5-gallery-modal .s3-right-sidebar {
    order: 0;
    position: relative;
    z-index: 6;
    height: 76px;
    min-height: 76px;
    padding: 0 52px 0 4px;
    box-sizing: border-box;
  }
  #s5-gallery-modal .s3-top-toolbar {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: 100%;
    margin: 8px 0 0;
    padding: 4px 2px;
    z-index: 5;
    background: rgba(12, 12, 14, 0.88);
    border-radius: 14px;
  }
  #s5-gallery-modal .s3-close,
  #stage3-modal .s3-close {
    top: calc(8px + env(safe-area-inset-top, 0px));
    right: 10px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(20, 20, 22, 0.78);
    color: #fff;
    display: grid;
    place-items: center;
    z-index: 10020;
  }
  #s5-gallery-modal .s3-close {
    top: calc(26px + env(safe-area-inset-top, 0px));
  }
  #stage3-modal .s3-top-toolbar {
    width: calc(100% + 24px);
    margin: 0 -12px;
    padding: 0 48px;
    box-sizing: border-box;
    justify-content: center;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #s5-gallery-modal .s3-top-toolbar {
    box-sizing: border-box;
    justify-content: center;
    align-items: center;
    gap: 4px;
    overflow: visible;
    scrollbar-width: none;
  }
  #s5-gallery-modal .s3-top-toolbar .toolbar-btn {
    flex: 1 1 0;
    max-width: 52px;
    height: 46px;
    min-width: 0;
    padding: 0;
    border-radius: 12px;
  }
  #s5-gallery-modal .s3-top-toolbar .toolbar-btn svg {
    width: 23px;
    height: 23px;
  }
  #s5-gallery-modal.is-phone-fs .s3-top-toolbar,
  #s5-gallery-modal.is-phone-fs #s5g-chatBar,
  #s5-gallery-modal.is-phone-fs #s5g-left-panel,
  #s5-gallery-modal.is-phone-fs .s3-right-sidebar,
  #s5-gallery-modal.is-phone-fs .s3-close {
    display: none !important;
  }
  #s5-gallery-modal.is-phone-fs .s3-layout-container {
    padding: 0;
    overflow: hidden;
  }
  #s5-gallery-modal.is-phone-fs #s5g-media-stage {
    position: fixed;
    inset: 0;
    z-index: 10040;
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    max-height: none;
    border-radius: 0;
    background: #000;
    touch-action: none;
  }
  #s5-gallery-modal.is-phone-fs #s5g-media-stage .s5g-stage-image,
  #s5-gallery-modal.is-phone-fs #s5g-media-stage .s5g-stage-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  #s5-gallery-modal .toolbar-btn,
  #stage3-modal .toolbar-btn {
    flex: 0 0 auto;
  }
  #s5g-media-stage,
  .s3-center-area .image-preview-wrapper {
    height: 42dvh;
    min-height: 220px;
  }
  #s5g-chatBar .s5g-chat-head {
    display: flex;
    align-items: flex-start;
    gap: 8px;
  }
  #s5g-chatBar .s5g-chat-head textarea {
    flex: 1 1 auto;
    min-width: 0;
  }
  #s5g-attach-slot {
    display: flex;
    flex: 0 0 auto;
    align-items: flex-start;
    justify-content: flex-end;
    max-width: 46%;
  }
  #s5g-attach-slot:empty {
    display: none;
  }
  #s5g-attach-wrap {
    justify-content: flex-end;
  }
  #s5g-attach-thumbs {
    max-width: 108px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  #s5g-chatBar .chat-controls-row {
    gap: 6px;
    align-items: center;
  }
  #s5g-chatBar .chat-left-controls {
    min-width: 0;
    flex: 1 1 auto;
    gap: 6px;
    overflow: hidden;
  }
  #s5g-chatBar .s5g-param-slots {
    flex-wrap: nowrap;
    gap: 4px;
    min-width: 0;
  }
  #s5g-model-btn {
    max-width: 46vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #s3-right-panel,
  #s5g-left-panel {
    order: 2;
    width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    margin: 0 !important;
  }
  .s3-right-sidebar {
    order: 3;
    width: 100%;
    min-width: 0;
    height: 84px;
    min-height: 84px;
    flex: 0 0 auto;
    margin: 0;
    flex-direction: row;
    align-items: center;
    overflow: hidden;
    padding-top: 0;
  }
  #s5-gallery-modal #s5g-thumbnails,
  #s5-gallery-modal #s3-thumbnails,
  #stage3-modal #s5g-thumbnails,
  #stage3-modal #s3-thumbnails {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    height: 76px;
    min-height: 76px;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 4px 2px !important;
    touch-action: pan-x;
    scrollbar-width: none;
  }
  #s5-gallery-modal #s5g-thumbnails .thumb-wrapper,
  #s5-gallery-modal #s3-thumbnails .thumb-wrapper,
  #stage3-modal #s5g-thumbnails .thumb-wrapper,
  #stage3-modal #s3-thumbnails .thumb-wrapper {
    flex: 0 0 64px;
    width: 64px;
    height: 64px;
  }

  /* Shared overlays */
  .vision-modal-content,
  .pr-modal,
  .s5-audio-modal-content,
  .s5-render-box {
    width: min(100% - 16px, 520px) !important;
    max-height: calc(100dvh - 24px);
    overflow: auto;
  }
  .s5-render-box { padding: 16px !important; }
  #s5-render-overlay {
    padding: 8px;
    align-items: flex-end;
  }
  .s5-render-link-row {
    flex-wrap: wrap;
  }
  #s5-render-copy,
  #s5-render-download,
  #s5-render-start-btn,
  #s5-render-cancel-btn,
  .s5-render-res label {
    min-height: 44px;
  }
  .smp-panel {
    width: calc(100vw - 16px);
    max-height: min(72dvh, 520px);
  }

  /* Chat */
  body.chat-page .chat-shell { min-height: 0; }
  body.chat-page .chat-thread,
  body.chat-page .chat-skills-panel { padding-top: calc(52px + env(safe-area-inset-top, 0px)); }
  body.chat-page .chat-composer-wrap {
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
  body.chat-page .chat-sidebar {
    width: min(100%, 320px);
  }
  .chat-skills-grid { grid-template-columns: 1fr !important; }

  /* Account */
  body.account-page .account-switcher,
  body.pricing-page .account-switcher {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: none;
    box-shadow: none;
    padding: 3px;
    gap: 2px;
  }
  body.account-page .account-switcher::-webkit-scrollbar,
  body.pricing-page .account-switcher::-webkit-scrollbar { display: none; }
  body.account-page .account-switcher span,
  body.pricing-page .account-switcher span {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 7px 12px;
    font-size: 12px;
    letter-spacing: 0;
  }
  body.account-page .account-main,
  body.account-page .account-panel {
    padding-left: 12px;
    padding-right: 12px;
  }
  .password-row { grid-template-columns: 1fr !important; }
  .acc-toast { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); max-width: calc(100% - 24px); }

  /* Pricing / checkout */
  body.pricing-page .pricing-hero h1 { font-size: 28px; }
  body.pricing-page .pricing-shell { width: min(100% - 20px, 1180px); }
  .compare-wrap { overflow-x: auto; }
  .compare-table { min-width: 640px; }
  .billing-bar, .cat-filters { flex-wrap: wrap; }
  .checkout-grid { grid-template-columns: 1fr !important; }

  /* App stack: content, then chat/generate box, then the black menu. */
  body.studio-app .chat-container.show,
  body.studio-app #chatBar.chat-container,
  body.studio-app #s2-chatBar.chat-container,
  body.studio-app.studio-agent-open.studio-agent-available:not(.ai-generate-mode) #chatBar.chat-container,
  body.studio-app.studio-agent-open.studio-agent-available:not(.ai-generate-mode) #s2-chatBar.chat-container,
  body.studio-app.studio-agent-entering:not(.ai-generate-mode) #chatBar.chat-container,
  body.studio-app.studio-agent-entering:not(.ai-generate-mode) #s2-chatBar.chat-container {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: var(--studio-dock) !important;
    top: auto !important;
    width: auto !important;
    z-index: 75;
    margin: 0;
    padding: 8px 10px;
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    background: #101012;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px 16px 0 0;
  }
  #stage-1:not(.active) #chatBar,
  #stage-2:not(.active) #s2-chatBar {
    display: none !important;
  }
  #stage-1.active,
  #stage-2.active,
  #stage-3.active {
    padding-bottom: calc(var(--app-composer) + 8px);
  }
  #stage-4.active {
    padding-bottom: 0;
  }
  #stage-5.active .s5-settings-panel {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: calc(var(--studio-dock) + var(--keyboard-inset, 0px)) !important;
    top: auto !important;
    width: auto !important;
    height: auto !important;
    max-height: 42dvh !important;
    margin: 0 !important;
    transform: none !important;
    z-index: 75;
    padding: 10px 12px 12px;
    border-radius: 18px 18px 0 0 !important;
    background: #141414 !important;
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  }
  #stage-5.active .s5-settings-panel.is-phone-prompt-open {
    max-height: min(72dvh, 640px) !important;
  }
  #stage-5.active .s5-settings-panel.is-agent-tab {
    display: flex !important;
    flex-direction: column;
    height: min(78dvh, 720px) !important;
    max-height: min(78dvh, 720px) !important;
    overflow: hidden;
  }
  #stage-5.active .s5-settings-panel.is-agent-tab > .s5-agent-host {
    flex: 1 1 auto;
    min-height: 0;
  }
  #stage-5.active .s5-editor-container,
  #stage-5.active .s5-preview-area,
  #stage-5.active .s5-timeline-layout,
  #stage-5.active .s5-gallery-pane {
    width: 100% !important;
  }
  #stage-5.active .s5-workspace {
    padding-bottom: 0;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-workspace {
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
    padding-bottom: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden;
  }
  #stage-5.active .s5-gallery-pane,
  #stage-5.s5-gallery-mode .s5-gallery-pane {
    padding-bottom: 230px !important;
  }
  #stage-5.active:not(.is-phone-collapsed):not(:has(.is-phone-prompt-open)) #s5-gallery-pane {
    padding-bottom: calc(var(--s5-small-sheet-h, 120px) + var(--keyboard-inset, 0px)) !important;
  }
  /* Small composer: no settings card. Style and reference buttons stay above the prompt. */
  #stage-5.active.s5-gallery-mode:not(.is-phone-collapsed):not(:has(.is-phone-prompt-open)) .s5-settings-panel:not(.is-agent-tab),
  body.ai-generate-mode #stage-5.active:not(.is-phone-collapsed):not(:has(.is-phone-prompt-open)) .s5-settings-panel:not(.is-agent-tab) {
    padding: 0 8px 4px !important;
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  #stage-5.active.s5-gallery-mode:not(.is-phone-collapsed):not(:has(.is-phone-prompt-open)) .s5-section-title,
  body.ai-generate-mode #stage-5.active:not(.is-phone-collapsed):not(:has(.is-phone-prompt-open)) .s5-section-title {
    display: none !important;
  }
  #stage-5.active.s5-gallery-mode:not(.is-phone-collapsed):not(:has(.is-phone-prompt-open)) .s5-ref-grid-2,
  #stage-5.active.s5-gallery-mode:not(.is-phone-collapsed):not(:has(.is-phone-prompt-open)) .s5-ref-grid-4,
  body.ai-generate-mode #stage-5.active:not(.is-phone-collapsed):not(:has(.is-phone-prompt-open)) .s5-ref-grid-2,
  body.ai-generate-mode #stage-5.active:not(.is-phone-collapsed):not(:has(.is-phone-prompt-open)) .s5-ref-grid-4 {
    display: flex !important;
  }
  #stage-5.active:not(.s5-gallery-mode) {
    --s5-transport: 64px;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-editor-container {
    order: 1;
    height: auto !important;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow: hidden;
    display: flex !important;
    flex-direction: column !important;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-editor-container > audio {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-stage-nav {
    order: 2;
    position: relative !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    z-index: 6;
    width: 100% !important;
    flex: 0 0 52px;
    height: 52px;
    margin: 0 !important;
    padding: 0 4px;
    min-height: 52px;
    max-height: 52px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    gap: 0;
    background: #121214;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    overflow: visible;
    flex-wrap: nowrap;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-bottom-center-tools,
  #stage-5.active:not(.s5-gallery-mode) .s5-zoom-controls,
  #stage-5.active:not(.s5-gallery-mode) .s5-toolbar-left,
  #stage-5.active:not(.s5-gallery-mode) .s5-toolbar-right,
  #stage-5.active:not(.s5-gallery-mode) .s5-export-cluster,
  #stage-5.active:not(.s5-gallery-mode) .s5-mobile-tools {
    display: contents !important;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-tool-divider,
  #stage-5.active:not(.s5-gallery-mode) .s5-zoom-label,
  #stage-5.active:not(.s5-gallery-mode) .s5-volume-wrapper,
  #stage-5.active:not(.s5-gallery-mode) #s5-btn-prev,
  #stage-5.active:not(.s5-gallery-mode) #s5-snap-btn,
  #stage-5.active:not(.s5-gallery-mode) .s5-timeline-play-btn {
    display: none !important;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-zoom-btn,
  #stage-5.active:not(.s5-gallery-mode) .s5-tool-btn,
  #stage-5.active:not(.s5-gallery-mode) #s5-export-btn,
  #stage-5.active:not(.s5-gallery-mode) .s5-download-btn,
  #stage-5.active:not(.s5-gallery-mode) .s5-mobile-tools button {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    flex: 0 0 32px;
    margin: 0;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 8px;
    background: transparent !important;
    color: #ececf1;
    font-size: 0 !important;
    letter-spacing: 0 !important;
    line-height: 0;
    box-shadow: none !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-save-wrap,
  #stage-5.active:not(.s5-gallery-mode) .s5-download-wrap {
    width: 32px;
    height: 32px;
    min-width: 32px;
    flex: 0 0 32px;
    margin: 0;
    padding: 0;
    position: relative;
    overflow: visible;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: normal;
    letter-spacing: normal;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-phone-ico,
  #stage-5.active:not(.s5-gallery-mode) .s5-zoom-btn svg,
  #stage-5.active:not(.s5-gallery-mode) #s5-import-s4-btn svg,
  #stage-5.active:not(.s5-gallery-mode) .s5-download-btn svg,
  #stage-5.active:not(.s5-gallery-mode) .s5-mobile-tools svg,
  #stage-5.active:not(.s5-gallery-mode) #s5-export-btn svg {
    display: block !important;
    width: 18px;
    height: 18px;
    stroke: currentColor;
    flex: 0 0 auto;
    pointer-events: none;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-zoom-btn.active,
  #stage-5.active:not(.s5-gallery-mode) .s5-ripple-btn.active,
  #stage-5.active:not(.s5-gallery-mode) .s5-snap-btn.active {
    background: rgba(255, 255, 255, 0.14) !important;
    color: #fff;
  }
  .s5-context-menu {
    min-width: min(260px, calc(100vw - 20px));
    max-width: calc(100vw - 20px);
    max-height: min(68dvh, 440px);
    overflow: auto;
    border-radius: 16px;
    padding: 6px;
    z-index: 12000;
  }
  .s5-context-item {
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: 15px;
    padding: 10px 14px;
  }
  .s5-context-item.s5-has-submenu.is-open {
    flex-wrap: wrap;
  }
  .s5-context-item.s5-has-submenu.is-open > .s5-context-submenu {
    display: block !important;
    position: static;
    left: auto;
    top: auto;
    flex: 1 0 100%;
    margin-top: 6px;
    width: 100%;
    box-sizing: border-box;
  }
  #stage-5:not(.s5-gallery-mode) .s5-clip,
  #stage-5:not(.s5-gallery-mode) .s5-audio-block {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  #stage-5:not(.s5-gallery-mode) .s5-clip,
  #stage-5:not(.s5-gallery-mode) .s5-audio-block,
  #stage-5:not(.s5-gallery-mode) .s5-trim-handle,
  #stage-5:not(.s5-gallery-mode) .s5-audio-trim-handle {
    touch-action: none;
  }
  #stage-5.active.is-phone-collapsed .s5-settings-panel {
    padding: 0 12px 8px !important;
    background: transparent !important;
    background-image: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    max-height: none !important;
    overflow: visible !important;
  }
  #stage-5.active.is-phone-collapsed .s5-settings-panel:not(.is-agent-tab) .s5-dock,
  #stage-5.active.is-phone-collapsed .s5-settings-panel:not(.is-agent-tab) .s5-composer,
  #stage-5.active.is-phone-collapsed .s5-settings-panel:not(.is-agent-tab) .s5-tab-content {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
  }
  #stage-5.active.is-phone-collapsed .s5-settings-panel.is-agent-tab {
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    padding: 0 12px 8px !important;
    overflow: visible !important;
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  #stage-5.active.is-phone-collapsed .s5-settings-panel.is-agent-tab > .s5-agent-host {
    display: flex !important;
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }
  #stage-5.active.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-panel.is-docked {
    height: auto !important;
    min-height: 0 !important;
    flex: 0 0 auto !important;
    overflow: hidden !important;
    background: transparent !important;
  }
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-header,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-thread,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-error,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-gen-blank,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-composer-bar,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-voice,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-autospend,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-surface-row,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-plus,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-mode-wrap,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-gen-refs,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab #s5-phone-sheet-toggle {
    display: none !important;
  }
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-composer {
    padding: 0;
  }
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-form {
    min-height: 52px;
    padding: 8px 8px 8px 16px;
    border-radius: 28px;
    background: rgba(18, 18, 18, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.05),
      0 12px 40px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
  }
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab textarea.studio-agent-input {
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    padding: 4px 0 !important;
    font-size: 16px !important;
    line-height: 28px !important;
  }
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-form-actions {
    display: flex !important;
  }
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-send {
    width: 36px;
    height: 36px;
    opacity: 1;
  }
  #stage-5 .studio-agent-form.is-phone-open,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-form.is-phone-open {
    display: flex;
    flex-direction: column;
    min-height: 168px;
    padding: 10px 12px 12px 14px;
    border-radius: 22px;
  }
  #stage-5 .studio-agent-form.is-phone-open .studio-agent-form-row,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-form.is-phone-open .studio-agent-form-row {
    align-items: flex-end;
    flex: 1 1 auto;
    min-height: 140px;
  }
  #stage-5 .studio-agent-form.is-phone-open textarea.studio-agent-input,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-form.is-phone-open textarea.studio-agent-input {
    align-self: stretch;
    min-height: 120px !important;
    max-height: 34dvh !important;
    padding: 0 8px 0 0 !important;
    font-size: 16px !important;
    line-height: 1.4 !important;
    overflow-y: auto !important;
  }
  #stage-5 .studio-agent-form.is-phone-open .studio-agent-form-actions,
  #stage-5.is-phone-collapsed .s5-settings-panel.is-agent-tab .studio-agent-form.is-phone-open .studio-agent-form-actions {
    align-self: flex-end;
    margin-bottom: 2px;
  }
  #stage-5.active.is-phone-collapsed .s5-gallery-pane,
  #stage-5.active.is-phone-collapsed.s5-gallery-mode .s5-gallery-pane {
    padding-bottom: 0 !important;
  }
  .s5-settings-panel.is-agent-tab .studio-agent-header {
    padding-right: 44px;
  }
  .studio-agent-panel.is-docked .studio-agent-collapse {
    display: none !important;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-stage-nav .s5-mobile-tools,
  #stage-5.active:not(.s5-gallery-mode) .s5-mobile-tools {
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-workspace > .s5-mobile-tools {
    display: none !important;
  }
  #stage-5 .s5-mobile-tools button[data-sheet="gen"] { display: none; }

  body.chat-page .chat-composer-wrap {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--studio-dock) + var(--keyboard-inset, 0px));
    z-index: 40;
    padding: 8px 12px 10px;
    background: #0a0a0c;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
  body.chat-page .chat-thread,
  body.chat-page .chat-skills-panel {
    padding-bottom: calc(var(--studio-dock) + 96px);
  }
  body.chat-page.chat-phone-shell {
    --phone-chat-composer: 92px;
  }
  body.chat-page.chat-phone-shell .chat-sidebar-toggle,
  body.chat-page.chat-phone-shell .chat-phone-history,
  body.chat-page.chat-phone-shell .chat-phone-backdrop {
    display: none !important;
  }
  body.chat-page.chat-phone-shell .chat-sidebar {
    display: flex !important;
    position: fixed;
    top: var(--phone-header, 52px);
    bottom: 0;
    left: 0;
    z-index: 90;
    width: min(280px, 86vw);
    background: #080808;
    transform: translateX(-105%);
  }
  body.chat-page.chat-phone-shell.chat-sidebar-open .chat-sidebar {
    transform: none;
  }
  body.chat-page header#mainHeader {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
  }
  body.chat-page header .logo {
    display: none !important;
  }
  body.chat-page header .profile-wrapper {
    margin-left: auto;
  }
  body.chat-page.chat-phone-shell #mainHeader .chat-phone-menu {
    position: static;
    display: grid;
    place-items: center;
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent !important;
    color: #fff;
    box-shadow: none !important;
    backdrop-filter: none;
    transform: none !important;
    pointer-events: auto;
  }
  body.chat-page.chat-phone-shell .chat-phone-menu[hidden] {
    display: none !important;
  }
  body.chat-page.chat-phone-shell #mainHeader .chat-phone-menu svg {
    display: block;
    width: 16px;
    height: 16px;
    stroke: #fff;
    fill: none;
    opacity: 1;
  }
  body.chat-page .chat-phone-recents {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
    margin: 4px 0 22px;
    text-align: start;
  }
  body.chat-page .chat-phone-recents[hidden] {
    display: none !important;
  }
  body.chat-page .chat-phone-recents-label {
    margin: 0 2px 2px;
    color: #8e8e93;
    font: 650 12px/1 var(--font-main, system-ui);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  body.chat-page .chat-phone-recents-list {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  body.chat-page .chat-empty {
    max-width: 560px;
    margin: 8px auto 0;
    padding: 0 4px;
    text-align: start;
  }
  body.chat-page .chat-empty h1,
  body.chat-page .chat-empty p {
    text-align: start;
  }
  body.chat-page.chat-phone-shell .chat-phone-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1102;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.48);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }
  body.chat-page.chat-phone-shell.chat-phone-history-open .chat-phone-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  body.chat-page.chat-phone-shell .chat-phone-history {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: var(--phone-header, 56px);
    left: 0;
    bottom: var(--studio-dock);
    z-index: 1104;
    width: min(84vw, 320px);
    padding: 16px 14px 18px;
    background: #101012;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 18px 0 48px rgba(0, 0, 0, 0.45);
    box-sizing: border-box;
    transform: translateX(-105%);
    transition: transform 0.24s ease;
  }
  body.chat-page.chat-phone-shell.chat-phone-history-open .chat-phone-history {
    transform: none;
  }
  body.chat-page.chat-phone-shell .chat-phone-history[hidden] {
    display: none !important;
  }
  body.chat-page.chat-phone-shell .chat-phone-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
    margin-bottom: 14px;
  }
  body.chat-page.chat-phone-shell .chat-phone-history-head .chat-history-label {
    margin: 0;
    padding: 0;
    letter-spacing: 0.12em;
  }
  body.chat-page.chat-phone-shell .chat-phone-new-btn {
    flex-shrink: 0;
    height: 32px;
    padding: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: #f5f5f7;
    color: #111;
    font: 650 12px/1 var(--font-main, system-ui);
  }
  body.chat-page.chat-phone-shell .chat-phone-history-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
  }
  body.chat-page.chat-phone-shell .chat-phone-item {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 48px;
    margin: 0;
    padding: 12px 14px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.045) !important;
    color: #f5f5f7;
    text-align: start;
    font: 560 15px/1.35 var(--font-main, system-ui);
    box-shadow: none !important;
    backdrop-filter: none;
    transform: none !important;
  }
  body.chat-page.chat-phone-shell .chat-phone-item span {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: start;
  }
  body.chat-page.chat-phone-shell .chat-phone-item.active,
  body.chat-page.chat-phone-shell .chat-phone-item:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: rgba(255, 255, 255, 0.16);
    color: #fff;
    transform: none !important;
    box-shadow: none !important;
  }
  body.chat-page.chat-phone-shell .chat-thread,
  body.chat-page.chat-phone-shell .chat-skills-panel {
    padding-bottom: calc(var(--studio-dock) + var(--phone-chat-composer, 92px) + 12px + var(--keyboard-inset, 0px));
  }
  body.account-page .account-main,
  body.pricing-page .main-container {
    padding-bottom: var(--studio-dock);
  }

  .app-phone-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    height: var(--studio-dock);
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    padding: 4px 4px env(safe-area-inset-bottom, 0px);
    background: rgba(8, 8, 8, 0.96);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }
  .app-phone-dock a,
  .app-phone-dock button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px 4px;
    border: 0;
    border-radius: 12px;
    background: transparent !important;
    color: #86868b;
    text-decoration: none;
    font: 700 9px/1.1 var(--font-main, system-ui);
    box-shadow: none !important;
    transform: none !important;
  }
  .app-phone-dock svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }
  .app-phone-dock .is-on { color: #fff; background: rgba(255, 255, 255, 0.1) !important; }

  textarea,
  .main-textarea,
  .s5-prompt-container textarea,
  .s5-prompt-editor,
  .s3-chat-input-box {
    font-size: 16px !important;
  }

  /* Timeline editor: preview, timeline, transport, then the original composer.
     The generate card is in the column, so it cannot cover the transport. */
  body.studio-app:has(#stage-5.active) #stage-1 .prompt-box,
  body.studio-app:has(#stage-5.active) #stage-1 h1.seq-header {
    display: none !important;
  }
  #stage-5.active:not(.s5-gallery-mode) {
    display: flex !important;
    flex-direction: column !important;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
    padding-bottom: 0 !important;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-preview-area {
    flex: 1 1 auto !important;
    height: auto !important;
    min-height: 88px;
    max-height: none;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-timeline-layout {
    flex: 0 0 156px !important;
    height: 156px !important;
    min-height: 156px !important;
    max-height: 156px !important;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-settings-panel {
    order: 3;
    position: relative !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: 46dvh !important;
    flex: 0 0 auto;
    margin: 0 !important;
    transform: none !important;
    z-index: 5;
    overflow: auto !important;
    display: flex !important;
    flex-direction: column !important;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-settings-panel > .s5-dock,
  #stage-5.active:not(.s5-gallery-mode) .s5-settings-panel .s5-composer,
  #stage-5.active:not(.s5-gallery-mode) .s5-tab-content[style*="display: block"],
  #stage-5.active:not(.s5-gallery-mode) .s5-tab-content[style*="display: flex"] {
    overflow: visible !important;
    flex: 0 0 auto !important;
    justify-content: flex-start !important;
    min-height: 0;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-tab-content[style*="display: block"],
  #stage-5.active:not(.s5-gallery-mode) .s5-tab-content[style*="display: flex"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px;
  }
  #stage-5.active:not(.s5-gallery-mode):not(.is-phone-collapsed) .s5-ref-grid-2,
  #stage-5.active:not(.s5-gallery-mode):not(.is-phone-collapsed) .s5-ref-grid-4 {
    display: flex;
    order: 1;
    margin: 0;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-controls-row {
    order: 2 !important;
    flex: 0 0 auto !important;
    flex-wrap: nowrap !important;
    align-items: center;
    gap: 6px;
    overflow: visible;
    margin: 0 0 8px !important;
    max-width: 100%;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-prompt-container {
    order: 3 !important;
    flex: 0 0 auto !important;
    overflow: visible;
    margin: 0 0 8px !important;
  }
  #stage-5.active:not(.s5-gallery-mode) .s5-tabs {
    order: 4 !important;
    flex: 0 0 auto !important;
    margin-top: 0;
  }
}

html.app-phone.is-tl-clip-drag,
html.app-phone.is-tl-clip-drag body {
  overflow: hidden !important;
  touch-action: none;
}

html.app-phone #tbeniCookieBanner {
  top: calc(var(--phone-header, 56px) + 8px);
  bottom: auto;
  z-index: 90;
}

html.app-phone body.studio-app #s2-chatBar.chat-container.show,
html.app-phone body.studio-app.studio-agent-open.studio-agent-available:not(.ai-generate-mode) #s2-chatBar.chat-container.show,
html.app-phone body.studio-app.studio-agent-entering:not(.ai-generate-mode) #s2-chatBar.chat-container.show,
html.app-phone body.studio-app #chatBar.chat-container.show {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: var(--studio-dock) !important;
  top: auto !important;
  width: auto !important;
  transform: none !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
  z-index: 75;
}
html.app-phone #chatBar:not(.show),
html.app-phone #stage-1:has(.s1-home-workspace) #chatBar {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
html.app-phone body.app-library-open .projects-sidebar.open {
  position: fixed !important;
  transform: none !important;
  top: var(--phone-header) !important;
  bottom: auto !important;
  height: calc(50dvh - var(--phone-header)) !important;
  padding-top: 12px !important;
  z-index: 96 !important;
  visibility: visible !important;
  pointer-events: auto !important;
  box-sizing: border-box;
}
html.app-phone body.app-library-open .chats-sidebar.open {
  position: fixed !important;
  transform: none !important;
  top: 50dvh !important;
  bottom: var(--studio-dock) !important;
  height: auto !important;
  display: flex !important;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  z-index: 97 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}
html.app-phone body.chat-page,
html.app-phone body.chat-page .app-wrapper,
html.app-phone body.account-page,
html.app-phone body.account-page .app-wrapper {
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
}
html.app-phone body.pricing-page {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
html.app-phone body[data-auth-standalone="1"] .app-wrapper {
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: border-box;
}
html.app-phone body.app-library-open #appLibraryBackdrop { display: block !important; }
html.app-phone #appMenuBtn { display: grid !important; }
html.app-phone #appLibraryTabs { display: none !important; }

html.app-phone:has(#stage-1.active .s1-home-workspace),
html.app-phone:has(#stage-1.active .s1-home-workspace) body {
  overflow: hidden !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
}
html.app-phone #stage-1.active:has(.s1-home-workspace) {
  overflow: hidden !important;
  padding: 0 !important;
  height: 100% !important;
}
html.app-phone #stage1-flow:has(.s1-home-workspace) {
  max-width: none;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  justify-content: flex-start;
}
html.app-phone .s1-home-workspace {
  min-height: 0 !important;
  height: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
}

/* Phone-only style popover. Anchored above the Style button by s5-style-picker.js. */
html.app-phone #s5-style-picker.is-phone-pop:not([hidden]) {
  top: auto;
  right: auto;
  left: var(--s5-style-pop-left, 12px);
  bottom: var(--s5-style-pop-bottom, 140px);
  width: var(--s5-style-pop-width, 240px);
  height: auto;
  padding: 8px 8px 7px;
  gap: 6px;
  border-radius: 18px;
  z-index: 120;
  overflow: visible;
  background: rgba(18, 18, 20, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}
html.app-phone #s5-style-picker.is-phone-pop:not([hidden])::after {
  content: "";
  position: absolute;
  left: var(--s5-style-pop-arrow, 24px);
  bottom: -5px;
  width: 10px;
  height: 10px;
  background: rgba(18, 18, 20, 0.96);
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  transform: rotate(45deg);
}
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-search-wrap svg {
  left: 9px;
  width: 13px;
  height: 13px;
}
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-search {
  height: 32px;
  padding: 0 10px 0 28px;
  border-radius: 10px;
  font-size: 12px;
}
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-tabs {
  gap: 4px;
}
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-tabs button,
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-tabs button:hover,
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-tabs button:active {
  height: 26px;
  border-radius: 8px;
  font-size: 11px;
}
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px 5px;
  padding: 1px 1px 2px;
  min-height: 0;
  max-height: min(168px, calc(var(--s5-style-pop-max, 280px) - 108px));
  overflow-y: auto;
}
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-tile,
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-tile:hover,
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-tile:focus,
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-tile:active {
  gap: 3px;
  padding: 0;
  border-radius: 8px;
}
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-cover {
  border-radius: 9px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.28);
}
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-fallback {
  font-size: 15px;
}
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-name {
  font-size: 9px;
  line-height: 1.15;
}
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-drop,
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-drop:hover,
html.app-phone #s5-style-picker.is-phone-pop .s5-style-picker-drop:active {
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 11px;
}

/* Movie Maker phone: idea, story, concept, timeline only. */
html.app-phone body.studio-app #ideas-container {
  top: calc(var(--phone-header, 96px) + 6px) !important;
  right: 0 !important;
  bottom: calc(var(--studio-dock) + var(--mm-composer, 168px) + 8px) !important;
  left: 0 !important;
  width: auto !important;
  padding: 8px 12px 24px;
  box-sizing: border-box;
  scroll-padding-bottom: 24px;
  overscroll-behavior: contain;
}

html.app-phone #chatBar .bottom-toolbar {
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  overflow: visible;
}
html.app-phone #chatBar .toolbar-left,
html.app-phone #chatBar .toolbar-right {
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: 6px !important;
  min-width: 0;
  width: auto;
}
html.app-phone #chatBar .toolbar-right { justify-content: flex-end; }
html.app-phone #chatBar .setting-pill,
html.app-phone #chatBar .view-toggle-btn,
html.app-phone #chatBar .smp-trigger {
  flex: 0 0 auto;
}
html.app-phone #chatBar .smp-trigger { max-width: 128px; }
html.app-phone #chatBar .smp-trigger-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.app-phone #menu-lang.show,
html.app-phone #menu-genre.show {
  position: fixed !important;
  left: 12px !important;
  right: 12px !important;
  width: auto !important;
  min-width: 0 !important;
  bottom: calc(var(--studio-dock) + var(--mm-composer, 168px) + 8px) !important;
  top: auto !important;
  transform: none !important;
  max-height: min(52dvh, calc(100dvh - var(--studio-dock) - var(--mm-composer, 168px) - var(--phone-header, 96px) - 28px));
  z-index: 220;
  animation: none !important;
  overflow: hidden;
  box-sizing: border-box;
}
html.app-phone #menu-lang.show {
  display: flex !important;
  flex-direction: column;
  padding: 10px;
}
html.app-phone #menu-lang .search-box-wrapper { flex: 0 0 auto; }
html.app-phone #menu-lang .lang-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
html.app-phone #menu-genre.show {
  display: grid !important;
  grid-template-columns: 1fr 1fr;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

html.app-phone #s2-quill-toolbar.ql-toolbar.ql-snow {
  display: flex !important;
  flex-flow: row wrap;
  align-items: center;
  gap: 4px 2px;
  overflow: visible;
  padding: 6px 8px !important;
}
html.app-phone #s2-quill-toolbar .ql-formats {
  display: inline-flex !important;
  align-items: center;
  float: none !important;
  flex: 0 0 auto;
  margin-right: 8px !important;
}
html.app-phone #s2-quill-toolbar .ql-formats::after {
  display: none !important;
  content: none !important;
}
html.app-phone #s2-quill-toolbar button,
html.app-phone #s2-quill-toolbar .ql-picker {
  float: none !important;
}
html.app-phone #s2-quill-toolbar .ql-toolbar button,
html.app-phone #s2-quill-toolbar.ql-toolbar button {
  width: 30px;
  height: 30px;
  padding: 4px;
}
html.app-phone #s2-quill-toolbar .ql-snow .ql-picker.ql-font,
html.app-phone #s2-quill-toolbar.ql-snow .ql-picker.ql-font { width: 92px; }
html.app-phone #s2-quill-toolbar .ql-snow .ql-picker.ql-size,
html.app-phone #s2-quill-toolbar.ql-snow .ql-picker.ql-size { width: 54px; }
html.app-phone #stage-2 .s2-phone-align {
  position: relative;
  display: inline-flex;
  align-items: center;
}
html.app-phone #stage-2 .s2-phone-align-btn {
  width: 30px;
  height: 30px;
  padding: 4px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
html.app-phone #stage-2 .s2-phone-align-btn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.12);
}
html.app-phone #stage-2 .s2-phone-align-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 12px;
  background: #1c1c1e;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
  z-index: 40;
}
html.app-phone #stage-2 .s2-phone-align-menu[hidden] { display: none !important; }
html.app-phone #stage-2 .s2-phone-align-menu button { float: none !important; }

html.app-phone #stage-3 .style-header {
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 44px;
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  touch-action: pan-x;
  z-index: 8;
}
html.app-phone #stage-3 .style-header::-webkit-scrollbar { display: none; }
html.app-phone #stage-3 .s3-header-actions {
  position: static !important;
  right: auto !important;
  top: auto !important;
  transform: none !important;
  width: auto;
  flex: 0 0 auto;
  order: 2;
  justify-content: flex-start;
  flex-wrap: nowrap;
  overflow: visible;
  gap: 6px;
}
html.app-phone #stage-3 #s3-image-gen-wrap {
  position: static !important;
  left: auto !important;
  top: auto !important;
  transform: none !important;
  order: 1;
  width: auto;
  max-width: none;
  flex: 0 0 auto;
  box-sizing: border-box;
}
html.app-phone #stage-3 #s3-image-model-btn {
  min-width: 0;
  flex: 1 1 auto;
}
html.app-phone #stage-3 #s3-image-model-label,
html.app-phone #stage-3 #s3-generate-images-btn {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
html.app-phone #stage-3 #s3-image-model-label { max-width: 38vw; }
html.app-phone #stage-3 .style-section-wrapper {
  max-width: none;
  padding: 6px 0 10px;
  justify-content: flex-start;
  box-sizing: border-box;
  overflow: auto;
}
html.app-phone #stage-3 .style-content,
html.app-phone #stage-3 .s3-style-dock { width: 100%; min-width: 0; }
html.app-phone #stage-3 .s3-style-dock,
html.app-phone #stage-3 .s3-style-dock.is-two-rows {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 10px;
}
html.app-phone #stage-3 .s3-style-rail {
  max-width: calc(100% - 72px);
  width: auto;
  flex: 1 1 auto;
}
html.app-phone #stage-3 .s3-style-add {
  align-self: flex-end;
  margin: 0 0 8px;
}
html.app-phone #stage-3 .s3-extract-bar {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 12px;
  overflow: hidden;
}
html.app-phone #stage-3 .s3-extract-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.95fr);
  gap: 8px;
  max-width: 100%;
}
html.app-phone #stage-3 .s3-extract-settings,
html.app-phone #stage-3 .s3-extract-types,
html.app-phone #stage-3 .s3-field,
html.app-phone #stage-3 .vision-checkbox-row {
  min-width: 0;
  max-width: 100%;
}
html.app-phone #stage-3 .s3-field {
  gap: 6px;
  padding: 6px 8px;
}
html.app-phone #stage-3 .s3-field > span {
  min-width: 0;
  flex: 1 1 auto;
}
html.app-phone #stage-3 .vision-select {
  min-width: 0;
  width: auto;
  flex: 0 1 74px;
  max-width: 46%;
  padding: 6px 4px;
}

html.app-phone body.studio-app:has(#stage-5.active:not(.s5-gallery-mode)) .stages-container,
html.app-phone #stage-5.active:not(.s5-gallery-mode) {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
html.app-phone #stage-5.active:not(.s5-gallery-mode) .s5-preview-area {
  max-height: none;
  height: auto !important;
  flex: 1 1 auto !important;
}
html.app-phone #stage-5.active:not(.s5-gallery-mode) .s5-settings-panel:not(.is-phone-prompt-open):not(.is-agent-tab) {
  max-height: 46dvh !important;
}
html.app-phone #stage-5.active:not(.s5-gallery-mode) .s5-timeline-layout {
  flex: 0 0 156px !important;
  min-height: 156px !important;
  max-height: 156px !important;
  height: 156px !important;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
html.app-phone #stage-5:not(.s5-gallery-mode) .s5-timeline-tracks-scroll {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
  overflow-x: clip;
  overflow-y: auto;
  flex-wrap: wrap;
  align-content: flex-start;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
html.app-phone #stage-5:not(.s5-gallery-mode) .s5-timeline-container {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
  touch-action: pan-x pan-y;
}
html.app-phone #stage-5:not(.s5-gallery-mode) .s5-clip,
html.app-phone #stage-5:not(.s5-gallery-mode) .s5-audio-block,
html.app-phone #stage-5:not(.s5-gallery-mode) .s5-trim-handle,
html.app-phone #stage-5:not(.s5-gallery-mode) .s5-audio-trim-handle {
  touch-action: none;
}
html.app-phone.is-tl-clip-drag,
html.app-phone.is-tl-clip-drag body {
  overflow: hidden !important;
  overscroll-behavior: none;
}
html.app-phone.is-tl-clip-drag #stage-5 .s5-timeline-container,
html.app-phone.is-tl-clip-drag #stage-5 .s5-timeline-tracks-scroll {
  touch-action: none;
}

/* Phone app bar: one row. Stage names and Generate scroll together. */
html.app-phone #mainHeader .profile-btn {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
}
html.app-phone #mainHeader .profile-btn > svg:not(.profile-credit-ring) {
  width: 16px;
  height: 16px;
}
html.app-phone #mainHeader button,
html.app-phone #mainHeader .profile-btn {
  transform: none;
}
html.app-phone #mainHeader button:hover,
html.app-phone #mainHeader button:active,
html.app-phone #mainHeader .profile-btn:hover {
  transform: none;
}
html.app-phone body.studio-app header#mainHeader:not(:has(.pipeline.show-pipeline)) .header-brand,
html.app-phone body.studio-app header#mainHeader:not(:has(.pipeline.show-pipeline)) .logo {
  display: none;
}
html.app-phone body.studio-app header#mainHeader:not(:has(.pipeline.show-pipeline)) .header-right {
  margin-left: auto;
}

html.app-phone body.studio-app header#mainHeader:has(.pipeline.show-pipeline) .phone-header-lead {
  order: 1;
}
html.app-phone body.studio-app header#mainHeader:has(.pipeline.show-pipeline) .project-title {
  order: 2;
  display: flex;
}
html.app-phone body.studio-app header#mainHeader:has(.pipeline.show-pipeline) .header-brand {
  display: none;
}
html.app-phone body.studio-app header#mainHeader:has(.pipeline.show-pipeline) .header-right {
  order: 4;
  margin-left: 0;
}
html.app-phone body.studio-app header#mainHeader:has(.pipeline.show-pipeline) .logo {
  display: none;
}
html.app-phone body.studio-app header#mainHeader:has(.pipeline.show-pipeline) .phone-header-lead .studio-rail-btn[data-rail="movie"] {
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  gap: 0;
  border-radius: 12px;
}
html.app-phone body.studio-app header#mainHeader:has(.pipeline.show-pipeline) .phone-header-lead .studio-rail-btn[data-rail="movie"] span {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
html.app-phone #main-pipeline {
  clip-path: inset(0 var(--phone-clip-r, 0px) 0 var(--phone-clip-l, 0px));
}

@media (max-width: 380px) {
  html.app-phone body.studio-app header .phone-header-lead .studio-rail-btn[data-rail="movie"] {
    width: 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
    gap: 0;
    border-radius: 12px;
  }
  html.app-phone body.studio-app header .phone-header-lead .studio-rail-btn[data-rail="movie"] span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

html.app-phone #stage-5 .s5-settings-panel .s5-tabs,
html.app-phone #stage-5.active .s5-tabs,
html.app-phone #stage-5.active:not(.s5-gallery-mode) .s5-tabs,
html.app-phone #stage-5.s5-gallery-mode .s5-tabs,
html.app-phone #stage-5.is-phone-collapsed .s5-tabs,
html.app-phone body.ai-generate-mode #stage-5 .s5-tabs,
html:not(.app-phone) #stage-5 .s5-settings-panel .s5-tabs,
html:not(.app-phone) #stage-5 .s5-dock > .s5-tabs,
.s5-settings-panel > .s5-dock > .s5-tabs {
  display: none !important;
}

html.app-phone body.studio-agent-left .s5-settings-panel {
  display: flex !important;
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: calc(var(--studio-dock) + var(--keyboard-inset, 0px)) !important;
  top: auto !important;
  width: auto !important;
  height: min(78dvh, 720px) !important;
  max-height: min(78dvh, 720px) !important;
  z-index: 75;
  margin: 0 !important;
  padding: 10px 12px 12px;
  overflow: hidden;
  border-radius: 18px 18px 0 0 !important;
  background: #141414 !important;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  transition: transform 0.34s cubic-bezier(0.32, 0.72, 0, 1);
}

html.app-phone #stage-5.active .s5-settings-panel.is-agent-tab {
  transition: transform 0.34s cubic-bezier(0.32, 0.72, 0, 1);
}
html.app-phone body.studio-agent-left .s5-settings-panel.is-phone-agent-closing,
html.app-phone #stage-5.active .s5-settings-panel.is-agent-tab.is-phone-agent-closing {
  transform: translateY(120%) !important;
  pointer-events: none !important;
}
html.app-phone .s5-settings-panel.is-agent-tab #s5-phone-sheet-toggle {
  display: none !important;
}
html.app-phone .s5-settings-panel.is-agent-tab .studio-agent-panel.is-docked .studio-agent-collapse {
  display: inline-flex !important;
}
html.app-phone .s5-settings-panel.is-agent-tab .studio-agent-panel.is-docked .studio-agent-collapse svg {
  transform: rotate(90deg);
}
html.app-phone .s5-settings-panel.is-agent-tab .studio-agent-header {
  padding-right: 8px;
}
@media (prefers-reduced-motion: reduce) {
  html.app-phone body.studio-agent-left .s5-settings-panel,
  html.app-phone #stage-5.active .s5-settings-panel.is-agent-tab {
    transition: none;
  }
}

html.app-phone body.studio-agent-left .s5-settings-panel > .s5-panel-handle-slot,
html.app-phone body.studio-agent-left .s5-settings-panel .s5-panel-drag-handle,
html.app-phone body.studio-agent-left .s5-settings-panel #s5-phone-sheet-toggle {
  display: none !important;
}
html.app-phone body.studio-agent-left .s5-settings-panel.is-agent-tab .studio-agent-header {
  padding-right: 0;
}
html.app-phone body.studio-agent-left .studio-agent-panel.is-docked .studio-agent-collapse {
  display: inline-flex !important;
}

html.app-phone #stage-5 .s5-play-overlay {
  inset: auto;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  font-size: 16px;
  line-height: 44px;
  text-align: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  text-shadow: none;
  opacity: 1;
}
html.app-phone #stage-5 .s5-preview-area.is-playing .s5-play-overlay,
html.app-phone #stage-5 .s5-preview-area.is-playing.s5-show-play-chrome .s5-play-overlay {
  opacity: 0;
}

/* ===== Studio Agent composer — mobile multiline =====
   When the prompt wraps to 2+ lines, .is-multiline (toggled in
   studio-agent.js) reuses the desktop grid so the input spans the full
   width on top and the buttons sit along the bottom edge. */
html.app-phone .studio-agent-form.is-multiline .studio-agent-form-row {
  align-items: stretch;
  row-gap: 6px;
}
html.app-phone .studio-agent-form.is-multiline textarea.studio-agent-input {
  width: 100% !important;
  max-height: 30dvh !important;
  padding: 6px 8px 10px !important;
  align-self: stretch;
}
html.app-phone .studio-agent-form.is-multiline .studio-agent-expand {
  display: none !important;
}
html.app-phone .studio-agent-form.is-multiline .studio-agent-plus,
html.app-phone .studio-agent-form.is-multiline .studio-agent-form-actions {
  align-self: end;
}
