:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --urgent: #dc2626;
  --high: #ea580c;
  --medium: #ca8a04;
  --low: #16a34a;
  --urgent-bg: #fef2f2;
  --high-bg: #fff7ed;
  --medium-bg: #fefce8;
  --low-bg: #f0fdf4;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d24;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #2a2f3a;
    --brand: #818cf8;
    --brand-ink: #111827;
    --urgent: #f87171;
    --high: #fb923c;
    --medium: #facc15;
    --low: #4ade80;
    --urgent-bg: #2a1515;
    --high-bg: #2a1c12;
    --medium-bg: #26230f;
    --low-bg: #12241a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }

header.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) 16px 8px;
  max-width: 640px; margin: 0 auto;
}
.title-row { display: flex; align-items: center; gap: 10px; }
.title-row h1 { font-size: 22px; margin: 0; flex: 1; }
.me {
  display: flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px 4px 4px; font-size: 14px;
}
.demo-banner {
  font-size: 13px; color: var(--muted); margin: 6px 0 0;
}
.demo-banner select { font-size: 13px; padding: 2px 4px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); }

.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 700; flex: none;
}
.avatar.none { background: transparent; border: 1.5px dashed var(--muted); color: var(--muted); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap;
}
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip .count { opacity: .75; margin-left: 4px; }
.chip.review { border-color: var(--high); color: var(--high); }
.chip.review.on { background: var(--high); color: #fff; }

.quick { display: flex; gap: 8px; margin: 10px 0 4px; }
.quick input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
}
.quick input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.btn {
  border: none; border-radius: 12px; padding: 12px 16px;
  background: var(--brand); color: var(--brand-ink); font-weight: 600;
}
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--urgent); border: 1px solid var(--urgent); }
.btn.warn { background: var(--high); color: #fff; }

.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin: 8px 2px 4px; flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; background: var(--c); }

.section-label { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 2px 8px; }

.task {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); border-left: 6px solid var(--p);
  padding: 12px 12px 12px 10px; margin-bottom: 8px;
}
.task[data-p="urgent"] { --p: var(--urgent); background: linear-gradient(90deg, var(--urgent-bg), var(--card) 45%); }
.task[data-p="high"]   { --p: var(--high);   background: linear-gradient(90deg, var(--high-bg), var(--card) 45%); }
.task[data-p="medium"] { --p: var(--medium); }
.task[data-p="low"]    { --p: var(--low); }
.task.done { opacity: .55; }
.task.done .t-title { text-decoration: line-through; }
.task.pending { border-style: dashed; border-left-style: solid; }

.check {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  border: 2.5px solid var(--p); background: transparent; display: grid; place-items: center; padding: 0;
}
.check.doing { background: linear-gradient(90deg, var(--p) 50%, transparent 50%); }
.check.done { background: var(--p); }
.check svg { width: 16px; height: 16px; stroke: #fff; stroke-width: 3; fill: none; }

.t-body { flex: 1; min-width: 0; background: none; border: none; text-align: left; padding: 0; }
.t-title { font-weight: 600; overflow-wrap: anywhere; }
.t-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; font-size: 13px; color: var(--muted); align-items: center; }
.tag { border-radius: 6px; padding: 1px 6px; background: var(--bg); border: 1px solid var(--line); }
.tag.due-overdue { background: var(--urgent); color: #fff; border-color: var(--urgent); font-weight: 600; }
.tag.due-today { background: var(--high); color: #fff; border-color: var(--high); font-weight: 600; }
.tag.due-soon { color: var(--high); border-color: var(--high); }
.tag.private { color: var(--brand); border-color: var(--brand); }
.tag.pending { color: var(--high); border-color: var(--high); }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

.fab {
  position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--brand); color: var(--brand-ink); font-size: 30px; line-height: 1;
  box-shadow: 0 6px 16px rgba(79,70,229,.4); z-index: 6;
}

/* Bottom sheet editor */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(40px); } }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input[type=text], .field input[type=date], .field textarea, .field select {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}
.field textarea { min-height: 70px; resize: vertical; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button { padding: 10px 4px; border-radius: 10px; border: 2px solid var(--c); background: transparent; color: var(--c); font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--c); color: #fff; }
.row-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.row-chips .chip { display: inline-flex; align-items: center; gap: 6px; }
.row-chips .chip .avatar { width: 20px; height: 20px; font-size: 10px; }
.toggle { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.toggle input { width: 22px; height: 22px; accent-color: var(--brand); }
.toggle small { display: block; color: var(--muted); }
.actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.actions .btn { flex: 1; }
.note { font-size: 13px; padding: 10px 12px; border-radius: 10px; background: var(--high-bg); border: 1px solid var(--high); margin-bottom: 14px; }

/* Sign in */
.signin { max-width: 380px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.signin img { width: 72px; height: 72px; }
.signin input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); margin: 16px 0 10px; }
.signin .btn { width: 100%; }
.signin p { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20;
  display: flex; gap: 12px; align-items: center;
}
.toast button { background: none; border: none; color: var(--brand); font-weight: 700; padding: 0; }
