:root {
  --paper:      #faf7f2;
  --card:       #fffdfa;
  --card-soft:  #f3ede4;
  --ink:        #2f2b26;
  --ink-soft:   #6d6459;
  --ink-faint:  #a09688;
  --line:       #e8e0d4;
  --accent:     #b4795a;
  --accent-dim: #c99f80;
  --star:       #c9973f;
  --on-accent:  #fffdfa;
  --shadow:     0 1px 2px rgba(60,45,30,.05), 0 8px 24px -12px rgba(60,45,30,.14);
  --radius:     14px;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --serif: "Songti SC", "Source Han Serif SC", "Noto Serif CJK SC", Georgia,
           ui-serif, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #14120f;
    --card:       #1c1a17;
    --card-soft:  #262219;
    --ink:        #e9e3d8;
    --ink-soft:   #a89f92;
    --ink-faint:  #6f675c;
    --line:       #2e2924;
    --accent:     #d59d74;
    --accent-dim: #8a6449;
    --star:       #e0b25c;
    --on-accent:  #17140f;
    --shadow:     0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper:      #14120f;
  --card:       #1c1a17;
  --card-soft:  #262219;
  --ink:        #e9e3d8;
  --ink-soft:   #a89f92;
  --ink-faint:  #6f675c;
  --line:       #2e2924;
  --accent:     #d59d74;
  --accent-dim: #8a6449;
  --star:       #e0b25c;
  --on-accent:  #17140f;
  --shadow:     0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
input, select, textarea { min-width: 0; }

/* 横向滚动的地方都不显示滚动条 */
.chips::-webkit-scrollbar { display: none; }
.chips { scrollbar-width: none; }

/* ——— 登录 ——— */
.gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: var(--paper); padding: 24px;
}
.gate-card {
  width: 100%; max-width: 320px; text-align: center;
  display: flex; flex-direction: column; gap: 14px;
}
.gate-mark { font-size: 40px; line-height: 1; }
.gate-card h1 {
  margin: 0; font-size: 24px; font-weight: 500;
  font-family: var(--serif); letter-spacing: .12em;
}
.gate-hint { margin: -8px 0 4px; color: var(--ink-faint); font-size: 13px; }
.gate-card input {
  padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); text-align: center; letter-spacing: .1em;
  outline: none; transition: border-color .15s;
}
.gate-card input:focus { border-color: var(--accent); }
.gate-card button {
  padding: 11px; border: none; border-radius: 10px;
  background: var(--accent); color: var(--on-accent); font-weight: 500;
  letter-spacing: .1em; transition: opacity .15s;
}
.gate-card button:hover { opacity: .88; }
.gate-error { margin: 0; color: #c0563f; font-size: 13px; }

/* ——— 顶栏 ——— */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 11px 24px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 9px; flex-shrink: 0; }
.brand-mark { font-size: 16px; }
.brand-name {
  font-family: var(--serif); font-size: 17px;
  letter-spacing: .18em; font-weight: 500; white-space: nowrap;
}
.brand-date { color: var(--ink-faint); font-size: 12.5px; white-space: nowrap; }
.topbar-actions {
  display: flex; align-items: center; gap: 4px;
  margin-left: auto; min-width: 0; flex: 1; justify-content: flex-end;
}
#search {
  width: 190px; max-width: 100%; padding: 7px 13px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); outline: none; font-size: 13.5px;
  transition: border-color .15s;
}
#search:focus { border-color: var(--accent-dim); }
.icon-btn {
  flex-shrink: 0;
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 9px;
  background: transparent; color: var(--ink-soft); font-size: 14px;
  line-height: 1; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--card-soft); color: var(--ink); }

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .brand-date { display: none; }
  #search { flex: 1; width: auto; }
  .topbar-actions { gap: 2px; }
}

/* ——— 布局 ——— */
.layout {
  max-width: 1180px; margin: 0 auto;
  padding: 26px 24px 80px;
  display: grid; grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
  gap: 30px; align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 22px; padding: 18px 16px 60px; }
}

/* ——— 写作区 ——— */
.composer {
  position: sticky; top: 72px;
  max-height: calc(100vh - 96px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 11px;
  padding: 18px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow);
}
@media (max-width: 900px) {
  .composer { position: static; max-height: none; overflow: visible; }
}
.composer.editing { border-color: var(--accent-dim); }
.composer-head { display: flex; align-items: center; justify-content: space-between; }
.composer-head h2 {
  margin: 0; font-family: var(--serif); font-size: 15.5px;
  font-weight: 500; letter-spacing: .1em;
}

.field-row { display: flex; flex-wrap: wrap; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 3px; flex: 1 1 140px; min-width: 0; }
.field input { width: 100%; }

.field-label {
  font-size: 11.5px; color: var(--ink-faint);
  letter-spacing: .1em; white-space: nowrap;
}
.field input, .inline-input, #f-content, .filters select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--paper); outline: none;
  transition: border-color .15s, background .15s;
}
.field input:focus, .inline-input:focus, #f-content:focus {
  border-color: var(--accent-dim); background: var(--card);
}
.field input[type="date"], .field input[type="time"] { font-size: 13.5px; }

.title-input {
  width: 100%; font-family: var(--serif); font-size: 16px;
  border: none; border-bottom: 1px solid var(--line); border-radius: 0;
  background: transparent; padding: 5px 2px; outline: none;
  transition: border-color .15s;
}
.title-input:focus { border-bottom-color: var(--accent); }

/* 心情 / 天气：一行装不下就横向滚，不撑破页面 */
.chip-group {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center; gap: 8px;
}
.chip-group.with-temp { grid-template-columns: auto minmax(0, 1fr) auto auto auto; }
.chips {
  display: flex; flex-wrap: nowrap; gap: 5px;
  overflow-x: auto; padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
.chip {
  flex-shrink: 0;
  padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--paper); font-size: 13px; line-height: 1.55;
  white-space: nowrap; transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: var(--accent-dim); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.inline-input { width: 78px; font-size: 12.5px; padding: 4px 8px; }
.inline-input.tiny { width: 58px; }

#f-content {
  min-height: 190px; resize: vertical; width: 100%;
  font-family: var(--serif); font-size: 15.5px; line-height: 1.85;
}

.composer-foot {
  position: sticky; bottom: -18px;
  display: flex; align-items: center; gap: 12px;
  margin: 0 -18px -18px; padding: 11px 18px 18px;
  background: var(--card); border-top: 1px solid var(--line);
}
.star-toggle {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ink-soft); cursor: pointer;
}
.star-toggle input { accent-color: var(--star); }
.save-hint { margin-left: auto; font-size: 12px; color: var(--ink-faint); }
.primary-btn {
  padding: 8px 20px; border: none; border-radius: 9px;
  background: var(--accent); color: var(--on-accent);
  font-weight: 500; letter-spacing: .08em;
  transition: opacity .15s, transform .1s;
}
.primary-btn:hover { opacity: .88; }
.primary-btn:active { transform: translateY(1px); }
.primary-btn:disabled { opacity: .45; cursor: default; }
.ghost-btn {
  padding: 6px 13px; border: 1px solid var(--line); border-radius: 9px;
  background: transparent; color: var(--ink-soft); font-size: 13px;
  text-decoration: none; transition: border-color .15s, color .15s;
}
.ghost-btn:hover { border-color: var(--accent-dim); color: var(--ink); }

/* ——— 列表 ——— */
.filters {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  margin-bottom: 16px;
}
.filters select {
  padding: 5px 10px; font-size: 13px; border-radius: 999px;
  max-width: 190px;
}
.filter-btn {
  padding: 5px 13px; border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--ink-soft); font-size: 13px;
  white-space: nowrap; transition: border-color .15s, background .15s, color .15s;
}
.filter-btn:hover { border-color: var(--accent-dim); }
.filter-btn.on { background: var(--card-soft); color: var(--ink); border-color: var(--accent-dim); }
.result-count { margin-left: auto; font-size: 12px; color: var(--ink-faint); }

.entries { display: flex; flex-direction: column; gap: 13px; }
.day-mark {
  display: flex; align-items: center; gap: 10px;
  margin: 8px 0 -3px; color: var(--ink-faint);
  font-size: 12px; letter-spacing: .1em; white-space: nowrap;
}
.day-mark::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.entry {
  padding: 17px 19px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow);
  transition: border-color .15s;
}
.entry:hover { border-color: var(--accent-dim); }
.entry.starred { border-left: 3px solid var(--star); }
.entry-meta {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  margin-bottom: 7px; font-size: 12.5px; color: var(--ink-soft);
}
.entry-meta .sep { color: var(--line); }
.entry-title {
  margin: 0 0 5px; font-family: var(--serif);
  font-size: 17px; font-weight: 500; line-height: 1.5;
}
.entry-content {
  font-family: var(--serif); font-size: 15px; line-height: 1.9;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.entry-content.clipped {
  display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical;
  overflow: hidden;
}
.entry-expand {
  margin-top: 5px; padding: 0; border: none; background: none;
  color: var(--accent); font-size: 12.5px;
}
.entry-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.tag {
  padding: 2px 9px; border: none; border-radius: 999px;
  background: var(--card-soft); color: var(--ink-soft); font-size: 12px;
  transition: color .15s;
}
.tag:hover { color: var(--accent); }
.entry-actions {
  display: flex; gap: 4px; margin-top: 11px;
  opacity: 0; transition: opacity .2s;
}
.entry:hover .entry-actions, .entry:focus-within .entry-actions { opacity: 1; }
@media (hover: none) { .entry-actions { opacity: 1; } }
.entry-actions button {
  padding: 3px 10px; border: 1px solid transparent; border-radius: 7px;
  background: transparent; color: var(--ink-faint); font-size: 12px;
  transition: background .15s, color .15s;
}
.entry-actions button:hover { background: var(--card-soft); color: var(--ink); }
.entry-actions button.danger:hover { color: #c0563f; }

.more-btn {
  width: 100%; margin-top: 16px; padding: 11px;
  border: 1px dashed var(--line); border-radius: var(--radius);
  background: transparent; color: var(--ink-soft); font-size: 13.5px;
  transition: border-color .15s, color .15s;
}
.more-btn:hover { border-color: var(--accent-dim); color: var(--ink); }
.empty { padding: 56px 20px; text-align: center; color: var(--ink-soft); }
.empty p { margin: 4px 0; }
.empty .dim, .dim { color: var(--ink-faint); font-size: 13px; }

/* ——— 回顾 ——— */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(20, 16, 12, .42);
  backdrop-filter: blur(3px); padding: 20px;
}
.overlay-card {
  width: 100%; max-width: 560px; max-height: 86vh;
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); overflow: hidden;
}
.overlay-head, .overlay-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; flex-shrink: 0;
}
.overlay-head { border-bottom: 1px solid var(--line); }
.overlay-foot { border-top: 1px solid var(--line); }
.overlay-head h2 {
  margin: 0; font-family: var(--serif); font-size: 16px;
  font-weight: 500; letter-spacing: .1em;
}
.stats-body { padding: 20px; overflow-y: auto; }
.stat-grid {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px; margin-bottom: 20px;
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.stat-cell {
  padding: 12px 6px; border-radius: 10px;
  background: var(--card-soft); text-align: center;
}
.stat-num { font-family: var(--serif); font-size: 21px; line-height: 1.2; }
.stat-label { font-size: 11.5px; color: var(--ink-faint); letter-spacing: .06em; }
.stat-section { margin-bottom: 20px; }
.stat-section h3 {
  margin: 0 0 9px; font-size: 12.5px; font-weight: 500;
  color: var(--ink-faint); letter-spacing: .12em;
}
.bar-row {
  display: grid; grid-template-columns: minmax(70px, 96px) 1fr 30px;
  align-items: center; gap: 10px; margin-bottom: 6px; font-size: 13px;
}
.bar-row > span:first-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-track { height: 6px; border-radius: 999px; background: var(--card-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); opacity: .65; }
.bar-count { text-align: right; font-size: 12px; color: var(--ink-faint); }
.trend { width: 100%; height: 70px; display: block; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-cloud .tag { padding: 3px 10px; }

/* ——— toast ——— */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  padding: 9px 20px; border-radius: 999px;
  background: var(--ink); color: var(--paper);
  font-size: 13.5px; box-shadow: var(--shadow);
  z-index: 60; animation: rise .25s ease-out;
}
@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* 滚动区右边渐隐一点，暗示还能往右滑 */
.chips {
  mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent);
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent);
}
.chip-custom {
  color: var(--ink-faint);
  padding: 3px 8px;
}
.chip-custom:hover { color: var(--accent); }

/* 刚写下/改完的那篇，亮一下 */
.entry.just-saved { animation: just-saved 1.8s ease-out; }
@keyframes just-saved {
  0%, 60% {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent), var(--shadow);
  }
  100% { box-shadow: var(--shadow); }
}
