* { box-sizing: border-box; }
html, body { margin: 0; }

#root[data-theme="dark"],
#root {
  --bg: #0e1013; --panel: #16191e; --panel2: #191d23; --border: #262b31; --line: #23272e;
  --ink: #eceef1; --muted: #8a919b; --faint: #7a828d; --dim: #5c636d;
  --bar-track: #23272e; --input: #0e1013;
  --acc-ink: #0e1013;
  --chip: rgba(255,255,255,.05); --chip-border: #2a333a;
  --hero-a: #171b21; --hero-border: #223026aa;
  --overlay: rgba(4,6,8,.66); --header-bg: rgba(14,16,19,.72);
  --remove-bg: #2a1f1f; --remove-ink: #f0846a;
  --elev: 0 1px 0 rgba(255,255,255,.03) inset, 0 14px 34px -22px rgba(0,0,0,.75);
  --elev-hover: 0 1px 0 rgba(255,255,255,.05) inset, 0 20px 46px -20px rgba(0,0,0,.85);
  --rad: 20px;
}

#root[data-theme="light"] {
  --bg: #faf9f6; --panel: #ffffff; --panel2: #ffffff; --border: #e9e6df; --line: #f0ede6;
  --ink: #23211c; --muted: #7a766c; --faint: #9a968c; --dim: #b8b3a8;
  --bar-track: #f0ede6; --input: #fbfaf7;
  --acc-ink: #12140f;
  --chip: #f7f5f0; --chip-border: #ece8e0;
  --hero-a: #ffffff; --hero-border: #ece8dfaa;
  --overlay: rgba(30,28,24,.42); --header-bg: rgba(250,249,246,.7);
  --remove-bg: #faeceb; --remove-ink: #c0553f;
  --elev: 0 1px 2px rgba(35,33,28,.04), 0 14px 34px -22px rgba(35,33,28,.26);
  --elev-hover: 0 2px 4px rgba(35,33,28,.05), 0 20px 44px -22px rgba(35,33,28,.32);
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #88888844; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

@keyframes pop { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.mono { font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }

#root {
  min-height: 100vh;
  overflow-x: hidden;
  background: radial-gradient(1100px 520px at 50% -260px, color-mix(in srgb, var(--acc) 7%, transparent), transparent), var(--bg);
  color: var(--ink);
  transition: background .25s ease, color .25s ease;
}

/* ---------- header ---------- */
header {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(16px) saturate(1.4);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1080px; margin: 0 auto; padding: 14px clamp(14px,4vw,20px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; row-gap: 10px;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-dot { width: 28px; height: 28px; border-radius: 50%; background: var(--acc); box-shadow: 0 0 16px var(--acc); }
.brand-name { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name b { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-name span { font-size: 11px; color: var(--faint); white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel); color: var(--muted); cursor: pointer; font: inherit; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--acc); color: var(--ink); }
.seg { display: flex; gap: 3px; background: var(--input); border: 1px solid var(--border); padding: 3px; border-radius: 999px; }
.seg button { border: none; background: transparent; color: var(--faint); border-radius: 999px; padding: 5px 11px; font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; }
.seg button.active { background: var(--acc); color: var(--acc-ink); font-weight: 600; }
.add-btn {
  display: inline-flex; align-items: center; gap: 6px; background: var(--acc); color: var(--acc-ink);
  border: none; border-radius: 999px; padding: 10px 17px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
}
.add-btn:hover { filter: brightness(1.08); }
.currency-wrap { position: relative; }
.currency-menu {
  position: absolute; top: 44px; right: 0; z-index: 40; background: var(--panel2); border: 1px solid #2a2f37aa;
  border-radius: 16px; padding: 10px; box-shadow: 0 14px 40px -12px rgba(0,0,0,.5); width: 220px; animation: pop .16s ease;
}
.currency-menu .title { font-weight: 600; font-size: 13px; padding: 4px 8px 2px; }
.currency-menu .note { font-size: 11.5px; line-height: 1.4; color: var(--faint); padding: 0 8px 10px; }
.currency-menu button { width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; border: none; border-radius: 10px; padding: 8px; font: inherit; font-size: 13px; cursor: pointer; background: transparent; color: var(--ink); }
.currency-menu button.active { background: var(--acc); color: var(--acc-ink); font-weight: 600; }
.currency-menu button .sym { width: 18px; display: inline-block; text-align: center; font-family: 'Noto Sans', system-ui, sans-serif; font-weight: 600; }

nav.tabs { max-width: 1080px; margin: 0 auto; padding: 0 clamp(14px,4vw,20px) 13px; display: flex; gap: 7px; flex-wrap: wrap; }
nav.tabs button { border: 1px solid var(--border); background: var(--panel); color: var(--muted); border-radius: 999px; padding: 8px 15px; font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
nav.tabs button.active { border-color: var(--acc); background: var(--acc); color: var(--acc-ink); font-weight: 600; }

/* ---------- main ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 22px clamp(14px,4vw,20px) 60px; display: flex; flex-direction: column; gap: 18px; }

.month-nav { display: flex; align-items: center; justify-content: center; gap: 16px; }
.month-nav .nav-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); background: var(--panel); color: var(--ink);
  cursor: pointer; font: inherit; font-size: 17px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.month-nav .nav-btn:disabled { opacity: .32; cursor: not-allowed; }
.month-label { text-align: center; min-width: 150px; }
.month-label .m { font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.month-label .delta { font-size: 12px; margin-top: 3px; font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--rad); box-shadow: var(--elev); padding: 18px; }

.hero {
  position: relative; overflow: hidden; border: 1px solid var(--hero-border); border-radius: 24px;
  padding: clamp(20px,5vw,26px) clamp(18px,5vw,24px);
  background: linear-gradient(135deg, var(--hero-a) 0%, color-mix(in srgb, var(--acc) 18%, var(--bg)) 100%);
  box-shadow: var(--elev);
}
.hero::before { content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; box-shadow: inset 0 1px 0 rgba(255,255,255,.06); }
.hero::after { content: ''; position: absolute; top: -40px; right: -30px; width: 180px; height: 180px; border-radius: 50%; background: var(--acc); opacity: .14; filter: blur(30px); }
.hero .label { font-size: 12px; color: color-mix(in srgb, var(--acc), var(--faint) 45%); text-transform: uppercase; letter-spacing: .1em; position: relative; }
.hero .total { font-size: clamp(36px,11vw,46px); font-weight: 600; letter-spacing: -.03em; margin: 8px 0 18px; font-variant-numeric: tabular-nums; position: relative; }
.hero .chips { display: flex; gap: 10px; flex-wrap: wrap; position: relative; }
.hero .chip { background: var(--chip); border: 1px solid var(--chip-border); border-radius: 14px; padding: 11px 15px; }
.hero .chip .l { font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.hero .chip .v { font-family: 'IBM Plex Mono', monospace; font-size: 18px; font-variant-numeric: tabular-nums; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px,1fr)); gap: 14px; }
.list-card .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.list-card .head .title { font-weight: 600; font-size: 15px; }
.list-card .head .meta { font-size: 12px; color: var(--faint); }
.row-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.avatar { width: 36px; height: 36px; border-radius: 11px; display: flex; align-items: center; justify-content: center; color: #12140f; font-size: 14px; font-weight: 700; flex-shrink: 0; }
.row-item .info { flex: 1; min-width: 0; }
.row-item .name { font-weight: 500; font-size: 14px; }
.row-item .sub { font-size: 12px; color: var(--faint); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.row-item .amt { text-align: right; }
.row-item .amt .v { font-family: 'IBM Plex Mono', monospace; font-size: 14px; font-variant-numeric: tabular-nums; }
.row-item .amt .d { font-size: 12px; color: var(--acc); font-weight: 500; }
.empty-note { padding: 22px 0; text-align: center; color: var(--dim); font-size: 13px; }
.empty-box { background: var(--panel); border: 1px dashed var(--border); border-radius: var(--rad); padding: 40px; text-align: center; color: var(--dim); font-size: 14px; }
.empty-box b { color: var(--ink); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head .title { font-weight: 600; font-size: 18px; letter-spacing: -.01em; }
.section-head .meta { font-size: 13px; color: var(--muted); font-family: 'IBM Plex Mono', monospace; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px,1fr)); gap: 14px; }
.item-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--rad); box-shadow: var(--elev);
  padding: 16px; display: flex; flex-direction: column; gap: 13px; cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.item-card:hover { border-color: color-mix(in srgb, var(--acc) 45%, var(--border)); box-shadow: var(--elev-hover); transform: translateY(-2px); }
.item-card .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.item-card .top .left { display: flex; align-items: center; gap: 11px; min-width: 0; }
.item-card .top .left .name { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.remove-btn { border: none; background: transparent; color: var(--dim); cursor: pointer; font-size: 12px; padding: 4px 6px; border-radius: 7px; }
.remove-btn:hover { background: var(--remove-bg); color: var(--remove-ink); }
.item-card .amount-row { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.item-card .amount-row .amt { font-family: 'IBM Plex Mono', monospace; font-size: 24px; font-weight: 500; font-variant-numeric: tabular-nums; }
.item-card .amount-row .cycle { font-size: 13px; color: var(--faint); }
.item-card .footline { font-size: 12px; color: var(--faint); border-top: 1px solid var(--line); padding-top: 11px; }
.item-card .footline b { color: var(--acc); font-weight: 500; }

.cat-card { display: flex; flex-direction: column; gap: 16px; padding: 20px; }
.cat-card .head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.cat-card .head .t1 { font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.cat-card .head .t2 { font-size: 12px; color: var(--faint); }
.cat-card .head .total { text-align: right; }
.cat-card .head .total .v { font-family: 'IBM Plex Mono', monospace; font-size: 17px; letter-spacing: -.01em; }
.cat-card .head .total .l { font-size: 11px; color: var(--faint); }
.cat-bars { display: flex; flex-direction: column; gap: 16px; }
.cat-row { display: flex; flex-direction: column; gap: 8px; }
.cat-row .line1 { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.cat-row .line1 .left { display: flex; align-items: center; gap: 9px; min-width: 0; }
.cat-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-row .name.top { font-weight: 600; }
.cat-row .share { flex-shrink: 0; font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--faint); }
.cat-row .amt { flex-shrink: 0; font-family: 'IBM Plex Mono', monospace; color: var(--muted); }
.cat-row .amt.top { color: var(--ink); font-weight: 600; }
.cat-track { height: 10px; background: var(--bar-track); border-radius: 999px; overflow: hidden; }
.cat-fill { height: 100%; border-radius: 999px; }

footer { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 6px; border-top: 1px solid var(--line); }
footer .priv { font-size: 12px; color: var(--dim); display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; text-align: center; }
footer .priv .d { display: flex; align-items: center; gap: 7px; }
footer .priv .d span:first-child { width: 6px; height: 6px; border-radius: 50%; background: var(--acc); }
footer .foot-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
footer .copyright { font-size: 11px; color: var(--dim); }
.pill-btn { border: 1px solid var(--border); background: var(--panel); color: var(--muted); border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 13px; cursor: pointer; }
.pill-btn:hover { border-color: var(--acc); }
.pill-btn.danger { border-color: #3a2a2a; background: var(--panel); color: #e08a76; }

/* ---------- modals ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; background: var(--overlay); display: flex; align-items: center; justify-content: center; padding: 18px; animation: overlayIn .15s ease; }
.overlay.faq, .overlay.onboard { z-index: 80; backdrop-filter: blur(4px); }
/* Suppresses the entrance animation on step/toggle re-renders of an
   already-open modal (see renderModals' freshOpen), so only the initial
   open animates instead of replaying on every internal click. */
.overlay.no-anim, .modal.no-anim, .faq-modal.no-anim, .ob-modal.no-anim { animation: none; }
.modal { background: var(--panel2); border: 1px solid #2a2f37aa; width: 100%; max-width: 460px; border-radius: 20px; padding: 24px; animation: pop .22s cubic-bezier(.2,.8,.2,1); max-height: 92vh; overflow: auto; }
.modal-title { font-weight: 600; font-size: 18px; margin-bottom: 16px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field .lbl { font-size: 12px; color: var(--muted); font-weight: 500; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; border: 1px solid #2a2f37aa; border-radius: 11px; padding: 11px 13px; font: inherit; font-size: 15px;
  background: var(--input); color: var(--ink);
}
.form-field textarea { resize: vertical; min-height: 80px; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { border-color: var(--acc); outline: none; }
.feedback-status { font-size: 13px; line-height: 1.5; padding: 10px 12px; border-radius: 10px; }
.feedback-status.error { background: var(--remove-bg); color: var(--remove-ink); }
.form-row { display: flex; gap: 12px; }
.form-row .form-field { flex: 1; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn-cancel { flex: 1; border: 1px solid #2a2f37aa; background: transparent; color: var(--muted); border-radius: 12px; padding: 12px; font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; }
.btn-cancel:hover { background: var(--input); }
.btn-save { flex: 1; border: none; border-radius: 12px; padding: 12px; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; background: var(--acc); color: var(--acc-ink); }
.btn-save[disabled] { color: var(--dim); background: var(--bar-track); cursor: not-allowed; }
.btn-danger { flex: 1; border: none; border-radius: 12px; padding: 12px; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; background: var(--remove-ink); color: #1a0f0c; }
.btn-danger:hover { filter: brightness(1.06); }
.confirm-body { font-size: 14px; line-height: 1.55; color: var(--muted); margin: 0 0 18px; }
.kind-toggle { display: flex; gap: 6px; background: var(--input); padding: 4px; border-radius: 12px; margin-bottom: 18px; }
.kind-toggle button, .cycle-toggle button { flex: 1; border: none; border-radius: 9px; padding: 9px; font: inherit; font-size: 14px; cursor: pointer; background: transparent; color: var(--muted); }
.kind-toggle button.active, .cycle-toggle button.active { font-weight: 600; background: var(--acc); color: var(--acc-ink); }
.cycle-toggle { display: flex; gap: 6px; background: var(--input); padding: 4px; border-radius: 11px; }

/* faq */
.faq-modal { position: relative; display: flex; flex-direction: column; background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid #2a2f37aa; width: 100%; max-width: 460px; max-height: min(86vh,720px); border-radius: 24px; box-shadow: 0 30px 70px -30px rgba(0,0,0,.8); animation: pop .24s cubic-bezier(.2,.8,.2,1); overflow: hidden; }
.faq-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 22px 24px 16px; border-bottom: 1px solid var(--line); }
.faq-head .kicker { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--acc); display: block; }
.faq-head .title { font-weight: 600; font-size: 20px; letter-spacing: -.02em; }
.faq-close { flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%; border: 1px solid #333a42aa; background: transparent; color: var(--muted); font: inherit; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.faq-body { overflow-x: hidden; overflow-y: auto; padding: 8px 24px 22px; display: flex; flex-direction: column; }
.faq-item { border-bottom: 1px solid var(--line); }
.faq-q { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 14px; background: transparent; border: none; font: inherit; text-align: left; cursor: pointer; padding: 16px 0; color: var(--ink); }
.faq-q .qt { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.faq-q .plus { flex-shrink: 0; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; font-size: 19px; color: var(--acc); transition: transform .2s ease; }
.faq-item.open .plus { transform: rotate(45deg); }
.faq-a-wrap { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .22s ease; overflow: hidden; }
.faq-item.open .faq-a-wrap { grid-template-rows: 1fr; }
.faq-a-wrap .inner { min-height: 0; overflow: hidden; }
.faq-a { font-size: 14px; line-height: 1.6; color: var(--muted); padding: 0 0 16px; }

/* onboarding */
.ob-modal { position: relative; overflow: hidden; background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid #2a2f37aa; width: 100%; max-width: 420px; border-radius: 24px; padding: 26px 24px 22px; box-shadow: 0 30px 70px -30px rgba(0,0,0,.8); animation: pop .24s cubic-bezier(.2,.8,.2,1); }
.ob-modal .glow { position: absolute; top: -70px; right: -50px; width: 220px; height: 220px; border-radius: 50%; background: var(--acc); opacity: .1; filter: blur(50px); pointer-events: none; }
.ob-head { position: relative; display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.ob-head .counter { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.ob-skip { border: none; background: transparent; color: var(--faint); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.ob-skip:hover { color: var(--ink); }
.ob-body { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 20px; }
.ob-stage { position: relative; width: 100%; height: 186px; border-radius: 18px; background: radial-gradient(120% 120% at 50% -20%, color-mix(in srgb, var(--acc) 12%, transparent), transparent 60%), var(--input); border: 1px solid #2a2f37aa; overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 22px; }
.ob-text { display: flex; flex-direction: column; gap: 6px; }
.ob-kicker { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--acc); }
.ob-title { font-weight: 600; font-size: 22px; letter-spacing: -.02em; }
.ob-copy { font-size: 14.5px; line-height: 1.6; color: var(--muted); }
.ob-dots { position: relative; display: flex; align-items: center; justify-content: center; gap: 7px; margin: 22px 0; }
.ob-dots button { height: 7px; border-radius: 99px; border: none; cursor: pointer; padding: 0; transition: width .2s ease, background .2s ease; background: var(--border); }
.ob-dots button.active { background: var(--acc); }
.ob-actions { position: relative; display: flex; align-items: center; gap: 10px; }
.ob-actions .ghost { flex: 0 0 auto; border: 1px solid var(--border); background: transparent; color: var(--muted); border-radius: 13px; padding: 13px 18px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.ob-actions .ghost:hover { border-color: var(--dim); }
.ob-actions .primary { flex: 1; border: none; background: var(--acc); color: var(--acc-ink); border-radius: 13px; padding: 13px; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; }
.ob-actions .primary:hover { filter: brightness(1.08); }

@media (max-width: 480px) {
  .modal { padding: 20px; }
}
