:root {
  --purple: #6c5ce7;
  --purple-dark: #5a4bd4;
  --pink: #ff6b9d;
  --blue: #5b8def;
  --green: #3ec78f;
  --yellow: #ffc93c;
  --orange: #ff8c42;
  --ink: #2d2a4a;
  --muted: #8b88a8;
  --paper: #ffffff;
  --bg: #f3f0ff;
  --shadow: 0 10px 30px rgba(108, 92, 231, 0.18);
  --shadow-sm: 0 4px 14px rgba(108, 92, 231, 0.14);
  --radius: 22px;
}

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

html, body { margin: 0; padding: 0; }

body {
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #e8e2ff 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #ffe6f1 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
}

h1, h2, h3, .display { font-family: "Baloo 2", "Nunito", sans-serif; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(108, 92, 231, 0.1);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: none;
  cursor: pointer;
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: var(--purple);
}
.brand-star { font-size: 24px; filter: drop-shadow(0 2px 4px rgba(255,201,60,.6)); }
.parent-btn {
  border: 0;
  background: white;
  color: var(--ink);
  font-weight: 800;
  font-family: inherit;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  font-size: 15px;
}
.parent-btn:active { transform: scale(0.96); }

main { max-width: 880px; margin: 0 auto; padding: 22px 18px 80px; }
.loading { text-align: center; color: var(--muted); padding: 60px 0; font-weight: 700; }

/* ---------- Generic ---------- */
.page-title {
  font-size: 30px;
  margin: 6px 0 22px;
  text-align: center;
}
.subtitle { text-align: center; color: var(--muted); margin: -14px 0 24px; font-weight: 700; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  background: var(--purple);
  color: white;
  box-shadow: var(--shadow-sm);
  transition: transform .08s ease;
}
.btn:active { transform: scale(0.96); }
.btn.secondary { background: white; color: var(--purple); }
.btn.ghost { background: rgba(108,92,231,.08); color: var(--purple); box-shadow: none; }
.btn.danger { background: #ff5a6a; }
.btn.small { padding: 9px 14px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.row { display: flex; gap: 10px; align-items: center; }
.spread { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.back-link {
  background: none; border: 0; color: var(--purple); font-weight: 800;
  font-size: 16px; cursor: pointer; padding: 4px 0; margin-bottom: 6px;
}

/* ---------- Kid picker ---------- */
.kid-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
}
.kid-card {
  border: 0;
  cursor: pointer;
  background: white;
  border-radius: var(--radius);
  padding: 26px 14px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform .12s ease;
  position: relative;
  overflow: hidden;
}
.kid-card:active { transform: scale(0.97); }
.kid-card .ribbon {
  position: absolute; inset: 0 0 auto 0; height: 8px;
}
.kid-avatar {
  width: 92px; height: 92px; margin: 0 auto 12px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 50px;
  box-shadow: inset 0 0 0 5px rgba(255,255,255,.7);
}
.kid-name { font-family: "Baloo 2"; font-weight: 800; font-size: 20px; }
.kid-card .mini { color: var(--muted); font-weight: 700; font-size: 13px; margin-top: 4px; }

/* ---------- Kid dashboard ---------- */
.hero {
  display: flex; align-items: center; gap: 16px;
  background: white; border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.hero .kid-avatar { width: 72px; height: 72px; font-size: 40px; margin: 0; flex: none; }
.hero .who { font-family: "Baloo 2"; font-weight: 800; font-size: 24px; line-height: 1.1; }
.hero .points-pill {
  margin-left: auto; text-align: center; background: linear-gradient(135deg, var(--yellow), var(--orange));
  color: #5a3d00; padding: 10px 16px; border-radius: 18px; font-family: "Baloo 2"; font-weight: 800;
}
.points-pill .num { font-size: 26px; line-height: 1; display: block; }
.points-pill .lbl { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }

/* Date navigator on a kid's chart (today + retroactive fill-in). */
.date-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 2px 0 14px; }
.date-btn {
  border: 0; background: white; width: 46px; height: 46px; border-radius: 50%;
  box-shadow: var(--shadow-sm); font-size: 18px; cursor: pointer; color: var(--purple); font-weight: 800;
}
.date-btn:active { transform: scale(0.92); }
.date-btn:disabled { opacity: .35; cursor: not-allowed; }
.date-label {
  font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 18px;
  min-width: 150px; text-align: center; color: var(--page-text, var(--ink));
}
.retro-tag {
  display: inline-block; font-family: "Nunito", sans-serif; font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em; color: white; background: var(--orange);
  padding: 2px 8px; border-radius: 999px; vertical-align: middle; margin-left: 4px;
}
.today-jump { display: block; margin: -6px auto 16px; }

.progress-wrap { margin: 4px 0 22px; }
.progress-bar {
  height: 18px; background: rgba(108,92,231,.12); border-radius: 999px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--green), #7be0b0);
  transition: width .5s cubic-bezier(.2,.9,.3,1.3);
}
.progress-label { text-align: center; font-weight: 800; color: var(--muted); margin-top: 8px; }
.all-done-banner {
  text-align: center; background: linear-gradient(135deg, var(--green), #51d99a);
  color: white; padding: 14px; border-radius: 16px; font-family: "Baloo 2";
  font-weight: 800; font-size: 18px; margin-top: 12px; box-shadow: var(--shadow-sm);
}

.section-head { font-size: 20px; margin: 22px 0 12px; }

.chore-list { display: flex; flex-direction: column; gap: 12px; }
.chore {
  display: flex; align-items: center; gap: 14px;
  background: white; border-radius: 18px; padding: 14px 16px;
  box-shadow: var(--shadow-sm); cursor: pointer; border: 3px solid transparent;
  transition: transform .08s ease, border-color .15s ease;
  text-align: left; width: 100%; font: inherit; color: inherit;
}
.chore:active { transform: scale(0.99); }
.chore .c-icon {
  width: 50px; height: 50px; flex: none; border-radius: 14px;
  display: grid; place-items: center; font-size: 28px;
  background: var(--bg);
}
.chore .c-main { flex: 1; min-width: 0; }
.chore .c-title { font-weight: 800; font-size: 17px; }
.chore .c-pts { color: var(--orange); font-weight: 800; font-size: 14px; }
.chore .check {
  width: 36px; height: 36px; flex: none; border-radius: 50%;
  border: 3px solid rgba(108,92,231,.25); display: grid; place-items: center;
  font-size: 20px; color: transparent; transition: all .15s ease;
}
.chore.done { border-color: var(--green); background: #f1fdf7; }
.chore.done .c-title { text-decoration: line-through; color: var(--muted); }
.chore.done .check { background: var(--green); border-color: var(--green); color: white; }
.empty-note { color: var(--muted); font-weight: 700; text-align: center; padding: 24px; }

/* ---------- Prize shop ---------- */
.prize-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px;
}
.prize {
  background: white; border-radius: 18px; padding: 16px 12px; text-align: center;
  box-shadow: var(--shadow-sm); position: relative;
}
.prize .p-icon { font-size: 40px; }
.prize .p-title { font-weight: 800; margin: 6px 0 8px; }
.prize .p-cost {
  display: inline-block; background: linear-gradient(135deg, var(--yellow), var(--orange));
  color: #5a3d00; font-weight: 800; padding: 4px 12px; border-radius: 999px; font-size: 14px;
}
.prize.affordable { outline: 3px solid var(--green); outline-offset: -3px; }
.prize .p-redeem {
  margin-top: 10px; width: 100%;
}

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 8px; background: white; padding: 6px; border-radius: 999px;
  box-shadow: var(--shadow-sm); margin-bottom: 22px; overflow-x: auto; }
.tab {
  border: 0; background: none; padding: 10px 16px; border-radius: 999px;
  font-family: "Baloo 2"; font-weight: 700; font-size: 15px; cursor: pointer; color: var(--muted);
  white-space: nowrap;
}
.tab.active { background: var(--purple); color: white; }

.admin-card {
  background: white; border-radius: 18px; padding: 16px; box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
}
.admin-card .row.spread { gap: 12px; }
.admin-card .a-icon { font-size: 26px; }
.admin-card .a-title { font-weight: 800; font-size: 17px; }
.admin-card .a-sub { color: var(--muted); font-weight: 700; font-size: 13px; margin-top: 2px; }
.icon-actions { display: flex; gap: 6px; }
.icon-btn {
  border: 0; background: var(--bg); width: 38px; height: 38px; border-radius: 12px;
  cursor: pointer; font-size: 17px; display: grid; place-items: center;
}
.icon-btn:active { transform: scale(0.92); }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 800; margin-bottom: 6px; font-size: 14px; }
.field input, .field select {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 2px solid rgba(108,92,231,.18);
  font: inherit; font-weight: 700; background: #fbfaff; color: var(--ink);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--purple); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button {
  border: 2px solid transparent; background: var(--bg); border-radius: 12px;
  width: 42px; height: 42px; font-size: 22px; cursor: pointer;
}
.emoji-pick button.sel { border-color: var(--purple); background: white; }

.day-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.day-pick button {
  border: 2px solid rgba(108,92,231,.18); background: #fbfaff; border-radius: 10px;
  padding: 8px 10px; font-weight: 800; cursor: pointer; font-size: 13px; text-transform: capitalize;
  color: var(--muted);
}
.day-pick button.sel { border-color: var(--purple); background: var(--purple); color: white; }

.color-pick { display: flex; gap: 8px; flex-wrap: wrap; }
.color-pick button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid white; cursor: pointer; box-shadow: var(--shadow-sm); }
.color-pick button.sel { outline: 3px solid var(--ink); outline-offset: 2px; }

.add-bar { margin: 18px 0; }

/* ---------- PIN pad ---------- */
.pin-display { display: flex; gap: 12px; justify-content: center; margin: 18px 0 22px; }
.pin-dot { width: 18px; height: 18px; border-radius: 50%; background: rgba(108,92,231,.18); transition: background .1s; }
.pin-dot.on { background: var(--purple); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 280px; margin: 0 auto; }
.pin-key {
  border: 0; background: white; border-radius: 18px; padding: 18px; font-family: "Baloo 2";
  font-weight: 800; font-size: 24px; cursor: pointer; box-shadow: var(--shadow-sm); color: var(--ink);
}
.pin-key:active { transform: scale(0.94); }
.pin-key.wide { font-size: 16px; }
.pin-error { color: #ff5a6a; text-align: center; font-weight: 800; min-height: 22px; margin-top: 12px; }

/* ---------- Modal ---------- */
.modal-root { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; }
/* The author `display: grid` above overrides the `hidden` attribute's UA
   `display: none`, so re-assert it for the hidden state. */
.modal-root[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(45,42,74,.45); backdrop-filter: blur(3px); }
.modal-card {
  position: relative; background: white; border-radius: 26px; padding: 26px;
  width: 100%; max-width: 440px; box-shadow: var(--shadow); max-height: 88vh; overflow-y: auto;
  animation: pop .2s ease;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-x {
  position: absolute; top: 14px; right: 14px; border: 0; background: var(--bg);
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 16px; color: var(--muted);
}
.modal-card h2 { margin: 0 6px 16px 0; font-size: 24px; }

/* ---------- Toast & confetti ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: white; padding: 14px 22px; border-radius: 999px;
  font-weight: 800; z-index: 60; box-shadow: var(--shadow); animation: toastIn .25s ease;
  max-width: 90vw; text-align: center;
}
@keyframes toastIn { from { transform: translate(-50%, 20px); opacity: 0; } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; }

@media (max-width: 480px) {
  .brand-name { display: none; }
  .page-title { font-size: 26px; }
}

/* ============================ Per-kid themes ============================ */
/* Headings/labels that sit directly on the page background follow --page-text
   so they stay readable on dark themes. */
.section-head { color: var(--page-text, var(--ink)); }
.progress-label { color: var(--page-text, var(--muted)); }

/* Floating background decoration on a kid's chart. */
.theme-deco { position: fixed; inset: 0; pointer-events: none; z-index: -1; overflow: hidden; }
.theme-deco span {
  position: absolute; opacity: .2; filter: saturate(1.15);
  animation: floaty 7s ease-in-out infinite;
}
.theme-deco span:nth-child(even) { animation-duration: 9s; opacity: .16; }
@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-16px) rotate(8deg); }
}
@media (prefers-reduced-motion: reduce) { .theme-deco span { animation: none; } }

/* Little theme badge on the picker cards. */
.kid-theme-badge { position: absolute; top: 12px; right: 12px; font-size: 20px; }

/* Theme chooser in the parent's kid form. */
.theme-pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.theme-opt {
  display: flex; align-items: center; gap: 8px; cursor: pointer; font: inherit;
  font-weight: 800; color: var(--ink); border: 2px solid rgba(108, 92, 231, .18);
  background: #fbfaff; border-radius: 14px; padding: 10px 12px; text-align: left;
}
.theme-opt .theme-emoji { font-size: 22px; }
.theme-opt.sel { border-color: var(--purple); box-shadow: var(--shadow-sm); }
.theme-opt.theme-rainbow { background: linear-gradient(90deg, #ffe6f1, #e8e2ff); }
.theme-opt.theme-starwars { background: #11162a; color: #ffd54f; border-color: #2a3358; }
.theme-opt.theme-frozen { background: #eaf6ff; }
.theme-opt.theme-flowers { background: #fff0f6; }

/* ---- Star Wars: deep space, gold + saber-blue accents ---- */
body[data-theme="starwars"] {
  background:
    radial-gradient(2px 2px at 18% 28%, #fff, transparent),
    radial-gradient(1px 1px at 68% 58%, #fff, transparent),
    radial-gradient(1.6px 1.6px at 42% 82%, #fff, transparent),
    radial-gradient(1px 1px at 84% 22%, #cfe3ff, transparent),
    radial-gradient(2px 2px at 90% 70%, #fff, transparent),
    radial-gradient(900px 520px at 100% 0%, #1b2550 0%, transparent 60%),
    linear-gradient(180deg, #060a1a, #0d1430);
}
body[data-theme="starwars"] #app {
  --purple: #ffd54f; --purple-dark: #e6bb2c; --page-text: #eef2ff;
}
body[data-theme="starwars"] #app .btn { color: #1a1400; }

/* ---- Frozen: icy blues ---- */
body[data-theme="frozen"] {
  background:
    radial-gradient(1000px 520px at 10% -10%, #dff1ff 0%, transparent 60%),
    radial-gradient(820px 520px at 100% 0%, #ece6ff 0%, transparent 55%),
    linear-gradient(180deg, #f4fbff, #e7f3ff);
}
body[data-theme="frozen"] #app { --purple: #3aa0e0; --purple-dark: #2b86c4; }
body[data-theme="frozen"] #app .progress-fill { background: linear-gradient(90deg, #5ec2f0, #bfe9ff); }

/* ---- Flowers: pinks + greens ---- */
body[data-theme="flowers"] {
  background:
    radial-gradient(1000px 520px at 10% -10%, #ffe3f0 0%, transparent 60%),
    radial-gradient(820px 520px at 100% 0%, #e6ffe9 0%, transparent 55%),
    linear-gradient(180deg, #fff5fa, #f3fff4);
}
body[data-theme="flowers"] #app { --purple: #ff5fa2; --purple-dark: #e84d8e; }
