/* =====================================================
   你的日记 · 手写体文艺手账风格（v2 · 移动端优化）
   ===================================================== */
:root {
  --bg: #f7f1e3;
  --bg-card: #fffdf6;
  --bg-deep: #efe6d0;
  --ink: #4a3f35;
  --ink-soft: #8a7a68;
  --ink-faint: #b5a894;
  --line: #e3d7bd;
  --accent: #e8a33d;
  --accent-deep: #c9821f;
  --accent-soft: #fbeed3;
  --pink: #e88ba0;
  --green: #7ba05b;
  --danger: #d96a6a;
  --shadow: 0 4px 18px rgba(90, 70, 40, 0.10);
  --radius: 18px;
  --font-hand: 'Ma Shan Zheng', 'ZCOOL KuaiLe', 'KaiTi', 'STKaiti', cursive;
  --font-body: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(232,163,61,0.06) 0, transparent 40%),
    radial-gradient(circle at 88% 72%, rgba(232,139,160,0.07) 0, transparent 42%),
    radial-gradient(circle at 70% 10%, rgba(123,160,91,0.06) 0, transparent 35%);
  transition: background 0.3s, color 0.3s;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-overflow-scrolling: touch;
  font-size: 16px;
}

/* ---------- 夜间模式：全局变量覆盖 ---------- */
body.night {
  --bg: #1d1813;
  --bg-card: #2a241d;
  --bg-deep: #352e25;
  --ink: #eadfce;
  --ink-soft: #b5a28c;
  --ink-faint: #7d6f5e;
  --line: #453a2d;
  --accent: #e8a33d;
  --accent-deep: #f0b455;
  --accent-soft: #4a3a24;
  --pink: #d97a90;
  --green: #8fae6f;
  --danger: #e07b7b;
  --shadow: 0 4px 18px rgba(0,0,0,0.4);
}

/* ============ 布局骨架（含安全区适配） ============ */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  height: calc(52px + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(247,241,227,0.90);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px dashed var(--line);
}
body.night .app-header { background: rgba(29,24,19,0.92); }

.header-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.app-title {
  font-family: var(--font-hand);
  font-size: 24px; font-weight: normal;
  letter-spacing: 2px;
  color: var(--ink);
  white-space: nowrap;
}
.header-right { display: flex; gap: 4px; }

.icon-btn {
  width: 44px; height: 44px;
  border: none; background: transparent;
  font-size: 20px; color: var(--ink-soft);
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}
.icon-btn:active { background: var(--bg-deep); }

.app-main {
  position: fixed; top: calc(52px + var(--safe-top));
  bottom: calc(62px + var(--safe-bottom));
  left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px 14px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

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

/* ============ 底部导航（含安全区） ============ */
.app-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: calc(62px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; align-items: center; justify-content: space-around;
  background: rgba(255,253,246,0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
body.night .app-nav { background: rgba(42,36,29,0.96); }

.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; width: 56px; height: 100%;
  color: var(--ink-faint);
  text-decoration: none; cursor: pointer;
  transition: color 0.2s, transform 0.15s;
  touch-action: manipulation;
}
.nav-item .nav-icon { font-size: 20px; line-height: 1; }
.nav-item .nav-label { font-size: 10px; letter-spacing: 1px; font-family: var(--font-body); }
.nav-item.active { color: var(--accent-deep); }
.nav-item:active { transform: scale(0.92); }

.nav-write { position: relative; }
.nav-plus {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fff;
  font-size: 30px; font-weight: normal;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 5px 14px rgba(232,163,61,0.45);
  margin-top: -22px;
  border: 3px solid var(--bg-card);
}

/* ============ 通用组件 ============ */
.empty-state { text-align: center; padding: 70px 20px; color: var(--ink-soft); }
.empty-art { font-size: 56px; margin-bottom: 12px; opacity: 0.8; }
.empty-state p { font-size: 16px; margin-bottom: 4px; }
.empty-sub { font-size: 13px; color: var(--ink-faint); }
.empty-sub b { color: var(--accent-deep); font-weight: normal; }

/* ============ 登录 / 注册页 ============ */
.auth-page {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 22px calc(24px + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 15% 20%, rgba(232,163,61,0.10) 0, transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(232,139,160,0.10) 0, transparent 40%);
}
.auth-page.hidden { display: none; }

.auth-card {
  width: 100%; max-width: 400px;
  background: var(--bg-card);
  border-radius: 22px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 30px 26px 22px;
  text-align: center;
  animation: pageIn 0.35s ease;
}
.auth-logo { font-size: 44px; margin-bottom: 6px; }
.auth-brand { font-family: var(--font-hand); font-size: 34px; font-weight: normal; letter-spacing: 4px; color: var(--ink); }
.auth-slogan { font-size: 13px; color: var(--ink-faint); margin: 4px 0 22px; letter-spacing: 2px; }

.auth-form { text-align: left; }
.auth-field { display: block; margin-bottom: 14px; }
.auth-field-label { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; letter-spacing: 1px; }
.auth-input {
  width: 100%;
  font-size: 16px; /* >=16px 防 iOS 聚焦自动缩放 */
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  font-family: var(--font-body);
  min-height: 48px;
  transition: border-color 0.2s;
  -webkit-user-select: text; user-select: text;
}
.auth-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-input::placeholder { color: var(--ink-faint); }
.auth-error { min-height: 18px; font-size: 12px; color: var(--danger); margin-bottom: 8px; }
.auth-hint { font-size: 11px; color: var(--ink-faint); line-height: 1.7; margin-bottom: 8px; text-align: left; }

.btn-block { width: 100%; padding: 14px 20px; font-size: 16px; min-height: 50px; margin-top: 4px; }

.auth-switch { margin-top: 18px; font-size: 13px; color: var(--ink-soft); }
.auth-switch a { color: var(--accent-deep); text-decoration: none; font-weight: 600; }
.auth-foot { margin-top: 10px; font-size: 10px; color: var(--ink-faint); letter-spacing: 1px; }

/* ============ 日记列表页 ============ */
.diary-list { display: flex; flex-direction: column; gap: 14px; }

.diary-card {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
  overflow: hidden;
}
.diary-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--pink), var(--green));
  opacity: 0.55;
}
.diary-card:active { transform: scale(0.985); }

.diary-card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.diary-date { font-family: var(--font-hand); font-size: 17px; color: var(--accent-deep); letter-spacing: 1px; }
.diary-time { font-size: 12px; color: var(--ink-faint); margin-left: 8px; }
.diary-title { font-family: var(--font-hand); font-size: 19px; margin-bottom: 4px; word-break: break-all; }
.diary-summary {
  font-size: 14px; color: var(--ink-soft); line-height: 1.7;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-all;
}
.diary-card-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.diary-tag {
  font-size: 11px; color: var(--accent-deep); background: var(--accent-soft);
  padding: 3px 10px; border-radius: 20px;
}
.diary-imgs { font-size: 12px; color: var(--ink-faint); }
.diary-actions { display: flex; gap: 10px; }
.diary-action {
  font-size: 13px; color: var(--ink-faint);
  padding: 9px 14px; min-height: 44px;
  border-radius: 20px;
  border: 1px dashed var(--line);
  background: transparent; cursor: pointer;
  touch-action: manipulation;
}
.diary-action.edit { color: var(--green); }
.diary-action.del { color: var(--pink); }
.diary-action:active { background: var(--bg-deep); }

/* ============ 日历页 ============ */
.cal-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-title { font-family: var(--font-hand); font-size: 22px; letter-spacing: 2px; }
.cal-nav {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg-card);
  font-size: 20px; color: var(--ink-soft); cursor: pointer;
  touch-action: manipulation;
}
.cal-nav:active { background: var(--bg-deep); }

.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; margin-bottom: 4px;
}
.cal-weekdays span { font-size: 12px; color: var(--ink-faint); padding: 6px 0; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-day {
  aspect-ratio: 1 / 1;
  min-height: 44px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative;
  border-radius: 12px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s;
  touch-action: manipulation;
}
.cal-day.out { color: var(--ink-faint); opacity: 0.45; }
.cal-day.today { font-weight: bold; color: var(--accent-deep); }
.cal-day.selected {
  background: var(--accent); color: #fff;
  box-shadow: 0 3px 10px rgba(232,163,61,0.4);
}
body.night .cal-day.selected { background: var(--accent-deep); color: #1d1813; box-shadow: 0 3px 12px rgba(240,180,85,0.35); }
.cal-day:active { background: var(--accent-soft); }
body.night .cal-day:active { background: var(--accent-soft); }
.cal-day.selected:active { background: var(--accent-deep); }

.cal-dot {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--pink);
}
.cal-day.selected .cal-dot { background: #fff; }
body.night .cal-day.selected .cal-dot { background: #1d1813; }

.cal-detail { margin-top: 16px; }
.cal-detail-empty { text-align: center; color: var(--ink-faint); font-size: 13px; padding: 24px 0; }
.cal-detail-list { display: flex; flex-direction: column; gap: 10px; }

/* ============ 个人信息页 ============ */
.profile-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 26px 20px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  position: relative;
  margin-bottom: 16px;
}
.avatar-wrap { position: relative; display: inline-block; margin-bottom: 10px; }
.avatar {
  width: 88px; height: 88px; border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-soft), var(--accent));
  color: #fff;
  font-family: var(--font-hand);
  font-size: 40px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(232,163,61,0.35);
  border: 3px solid var(--bg-card);
}
body.night .avatar { color: #2a241d; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-edit {
  position: absolute; right: -4px; bottom: -4px;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--ink); color: var(--bg-card);
  border: 2px solid var(--bg-card);
  font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}
body.night .avatar-edit { color: #1d1813; }
.nickname { font-family: var(--font-hand); font-size: 28px; margin-bottom: 16px; letter-spacing: 2px; }

.profile-stats { display: flex; justify-content: space-around; padding: 14px 0; border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line); margin-bottom: 16px; }
.stat-item { display: flex; flex-direction: column; gap: 2px; min-height: 44px; justify-content: center; }
.stat-item b { font-family: var(--font-hand); font-size: 28px; color: var(--ink); font-weight: normal; }
.stat-item span { font-size: 11px; color: var(--ink-faint); }

.pro-btn {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(120deg, #ffd76e, #f5b73d);
  border: none; border-radius: 30px;
  padding: 14px 18px; min-height: 50px;
  color: #7a5410;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(245,183,61,0.4);
  touch-action: manipulation;
}
body.night .pro-btn {
  background: linear-gradient(120deg, #c99b3d, #a67c26);
  color: #f7ecd2;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
.pro-btn:active { transform: scale(0.98); }
.pro-icon { font-size: 20px; }
.pro-arrow { margin-left: auto; font-size: 20px; }
.pro-hint { font-size: 11px; color: var(--ink-faint); margin-top: 8px; }

.profile-menu { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.menu-item {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 16px; min-height: 52px;
  font-size: 15px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  touch-action: manipulation;
}
.menu-item:last-child { border-bottom: none; }
.menu-item:active { background: var(--bg-deep); }
.menu-icon { font-size: 18px; }
.menu-arrow { margin-left: auto; color: var(--ink-faint); font-size: 18px; }

/* ============ 设置页 ============ */
.settings-group {
  background: var(--bg-card);
  border-radius: 14px;
  border: 1px solid var(--line);
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.setting-item, .setting-link {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 16px; min-height: 52px;
  font-size: 15px;
  border-bottom: 1px solid var(--line);
  text-decoration: none; color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.setting-item:last-child, .setting-link:last-child { border-bottom: none; }
.setting-link:active { background: var(--bg-deep); }
.setting-value { color: var(--ink-faint); font-size: 13px; }
.setting-logout { color: var(--danger); }
.setting-logout .menu-arrow { color: var(--danger); }

.switch { position: relative; display: inline-block; width: 48px; height: 27px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--line);
  border-radius: 27px;
  transition: 0.25s;
  cursor: pointer;
}
body.night .slider { background: #5a4c3a; }
.slider::before {
  content: '';
  position: absolute; width: 21px; height: 21px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%;
  transition: 0.25s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(21px); }

.settings-foot { text-align: center; color: var(--ink-faint); font-size: 12px; padding: 20px 0 8px; letter-spacing: 1px; }

/* ============ 新建日记页 ============ */
.write-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 320px;
}
.write-meta { display: flex; justify-content: space-between; margin-bottom: 8px; }
.write-date { font-family: var(--font-hand); font-size: 16px; color: var(--accent-deep); }
.write-edit-id { font-size: 11px; color: var(--ink-faint); align-self: center; }
.write-title {
  border: none; outline: none;
  background: transparent;
  font-family: var(--font-hand);
  font-size: 24px; color: var(--ink);
  padding: 8px 0 10px;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 12px;
  -webkit-user-select: text; user-select: text;
}
.write-title::placeholder { color: var(--ink-faint); }
.write-content {
  border: none; outline: none; resize: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 16px; line-height: 2.0; /* >=16px 防 iOS 聚焦缩放 */
  color: var(--ink);
  min-height: 220px;
  flex: 1;
  -webkit-user-select: text; user-select: text;
}
.write-content::placeholder { color: var(--ink-faint); }

.write-toolbar {
  display: flex; justify-content: space-between;
  padding: 10px 2px 2px;
}
.tool-btn {
  border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 18px; color: var(--ink-soft);
  cursor: pointer; padding: 6px 4px;
  min-width: 52px; min-height: 52px;
  touch-action: manipulation;
}
.tool-btn span { font-size: 9px; color: var(--ink-faint); }
.tool-btn:active { transform: scale(0.9); }

.tool-panel { margin-top: 8px; min-height: 0; }
.tool-panel.show {
  background: var(--bg-card);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 12px;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.tool-panel .tp-chip {
  font-size: 13px; padding: 9px 12px; min-height: 40px;
  border-radius: 18px;
  background: var(--bg-deep);
  color: var(--ink-soft);
  cursor: pointer;
  touch-action: manipulation;
}
.tool-panel .tp-chip:active { background: var(--accent-soft); color: var(--accent-deep); }
.tool-panel .tp-row { width: 100%; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); }
.tool-panel .tp-emoji { font-size: 24px; cursor: pointer; padding: 4px; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.tool-panel .tp-emoji:active { transform: scale(1.2); }

.write-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.btn {
  border: none; border-radius: 24px;
  padding: 12px 26px; min-height: 48px;
  font-size: 15px; cursor: pointer;
  font-family: var(--font-body);
  transition: transform 0.1s;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: linear-gradient(145deg, var(--accent), var(--accent-deep)); color: #fff; box-shadow: 0 4px 12px rgba(232,163,61,0.4); }
body.night .btn-primary { color: #2a241d; }
.btn-secondary { background: var(--bg-deep); color: var(--ink-soft); }

/* ============ 弹层 ============ */
.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(30, 24, 15, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%; max-width: 420px;
  max-height: 74vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  animation: modalIn 0.25s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.94) translateY(14px); } to { opacity: 1; transform: none; } }
.modal h3 { font-family: var(--font-hand); font-size: 21px; margin-bottom: 12px; text-align: center; letter-spacing: 2px; }
.modal p { font-size: 13px; line-height: 1.9; color: var(--ink-soft); margin-bottom: 10px; -webkit-user-select: text; user-select: text; }
.modal textarea, .modal input[type="text"] {
  width: 100%;
  border: 1px dashed var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink);
  padding: 10px; font-size: 16px; line-height: 1.8;
  font-family: var(--font-body); outline: none; resize: none;
  min-height: 44px;
}
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.modal .btn { padding: 10px 24px; font-size: 14px; min-height: 46px; }

/* ============ 图片在日记中的展示 ============ */
.diary-img {
  width: 100%; max-height: 220px; object-fit: cover;
  border-radius: 10px; margin-top: 8px;
  border: 1px solid var(--line);
}

/* ============ Toast 提示 ============ */
.toast {
  position: fixed; bottom: calc(84px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: rgba(74, 63, 53, 0.92);
  color: #fdf8ec;
  font-size: 13px;
  padding: 11px 22px;
  border-radius: 24px;
  z-index: 200;
  animation: toastIn 0.25s ease;
  max-width: 78vw;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
body.night .toast { background: rgba(234, 223, 206, 0.92); color: #2d2620; }
.toast.out { opacity: 0; transition: opacity 0.3s; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* 滚动条美化 */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
