/* ============================================================
   FlexHabit · PWA styles
   Theme system is driven entirely by CSS variables set on :root
   by app.js. Default is DARK (no white background) to guarantee
   top-bar text contrast.
   ============================================================ */

:root {
  /* Default = DARK 紫藍主題。运行时由 applyTheme() 覆写。 */
  --bg: #0b0820;
  --bg-gradient: linear-gradient(160deg, #0b0820 0%, #1a0f3d 50%, #2d1f5f 100%);
  --surface: #1e1638;
  --surface-2: #2a1f4d;
  --label: #f5f3ff;
  --label-2: #aea4d6;
  --separator: rgba(255,255,255,0.08);
  --accent: #7F77DD;
  --green: #30d158;
  --orange: #ff9f0a;
  --red: #ff453a;

  /* ===== 紫蓝设计 token（参考图 6 张截图统一提取） ===== */
  /* 三段渐变：深紫底 → 紫水晶 → 薰衣草 */
  --violet-50:  #f1eefe;
  --violet-100: #d4ccfb;
  --violet-200: #b3a6f3;
  --violet-400: #8677e5;
  --violet-600: #534AB7;
  --violet-800: #312876;
  --violet-900: #1e1a4a;
  --lavender:   #b9b0f0;
  --magenta:    #c879ff;

  /* 强调色渐变：薰衣草 → 蓝（参考图按钮/进度条/顶部 hero 用） */
  --grad-violet:  linear-gradient(135deg, #8677e5 0%, #6c5ce7 50%, #534AB7 100%);
  --grad-violet-h: linear-gradient(135deg, #9d8ff0 0%, #7e6fee 50%, #6358c5 100%);
  --grad-blue:    linear-gradient(135deg, #85B7EB 0%, #378ADD 100%);
  --grad-green:   linear-gradient(135deg, #97C459 0%, #639922 100%);
  --grad-orange:  linear-gradient(135deg, #fac775 0%, #ef9f27 100%);
  --grad-pink:    linear-gradient(135deg, #f4c0d1 0%, #d4537e 100%);
  --grad-aqua:    linear-gradient(135deg, #9fe1cb 0%, #1D9E75 100%);

  /* 习惯类别彩条（左側 4px 渐变彩条区分类别） */
  --stripe-mind:   linear-gradient(180deg, #8677e5, #534AB7);
  --stripe-study:  linear-gradient(180deg, #85B7EB, #378ADD);
  --stripe-health: linear-gradient(180deg, #97C459, #639922);
  --stripe-body:   linear-gradient(180deg, #fac775, #ef9f27);
  --stripe-other:  linear-gradient(180deg, #f4c0d1, #d4537e);

  /* icon 徽章 token（56×56 圆角，渐变背景） */
  --icon-mind:   linear-gradient(135deg, #b3a6f3, #6c5ce7);
  --icon-study:  linear-gradient(135deg, #b5d4f4, #185fa5);
  --icon-health: linear-gradient(135deg, #c0dd97, #3b6d11);
  --icon-body:   linear-gradient(135deg, #fac775, #ba7517);
  --icon-other:  linear-gradient(135deg, #f4c0d1, #993556);

  /* 玻璃胶囊（参考图 un打卡/+/设置胶囊） */
  --glass-bg:   rgba(255,255,255,0.06);
  --glass-bg-2: rgba(255,255,255,0.10);
  --glass-bd:   rgba(255,255,255,0.10);

  /* 阴影 / 圆角 */
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-violet: 0 8px 24px rgba(83, 74, 183, 0.35);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-lg: 20px;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    "PingFang TC", "Microsoft JhengHei", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--label);
  overflow: hidden;
}

/* Live background layer (sits behind everything) */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-size: cover;
  transition: background-color 0.35s ease, background-image 0.35s ease;
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
}

/* ---------- Top app bar (the previously low-contrast area) ---------- */
.topbar {
  flex: 0 0 auto;
  padding-top: var(--safe-top);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 6px 18px;
}
.topbar-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.2px;
  margin: 0;
  color: var(--label);            /* guaranteed contrast on dark bg */
}
.topbar-action {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}

/* ---------- Screen ---------- */
.screen {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  scrollbar-width: none;
}
.screen::-webkit-scrollbar { display: none; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  z-index: 5;
}
.tab {
  flex: 1 1 0;
  border: none;
  background: transparent;
  color: var(--label-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  cursor: pointer;
  transition: color 0.2s ease;
}
.tab-ico { font-size: 22px; line-height: 1; filter: grayscale(0.4); }
.tab-label { font-weight: 600; }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { filter: none; }

/* ---------- Generic cards ---------- */
.card {
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 0.5px solid var(--separator);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-2 {
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.muted { color: var(--label-2); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.spacer { flex: 1 1 auto; }

/* ---------- Section headings ---------- */
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--label-2);
  margin: 18px 4px 10px;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: transform 0.08s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-accent { background: var(--grad-violet); color: #fff; box-shadow: var(--shadow-violet); }
.btn-soft { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--label); border: 0.5px solid var(--separator); }
.btn-danger { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.btn-block { width: 100%; }

/* ============================================================
   紫蓝设计系统 · 参考图 6 张截图统一设计语言（v2）
   ============================================================ */

/* 圆角卡片（参考图所有习惯/挑战/设置卡） */
.flex-card {
  position: relative;
  background: var(--glass-bg);
  border: 0.5px solid var(--glass-bd);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  overflow: hidden;
  isolation: isolate;
}
.flex-card.is-elevated {
  background: rgba(255,255,255,0.04);
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}

/* 左侧彩条 habit-card 用：左侧 4px 渐变彩条 */
.flex-stripe {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: var(--radius) 0 0 var(--radius);
  z-index: 1;
}
.stripe-mind   { background: var(--stripe-mind); }
.stripe-study  { background: var(--stripe-study); }
.stripe-health { background: var(--stripe-health); }
.stripe-body   { background: var(--stripe-body); }
.stripe-other  { background: var(--stripe-other); }

/* icon 徽章（56×56 圆角方块 + 渐变背景） */
.flex-icon-badge {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: grid; place-items: center;
  font-size: 26px;
  flex: 0 0 auto;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.icon-mind   { background: var(--icon-mind); }
.icon-study  { background: var(--icon-study); }
.icon-health { background: var(--icon-health); }
.icon-body   { background: var(--icon-body); }
.icon-other  { background: var(--icon-other); }
.icon-violet { background: var(--grad-violet); }
.icon-blue   { background: var(--grad-blue); }
.icon-aqua   { background: var(--grad-aqua); }
.icon-pink   { background: var(--grad-pink); }

/* 玻璃胶囊（参考图 未打卡 / 加入 / 已完成 / 人数 / 设定右側） */
.flex-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 0.5px solid var(--glass-bd);
  color: var(--label);
  letter-spacing: 0.2px;
}
.flex-pill.pill-violet { background: var(--grad-violet); color: #fff; border: 0; box-shadow: var(--shadow-violet); }
.flex-pill.pill-blue   { background: var(--grad-blue); color: #fff; border: 0; }
.flex-pill.pill-green  { background: var(--grad-green); color: #fff; border: 0; }
.flex-pill.pill-orange { background: var(--grad-orange); color: #1c1c1e; border: 0; }
.flex-pill.pill-ghost  { background: var(--glass-bg-2); color: var(--label); }
.flex-pill.pill-dim    { opacity: 0.85; font-weight: 600; }

/* 进度条（紫蓝渐变） */
.flex-progress {
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
  flex: 1 1 auto;
}
.flex-progress-bar {
  height: 100%;
  background: var(--grad-violet);
  border-radius: 999px;
  transition: width 0.5s ease;
  box-shadow: 0 0 10px rgba(135,119,229,0.5);
}
.flex-progress-bar.is-blue   { background: var(--grad-blue); box-shadow: 0 0 10px rgba(55,138,221,0.5); }
.flex-progress-bar.is-green  { background: var(--grad-green); }
.flex-progress-bar.is-orange { background: var(--grad-orange); }

/* 个人档案卡（参考图 我的 tab 头像卡） */
.flex-profile-card {
  background: var(--grad-violet);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 18px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow-violet);
  position: relative;
  overflow: hidden;
}
.flex-profile-card::before {
  content: '';
  position: absolute;
  right: -40px; top: -40px;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
}
.flex-profile-card::after {
  content: '';
  position: absolute;
  right: -60px; bottom: -60px;
  width: 100px; height: 100px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
}
.flex-profile-avatar {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: rgba(0,0,0,0.25);
  display: grid; place-items: center;
  font-size: 28px;
  flex: 0 0 auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.flex-profile-name {
  font-size: 17px; font-weight: 700; color: #fff;
  margin: 0; line-height: 1.2;
}
.flex-profile-sub {
  font-size: 12px; color: rgba(255,255,255,0.85);
  margin-top: 2px;
}
.flex-profile-upgrade {
  margin-left: auto;
  flex: 0 0 auto;
}

/* 主标题大字（参考图 9月13日 週日 / 習慣挑戰營 / AI 週報與探索） */
.flex-h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 12px 4px 14px;
  color: var(--label);
}
.flex-subtle {
  font-size: 13px; font-weight: 700;
  color: var(--label-2);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin: 14px 4px 10px;
}

/* 行动按钮圆点（参考图 + 号） */
.flex-fab {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--grad-violet);
  border: none;
  color: #fff;
  font-size: 20px; font-weight: 700;
  cursor: pointer;
  display: grid; place-items: center;
  box-shadow: var(--shadow-violet);
  transition: transform 0.12s ease;
}
.flex-fab:active { transform: scale(0.94); }

/* 挑战营卡片（参考图大卡 + 顶部圆形 icon 徽章 + 加入胶囊） */
.flex-challenge {
  position: relative;
  background: var(--glass-bg);
  border: 0.5px solid var(--glass-bd);
  border-radius: var(--radius);
  padding: 18px 18px 14px;
  margin-bottom: 12px;
  overflow: hidden;
  isolation: isolate;
}
.flex-challenge::after {
  content: '';
  position: absolute;
  right: -40px; top: -20px;
  width: 100px; height: 100px;
  border-radius: 50%;
  background: var(--grad-violet);
  opacity: 0.18;
  z-index: 0;
  filter: blur(8px);
}
.flex-challenge > * { position: relative; z-index: 1; }
.flex-challenge-icon {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--icon-mind);
  display: grid; place-items: center;
  font-size: 28px;
  box-shadow: var(--shadow-violet);
  margin-bottom: 12px;
}

/* ---------- Habit rows (Today) ---------- */
.habit-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 0.5px solid var(--separator);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.habit-emoji {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 22px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  flex: 0 0 auto;
}
.habit-main { flex: 1 1 auto; min-width: 0; }
.habit-title { font-size: 16px; font-weight: 600; }
.habit-sub { font-size: 13px; color: var(--label-2); margin-top: 2px; }
.streak-pill {
  font-size: 12px; font-weight: 700;
  color: var(--orange);
  background: color-mix(in srgb, var(--orange) 16%, transparent);
  padding: 3px 8px; border-radius: 999px;
}
.check-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 2px solid var(--separator);
  background: transparent;
  color: var(--label-2);
  font-size: 20px;
  cursor: pointer;
  flex: 0 0 auto;
  display: grid; place-items: center;
}
.check-btn.done-full { background: var(--green); border-color: var(--green); color: #fff; }
.check-btn.done-flex { background: var(--orange); border-color: var(--orange); color: #fff; }

/* ---------- Heatmap ---------- */
.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.heat-cell {
  width: 14px; height: 14px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--label) 10%, transparent);
}
.heat-cell.full { background: var(--green); }
.heat-cell.flex { background: var(--orange); }

/* ---------- 近一週完成熱力圖（習慣 tab 下方） ---------- */
.week-heatmap {
  display: flex;
  gap: 10px;
  justify-content: space-between;
}
.week-day {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.week-cell {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: color-mix(in srgb, var(--label) 10%, transparent);
}
.week-cell.full { background: var(--green); }
.week-cell.flex { background: var(--orange); }
.week-day-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--label-2);
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--label-2);
}
.empty-emoji { font-size: 52px; margin-bottom: 12px; }
.empty-title { font-size: 18px; font-weight: 700; color: var(--label); margin-bottom: 6px; }

/* ---------- Pro badge / rescue card ---------- */
.pro-badge {
  font-size: 11px; font-weight: 800; letter-spacing: 0.5px;
  color: #1c1c1e;
  background: linear-gradient(90deg, #ffd60a, #ff9f0a);
  padding: 3px 8px; border-radius: 999px;
}
/* ---------- Subscription plan buttons (Lemon Squeezy) ---------- */
.plan-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 6px;
}
.plan-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}
.muted-inline {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.85;
}
.rescue-card {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--accent) 30%, var(--surface)),
    color-mix(in srgb, var(--orange) 22%, var(--surface)));
  border: 0.5px solid var(--separator);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.rescue-card h3 { margin: 0 0 6px; font-size: 17px; }
.rescue-card p { margin: 0 0 12px; font-size: 13px; color: var(--label); opacity: 0.85; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.2s ease;
}
.modal {
  width: 100%; max-width: 520px;
  background: var(--surface);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  border: 0.5px solid var(--separator);
  padding: 18px 18px calc(18px + var(--safe-bottom));
  max-height: 88dvh; overflow-y: auto;
  animation: slideup 0.25s ease;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.modal-title { font-size: 19px; font-weight: 700; }
.modal-close {
  border: none; background: transparent; color: var(--label-2);
  font-size: 26px; line-height: 1; cursor: pointer; min-width: 44px; min-height: 44px;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Form fields ---------- */
.field { margin-bottom: 14px; }
.label { display: block; font-size: 13px; color: var(--label-2); margin-bottom: 6px; font-weight: 600; }
.input, .select {
  width: 100%;
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  border: 0.5px solid var(--separator);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 16px;
  color: var(--label);
  min-height: 44px;
}
.input:focus, .select:focus { outline: 2px solid var(--accent); }

/* ---------- Theme picker ---------- */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.theme-chip {
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  background: transparent;
  text-align: left;
}
.theme-chip.active { border-color: var(--accent); }
.theme-swatch {
  height: 64px;
  border-radius: 12px;
  border: 0.5px solid var(--separator);
}
.theme-name { font-size: 12px; color: var(--label); padding: 6px 2px; font-weight: 600; }

.hue-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.hue-slider { flex: 1 1 auto; }
.hue-preview {
  width: 44px; height: 44px; border-radius: 12px;
  border: 0.5px solid var(--separator); flex: 0 0 auto;
}
.hint { font-size: 12px; color: var(--label-2); margin-top: 8px; line-height: 1.5; }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  background: color-mix(in srgb, var(--surface) 96%, #000 4%);
  color: var(--label);
  border: 0.5px solid var(--separator);
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastin 0.2s ease;
  max-width: 90%;
  text-align: center;
}
@keyframes toastin { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Auth ---------- */
.auth-wrap { padding: 8px 4px; }
.auth-logo { font-size: 40px; text-align: center; margin-bottom: 6px; }
.auth-title { font-size: 24px; font-weight: 800; text-align: center; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--label-2); margin-bottom: 22px; font-size: 14px; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 15px; font-weight: 600; cursor: pointer; padding: 10px; }
.divider { text-align: center; color: var(--label-2); margin: 16px 0; font-size: 13px; }

/* ---------- Stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-tile { background: color-mix(in srgb, var(--surface) 90%, transparent); border: 0.5px solid var(--separator); border-radius: 14px; padding: 14px; text-align: center; }
.stat-num { font-size: 24px; font-weight: 800; }
.stat-cap { font-size: 12px; color: var(--label-2); margin-top: 4px; }

/* ---------- Rescue sheet list ---------- */
.rescue-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 16px; }
.rescue-item {
  display: flex; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  border-radius: 12px; padding: 12px 14px;
}
.rescue-date { font-size: 14px; font-weight: 600; }
.rescue-dow { font-size: 12px; color: var(--label-2); }

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 12px;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------- Habit detail (30-day history) ---------- */
.habit-row-link { cursor: pointer; }
.habit-row-link:active { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }

/* 詳情頁右上角動作按鈕群 */
.detail-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: -4px;
}
.topbar-icon-btn {
  border: none;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  min-width: 38px;
  min-height: 38px;
  border-radius: 10px;
  cursor: pointer;
  opacity: 0.85;
  transition: background-color .15s ease, opacity .15s ease;
}
.topbar-icon-btn:hover { background: color-mix(in srgb, var(--surface-2) 50%, transparent); opacity: 1; }
.topbar-icon-btn:active { transform: scale(0.95); }
.topbar-icon-btn.danger { color: var(--red); }

.chart-title { font-size: 15px; font-weight: 700; color: var(--label); }
.chart-legend { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.stat-icon {
  font-size: 16px;
  margin-bottom: 4px;
  display: flex; justify-content: center;
  opacity: 0.95;
}
.stat-tile {
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 0.5px solid var(--separator);
  border-radius: 14px;
  padding: 12px 10px 14px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.stat-num {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.1;
}
.stat-cap {
  font-size: 11px;
  color: var(--label-2);
  margin-top: 4px;
  letter-spacing: 0.2px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 132px;
}
.bar {
  flex: 1 1 0;
  min-width: 4px;
  border-radius: 4px 4px 2px 2px;
  background: color-mix(in srgb, var(--label) 8%, transparent);
  height: 8px;              /* 未打卡短柱 */
  transition: opacity .2s;
}
.bar.full { background: linear-gradient(180deg, var(--green), color-mix(in srgb, var(--green) 65%, transparent)); height: 100%; box-shadow: 0 0 8px color-mix(in srgb, var(--green) 30%, transparent); }
.bar.flex { background: linear-gradient(180deg, var(--orange), color-mix(in srgb, var(--orange) 65%, transparent)); height: 100%; box-shadow: 0 0 8px color-mix(in srgb, var(--orange) 30%, transparent); }
.bar.none { height: 8px; }
.bar:hover { opacity: 0.8; }

/* 打卡紀錄行（含左側狀態圓點 + 日期 + 類型徽章） */
.log-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 0.5px solid var(--separator);
  border-radius: 14px;
  margin-bottom: 8px;
}
.log-leading {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.log-dot.full { background: var(--green); box-shadow: 0 0 6px color-mix(in srgb, var(--green) 50%, transparent); }
.log-dot.flex { background: var(--orange); box-shadow: 0 0 6px color-mix(in srgb, var(--orange) 50%, transparent); }

.type-badge {
  font-size: 12px; font-weight: 700;
  padding: 4px 12px; border-radius: 999px;
  flex: 0 0 auto;
  letter-spacing: 0.2px;
}
.type-full { color: var(--green); background: color-mix(in srgb, var(--green) 16%, transparent); }
.type-flex { color: var(--orange); background: color-mix(in srgb, var(--orange) 16%, transparent); }

/* ---------- 今日進度環（Streaks/Habitica 風格） ---------- */
.today-hero { align-items: center; }
.progress-ring {
  --size: 96px;
  width: var(--size); height: var(--size);
  border-radius: 50%;
  flex: 0 0 auto;
  /* conic-gradient 用 --p（度數）畫進度弧，餘下為未完成底色 */
  background: conic-gradient(var(--green) var(--p, 0deg), color-mix(in srgb, var(--label) 10%, transparent) 0deg);
  display: grid; place-items: center;
  transition: background 0.4s ease;
}
.progress-ring.ring-done {
  box-shadow: 0 0 20px color-mix(in srgb, var(--green) 40%, transparent);
}
.progress-ring-inner {
  width: calc(var(--size) - 14px);
  height: calc(var(--size) - 14px);
  border-radius: 50%;
  background: var(--surface);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
}
.ring-num { font-size: 22px; font-weight: 800; line-height: 1; letter-spacing: -0.5px; }
.ring-cap { font-size: 10px; color: var(--label-2); margin-top: 3px; }

.today-count { font-size: 24px; font-weight: 800; line-height: 1.1; margin-bottom: 4px; }
.quote-text { font-size: 13px; color: var(--label); line-height: 1.5; margin: 2px 0; }
.quote-author { font-size: 12px; color: var(--label-2); }

/* ---------- 成就徽章（Habitica/Fabulous 風格） ---------- */
.ach-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}
.ach-chip {
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 0.5px solid var(--separator);
  border-radius: 12px;
  padding: 10px 6px;
  display: flex; flex-direction: column;
  align-items: center; text-align: center;
  gap: 3px;
}
.ach-icon { font-size: 24px; line-height: 1; }
.ach-name { font-size: 11px; font-weight: 700; color: var(--label); }
.ach-desc { font-size: 9px; color: var(--label-2); }
.ach-chip.locked { opacity: 0.42; filter: grayscale(0.7); }
.ach-chip.unlocked { border-color: color-mix(in srgb, var(--orange) 45%, transparent); }
.ach-chip.unlocked .ach-icon { filter: drop-shadow(0 0 5px color-mix(in srgb, var(--orange) 45%, transparent)); }

/* ---------- 每週回顧（Forest/HabitBull 風格） ---------- */
.weekly-review { padding: 16px; }
.weekly-bar {
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--label) 10%, transparent);
  overflow: hidden;
  margin-bottom: 10px;
}
.weekly-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--accent));
  transition: width 0.5s ease;
}
.weekly-insight {
  font-size: 13px;
  color: var(--label);
  line-height: 1.5;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 10px;
  padding: 10px 12px;
}

/* ---------- 連擊保護（Streaks 風格） ---------- */
.guard-pill {
  border: none;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  margin-top: 6px;
  cursor: pointer;
  display: inline-block;
}
.guard-pill.static {
  cursor: default;
  color: var(--label-2);
  background: color-mix(in srgb, var(--label) 8%, transparent);
}
.guard-pill:active { transform: scale(0.96); }
