/* style.css — 打卡日历：iPhone 优先，裸 CSS 无依赖 */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #1b1b1f;
  --text-dim: #6b7280;
  --border: #e4e4e7;
  --accent: #3e63dd;
  --accent-soft: #e7ecfc;
  --danger: #e5484d;
  --today-ring: #3e63dd;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1c1c1f;
    --text: #f0f0f2;
    --text-dim: #9ca3af;
    --border: #2e2e33;
    --accent: #7b9bf0;
    --accent-soft: #232b45;
    --today-ring: #7b9bf0;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(16px + var(--safe-bottom));
}

button {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px; /* 触屏最小目标 */
  cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: scale(0.96); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }

/* ── 顶栏 ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav button { min-width: 44px; padding: 6px 10px; }
.month-label { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 96px; }
.today-btn { color: var(--accent); border-color: var(--accent); font-size: 14px; min-height: 36px; }

main { max-width: 560px; margin: 0 auto; padding: 0 12px; }

/* ── 统计条 ── */
.stats { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.stats:empty { display: none; }
.stat-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--text-dim);
}
.stat-chip .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.stat-chip b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ── 月历 ── */
.calendar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays span {
  text-align: center; font-size: 12px; color: var(--text-dim);
  padding: 8px 0 4px;
}
.grid { border-top: 1px solid var(--border); }
.day {
  min-height: 56px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 5px 3px 4px;
  position: relative;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.day:nth-child(7n) { border-right: none; }
.day.out { opacity: 0.32; }
.day .num {
  font-size: 13px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-variant-numeric: tabular-nums;
}
.day.today .num {
  background: var(--today-ring); color: #fff; font-weight: 700;
}
.day .dots {
  display: flex; flex-wrap: wrap; gap: 2px;
  justify-content: center; align-items: center;
  min-height: 18px;
}
.day .hb {
  width: 18px; height: 18px; border-radius: 5px;
  font-size: 9px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ── 任务列表 ── */
.habits { margin-top: 16px; }
.habits-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.habits-head h2 { font-size: 17px; }
.habit-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.habit-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px; min-height: 52px;
  cursor: pointer;
}
.habit-item .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.habit-item .name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.habit-item .streak { font-size: 13px; color: var(--text-dim); flex: none; }
.habit-item .streak b { color: var(--text); }
.habit-item .chevron { color: var(--text-dim); font-size: 14px; flex: none; }

.empty-hint { color: var(--text-dim); font-size: 14px; padding: 12px 4px; }

/* ── 底部按钮 ── */
.io { display: flex; gap: 8px; margin-top: 20px; }
.io button { flex: 1; color: var(--text-dim); }

/* ── 底部弹层 (dialog) ── */
dialog.sheet {
  border: none;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 560px;
  margin: auto auto 0; /* 贴底 */
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + var(--safe-bottom));
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog[open] { animation: slide-up 0.18s ease-out; }
@keyframes slide-up { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-size: 17px; }
.close { border: none; background: transparent; min-width: 44px; min-height: 44px; font-size: 18px; color: var(--text-dim); }

/* 当日勾选列表 */
.check-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.check-item {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; min-height: 52px; cursor: pointer;
  background: transparent; color: var(--text); width: 100%;
}
.check-item .dot { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.check-item .name { flex: 1; text-align: left; font-weight: 500; }
.check-item .box {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: transparent;
}
.check-item.checked { background: var(--accent-soft); border-color: var(--accent); }
.check-item.checked .box { background: var(--accent); border-color: var(--accent); color: #fff; }

/* 任务编辑表单 */
.habit-form { display: flex; flex-direction: column; gap: 16px; }
.field { border: none; display: flex; flex-direction: column; gap: 8px; }
.field > span, .field legend { font-size: 13px; color: var(--text-dim); padding: 0; }
.field input[type="text"] {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; min-height: 48px; width: 100%;
}
.field input[type="text"]:focus { outline: 2px solid var(--accent); border-color: transparent; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid transparent; cursor: pointer; padding: 0; min-height: 40px;
}
.swatch.selected { border-color: var(--text); }
.custom-color { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-dim); }
.custom-color input[type="color"] {
  width: 40px; height: 40px; border: 1px solid var(--border);
  border-radius: 50%; padding: 0; background: transparent; cursor: pointer;
}
.form-actions { display: flex; gap: 8px; align-items: center; }
.form-actions .spacer { flex: 1; }

/* ── toast ── */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px;
  z-index: 100; white-space: nowrap;
}

@media (min-width: 600px) {
  .topbar { padding-left: 24px; padding-right: 24px; }
  dialog.sheet { border-radius: 16px; margin: auto; }
}
