:root {
  --brand: #1677ff;
  --brand-dark: #0f5fcc;
  --ink: #1a2233;
  --ink-2: #5b6474;
  --line: #e6e9f0;
  --bg: #f4f6fb;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

a { color: inherit; }

.top {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: .5px;
}

.top .spacer { flex: 1; }

.price-tag {
  font-size: 13px;
  color: var(--ink-2);
  background: #f0f4ff;
  border: 1px solid #dbe6ff;
  padding: 6px 12px;
  border-radius: 999px;
}

.top .link {
  font-size: 14px;
  color: var(--ink-2);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 10px;
}
.top .link:hover { background: #f2f5fa; }

.main {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  padding: 20px;
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
}

.panel {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 18px;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 104px);
  overflow: auto;
}

.panel h2 {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: .5px;
  margin: 20px 0 10px;
}
.panel h2:first-child { margin-top: 0; }

.themes {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.theme {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 8px 4px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
  transition: .15s;
}
.theme:hover { border-color: #c9d6ee; }
.theme.on {
  border-color: var(--brand);
  color: var(--brand);
  box-shadow: 0 0 0 3px rgba(22,119,255,.1);
}
.theme .sw {
  width: 22px; height: 22px;
  border-radius: 50%;
}

label.field { display: block; margin-bottom: 10px; }
label.field span {
  display: block;
  font-size: 12px;
  color: var(--ink-2);
  margin-bottom: 5px;
}

input[type=text], textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: #fbfcfe;
  outline: none;
  transition: .15s;
}
input[type=text]:focus, textarea:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(22,119,255,.08);
}
textarea { resize: vertical; min-height: 64px; line-height: 1.6; }

.seg {
  display: flex;
  background: #f2f5fa;
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  font-family: inherit;
}
.seg button.on {
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.seg.grid4 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

/* ---- 版式骨架选择器 ---- */
.skel-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.skel {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  color: var(--ink-2);
  transition: .14s;
  text-align: left;
}
.skel svg { flex: none; color: #a9b6cc; transition: .14s; }
.skel span { line-height: 1.25; }
.skel:hover { border-color: #c9d6ee; color: var(--brand); }
.skel:hover svg { color: var(--brand); }
.skel.on {
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 600;
  background: rgba(22,119,255,.045);
  box-shadow: 0 0 0 2px rgba(22,119,255,.10);
}
.skel.on svg { color: var(--brand); }

.style-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.style-row .chip { padding: 5px 11px; font-size: 12px; }
.style-row .chip.on {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}
.style-row .chip.dim { opacity: .55; }

.sec {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
  background: #fbfcfe;
}
.sec input[type=text] { margin-bottom: 8px; background: #fff; }

.stage {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.canvas-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 420px;
  /* 原来这里是四层渐变拼的棋盘格（给透明图做底），
     但生成的是不透明成品图，格子只会干扰视线，改成淡纯色。 */
  background: #f7f9fc;
  border-radius: 12px;
  padding: 16px;
  position: relative;
}

/* ---- 生成结果 ---- */
/* 必须显式处理 hidden：下面的 display:block 会盖掉 HTML 的 hidden 属性 */
#result[hidden],
.placeholder[hidden],
.loading[hidden] { display: none !important; }

#result {
  width: 100%;
  max-width: 880px;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(24,32,54,.13);
  display: block;
}

.placeholder { text-align: center; color: var(--ink-2); padding: 60px 20px; }
.ph-icon { font-size: 44px; color: #c8d2e4; margin-bottom: 10px; }
.ph-title { font-size: 16px; font-weight: 600; margin: 0 0 6px; color: var(--ink); }
.ph-sub { font-size: 13px; margin: 0; color: #8b93a3; line-height: 1.7; }

.loading { text-align: center; padding: 80px 20px; }
.loading p { font-size: 13px; color: #7a8296; margin-top: 16px; }
.spinner {
  width: 38px; height: 38px; margin: 0 auto;
  border: 3px solid #e3e9f4;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 风格卡 ---- */
.style-cards { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 10px; }
.style-card {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  transition: .14s;
  overflow: hidden;
}
.style-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #f2f5fa;
  border-bottom: 1px solid var(--line);
}
.style-thumb-empty { background: linear-gradient(135deg, #f6f8fc, #eaeff8); }
.style-name {
  display: block;
  font-size: 12px;
  color: var(--ink);
  padding: 7px 0 8px;
  text-align: center;
}
.style-card:hover { border-color: #c9d6ee; transform: translateY(-1px); }
.style-card.on {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(22,119,255,.14);
}
.style-card.on .style-name { color: var(--brand); font-weight: 600; }

/* ---- 生成按钮 ---- */
.gen-btn {
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  font-size: 15px;
}

/* ---- 更多设置（默认收起） ---- */
.more {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.more + .more { margin-top: 6px; }
.more summary {
  font-size: 12px;
  color: #8b93a3;
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 4px 0;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: "＋ "; }
.more[open] summary::before { content: "－ "; }
.more .field { margin-top: 10px; }
.more .chips { margin-top: 8px; }

/* ---- 自动/自定义标记 ---- */
.auto-tag {
  font-style: normal;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #eef2f9;
  color: #8b93a3;
  margin-left: 6px;
  font-weight: 400;
}
.auto-tag.own { background: rgba(22,119,255,.10); color: var(--brand); }

/* ---- 提示词预览 ---- */
.prompt-box {
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11.5px;
  line-height: 1.7;
  color: #4a5266;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 10px 0;
  max-height: 220px;
  overflow: auto;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@keyframes shakeX {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.shake { animation: shakeX .3s; border-color: #e8534a !important; }

canvas {
  width: 100%;
  max-width: 880px;
  height: auto;
  box-shadow: 0 6px 28px rgba(20,30,60,.16);
  border-radius: 4px;
  background: #fff;
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 26px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #f2f5fa; color: var(--ink); }
.btn.ghost:hover { background: #e8edf7; }
.btn[disabled] { background: #dfe3ea; color: #9aa3b2; cursor: not-allowed; }

.hint {
  font-size: 12px;
  color: var(--ink-2);
  text-align: center;
  max-width: 520px;
  line-height: 1.7;
}

/* ------------------------- 主题输入与一键生成 ------------------------- */

.topic-box { display: flex; gap: 8px; }
.topic-box input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  background: #fbfcfe;
  outline: none;
  transition: .15s;
}
.topic-box input:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(22,119,255,.08);
}
.topic-box .btn { padding: 12px 22px; flex: none; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.chip {
  border: 1px solid var(--line);
  background: #fbfcfe;
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: .15s;
}
.chip:hover { border-color: #c9d6ee; color: var(--brand); background: #fff; }

.gen-status {
  margin: 12px 0 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink-2);
  background: #f7f9fd;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}
.gen-status b { color: var(--ink); }

.row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.btn.small { padding: 8px 16px; font-size: 13px; }
.hint-inline { font-size: 11px; color: #98a1b0; }

.secs { margin: 14px 0 6px; }
.secs summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
  padding: 8px 0;
}
.secs .sec { margin-top: 8px; }

.canvas-wrap.busy canvas { opacity: .45; filter: blur(1px); }
.canvas-wrap { transition: opacity .2s; }
.canvas-wrap.busy::after {
  content: "正在生成…";
  position: absolute;
  font-size: 14px;
  color: var(--ink-2);
}
.canvas-wrap { position: relative; }
.canvas-wrap.busy { display: flex; align-items: center; justify-content: center; flex-direction: column; }
.canvas-wrap.busy::after { position: static; margin-top: 10px; }

@media (max-width: 980px) {
  /* 1fr 的最小尺寸是 min-content，图片会把网格撑出视口。
     必须用 minmax(0,1fr) + 子项 min-width:0 才能真正收缩。 */
  .main { grid-template-columns: minmax(0, 1fr); }
  .panel { position: static; max-height: none; }
  .panel, .stage { min-width: 0; }
  .style-card, .style-cards > * { min-width: 0; }
  .style-thumb { min-width: 0; }
}

/* ===================== 手机端 ===================== */
@media (max-width: 640px) {
  /* 全局：禁止横向溢出 */
  html, body { overflow-x: hidden; }
  * { box-sizing: border-box; }

  .top {
    height: 52px;
    padding: 0 14px;
    gap: 8px;
  }
  .logo { font-size: 15px; }

  .main {
    padding: 10px;
    gap: 10px;
  }
  .panel {
    padding: 14px;
    border-radius: 14px;
  }
  .panel h2 {
    font-size: 12px;
    margin-bottom: 8px;
  }

  /* 风格卡：保持两列但限制宽度，图不被拉变形 */
  .style-cards {
    grid-template-columns: minmax(0,1fr) minmax(0,1fr);
    gap: 8px;
  }
  .style-thumb { aspect-ratio: 4 / 3; }
  .style-name { font-size: 12px; padding: 6px 0; }

  /* 输入框字号 16px，避免 iOS 聚焦时自动放大 */
  .topic-box input,
  .field input,
  .field textarea {
    font-size: 16px;
  }

  .gen-btn {
    margin-top: 14px;
    padding: 14px;
    font-size: 16px;
  }

  /* 预览区：手机上占满宽度，不必留大片留白 */
  .stage {
    padding: 10px;
    border-radius: 14px;
    /* .stage 默认 align-items:center，会把 .actions 压成内容宽 */
    align-items: stretch;
    gap: 10px;
  }
  .actions {
    width: 100%;
  }
  .canvas-wrap {
    padding: 8px;
    min-height: 220px;
    /* 点阵底纹在窄屏上会显得脏，换成纯色 */
    background: #f6f8fc;
  }
  #result { max-width: 100%; border-radius: 6px; }
  .placeholder { padding: 40px 12px; }
  .ph-icon { font-size: 34px; }
  .ph-sub { font-size: 13px; }

  .actions {
    gap: 8px;
    margin-top: 10px;
    flex-wrap: nowrap;
    justify-content: stretch;
  }
  /* .btn 是 inline-flex，不显式给 width 会被 justify-content 压到内容宽 */
  .actions .btn,
  .actions .btn.primary,
  .actions .btn.ghost {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    padding: 12px 6px;
    font-size: 14px;
    white-space: nowrap;
    justify-content: center;
  }

  .hint { font-size: 12px; }
  .chips { gap: 6px; }
  .chip { font-size: 12px; padding: 6px 10px; }
}

/* 超窄屏（iPhone SE / 320px）：风格卡改单列，图更大更好点 */
@media (max-width: 340px) {
  .style-cards { grid-template-columns: minmax(0, 1fr); }
  .style-thumb { aspect-ratio: 16 / 9; }
  .panel { padding: 12px; }
  .main { padding: 8px; }
}
