/* 秒创AI 手机端 UI 优化层
   只覆盖 <=720px 的布局与触控体验，不改任何功能逻辑、ID、表单字段或事件绑定。 */
@media (max-width: 720px) {
  :root {
    --mobile-nav-height: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
  }

  main {
    padding: 18px max(14px, env(safe-area-inset-left, 0px)) calc(30px + env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-right, 0px));
  }

  .topbar {
    height: calc(58px + env(safe-area-inset-top, 0px));
    min-height: calc(58px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) max(12px, env(safe-area-inset-left, 0px)) 0 max(12px, env(safe-area-inset-right, 0px));
    gap: 8px;
  }

  .brand {
    min-height: 44px;
  }

  .top-actions {
    gap: 8px;
  }

  .credits-pill,
  .account-button,
  .outline-button.compact,
  .primary-button.compact {
    min-height: 44px;
  }

  .credits-pill {
    padding-top: 0;
    padding-bottom: 0;
  }

  .credits-pill b {
    flex: 0 0 22px;
  }

  .mobile-nav {
    height: var(--mobile-nav-height);
    min-height: var(--mobile-nav-height);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mobile-nav button {
    min-height: 56px;
    font-size: 11px;
    line-height: 1.1;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-nav button span {
    font-size: 20px;
    line-height: 1;
  }

  .icon-button {
    min-width: 44px;
    min-height: 44px;
  }

  .toast {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 28px);
    text-align: center;
  }

  /* 手机端弹窗改为底部抽屉，避免键盘弹出后看不到输入框和操作按钮。 */
  .modal {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: none;
    max-height: 92vh;
    max-height: min(92dvh, 760px);
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 22px 22px 0 0;
    padding: 24px 16px calc(20px + env(safe-area-inset-bottom, 0px));
    transform: none;
    animation: mobile-sheet-in .22s ease;
  }

  .modal-close {
    top: 12px;
    right: 12px;
  }

  .auth-tabs button {
    min-height: 44px;
  }

  .auth-form input,
  .field input,
  .field select,
  .field textarea,
  textarea,
  select {
    min-height: 46px;
    font-size: 16px;
  }

  .code-field {
    display: grid;
    grid-template-columns: 1fr;
  }

  .code-field button {
    width: 100%;
    min-height: 44px;
  }

  .rotate-slider {
    height: 44px;
  }

  .plan-grid button {
    min-height: 88px;
  }

  .account-balance {
    margin: 18px 0;
    padding: 16px;
  }

  .account-logout,
  .primary-button.full,
  .execution-account-modal .primary-button.full {
    min-height: 48px;
  }

  /* 未登录落地页 */
  .landing-grid {
    gap: 22px;
  }

  .landing-title {
    font-size: 30px;
    line-height: 1.18;
    letter-spacing: -.03em;
  }

  .landing-sub {
    font-size: 13px;
    line-height: 1.7;
  }

  .landing-auth-card {
    padding: 18px 16px;
    border-radius: 20px;
  }

  .landing-auth-card .auth-tabs {
    margin: 12px 0 14px;
  }

  .landing-auth-card .auth-form {
    gap: 11px;
  }

  .landing-auth-card .auth-form label {
    margin-bottom: 0;
  }

  .landing-showcase-head {
    align-items: center;
  }

  .landing-workflow-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .landing-workflow-card {
    border-radius: 14px;
  }

  .landing-workflow-card .workflow-cover {
    height: 76px;
    font-size: 24px;
  }

  .landing-workflow-meta {
    padding: 11px 11px 13px;
  }

  .landing-workflow-meta strong {
    display: -webkit-box;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .landing-workflow-meta p {
    display: -webkit-box;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.45;
    margin-bottom: 8px;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  /* 创作台：把“开始创作”移动到上传素材区正下方。 */
  .workbench-head {
    align-items: center;
    gap: 10px;
    min-height: 44px;
  }

  .workbench-head h1 {
    font-size: 28px;
  }

  .account-summary {
    flex: 0 0 auto;
  }

  .workspace-grid,
  .creator-card,
  .activity-card {
    min-width: 0;
    max-width: 100%;
  }

  .creator-card {
    display: flex;
    flex-direction: column;
    padding: 16px;
  }

  /* 【2026-10-17】移动端顺序修正：素材 → 开始创作 → 创作设置。
     旧写法 .submit-row:nth-of-type(7) 按 div 序号计数永远匹配不上，规则整批失效。
     flex 默认 order:0，故只需给按钮和设置块指定次序即可。 */
  .creator-card > .submit-row { order: 5; }
  .creator-card > #settingsBlock { order: 6; }

  .section-label {
    gap: 9px;
  }

  .section-label > div {
    min-width: 0;
  }

  .section-label b {
    font-size: 15px;
  }

  .section-label small {
    font-size: 11px;
    line-height: 1.45;
  }

  /* 手机端功能选择：双列紧凑卡片，全部功能一眼可见，不再横向翻找。 */
  .inline-workflow-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    max-width: 100%;
    min-width: 0;
    gap: 8px;
    overflow: visible;
    margin: 0 0 20px;
    padding: 0;
  }

  .inline-workflow-card {
    position: relative;
    min-width: 0;
    min-height: 58px;
    gap: 8px;
    padding: 8px 9px;
    border-radius: 12px;
  }

  .inline-workflow-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .inline-workflow-card.active::after {
    content: "✓";
    position: absolute;
    top: 5px;
    right: 7px;
    color: #159171;
    font-size: 11px;
    font-weight: 900;
    line-height: 1;
  }

  .inline-wf-cover {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 13px;
  }

  .inline-wf-meta {
    min-width: 0;
    flex: 1 1 auto;
  }

  .inline-wf-meta strong {
    display: block;
    overflow: hidden;
    font-size: 12.5px;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .inline-wf-meta small {
    overflow: hidden;
    font-size: 10px;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .inline-workflow-card em {
    display: none;
  }

  .upload-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    margin-bottom: 0;
  }

  .upload-card {
    min-height: 120px;
    padding: 10px 8px;
  }

  .upload-grid > .upload-card:only-child {
    grid-column: 1 / -1;
    min-height: 126px;
  }

  .upload-card .upload-preview {
    height: 110px;
  }

  .upload-card strong {
    font-size: 13px;
  }

  .upload-card small {
    font-size: 11px;
    line-height: 1.35;
  }

  .submit-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    margin: 14px 0 22px;
    padding: 12px;
    border: 1px solid #bfe9dc;
    border-radius: 16px;
    background: linear-gradient(135deg, #f1fbf7, #fff);
    box-shadow: 0 8px 20px rgba(33, 190, 149, .08);
  }

  .submit-row > div {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 6px;
    min-width: 0;
  }

  .submit-row > div > span {
    width: 100%;
  }

  .submit-row strong {
    font-size: 14px;
  }

  .submit-row strong b {
    font-size: 20px;
  }

  .submit-row small {
    width: 100%;
    font-size: 10px;
  }

  .submit-row .primary-button {
    min-height: 48px;
    padding: 12px 16px;
    white-space: nowrap;
  }

  .form-grid {
    gap: 11px;
  }

  .field {
    gap: 6px;
  }

  .switch-field,
  .range-field {
    min-height: 56px;
  }

  .activity-card {
    padding: 16px;
  }

  .aside-head {
    margin-bottom: 16px;
  }

  .aside-head h2 {
    font-size: 20px;
  }

  .aside-head button {
    min-height: 44px;
    padding: 0 4px;
  }

  .swap-all {
    min-height: 44px;
    padding: 8px 12px;
  }

  .task-download {
    min-height: 44px;
    padding: 8px 12px;
    font-size: 11px;
  }

  /* 作品中心 */
  .page-head {
    gap: 10px;
    margin-bottom: 18px;
  }

  .page-head h1 {
    font-size: 28px;
  }

  .page-head .primary-button.compact {
    min-height: 44px;
    padding: 10px 12px;
    white-space: nowrap;
  }

  .task-gallery {
    gap: 12px;
  }

  .result-card {
    border-radius: 16px;
  }

  .result-cover {
    height: 180px;
  }

  .result-card > div:last-child {
    padding: 12px 14px;
  }

  .result-card strong {
    font-size: 15px;
  }

  .result-card p {
    margin: 4px 0 9px;
    font-size: 12px;
  }

  .result-card footer time {
    font-size: 11px;
  }

  .result-download {
    min-height: 40px;
    padding: 8px 12px;
  }

  /* 邀请中心 */
  .invite-hero {
    padding: 20px 16px;
    border-radius: 20px;
  }

  .invite-hero h1 {
    font-size: 28px;
  }

  .invite-code {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 12px;
  }

  .invite-code > span {
    grid-column: 1 / -1;
  }

  .invite-code strong {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-all;
    font-size: 12px;
    line-height: 1.5;
  }

  .invite-code button {
    min-height: 44px;
    padding: 10px 12px;
    white-space: nowrap;
  }

  .reward-orbit {
    width: 116px;
    height: 116px;
    margin: 20px auto 0;
  }

  .reward-orbit strong {
    font-size: 28px;
  }

  .stats-grid {
    gap: 10px;
    margin-top: 16px;
  }

  .stats-grid > div {
    min-height: 100px;
    padding: 12px;
    border-radius: 16px;
  }

  /* 去水印 */
  .wm-card {
    padding: 16px;
    border-radius: 18px;
  }

  .wm-steps {
    gap: 6px;
    margin-bottom: 16px;
  }

  .wm-steps span {
    padding: 7px 9px;
  }

  .wm-drop {
    min-height: 156px;
    border-radius: 16px;
  }

  .wm-drop-icon {
    width: 46px;
    height: 46px;
  }

  .wm-note {
    line-height: 1.65;
  }

  .wm-mode {
    padding: 11px;
  }

  .wm-mode-opt {
    min-height: 48px;
    padding: 10px;
  }

  .wm-mode-opt input {
    width: 18px;
    height: 18px;
  }

  .wm-actions {
    gap: 9px;
  }

  .wm-actions button {
    min-height: 48px;
  }

  .wm-side {
    padding: 18px 16px;
    border-radius: 18px;
  }

  .wm-preview-tip {
    font-size: 12px;
    text-align: left;
  }

  .wm-result-video {
    max-width: 100%;
  }

  .wm-progress-text {
    flex-wrap: wrap;
    gap: 6px 10px;
  }

  /* 工作流抽屉 */
  .workflow-drawer {
    max-height: 92vh;
    max-height: 92dvh;
  }

  .workflow-select {
    min-height: 44px;
  }

  .drawer-filters button {
    min-height: 44px;
  }

  .workflow-list {
    gap: 8px;
  }

  .workflow-card {
    grid-template-columns: 54px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    min-height: 76px;
    padding: 9px;
  }

  .workflow-card .workflow-cover {
    width: 54px;
    height: 54px;
    border-radius: 11px;
    font-size: 20px;
  }

  .workflow-card .workflow-meta {
    min-width: 0;
    padding: 0;
  }

  .workflow-card .workflow-meta strong {
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workflow-card .workflow-meta > p {
    display: -webkit-box;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.4;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .workflow-card .workflow-select {
    grid-column: auto;
    width: auto;
    min-height: 40px;
    padding: 8px 10px;
  }
}

@keyframes mobile-sheet-in {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (min-width: 370px) and (max-width: 720px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stats-grid > div {
    min-height: 96px;
    padding: 12px 8px;
    text-align: center;
    align-items: center;
  }

  .stats-grid strong {
    font-size: 20px;
  }

  .stats-grid span,
  .stats-grid small {
    font-size: 10px;
    line-height: 1.35;
  }
}

@media (max-width: 360px) {
  .topbar {
    padding-left: 10px;
    padding-right: 10px;
  }

  .brand {
    gap: 8px;
  }

  .credits-pill {
    padding-left: 9px;
  }

  .credits-pill b {
    width: 20px;
    height: 20px;
  }

  .account-button {
    padding: 0 9px;
  }

  .landing-title {
    font-size: 27px;
  }

  .landing-workflow-grid {
    gap: 8px;
  }

  .landing-workflow-card .workflow-cover {
    height: 68px;
    font-size: 22px;
  }

  .landing-workflow-meta {
    padding: 10px 9px 12px;
  }

  .inline-workflow-card {
    min-height: 54px;
    padding: 7px 8px;
  }

  .inline-wf-cover {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }

  .submit-row {
    grid-template-columns: 1fr;
  }

  .submit-row .primary-button {
    width: 100%;
  }

  .wm-steps {
    display: grid;
    grid-template-columns: 1fr;
  }

  .wm-steps span {
    text-align: center;
  }

  .wm-result-head {
    display: block;
  }

  .page-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .invite-code {
    grid-template-columns: 1fr;
  }

  .invite-code button {
    width: 100%;
  }
}