:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #1e2235;
  --muted: #7a819b;
  --primary: #6c5ce7;
  --primary-dark: #5a4bd4;
  --green: #16a37a;
  --red: #e5484d;
  --amber: #f2a33c;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(30, 34, 53, 0.08);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Nunito", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

#app { max-width: 760px; margin: 0 auto; padding: 20px 16px 60px; }

.view { animation: fadein 0.25s ease; }
.hidden { display: none !important; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- loading ---------- */
#view-loading { display: flex; justify-content: center; padding-top: 30vh; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid #e3e5f0; border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- auth ---------- */
.auth-card {
  max-width: 380px; margin: 8vh auto 0; text-align: center;
  background: var(--card); border-radius: 24px; padding: 36px 28px;
  box-shadow: var(--shadow);
}
.auth-logo { font-size: 64px; line-height: 1; margin-bottom: 12px; }
.auth-card h1 { font-size: 30px; margin-bottom: 6px; }
.auth-sub { color: var(--muted); margin-bottom: 22px; }
.big-input {
  width: 100%; padding: 15px 18px; font-size: 18px; border: 2px solid #e3e5f0;
  border-radius: 14px; margin-bottom: 14px; text-align: center; color: var(--ink);
  background: #fbfbfe; outline: none; transition: border-color 0.15s;
}
.big-input:focus { border-color: var(--primary); }
.pin-input { letter-spacing: 12px; font-size: 26px; font-weight: 700; }

/* ---------- buttons ---------- */
.btn {
  border: none; border-radius: 13px; padding: 12px 20px; font-size: 15px;
  font-weight: 700; cursor: pointer; font-family: inherit;
  transition: transform 0.06s, opacity 0.15s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eef0fa; color: var(--ink); }
.btn-danger { background: #fdecec; color: var(--red); }
.btn-ghost { background: none; color: var(--muted); margin-top: 18px; }
.btn-ghost:hover { color: var(--ink); }
.big-btn { width: 100%; padding: 15px; font-size: 17px; }
.btn:disabled { opacity: 0.55; cursor: default; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 2px 18px;
}
.brand { font-size: 22px; font-weight: 800; }
.kid-topbar .brand { font-size: 19px; }

/* ---------- summary ---------- */
.summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 26px;
}
.stat {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat-value.green { color: var(--green); }

/* ---------- sections ---------- */
.section { margin-bottom: 30px; }
.section-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.section h2 { font-size: 19px; }

/* ---------- kid cards ---------- */
.kid-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.kid-card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); cursor: pointer; text-align: left;
  border: 2px solid transparent; transition: transform 0.1s, border-color 0.15s;
  font-family: inherit;
}
.kid-card:hover { transform: translateY(-3px); border-color: var(--kid-color, var(--primary)); }
.kid-card .avatar {
  width: 52px; height: 52px; border-radius: 16px; display: flex;
  align-items: center; justify-content: center; font-size: 28px;
  background: var(--kid-soft, #eef0fa); margin-bottom: 12px;
}
.kid-card .name { font-size: 17px; font-weight: 800; }
.kid-card .balance { font-size: 24px; font-weight: 800; margin-top: 4px; color: var(--green); }
.kid-card .balance.neg { color: var(--red); }

/* ---------- kid hero (big balance) ---------- */
.kid-hero {
  border-radius: 24px; padding: 34px 24px; text-align: center; color: #fff;
  background: linear-gradient(135deg, var(--hero-a, #6c5ce7), var(--hero-b, #a29bfe));
  box-shadow: var(--shadow); margin-bottom: 26px;
}
.kid-hero-label { font-size: 15px; opacity: 0.9; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.kid-hero-amount { font-size: 52px; font-weight: 800; margin: 6px 0; }
.kid-hero-sub { opacity: 0.9; font-size: 15px; }

/* ---------- transactions ---------- */
.tx-list { display: flex; flex-direction: column; gap: 10px; }
.tx-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: 14px; padding: 14px 16px;
  box-shadow: var(--shadow);
}
.tx-icon {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.tx-icon.credit { background: #e5f6ef; }
.tx-icon.debit { background: #fdecec; }
.tx-info { flex: 1; min-width: 0; }
.tx-note { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-date { color: var(--muted); font-size: 13px; }
.tx-amount { font-weight: 800; font-size: 17px; white-space: nowrap; }
.tx-amount.credit { color: var(--green); }
.tx-amount.debit { color: var(--red); }
.tx-del {
  background: none; border: none; color: #c9cddd; cursor: pointer;
  font-size: 17px; padding: 4px; border-radius: 8px;
}
.tx-del:hover { color: var(--red); background: #fdecec; }

.empty {
  text-align: center; color: var(--muted); padding: 30px 10px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* ---------- recurring ---------- */
.recurring-list { display: flex; flex-direction: column; gap: 10px; }
.rec-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: 14px; padding: 14px 16px;
  box-shadow: var(--shadow);
}
.rec-row.off { opacity: 0.55; }
.rec-info { flex: 1; min-width: 0; }
.rec-title { font-weight: 700; }
.rec-meta { color: var(--muted); font-size: 13px; }
.rec-amount { font-weight: 800; color: var(--green); white-space: nowrap; }
.rec-actions { display: flex; gap: 6px; }
.icon-btn {
  background: #eef0fa; border: none; border-radius: 10px; width: 36px; height: 36px;
  cursor: pointer; font-size: 16px; line-height: 1;
}
.icon-btn:hover { background: #e2e5f5; }

/* ---------- kid picker ---------- */
.kid-picker { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-bottom: 10px; }
.kid-pick {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--card); border: 2px solid #e3e5f0; border-radius: 16px;
  padding: 14px 18px; cursor: pointer; font-family: inherit; min-width: 96px;
}
.kid-pick:hover, .kid-pick.selected { border-color: var(--primary); }
.kid-pick .p-emoji { font-size: 32px; }
.kid-pick .p-name { font-weight: 700; }

/* ---------- settings ---------- */
.settings-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- modal ---------- */
.modal-host { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 22, 40, 0.5); }
.modal {
  position: relative; background: var(--card); width: 100%; max-width: 480px;
  border-radius: 22px 22px 0 0; padding: 26px 22px 34px; max-height: 88vh; overflow-y: auto;
  animation: slideup 0.22s ease;
}
@media (min-width: 560px) {
  .modal-host { align-items: center; }
  .modal { border-radius: 22px; }
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.modal h3 { font-size: 20px; margin-bottom: 18px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.field input, .field select {
  width: 100%; padding: 12px 14px; font-size: 16px; border: 2px solid #e3e5f0;
  border-radius: 12px; background: #fbfbfe; color: var(--ink); outline: none;
  font-family: inherit;
}
.field input:focus, .field select:focus { border-color: var(--primary); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; padding: 10px; border-radius: 11px; border: 2px solid #e3e5f0;
  background: #fbfbfe; font-weight: 700; cursor: pointer; font-family: inherit; color: var(--ink);
}
.seg button.active { border-color: var(--primary); background: #f0edff; color: var(--primary); }
.emoji-row { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-row button {
  font-size: 24px; width: 48px; height: 48px; border-radius: 12px;
  border: 2px solid #e3e5f0; background: #fbfbfe; cursor: pointer;
}
.emoji-row button.active { border-color: var(--primary); background: #f0edff; }
.color-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-row button {
  width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent;
  cursor: pointer;
}
.color-row button.active { border-color: var(--ink); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 13px 22px; border-radius: 13px;
  font-weight: 700; z-index: 100; box-shadow: var(--shadow); max-width: 88vw;
  animation: fadein 0.2s ease;
}

/* responsive niceties */
@media (max-width: 420px) {
  .kid-hero-amount { font-size: 42px; }
  .stat-value { font-size: 22px; }
}
