:root {
  --bg: #F7F7F5;
  --surface: #FBFBFA;
  --text: #37352F;
  --text-secondary: #787774;
  --border: #E9E9E7;
  --line: #E9E9E7;
  --hover: #EFEFEF;
  --accent: #2383E2;
  --blue: #2383E2;
  --red: #EB5757;
  --orange: #D9730D;
  --green: #448361;
  --input-bg: transparent;
  --card: transparent;
  --radius: 5px;
  color-scheme: light;
}

html.dark {
  --bg: #191919;
  --surface: #1F1F1F;
  --text: #D4D4D4;
  --text-secondary: #9B9B9B;
  --border: #333333;
  --line: #333333;
  --hover: #252525;
  --accent: #529CCA;
  --blue: #529CCA;
  --red: #EB5757;
  --orange: #D9730D;
  --green: #6A9A7B;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
input, textarea { user-select: auto; -webkit-user-select: auto; }

html, body { background: var(--bg); }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  display: flex;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app-container {
  width: 100%;
  max-width: 480px;
  height: 100%;
  background: var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
}

#content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(88px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.18s ease-out; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.page h1 { font-size: 30px; font-weight: 700; margin: 4px 0 20px; letter-spacing: -0.02em; }
h2 { font-size: 15px; font-weight: 600; margin-top: 0; margin-bottom: 10px; letter-spacing: -0.01em; }

.card {
  background: transparent;
  border-radius: 0;
  padding: 18px 0;
  margin: 0;
  border-bottom: 1px solid var(--border);
  box-shadow: none;
}
.card:last-child { border-bottom: none; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--border); border-radius: 4px; padding: 7px 14px;
  min-height: 36px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  background: transparent; color: var(--text); font-family: inherit;
  touch-action: manipulation;
  transition: opacity 0.15s;
}
.btn:hover { background: var(--hover); }
.btn:active { opacity: 0.75; }
.btn.primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.primary:hover { background: var(--text); opacity: 0.88; }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: rgba(235, 87, 87, 0.08); }
.btn.small { padding: 4px 9px; min-height: 32px; font-size: 12.5px; border-radius: 4px; }

.task {
  display: flex; align-items: center; gap: 10px; padding: 12px 0;
  border-bottom: 1px solid var(--border); min-width: 0;
}
.task:last-child { border-bottom: none; }
.task.done .title { text-decoration: line-through; color: var(--text-secondary); }
.task .title { flex: 1; min-width: 0; font-size: 15px; font-weight: 500; line-height: 1.5; overflow-wrap: anywhere; }
.task .due-today, .task .due-overdue, .task .muted { white-space: nowrap; }
.task input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--text); cursor: pointer; flex-shrink: 0;
}
.task-del {
  flex-shrink: 0; border: none; background: transparent; color: var(--text-secondary);
  min-height: 36px;
  font-size: 12px; font-family: inherit; padding: 5px 6px; border-radius: 4px; cursor: pointer;
  touch-action: manipulation;
}
.task-del:hover { background: var(--hover); color: var(--text); }

.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot.high { background: var(--red); }
.dot.medium { background: var(--orange); }
.dot.low { background: var(--green); }

.tag { display: none; }
.muted { color: var(--text-secondary); font-size: 13px; line-height: 1.6; }
.due-overdue { color: var(--red); font-size: 12.5px; }
.due-today { color: var(--orange); font-size: 12.5px; }

input[type="text"], input[type="date"], input[type="number"], input[type="datetime-local"], select, textarea {
  width: 100%; padding: 10px 11px; min-height: 42px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--input-bg); font-size: 16px; font-family: inherit; outline: none;
  color: var(--text); -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--text-secondary); }

.empty { text-align: center; color: var(--text-secondary); padding: 28px 0; font-size: 13px; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 20px; width: 340px; max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  box-shadow: none;
}
.modal h3 { margin: 0 0 14px; font-size: 16px; font-weight: 600; text-align: center; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }
.modal-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.modal-actions .btn { flex: 1; text-align: center; padding: 9px; font-size: 14px; }

#tab-bar {
  position: absolute; bottom: 0; left: 0; width: 100%; height: auto;
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex; overflow-x: auto; white-space: nowrap;
  padding-bottom: env(safe-area-inset-bottom);
  scrollbar-width: none; z-index: 10;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}
#tab-bar::-webkit-scrollbar { display: none; }
#tab-bar button {
  flex: 0 0 auto; padding: 8px 12px 7px; min-height: 48px; border: none; background: transparent;
  color: var(--text-secondary); font-size: 10px; font-weight: 500;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  cursor: pointer; transition: color 0.15s; touch-action: manipulation;
  scroll-snap-align: center;
}
#tab-bar button.active { color: var(--text); font-weight: 600; }
.tab-icon { display: flex; align-items: center; justify-content: center; height: 20px; }
.tab-icon svg { width: 20px; height: 20px; }

#toast-root {
  position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--text); color: var(--bg); padding: 8px 14px;
  border-radius: 4px; font-size: 13px; font-weight: 500;
  animation: slideDown 0.2s ease-out;
}
.toast.error { background: var(--red); color: #fff; }
@keyframes slideDown { from { transform: translateY(-8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-head { font-size: 11px; color: var(--text-secondary); text-align: center; padding: 6px 0; font-weight: 500; }
.cal-cell {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 4px; font-size: 14px; cursor: pointer; position: relative; color: var(--text);
}
.cal-cell:hover { background: var(--hover); }
.cal-cell.out { opacity: 0.3; }
.cal-cell.today { color: var(--accent); font-weight: 600; }
.cal-cell.selected { background: var(--hover); color: var(--text); font-weight: 600; }
.cal-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); position: absolute; bottom: 4px; }
.cal-count { font-size: 9px; color: var(--text-secondary); position: absolute; top: 2px; right: 4px; }

.stat { display: flex; flex-direction: column; }
.stat .num { font-size: 22px; font-weight: 700; }
.stat .lbl { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }

.timer { font-size: 56px; font-weight: 300; letter-spacing: -0.02em; text-align: center; margin: 18px 0; font-variant-numeric: tabular-nums; }

#ai-helper-container .card { padding: 18px 0; }
#ai-chat-history { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.chat-bubble { max-width: 82%; padding: 8px 11px; border-radius: 4px; font-size: 14px; line-height: 1.6; word-wrap: break-word; }
.chat-bubble.user { align-self: flex-end; background: var(--hover); color: var(--text); }
.chat-bubble.ai { align-self: flex-start; background: transparent; color: var(--text); border: 1px solid var(--border); }
#ai-chat-history .chat-bubble { white-space: pre-wrap; }
.ai-tip { color: var(--text-secondary); font-size: 12px; margin: 8px 0; }
.ai-examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ai-chip {
  border: 1px solid transparent; border-radius: 4px; padding: 6px 10px; min-height: 32px; font-size: 12px;
  background: var(--hover); color: var(--text); cursor: pointer; font-family: inherit;
  touch-action: manipulation;
}
.ai-chip:hover { border-color: var(--border); }
.ai-chip:disabled { color: var(--text-secondary); opacity: 0.6; }
.ai-card-name { font-size: 15px; font-weight: 600; text-align: center; margin: 0 0 10px; word-break: break-word; }
.ai-card-line { text-align: center; font-size: 14px; margin: 5px 0; word-break: break-word; }
.ai-timer {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 300px; max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--surface); border-radius: 6px; padding: 22px 20px;
  z-index: 60; text-align: center; border: 1px solid var(--border);
}
.ai-timer-title { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin-bottom: 8px; }
.ai-timer-display { font-size: 48px; font-weight: 300; font-variant-numeric: tabular-nums; line-height: 1.1; letter-spacing: -0.02em; }
.ai-timer-label { font-size: 13px; color: var(--text-secondary); margin-top: 6px; word-break: break-word; }
.ai-timer-controls { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* 日记 */
button.cal-cell {
  border: none; background: transparent; padding: 0;
  font-family: inherit; font-size: 14px; color: var(--text); cursor: pointer;
}
.cal-cell .cal-day { line-height: 1; }
.diary-mark { position: absolute; bottom: 2px; font-size: 10px; line-height: 1.2; }
.diary-modal { width: 360px; max-height: 82vh; max-height: 82dvh; overflow-y: auto; }
.diary-body { margin-top: 4px; }
.diary-badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 12px; }
.diary-badge { background: var(--hover); border-radius: 4px; padding: 4px 9px; font-size: 12px; }
.diary-content {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  font-size: 17px; line-height: 1.8; white-space: pre-wrap; word-break: break-word;
  max-height: 40vh; overflow-y: auto; padding: 4px 2px;
  user-select: text; -webkit-user-select: text;
}
.diary-content.serif { font-family: "Songti SC", "STSong", "SimSun", "Songti TC", serif; }
.diary-field-label { font-size: 12px; color: var(--text-secondary); margin: 12px 0 6px; font-weight: 500; }
.diary-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.diary-chip {
  border: 1px solid transparent; border-radius: 4px; padding: 6px 10px; min-height: 34px; background: var(--hover);
  font-size: 13px; font-family: inherit; color: var(--text); cursor: pointer; touch-action: manipulation;
}
.diary-chip.active { background: var(--text); color: var(--bg); }
.diary-textarea {
  width: 100%; min-height: 160px; margin-top: 12px; padding: 11px;
  border: 1px solid var(--border); border-radius: 4px; background: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  font-size: 17px; line-height: 1.8; color: var(--text); resize: vertical; outline: none;
}

/* 学习时长图表 */
.study-chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding: 8px 0 0; }
.study-bar-col {
  flex: 1; min-width: 0; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px;
}
.study-bar-value { height: 14px; font-size: 10px; color: var(--text-secondary); line-height: 14px; }
.study-bar-track {
  width: 100%; max-width: 30px; flex: 1;
  background: var(--hover); border-radius: 4px; overflow: hidden;
  display: flex; align-items: flex-end;
}
.study-bar-fill { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; }
.study-bar-col.today .study-bar-fill { background: var(--green); }
.study-bar-col.today .study-bar-label { color: var(--text); font-weight: 600; }
.study-bar-label { font-size: 9.5px; color: var(--text-secondary); white-space: nowrap; }
.study-summary { text-align: center; font-size: 12px; color: var(--text-secondary); margin: 12px 0 0; }

/* 首页 */
.home-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.home-hero { margin: 2px 0 10px; }
.home-date { margin: 0 0 6px; font-size: 12px; color: var(--text-secondary); letter-spacing: 0.02em; }
.home-head .home-title { margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; }
.icon-btn {
  width: 40px; height: 40px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 4px; background: transparent;
  color: var(--text-secondary); cursor: pointer; margin-top: 0; touch-action: manipulation;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 15px; height: 15px; }

.home-summary {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 0 16px; border-bottom: 1px solid var(--border);
}
.home-stat { display: flex; flex-direction: column; min-width: 44px; }
.home-stat .num { font-size: 28px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.home-stat .lbl { margin-top: 2px; font-size: 11px; color: var(--text-secondary); }
.home-stat.warn .num { color: var(--red); }
.home-divider { width: 1px; height: 34px; background: var(--border); flex-shrink: 0; }
.home-progress { flex: 1; min-width: 0; }
.home-progress-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-secondary); margin-bottom: 8px; }
.home-progress-track { height: 4px; background: var(--border); overflow: hidden; }
.home-progress-fill { height: 100%; background: var(--accent); transition: width 0.25s ease; }

.section-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.section-head h2 { margin: 0; }
.count-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 4px;
  background: var(--hover); color: var(--text-secondary);
  font-size: 11px; font-weight: 600; line-height: 20px; text-align: center;
}
.section-action { margin-left: auto; }

/* AI 输入行 */
#ai-helper-container .row { flex-wrap: nowrap; }
#ai-helper-container #ai-input { width: auto; flex: 1 1 auto; min-width: 0; }
#ai-helper-container #ai-send { flex: 0 0 auto; }

/* 底部导航设置 + 更多页 */
.nav-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.nav-option {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 11px; min-height: 40px; border-radius: 4px; background: var(--hover);
  font-size: 13px; cursor: pointer;
}
.nav-option input { width: 16px; height: 16px; margin: 0; accent-color: var(--text); }
.more-list { display: flex; flex-direction: column; margin-top: 6px; }
.more-item {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 13px 2px; border: none; border-bottom: 1px solid var(--border); border-radius: 0;
  background: transparent; color: var(--text); font-size: 14px; font-family: inherit; cursor: pointer;
}
.more-item:hover { background: var(--hover); }
.more-arrow { color: var(--text-secondary); font-size: 12px; }

/* 小屏（320–360px）收紧一点，避免横向溢出 */
@media (max-width: 360px) {
  #content { padding-left: 16px; padding-right: 16px; }
  .home-title { font-size: 28px; }
  .home-summary { flex-wrap: wrap; gap: 12px 16px; }
  .home-progress { flex-basis: 100%; }
  .home-stat .num { font-size: 24px; }
  .task { gap: 8px; }
  .task .title { font-size: 14px; }
  .task .due-today, .task .due-overdue, .task .muted { font-size: 11px; }
  .task-del { padding: 5px 3px; }
  .cal-cell { font-size: 13px; }
  .study-chart { gap: 3px; }
  .study-bar-label { font-size: 8.5px; }
  .btn { padding: 7px 11px; }
  .home-head { gap: 8px; }
}

/* 横屏或很矮的屏幕，弹窗别超出 */
@media (max-height: 620px) {
  .modal { max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); }
}
