/* mark_tang · 育儿问答
 * 3 themes via [data-theme] attribute on <html>
 * - g: 工具感 (ChatGPT-style)  ← default
 * - e: 温暖 (Ghibli's Clinic)
 * - f: 医院 (Hospital Brutalism)
 *
 * 切换: localStorage.mt-theme, persisted across reloads
 */

* { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== Theme tokens (default = g) ===== */
:root,
[data-theme="g"] {
  --bg:        #FFFFFF;
  --bg-side:   #F9FAFB;
  --surface:   #FFFFFF;
  --surface-2: #F3F4F6;
  --border:    #E5E7EB;
  --border-strong: #D1D5DB;
  --text:      #111827;
  --text-2:    #6B7280;
  --text-3:    #9CA3AF;
  --accent:    #10A37F;
  --accent-hover: #0E906F;
  --accent-tint: rgba(16, 163, 127, 0.08);
  --accent-fg: #FFFFFF;
  --radius:    8px;
  --radius-sm: 6px;
  --radius-pill: 9999px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, monospace;
  --hero-h1-size: 22px;
  --shadow: none;
  --composer-bg: #FFFFFF;
  --composer-border: #E5E7EB;
}

[data-theme="e"] {
  --bg:        #FFF8F0;
  --bg-side:   #FFF8F0;
  --surface:   #FFFFFF;
  --surface-2: #FDEAE0;
  --border:    #F2D8C0;
  --border-strong: #E5C8A8;
  --text:      #3D3528;
  --text-2:    #8B7E6A;
  --text-3:    #C2B89E;
  --accent:    #E8896B;
  --accent-hover: #C56F4F;
  --accent-tint: #FDEAE0;
  --accent-fg: #FFFFFF;
  --accent-2:  #95B58A;
  --radius:    20px;
  --radius-sm: 14px;
  --radius-pill: 9999px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", Menlo, monospace;
  --hero-h1-size: 32px;
  --shadow: 0 4px 20px rgba(61, 53, 40, 0.06);
  --composer-bg: #FFFFFF;
  --composer-border: #F2D8C0;
}

[data-theme="f"] {
  --bg:        #FFFFFF;
  --bg-side:   #F8FAFB;
  --surface:   #FFFFFF;
  --surface-2: #EFF4FB;
  --border:    #E2E8F0;
  --border-strong: #CBD5E1;
  --text:      #0A2540;
  --text-2:    #4A5568;
  --text-3:    #94A3B8;
  --accent:    #1E40AF;
  --accent-hover: #1A3691;
  --accent-tint: #EFF4FB;
  --accent-fg: #FFFFFF;
  --radius:    4px;
  --radius-sm: 3px;
  --radius-pill: 2px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, monospace;
  --hero-h1-size: 38px;
  --shadow: none;
  --composer-bg: #FFFFFF;
  --composer-border: #0A2540;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.2s ease, color 0.2s ease;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  transition: border-color 0.2s, background 0.2s;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}
.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transition: background 0.2s;
}
.brand-name { font-weight: 600; }
.brand-divider { color: var(--text-3); font-weight: 300; }
.brand-tag { color: var(--text-2); }

.nav { display: flex; align-items: center; gap: 12px; }

/* ===== Theme switcher (always-on top right) ===== */
.theme-switch {
  display: inline-flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 2px;
  border: 1px solid var(--border);
}
.theme-btn {
  background: transparent;
  border: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 14px;
  transition: background 0.15s, transform 0.1s;
  font-family: inherit;
  padding: 0;
  opacity: 0.55;
}
.theme-btn:hover { opacity: 1; }
.theme-btn:active { transform: scale(0.92); }
.theme-btn[aria-pressed="true"],
html:not([data-theme]) .theme-btn[data-theme="g"] {
  background: var(--bg);
  opacity: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
html[data-theme="e"] .theme-btn[data-theme="e"],
html[data-theme="f"] .theme-btn[data-theme="f"],
html[data-theme="g"] .theme-btn[data-theme="g"] {
  background: var(--bg);
  opacity: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.t-emoji { line-height: 1; pointer-events: none; }

.nav-link {
  font-size: 13px;
  color: var(--text-2);
  text-decoration: none;
  transition: color 0.15s;
}
.nav-link:hover { color: var(--text); }
.install-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  padding: 4px 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.install-link:hover { background: var(--accent); color: var(--accent-fg); }

/* ===== Page ===== */
.page {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 28px 24px;
  transition: max-width 0.2s;
}

/* ===== Hero ===== */
.hero { margin-bottom: 32px; }
.hero-title {
  font-size: var(--hero-h1-size);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
  line-height: 1.2;
  transition: font-size 0.2s;
}
.hero-sub {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
}

/* ===== Examples ===== */
.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.example {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.example:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== Chat Card ===== */
.chat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s, border-color 0.2s;
}

/* ===== Messages ===== */
.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 56vh;
  min-height: 60px;
  overflow-y: auto;
  margin-bottom: 16px;
  padding: 4px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg { display: flex; flex-direction: column; gap: 6px; }
.msg-user { align-items: flex-end; }
.msg-user .bubble {
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--radius);
  max-width: 78%;
  font-size: 14px;
  padding: 8px 12px;
}
.msg-assistant .bubble {
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius);
  max-width: 92%;
  font-size: 14px;
  padding: 8px 12px;
  line-height: 1.7;
}
.msg-assistant .bubble strong { font-weight: 600; }
.msg-info .bubble, .msg-empty .bubble {
  background: transparent;
  color: var(--text-3);
  font-size: 13px;
  padding: 12px 0 0;
  text-align: center;
}
.msg-error .bubble {
  background: #FEF2F2;
  color: #B91C1C;
  border: 1px solid #FECACA;
  border-radius: var(--radius);
  font-size: 13px;
  padding: 8px 12px;
  max-width: 92%;
}

.bubble {
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  transition: background 0.2s, color 0.2s, border-radius 0.2s;
}

/* ===== Citations ===== */
.citations {
  margin: 4px 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 92%;
}
.cite-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.cite-item {
  display: flex;
  gap: 8px;
  font-size: 13px;
  padding: 6px 0;
}
.cite-num {
  font-weight: 600;
  color: var(--accent);
  min-width: 22px;
  flex-shrink: 0;
  font-family: var(--font-mono);
  transition: color 0.2s;
}
.cite-body { flex: 1; min-width: 0; }
.cite-title-line {
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
  line-height: 1.4;
  word-break: break-word;
}
.cite-source {
  font-weight: 400;
  color: var(--text-3);
  font-size: 11px;
  margin-left: 4px;
}
.cite-snippet {
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
}
.cite-snippet-empty { font-style: italic; color: var(--text-3); }

.trust-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
  background: var(--accent-tint);
  color: var(--accent);
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  vertical-align: 1px;
  transition: background 0.2s, color 0.2s;
}
.trust-0 { background: var(--surface-2); color: var(--text-3); }
.trust-2 { background: var(--accent-tint); color: var(--accent); }
.trust-3 { background: var(--text); color: var(--bg); }

.cite-toggle {
  display: inline-block;
  margin-top: 4px;
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
}
.cite-toggle:hover { color: var(--accent-hover); }

/* ===== Sticky Composer (常驻底部) ===== */
.composer {
  position: sticky;
  bottom: 0;
  z-index: 50;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 14px 24px 18px;
  margin: 0 -24px -24px;
  transition: background 0.2s, border-color 0.2s;
}
.composer-row {
  max-width: 904px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 6px 6px 12px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.04);
  transition: border-color 0.15s, background 0.2s;
}
.composer-row:focus-within {
  border-color: var(--accent);
}
.composer-row textarea {
  flex: 1;
  background: transparent;
  border: 0;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  outline: none;
  resize: none;
  min-height: 32px;
  max-height: 140px;
  line-height: 1.5;
  padding: 6px 0;
}
.composer-row textarea::placeholder { color: var(--text-3); }

.composer-row button {
  background: var(--accent);
  color: var(--accent-fg);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 16px;
  height: 32px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.composer-row button:hover:not(:disabled) { background: var(--accent-hover); }
.composer-row button:active:not(:disabled) { transform: translateY(0.5px); }
.composer-row button:disabled {
  background: var(--text-3);
  cursor: not-allowed;
  opacity: 0.6;
}

/* ===== Status ===== */
.status {
  margin-top: 10px;
  font-size: 12px;
  text-align: center;
  color: var(--text-3);
  min-height: 16px;
  font-family: var(--font-mono);
}
.status-loading { color: var(--accent); }
.status-ok { color: var(--text-2); }
.status-err { color: #B91C1C; }

/* ===== Meta ===== */
.meta {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 32px;
  padding: 16px 0;
  font-size: 12px;
  color: var(--text-3);
  flex-wrap: wrap;
}
.meta-sep { color: var(--border-strong); }

/* ===== Theme-specific tweaks ===== */

/* Theme e (Ghibli): big radius, soft shadow, welcome emoji in hero */
[data-theme="e"] .hero-title::before {
  content: "🌿 ";
}
[data-theme="e"] .msg-user .bubble {
  border-radius: 18px 18px 4px 18px;
}
[data-theme="e"] .msg-assistant .bubble {
  border-radius: 18px 18px 18px 4px;
}
[data-theme="e"] .chat-card {
  border-width: 0;
}
[data-theme="e"] .hero::after {
  content: "👋 欢迎";
  display: block;
  font-size: 28px;
  margin-bottom: 4px;
}

/* Theme f (Hospital): mono labels, big section gaps, sharp corners */
[data-theme="f"] .hero {
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}
[data-theme="f"] .hero::before {
  content: "MARK_TANG · 育儿问答";
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--accent);
  margin-bottom: 16px;
  text-transform: uppercase;
  font-weight: 600;
}
[data-theme="f"] .cite-title,
[data-theme="f"] .status,
[data-theme="f"] .meta {
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
[data-theme="f"] .composer {
  border-top-width: 2px;
}
[data-theme="f"] .composer textarea {
  border-width: 1.5px;
  border-color: var(--text);
}
[data-theme="f"] .composer button {
  border-radius: 4px;
}
[data-theme="f"] .msg-user .bubble,
[data-theme="f"] .msg-assistant .bubble {
  border-radius: 4px;
}

/* Theme g (ChatGPT): default — no extra rules */
[data-theme="g"] .hero::before {
  content: "";
}

/* ===== Mobile ===== */
@media (max-width: 640px) {
  .page { padding: 32px 16px 16px; }
  .topbar { padding: 12px 16px; }
  .hero-title { font-size: 24px; }
  [data-theme="e"] .hero-title { font-size: 28px; }
  [data-theme="f"] .hero-title { font-size: 28px; }
  .chat-card { padding: 16px; }
  .composer { padding: 12px 16px 14px; margin: 0 -16px -16px; }
  .msg-user .bubble, .msg-assistant .bubble { max-width: 88%; font-size: 14px; }
  .meta { font-size: 11px; }
  .theme-btn { width: 26px; height: 26px; font-size: 13px; }
}

/* ===== Large desktop: 给大屏更多宽度 (避免 960 在 1920 上太窄) ===== */
@media (min-width: 1280px) {
  .page { max-width: 1080px; }
  .composer-row { max-width: 1024px; }
}
