/* ============ 随笔点评 · 全局样式 ============ */
:root {
  --bg: #f6f1e7;
  --card: #fffdf8;
  --ink: #3d3628;
  --ink-soft: #8a7f6a;
  --line: #e8dfce;
  --accent: #b3562e;
  --accent-dark: #93441f;
  --accent-soft: #f4e3d6;
  --green: #2e6e5e;
  --green-soft: #e1eeea;
  --danger: #b0433f;
  --danger-soft: #f6e3e1;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(61, 54, 40, .08);
}

/* ---------- 深色模式 ---------- */
body.dark {
  --bg: #1c1915;
  --card: #262219;
  --ink: #e9e1d2;
  --ink-soft: #a29682;
  --line: #3b342a;
  --accent: #d98a5f;
  --accent-dark: #b56a42;
  --accent-soft: #4a3323;
  --green: #6fae9d;
  --green-soft: #2a3d37;
  --danger: #e0827d;
  --danger-soft: #4a2a28;
  --shadow: 0 2px 10px rgba(0, 0, 0, .3);
}

body.dark .topbar {
  background: rgba(28, 25, 21, .92);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 52px;
  padding: 0 12px;
  background: rgba(246, 241, 231, .92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar .title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 2px;
}

.topbar .spacer { flex: 1; }

.topbar .back {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 30px;
  line-height: 1;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
}

.topbar .back:active { background: var(--accent-soft); }

/* ---------- 页面主体 ---------- */
.app {
  padding: 14px 14px 96px;
  max-width: 560px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.hint {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.7;
  margin: 0 0 10px;
}

.tag-optional {
  font-size: 11px;
  font-weight: 400;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 99px;
  padding: 2px 8px;
  vertical-align: 2px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  user-select: none;
  transition: transform .05s ease, opacity .15s ease;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; }

.btn-block { width: 100%; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:active { background: var(--accent-dark); }

.btn-ghost {
  border-color: var(--line);
  background: var(--card);
}

.btn-danger-ghost {
  border-color: var(--line);
  color: var(--danger);
  background: var(--card);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-file { position: relative; overflow: hidden; }
.btn-file input { position: absolute; left: -9999px; opacity: 0; }

.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.row-btns .btn { flex: 1; }

.actions-card {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions-card .btn { flex: 1; }

/* ---------- 搜索栏 ---------- */
.searchbar input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 15px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}

.searchbar input:focus { border-color: var(--accent); }

.searchbar { margin-bottom: 12px; }

.section-actions { margin-bottom: 12px; }
.section-actions .btn { margin-bottom: 8px; }

/* ---------- 导入 ---------- */
.import-card .divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-soft);
  font-size: 12px;
  margin: 14px 0;
}

.import-card .divider::before,
.import-card .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.import-paste-content {
  width: 100%;
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.7;
  background: var(--card);
  color: var(--ink);
  outline: none;
  resize: vertical;
  font-family: inherit;
}

.import-paste-content:focus { border-color: var(--accent); }

/* ---------- 作品列表 ---------- */
.work-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.work-main { display: block; text-decoration: none; color: inherit; }

.work-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}

.work-meta {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.work-excerpt {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.7;
  margin-top: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.work-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* ---------- 专栏 ---------- */
.archive-summary {
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
  margin: 4px 0 14px;
}

.archive-month {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin: 18px 2px 8px;
}

.archive-month::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.archive-item {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
}

.archive-item-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.empty .btn { margin-top: 14px; }

/* ---------- 徽章 / 主题标签 ---------- */
.chip {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 12px;
}

.chip-sm { font-size: 11px; padding: 2px 8px; }

.chip-green {
  background: var(--green-soft);
  color: var(--green);
}

.topic-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--green-soft);
  color: var(--green);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 13px;
  margin-bottom: 10px;
}

.chip-x {
  border: none;
  background: transparent;
  color: var(--green);
  font-size: 13px;
  cursor: pointer;
  padding: 0 2px;
}

/* ---------- 空状态 ---------- */
.empty {
  text-align: center;
  padding: 52px 22px;
  color: var(--ink-soft);
  line-height: 1.9;
}

.empty .empty-ico { font-size: 46px; display: block; margin-bottom: 10px; }

/* ---------- 分类筛选 ---------- */
.cat-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.cat-chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-soft);
  border-radius: 99px;
  padding: 6px 13px;
  font-size: 13px;
  cursor: pointer;
}

.cat-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ---------- 灵感页 ---------- */
.topic-card {
  text-align: center;
  padding: 38px 22px 30px;
  background: linear-gradient(150deg, var(--accent), var(--green));
  border-radius: var(--radius);
  color: #fff;
  box-shadow: 0 6px 18px rgba(61, 54, 40, .18);
  margin-bottom: 14px;
}

.topic-card .topic-cat {
  display: inline-block;
  font-size: 12px;
  background: rgba(255, 255, 255, .22);
  border-radius: 99px;
  padding: 3px 12px;
  margin-bottom: 16px;
}

.topic-card .topic-text {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.6;
  margin: 0;
}

.topic-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.topic-btns .wide { grid-column: 1 / -1; }

.topic-btns .btn {
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .45);
  color: #fff;
}

.custom-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.custom-form input[type="text"] {
  flex: 1;
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}

.custom-form select {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 8px;
  font-size: 14px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}

.custom-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.custom-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}

.custom-item .grow { flex: 1; line-height: 1.5; }

.custom-item .del {
  border: none;
  background: transparent;
  color: var(--danger);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
}

.custom-item .del:active { background: var(--danger-soft); }

.ai-topic-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.ai-topic-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}

.ai-topic-form input:focus { border-color: var(--accent); }

.ai-topic-result {
  background: var(--green-soft);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.ai-topic-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.6;
  color: var(--green);
}

.ai-topic-tip {
  font-size: 13px;
  line-height: 1.8;
  color: var(--ink);
  margin-top: 6px;
  white-space: pre-wrap;
}

/* ---------- 编辑器 ---------- */
.editor-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 96px;
}

.ai-editor-row {
  display: flex;
  gap: 8px;
}

.ai-editor-row .btn { flex: 1; }

.ed-title {
  font-size: 20px;
  font-weight: 700;
  border: none;
  outline: none;
  background: transparent;
  padding: 4px 2px 8px;
  border-bottom: 2px solid var(--line);
  color: var(--ink);
}

.ed-content {
  width: 100%;
  min-height: 55vh;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 16px;
  line-height: 1.9;
  font-family: "Songti SC", "SimSun", "Noto Serif SC", serif;
  padding: 6px 2px;
  color: var(--ink);
}

.editor-foot {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.editor-foot .count {
  font-size: 12px;
  color: var(--ink-soft);
}

/* ---------- 作品详情 ---------- */
.work-detail h1 {
  font-size: 22px;
  line-height: 1.5;
  margin: 0 0 8px;
}

.work-body p {
  line-height: 2;
  text-indent: 2em;
  margin: 0 0 1em;
  font-family: "Songti SC", "SimSun", "Noto Serif SC", serif;
  font-size: 16.5px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stat {
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 4px;
  text-align: center;
}

.stat b {
  display: block;
  font-size: 18px;
  color: var(--accent);
}

.stat span {
  font-size: 11px;
  color: var(--ink-soft);
}

.stat-words { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.stat-words .label { font-size: 13px; color: var(--ink-soft); }

/* ---------- AI 点评 ---------- */
.ai-result {
  background: var(--green-soft);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.9;
  margin-bottom: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-modes {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.ai-mode {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-soft);
  border-radius: 12px;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.ai-mode.active {
  background: var(--green-soft);
  color: var(--green);
  border-color: var(--green);
}

.btn-copy { margin-top: 10px; }

.portrait-meta {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 8px;
}

.ai-loading, .ai-error {
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 10px;
  line-height: 1.7;
}

.ai-loading { background: var(--bg); color: var(--ink-soft); }
.ai-error { background: var(--danger-soft); color: var(--danger); }

/* ---------- 设置表单 ---------- */
.field {
  display: block;
  margin-bottom: 12px;
}

.field span {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}

.field input:focus { border-color: var(--accent); }

.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}

.field select:focus { border-color: var(--accent); }

#setTestResult { margin-top: 10px; font-size: 13px; line-height: 1.7; }

/* ---------- 个人资料 ---------- */
.profile-row {
  display: flex;
  gap: 14px;
  align-items: center;
}

.avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-fields input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}

.profile-fields input:focus { border-color: var(--accent); }

.profile-banner {
  display: flex;
  align-items: center;
  gap: 14px;
}

.profile-banner .avatar {
  width: 56px;
  height: 56px;
  font-size: 26px;
}

.profile-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 3px;
}

.profile-info .work-meta { margin-bottom: 0; }

/* ---------- 拾遗 ---------- */
.revisit-box {
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.revisit-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.revisit-preview {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.7;
  margin-top: 8px;
}

/* ---------- 统计 ---------- */
.stat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-card b {
  display: block;
  font-size: 22px;
  color: var(--accent);
}

.stat-card span {
  font-size: 12px;
  color: var(--ink-soft);
}

/* ---------- 写作日历 ---------- */
.cal-grid {
  display: grid;
  grid-template-columns: 26px repeat(17, 12px);
  gap: 3px;
  overflow-x: auto;
}

.cal-month-row { margin-bottom: 5px; }

.cal-month {
  font-size: 10px;
  color: var(--ink-soft);
  white-space: nowrap;
  align-self: end;
}

.cal-day-label {
  font-size: 10px;
  color: var(--ink-soft);
  line-height: 12px;
}

.cal-cell {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--bg);
}

.cal-cell.today { outline: 2px solid var(--accent); }

.cal-lv1 { background: #d9ebdf; }
.cal-lv2 { background: #a8d6b8; }
.cal-lv3 { background: #67b286; }
.cal-lv4 { background: #2f8f5d; }

body.dark .cal-lv1 { background: #2c4a3d; }
body.dark .cal-lv2 { background: #356349; }
body.dark .cal-lv3 { background: #3f7d56; }
body.dark .cal-lv4 { background: #55a877; }

.cal-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 10px;
  color: var(--ink-soft);
}

.cal-legend span.cal-lv1,
.cal-legend span.cal-lv2,
.cal-legend span.cal-lv3,
.cal-legend span.cal-lv4 {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.month-chart {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.month-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-soft);
}

.month-row .month-label { width: 34px; flex-shrink: 0; }

.month-row .bar-track {
  flex: 1;
  height: 10px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
}

.month-row .bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 99px;
}

.month-row .month-num {
  width: 48px;
  text-align: right;
  flex-shrink: 0;
}

.top-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.top-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}

.top-item .grow {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: inherit;
  text-decoration: none;
}

.top-item .work-meta { margin: 0; flex-shrink: 0; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 560px;
  margin: 0 auto;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 11px;
}

.tab .tab-ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); font-weight: 600; }

/* ---------- 提示 ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 86px;
  transform: translate(-50%, 14px);
  background: rgba(61, 54, 40, .92);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 99px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 99;
  max-width: 86vw;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
