* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  /* 딸기 🍓 팔레트 — 변수명은 v1 유지 */
  --blue: #FF7FA2;
  --blue-dark: #E85D75;
  --red: #E85D75;
  --green: #4CAF87;
  --bg: #FFF7F2;
  --card: #FFFFFF;
  --text: #4A3038;
  --text-sub: #B08894;
  --line: #FFE3EC;
  --radius: 20px;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  background: var(--bg);
  background-image: radial-gradient(#FFE9F0 1.2px, transparent 1.2px);
  background-size: 26px 26px;
  color: var(--text);
  overscroll-behavior: none;
}
h1, h3, .tab, .btn, .seg button, .month-nav .label, .amount-value, .section-title, .ledger-chip, .save-btn {
  font-family: "Jua", "Apple SD Gothic Neo", sans-serif;
}
.hidden { display: none !important; }
button { font: inherit; border: none; background: none; color: inherit; cursor: pointer; }
input, select { font: inherit; }

/* ───── PIN 화면 ───── */
.pin-screen {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; max-width: 420px; margin: 0 auto;
}
.pin-logo { font-size: 56px; }
.pin-title { font-size: 24px; margin-top: 8px; }
.pin-sub { color: var(--text-sub); margin-top: 6px; font-size: 15px; }
.pin-dots { display: flex; gap: 14px; margin: 26px 0 8px; height: 16px; }
.pin-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.pin-dot.on { background: var(--blue); }
.pin-error { color: var(--red); font-size: 14px; height: 20px; }

/* ───── 공용 키패드 ───── */
.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  width: 100%; max-width: 340px; margin-top: 12px;
}
.keypad button {
  height: 62px; font-size: 26px; font-weight: 600;
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(20,30,60,.06);
}
.keypad button:active { background: #FFE3EC; }
.keypad button.fn { font-size: 20px; color: var(--text-sub); }

/* ───── 앱 레이아웃 ───── */
.app { min-height: 100dvh; max-width: 640px; margin: 0 auto; }
.app-header {
  font-family: "Jua", sans-serif; font-size: 19px; color: var(--blue-dark);
  text-align: center; padding: 14px 0 2px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.kitty-sm { height: 30px; vertical-align: middle; }
.kitty-lg { height: 88px; }
.header-ribbon { font-size: 15px; }

/* 빈 화면 키티 */
.empty::before {
  content: '';
  display: block; height: 64px; margin: 0 auto 10px;
  background: url('kitty.svg') center / contain no-repeat;
  opacity: .8;
}
main { padding: 12px 16px calc(84px + env(safe-area-inset-bottom)); }

.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px;
  display: flex; background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 8px; font-size: 11px; color: var(--text-sub); min-height: 56px;
}
.tab .tab-icon { font-size: 22px; filter: grayscale(1) opacity(.55); }
.tab.active { color: var(--blue-dark); font-weight: 700; }
.tab.active .tab-icon { filter: none; }

/* ───── 카드/공통 ───── */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 3px rgba(20,30,60,.05); }
.section-title { font-size: 14px; color: var(--text-sub); font-weight: 700; margin: 20px 4px 8px; }

/* 가계부 칩 바 */
.ledger-bar { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 12px; -webkit-overflow-scrolling: touch; }
.ledger-bar::-webkit-scrollbar { display: none; }
.ledger-chip {
  flex-shrink: 0; padding: 9px 16px; border-radius: 999px; font-size: 14px;
  background: var(--card); color: var(--text-sub); border: 1.5px solid var(--line); min-height: 40px;
}
.ledger-chip.on { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 3px 8px rgba(255,127,162,.35); }

/* 저장 버튼 */
.save-btn { width: 100%; margin-top: 14px; font-size: 18px; min-height: 56px; box-shadow: 0 4px 12px rgba(255,127,162,.35); }
.save-btn:disabled { box-shadow: none; background: #F3D9E1; color: #C9A5B2; }

/* 세그먼트 토글 */
.seg { display: flex; background: #FFE9F0; border-radius: 14px; padding: 4px; }
.seg button { flex: 1; padding: 10px 0; border-radius: 9px; font-weight: 700; font-size: 15px; color: var(--text-sub); min-height: 44px; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(20,30,60,.1); }
.seg button.on.expense { color: var(--red); }
.seg button.on.income { color: var(--green); }

/* ───── 홈(입력) ───── */
.amount-box { text-align: center; padding: 22px 0 10px; }
.amount-value { font-size: 44px; font-weight: 800; letter-spacing: -1px; }
.amount-value .won { font-size: 26px; font-weight: 600; color: var(--text-sub); margin-left: 4px; }
.amount-value.zero { color: #C6CCD9; }
.date-chip {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  background: #FFE9F0; border-radius: 999px; padding: 8px 14px; font-size: 14px; color: var(--text-sub);
  min-height: 36px;
}
.memo-input {
  width: 100%; margin-top: 12px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  font-size: 15px; outline: none;
}
.memo-input:focus { border-color: var(--blue); }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; }
@media (min-width: 480px) { .cat-grid { grid-template-columns: repeat(5, 1fr); } }
.cat-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--card); border-radius: var(--radius); padding: 12px 4px;
  box-shadow: 0 1px 3px rgba(20,30,60,.05); min-height: 72px;
}
.cat-btn:active { transform: scale(.96); }
.cat-btn .emoji { font-size: 26px; }
.cat-btn .name { font-size: 12px; color: var(--text-sub); font-weight: 600; }
.cat-btn.selected { outline: 2.5px solid var(--blue); }
.cat-btn.disabled { opacity: .35; pointer-events: none; }

/* 거래 리스트 */
.tx-group { margin-bottom: 14px; }
.tx-date-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-sub); font-weight: 700; padding: 0 6px 6px; }
.tx-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); padding: 13px 14px; min-height: 56px;
}
.tx-item:first-of-type { border-radius: var(--radius) var(--radius) 0 0; }
.tx-item:last-of-type { border-radius: 0 0 var(--radius) var(--radius); }
.tx-item:only-of-type { border-radius: var(--radius); }
.tx-item + .tx-item { border-top: 1px solid var(--line); }
.tx-item .emoji { font-size: 24px; }
.tx-item .mid { flex: 1; min-width: 0; }
.tx-item .cat { font-size: 15px; font-weight: 600; }
.tx-item .memo { font-size: 12px; color: var(--text-sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-item .amt { font-weight: 700; font-size: 15px; }
.amt.expense { color: var(--red); }
.amt.income { color: var(--green); }

.empty { text-align: center; color: var(--text-sub); padding: 40px 0; font-size: 14px; }

/* 월 이동 */
.month-nav { display: flex; align-items: center; justify-content: center; gap: 4px; margin-bottom: 14px; }
.month-nav button { font-size: 22px; color: var(--text-sub); padding: 8px 16px; min-height: 44px; }
.month-nav .label { font-size: 18px; font-weight: 800; min-width: 130px; text-align: center; }

/* ───── 통계 ───── */
.sum-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.sum-card { background: var(--card); border-radius: var(--radius); padding: 14px 10px; text-align: center; }
.sum-card .lbl { font-size: 12px; color: var(--text-sub); }
.sum-card .val { font-size: 15px; font-weight: 800; margin-top: 4px; }

.donut-wrap { display: flex; justify-content: center; padding: 8px 0 4px; }
.rank-item { display: flex; align-items: center; gap: 10px; padding: 11px 4px; min-height: 48px; }
.rank-item + .rank-item { border-top: 1px solid var(--line); }
.rank-item .dot { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; }
.rank-item .nm { flex: 1; font-size: 15px; font-weight: 600; }
.rank-item .pct { font-size: 13px; color: var(--text-sub); margin-right: 8px; }
.rank-item .amt { font-weight: 700; font-size: 14px; }

/* 예산 */
.budget-item { padding: 13px 2px; }
.budget-item + .budget-item { border-top: 1px solid var(--line); }
.budget-top { display: flex; justify-content: space-between; align-items: center; font-size: 15px; font-weight: 600; }
.budget-top .rest { font-size: 13px; color: var(--text-sub); font-weight: 600; }
.budget-top .rest.over { color: var(--red); }
.bar { height: 10px; border-radius: 999px; background: #FFE9F0; margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--blue); }
.bar > i.over { background: var(--red); }
.budget-sub { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-sub); margin-top: 5px; }

/* ───── 설정 ───── */
.set-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); padding: 14px; min-height: 56px; width: 100%; text-align: left;
}
.set-row:first-of-type { border-radius: var(--radius) var(--radius) 0 0; }
.set-row:last-of-type { border-radius: 0 0 var(--radius) var(--radius); }
.set-row:only-of-type { border-radius: var(--radius); }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row .grow { flex: 1; min-width: 0; }
.set-row .sub { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.set-row .chev { color: #C6CCD9; font-size: 18px; }

/* ───── 바텀시트 ───── */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20,25,40,.4); z-index: 30; }
.sheet {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px; z-index: 31;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 85dvh; overflow-y: auto;
}
.sheet h3 { font-size: 17px; margin-bottom: 14px; }
.sheet .field { margin-bottom: 12px; }
.sheet .field label { display: block; font-size: 13px; color: var(--text-sub); font-weight: 700; margin-bottom: 6px; }
.sheet input, .sheet select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; outline: none; background: var(--bg);
}
.sheet input:focus, .sheet select:focus { border-color: var(--blue); }
.sheet-btns { display: flex; gap: 8px; margin-top: 16px; }
.btn { flex: 1; padding: 14px 0; border-radius: 14px; font-size: 16px; font-weight: 700; min-height: 50px; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:active { background: var(--blue-dark); }
.btn.danger { background: #FDECEE; color: var(--red); }
.btn.ghost { background: #FFE9F0; color: var(--text-sub); }
.btn:disabled { opacity: .5; }

.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emoji-grid button { font-size: 24px; padding: 8px 0; border-radius: 10px; min-height: 44px; }
.emoji-grid button.on { background: #FFE3EC; outline: 2px solid var(--blue); }

/* ───── 토스트 ───── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom));
  background: rgba(30,35,50,.92); color: #fff;
  padding: 12px 20px; border-radius: 999px; font-size: 14px; z-index: 50;
  display: flex; align-items: center; gap: 12px; max-width: 90%;
}
.toast button { color: #9BC0FF; font-weight: 700; }

.fade-in { animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
