:root {
  --bg: #f4f4f8;
  --card: #ffffff;
  --text: #1c1c28;
  --muted: #6b6b80;
  --line: #e4e4ee;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --good: #16a34a;
  --bad: #dc2626;
  --pending: #d97706;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14141c;
    --card: #1e1e2a;
    --text: #f0f0f6;
    --muted: #9a9ab0;
    --line: #30303f;
    --accent: #6d64ff;
    --accent-dark: #5b52f0;
  }
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

/* --- Top bar --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 700; font-size: 17px; }
.topbar-user { color: var(--muted); font-size: 14px; margin-right: 8px; }
.logout-form { display: flex; align-items: center; }

/* --- Layout --- */
.page { max-width: 560px; margin: 0 auto; padding: 16px; }
section { margin-bottom: 24px; }
h1 { font-size: 24px; margin-bottom: 8px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }
h3 { font-size: 16px; }
p { margin-bottom: 8px; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
hr { border: none; border-top: 1px solid var(--line); margin: 8px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; }

.banner { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-weight: 500; }
.banner.ok { background: rgba(22, 163, 74, 0.12); color: var(--good); }
.banner.bad { background: rgba(220, 38, 38, 0.12); color: var(--bad); }

/* --- Buttons & forms (big touch targets) --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dark); }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 40px; padding: 6px 14px; font-size: 14px; }
.btn.big { min-height: 54px; font-size: 17px; }
.btn.block { display: flex; width: 100%; margin-top: 4px; }
.btn:disabled { opacity: 0.45; cursor: default; }

input, select {
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
fieldset { border: none; }
legend { font-weight: 700; margin-bottom: 8px; }
.radio-row { display: flex; gap: 6px; flex-wrap: wrap; }
.radio-opt {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; min-height: 48px; cursor: pointer;
}
.radio-opt input { width: auto; min-height: 0; accent-color: var(--accent); }
.radio-opt:has(input:checked) { border-color: var(--accent); background: rgba(79, 70, 229, 0.08); }

details.card summary { font-weight: 600; cursor: pointer; min-height: 32px; display: flex; align-items: center; }

/* --- Auth --- */
.auth-wrap { max-width: 380px; margin: 8vh auto 0; }
.auth-logo { font-size: 56px; text-align: center; }
.auth-title { text-align: center; margin-bottom: 18px; }

/* --- Balance card --- */
.balance-card {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  border-radius: 18px;
  padding: 20px;
  text-align: center;
}
.balance-label { font-size: 14px; opacity: 0.85; }
.balance-amount { font-size: 44px; font-weight: 800; letter-spacing: -0.02em; }
.balance-amount.neg { color: #fecaca; }
.balance-note { font-size: 13px; opacity: 0.9; margin-bottom: 4px; }
.streak { font-size: 14px; opacity: 0.95; margin-top: 4px; }

/* --- Badges --- */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 6px; text-align: center; opacity: 0.38; filter: grayscale(1);
}
.badge.earned { opacity: 1; filter: none; border-color: var(--accent); }
.badge-icon { font-size: 26px; }
.badge-label { font-size: 11px; font-weight: 600; margin-top: 2px; }

/* --- Chore rows --- */
.chore {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px;
}
.chore-info { flex: 1; min-width: 0; }
.chore-name { font-weight: 600; font-size: 16px; }
.chore-meta { font-size: 13px; color: var(--muted); }
.chore-note { font-size: 13px; color: var(--pending); margin-top: 2px; }
.chore.approved { border-color: var(--good); }
.chore.pending { border-color: var(--pending); }
.chore.taken { opacity: 0.6; }

.pill {
  font-size: 13px; font-weight: 600; padding: 8px 12px; border-radius: 999px; white-space: nowrap;
}
.pill.pending { background: rgba(217, 119, 6, 0.14); color: var(--pending); }
.pill.approved { background: rgba(22, 163, 74, 0.14); color: var(--good); }
.pill.taken { background: var(--bg); color: var(--muted); }

/* --- Leaderboard --- */
.toggle { display: flex; gap: 6px; margin-bottom: 10px; }
.toggle-opt {
  flex: 1; text-align: center; padding: 10px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px;
  background: var(--card);
}
.toggle-opt.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.lb-row:last-child { border-bottom: none; }
.lb-row.me { font-weight: 700; }
.lb-rank { width: 32px; text-align: center; font-size: 20px; }
.lb-name { flex: 1; }
.lb-count { color: var(--muted); font-size: 14px; }

/* --- Approvals & kid cards (parent) --- */
.approval-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.approval-value { font-weight: 700; color: var(--good); font-size: 18px; white-space: nowrap; }
.kid-card { display: block; text-decoration: none; color: var(--text); }
.kid-card-top { display: flex; justify-content: space-between; align-items: baseline; }
.kid-name { font-weight: 700; font-size: 18px; }
.kid-balance { font-weight: 800; font-size: 22px; color: var(--good); }
.kid-balance.neg { color: var(--bad); }
.kid-card-hint { font-size: 13px; color: var(--accent); margin-top: 6px; font-weight: 600; }
.chore-admin { display: flex; align-items: center; gap: 10px; justify-content: space-between; }

/* --- History rows --- */
.hist-row { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.hist-row:last-child { border-bottom: none; }
.hist-icon { font-size: 20px; width: 28px; text-align: center; }
.hist-main { flex: 1; min-width: 0; }
.hist-date { font-size: 12px; color: var(--muted); }
.hist-amt { font-weight: 700; white-space: nowrap; }
.hist-amt.pos { color: var(--good); }
.hist-amt.neg { color: var(--bad); }

/* --- Bottom tab bar --- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.tab.on { color: var(--accent); }
.tab-icon { font-size: 22px; }
