:root {
  --bg: #E8EDE4;
  --card: #FCFBF7;
  --ink: #1C3A2E;
  --ink-soft: #4d6b5d;
  --ink-mute: #7a8a82;
  --accent: #2E6B4F;
  --accent-soft: #d7e4dc;
  --warm: #B5762A;
  --warm-soft: #f0e3cf;
  --alert: #C2603F;
  --alert-soft: #f3dcd1;
  --line: #dde3d8;
  --shadow: 0 1px 2px rgba(28,58,46,.04), 0 8px 24px -12px rgba(28,58,46,.12);
  --radius: 18px;
  --radius-sm: 12px;
  --font-body: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(32px + var(--safe-bot));
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

input, select, textarea {
  font-family: inherit;
  font-size: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 12px 14px;
  width: 100%;
}
input[type="color"] {
  padding: 4px;
  height: 44px;
  width: 56px;
}
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; font-weight: 500; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: calc(8px + var(--safe-top)) 16px 8px;
  display: flex; align-items: center; gap: 12px;
}
.tabs {
  flex: 1;
  background: var(--card);
  border-radius: 999px;
  padding: 4px;
  display: flex;
  box-shadow: var(--shadow);
}
.tab {
  flex: 1;
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  color: var(--ink-soft);
  transition: background .2s, color .2s;
}
.tab[aria-selected="true"] {
  background: var(--accent);
  color: #fff;
}
.icon-btn {
  background: var(--card);
  border-radius: 999px;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  color: var(--ink);
  box-shadow: var(--shadow);
}

/* Main views */
main { padding: 8px 16px 24px; }
.view { display: flex; flex-direction: column; gap: 18px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

/* Hero */
.hero { text-align: left; padding: 22px 20px; }
.hero-label { font-size: 14px; color: var(--ink-soft); font-weight: 500; }
.hero-amount {
  font-family: var(--font-display);
  font-size: 44px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 4px 0 6px;
  line-height: 1.1;
}
.hero-amount.over { color: var(--alert); }
.hero-sub { font-size: 13px; color: var(--ink-mute); }
.hero-breakdown {
  display: flex; gap: 12px; flex-wrap: wrap;
  margin-top: 14px;
  font-size: 13px;
}
.hero-breakdown span { color: var(--ink-soft); }
.hero-breakdown strong { color: var(--ink); font-weight: 600; }

/* Blocks */
.block { display: flex; flex-direction: column; gap: 10px; }
.block-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px;
}
.link-btn {
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  padding: 6px 8px;
  border-radius: 8px;
}
.link-btn:hover { background: var(--accent-soft); }

.list { display: flex; flex-direction: column; gap: 10px; }

/* Envelope rows */
.envelope {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
  position: relative;
}
.env-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.env-name { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.env-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 12px; }
.env-left { font-size: 14px; color: var(--ink-soft); }
.env-left.over { color: var(--alert); font-weight: 600; }
.env-bar { height: 8px; background: var(--accent-soft); border-radius: 999px; overflow: hidden; }
.env-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.env-fill.warn { background: var(--warm); }
.env-fill.over { background: var(--alert); }
.env-actions { display: flex; gap: 6px; }
.env-actions button {
  font-size: 13px; padding: 4px 8px; border-radius: 8px; color: var(--ink-mute);
}
.env-actions button:hover { background: var(--bg); color: var(--ink); }

/* Buffer */
.buffer.hint {
  padding: 12px 16px; font-size: 14px; color: var(--ink-soft);
  display: flex; justify-content: space-between; align-items: center;
}
.buffer.hint strong { color: var(--ink); font-weight: 600; }

/* Cushion / asides */
.cushion-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cushion-amount { font-family: var(--font-display); font-size: 28px; font-weight: 600; color: var(--warm); }
.cushion-actions { display: flex; gap: 8px; }
.ghost-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
}
.ghost-btn:hover { background: var(--bg); }
.ghost-btn.wide { width: 100%; padding: 14px; }
.ghost-btn.danger { color: var(--alert); border-color: var(--alert-soft); }

.asides-card { display: flex; flex-direction: column; gap: 14px; }
.aside-row { display: flex; align-items: center; justify-content: space-between; }
.aside-name { font-weight: 600; }
.aside-pct { font-size: 13px; color: var(--ink-mute); }
.aside-amount { font-family: var(--font-display); font-size: 22px; font-weight: 600; color: var(--warm); }

/* Goals */
.goal {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.goal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.goal-name { font-weight: 600; font-family: var(--font-display); font-size: 17px; }
.goal-amounts { font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.goal-bar { height: 8px; background: var(--warm-soft); border-radius: 999px; overflow: hidden; }
.goal-fill { height: 100%; background: var(--warm); border-radius: 999px; }
.goal-meta { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--ink-mute); }
.goal-meta button { font-size: 13px; color: var(--accent); font-weight: 600; padding: 4px 8px; border-radius: 8px; }
.goal-meta button:hover { background: var(--accent-soft); }

/* Transactions */
.tx-list { gap: 6px; }
.tx {
  background: var(--card); border-radius: var(--radius-sm); padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 1px 2px rgba(28,58,46,.04);
}
.tx-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tx-cat { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-note { font-size: 12px; color: var(--ink-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-right { display: flex; align-items: center; gap: 8px; }
.tx-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amount.pos { color: var(--accent); }
.tx-amount.neg { color: var(--ink); }
.tx-menu { color: var(--ink-mute); padding: 4px; border-radius: 8px; }
.tx-menu:hover { background: var(--bg); color: var(--ink); }

/* History */
.month-row {
  background: var(--card); border-radius: var(--radius-sm); padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center;
  box-shadow: 0 1px 2px rgba(28,58,46,.04);
}
.month-row strong { font-family: var(--font-display); font-weight: 600; }
.month-row .pos { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.month-row .neg { color: var(--alert); font-weight: 600; font-variant-numeric: tabular-nums; }

.closing { padding-top: 4px; }

.quick-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.primary-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 16px 18px;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 6px 16px -8px rgba(46,107,79,.5);
}
.primary-btn:active { transform: scale(.98); }
.primary-btn.warm { background: var(--warm); box-shadow: 0 6px 16px -8px rgba(181,118,42,.5); }
.primary-btn.danger { background: var(--alert); box-shadow: 0 6px 16px -8px rgba(194,96,63,.5); }
.empty {
  text-align: center; color: var(--ink-mute); font-size: 14px; padding: 24px 12px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + var(--safe-bot));
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 16px 22px;
  display: flex; align-items: center; gap: 8px;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 10px 24px -6px rgba(46,107,79,.5), 0 2px 6px rgba(28,58,46,.15);
  z-index: 9;
  transition: transform .15s ease;
}
.fab:active { transform: scale(0.96); }
.fab-label { line-height: 1; }

/* Sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(28,58,46,.35);
  z-index: 100; animation: fadein .2s;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 8px 16px calc(24px + var(--safe-bot));
  z-index: 101;
  max-height: 92vh;
  display: flex; flex-direction: column;
  animation: slideup .25s cubic-bezier(.2,.7,.2,1);
  box-shadow: 0 -8px 30px rgba(28,58,46,.18);
}
.sheet-handle {
  width: 40px; height: 4px; border-radius: 4px; background: var(--line);
  margin: 6px auto 8px;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 4px 12px;
}
.sheet-head h3 { font-size: 20px; margin: 0; }
.sheet-body {
  overflow-y: auto;
  padding: 4px 4px 8px;
}
.sheet .form-actions { display: flex; gap: 10px; padding-top: 8px; }
.sheet .form-actions .primary {
  flex: 1; background: var(--accent); color: #fff;
  border-radius: 999px; padding: 14px; font-weight: 700; font-size: 16px;
}
.sheet .form-actions .primary:active { transform: scale(.98); }
.sheet .form-actions .secondary {
  flex: 0 0 auto; background: transparent; color: var(--ink); padding: 14px 18px; border-radius: 999px; border: 1px solid var(--line);
}
.sheet .form-actions .secondary.danger { color: var(--alert); border-color: var(--alert-soft); }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-bot)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 200;
  animation: fadein .2s;
}

@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideup { from { transform: translateY(100%) } to { transform: translateY(0) } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Settings list */
.settings-section { margin-bottom: 18px; }
.settings-section h4 {
  font-family: var(--font-display); font-size: 15px; font-weight: 600;
  margin: 0 0 8px; color: var(--ink-soft);
}
.row-btn {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-radius: var(--radius-sm); padding: 14px;
  width: 100%; text-align: left; font-size: 15px; font-weight: 500;
  box-shadow: 0 1px 2px rgba(28,58,46,.04);
}
.row-btn + .row-btn { margin-top: 6px; }
.row-btn .arrow { color: var(--ink-mute); }
.row-btn.danger { color: var(--alert); }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line);
  font-size: 14px; font-weight: 500;
}
.chip[aria-pressed="true"] {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

.list-editor { display: flex; flex-direction: column; gap: 8px; }
.list-editor .item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: var(--radius-sm); padding: 10px 12px;
}
.list-editor .item .dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 14px; }
.list-editor .item .name { flex: 1; font-weight: 500; }
.list-editor .item .amount { color: var(--ink-soft); font-size: 14px; }
.list-editor .item button { color: var(--ink-mute); padding: 4px 8px; border-radius: 8px; font-size: 13px; }
.list-editor .item button:hover { background: var(--bg); color: var(--ink); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
