/* ============================================================
   Thread Art · Web 设计系统
   定位：前台（生成配置 / 进度 / 结果）与后台共用的组件资产。
   结构：1. Design Tokens  2. 基础  3. 布局壳  4. 组件  5. 状态
   ============================================================ */

/* ---------- 1. Design Tokens ---------- */
:root {
  /* 品牌色 */
  --brand-50: #eef4ff;
  --brand-100: #dbe7ff;
  --brand-200: #b9d0ff;
  --brand-500: #2f6fed;
  --brand-600: #2458cc;
  --brand-700: #1c47a6;

  /* 中性色 */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #fafbfc;
  --border: #e4e7ec;
  --border-strong: #d0d5dc;
  --text: #1f2329;
  --text-muted: #6b7280;
  --text-faint: #9aa1ac;

  /* 状态色 */
  --ok: #2e9e5b;
  --ok-bg: #e9f7ef;
  --ok-border: #bfe3cd;
  --danger: #d64545;
  --danger-bg: #fdecec;
  --danger-border: #f5c7c7;
  --warning: #b45309;
  --warning-bg: #fdf4e4;
  --warning-border: #efd9b4;

  /* 间距 */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px;
  --space-4: 16px; --space-5: 20px; --space-6: 24px;
  --space-8: 32px; --space-10: 40px;

  /* 圆角 / 阴影 */
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
  --shadow-focus: 0 0 0 3px rgba(47, 111, 237, 0.18);

  /* 字体 */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* 布局 */
  --shell-max: 1080px;
  --shell-pad: 24px;
}

/* ---------- 2. 基础 ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.3; font-weight: 600; }
a { color: var(--brand-500); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
}
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }

/* ---------- 3. 布局壳 ---------- */
.tool-shell { max-width: var(--shell-max); margin: 0 auto; padding: 0 var(--shell-pad) 64px; }

/* 顶部工具条 */
.tool-chrome {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; margin-bottom: 32px;
  border-bottom: 1px solid var(--border);
}
.brand-mark { font-size: 17px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.brand-mark:hover { text-decoration: none; }
.brand-mark .brand-dot { color: var(--brand-500); }
.tool-nav { display: flex; gap: 4px; }
.tool-nav-link {
  padding: 7px 14px; border-radius: var(--radius-md);
  color: var(--text-muted); font-size: 13px; font-weight: 500;
}
.tool-nav-link:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.tool-nav-link.is-active { background: var(--brand-50); color: var(--brand-600); }

/* 配置区容器 */
.config-shell { max-width: 860px; }
.config-hero { margin-bottom: 24px; }
.eyebrow {
  margin: 0 0 6px; font-size: 12px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--brand-500);
}
.config-hero h1 { margin: 0 0 6px; font-size: 26px; }
.intro { margin: 0; color: var(--text-muted); font-size: 14px; }

/* 分区卡片栈：每个功能区独立成卡片，拉开层次 */
.config-stack { display: flex; flex-direction: column; gap: 20px; }
.config-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.config-card-head { margin-bottom: 16px; }
.config-card-title { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.result-home-bar { margin: -8px 0 20px; }
.config-card-desc { margin: 0; font-size: 12px; color: var(--text-muted); }
.config-card .config-topbar { margin-bottom: 0; }

/* ---------- 4. 组件 ---------- */

/* 按钮 */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border: 1px solid transparent; border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500; line-height: 1.4; cursor: pointer;
  background: var(--surface); color: var(--text);
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.button-primary { background: var(--brand-500); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--brand-600); }
.button-primary:disabled { background: var(--brand-500); }
.button-secondary { border-color: var(--border-strong); background: var(--surface); }
.button-secondary:hover:not(:disabled) { border-color: var(--brand-500); color: var(--brand-600); }
.button-lg { height: 48px; padding: 0 28px; font-size: 16px; border-radius: var(--radius-lg); }
.button-block { width: 100%; }

/* 表单 */
.field-block { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--text); }
.field-hint { margin: 10px 0 0; font-size: 12px; color: var(--text-faint); }
.text-input {
  width: 100%; height: 48px; padding: 0 16px; font-size: 18px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.text-input::placeholder { color: var(--text-faint); }
.text-input:focus { border-color: var(--brand-500); box-shadow: var(--shadow-focus); }

/* 顶部条：文案输入 + 操作按钮同排 */
.config-topbar { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 28px; }
.config-topbar .text-field { flex: 1 1 auto; }
.actions { flex: 0 0 auto; }

/* 选项组（fieldset） */
.option-group {
  margin: 0; padding: 0; border: 0; min-width: 0;
}
.option-group legend {
  font-size: 13px; font-weight: 600; color: var(--text);
  padding: 0; margin-bottom: 12px;
}

/* 字体卡片 */
.font-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.font-card {
  display: block; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); padding: 14px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.font-card:hover { border-color: var(--brand-200); }
.font-card input { position: absolute; opacity: 0; pointer-events: none; }
.font-card:has(input:checked) {
  border-color: var(--brand-500); box-shadow: var(--shadow-focus);
}
.font-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.font-card-name { font-size: 13px; font-weight: 600; color: var(--text); }
.font-card-preview {
  display: flex; align-items: center; justify-content: center;
  min-height: 52px; padding: 8px; border-radius: var(--radius-md);
  background: var(--surface-muted); border: 1px dashed var(--border);
  overflow: hidden;
}
.font-card-preview-text { font-size: 30px; line-height: 1.2; color: var(--text); white-space: nowrap; }
.font-card.is-empty { cursor: default; }

/* 徽标 */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; line-height: 1.6;
  background: var(--brand-50); color: var(--brand-600);
}
.badge-warning { background: var(--warning-bg); color: var(--warning); }

/* 提示条（顶部警告/通知） */
.config-warning {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 16px; margin-bottom: 24px;
  border: 1px solid var(--warning-border); border-radius: var(--radius-md);
  background: var(--warning-bg); color: var(--warning); font-size: 13px;
}

/* 卡片 */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px; margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.card h2 { margin: 0 0 16px; font-size: 16px; }
.card h3 { margin: 0 0 12px; font-size: 14px; }

/* 错误框 */
.error-box {
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid var(--danger-border); border-radius: var(--radius-md);
  padding: 10px 14px; margin-top: 12px; font-size: 13px;
}

/* 空态提示 */
.empty-hint { color: var(--text-muted); font-size: 13px; }

/* 链接返回 */
.link-back { color: var(--brand-500); text-decoration: none; display: inline-block; margin-top: 12px; }
.link-back:hover { text-decoration: underline; }

/* 进度页：阶段列表 */
.stage-list { list-style: none; padding: 0; margin: 0; }
.stage-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; color: var(--text-muted); font-size: 13px; }
.stage-list li + li { border-top: 1px solid var(--border); }
.stage-list li .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border-strong); flex: none; }
.stage-list li.done .dot { background: var(--ok); }
.stage-list li.running .dot { background: var(--brand-500); animation: pulse 1s infinite; }
.stage-list li.failed .dot { background: var(--danger); }
.stage-list li.done, .stage-list li.running { color: var(--text); }
.stage-list .stage-status { margin-left: auto; font-size: 12px; color: var(--text-faint); }
@keyframes pulse { 50% { opacity: 0.35; } }
.progress-hint { color: var(--text-muted); margin-top: 16px; font-size: 13px; }

/* 进度条 */
.progress-track {
  height: 8px; border-radius: 999px; overflow: hidden;
  background: var(--surface-muted); border: 1px solid var(--border);
  margin: 16px 0;
}
.progress-bar {
  height: 100%; border-radius: 999px;
  background: var(--brand-500);
  transition: width 0.4s ease;
}
.progress-meta { display: flex; justify-content: space-between; align-items: baseline; }
.progress-percent { font-size: 22px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.progress-label { font-size: 13px; color: var(--text-muted); }

/* 结果页：预览图 */
.gallery-img {
  width: 100%; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: #fff; display: block;
}
.gallery-label { color: var(--text-muted); margin: 10px 0 0; font-size: 13px; }

/* 结果页：摘要 */
.summary dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; margin: 0; }
.summary dt { color: var(--text-muted); font-size: 13px; }
.summary dd { margin: 0; font-variant-numeric: tabular-nums; }

/* 结果页：下载 */
.downloads ul { list-style: none; padding: 0; margin: 0; }
.downloads li { padding: 4px 0; }
.downloads a { color: var(--brand-500); text-decoration: none; }
.downloads a:hover { text-decoration: underline; }

/* 状态徽标（结果页三态） */
.result-status { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.result-status .dot { width: 8px; height: 8px; border-radius: 50%; }
.result-status-ok { background: var(--ok-bg); color: var(--ok); }
.result-status-ok .dot { background: var(--ok); }
.result-status-warn { background: var(--warning-bg); color: var(--warning); }
.result-status-warn .dot { background: var(--warning); }
.result-status-error { background: var(--danger-bg); color: var(--danger); }
.result-status-error .dot { background: var(--danger); }
.result-status-row { display: flex; flex-direction: column; gap: 8px; }
.result-status-note { margin: 0; font-size: 13px; color: var(--text-muted); }

/* 主下载按钮 */
.primary-download-button {
  display: inline-flex; flex-direction: column; gap: 2px;
  padding: 14px 28px; border-radius: var(--radius-lg);
  background: var(--brand-500); color: #fff; font-weight: 600;
}
.primary-download-button:hover { background: var(--brand-600); color: #fff; text-decoration: none; }
.primary-download-button small { font-size: 12px; font-weight: 400; opacity: 0.85; }

/* 下载列表 */
.download-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.download-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text);
  transition: border-color 0.15s;
}
.download-item:hover { border-color: var(--brand-500); text-decoration: none; }
.download-item strong { font-size: 14px; font-weight: 600; }
.download-item span { font-size: 12px; color: var(--text-muted); }
.download-item.is-primary { border-color: var(--brand-200); background: var(--brand-50); }

/* 产物卡片（进度页产物流） */
.artifact-feed { display: flex; flex-direction: column; gap: 20px; margin-top: 20px; }
.artifact-stage {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px 24px; box-shadow: var(--shadow-sm);
}
.artifact-stage-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; font-size: 13px;
}
.artifact-stage-head strong { font-size: 14px; font-weight: 600; }
.artifact-stage-status { font-size: 12px; color: var(--text-faint); }
.artifact-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.artifact-card {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); cursor: pointer; overflow: hidden;
  transition: border-color 0.15s;
}
.artifact-card:hover { border-color: var(--brand-500); }
.artifact-card-topline {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px 0; font-size: 12px;
}
.artifact-card-role { color: var(--brand-600); font-weight: 600; }
.artifact-card-order { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.artifact-image {
  width: 100%; aspect-ratio: 1; object-fit: contain;
  background: #fff; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.artifact-card-label { padding: 0 12px; font-size: 13px; font-weight: 600; }
.artifact-card-hint { padding: 0 12px 10px; font-size: 12px; color: var(--text-faint); }
.artifact-empty { color: var(--text-muted); font-size: 13px; }

/* 结果页：gallery */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.gallery-card {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); cursor: pointer; overflow: hidden;
  transition: border-color 0.15s;
}
.gallery-card:hover { border-color: var(--brand-500); }
.gallery-card.is-featured { border-color: var(--brand-200); box-shadow: var(--shadow-focus); }
.gallery-card-topline {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px 0; font-size: 12px;
}
.gallery-card-role { color: var(--brand-600); font-weight: 600; }
.gallery-card-order { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.gallery-image {
  width: 100%; aspect-ratio: 1; object-fit: contain;
  background: #fff; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.gallery-card-label { padding: 0 12px; font-size: 13px; font-weight: 600; }
.gallery-card-note { padding: 0 12px; font-size: 12px; color: var(--text-muted); }
.gallery-card-hint { padding: 0 12px 10px; font-size: 12px; color: var(--text-faint); }

/* 警告面板 */
.warning-list { list-style: none; padding: 0; margin: 0; }
.warning-list li {
  position: relative; padding: 8px 0 8px 22px;
  border-top: 1px solid var(--border); font-size: 13px;
}
.warning-list li:first-child { border-top: 0; }
.warning-list li::before {
  content: ""; position: absolute; left: 4px; top: 15px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--warning);
}

/* 大图预览浮层（全屏遮罩 + 居中图片） */
#image-modal.config-card[hidden] { display: none; }
#image-modal.config-card {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; margin: 0; padding: 24px;
  background: rgba(16, 24, 40, 0.55);
  border: 0; border-radius: 0; box-shadow: none;
}
#image-modal .modal-close {
  position: absolute; top: 18px; right: 20px; z-index: 2;
  width: 36px; height: 36px; border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  background: rgba(16, 24, 40, 0.6); color: #fff; font-size: 20px; line-height: 1;
  cursor: pointer;
}
#image-modal .modal-close:hover { color: #fff; border-color: #fff; }
#image-modal .modal-image {
  width: auto; max-width: min(92vw, 920px); max-height: 84vh;
  border-radius: var(--radius-md); border: 1px solid var(--border);
  background: #fff; box-shadow: var(--shadow-md);
}
#image-modal .modal-label { margin: 0; font-size: 13px; color: #e6e9ef; text-align: center; }

/* ---------- 5. 响应式 ---------- */
@media (max-width: 640px) {
  :root { --shell-pad: 16px; }
  .config-topbar { flex-direction: column; align-items: stretch; }
  .actions { width: 100%; }
  .actions .button { width: 100%; }
  .config-hero h1 { font-size: 22px; }
  .font-card-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .summary dl { grid-template-columns: 110px 1fr; }
  .tool-chrome { margin-bottom: 20px; }
}
