:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --on-accent: #ffffff;
  --danger: #dc2626;
  --high: #b45309;
  --high-soft: #fef3c7;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --line: #2a2f37;
    --accent: #4f8cff;
    --accent-soft: #1c2638;
    --on-accent: #ffffff;
    --danger: #f87171;
    --high: #fbbf24;
    --high-soft: #3a2f12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.wrap { max-width: 40rem; margin: 0 auto; padding: 0 16px 96px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top .wrap { display: flex; align-items: center; gap: 8px; padding-bottom: 0; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  border: 0; background: none; padding: 14px 12px 12px;
  color: var(--muted); font-weight: 600;
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.icon-btn {
  border: 0; background: none; color: var(--muted);
  width: 44px; height: 44px; border-radius: 50%; font-size: 1.3rem;
  flex: none; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--accent-soft); }
@media (max-width: 400px) { /* three tabs and three icons on a 360px phone */
  .top .wrap { gap: 2px; }
  .tab { padding-left: 8px; padding-right: 8px; }
}

.banner {
  margin: 12px 0 0; padding: 8px 12px; border-radius: var(--radius);
  background: var(--high-soft); color: var(--text); font-size: .9rem;
}

/* context chips */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 4px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 7px 14px; min-height: 38px; white-space: nowrap;
}
.chip .n { color: var(--muted); margin-left: 4px; font-size: .9em; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip.active .n { color: inherit; opacity: .8; }

/* add form */
.add { display: flex; gap: 8px; margin: 12px 0 8px; }
.add input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card);
}
.add input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.btn {
  border: 0; border-radius: var(--radius); padding: 11px 18px; min-height: 44px;
  background: var(--accent); color: var(--on-accent); font-weight: 600;
}
.btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: none; color: var(--danger); border: 1px solid var(--line); }
.hint { color: var(--muted); font-size: .85rem; margin: 0 2px 8px; }

/* task list */
.group { margin-top: 18px; }
.group h2 {
  font-size: .8rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin: 0 4px 6px; font-weight: 700;
}
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.task { display: flex; align-items: flex-start; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.task.is-high { box-shadow: inset 3px 0 0 var(--high); }
.check {
  flex: none; width: 52px; min-height: 52px; border: 0; background: none; position: relative;
}
.check::before {
  content: ""; position: absolute; left: 16px; top: 15px;
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted);
}
.check:hover::before { border-color: var(--accent); }
.check.done::before { background: var(--accent); border-color: var(--accent); }
.task-body {
  flex: 1; min-width: 0; text-align: left; border: 0; background: none;
  padding: 13px 14px 13px 0; display: flex; flex-direction: column; gap: 2px;
}
.task-text { overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .82rem; color: var(--muted); }
.meta .overdue { color: var(--danger); font-weight: 600; }
.meta .high { color: var(--high); font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

/* editor */
.editor { padding: 14px; border-top: 1px solid var(--line); background: var(--accent-soft); }
.editor:first-child { border-top: 0; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
.field input, .field select, .field textarea {
  font-size: 1rem; color: var(--text); padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); min-width: 0; width: 100%;
}
.field textarea { min-height: 45vh; resize: vertical; line-height: 1.5; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.actions .spacer { flex: 1; }

/* done */
.done-row .task-body { padding-left: 16px; }
.done-row .task-text { color: var(--muted); text-decoration: line-through; }
.small-btn {
  flex: none; align-self: center; margin-right: 10px; border: 1px solid var(--line);
  background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: .85rem;
}

/* notes */
.note-row { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 13px 14px; border-top: 1px solid var(--line); }
.note-row:first-child { border-top: 0; }
.note-row .meta { margin-top: 2px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin: 14px 0; }
.toolbar h1 { font-size: 1.25rem; margin: 0; flex: 1; overflow-wrap: anywhere; }
.note-body { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px; overflow-wrap: anywhere; }
.note-body pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; }
.note-body code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
.note-body a { color: var(--accent); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); border-radius: var(--radius);
  padding: 10px 10px 10px 16px; display: flex; gap: 12px; align-items: center;
  max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 10;
}
.toast button { border: 0; background: none; color: var(--accent); font-weight: 700; padding: 6px 8px; filter: brightness(1.3); }

/* sign-in page */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin .card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px 28px; width: 100%; max-width: 22rem; text-align: center;
}
.signin h1 { margin: 12px 0 6px; font-size: 1.5rem; }
.signin p { color: var(--muted); margin: 0 0 22px; }
.signin .btn { display: block; text-decoration: none; }
