* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --green: #1f8f5c;        /* 主色（通過圖表對比檢驗） */
  --green-deep: #146c44;
  --green-tint: #e9f5ee;
  --red: #cf4b4b;
  --red-tint: #fbeeee;
  --gold: #b07d10;
  --gold-tint: #fdf6e6;
  --bg: #f2f5f3;
  --card: #ffffff;
  --text: #222b26;
  --muted: #6f7f76;
  --border: #e3e9e5;
  --shadow: 0 1px 2px rgba(20, 44, 32, 0.05), 0 4px 14px rgba(20, 44, 32, 0.05);
}

body {
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 80px;
}

.page { display: none; padding: 22px 16px; }
.page.active { display: block; }

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}
.page-header h1 { font-size: 24px; letter-spacing: 0.02em; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ===== 圖標 ===== */
.icon, .tab-icon {
  width: 1.15em;
  height: 1.15em;
  vertical-align: -0.22em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h3 {
  font-size: 15px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.card h3 .icon { color: var(--green); }

/* ===== 進度環 ===== */
.ring-wrap { position: relative; width: 220px; margin: 6px auto 20px; }
.ring { width: 220px; height: 220px; transform: rotate(-90deg); }
.ring-bg, .ring-fg { fill: none; stroke-width: 13; stroke-linecap: round; }
.ring-bg { stroke: #e6ede8; }
.ring-fg {
  stroke: var(--green);
  stroke-dasharray: 540;
  stroke-dashoffset: 540;
  transition: stroke-dashoffset 0.6s ease;
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.big-num { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.goal-label { margin-top: 6px; font-size: 13px; color: var(--muted); }

.status-card { border-left: 4px solid var(--green); }
.status-card .icon { color: var(--green); }
.status-card.warn { border-left-color: var(--red); }
.status-card.warn .icon { color: var(--red); }

/* ===== 週步數圖表 ===== */
.chart-wrap { position: relative; }
#week-chart { width: 100%; height: auto; display: block; }
#week-chart .bar { fill: var(--green); }
#week-chart .bar-hit { fill: transparent; cursor: pointer; }
#week-chart .bar-hit:hover + .bar, #week-chart g:hover .bar { fill: var(--green-deep); }
#week-chart .axis-line { stroke: var(--border); stroke-width: 1; }
#week-chart .goal-line { stroke: var(--gold); stroke-width: 1.5; stroke-dasharray: 4 4; }
#week-chart .x-label { font-size: 11px; fill: var(--muted); text-anchor: middle; }
#week-chart .x-label.today { fill: var(--text); font-weight: 600; }
#week-chart .goal-text { font-size: 10px; fill: var(--gold); text-anchor: end; }
#week-chart .bar-label { font-size: 11px; fill: var(--text); text-anchor: middle; font-weight: 600; }
.chart-tip {
  position: absolute;
  background: #26302b;
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  padding: 6px 10px;
  border-radius: 8px;
  pointer-events: none;
  transform: translate(-50%, -110%);
  white-space: nowrap;
  z-index: 10;
}

/* ===== 按鈕 ===== */
.btn {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { background: var(--green-deep); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-outline { background: #fff; color: var(--green); border: 1px solid var(--green); }
.btn-danger-outline { background: #fff; color: var(--red); border: 1px solid var(--red); }
.btn.full { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.btn-row .btn { flex: 1; min-width: 118px; padding: 10px 8px; font-size: 14px; }
.link-btn {
  background: none; border: none;
  color: var(--green); font-size: 13px; cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; gap: 4px;
}

/* ===== 挑戰 ===== */
.challenge-form label { display: block; font-size: 14px; margin: 12px 0 6px; }
.challenge-form select, .challenge-form input {
  width: 100%;
  padding: 11px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.pledge-note {
  background: var(--gold-tint);
  border: 1px solid #efdfae;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  margin-top: 12px;
  line-height: 1.6;
}
.pledge-note .icon { color: var(--gold); }
.day-grid { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.day-cell {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.day-cell.ok { background: var(--green); color: #fff; border-color: var(--green); }
.day-cell.miss { background: var(--red); color: #fff; border-color: var(--red); }
.day-cell.today { outline: 2px solid var(--gold); outline-offset: 1px; }

/* ===== 排行榜 ===== */
.rank-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.rank-item.me { border-color: var(--green); background: var(--green-tint); }
.rank-num {
  width: 30px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  color: var(--muted);
}
.rank-num .icon { width: 22px; height: 22px; }
.rank-num.gold { color: #c9930a; }
.rank-num.silver { color: #8b959e; }
.rank-num.bronze { color: #b56f3c; }
.rank-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.rank-avatar .icon { width: 18px; height: 18px; }
.rank-name { flex: 1; font-size: 15px; }
.rank-steps { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ===== 商城 ===== */
.points-badge {
  background: var(--green-tint);
  border: 1px solid var(--green);
  color: var(--green-deep);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.shop-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.shop-icon {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--green-tint);
  color: var(--green);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.shop-icon .icon { width: 24px; height: 24px; }
.shop-info { flex: 1; }
.shop-name { font-size: 15px; font-weight: 600; }
.shop-desc { font-size: 12px; color: var(--muted); }
.shop-cost {
  font-size: 13px; color: var(--gold); font-weight: 600;
  display: inline-flex; align-items: center; gap: 3px;
}

/* ===== 我的 ===== */
.profile-card { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--green-tint);
  color: var(--green);
  display: flex; align-items: center; justify-content: center;
}
.avatar .icon { width: 28px; height: 28px; }
.me-name { font-size: 18px; font-weight: 700; }
.stat-row { display: flex; gap: 10px; }
.stat { flex: 1; text-align: center; padding: 12px 6px; }
.stat .big-num { font-size: 22px; }
.txn-list { max-height: 220px; overflow-y: auto; }
.txn {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.txn:last-child { border-bottom: none; }
.txn .plus { color: var(--green); font-weight: 600; }
.txn .minus { color: var(--red); font-weight: 600; }

/* ===== 底部導覽 ===== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  background: none;
  border: none;
  padding: 9px 0 10px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.tab-icon { width: 22px; height: 22px; }
.tab span { font-size: 11px; }
.tab.active { color: var(--green); }
.tab.active .tab-icon { stroke-width: 2.4; }

/* ===== 彈窗 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 25, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: 18px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 12px 40px rgba(15, 25, 20, 0.2);
}
.modal-box h2 {
  font-size: 19px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.modal-box h2 .icon { color: var(--green); }
.modal-box h2.warn .icon { color: var(--red); }
.modal-box p { font-size: 14px; line-height: 1.7; margin-bottom: 14px; }
.modal-box input {
  width: 100%;
  padding: 11px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 14px;
}
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { flex: 1; }
