:root {
  --bg: #f7f3ee;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #ebe5dc;
  --soft: #f1ebe3;
  --accent: #2a9d8f;
  --accent-ink: #ffffff;
  --accent-soft: #dff1ee;
  --warn: #e9a23b;
  --warn-soft: #fdf0db;
  --danger: #d1495b;
  --danger-soft: #fbe3e6;
  --ok: #3f9d5d;
  --ok-soft: #e1f3e6;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(0,0,0,.05);
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d; --card: #1f2229; --ink: #eceff4; --muted: #9aa3b2; --line: #2c3039; --soft: #272b33;
    --accent: #3fb8a8; --accent-soft: #1d3a37; --warn-soft: #3a2f1c; --danger-soft: #3c2228; --ok-soft: #1f3526;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'Rubik', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif; font-size: 16px; }
body { min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100dvh; font-size: 48px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

/* layout */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); padding: calc(env(safe-area-inset-top, 0px) + 12px) 18px 10px; display: flex; align-items: center; justify-content: space-between; }
.top h1 { font-size: 21px; margin: 0; font-weight: 700; }
.top .sub { color: var(--muted); font-size: 13px; }
main { padding: 4px 14px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 680px; margin: 0 auto; }
nav.bottom { position: fixed; bottom: 0; inset-inline: 0; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--card); border-top: 1px solid var(--line); display: flex; z-index: 6; }
nav.bottom button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11.5px; color: var(--muted); position: relative; cursor: pointer; }
nav.bottom button .ic { font-size: 22px; filter: grayscale(1); opacity: .7; }
nav.bottom button.on { color: var(--accent); font-weight: 600; }
nav.bottom button.on .ic { filter: none; opacity: 1; }
.badge { position: absolute; top: 7px; inset-inline-start: calc(50% + 6px); background: var(--danger); color: #fff; border-radius: 10px; min-width: 18px; height: 18px; font-size: 11px; display: grid; place-items: center; padding: 0 5px; font-weight: 600; }

/* cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.section-title { font-size: 15px; font-weight: 600; margin: 18px 4px 8px; display: flex; align-items: center; justify-content: space-between; }
.section-title .link { font-weight: 500; font-size: 14px; color: var(--accent); background: none; border: 0; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; font-size: 14px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 6px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }

/* buttons */
.btn { border: 0; border-radius: 12px; padding: 10px 14px; background: var(--soft); cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; justify-content: center; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: none; color: var(--muted); padding: 6px 8px; }
.btn.sm { padding: 6px 10px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: none; font-size: 18px; padding: 6px; cursor: pointer; border-radius: 10px; color: var(--muted); }
.fab { position: fixed; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); inset-inline-end: 18px; width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: #fff; font-size: 28px; box-shadow: 0 6px 18px rgba(42,157,143,.35); cursor: pointer; z-index: 4; }

/* inputs */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; outline: none; }
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 70px; }
.addbar { display: flex; gap: 8px; }
.addbar .input { flex: 1; }

/* segmented */
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; margin: 4px 0 12px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 10px; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); padding: 6px 11px; border-radius: 20px; font-size: 13.5px; cursor: pointer; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 500; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.tag.warn { background: var(--warn-soft); color: #b37515; }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }

/* avatar */
.av { width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 600; font-size: 14px; flex-shrink: 0; }
.av.sm { width: 22px; height: 22px; font-size: 11px; }
.av.lg { width: 44px; height: 44px; font-size: 18px; }
.av.xl { width: 96px; height: 96px; font-size: 38px; }
img.av { object-fit: cover; display: inline-block; background: var(--soft); }
.who { display: inline-flex; align-items: center; gap: 6px; }

/* chores */
.chore { display: flex; gap: 12px; align-items: center; }
.chore .emoji { width: 46px; height: 46px; border-radius: 14px; background: var(--soft); display: grid; place-items: center; font-size: 24px; flex-shrink: 0; }
.chore.done .emoji { background: var(--ok-soft); }
.chore .title { font-weight: 600; }
.card.mine { outline: 2px solid var(--accent); outline-offset: -2px; }
.card.overdue { outline: 2px solid var(--danger); outline-offset: -2px; }
.upcoming { display: flex; gap: 6px; overflow-x: auto; padding-top: 10px; }
.upcoming .u { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); min-width: 46px; }
.bar { height: 8px; border-radius: 6px; background: var(--soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 6px; }

/* shopping */
.item { display: flex; gap: 12px; align-items: flex-start; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.check { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); background: none; flex-shrink: 0; cursor: pointer; display: grid; place-items: center; color: #fff; font-size: 15px; margin-top: 1px; }
.check.on { background: var(--ok); border-color: var(--ok); }
.item.bought .name { text-decoration: line-through; color: var(--muted); }
.item .name { font-weight: 500; }
.store-banner { background: linear-gradient(135deg, var(--accent), #3c8dbc); color: #fff; border-radius: var(--radius); padding: 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 12px; }
.store-banner .btn { background: rgba(255,255,255,.22); color: #fff; }

/* inventory */
.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.inv { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.inv .top-row { display: flex; align-items: center; gap: 8px; }
.inv .em { font-size: 22px; }
.inv .nm { font-weight: 500; flex: 1; font-size: 14.5px; }
.tri { display: flex; gap: 3px; }
.tri button { flex: 1; border: 0; border-radius: 8px; padding: 6px 2px; font-size: 12px; background: var(--soft); color: var(--muted); cursor: pointer; }
.tri button.on.ok { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.tri button.on.low { background: var(--warn-soft); color: #b37515; font-weight: 600; }
.tri button.on.out { background: var(--danger-soft); color: var(--danger); font-weight: 600; }

/* notices */
.notice { padding: 12px 2px; border-bottom: 1px solid var(--line); }
.notice:last-child { border-bottom: 0; }
.notice .txt { white-space: pre-wrap; margin: 6px 0 0; line-height: 1.45; }

/* issues */
.issue-img { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; flex-shrink: 0; cursor: pointer; }

/* polls */
.opt { position: relative; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 8px; cursor: pointer; overflow: hidden; background: var(--card); width: 100%; text-align: start; }
.opt .fill { position: absolute; inset: 0; inset-inline-end: auto; background: var(--accent-soft); z-index: 0; transition: width .3s; }
.opt > span { position: relative; z-index: 1; }
.opt.mine { border-color: var(--accent); }

/* info */
.info-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.info-row:last-child { border-bottom: 0; }
.info-row .lbl { color: var(--muted); font-size: 13px; }
.info-row .val { font-weight: 500; word-break: break-word; direction: auto; unicode-bidi: plaintext; }

/* sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 10px 18px calc(18px + var(--safe-b)); max-height: 88dvh; overflow-y: auto; animation: up .2s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 19px; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 20px; cursor: pointer; }
.emoji-pick button.on { border-color: var(--accent); background: var(--accent-soft); }
.color-pick { display: flex; gap: 8px; flex-wrap: wrap; }
.color-pick button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.color-pick button.on { border-color: var(--ink); }
.photo-prev { width: 100%; max-height: 200px; object-fit: cover; border-radius: 12px; margin-top: 8px; }
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 30; display: grid; place-items: center; }
.viewer img { max-width: 96vw; max-height: 90dvh; border-radius: 8px; }

/* onboarding */
.onb { max-width: 440px; margin: 0 auto; padding: calc(env(safe-area-inset-top,0px) + 40px) 18px 40px; }
.onb .logo { font-size: 56px; text-align: center; }
.onb h1 { text-align: center; margin: 6px 0 4px; font-size: 30px; }
.onb p.lead { text-align: center; color: var(--muted); margin: 0 0 24px; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 26px; letter-spacing: 4px; font-weight: 700; direction: ltr; text-align: center; }

#toast { position: fixed; bottom: calc(var(--nav-h) + var(--safe-b) + 84px); inset-inline: 0; margin: 0 auto; width: max-content; max-width: 90vw; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 40; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: none; }
.hl { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px; cursor: pointer; }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { font-size: 13px; color: var(--muted); }
