:root {
  --bg: #fff8ef;
  --card: #ffffff;
  --ink: #2d3047;
  --muted: #7a7f9a;
  --line: #f0e6d8;
  --primary: #6c5ce7;
  --primary-ink: #ffffff;
  --good: #20bf6b;
  --bad: #eb3b5a;
  --warn: #f7b731;
  --star: #ffb400;
  --radius: 20px;
  --shadow: 0 6px 0 rgba(45, 48, 71, .08), 0 10px 30px rgba(45, 48, 71, .06);
  /* chart (validated for colour-blind safety against the card surface) */
  --earned: #2a78d6;
  --lost: #e34948;
  --c-grid: #ecebe6;
  --c-axis: #c3c2b7;
  --c-wash: rgba(108, 92, 231, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1c2b; --card: #262840; --ink: #f4f1ff; --muted: #a9acc7; --line: #34365a;
    --shadow: 0 6px 0 rgba(0,0,0,.25), 0 10px 30px rgba(0,0,0,.25);
    --earned: #3987e5; --lost: #e66767; --c-grid: #33355a; --c-axis: #4a4d78; --c-wash: rgba(255,255,255,.06);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 17px;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* --- top bar --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
  background: var(--primary); color: #fff;
}
.brand { font-weight: 700; font-size: 1.3rem; text-decoration: none; white-space: nowrap; }
#topnav { display: flex; gap: 8px; }

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 80px; }
h1 { font-size: 2rem; margin: 0 0 8px; }
h2 { font-size: 1.4rem; margin: 28px 0 12px; }
.sub { color: var(--muted); margin: 0 0 24px; }

/* --- buttons --- */
.btn {
  border: 0; border-radius: 14px; padding: 10px 18px; cursor: pointer;
  font-weight: 600; background: var(--line); color: var(--ink);
  box-shadow: 0 3px 0 rgba(0,0,0,.12); transition: transform .08s;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.12); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.good { background: var(--good); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn.ghost { background: rgba(255,255,255,.18); color: #fff; box-shadow: none; }
.btn.small { padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn.big { padding: 14px 24px; font-size: 1.15rem; }

/* --- cards / grids --- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.kids { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

.kid-card {
  text-align: center; text-decoration: none; cursor: pointer; border: 4px solid transparent;
  transition: transform .15s;
}
.kid-card:hover { transform: translateY(-4px) rotate(-1deg); }
.avatar {
  width: 96px; height: 96px; border-radius: 50%;
  display: grid; place-items: center; font-size: 56px; margin: 0 auto 10px;
}
.kid-card .name { font-size: 1.4rem; font-weight: 700; }
.points-pill {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px;
  background: #fff3cd; color: #8a5a00; border-radius: 999px; padding: 4px 14px; font-weight: 700;
}
.badge { background: var(--bad); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: .8rem; font-weight: 600; }

/* --- kid page hero --- */
.hero {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 24px; border-radius: 28px; color: #fff; margin-bottom: 8px;
}
.hero .avatar { width: 110px; height: 110px; font-size: 64px; background: rgba(255,255,255,.3); margin: 0; }
.hero .big-points { font-size: 3.4rem; font-weight: 700; line-height: 1; }
.hero .label { opacity: .9; }

/* --- prize card --- */
.prize { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.prize .img {
  aspect-ratio: 4/3; background: var(--line); display: grid; place-items: center; font-size: 64px; overflow: hidden;
}
.prize .img img { width: 100%; height: 100%; object-fit: cover; }
.prize .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.prize .title { font-weight: 700; font-size: 1.15rem; }
.prize .desc { color: var(--muted); font-size: .95rem; }
.prize .cost { font-weight: 700; color: #c27c00; }
.prize.locked .img { filter: grayscale(.7); opacity: .7; }
.progress { height: 12px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--star), #ff7f50); border-radius: 99px; }
.spacer { flex: 1; }
.tag { display: inline-block; font-size: .8rem; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--muted); }

/* --- lists --- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.plus { color: var(--good); font-weight: 700; min-width: 56px; }
.minus { color: var(--bad); font-weight: 700; min-width: 56px; }
.when { color: var(--muted); font-size: .85rem; margin-left: auto; white-space: nowrap; }
.status { font-size: .85rem; font-weight: 600; padding: 2px 10px; border-radius: 99px; }
.status.pending { background: #fff3cd; color: #8a5a00; }
.status.approved { background: #d4f5e2; color: #137a44; }
.status.rejected { background: #fde2e7; color: #a3203a; }

/* --- tabs --- */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.tabs .btn.active { background: var(--primary); color: #fff; }

/* --- parent kid rows --- */
.kid-row { display: flex; flex-direction: column; gap: 14px; }
.kid-row .head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.kid-row .avatar { width: 64px; height: 64px; font-size: 38px; margin: 0; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --- forms --- */
label { display: block; font-weight: 600; margin: 12px 0 6px; }
input[type=text], input[type=number], input[type=password], textarea, select {
  width: 100%; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg);
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button { font-size: 28px; width: 48px; height: 48px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); cursor: pointer; }
.emoji-pick button.sel { border-color: var(--primary); background: #ece9ff; }
.color-pick { display: flex; gap: 8px; flex-wrap: wrap; }
.color-pick button { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.color-pick button.sel { border-color: var(--ink); }
.preview-img { width: 100%; max-height: 200px; object-fit: contain; border-radius: 12px; margin-top: 8px; background: var(--line); }

/* --- modal --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 20, 40, .5); z-index: 50;
  display: grid; place-items: center; padding: 16px; animation: fade .15s;
}
.modal { width: min(480px, 100%); max-height: 90vh; overflow: auto; animation: pop .2s; }
.modal h3 { margin: 0 0 8px; font-size: 1.4rem; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }

.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.pin-pad button { font-size: 1.6rem; padding: 14px 0; border-radius: 16px; border: 0; background: var(--line); cursor: pointer; font-weight: 600; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 12px 0; min-height: 22px; }
.pin-dots span { width: 18px; height: 18px; border-radius: 50%; background: var(--primary); }

/* --- toast & celebration --- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px);
  background: var(--ink); color: var(--bg); padding: 12px 22px; border-radius: 14px; z-index: 60;
  font-weight: 600; transition: transform .25s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); color: #fff; }
.confetti { position: fixed; top: -20px; font-size: 28px; z-index: 70; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .icon { font-size: 56px; }

@media (max-width: 600px) {
  h1 { font-size: 1.6rem; }
  .hero .big-points { font-size: 2.6rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .when { display: none; }
}

/* --- progress chart --- */
.c-controls { margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--line); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: .9rem; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .key { margin-right: 0; }
.key.earned { background: var(--earned); }
.key.lost { background: var(--lost); }

.progress-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--bg); border-radius: 14px; padding: 10px 12px; min-width: 0; }
.t-label { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.t-sub { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-grid .t-value { font-size: 1.2rem; }

.chart { position: relative; width: 100%; min-width: 0; overflow: hidden; }
.chart svg { display: block; max-width: 100%; touch-action: pan-y; }
.c-grid { stroke: var(--c-grid); stroke-width: 1; }
.c-base { stroke: var(--c-axis); stroke-width: 1; }
.c-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.c-today { fill: var(--ink); font-weight: 600; }
.c-value { fill: var(--ink); font-size: 12px; font-weight: 600; }
.c-earned { fill: var(--earned); }
.c-lost { fill: var(--lost); }
.c-hover { fill: var(--c-wash); }
.c-hit { cursor: crosshair; }
.c-tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 140px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.15); font-size: .9rem; line-height: 1.5;
}
.c-tip .t-net { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; font-weight: 600; }
.c-table { margin-top: 8px; font-size: .9rem; }
.c-table summary { cursor: pointer; color: var(--muted); }
.c-table table { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.c-table th, .c-table td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.c-table th:first-child, .c-table td:first-child { text-align: left; }

@media (max-width: 600px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .progress-grid { grid-template-columns: 1fr; }
  .legend { width: 100%; }
}

.progress-card { min-width: 0; }

/* --- stars date bar (back-dating) --- */
.date-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; margin-bottom: 16px; border: 2px solid transparent; }
.date-bar.backdated { border-color: var(--warn); }
.date-label { font-weight: 600; }
.date-bar input[type=date] { padding: 6px 10px; border-radius: 10px; border: 2px solid var(--line); background: var(--bg); color-scheme: light dark; }
.date-note { color: var(--ink); }
