:root {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --surface-2: #efebe3;
  --ink: #1c2421;
  --muted: #6a736e;
  --line: #e2ddd3;
  --brand: #2f5d50;
  --brand-ink: #ffffff;
  --brand-soft: #dde9e3;
  --warn: #b85a2e;
  --warn-soft: #f7e3d8;
  --ok: #2f7a4f;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .06);
  --radius: 14px;
  --tabbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121816;
    --surface: #1b2320;
    --surface-2: #232d29;
    --ink: #e9eeeb;
    --muted: #93a09a;
    --line: #2c3833;
    --brand: #7fb8a5;
    --brand-ink: #0f1a16;
    --brand-soft: #22352e;
    --warn: #e59268;
    --warn-soft: #3a2519;
    --ok: #79c497;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- boot ---------- */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.boot-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--brand); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; transform: scale(.92); } }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); }
.login h1 { margin: 12px 0 2px; font-size: 24px; }
.login p { margin: 0 0 20px; color: var(--muted); }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.who button { padding: 14px 10px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); font-weight: 600; }
.who button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.pin { width: 100%; padding: 14px; font-size: 22px; letter-spacing: .4em; text-align: center; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.login .err { color: var(--warn); min-height: 1.4em; margin: 8px 0; font-size: 14px; }
.logo { width: 52px; height: 52px; }

/* ---------- shell ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
}
.top-row { display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 26px; margin: 0; flex: 1; letter-spacing: -.01em; }
.me { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); opacity: .8; }
.sync-dot.off { background: var(--warn); }
.sub { color: var(--muted); font-size: 14px; margin-top: 2px; }

main { padding: 4px 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 90px); max-width: 720px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { height: var(--tabbar); border: 0; background: none; display: grid; place-items: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; padding: 8px 0 6px; white-space: nowrap; }
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button[aria-current="page"] { color: var(--brand); }
.tabbar .badge.alert { background: var(--warn); }
.tabbar .badge { position: absolute; top: 6px; left: calc(50% + 6px); margin: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); font-size: 11px; line-height: 18px; }
.tabbar button { position: relative; }

/* ---------- chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 16px 6px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .n { font-weight: 500; opacity: .6; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* ---------- add bar ---------- */
.addbar {
  position: fixed; left: 0; right: 0; z-index: 25;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding: 10px 12px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.addbar form { display: flex; gap: 8px; max-width: 720px; margin: 0 auto; }
.addbar input { flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.addbar select { max-width: 38%; padding: 0 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; }
.addbar button { width: 48px; border-radius: 12px; border: 0; background: var(--brand); color: var(--brand-ink); font-size: 26px; line-height: 1; }

/* ---------- lists ---------- */
.group { margin-top: 18px; }
.group-h { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; margin: 0 2px 8px; }
.group-h .n { color: var(--muted); font-weight: 500; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); min-height: 56px; }
.row:first-child { border-top: 0; }
.tick { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); background: none; display: grid; place-items: center; padding: 0; }
.tick svg { width: 16px; height: 16px; opacity: 0; }
.done .tick { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.done .tick svg { opacity: 1; }
.row-body { flex: 1; min-width: 0; background: none; border: 0; text-align: left; padding: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.done .row-title { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.row-meta { font-size: 13px; color: var(--muted); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.qty { flex: none; font-size: 13px; font-weight: 700; background: var(--surface-2); padding: 3px 8px; border-radius: 8px; }
.tag { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.tag.urgent { background: var(--warn-soft); color: var(--warn); }
.tag.who { background: var(--brand-soft); color: var(--brand); }
.overdue { color: var(--warn); font-weight: 600; }

.usuals { margin-top: 14px; }
.usuals .label { font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 2px 6px; }
.usuals .chips { padding-top: 2px; }
.usuals .chip { font-weight: 500; }
.usuals .chip::before { content: "+"; font-weight: 700; color: var(--brand); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

.fold { margin-top: 22px; }
.fold-h { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 8px; }
.fold-h button.link { border: 0; background: none; color: var(--muted); font-weight: 600; font-size: 14px; padding: 6px 0; }
.fold-h button.clear { border: 0; background: none; color: var(--warn); font-weight: 600; font-size: 14px; padding: 6px 0; }

/* ---------- meals ---------- */
.weeknav { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; }
.weeknav .label { flex: 1; text-align: center; font-weight: 700; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; padding: 0; }
.iconbtn svg { width: 20px; height: 20px; }
.day { display: flex; gap: 14px; align-items: stretch; padding: 12px 14px; border-top: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; }
.day:first-child { border-top: 0; }
.day-date { flex: none; width: 44px; text-align: center; }
.day-date .dow { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.day-date .dn { font-size: 22px; font-weight: 700; line-height: 1.1; }
.day.today .day-date .dn { color: var(--brand); }
.day.today { background: var(--brand-soft); }
.day-main { flex: 1; min-width: 0; align-self: center; }
.day-main .plan { font-weight: 600; }
.day-main .plan.none { color: var(--muted); font-weight: 400; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }

/* ---------- buttons ---------- */
.btn { padding: 13px 16px; border-radius: 12px; border: 0; background: var(--brand); color: var(--brand-ink); font-weight: 700; width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: none; color: var(--warn); }
.btn:disabled { opacity: .5; }

/* ---------- sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 15, 12, .45); z-index: 50; animation: fade .15s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 18px);
  max-width: 720px; margin: 0 auto;
  animation: up .2s cubic-bezier(.2,.8,.2,1);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 20px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.field textarea { min-height: 96px; resize: vertical; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; padding: 10px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 14px; font-weight: 600; }
.switch input { width: 22px; height: 22px; accent-color: var(--warn); }
.hint { font-size: 13px; color: var(--muted); margin: -6px 0 14px; }
.sheet .foot { display: grid; gap: 8px; margin-top: 6px; }
.sheet .foot-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px); z-index: 60;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 84px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--brand-soft); font-weight: 700; padding: 0; }
@media (prefers-color-scheme: dark) { #toast button { color: var(--brand-ink); } }

/* ---------- messages & lost/found ---------- */
.bell { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--muted); display: grid; place-items: center; padding: 0; }
.bell svg { width: 20px; height: 20px; }
.bell[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.msgs { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 3px; align-self: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 4px; }
.msg .bubble { background: var(--surface); box-shadow: var(--shadow); border-radius: 16px 16px 16px 4px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; border: 0; text-align: left; font: inherit; color: inherit; }
.msg.mine .bubble { background: var(--brand); color: var(--brand-ink); border-radius: 16px 16px 4px 16px; }
.msg .when { font-size: 11px; color: var(--muted); padding: 0 4px; }
.daysep { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; margin: 8px 0 2px; }
.tag.lost { background: var(--warn-soft); color: var(--warn); }
.tag.found { background: var(--brand-soft); color: var(--brand); }
