/* ============================================================
   摸摸头 · Petpet GIF 生成器 — Apple 风格
   设计语言：大标题、留白、毛玻璃卡片、胶囊按钮、发丝线
   ============================================================ */

:root {
  --bg: #fbfbfd;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --blue: #0071e3;
  --blue-hover: #0077ed;
  --hairline: rgba(0, 0, 0, 0.08);
  --card-bg: rgba(255, 255, 255, 0.72);
  --field-bg: #f5f5f7;
  --seg-bg: rgba(120, 120, 128, 0.12);
  --seg-thumb: #ffffff;
  --shadow-card: 0 24px 70px rgba(0, 0, 0, 0.09), 0 2px 12px rgba(0, 0, 0, 0.04);
  --focus-ring: 0 0 0 4px rgba(0, 113, 227, 0.28);
  --checker-a: #e9e9ee;
  --checker-b: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #060607;
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #86868b;
    --hairline: rgba(255, 255, 255, 0.12);
    --card-bg: rgba(28, 28, 30, 0.72);
    --field-bg: #1c1c1e;
    --seg-bg: rgba(120, 120, 128, 0.24);
    --seg-thumb: #636366;
    --shadow-card: 0 24px 70px rgba(0, 0, 0, 0.55), 0 2px 12px rgba(0, 0, 0, 0.35);
    --checker-a: #3a3a3c;
    --checker-b: #2c2c2e;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
               "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---------- 背景光晕 ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
}
.blob-blue   { width: 560px; height: 560px; top: -180px; left: 8%;
               background: radial-gradient(circle, rgba(10, 132, 255, 0.35), transparent 70%); }
.blob-pink   { width: 480px; height: 480px; top: -80px; right: 4%;
               background: radial-gradient(circle, rgba(255, 55, 95, 0.22), transparent 70%); }
.blob-purple { width: 520px; height: 520px; top: 46vh; left: 50%;
               transform: translateX(-50%);
               background: radial-gradient(circle, rgba(191, 90, 242, 0.16), transparent 70%); }

@media (prefers-color-scheme: dark) {
  .blob { opacity: 0.32; }
}

/* ---------- 版面 ---------- */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 72px 22px 40px;
}

/* ---------- 头部 ---------- */
.hero { text-align: center; margin-bottom: 40px; animation: rise 0.7s cubic-bezier(0, 0, 0.2, 1) both; }

.eyebrow {
  font-size: 15px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 10px;
  letter-spacing: 0.01em;
}

.hero h1 {
  font-size: clamp(44px, 9vw, 68px);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.05;
}
.hero h1 .dot { color: var(--blue); }

.hero .sub {
  margin-top: 14px;
  font-size: 19px;
  line-height: 1.45;
  color: var(--text-2);
  letter-spacing: -0.01em;
}

/* ---------- 毛玻璃卡片 ---------- */
.card {
  background: var(--card-bg);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--hairline);
  border-radius: 28px;
  box-shadow: var(--shadow-card);
  padding: 26px;
  animation: rise 0.7s 0.08s cubic-bezier(0, 0, 0.2, 1) both;
}

/* ---------- 分段控件 ---------- */
.seg {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--seg-bg);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 22px;
}
.seg-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  background: var(--seg-thumb);
  border-radius: 9px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.06);
  transition: transform 0.28s cubic-bezier(0.3, 0.9, 0.4, 1.1);
}
.seg[data-mode="custom"] .seg-thumb { transform: translateX(100%); }

.seg-btn {
  position: relative;
  z-index: 1;
  appearance: none;
  border: 0;
  background: none;
  height: 40px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-2);
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.2s ease;
}
.seg-btn.is-active { color: var(--text); }
.seg-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- 面板 ---------- */
.panel { animation: fadeIn 0.25s ease both; }
.panel.hidden { display: none; }

.qq-row { display: flex; gap: 12px; align-items: center; }

.field-input {
  width: 100%;
  height: 52px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--field-bg);
  padding: 0 18px;
  font: inherit;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--text);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.field-input::placeholder { color: var(--text-3); }
.field-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: var(--focus-ring);
}

.qq-avatar {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--hairline);
  background: var(--field-bg);
  animation: fadeIn 0.3s ease both;
}
.qq-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- 拖拽上传 ---------- */
.drop {
  border: 1.5px dashed rgba(120, 120, 128, 0.4);
  border-radius: 16px;
  padding: 30px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}
.drop:hover, .drop:focus-visible, .drop.is-dragover {
  outline: none;
  border-color: var(--blue);
  background: rgba(0, 113, 227, 0.05);
}
.drop.is-dragover { transform: scale(1.015); }

.drop-icon {
  width: 30px;
  height: 30px;
  color: var(--text-3);
  margin-bottom: 10px;
}
.drop-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.drop-browse { color: var(--blue); }
.drop-hint { margin-top: 5px; font-size: 13px; color: var(--text-3); }

.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--field-bg);
  border-radius: 14px;
  padding: 10px 14px 10px 10px;
  animation: fadeIn 0.25s ease both;
}
.file-row.hidden { display: none; }
.file-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--hairline);
}
.file-meta { min-width: 0; flex: 1; }
.file-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-size { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.file-remove {
  flex: none;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgba(120, 120, 128, 0.16);
  color: var(--text-2);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease;
}
.file-remove:hover { background: rgba(120, 120, 128, 0.28); }

.or {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 16px 0;
  color: var(--text-3);
  font-size: 13px;
}
.or::before, .or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--hairline);
}

/* ---------- 背景选择 ---------- */
.bg-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 22px 2px;
  flex-wrap: wrap;
}
.bg-label { font-size: 15px; font-weight: 600; color: var(--text-2); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  appearance: none;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  height: 36px;
  padding: 0 16px;
  border-radius: 980px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.chip:hover { background: rgba(120, 120, 128, 0.1); }
.chip:active { transform: scale(0.95); }
.chip.is-active { background: var(--text); color: var(--bg); border-color: transparent; }
.chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- 按钮 ---------- */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 980px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease, transform 0.15s ease, opacity 0.2s ease;
}
.btn-primary:hover { background: var(--blue-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-primary:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn-ghost {
  border: 0;
  background: none;
  color: var(--blue);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 18px;
  border-radius: 980px;
  transition: background 0.2s ease;
}
.btn-ghost:hover { background: rgba(0, 113, 227, 0.08); }
.btn-ghost:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- 加载指示 ---------- */
.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-primary.is-loading .spinner { display: inline-block; }
.btn-primary.is-loading { pointer-events: none; }

/* ---------- 提示消息 ---------- */
.msg {
  min-height: 20px;
  margin-top: 14px;
  font-size: 14px;
  color: var(--text-3);
  text-align: center;
  transition: color 0.2s ease;
}
.msg.is-error { color: #ff3b30; font-weight: 500; }

/* ---------- 结果 ---------- */
.result { margin-top: 28px; animation: rise 0.55s cubic-bezier(0, 0, 0.2, 1) both; }
.result.hidden { display: none; }

.result-frame {
  display: flex;
  justify-content: center;
  padding: 22px;
  background: var(--card-bg);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--hairline);
  border-radius: 28px;
  box-shadow: var(--shadow-card);
}
.result-frame.is-checker {
  background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 0 / 20px 20px;
}
#result-img {
  max-width: min(320px, 100%);
  border-radius: 18px;
  display: block;
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}
.btn-download { width: auto; padding: 0 34px; }

/* ---------- 历史记录 ---------- */
.history { margin-top: 34px; animation: rise 0.55s 0.05s cubic-bezier(0, 0, 0.2, 1) both; }
.history.hidden { display: none; }
.history-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  margin: 0 4px 10px;
}
.history-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px;
  scrollbar-width: thin;
}
.history-item {
  flex: none;
  width: 92px;
  height: 92px;
  border-radius: 14px;
  border: 1px solid var(--hairline);
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  background: var(--field-bg);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.history-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.history-item:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12); }
.history-item:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ---------- 页脚 ---------- */
.foot {
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}
.foot a { color: inherit; }

/* ---------- 动画 ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- 小屏适配 ---------- */
@media (max-width: 480px) {
  .page { padding-top: 52px; }
  .hero { margin-bottom: 30px; }
  .hero .sub br { display: none; }
  .card { padding: 20px; border-radius: 22px; }
  .bg-row { align-items: flex-start; flex-direction: column; gap: 10px; }
}
