:root {
  --bg: #0e1116;
  --bg-soft: #161b23;
  --card: #171d27;
  --line: #263042;
  --text: #e8edf5;
  --muted: #93a1b8;
  --brand: #6d8bff;
  --brand-2: #b06dff;
  --ok: #3ddc97;
  --err: #ff6b6b;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1100px 520px at 12% -12%, #1c2440, transparent), var(--bg);
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }

.app { max-width: 900px; margin: 0 auto; padding: 20px 16px 40px; }

.hero { text-align: center; padding: 12px 0 22px; }
.hero h1 {
  margin: 0 0 8px;
  font-size: 26px;
  letter-spacing: .5px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero .sub { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }

.env-tip {
  margin-top: 12px; padding: 10px 12px; border-radius: 10px;
  background: rgba(255,107,107,.12); border: 1px solid rgba(255,107,107,.35);
  color: #ffb4b4; font-size: 13px; text-align: left;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.card-title.no-step { margin-bottom: 4px; }
.step {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-size: 12px; display: inline-flex; align-items: center; justify-content: center;
}

/* 上传区 */
.drop-zone {
  position: relative;
  width: 100%;
  min-height: 220px;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; cursor: pointer; transition: border-color .2s;
}
.drop-zone:active, .drop-zone.dragover { border-color: var(--brand); }
.placeholder { text-align: center; color: var(--muted); padding: 24px; }
.placeholder p { margin: 10px 0 4px; font-size: 15px; color: var(--text); }
.placeholder small { font-size: 12px; }
.preview { max-width: 100%; max-height: 52vh; object-fit: contain; display: block; }

/* 图片加载/错误态 */
.img-loading, .img-error {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center; padding: 20px;
  background: rgba(14,17,22,.78); backdrop-filter: blur(2px);
  color: var(--muted); font-size: 13px;
}
.img-error { color: #ffb4b4; }
.img-loading p, .img-error p { margin: 0; }
.img-spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid rgba(109,139,255,.25); border-top-color: var(--brand);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.file-info { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

/* 按钮 */
.btn {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: transform .08s, opacity .2s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { flex: 1 1 120px; }
.btn-text { background: transparent; border-color: transparent; color: var(--muted); flex: 0 0 auto; }
.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border: none; color: #fff; font-weight: 600;
}
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: 13px; }

/* 分段控件 */
.segmented { display: flex; gap: 8px; }
.seg {
  flex: 1; min-height: 48px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-soft);
  color: var(--muted); font-size: 15px; cursor: pointer;
}
.seg[aria-checked="true"] {
  background: linear-gradient(135deg, rgba(109,139,255,.22), rgba(176,109,255,.22));
  border-color: var(--brand); color: var(--text); font-weight: 600;
}

.field { margin-top: 14px; display: flex; align-items: center; gap: 10px; }
.field label { font-size: 13px; color: var(--muted); flex: 0 0 auto; }
select {
  flex: 1; min-height: 44px; padding: 0 10px; border-radius: 10px;
  background: var(--bg-soft); color: var(--text); border: 1px solid var(--line); font-size: 14px;
}

.advanced { margin-top: 12px; }
.advanced summary { font-size: 13px; color: var(--muted); cursor: pointer; padding: 6px 0; }
.switch { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.switch input { width: 20px; height: 20px; accent-color: var(--brand); }

/* 偏好 */
.pref-block { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.pref-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pref-row-stack { flex-direction: column; align-items: stretch; gap: 6px; }
.pref-label { font-size: 13px; color: var(--muted); min-width: 3em; flex: 0 0 auto; }
.pref-seg { flex: 1; min-width: 0; }
.pref-seg-btn { font-size: 14px; min-height: 40px; }
.pref-text {
  width: 100%; min-height: 42px; padding: 10px 12px;
  border-radius: 10px; background: var(--bg-soft);
  border: 1px solid var(--line); color: var(--text); font-size: 14px;
  outline: none; transition: border-color .15s;
}
.pref-text::placeholder { color: #5d6b82; }
.pref-text:focus { border-color: var(--brand); }

/* 进度 */
.progress { margin-top: 14px; }
.progress .bar { height: 6px; border-radius: 6px; background: var(--bg-soft); overflow: hidden; }
.progress .bar i {
  display: block; height: 100%; width: 35%;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  animation: slide 1.2s ease-in-out infinite;
}
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(320%); } }
.progress p { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

.error-box {
  margin-top: 14px; padding: 12px; border-radius: 12px;
  background: rgba(255,107,107,.1); border: 1px solid rgba(255,107,107,.35);
}
.error-box p { margin: 0 0 10px; font-size: 13px; color: #ffb4b4; word-break: break-word; }

/* 结果 */
.result-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.face-info { margin: 4px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden; display: flex; flex-direction: column;
}
.tile img { width: 100%; display: block; background: #0b0e13; aspect-ratio: 3 / 4; object-fit: cover; }
.tile-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.tile-name { font-size: 14px; font-weight: 600; }
.tile-desc { font-size: 12px; color: var(--muted); line-height: 1.5; flex: 1; }
.tile .btn { width: 100%; }

.tip { margin: 12px 0 0; font-size: 12px; color: #ffd28a; }

.foot { text-align: center; font-size: 12px; color: var(--muted); padding: 8px 0 0; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(20,26,36,.96); border: 1px solid var(--line);
  color: var(--text); padding: 12px 18px; border-radius: 12px;
  font-size: 13px; z-index: 99; max-width: 88vw; text-align: center;
}

/* 平板与桌面 */
@media (min-width: 1024px) {
  .app { max-width: 1180px; }
  .grid { grid-template-columns: repeat(4, 1fr); }
  .hero h1 { font-size: 32px; }
  .drop-zone { min-height: 300px; }
}

/* 手机端：小屏（≤720px）按钮紧凑 + 结果头改竖排，避免按钮被挤成竖排单字 */
@media (max-width: 720px) {
  .app { padding: 14px 12px 28px; }
  .hero { padding: 8px 0 18px; }
  .hero h1 { font-size: 22px; letter-spacing: .3px; }
  .hero .sub { font-size: 12px; }
  .card { padding: 14px; border-radius: 14px; }
  .card-title { font-size: 14px; margin-bottom: 10px; }
  .step { width: 20px; height: 20px; font-size: 11px; }

  /* 按钮：减小高度/内边距/字号，移动端仍可点不显笨重 */
  .btn { min-height: 44px; padding: 0 14px; font-size: 14px; border-radius: 11px; }
  .btn-sm { min-height: 38px; padding: 0 12px; font-size: 13px; }
  .seg { min-height: 44px; font-size: 14px; }
  .pref-seg-btn { min-height: 38px; font-size: 13px; }
  .btn-row { gap: 8px; }
  .btn-row .btn { flex: 1 1 0; min-width: 0; }

  /* 上传区 */
  .drop-zone { min-height: 180px; }
  .preview { max-height: 50vh; }
  .placeholder { padding: 18px; }
  .placeholder p { font-size: 14px; }
  .placeholder small { font-size: 11px; }

  /* 偏好 */
  .pref-block { gap: 10px; }
  .pref-row { gap: 8px; }
  .pref-label { font-size: 12px; }
  .pref-text { min-height: 40px; font-size: 14px; padding: 9px 11px; }

  /* 结果头：窄屏改竖排，按钮全宽，文字不再竖向断行 */
  .result-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .result-head .face-info { text-align: left; }
  .result-head .btn { width: 100%; }

  /* 结果网格 2 列保留；卡片内文字、按钮同步缩小 */
  .grid { gap: 10px; }
  .tile { border-radius: 12px; }
  .tile-body { padding: 9px; gap: 6px; }
  .tile-name { font-size: 13px; }
  .tile-desc { font-size: 11px; line-height: 1.45; }
  .face-info { font-size: 11px; line-height: 1.55; }

  /* 加载/错误遮罩字号收紧 */
  .img-loading p, .img-error p { font-size: 12px; }
}

/* 极窄屏（如 360px 以下）进一步压缩 */
@media (max-width: 380px) {
  .app { padding: 12px 10px 24px; }
  .btn { min-height: 42px; padding: 0 12px; font-size: 13px; }
  .hero h1 { font-size: 20px; }
  .drop-zone { min-height: 160px; }
}
