:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e4e2dc;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --chip: #ecebe5;
  --warn: #9a5b00;
  --warn-bg: #fff4e0;
  --bad: #b3261e;
  --radius: 14px;
  --tap: 44px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --card: #222326;
    --ink: #ececee;
    --muted: #9b9ba2;
    --line: #34353a;
    --accent: #6cc196;
    --accent-ink: #0f1f17;
    --chip: #2e3034;
    --warn: #f0b45a;
    --warn-bg: #3a2c14;
    --bad: #ff8a80;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
body.sheet-open { overflow: hidden; }
body.busy { cursor: progress; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* top bar */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.top h1 { flex: 1; margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.pill {
  min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); display: inline-flex; align-items: center; gap: 6px; font-size: 15px; cursor: pointer;
}
.pill .count:not(:empty) {
  background: var(--accent); color: var(--accent-ink); border-radius: 999px;
  min-width: 20px; padding: 0 6px; font-size: 13px; font-weight: 600; text-align: center;
}
.icon-btn {
  width: var(--tap); height: var(--tap); border: 0; background: none; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn svg { width: 22px; height: 22px; }
body.busy .icon-btn svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status { margin: 0 16px 6px; font-size: 13px; color: var(--muted); min-height: 18px; }
.status.bad { color: var(--bad); }

main { padding: 0 16px; max-width: 720px; margin: 0 auto; }

/* context chips */
.contexts {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 12px; margin: 0 -16px;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.contexts::-webkit-scrollbar { display: none; }
.ctx-chip {
  flex: none; scroll-snap-align: start; min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; font-size: 15px;
}
.ctx-chip .n { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ctx-chip.none { color: var(--muted); }
.ctx-chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.ctx-chip.on .n { color: inherit; opacity: 0.7; }

.banner {
  display: block; width: 100%; text-align: left; margin: 0 0 12px; padding: 10px 14px;
  border: 0; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn);
  font-size: 15px; cursor: pointer;
}
.note { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.empty { color: var(--muted); text-align: center; padding: 28px 0; margin: 0; }
.empty.small { padding: 6px 0; text-align: left; font-size: 14px; }
.group { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 16px 4px 6px; }

/* action and list rows */
.list { list-style: none; margin: 0 0 12px; padding: 0; background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px 12px 8px; }
.check {
  flex: none; width: var(--tap); height: var(--tap); margin: -6px 0; border: 0; background: none; cursor: pointer;
  display: grid; place-items: center;
}
.check::before {
  content: ""; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--muted);
  transition: background 0.15s, border-color 0.15s;
}
.check:hover::before { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.item-body { flex: 1; min-width: 0; }
.item-text { overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.chip {
  border: 0; background: var(--chip); border-radius: 6px; padding: 2px 8px; font-size: 13px; cursor: pointer; color: var(--ink);
  min-height: 24px;
}
.chip.plain { cursor: default; color: var(--muted); }
.tick { padding: 12px 14px; }

.done-today { margin: 8px 0 20px; color: var(--muted); font-size: 15px; }
.done-today summary { cursor: pointer; padding: 6px 4px; }
.done-today ul { margin: 4px 0 0; padding-left: 22px; }

/* projects */
.summary { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }
.warn { color: var(--warn); }
.area h2 { font-size: 17px; margin: 18px 4px 8px; display: flex; gap: 8px; align-items: baseline; }
.area h2 .n { font-size: 13px; color: var(--muted); font-weight: 400; }
.plist { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.plist > li + li { border-top: 1px solid var(--line); }
.project {
  width: 100%; text-align: left; background: none; border: 0; padding: 12px 14px; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
}
.p-tag { font-size: 13px; color: var(--muted); grid-column: 1; }
.p-outcome { grid-column: 1; overflow-wrap: anywhere; }
.p-meta { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 13px; color: var(--muted); white-space: nowrap; }
.project.stalled .p-meta { color: var(--warn); font-weight: 600; }

/* coming up */
.span-title { font-size: 17px; margin: 18px 4px 8px; }
.day h2, .day h3 { font-size: 15px; margin: 14px 4px 6px; display: flex; gap: 8px; align-items: baseline; }
.day .sub { font-weight: 400; font-size: 13px; color: var(--muted); }
.day.due h2 { color: var(--warn); font-size: 17px; }
.later { margin: 12px 0 24px; }
.later summary { cursor: pointer; color: var(--muted); padding: 6px 4px; }
.later-row { padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.when { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  border: 0; background: none; cursor: pointer; min-height: 52px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--muted);
}
.tab span { font-size: 20px; line-height: 1; }
.tab[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* bottom sheet */
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto;
  box-shadow: 0 -10px 40px rgb(0 0 0 / 0.2);
  animation: up 0.2s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } body.busy .icon-btn svg { animation: none; } }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 8px; font-size: 21px; letter-spacing: -0.01em; }
.sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 4px 8px; }
.sheet .big { font-size: 19px; margin: 0 0 6px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
.warn-box { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 15px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; position: sticky; bottom: 0; }
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 500;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn:disabled { opacity: 0.5; cursor: progress; }
textarea {
  width: 100%; font: inherit; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); resize: vertical;
}
.inbox-list { list-style: none; padding: 0; margin: 0; }
.inbox-list li { padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }

/* project notes */
.md { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px; font-size: 15px; overflow-wrap: anywhere; }
.md h2, .md h3, .md h4, .md h5 { font-size: 15px; margin: 14px 0 6px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.md ul, .md ol { padding-left: 20px; }
.md a { color: var(--accent); }
.md code { background: var(--chip); padding: 1px 4px; border-radius: 4px; font-size: 0.9em; }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 15px; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
}
.toast.bad { background: var(--bad); color: #fff; }

@media (min-width: 900px) {
  body { font-size: 16px; }
}
