:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --text: #111111;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #fa5400;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(250, 84, 0, 0.08);
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 20px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --radius-sm: 8px;
}

html[data-theme="dark"] {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1c1c1c;
  --text: #f5f5f5;
  --muted: #9ca3af;
  --border: #262626;
  --accent: #ff6a1a;
  --accent-contrast: #0a0a0a;
  --accent-soft: rgba(255, 106, 26, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 4px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; margin-top: 1.4rem; margin-bottom: 0.5rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
p { margin: 0.4rem 0; }

.hidden { display: none !important; }

/* ---- Header ---- */
.site-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: color-mix(in oklab, var(--surface) 85%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-text .tagline { margin: 0; color: var(--muted); font-size: 0.82rem; }
.swoosh {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--accent-contrast);
  font-weight: 900; font-size: 1.1rem;
}
.controls { display: flex; gap: 8px; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text);
  width: 40px; height: 40px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1rem;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: translateY(1px); }
.lang-btn { width: auto; padding: 0 12px; font-weight: 600; font-size: 0.85rem; }

/* theme/lang icon visibility */
.theme-icon-dark, .lang-zh { display: none; }
html[data-theme="dark"] .theme-icon-light { display: none; }
html[data-theme="dark"] .theme-icon-dark { display: inline; }
html[data-lang="zh"] .lang-en { display: none; }
html[data-lang="zh"] .lang-zh { display: inline; }

/* ---- Layout ---- */
.container {
  max-width: 960px;
  margin: 28px auto 80px;
  padding: 0 20px;
  display: flex; flex-direction: column; gap: 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card-title { font-size: 1.15rem; }
.card-sub { color: var(--muted); margin-bottom: 18px; }

/* ---- Form ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.field input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) {
  .grid-2 { grid-template-columns: 1fr; }
  .site-header { padding: 12px 16px; }
  .brand-text .tagline { display: none; }
}

.actions { display: flex; gap: 10px; margin-top: 6px; }
.primary-btn {
  background: var(--accent); color: var(--accent-contrast);
  border: none; border-radius: var(--radius-sm);
  padding: 12px 22px;
  font-size: 0.95rem; font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn:disabled { opacity: 0.55; cursor: not-allowed; filter: grayscale(0.3); }
.ghost-btn {
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.9rem; font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.ghost-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---- Status / pipeline ---- */
.status-card { display: flex; flex-direction: column; gap: 14px; }
.pipeline { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.pipeline-step {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 0.9rem; font-weight: 600;
  transition: border-color 0.2s, background 0.2s;
}
.pipeline-step.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.pipeline-step.done { border-color: var(--success); color: var(--success); }
.pipeline-step .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  transition: background 0.2s;
}
.pipeline-step.active .dot {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
.pipeline-step.done .dot { background: var(--success); animation: none; }
.arrow { color: var(--muted); }
@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.85); }
  50%      { opacity: 1;   transform: scale(1.15); }
}
.status-meta {
  display: flex; justify-content: space-between; align-items: center;
  color: var(--muted); font-size: 0.9rem;
}
.elapsed { font-variant-numeric: tabular-nums; }

/* ---- Error ---- */
.error-card { border-color: var(--danger); background: color-mix(in oklab, var(--danger) 8%, var(--surface)); }
.error-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.error-card strong { color: var(--danger); }

/* ---- Report ---- */
.report { display: flex; flex-direction: column; gap: 18px; }
.report-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.copy-feedback { color: var(--success); font-size: 0.85rem; opacity: 0; transition: opacity 0.2s; }
.copy-feedback.show { opacity: 1; }
.section-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px; gap: 10px; flex-wrap: wrap;
}
.section-head h2 { display: inline-flex; align-items: center; gap: 8px; }
.sec-icon { font-size: 1.1rem; }
.muted { color: var(--muted); font-size: 0.85rem; }

.prose { line-height: 1.7; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 1em 0 0.4em; line-height: 1.3; }
.prose h1 { font-size: 1.3rem; }
.prose h2 { font-size: 1.15rem; }
.prose h3 { font-size: 1rem; text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 700; }
.prose p  { margin: 0.6em 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose code {
  background: var(--surface-2); padding: 1px 6px;
  border-radius: 4px; font-size: 0.88em;
}
.prose pre {
  background: var(--surface-2); padding: 14px; border-radius: var(--radius-sm);
  overflow-x: auto; border: 1px solid var(--border);
}
.prose a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
.prose a:hover { border-bottom-color: var(--accent); }
.prose blockquote {
  margin: 0.6em 0; padding: 4px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 4px;
}

#research-facts li, #research-sources li, #research-needs li,
#draft-risk li, #qa-issues li, #qa-factflags li, #qa-improvements li {
  margin: 4px 0;
}
.empty-placeholder { color: var(--muted); font-style: italic; list-style: none; margin-left: -1.4em; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px;
  font-size: 0.82rem; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted);
}
.badge.good  { background: color-mix(in oklab, var(--success) 14%, var(--surface)); border-color: var(--success); color: var(--success); }
.badge.ok    { background: color-mix(in oklab, var(--warn) 14%, var(--surface));    border-color: var(--warn);    color: var(--warn); }
.badge.bad   { background: color-mix(in oklab, var(--danger) 14%, var(--surface));  border-color: var(--danger);  color: var(--danger); }

.final-card { border-color: var(--accent); }
.final-card .section-head h2 { color: var(--accent); }

/* ---- Footer ---- */
.site-footer {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.site-footer > div + div { margin-top: 6px; }
.footer-credit a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
.footer-credit a:hover { border-bottom-color: var(--accent); }
