:root {
  --bg: #FAF7F5; --card: #FFFFFF; --ink: #1D1A1B; --muted: #8C8285; --line: #EFE8E5; --chip: #F3EDEA;
  --accent: #761C33; --accent-ink: #761C33; --accent-soft: #F7EAEE;
  --good: #2E8B57; --good-soft: #E5F3EA; --warn: #B7770F; --warn-soft: #FBF0DC; --bad: #C2334D; --bad-soft: #FBE6EA;
  --shadow: 0 1px 2px rgba(60, 20, 30, .05), 0 8px 24px rgba(60, 20, 30, .06);
  --r: 18px; --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141012; --card: #1E191B; --ink: #F5EFF1; --muted: #A2969A; --line: #2E2629; --chip: #2A2326;
    --accent-ink: #E58BA3; --accent-soft: #3A2129;
    --good: #5CC08A; --good-soft: #1C2E24; --warn: #E3A94A; --warn-soft: #33281A; --bad: #EF7189; --bad-soft: #3A1F25;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 16px; }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--good); } .neg { color: var(--bad); }

.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-logo { width: 120px; opacity: .9; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* layout */
.page { max-width: 680px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 14px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); }
.topbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 16px; gap: 8px; }
.topbar h1 { font-family: var(--serif); font-weight: 600; font-size: 28px; margin: 0; letter-spacing: -.01em; }
.topbar .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--accent-ink); font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.section { margin-top: 22px; }
.section-h { display: flex; justify-content: space-between; align-items: baseline; margin: 0 4px 10px; }
.section-h h2 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0; }
.link { color: var(--accent-ink); font-weight: 600; font-size: 14px; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); }
.pad { padding: 16px; }

/* hero */
.hero { position: relative; overflow: hidden; border-radius: 24px; padding: 20px 20px 18px; color: #fff;
  background: radial-gradient(120% 140% at 100% 0%, #A23A57 0%, #761C33 45%, #4C0F21 100%); box-shadow: 0 12px 30px rgba(118, 28, 51, .28); }
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.12); }
.hero-label { font-size: 13px; opacity: .78; }
.hero-total { font-family: var(--serif); font-size: 38px; font-weight: 600; margin: 4px 0 16px; letter-spacing: -.01em; }
.hero-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hero-tile { background: rgba(255,255,255,.1); border-radius: 14px; padding: 10px 11px; text-align: left; color: #fff; }
.hero-tile .k { font-size: 12px; opacity: .78; display: flex; gap: 5px; align-items: center; }
.hero-tile .v { font-size: 16px; font-weight: 650; margin-top: 3px; }
.pills { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.pill { display: inline-flex; gap: 6px; align-items: center; padding: 9px 13px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-size: 14px; }
.pill b { font-weight: 650; }

/* lists */
.list { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; width: 100%; text-align: left; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 64px; right: 0; border-top: 1px solid var(--line); }
.row.plain + .row.plain::before { left: 16px; }
.row:active { background: var(--chip); }
.ico { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; background: var(--chip); }
.ico.acc { background: var(--accent-soft); color: var(--accent-ink); font-size: 17px; font-weight: 700; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r { text-align: right; font-weight: 650; white-space: nowrap; }
.row .r .s { font-weight: 400; }
.day-h { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 6px 8px; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--chip); color: var(--muted); vertical-align: 1px; margin-left: 4px; letter-spacing: .02em; }
.tag.d { background: #E9F2EC; color: #2E6B47; }
@media (prefers-color-scheme: dark) { .tag.d { background: #1C2E24; color: #7FD3A3; } }
.tag.a { background: var(--accent-soft); color: var(--accent-ink); }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; font-size: 14.5px; }

/* targets */
.goal { padding: 14px 16px; }
.goal + .goal { border-top: 1px solid var(--line); }
.goal-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.goal-name { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.bar { height: 8px; border-radius: 99px; background: var(--chip); margin: 10px 0 8px; position: relative; overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--good); }
.bar.warn > i { background: var(--warn); } .bar.over > i { background: var(--bad); }
.bar > b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: .35; }
.goal-meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); gap: 8px; }
.status { font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 99px; white-space: nowrap; }
.status.ok { background: var(--good-soft); color: var(--good); } .status.warn { background: var(--warn-soft); color: var(--warn); } .status.over { background: var(--bad-soft); color: var(--bad); }

/* segmented & chips */
.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; padding: 8px 10px; border-radius: 10px; font-weight: 600; font-size: 14.5px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 2px 18px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 8px 12px; border-radius: 999px; background: var(--chip); font-size: 14.5px; font-weight: 550; display: inline-flex; gap: 6px; align-items: center; border: 1.5px solid transparent; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.chip.add { background: transparent; border: 1.5px dashed var(--line); color: var(--muted); }
.chip small { font-size: 11.5px; opacity: .75; font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 2px 0; }
.hint.good { color: var(--good); font-weight: 600; }

/* bottom nav */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.4) blur(18px); -webkit-backdrop-filter: saturate(1.4) blur(18px);
  border-top: 1px solid var(--line); }
.nav-in { max-width: 520px; margin: 0 auto; height: var(--nav-h); display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none; }
.nav a.on { color: var(--accent-ink); }
.nav svg { width: 24px; height: 24px; }
.fab { justify-self: center; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(118, 28, 51, .35); transform: translateY(-10px); }
.fab svg { width: 28px; height: 28px; }

/* buttons & forms */
.btn { display: inline-flex; justify-content: center; align-items: center; gap: 8px; padding: 14px 18px; border-radius: 14px; font-weight: 650; font-size: 16px; width: 100%; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:disabled { opacity: .45; }
.btn.ghost { background: var(--chip); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.sm { padding: 9px 13px; font-size: 14px; border-radius: 11px; width: auto; }
.btns { display: flex; gap: 10px; margin-top: 16px; }
.field { margin-top: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 650; color: var(--muted); margin: 0 2px 7px; }
.input { width: 100%; padding: 13px 14px; border-radius: 13px; border: 1.5px solid var(--line); background: var(--card); outline: none; font-size: 16px; }
.input:focus { border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 2px; }
.switch input { appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--line); position: relative; transition: .2s; flex: 0 0 50px; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 23px; }
.switch .s { font-size: 13px; color: var(--muted); }

/* sheet */
.sheet-bg { position: fixed; inset: 0; z-index: 40; background: rgba(20, 8, 12, .38); animation: fade .2s ease; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 94vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 18px calc(env(safe-area-inset-bottom) + 18px);
  max-width: 560px; margin: 0 auto; animation: up .26s cubic-bezier(.2, .9, .3, 1); box-shadow: 0 -10px 40px rgba(0,0,0,.15); }
@media (min-width: 700px) { .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 24px; animation: fade .2s ease; max-height: 90vh; } }
.grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 2px auto 10px; }
.sheet-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sheet-h h3 { margin: 0; font-size: 19px; font-family: var(--serif); font-weight: 600; }
.x { width: 32px; height: 32px; border-radius: 50%; background: var(--chip); display: grid; place-items: center; color: var(--muted); font-size: 18px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* quick add */
.amount { text-align: center; margin: 8px 0 4px; }
.amount .v { font-family: var(--serif); font-size: 46px; font-weight: 600; letter-spacing: -.01em; line-height: 1.1; }
.amount .v.zero { color: var(--muted); }
.amount .cur { font-size: 13px; color: var(--muted); font-weight: 600; }
.qa-block { margin-top: 10px; }
.qa-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; margin: 0 2px 8px; }
.qa-opts { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 10px; }
.pad-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 12px; }
.pad-keys button { height: 48px; border-radius: 14px; background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.05); font-size: 22px; font-weight: 550; }
.pad-keys button:active { background: var(--chip); }
.note-in { margin-top: 10px; }

/* pin */
.lock { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; padding-top: calc(env(safe-area-inset-top) + 24px); }
.lock img { width: 110px; margin-bottom: 18px; }
.lock h2 { font-family: var(--serif); font-weight: 600; margin: 0 0 6px; font-size: 24px; }
.dots { display: flex; gap: 14px; margin: 22px 0 26px; height: 16px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); }
.dots i.f { background: var(--accent); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pinpad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; }
.pinpad button { width: 76px; height: 76px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); font-size: 28px; font-weight: 500; }
.pinpad button.t { background: none; box-shadow: none; font-size: 15px; color: var(--muted); font-weight: 600; }
.enroll { width: 100%; max-width: 380px; }
.err { color: var(--bad); font-size: 14px; font-weight: 600; margin-top: 10px; min-height: 20px; text-align: center; }

/* toast */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px); z-index: 60;
  background: #2A2024; color: #fff; border-radius: 14px; padding: 12px 14px 12px 16px; display: flex; gap: 14px; align-items: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 15px; animation: fade .2s; max-width: calc(100vw - 32px); }
.toast button { color: #F3A6BA; font-weight: 700; }

/* misc */
.kv { display: flex; justify-content: space-between; padding: 11px 2px; border-bottom: 1px solid var(--line); gap: 12px; font-size: 15px; }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }
.big { font-family: var(--serif); font-size: 34px; font-weight: 600; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; padding: 10px 2px; list-style: none; }
details summary::-webkit-details-marker { display: none; }
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-size: 21px; font-weight: 700; margin-top: 4px; }
.month-nav { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 14px; font-weight: 650; }
.month-nav button { width: 36px; height: 36px; border-radius: 50%; background: var(--chip); font-size: 18px; }
.code { font-family: var(--serif); font-size: 40px; letter-spacing: .12em; text-align: center; margin: 12px 0; font-weight: 600; }
.search { margin-bottom: 10px; }
.card-h { display: flex; justify-content: space-between; align-items: center; }

input.chip { width: 150px; } input.chip, select.chip { border: 1.5px solid transparent; appearance: none; -webkit-appearance: none; min-height: 38px; }
