/* baby_star_counter — 寶貝勳章 前端樣式 (kid-friendly, mobile-first) */
:root {
  --bg1: #f3e7ff;
  --bg2: #e0f2fe;
  --card: #ffffff;
  --ink: #2d2540;
  --muted: #8b80a8;
  --line: #ece6f7;
  --accent: #a78bfa;
  --accent-d: #7c5cf0;
  --plus: #34d399;
  --plus-d: #059669;
  --minus: #fb7185;
  --minus-d: #e11d48;
  --gold: #fbbf24;
  --shadow: 0 8px 24px rgba(124, 92, 240, .14);
  --radius: 20px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  min-height: 100vh;
  min-height: 100dvh;
  /* 鎖住縮放: 不讓「點兩下放大」/ 雙指縮放 (配合 viewport user-scalable=no) */
  touch-action: manipulation;
}

#app { max-width: 560px; margin: 0 auto; padding: 0 0 96px; }

.boot {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; height: 100dvh; font-size: 22px; color: var(--accent-d);
  animation: pulse 1.4s ease-in-out infinite alternate;
}
@keyframes pulse { from { opacity: .55; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }

/* ---------------- 通用元件 ---------------- */
button { font-family: inherit; cursor: pointer; border: none; }
.btn {
  border-radius: 14px; padding: 12px 18px; font-size: 16px; font-weight: 700;
  background: var(--accent); color: #fff; box-shadow: var(--shadow);
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.95); }
.btn.ghost { background: #fff; color: var(--accent-d); box-shadow: 0 2px 8px rgba(124,92,240,.1); }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 11px; }
.btn:disabled { filter: grayscale(.5) opacity(.6); pointer-events: none; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin: 14px 12px;
}

.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.hidden { display: none !important; }
input, select, textarea {
  font-family: inherit; font-size: 16px; padding: 11px 13px; border-radius: 12px;
  border: 2px solid var(--line); background: #fbfaff; color: var(--ink); width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
label.fld { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }

/* ---------------- PIN 閘門 ---------------- */
#gate {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px; background: linear-gradient(160deg, var(--bg1), var(--bg2));
}
#gate .lock { font-size: 64px; animation: pulse 1.6s ease-in-out infinite alternate; }
#gate h1 { font-size: 24px; margin: 0; }
#gate .pinbox { width: 100%; max-width: 280px; }
#gate input { text-align: center; font-size: 28px; letter-spacing: 10px; }
#gate .err { color: var(--minus-d); font-size: 14px; min-height: 20px; font-weight: 600; }

/* ---------------- 頂列 ---------------- */
header.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px; padding: 12px 14px 10px;
  background: linear-gradient(160deg, rgba(243,231,255,.96), rgba(224,242,254,.92));
  backdrop-filter: blur(6px);
}
header.top .title { font-size: 20px; font-weight: 800; }
header.top .title small { font-size: 11px; color: var(--muted); font-weight: 600; margin-left: 4px; }

/* 操作者切換 爸爸/媽媽 */
.actor-switch { display: inline-flex; background: #fff; border-radius: 999px; padding: 3px; box-shadow: var(--shadow); }
.actor-switch button {
  border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 700;
  background: transparent; color: var(--muted);
}
.actor-switch button.on { background: var(--accent); color: #fff; }

/* ---------------- 小朋友切換列 ---------------- */
.kid-strip { display: flex; gap: 10px; overflow-x: auto; padding: 6px 12px 10px; scrollbar-width: none; }
.kid-strip::-webkit-scrollbar { display: none; }
.kid-chip {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #fff; border-radius: 18px; padding: 9px 12px; min-width: 66px;
  box-shadow: 0 2px 8px rgba(124,92,240,.1); border: 3px solid transparent;
  transition: transform .1s ease;
}
.kid-chip:active { transform: scale(.94); }
.kid-chip.on { border-color: var(--kc, var(--accent)); }
.kid-chip .av { font-size: 26px; line-height: 1; }
.kid-chip .nm { font-size: 12px; font-weight: 700; max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kid-chip .ct { font-size: 12px; font-weight: 800; color: var(--gold); }
.kid-chip.add { justify-content: center; color: var(--accent-d); font-size: 24px; min-width: 52px; }

/* ---------------- 主勳章卡 ---------------- */
.hero { text-align: center; padding: 26px 18px; position: relative; overflow: hidden; }
.hero .av { font-size: 60px; }
.hero .nm { font-size: 22px; font-weight: 800; margin-top: 2px; }
.hero .count {
  font-size: 76px; font-weight: 900; line-height: 1.05; margin: 6px 0 2px;
  color: var(--gold); text-shadow: 0 3px 0 rgba(251,191,36,.25);
}
.hero .count.bump { animation: bump .5s cubic-bezier(.2,1.6,.4,1); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
.hero .unit { font-size: 16px; color: var(--muted); font-weight: 700; }

/* 加減按鈕 */
.pm { display: flex; gap: 12px; margin: 16px 12px 4px; }
.pm button { flex: 1; font-size: 30px; font-weight: 900; padding: 16px 0; border-radius: 18px; color: #fff; box-shadow: var(--shadow); transition: transform .08s; }
.pm button:active { transform: scale(.93); }
.pm .add { background: linear-gradient(160deg, var(--plus), var(--plus-d)); }
.pm .sub { background: linear-gradient(160deg, var(--minus), var(--minus-d)); }

/* ---------------- 分頁 ---------------- */
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; max-width: 560px; margin: 0 auto;
  background: #fff; box-shadow: 0 -4px 18px rgba(124,92,240,.12);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
nav.tabs button {
  flex: 1; background: transparent; padding: 8px 0; border-radius: 14px;
  font-size: 12px; font-weight: 700; color: var(--muted); display: flex; flex-direction: column; gap: 2px; align-items: center;
}
nav.tabs button .ic { font-size: 22px; }
nav.tabs button.on { color: var(--accent-d); background: #f3eeff; }

.page { display: none; }
.page.on { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- 歷史 ---------------- */
.hist-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.hist-item:last-child { border-bottom: none; }
.hist-item .d { font-size: 22px; font-weight: 900; min-width: 52px; text-align: center; border-radius: 12px; padding: 6px 0; }
.hist-item .d.pos { color: var(--plus-d); background: #e8fbf3; }
.hist-item .d.neg { color: var(--minus-d); background: #fff0f3; }
.hist-item .info { flex: 1; min-width: 0; }
.hist-item .rs { font-size: 15px; font-weight: 600; }
.hist-item .rs.empty { color: var(--muted); font-style: italic; }
.hist-item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.hist-item .undo { color: var(--muted); background: #f6f3fc; border-radius: 10px; padding: 6px 9px; font-size: 12px; font-weight: 700; }

.empty-msg { text-align: center; color: var(--muted); padding: 36px 12px; font-size: 15px; }

/* ---------------- 分析 ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-box { background: #faf8ff; border-radius: 14px; padding: 12px 8px; text-align: center; }
.stat-box .v { font-size: 26px; font-weight: 900; }
.stat-box .v.pos { color: var(--plus-d); }
.stat-box .v.neg { color: var(--minus-d); }
.stat-box .v.tot { color: var(--gold); }
.stat-box .k { font-size: 12px; color: var(--muted); margin-top: 2px; font-weight: 600; }

.sec-title { font-size: 15px; font-weight: 800; margin: 18px 0 8px; }
.range-pick { display: inline-flex; gap: 6px; }
.range-pick button { background: #f3eeff; color: var(--accent-d); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 700; }
.range-pick button.on { background: var(--accent); color: #fff; }

/* 長條圖 (純 CSS) */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 6px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px; height: 100%; }
.bars .col .bar { width: 70%; border-radius: 5px 5px 0 0; background: var(--accent); min-height: 2px; transition: height .4s ease; }
.bars .col .bar.neg { background: var(--minus); }
.bars .col .lab { font-size: 9px; color: var(--muted); white-space: nowrap; }

.reason-row { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.reason-row:last-child { border-bottom: none; }
.reason-row .rn { flex: 1; font-size: 14px; }
.reason-row .rc { font-size: 12px; color: var(--muted); }
.reason-row .rv { font-weight: 800; min-width: 44px; text-align: right; }
.reason-row .rv.pos { color: var(--plus-d); }
.reason-row .rv.neg { color: var(--minus-d); }

/* ---------------- Modal / 底部彈窗 ---------------- */
.modal-bg {
  position: fixed; inset: 0; z-index: 60; background: rgba(45,37,64,.45);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease;
}
.modal-bg.center { align-items: center; }
.sheet {
  background: #fff; width: 100%; max-width: 560px; border-radius: 24px 24px 0 0;
  padding: 20px 18px calc(22px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0,0,0,.2);
  animation: slideup .28s cubic-bezier(.2,1,.3,1);
}
.modal-bg.center .sheet { border-radius: 24px; margin: 0 16px; animation: bump .3s ease; }
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet h3 { margin: 0 0 4px; font-size: 19px; }
.sheet .sub { color: var(--muted); font-size: 13px; margin-bottom: 8px; }

/* 數量 stepper — 加減點數的大圓鈕 */
.amt { display: flex; align-items: center; justify-content: center; gap: 20px; margin: 8px 0 4px; }
.amt button {
  width: 64px; height: 64px; border-radius: 50%; font-size: 36px; font-weight: 900; color: #fff;
  box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; line-height: 1;
  transition: transform .08s;
}
.amt button:active { transform: scale(.9); }
.amt .amt-minus { background: linear-gradient(160deg, var(--minus), var(--minus-d)); }
.amt .amt-plus { background: linear-gradient(160deg, var(--plus), var(--plus-d)); }
.amt .amt-val { font-size: 40px; font-weight: 900; min-width: 96px; text-align: center; }

/* 快速理由 chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 2px; }
.chips button {
  background: #f3eeff; color: var(--accent-d); border-radius: 999px; padding: 8px 13px;
  font-size: 14px; font-weight: 600;
}
.chips button.on { background: var(--accent); color: #fff; }

/* emoji / color 選擇 */
.picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.picker .opt { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; background: #f6f3fc; border: 3px solid transparent; }
.picker .opt.on { border-color: var(--accent); }
.picker .opt.col { font-size: 0; }

.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }
.danger-text { color: var(--minus-d); }

/* 版本號 + 修改日期 — 固定在 sticky 標題列, 不隨內容捲動 */
.title-wrap { display: flex; flex-direction: column; justify-content: center; }
.ver-head { font-size: 10px; color: var(--muted); margin-top: 1px; opacity: .8; line-height: 1.1; }
.gate-ver { color: var(--muted); font-size: 11px; opacity: .75; margin-top: 4px; }
