:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --line: #e4e2dc;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-soft: #e3efe9;
  --danger: #b3261e;
  --warn-bg: #fff4d6;
  --warn-text: #5c4400;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2227;
    --text: #eceef1;
    --muted: #9aa0a8;
    --line: #2f333a;
    --accent: #6cc3a6;
    --accent-text: #0f1a16;
    --accent-soft: #22352f;
    --danger: #ff8a80;
    --warn-bg: #3a3118;
    --warn-text: #f5dc9a;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

main, .topbar, .banner { max-width: 640px; margin-left: auto; margin-right: auto; }
main { padding: 0 16px; }

.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 16px) 16px 12px;
}
.topbar h1 { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: -0.01em; }
.topbar p { margin: 2px 0 0; font-size: 15px; }

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 15px; }
.btn-block { width: 100%; border-radius: 12px; }
.btn-link { border: 0; background: none; color: var(--accent); padding: 0 4px; }
.icon-btn {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Banner */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 16px 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 15px;
}
@media (min-width: 672px) { .banner { margin-left: auto; margin-right: auto; } }

/* Cards and lists */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }

.day { margin-bottom: 20px; }
.day h2 {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 8px 4px;
}
.day.today h2 { color: var(--accent); }

.event {
  position: relative;
  display: flex;
  gap: 14px;
  width: 100%;
  padding: 14px 16px 14px 20px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.event::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 5px;
  border-radius: 0 3px 3px 0;
  background: var(--m);
}
.event-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.repeat-mark { color: var(--muted); font-weight: 400; }
.who-line { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; color: var(--muted); margin-top: 2px; }
.who { display: inline-flex; align-items: center; gap: 6px; }
.event-time { flex: none; width: 76px; color: var(--muted); font-size: 15px; padding-top: 1px; }
.event-title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.event-where { display: block; color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }
.empty { padding: 16px; color: var(--muted); }

/* Meals */
.week-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.week-nav strong { font-size: 17px; }
.meal-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  min-height: 60px;
}
.meal-day { flex: none; width: 52px; }
.meal-day b { display: block; font-size: 15px; }
.meal-day span { font-size: 14px; color: var(--muted); }
.meal-name { flex: 1; overflow-wrap: anywhere; }
.meal-name.placeholder { color: var(--muted); }
.meal-row.today { background: var(--accent-soft); }
.meal-row.today .meal-day b { color: var(--accent); }
.chevron { color: var(--muted); flex: none; }

/* Groceries */
.add-form { display: flex; gap: 8px; margin-bottom: 16px; }
.add-form input { flex: 1; }
.grocery { display: flex; align-items: center; gap: 4px; padding-right: 4px; }
.grocery label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 8px 12px 16px;
  min-height: 56px;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.grocery input[type="checkbox"] {
  appearance: none;
  flex: none;
  width: 26px;
  height: 26px;
  min-height: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  border: 2px solid var(--muted);
  border-radius: 50%;
  display: grid;
  place-content: center;
}
.grocery input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.grocery input[type="checkbox"]:checked::after {
  content: "";
  width: 10px;
  height: 6px;
  border: solid var(--accent-text);
  border-width: 0 0 2.5px 2.5px;
  transform: translateY(-1px) rotate(-45deg);
}
.grocery.done label { color: var(--muted); text-decoration: line-through; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 4px 8px;
}
.section-head h2 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

/* Forms */
input, textarea, select {
  font: inherit;
  font-size: 17px; /* 16px+ stops iOS zooming on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
textarea { resize: vertical; }
label { display: block; font-size: 15px; font-weight: 600; }
label > input, label > textarea { margin-top: 6px; font-weight: 400; }
label.check { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 400; }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.form-error { color: var(--danger); margin: 0; font-size: 15px; }

select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
label > select { margin-top: 6px; font-weight: 400; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; font-size: 15px; font-weight: 600; }
.stack { display: grid; gap: 16px; }
.stack > p, .stack > h2 { margin: 0; }
h3 { margin: 0; font-size: 17px; }

/* Family colors: each person gets one, used for dots, bars and chips */
.m-none { --m: transparent; }
.m-green { --m: #2e8b57; }
.m-blue { --m: #2f6fd6; }
.m-purple { --m: #7b4fc9; }
.m-pink { --m: #c43c82; }
.m-orange { --m: #cf6415; }
.m-teal { --m: #11879a; }
.m-red { --m: #c8372f; }
.m-gold { --m: #a37800; }
@media (prefers-color-scheme: dark) {
  .m-green { --m: #5cc98a; }
  .m-blue { --m: #6ea8ff; }
  .m-purple { --m: #b28cff; }
  .m-pink { --m: #f28cc0; }
  .m-orange { --m: #ffa25c; }
  .m-teal { --m: #4fd0e0; }
  .m-red { --m: #ff7b73; }
  .m-gold { --m: #e6c14d; }
}
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--m); }

/* Filter and "who's going" chips */
.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 -16px 16px;
  padding: 2px 16px 4px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip[aria-pressed="true"] {
  border-color: var(--m);
  background: color-mix(in srgb, var(--m) 16%, var(--surface));
  box-shadow: inset 0 0 0 1px var(--m);
}
.chip-all { --m: var(--text); }
.chip-edit { color: var(--accent); border-style: dashed; }

/* Family editor */
.member-row { display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; }
.member-name { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.member-row .dot { width: 14px; height: 14px; }
.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch {
  appearance: none;
  width: 40px;
  height: 40px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  border: 3px solid var(--surface);
  background: var(--m);
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
}
.swatch:checked { box-shadow: 0 0 0 3px var(--text); }

/* "This event / All events" switch */
.seg-group { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg-group label { flex: 1; text-align: center; padding: 10px; font-weight: 600; cursor: pointer; }
.seg-group label + label { border-left: 1px solid var(--line); }
.seg-group input { position: absolute; opacity: 0; pointer-events: none; }
.seg-group label:has(input:checked) { background: var(--accent-soft); color: var(--accent); }
.seg-group label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: -3px; }

.btn-danger { color: var(--danger); }
.spacer { flex: 1; }

/* Dialogs */
dialog {
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  width: min(560px, calc(100% - 24px));
  border: 0;
  border-radius: 20px;
  padding: 20px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h2 { margin: 0 0 4px; font-size: 22px; }
dialog form { display: grid; gap: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Bottom tabs */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tabbar a {
  flex: 1;
  max-width: 200px;
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--accent); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 15px;
  max-width: calc(100% - 32px);
  z-index: 20;
}

.more { display: flex; justify-content: center; margin: 8px 0 24px; }
