:root {
  --bg: #0f1217;
  --card: #1a1f28;
  --card-hi: #232a35;
  --line: #252c38;
  --text: #eef1f7;
  --muted: #7c8798;
  --dim: #525b6b;
  --accent: #6d8bff;
  --green: #3ddc97;
  --gold: #ffcf5c;
  --red: #ff6b6b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

#app {
  max-width: 620px;
  margin: 0 auto;
  padding: 0 14px calc(28px + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; }

/* ---------- 顶部标签 ---------- */
.tabs {
  position: sticky; top: 0; z-index: 30;
  display: flex; gap: 8px; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: linear-gradient(#0f1217 70%, rgba(15,18,23,0));
  backdrop-filter: blur(6px);
}
.tab {
  padding: 7px 16px; border-radius: 999px;
  color: var(--muted); font-weight: 600; font-size: 14px;
  transition: background .15s, color .15s;
}
.tab.on { color: var(--accent); background: rgba(109,139,255,.16); box-shadow: inset 0 0 0 1px rgba(109,139,255,.45); }
.tab:active { background: var(--card-hi); }
.tabs .spacer { flex: 1; }
.tabs .ghost { color: var(--muted); font-size: 13px; padding: 7px 10px; border-radius: 999px; }
.tabs .ghost:active { background: var(--card-hi); }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-bottom: 12px;
}

/* ---------- 今天：顶部概览 ---------- */
.head { padding: 14px 16px 12px; }
.head .l1 { display: flex; justify-content: space-between; color: var(--muted); font-size: 12.5px; }
.head .l2 { display: flex; align-items: center; gap: 14px; margin-top: 2px; }
.head .big { font-size: 38px; font-weight: 700; letter-spacing: .5px; line-height: 1.15; }
.head .big.done { color: var(--green); }
.head .big.empty { color: var(--dim); font-weight: 400; }
.head .progwrap { flex: 1; }
.prog { height: 9px; border-radius: 999px; background: var(--card-hi); overflow: hidden; }
.prog > i { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .35s ease; }
.prog > i.full { background: var(--green); }
.head .pct { text-align: right; color: var(--muted); font-size: 11.5px; margin-top: 5px; }
.head .status { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.head .status.warn { color: var(--red); }
.head .status.ok { color: var(--green); }

/* ---------- 添加栏 ---------- */
.addbar { display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 14px; }
.addbar input[type=text] { flex: 1; min-width: 0; background: none; border: 0; color: var(--text); padding: 12px 0; outline: none; font-size: 15px; }
.addbar input::placeholder { color: var(--muted); }
.addbar .min {
  width: 46px; text-align: center; background: none; border: 0;
  border-left: 1px solid var(--line); color: var(--text); padding: 8px 0; outline: none;
}
.addbar .unit { color: var(--muted); font-size: 12px; padding-right: 4px; }
.addbar .add {
  background: var(--accent); color: #0b0e14; font-weight: 700;
  padding: 9px 16px; border-radius: 10px; font-size: 14px;
}
.addbar .add:active { background: #8ba3ff; }

/* ---------- 列表 ---------- */
.list { min-height: 40px; }
.empty { color: var(--dim); text-align: center; padding: 40px 10px; font-size: 13.5px; line-height: 1.8; }

.task {
  position: relative;
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 13px; padding: 12px 12px 12px 16px; margin-bottom: 8px;
  touch-action: pan-y;
  transition: border-color .15s, background .15s, transform .12s;
}
.task:active { transform: scale(.995); }
.task.drag { opacity: .45; }
.task.hover { background: var(--card-hi); }
.task .rail {
  position: absolute; left: 5px; top: 11px; bottom: 11px; width: 3px;
  border-radius: 2px; background: var(--accent);
}
.task.star .rail { background: var(--gold); }
.task.done .rail { background: var(--green); }

.check {
  flex: 0 0 22px; width: 22px; height: 22px; margin-top: 1px;
  border-radius: 50%; border: 1.6px solid var(--muted);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
}
.check svg { width: 12px; height: 12px; opacity: 0; }
.task.done .check { background: var(--green); border-color: var(--green); }
.task.done .check svg { opacity: 1; }
.task.done .title { color: var(--dim); text-decoration: line-through; }

.body { flex: 1; min-width: 0; }
.title { font-size: 15px; word-break: break-word; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 3px; font-size: 11.5px; color: var(--muted); }
.meta .due { color: var(--gold); }
.meta .due.late { color: var(--red); }
.meta .rep { color: var(--accent); }
.meta .dn { color: var(--green); }
.star-i { color: var(--gold); font-size: 12px; }

.acts { display: flex; gap: 2px; align-items: center; flex: 0 0 auto; }
.acts button {
  width: 34px; height: 34px; border-radius: 9px; color: var(--dim);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.acts button:active { background: var(--card-hi); color: var(--text); }
.acts svg { width: 16px; height: 16px; }
.acts button span { font-size: 11.5px; }
@media (hover: hover) {
  .acts button { opacity: .55; }
  .task:hover .acts button { opacity: 1; }
}

/* ---------- 日历头 ---------- */
.calhead { display: flex; align-items: center; gap: 4px; padding: 2px 0 10px; }
.calhead .arrow { width: 34px; height: 34px; border-radius: 10px; color: var(--muted); font-size: 20px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.calhead .arrow:active { background: var(--card-hi); }
.calhead .title { font-size: 16px; font-weight: 700; margin-left: 6px; white-space: nowrap; }
.calhead .spacer { flex: 1; }
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.seg button { padding: 5px 10px; border-radius: 999px; font-size: 12.5px; color: var(--muted); }
.seg button.on { background: rgba(109,139,255,.18); color: var(--accent); font-weight: 600; }
.calhead .today { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--accent); font-size: 12.5px; }

/* ---------- 月视图 ---------- */
.month { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 8px; margin-bottom: 12px; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); color: var(--dim); font-size: 11px; text-align: center; padding: 2px 0 6px; }
.cells { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cell {
  position: relative; aspect-ratio: 1 / 1; min-height: 44px;
  border-radius: 9px; background: #171b23; border: 1px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding-top: 5px; font-size: 12.5px; color: var(--text);
  transition: background .15s, border-color .15s;
}
.cell.out { color: var(--dim); background: #13161d; }
.cell.sel { border-color: var(--accent); }
.cell.drop { background: rgba(109,139,255,.28); border-color: var(--accent); }
.cell.today .num { background: var(--accent); color: #0b0e14; border-radius: 999px; padding: 0 6px; font-weight: 700; }
.cell .num { line-height: 17px; }
.cell .due-dot { position: absolute; top: 6px; right: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--red); }
.cell .due-dot.ok { background: var(--green); }
.cell .chip {
  margin-top: auto; margin-bottom: 5px; font-size: 10px; line-height: 15px;
  padding: 0 6px; border-radius: 999px;
  background: rgba(109,139,255,.18); color: var(--accent);
}
.cell .chip.all { background: rgba(61,220,151,.16); color: var(--green); }
.cell .rec-dot { margin-top: auto; margin-bottom: 8px; width: 5px; height: 5px; border-radius: 50%; background: rgba(109,139,255,.6); }

/* ---------- 某天详情 ---------- */
.dayhead { display: flex; align-items: center; gap: 8px; padding: 2px 2px 8px; }
.dayhead b { font-size: 14px; }
.dayhead .sub { color: var(--muted); font-size: 12px; }
.dayhead .spacer { flex: 1; }
.dayhead .add { color: var(--accent); font-size: 13px; border: 1px solid var(--line); background: var(--card); padding: 5px 12px; border-radius: 999px; }

/* ---------- 周 / 两周 ---------- */
.agenda { padding-bottom: 10px; }
.days { }
.daysec { margin-bottom: 6px; }
.daybar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 4px 8px; border-bottom: 1px solid var(--line); margin-bottom: 8px;
}
.daybar b { font-size: 14px; }
.daybar .badge { font-size: 10.5px; color: var(--accent); background: rgba(109,139,255,.16); border-radius: 999px; padding: 1px 8px; }
.daybar .sub { margin-left: auto; color: var(--dim); font-size: 11.5px; }
.daysec.today .daybar b { color: var(--accent); }
.dayempty { color: var(--dim); font-size: 12.5px; padding: 2px 6px 10px; }

/* ---------- 全部 ---------- */
.listhead { display: flex; align-items: center; gap: 8px; padding: 2px 2px 10px; }
.listhead b { font-size: 14px; }
.listhead .spacer { flex: 1; }
.listhead .add { color: var(--accent); font-size: 13px; border: 1px solid var(--line); background: var(--card); padding: 6px 12px; border-radius: 999px; }

/* ---------- 底部设置 ---------- */
.foot { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; padding: 14px 4px 4px; font-size: 12px; color: var(--muted); }
.foot button { color: var(--muted); }
.foot button:active { color: var(--text); }
.foot .on { color: var(--accent); }
.foot .spacer { flex: 1; }

/* ---------- 弹窗 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.mask.on { opacity: 1; pointer-events: auto; }
.dialog {
  width: 100%; max-width: 420px; max-height: 90vh; overflow: auto;
  background: #151a22; border: 1px solid var(--line); border-radius: 18px; padding: 18px;
  transform: translateY(8px); transition: transform .18s;
}
.mask.on .dialog { transform: none; }
.dialog h3 { margin: 0 0 14px; font-size: 15px; font-weight: 600; display: flex; align-items: center; }
.dialog h3 .spacer { flex: 1; }
.field { margin-bottom: 12px; }
.field > label { display: block; color: var(--muted); font-size: 11.5px; margin-bottom: 5px; }
.input {
  width: 100%; background: var(--card-hi); border: 1px solid transparent; border-radius: 10px;
  color: var(--text); padding: 10px 12px; outline: none; font-size: 14px;
}
.input:focus { border-color: rgba(109,139,255,.6); }
.input:disabled { color: var(--dim); }
.row { display: flex; gap: 8px; }
.chip {
  padding: 6px 12px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--line); color: var(--muted); font-size: 12.5px;
}
.chip.on { background: rgba(109,139,255,.16); border-color: rgba(109,139,255,.55); color: var(--accent); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.hint { font-size: 11.5px; color: var(--dim); margin-top: 6px; }
.hint.bad { color: var(--red); }
.dialog .btns { display: flex; gap: 8px; margin-top: 18px; }
.dialog .btns button { flex: 1; padding: 11px; border-radius: 11px; font-weight: 600; font-size: 14px; }
.btn-primary { background: var(--accent); color: #0b0e14; }
.btn-ghost { background: var(--card); border: 1px solid var(--line); color: var(--muted); }
.btn-danger { background: transparent; border: 1px solid rgba(255,107,107,.4); color: var(--red); }

/* ---------- 提示条 ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px); z-index: 70;
  background: var(--card-hi); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 18px; font-size: 13px; color: var(--text);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 40px); text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 特效 ---------- */
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 55; }

/* ---------- 窄屏 ---------- */
@media (max-width: 430px) {
  #app { padding: 0 10px calc(20px + env(safe-area-inset-bottom)); }
  .head .big { font-size: 32px; }
  .cell { min-height: 40px; font-size: 12px; }
  .cell .chip { font-size: 9px; padding: 0 4px; }
  .calhead .title { font-size: 14px; }
  .seg button { padding: 5px 8px; font-size: 12px; }
  .calhead .today { padding: 6px 10px; }
}
