/* ============================================================
   吾心日记 · 移动端 (PWA) styles
   设计：Mobile First，单手可达区
   ============================================================ */

:root {
  --c-bg: #faf7f2;
  --c-bg-soft: #f3ede3;
  --c-surface: #ffffff;
  --c-surface-alt: #fffbf3;
  --c-border: #ece2d3;
  --c-text: #3d362f;
  --c-text-soft: #7a6e60;
  --c-text-muted: #a89c8d;
  --c-primary: #b8865a;
  --c-primary-hover: #a07147;
  --c-primary-soft: #f7ecd9;
  --c-accent: #d4a574;
  --c-warn: #c96a5a;
  --c-success: #7ba37a;
  --c-shadow: rgba(100, 80, 60, 0.08);
  --c-shadow-hover: rgba(100, 80, 60, 0.18);

  --header-h: 56px;
  --tabbar-h: calc(64px + env(safe-area-inset-bottom));
  --fab-size: 60px;

  --radius-s: 10px;
  --radius-m: 14px;
  --radius-l: 20px;
  --radius-xl: 28px;

  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', 'PingFang SC', Georgia, serif;
  --font-xiaowei: 'ZCOOL XiaoWei', 'Noto Serif SC', serif;
}

[data-theme="dark"] {
  --c-bg: #1a1814;
  --c-bg-soft: #242019;
  --c-surface: #2a251d;
  --c-surface-alt: #302a21;
  --c-border: #3d3428;
  --c-text: #e8dfd3;
  --c-text-soft: #b5a99a;
  --c-text-muted: #7a6e60;
  --c-primary: #d4a574;
  --c-primary-hover: #e8bc8a;
  --c-primary-soft: #3d3024;
  --c-shadow: rgba(0, 0, 0, 0.35);
  --c-shadow-hover: rgba(0, 0, 0, 0.55);
}

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

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-serif);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.65;
  transition: background 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; -webkit-appearance: none; }
input, textarea, select { font-family: inherit; color: inherit; -webkit-appearance: none; }
img { max-width: 100%; display: block; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
  background: var(--c-bg);
  overflow: hidden;
}

/* ============================================================
   Header
   ============================================================ */
.app-header {
  flex: 0 0 var(--header-h);
  padding: 0 8px;
  padding-top: env(safe-area-inset-top);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
  z-index: 5;
}

.header-left { display: flex; justify-content: flex-start; }
.header-center { text-align: center; }
.header-right { display: flex; justify-content: flex-end; gap: 2px; }

.app-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.app-subtitle {
  font-size: 11px;
  color: var(--c-text-muted);
  margin-top: 1px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--c-text-soft);
  transition: background 0.15s;
}
.icon-btn:active { background: var(--c-bg-soft); }

/* ============================================================
   Main / Pages
   ============================================================ */
.app-main {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px calc(var(--tabbar-h) + 80px);
  scroll-behavior: smooth;
}

.page { display: none; animation: pageIn 0.22s ease; }
.page.active { display: block; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============================================================
   Hero card (Timeline top)
   ============================================================ */
.hero-card {
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-accent) 100%);
  color: white;
  border-radius: var(--radius-xl);
  padding: 22px 20px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 26px rgba(184, 134, 90, 0.3);
}
[data-theme="dark"] .hero-card { box-shadow: 0 8px 26px rgba(0,0,0,0.4); }

.hero-card::after {
  content: '';
  position: absolute;
  right: -40px;
  top: -40px;
  width: 160px;
  height: 160px;
  background: rgba(255,255,255,0.1);
  border-radius: 50%;
}

.hero-date { font-size: 13px; opacity: 0.9; letter-spacing: 0.5px; }
.hero-words {
  font-size: 20px;
  font-weight: 600;
  margin-top: 6px;
  line-height: 1.45;
  max-width: 80%;
}

.hero-write {
  margin-top: 16px;
  padding: 10px 18px;
  border-radius: 100px;
  background: white;
  color: var(--c-primary);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transition: transform 0.15s;
}
.hero-write:active { transform: scale(0.97); }
.hero-write-icon { font-size: 16px; }

/* ============================================================
   Timeline
   ============================================================ */
.timeline-wrapper { position: relative; padding-left: 26px; }
.timeline-wrapper::before {
  content: '';
  position: absolute;
  left: 9px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, transparent, var(--c-border) 10%, var(--c-border) 90%, transparent);
}

.timeline-group { margin-bottom: 26px; }

.timeline-date {
  position: sticky;
  top: -12px;
  background: var(--c-bg);
  padding: 6px 0 10px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  margin-left: -26px;
  padding-left: 26px;
}
.timeline-date::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}
.timeline-date-text { font-size: 15px; font-weight: 700; }
.timeline-date-count {
  font-size: 11px;
  color: var(--c-text-muted);
  background: var(--c-bg-soft);
  padding: 2px 8px;
  border-radius: 20px;
}

.entry-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-l);
  padding: 14px 14px 14px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.18s;
  position: relative;
  box-shadow: 0 2px 8px var(--c-shadow);
}
.entry-card:active { transform: scale(0.985); }
.entry-card::before {
  content: '';
  position: absolute;
  left: -23px;
  top: 18px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
}

.entry-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--c-text-muted);
  flex-wrap: wrap;
}
.meta-weather, .meta-mood { font-size: 14px; }
.meta-category {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.entry-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.4;
}
.entry-preview {
  font-size: 13.5px;
  color: var(--c-text-soft);
  line-height: 1.65;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}
.entry-tag {
  background: var(--c-bg-soft);
  color: var(--c-text-soft);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
}

.entry-images {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.entry-images img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-s);
}
.entry-images.more-1 { grid-template-columns: 1fr; }
.entry-images.more-2 { grid-template-columns: repeat(2, 1fr); }

/* ============================================================
   Empty state
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 50px 20px;
}
.empty-emoji { font-size: 56px; margin-bottom: 14px; opacity: 0.7; }
.empty-state h2 { font-size: 20px; margin-bottom: 8px; }
.empty-state p { font-size: 14px; color: var(--c-text-muted); margin-bottom: 24px; }
.btn-primary {
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
  color: white;
  padding: 12px 26px;
  border-radius: 100px;
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 16px rgba(184, 134, 90, 0.28);
  transition: transform 0.15s;
}
.btn-primary:active { transform: scale(0.97); }

/* ============================================================
   FAB + Tabbar
   ============================================================ */
.fab {
  position: fixed;
  right: calc(50% - min(320px, 50vw) + 18px);
  bottom: calc(var(--tabbar-h) - 18px + 8px);
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  box-shadow: 0 8px 22px rgba(184, 134, 90, 0.5);
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.93); }

/* 小屏幕优化 fab 位置 */
@media (max-width: 640px) {
  .fab { right: 18px; bottom: calc(var(--tabbar-h) - 18px + 8px); }
}

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 640px;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  align-items: stretch;
  z-index: 15;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.03);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10.5px;
  color: var(--c-text-muted);
  transition: color 0.15s;
  position: relative;
}
.tab.active { color: var(--c-primary); font-weight: 600; }
.tab-icon { font-size: 21px; }

.tab-write { position: relative; }
.tab-write-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 6px 16px rgba(184, 134, 90, 0.4);
  margin-bottom: 18px;
  transition: transform 0.15s;
}
.tab-write:active .tab-write-icon { transform: scale(0.92); }

/* ============================================================
   Calendar
   ============================================================ */
.calendar-container {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-l);
  padding: 16px 12px 18px;
  box-shadow: 0 2px 8px var(--c-shadow);
}
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  margin-bottom: 14px;
}
.calendar-header h2 { font-size: 17px; font-weight: 700; min-width: 110px; text-align: center; }
.cal-nav {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--c-bg-soft);
  font-size: 22px;
  color: var(--c-text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cal-nav:active { background: var(--c-primary-soft); color: var(--c-primary); }

.calendar-weekdays, .calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.calendar-weekdays { margin-bottom: 4px; }
.calendar-weekdays > div {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-muted);
  padding: 6px 0;
}
.calendar-weekdays > div:first-child,
.calendar-weekdays > div:last-child { color: var(--c-warn); }

.cal-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
  position: relative;
}
.cal-cell:active { background: var(--c-bg-soft); }
.cal-cell.other-month { color: var(--c-text-muted); opacity: 0.35; }
.cal-cell.today { background: var(--c-primary-soft); color: var(--c-primary); font-weight: 700; }
.cal-cell.has-entry::after {
  content: '';
  position: absolute;
  bottom: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--c-primary);
}
.cal-cell.selected {
  background: var(--c-primary);
  color: white;
  font-weight: 700;
}
.cal-cell.selected.has-entry::after { background: white; }
.cal-cell-entry-count { font-size: 9px; color: inherit; opacity: 0.7; margin-top: 1px; }

.cal-stats-row {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.cal-stat {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-m);
  padding: 12px 8px;
  text-align: center;
}
.cal-stat strong {
  display: block;
  font-size: 20px;
  color: var(--c-primary);
  font-weight: 700;
  margin-bottom: 2px;
}
.cal-stat span { font-size: 12px; color: var(--c-text-muted); }

.cal-day-detail {
  margin-top: 18px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-l);
  padding: 14px;
}
.cal-day-detail h3 {
  font-size: 15px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--c-border);
}

/* ============================================================
   Categories
   ============================================================ */
.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.category-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-l);
  padding: 18px 14px;
  cursor: pointer;
  transition: transform 0.15s;
  box-shadow: 0 2px 8px var(--c-shadow);
  position: relative;
  overflow: hidden;
}
.category-card:active { transform: scale(0.97); }
.category-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--c-primary), var(--c-accent));
  opacity: 0;
}
.category-card:active::before { opacity: 1; }
.category-icon { font-size: 32px; margin-bottom: 8px; }
.category-name { font-size: 16px; font-weight: 700; }
.category-count { font-size: 12px; color: var(--c-text-muted); margin-top: 2px; }
.category-latest {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--c-border);
  font-size: 11.5px;
  color: var(--c-text-soft);
  line-height: 1.5;
}

/* ============================================================
   Search
   ============================================================ */
.search-box {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search-box input, .search-box select {
  padding: 11px 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-m);
  background: var(--c-surface);
  font-size: 14px;
  min-height: 44px;
}
.search-box input { flex: 1; }
.search-box input:focus, .search-box select:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}

.quick-tags-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.quick-tags-label { font-size: 12px; color: var(--c-text-muted); }
#quickTags { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-tag {
  background: var(--c-bg-soft);
  color: var(--c-text-soft);
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 12px;
  transition: all 0.15s;
}
.quick-tag:active { background: var(--c-primary-soft); color: var(--c-primary); }

.search-results { display: flex; flex-direction: column; gap: 10px; }
.search-empty {
  text-align: center;
  padding: 50px 20px;
  color: var(--c-text-muted);
  font-size: 14px;
}

/* ============================================================
   Me page
   ============================================================ */
.profile-card {
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-accent) 100%);
  color: white;
  border-radius: var(--radius-xl);
  padding: 22px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  box-shadow: 0 8px 26px rgba(184, 134, 90, 0.28);
}
.profile-avatar {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  backdrop-filter: blur(4px);
  border: 2px solid rgba(255,255,255,0.35);
  flex-shrink: 0;
}
.profile-info h2 { font-size: 19px; font-weight: 700; }
.profile-info p { font-size: 13px; opacity: 0.9; margin-top: 3px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.stat-cell {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-m);
  padding: 12px 4px;
  text-align: center;
}
.stat-num {
  font-size: 18px;
  font-weight: 700;
  color: var(--c-primary);
  margin-bottom: 3px;
}
.stat-label { font-size: 10.5px; color: var(--c-text-muted); }

.menu-group {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-l);
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: 0 2px 8px var(--c-shadow);
}
.menu-item {
  padding: 14px 16px;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--c-border);
}
.menu-item:last-child { border-bottom: none; }
.menu-item:active { background: var(--c-bg-soft); }
.menu-arrow { color: var(--c-text-muted); font-size: 18px; }
.menu-item.danger { color: var(--c-warn); }

.app-footer-text {
  text-align: center;
  font-size: 11.5px;
  color: var(--c-text-muted);
  padding: 14px 0;
}

/* ============================================================
   Writer page (full screen editor for mobile)
   ============================================================ */
.writer-page {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--c-bg);
  display: none;
  flex-direction: column;
  animation: slideUp 0.25s ease;
  max-width: 640px;
  margin: 0 auto;
}
.writer-page.active { display: flex; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }

.writer-header {
  padding: 8px 8px;
  padding-top: calc(8px + env(safe-area-inset-top));
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-bg);
}
.w-btn {
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 10px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.w-cancel { color: var(--c-text-soft); }
.w-save {
  background: linear-gradient(135deg, var(--c-primary), var(--c-accent));
  color: white;
  box-shadow: 0 4px 12px rgba(184, 134, 90, 0.28);
}
.w-save:active { transform: scale(0.96); }

.w-title-wrap { text-align: center; }
.w-date {
  padding: 8px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-s);
  background: var(--c-surface);
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);
  max-width: 160px;
}

.w-meta-chips {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  overflow-x: auto;
  border-bottom: 1px solid var(--c-border);
  -webkit-overflow-scrolling: touch;
  background: var(--c-surface-alt);
}
.w-meta-chips::-webkit-scrollbar { display: none; }
.meta-chip {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--c-bg-soft);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.meta-chip:active { background: var(--c-primary-soft); transform: scale(0.92); }
.meta-chip.selected {
  background: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-soft);
}
.meta-divider {
  flex: 0 0 auto;
  width: 1px;
  height: 22px;
  background: var(--c-border);
  margin: 0 4px;
}
.w-cat-select {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-radius: 100px;
  background: var(--c-bg-soft);
  border: none;
  font-size: 13px;
  max-width: 130px;
  color: var(--c-text-soft);
  height: 36px;
}

.w-formatbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  overflow-x: auto;
  border-bottom: 1px solid var(--c-border);
  -webkit-overflow-scrolling: touch;
  background: var(--c-surface);
}
.w-formatbar::-webkit-scrollbar { display: none; }
.w-formatbar button, .fmt-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--c-text-soft);
  cursor: pointer;
}
.w-formatbar button:active, .fmt-btn:active { background: var(--c-primary-soft); color: var(--c-primary); }
.fmt-divider {
  flex: 0 0 auto;
  width: 1px;
  height: 20px;
  background: var(--c-border);
  margin: 0 4px;
}
.w-formatbar select {
  flex: 0 0 auto;
  padding: 6px 8px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface-alt);
  font-size: 12.5px;
  max-width: 80px;
  height: 34px;
  margin: 0 2px;
  color: var(--c-text-soft);
}
#btnSpeech.listening {
  background: var(--c-warn);
  color: white;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201,106,90,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(201,106,90,0); }
}

.w-title-input {
  width: 100%;
  border: none;
  padding: 14px 18px 6px;
  font-size: 20px;
  font-weight: 700;
  background: transparent;
  outline: none;
  line-height: 1.4;
}
.w-title-input::placeholder { color: var(--c-text-muted); }

.w-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 20px 20px;
  font-size: 16px;
  line-height: 1.85;
  outline: none;
  -webkit-overflow-scrolling: touch;
  transition: background 0.3s ease;
}
.w-body[contenteditable]:empty:before {
  content: attr(placeholder);
  color: var(--c-text-muted);
}
.w-body img {
  max-width: 100%;
  border-radius: 14px;
  margin: 10px 0;
  box-shadow: 0 4px 14px var(--c-shadow);
}

/* 信纸主题，应用在 w-body 上 */
.stationery-default {}
.stationery-warm { background: linear-gradient(135deg, #fff8ee 0%, #fde8d0 100%); color: #4a3725; }
.stationery-forest { background: linear-gradient(135deg, #eaf4e8 0%, #d1e4cc 100%); color: #2a3a2a; }
.stationery-ocean { background: linear-gradient(135deg, #e6f2f7 0%, #cfe0ec 100%); color: #1e3a52; }
.stationery-pink { background: linear-gradient(135deg, #fdf0f5 0%, #f6d7e2 100%); color: #523040; }
.stationery-night { background: linear-gradient(135deg, #2d3250 0%, #424769 100%); color: #e8e0d0; }
.stationery-paper {
  background:
    repeating-linear-gradient(transparent, transparent 33px, rgba(184, 134, 90, 0.18) 34px),
    linear-gradient(to bottom, #fdfbf4, #f5edd6);
  background-attachment: local;
  color: #3d362f;
}

.font-serif { font-family: var(--font-serif); }
.font-sans-serif { font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif; }
.font-xiaowei { font-family: var(--font-xiaowei); }

.w-images {
  padding: 4px 20px 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 6px;
}
.w-images .img-wrap {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--c-border);
}
.w-images img { width: 100%; height: 100%; object-fit: cover; }
.w-images .img-remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  opacity: 0.95;
}

.w-tags-row {
  padding: 8px 14px 14px;
  border-top: 1px solid var(--c-border);
}
.tags-input-wrapper {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-m);
  min-height: 44px;
  background: var(--c-surface-alt);
}
.tags-list { display: flex; flex-wrap: wrap; gap: 5px; }
.tag-chip {
  background: var(--c-primary);
  color: white;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.tag-chip .tag-remove { font-size: 14px; line-height: 1; cursor: pointer; }
.tag-input {
  flex: 1;
  min-width: 100px;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13px;
  padding: 4px;
}

.speech-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  background: rgba(201, 106, 90, 0.96);
  color: white;
  padding: 10px 18px;
  border-radius: 100px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  box-shadow: 0 10px 26px rgba(201, 106, 90, 0.5);
  z-index: 150;
  animation: pulse 1.2s infinite;
}
.speech-pulse {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: white;
}

/* ============================================================
   Detail Page (full screen)
   ============================================================ */
.detail-page {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--c-bg);
  display: none;
  flex-direction: column;
  animation: slideUp 0.25s ease;
  max-width: 640px;
  margin: 0 auto;
}
.detail-page.active { display: flex; }

.detail-header {
  flex: 0 0 auto;
  padding: 8px 8px;
  padding-top: calc(8px + env(safe-area-inset-top));
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-bg);
  z-index: 5;
}
.d-back {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--c-text-soft);
  font-weight: 300;
  line-height: 1;
}
.d-back:active { background: var(--c-bg-soft); }
.d-title-wrap { text-align: center; }
.d-title-wrap h2 {
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 0 8px;
}
.d-actions { display: flex; justify-content: flex-end; gap: 2px; }

.d-content {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px calc(30px + env(safe-area-inset-bottom));
}

.d-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--c-text-muted);
}
.d-meta .meta-category {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  padding: 3px 10px;
  border-radius: 100px;
  font-weight: 600;
  font-size: 11.5px;
}
.d-meta .meta-weather, .d-meta .meta-mood { font-size: 18px; }

.d-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 16px;
}

.d-body {
  font-size: 16px;
  line-height: 1.9;
  padding: 18px 16px;
  border-radius: var(--radius-l);
  margin-bottom: 14px;
}
.d-body img {
  max-width: 100%;
  border-radius: 14px;
  margin: 12px 0;
  box-shadow: 0 4px 14px var(--c-shadow);
}

.d-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.d-footer-info {
  font-size: 12px;
  color: var(--c-text-muted);
  padding: 12px 0;
  border-top: 1px solid var(--c-border);
  text-align: center;
}

.category-entries {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ============================================================
   Sheet (more menu)
   ============================================================ */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  max-width: 640px;
  left: 50%;
  transform: translateX(-50%);
}
.sheet.active { display: block; }
.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(30, 25, 20, 0.5);
  backdrop-filter: blur(3px);
  animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet-panel {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  background: var(--c-surface);
  border-radius: 24px 24px 0 0;
  padding: 6px 10px calc(10px + env(safe-area-inset-bottom));
  animation: slideUpSheet 0.22s ease;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
}
@keyframes slideUpSheet { from { transform: translateY(100%); } to { transform: none; } }

.sheet-item {
  padding: 15px 16px;
  font-size: 15.5px;
  text-align: center;
  border-bottom: 1px solid var(--c-border);
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 14px;
  margin: 2px 0;
}
.sheet-item:last-child { border-bottom: none; }
.sheet-item:active { background: var(--c-bg-soft); }
.sheet-item.cancel {
  color: var(--c-text-muted);
  margin-top: 6px;
  background: var(--c-bg-soft);
  font-weight: 500;
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  bottom: calc(var(--tabbar-h) + 20px);
  background: rgba(50, 45, 40, 0.94);
  color: white;
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s;
  z-index: 300;
  max-width: 80%;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   Desktop (screen wider than 640) - Keep mobile layout centered
   ============================================================ */
@media (min-width: 641px) {
  #app {
    border-left: 1px solid var(--c-border);
    border-right: 1px solid var(--c-border);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.05);
  }
}

/* 滚动条隐藏（移动端更整洁） */
.app-main::-webkit-scrollbar,
.d-content::-webkit-scrollbar,
.w-body::-webkit-scrollbar { width: 0; }

/* 禁用选择高亮 */
::selection { background: var(--c-primary-soft); color: var(--c-primary); }
