:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #16a34a;
  --accent-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --toast: #111827;
  --toast-text: #ffffff;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b22;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #2a2f3a;
    --accent: #22c55e;
    --accent-soft: #143222;
    --red: #f87171;
    --red-soft: #3b1a1a;
    --amber: #fbbf24;
    --amber-soft: #3a2e10;
    --toast: #f3f4f6;
    --toast-text: #111827;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body.noscroll { overflow: hidden; }
#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(100px + env(safe-area-inset-bottom));
}
h1 { font-size: 24px; margin: 0; letter-spacing: -0.3px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3.day { font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 4px 6px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--accent); }
.neg { color: var(--red); }
.center { text-align: center; }
[hidden] { display: none !important; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 14px; min-height: 44px; }
.top .back { text-decoration: none; font-weight: 600; font-size: 15px; }
.avatar {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 22px; text-decoration: none;
}

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card.list { padding: 0; overflow: hidden; }
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 .link { font-size: 14px; }
.big { font-size: 34px; font-weight: 700; letter-spacing: -0.5px; margin: 0 0 12px; font-variant-numeric: tabular-nums; }
.big2 { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.row3 b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.split { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.warn > span { background: var(--amber); }
.bar.over > span { background: var(--red); }
.today-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.streak { text-align: center; min-width: 76px; }
.streak b { display: block; font-size: 24px; }
.tips p { margin: 6px 0; }
.tips p::before { content: "• "; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }

/* list rows */
.item { display: flex; align-items: center; gap: 12px; padding: 11px 16px; color: inherit; text-decoration: none; cursor: default; }
.item[data-act], a.item { cursor: pointer; }
.list .item + .item { border-top: 1px solid var(--line); }
.item .ic {
  width: 38px; height: 38px; flex: none; border-radius: 11px;
  background: var(--bg); display: grid; place-items: center; font-size: 19px;
}
.item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item .grow b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item small { color: var(--muted); font-size: 12.5px; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.amt small { display: block; font-weight: 400; }
.item.off { opacity: .55; }
.item.off .grow b { text-decoration: line-through; }
.item.me { background: var(--accent-soft); }
.rank { width: 26px; text-align: center; font-weight: 700; color: var(--muted); flex: none; }
.tag {
  display: inline-block; align-self: flex-start; font-size: 11.5px; padding: 1px 8px; margin-top: 3px;
  border-radius: 99px; background: var(--line); color: var(--muted);
}
.tag.warn { background: var(--amber-soft); color: var(--amber); }
.catrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; margin: 10px 0; }
.catrow .bar { grid-column: 1 / -1; height: 6px; }

/* buttons and inputs */
.btn {
  display: block; width: 100%; margin-top: 12px; padding: 13px 16px;
  border: 0; border-radius: 12px; font: inherit; font-weight: 600; text-align: center; text-decoration: none;
  background: var(--accent); color: #fff; cursor: pointer;
}
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn:disabled { opacity: .5; }
.link { border: 0; background: none; padding: 0; font: inherit; color: var(--accent); font-weight: 600; cursor: pointer; }
.link.danger { color: var(--red); }
input {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); outline: none;
}
input:focus { border-color: var(--accent); }
label { display: block; margin: 12px 0; font-size: 13px; color: var(--muted); }
label > input { margin-top: 6px; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 15px; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; padding: 3px; background: var(--bg); border-radius: 12px; }
.seg button { border: 0; background: transparent; padding: 8px 4px; border-radius: 9px; font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 99px; padding: 7px 12px; font: inherit; font-size: 14px; cursor: pointer;
}
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.emojis { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin: 8px 0; }
.emojis button { aspect-ratio: 1; font-size: 22px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer; padding: 0; }
.emojis button.on { border-color: var(--accent); background: var(--accent-soft); }

.monthnav {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px;
}
.monthnav button { width: 44px; height: 36px; border: 0; border-radius: 9px; background: transparent; color: var(--text); font-size: 22px; cursor: pointer; }
.monthnav button:disabled { opacity: .25; }
.monthnav span { font-weight: 600; }

/* add sheet */
.sheet-wrap {
  position: fixed; left: 0; right: 0; top: var(--vvt, 0px); height: var(--vvh, 100%); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .4); animation: fade .15s;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 94%; overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 6px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .2s ease-out;
}
.grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin-bottom: 12px; }
.amount { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: 10px 0 6px; }
.amount input { width: 2ch; min-width: 1.6ch; max-width: 80%; border: 0; background: transparent; padding: 4px; text-align: center; font-size: 42px; font-weight: 700; }
.amount span { font-size: 28px; color: var(--muted); }
.dates { display: grid; grid-template-columns: auto auto 1fr; gap: 8px; align-items: center; margin: 12px 0; }
.dates input { padding: 8px 10px; font-size: 15px; }
.row2 { display: flex; gap: 12px; justify-content: space-between; align-items: center; margin-top: 14px; }

/* feed */
.people { display: flex; gap: 12px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.people::-webkit-scrollbar { display: none; }
.person { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 60px; color: inherit; text-decoration: none; font-size: 12px; }
.person .av { width: 52px; height: 52px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: 26px; }
.feed .item { align-items: flex-start; }
.feed .who { color: inherit; text-decoration: none; }
.feed .what { margin-top: 1px; }
.rx { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.rx button { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 99px; padding: 2px 9px; font-size: 14px; cursor: pointer; }
.rx button.z { opacity: .5; }
.rx button.on { border-color: var(--accent); background: var(--accent-soft); opacity: 1; }
.rx button span { font-size: 12px; font-weight: 600; margin-left: 2px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { font-size: 12.5px; padding: 3px 10px; border-radius: 99px; background: var(--amber-soft); color: var(--amber); }
.hero { text-align: center; margin: 4px 0 14px; }
.hero .face { font-size: 52px; line-height: 1.1; }
.hero .badges { justify-content: center; }
details summary { cursor: pointer; font-weight: 600; }
details ul { padding-left: 18px; margin: 10px 0 0; }
details li { margin: 4px 0; }

/* auth */
.auth { max-width: 400px; margin: 7vh auto 0; }
.brand { text-align: center; margin-bottom: 18px; }
.brand img { border-radius: 18px; }
.brand h1 { margin-top: 8px; font-size: 28px; }
.brand p { margin: 4px 0 0; }

/* tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; max-width: 560px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; color: var(--muted); text-decoration: none; font-size: 11px; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs svg, .fab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fab {
  justify-self: center; align-self: center; width: 54px; height: 54px; margin-top: -24px;
  border: 0; border-radius: 50%; background: var(--accent); color: #fff; cursor: pointer;
  display: grid; place-items: center; box-shadow: 0 6px 16px rgba(22, 163, 74, .35);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }

.offline {
  position: sticky; top: 0; z-index: 20; padding: calc(6px + env(safe-area-inset-top)) 16px 6px;
  background: var(--amber-soft); color: var(--amber); font-size: 13px; font-weight: 600; text-align: center;
}
.item .actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100;
  max-width: calc(100vw - 32px); padding: 11px 16px; border-radius: 12px;
  background: var(--toast); color: var(--toast-text); font-size: 14px; font-weight: 500; animation: up .2s;
}
.toast.err { background: var(--red); color: #fff; }

.loading { display: grid; place-items: center; padding: 70px 0; }
.loading span { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }

@keyframes up { from { transform: translate(var(--tx, 0), 24px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { --tx: -50%; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
