:root {
  color-scheme: light dark;
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #15140f;
  --muted: #6b675c;
  --faint: #a29d90;
  --line: #e4e0d6;
  --clean: #1d8a55;
  --clean-soft: #dcf0e4;
  --slip: #d9543a;
  --slip-soft: #fbe4dd;
  --open: #bdb8ab;
  --hero-bg: #15140f;
  --hero-ink: #f7f5ef;
  --hero-muted: #a9a496;
  --gold: #e9c46a;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 1px 2px rgba(20, 18, 10, .04), 0 10px 30px rgba(20, 18, 10, .06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e0c;
    --surface: #181714;
    --surface-2: #22201c;
    --ink: #f3f1ea;
    --muted: #9d998d;
    --faint: #625e55;
    --line: #2b2924;
    --clean: #48c487;
    --clean-soft: rgba(72, 196, 135, .14);
    --slip: #ff7d60;
    --slip-soft: rgba(255, 125, 96, .14);
    --open: #5a564d;
    --hero-bg: #1d1b17;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
h1, h2, h3, p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout ---------- */
.app {
  max-width: 540px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 12px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 40px) max(16px, env(safe-area-inset-left));
}
.stack > * + * { margin-top: 14px; }
.cols { display: block; }
.cols > .stack + .stack { margin-top: 14px; }
@media (min-width: 920px) {
  .app.wide { max-width: 1080px; padding-top: 28px; }
  .cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
  .cols > .stack + .stack { margin-top: 0; }
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 4px 2px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; }
.who { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); color: var(--bg); font-weight: 650; font-size: 14px;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; color: var(--muted);
  transition: transform .15s var(--ease), color .2s;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn:hover { color: var(--ink); }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.card h2 { font-size: 19px; font-weight: 650; letter-spacing: -.01em; margin-top: 2px; }
.enter { animation: rise .55s var(--ease) both; }
.enter:nth-child(2) { animation-delay: .05s; }
.enter:nth-child(3) { animation-delay: .1s; }
.enter:nth-child(4) { animation-delay: .15s; }
.enter:nth-child(5) { animation-delay: .2s; }
.enter:nth-child(6) { animation-delay: .25s; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- hero balance ---------- */
.hero {
  position: relative; overflow: hidden; border: none;
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(233, 196, 106, .26), transparent 55%),
    radial-gradient(90% 90% at 0% 100%, rgba(72, 196, 135, .12), transparent 60%),
    var(--hero-bg);
  color: var(--hero-ink);
  padding: 22px 20px 20px;
}
.hero .eyebrow { color: var(--hero-muted); }
.amount {
  display: flex; align-items: flex-start; gap: 4px;
  font-size: clamp(56px, 18vw, 84px); font-weight: 700; letter-spacing: -.045em; line-height: 1;
  margin: 12px 0 14px; font-variant-numeric: tabular-nums;
}
.amount .cur { font-size: .48em; margin-top: .12em; color: var(--gold); font-weight: 650; letter-spacing: 0; }
.hero-sub { color: var(--hero-muted); font-size: 15px; }
.hero-sub b { color: var(--hero-ink); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px;
  font-size: 13px; font-weight: 550; background: rgba(255, 255, 255, .09); color: var(--hero-ink);
}
.chip .ico { width: 15px; height: 15px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge .ico { width: 14px; height: 14px; }
.badge.clean { background: var(--clean-soft); color: var(--clean); }
.badge.slip, .badge.slipping { background: var(--slip-soft); color: var(--slip); }

/* ---------- today ---------- */
.today-body { display: flex; gap: 16px; align-items: center; margin-bottom: 6px; }
.ring { flex: none; width: 76px; height: 76px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; stroke-linecap: round; transition: stroke .3s; }
.ring .seg-open { stroke: var(--surface-2); }
.ring .seg-done { stroke: var(--clean); }
.ring .seg-missed { stroke: var(--slip); }
.ring-label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.05; }
.ring-label b { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.ring-label span { display: block; font-size: 11px; color: var(--muted); }
.habits { flex: 1; min-width: 0; }
.habit { display: flex; align-items: center; gap: 12px; padding: 9px 0; }
.habit + .habit { border-top: 1px solid var(--line); }
.habit-ico {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--muted); transition: background .3s, color .3s;
}
.habit-ico .ico { width: 18px; height: 18px; }
.habit.done .habit-ico, .check.done .habit-ico { background: var(--clean-soft); color: var(--clean); }
.habit.missed .habit-ico, .check.missed .habit-ico { background: var(--slip-soft); color: var(--slip); }
.habit-text { flex: 1; min-width: 0; }
.habit-title { font-weight: 600; font-size: 15px; }
.habit-detail { font-size: 13px; color: var(--muted); line-height: 1.35; }
.habit-state { font-size: 13px; font-weight: 600; color: var(--faint); white-space: nowrap; }
.habit.done .habit-state { color: var(--clean); }
.habit.missed .habit-state { color: var(--slip); }
.lockline { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.lockline .ico { width: 15px; height: 15px; }
.callout { margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; background: var(--surface-2); }
.callout.slip { background: var(--slip-soft); color: var(--slip); font-weight: 550; }
.callout.clean { background: var(--clean-soft); color: var(--clean); font-weight: 550; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px 12px; box-shadow: var(--shadow); }
.tile-val { font-size: 26px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile-val small { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; margin-left: 3px; }
.tile-label { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.tile.clean .tile-val { color: var(--clean); }
.tile.slip .tile-val { color: var(--slip); }

/* ---------- calendar ---------- */
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend .l-clean { background: var(--clean); }
.legend .l-slip { background: var(--slip); }
.legend .l-open { box-shadow: inset 0 0 0 1.5px var(--open); }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.dow { font-size: 11px; font-weight: 600; color: var(--faint); text-align: center; padding-bottom: 2px; }
.cell {
  aspect-ratio: 1; border: 0; padding: 0; border-radius: 9px; position: relative;
  background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums; display: grid; place-items: center;
  transition: transform .15s var(--ease);
}
.cell:active { transform: scale(.9); }
.cell.clean { background: var(--clean); color: rgba(255, 255, 255, .92); }
.cell.slip { background: var(--slip); color: rgba(255, 255, 255, .95); }
.cell.open { background: transparent; box-shadow: inset 0 0 0 1.5px var(--open); }
.cell.slipping { background: var(--slip-soft); box-shadow: inset 0 0 0 1.5px var(--slip); color: var(--slip); }
.cell.before, .cell.future { background: transparent; box-shadow: inset 0 0 0 1px var(--line); color: var(--faint); }
.cell.today { outline: 2px solid var(--ink); outline-offset: 2px; }
.cell.sel { transform: scale(.9); }
.cal-detail { margin-top: 12px; min-height: 40px; font-size: 14px; color: var(--muted); padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.cal-detail b { color: var(--ink); }

/* ---------- lists ---------- */
.rows > li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.rows > li + li { border-top: 1px solid var(--line); }
.row-main { min-width: 0; }
.row-title { font-weight: 600; font-size: 15px; }
.row-sub { font-size: 13px; color: var(--muted); }
.amount-sm { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount-sm.slip { color: var(--slip); }
.empty { font-size: 14px; color: var(--muted); padding: 6px 0 2px; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 54px; padding: 0 20px; border: 0; border-radius: 16px;
  background: var(--ink); color: var(--bg); font-weight: 650; font-size: 16px; letter-spacing: -.005em;
  transition: transform .15s var(--ease), opacity .2s, background .2s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .38; cursor: default; transform: none; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.gold { background: var(--gold); color: #15140f; }
.btn.small { min-height: 40px; width: auto; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn.danger { background: var(--slip-soft); color: var(--slip); }
.btn.success { background: var(--clean); color: #fff; }
.field {
  width: 100%; min-height: 58px; padding: 0 18px; border-radius: 16px;
  border: 1.5px solid var(--line); background: var(--surface); font-size: 18px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field:focus { border-color: var(--ink); box-shadow: 0 0 0 4px var(--surface-2); }
textarea.field { min-height: 76px; padding: 12px 14px; font-size: 16px; resize: vertical; line-height: 1.4; }
.shake { animation: shake .42s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

/* ---------- login ---------- */
.login { min-height: calc(100dvh - 80px); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 24px 4px; }
.login .logo { width: 84px; height: 84px; margin-bottom: 22px; }
.login .logo { animation: turn-in 1s var(--ease) both; }
.login h1 { font-size: 34px; font-weight: 750; letter-spacing: -.035em; }
.login .lede { margin-top: 8px; font-size: 17px; color: var(--muted); }
.login form { width: 100%; max-width: 360px; margin-top: 30px; display: grid; gap: 12px; }
.login .err { min-height: 20px; font-size: 14px; color: var(--slip); font-weight: 550; }
.login .fine { margin-top: 6px; font-size: 13px; color: var(--faint); }
@keyframes turn-in { from { opacity: 0; transform: rotate(-120deg) scale(.7); } }

/* ---------- details ---------- */
details.how summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; font-weight: 650; }
details.how summary::-webkit-details-marker { display: none; }
details.how summary .ico { transition: transform .25s var(--ease); color: var(--muted); }
details.how[open] summary .ico { transform: rotate(180deg); }
details.how ol { margin: 12px 0 0; padding-left: 20px; color: var(--muted); font-size: 14.5px; }
details.how li + li { margin-top: 8px; }
details.how b { color: var(--ink); font-weight: 600; }

/* ---------- toast & boot ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); z-index: 20;
  transform: translate(-50%, 24px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 550; max-width: calc(100% - 32px); text-align: center;
  transition: transform .35s var(--ease), opacity .35s var(--ease);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.boot { min-height: 70dvh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--ink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.foot { text-align: center; font-size: 12.5px; color: var(--faint); padding: 18px 0 0; }

/* ---------- admin ---------- */
.tabs { display: flex; gap: 6px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.tabs button { flex: 1; min-height: 40px; border: 0; border-radius: 11px; background: transparent; font-weight: 600; font-size: 14px; color: var(--muted); transition: background .2s, color .2s; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.check { padding: 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); transition: border-color .25s; }
.check + .check { margin-top: 10px; }
.check.done { border-color: color-mix(in srgb, var(--clean) 45%, var(--line)); }
.check.missed { border-color: color-mix(in srgb, var(--slip) 45%, var(--line)); }
.check-top { display: flex; gap: 12px; align-items: flex-start; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.seg button {
  min-height: 50px; border-radius: 14px; border: 1.5px solid var(--line); background: transparent;
  font-weight: 650; display: flex; align-items: center; justify-content: center; gap: 7px; color: var(--muted);
  transition: background .18s var(--ease), border-color .18s, color .18s, transform .12s;
}
.seg button:active { transform: scale(.97); }
.seg button.on.done { background: var(--clean); border-color: var(--clean); color: #fff; }
.seg button.on.missed { background: var(--slip); border-color: var(--slip); color: #fff; }
.seg button[disabled] { opacity: .35; }
.note-wrap { margin-top: 10px; }
.history-day { padding: 12px 0; }
.history-day + .history-day { border-top: 1px solid var(--line); }
.history-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.mini { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.mini button, .mini span {
  display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 999px; border: 0;
  font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--muted);
}
.mini .done { background: var(--clean-soft); color: var(--clean); }
.mini .missed { background: var(--slip-soft); color: var(--slip); }
.mini .ico { width: 13px; height: 13px; }
.signin { text-align: center; padding: 40px 10px; }
.signin p { margin: 10px 0 20px; color: var(--muted); }
