/* ============ 设计令牌 ============ */
:root {
  --font-sans: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Source Han Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Songti SC", "Source Han Serif SC", "Noto Serif CJK SC", "SimSun", Georgia, serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, Menlo, monospace;

  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 999px;

  --t-fast: 130ms cubic-bezier(.4, 0, .2, 1);
  --t-mid: 240ms cubic-bezier(.4, 0, .2, 1);
  --t-slow: 420ms cubic-bezier(.16, 1, .3, 1);

  --sidebar-w: 264px;
  --aipanel-w: 372px;
  --topbar-h: 56px;

  /* 主题色相（由 data-scheme 覆盖，下方主色全部由此派生） */
  --p-h: 242;
  --p-s: 62%;
  --a-h: 340;
}

/* ---------- 配色方案 ---------- */
[data-scheme="violet"] { --p-h: 242; --p-s: 62%; --a-h: 340; }          /* 靛紫 · 默认 */
[data-scheme="cinnabar"] { --p-h: 356; --p-s: 64%; --a-h: 214; }        /* 朱砂 */
[data-scheme="pine"] { --p-h: 163; --p-s: 42%; --a-h: 34; }             /* 松墨 */
[data-scheme="mist"] { --p-h: 212; --p-s: 32%; --a-h: 172; }            /* 远山 */
[data-scheme="orchid"] { --p-h: 292; --p-s: 48%; --a-h: 320; }          /* 幽兰 */
[data-scheme="paper"] { --p-h: 26; --p-s: 46%; --a-h: 8; }              /* 宣纸 · 暖中性 */

/* 浅色（默认） */
[data-theme="light"] {
  --bg: #f4f5fa;
  --bg-grad: radial-gradient(1200px 600px at 12% -10%, #ece9ff 0%, transparent 60%),
             radial-gradient(1000px 520px at 92% 8%, #e6f4ff 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --surface-3: #eef0f7;
  --surface-inset: #f2f3f9;
  --border: #e4e6f0;
  --border-strong: #d3d7e6;
  --text: #1b1e2b;
  --text-2: #545a70;
  --text-3: #8b91a6;
  --primary: hsl(var(--p-h), var(--p-s), 55%);
  --primary-hover: hsl(var(--p-h), var(--p-s), 47%);
  --primary-soft: hsl(var(--p-h), var(--p-s), 96%);
  --primary-ring: hsla(var(--p-h), var(--p-s), 55%, .18);
  --accent: hsl(var(--a-h), 62%, 51%);
  --accent-soft: hsl(var(--a-h), 62%, 96%);
  --success: #18985c;
  --success-soft: #e7f7ee;
  --warn: #c98a10;
  --warn-soft: #fdf4e0;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --gold: #b8860b;
  --shadow-sm: 0 1px 2px rgba(24, 28, 48, .05), 0 1px 3px rgba(24, 28, 48, .04);
  --shadow-md: 0 4px 14px rgba(24, 28, 48, .07), 0 1px 3px rgba(24, 28, 48, .05);
  --shadow-lg: 0 18px 48px rgba(24, 28, 48, .13), 0 4px 12px rgba(24, 28, 48, .06);
  --scroll: #cbcfdd;
  --scroll-hover: #a8adc2;
}

/* 深色 */
[data-theme="dark"] {
  --bg: #101219;
  --bg-grad: radial-gradient(1100px 560px at 10% -12%, #221f3d 0%, transparent 60%),
             radial-gradient(900px 480px at 92% 6%, #16283a 0%, transparent 55%);
  --surface: #191c26;
  --surface-2: #1f2330;
  --surface-3: #262b3a;
  --surface-inset: #14161f;
  --border: #2a2f3d;
  --border-strong: #3a4152;
  --text: #e8eaf3;
  --text-2: #a7adc2;
  --text-3: #727a92;
  --primary: hsl(var(--p-h), var(--p-s), 72%);
  --primary-hover: hsl(var(--p-h), var(--p-s), 80%);
  --primary-soft: hsl(var(--p-h), 38%, 21%);
  --primary-ring: hsla(var(--p-h), var(--p-s), 72%, .26);
  --accent: hsl(var(--a-h), 68%, 70%);
  --accent-soft: hsl(var(--a-h), 45%, 22%);
  --success: #45c98a;
  --success-soft: #16301f;
  --warn: #e0ad4e;
  --warn-soft: #33291a;
  --danger: #ef6a6a;
  --danger-soft: #381f21;
  --gold: #d9a83a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .35);
  --shadow-lg: 0 22px 56px rgba(0, 0, 0, .5);
  --scroll: #3a4152;
  --scroll-hover: #4d566b;
}

/* 宣纸方案：暖中性背景（浅/深各一套） */
[data-theme="light"][data-scheme="paper"] {
  --bg: #f5f1e8;
  --bg-grad: radial-gradient(1200px 600px at 12% -10%, #f0e6d3 0%, transparent 60%),
             radial-gradient(1000px 520px at 92% 8%, #eceadd 0%, transparent 55%);
  --surface: #fffdf8;
  --surface-2: #faf6ed;
  --surface-3: #f2ece0;
  --surface-inset: #f9f5ec;
  --border: #e8dfcd;
  --border-strong: #d7cbaf;
  --text: #2c241a;
  --text-2: #5f5545;
  --text-3: #968a72;
  --scroll: #d5c9b2;
  --scroll-hover: #b8a986;
}
[data-theme="dark"][data-scheme="paper"] {
  --bg: #14120d;
  --bg-grad: radial-gradient(1100px 560px at 10% -12%, #2a2317 0%, transparent 60%),
             radial-gradient(900px 480px at 92% 6%, #241f16 0%, transparent 55%);
  --surface: #1c1913;
  --surface-2: #231f18;
  --surface-3: #2b261c;
  --surface-inset: #191610;
  --border: #3a3325;
  --border-strong: #4c422f;
  --text: #ece3d1;
  --text-2: #a99e86;
  --text-3: #7d725b;
  --scroll: #453c2b;
  --scroll-hover: #5c5138;
}

/* ============ 重置 ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}
h1, h2, h3, h4, h5, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; padding: 0; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-hover); background-clip: content-box; }

/* ============ 通用组件 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px; font-weight: 500;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast), color var(--t-fast);
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn svg { width: 15px; height: 15px; flex: none; }

.btn-primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
  box-shadow: 0 2px 8px var(--primary-ring);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }

.btn-soft { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.btn-soft:hover { background: var(--primary-ring); border-color: transparent; color: var(--primary); }

.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; color: var(--text); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: var(--r-xs); }
.btn-sm svg { width: 13px; height: 13px; }
.btn-lg { height: 42px; padding: 0 22px; font-size: 14px; border-radius: var(--r-md); }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }
.btn-block { width: 100%; }

.input, .textarea, .select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  color: var(--text);
  font-size: 13px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--primary); background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.textarea { resize: vertical; min-height: 90px; line-height: 1.7; font-family: inherit; }
.select { cursor: pointer; appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b91a6' stroke-width='3'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 11px center;
}
.field { margin-bottom: 14px; }
.field-label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); letter-spacing: .02em; }
.field-hint { margin-top: 5px; font-size: 11.5px; color: var(--text-3); }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 8px;
  border-radius: var(--r-full);
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  background: var(--surface-3); color: var(--text-2);
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  font-size: 12px; color: var(--text-2);
  cursor: pointer;
  transition: all var(--t-fast);
}
.chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip-group { display: flex; flex-wrap: wrap; gap: 7px; }

.avatar-emoji {
  display: grid; place-items: center;
  border-radius: var(--r-md);
  font-size: 22px; line-height: 1;
}

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 60px 20px; text-align: center; color: var(--text-3);
}
.empty-icon { font-size: 42px; opacity: .6; }
.empty-title { font-size: 15px; font-weight: 600; color: var(--text-2); }
.empty-desc { font-size: 13px; max-width: 320px; }

.divider { height: 1px; background: var(--border); margin: 12px 0; }
.vdivider { width: 1px; align-self: stretch; background: var(--border); margin: 0 4px; }

.spinner {
  width: 15px; height: 15px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dot-typing { display: inline-flex; gap: 3px; align-items: center; }
.dot-typing i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: bounce 1.2s infinite; }
.dot-typing i:nth-child(2) { animation-delay: .18s; }
.dot-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-4px); opacity: 1; } }

/* 开关 */
.switch { position: relative; width: 38px; height: 22px; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider {
  position: absolute; inset: 0; border-radius: var(--r-full);
  background: var(--surface-3); border: 1px solid var(--border);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.switch .slider::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform var(--t-mid);
}
.switch input:checked + .slider { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* 提示气泡 */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%) scale(.94);
  padding: 5px 9px; border-radius: var(--r-xs);
  background: var(--text); color: var(--bg);
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: all var(--t-fast);
  z-index: 60;
}
.tip:hover::after { opacity: 1; transform: translateX(-50%) scale(1); }

/* 贴着容器顶边的工具条（顶栏 / 写作工具条）：默认向上弹，会被
   .app-shell 与 .view 的 overflow:hidden 直接裁掉 —— 悬停了也什么都看不到。
   这两处统一改成向下弹。 */
.topbar .tip::after, .writer-bar .tip::after { bottom: auto; top: calc(100% + 7px); }

/* ============ 模态框 ============ */
.modal-mask {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(16, 18, 28, .45);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn var(--t-fast);
}
.modal {
  width: 100%; max-width: 520px; max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: popIn var(--t-mid);
  overflow: hidden;
}
.modal-wide { max-width: 760px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 650; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2);
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(14px) scale(.97); } }

/* ============ Toast ============ */
.toast-root {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  border-radius: var(--r-full);
  background: var(--text); color: var(--bg);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn var(--t-mid);
  max-width: 78vw;
}
.toast.out { animation: toastOut var(--t-fast) forwards; }
.toast .icon { font-size: 14px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(.97); } }

/* 工具类 */
.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.col { display: flex; flex-direction: column; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text-3); }
.dim { color: var(--text-2); }
.small { font-size: 12px; }
.tiny { font-size: 11.5px; }
.mono { font-family: var(--font-mono); }
.bold { font-weight: 650; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
