:root {
  --bg: #F7F3EC;
  --card: #FDFBF7;
  --line: #E8E1D5;
  --ash: #353431;
  --ash-2: #6E6A63;
  --ash-3: #A29D94;
  --teal: #D5F0EB;
  --teal-2: #A8DDD4;
  --teal-ink: #2D6A61;
  --cora: #F2D26A;
  --cora-soft: #FBF1CD;
  --cora-ink: #6B5413;
  --masha: #86AEE0;
  --masha-soft: #E1EBF8;
  --masha-ink: #274A72;
  --both: linear-gradient(90deg, var(--cora) 50%, var(--masha) 50%);
  --both-soft: linear-gradient(90deg, var(--cora-soft) 50%, var(--masha-soft) 50%);
  --round: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, "Segoe UI", sans-serif;
  --sans: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --on-accent: #353431;
  --cora-on: #6B5413;
  --masha-on: #274A72;
  --bar-bg: rgba(247, 243, 236, 0.94);
  --scrim: rgba(53, 52, 49, 0.32);
  --error: #9A4A3A;
  --focus: var(--teal-ink);
  --focus-ring: var(--teal);
  color-scheme: light;
}

/* Dark: ash background, beige text. Chosen in Settings, saved on each phone. */
html[data-theme="dark"] {
  --bg: #2B2A27;
  --card: #363531;
  --line: #474540;
  --ash: #F3EEE5;
  --ash-2: #BEB7AB;
  --ash-3: #8A847A;
  --cora-soft: #4A4127;
  --cora-ink: #F2D26A;
  --masha-soft: #2E3B4D;
  --masha-ink: #AFCBEE;
  --on-accent: #2B2A27;
  --bar-bg: rgba(43, 42, 39, 0.94);
  --scrim: rgba(0, 0, 0, 0.5);
  --error: #E8A08C;
  --focus: var(--teal-2);
  --focus-ring: rgba(213, 240, 235, 0.22);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ash); font-family: var(--sans); }
body { min-height: 100dvh; -webkit-font-smoothing: antialiased; }
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
input { font: inherit; font-size: 17px; color: var(--ash); }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 14px) 16px calc(var(--safe-b) + 96px);
}

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.top h1 { font-family: var(--round); font-size: 30px; font-weight: 600; margin: 0; letter-spacing: -0.3px; }
.top h1 small { font-size: 17px; font-weight: 500; color: var(--ash-3); margin-left: 6px; }
.top .grow { flex: 1; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; background: var(--card); border: 1px solid var(--line);
}
.icon-btn svg { width: 20px; height: 20px; }
.pill-btn { height: 34px; padding: 0 14px; border-radius: 17px; background: var(--teal); color: var(--teal-ink); font-weight: 600; font-size: 14px; }
.me {
  height: 40px; padding: 0 12px 0 8px; border-radius: 20px; display: flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--line); font-weight: 600; font-size: 15px;
}
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none; }
.dot.cora { background: var(--cora); }
.dot.masha { background: var(--masha); }
.dot.both { background: var(--both); }

/* ---------- calendar ---------- */
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays span { text-align: center; font-size: 12px; font-weight: 600; color: var(--ash-3); padding-bottom: 6px; }
.grid { gap: 4px; }
.day {
  min-height: 66px; border-radius: 12px; background: var(--card); border: 1px solid var(--line);
  padding: 5px 4px 6px; display: flex; flex-direction: column; align-items: stretch; gap: 3px; text-align: left;
}
.day.out { background: transparent; border-color: transparent; }
.day.out .num { color: var(--ash-3); }
.day .num {
  font-family: var(--round); font-size: 15px; font-weight: 600; width: 26px; height: 26px;
  display: grid; place-items: center; border-radius: 50%; margin-bottom: 1px;
}
.day.today { border-color: var(--teal-2); }
.day.today .num { background: var(--teal); color: var(--teal-ink); }
.bar { height: 6px; border-radius: 3px; }
.bar.cora { background: var(--cora); }
.bar.masha { background: var(--masha); }
.bar.both { background: var(--both); }
.bar.done { opacity: 0.3; }
.more { font-size: 11px; font-weight: 600; color: var(--ash-2); line-height: 1; padding-left: 2px; }

.section-title { display: flex; align-items: baseline; gap: 8px; margin: 26px 2px 10px; }
.section-title h2 { font-family: var(--round); font-size: 21px; font-weight: 600; margin: 0; }
.section-title span { color: var(--ash-3); font-size: 15px; font-weight: 500; }

/* ---------- task rows ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-height: 60px;
}
.row.is-done .title { text-decoration: line-through; color: var(--ash-3); }
.check {
  width: 32px; height: 32px; border-radius: 50%; flex: none; padding: 3px; display: grid;
}
.check i { border-radius: 50%; background: var(--card); display: grid; place-items: center; }
.check svg { width: 17px; height: 17px; stroke-width: 2.6; opacity: 0; color: var(--on-accent); }
.check.cora { background: var(--cora); }
.check.masha { background: var(--masha); }
.check.both { background: var(--both); }
.check.plain { background: var(--ash-3); }
.is-done .check i { background: transparent; }
.is-done .check svg { opacity: 1; }
.is-done .check.plain i { background: var(--teal); }
.is-done .check.plain { background: var(--teal-2); }
.row-main { flex: 1; min-width: 0; text-align: left; display: flex; flex-direction: column; gap: 3px; }
.title { font-size: 17px; font-weight: 500; overflow-wrap: anywhere; }
.meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tag { font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 8px; }
.tag.cora { background: var(--cora-soft); color: var(--cora-ink); }
.tag.masha { background: var(--masha-soft); color: var(--masha-ink); }
.tag.both { background: var(--both-soft); color: var(--ash); }
.tag.time { background: var(--bg); color: var(--ash-2); border: 1px solid var(--line); }
.tag.ok { background: var(--teal); color: var(--teal-ink); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 2px 4px 6px 56px; margin-top: -4px; }
.mini { height: 34px; padding: 0 12px; border-radius: 10px; font-size: 14px; font-weight: 600; border: 1px solid var(--line); background: var(--card); }
.mini.cora { background: var(--cora-soft); color: var(--cora-ink); border-color: transparent; }
.mini.masha { background: var(--masha-soft); color: var(--masha-ink); border-color: transparent; }
.mini.both { background: var(--both-soft); border-color: transparent; }
.mini.active { outline: 2px solid var(--ash); outline-offset: -2px; }
.mini.danger { margin-left: auto; color: var(--ash-2); }
.empty { color: var(--ash-2); background: transparent; border: 1.5px dashed var(--line); border-radius: 16px; padding: 18px; text-align: center; font-size: 15px; }

/* ---------- tabs ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 10px;
  padding: 8px 16px calc(var(--safe-b) + 8px);
  background: var(--bar-bg); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.tab {
  position: relative; flex: 1; max-width: 220px; height: 52px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--ash-2); font-weight: 600; font-size: 16px;
}
.tab svg { width: 23px; height: 23px; }
.tab.active { background: var(--teal); color: var(--on-accent); }
.me-tab { flex: none; width: 52px; }
.me-tab .dot { width: 24px; height: 24px; box-shadow: 0 0 0 3px var(--card), 0 0 0 4px var(--line); }
.static, .static .sheet { animation: none; }
.count {
  min-width: 22px; height: 22px; border-radius: 11px; padding: 0 6px; font-size: 13px;
  background: var(--ash); color: var(--bg); display: grid; place-items: center;
}

/* ---------- sheet ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 20; background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 160ms ease-out;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 90dvh; background: var(--bg);
  border-radius: 24px 24px 0 0; display: flex; flex-direction: column;
  animation: up 220ms cubic-bezier(.2,.8,.3,1);
}
.sheet-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 6px 16px 20px; }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 4px; flex: none; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; padding: 4px 16px 8px; flex: none; }
.sheet-head .grow { flex: 1; }
.sheet-head .kicker { font-size: 14px; font-weight: 600; color: var(--ash-3); }
.sheet-head h2 { font-family: var(--round); font-size: 26px; font-weight: 600; margin: 0; }
.label { font-size: 14px; font-weight: 600; color: var(--ash-2); margin: 22px 2px 10px; }

.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chip {
  min-height: 52px; padding: 8px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line);
  text-align: left; font-size: 15.5px; font-weight: 500; line-height: 1.25;
}
.chip.custom { border-style: dashed; color: var(--ash-2); }
.chip.picked { background: var(--teal); border-color: var(--teal-ink); color: var(--on-accent); }

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ash-2); padding-left: 2px; }
.input {
  height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  padding: 0 14px; outline: none; width: 100%; -webkit-appearance: none; appearance: none;
}
.input:focus { border-color: var(--focus); box-shadow: 0 0 0 3px var(--focus-ring); }
.field-error { color: var(--error); font-size: 14px; font-weight: 500; padding-left: 2px; }

.who {
  flex: none; border-top: 1px solid var(--line); background: var(--card);
  padding: 12px 16px calc(var(--safe-b) + 12px); animation: up 180ms ease-out;
}
.who p { margin: 0 0 10px; font-size: 15px; color: var(--ash-2); }
.who p b { color: var(--ash); }
.who-btns { display: flex; gap: 8px; }
.who-btn { flex: 1; height: 56px; border-radius: 16px; font-weight: 700; font-size: 17px; }
.who-btn.cora { background: var(--cora); color: var(--cora-on); }
.who-btn.masha { background: var(--masha); color: var(--masha-on); }
.who-btn.both { background: var(--both); color: var(--on-accent); }

/* ---------- food ---------- */
.add-row { display: flex; gap: 8px; }
.add-row .input { flex: 1; }
.add-btn { width: 50px; height: 50px; border-radius: 14px; background: var(--ash); color: var(--bg); display: grid; place-items: center; flex: none; }
.add-btn svg { width: 22px; height: 22px; stroke-width: 2.4; }
.food-who { font-size: 13px; color: var(--ash-3); font-weight: 500; }
.link-btn { margin: 14px auto 0; display: block; color: var(--ash-2); font-weight: 600; font-size: 15px; padding: 10px; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- settings + onboarding ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.card p { margin: 0 0 12px; font-size: 15px; line-height: 1.45; color: var(--ash-2); }
.card p b { color: var(--ash); }
.btn {
  height: 52px; width: 100%; border-radius: 16px; background: var(--ash); color: var(--bg);
  font-weight: 700; font-size: 17px;
}
.btn.soft { background: var(--teal); color: var(--on-accent); }
.seg { display: flex; gap: 8px; }
.seg .who-btn { opacity: 0.55; }
.mode-btn { flex: 1; height: 52px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); font-weight: 700; font-size: 17px; color: var(--ash-2); }
.mode-btn.on { background: var(--teal); border-color: var(--teal-ink); color: var(--on-accent); }
.seg .who-btn.on { opacity: 1; outline: 2.5px solid var(--ash); outline-offset: -2.5px; }
.hint { background: var(--teal); color: var(--teal-ink); border-radius: 14px; padding: 12px 14px; font-size: 15px; line-height: 1.45; font-weight: 500; }

.welcome { min-height: calc(100dvh - 60px); display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.logo { width: 64px; height: 64px; border-radius: 16px; }
.welcome h1 { font-family: var(--round); font-size: 34px; font-weight: 600; margin: 4px 0 0; }
.welcome .sub { margin: 0 0 12px; color: var(--ash-2); font-size: 17px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 84px); z-index: 40;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ash); color: var(--bg); padding: 11px 18px; border-radius: 14px;
  font-weight: 600; font-size: 15px; transition: all 200ms ease; max-width: calc(100% - 40px); text-align: center;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

@keyframes up { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes nudge { 0%, 100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.nudge { animation: nudge 220ms ease; }
