:root {
  --bg: #f6f1e7;
  --card: #fffdf8;
  --ink: #2b2118;
  --muted: #8a7a66;
  --line: #e8dcc8;
  --accent: #b8742a;
  --accent-ink: #fff;
  --accent-soft: #f4e3c8;
  --good: #3f7d4e;
  --bad: #b5452f;
  --shadow: 0 1px 2px rgb(60 40 10 / .05), 0 8px 24px rgb(60 40 10 / .06);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1712;
    --card: #25201a;
    --ink: #f1e8da;
    --muted: #a8987f;
    --line: #3a3127;
    --accent: #e0a35a;
    --accent-ink: #1b1712;
    --accent-soft: #3d2e1c;
    --good: #7cc08e;
    --bad: #ec8a74;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 Inter, system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
h1, h2, .brand, .big { font-family: Lora, Georgia, serif; }
h1 { margin: 4px 0 2px; font-size: 30px; }
h2 { margin: 0 0 12px; font-size: 19px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }

.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px 40px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; text-align: center; }
.login-card label { text-align: left; }
.lotus { color: var(--accent); font-size: 32px; line-height: 1; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  max-width: 640px; margin: 0 auto;
}
.brand { font-size: 20px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.brand .lotus { font-size: 22px; }
.rhythm, .kinds {
  display: flex; background: var(--accent-soft); border-radius: 999px; padding: 3px; gap: 2px;
}
.rhythm button, .kinds button {
  border: 0; background: none; color: var(--ink); font: inherit; font-size: 14px; font-weight: 500;
  padding: 7px 12px; border-radius: 999px; cursor: pointer; transition: background .15s, color .15s;
}
.rhythm button.active, .kinds button.active { background: var(--card); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.kinds { margin-bottom: 14px; }
.kinds button { flex: 1; padding: 9px 6px; }

/* Hero */
.hero-label { font-size: 14px; color: var(--muted); margin-bottom: 8px; text-transform: lowercase; }
.hero-label::first-letter { text-transform: uppercase; }
.hero-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.right { text-align: right; }
.big { font-size: 40px; font-weight: 600; line-height: 1.1; color: var(--accent); }
.mid { font-size: 22px; font-weight: 600; }
.progress { height: 8px; background: var(--accent-soft); border-radius: 99px; margin: 14px 0; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s ease; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.stats div { background: var(--bg); border-radius: 12px; padding: 8px 10px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 0; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.balance {
  margin-top: 12px; padding: 10px 12px; border-radius: 12px; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: color-mix(in srgb, var(--good) 12%, transparent); color: var(--good);
}
.balance.owe { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }

/* Form */
.entry-form { display: grid; gap: 12px; }
.hint { margin: -4px 0 0; font-size: 13px; color: var(--muted); }
label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; width: 100%; min-width: 0;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.row { display: flex; gap: 10px; }
.row .grow { flex: 1; }
.row input[type=date] { width: 150px; }

.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.balance .btn.ghost { color: inherit; border-color: currentColor; }

/* Entries */
.entries { list-style: none; margin: 0; padding: 0; }
.day-head { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 4px; }
.day-head:first-child { margin-top: 0; }
.entry { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry .dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; flex: none; }
.entry.income .dot { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.entry.expense .dot { background: color-mix(in srgb, var(--bad) 13%, transparent); color: var(--bad); }
.entry.donation .dot { background: var(--accent-soft); color: var(--accent); }
.entry .body { flex: 1; min-width: 0; }
.entry .title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .sum { font-weight: 600; white-space: nowrap; }
.entry .del {
  border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 6px; border-radius: 8px;
}
.entry .del:hover { color: var(--bad); }
.empty { margin: 0; }

/* History */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.history { width: 100%; border-collapse: collapse; font-size: 14px; }
.history th { text-align: right; font-weight: 500; color: var(--muted); font-size: 12px; padding: 4px; }
.history td { text-align: right; padding: 7px 4px; border-top: 1px solid var(--line); white-space: nowrap; }
.history th:first-child, .history td:first-child { text-align: left; }
.history tr.owe td:last-child { color: var(--bad); }

/* Practice */
.practice details { margin-top: 10px; }
.practice summary { cursor: pointer; font-weight: 500; }
.practice ol { padding-left: 20px; margin: 10px 0; }
.practice li { margin-bottom: 4px; }
.gifts { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.gifts li { background: var(--accent-soft); border-radius: 12px; padding: 8px 12px; font-size: 14px; }
.gifts .ded { display: block; font-style: italic; color: var(--muted); font-size: 13px; }

/* Footer */
.foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 4px 2px; }
.rate { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.rate input { width: 64px; padding: 6px 8px; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 420px) {
  .top { flex-direction: column; align-items: stretch; }
  .rhythm button { flex: 1; }
  .big { font-size: 34px; }
  .row { flex-direction: column; }
  .row input[type=date] { width: 100%; }
  .card { padding: 16px 14px; }
  .history { font-size: 13px; }
  .stats dd { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
