/* 日记本样式：手机竖屏优先，max-width 480px 居中；主色 #4a76a8 / 背景 #f7f5f0。
   不引用任何外部字体与资源，离线才能完整可用。 */

:root {
  --primary: #4a76a8;
  --primary-dark: #3b5f89;
  --bg: #f7f5f0;
  --card: #ffffff;
  --text: #2f3338;
  --muted: #8a8f96;
  --line: #e4e0d8;
  --danger: #c62828;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* hidden 属性必须压过元素默认 display（预览区、提示条依赖它） */
[hidden] { display: none !important; }

a { color: var(--primary); }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  /* 给固定底栏留出高度，再叠加 iPhone 底部安全区 */
  padding-bottom: calc(66px + env(safe-area-inset-bottom));
}

.view { padding: 16px 14px 24px; }

/* ---------- 底部标签栏 ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: 480px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  text-decoration: none;
  color: var(--muted);
  font-size: 12px;
}

.tabbar a.active { color: var(--primary); font-weight: 600; }
.tab-icon { font-size: 20px; line-height: 1.2; }

/* ---------- 顶部刷新横幅 ---------- */

.update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: var(--primary-dark);
  color: #fff;
  font-size: 14px;
  z-index: 30;
}

.update-actions { display: flex; gap: 8px; }

/* ---------- 页头 / 通用块 ---------- */

.page-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.page-head h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

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

.section-title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

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

.hint { margin: 4px 0; font-size: 13px; color: var(--muted); }

.empty-hint {
  margin: 18px 4px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
}

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

.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.danger:active { background: #fdecea; }

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

.btn.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }

.btn.block { display: flex; width: 100%; margin-bottom: 14px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--primary);
  font-size: 22px;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  flex: none;
}

.icon-btn:active { background: #eef2f7; }

/* ---------- 日历 ---------- */

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.month-title { margin: 0; font-size: 18px; font-weight: 700; }

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 16px;
}

.day-empty { aspect-ratio: 1; }

.day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
}

.day-cell:active { background: #eef2f7; }

/* 今天：主色描边 + 数字实心圆 */
.day-cell.today { border-color: var(--primary); }
.day-cell.today .day-num {
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 有日记的日期：圆点 = 当天最新一条的心情色 */
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

/* ---------- 日记列表 ---------- */

.entry-list { list-style: none; margin: 0; padding: 0; }

.entry-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
}

.entry-list li:last-child .entry-item { border-bottom: none; }
.entry-item:active { background: #eef2f7; }

.entry-date { color: var(--primary); font-size: 13px; flex: none; }
.entry-mood { font-size: 16px; flex: none; }

.entry-line {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  /* 超长单行省略，保持列表整齐 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-time { color: var(--muted); font-size: 12px; flex: none; }

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

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }

input[type="date"],
input[type="search"],
input[type="text"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* ≥16px 防安卓聚焦时页面被放大 */
}

input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

textarea {
  min-height: 220px;
  resize: vertical;
  line-height: 1.7;
}

.range-inputs { display: flex; align-items: center; gap: 8px; }
.range-inputs input { flex: 1; min-width: 0; }
.range-sep { color: var(--muted); font-size: 13px; flex: none; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.actions .btn { flex: 1; min-width: 90px; }

/* ---------- 心情选择器（8 个固定心情，点选/再点取消） ---------- */

.mood-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.mood-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
  font-family: inherit;
}

.mood-btn:active { transform: scale(0.97); }
.mood-emoji { font-size: 24px; line-height: 1.2; }
.mood-label { font-size: 12px; color: var(--muted); }
.mood-btn.selected .mood-label { color: var(--text); font-weight: 600; }

/* ---------- 编辑器切换 / Markdown 预览 ---------- */

.editor-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
}

.toggle-btn {
  padding: 6px 16px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}

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

.md-preview {
  min-height: 220px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--card);
  overflow-wrap: break-word;
}

.md-preview h1, .md-preview h2, .md-preview h3,
.md-preview h4, .md-preview h5, .md-preview h6 {
  margin: 0.8em 0 0.4em;
  line-height: 1.3;
}
.md-preview h1 { font-size: 1.4em; }
.md-preview h2 { font-size: 1.3em; }
.md-preview h3 { font-size: 1.2em; }

.md-preview p { margin: 0.6em 0; }

.md-preview blockquote {
  margin: 0.6em 0;
  padding: 4px 12px;
  border-left: 3px solid var(--primary);
  background: #eef2f7;
  color: var(--muted);
}

.md-preview pre {
  margin: 0.6em 0;
  padding: 10px;
  background: #2f3338;
  color: #f4f4f4;
  border-radius: 8px;
  overflow-x: auto;
}

.md-preview code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.92em;
  background: #eceae4;
  padding: 1px 5px;
  border-radius: 4px;
}

.md-preview pre code { background: none; padding: 0; }

.md-preview ul, .md-preview ol { margin: 0.6em 0; padding-left: 1.6em; }

.md-preview a { color: var(--primary); }
.md-preview del { color: var(--muted); }

/* ---------- 搜索结果 ---------- */

.result-count { color: var(--muted); font-size: 13px; margin: 0 0 6px; }

mark {
  background: #ffe082;
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

/* ---------- 设置页 ---------- */

.file-btn { position: relative; overflow: hidden; }

.prose { margin: 0; padding-left: 1.2em; font-size: 14px; }
.prose li { margin-bottom: 8px; }
