/* =========================================================
   CommonCents — tokens
   ========================================================= */
:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --fill: #f1efe9;        /* quiet button / keypad fill */
  --fill-hover: #e8e5dd;
  --line: #e5e2d9;
  --line-strong: #d4cfc3;
  --ink: #17201c;
  --ink-2: #414b46;
  --muted: #6d7671;

  --brand: #0f5c46;
  --brand-hover: #0b4a38;
  --brand-tint: #e6efe9;

  --positive: #157a5c;
  --negative: #b3361f;
  --gold: #e9a92f;

  --cash: #1f8a5b;
  --bank: #2f5bd3;
  --gift: #a83f86;

  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 10px;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--brand);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px; font-weight: 500; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, p { margin: 0; }
strong { font-weight: 700; }
::selection { background: #cfe3d8; }
::placeholder { color: #9ba39f; }

/* =========================================================
   Shell
   ========================================================= */
.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) clamp(16px, 4vw, 40px) 80px;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 32px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 36px; height: 36px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--brand); border-radius: 10px;
}
.logo svg { width: 24px; height: 24px; }
.app-title { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.data-actions { display: flex; gap: 4px; }

/* ---------- Total ---------- */
.hero {
  display: grid; grid-template-columns: auto minmax(0, 1fr);
  align-items: end; gap: 20px 56px;
  margin-bottom: 40px;
}
.hero-label { color: var(--muted); font-size: 0.95rem; font-weight: 600; margin-bottom: 6px; }
.total-pill {
  font-size: clamp(2.75rem, 7vw, 3.75rem);
  font-weight: 700; line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.hero-breakdown { min-width: 0; padding-bottom: 4px; }
.split-bar {
  display: flex; gap: 2px; height: 8px;
  border-radius: 4px; overflow: hidden;
  background: var(--fill);
  margin-bottom: 12px;
}
.split-bar span { display: block; height: 100%; min-width: 4px; transition: flex-grow 0.5s var(--ease); }
.split-legend { display: flex; flex-wrap: wrap; gap: 6px 24px; list-style: none; margin: 0; padding: 0; }
.split-legend li { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.split-legend strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.seg-cash { background: var(--cash); }
.seg-bank { background: var(--bank); }
.seg-gift { background: var(--gift); }

/* ---------- Section heads ---------- */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; min-height: 40px;
}
.section-head h2 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
.section-head h3 { font-size: 1rem; font-weight: 700; }

/* =========================================================
   Accounts
   ========================================================= */
.accounts-section { margin-bottom: 40px; }
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.card {
  --hue: var(--brand);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 18px 18px 20px;
  display: flex; flex-direction: column;
  animation: card-in 0.4s var(--ease) both;
}
.card.cash { --hue: var(--cash); }
.card.bank { --hue: var(--bank); }
.card.gift { --hue: var(--gift); }
@keyframes card-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px; }
.card-id { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-emoji { display: flex; color: var(--hue); flex-shrink: 0; }
.card-emoji svg { width: 20px; height: 20px; }
.card-name { font-weight: 600; font-size: 0.98rem; color: var(--ink-2); overflow-wrap: anywhere; line-height: 1.3; }
.card-tools { display: flex; gap: 2px; margin-right: -8px; flex-shrink: 0; }
.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--fill); color: var(--ink); }
.icon-btn.danger:hover { color: var(--negative); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus); }

.card-balance {
  font-size: clamp(2.1rem, 4.6vw, 2.5rem);
  font-weight: 700; line-height: 1;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
  margin: 10px 0 20px;
  transform-origin: left center;
}
.card-balance.pop { animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }

.card-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: auto; }
.card-actions .btn { padding: 0 8px; gap: 6px; }

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 1rem; font-weight: 700;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.08s ease;
}
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn span { line-height: 1; }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }

.btn-primary, .btn-add, .btn-green { background: var(--brand); color: #fff; }
.btn-primary:hover, .btn-add:hover, .btn-green:hover { background: var(--brand-hover); }

.btn-spend, .btn-set, .btn-secondary, .btn-ghost { background: var(--fill); color: var(--ink); }
.btn-spend:hover, .btn-set:hover, .btn-secondary:hover, .btn-ghost:hover { background: var(--fill-hover); }
.btn-spend svg { color: var(--negative); }
.btn-add svg { color: #bfe3d2; }
.btn-set svg { color: var(--muted); }

.btn-quiet { background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--fill); }
.btn-danger { background: var(--negative); color: #fff; }
.btn-danger:hover { background: #942a16; }

.btn-small { min-height: 40px; padding: 0 12px; font-size: 0.9rem; font-weight: 700; }
.btn-small svg { width: 16px; height: 16px; }
.add-gift-btn.btn-ghost { background: transparent; color: var(--brand); }
.add-gift-btn.btn-ghost:hover { background: var(--brand-tint); }

/* =========================================================
   Panels
   ========================================================= */
.columns { display: grid; grid-template-columns: 1fr; gap: 20px; align-items: start; }
@media (min-width: 960px) {
  .columns { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 22px 8px;
}

/* ---------- Goal ---------- */
.goal-hero {
  display: flex; flex-direction: column; gap: 12px;
  padding-bottom: 22px; margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.goal-hero-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.goal-body { flex: 1; min-width: 0; }
.goal-title { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.015em; overflow-wrap: anywhere; line-height: 1.25; }
.goal-meta { color: var(--muted); margin-top: 4px; font-size: 0.95rem; }
.goal-meta strong { color: var(--ink-2); font-weight: 600; }
.progress-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.goal-amounts { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.goal-saved { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.goal-price { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.progress-pct { font-weight: 700; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress-track { height: 10px; border-radius: 5px; overflow: hidden; background: var(--fill); }
.progress-fill { height: 100%; border-radius: 5px; background: var(--brand); transition: width 0.6s var(--ease); }
.goal-actions { display: flex; gap: 8px; margin-top: 4px; }
.goal-actions .btn:first-child { flex: 1; }
.goal-chip {
  display: inline-flex; align-items: center;
  background: var(--brand-tint); color: var(--brand);
  font-weight: 700; font-size: 0.8rem;
  border-radius: 6px; padding: 2px 8px;
  white-space: nowrap;
}

/* ---------- Wish list ---------- */
.wish-head { margin-bottom: 4px; }
.wish-head-actions { display: flex; gap: 4px; align-items: center; }
.wish-head-actions .btn-primary { background: transparent; color: var(--brand); }
.wish-head-actions .btn-primary:hover { background: var(--brand-tint); }
.wish-list { list-style: none; margin: 0; padding: 0; }
.wish-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center; gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.wish-item:first-child { border-top: none; }
.wish-item.done .wish-name { color: var(--muted); text-decoration: line-through; }
.wish-stars {
  display: inline-flex; align-items: center;
  min-height: 44px; padding: 0 6px; margin-left: -6px;
  background: transparent; border: none; border-radius: var(--radius-sm);
  cursor: pointer;
}
.wish-stars:hover { background: var(--fill); }
.wish-stars:focus-visible { outline: none; box-shadow: var(--focus); }
.wish-stars-inner { display: inline-flex; gap: 1px; }
.wish-stars svg { width: 16px; height: 16px; }
.wish-stars .star { color: var(--gold); fill: var(--gold); }
.wish-stars .star.off { color: #d3cec2; fill: none; }
.wish-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.wish-name { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; line-height: 1.3; }
.wish-name .goal-chip { display: none; }
.wish-meta { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.wish-progress { height: 4px; border-radius: 2px; background: var(--fill); overflow: hidden; margin-top: 5px; max-width: 200px; }
.wish-progress span { display: block; height: 100%; background: var(--brand); }
.wish-empty, .empty { color: var(--muted); text-align: center; padding: 28px 12px; }

.goal-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-2);
  font-family: inherit; font-weight: 700; font-size: 0.85rem;
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.goal-toggle svg { width: 15px; height: 15px; }
.goal-toggle:hover { background: var(--fill); }
.goal-toggle.is-goal { border-color: transparent; background: var(--brand-tint); color: var(--brand); }
.goal-toggle:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- Activity ---------- */
.log-list {
  list-style: none; margin: 0; padding: 0;
  max-height: 640px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
.log-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.log-item:first-child { border-top: none; }
.log-item .icon {
  width: 34px; height: 34px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 50%; background: var(--fill); color: var(--ink-2);
}
.log-item .icon svg { width: 16px; height: 16px; }
.log-item .icon.plus { color: var(--positive); }
.log-item .icon.minus { color: var(--negative); }
.log-item .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.log-item .what { font-weight: 600; overflow-wrap: anywhere; line-height: 1.3; }
.log-item .when { color: var(--muted); font-size: 0.84rem; }
.log-item .amount { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.log-item .amount.plus { color: var(--positive); }
.log-item .amount.minus { color: var(--ink); }

.log-item .delete, .wish-item .delete {
  width: 40px; min-width: 40px; min-height: 40px; padding: 0;
  background: transparent; color: #a6ada9; border: none;
}
.log-item .delete:hover, .wish-item .delete:hover { background: var(--fill); color: var(--negative); }
.log-item .delete svg, .wish-item .delete svg { width: 17px; height: 17px; }

/* =========================================================
   Modals
   ========================================================= */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(15, 22, 19, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade-in 0.18s ease;
}
.modal-backdrop[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  width: min(420px, 100%);
  max-height: 92vh; overflow-y: auto;
  box-shadow: 0 20px 50px rgba(15, 22, 19, 0.25);
  animation: modal-in 0.26s var(--ease);
}
.modal-wide { width: min(520px, 100%); }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.modal h2 { margin: 0 0 16px; font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }
.hint { color: var(--muted); font-size: 0.92rem; margin: -6px 0 14px; }
.hint strong { color: var(--ink-2); font-weight: 600; }
.hint code { background: var(--fill); padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }

.amount-display {
  text-align: center;
  font-size: 3.25rem; font-weight: 700;
  letter-spacing: -0.04em; line-height: 1;
  padding: 18px 0 26px;
  font-variant-numeric: tabular-nums;
}
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.keypad button {
  min-height: 60px;
  border: none; border-radius: var(--radius);
  background: var(--fill); color: var(--ink);
  font-family: inherit; font-size: 1.45rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 0.1s ease, transform 0.08s ease;
}
.keypad button:hover { background: var(--fill-hover); }
.keypad button:active { background: var(--line-strong); transform: scale(0.97); }
.keypad button:focus-visible { outline: none; box-shadow: var(--focus); }
.keypad button.btn { font-size: 0.98rem; font-weight: 700; min-height: 52px; background: transparent; border: 1px solid var(--line); color: var(--ink-2); }
.keypad button.btn:hover { background: var(--fill); }
.keypad button.wide { grid-column: span 2; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { flex: 1; min-height: 54px; }

.name-input {
  width: 100%; min-height: 54px;
  font-size: 1.05rem; font-family: inherit; font-weight: 600;
  padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  margin-bottom: 10px;
  background: var(--surface); color: var(--ink);
  caret-color: var(--brand);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#nameInput { margin-bottom: 18px; }
.name-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.confirm-body { font-size: 1rem; color: var(--ink-2); margin: -4px 0 22px; overflow-wrap: anywhere; }

.bulk-textarea {
  width: 100%; min-height: 160px; resize: vertical;
  padding: 12px 14px; margin-bottom: 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font: inherit; color: var(--ink); background: var(--surface);
}
.bulk-textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: var(--radius);
  font-weight: 600; font-size: 0.95rem;
  box-shadow: 0 8px 24px rgba(15, 22, 19, 0.25);
  z-index: 60; max-width: calc(100% - 32px);
  animation: toast-in 0.22s var(--ease);
}
.toast[hidden] { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; gap: 20px; }
}
@media (max-width: 560px) {
  .topbar { margin-bottom: 24px; }
  .panel { padding: 16px 16px 6px; }
  .wish-item { grid-template-columns: auto minmax(0, 1fr) auto; }
  .wish-item .delete { grid-column: 3; grid-row: 1; }
  .wish-item .goal-toggle { grid-column: 2 / -1; grid-row: 2; justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}

/* Optical alignment: quiet buttons at the right edge line up with content edges */
.data-actions { margin-right: -12px; }
.section-head > .btn-quiet:last-child,
.section-head > .add-gift-btn,
.wish-head-actions { margin-right: -12px; }
.card-top { height: 36px; }
@media (max-width: 560px) {
  .data-actions { margin: 0 0 0 -12px; }
}

/* ---------- Backup reminder ---------- */
.backup-note {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: -12px 0 28px;
  padding: 10px 10px 10px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.92rem; color: var(--ink-2);
}
.backup-note[hidden] { display: none; }
.backup-note strong { color: var(--ink); }
.backup-note.warn { border-color: #efc9bf; background: #fdf3f0; color: var(--negative); padding: 12px 16px; }
