:root {
  --bg: #12151c; --card: #1c212b; --fg: #e8ecf3; --dim: #8b93a5;
  --accent: #34d399; --blue: #60a5fa; --amber: #f59e0b;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  max-width: 640px; margin: 0 auto; padding: 0 14px 60px;
}
header { display: flex; align-items: center; gap: 8px; padding: 14px 0 6px; flex-wrap: wrap; }
header h1 { font-size: 18px; margin: 0; flex: 1; min-width: 70px; }
.level-badge { background: #252b38; border-radius: 20px; padding: 4px 10px; font-size: 12px; color: var(--amber); white-space: nowrap; }
.user-chip { max-width: none; overflow: visible; white-space: nowrap; }
.user-chip.logged-in { background: #1a2b24; border: 1px solid var(--accent); color: #fff; font-weight: 700; }
.ble-btn { background: var(--blue); border: 0; color: #fff; border-radius: 20px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.ble-btn.on { background: var(--accent); }

nav#tabs { display: flex; gap: 8px; margin: 10px 0 16px; }
nav#tabs button {
  flex: 1; padding: 10px; border: 0; border-radius: 12px;
  background: var(--card); color: var(--dim); font-size: 15px; cursor: pointer;
}
nav#tabs button.active { background: var(--accent); color: #0b100d; font-weight: 600; }

.tab { display: none; }
.tab.active { display: block; }
.card { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.date-line { color: var(--dim); margin-bottom: 10px; font-size: 14px; }

.metric-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.metric-row label { flex: 1; font-size: 14px; }
.metric-row label small { color: var(--dim); margin-left: 4px; }
.metric-row input {
  width: 90px; background: #12151c; border: 1px solid #2a2f3a; color: var(--fg);
  border-radius: 8px; padding: 8px; text-align: right; font-size: 15px;
}
.metric-row .delta { width: 70px; font-size: 12px; text-align: right; }
.delta.good { color: var(--accent); } .delta.bad { color: #f87171; }

#habitGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.habit {
  background: var(--card); border: 2px solid transparent; border-radius: 12px;
  padding: 12px 6px; text-align: center; cursor: pointer; font-size: 13px; color: var(--dim);
}
.habit .emoji { display: block; font-size: 22px; margin-bottom: 4px; }
.habit.done { border-color: var(--accent); color: var(--fg); background: #1a2b24; }

.score-line { margin-top: 14px; color: var(--amber); font-size: 14px; text-align: center; }
.reward-line { margin-top: 8px; color: var(--dim); font-size: 12px; text-align: center; line-height: 1.8; }
.reward-chip { display: inline-block; background: #252b38; border-radius: 999px; padding: 2px 8px; margin: 2px; color: var(--fg); }
.reward-chip.rare { border: 1px solid var(--blue); }
.reward-chip.legendary { border: 1px solid var(--amber); color: var(--amber); }
.confetti { position: fixed; top: -12px; width: 9px; height: 14px; border-radius: 2px; z-index: 999; pointer-events: none; animation: confetti-fall 1.2s ease-in forwards; }
@keyframes confetti-fall { to { transform: translateY(105vh) rotate(720deg); opacity: 0.2; } }

.goal-form-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.goal-form-row label { flex: 1; font-size: 14px; }
.goal-form-row input, .goal-form-row select {
  width: 100px; background: #12151c; border: 1px solid #2a2f3a; color: var(--fg);
  border-radius: 8px; padding: 8px; text-align: right;
}
button.primary {
  width: 100%; padding: 12px; border: 0; border-radius: 12px;
  background: var(--accent); color: #0b100d; font-size: 16px; font-weight: 600; cursor: pointer;
}
button.secondary {
  width: 100%; padding: 10px; border: 1px solid #2a2f3a; border-radius: 12px;
  background: transparent; color: var(--dim); cursor: pointer;
}
.chart-picker { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.chart-picker button {
  border: 1px solid #2a2f3a; background: transparent; color: var(--dim);
  border-radius: 16px; padding: 4px 12px; font-size: 13px; cursor: pointer;
}
.chart-picker button.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.goal-summary { color: var(--dim); font-size: 13px; margin-top: 8px; line-height: 1.7; }

.advice-item { background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.advice-item .cat { color: var(--amber); font-size: 12px; margin-bottom: 4px; }
.advice-item .text { font-size: 14px; line-height: 1.6; }

footer { text-align: center; color: #4a5264; font-size: 12px; margin-top: 30px; }

/* ---- AI 教练 ---- */
.chat-box { height: 55vh; overflow-y: auto; background: var(--card); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.chat-msg { max-width: 85%; padding: 10px 13px; border-radius: 14px; margin-bottom: 10px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.chat-msg.user { background: var(--blue); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.chat-msg.assistant { background: #252b38; border-bottom-left-radius: 4px; }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input {
  flex: 1; background: var(--card); border: 1px solid #2a2f3a; color: var(--fg);
  border-radius: 12px; padding: 12px; font-size: 15px;
}
.chat-input-row button { width: auto; padding: 12px 20px; }
.chat-status { color: var(--dim); font-size: 12px; text-align: center; margin-top: 6px; }

/* ---- 用户 / 社交 / 习惯管理 ---- */
.user-chip {
  background: #252b38; border: 0; color: var(--fg); border-radius: 20px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.user-chip .switch { color: var(--dim); font-size: 11px; margin-left: 4px; }

.modal {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  background: var(--card); border-radius: 16px; padding: 20px; width: 320px;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-card h3 { margin: 0 0 6px; }
.modal-card input {
  background: #12151c; border: 1px solid #2a2f3a; color: var(--fg);
  border-radius: 10px; padding: 12px; font-size: 15px;
}
.auth-btns { display: flex; gap: 8px; }
.auth-btns .primary { flex: 1; }
.auth-btns .secondary { width: auto; padding: 10px 16px; }
.auth-msg { color: var(--amber); font-size: 13px; min-height: 18px; text-align: center; }

.habit small { display: block; font-size: 11px; margin-top: 3px; }
.habit .habit-target { color: var(--blue); }
.habit .habit-reward { color: var(--amber); }
.all-done {
  background: linear-gradient(90deg, #2a1f0a, #1a2b24); border: 1px solid var(--amber);
  color: var(--amber); border-radius: 12px; padding: 10px; text-align: center;
  margin-bottom: 10px; font-size: 14px;
}

.mgr { margin-top: 16px; }
.mgr h3 { margin: 0 0 10px; font-size: 15px; }
.mgr-row { display: flex; gap: 6px; margin-bottom: 8px; }
.mgr-row input {
  background: #12151c; border: 1px solid #2a2f3a; color: var(--fg);
  border-radius: 8px; padding: 8px; font-size: 13px; min-width: 0;
}
.mgr-row .h-emoji { width: 40px; text-align: center; }
.mgr-row .h-label { flex: 1.2; }
.mgr-row .h-target { flex: 2; }
.mgr-row .h-reward { flex: 2; }
button.mini {
  border: 1px solid #2a2f3a; background: transparent; color: var(--dim);
  border-radius: 8px; padding: 3px 8px; font-size: 12px; cursor: pointer;
}
button.danger { color: #f87171; }

.share-row { margin-bottom: 12px; }
.post { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.post-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.post-head .me-tag { background: var(--accent); color: #0b100d; font-size: 10px; border-radius: 6px; padding: 1px 5px; }
.post-time { color: var(--dim); font-size: 12px; margin-left: auto; }
.post-text { font-size: 14px; line-height: 1.7; white-space: pre-wrap; }
.post-checkin {
  background: #12151c; border-radius: 10px; padding: 10px; margin-top: 8px;
  font-size: 13px; color: var(--accent); white-space: pre-wrap; line-height: 1.7;
}
.post-actions { margin-top: 8px; }
.like-btn { border: 0; background: transparent; font-size: 14px; cursor: pointer; color: var(--dim); }
.like-btn.liked { color: #f87171; }
.comments { margin-top: 8px; }
.comment { font-size: 13px; color: var(--dim); padding: 4px 0; border-top: 1px solid #232936; }
.comment b { color: var(--fg); }
.comment-row { display: flex; gap: 6px; margin-top: 8px; }
.comment-row input {
  flex: 1; background: #12151c; border: 1px solid #2a2f3a; color: var(--fg);
  border-radius: 8px; padding: 7px; font-size: 13px;
}
.comment-row button {
  border: 0; background: var(--blue); color: #fff; border-radius: 8px;
  padding: 0 12px; font-size: 13px; cursor: pointer;
}

.w-msg { color: var(--amber); font-size: 13px; text-align: center; min-height: 16px; }
.w-login-link { border: 0; background: transparent; color: var(--dim); font-size: 13px; cursor: pointer; padding: 4px; }
.w-login-link:hover { color: var(--blue); }
.w-logged { text-align: center; color: var(--accent); font-size: 14px; }
.w-links { display: flex; justify-content: space-between; }

/* ---- 数字孪生 ---- */
.webgl-error { color: var(--dim); text-align: center; padding: 60px 20px; font-size: 14px; line-height: 2; }
.twin-layout { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 560px) { .twin-layout { flex-direction: row; } .twin-stage { flex: 1.2; } .twin-panel { flex: 1; } }
.twin-stage {
  position: relative; background: radial-gradient(circle at 50% 30%, #1e2532, #12151c);
  border-radius: 14px; min-height: 380px; overflow: hidden;
}
#twinCanvas { width: 100%; height: 380px; display: block; cursor: grab; }
#twinCanvas:active { cursor: grabbing; }
.twin-hint {
  position: absolute; bottom: 10px; left: 0; right: 0; text-align: center;
  color: var(--dim); font-size: 12px; pointer-events: none;
}
.twin-bubble {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(37, 43, 56, 0.95); border: 1px solid #2a2f3a; color: var(--fg);
  border-radius: 14px; padding: 8px 14px; font-size: 13px; max-width: 85%;
  z-index: 5; white-space: pre-wrap;
}
.twin-photo-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.twin-photo {
  width: 72px; height: 72px; object-fit: cover; border-radius: 12px;
  border: 1px solid #2a2f3a;
}
.twin-photo.wide { width: 100%; height: 120px; }
.twin-photo.placeholder {
  display: flex; align-items: center; justify-content: center; text-align: center;
  color: var(--dim); font-size: 12px; background: #12151c; line-height: 1.4;
}
.mini-btn {
  border: 1px solid #2a2f3a; background: #252b38; color: var(--fg);
  border-radius: 10px; padding: 8px 12px; font-size: 13px; cursor: pointer;
}
.motto-banner {
  background: linear-gradient(90deg, #1a2b24, #1e2532); border: 1px solid var(--accent);
  color: var(--accent); border-radius: 12px; padding: 12px 16px; margin-bottom: 12px;
  font-size: 16px; text-align: center; font-style: italic;
}
/* ---- 打卡增强 / 增肌 / 平台期 / 欢迎页 ---- */
.day-photo-row { display: flex; align-items: center; gap: 10px; margin: 12px 0 8px; }
.day-photo-thumb { height: 64px; border-radius: 10px; border: 1px solid #2a2f3a; }
.recent-photos { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 6px; }
.recent-photo { height: 48px; border-radius: 8px; border: 1px solid #2a2f3a; flex: none; }
.habit .habit-week { color: var(--amber); }
.habit .habit-time { color: var(--accent); }

.muscle-hero { text-align: center; padding: 10px 0; }
.muscle-num { font-size: 44px; font-weight: 700; color: var(--fg); }
.muscle-num small { font-size: 16px; color: var(--dim); margin-left: 4px; }
.muscle-rating { margin-top: 6px; font-size: 15px; }
.protein-target { font-size: 30px; font-weight: 700; color: var(--accent); text-align: center; padding: 8px 0; }
.protein-target small { font-size: 13px; color: var(--dim); font-weight: 400; display: block; }
.progress-bar { background: #12151c; border-radius: 12px; height: 16px; overflow: hidden; margin: 8px 0; }
.progress-fill { background: linear-gradient(90deg, var(--accent), #10b981); height: 100%; border-radius: 12px; transition: width 0.4s; }
.stat-grid { display: flex; gap: 10px; }
.stat { flex: 1; background: #12151c; border-radius: 12px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 24px; color: var(--fg); margin: 4px 0; }
.stat b.hl { color: var(--amber); }
.stat small { color: var(--dim); font-size: 12px; }

.plateau-detail { color: var(--dim); font-size: 14px; line-height: 1.7; }
.plateau-prediction {
  background: linear-gradient(90deg, #1a2b24, #1e2532); border: 1px solid var(--accent);
  border-radius: 12px; padding: 12px; font-size: 14px; line-height: 1.7; margin: 10px 0;
}
.plateau-plan b { display: block; margin-bottom: 8px; }
.plan-item {
  display: flex; gap: 10px; align-items: flex-start; padding: 8px 0;
  border-top: 1px solid #232936; font-size: 13px; line-height: 1.6; cursor: pointer;
}
.plan-item input { margin-top: 3px; accent-color: var(--accent); }
.plan-item.done span { text-decoration: line-through; color: var(--dim); }

.welcome-overlay {
  position: fixed; inset: 0; background: rgba(10, 12, 16, 0.96); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.welcome-card {
  background: var(--card); border-radius: 20px; padding: 24px; width: 100%; max-width: 400px;
  display: flex; flex-direction: column; gap: 12px; max-height: 92vh; overflow-y: auto;
}
.welcome-hero { font-size: 46px; text-align: center; }
.welcome-card h2 { margin: 0; text-align: center; }
.welcome-sub { color: var(--dim); font-size: 13px; text-align: center; margin: 0; line-height: 1.6; }
.welcome-card input, .welcome-card select {
  background: #12151c; border: 1px solid #2a2f3a; color: var(--fg);
  border-radius: 10px; padding: 12px; font-size: 15px; width: 100%;
}
.w-row { display: flex; gap: 8px; }
.w-row input, .w-row select { min-width: 0; }
.w-row #wSex { width: 70px; flex: none; }
.w-goals { display: flex; gap: 8px; }
.w-goal {
  flex: 1; border: 2px solid #2a2f3a; background: transparent; color: var(--dim);
  border-radius: 12px; padding: 12px 4px; font-size: 14px; cursor: pointer;
}
.w-goal.sel { border-color: var(--accent); color: var(--fg); background: #1a2b24; }
.w-msg { color: var(--amber); font-size: 13px; text-align: center; min-height: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%) translateY(20px);
  background: var(--accent); color: #0b100d; font-weight: 600; font-size: 14px;
  border-radius: 24px; padding: 10px 20px; opacity: 0; transition: all 0.3s; z-index: 200;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
