:root {
  --bg: #FBF7F0;
  --bg2: #F5EEE3;
  --card: #FFFFFF;
  --ink: #2E2A25;
  --ink2: #5C544B;
  --muted: #9A9086;
  --line: #EDE4D6;
  --accent: #FF8A3D;
  --accent-soft: #FFF0E4;
  --blue: #4C9AFF;
  --green: #2FB98A;
  --green-soft: #E7F7F1;
  --red: #F0685F;
  --red-soft: #FDECEA;
  --yellow: #FFC24B;
  --radius: 22px;
  --shadow: 0 2px 4px rgba(80, 60, 30, .04), 0 12px 28px rgba(80, 60, 30, .06);
  --shadow-lg: 0 8px 18px rgba(80, 60, 30, .08), 0 24px 48px rgba(80, 60, 30, .1);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; }

button {
  font-family: inherit;
  font-size: inherit;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: 17px;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type="date"] { min-height: 48px; }

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 22px calc(40px + env(safe-area-inset-bottom));
}

/* ---------------- 顶部 ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.who { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 60px; height: 60px;
  border-radius: 20px;
  background: var(--accent-soft);
  display: grid; place-items: center;
  font-size: 32px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.04);
  overflow: hidden;
  flex: none;
}
.avatar-sm {
  width: 42px; height: 42px;
  border-radius: 13px;
  background: var(--accent-soft);
  display: grid; place-items: center;
  font-size: 20px;
  overflow: hidden;
  flex: none;
}
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.avatar-preview {
  width: 128px;
  height: 128px;
  margin: 4px auto 16px;
  border-radius: 40px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  font-size: 56px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.avatar-preview .avatar-img { border-radius: inherit; }
.who .name { font-size: 22px; font-weight: 700; letter-spacing: .3px; }
.who .date { font-size: 14px; color: var(--muted); margin-top: 2px; }

.ghost-btn {
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--card);
  border: 1.5px solid var(--line);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink2);
  box-shadow: var(--shadow);
}
.ghost-btn:active { transform: scale(.97); }

/* ---------------- 余额卡 ---------------- */

.balance-card {
  position: relative;
  background: linear-gradient(135deg, #FFF6EC 0%, #FFEFE0 46%, #FFE7D2 100%);
  border-radius: 28px;
  padding: 26px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 22px;
}
.balance-card::after {
  content: "";
  position: absolute;
  right: -60px; top: -80px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .45);
}
.balance-label { font-size: 14px; color: #B07A46; font-weight: 600; letter-spacing: 1px; }
.balance-value {
  font-size: 68px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -1.5px;
  font-variant-numeric: tabular-nums;
  margin: 4px 0 6px;
}
.balance-value small { font-size: 22px; font-weight: 700; margin-left: 4px; color: #B07A46; }
.flow { display: flex; gap: 14px; font-size: 14px; font-weight: 600; }
.flow .in { color: var(--green); }
.flow .out { color: var(--red); }

.ring-box { position: relative; z-index: 1; display: grid; place-items: center; }
.ring-box svg { transform: rotate(-90deg); }
.ring-text {
  position: absolute;
  text-align: center;
  font-size: 11px;
  color: #B07A46;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: .6px;
}
.ring-text b {
  display: block;
  font-size: 20px;
  line-height: 1.15;
  color: var(--ink);
  margin-bottom: 4px;
  letter-spacing: 0;
}

/* ---------------- 区块 ---------------- */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 30px 4px 14px;
}
.section-head h2 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .3px; }
.section-head .sub { font-size: 14px; color: var(--muted); font-weight: 600; }

/* ---------------- 任务卡 ---------------- */

.task-list { display: grid; gap: 12px; }

.task {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  transition: transform .15s ease;
}
.task:active { transform: scale(.995); }
.task .emoji {
  width: 52px; height: 52px;
  border-radius: 16px;
  background: var(--bg2);
  display: grid; place-items: center;
  font-size: 27px;
  flex: none;
}
.task .main { flex: 1; min-width: 0; }
.task .tname { font-size: 17px; font-weight: 650; }
.task .meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.task .pts {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  flex: none;
  margin-right: 4px;
}
.task .pts::after { content: " 分"; font-size: 12px; font-weight: 600; color: var(--muted); }

.task .act { flex: none; }
.btn-done {
  padding: 12px 22px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 4px 12px rgba(255, 138, 61, .34);
}
.btn-done:active { transform: scale(.96); }

.state-tag {
  padding: 10px 16px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
.state-tag.pending { background: var(--accent-soft); color: #C56A20; }
.state-tag.approved { background: var(--green-soft); color: var(--green); }
.state-tag.rejected { background: var(--red-soft); color: var(--red); }

.task.approved { opacity: .62; }
.task.rejected .tname { color: var(--red); }

.empty {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  box-shadow: var(--shadow);
}

/* ---------------- 奖励橱窗 ---------------- */

.reward-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}
.reward {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.reward .emoji { font-size: 34px; }
.reward .rname { font-size: 15px; font-weight: 650; }
.reward .cost { font-size: 13px; color: var(--muted); font-weight: 600; }
.btn-redeem {
  margin-top: 4px;
  width: 100%;
  padding: 10px;
  border-radius: 12px;
  background: var(--bg2);
  color: var(--ink2);
  font-weight: 700;
  font-size: 14px;
}
.btn-redeem:active { transform: scale(.97); }
.btn-redeem[disabled] { opacity: .42; }

/* ---------------- 家长控制台 ---------------- */

.console-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg2);
  padding: 6px;
  border-radius: 18px;
  margin-bottom: 22px;
  overflow-x: auto;
  scrollbar-width: none;
}
.console-tabs::-webkit-scrollbar { display: none; }
.console-tabs button {
  flex: none;
  padding: 11px 18px;
  border-radius: 13px;
  font-size: 15px;
  font-weight: 650;
  color: var(--ink2);
  white-space: nowrap;
  position: relative;
}
.console-tabs button.on {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(80, 60, 30, .1);
}
.console-tabs .dot {
  display: inline-block;
  min-width: 19px;
  height: 19px;
  line-height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  margin-left: 5px;
  vertical-align: 1px;
}

.panel { display: grid; gap: 12px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 4px; font-size: 16px; font-weight: 700; }
.card .hint { font-size: 13px; color: var(--muted); }

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; padding-bottom: 0; }
.row:first-child { padding-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-size: 16px; font-weight: 620; }
.row .desc { font-size: 13px; color: var(--muted); margin-top: 2px; }

.mini-btn {
  padding: 9px 15px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 700;
  background: var(--bg2);
  color: var(--ink2);
}
.mini-btn.pri { background: var(--green); color: #fff; }
.mini-btn.warn { background: var(--red-soft); color: var(--red); }
.mini-btn.line { background: #fff; border: 1.5px solid var(--line); }
.mini-btn:active { transform: scale(.96); }

.primary-btn {
  padding: 15px 22px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 6px 16px rgba(255, 138, 61, .3);
  width: 100%;
}
.primary-btn:active { transform: scale(.985); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 15px;
  border-radius: 999px;
  background: var(--bg2);
  font-size: 14px;
  font-weight: 650;
  color: var(--ink2);
}
.chip.on { background: var(--accent); color: #fff; }
.chip-row button:active { transform: scale(.96); }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 650;
  color: var(--ink2);
  margin-bottom: 6px;
}
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

/* ---------------- 明细表 ---------------- */

.ledger-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.ledger-row:last-child { border-bottom: 0; }
.ledger-icon {
  width: 40px; height: 40px;
  border-radius: 13px;
  display: grid; place-items: center;
  font-size: 18px;
  flex: none;
}
.ledger-icon.in { background: var(--green-soft); }
.ledger-icon.out { background: var(--red-soft); }
.ledger-main { flex: 1; min-width: 0; }
.ledger-reason {
  font-size: 15px;
  font-weight: 620;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ledger-time { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ledger-amt {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.ledger-amt.in { color: var(--green); }
.ledger-amt.out { color: var(--red); }

.summary-strip { display: flex; gap: 10px; margin-bottom: 4px; }
.sum-item {
  flex: 1;
  background: var(--bg2);
  border-radius: 16px;
  padding: 14px 16px;
}
.sum-item .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.sum-item .v {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

/* ---------------- 弹层 ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 32, 24, .42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.overlay.show .modal { transform: scale(1); }

.modal {
  background: var(--card);
  border-radius: 26px;
  padding: 26px;
  width: min(460px, 100%);
  max-height: 86vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(.96);
  transition: transform .18s ease;
}
.modal h3 { margin: 0 0 6px; font-size: 20px; font-weight: 750; }
.modal .sub { font-size: 14px; color: var(--muted); margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions button { flex: 1; padding: 15px; border-radius: 16px; font-weight: 700; font-size: 16px; }
.btn-cancel { background: var(--bg2); color: var(--ink2); }
.btn-ok { background: var(--accent); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }

/* PIN 键盘 */
.pin-dots { display: flex; gap: 16px; justify-content: center; margin: 22px 0 8px; }
.pin-dots i {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--bg2);
  border: 2px solid var(--line);
  transition: all .12s ease;
}
.pin-dots i.on { background: var(--accent); border-color: var(--accent); transform: scale(1.12); }

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 20px;
}
.pin-pad button {
  height: 62px;
  border-radius: 18px;
  background: var(--bg2);
  font-size: 26px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.pin-pad button:active { background: var(--accent-soft); transform: scale(.96); }
.pin-pad button.plain { background: transparent; font-size: 15px; color: var(--ink2); font-weight: 700; }
.pin-err { color: var(--red); font-size: 14px; text-align: center; min-height: 20px; margin-top: 8px; font-weight: 600; }
.pin-shake { animation: shake .3s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(34px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: rgba(46, 42, 37, .94);
  color: #fff;
  padding: 13px 22px;
  border-radius: 15px;
  font-size: 15px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all .22s ease;
  z-index: 200;
  max-width: 84vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.hidden { display: none !important; }

.tabbar {
  display: flex;
  gap: 4px;
  background: var(--bg2);
  padding: 5px;
  border-radius: 16px;
  margin-bottom: 18px;
}

/* ---------------- 日历 ---------------- */

.card.cal { padding: 16px 16px 20px; }

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.cal-title { font-size: 16px; font-weight: 700; letter-spacing: .5px; }
.cal-nav {
  width: 44px; height: 44px;
  border-radius: 14px;
  background: var(--bg2);
  font-size: 22px;
  font-weight: 700;
  color: var(--ink2);
  line-height: 1;
  display: grid;
  place-items: center;
  padding-bottom: 4px;
}
.cal-nav:active { transform: scale(.94); }

.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.cal-week span {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-pad { aspect-ratio: 1 / 1; }

.cal-day {
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  background: var(--bg);
  border: 1.5px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 2px;
  overflow: hidden;
}
.cal-day .cd {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink2);
  line-height: 1.1;
}
.cal-day .cflow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  line-height: 1.1;
}
.cal-day .cflow i {
  font-style: normal;
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cal-day .cflow .in { color: var(--green); }
.cal-day .cflow .out { color: var(--red); }

.cal-day.idle { background: #FAF5EC; }
.cal-day.idle .cd { color: var(--muted); font-weight: 600; }
.cal-day.pos { background: var(--green-soft); }
.cal-day.neg { background: var(--red-soft); }
.cal-day.today { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 138, 61, .14); }
.cal-day:active { transform: scale(.95); }

/* ---------------- 内置任务库 ---------------- */

.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.tpl-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 12px;
  border-radius: 14px;
  background: var(--bg);
  border: 1.5px solid var(--line);
  text-align: left;
}
.tpl-item:active { transform: scale(.97); background: var(--accent-soft); }
.tpl-item .te { font-size: 20px; flex: none; }
.tpl-item .tn {
  flex: 1;
  font-size: 14px;
  font-weight: 620;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tpl-item .tp {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  flex: none;
}

/* ---------------- 会话状态 ---------------- */

.sess-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg2);
  color: var(--muted);
  vertical-align: 3px;
  margin-left: 6px;
  letter-spacing: .3px;
}
.sess-badge.on { background: var(--green-soft); color: var(--green); }

.topbar-actions { display: flex; gap: 8px; }

/* ---------------- 今日任务分数统计 ---------------- */

.head-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.hs {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  background: var(--card);
  border-radius: 999px;
  padding: 5px 12px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.hs b {
  font-size: 14px;
  color: var(--ink);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-right: 3px;
}
.hs.pts b { color: var(--accent); }

/* ---------------- 日历统计条 ---------------- */

.cal-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.cs {
  background: var(--bg);
  border-radius: 13px;
  padding: 10px 6px;
  text-align: center;
}
.cs .k { font-size: 11px; color: var(--muted); font-weight: 600; }
.cs .v {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.cs .v.in { color: var(--green); }
.cs .v.out { color: var(--red); }
.cs .v.dim { color: var(--muted); }

/* ---------------- 任务分组 ---------------- */

.count-badge {
  display: inline-block;
  margin-left: 8px;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--bg2);
  color: var(--ink2);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  vertical-align: 1px;
}
.task-thumb {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--bg2);
  display: grid;
  place-items: center;
  font-size: 20px;
  flex: none;
}
.row.dim { opacity: .58; }

/* ---------------- 图标选择器 ---------------- */

.emo-tabs { margin-bottom: 10px; }
.emo-tabs .chip { padding: 7px 13px; font-size: 13px; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 6px;
  max-height: 210px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg);
  border-radius: 14px;
  border: 1.5px solid var(--line);
  -webkit-overflow-scrolling: touch;
}
.emoji-grid button {
  height: 46px;
  border-radius: 11px;
  background: var(--card);
  font-size: 23px;
  line-height: 1;
  display: grid;
  place-items: center;
  border: 1.5px solid transparent;
}
.emoji-grid button:active {
  transform: scale(.92);
  background: var(--accent-soft);
  border-color: var(--accent);
}

@media (max-width: 620px) {
  .topbar-actions .ghost-btn { padding: 10px 12px; font-size: 13px; }
  .cal-grid, .cal-week { gap: 4px; }
  .cal-day { border-radius: 11px; }
  .cal-day .cflow i { font-size: 9px; }
  .wrap { padding: calc(14px + env(safe-area-inset-top)) 14px calc(30px + env(safe-area-inset-bottom)); }
  .balance-value { font-size: 54px; }
  .balance-card { padding: 20px; }
  .task { padding: 14px; gap: 12px; }
  .task .emoji { width: 46px; height: 46px; font-size: 24px; }
  .btn-done { padding: 11px 16px; font-size: 14px; }
}
