:root {
  --bg: #0f1020;
  --bg-soft: #1a1b2e;
  --card: #1c1d33;
  --card-2: #23244180;
  --line: #2e2f4d;
  --text: #ecedf7;
  --muted: #9a9bc0;
  --accent: #ff5d8f;
  --accent-2: #7c5cff;
  --income: #36d399;
  --expense: #ff6b6b;
  --saving: #ffd166;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Be Vietnam Pro", system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #2a1c4a 0%, transparent 60%),
              radial-gradient(900px 500px at -10% 110%, #3a1330 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-emoji { font-size: 42px; filter: drop-shadow(0 4px 8px rgba(0,0,0,.4)); }
.brand h1 {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: var(--muted); font-size: 13px; }

.mood-btn {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform .15s, border-color .2s;
}
.mood-btn:hover { transform: translateY(-2px); border-color: var(--accent); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 20px;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

.left, .right { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* Mom card */
.mom-card {
  background: linear-gradient(160deg, #25264a, #1a1b30);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  box-shadow: var(--shadow);
}
.mom-avatar {
  font-size: 54px;
  line-height: 1;
  flex-shrink: 0;
  transition: transform .3s;
}
.mom-avatar.shake { animation: shake .5s; }
@keyframes shake {
  0%,100% { transform: rotate(0); }
  20% { transform: rotate(-12deg) scale(1.1); }
  40% { transform: rotate(12deg) scale(1.1); }
  60% { transform: rotate(-8deg); }
  80% { transform: rotate(8deg); }
}
.speech-bubble {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  flex: 1;
  min-height: 64px;
  display: flex;
  align-items: center;
}
.speech-bubble::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 22px;
  width: 16px; height: 16px;
  background: var(--card);
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}
#momMessage { font-size: 15.5px; font-weight: 500; }

/* Stats */
.stats { display: flex; flex-direction: column; gap: 12px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-card.balance {
  background: linear-gradient(135deg, rgba(124,92,255,.18), rgba(255,93,143,.12));
  border-color: #4a3a7a;
}
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat-value { font-size: 30px; font-weight: 800; overflow-wrap: anywhere; word-break: break-word; }
.stat-value-sm { font-size: 17px; font-weight: 700; overflow-wrap: anywhere; word-break: break-word; }
.stat-card { min-width: 0; }
.stat-row { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; }
.stat-card.mini { padding: 14px; }
.mini.income .stat-value-sm { color: var(--income); }
.mini.expense .stat-value-sm { color: var(--expense); }
.mini.saving .stat-value-sm { color: var(--saving); }

/* Salary */
.salary-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.salary-box label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.salary-input-row { display: flex; gap: 8px; }
.salary-input-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}
.salary-input-row input:focus { outline: none; border-color: var(--accent-2); }
.salary-input-row button {
  background: var(--accent-2);
  border: none;
  color: #fff;
  padding: 0 18px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}
.salary-hint { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* Form */
.form-card, .history-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.form-card h2, .history-card h2 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

.type-tabs { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 16px; }
.type-tab {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 10px 6px;
  border-radius: 12px;
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all .18s;
}
.type-tab:hover { border-color: var(--accent); }
.type-tab.active {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  border-color: transparent;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--text); }
.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}
.field input:focus { outline: none; border-color: var(--accent-2); }

.essential-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ess-btn {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 10px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all .18s;
}
.ess-btn.active { background: var(--card-2); color: var(--text); border-color: var(--accent); }

.add-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  padding: 14px;
  border-radius: 12px;
  font-family: inherit;
  font-weight: 700;
  font-size: 15.5px;
  cursor: pointer;
  margin-top: 6px;
  transition: transform .15s, box-shadow .2s;
}
.add-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(255,93,143,.3); }
.add-btn:active { transform: translateY(0); }

/* History */
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.history-head h2 { margin-bottom: 0; }
.clear-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.clear-btn:hover { color: var(--expense); border-color: var(--expense); }

.history-list { list-style: none; display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; }
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  animation: slideIn .3s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.item-icon { font-size: 24px; flex-shrink: 0; }
.item-body { flex: 1; min-width: 0; }
.item-note { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 12px; color: var(--muted); }
.item-amount { font-weight: 700; font-size: 15px; white-space: nowrap; }
.item-amount.expense { color: var(--expense); }
.item-amount.income { color: var(--income); }
.item-amount.saving { color: var(--saving); }
.item-del {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 16px; padding: 4px; flex-shrink: 0;
}
.item-del:hover { color: var(--expense); }
.empty-state { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 14px; }

.footer { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 30px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%) translateY(120px);
  background: linear-gradient(135deg, #2a2b4f, #1d1e38);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 14px 22px;
  border-radius: 14px;
  font-weight: 600;
  font-size: 15px;
  max-width: 90vw;
  box-shadow: 0 16px 40px rgba(0,0,0,.5);
  opacity: 0;
  transition: transform .4s cubic-bezier(.2,1.2,.4,1), opacity .3s;
  z-index: 100;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.praise { border-color: var(--income); }
.toast.scold { border-color: var(--expense); }

/* ===== Topbar actions ===== */
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  width: 42px; height: 42px;
  border-radius: 999px;
  font-size: 18px;
  cursor: pointer;
  transition: transform .15s, border-color .2s, opacity .2s;
}
.icon-btn:hover { transform: translateY(-2px); border-color: var(--accent); }
.icon-btn.muted { opacity: .5; }

/* ===== Share trigger ===== */
.share-trigger {
  background: var(--card);
  border: 1px dashed var(--line);
  color: var(--text);
  padding: 12px;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all .18s;
}
.share-trigger:hover { border-color: var(--accent); border-style: solid; transform: translateY(-2px); }

/* ===== Budget box ===== */
.budget-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.budget-box label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.budget-progress { margin-top: 14px; }
.budget-bar {
  width: 100%;
  height: 14px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.budget-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--income), #2bbf86);
  transition: width .5s ease, background .3s;
}
.budget-bar-fill.warn { background: linear-gradient(90deg, var(--saving), #f5a623); }
.budget-bar-fill.over { background: linear-gradient(90deg, var(--expense), #c0392b); }
.budget-status { font-size: 12.5px; color: var(--muted); margin-top: 8px; font-weight: 500; }
.budget-status.over { color: var(--expense); font-weight: 700; }

/* ===== Share modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 18, .8);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  position: relative;
  box-shadow: var(--shadow);
  max-height: 92vh;
  overflow-y: auto;
}
.modal h3 { font-size: 18px; margin-bottom: 16px; padding-right: 30px; }
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  width: 30px; height: 30px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
}
.modal-close:hover { color: var(--expense); border-color: var(--expense); }
.share-preview {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  margin-bottom: 16px;
  background: var(--bg);
}
.share-preview canvas { display: block; width: 100%; height: auto; }
.share-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.share-act {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all .15s;
}
.share-act:hover { border-color: var(--accent); }
.share-act.primary {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
}
.share-social { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.social-link {
  text-align: center;
  text-decoration: none;
  padding: 10px 6px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  transition: transform .15s, opacity .2s;
}
.social-link:hover { transform: translateY(-2px); opacity: .9; }
.social-link.fb { background: #1877f2; }
.social-link.tw { background: #000; border: 1px solid #333; }
.social-link.th { background: #101010; border: 1px solid #333; }

/* ===== Category selector ===== */
.category-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
@media (max-width: 480px) {
  .category-grid { grid-template-columns: repeat(3, 1fr); }
}
.cat-btn {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 9px 4px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.cat-btn .cat-emoji { font-size: 18px; }
.cat-btn:hover { border-color: var(--accent); }
.cat-btn.active { background: var(--card-2); color: var(--text); border-color: var(--accent); }

/* ===== Analytics ===== */
.analytics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 20px;
}
@media (max-width: 860px) {
  .analytics { grid-template-columns: 1fr; }
}
.chart-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.chart-card h2 { font-size: 17px; font-weight: 700; margin-bottom: 16px; }
.chart-card.compare { grid-column: 1 / -1; }
.chart-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.chart-head h2 { margin-bottom: 0; }

.range-tabs { display: flex; gap: 6px; }
.range-tab {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.range-tab.active { background: var(--accent-2); color: #fff; border-color: transparent; }

.pie-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.pie-wrap canvas { flex-shrink: 0; max-width: 100%; }
.pie-legend { list-style: none; display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 140px; }
.pie-legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-dot { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; }
.legend-label { flex: 1; color: var(--text); }
.legend-pct { color: var(--muted); font-weight: 600; }

#barChart { width: 100%; height: auto; }

.chart-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 0; display: none; }
.chart-empty.show { display: block; }

.compare-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
@media (max-width: 600px) { .compare-grid { grid-template-columns: 1fr; } }
.compare-item {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.compare-item .ci-label { font-size: 12px; color: var(--muted); }
.compare-item .ci-value { font-size: 20px; font-weight: 800; margin: 4px 0; }
.compare-item .ci-delta { font-size: 12.5px; font-weight: 600; }
.ci-delta.up { color: var(--expense); }
.ci-delta.down { color: var(--income); }
.ci-delta.flat { color: var(--muted); }

.saving-rate { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.saving-rate-head { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 10px; }
#savingRateValue { color: var(--income); }
.saving-rate-note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* ===== Streak & combo ===== */
.mini.streak .stat-value-sm { color: #ff9f43; }
.mini.combo .stat-value-sm { color: var(--expense); }
.mini.combo.hot { animation: comboPulse .5s; border-color: var(--expense); }
@keyframes comboPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); box-shadow: 0 0 20px rgba(255,107,107,.4); }
}

/* ===== AI box ===== */
.ai-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.ai-box summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  list-style: none;
}
.ai-box summary::-webkit-details-marker { display: none; }
.ai-box[open] summary { margin-bottom: 12px; }
.ai-body { display: flex; flex-direction: column; gap: 10px; }
.ai-note { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.ai-note b { color: var(--text); }
.ai-toggle { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.ai-toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
.ai-body input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
.ai-body input[type="password"]:focus { outline: none; border-color: var(--accent-2); }
#aiSaveBtn {
  background: var(--accent-2);
  border: none;
  color: #fff;
  padding: 10px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}
.ai-status { font-size: 12.5px; font-weight: 600; }
.ai-status.ok { color: var(--income); }
.ai-status.err { color: var(--expense); }
.ai-thinking { font-style: italic; opacity: .7; }

/* ===== Achievements ===== */
.achievements { margin-top: 20px; }
.ach-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.ach-count { color: var(--muted); font-weight: 700; font-size: 14px; }
.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.ach-item {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
  transition: transform .15s;
  opacity: .45;
  filter: grayscale(1);
}
.ach-item.unlocked {
  opacity: 1;
  filter: none;
  border-color: var(--accent);
  background: linear-gradient(160deg, rgba(124,92,255,.12), rgba(255,93,143,.08));
}
.ach-item:hover { transform: translateY(-3px); }
.ach-emoji { font-size: 34px; }
.ach-title { font-weight: 700; font-size: 13.5px; margin-top: 6px; }
.ach-desc { font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.ach-item.unlocked .ach-badge { color: var(--income); font-size: 11px; font-weight: 700; margin-top: 6px; display: block; }
.ach-item:not(.unlocked) .ach-badge { color: var(--muted); font-size: 11px; margin-top: 6px; display: block; }

/* ===== Light theme ===== */
:root[data-theme="light"] {
  --bg: #f4f5fb;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-2: #eef0fa;
  --line: #e2e4f0;
  --text: #1c1d33;
  --muted: #6b6d8c;
  --shadow: 0 18px 40px rgba(80, 70, 140, 0.12);
}
:root[data-theme="light"] body {
  background: radial-gradient(1200px 600px at 80% -10%, #ffe3ee 0%, transparent 60%),
              radial-gradient(900px 500px at -10% 110%, #e7e0ff 0%, transparent 55%),
              var(--bg);
}
:root[data-theme="light"] .mom-card {
  background: linear-gradient(160deg, #ffffff, #f6f3ff);
}
:root[data-theme="light"] .toast {
  background: linear-gradient(135deg, #ffffff, #f3f0ff);
  color: var(--text);
}
:root[data-theme="light"] .social-link.tw,
:root[data-theme="light"] .social-link.th { color: #fff; }

/* ===== Onboarding ===== */
.modal.onboard { max-width: 380px; text-align: center; }
.onboard-emoji { font-size: 72px; line-height: 1; margin-bottom: 8px; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.modal.onboard h3 { padding-right: 0; font-size: 20px; margin-bottom: 10px; }
.modal.onboard p { color: var(--muted); font-size: 14.5px; line-height: 1.55; min-height: 66px; }
.onboard-dots { display: flex; justify-content: center; gap: 7px; margin: 18px 0; }
.onboard-dots span { width: 8px; height: 8px; border-radius: 999px; background: var(--line); transition: all .2s; }
.onboard-dots span.active { background: var(--accent); width: 22px; }
.onboard-actions { display: flex; gap: 10px; }
.onboard-skip {
  flex: 1; background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  padding: 12px; border-radius: 12px; font-family: inherit; font-weight: 600; cursor: pointer;
}
.onboard-next {
  flex: 2; background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff;
  padding: 12px; border-radius: 12px; font-family: inherit; font-weight: 700; cursor: pointer;
}

/* ===== Confetti ===== */
.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 300;
  display: none;
}
.confetti-canvas.show { display: block; }

/* ===== Goal box ===== */
.goal-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.goal-box label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.goal-inputs { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.goal-inputs input, .goal-inputs button {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; color: var(--text); font-family: inherit; font-size: 14px;
}
.goal-inputs input:focus { outline: none; border-color: var(--accent-2); }
.goal-inputs button { background: var(--accent-2); color: #fff; border: none; font-weight: 600; cursor: pointer; padding: 0 16px; }
.goal-progress { margin-top: 14px; }
.budget-bar-fill.goal-fill { background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.budget-bar-fill.goal-fill.done { background: linear-gradient(90deg, var(--income), #2bbf86); }

/* ===== Settings / category-budget boxes ===== */
.settings-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.settings-box summary { cursor: pointer; font-weight: 600; font-size: 14px; list-style: none; }
.settings-box summary::-webkit-details-marker { display: none; }
.settings-box[open] summary { margin-bottom: 12px; }
.settings-body { display: flex; flex-direction: column; gap: 10px; }
.settings-note { font-size: 12px; color: var(--muted); line-height: 1.5; }
#currencySelect, #filterType, #filterCategory {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; color: var(--text); font-family: inherit; font-size: 14px; cursor: pointer;
}
#currencySelect:focus { outline: none; border-color: var(--accent-2); }

.catbudget-body { display: flex; flex-direction: column; gap: 10px; }
.catbudget-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.catbudget-row .cb-icon { font-size: 18px; width: 24px; text-align: center; }
.catbudget-row .cb-label { flex: 1; font-size: 13.5px; font-weight: 600; }
.catbudget-row input {
  width: 120px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; color: var(--text); font-family: inherit; font-size: 13.5px; text-align: right;
}
.catbudget-row input:focus { outline: none; border-color: var(--accent-2); }
.catbudget-row .cb-used { font-size: 11px; color: var(--muted); width: 100%; }
.catbudget-row.over input { border-color: var(--expense); color: var(--expense); }

/* ===== Recurring ===== */
.recurring-card, .ai-box {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
}
.recurring-card summary { cursor: pointer; font-weight: 600; font-size: 14px; list-style: none; }
.recurring-card summary::-webkit-details-marker { display: none; }
.recurring-card[open] summary { margin-bottom: 12px; }
.recurring-body { display: flex; flex-direction: column; gap: 12px; }
.recurring-form { display: grid; grid-template-columns: 1.4fr 1fr 0.7fr auto; gap: 8px; }
.recurring-form input, .recurring-form button {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; color: var(--text); font-family: inherit; font-size: 13.5px; min-width: 0;
}
.recurring-form input:focus { outline: none; border-color: var(--accent-2); }
.recurring-form button { background: var(--accent-2); color: #fff; border: none; font-weight: 600; cursor: pointer; }
.recurring-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.recurring-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.recurring-item.due { border-color: var(--saving); }
.rec-info { flex: 1; min-width: 0; }
.rec-name { font-weight: 600; font-size: 13.5px; }
.rec-meta { font-size: 11.5px; color: var(--muted); }
.rec-apply {
  background: var(--saving); color: #1c1d33; border: none; border-radius: 8px;
  padding: 6px 10px; font-family: inherit; font-weight: 700; font-size: 12px; cursor: pointer;
}
.rec-applied { font-size: 11.5px; color: var(--income); font-weight: 600; }
.rec-del { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }
.rec-del:hover { color: var(--expense); }

/* ===== History filters & edit ===== */
.history-filters { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin-bottom: 14px; }
@media (max-width: 520px) { .history-filters { grid-template-columns: 1fr; } }
#searchInput {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; color: var(--text); font-family: inherit; font-size: 13.5px;
}
#searchInput:focus { outline: none; border-color: var(--accent-2); }
.item-edit { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px; flex-shrink: 0; }
.item-edit:hover { color: var(--accent-2); }

/* ===== Data backup buttons ===== */
.data-btn {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all .15s;
}
.data-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.data-btn.danger:hover { border-color: var(--expense); color: var(--expense); }

/* ===== Prediction ===== */
.prediction {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 18px;
  line-height: 1.5;
}
.prediction.warn { border-color: var(--saving); }
.prediction.over { border-color: var(--expense); }
.prediction:empty { display: none; }
#summaryBtn { cursor: pointer; }

/* ===== Custom scold / character forms ===== */
.inline-form { display: flex; gap: 8px; }
.inline-form input {
  flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; color: var(--text); font-family: inherit; font-size: 14px;
}
.inline-form input:focus { outline: none; border-color: var(--accent-2); }
.inline-form button {
  background: var(--accent-2); color: #fff; border: none; border-radius: 10px;
  padding: 0 16px; font-family: inherit; font-weight: 600; cursor: pointer;
}
.settings-body textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; color: var(--text); font-family: inherit; font-size: 13.5px; resize: vertical;
}
.settings-body textarea:focus { outline: none; border-color: var(--accent-2); }
.chip-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.chip-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.chip-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.chip-item button { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }
.chip-item button:hover { color: var(--expense); }

/* ===== Responsive: điện thoại nhỏ ===== */
@media (max-width: 560px) {
  .app { padding: 16px 12px 32px; }
  .brand h1 { font-size: 22px; }
  .brand-emoji { font-size: 34px; }
  .tagline { font-size: 12px; }
  .topbar { gap: 10px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
  .icon-btn { width: 38px; height: 38px; font-size: 16px; }
  .mood-btn { padding: 9px 12px; font-size: 13px; }

  .stat-value { font-size: 26px; }
  .stat-row { gap: 8px; }
  .stat-card.mini { padding: 11px; }

  /* Các form nhiều cột -> xếp dọc cho dễ bấm */
  .goal-inputs { grid-template-columns: 1fr 1fr; }
  .goal-inputs button { grid-column: 1 / -1; padding: 11px; }
  .recurring-form { grid-template-columns: 1fr 1fr; }
  .recurring-form #recDay { grid-column: 1; }
  .recurring-form button { grid-column: 1 / -1; padding: 11px; }

  /* Modal gọn hơn */
  .modal { padding: 18px; border-radius: 16px; }
  .modal h3 { font-size: 17px; }
  .share-actions { grid-template-columns: 1fr; }

  /* Biểu đồ tròn xếp dọc */
  .pie-wrap { justify-content: center; }
  .pie-wrap canvas { width: 240px; height: 240px; }

  .footer { font-size: 11.5px; }
}

@media (max-width: 380px) {
  .type-tabs { grid-template-columns: 1fr; }
  .category-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Settings: nút mở ===== */
.settings-open-btn {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 14px;
  border-radius: var(--radius);
  font-family: inherit;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  transition: all .18s;
  box-shadow: var(--shadow);
}
.settings-open-btn:hover { border-color: var(--accent); transform: translateY(-2px); }

/* ===== Settings: trang riêng ===== */
.settings-page {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 250;
  display: none;
  grid-template-columns: 280px 1fr;
}
.settings-page.show { display: grid; }

.settings-nav {
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  overflow-y: auto;
  background: var(--bg-soft);
}
.settings-nav-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; padding: 0 6px; }
.settings-nav-head h2 { font-size: 20px; font-weight: 800; }
.settings-close-btn {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  width: 34px; height: 34px; border-radius: 999px; cursor: pointer; font-size: 15px;
}
.settings-close-btn:hover { color: var(--expense); border-color: var(--expense); }
.settings-nav nav { display: flex; flex-direction: column; gap: 6px; }
.snav-item {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 13px 14px; border-radius: 12px; font-family: inherit; font-weight: 600;
  font-size: 14.5px; cursor: pointer; text-align: left; transition: all .15s;
}
.snav-item span { flex: 1; }
.snav-item:hover { background: var(--card); color: var(--text); }
.snav-item.active {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff; border-color: transparent;
}

.settings-content { padding: 40px; overflow-y: auto; max-width: 720px; }
.settings-panel { display: none; animation: slideIn .25s ease; }
.settings-panel.active { display: block; }
.panel-title { font-size: 24px; font-weight: 800; margin-bottom: 22px; }
.settings-panel .settings-body,
.settings-panel .recurring-body,
.settings-panel .ai-body { display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 700px) {
  .settings-page.show { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .settings-nav { border-right: none; border-bottom: 1px solid var(--line); padding: 16px 12px; }
  .settings-nav nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 8px; padding-bottom: 4px; }
  .snav-item { flex-direction: column; gap: 4px; padding: 10px 12px; white-space: nowrap; font-size: 12px; text-align: center; }
  .snav-item span { font-size: 11px; }
  .settings-content { padding: 22px 16px; }
  .panel-title { font-size: 20px; }
}

/* ===== Mood meter (tâm trạng nhân vật) ===== */
.mood-meter {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  transition: border-color .3s;
}
.mood-face { font-size: 38px; line-height: 1; flex-shrink: 0; transition: transform .3s; }
.mood-face.bump { animation: faceBump .4s; }
@keyframes faceBump { 0%,100% { transform: scale(1); } 50% { transform: scale(1.35); } }
.mood-bar-wrap { flex: 1; min-width: 0; }
.mood-bar {
  width: 100%; height: 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.mood-bar-fill {
  height: 100%; width: 35%; border-radius: 999px;
  background: linear-gradient(90deg, var(--income), #2bbf86);
  transition: width .5s ease, background .4s;
}
.mood-meter-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-top: 7px; }

/* Rung màn hình khi mẹ giận */
@keyframes screenShake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
.app.screen-shake { animation: screenShake .45s; }
.mom-card.angry { border-color: var(--expense); box-shadow: 0 0 0 1px var(--expense), 0 18px 40px rgba(255,0,0,.12); }

/* ===== Mom action buttons ===== */
.mom-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.mom-act {
  flex: 1; min-width: 90px;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  padding: 10px 8px; border-radius: 12px; font-family: inherit; font-weight: 600;
  font-size: 13px; cursor: pointer; transition: all .15s;
}
.mom-act:hover { border-color: var(--accent); transform: translateY(-2px); }
#argueBtn { border-color: var(--expense); color: var(--expense); }

/* ===== Game card: level + challenge ===== */
.game-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.level-row { display: flex; align-items: center; gap: 14px; }
.level-badge {
  flex-shrink: 0; width: 50px; height: 50px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; color: #fff;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
}
.level-info { flex: 1; min-width: 0; }
.level-title { font-weight: 700; font-size: 15px; margin-bottom: 7px; }
.xp-fill { background: linear-gradient(90deg, #ffd166, #ff9f43); }
.level-xp { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.challenge { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.challenge-head { font-weight: 700; font-size: 13.5px; margin-bottom: 6px; }
.challenge-desc { font-size: 13px; color: var(--text); }
.challenge-status { font-size: 12px; color: var(--muted); margin-top: 5px; font-weight: 600; }

/* ===== Beg result ===== */
.beg-result { margin: 14px 0; font-size: 15px; font-weight: 600; line-height: 1.5; min-height: 24px; }
.beg-result.ok { color: var(--income); }
.beg-result.no { color: var(--expense); }
