:root {
  --bg: #0B0F17;
  --bg-elevated: #121826;
  --card: #161D2B;
  --card-alt: #1B2435;
  --border: #232C3D;
  --border-strong: #2E3A50;
  --text: #F4F7FB;
  --muted: #9AA7BD;
  --faint: #5E6B82;
  --positive: #34D399;
  --positive-dim: #1E3A33;
  --negative: #F87171;
  --negative-dim: #3A1F25;
  --accent: #5B8DEF;
  --accent-dim: #1C2A45;
  --violet: #A78BFA;
  --violet-dim: #241F3D;
  --amber: #FBBF24;
  --amber-dim: #3A3219;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; overflow-x: hidden; width: 100%; max-width: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: pan-y;
  position: relative;
}

#app { min-height: 100vh; overflow-x: hidden; }

/* Screen layout */
.screen {
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(96px + env(safe-area-inset-bottom)) 16px;
  max-width: 560px;
  margin: 0 auto;
}
.screen-header { margin: 8px 0 14px; }
.screen-title { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; margin: 0; }
.screen-sub { color: var(--muted); font-size: 15px; margin-top: 2px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.card + .card, .card + .section, .section + .card { margin-top: 12px; }

/* Hero */
.hero { text-align: center; padding: 24px 16px; }
.hero-label { color: var(--muted); font-size: 15px; font-weight: 600; }
.hero-amount { font-size: 46px; font-weight: 800; letter-spacing: -1px; margin: 6px 0 2px; }
.hero-sub { color: var(--faint); font-size: 13px; }
.hero-badge { color: var(--negative); font-size: 13px; font-weight: 600; margin-top: 4px; }

/* Progress */
.progress { height: 8px; background: var(--card-alt); border-radius: 8px; overflow: hidden; margin-top: 12px; }
.progress > div { height: 100%; border-radius: 8px; transition: width 0.3s; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: var(--radius-md); padding: 14px 18px;
  font-size: 17px; font-weight: 700; cursor: pointer; font-family: inherit;
  width: 100%;
}
.btn:active { opacity: 0.8; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-positive { background: var(--positive); color: #06291F; }
.btn-negative { background: var(--negative); color: #2A0F12; }
.btn-violet { background: var(--violet); color: #1B1430; }
.btn-subtle { background: var(--card-alt); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border-strong); }
.btn-small { padding: 9px 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-row { display: flex; gap: 12px; margin-top: 16px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* Stat tiles */
.stats { display: flex; gap: 8px; margin-top: 12px; }
.stat {
  flex: 1; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px; min-width: 0;
}
.stat-label { color: var(--muted); font-size: 11px; font-weight: 600; margin-bottom: 6px; }
.stat-value { font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub { color: var(--faint); font-size: 11px; margin-top: 2px; }

/* Section header */
.section-header { display: flex; align-items: center; justify-content: space-between; margin: 24px 0 12px; }
.section-title { font-size: 21px; font-weight: 700; }
.section-action { color: var(--accent); font-size: 15px; font-weight: 600; cursor: pointer; background: none; border: none; font-family: inherit; }

/* Transaction / list rows */
.tx-row { display: flex; align-items: center; gap: 12px; padding: 12px 8px; border-bottom: 1px solid var(--border); cursor: pointer; }
.tx-row:last-child { border-bottom: none; }
.tx-icon { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.tx-main { flex: 1; min-width: 0; }
.tx-note { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-date { color: var(--faint); font-size: 13px; }
.tx-amount { font-size: 17px; font-weight: 700; white-space: nowrap; }

/* Pills */
.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }

/* Empty state */
.empty { text-align: center; padding: 24px 8px; color: var(--muted); }
.empty .ico { font-size: 30px; opacity: 0.5; }
.empty .t { font-weight: 600; margin-top: 6px; }
.empty .s { color: var(--faint); font-size: 13px; margin-top: 2px; }

/* Plan / debt cards */
.amount-line { display: flex; align-items: baseline; gap: 6px; margin: 10px 0; }
.big-num { font-size: 28px; font-weight: 800; }
.line-label { color: var(--muted); font-size: 13px; }
.card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-title { font-size: 17px; font-weight: 700; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-bottom { display: flex; justify-content: space-between; margin-top: 10px; }
.card-meta { color: var(--muted); font-size: 13px; }
.menu-btn { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px; line-height: 1; }

/* Summary tiles (debts) */
.summary { display: flex; gap: 8px; }
.sum-tile { flex: 1; background: var(--card); border: 1px solid; border-radius: var(--radius-md); padding: 16px; text-align: center; }
.sum-label { color: var(--muted); font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.sum-value { font-size: 26px; font-weight: 800; }

/* Settings rows */
.rows { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 15px; border-bottom: 1px solid var(--border); cursor: pointer; }
.row:last-child { border-bottom: none; }
.row .ico { width: 22px; text-align: center; color: var(--muted); }
.row .label { flex: 1; font-size: 15px; font-weight: 600; }
.row .val { color: var(--muted); font-size: 15px; }
.row.danger .label, .row.danger .ico { color: var(--negative); }
.group-label { color: var(--faint); font-size: 11px; font-weight: 700; letter-spacing: 1px; margin: 24px 4px 8px; }
.foot-note { color: var(--faint); font-size: 13px; text-align: center; margin-top: 24px; line-height: 1.5; }

/* Bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 50;
}
.tab { flex: 1; background: none; border: none; color: var(--faint); cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 2px; }
.tab .ti { font-size: 22px; line-height: 1; }
.tab .lb { font-size: 11px; font-weight: 600; }
.tab.active { color: var(--accent); }
.empty .ico { display: flex; justify-content: center; }
.row .ico { display: flex; align-items: center; justify-content: center; }

/* Modal / sheet */
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 100;
  display: flex; align-items: flex-end; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  background: var(--bg-elevated); width: 100%; max-width: 560px; margin: 0 auto;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; border: 1px solid var(--border);
  max-height: 100%; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.25s;
  padding-bottom: env(safe-area-inset-bottom);
}
.backdrop.open .sheet { transform: translateY(0); }
.sheet-handle { width: 38px; height: 5px; border-radius: 3px; background: var(--border-strong); margin: 8px auto 4px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.sheet-head .t { font-size: 17px; font-weight: 700; flex: 1; text-align: center; }
.sheet-head button { background: none; border: none; font-family: inherit; font-size: 15px; cursor: pointer; min-width: 60px; }
.sheet-cancel { color: var(--muted); text-align: left; }
.sheet-save { color: var(--accent); font-weight: 700; text-align: right; }
.sheet-save[disabled] { opacity: 0.4; }
.sheet-body { padding: 16px; overflow-y: auto; }

/* Form fields */
.field { margin-bottom: 16px; }
.field-label { color: var(--muted); font-size: 13px; font-weight: 600; margin-bottom: 8px; display: block; }
.field-hint { color: var(--faint); font-size: 13px; margin-top: 6px; }
input, select {
  width: 100%; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 14px 16px; color: var(--text);
  font-size: 17px; font-family: inherit; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.amount-field { display: flex; align-items: center; justify-content: center; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; }
.amount-field input { background: none; border: none; text-align: center; font-size: 40px; font-weight: 800; padding: 0; width: auto; max-width: 70%; }
.amount-field .cur { font-size: 32px; font-weight: 700; margin-left: 4px; }

.segmented { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 4px; }
.segmented button { flex: 1; padding: 11px; border: none; border-radius: var(--radius-sm); background: none; color: var(--muted); font-size: 15px; font-weight: 700; font-family: inherit; cursor: pointer; }
.segmented button.active { color: #fff; }

.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; }
.choice.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.time-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.time-row input { flex: 1; }
.time-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--card-alt); padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; margin: 0 6px 6px 0; }
.del-btn { background: none; border: none; color: var(--negative); font-size: 20px; cursor: pointer; padding: 6px; }

.switch { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { display: none; }
.switch .slider { position: absolute; inset: 0; background: var(--card-alt); border-radius: 999px; transition: 0.2s; }
.switch .slider::before { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: 0.2s; }
.switch input:checked + .slider { background: var(--violet); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* Onboarding */
.onb { padding: calc(env(safe-area-inset-top) + 40px) 24px 24px; max-width: 480px; margin: 0 auto; }
.onb-logo { width: 60px; height: 60px; border-radius: var(--radius-lg); background: var(--positive-dim); display: flex; align-items: center; justify-content: center; font-size: 30px; margin-bottom: 16px; }
.onb h1 { font-size: 38px; font-weight: 800; margin: 0 0 8px; }
.onb .lead { color: var(--muted); font-size: 17px; line-height: 1.5; }

.toast { position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--card-alt); color: var(--text); padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 200; opacity: 0; transition: opacity 0.2s; border: 1px solid var(--border); }
.toast.show { opacity: 1; }

/* Categories */
.cat-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; flex-shrink: 0; }
.cat-row { display: flex; align-items: center; gap: 8px; padding: 13px 4px; border-bottom: 1px solid var(--border); }
.cat-row:last-child { border-bottom: none; }
.icon-act { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 6px; }
.color-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.color-swatch { width: 36px; height: 36px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; transition: transform 0.1s; }
.color-swatch.active { border-color: var(--text); transform: scale(1.08); }

/* Wow: animated hero ring */
.hero { position: relative; padding: 16px; }
.hero-ring-wrap { position: relative; width: 224px; height: 224px; margin: 4px auto; }
.hero-ring { width: 100%; height: 100%; display: block; transform: rotate(-90deg); transform-origin: center; }
.ring-track { fill: none; stroke: var(--card-alt); stroke-width: 9; }
.ring-prog { fill: none; stroke-width: 9; stroke-linecap: round; transition: stroke-dashoffset 0.6s ease, stroke 0.4s; }
.hero-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 14px; }
.hero-center .hero-amount { font-size: 34px; font-weight: 800; letter-spacing: -1px; margin: 3px 0; white-space: nowrap; line-height: 1.05; }
.hero-center .hero-label { font-size: 12px; color: var(--muted); line-height: 1.25; }
.hero-center .hero-sub { font-size: 11px; color: var(--faint); margin-top: 1px; }
@keyframes breathe { 0%,100% { transform: rotate(-90deg) scale(1); } 50% { transform: rotate(-90deg) scale(1.025); } }
.hero-ring.breathe { animation: breathe 4.5s ease-in-out infinite; }
@keyframes heroShake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-7px)} 40%{transform:translateX(7px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }
.hero-neg .hero-ring-wrap { animation: heroShake 0.55s ease; }
@media (prefers-reduced-motion: reduce) { .hero-ring.breathe { animation: none; } .hero-neg .hero-ring-wrap { animation: none; } }
.streak-badge { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: var(--positive-dim); color: var(--positive); font-size: 11px; font-weight: 700; padding: 4px 11px; border-radius: 999px; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; z-index: 2; }

/* Wow: heatmap */
.heatmap { display: flex; gap: 3px; overflow-x: auto; padding-bottom: 2px; }
.hm-col { display: flex; flex-direction: column; gap: 3px; }
.hm-cell { width: 13px; height: 13px; border-radius: 3px; background: var(--card-alt); flex-shrink: 0; }
.hm-empty { background: transparent; }
.hm-1 { background: var(--positive); }
.hm-2 { background: var(--negative); }
.hm-legend { width: 11px; height: 11px; display: inline-block; vertical-align: -1px; }

/* Monthly calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--faint); font-weight: 600; padding-bottom: 2px; }
.cal-cell { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--card-alt); }
.cal-blank { background: transparent; }
.cal-empty { background: var(--card-alt); color: var(--faint); }
.cal-future { background: transparent; color: var(--faint); opacity: 0.4; }
.cal-under { background: rgba(52, 211, 153, 0.18); color: var(--positive); }
.cal-over { background: rgba(248, 113, 113, 0.18); color: var(--negative); }
.cal-today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-dot { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: -1px; }
.cal-nav { background: var(--card-alt); border: none; color: var(--text); cursor: pointer; width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-family: inherit; }
.cal-nav[disabled] { opacity: 0.3; pointer-events: none; }
