:root {
  --bg: #f6f4ef;
  --card: #fffdf8;
  --text: #2b2a27;
  --muted: #8a867d;
  --line: #e7e2d7;
  --line-strong: #d6d0c3;
  --accent: #6fa58a;
  --now: #c98f5a;
  --c-fixed: #8aa4c4;
  --c-deep: #6fa58a;
  --c-recovery: #ab9acb;
  --c-default: #bcae94;
  --tabbar-h: 56px;
  --gutter: 52px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1c;
    --card: #242427;
    --text: #ecebe7;
    --muted: #9a978f;
    --line: #313136;
    --line-strong: #3d3d43;
    --now: #d9a273;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 88px); /* 给 + 按钮留位置 */
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

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

h1 { font-size: 26px; font-weight: 600; margin: 20px 0 4px; letter-spacing: .5px; }
h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px; }

.muted { color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.center { text-align: center; }

input, textarea, button { font: inherit; color: inherit; }
input, textarea { font-size: 16px; } /* 小于 16px 时 iOS 会自动放大页面 */

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 10px 0;
}

/* ---------- 今日页头部 ---------- */
.sleep-line { margin: 0 0 8px; font-size: 15px; display: flex; align-items: center; flex-wrap: wrap; }
.sleep-line label { display: inline-flex; align-items: center; min-height: 44px; }
.inline-time {
  border: 0;
  background: transparent;
  padding: 0 4px;
  min-height: 44px;
  font-weight: 600;
  color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
}

.summary {
  width: 100%;
  border: 0;
  background: transparent;
  resize: none;
  padding: 4px 0;
  min-height: 32px;
  outline: none;
  line-height: 1.5;
}

.reminders { list-style: none; margin: 0; padding: 0; }
.reminders li { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.reminders li.done span { color: var(--muted); text-decoration: line-through; }

.check { flex: 1; display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: none; }
.check.big { margin-top: 4px; }

.icon-btn {
  width: 44px; height: 44px;
  border: 0; background: transparent;
  color: var(--muted);
  font-size: 22px;
  flex: none;
}

.add-form { display: flex; }
.add-input {
  flex: 1;
  min-height: 44px;
  border: 0;
  background: transparent;
  outline: none;
  padding: 0;
}
.add-input::placeholder, .summary::placeholder { color: var(--muted); }

/* ---------- 时间轴 ---------- */
.timeline-wrap { padding: 14px 0 6px; }

.timeline { position: relative; }

.hour {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-top: 1px solid var(--line);
  pointer-events: none;
}
.hour span {
  position: absolute;
  left: 0;
  width: calc(var(--gutter) - 8px);
  transform: translateY(-50%);
  background: var(--bg);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.hour.edge { border-top-color: var(--line-strong); }
.hour.edge span { color: var(--text); font-weight: 600; }

.lane {
  position: absolute;
  top: 0; bottom: 0;
  left: var(--gutter);
  right: 0;
}

.deep-zone {
  position: absolute;
  left: 0; right: 0;
  background: color-mix(in srgb, var(--c-deep) 9%, transparent);
  border-radius: 10px;
  pointer-events: none;
}
.deep-zone span {
  position: absolute;
  right: 8px; top: 4px;
  font-size: 11px;
  color: color-mix(in srgb, var(--c-deep) 80%, var(--text));
  opacity: .8;
}

.block {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  overflow: hidden;
  text-align: left;
  border: 0;
  border-left: 4px solid var(--c);
  border-radius: 8px;
  padding: 4px 8px;
  background: color-mix(in srgb, var(--c) 24%, var(--card));
  line-height: 1.3;
  cursor: pointer;
}
.block.t-fixed { --c: var(--c-fixed); }
.block.t-deep { --c: var(--c-deep); }
.block.t-recovery { --c: var(--c-recovery); }
.block.t-default { --c: var(--c-default); }

.b-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.b-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.b-deliv { font-size: 13px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.block.short { flex-direction: row; align-items: center; gap: 8px; padding-top: 0; padding-bottom: 0; }
.block.short .b-deliv { display: none; }
.block.done { opacity: .6; }

.now {
  position: absolute;
  left: calc(var(--gutter) - 6px);
  right: 0;
  height: 0;
  border-top: 2px solid var(--now);
  pointer-events: none;
  z-index: 2;
}
.now::before {
  content: "";
  position: absolute;
  left: -4px; top: -6px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--now);
}
.now[hidden] { display: none; }

.sleep-band {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-left: var(--gutter);
  padding: 0 12px;
  height: 28px;
  border-radius: 8px;
  font-size: 12px;
  background: color-mix(in srgb, var(--muted) 14%, transparent);
}

/* ---------- 悬浮按钮和底栏 ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .15);
  z-index: 5;
}
.fab[hidden] { display: none; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 6;
}
.tabbar button {
  flex: 1;
  border: 0;
  background: transparent;
  font-size: 15px;
  color: var(--muted);
}
.tabbar button[aria-current="true"] { color: var(--text); font-weight: 600; }

/* ---------- 底部弹出的编辑面板 ---------- */
.sheet {
  border: 0;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  background: var(--card);
  color: var(--text);
  border-radius: 18px 18px 0 0;
}
.sheet::backdrop { background: rgba(0, 0, 0, .3); }

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-body h2 { font-size: 15px; color: var(--text); margin: 0; }
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 0 auto 4px; }

.sheet-body input:not([type=checkbox]), .sheet-body textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  padding: 8px 12px;
  outline: none;
}
.sheet-body textarea { resize: none; }
.f-title { font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); }
.field[hidden] { display: none; }
.time-row { display: flex; gap: 10px; }
.time-row input { -webkit-appearance: none; appearance: none; }

.seg-group { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  font-size: 14px;
  padding: 0 2px;
}
.seg.t-fixed { --c: var(--c-fixed); }
.seg.t-deep { --c: var(--c-deep); }
.seg.t-recovery { --c: var(--c-recovery); }
.seg.t-default { --c: var(--c-default); }
.seg[aria-pressed="true"] {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 28%, var(--card));
  font-weight: 600;
}

.msg { margin: 0; font-size: 14px; color: var(--muted); min-height: 0; }
.msg:empty { display: none; }

.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  border: 0;
  font-size: 16px;
}
.btn.primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.full { width: 100%; margin-top: 6px; }
.actions .btn.ghost:first-child:not(:only-of-type) { margin-right: auto; }

/* ---------- 设置页 ---------- */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
}
.row:last-of-type { border-bottom: 0; }
.row span { display: flex; align-items: center; gap: 8px; }
.row input[type=time] {
  border: 0; background: transparent; text-align: right; min-height: 44px; color: var(--accent); font-weight: 600;
  -webkit-appearance: none; appearance: none;
}
.row input[type=color] { width: 44px; height: 32px; border: 0; padding: 0; background: transparent; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--c); }
.swatch.t-fixed { --c: var(--c-fixed); }
.swatch.t-deep { --c: var(--c-deep); }
.swatch.t-recovery { --c: var(--c-recovery); }
.swatch.t-default { --c: var(--c-default); }

@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } }
}

/* ---------- 里程碑 2 ---------- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin: 12px 0 0;
  padding: 10px 4px 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
}
.banner p { margin: 0; flex: 1; padding-top: 2px; }

.pending-card { background: color-mix(in srgb, var(--c-deep) 12%, var(--card)); }
.pending-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
  padding: 0;
}
.pending-row:first-of-type { border-top: 0; }
.pending-row .muted { font-size: 13px; flex: none; }
.pr-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); font-size: 20px; }

.block.pending { border: 1.5px dashed var(--c); border-left: 4px solid var(--c); }
.block.faded { opacity: .45; }

.checkin-meta { margin: 0; font-size: 14px; }
.checkin-deliv { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.choice-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn.soft { background: var(--bg); border: 1px solid var(--line); padding: 0 6px; }
.seg-group.two { grid-template-columns: repeat(2, 1fr); }
.seg:not([class*="t-"])[aria-pressed="true"] { --c: var(--accent); }

/* 本周页 */
.sub { margin: 0; font-size: 14px; }
.week-count { font-size: 17px; margin: 14px 0 4px; }
.week-count b { font-size: 22px; }
.week-list { list-style: none; padding: 4px 14px; }
.week-day { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.week-day:last-child { border-bottom: 0; }
.wd-label { width: 48px; flex: none; display: flex; flex-direction: column; line-height: 1.3; }
.wd-label span { font-size: 12px; }
.week-day.is-today .wd-label b { color: var(--accent); }
.wd-items { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.wd-item { display: flex; gap: 8px; align-items: baseline; }
.wd-item .mark { width: 16px; flex: none; color: var(--muted); text-align: center; }
.wd-item.done .mark { color: var(--accent); font-weight: 700; }
.wd-item.dropped { color: var(--muted); }

.review .field { margin-top: 10px; }
.review .field .hint { margin: 0; }
.review textarea, .review input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  padding: 8px 12px;
  outline: none;
  resize: none;
}
.review .row b { font-size: 17px; }
.hint.first { margin: 0 0 8px; }

/* ---------- V1.0 ---------- */
/* 顶部日期栏 / 月份栏：‹ 标题 ›，日视图里滚动时贴在顶部 */
.nav-bar {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 8px -16px 0;
  padding: 4px 4px;
}
.nav-bar h1 { margin: 0; font-size: 18px; flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-bar .rel { font-weight: 400; color: var(--muted); font-size: 14px; }
.nav-bar .icon-btn { font-size: 28px; color: var(--text); width: 40px; }
.back-btn { margin-left: auto; padding: 0 8px; font-size: 14px; white-space: nowrap; flex: none; color: var(--accent) !important; }
.day-nav {
  position: sticky;
  top: 0;
  z-index: 4;
  margin-top: 0;
  padding-top: 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.add-btn {
  flex: none;
  min-width: 56px;
  padding: 0 12px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
}

/* 周视图：每天一行可点 */
.week-list li { border-bottom: 1px solid var(--line); }
.week-list li:last-child { border-bottom: 0; }
button.week-day {
  width: 100%;
  border: 0;
  border-bottom: 0;
  background: transparent;
  text-align: left;
  align-items: center;
  min-height: 48px;
}
button.week-day .chev { color: var(--muted); font-size: 20px; flex: none; }

/* 月视图 */
.month-card { padding: 10px 8px; }
.mc-head, .mc-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.mc-head span { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 6px; }
.mc {
  position: relative;
  min-height: 56px;
  min-width: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 1px;
  padding: 6px 0 4px;
}
.mc-num {
  width: 28px; height: 28px;
  line-height: 28px;
  border-radius: 50%;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.mc.is-today .mc-num { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent); font-weight: 600; }
.mc-count { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mc-count.all { color: var(--accent); font-weight: 600; }
.mc-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); opacity: .6; }

/* 拖动 */
.block { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.block.lifted {
  z-index: 3;
  overflow: visible;
  touch-action: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  outline: 1.5px solid var(--c);
}
.block.dragging { opacity: .95; }
.drag-handle {
  position: absolute;
  left: 0; right: 0;
  bottom: -22px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: ns-resize;
}
.drag-handle i {
  width: 40px; height: 6px;
  border-radius: 3px;
  background: var(--c);
  box-shadow: 0 0 0 2px var(--card);
}
@media (prefers-reduced-motion: no-preference) {
  .block.lifted { transition: box-shadow .15s; }
}

/* ---------- V1.1 ---------- */
.earlier-row { padding: 8px 0; border-top: 1px solid var(--line); }
.earlier-row:first-of-type { border-top: 0; }
.er-text { margin: 0 0 6px; overflow-wrap: anywhere; }
.er-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.btn.small { font-size: 14px; padding: 0 4px; }
.reminders li.moved span { color: var(--muted); }

/* 周总结里“这周没完成的提醒” */
.review .reminders li { border-bottom: 1px solid var(--line); }
.check-box { width: 44px; min-height: 44px; display: flex; align-items: center; flex: none; }
.check-box input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.link-row {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  min-height: 44px;
  border: 0; background: transparent; padding: 0; text-align: left;
}
.link-row .muted { font-size: 13px; flex: none; }
.review li.done .pr-text { color: var(--muted); text-decoration: line-through; }
.review .field > span:first-child { font-size: 13px; color: var(--muted); }

/* 循环 */
.sub-h { margin: 10px 0 2px; font-size: 14px; font-weight: 600; }
.routine-row {
  display: flex; align-items: center; gap: 8px;
  width: 100%; min-height: 48px;
  border: 0; border-bottom: 1px solid var(--line);
  background: transparent; text-align: left; padding: 0;
}
.rr-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rr-days { font-size: 13px; flex: none; }
.add-routine { padding: 0; color: var(--accent); }
.seg-group.seven { grid-template-columns: repeat(7, 1fr); gap: 4px; }
.seg.day { padding: 0; }
.b-deliv.empty { color: var(--muted); font-style: italic; }

/* 同步 */
.sync-form .field { margin-bottom: 8px; }
.sync-form input, .settings .sync-form input {
  width: 100%; min-height: 44px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); padding: 8px 12px; outline: none;
  font-size: 16px;
}
.key-box { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; user-select: all; -webkit-user-select: all; }
.key-box[hidden] { display: none; }
