:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --ink: #1c1b18;
  --ink-2: #5d5a52;
  --line: #e1ded5;
  --accent: #0f6e56;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ec;
  --joint: #6a4bc4;
  --joint-soft: #eeeafb;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --dur-fast: 150ms;
  --dur: 200ms;
  --dur-slow: 250ms;
  --ease: cubic-bezier(.2, .7, .2, 1); /* ease-out, no bounce */
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --amber-fill: #c98200; /* bars: --warn is for text and reads as brown when filled */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121311;
    --surface: #1b1d1a;
    --surface-2: #242723;
    --ink: #ecebe6;
    --ink-2: #a3a199;
    --line: #2f322d;
    --accent: #3fbf95;
    --accent-ink: #08130f;
    --accent-soft: #163329;
    --joint: #a68cf0;
    --joint-soft: #2a2340;
    --danger: #f2827a;
    --warn: #e9b65a;
    --warn-soft: #35290f;
    --amber-fill: #e9b65a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) 16px calc(32px + env(safe-area-inset-bottom));
}
main { max-width: 640px; margin: 0 auto; overflow-x: clip; }
[hidden] { display: none !important; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* top bar */
.top { display: flex; align-items: center; justify-content: space-between; padding: 18px 0 14px; }
.brand { font-weight: 700; letter-spacing: -.01em; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 12px; height: 12px; border-radius: 4px; background: var(--accent); }
.who { font-size: 14px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28vw; margin-right: 4px; }
.top-actions { display: flex; align-items: center; min-width: 0; }
.top-actions .btn { padding: 0 10px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: .01em; }

/* buttons + fields */
button, input, select { font: inherit; color: inherit; }
.btn { min-height: 44px; padding: 0 18px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn.block { width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: grid; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.field input, .field select {
  min-height: 44px; width: 100%; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.amount input { font-family: var(--mono); font-size: 20px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 0 0 10px; }
.note { font-size: 13px; color: var(--ink-2); margin: 10px 0 0; }

/* segmented control */
.seg { display: flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 3px; margin: 0 0 12px; border: 0; min-width: 0; }
.seg legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.seg label { flex: 1; position: relative; min-width: 0; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 44px; padding: 0 6px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.joint-only:not([hidden]) { animation: fade var(--dur) var(--ease) both; }

/* top bar extras */
.title { font-size: 17px; margin: 0; flex: 1; text-align: center; min-width: 0; }
.back-btn { padding: 0 10px 0 0; }
.back-btn ~ .top-actions { min-width: 62px; }
.month-nav { display: flex; align-items: center; margin-bottom: 10px; }
.arrow { width: 44px; padding: 0; font-size: 22px; flex: none; }
.btn.arrow[disabled] { cursor: default; opacity: .3; }

/* month totals */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-width: 0; }
.stat .label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.stat .value { font-size: 18px; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.stat .sub { font-size: 12px; color: var(--ink-2); }
.banner { display: grid; gap: 2px; width: 100%; text-align: left; min-height: 44px; padding: 10px 14px; margin-bottom: 12px; border-radius: var(--radius); border: 1px solid var(--warn); background: var(--warn-soft); cursor: pointer; }
.banner span { font-size: 13px; color: var(--ink-2); }
.actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.actions .btn { padding: 0 4px; font-size: 14px; }

/* bars (one series; the tick is the average; every value is also written out) */
.bar { display: block; position: relative; height: 8px; background: var(--surface-2); border-radius: 0 4px 4px 0; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; transform-origin: left; }
.bar-avg { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--ink); box-shadow: 0 0 0 1px var(--surface); }
.grow .bar-fill { animation: grow var(--dur-slow) var(--ease) both; }
.group { border-top: 1px solid var(--line); }
.group summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 10px 0; min-height: 44px; cursor: pointer; list-style: none; }
.group summary::-webkit-details-marker { display: none; }
.group summary .bar, .group summary .group-vs { grid-column: 1 / -1; }
.group-name { font-weight: 600; overflow-wrap: anywhere; }
.group-name::after { content: " ›"; color: var(--ink-2); }
.group[open] .group-name::after { content: " ⌄"; }
.group-vs { font-size: 12px; color: var(--ink-2); }
.group[open] .cats { animation: fade var(--dur) var(--ease) both; }
.cats { list-style: none; margin: 0 0 8px; padding: 0 0 0 10px; }
.cats li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; font-size: 14px; padding: 3px 0; }
.settle { font-weight: 600; }

/* budgets: green under, amber within the allowance, red past it (always said in words too) */
.bar.under .bar-fill { background: var(--accent); }
.bar.near .bar-fill { background: var(--amber-fill); }
.bar.over .bar-fill { background: var(--danger); }
.variance { font-size: 12px; color: var(--ink-2); }
.variance.under { color: var(--accent); }
.variance.near { color: var(--warn); }
.variance.over { color: var(--danger); }
.budget-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; font-size: 14px; padding: 6px 0; }
.budget-line .bar, .budget-line .variance { grid-column: 1 / -1; }
.group summary > .budget-line { grid-column: 1 / -1; padding: 4px 0 0 10px; }
.group-name-plain { font-weight: 600; overflow-wrap: anywhere; }
.budget-block { border-top: 1px solid var(--line); padding: 4px 0; }
.budget-block:first-of-type { border-top: 0; }
.budget-group-title { margin: 6px 0 0; font-size: 14px; font-weight: 600; }
.sub-budgets { padding-left: 10px; }
.sub-budgets .group-name-plain { font-weight: 400; }
.budget-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px 64px; gap: 6px; align-items: center; margin-bottom: 8px; }
.budget-head { margin-bottom: 2px; font-size: 12px; color: var(--ink-2); font-weight: 600; }
.budget-name { display: grid; font-size: 14px; overflow-wrap: anywhere; }
.budget-name .muted { font-size: 12px; }
.budget-row input { min-height: 44px; width: 100%; min-width: 0; padding: 0 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); text-align: right; }
.by-cat summary::after { content: " ›"; margin-left: 4px; }
.by-cat[open] summary::after { content: " ⌄"; }
.btn.spaced { margin-top: 12px; }
.card.closed { border-color: var(--accent); }
.note.hint { margin: -6px 0 12px; }

/* all lines */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.tx { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%; min-height: 56px; padding: 10px 14px; border: 0; background: none; text-align: left; cursor: pointer; }
.tx-main { display: grid; min-width: 0; }
.tx .desc { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .meta { font-size: 13px; color: var(--ink-2); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tx .amt { font-weight: 600; text-align: right; }
.tx .amt.in { color: var(--accent); }
.tag { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); justify-self: start; }
.tag.joint { background: var(--joint-soft); color: var(--joint); }
.tag.waiting { background: var(--warn-soft); color: var(--warn); }
.tag.quiet { background: var(--surface-2); color: var(--ink-2); }
.empty { text-align: center; padding: 28px 12px; color: var(--ink-2); }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; margin: 0; font-size: 14px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.card h2 { overflow-wrap: anywhere; }
.btn.ghost.danger { color: var(--danger); }

/* import */
.file-btn { display: flex; align-items: center; justify-content: center; margin-top: 12px; position: relative; }
.file-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.counts, .accounts, .files, .rules, .edit-list, .sort-lines { list-style: none; margin: 0; padding: 0; }
.counts li { display: flex; gap: 10px; align-items: baseline; padding: 4px 0; animation: rise var(--dur) var(--ease) both; }
.counts li:nth-child(2) { animation-delay: 90ms; }
.counts li:nth-child(3) { animation-delay: 180ms; }
.counts li:nth-child(4) { animation-delay: 270ms; }
.counts li:nth-child(5) { animation-delay: 360ms; }
.counts li:nth-child(6) { animation-delay: 450ms; }
.count { font-size: 22px; font-weight: 600; min-width: 4ch; text-align: right; }
.accounts li { display: grid; gap: 2px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.accounts li:first-child { border-top: 0; }
.card.warn { border-color: var(--warn); }
.question { border-top: 1px solid var(--line); padding-top: 10px; }
.question p { margin: 0 0 6px; overflow-wrap: anywhere; }
.files li { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }

/* to sort */
.status { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; margin-bottom: 8px; font-size: 14px; color: var(--accent); }
.sort-group h2 { margin-bottom: 2px; }
.sort-group > p { margin: 0 0 8px; }
.sort-group select, .sort-lines input, .edit-list input, .rules input, .rules select, .add-row input, .add-row select, .group-input {
  min-height: 44px; width: 100%; min-width: 0; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip { flex: 1 1 auto; padding: 0 12px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.peek summary { min-height: 44px; display: flex; align-items: center; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.bank-text { overflow-wrap: anywhere; font-size: 13px; margin: 2px 0 6px; }
.peek .bank-text { grid-column: 1 / -1; }
.sort-lines li { display: grid; gap: 6px; border-top: 1px solid var(--line); padding: 10px 0; }
.sort-lines .bank-text { margin: 0; }
.line-head { display: flex; justify-content: space-between; font-weight: 600; }
.leaving { opacity: 0; transform: translateY(-8px); transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.sliding { transition: transform var(--dur) var(--ease); }

/* history */
.history { width: 100%; border-collapse: collapse; font-size: 13px; }
.history th, .history td { text-align: right; padding: 0 0 0 6px; }
.history thead th { color: var(--ink-2); font-size: 12px; padding-bottom: 4px; }
.history th:first-child { text-align: left; padding-left: 0; }
.history tbody tr:first-child > * { border-top: 1px solid var(--line); }
.history .month-btn { padding: 0; white-space: nowrap; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.history .bar-row td { padding: 0 0 10px; }
.history tfoot th, .history tfoot td { border-top: 2px solid var(--line); padding-top: 8px; font-weight: 600; }
.history .short { color: var(--danger); }

/* settings */
.menu { display: grid; gap: 8px; margin-bottom: 14px; }
.menu-item { display: flex; justify-content: space-between; align-items: center; text-align: left; }
.group-input { font-weight: 700; margin-bottom: 8px; }
.edit-list li { display: grid; grid-template-columns: minmax(0, 1fr) 58px auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.edit-list .type { font-size: 12px; }
.edit-list .btn { padding: 0 8px; min-width: 56px; }
.hidden-cat input { color: var(--ink-2); text-decoration: line-through; }
.add-row { display: grid; grid-template-columns: minmax(0, 1fr) 104px auto; gap: 6px; margin-top: 10px; }
.add-row.two { grid-template-columns: minmax(0, 1fr) auto; margin-top: 0; }
.add-row .btn { padding: 0 12px; }
.rules li { display: grid; gap: 8px; }
.btn.block + .btn.block { margin-top: 8px; }
.menu .btn.block + .btn.block { margin-top: 0; }

/* passphrase strength */
.strength { font-size: 13px; margin: -6px 0 12px; min-height: 1.2em; color: var(--ink-2); }
.strength[data-level="short"], .strength[data-level="weak"] { color: var(--danger); }
.strength[data-level="strong"] { color: var(--accent); }
.note.ok { color: var(--accent); margin: 0 0 12px; }
.note.ok:empty { display: none; }

/* recovery code */
.code-input { font-family: var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.recovery { border: 1px dashed var(--accent); background: var(--accent-soft); border-radius: 12px; padding: 14px; margin: 0 0 12px; }
.recovery-for { font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.recovery-code { display: grid; grid-template-columns: repeat(3, auto); justify-content: center; gap: 6px 14px; font-size: 22px; font-weight: 600; letter-spacing: .08em; color: var(--ink); }
.row + .note, .row + [role="status"] { margin-top: 10px; }
.recovery ~ .note:not(:empty) { margin-bottom: 14px; }

/* background veil: nothing readable in the app switcher */
body.veiled #app { visibility: hidden; }

/* lock screen */
.lock { padding-top: 8vh; }
.lock .card { padding: 22px; }
.lock p.lede { color: var(--ink-2); margin: 0 0 18px; }
.vaults { display: grid; gap: 8px; margin-bottom: 8px; }
.vault-btn { text-align: left; display: flex; justify-content: space-between; align-items: center; }

/* motion: only transform and opacity, short, ease-out; it explains a change, never decorates */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes from-right { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes from-left { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.screen.in { animation: from-right var(--dur) var(--ease) both; }
.screen.back { animation: from-left var(--dur) var(--ease) both; }
.screen.fade { animation: rise var(--dur) var(--ease) both; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  body { background: #fff; color: #000; padding: 0; }
  body * { visibility: hidden; }
  .recovery, .recovery * { visibility: visible; }
  .recovery { position: absolute; top: 24px; left: 24px; right: 24px; background: #fff; border: 1px solid #000; }
  .recovery-for { color: #000; }
}
