:root {
  --bg: #f3f5ff;
  --bg-glow-a: #e7ecff;
  --bg-glow-b: #fbeefb;
  --card: #ffffff;
  --text: #1d2340;
  --muted: #7b85a5;
  --line: #e8ecf8;
  --primary: #5566f5;
  --primary-strong: #4150e4;
  --primary-soft: #eef0ff;
  --success: #12a37a;
  --success-soft: #e7f8f1;
  --danger: #e8526a;
  --danger-soft: #fff0f2;
  --field: #f7f9ff;
  --done-bg: #f7f9fc;
  --shadow: 0 12px 34px rgba(46, 60, 132, .10);
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1120;
    --bg-glow-a: #17203d;
    --bg-glow-b: #1c1730;
    --card: #171d30;
    --text: #edf1ff;
    --muted: #98a3c4;
    --line: #283150;
    --primary: #8390ff;
    --primary-strong: #6d7cf5;
    --primary-soft: #232b4d;
    --success: #43d6a5;
    --success-soft: #173a31;
    --danger: #ff7d92;
    --danger-soft: #3a1e2b;
    --field: #1e2540;
    --done-bg: #141a2b;
    --shadow: 0 12px 34px rgba(0, 0, 0, .30);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 12% 4%, var(--bg-glow-a) 0, transparent 42%),
    radial-gradient(circle at 92% 12%, var(--bg-glow-b) 0, transparent 38%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }
button { cursor: pointer; }

.page {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 30px 18px calc(36px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border-radius: 15px;
  background: linear-gradient(140deg, var(--primary), #8f7cf7);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(85, 102, 245, .32);
}

.brand-text { min-width: 0; }
.brand h1 { margin: 0; font-size: 21px; letter-spacing: .3px; font-weight: 700; }
.date-line { margin: 3px 0 0; font-size: 13px; color: var(--muted); }

.user-box { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 700;
  font-size: 14px;
}
.username { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 600; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.muted { color: var(--muted); font-size: 13px; margin: 0; }
.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; }
[hidden] { display: none !important; }

/* ---------- 认证 ---------- */
.auth-card { max-width: 430px; margin: 8px auto 24px; }
.auth-tabs {
  display: flex;
  background: var(--field);
  border-radius: 13px;
  padding: 5px;
  margin-bottom: 24px;
}
.tab {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  transition: background .18s, color .18s, box-shadow .18s;
}
.tab.active { background: var(--card); color: var(--primary-strong); box-shadow: 0 2px 10px rgba(46,60,132,.10); }
.auth-title { margin: 0 0 6px; font-size: 22px; }
.auth-card > .muted { margin-bottom: 22px; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 8px; }
.text-input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  background: var(--field);
  color: var(--text);
  outline: none;
  transition: border-color .18s, box-shadow .18s, background .18s;
  font-size: 16px;
}
.text-input::placeholder { color: var(--muted); opacity: .8; }
.text-input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); background: var(--card); }
.text-input.invalid { border-color: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
#authForm .text-input { margin-bottom: 18px; }

.btn-primary {
  min-height: 50px;
  padding: 0 22px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 6px 16px rgba(85, 102, 245, .25);
  transition: transform .12s, box-shadow .18s, opacity .18s;
}
.btn-primary:active { transform: scale(.975); }
.btn-primary:hover { box-shadow: 0 9px 22px rgba(85, 102, 245, .32); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-ghost {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.btn-ghost:hover { color: var(--danger); border-color: var(--danger); }

.form-error, .field-hint {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}
.privacy-note { text-align: center; color: var(--muted); font-size: 12px; margin: 20px 0 0; }

/* ---------- 进度 ---------- */
.summary-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.eyebrow { margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 1.4px; color: var(--primary); text-transform: uppercase; }
.summary-figure { display: flex; align-items: baseline; gap: 9px; margin: 0 0 6px; }
.count-number { font-size: 44px; font-weight: 800; line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; }
.count-number.bump { animation: pop .42s ease; }
.count-unit { font-size: 14px; font-weight: 600; color: var(--muted); }
.progress-badge {
  flex: 0 0 74px;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 800;
  font-size: 19px;
  border: 6px solid var(--card);
  box-shadow: 0 0 0 2px var(--line);
  font-variant-numeric: tabular-nums;
}
.progress-track { height: 9px; border-radius: 999px; background: var(--field); overflow: hidden; margin-top: 18px; }
.progress-fill {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width .38s cubic-bezier(.22,.9,.3,1);
}

/* ---------- 新增 ---------- */
.add-row { display: flex; gap: 10px; align-items: stretch; }
.task-input { flex: 1; min-width: 0; }
.add-btn { flex: 0 0 96px; padding: 0 12px; }
.tip { margin: 12px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- 列表 ---------- */
.list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.list-head h2 { margin: 0; font-size: 16px; }
.badge { padding: 5px 11px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-strong); font-size: 12px; font-weight: 700; }
.task-list { list-style: none; margin: 0; padding: 0; }
.task-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 62px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  border-radius: 12px;
  animation: slideIn .26s ease both;
  transition: background .2s, opacity .2s, transform .2s;
}
.task-item:last-child { border-bottom: 0; }
.task-item.done { background: var(--done-bg); }
.task-item.removing { opacity: 0; transform: translateX(22px); }

.check-wrap {
  position: relative;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 12px;
}
.check-wrap:hover { background: var(--primary-soft); }
.task-check { position: absolute; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 2; }
.check-visual {
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  display: grid;
  place-items: center;
  transition: background .18s, border-color .18s, transform .18s;
}
.check-visual::after {
  content: "";
  width: 6px;
  height: 11px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) scale(0);
  margin-top: -2px;
  transition: transform .18s ease;
}
.task-check:checked + .check-visual { background: var(--success); border-color: var(--success); transform: scale(1.06); }
.task-check:checked + .check-visual::after { transform: rotate(45deg) scale(1); }
.task-check:focus-visible + .check-visual { outline: 3px solid var(--primary); outline-offset: 3px; }

.task-text {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  transition: color .2s, opacity .2s;
}
.task-item.done .task-text { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 2px; opacity: .78; }
.task-state { flex: 0 0 auto; font-size: 11px; font-weight: 700; color: var(--success); padding: 4px 8px; border-radius: 8px; background: var(--success-soft); }
.delete-btn {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background .18s, color .18s;
}
.delete-btn:hover, .delete-btn:focus-visible { background: var(--danger-soft); color: var(--danger); outline: none; }

.empty-state { text-align: center; padding: 30px 10px 20px; }
.empty-icon { display: inline-grid; place-items: center; width: 54px; height: 54px; border-radius: 18px; background: var(--primary-soft); color: var(--primary); font-size: 26px; margin-bottom: 12px; }
.empty-title { margin: 0 0 6px; font-weight: 700; }

.footer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 24px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 40px);
  padding: 12px 20px;
  border-radius: 14px;
  background: #22294a;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  z-index: 50;
  animation: toastIn .24s ease;
  text-align: center;
}
.toast.error { background: #b8344c; }

@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.28); color: var(--primary); } 100% { transform: scale(1); } }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.shake { animation: shake .3s ease; }

@media (max-width: 560px) {
  .page { padding: 20px 14px calc(28px + env(safe-area-inset-bottom)); }
  .topbar { flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
  .brand-mark { flex-basis: 42px; width: 42px; height: 42px; border-radius: 13px; font-size: 22px; }
  .brand h1 { font-size: 19px; }
  .user-box { width: 100%; justify-content: flex-end; }
  .card { padding: 18px 15px; border-radius: 17px; margin-bottom: 13px; }
  .count-number { font-size: 38px; }
  .progress-badge { flex-basis: 62px; width: 62px; height: 62px; font-size: 16px; }
  .add-btn { flex-basis: 84px; }
  .task-item { gap: 4px; min-height: 64px; }
  .check-wrap, .delete-btn { flex-basis: 46px; width: 46px; height: 46px; }
  .task-text { font-size: 15px; }
  .task-state { display: none; }
}

@media (max-width: 360px) {
  .add-btn { flex-basis: 74px; padding: 0 8px; font-size: 14px; }
  .text-input { font-size: 16px; padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
