:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #23262b;
  --muted: #8b909a;
  --line: #ece9e2;
  --gold: #f2c14e;
  --gold-ink: #7a5b12;
  --green: #3c9d6f;
  --red: #e05656;
  --dad: #5b8def;
  --mom: #e76ba9;
  --surface-muted: #f3f1eb;
  --input: #ffffff;
  --primary: #23262b;
  --on-primary: #ffffff;
  --danger-bg: #fdf1f1;
  --danger-line: #f8dddd;
  --topbar-bg: rgba(246, 243, 236, 0.82);
  --topbar-line: rgba(236, 233, 226, 0.9);
  --toast: #23262b;
  --on-toast: #ffffff;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow-card: 0 1px 2px rgba(35, 38, 43, 0.04), 0 10px 28px rgba(35, 38, 43, 0.06);
  --shadow-pop: 0 4px 12px rgba(35, 38, 43, 0.1), 0 24px 60px rgba(35, 38, 43, 0.16);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1118;
  --card: #171d27;
  --ink: #edf1f7;
  --muted: #9da8b8;
  --line: #2c3543;
  --gold: #ffd166;
  --gold-ink: #2d240c;
  --green: #70d6a3;
  --red: #ff9a9a;
  --surface-muted: #202836;
  --input: #111722;
  --primary: #ffd166;
  --on-primary: #2d240c;
  --danger-bg: #37212a;
  --danger-line: #653646;
  --topbar-bg: rgba(13, 17, 24, 0.88);
  --topbar-line: rgba(44, 53, 67, 0.9);
  --toast: #edf1f7;
  --on-toast: #171d27;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.03), 0 14px 30px rgba(0, 0, 0, 0.28);
  --shadow-pop: 0 8px 22px rgba(0, 0, 0, 0.38), 0 30px 72px rgba(0, 0, 0, 0.5);
}

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

html {
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1000px 480px at 50% -120px, rgba(242, 193, 78, 0.12), transparent 70%),
    radial-gradient(900px 400px at 108% -40px, rgba(91, 141, 239, 0.06), transparent 60%),
    var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  padding-bottom: 40px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
:root[data-theme="dark"] body {
  background:
    radial-gradient(900px 480px at 50% -160px, rgba(245, 201, 90, 0.09), transparent 70%),
    radial-gradient(700px 400px at 110% -80px, rgba(91, 141, 239, 0.11), transparent 65%),
    var(--bg);
}

.wrap { max-width: 640px; margin: 0 auto; padding: 18px 18px 40px; }

h1 { font-size: 22px; letter-spacing: -0.02em; }
h2 {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 12px;
}
.muted { color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px;
  margin-bottom: 14px;
}

button, input, select {
  font-family: inherit;
  font-size: 16px;
}

button {
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  transition: transform 0.06s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

button:active { transform: scale(0.97); }
button.primary {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 6px 16px rgba(35, 38, 43, 0.16);
}
button.primary:active { box-shadow: 0 2px 6px rgba(35, 38, 43, 0.16); }
button.ghost {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(35, 38, 43, 0.04);
}
button.danger {
  background: var(--danger-bg);
  color: var(--red);
  border: 1px solid var(--danger-line);
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  background: var(--input);
  box-shadow: inset 0 1px 2px rgba(35, 38, 43, 0.03);
}
input:focus, select:focus {
  outline: none;
  border-color: #c9c4b8;
  box-shadow: 0 0 0 3px rgba(242, 193, 78, 0.3);
}

button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.hidden { display: none !important; }

/* top bar */
.topbar {
  position: sticky;
  top: 0;
  top: env(safe-area-inset-top);
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  background: var(--topbar-bg);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--topbar-line);
}
#whoBadge { background: var(--surface-muted) !important; color: var(--ink); }
.topbar .title { font-weight: 800; font-size: 19px; letter-spacing: -0.02em; white-space: nowrap; }
.topbar .link { color: var(--muted); font-size: 14px; text-decoration: none; font-weight: 700; }
.topbar .link:active { color: var(--ink); }
.header-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.theme-toggle {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  box-shadow: none;
  font-size: 19px;
  line-height: 1;
}

/* balances / kid cards */
.kids-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
#pickerGrid, #balanceGrid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}
#pickerGrid .kid-card, #balanceGrid .kid-card {
  flex: 0 1 172px;
  width: min(172px, calc(50% - 6px));
}
#picker { text-align: center; }
#picker h2 { text-align: center; }
.kid-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.kid-card:active { transform: scale(0.96); }
.kid-card:hover { transform: translateY(-2px); }
.kid-card.active {
  border-color: var(--c, var(--dad));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c, var(--dad)) 20%, transparent);
}
.kid-card .emoji {
  font-size: 26px;
  width: 50px;
  height: 50px;
  line-height: 50px;
  margin: 0 auto;
  border-radius: 16px;
  background: color-mix(in srgb, var(--c, var(--dad)) 13%, var(--card));
}
.avatar-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  border-radius: inherit;
}
.image-avatar { background: transparent !important; }
.kid-card .name { font-weight: 700; margin-top: 8px; font-size: 14px; }
.kid-card .pts { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* task grid (award) */
.task-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.task-btn {
  text-align: left;
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(35, 38, 43, 0.03);
  padding: 13px;
  border-radius: 16px;
  font-weight: 600;
}
.task-btn:active { border-color: color-mix(in srgb, var(--gold) 60%, var(--line)); }
.task-btn .t-emoji {
  font-size: 19px;
  width: 40px;
  height: 40px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: color-mix(in srgb, var(--gold) 26%, var(--card));
}
.task-btn .t-title { flex: 1; min-width: 0; font-size: 14px; line-height: 1.25; color: var(--ink); }
.task-btn .t-pts {
  background: var(--gold);
  color: var(--gold-ink);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.management-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}
.management-actions button { padding: 12px; }

.pts-pill {
  background: var(--gold);
  color: var(--gold-ink);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  flex: none;
}

/* goals */
.goal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.goal-item:last-child { border-bottom: none; }
.goal-item .g-emoji {
  font-size: 19px;
  width: 42px;
  height: 42px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 13px;
  background: color-mix(in srgb, var(--gold) 22%, var(--card));
}
.goal-item .g-body { flex: 1; min-width: 0; }
.goal-item .g-title { font-size: 14px; font-weight: 650; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.goal-item .g-meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.goal-bar { height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--line) 80%, var(--card)); overflow: hidden; margin-top: 6px; }
.goal-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f2c14e, #e59b2e);
  transition: width 0.3s ease;
}
.goal-ready-badge {
  background: color-mix(in srgb, var(--gold) 30%, var(--card));
  color: var(--gold-ink);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 800;
}
.redeem-btn { flex: none; padding: 9px 14px; font-size: 13px; font-weight: 700; }
.redeem-btn:disabled { opacity: 0.4; box-shadow: none; }

.goal-manager-item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 72px auto auto;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.goal-manager-item:last-child { border-bottom: none; }
.goal-manager-item .h-emoji { margin: 0; }
.goal-cost-control input {
  min-width: 0;
  height: 40px;
  padding: 8px;
  text-align: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.goal-save-btn { padding: 10px 11px; font-size: 13px; }
.icon-btn { padding: 9px 11px; font-size: 15px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* history */
.hist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.hist-item:last-child { border-bottom: none; }
.hist-item .h-emoji {
  font-size: 17px;
  width: 36px;
  height: 36px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--line) 55%, var(--card));
  border-radius: 11px;
}
.hist-item .h-body { flex: 1; min-width: 0; }
.hist-item .h-title { font-size: 14px; font-weight: 650; }
.hist-item .h-meta { font-size: 12px; color: var(--muted); }
.hist-item .h-pts { font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.hist-item .h-pts.pos { color: var(--green); }
.hist-item .h-pts.neg { color: var(--red); }
.undo-btn {
  flex: none;
  padding: 7px 10px;
  font-size: 12px;
}

/* forms */
.row { margin-bottom: 12px; }
.row label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}
.row-inline { display: flex; gap: 8px; }
.row-inline > * { flex: 1; }

/* modal / pin */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(35, 38, 43, 0.45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  overflow-y: auto;
}
.modal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 24px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow-pop);
}
.modal h2 {
  text-transform: none;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 8px;
}
.modal .pin-input { font-size: 28px; text-align: center; letter-spacing: 10px; font-weight: 700; }
.modal .actions { display: flex; gap: 8px; margin-top: 16px; }
.modal .actions > * { flex: 1; }

.big-balance {
  font-size: 60px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  text-align: center;
  margin: 6px 0 2px;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
}

/* kid dashboard scoreboard */
.split { display: flex; gap: 10px; margin-top: 16px; }
.split-box {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  text-align: center;
  background: color-mix(in srgb, var(--splitc, var(--dad)) 7%, var(--card));
}
.split-box .icon { font-size: 22px; }
.split-box .who { font-size: 12px; color: var(--muted); }
.split-box .pts { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  bottom: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast);
  color: var(--on-toast);
  padding: 13px 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  z-index: 100;
  box-shadow: var(--shadow-pop);
  animation: pop 0.2s ease;
  white-space: nowrap;
}
@keyframes pop { from { transform: translate(-50%, 10px); opacity: 0; } }

@media (min-width: 700px) {
  .task-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kids-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  .topbar { padding-left: 28px; padding-right: 28px; }
  .wrap { padding-left: 24px; padding-right: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}