/* ─── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1e2a4a;
  --bg-input: #253254;
  --accent: #FF6B00;
  --accent-hover: #e85d00;
  --accent-light: rgba(255, 107, 0, 0.15);
  --text-primary: #ffffff;
  --text-secondary: #a0a8c0;
  --text-muted: #6b7294;
  --border: #2a365a;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --tg-bg: var(--bg-primary);
  --tg-text: var(--text-primary);
  --tg-hint: var(--text-secondary);
  --tg-btn: var(--accent);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: 56px;
  --header-height: 48px;
  font-size: 16px;
}

html, body {
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ─── Splash ──────────────────────────────────────────── */
.splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: var(--bg-primary);
  gap: 16px;
  transition: opacity 0.4s ease;
}
.splash.hidden { opacity: 0; pointer-events: none; }
.splash .logo { font-size: 64px; }
.splash h1 { font-size: 28px; font-weight: 800; color: var(--accent); }
.splash p { color: var(--text-secondary); font-size: 14px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin-top: 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Header ──────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  padding-top: calc(8px + var(--safe-top));
  height: calc(var(--header-height) + var(--safe-top));
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-title { font-size: 17px; font-weight: 700; }
.header-btn {
  background: none; border: none; color: var(--text-primary);
  width: 36px; height: 36px; display: flex; align-items: center;
  justify-content: center; border-radius: 10px; cursor: pointer;
  font-size: 20px; transition: background 0.2s;
}
.header-btn:active { background: var(--bg-card); }
.header-right { display: flex; gap: 4px; }

/* ─── Bottom Navigation ───────────────────────────────── */
.bottom-nav {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 4px 8px;
  padding-bottom: calc(4px + var(--safe-bottom));
  height: calc(var(--nav-height) + var(--safe-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 100;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none; border: none;
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 8px;
  transition: all 0.2s;
  min-width: 56px;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--accent); }
.nav-item:active { background: var(--accent-light); }
.nav-add svg { color: var(--accent); width: 26px; height: 26px; }

/* ─── Page Container ──────────────────────────────────── */
.page-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
.page { display: none; padding: 0 16px 16px; min-height: 100%; }
.page.active { display: block; }

/* ─── Onboarding ──────────────────────────────────────── */
.onboarding {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 32px 20px;
  gap: 24px;
  text-align: center;
}
.onboarding h2 { font-size: 22px; font-weight: 700; }
.onboarding p { color: var(--text-secondary); font-size: 14px; line-height: 1.5; max-width: 320px; }
.onboarding .progress-dots { display: flex; gap: 8px; margin: 8px 0; }
.onboarding .progress-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--border); transition: all 0.3s; }
.onboarding .progress-dots span.active { background: var(--accent); width: 24px; border-radius: 4px; }
.onboarding .step-content { width: 100%; max-width: 360px; }
.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}
.option-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.option-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px 12px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.option-card .icon { font-size: 28px; }
.option-card .label { font-size: 13px; font-weight: 600; }
.option-card .desc { font-size: 11px; color: var(--text-secondary); }
.option-card.selected { border-color: var(--accent); background: var(--accent-light); }
.option-card:active { transform: scale(0.96); }
.day-pills {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px 0;
}
.day-pill {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
}
.day-pill.selected { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }
.day-pill:active { transform: scale(0.92); }
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-primary:active { transform: scale(0.97); background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-secondary {
  width: 100%;
  padding: 14px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-secondary:active { background: var(--bg-input); }
.btn-outline {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-outline:active { background: var(--accent-light); }
.btn-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 18px;
}
.btn-icon:active { background: var(--bg-input); }

/* ─── Feed ────────────────────────────────────────────── */
.feed-pull { text-align: center; padding: 12px; color: var(--text-muted); font-size: 13px; }
.post-card {
  background: var(--bg-card);
  border-radius: 14px;
  margin-bottom: 12px;
  overflow: hidden;
}
.post-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 0;
}
.post-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px; font-weight: 700;
  color: white;
  flex-shrink: 0;
  overflow: hidden;
}
.post-avatar img { width: 100%; height: 100%; object-fit: cover; }
.post-author { flex: 1; }
.post-author-name { font-size: 14px; font-weight: 600; }
.post-author-name .level-badge {
  font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: var(--accent-light); color: var(--accent); margin-left: 6px;
  font-weight: 500;
}
.post-date { font-size: 11px; color: var(--text-muted); }
.post-type-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 6px;
  background: var(--accent-light); color: var(--accent);
}
.post-image {
  width: 100%; aspect-ratio: 4/3;
  object-fit: cover;
  margin-top: 10px;
  background: var(--bg-input);
}
.post-text { padding: 10px 14px; font-size: 14px; line-height: 1.5; }
.post-tags { display: flex; gap: 6px; padding: 0 14px 8px; flex-wrap: wrap; }
.post-tag {
  font-size: 12px; padding: 3px 8px; border-radius: 6px;
  background: var(--bg-input); color: var(--text-secondary);
}
.post-actions {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 14px 12px; border-top: 1px solid var(--border);
}
.post-action-btn {
  display: flex; align-items: center; gap: 4px;
  background: none; border: none; color: var(--text-secondary);
  font-size: 13px; padding: 6px 12px; border-radius: 8px;
  cursor: pointer; font-family: inherit;
  transition: all 0.2s;
}
.post-action-btn:active { background: var(--bg-input); }
.post-action-btn.liked { color: var(--accent); }
.post-action-btn .count { font-size: 12px; }
.copy-program-btn {
  margin: 0 14px 12px;
  padding: 10px;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 10px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.copy-program-btn:active { background: rgba(255, 107, 0, 0.25); }
.feed-end { text-align: center; padding: 20px; color: var(--text-muted); font-size: 13px; }
.feed-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 300px; gap: 12px;
  color: var(--text-muted);
}
.feed-empty .icon { font-size: 48px; }
.feed-empty p { font-size: 14px; }

/* ─── Profile ─────────────────────────────────────────── */
.profile-header {
  display: flex; flex-direction: column; align-items: center;
  padding: 24px 0 16px; text-align: center; gap: 8px;
}
.profile-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center;
  justify-content: center; font-size: 28px; font-weight: 700;
  color: white; overflow: hidden;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-name { font-size: 20px; font-weight: 700; }
.profile-bio { font-size: 14px; color: var(--text-secondary); max-width: 320px; }
.profile-meta { display: flex; gap: 16px; margin: 8px 0; }
.profile-meta-item { text-align: center; }
.profile-meta-value { font-size: 18px; font-weight: 700; }
.profile-meta-label { font-size: 11px; color: var(--text-muted); }
.profile-badges { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.badge {
  font-size: 12px; padding: 4px 10px; border-radius: 8px;
  background: var(--accent-light); color: var(--accent); font-weight: 500;
}
.badge-secondary { background: var(--bg-input); color: var(--text-secondary); }
.profile-tabs {
  display: flex; border-bottom: 1px solid var(--border); margin: 12px 0;
}
.profile-tab {
  flex: 1; text-align: center; padding: 10px; font-size: 14px;
  font-weight: 600; color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent; transition: all 0.2s;
}
.profile-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.profile-section { padding: 8px 0; }
.section-title { font-size: 15px; font-weight: 600; margin: 16px 0 8px; }
.program-mini-card {
  background: var(--bg-card); border-radius: 12px;
  padding: 12px; margin-bottom: 8px; cursor: pointer;
  transition: all 0.2s;
}
.program-mini-card:active { background: var(--bg-input); }
.program-mini-card .title { font-size: 14px; font-weight: 600; }
.program-mini-card .subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ─── Tracker ─────────────────────────────────────────── */
.tracker-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0; flex-wrap: wrap; gap: 8px;
}
.tracker-header h2 { font-size: 20px; font-weight: 700; }
.tracker-header .date { color: var(--text-secondary); font-size: 13px; }
.exercise-card {
  background: var(--bg-card); border-radius: 14px;
  padding: 14px; margin-bottom: 10px;
}
.exercise-card .ex-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.exercise-card .ex-name { font-size: 15px; font-weight: 600; }
.exercise-card .ex-muscles { font-size: 11px; color: var(--text-secondary); }
.set-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.set-row:last-child { border-bottom: none; }
.set-row .set-num { width: 28px; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.set-row .set-target { flex: 1; font-size: 13px; color: var(--text-secondary); }
.set-row .set-weight { width: 70px; text-align: right; font-size: 13px; color: var(--text-primary); }
.set-checkbox {
  width: 22px; height: 22px; border-radius: 6px;
  border: 2px solid var(--border); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; flex-shrink: 0;
  background: transparent;
}
.set-checkbox.checked { background: var(--accent); border-color: var(--accent); }
.set-checkbox.checked::after { content: '✓'; color: white; font-size: 12px; font-weight: 700; }
.set-checkbox:active { transform: scale(0.9); }

.rest-timer {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 12px; margin-bottom: 10px;
  background: var(--bg-input); border-radius: 12px;
}
.rest-timer .time { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rest-timer .label { font-size: 13px; color: var(--text-secondary); }
.rest-timer.active { border: 1px solid var(--accent); }
.timer-controls { display: flex; gap: 8px; }
.timer-btn {
  padding: 8px 16px; border-radius: 8px; border: none;
  font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all 0.2s;
}
.timer-btn:active { transform: scale(0.95); }
.timer-btn-start { background: var(--accent); color: white; }
.timer-btn-stop { background: var(--danger); color: white; }

.tracker-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 300px; gap: 12px;
  color: var(--text-muted); text-align: center;
}
.tracker-empty .icon { font-size: 48px; }
.tracker-empty h3 { font-size: 16px; color: var(--text-primary); }

/* ─── Challenges ──────────────────────────────────────── */
.challenge-card {
  background: var(--bg-card); border-radius: 14px;
  padding: 14px; margin-bottom: 10px; cursor: pointer;
  transition: all 0.2s;
}
.challenge-card:active { background: var(--bg-input); }
.challenge-card .title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.challenge-card .meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-secondary); flex-wrap: wrap; }
.challenge-card .meta span { display: flex; align-items: center; gap: 4px; }
.challenge-card .progress-bar {
  height: 4px; background: var(--bg-input); border-radius: 2px;
  margin-top: 10px; overflow: hidden;
}
.challenge-card .progress-fill {
  height: 100%; background: var(--accent); border-radius: 2px;
  transition: width 0.5s ease;
}
.leaderboard-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.leaderboard-item:last-child { border-bottom: none; }
.leaderboard-rank {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  background: var(--bg-input); color: var(--text-secondary);
  flex-shrink: 0;
}
.leaderboard-rank.top3 { background: var(--accent); color: white; }
.leaderboard-user { flex: 1; display: flex; align-items: center; gap: 8px; }
.leaderboard-user .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center;
  justify-content: center; font-size: 12px; color: white; font-weight: 600;
  overflow: hidden;
}
.leaderboard-user .avatar img { width: 100%; height: 100%; object-fit: cover; }
.leaderboard-user .name { font-size: 13px; font-weight: 500; }
.leaderboard-score { font-size: 14px; font-weight: 700; color: var(--accent); }

/* ─── Create Post ─────────────────────────────────────── */
.create-form { padding: 16px 0; }
.create-form textarea {
  width: 100%; min-height: 120px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; color: var(--text-primary);
  font-size: 15px; font-family: inherit; resize: none;
  outline: none; transition: border 0.2s;
}
.create-form textarea:focus { border-color: var(--accent); }
.create-form .type-selector {
  display: flex; gap: 8px; margin: 12px 0;
}
.type-option {
  flex: 1; padding: 10px; text-align: center;
  border-radius: 10px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-secondary);
}
.type-option.selected { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.create-form .program-selector {
  margin: 12px 0;
}
.program-option {
  padding: 12px; background: var(--bg-card); border-radius: 10px;
  margin-bottom: 6px; cursor: pointer; border: 1px solid var(--border);
  transition: all 0.2s;
}
.program-option.selected { border-color: var(--accent); background: var(--accent-light); }

/* ─── Post Detail ─────────────────────────────────────── */
.post-detail-card { background: var(--bg-card); border-radius: 14px; overflow: hidden; margin-bottom: 16px; }
.post-detail-card .post-image { aspect-ratio: 16/9; }
.comments-section { padding: 8px 0; }
.comment-input {
  display: flex; gap: 8px; padding: 8px 0;
}
.comment-input input {
  flex: 1; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-primary); font-size: 14px; font-family: inherit;
  outline: none;
}
.comment-input input:focus { border-color: var(--accent); }
.comment-input button {
  padding: 10px 16px; border-radius: 10px; border: none;
  background: var(--accent); color: white; font-weight: 600;
  font-size: 14px; cursor: pointer; font-family: inherit;
}

/* ─── Search ──────────────────────────────────────────── */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-card); border-radius: 12px;
  padding: 0 14px; margin: 12px 0;
}
.search-bar input {
  flex: 1; padding: 12px 0; background: none; border: none;
  color: var(--text-primary); font-size: 14px; font-family: inherit;
  outline: none;
}
.search-bar svg { color: var(--text-muted); flex-shrink: 0; }

/* ─── Utility ─────────────────────────────────────────── */
.hidden { display: none !important; }
.text-accent { color: var(--accent); }
.text-muted { color: var(--text-secondary); }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.gap-8 { gap: 8px; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-input) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
