/* Mobile adaptation layer for the built PCAI H5 package. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body,
uni-page-body {
  min-width: 0;
  overflow-x: hidden;
}

img,
uni-image,
video,
canvas {
  max-width: 100%;
}

uni-button,
button,
a,
[role="button"],
.nav-item,
.app-card,
.tool-item,
.tag-pill,
.holiday-pill,
.gen-count-pill {
  touch-action: manipulation;
}

input,
textarea,
select,
uni-input,
uni-textarea {
  max-width: 100%;
}

.home-page .gallery-card {
  position: relative;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 1.25rem;
}

.home-page .gallery-card .image-wrap {
  position: relative;
  width: 100%;
  padding-bottom: 148%;
  overflow: hidden;
  background: #1e293b;
}

.home-page .gallery-card .image-cover,
.home-page .gallery-card uni-image.image-cover,
.home-page .gallery-card uni-image.image-cover img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.home-page .gallery-card .card-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
}

.home-page .gallery-card .card-info {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1rem 0.875rem 0.875rem;
  background: linear-gradient(to top, rgba(15, 23, 42, 0.92), transparent);
}

.home-page .gallery-card .card-title {
  display: block;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media screen and (max-width: 960px) {
  :root {
    --pcai-mobile-nav-h: calc(3.75rem + env(safe-area-inset-bottom));
    --pcai-mobile-pad-x: clamp(0.875rem, 4vw, 1.125rem);
  }

  html,
  body,
  #app,
  uni-app,
  uni-page,
  uni-page-wrapper,
  uni-page-body {
    min-height: 100%;
    height: auto;
    overflow-x: hidden;
  }

  body {
    overscroll-behavior-y: contain;
  }

  .pcai-home-brand-logo {
    width: 30px;
    height: 30px;
    border-radius: 7px;
  }

  .pcai-home-brand-logo-wrap {
    gap: 8px;
    max-width: 100%;
    line-height: 1.15;
  }

  .sidebar {
    padding-bottom: env(safe-area-inset-bottom) !important;
  }

  .sidebar-inner {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .sidebar-inner::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    min-width: 3.25rem;
    min-height: 3.75rem;
  }

  .nav-label {
    max-width: 3.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .home-page,
  .create-page,
  .holiday-page,
  .reposter-page,
  .interior-uni-page,
  .employee-photo-page,
  .viral-page,
  [class$="-page"] {
    min-height: 100vh;
    height: auto !important;
    overflow: visible !important;
  }

  .content-wrap {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    padding: calc(0.875rem + env(safe-area-inset-top)) var(--pcai-mobile-pad-x) calc(var(--pcai-mobile-nav-h) + 1.25rem) !important;
    box-sizing: border-box !important;
  }

  .hero,
  .section-head,
  .stage-header,
  .header-actions,
  .hero-actions {
    min-width: 0;
  }

  .hero {
    align-items: flex-start !important;
    gap: 0.75rem !important;
  }

  .hero-copy,
  .section-head-main {
    min-width: 0;
    width: 100%;
  }

  .hero-title {
    font-size: clamp(1.45rem, 8vw, 2rem) !important;
    line-height: 1.08 !important;
    word-break: keep-all;
    overflow-wrap: anywhere;
  }

  .hero-subtitle,
  .gallery-hint,
  .apps-empty-desc {
    line-height: 1.55 !important;
  }

  .hero-actions,
  .hero-actions--logged-in {
    width: 100%;
    margin-left: 0 !important;
  }

  .hero-actions > *,
  .hero-actions--logged-in > * {
    min-height: 2.5rem;
  }

  .points-box {
    max-width: 100%;
  }

  .app-filter-bar {
    display: flex !important;
    gap: 0.5rem !important;
    margin-left: calc(var(--pcai-mobile-pad-x) * -1);
    margin-right: calc(var(--pcai-mobile-pad-x) * -1);
    padding: 0 var(--pcai-mobile-pad-x) 0.25rem !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .app-filter-bar::-webkit-scrollbar {
    display: none;
  }

  .app-filter-item {
    flex: 0 0 auto;
    min-height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }

  .app-grid,
  .gallery-grid {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
  }

  .gallery-grid {
    gap: 0.625rem !important;
  }

  .gallery-card {
    border-radius: 0.75rem !important;
  }

  .gallery-card .image-wrap {
    position: relative !important;
    padding-bottom: 100% !important;
  }

  .gallery-card .image-cover,
  .gallery-card uni-image.image-cover,
  .gallery-card uni-image.image-cover img {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
  }

  .gallery-card .card-info {
    position: absolute !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    padding: 0.5rem 0.4375rem 0.4375rem !important;
  }

  .gallery-card .card-title {
    font-size: 0.75rem !important;
    margin-bottom: 0.25rem !important;
  }

  .gallery-card .card-meta {
    font-size: 0.625rem !important;
  }

  .gallery-card .card-overlay {
    display: none !important;
  }

  .app-card,
  .gallery-card {
    min-width: 0 !important;
    border-radius: 0.75rem !important;
  }

  .app-card *,
  .gallery-card * {
    max-width: 100%;
  }

  .main-container,
  .workspace {
    width: 100% !important;
    margin-left: 0 !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: 100vh !important;
    overflow: visible !important;
    padding-bottom: var(--pcai-mobile-nav-h);
    box-sizing: border-box;
  }

  .control-panel,
  .form-column {
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    border-right: 0 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
    overflow: visible !important;
  }

  .panel-inner,
  .form-inner {
    width: 100% !important;
    max-width: 100% !important;
    padding: calc(0.875rem + env(safe-area-inset-top)) var(--pcai-mobile-pad-x) 1.25rem !important;
    box-sizing: border-box !important;
  }

  .viewport,
  .result-column {
    width: 100% !important;
    min-height: 48vh !important;
    height: auto !important;
    overflow: visible !important;
  }

  .stage-header {
    height: auto !important;
    min-height: 3rem;
    padding: 0.75rem var(--pcai-mobile-pad-x) !important;
    gap: 0.625rem !important;
    flex-wrap: wrap !important;
  }

  .task-id {
    max-width: 100%;
    word-break: break-all;
  }

  .stage {
    min-height: 18rem !important;
    height: auto !important;
    padding: 0.875rem var(--pcai-mobile-pad-x) 1.25rem !important;
    overflow: visible !important;
  }

  .preview-empty,
  .empty-stage,
  .error-stage,
  .gen-loading {
    max-width: 100% !important;
  }

  .result-box,
  .image-frame {
    min-height: 18rem !important;
    max-height: none !important;
  }

  .main-img,
  .upload-preview,
  .gallery-img,
  .history-thumb {
    object-fit: contain !important;
  }

  .img-toolbar {
    width: calc(100% - 1rem) !important;
    max-width: 100%;
    margin: 0.75rem auto 0 !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
  }

  .tool-group {
    flex-wrap: wrap !important;
    justify-content: center !important;
  }

  .tool-divider {
    display: none !important;
  }

  .tool-item,
  .ghost-mini,
  .pill-extract,
  .preset-link,
  .inspire-link {
    min-height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .tag-grid,
  .select-grid,
  .module-grid,
  .quick-tips {
    grid-template-columns: 1fr 1fr !important;
  }

  .upload-box,
  .upload-card {
    min-height: 8.5rem !important;
  }

  .submit-btn,
  .gen-btn,
  .mobile-gen-btn,
  .retry-btn,
  uni-button {
    min-height: 2.75rem;
  }

  .mobile-action-bar {
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom)) !important;
  }

  .history-bar {
    height: auto !important;
    max-height: 9rem;
  }

  .history-modal-mask {
    align-items: flex-end !important;
    padding: 0.75rem !important;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom)) !important;
  }

  .history-modal {
    max-height: 82vh !important;
    border-radius: 0.875rem !important;
  }

  .profile-overlay {
    align-items: flex-end !important;
  }

  .profile-sheet {
    width: min(100%, 24rem) !important;
    height: auto !important;
    min-height: unset !important;
    max-height: calc(100dvh - 1rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    border-radius: 1rem 1rem 0 0 !important;
  }
}

@media screen and (max-width: 520px) {
  .content-wrap {
    padding-left: 0.875rem !important;
    padding-right: 0.875rem !important;
  }

  .app-grid {
    grid-template-columns: 1fr !important;
  }

  .gallery-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 0.5rem !important;
  }

  .tag-grid,
  .select-grid,
  .module-grid,
  .quick-tips,
  .gen-count-row {
    grid-template-columns: 1fr !important;
  }

  .section {
    margin-bottom: 1.25rem !important;
  }

  .section-head {
    margin-bottom: 0.75rem !important;
  }

  .hero-actions,
  .header-actions,
  .submit-row {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .hero-actions > *,
  .header-actions > *,
  .submit-row > *,
  .gen-count-pill {
    width: 100% !important;
  }

  .stage {
    min-height: 16rem !important;
  }

  .result-box,
  .image-frame {
    min-height: 16rem !important;
  }

  .pcai-home-brand-logo {
    width: 28px;
    height: 28px;
  }
}

/* Profile modal — fit all rows on desktop & mobile (built bundle uses fixed square) */
.profile-overlay {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.profile-sheet {
  width: min(100%, 22rem) !important;
  height: auto !important;
  min-height: unset !important;
  max-height: min(36rem, calc(100dvh - 1.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom))) !important;
}

.profile-sheet-inner {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

.profile-rows {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  justify-content: flex-start !important;
}

.profile-row {
  padding: 0.5625rem 0 !important;
  flex-shrink: 0;
}

.profile-header,
.profile-loading,
.logout-btn {
  flex-shrink: 0;
}

.profile-row .row-value {
  max-width: 58%;
  text-align: right;
  line-height: 1.35;
  word-break: break-word;
}

.logout-btn {
  margin-top: 0.625rem !important;
}

.home-page .gallery-grid .gallery-card {
  content-visibility: auto;
  contain-intrinsic-size: 140px 160px;
}

/* 灵感画廊分页样式 */
.gallery-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem 0.5rem 0.5rem;
  flex-wrap: wrap;
}

.gallery-pagination .page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 1rem;
  background: #f0f4f8;
  border: 1px solid #d0dbe6;
  border-radius: 1.25rem;
  font-size: 0.8rem;
  color: #4a6fa5;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 2rem;
  line-height: 1;
}

.gallery-pagination .page-btn:active {
  background: #e0e8f0;
  transform: scale(0.97);
}

.gallery-pagination .page-info {
  font-size: 0.8rem;
  color: #6b7c93;
  padding: 0 0.25rem;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .gallery-pagination {
    gap: 0.5rem;
    padding: 0.875rem 0.25rem 0.25rem;
  }
  .gallery-pagination .page-btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
  }
  .gallery-pagination .page-info {
    font-size: 0.75rem;
  }
}
