:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #667089;
  --line: #e2e6ef;
  --primary: #2f45d8;
  --primary-ink: #ffffff;
  --primary-soft: #e6e9fc;
  --done: #17a177;
  --done-soft: #ddf3ea;
  --warn: #b86e00;
  --warn-soft: #fdefd4;
  --danger: #d6455d;
  --danger-soft: #fbe3e7;
  --radius: 16px;
  --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0f1420;
  --surface: #182033;
  --ink: #e8ecf6;
  --muted: #98a2bd;
  --line: #27314a;
  --primary: #8c9bff;
  --primary-ink: #0f1420;
  --primary-soft: #232c55;
  --done: #3ccf9f;
  --done-soft: #16352f;
  --warn: #f0b04a;
  --warn-soft: #3a2f16;
  --danger: #ff7c92;
  --danger-soft: #3d1f28;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.4 var(--font);
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

#app { max-width: 640px; margin: 0 auto; padding: 20px 16px 8px; }

/* Header */
.head { margin: 4px 2px 18px; }
.head h1 { font-size: 30px; line-height: 1.1; font-weight: 650; letter-spacing: -0.02em; margin: 0; }
.head p { margin: 6px 0 0; color: var(--muted); font-size: 15px; }

/* Group chips */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 16px; padding: 2px 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip.small { padding: 6px 12px; font-size: 13px; }

/* Task list */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.task {
  position: relative; display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border-radius: var(--radius); padding: 14px 14px 14px 16px;
  border: 1px solid var(--line); overflow: hidden;
}
.task::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--line); }
.task.due-soon::before { background: var(--warn); }
.task.overdue::before { background: var(--danger); }
.task.finished::before { background: var(--done); }
button.task { width: 100%; text-align: left; }
.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 600; font-size: 16.5px; overflow-wrap: anywhere; }
.task.finished .title { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.task .desc { color: var(--muted); font-size: 14px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.task .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }

.check {
  flex: none; width: 30px; height: 30px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--line); background: transparent; display: grid; place-items: center; padding: 0;
  transition: background .18s, border-color .18s, transform .18s;
}
.check svg { width: 16px; height: 16px; stroke: var(--primary-ink); opacity: 0; transform: scale(.5); transition: opacity .18s, transform .18s; }
.check[aria-checked="true"] { background: var(--done); border-color: var(--done); }
.check[aria-checked="true"] svg { opacity: 1; transform: scale(1); }
.check:active { transform: scale(.9); }
:root[data-theme="dark"] .check svg { stroke: #0f1420; }

.pill { font-size: 12.5px; font-weight: 550; padding: 3px 9px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.done { background: var(--done-soft); color: var(--done); }
.pill.plain { background: transparent; border: 1px solid var(--line); color: var(--muted); }

/* Assignee pips: the signature element — who has done their part at a glance */
.pips { display: inline-flex; align-items: center; }
.pip {
  width: 24px; height: 24px; border-radius: 50%; margin-left: -6px; display: grid; place-items: center;
  font-size: 11px; font-weight: 650; background: var(--bg); color: var(--muted);
  border: 2px solid var(--surface);
}
.pip:first-child { margin-left: 0; }
.pip.done { background: var(--done); color: var(--primary-ink); }
:root[data-theme="dark"] .pip.done { color: #0f1420; }
.pip-count { margin-left: 8px; font-size: 13px; color: var(--muted); }

/* Empty + state */
.empty { text-align: center; color: var(--muted); padding: 44px 24px; }
.empty strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; font-weight: 600; }
.skeleton { height: 78px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); opacity: .6; }

/* Panels (members, groups) */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.row + .row { border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 600; overflow-wrap: anywhere; }
.row .sub { color: var(--muted); font-size: 13.5px; }
.avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 650; background: var(--primary-soft); color: var(--primary); }
.section-title { margin: 22px 2px 8px; font-size: 15px; font-weight: 600; color: var(--muted); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; gap: 4px; background: var(--bg); border-radius: 12px; border: 1px solid var(--line); }
.segmented button { border: 0; background: transparent; border-radius: 9px; padding: 10px 8px; font-weight: 550; font-size: 14px; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(20, 30, 60, .12); }
.hint { color: var(--muted); font-size: 13.5px; margin: 8px 2px 0; }

/* Buttons */
.btn {
  border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 600; background: var(--primary); color: var(--primary-ink);
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.icon { padding: 8px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; }

/* Floating action */
.fab {
  position: fixed; right: 18px; bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 8px; border: 0; border-radius: 999px; padding: 14px 20px 14px 16px;
  background: var(--primary); color: var(--primary-ink); font-weight: 600; box-shadow: 0 8px 22px rgba(47, 69, 216, .35);
}
.fab svg { width: 20px; height: 20px; }
:root[data-theme="dark"] .fab { box-shadow: 0 8px 22px rgba(0, 0, 0, .45); }

/* Tab bar */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
#tabs button {
  flex: 1; max-width: 160px; border: 0; background: transparent; border-radius: 12px; padding: 6px 4px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 12px; font-weight: 550;
}
#tabs button svg { width: 24px; height: 24px; }
#tabs button[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }

/* Bottom sheet */
.scrim { position: fixed; inset: 0; background: rgba(10, 14, 26, .5); animation: fade .2s ease-out; z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom, 0px));
  max-width: 640px; margin: 0 auto; animation: rise .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 4px; font-size: 22px; font-weight: 650; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.sheet .stack { display: flex; flex-direction: column; gap: 18px; margin-top: 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }

/* Forms */
.field label, .field .label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.field input[type="text"], .field input[type="date"], .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px;
}
.field textarea { min-height: 76px; resize: vertical; }
.field .chips { margin: 0; padding: 0; flex-wrap: wrap; overflow: visible; }
.field .chips.wrap { flex-wrap: wrap; }
.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 550;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 40; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
