/* StarJar — playful & colorful, mobile-first. No external fonts (works offline). */

:root {
  --bg1: #fff7ed;
  --bg2: #faf0ff;
  --ink: #2b2240;
  --dim: #8a83a0;
  --card: #ffffff;
  --line: #efeaf7;
  --primary: #6c5ce7;
  --primary-d: #5a48d6;
  --credit: #14b86a;
  --credit-bg: #e7faf0;
  --debit: #f0466b;
  --debit-bg: #ffecf1;
  --gold: #f5a623;
  --gold-2: #ffd23f;
  --warn: #ff8a3d;
  --danger: #e23b53;
  --radius: 18px;
  --shadow: 0 6px 20px rgba(80, 60, 140, 0.10);
  --shadow-sm: 0 2px 8px rgba(80, 60, 140, 0.08);
  --maxw: 520px;
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---- top bar ---- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-top, 0));
  background: linear-gradient(135deg, var(--primary), #8a6cf0);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.brand-logo { font-size: 22px; filter: drop-shadow(0 2px 2px rgba(0,0,0,.15)); }
.brand-name { font-size: 20px; letter-spacing: .2px; }
.brand-tag { font-size: 12px; opacity: .9; font-weight: 600; }

/* ---- layout ---- */
#app { max-width: var(--maxw); margin: 0 auto; padding: 14px 14px calc(var(--nav-h) + 28px); }
.screen { display: flex; flex-direction: column; gap: 14px; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.screen-h { margin: 2px 2px; font-size: 22px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-actions { display: flex; gap: 10px; }
.row-actions.wrap { flex-wrap: wrap; }

/* ---- goal jar ---- */
.jar {
  background: linear-gradient(135deg, #fff, #fffdf6);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.jar.nogoal { cursor: pointer; }
.jar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 700; }
.jar-title { font-size: 16px; }
.jar-count { font-variant-numeric: tabular-nums; color: var(--gold); }
.jar-count.neg { color: var(--debit); }
.jar-track {
  position: relative; height: 26px; margin-top: 10px; border-radius: 14px;
  background: repeating-linear-gradient(45deg, #f3eefb, #f3eefb 8px, #eee6fb 8px, #eee6fb 16px);
  overflow: hidden; border: 1px solid var(--line);
}
.jar-fill {
  height: 100%; border-radius: 14px;
  background: linear-gradient(90deg, var(--gold-2), var(--gold));
  box-shadow: inset 0 -6px 10px rgba(0,0,0,.06);
  transition: width .5s cubic-bezier(.2,.8,.2,1);
}
.jar-pct {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #6b4e00; text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
.link { color: var(--primary); font-weight: 700; }

.pool {
  text-align: center; font-weight: 700; color: var(--dim);
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px;
}
.pool b { color: var(--gold); font-size: 18px; }
.pool b.neg, .neg { color: var(--debit); }

/* ---- kid tabs ---- */
.kid-tabs { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.kid-tab {
  flex: 1 0 auto; min-width: 96px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 10px 8px;
  cursor: pointer; transition: transform .12s, border-color .12s; font: inherit; color: inherit;
}
.kid-tab:active { transform: scale(.96); }
.kid-tab.active { border-color: var(--primary); box-shadow: var(--shadow); }
.kid-emoji { font-size: 28px; }
.kid-name { font-weight: 700; font-size: 14px; }
.kid-bal { font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

.scoring-for { font-size: 16px; color: var(--dim); margin: 0; font-weight: 700; }
.scoring-for b { color: var(--ink); }

/* ---- task rows (scoring) ---- */
.task-list, .card-list { display: flex; flex-direction: column; gap: 10px; }
.task-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--credit);
  border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow-sm);
}
.task-row.neg { border-left-color: var(--debit); }
.task-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.task-emoji { font-size: 26px; flex: 0 0 auto; }
.task-text { display: flex; flex-direction: column; min-width: 0; }
.task-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.task-meta { font-size: 12px; color: var(--dim); }
.task-meta .cnt { color: var(--credit); }
.task-btns { display: flex; gap: 8px; flex: 0 0 auto; }
.tbtn {
  border: none; border-radius: 12px; padding: 10px 12px; font-weight: 800; font-size: 14px;
  cursor: pointer; min-width: 56px; transition: transform .1s; font-variant-numeric: tabular-nums;
}
.tbtn:active { transform: scale(.9); }
.tbtn.credit { background: var(--credit-bg); color: var(--credit); }
.tbtn.debit { background: var(--debit-bg); color: var(--debit); }
.tbtn.credit.primary { background: var(--credit); color: #fff; }
.tbtn.debit.primary { background: var(--debit); color: #fff; }

/* ---- task cards (manage) ---- */
.tcard {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
  box-shadow: var(--shadow-sm);
}
.tcard .task-text { flex: 1; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-weight: 800; font-size: 11px; }
.pill.positive { background: var(--credit-bg); color: var(--credit); }
.pill.negative { background: var(--debit-bg); color: var(--debit); }
.card-btns { display: flex; gap: 4px; }
.archived-card { opacity: .7; }

/* ---- buttons ---- */
.btn {
  border: none; border-radius: 12px; padding: 11px 14px; font-weight: 800; font-size: 14px;
  cursor: pointer; font: inherit; font-weight: 800; transition: transform .1s, filter .1s; color: var(--ink);
  background: #f1edfb;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.03); }
.btn.ghost { background: #fff; border: 1.5px solid var(--line); }
.btn.bonus { background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: #5b4300; }
.btn.warn { background: #fff3e8; color: var(--warn); border: 1.5px solid #ffe0c4; }
.btn.danger { background: #fdeaed; color: var(--danger); }
.btn.wide { width: 100%; }
.btn.big { padding: 14px; font-size: 16px; }
.btn.tiny { padding: 6px 10px; font-size: 12px; border-radius: 10px; }
.btn.done { background: var(--credit-bg); color: var(--credit); }
.icon-btn {
  border: none; background: #f6f3fd; border-radius: 10px; padding: 7px 9px; font-size: 15px; cursor: pointer;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn.rev { background: #fff3e8; }

/* ---- empty state ---- */
.empty { text-align: center; padding: 36px 16px; color: var(--dim); }
.empty-emoji { font-size: 48px; }
.empty h3 { margin: 10px 0 4px; color: var(--ink); }
.empty p { margin: 0 0 14px; }

/* ---- redeem ---- */
.redeem-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.fld { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 14px; }
.fld small { color: var(--dim); font-weight: 600; }
.fld input, .fld textarea, .fld select {
  font: inherit; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
}
.fld input:focus, .fld textarea:focus, .fld select:focus { outline: none; border-color: var(--primary); }
.emoji-input { font-size: 22px; text-align: center; max-width: 90px; }
.hint { font-size: 12px; color: var(--dim); margin: 2px 0 0; font-weight: 600; }
.form-err { color: var(--debit); font-size: 13px; font-weight: 700; min-height: 0; }
.link-chip {
  background: #f1edfb; border-radius: 12px; padding: 8px 12px; font-size: 13px; display: flex; align-items: center; gap: 6px;
}
.chip-x { margin-left: auto; border: none; background: transparent; cursor: pointer; font-weight: 800; color: var(--dim); }

/* ---- split confirm ---- */
.split { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.split-row, .split-total { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 10px; background: #faf8ff; }
.split-total { border-top: 1.5px dashed var(--line); background: transparent; font-weight: 800; }
.debit { color: var(--debit); font-weight: 800; }
.credit { color: var(--credit); font-weight: 800; }

/* ---- history ---- */
.hist { display: flex; flex-direction: column; gap: 8px; }
.hist-date { font-weight: 800; color: var(--dim); font-size: 13px; margin-top: 8px; padding-left: 4px; }
.hist-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; box-shadow: var(--shadow-sm);
}
.hist-row.is-reversed { opacity: .55; }
.hist-row.is-reversed .hist-desc { text-decoration: line-through; }
.hist-kid { font-size: 22px; }
.hist-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.hist-desc { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.hist-meta { font-size: 11px; color: var(--dim); }
.hist-meta i { color: var(--warn); font-style: normal; font-weight: 700; }
.src { text-transform: capitalize; font-weight: 700; }
.src.task { color: var(--primary); }
.src.adjustment { color: var(--gold); }
.src.redemption { color: var(--debit); }
.src.reversal { color: var(--warn); }
.hist-pts { font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---- setup panels ---- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-sm); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.panel-head h3 { margin: 0; font-size: 16px; }
.srow { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-top: 1px solid var(--line); }
.srow:first-of-type { border-top: none; }
.srow-name { flex: 1; font-weight: 700; }
.srow.dim, .dim { color: var(--dim); }
.srow-name small { font-weight: 600; }
.footer-note { text-align: center; color: var(--dim); font-size: 11px; font-weight: 600; }

details.archived { margin-top: 8px; }
details.archived summary { cursor: pointer; color: var(--dim); font-weight: 700; font-size: 13px; padding: 6px 2px; }

/* ---- template picker ---- */
.tpl-cat { font-weight: 800; color: var(--primary); font-size: 13px; margin: 12px 0 4px; }
.tpl-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.tpl-row .task-text { flex: 1; }

/* ---- segmented + emoji pick ---- */
.seg { display: flex; gap: 6px; background: #f4f1fc; padding: 4px; border-radius: 12px; }
.seg.pts .seg-opt { font-size: 16px; }
.seg-opt {
  flex: 1; border: none; background: transparent; padding: 9px 6px; border-radius: 9px;
  font: inherit; font-weight: 800; cursor: pointer; color: var(--dim); transition: background .12s, color .12s;
}
.seg-opt.active { background: #fff; color: var(--primary); box-shadow: var(--shadow-sm); }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; margin: -2px 0 4px; }
.epick { font-size: 20px; border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 4px 7px; cursor: pointer; }
.epick.active { border-color: var(--primary); background: #f1edfb; }

/* ---- bottom nav ---- */
#nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; max-width: var(--maxw); margin: 0 auto;
  background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -4px 16px rgba(80,60,140,.06);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: none; background: transparent; padding: 8px 2px; cursor: pointer; font: inherit;
  font-size: 11px; font-weight: 700; color: var(--dim); height: var(--nav-h);
}
.nav-ico { font-size: 20px; transition: transform .15s; }
.nav-btn.active { color: var(--primary); }
.nav-btn.active .nav-ico { transform: translateY(-2px) scale(1.15); }

/* ---- modal ---- */
.modal {
  position: fixed; inset: 0; z-index: 40; display: none;
  align-items: flex-end; justify-content: center;
  background: rgba(40, 30, 70, .45);
}
.modal.show { display: flex; animation: fade .15s ease; }
.modal-card {
  width: 100%; max-width: var(--maxw); background: #fff;
  border-radius: 22px 22px 0 0; padding: 16px 16px calc(18px + env(safe-area-inset-bottom, 0));
  box-shadow: 0 -10px 40px rgba(40,30,70,.25); max-height: 88vh; overflow-y: auto;
  animation: slideup .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translateY(40px); } to { transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-title { margin: 0; font-size: 18px; }
.modal-x { border: none; background: #f4f1fc; border-radius: 50%; width: 32px; height: 32px; cursor: pointer; font-weight: 800; color: var(--dim); }
.modal-body { display: flex; flex-direction: column; gap: 10px; }
.modal-foot { display: flex; gap: 10px; margin-top: 14px; }
.modal-foot .btn { flex: 1; }
.modal-foot .btn.wide { flex: 1; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- floating +N pop ---- */
.point-pop {
  position: fixed; transform: translate(-50%, -50%); z-index: 60; pointer-events: none;
  font-weight: 900; font-size: 22px; font-variant-numeric: tabular-nums;
  animation: pop .85s ease-out forwards;
}
.point-pop.credit { color: var(--credit); }
.point-pop.debit { color: var(--debit); }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
  20% { opacity: 1; transform: translate(-50%, -90%) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* ---- confetti ---- */
.confetti {
  position: fixed; top: -24px; z-index: 55; pointer-events: none;
  animation: fall linear forwards;
}
@keyframes fall {
  0% { transform: translateY(-10px) rotate(0); opacity: 1; }
  100% { transform: translateY(105vh) rotate(540deg); opacity: .9; }
}
.confetti { animation-duration: 1.5s; }

@media (max-width: 360px) {
  .tbtn { min-width: 48px; padding: 9px; }
  .brand-tag { display: none; }
}
