/* ---- base ---- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button { font: inherit; border: 0; background: none; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

/* ---- themes ---- */
:root, body[data-theme="violet"] {
  --bg: linear-gradient(160deg, #f3eeff 0%, #fdf3ff 55%, #fff7ef 100%);
  --surface: #ffffff;
  --surface-2: #f6f2ff;
  --ink: #241a3d;
  --ink-2: #6d6488;
  --muted: #a49bc0;
  --accent: #7c5cff;
  --accent-soft: #ece5ff;
  --ok: #23b26d;
  --ring-track: #eae3fb;
  --shadow: 0 4px 18px rgba(90, 60, 180, .10);
}
body[data-theme="teal"] {
  --bg: linear-gradient(160deg, #e8fbf7 0%, #eefaff 55%, #fff8ec 100%);
  --surface: #ffffff;
  --surface-2: #edf9f6;
  --ink: #10333a;
  --ink-2: #557b7a;
  --muted: #8fb5b1;
  --accent: #0da695;
  --accent-soft: #d9f4ef;
  --ok: #23b26d;
  --ring-track: #dcf0ec;
  --shadow: 0 4px 18px rgba(20, 120, 110, .10);
}
body[data-theme="dark"] {
  --bg: #14161d;
  --surface: #1e212b;
  --surface-2: #262a36;
  --ink: #eef0f6;
  --ink-2: #a9aec0;
  --muted: #6f7488;
  --accent: #6688fc;
  --accent-soft: #2a3350;
  --ok: #3ecf8e;
  --ring-track: #2c3040;
  --shadow: 0 4px 18px rgba(0, 0, 0, .35);
}

/* ---- layout ---- */
#app { max-width: 560px; margin: 0 auto; padding: 16px 16px 8px; }
.boot { text-align: center; padding: 40vh 0; color: var(--muted); }

header.page {
  display: flex; align-items: center; gap: 12px;
  margin: 8px 0 16px;
}
header.page .hi { font-size: 1.35rem; font-weight: 700; }
header.page .date { color: var(--ink-2); font-size: .9rem; }
header.page .avatar {
  width: 48px; height: 48px; border-radius: 16px;
  background: var(--accent-soft);
  display: grid; place-items: center; font-size: 26px;
}

/* ---- progress ring ---- */
.ring-wrap { display: flex; align-items: center; gap: 16px; background: var(--surface); border-radius: 20px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.ring {
  --p: 0;
  width: 84px; height: 84px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--ring-track) 0);
  display: grid; place-items: center;
  transition: background .4s;
  flex: none;
}
.ring::after { content: ""; position: absolute; }
.ring .hole {
  width: 62px; height: 62px; border-radius: 50%;
  background: var(--surface);
  display: grid; place-items: center;
  font-weight: 800; font-size: 1.05rem;
}
.ring-label { font-weight: 700; }
.ring-sub { color: var(--ink-2); font-size: .88rem; margin-top: 2px; }

/* ---- task cards ---- */
.section-title { font-weight: 800; margin: 18px 4px 10px; font-size: 1.02rem; }
.task {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  width: 100%;
  text-align: left;
  transition: transform .12s;
  position: relative;
  overflow: hidden;
}
.task:active { transform: scale(.97); }
.task .emo {
  width: 46px; height: 46px; border-radius: 14px; flex: none;
  background: var(--surface-2);
  display: grid; place-items: center; font-size: 24px;
}
.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 600; line-height: 1.25; }
.task .sub { color: var(--ink-2); font-size: .82rem; margin-top: 2px; }
.task .check {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  border: 2.5px solid var(--muted);
  display: grid; place-items: center;
  color: transparent; font-size: 17px; font-weight: 800;
  transition: all .18s;
}
.task.done { background: var(--accent-soft); box-shadow: none; }
.task.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.task.done .title { opacity: .75; }
.chips { display: flex; gap: 5px; margin-top: 6px; }
.chip { width: 14px; height: 14px; border-radius: 50%; background: var(--ring-track); }
.chip.on { background: var(--ok); }

/* ---- week grid ---- */
.card { background: var(--surface); border-radius: 20px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.week-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.week-nav .label { font-weight: 800; }
.week-nav button { font-size: 1.2rem; padding: 6px 14px; border-radius: 12px; background: var(--surface-2); }
.week-nav button:disabled { opacity: .35; }
.wgrid { width: 100%; border-collapse: collapse; }
.wgrid th { font-size: .68rem; color: var(--muted); font-weight: 600; padding: 4px 2px; text-align: center; }
.wgrid th.today { color: var(--accent); }
.wgrid td { text-align: center; padding: 5px 2px; }
.wgrid td.name { text-align: left; font-size: .78rem; line-height: 1.15; padding-right: 6px; max-width: 130px; }
.wgrid td.name .pct { color: var(--ink-2); font-size: .68rem; }
.dot {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--ring-track); border: none;
  display: inline-grid; place-items: center;
  color: transparent; font-size: 13px; font-weight: 800;
  transition: all .15s;
}
.dot.on { background: var(--ok); color: #fff; }
.dot.future { opacity: .35; }
.dot:not(:disabled):active { transform: scale(.85); }

/* ---- reward banner ---- */
.reward { display: flex; gap: 12px; align-items: center; }
.reward .icon { font-size: 30px; }
.reward .bar { height: 10px; background: var(--ring-track); border-radius: 6px; overflow: hidden; margin-top: 8px; position: relative; }
.reward .bar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width .5s; }
.reward .bar > b { position: absolute; top: -3px; width: 2px; height: 16px; background: var(--ink-2); opacity: .55; }
.reward .nums { display: flex; justify-content: space-between; font-size: .8rem; color: var(--ink-2); margin-top: 5px; }
.reward-hit { color: var(--ok); font-weight: 700; }

/* ---- stats ---- */
.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; }
.streak { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--surface-2); font-size: .92rem; }
.streak:last-child { border-bottom: 0; }
.streak .n { margin-left: auto; font-weight: 800; color: var(--accent); }

/* ---- admin ---- */
.kid-switch { display: flex; gap: 8px; margin-bottom: 16px; }
.kid-switch button {
  flex: 1; padding: 10px; border-radius: 14px; background: var(--surface);
  font-weight: 700; box-shadow: var(--shadow); border: 2px solid transparent;
}
.kid-switch button.on { border-color: var(--accent); color: var(--accent); }
.tlist .row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--surface-2); }
.tlist .row:last-child { border-bottom: 0; }
.tlist .row .t { flex: 1; min-width: 0; font-size: .92rem; }
.tlist .row .f { color: var(--ink-2); font-size: .75rem; }
.tlist .row.off { opacity: .45; }
.iconbtn { padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: .9rem; }
.btn {
  display: block; width: 100%; padding: 13px; border-radius: 14px;
  background: var(--accent); color: #fff; font-weight: 700; text-align: center;
  margin-top: 12px;
}
.btn.secondary { background: var(--surface-2); color: var(--ink); }
.form label { display: block; font-size: .8rem; color: var(--ink-2); margin: 12px 0 4px; }
.form input, .form select {
  width: 100%; padding: 11px 12px; border-radius: 12px;
  border: 1.5px solid var(--ring-track); background: var(--surface); color: var(--ink);
}
.modal-wrap {
  position: fixed; inset: 0; background: rgba(10, 8, 30, .45);
  display: grid; place-items: end center; z-index: 40;
}
.modal {
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  width: 100%; max-width: 560px; max-height: 85dvh; overflow: auto;
}
.modal h3 { margin: 0 0 4px; }

/* ---- tab bar ---- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
#tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; color: var(--muted); font-size: .68rem; font-weight: 600;
  border-radius: 12px;
}
#tabbar button .ico { font-size: 21px; }
#tabbar button.on { color: var(--accent); }

/* ---- misc ---- */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg, #fff); background: #2a2438; color: #fff;
  padding: 10px 18px; border-radius: 14px; font-size: .9rem; z-index: 60;
  max-width: 90vw; text-align: center;
}
.offline-note { text-align: center; color: var(--muted); font-size: .78rem; margin: 8px 0; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.celebrate { animation: pop .5s; }
@keyframes pop { 30% { transform: scale(1.06); } }
