:root {
  --bg: #f6f1ea;
  --surface: #fffdf9;
  --surface-2: #efe8de;
  --text: #2a2622;
  --muted: #8a8077;
  --line: #e4dbcf;
  --accent: #d0603d;
  --accent-ink: #fff;
  --accent-soft: #f7ddd2;
  --ok: #3f8f5a;
  --warn: #c2410c;
  --warn-soft: #fde4d4;
  --today: #b7791f;
  --today-soft: #fbefcf;
  --mine: #d0603d;
  --theirs: #efe8de;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .06);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --surface: #25221e;
    --surface-2: #302c27;
    --text: #f1ebe3;
    --muted: #a1978c;
    --line: #3a352f;
    --accent: #e8764f;
    --accent-ink: #1b1916;
    --accent-soft: #4a2c20;
    --ok: #6cc08a;
    --warn: #ff8a5b;
    --warn-soft: #4a2618;
    --today: #f0b955;
    --today-soft: #44361a;
    --mine: #e8764f;
    --theirs: #302c27;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, textarea { font-size: 16px; } /* stops iOS zoom-on-focus */

#app { height: 100dvh; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; }
.boot { margin: auto; color: var(--muted); }

/* --- top bar ------------------------------------------------------------ */
.bar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-top) + 8px) 8px 8px;
  min-height: 56px; flex-shrink: 0;
}
.bar h1 {
  flex: 1; margin: 0 4px; font-size: 22px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar h1 .emoji { margin-right: 6px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font-size: 22px; color: var(--text); flex-shrink: 0;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; }

.scroll { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: 4px 12px 24px; }

/* --- home: list cards --------------------------------------------------- */
.greet { color: var(--muted); margin: 0 4px 12px; font-size: 15px; }
.cards { display: grid; gap: 10px; }
.card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--surface); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); min-height: 72px;
}
.card:active { transform: scale(.985); }
.card .emoji { font-size: 30px; width: 40px; text-align: center; }
.card .body { flex: 1; min-width: 0; }
.card .name { font-weight: 650; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub { color: var(--muted); font-size: 14px; margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.card .count { font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.add-card {
  justify-content: center; color: var(--accent); font-weight: 600; background: transparent;
  border: 2px dashed var(--line); box-shadow: none; min-height: 60px;
}
.sublists { margin: 0 0 16px; }
.lock { font-size: .8em; margin-right: 4px; }
.toggle {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); cursor: pointer;
}
.toggle > span { flex: 1; display: grid; gap: 2px; }
.toggle small { color: var(--muted); font-size: 13px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i {
  width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative;
  flex-shrink: 0; transition: background .15s;
}
.toggle i::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(18px); }
.toggle:has(input:focus-visible) { outline: 2px solid var(--accent); }
.add-card.small { min-height: 48px; font-size: 15px; }
.crumbs {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap; margin: -4px 0 10px;
  font-size: 14px; color: var(--muted);
}
.crumbs button { color: var(--muted); padding: 6px 6px; border-radius: 8px; font-weight: 600; }
.crumbs button:active { background: var(--surface-2); }
.link { color: var(--accent); font-weight: 600; text-decoration: underline; }
.sheet-actions.tight { gap: 2px; }
.menu-btn.current { background: var(--surface-2); }
.menu-btn .here { margin-left: auto; font-size: 13px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 44px; display: block; margin-bottom: 8px; }

/* --- chips --------------------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.chip.overdue { background: var(--warn-soft); color: var(--warn); }
.chip.today { background: var(--today-soft); color: var(--today); }
.chip.plain { background: transparent; padding: 0; font-weight: 500; }

/* --- people & assignment ------------------------------------------------- */
.avatar {
  --hue: 20;
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; line-height: 1;
  background: hsl(var(--hue) 65% 55%); color: #fff;
}
.avatar.none { background: var(--surface-2); color: var(--muted); }
.chip.who { background: transparent; padding: 0; color: var(--text); font-weight: 600; gap: 5px; }
.chip.who .avatar { width: 18px; height: 18px; font-size: 10px; }

.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; margin-bottom: 18px; }
.person {
  display: flex; align-items: center; gap: 6px; background: var(--surface); border-radius: 14px;
  padding: 8px 10px 8px 8px; box-shadow: var(--shadow); min-height: 52px; min-width: 0; font-size: 15px;
}
.person:active { transform: scale(.97); }
.person .avatar { width: 28px; height: 28px; font-size: 13px; }
.person .pinfo { flex: 1; min-width: 0; display: grid; text-align: left; line-height: 1.2; }
.person .pname { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .pcount { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cards { margin-top: 8px; }
.section-title + .cards { margin-top: 8px; }

.filters {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 12px; margin: 0 -12px; padding-left: 12px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.fchip {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  min-height: 38px; padding: 0 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
}
.fchip .avatar { width: 20px; height: 20px; font-size: 11px; margin-left: -6px; }
.fchip .n { color: var(--muted); font-weight: 500; }
.fchip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.fchip.on .n { color: inherit; opacity: .7; }
.assign { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 0; }

.group-title {
  display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 15px; color: var(--muted);
  padding: 16px 4px 8px; width: 100%;
}
.group-title:first-child { padding-top: 4px; }
.group-title svg { width: 14px; height: 14px; }
#person-title { display: flex; align-items: center; gap: 8px; }
#person-title .avatar { width: 28px; height: 28px; font-size: 14px; }

/* --- items --------------------------------------------------------------- */
.items { display: grid; gap: 8px; }
.item {
  display: flex; align-items: flex-start; gap: 4px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  transition: opacity .25s, transform .25s;
}
.item.done .title { text-decoration: line-through; color: var(--muted); }
.item.leaving { opacity: 0; transform: translateX(20px); }
.check {
  width: 52px; height: 52px; flex-shrink: 0; display: grid; place-items: center;
}
.check span {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.check span svg { width: 16px; height: 16px; opacity: 0; color: #fff; }
.item.done .check span, .check.on span { background: var(--ok); border-color: var(--ok); }
.item.done .check span svg, .check.on span svg { opacity: 1; }
.item .body { flex: 1; min-width: 0; text-align: left; padding: 14px 14px 14px 0; min-height: 52px; }
.item .title { font-size: 16px; word-wrap: break-word; }
.item .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 5px; align-items: center; }
.item .meta:empty { display: none; }

.done-toggle {
  display: flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600;
  font-size: 14px; padding: 18px 6px 10px; width: 100%;
}
.done-toggle svg { width: 16px; height: 16px; transition: transform .2s; }
.done-toggle.open svg { transform: rotate(90deg); }

/* --- bottom composer ---------------------------------------------------- */
.composer {
  flex-shrink: 0; display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 12px calc(var(--safe-bottom) + 10px);
  background: var(--bg); border-top: 1px solid var(--line);
}
.composer .field {
  flex: 1; display: flex; align-items: center; background: var(--surface);
  border: 1px solid var(--line); border-radius: 24px; min-height: 48px; padding: 0 6px 0 16px;
}
.composer input[type=text], .composer textarea {
  flex: 1; border: 0; background: transparent; outline: none; min-width: 0; padding: 12px 0;
  resize: none; max-height: 120px; overflow-y: hidden;
}
.composer .date-pill {
  font-size: 13px; font-weight: 600; color: var(--accent); background: var(--accent-soft);
  border-radius: 999px; padding: 4px 10px; margin-right: 4px; white-space: nowrap;
}
.composer .cal { position: relative; width: 40px; height: 40px; display: grid; place-items: center; color: var(--muted); border-radius: 50%; }
.composer .cal.set { color: var(--accent); }
.composer .cal svg { width: 22px; height: 22px; }
.composer .cal input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.send {
  width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; flex-shrink: 0;
}
.send:disabled { opacity: .35; }
.send svg { width: 22px; height: 22px; }

/* --- item detail -------------------------------------------------------- */
.detail { display: grid; gap: 14px; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 16px; }
.title-row { display: flex; align-items: flex-start; gap: 4px; padding: 6px 0; }
.title-row .check { margin-left: -12px; }
.title-input {
  flex: 1; border: 0; background: transparent; outline: none; resize: none;
  font-size: 20px; font-weight: 650; padding: 12px 0; line-height: 1.3; overflow: hidden;
}
.row { display: flex; align-items: center; gap: 12px; min-height: 52px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .label { color: var(--muted); width: 56px; font-size: 14px; flex-shrink: 0; }
.row input[type=date] {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none; min-height: 44px; font-size: 16px;
}
@media (max-width: 420px) { .hide-narrow { display: none; } }
.row .clear { color: var(--muted); font-size: 14px; padding: 10px; }
.notes {
  width: 100%; border: 0; background: transparent; outline: none; resize: none;
  min-height: 80px; padding: 12px 0; line-height: 1.45; overflow: hidden;
}
.byline { color: var(--muted); font-size: 13px; padding: 0 6px; line-height: 1.6; }

.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 8px 6px 0; }
.comments { display: grid; gap: 10px; }
.comment { max-width: 85%; justify-self: start; }
.comment.mine { justify-self: end; text-align: right; }
.comment .bubble {
  display: inline-block; text-align: left; padding: 9px 14px; border-radius: 18px; background: var(--theirs);
  white-space: pre-wrap; word-wrap: break-word;
}
.comment.mine .bubble { background: var(--mine); color: var(--accent-ink); }
.comment .who { font-size: 12px; color: var(--muted); margin: 3px 8px 0; }
.comment .who button { color: var(--muted); text-decoration: underline; font-size: 12px; margin-left: 6px; }
.no-comments { color: var(--muted); font-size: 14px; padding: 0 6px; }

/* --- sheets & toast ----------------------------------------------------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(20, 14, 8, .4); z-index: 10;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 640px; border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(var(--safe-bottom) + 16px); animation: up .2s ease-out;
  max-height: 90dvh; overflow-y: auto;
}
.sheet .grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet .text {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px;
  padding: 12px 14px; outline: none; min-height: 48px;
}
.sheet .text:focus { border-color: var(--accent); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin: 12px 0; }
.emoji-grid button { font-size: 24px; height: 44px; border-radius: 10px; }
.emoji-grid button.sel { background: var(--accent-soft); outline: 2px solid var(--accent); }
.sheet-actions { display: grid; gap: 8px; margin-top: 12px; }
.btn {
  min-height: 50px; border-radius: 14px; font-weight: 650; background: var(--surface-2); width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--warn); }
.btn:disabled { opacity: .5; }
.menu-btn { justify-content: flex-start; padding: 0 16px; background: transparent; font-weight: 500; }
.menu-btn:active { background: var(--surface-2); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 84px); z-index: 20;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; gap: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.2);
  max-width: calc(100vw - 32px); font-size: 15px; animation: up .2s ease-out;
}
.toast[hidden] { display: none; }
.toast button { color: var(--accent); font-weight: 700; padding: 6px 10px; }
@media (prefers-color-scheme: dark) { .toast button { color: #c0451f; } }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.toast { animation-name: toastup; }
@keyframes toastup { from { transform: translate(-50%, 16px); opacity: 0; } }

/* --- login --------------------------------------------------------------- */
.login {
  margin: auto; width: 100%; max-width: 380px; padding: 24px 20px calc(var(--safe-bottom) + 24px);
  display: grid; gap: 14px;
}
.login .logo { font-size: 56px; text-align: center; }
.login h1 { text-align: center; margin: 0; font-size: 28px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 8px; }
.login label { font-size: 14px; font-weight: 600; color: var(--muted); display: grid; gap: 6px; }
.login input {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 13px 14px; outline: none; min-height: 50px;
}
.login input:focus { border-color: var(--accent); }
.login .err { color: var(--warn); text-align: center; min-height: 1.4em; font-size: 15px; }
