:root {
  --bg: #eadfcf;
  --paper: #fbf6ec;
  --ink: #1c1610;
  --muted: #7c7164;
  --line: #e2d4bf;
  --gold: #b0894a;
  --in: #1f6b4a;
  --out: #a33b2c;
  --accent: #241c16;
  --chip: #f0e6d4;
  --shadow: 0 14px 36px rgba(36, 28, 22, 0.08);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(720px 380px at 110% -8%, rgba(176, 137, 74, 0.18), transparent 55%),
    radial-gradient(520px 280px at -10% 110%, rgba(31, 107, 74, 0.08), transparent 50%),
    repeating-linear-gradient(
      180deg,
      transparent 0 31px,
      rgba(176, 137, 74, 0.06) 31px 32px
    ),
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, .serif {
  font-family: Fraunces, "Iowan Old Style", Palatino, serif;
  font-weight: 640;
  font-optical-sizing: auto;
  letter-spacing: -0.03em;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:active { transform: translateY(1px); }
.tabbar button:active, .tab:active { transform: none; }

.app-shell {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) 16px calc(92px + var(--safe-bottom));
}

.demo-ribbon {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  color: var(--gold);
  font-weight: 700;
  margin: 0 0 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  position: sticky;
  top: var(--safe-top);
  z-index: 2;
  padding: 8px 0 6px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
}
.brand::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--gold);
  border-radius: 50%;
  box-shadow: inset 0 0 0 3px var(--bg);
}

.top-actions { display: flex; gap: 8px; }

.icon-btn, .primary, .ghost, .danger {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
}

.icon-btn {
  width: 44px;
  padding: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 18px;
}

.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.primary {
  background: var(--accent);
  color: #f7f1e6;
}

.danger { background: #f8e8e4; color: var(--out); }
.primary:disabled, .ghost:disabled { opacity: 0.5; }

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 10px;
}

.month-title { text-align: center; min-width: 0; }
.month-title h1 {
  margin: 0;
  font-size: clamp(34px, 9vw, 46px);
  line-height: 0.95;
}
.month-title .year {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 600;
}

.rule {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 0 0 16px;
}

.hero {
  background: var(--paper);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 22px 20px 18px;
  margin-bottom: 14px;
  border: 1px solid rgba(176, 137, 74, 0.18);
}

.hero .label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.hero .net {
  font-size: clamp(38px, 11vw, 52px);
  line-height: 0.95;
  margin: 8px 0 14px;
  font-variant-numeric: tabular-nums;
}
.net.pos { color: var(--in); }
.net.neg { color: var(--out); }

.meter-wrap { margin: 0 0 16px; }
.meter {
  height: 10px;
  background: #efe4d0;
  border-radius: 99px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  background: linear-gradient(90deg, #2d6a4f, #b0894a);
  border-radius: 99px;
  min-width: 4px;
}
.meter-fill.over { background: var(--in); }
.meter-fill.under { background: linear-gradient(90deg, #a33b2c, #b0894a); }
.meter-cap {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

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

.kpi {
  background: var(--chip);
  border-radius: 16px;
  padding: 12px 14px;
}
button.kpi {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid transparent;
  font: inherit;
  color: inherit;
  text-align: left;
  width: 100%;
}
button.kpi:disabled { opacity: 0.55; }
.kpi .k { font-size: 11px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.kpi .v { font-size: 20px; margin-top: 4px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi.out .v { color: var(--out); }
.kpi.in .v { color: var(--in); }

.delta {
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--accent);
  color: #f7f1e6;
  border-radius: 20px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.banner p { margin: 0; font-size: 14px; line-height: 1.35; }
.banner .primary { background: #f7f1e6; color: var(--ink); flex-shrink: 0; }

.card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(176, 137, 74, 0.12);
}

.card h2 { margin: 0 0 8px; font-size: 22px; }
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.card-head h2 { margin: 0; }
.card-head .muted { color: var(--muted); font-size: 13px; }
button.card-head {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
}
button.card-head:disabled { opacity: 0.5; }

.cat-hit {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  padding: 0 0 2px;
  margin: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  border-radius: 12px;
}
button.ledger-row.cat-hit {
  display: flex;
  padding: 0;
}

.ledger-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 11px 0 4px;
  font-size: 15px;
}
.ledger-row .name {
  max-width: 52%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ledger-row .dots {
  flex: 1;
  border-bottom: 1px dotted #c9b89a;
  transform: translateY(-4px);
}
.ledger-row .amt {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}
.ledger-row .share {
  color: var(--muted);
  font-size: 12px;
  min-width: 2.4em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.track {
  height: 4px;
  background: #efe4d0;
  border-radius: 99px;
  overflow: hidden;
  margin: 0 0 10px;
}
.fill { height: 100%; background: var(--ink); border-radius: 99px; }
.fill.out { background: var(--out); }
.fill.in { background: var(--in); }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 22px 12px;
}

.drop {
  position: relative;
  display: grid;
  place-items: center;
  border: 1.5px dashed #cbb496;
  border-radius: 20px;
  padding: 26px 16px 18px;
  text-align: center;
  background:
    radial-gradient(180px 80px at 50% 0%, rgba(176, 137, 74, 0.12), transparent 70%),
    rgba(255, 250, 243, 0.55);
}
.drop.drag { background: #fff; border-color: var(--ink); }
.drop strong { display: block; font-size: 17px; }
.drop p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.drop::before {
  content: "+";
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin: 0 auto 10px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  color: var(--gold);
  font-size: 22px;
  line-height: 1;
  pointer-events: none;
}
.pick-file {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 14px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.file-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
  border: 1px solid var(--line);
  background: var(--chip);
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 40px;
}
.chip.on { background: var(--ink); color: #f7f1e6; border-color: var(--ink); }

.mode-row { display: flex; gap: 8px; margin: 12px 0; }
.mode-row button {
  flex: 1;
  font-size: 13px;
  padding: 10px 8px;
  line-height: 1.2;
}

textarea, .text-input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
}

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--paper);
  border-radius: 28px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(176, 137, 74, 0.2);
}
.login-card h1 { margin: 0 0 8px; font-size: 34px; }
.login-card p { color: var(--muted); margin: 0 0 18px; }
.login-card .primary { width: 100%; margin-top: 12px; }

.error { color: var(--out); font-size: 14px; margin-top: 8px; }
.ok {
  color: var(--in);
  font-size: 14px;
  background: rgba(31, 107, 74, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
}
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; line-height: 1.45; }

.goal-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.goal-row .text-input { flex: 1; }
.recs { margin: 8px 0 0; padding-left: 18px; }
.recs li { margin: 8px 0; line-height: 1.45; color: var(--muted); }

.hero .desc { margin: 0; font-size: 17px; font-weight: 600; }
.hero .sub { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.spike-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--out);
}

.progress-dots {
  display: flex;
  gap: 6px;
  margin: 0 0 12px;
}
.progress-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
}
.progress-dots span.on { background: var(--gold); }

.queue-title {
  margin: 4px 0 8px;
  font-size: 32px;
  line-height: 1;
}
.queue-actions {
  display: grid;
  gap: 8px;
  margin: 8px 0 12px;
}
.queue-actions .hint { margin: 0; }
button.income-all {
  width: 100%;
  background: var(--in);
  border-color: var(--in);
  color: #f4faf6;
}
.tx-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 12px 0;
  min-height: 52px;
  font: inherit;
  color: inherit;
}
.tx-row:last-child { border-bottom: 0; }
button.tx-row { cursor: pointer; }
.tx-desc { font-size: 14px; line-height: 1.35; }
.tx-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.tx-amt { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-amt.neg { color: var(--out); }
.tx-amt.pos { color: var(--in); }
.unlabeled-card { border-color: rgba(163, 59, 44, 0.22); }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: linear-gradient(180deg, transparent, var(--bg) 30%);
  z-index: 40;
  pointer-events: auto;
  isolation: isolate;
}
.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-weight: 600;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto;
  position: relative;
  z-index: 1;
}
.tab.on { background: var(--accent); color: #f7f1e6; border-color: var(--accent); }
.tab.hot:not(.on) {
  border-color: var(--out);
  color: var(--out);
  box-shadow: 0 0 0 1px rgba(163, 59, 44, 0.25);
}
.tab-badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--out);
  color: #fff;
  font-size: 12px;
  animation: pulse-hot 1.6s ease-in-out infinite;
}
.tab.on .tab-badge { background: #f7f1e6; color: var(--out); }
@keyframes pulse-hot {
  50% { transform: scale(1.08); opacity: 0.85; }
}

.reconcile {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.35;
}
.reconcile-title { font-weight: 700; margin-bottom: 2px; }
.reconcile.ok { background: rgba(31, 107, 74, 0.1); color: var(--in); }
.reconcile.bad { background: rgba(163, 59, 44, 0.1); color: var(--out); }

@media (max-width: 520px) {
  .banner { flex-direction: column; align-items: stretch; }
  .banner .primary { width: 100%; }
  .mode-row { flex-direction: column; }
  .ledger-row .name { max-width: 48%; }
}
