:root {
  --bg: #fff3e4;
  --bg-2: #ffe6c8;
  --card: #fffdf9;
  --text: #3b2414;
  --muted: #94705a;
  --line: #f1dcc4;
  --accent: #ff7a1a;
  --accent-2: #ffb03a;
  --accent-ink: #fff;
  --good: #2fb67c;
  --warn: #f2a516;
  --bad: #ef4f3a;
  --field: #fff4e6;
  --shadow: 0 10px 30px rgba(170, 90, 20, 0.12);
  --hd-bg: #fffdf9; --hd-text: #3b2414; --hd-muted: #94705a; --hd-field: #fff1e0; --hd-accent: #ff7a1a; --hd-accent-ink: #fff; --hd-shadow: rgba(255, 122, 26, 0.35);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d140d; --bg-2: #2a1c11; --card: #261a11; --text: #fbe9d6; --muted: #c09a7d; --line: #3d2a1b; --field: #312216;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --hd-bg: #261a11; --hd-text: #fbe9d6; --hd-muted: #c09a7d; --hd-field: #352418;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; color: var(--text);
  font: 15px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(900px 500px at 100% -10%, var(--bg-2), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, var(--bg-2), transparent 60%), var(--bg);
}
button { font: inherit; color: inherit; cursor: pointer; }
:is(.icon-btn, .del) svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top ---------- */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; max-width: 1180px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 20px 8px; }
.brand { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.brand span { display: grid; line-height: 1.2; }
.brand b { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.brand small { color: var(--muted); font-size: 13px; }
.top-right { display: flex; gap: 10px; align-items: center; }
.month { display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); }
.month b { min-width: 118px; text-align: center; font-size: 14px; font-weight: 700; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--field); color: var(--text); }
.account { display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 14px 0 5px; border: 0; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-weight: 700; font-size: 14px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 800; }

/* ---------- layout ---------- */
.layout { max-width: 1180px; margin: 0 auto; padding: 8px 20px 40px; display: grid; gap: 18px; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); grid-template-rows: auto 1fr; grid-template-areas: "hero panel" "add panel"; align-items: start; }
.hero { grid-area: hero; }
.add { grid-area: add; }
.panel { grid-area: panel; position: sticky; top: 12px; }
.card { background: var(--card); border-radius: 28px; box-shadow: var(--shadow); padding: 22px; border: 1px solid var(--line); }
h2 { margin: 0 0 14px; font-size: 18px; font-weight: 800; }

/* ---------- hero ---------- */
.hero { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; align-items: center; background: linear-gradient(160deg, #f8913f 0%, #ef7428 50%, #df5f22 100%); color: #fff; border: 0; overflow: hidden; position: relative; box-shadow: 0 18px 40px rgba(205, 90, 20, 0.22); }
.hero::after { content: ""; position: absolute; inset: 0; background: radial-gradient(420px 260px at 85% -20%, rgba(255, 255, 255, 0.16), transparent 70%), radial-gradient(300px 200px at 0% 120%, rgba(120, 30, 0, 0.18), transparent 70%); pointer-events: none; }
.wallet-wrap { position: relative; display: grid; justify-items: center; }
#wallet { width: 210px; height: 175px; overflow: visible; }
#wallet.hit { animation: shake 0.5s ease; }
#wallet.happy { animation: hop 0.6s ease; }
@keyframes shake { 20% { transform: translateX(-8px) rotate(-4deg); } 40% { transform: translateX(7px) rotate(3deg); } 60% { transform: translateX(-5px) rotate(-2deg); } 80% { transform: translateX(3px); } }
@keyframes hop { 40% { transform: translateY(-14px) scale(1.04); } }
.bubble {
  position: relative; margin-bottom: 10px; padding: 10px 14px; border-radius: 18px; background: #fff; color: var(--text);
  font-size: 13.5px; font-weight: 600; line-height: 1.35; text-align: center; box-shadow: 0 8px 20px rgba(120, 50, 0, 0.2); max-width: 220px;
}
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -8px; width: 16px; height: 16px; background: #fff; transform: translateX(-50%) rotate(45deg); border-radius: 3px; }
.bubble.pop { animation: bub 0.35s ease; }
@keyframes bub { from { transform: scale(0.85); opacity: 0.4; } }
.numbers { display: grid; gap: 14px; position: relative; z-index: 1; }
.big small, .mini small { opacity: 0.85; font-size: 13px; font-weight: 600; }
.big b { display: block; font-size: clamp(28px, 4vw, 38px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.budget-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; flex-wrap: wrap; }
.link { border: 0; background: none; padding: 0; color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; font-size: 13.5px; }
.bar { height: 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.3); overflow: hidden; margin: 6px 0 4px; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: #fff; transition: width 0.6s ease, background 0.3s; }
.bar i.warn { background: #ffe066; }
.bar i.bad { background: #ffd0c8; }
.budget small { opacity: 0.9; font-size: 12.5px; }
.mini { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mini div { background: rgba(255, 255, 255, 0.14); border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 16px; padding: 8px 12px; }
.mini b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- add form ---------- */
.type-toggle { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; background: var(--field); border-radius: 16px; margin-bottom: 12px; }
.type-toggle button { border: 0; background: none; padding: 10px; border-radius: 12px; font-weight: 700; color: var(--muted); }
.type-toggle button[aria-checked="true"] { background: var(--card); color: var(--text); box-shadow: 0 2px 8px rgba(120, 60, 0, 0.12); }
.type-toggle button[data-type="thu"][aria-checked="true"] { color: var(--good); }
.amount { display: block; position: relative; margin-bottom: 12px; }
.amount input { width: 100%; font: inherit; font-size: 26px; font-weight: 800; padding: 14px 16px; border-radius: 18px; border: 2px solid var(--line); background: var(--field); color: var(--text); outline: none; }
.amount input:focus, .row input:focus, .field input:focus { border-color: var(--accent); }
.amount-preview { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; font-size: 14px; pointer-events: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; border: 2px solid var(--line);
  background: var(--card); font-size: 14px; font-weight: 600;
}
.chip .e { font-size: 17px; line-height: 1; }
.chip[aria-checked="true"] { border-color: var(--accent); background: var(--field); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) 160px; gap: 8px; margin-bottom: 12px; }
.row input, .field input { font: inherit; padding: 11px 13px; border-radius: 14px; border: 2px solid var(--line); background: var(--field); color: var(--text); outline: none; min-width: 0; }
.btn { border: 0; border-radius: 999px; padding: 12px 20px; font-weight: 800; font-size: 15px; background: var(--field); color: var(--text); }
.btn.primary { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; box-shadow: 0 8px 20px rgba(255, 122, 26, 0.35); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.wide { width: 100%; }
.btn.small { padding: 7px 12px; font-size: 13px; font-weight: 700; }
.btn:disabled { opacity: 0.6; cursor: progress; }
:is(.btn, .chip, .icon-btn, .tabs button, .type-toggle button, .account):focus-visible { outline: 3px solid #3aa0ff; outline-offset: 2px; }

/* ---------- panel ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; padding: 4px; background: var(--field); border-radius: 16px; }
.tabs button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: 0 2px 8px rgba(120, 60, 0, 0.12); }
.day { margin-bottom: 14px; }
.day h3 { display: flex; justify-content: space-between; margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 700; }
.tx { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 8px 6px; border-radius: 14px; }
.tx:hover { background: var(--field); }
.tx .e { width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; font-size: 20px; background: var(--field); }
.tx b { display: block; font-size: 14.5px; }
.tx small { color: var(--muted); font-size: 12.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-weight: 800; white-space: nowrap; }
.tx .amt.thu { color: var(--good); }
.del { border: 0; background: none; color: var(--muted); width: 28px; height: 28px; border-radius: 8px; opacity: 0; }
.tx:hover .del, .del:focus-visible { opacity: 1; }
.del:hover { color: var(--bad); background: var(--card); }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.empty b { display: block; font-size: 32px; margin-bottom: 6px; }

.insights { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 8px; }
.insights li { display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px; border-radius: 16px; background: var(--field); font-size: 14px; }
.insights .e { font-size: 20px; line-height: 1.2; }
.cat-bars { display: grid; gap: 10px; margin-bottom: 18px; }
.cat-row { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; align-items: center; }
.cat-row .e { font-size: 20px; }
.cat-row .lbl { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 600; margin-bottom: 4px; gap: 8px; }
.cat-row .lbl small { color: var(--muted); font-weight: 600; }
.cat-row .track { height: 10px; border-radius: 999px; background: var(--field); overflow: hidden; }
.cat-row .track i { display: block; height: 100%; border-radius: inherit; }
.chart { width: 100%; height: 140px; display: block; }
.chart rect { transition: height 0.3s; }
.sub { font-size: 14px; font-weight: 800; margin: 4px 0 10px; }

.goals { display: grid; gap: 12px; }
.goal { padding: 14px; border-radius: 20px; background: var(--field); display: grid; gap: 10px; }
.goal-head { display: flex; gap: 12px; align-items: center; }
.goal-head .e { font-size: 28px; width: 46px; height: 46px; display: grid; place-items: center; background: var(--card); border-radius: 16px; }
.goal-head b { display: block; }
.goal-head small { color: var(--muted); }
.goal .bar { background: var(--card); height: 10px; margin: 0; }
.goal .bar i { background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.goal.done .bar i { background: var(--good); }
.goal-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.goal-actions .btn { background: var(--card); }
.goal-actions .rm { margin-left: auto; color: var(--muted); }

/* ---------- welcome ---------- */
.welcome { max-width: 560px; margin: 4vh auto 40px; padding: 0 20px; text-align: center; display: grid; justify-items: center; gap: 12px; }
.welcome svg { width: 260px; height: 216px; overflow: visible; }
.welcome h1 { margin: 0; font-size: clamp(28px, 6vw, 40px); font-weight: 800; letter-spacing: -0.02em; }
.welcome p { margin: 0; color: var(--muted); font-size: 16px; }
.welcome small { color: var(--muted); }

/* ---------- sheet + toast ---------- */
.sheet { width: min(420px, calc(100vw - 24px)); border: 0; border-radius: 26px; padding: 0; background: var(--card); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3); }
.sheet::backdrop { background: rgba(40, 20, 5, 0.4); }
.sheet form { padding: 22px; display: grid; gap: 12px; }
.sheet header { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { margin: 0; }
.x { border: 0; background: none; font-size: 26px; color: var(--muted); }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.err { margin: 0; color: var(--bad); font-weight: 600; }
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 150%); visibility: hidden;
  padding: 12px 18px; border-radius: 16px; background: var(--text); color: var(--bg); font-weight: 700; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  transition: transform 0.3s ease, visibility 0.3s; z-index: 30; max-width: calc(100vw - 32px);
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.toast.err { background: var(--bad); color: #fff; }

/* Two columns but a narrow left one: stack the wallet above the numbers. */
@media (min-width: 921px) and (max-width: 1180px) {
  .hero { grid-template-columns: minmax(0, 1fr); text-align: center; }
  .budget-row { justify-content: center; gap: 14px; }
  #wallet { width: 190px; height: 158px; }
}
@media (max-width: 920px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "hero" "add" "panel"; }
  .panel { position: static; }
}
@media (max-width: 560px) {
  .top { padding: max(12px, env(safe-area-inset-top)) 14px 6px; }
  .brand small { display: none; }
  .brand b { font-size: 16px; }
  .brand img { width: 34px; height: 34px; }
  .top-right { width: 100%; justify-content: space-between; }
  .account #account-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .layout { padding: 6px 12px 30px; gap: 12px; }
  .card { padding: 16px; border-radius: 24px; }
  .hero { grid-template-columns: minmax(0, 1fr); text-align: center; }
  .budget-row { justify-content: center; gap: 14px; }
  #wallet { width: 180px; height: 150px; }
  .row { grid-template-columns: minmax(0, 1fr); }
  .del { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* challenges, report card */
.challenges { display: grid; gap: 10px; margin-bottom: 18px; }
.ch { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px; border-radius: 20px; background: var(--field); }
.ch .e { width: 46px; height: 46px; border-radius: 16px; display: grid; place-items: center; font-size: 24px; background: var(--card); position: relative; }
.ch .e::after { content: ""; position: absolute; right: -4px; bottom: -4px; width: 18px; height: 18px; box-sizing: border-box; border-radius: 50%; border: 2.5px solid var(--bad); background: linear-gradient(45deg, transparent 42%, var(--bad) 42% 58%, transparent 58%), var(--card); }
.ch b { display: block; }
.ch small { color: var(--muted); }
.ch .bar { background: var(--card); height: 8px; margin-top: 6px; }
.ch .bar i { background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.ch.won .bar i { background: var(--good); }
.ch.lost .bar i { background: var(--bad); }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; background: var(--card); white-space: nowrap; }
.ch.won .pill { color: var(--good); }
.ch.lost .pill { color: var(--bad); }
.report img { display: block; width: 100%; border-radius: 18px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); }
.report { width: min(440px, calc(100vw - 24px)); }
a.btn { text-decoration: none; text-align: center; }
.sub-row .sub { margin: 4px 0 10px; }
/* quick add, limits */
.quick { display: flex; gap: 6px; overflow-x: auto; margin: -4px 0 12px; padding-bottom: 2px; scrollbar-width: none; }
.quick:empty { display: none; }
.quick button { flex: none; display: inline-flex; gap: 5px; align-items: center; padding: 6px 11px; border-radius: 999px; border: 1px dashed var(--accent); background: transparent; font-size: 13px; font-weight: 700; color: var(--text); }
.quick button:hover { background: var(--field); }
.limits { display: grid; gap: 10px; margin-bottom: 18px; }
.limit-row { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; align-items: center; cursor: pointer; border-radius: 12px; padding: 2px 4px; }
.limit-row:hover { background: var(--field); }
.limit-row .lbl { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; font-weight: 600; margin-bottom: 4px; }
.limit-row .lbl small { color: var(--muted); }
.limit-row .track { height: 10px; border-radius: 999px; background: var(--field); overflow: hidden; }
.limit-row .track i { display: block; height: 100%; border-radius: inherit; background: var(--good); }
.limit-row .track i.warn { background: var(--warn); }
.limit-row .track i.bad { background: var(--bad); }
.sub-row { display: flex; justify-content: space-between; align-items: center; }
/* list tools, edit sheet, recurring */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 140px; font: inherit; padding: 9px 13px; border-radius: 999px; border: 2px solid var(--line); background: var(--field); color: var(--text); outline: none; }
.toolbar input:focus { border-color: var(--accent); }
#filter-pill { background: var(--accent); color: #fff; }
.tx { cursor: pointer; }
.tx .rec-tag { font-size: 11px; font-weight: 700; color: var(--accent); margin-left: 4px; }
.cat-row { cursor: pointer; border-radius: 12px; padding: 2px 4px; }
.cat-row:hover { background: var(--field); }
.sheet-actions { display: flex; justify-content: space-between; gap: 8px; }
.sheet-actions .primary { margin-left: auto; }
.danger-text { background: transparent; color: var(--bad); }
.rec { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 10px 8px; border-radius: 16px; background: var(--field); margin-bottom: 8px; }
.rec .e { width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; font-size: 20px; background: var(--card); }
.rec b { display: block; }
.rec small { color: var(--muted); }
.rec .amt { font-weight: 800; white-space: nowrap; }
.tabs button { padding: 9px 4px; }

/* icon tiles (shared/icons.css) inside the old emoji slots */
.e:has(> .ci) { background: none !important; width: auto !important; height: auto !important; font-size: inherit !important; display: inline-flex !important; }
.tx .ci, .rec .ci { width: 40px; height: 40px; }
.chip .ci { width: 26px; height: 26px; border-radius: 9px; font-size: 16px; margin-left: -4px; }
.quick .ci { width: 22px; height: 22px; border-radius: 7px; font-size: 14px; margin-left: -5px; }
.insights .ci { width: 32px; height: 32px; border-radius: 11px; font-size: 17px; }
.cat-row .ci, .limit-row .ci { width: 34px; height: 34px; border-radius: 11px; font-size: 18px; }
.goal-head .ci, .ch .ci { width: 46px; height: 46px; border-radius: 15px; font-size: 23px; }
.ch .e { background: none; }
#g-icons .chip { padding: 5px; }
#g-icons .chip .ci { width: 36px; height: 36px; margin: 0; font-size: 20px; }
.empty b .ci { width: 56px; height: 56px; border-radius: 18px; font-size: 28px; }
.btn.more { display: block; margin: 4px auto 0; }
.tx { grid-template-columns: 40px minmax(0, 1fr) auto 28px; }
@media (max-width: 520px) {
  .tabs button { font-size: 13.5px; padding: 9px 2px; }
}

/* trend chart, debts */
.chart.trend { height: auto; aspect-ratio: 600 / 170; }
.legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.debt-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.debt-sum div { padding: 10px 14px; border-radius: 18px; background: var(--field); }
.debt-sum small { display: block; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.debt-sum b { font-size: 18px; }
.debt-sum .in b { color: var(--good); }
.debt-sum .out b { color: var(--bad); }
.debt { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 10px; border-radius: 18px; background: var(--field); margin-bottom: 8px; }
.debt > span:nth-child(2) { min-width: 0; }
.debt b { display: block; }
.debt small { display: block; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.debt .amt { font-weight: 800; white-space: nowrap; }
.debt.cho .amt { color: var(--good); }
.debt.no .amt { color: var(--bad); }
.debt .bar { height: 6px; margin: 5px 0 2px; background: var(--line); }
.debt .bar i { background: var(--good); }
.debt-actions { grid-column: 2 / -1; display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.debt.closed { opacity: 0.7; }
.debt.closed .debt-actions { grid-column: auto; }
.debt.closed { grid-template-columns: 40px minmax(0, 1fr) auto auto; }
.nag { margin: -2px 6px 10px; font-size: 13px; color: var(--accent); font-weight: 600; }
.closed-btn { color: var(--muted); margin: 2px 0 14px; display: block; }
#tab-rec .sub-row { margin-top: 6px; }
