:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --ink: #1b1b1a;
  --muted: #66665f;
  --line: #deded8;
  --accent: #d6136f;
  --on-accent: #ffffff;
  --err: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151516;
    --card: #1f1f21;
    --ink: #ecece8;
    --muted: #9a9a94;
    --line: #35353a;
    --accent: #ff4f9d;
    --on-accent: #1a0710;
    --err: #ff8a7a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.65 -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* 顶栏：分类标签 */
.top { display: flex; align-items: center; gap: 28px; padding: 0 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; padding: 14px 0; }
.cats { display: flex; gap: 6px; margin-right: auto; }
.cats button { padding: 15px 14px 13px; background: none; border: 0; border-bottom: 3px solid transparent; cursor: pointer; color: var(--muted); font-size: 16px; }
.cats button:hover { color: var(--ink); }
.cats button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.code { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.code input { width: 9.5em; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); font: inherit; }

/* 主体：中间表单与结果，右侧历史 */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
main { width: 100%; max-width: 760px; margin: 0 auto; padding: 24px 24px 64px; }

.subtabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.subtabs button { padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); cursor: pointer; }
.subtabs button:hover { border-color: var(--muted); }
.subtabs button[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }

h1 { margin: 0 0 4px; font-size: 22px; line-height: 1.3; }
.desc { margin: 0 0 22px; color: var(--muted); }

.field { margin-bottom: 18px; }
.lab { display: block; margin-bottom: 6px; font-weight: 600; }
.lab small { margin-left: 6px; font-weight: 400; font-size: 12px; color: var(--muted); }
textarea, select, input[type=number] {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink); font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
textarea:focus, select:focus, input[type=number]:focus, .code input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg button { flex: 1; padding: 8px 12px; background: none; border: 0; border-right: 1px solid var(--line); cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.drop { position: relative; display: block; padding: 14px 16px; border: 1px dashed var(--muted); border-radius: 8px; background: var(--card); cursor: pointer; }
.drop input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.drop:focus-within, .drop.over { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.drop-t { display: block; font-weight: 600; word-break: break-all; }
.drop-s { display: block; font-size: 13px; color: var(--muted); }
.drop.has { border-style: solid; border-color: var(--line); }
.preview { display: block; margin-top: 8px; max-width: 100%; max-height: 220px; border-radius: 8px; background: #000; }

.painter { position: relative; margin-top: 8px; line-height: 0; background: #000; border-radius: 8px; overflow: hidden; }
.painter canvas { display: block; width: 100%; height: auto; }
.painter canvas.paint { position: absolute; inset: 0; height: 100%; cursor: none; touch-action: none; opacity: .5; }
.painter .brush { position: absolute; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #000; transform: translate(-50%, -50%); pointer-events: none; }
.tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--muted); }
.tools input[type=range] { accent-color: var(--accent); }
.tools button { padding: 3px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.tools button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.paint-hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); }

.go { display: block; width: 100%; padding: 12px 24px; border: 0; border-radius: 8px; cursor: pointer; background: var(--accent); color: var(--on-accent); font-size: 16px; font-weight: 700; }
.go:disabled { opacity: .5; cursor: not-allowed; }
#status { min-height: 1.65em; margin: 10px 0 0; font-size: 14px; color: var(--muted); }
#status.err { color: var(--err); }
.limit { margin: 0 0 20px; font-size: 13px; color: var(--muted); }

/* 结果 */
.stage { position: relative; display: grid; place-items: center; min-height: 220px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); overflow: hidden; }
.idle, .busy { padding: 24px; text-align: center; color: var(--muted); }
.busy { display: none; }
.stage[data-state="busy"] .idle, .stage[data-state="done"] .idle { display: none; }
.stage[data-state="busy"] .busy { display: block; }
#phase { color: var(--ink); font-size: 18px; font-weight: 600; }
.stage:not([data-state="done"]) #results { display: none; }
#results { width: 100%; }
.out { margin: 0; }
.out + .out { border-top: 1px solid var(--line); }
.out img, .out video { display: block; width: 100%; max-height: 80vh; object-fit: contain; background: #000; }
.out pre { margin: 0; padding: 16px; white-space: pre-wrap; word-break: break-word; }
.out a { display: inline-block; margin: 8px 12px 10px; font-size: 13px; color: var(--accent); }

/* 右侧：生成记录 */
.history {
  position: sticky; top: 0; height: calc(100vh - 53px); overflow-y: auto;
  padding: 20px 16px 32px; border-left: 1px solid var(--line); background: var(--card);
}
.history h2 { margin: 0 0 4px; font-size: 16px; }
.hnote { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.hlist { list-style: none; margin: 0; padding: 0; }
.hrow { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 4px 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.hthumb { grid-row: span 2; width: 64px; height: 64px; padding: 0; border: 0; border-radius: 6px; overflow: hidden; background: #000; cursor: pointer; }
.hthumb img, .hthumb video { display: block; width: 100%; height: 100%; object-fit: cover; }
.hrow.gone .hthumb { display: grid; place-items: center; background: var(--bg); color: var(--muted); font-size: 12px; cursor: default; }
.hthumb.wait { display: grid; place-items: center; cursor: default; background: var(--bg); color: var(--ink); font-size: 12px; font-weight: 600; }
.hrow.run .hthumb.wait { background: color-mix(in srgb, var(--accent) 14%, var(--card)); color: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.hrow.gone .hthumb.wait { color: var(--muted); font-weight: 400; }
.el { font-variant-numeric: tabular-nums; }
.hinfo { min-width: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.hinfo b { display: block; color: var(--ink); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hinfo span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbtns { display: flex; gap: 8px; align-self: end; }
.hbtns button { padding: 2px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); cursor: pointer; font-size: 13px; }
.hbtns button.dl { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.hbtns button:disabled { opacity: .5; cursor: default; }

@media (max-width: 900px) {
  .top { flex-wrap: wrap; gap: 0 20px; padding: 0 16px; }
  .brand { width: 100%; padding-bottom: 0; }
  .layout { grid-template-columns: 1fr; }
  main { padding: 20px 16px 24px; }
  .history { position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; animation: none !important; } }
