:root {
  --bg: #F6F1EA;
  --card: #FFFFFF;
  --card-2: #EFE8DE;
  --ink: #1E1B16;
  --muted: #7A7268;
  --line: #E6DED2;
  --brand: #2F6B4F;
  --brand-ink: #FFFFFF;
  --brand-soft: #DCEBE2;
  --gold: #E9B44C;
  --gold-soft: #FBEFD4;
  --red: #D4553F;
  --red-soft: #F9E1DB;
  --green: #2E8B57;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(30, 27, 22, .04), 0 6px 20px rgba(30, 27, 22, .06);
  --num: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tabbar-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130F;
    --card: #1F1D18;
    --card-2: #2A2721;
    --ink: #F3EEE6;
    --muted: #A39B8F;
    --line: #34302A;
    --brand: #5FB48A;
    --brand-ink: #0E1A13;
    --brand-soft: #1D3328;
    --gold-soft: #3A2F18;
    --red: #F07A63;
    --red-soft: #3A1F1A;
    --green: #6BCB93;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--ink); }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------- layout ---------- */
.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 96px);
}
.topbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 16px; }
.topbar h1 { font-size: 28px; margin: 0; letter-spacing: -0.02em; }
.topbar .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; background: var(--card); box-shadow: var(--shadow);
}
.icon-btn svg { width: 20px; height: 20px; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.card h2, .section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 10px; font-weight: 600;
}
.section-title { margin: 22px 4px 10px; display: flex; justify-content: space-between; align-items: center; }
.section-title button { color: var(--brand); text-transform: none; letter-spacing: 0; font-size: 15px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- goal card ---------- */
.goal {
  background: var(--brand); color: var(--brand-ink);
  border-radius: 24px; padding: 20px; margin-bottom: 12px; position: relative; overflow: hidden;
}
.goal::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px;
  border-radius: 50%; background: rgba(255,255,255,.07);
}
.goal .label { font-size: 14px; opacity: .85; }
.goal .big { font-size: 40px; font-weight: 700; margin: 4px 0 2px; }
.goal .of { opacity: .8; font-size: 15px; }
.bar { height: 10px; border-radius: 99px; background: rgba(255,255,255,.22); overflow: hidden; margin: 14px 0 10px; }
.bar > i { display: block; height: 100%; background: var(--gold); border-radius: 99px; transition: width .6s ease; }
.goal .meta { display: flex; justify-content: space-between; font-size: 14px; opacity: .9; gap: 8px; }
.goal .link {
  margin-top: 14px; font-size: 14px; font-weight: 600; padding: 8px 12px; border-radius: 99px;
  background: rgba(255,255,255,.16); color: inherit; position: relative; z-index: 1;
}
.goal .pace { font-size: 13px; opacity: .85; margin-top: 8px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat .k { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.stat .v { font-size: 18px; font-weight: 700; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---------- cooking ---------- */
.meals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 12px; }
.meal {
  padding: 12px 6px; border-radius: 16px; background: var(--card-2); text-align: center;
  font-size: 14px; font-weight: 600; transition: transform .1s ease, background .2s ease;
}
.meal .e { font-size: 24px; display: block; margin-bottom: 2px; }
.meal.on { background: var(--brand); color: var(--brand-ink); }
.meal:active { transform: scale(.96); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
  padding: 6px 10px; border-radius: 99px; background: var(--gold-soft);
}
.pill.green { background: var(--brand-soft); }
.pill.red { background: var(--red-soft); }

/* ---------- transactions ---------- */
.tx { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.tx + .tx { border-top: 1px solid var(--line); }
.tx .ic {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--card-2); font-size: 20px; flex: none;
}
.tx .t { font-weight: 600; }
.tx .s { font-size: 13px; color: var(--muted); }
.tx .a { font-weight: 700; font-size: 16px; white-space: nowrap; }
.who {
  display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  font-size: 10px; font-weight: 700; color: #fff; vertical-align: 1px; margin-right: 4px;
}
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin: 16px 4px 6px; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 22px 8px; font-size: 15px; }
.empty .e { font-size: 34px; display: block; margin-bottom: 6px; }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav .m { font-weight: 700; font-size: 18px; }
.seg { display: flex; background: var(--card-2); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 8px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.cat-bar { margin: 8px 0; }
.cat-bar .row { font-size: 14px; }
.cat-bar .track { height: 8px; background: var(--card-2); border-radius: 99px; overflow: hidden; margin-top: 5px; }
.cat-bar .track i { display: block; height: 100%; background: var(--red); border-radius: 99px; opacity: .8; }

/* ---------- shopping ---------- */
.add-row { display: flex; gap: 8px; margin-bottom: 10px; }
.input {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); outline: none;
}
.input:focus { border-color: var(--brand); }
.btn {
  padding: 13px 18px; border-radius: 14px; background: var(--brand); color: var(--brand-ink);
  font-weight: 700; white-space: nowrap;
}
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; display: block; text-align: center; }
.btn.ghost { background: var(--card-2); color: var(--ink); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  padding: 7px 12px; border-radius: 99px; background: var(--card); border: 1px solid var(--line);
  font-size: 14px; font-weight: 500;
}
.chip:active { background: var(--brand-soft); }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 2px; }
.item + .item { border-top: 1px solid var(--line); }
.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); flex: none;
  display: grid; place-items: center; transition: all .15s ease;
}
.item.done .check { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.item.done .name { text-decoration: line-through; color: var(--muted); }
.item .name { font-weight: 500; }
.item .qty { font-size: 13px; color: var(--muted); margin-left: 6px; }
.item .x { color: var(--muted); font-size: 20px; width: 32px; height: 32px; display: grid; place-items: center; }
.sticky-cta {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px);
  padding: 0 16px; max-width: 560px; margin: 0 auto; z-index: 20;
}
.sticky-cta .btn { box-shadow: 0 8px 24px rgba(47, 107, 79, .35); }

/* ---------- challenges ---------- */
.ch-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.ch-title { font-weight: 700; font-size: 17px; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 12px; }
.d {
  aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--card-2); color: var(--muted);
}
.d.ok { background: var(--brand); color: var(--brand-ink); }
.d.fail { background: var(--red); color: #fff; }
.d.today { outline: 2px solid var(--brand); outline-offset: 2px; color: var(--ink); }
.d.miss { background: var(--red-soft); color: var(--red); }
.progress-mini { height: 6px; background: var(--card-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress-mini i { display: block; height: 100%; background: var(--brand); }
.tpl { display: block; width: 100%; text-align: left; padding: 14px; border-radius: 16px; background: var(--card-2); margin-bottom: 8px; }
.tpl.on { outline: 2px solid var(--brand); background: var(--brand-soft); }
.tpl b { display: block; margin-bottom: 2px; }
.tpl span { font-size: 13px; color: var(--muted); }

.bill { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.bill + .bill { border-top: 1px solid var(--line); }
.bill .day {
  width: 44px; height: 44px; border-radius: 12px; background: var(--card-2); flex: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1;
}
.bill .day b { font-size: 17px; }
.bill .day small { font-size: 10px; color: var(--muted); text-transform: uppercase; margin-top: 2px; }
.mini-btn { padding: 7px 12px; border-radius: 99px; background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 13px; }
.mini-btn.ghost { background: var(--card-2); color: var(--muted); }

/* ---------- tab bar + fab ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar nav { display: flex; max-width: 560px; margin: 0 auto; height: var(--tabbar-h); }
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--muted); position: relative;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button.on { color: var(--brand); }
.badge {
  position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 99px; background: var(--red); color: #fff; font-size: 11px; display: grid; place-items: center;
}
.fab {
  position: fixed; z-index: 25; right: max(16px, calc(50% - 264px));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  width: 60px; height: 60px; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; box-shadow: 0 10px 28px rgba(47, 107, 79, .4);
  transition: transform .12s ease;
}
.fab:active { transform: scale(.92); }
.fab svg { width: 28px; height: 28px; }

/* ---------- sheet ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(20, 18, 14, .38);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .24s cubic-bezier(.2, .9, .3, 1);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 14px; font-size: 20px; display: flex; justify-content: space-between; align-items: center; }
.sheet h3 button { color: var(--muted); font-size: 15px; font-weight: 500; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 4px; font-weight: 600; }
.amount-wrap { display: flex; align-items: center; gap: 6px; background: var(--card); border-radius: 18px; padding: 10px 16px; border: 1px solid var(--line); }
.amount-wrap span { font-size: 32px; color: var(--muted); font-family: var(--num); }
.amount-input {
  border: 0; outline: none; background: transparent; width: 100%;
  font-size: 40px !important; font-weight: 700; font-family: var(--num); padding: 0;
}
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cat {
  padding: 10px 2px 8px; border-radius: 14px; background: var(--card); text-align: center; font-size: 11.5px;
  font-weight: 600; border: 1.5px solid transparent; line-height: 1.15;
}
.cat .e { font-size: 22px; display: block; margin-bottom: 3px; }
.cat.on { border-color: var(--brand); background: var(--brand-soft); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stack > * + * { margin-top: 8px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login .logo { width: 84px; height: 84px; border-radius: 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.login h1 { font-size: 34px; margin: 0 0 6px; letter-spacing: -0.02em; }
.login p { color: var(--muted); margin: 0 0 24px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translate(-50%, -140%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px; font-weight: 600;
  z-index: 100; transition: transform .25s ease; max-width: 90vw; text-align: center;
}
#toast.show { transform: translate(-50%, 0); }

@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
