/* ============================================
   换脸 + 超分工具 — 样式（单页版）
   风格参考 cv-bill-calculator（移动端优先、卡片式）
   ============================================ */

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --violet-700: #6d28d9;
  --violet-600: #7c3aed;
  --violet-50: #f5f3ff;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --red-500: #ef4444;
  --red-100: #fee2e2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,.07), 0 10px 15px rgba(0,0,0,.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
}

/* === Header（全出血延伸至顶部，规避灵动岛遮挡） === */
.app-header {
  background: linear-gradient(135deg, var(--violet-700), var(--violet-600));
  color: #fff;
  padding: calc(20px + env(safe-area-inset-top)) 16px 20px;
  padding-top: calc(20px + constant(safe-area-inset-top)); /* iOS 11 兼容 */
  margin: 0 -16px 20px;
  border-radius: 0 0 var(--radius) var(--radius);
  text-align: center;
  box-shadow: var(--shadow-lg);
  -webkit-tap-highlight-color: transparent;
}
.app-header h1 {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .5px;
}
.h1-title { white-space: nowrap; }
.app-version {
  font-size: .7rem;
  font-weight: 400;
  margin-left: 6px;
  color: rgba(255,255,255,.85);
  letter-spacing: .5px;
  text-align: left;
  white-space: nowrap;
}

/* === Card === */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--gray-700);
}

/* === 上传区 === */
.upload-grid {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.upload-slot { flex: 1; min-width: 0; }
.upload-arrow {
  align-self: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gray-300);
  padding-top: 22px;
}
.form-group-label {
  font-size: .85rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
  text-align: center;
}

.dropzone {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 150px;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  background: var(--gray-50);
  cursor: pointer;
  overflow: hidden;
  transition: border-color .2s, background .2s;
  -webkit-tap-highlight-color: transparent;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--violet-600);
  background: var(--violet-50);
}
.dropzone-empty { text-align: center; color: var(--gray-500); }
.dropzone-icon { font-size: 1.6rem; margin-bottom: 4px; }
.dropzone-text { font-size: .78rem; line-height: 1.4; }
.dropzone-preview {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
}
.dropzone-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  line-height: 22px;
  text-align: center;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .85rem;
  cursor: pointer;
  z-index: 2;
}

.hint {
  margin-top: 12px;
  font-size: .78rem;
  color: var(--gray-500);
  text-align: center;
}

/* === 按钮 === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--violet-600), var(--violet-700));
  color: #fff;
  box-shadow: var(--shadow);
}
.btn-primary:hover { opacity: .92; }
.btn-primary:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
}
.btn-outline {
  background: #fff;
  color: var(--gray-700);
  border: 1.5px solid var(--gray-200);
}
.btn-outline:hover { border-color: var(--gray-300); background: var(--gray-50); }
.btn-block { width: 100%; }

/* === 超分开关 === */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.toggle-label {
  font-size: .9rem;
  font-weight: 500;
  color: var(--gray-700);
}
.toggle-sub {
  display: block;
  font-size: .75rem;
  font-weight: 400;
  color: var(--gray-500);
}
.toggle-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.toggle-switch {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--gray-300);
  transition: background .2s;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
  transition: transform .2s;
}
.toggle-input:checked + .toggle-switch {
  background: var(--violet-600);
}
.toggle-input:checked + .toggle-switch::after {
  transform: translateX(20px);
}

/* === 状态区 === */
.status-area {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--violet-50);
  font-size: .9rem;
}
.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--gray-700);
}
.spinner {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border: 2px solid rgba(124,58,237,.25);
  border-top-color: var(--violet-600);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-error {
  margin-top: 8px;
  color: var(--red-500);
  font-size: .85rem;
  word-break: break-all;
}

/* === 结果 === */
.result-img {
  width: 100%;
  border-radius: 8px;
  display: block;
  box-shadow: var(--shadow);
}
.result-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.result-actions .btn { flex: 1; }

/* === 图库按钮 & 弹窗 === */
#gallery-btn { margin-top: 12px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
}
.modal-box {
  position: relative;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-200);
}
.modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
}
.btn-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--gray-100);
  color: var(--gray-500);
  font-size: .9rem;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.btn-close:hover { background: var(--gray-200); color: var(--gray-900); }

.gallery-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px;
}
.gallery-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--gray-100);
  aspect-ratio: 1;
}
.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}
.gallery-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  line-height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .7rem;
  cursor: pointer;
}
.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--gray-500);
  font-size: .85rem;
  padding: 40px 12px;
}

/* === 轻提示（toast） === */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(40px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(17,24,39,.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: .85rem;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
  max-width: 86vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === 图库文件夹 === */
.gallery-folder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 26px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.gallery-folder:hover {
  border-color: var(--violet-600);
  background: var(--violet-50);
}
.gallery-folder-icon { font-size: 1.8rem; }
.gallery-folder-name { font-size: .85rem; font-weight: 500; color: var(--gray-700); }
.gallery-back {
  font-size: .85rem;
  color: var(--violet-600);
  cursor: pointer;
  padding: 2px 8px;
  margin-right: 4px;
}

/* === 工具类 === */
.hidden { display: none !important; }
