:root {
  --paper: #f6f7f4; --card: #ffffff; --ink: #203432; --muted: #6f7c76; --line: #e2e7e0;
  --teal: #23695f; --teal-soft: #d7e8df; --teal-ink: #164a43; --on-teal: #ffffff;
  --late: #be4747; --late-soft: #ffe4df;
  --wait: #a76913; --wait-soft: #ffeed0;
  --decide: #8048c7; --decide-soft: #eee2fc;
  --review: #2678bb; --review-soft: #e0eefc;
  --grey-soft: #eceeea;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121a19; --card: #1b2523; --ink: #e6eeeb; --muted: #95a39d; --line: #2c3936;
    --teal: #5ad2bf; --teal-soft: #1f3b37; --teal-ink: #c7fffa; --on-teal: #0d2a26;
    --late: #ff9b8e; --late-soft: #4d3032; --wait: #f4c471; --wait-soft: #473927;
    --decide: #ba8bf0; --decide-soft: #39294b; --review: #83bffe; --review-soft: #253b51; --grey-soft: #26302e;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body { font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  padding-bottom: calc(72px + var(--safe-bottom)); -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--paper) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  padding: calc(8px + var(--safe-top)) 16px 8px; border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.top h1 { font-size: 28px; line-height: 1.1; margin: 0; flex: 1; letter-spacing: -0.02em; }
.sync { display: inline-flex; align-items: center; gap: 6px; border: 0; background: var(--card); border-radius: 999px;
  padding: 6px 11px; font-size: 13px; color: var(--muted); box-shadow: 0 0 0 1px var(--line) inset; max-width: 52vw; }
.sync span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); flex: none; }
.sync.busy .dot { animation: pulse 1s infinite ease-in-out; }
.sync.warn .dot { background: var(--wait); }
.sync.bad .dot { background: var(--late); }
@keyframes pulse { 50% { opacity: .25; } }
.icon-button { width: 44px; height: 44px; border: 0; background: none; display: grid; place-items: center; margin-right: -8px; }
.icon-button svg { width: 24px; height: 24px; fill: var(--muted); }
.segmented { display: flex; gap: 4px; margin-top: 8px; background: var(--grey-soft); padding: 3px; border-radius: 11px; }
.segmented button { flex: 1; border: 0; background: none; padding: 7px 4px; border-radius: 8px; font-size: 15px; font-weight: 500; color: var(--muted); }
.segmented button.selected { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.search-row { margin-top: 8px; }
.search-row input { width: 100%; border: 0; border-radius: 11px; padding: 9px 12px; background: var(--grey-soft); font-size: 16px; }

/* banner, toast */
.banner { margin: 10px 16px 0; padding: 10px 12px; border-radius: 12px; background: var(--late-soft); color: var(--late); font-size: 14px; }
.banner .item { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; }
.banner .item span { flex: 1; }
.banner button { border: 0; background: none; color: inherit; font-weight: 600; padding: 0 2px; }
.toast { position: fixed; left: 12px; right: 12px; bottom: calc(80px + var(--safe-bottom)); z-index: 20; display: flex; align-items: center;
  gap: 12px; background: #203432; color: #fff; border-radius: 14px; padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast button { border: 0; background: none; color: #7fe0cf; font-weight: 600; padding: 4px 2px; }

/* lists */
main { padding: 4px 0 24px; outline: none; }
.section { margin: 16px 0 0; }
.section-head { display: flex; align-items: baseline; gap: 8px; padding: 0 20px 6px; font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border: 0; background: none; width: 100%; text-align: left; }
.section-head .count { font-weight: 500; }
.section-head.late { color: var(--late); }
.section-head.today { color: var(--teal); }
.list { list-style: none; margin: 0 12px; padding: 0; background: var(--card); border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--line) inset; overflow: hidden; }
.empty { margin: 40px 24px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }

.task { border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.row { display: flex; align-items: flex-start; gap: 4px; padding: 0 12px 0 4px; min-height: 52px; }
.check { flex: none; width: 44px; height: 48px; border: 0; background: none; display: grid; place-items: center; }
.check i { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #b9c4bf; display: grid; place-items: center; }
.task.done .check i { background: var(--teal); border-color: var(--teal); }
.task.done .check i::after { content: ""; width: 10px; height: 6px; border: solid var(--on-teal); border-width: 0 0 2.5px 2.5px; transform: translateY(-1px) rotate(-45deg); }
.task.step .check i { border-radius: 6px; width: 20px; height: 20px; }
.row-body { flex: 1; min-width: 0; padding: 13px 0 11px; border: 0; background: none; text-align: left; }
.row-title { font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.task.done .row-title { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(0,0,0,.25); }
.meta { display: flex; flex-wrap: wrap; gap: 5px 8px; margin-top: 5px; font-size: 13px; color: var(--muted); align-items: center; }
.chip { display: inline-flex; align-items: center; border-radius: 6px; padding: 1px 6px; font-size: 12.5px; font-weight: 600; background: var(--grey-soft); color: var(--muted); }
.chip.late { background: var(--late-soft); color: var(--late); }
.chip.today { background: var(--teal); color: var(--on-teal); }
.chip.soon { background: var(--teal-soft); color: var(--teal-ink); }
.chip.wait { background: var(--wait-soft); color: var(--wait); }
.chip.decide { background: var(--decide-soft); color: var(--decide); }
.chip.review { background: var(--review-soft); color: var(--review); }
.chip.high { background: var(--late-soft); color: var(--late); }
.pending-mark { width: 8px; height: 8px; border-radius: 50%; background: var(--wait); display: inline-block; }
.task.error .row-title { color: var(--late); }
.row.open .row-body { padding-top: 8px; }
.row.open .title-input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 6px 9px; background: var(--paper);
  resize: none; overflow: hidden; font-size: 16px; font-weight: 600; line-height: 1.3; min-height: 36px; }
.collapse { flex: none; width: 40px; height: 48px; border: 0; background: none; display: grid; place-items: center; margin-right: -8px; }
.collapse svg { width: 24px; height: 24px; fill: var(--muted); }

/* inline editor */
.editor { padding: 2px 14px 14px 48px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.editor > * { min-width: 0; }
.editor label.caption, .editor .caption { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: block; margin-bottom: 5px; }
.editor textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--paper);
  resize: none; overflow: hidden; font-size: 16px; line-height: 1.35; min-height: 40px; }
.editor textarea.title-input { font-weight: 600; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; min-width: 0; }
.chips::-webkit-scrollbar { display: none; }
.pick { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 11px; font-size: 14px; white-space: nowrap; }
.pick.selected { background: var(--teal); border-color: var(--teal); color: var(--on-teal); }
.date-line { display: flex; align-items: center; gap: 8px; }
.date-line .name { width: 70px; flex: none; font-size: 14px; color: var(--muted); }
.date-line .value { font-size: 14px; font-weight: 600; min-width: 56px; }
.date-line .chips { flex: 1; min-width: 0; }
.new-task { grid-template-columns: minmax(0, 1fr); }
.date-input { position: relative; flex: none; }
.date-input input { position: absolute; inset: 0; opacity: 0; width: 100%; }
.steps { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.steps .task .row { min-height: 44px; }
.steps .row-body { padding: 11px 0 9px; }
.add-step { display: flex; gap: 6px; padding: 6px; border-top: 1px solid var(--line); }
.add-step input, .new-task input[type=text] { flex: 1; border: 0; background: none; padding: 6px 8px; font-size: 16px; min-width: 0; }
.add-step button, .primary, .secondary { border: 0; border-radius: 10px; padding: 8px 14px; font-weight: 600; }
.add-step button, .primary { background: var(--teal); color: var(--on-teal); }
.secondary { background: var(--grey-soft); color: var(--ink); }
.info { font-size: 13px; color: var(--muted); }
.history { font-size: 14px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
details summary { font-size: 13px; color: var(--muted); padding: 4px 0; }

/* new task card */
.new-task { margin: 12px 12px 0; background: var(--card); border-radius: var(--radius); box-shadow: 0 0 0 2px var(--teal) inset; padding: 12px; display: grid; gap: 10px; }
.new-task input[type=text] { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: var(--paper); }
.new-task .actions { display: flex; justify-content: flex-end; gap: 8px; }

/* projects */
.project { margin: 12px 12px 0; background: var(--card); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--line) inset; overflow: hidden; }
.project-head { width: 100%; border: 0; background: none; text-align: left; padding: 13px 14px; display: grid; gap: 4px; }
.project-head .name { font-size: 17px; font-weight: 600; }
.project-head .sub { font-size: 13px; color: var(--muted); }
.project-head .next { font-size: 14px; }
.project .list { margin: 0; border-radius: 0; box-shadow: none; border-top: 1px solid var(--line); }
.project .section-head { padding: 10px 14px 4px; }
.project .add-in-project { border: 0; background: none; color: var(--teal); font-weight: 600; padding: 12px 14px; width: 100%; text-align: left; border-top: 1px solid var(--line); }
.more { display: block; margin: 8px auto 0; border: 0; background: none; color: var(--teal); font-weight: 600; padding: 8px 12px; }

/* settings / setup */
.panel { margin: 16px 12px; background: var(--card); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--line) inset; padding: 16px; display: grid; gap: 12px; }
.panel h2 { margin: 0; font-size: 20px; }
.panel p { margin: 0; color: var(--muted); }
.panel .primary, .panel .secondary { padding: 12px 16px; font-size: 16px; }

/* floating add, tabs */
.fab { position: fixed; right: 18px; bottom: calc(84px + var(--safe-bottom)); z-index: 6; width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--teal); box-shadow: 0 6px 18px rgba(0,0,0,.22); display: grid; place-items: center; }
.fab svg { width: 28px; height: 28px; fill: var(--on-teal); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; display: flex; background: color-mix(in srgb, var(--card) 94%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.tabs button { flex: 1; border: 0; background: none; padding: 7px 0 6px; display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--muted); }
.tabs svg { width: 26px; height: 26px; fill: currentColor; }
.tabs button.selected { color: var(--teal); }
