:root {
  --bg: #fbfbfd;
  --fg: #1c1c1e;
  --sub: #8e8e93;
  --line: #e6e6ea;
  --card: #ffffff;
  --field: #f2f2f5;
  --accent: #0a84ff;
  --danger: #ff3b30;
  --ok: #0a9d58;
  --warn: #c98a00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0c;
    --fg: #f2f2f7;
    --sub: #8e8e93;
    --line: #2a2a2e;
    --card: #151517;
    --field: #1e1e21;
    --accent: #0a84ff;
    --danger: #ff453a;
    --ok: #32d583;
    --warn: #f5b301;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* hidden 属性必须能压过 .lock / #app / .toast 上的 display:flex，
   否则 el.hidden = true 完全无效 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px 32px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- 顶部 ---------- */
.top { padding: 8px 0 4px; }

.top .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.top h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.tools { display: flex; gap: 6px; }

.icon {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--sub);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.icon:active { transform: scale(0.96); }

.search { margin-top: 10px; }
.search input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--fg);
  font-size: 15px;
  outline: none;
}
.search input:focus { border-color: var(--accent); }

/* ---------- 健康灯 ---------- */
.health {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--sub);
}
.health .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  flex: none;
}
.health.warn .dot { background: var(--warn); }
.health.bad .dot { background: var(--danger); }
.health.bad .txt { color: var(--danger); }
.health.warn .txt { color: var(--warn); }

/* ---------- 输入 ---------- */
.add {
  display: flex;
  gap: 8px;
  margin: 14px 0 6px;
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 8px 0;
  background: linear-gradient(var(--bg) 70%, transparent);
}

.add input {
  flex: 1;
  padding: 13px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  font-size: 16px;
  outline: none;
}
.add input:focus { border-color: var(--accent); }
.add input::placeholder { color: var(--sub); }

.add button {
  width: 48px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.add button:active { transform: scale(0.94); }

/* ---------- 列表 ---------- */
.list { flex: 1; }

.group { margin-top: 18px; }

.group > h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sub);
  margin: 0 0 6px 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.group > h2 .n {
  font-weight: 400;
  opacity: 0.7;
}

.group.overdue > h2 { color: var(--danger); }

ul.items { list-style: none; margin: 0; padding: 0; }

.item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 8px;
  transition: transform 0.16s ease, opacity 0.16s ease;
  touch-action: pan-y;
  will-change: transform;
}

.item .check {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.item .check:active { transform: scale(0.9); }

.item.done .check {
  background: var(--ok);
  border-color: var(--ok);
  position: relative;
}
.item.done .check::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.item .body { flex: 1; min-width: 0; }

.item .t {
  font-size: 15px;
  word-break: break-word;
}

.item .m {
  font-size: 12px;
  color: var(--sub);
  margin-top: 2px;
}
.item .m:empty { display: none; }

.item.done .t {
  color: var(--sub);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.item.overdue { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.item.overdue .m { color: var(--danger); font-weight: 600; }

.item.removing,
.item.swiping { transform: translateX(-92px); opacity: 0.6; }

.item .del {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 92px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 0 14px 14px 0;
  font-size: 13px;
  cursor: pointer;
  display: none;
}
.item.swiping .del { display: block; }

/* ---------- 空状态 ---------- */
.empty {
  text-align: center;
  color: var(--sub);
  font-size: 14px;
  padding: 56px 20px;
}
.empty .big { font-size: 34px; margin-bottom: 10px; opacity: 0.35; }

/* ---------- 底部 ---------- */
.foot {
  margin-top: 28px;
  text-align: center;
}
.foot button {
  border: none;
  background: transparent;
  color: var(--sub);
  font-size: 12px;
  padding: 10px;
  cursor: pointer;
}
.foot b { color: var(--fg); font-weight: 600; }

/* ---------- 口令 ---------- */
.lock {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  z-index: 50;
}

.lock-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}
.lock-card h1 { font-size: 18px; margin: 0 0 4px; }
.lock-card .hint { font-size: 13px; color: var(--sub); margin: 0 0 20px; }
.lock-card input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  font-size: 16px;
  outline: none;
  margin-bottom: 10px;
}
.lock-card input:focus { border-color: var(--accent); }
.lock-card button {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.lock-card .err {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  margin: 10px 0 0;
}

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(28, 28, 30, 0.94);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.toast .undo {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
@media (prefers-color-scheme: dark) {
  .toast { background: rgba(242, 242, 247, 0.96); color: #000; }
}
