:root {
  --bg: #fbf6f2;
  --ink: #221d1b;
  --ink-2: #6f6560;
  --ink-3: #a59a94;
  --card: rgba(255,255,255,.78);
  --card-solid: #fff;
  --line: rgba(34,29,27,.08);
  --chip: rgba(34,29,27,.05);
  --accent: #a3405f;
  --accent-soft: #f6e3e8;
  --gold: #a8672a;
  --good: #3f7d58;
  --warn: #b5443b;
  --fab: #221d1b;
  --fab-ink: #fff;
  --shadow: 0 1px 2px rgba(60,30,20,.04), 0 8px 24px rgba(60,30,20,.06);
  --r: 22px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171312; --ink: #f3ece8; --ink-2: #b3a8a2; --ink-3: #7b716c;
    --card: rgba(38,32,30,.82); --card-solid: #26201e; --line: rgba(255,255,255,.08);
    --chip: rgba(255,255,255,.07); --accent: #e48aa5; --accent-soft: rgba(228,138,165,.14);
    --gold: #d9a066; --good: #7cc19a; --warn: #ef8a80; --fab: #f3ece8; --fab-ink: #171312;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: var(--sans); color: var(--ink); background: var(--bg);
  min-height: 100dvh; font-size: 16px; line-height: 1.4;
  background-image:
    radial-gradient(120% 60% at 100% 0%, rgba(246,196,160,.45), transparent 60%),
    radial-gradient(90% 50% at 0% 35%, rgba(214,196,240,.35), transparent 60%),
    radial-gradient(90% 50% at 100% 90%, rgba(244,200,214,.3), transparent 60%);
  background-attachment: fixed;
}
@media (prefers-color-scheme: dark) {
  body { background-image:
    radial-gradient(120% 60% at 100% 0%, rgba(160,90,60,.22), transparent 60%),
    radial-gradient(90% 50% at 0% 35%, rgba(110,90,150,.18), transparent 60%); }
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); }

#app { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top, 0px) + 20px) 16px calc(120px + var(--safe-b)); }

h1 { font-family: var(--serif); font-weight: 600; font-size: 34px; letter-spacing: -.01em; margin: 6px 0 2px; }
h2 { font-family: var(--serif); font-weight: 600; font-size: 20px; margin: 0; }
.sub { color: var(--ink-2); margin: 0 0 18px; font-size: 15px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.card-head .count { color: var(--ink-2); font-size: 14px; }
.card-head .more { margin-left: auto; color: var(--ink-2); font-size: 14px; }
.hero { background: linear-gradient(135deg, rgba(248,214,196,.75), rgba(240,208,226,.7) 55%, rgba(222,210,246,.7)); }
@media (prefers-color-scheme: dark) { .hero { background: linear-gradient(135deg, rgba(120,70,55,.45), rgba(110,60,85,.4) 55%, rgba(80,70,130,.4)); } }

.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.date-label { color: var(--ink-2); font-size: 14px; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow);
  display: grid; place-items: center; }
.icon-btn svg { width: 20px; height: 20px; }

.avatars { display: flex; align-items: center; justify-content: center; }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-weight: 600; font-size: 17px; border: 3px solid var(--card-solid); flex: none; }
.avatar.sm { width: 26px; height: 26px; font-size: 11px; border-width: 2px; }
.avatar.lg { width: 76px; height: 76px; font-size: 30px; border-width: 4px; }
.avatars .avatar + .avatar { margin-left: -10px; }
.avatars .heart { width: 30px; height: 30px; border-radius: 50%; background: var(--card-solid); display: grid; place-items: center;
  margin: 0 -14px; z-index: 2; box-shadow: var(--shadow); }
.avatars .heart svg { width: 15px; fill: #e0526f; }
.greet { text-align: center; margin: 14px 0 2px; font-family: var(--serif); font-size: 30px; font-weight: 600; }
.greet em { color: var(--gold); font-weight: 500; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 14px 6px; }
.stats > * { padding: 0 4px; }
.stats > * + * { border-left: 1px solid var(--line); }
.stats b { display: block; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats span { color: var(--ink-2); font-size: 13px; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--card-solid); border-radius: 16px; padding: 12px; opacity: .92; text-align: left; }
.tile b { display: block; font-size: 22px; font-weight: 600; }
.tile span { color: var(--ink-2); font-size: 13px; }
.tile.on { outline: 2px solid var(--ink); }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 16px; padding: 2px 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; padding: 9px 18px; border-radius: 999px; background: var(--chip); font-weight: 500; font-size: 15px; }
.chip.on { background: var(--fab); color: var(--fab-ink); }

.seg { display: flex; background: var(--chip); border-radius: 14px; padding: 4px; margin-bottom: 16px; }
.seg button { flex: 1; padding: 9px 0; border-radius: 10px; font-weight: 500; font-size: 15px; color: var(--ink-2); }
.seg button.on { background: var(--card-solid); color: var(--ink); box-shadow: var(--shadow); }

/* list rows */
.item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.item:first-of-type, .card-head + .item { border-top: 0; }
.item .t { font-weight: 500; }
.item .meta { color: var(--ink-2); font-size: 13px; margin-top: 1px; }
.item.done .t { text-decoration: line-through; color: var(--ink-3); }
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--ink-3); flex: none; display: grid; place-items: center; }
.check.on { background: #e07c6d; border-color: #e07c6d; }
.check.on::after { content: ""; width: 10px; height: 5px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.flag { color: var(--warn); font-weight: 700; margin-right: 4px; }
.due { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.due.late { color: var(--warn); font-weight: 600; }
.due.soon { color: var(--accent); font-weight: 600; }
.empty { color: var(--ink-3); padding: 10px 0; font-size: 15px; }

/* progress */
.bar { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ink); border-radius: 99px; }
.bar.over > i { background: var(--warn); }
.bar.accent > i { background: linear-gradient(90deg, #d97a8f, #a3405f); }

/* grid cards */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mini { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.mini .tag { font-size: 13px; color: var(--accent); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.mini .tag .heart { margin-left: auto; color: #c0436e; font-size: 18px; line-height: 1; }
.mini .ttl { font-weight: 600; font-size: 17px; line-height: 1.25; }
.mini .price { color: var(--ink-2); margin-top: auto; font-variant-numeric: tabular-nums; }
.mini.got { opacity: .55; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* FAB */
.fab { position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(96px + var(--safe-b)); z-index: 20;
  background: var(--fab); color: var(--fab-ink); border-radius: 999px; padding: 15px 22px; font-weight: 600; font-size: 16px;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 10px 24px rgba(0,0,0,.18); }
.fab::before { content: "+"; font-size: 24px; line-height: 0; font-weight: 400; }

/* nav */
#nav { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--safe-b)); z-index: 30;
  width: min(528px, calc(100% - 24px)); display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-radius: 26px; box-shadow: 0 6px 30px rgba(60,30,20,.12); padding: 8px 4px; }
#nav button { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--ink-2); font-size: 12px; font-weight: 500; padding: 4px 0; }
#nav svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#nav button.on { color: var(--ink); font-weight: 600; }
#nav button.on svg { stroke-width: 2.3; }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head b { font-size: 18px; font-weight: 600; }
.cal-head button { width: 36px; height: 36px; border-radius: 50%; font-size: 22px; color: var(--ink-2); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; row-gap: 4px; }
.cal .dow { color: var(--ink-2); font-size: 12px; font-weight: 600; padding-bottom: 6px; }
.cal .d { height: 50px; display: flex; flex-direction: column; align-items: center; padding-top: 6px; border-radius: 14px; font-variant-numeric: tabular-nums; position: relative; }
.cal .d.today span { background: var(--accent-soft); color: var(--accent); }
.cal .d span { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; font-size: 15px; }
.cal .d.sel span { background: var(--fab); color: var(--fab-ink); }
.cal .d .dots { display: flex; gap: 3px; height: 6px; margin-top: 1px; }
.cal .d .dots i { width: 5px; height: 5px; border-radius: 50%; }
.cal .d .shift { position: absolute; bottom: 2px; left: 6px; right: 6px; display: flex; gap: 2px; }
.cal .d .shift i { flex: 1; height: 3px; border-radius: 2px; opacity: .55; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

/* money */
.big-num { font-size: 32px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.amt.in { color: var(--good); }
.day-label { font-size: 13px; color: var(--ink-2); font-weight: 600; margin: 14px 2px 6px; text-transform: uppercase; letter-spacing: .04em; }
.cat-ico { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; font-size: 18px; background: var(--chip); flex: none; }
.settle { background: var(--accent-soft); color: var(--accent); border-radius: 14px; padding: 10px 14px; font-size: 14px; font-weight: 500; margin-top: 12px; }

/* sheet */
#sheet-wrap { position: fixed; inset: 0; z-index: 50; }
#sheet-backdrop { position: absolute; inset: 0; background: rgba(20,12,10,.35); animation: fade .2s; }
#sheet { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); width: min(560px, 100%);
  max-height: 92dvh; overflow-y: auto; background: var(--bg); border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(22px + var(--safe-b)); animation: up .32s cubic-bezier(.16,1,.3,1);
  transition: transform .26s cubic-bezier(.2,.8,.2,1); overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  box-shadow: 0 -10px 40px rgba(0,0,0,.12); will-change: transform; }
#sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--ink-3); opacity: .5; margin: 0 auto 14px; }
@keyframes up { from { transform: translate(-50%, 100%); } }
#sheet-backdrop { transition: opacity .24s; }
#sheet-wrap.closing #sheet-backdrop { opacity: 0; }
#sheet-wrap.closing { pointer-events: none; }
body.locked { overflow: hidden; }
@keyframes fade { from { opacity: 0; } }
.sheet-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-title h2 { font-size: 22px; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--ink-2); font-weight: 500; margin: 0 0 5px 2px; }
input, select, textarea { width: 100%; background: var(--card-solid); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 14px; font-size: 16px; outline: none; appearance: none; -webkit-appearance: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 15px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
.f2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toggle { display: flex; gap: 6px; flex-wrap: wrap; }
.toggle button { padding: 10px 14px; border-radius: 12px; background: var(--chip); font-weight: 500; font-size: 15px; }
.toggle button.on { background: var(--fab); color: var(--fab-ink); }
.btn { width: 100%; padding: 15px; border-radius: 16px; background: var(--fab); color: var(--fab-ink); font-weight: 600; font-size: 16px; margin-top: 6px; }
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.danger { background: transparent; color: var(--warn); }
.btn:disabled { opacity: .5; }
.err { color: var(--warn); font-size: 14px; min-height: 20px; margin: 4px 2px; }

/* quick add bar */
.quick { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + var(--safe-b)); z-index: 20; width: min(528px, calc(100% - 24px));
  display: flex; gap: 8px; background: var(--card-solid); border-radius: 999px; padding: 6px 6px 6px 18px; box-shadow: 0 6px 24px rgba(60,30,20,.12); }
.quick input { border: 0; padding: 10px 0; background: transparent; border-radius: 0; }
.quick button { width: 44px; height: 44px; border-radius: 50%; background: var(--fab); color: var(--fab-ink); font-size: 22px; flex: none; }

.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); font-weight: 500; padding: 8px 0; }

/* auth */
.auth { max-width: 400px; margin: 8vh auto 0; }
.auth .logo { width: 72px; height: 72px; border-radius: 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.auth h1 { font-size: 38px; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top, 0px) + 14px); z-index: 60;
  background: var(--fab); color: var(--fab-ink); padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow); }
.swipe-hint { font-size: 12px; color: var(--ink-3); text-align: center; margin-top: 8px; }

/* smoother scrolling & screen changes */
html { scroll-behavior: auto; -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }
#app.enter { animation: pagein .26s cubic-bezier(.2,.8,.2,1); }
@keyframes pagein { from { opacity: 0; transform: translateY(8px); } }
button, .item, .mini { transition: transform .12s, opacity .12s, background-color .15s; }
button:active, .mini:active { transform: scale(.97); }
#nav button:active { transform: scale(.92); }
.check:active { transform: scale(.85); }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

/* photos */
.avatar { background-size: cover; background-position: center; }
.avatar.xl { width: 92px; height: 92px; font-size: 36px; border-width: 4px; }
.photos { display: flex; justify-content: center; gap: 28px; margin: 4px 0 8px; }
.who-photo { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.who-photo > button { position: relative; }
.who-photo .cam { position: absolute; right: -2px; bottom: 2px; width: 30px; height: 30px; border-radius: 50%; background: var(--card-solid); box-shadow: var(--shadow); display: grid; place-items: center; font-size: 15px; }
.linkbtn { color: var(--accent); font-size: 13px; font-weight: 500; padding: 2px 4px; }
.flabel { display: block; font-size: 13px; color: var(--ink-2); font-weight: 500; margin: 0 0 5px 2px; }
.photo-field { display: flex; gap: 12px; align-items: center; }
.photo-field .ph { width: 84px; height: 84px; border-radius: 16px; background: var(--chip) center/cover no-repeat; display: grid; place-items: center; font-size: 26px; flex: none; }
.mini.has-img { padding-top: 0; overflow: hidden; }
.mini .wimg { margin: 0 -14px 4px; height: 120px; background: var(--chip) center/cover no-repeat; }
.gimg { margin: -16px -18px 14px; height: 150px; border-radius: var(--r) var(--r) 0 0; background: var(--chip) center/cover no-repeat; }
.grid2 { align-items: start; }
