/* ============================================================
 * 墨间 · 样式表
 * 设计基调：旧纸、墨、一点点赭石。
 * 全部组件类都在这里定义，模块只允许使用这些类。
 * ============================================================ */

/* ---------- 主题变量 ---------- */

:root {
  --bg: #f3ede2;
  --bg-grad-1: #f7f2e9;
  --bg-grad-2: #ece3d4;
  --paper: #fffdf7;
  --paper-2: #faf6ec;
  --ink: #2c2823;
  --ink-2: #6a6156;
  --ink-3: #9c9284;
  --line: #ddd3c2;
  --line-soft: #e9e1d3;
  --accent: #8b5e3c;
  --accent-ink: #ffffff;
  --accent-soft: rgba(139, 94, 60, 0.10);
  --accent-line: rgba(139, 94, 60, 0.30);
  --danger: #a8453a;
  --ok: #4f7a52;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-1: 0 1px 2px rgba(90, 70, 45, 0.05);
  --shadow-2: 0 10px 30px -14px rgba(90, 70, 45, 0.28);
  --font-serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", Georgia, serif;
  --font-sans: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans SC", -apple-system, Segoe UI, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", Consolas, "SF Mono", monospace;
  --editor-font: var(--font-serif);
  --maxw: 940px;
}

[data-theme="night"] {
  --bg: #191817;
  --bg-grad-1: #201e1c;
  --bg-grad-2: #141312;
  --paper: #262421;
  --paper-2: #2b2925;
  --ink: #e9e2d5;
  --ink-2: #b0a696;
  --ink-3: #7d7466;
  --line: #3b3733;
  --line-soft: #322f2b;
  --accent-soft: rgba(200, 150, 110, 0.14);
  --accent-line: rgba(200, 150, 110, 0.34);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 12px 34px -16px rgba(0, 0, 0, 0.8);
}

[data-theme="green"] {
  --bg: #e8ede4;
  --bg-grad-1: #eef2ea;
  --bg-grad-2: #dfe7da;
  --paper: #fbfcf8;
  --paper-2: #f4f7f0;
  --ink: #2b3229;
  --ink-2: #5f6b5b;
  --ink-3: #8e9a88;
  --line: #d3ddcd;
  --line-soft: #e2e9dd;
  --accent: #5a7a52;
  --accent-soft: rgba(90, 122, 82, 0.10);
  --accent-line: rgba(90, 122, 82, 0.30);
}

[data-font="sans"] { --editor-font: var(--font-sans); }

/* ---------- 基础 ---------- */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  background-image: linear-gradient(170deg, var(--bg-grad-1) 0%, var(--bg-grad-2) 100%);
  background-attachment: fixed;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 纸面纹理：极细噪点，纯 CSS */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(139, 94, 60, 0.05), transparent 42%),
    radial-gradient(circle at 88% 82%, rgba(139, 94, 60, 0.045), transparent 46%);
}

#app { position: relative; z-index: 1; min-height: 100%; display: flex; flex-direction: column; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.35; font-family: var(--font-serif); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-soft); }

/* ---------- 布局 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--line-soft);
}

.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  letter-spacing: 0;
}
.brand-sub { font-size: 11px; color: var(--ink-3); letter-spacing: 0.12em; font-family: var(--font-sans); }

.nav { display: flex; gap: 2px; margin-left: auto; }
.nav a {
  padding: 6px 13px;
  border-radius: 999px;
  color: var(--ink-2);
  font-size: 13.5px;
  text-decoration: none;
  transition: background 0.16s, color 0.16s;
}
.nav a:hover { background: var(--accent-soft); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--accent); color: var(--accent-ink); }

.main {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 26px 20px 64px;
}

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; letter-spacing: 0.04em; }
.page-sub { color: var(--ink-3); font-size: 13px; }

.footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 20px 30px;
  color: var(--ink-3);
  font-size: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  border-top: 1px solid var(--line-soft);
}

/* 页脚的云端同步状态 */
.sync-badge {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.02em;
  transition: color 0.2s;
}
.sync-badge[data-state="syncing"] { color: var(--accent); }
.sync-badge[data-state="error"] { color: var(--danger); }

/* 通用 flex */
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.mt-lg { margin-top: 24px; }
.mb { margin-bottom: 12px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 268px;
  gap: 18px;
  align-items: start;
}

@media (max-width: 780px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding: 18px 14px 50px; }
  .brand-sub { display: none; }
}
@media (max-width: 520px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .nav a { padding: 6px 10px; font-size: 13px; }
}

/* ---------- 面板 ---------- */

.panel {
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-1);
}
.panel-tight { padding: 0; overflow: hidden; }
.panel-hover { transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease; }
.panel-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--line); }

.divider { height: 1px; background: var(--line-soft); margin: 16px 0; border: 0; }

/* ---------- 文字 ---------- */

.h1 { font-size: 24px; }
.h2 { font-size: 19px; }
.h3 { font-size: 15px; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tag {
  display: inline-block;
  padding: 1px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--ink-2);
  background: var(--paper-2);
  line-height: 1.75;
}
.empty {
  padding: 26px 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-3);
  text-align: center;
  font-size: 13px;
}

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper-2);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.06s, color 0.15s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); filter: brightness(1.07); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--ink); border-color: transparent; }

.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: var(--danger); }

.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-lg { padding: 11px 24px; font-size: 15px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- 表单 ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; color: var(--ink-2); letter-spacing: 0.02em; }

.input, .textarea, .select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.select {
  appearance: none;
  cursor: pointer;
  padding-right: 30px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%239c9284' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 11px center;
}

.textarea { resize: vertical; min-height: 120px; }

.writer {
  min-height: 46vh;
  padding: 22px 24px;
  font-family: var(--editor-font);
  font-size: 16.5px;
  line-height: 2;
  letter-spacing: 0.02em;
  background: var(--paper);
  border-color: var(--line-soft);
  resize: none;
}
.writer:focus { border-color: var(--accent-line); box-shadow: none; }
.writer::placeholder { color: var(--ink-3); opacity: 0.75; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--accent-line); color: var(--ink); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- 题目 ---------- */

.prompt-box {
  position: relative;
  padding: 14px 16px 14px 20px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
  font-family: var(--font-serif);
  font-size: 15.5px;
  line-height: 1.8;
  color: var(--ink);
}
.prompt-box .prompt-hint {
  display: block;
  margin-top: 6px;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink-2);
  letter-spacing: 0.01em;
}
.prompt-box .prompt-label {
  display: block;
  font-family: var(--font-sans);
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.16em;
  margin-bottom: 6px;
}

/* ---------- 计时器 ---------- */

.timer { text-align: center; }
.timer-num {
  font-family: var(--font-mono);
  font-size: 52px;
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.timer.urgent .timer-num { color: var(--danger); }
.timer-label { font-size: 12px; color: var(--ink-3); letter-spacing: 0.14em; margin-top: 4px; }

/* ---------- 统计 ---------- */

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-num {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 400;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.stat-label { font-size: 12px; color: var(--ink-3); letter-spacing: 0.05em; }

.meter { height: 6px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.5s ease; }

/* ---------- 列表 ---------- */

.list { display: flex; flex-direction: column; }
.list-item {
  padding: 12px 2px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.list-item:last-child { border-bottom: 0; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-size: 14px; color: var(--ink); margin-bottom: 2px; }
.list-item-meta { font-size: 11.5px; color: var(--ink-3); font-family: var(--font-mono); }
.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- 首页模块卡 ---------- */

.mod-card { display: flex; flex-direction: column; gap: 8px; height: 100%; }
.mod-card-top { display: flex; align-items: center; gap: 9px; }
.mod-icon {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  font-size: 17px;
  flex: none;
}
.mod-name { font-family: var(--font-serif); font-size: 16px; letter-spacing: 0.03em; }
.mod-tagline { color: var(--ink-2); font-size: 12.5px; line-height: 1.55; flex: 1; }
.mod-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }

/* ---------- 弹窗 / toast ---------- */

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(40, 30, 20, 0.28);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade 0.16s ease;
}
.modal {
  width: min(420px, 100%);
  background: var(--paper);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-2);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-msg { font-size: 14.5px; line-height: 1.7; white-space: pre-wrap; }

.toast-wrap {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}
.toast {
  padding: 9px 15px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  box-shadow: var(--shadow-2);
  animation: toastIn 0.22s ease;
  max-width: 78vw;
}
.toast-ok { background: var(--ok); color: #fff; }
.toast-warn { background: var(--danger); color: #fff; }
.toast-out { opacity: 0; transform: translateY(4px); transition: all 0.35s ease; }

@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.fade-in { animation: fadeUp 0.3s ease both; }

/* ---------- 杂项 ---------- */

.kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--paper-2);
  color: var(--ink-2);
}

.scroll-y { max-height: 420px; overflow-y: auto; }

/* 打印：把写作内容干净地印出来 */
@media print {
  .topbar, .nav, .btn, .btn-row, .toast-wrap { display: none !important; }
  body { background: #fff; }
  .panel { box-shadow: none; border-color: #ddd; }
}
