:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e4e7ed;
  --border-strong: #d0d5dd;
  --text: #1f2937;
  --text-2: #374151;
  --muted: #6b7280;
  --primary: #4a7cff;
  --primary-hover: #3d6bef;
  --primary-soft: #eaf0ff;
  --ai-bubble: #ffffff;
  --user-bubble: #4a7cff;
  --user-bubble-text: #ffffff;
  --success: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 2px 8px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

/* ========== Mode Picker (首屏二选一) ========== */
.mode-picker {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: linear-gradient(135deg, #f5f7fb 0%, #eaf0ff 100%);
}
.mode-header { text-align: center; margin-bottom: 36px; }
.mode-header h1 { margin: 0 0 8px; font-size: 28px; font-weight: 600; }
.mode-header p { margin: 0; color: var(--muted); font-size: 15px; }

.mode-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 380px));
  gap: 20px;
  max-width: 820px;
  width: 100%;
}
.mode-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  font-family: inherit;
  color: var(--text);
}
.mode-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(74, 124, 255, 0.15);
}
.mode-emoji { font-size: 56px; margin-bottom: 12px; line-height: 1; }
.mode-card h2 { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.mode-desc { margin: 0 0 8px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.mode-meta { margin: 0; color: var(--primary); font-size: 12px; font-weight: 500; }

/* ========== Chat ========== */
#chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 960px;
  margin: 0 auto;
  background: var(--bg);
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 12px; }
.avatar-small {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a7cff 0%, #7c3aed 100%);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
#topbar h1 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
#topbar #statusLine { margin: 0; color: var(--muted); font-size: 12px; }
#resetBtn {
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 6px 12px;
  font-size: 12px; cursor: pointer;
  transition: all 0.15s;
}
#resetBtn:hover { color: var(--text); border-color: var(--muted); background: var(--surface-2); }

#chatLog {
  flex: 1; overflow-y: auto;
  padding: 24px 20px 100px;
  display: flex; flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.msg { display: flex; gap: 10px; animation: fadeIn 0.25s ease; }
.msg.user { flex-direction: row-reverse; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
}
.msg.ai .avatar {
  background: linear-gradient(135deg, #4a7cff 0%, #7c3aed 100%);
  color: white;
}
.msg.user .avatar {
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}

.bubble {
  max-width: 72%;
  padding: 10px 14px;
  border-radius: 14px;
  word-wrap: break-word;
  font-size: 14px;
  color: var(--text);
}
.msg.ai .bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}
.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-top-right-radius: 4px;
}
.bubble p { margin: 0; }
.bubble p + p { margin-top: 8px; }
.bubble strong { color: #b45309; }
.msg.user .bubble strong { color: #fde68a; }
.bubble code {
  background: rgba(17, 24, 39, 0.06);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px;
  color: #b91c1c;
}
.msg.user .bubble code { background: rgba(255, 255, 255, 0.18); color: #fff; }

.bubble.progress {
  background: var(--primary-soft);
  border: 1px dashed #b8c9ff;
  color: #3d4d80;
  font-size: 13px;
  box-shadow: none;
}
.bubble.progress::before { content: '⏳ '; opacity: 0.75; }
.bubble.progress.done { background: #e8f7ee; border-color: #a7d9b4; color: #15803d; }
.bubble.progress.done::before { content: '✓ '; color: var(--success); }
.bubble.progress.err { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.bubble.progress.err::before { content: '✗ '; color: var(--err); }

.bubble.image {
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.bubble.image img {
  display: block;
  max-width: 420px; width: 100%;
  border-radius: 10px;
  cursor: zoom-in;
  background: var(--surface-2);
}
.bubble.image .caption {
  margin-top: 6px; font-size: 12px;
  color: var(--muted);
  padding-left: 4px;
}
.bubble.image.user img { max-height: 280px; width: auto; }
.msg.user .bubble.image { background: var(--surface); color: var(--text); }

.bubble.video {
  padding: 6px;
  background: #0a0d12;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  max-width: 480px;
}
.bubble.video video {
  display: block;
  max-width: 480px;
  width: 100%;
  border-radius: 10px;
  background: #0a0d12;
}
.bubble.video .caption {
  margin-top: 6px;
  font-size: 12px;
  color: #cbd5e1;
  padding-left: 4px;
}

.bubble details {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 6px;
}
.bubble details summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  list-style: none;
}
.bubble details summary::before { content: '▸ '; display: inline-block; margin-right: 4px; transition: transform 0.15s; }
.bubble details[open] summary::before { transform: rotate(90deg); }
.bubble details pre {
  white-space: pre-wrap; word-wrap: break-word;
  font-family: inherit; font-size: 13px;
  margin: 10px 0 0;
  max-height: 420px; overflow-y: auto;
  color: var(--text);
}
.bubble details ol {
  margin: 10px 0 0;
  padding-left: 20px;
  font-size: 12px; color: var(--muted);
  max-height: 320px; overflow-y: auto;
}
.bubble details li { margin-bottom: 8px; }
.bubble details li .name { color: var(--text); font-weight: 600; }

.chips {
  margin-top: 10px;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.chip {
  background: var(--primary-soft);
  border: 1px solid #c4d4ff;
  color: var(--primary);
  border-radius: 12px;
  padding: 4px 12px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { background: #d8e3ff; border-color: var(--primary); }
.msg.user .bubble .chip {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
}

#inputBar {
  position: sticky; bottom: 0;
  display: flex; gap: 10px;
  align-items: flex-end;
  padding: 14px 20px 18px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.file-btn {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
  flex-shrink: 0;
}
.file-btn:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.file-btn.has-file { color: var(--success); border-color: var(--success); background: #e8f7ee; }

#textInput {
  flex: 1; resize: none;
  max-height: 140px;
  padding: 10px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px; line-height: 1.5;
  overflow-y: auto;
}
#textInput:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74, 124, 255, 0.12); }
#textInput::placeholder { color: var(--muted); }

#sendBtn {
  background: var(--primary); color: white;
  border: none; border-radius: 10px;
  padding: 0 18px; height: 40px;
  font-size: 14px; cursor: pointer;
  flex-shrink: 0; font-weight: 500;
  transition: background 0.15s;
}
#sendBtn:hover { background: var(--primary-hover); }
#sendBtn:disabled { opacity: 0.4; cursor: not-allowed; }

.hidden { display: none !important; }

#lightbox {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 999; cursor: zoom-out;
}
#lightbox img {
  max-width: 92vw; max-height: 92vh;
  object-fit: contain; border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

#chatLog::-webkit-scrollbar,
.bubble details pre::-webkit-scrollbar,
.bubble details ol::-webkit-scrollbar,
#textInput::-webkit-scrollbar { width: 8px; }
#chatLog::-webkit-scrollbar-thumb,
.bubble details pre::-webkit-scrollbar-thumb,
.bubble details ol::-webkit-scrollbar-thumb,
#textInput::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
#chatLog::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Step-pause edit cards ──────────────────────────── */
.edit-card {
  background: #f8fafc;
  border: 1.5px solid #6366f1;
  border-radius: 12px;
  padding: 16px;
  margin: 4px 0;
}
.edit-card-header {
  font-weight: 600;
  font-size: 14px;
  color: #4338ca;
  margin-bottom: 12px;
}
.edit-section-title {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  margin: 12px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.edit-fields { display: flex; flex-direction: column; gap: 8px; }
.edit-label {
  font-size: 12px;
  font-weight: 500;
  color: #374151;
  margin-bottom: 2px;
}
.edit-textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  font-family: inherit;
  resize: vertical;
  background: #fff;
  color: #1f2937;
  box-sizing: border-box;
}
.edit-textarea:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}
.edit-textarea:disabled { background: #f3f4f6; color: #9ca3af; }
.edit-raw {
  font-size: 11px;
  background: #f3f4f6;
  border-radius: 6px;
  padding: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
