.mobile-topbar,
.mobile-menu-backdrop,
.mobile-menu-close {
  display: none;
}

.sidebar-head {
  display: block;
}

@media (max-width: 900px) {
  body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

  body.mobile-menu-open {
    overflow: hidden;
  }

  button,
  .button {
    min-height: 44px;
    touch-action: manipulation;
  }

  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 64px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    border-bottom: 1px solid var(--line);
    background: rgba(5, 10, 17, .96);
    box-shadow: 0 10px 28px rgba(0, 0, 0, .3);
  }

  .mobile-topbar > strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-menu-button {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 44px;
    padding: 9px 12px;
  }

  .mobile-menu-icon {
    display: grid;
    gap: 4px;
    width: 20px;
  }

  .mobile-menu-icon i {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 99px;
    background: currentColor;
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(0, 0, 0, .64);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }

  body.mobile-menu-open .mobile-menu-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  aside#studioSidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 70;
    display: flex;
    width: min(86vw, 320px);
    height: 100vh;
    height: 100dvh;
    padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: 1px solid var(--line);
    background: #050a11;
    box-shadow: 18px 0 48px rgba(0, 0, 0, .48);
    transform: translateX(-105%);
    transition: transform .22s ease;
    -webkit-overflow-scrolling: touch;
  }

  body.mobile-menu-open aside#studioSidebar {
    transform: translateX(0);
  }

  .sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .brand-lockup {
    min-width: 0;
  }

  .brand-lockup strong,
  .brand-lockup span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-menu-close {
    display: grid;
    flex: 0 0 44px;
    width: 44px;
    min-height: 44px;
    padding: 0;
    place-items: center;
    font-size: 27px;
    line-height: 1;
  }

  aside#studioSidebar .channel-card {
    display: flex;
    margin-top: 0;
  }

  aside#studioSidebar nav {
    display: grid;
    gap: 7px;
    margin: 0;
  }

  aside#studioSidebar nav button {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    font-size: 1rem;
    text-align: left;
  }

  aside#studioSidebar nav button::after {
    content: none;
  }

  aside#studioSidebar .sidebar-foot {
    display: grid;
    gap: 8px;
    margin-top: auto;
    padding-top: 12px;
  }

  main#studioMain {
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 22px 20px 30px;
  }

  header {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
  }

  .pill {
    display: inline-flex;
  }

  .grid.three,
  .grid.two,
  .package-workspace,
  .package-actions,
  .asset-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .package-workspace,
  .package-workspace .panel {
    min-width: 0;
  }

  .asset-row > *,
  .actions select {
    min-width: 0;
    max-width: 100%;
  }

  .results-panel {
    min-height: 0;
  }

  .site-footer {
    margin-left: 0;
  }
}

@media (max-width: 640px) {
  main#studioMain {
    padding: 16px 14px 26px;
  }

  .mobile-topbar {
    min-height: 58px;
    padding-right: 12px;
    padding-left: 12px;
  }

  .mobile-topbar > strong {
    font-size: .9rem;
  }

  header {
    display: grid;
    margin-bottom: 20px;
  }

  h1 {
    font-size: clamp(24px, 8vw, 31px);
    line-height: 1.16;
  }

  h2 {
    font-size: clamp(22px, 7vw, 27px);
    line-height: 1.2;
  }

  h3 {
    line-height: 1.25;
  }

  .panel,
  .stat,
  .plan-card {
    min-width: 0;
    padding: 18px;
    border-radius: 15px;
  }

  .hero {
    min-height: 0;
    padding: 24px 18px;
  }

  input,
  textarea,
  select {
    min-width: 0;
    max-width: 100%;
    font-size: 16px;
  }

  input,
  select {
    min-height: 48px;
  }

  textarea {
    min-height: 120px;
  }

  .idea {
    min-height: 180px;
    font-size: 16px;
  }

  button,
  .button {
    min-height: 46px;
  }

  .actions {
    align-items: stretch;
  }

  .actions > button,
  .actions > .button,
  .actions > select {
    width: 100%;
    min-width: 0;
    text-align: center;
  }

  .onboarding > #startButton {
    width: 100%;
  }

  .auth-tabs {
    align-items: stretch;
  }

  .auth-tabs button {
    flex: 1 1 0;
  }

  .auth-actions .quiet {
    padding: 10px 12px;
  }

  .legal-check input,
  .check input {
    flex: 0 0 20px;
    width: 20px;
    min-height: 20px;
  }

  .history-item {
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
  }

  .history-item > button {
    width: 100%;
  }

  .revision {
    display: grid;
    align-items: stretch;
  }

  .revision button {
    width: 100%;
  }

  .thumbnail-controls,
  .thumbnail-gallery,
  .finished-thumbnail-gallery,
  .grid.four,
  .admin-facts,
  .admin-access-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .thumbnail-card,
  .finished-thumbnail-card,
  .output,
  .compact {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .title-output {
    font-size: 18px;
  }

  .pre {
    word-break: break-word;
  }

  .gallery-empty {
    padding: 32px 16px;
  }

  .admin-card-head,
  .admin-section-head,
  .admin-access-row {
    display: grid;
    align-items: stretch;
  }

  .admin-status {
    justify-self: start;
  }

  .admin-actions > button,
  .admin-actions > .button,
  .admin-access-row > button {
    width: 100%;
    min-height: 46px;
  }

  .admin-protected {
    width: 100%;
  }

  .site-footer {
    flex-wrap: wrap;
    padding: 8px 14px 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  aside#studioSidebar,
  .mobile-menu-backdrop {
    transition: none;
  }
}
