:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --text: #1d2321;
  --muted: #6b7471;
  --line: #e3e1da;
  --accent: #2f6f62;
  --accent-soft: #dcebe6;
  --danger: #b4412f;
  --danger-soft: #f6e1dc;
  --ok: #2e7d4f;
  --radius: 14px;
  --tabbar-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514;
    --card: #1c2120;
    --text: #eef1ef;
    --muted: #97a19d;
    --line: #2c3331;
    --accent: #6cc2ad;
    --accent-soft: #1f3631;
    --danger: #ef8a76;
    --danger-soft: #3a2420;
    --ok: #7fd19f;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 8px; background: var(--bg);
}
.topbar h1 { font-size: 28px; margin: 0; letter-spacing: -0.02em; }

.avatar, .avatar-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  color: #fff; font-weight: 700; font-size: 15px; border: 0;
  background: var(--muted);
}
.avatar.sm { width: 26px; height: 26px; font-size: 12px; }
.avatar.lg { width: 48px; height: 48px; font-size: 20px; }

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

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px 6px 6px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--card); font-size: 15px;
}
.chip.plain { padding-left: 12px; }
.chip.active { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

h2.section {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 18px 4px 8px; font-weight: 600;
}
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.card + .card { margin-top: 10px; }
.empty { color: var(--muted); padding: 14px 16px; font-size: 15px; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; min-height: 56px; border-bottom: 1px solid var(--line);
  border-left: 4px solid var(--who, transparent);
}
.row:last-child { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 550; overflow-wrap: anywhere; }
.row .s { font-size: 14px; color: var(--muted); }
.row .s.late { color: var(--danger); font-weight: 600; }
.row.done .t { text-decoration: line-through; color: var(--muted); }
.row.tappable { cursor: pointer; }

.check {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  border: 2px solid var(--muted); background: transparent; display: grid; place-items: center;
}
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.check.on::after { content: "✓"; font-weight: 800; font-size: 16px; }

.time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 48px; color: var(--accent); }

.btn {
  border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.big { width: 100%; padding: 14px; font-size: 17px; border-radius: 12px; }
.btn.taken { background: var(--ok); color: #fff; min-width: 84px; }
.btn:disabled { opacity: 0.5; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--danger-soft); color: var(--danger); }

.fab {
  position: fixed; right: 18px; z-index: 6;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,0,0,.22);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600;
}
.tabbar .ti { font-size: 21px; line-height: 1; }
.tabbar button.active { color: var(--accent); }

.banner {
  margin: 0 16px 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--accent-soft); font-size: 14px;
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
}
.banner.warn { background: var(--danger-soft); }
.share-glyph { display: inline-block; font-weight: 700; }

/* Bottom sheet */
.sheet {
  width: 100%; max-width: 640px; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 18px 18px 0 0; background: var(--bg); color: var(--text);
  max-height: 92vh; max-height: 92dvh;
}
.sheet::backdrop { background: rgba(0,0,0,.4); }
.sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
#sheet-body { padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 12px; }
.sheet-head h3 { margin: 0; font-size: 20px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--line); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.seg button { border: 0; background: none; padding: 7px; border-radius: 8px; font-weight: 600; font-size: 15px; }
.seg button.active { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 4px 4px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card);
  border-radius: 10px; padding: 11px 12px; font-size: 16px; /* 16px stops iOS zooming in */
  min-height: 46px; -webkit-appearance: none; appearance: none;
}
.field select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.field textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.toggles button {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 8px 10px; min-width: 42px; font-weight: 600; font-size: 14px;
}
.toggles button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.times { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.times input { width: auto; min-width: 110px; }
.actions { display: flex; gap: 10px; margin-top: 18px; }
.actions .btn { flex: 1; padding: 13px; font-size: 16px; }

.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; }
.colors button.on { border-color: var(--text); }

.member-card { display: flex; gap: 14px; padding: 14px; align-items: flex-start; cursor: pointer; border-left: 5px solid var(--who); }
.member-card .stats { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.member-card .next { font-size: 14px; color: var(--muted); margin-top: 4px; }

.center-screen { min-height: 70vh; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.center-screen h2 { font-size: 26px; margin: 0; }
.center-screen p { color: var(--muted); margin: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 90px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 15px; font-weight: 600; box-shadow: 0 6px 18px rgba(0,0,0,.2);
  display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px);
}
.toast button { border: 0; background: none; color: var(--accent-soft); font-weight: 700; }

/* Food */
.dinner-card {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer;
  border-left: 6px solid var(--who);
  background: color-mix(in srgb, var(--who) 12%, var(--card));
}
.dinner-card .main { flex: 1; min-width: 0; }
.dinner-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--who); }
.dinner-title { font-size: 22px; font-weight: 700; margin: 2px 0; overflow-wrap: anywhere; }
.dinner-card .cook { color: var(--who); }
.muted { color: var(--muted); font-weight: 500; }
.row .day { min-width: 74px; font-weight: 600; font-size: 15px; }
.row.weekend .day { color: var(--accent); }
.shop-add { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.shop-add input {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg);
  border-radius: 10px; padding: 9px 12px; font-size: 16px;
}
.dish-chips { padding: 0 0 2px; flex-wrap: wrap; overflow: visible; }
.checkline { display: flex; align-items: center; gap: 10px; margin: 0 4px 6px; font-size: 15px; }
.checkline input { width: 22px; height: 22px; accent-color: var(--accent); }
.cook-pick button.on { background: var(--c); border-color: var(--c); color: #fff; }
.cook-pick button { border-color: color-mix(in srgb, var(--c) 45%, var(--line)); }

body.setup .tabbar, body.setup .fab { display: none; }
