:root {
  --g-950: #06190f; --g-900: #0a2e1c; --g-800: #0f3d22; --g-700: #17572f; --g-600: #1f7a44; --g-500: #2e8b57;
  --dollar: #85bb65; --dollar-100: #e8f3df;
  --au-800: #8a6508; --au-700: #a87b0a; --au-600: #c9a227; --au-500: #e6c35c; --au-400: #f2d272; --au-300: #f7e08f; --au-100: #fbf3d6;
  --gold: linear-gradient(135deg, #fff3c4 0%, #f2c94c 35%, #d4a017 60%, #f7e08f 80%, #b8860b 100%);
  --bg: #f6f3e7; --card: #fffdf6; --line: #ece5cd; --text: #13261c; --muted: #6b7a70;
  --up: #1f9d55; --down: #d1453b; --r: 20px; --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 1px 2px rgba(15, 61, 34, .05), 0 6px 18px rgba(15, 61, 34, .07);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
body { overscroll-behavior-y: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; touch-action: manipulation; }
input, select { font: inherit; color: inherit; }
svg { display: block; }
.hidden { display: none !important; }

/* ---------- Lock ---------- */
.lock { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; color: #fff;
  background: radial-gradient(120% 70% at 50% 0%, var(--g-600) 0%, var(--g-800) 55%, var(--g-950) 100%); }
.lock::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background: repeating-radial-gradient(circle at 50% 18%, transparent 0 22px, rgba(242, 201, 76, .06) 22px 23px); }
.lock > * { position: relative; }
.lock-logo img { width: 86px; height: 86px; border-radius: 24px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35), 0 0 0 1px rgba(247, 224, 143, .3); }
.lock-brand { margin-top: 16px; font-size: 13px; letter-spacing: .2em; text-transform: uppercase; font-weight: 800;
  background: var(--gold); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lock-title { font-size: 22px; font-weight: 700; margin-top: 6px; }
.lock-sub { color: rgba(255, 255, 255, .65); font-size: 14px; min-height: 20px; margin-top: 4px; text-align: center; }
.dots { display: flex; gap: 20px; margin: 28px 0 10px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--au-400); transition: background-color .15s, transform .15s var(--ease); }
.dots i.on { background: var(--au-400); transform: scale(1.15); box-shadow: 0 0 10px rgba(242, 201, 76, .6); }
.dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.lock-err { color: #ffb4a8; font-size: 14px; min-height: 20px; text-align: center; }
.keypad { display: grid; grid-template-columns: repeat(3, 74px); gap: 16px 26px; margin-top: 18px; }
.keypad button { width: 74px; height: 74px; border-radius: 50%; font-size: 28px; font-weight: 500; color: #fff; background: rgba(255, 255, 255, .08); border: 1px solid rgba(247, 224, 143, .25);
  touch-action: none; user-select: none; -webkit-user-select: none; transition: transform .25s var(--ease), background-color .3s; }
.keypad button.pressed { background: rgba(242, 201, 76, .4); transform: scale(.9); transition: none; }
.keypad button.ghost { background: none; border: 0; font-size: 22px; color: rgba(255, 255, 255, .7); }

/* ---------- Layout ---------- */
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(var(--safe-t) + 12px) 18px 6px; max-width: 640px; margin: 0 auto; }
.logo { width: 44px; height: 44px; border-radius: 13px; box-shadow: var(--shadow); }
.tb-text { flex: 1; min-width: 0; }
.topbar h1 { font-size: 21px; margin: 0; letter-spacing: -.2px; }
.greet { color: var(--muted); font-size: 12.5px; }
.icon-btn { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: var(--card); color: var(--g-800); box-shadow: var(--shadow); flex-shrink: 0; }
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:active, .btn:active, .add-row:active { transform: scale(.96); }
main { padding: 8px 18px calc(110px + var(--safe-b)); max-width: 640px; margin: 0 auto; }
main.enter > * { animation: enter .32s var(--ease); }
@keyframes enter { from { opacity: 0; transform: translateY(10px); } }

.tabbar { position: fixed; left: 50%; bottom: calc(12px + var(--safe-b)); transform: translateX(-50%); width: min(calc(100% - 28px), 360px); z-index: 10;
  display: grid; grid-template-columns: repeat(2, 1fr); padding: 6px; border-radius: 26px;
  background: rgba(10, 46, 28, .95); backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4);
  box-shadow: 0 10px 30px rgba(6, 25, 15, .35), inset 0 0 0 1px rgba(247, 224, 143, .14); }
.tab-ind { position: absolute; top: 6px; bottom: 6px; left: 6px; width: calc((100% - 12px) / 2); border-radius: 20px;
  background: linear-gradient(180deg, rgba(242, 201, 76, .26), rgba(242, 201, 76, .1)); box-shadow: inset 0 0 0 1px rgba(247, 224, 143, .3);
  transform: translateX(calc(var(--i, 0) * 100%)); transition: transform .35s var(--ease); }
.tabbar button { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0 6px; color: rgba(255, 255, 255, .55); font-size: 12px; font-weight: 700; }
.tabbar svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--au-400); }

/* ---------- Cards ---------- */
.sec-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--g-700); margin: 20px 4px 10px; }
.sec-title .badge { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.card { background: var(--card); border-radius: var(--r); padding: 6px 14px; margin-bottom: 14px; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; font-size: 19px; }
.ico.in { background: var(--au-100); }
.ico.out { background: var(--dollar-100); }
.row-label { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-label small { white-space: normal; }
.row-label small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.amt { width: 118px; text-align: right; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 10px; font-weight: 700; font-variant-numeric: tabular-nums; outline: none; }
.amt:focus { border-color: var(--au-500); box-shadow: 0 0 0 3px rgba(242, 201, 76, .25); }
.freq { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 4px; font-size: 13px; font-weight: 600; color: var(--g-700); outline: none; }
.name-in { flex: 1; min-width: 0; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 10px; font-weight: 600; outline: none; }
.del { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; color: var(--down); flex-shrink: 0; }
.del svg { width: 18px; height: 18px; }
.add-row { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; padding: 12px; margin: 6px 0 8px; border-radius: 14px; border: 1.5px dashed var(--au-600); color: var(--au-800); font-weight: 700; background: var(--au-100); }
.add-row svg { width: 18px; height: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0 10px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 11px; font-size: 13px; font-weight: 600; color: var(--g-700); }
.chip:active { background: var(--au-100); }
.total-bar { display: flex; justify-content: space-between; font-weight: 700; padding: 12px 4px 0; font-size: 14px; }

/* ---------- Hero ---------- */
.hero { position: relative; overflow: hidden; border-radius: 26px; padding: 20px; color: #fff; margin-bottom: 14px;
  background: radial-gradient(120% 100% at 100% 0%, var(--g-600) 0%, var(--g-800) 55%, var(--g-900) 100%); box-shadow: 0 14px 34px rgba(10, 46, 28, .32); }
.hero::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .55;
  background: repeating-radial-gradient(circle at 105% -10%, transparent 0 16px, rgba(242, 201, 76, .08) 16px 17px); }
.hero > * { position: relative; }
.hero-label { font-size: 13.5px; color: rgba(255, 255, 255, .72); font-weight: 500; }
.hero-total { font-size: 34px; font-weight: 800; letter-spacing: -1px; margin: 2px 0 6px; font-variant-numeric: tabular-nums;
  background: var(--gold); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.hero-grid div { background: rgba(255, 255, 255, .07); border: 1px solid rgba(247, 224, 143, .14); border-radius: 14px; padding: 10px 12px; }
.hero-grid b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.hero-grid span { font-size: 12px; color: rgba(255, 255, 255, .65); }
.c-in { color: var(--au-300) !important; }
.c-out { color: #a8dc8c !important; }
.neg { color: #ffb4a8 !important; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: #ebe5cf; padding: 4px; border-radius: 14px; margin-bottom: 12px; }
.seg button { padding: 9px 0; border-radius: 11px; font-weight: 700; font-size: 14px; color: var(--g-700); }
.seg button.on { background: var(--card); box-shadow: var(--shadow); color: var(--g-900); }
.custom { display: flex; align-items: center; gap: 8px; margin: -4px 0 12px; font-weight: 600; color: var(--muted); font-size: 14px; }
.custom input { width: 70px; }

.bars { padding: 8px 0 4px; }
.bar { margin: 8px 0; }
.bar-h { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; }
.bar-h span:last-child { font-variant-numeric: tabular-nums; }
.bar-t { height: 8px; border-radius: 6px; background: #efe9d5; margin-top: 5px; overflow: hidden; }
.bar-t i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--g-500), var(--dollar)); }
.bar-t.gold i { background: linear-gradient(90deg, var(--au-700), var(--au-400)); }

.chart { width: 100%; height: 150px; margin: 6px 0 2px; }
.chart-cap { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding-bottom: 8px; }

.goal { padding: 12px 0; border-bottom: 1px solid var(--line); }
.goal:last-child { border-bottom: 0; }
.goal-top { display: flex; align-items: center; gap: 10px; }
.goal-name { flex: 1; min-width: 0; font-weight: 700; }
.goal-name small { display: block; font-weight: 600; color: var(--muted); font-size: 12.5px; }
.goal-when { text-align: right; font-weight: 800; color: var(--g-700); font-size: 15px; }
.goal-when small { display: block; color: var(--muted); font-weight: 600; font-size: 12px; }
.goal-when.no { color: var(--down); }
.goal-act { display: flex; gap: 2px; }
.goal-act button { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); }
.goal-act svg { width: 16px; height: 16px; }
.goal .bar-t { margin-top: 8px; }
.note-s { color: var(--muted); font-size: 12.5px; margin: 6px 4px 12px; }

.btn { display: block; width: 100%; padding: 14px; border-radius: 16px; font-weight: 800; text-align: center; color: var(--g-950);
  background: var(--gold); box-shadow: 0 6px 16px rgba(184, 134, 11, .3); }
.btn.sec { background: var(--card); color: var(--g-800); box-shadow: var(--shadow); }
.btn.danger { background: #fff; color: var(--down); box-shadow: var(--shadow); }

/* ---------- Sheet / toast ---------- */
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-bg { position: absolute; inset: 0; background: rgba(6, 25, 15, .45); animation: fadeIn .2s; }
.sheet-body { position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; background: var(--bg); border-radius: 24px 24px 0 0; padding: 18px 18px calc(20px + var(--safe-b)); animation: up .3s var(--ease); max-height: 90vh; overflow: auto; }
.sheet-body h3 { margin: 0 0 14px; font-size: 19px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 4px 5px; }
.field input, .field select { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 14px; font-weight: 600; outline: none; }
.field input:focus { border-color: var(--au-500); }
.types { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.types button { background: #fff; border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 0 8px; font-size: 12px; font-weight: 700; color: var(--g-700); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.types button span { font-size: 22px; }
.types button.on { border-color: var(--au-600); background: var(--au-100); }
.btns { display: grid; gap: 10px; margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 20px); background: var(--g-900); color: #fff; padding: 10px 16px; border-radius: 14px; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s var(--ease); z-index: 60; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
