/* Final shell sizing: fit the available viewport instead of clipping controls. */
html body.reference-ui-shell[data-studio-ui] #workspace {
  height: calc(100dvh - var(--studio-header-height, 72px)) !important;
  min-width: 0 !important;
  min-height: 0 !important;
}
html body.reference-ui-shell[data-studio-ui] #workspace > .works {
  min-width: 0 !important;
  min-height: 0 !important;
}
html body.reference-ui-shell[data-studio-ui] #topbar {
  box-sizing: border-box;
  max-width: 100%;
}
html body.reference-ui-shell[data-studio-ui] #topbar .brand {
  min-width: 0 !important;
}
html body.reference-ui-shell[data-studio-ui] #topbar .nav {
  min-width: 0 !important;
  mask-image: none !important;
}
html body.reference-ui-shell[data-studio-ui] #view-home .reference-recent-projects {
  grid-auto-flow: row !important;
  grid-auto-columns: auto !important;
  grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)) !important;
  grid-template-rows: none !important;
  overflow: visible !important;
  scroll-snap-type: none;
  cursor: default;
  touch-action: auto;
}
html body.reference-ui-shell[data-studio-ui] #view-home .reference-recent-projects > .reference-empty {
  grid-column: 1 / -1;
}
html body.reference-ui-shell[data-studio-ui][data-studio-layout-active=left] #workspace #creationComposer[data-reference-surface]:not([hidden]) {
  top: calc(var(--studio-header-height, 72px) + 16px) !important;
  height: calc(100dvh - var(--studio-header-height, 72px) - 32px) !important;
}
/* 2026-11-16: one header row on desktop. The two-row header (100px) left a
   1366x620 / 1456x680 window too little height: the audio editor had to be
   scrolled to reach "生成", and the works list showed one row of cards. The
   nav sits between brand and account controls and only wraps below 1280px. */
@media (min-width: 1280px) {
  html body.reference-ui-shell[data-studio-ui] #topbar[style*="display: flex"] {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: 56px;
    align-items: center;
    height: 56px !important;
    min-height: 56px !important;
    padding: 0 clamp(12px, 1.6vw, 24px) !important;
    gap: 0 clamp(10px, 1.4vw, 24px) !important;
  }
  html body.reference-ui-shell[data-studio-ui] #topbar .brand { grid-column: 1; grid-row: 1; min-height: 0; }
  html body.reference-ui-shell[data-studio-ui] #topbar .brand-copy small { display: none !important; }
  html body.reference-ui-shell[data-studio-ui] #topbar .nav {
    display: flex !important;
    grid-column: 2;
    grid-row: 1;
    justify-content: center;
    flex-wrap: nowrap;
    width: auto !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    gap: 2px !important;
    overflow: hidden !important;
  }
  html body.reference-ui-shell[data-studio-ui] #topbar .nav button {
    flex: 0 1 auto !important;
    min-width: 0 !important;
    padding: 0 clamp(7px, 0.75vw, 16px) !important;
    height: 36px !important;
    white-space: nowrap;
  }
  html body.reference-ui-shell[data-studio-ui] #topbar .userbar {
    grid-column: 3;
    grid-row: 1;
    width: auto !important;
    margin: 0 !important;
    justify-self: end;
    gap: 6px !important;
    flex-wrap: nowrap;
  }
}
/* Admin accounts carry two more buttons; keep the nav labels whole. */
@media (min-width: 1280px) and (max-width: 1499px) {
  html body.reference-ui-shell[data-studio-ui] #topbar #studioLayoutToggle { padding-inline: 8px !important; }
  html body.reference-ui-shell[data-studio-ui] #topbar #studioLayoutToggle > span,
  html body.reference-ui-shell[data-studio-ui] #topbar #quotaAction { display: none !important; }
}
@media (max-width: 1279px) {

  html body.reference-ui-shell[data-studio-ui] #topbar[style*="display: flex"] {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    height: auto !important;
    min-height: 100px !important;
    padding: 8px clamp(12px, 2vw, 24px) !important;
    gap: 4px 12px !important;
  }
  html body.reference-ui-shell[data-studio-ui] #topbar .brand {
    grid-column: 1;
    grid-row: 1;
    min-height: 36px;
  }
  html body.reference-ui-shell[data-studio-ui] #topbar .userbar {
    grid-column: 2;
    grid-row: 1;
    width: auto !important;
    margin: 0 !important;
    justify-self: end;
    gap: 6px !important;
  }
  html body.reference-ui-shell[data-studio-ui] #topbar .nav {
    display: flex !important;
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    gap: 4px !important;
    flex-wrap: wrap;
    overflow: visible !important;
  }
  html body.reference-ui-shell[data-studio-ui] #topbar .nav button {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    padding: 0 10px !important;
    height: 36px !important;
    white-space: nowrap;
  }
}
@media (max-width: 640px) {
  html body.reference-ui-shell[data-studio-ui] #topbar[style*="display: flex"] {
    padding: 8px 12px !important;
    gap: 4px 8px !important;
  }
  html body.reference-ui-shell[data-studio-ui] #topbar .brand-copy { display: none !important; }
  html body.reference-ui-shell[data-studio-ui] #topbar .nav {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px !important;
  }
  html body.reference-ui-shell[data-studio-ui] #topbar .nav button {
    width: 100%;
    padding: 0 3px !important;
    font-size: 12px !important;
    height: 34px !important;
  }
  html body.reference-ui-shell[data-studio-ui] #view-home {
    padding-inline: 14px !important;
  }
  html body.reference-ui-shell[data-studio-ui] :is(.casting-dialog, .canvas-dialog) {
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - 24px) !important;
  }
}
@media (max-width: 359px) {
  html body.reference-ui-shell[data-studio-ui] #topbar .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
