:root {
  --bg-primary: #FFFFFF;
  --bg-secondary: #F5F5F5;
  --text-primary: #1A1A1A;
  --text-secondary: #666;
  --card-bg: #FFFFFF;
  --border: #E0E0E0;
  --accent: #3B82F6;
  --dot-red: #FF4444;
  --dot-blue: #3B82F6;
  --dot-green: #10B981;
  --dot-yellow: #F59E0B;
  --dot-purple: #8B5CF6;
  --dot-brown: #8B4513;
  --dot-gray: #9CA3AF;
  --level-0: #ebedf0;
  --level-1: #9be9a8;
  --level-2: #216e39;
  --muscle-bg: #e0e0e0;
  --muscle-stroke: #ffffff;
  --muscle-active: #ff4757;
  --svg-text: #666666;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1A1A1A;
    --bg-secondary: #252525;
    --text-primary: #EEEEEE;
    --text-secondary: #BBBBBB;
    --card-bg: #2A2A2A;
    --border: #3A3A3A;
    --accent: #60A5FA;
    --level-0: #161b22;
    --level-1: #0e4429;
    --level-2: #39d353;
    --muscle-bg: #333333;
    --muscle-stroke: #1a1a1a;
    --muscle-active: #ff4757;
    --svg-text: #aaaaaa;
  }
}

#fitness-app {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100vh;
  padding-bottom: calc(60px + env(safe-area-inset-bottom));
  position: relative;
  margin: 0 auto;
}

/* Month Nav */
.month-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 48px;
  padding: 0 16px;
  font-size: 1.1rem;
  font-weight: bold;
}
.month-nav button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.5rem;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}

/* Calendar */
.calendar-container {
  padding: 0 8px;
}
.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.day-cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 4px;
  border-radius: 8px;
  cursor: pointer;
}
.day-cell.empty {
  cursor: default;
}
.day-cell.today {
  border: 2px solid var(--accent);
}
.day-cell.has-data {
  background-color: var(--bg-secondary);
}
/* P2-21: active press scale feedback */
.day-cell:active {
  transform: scale(0.92);
  transition: transform 0.1s ease;
}
.day-number {
  font-size: 1rem;
  font-weight: 500;
}
.dots-container {
  display: flex;
  gap: 2px;
  margin-top: auto;
  margin-bottom: 4px;
  justify-content: center;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dot-red { background-color: var(--dot-red); }
.dot-blue { background-color: var(--dot-blue); }
.dot-green { background-color: var(--dot-green); }
.dot-yellow { background-color: var(--dot-yellow); }
.dot-purple { background-color: var(--dot-purple); }
.dot-brown { background-color: var(--dot-brown); }
.dot-gray { background-color: var(--dot-gray); }

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background-color: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-width: 60px;
  min-height: 44px;
  cursor: pointer;
}
.nav-item svg {
  color: inherit;
}
.nav-item.active {
  color: var(--accent);
  font-weight: bold;
}

/* Bottom Sheet */
.bottom-sheet-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
}
.bottom-sheet {
  position: fixed;
  bottom: -100%;
  left: 0;
  right: 0;
  height: 60vh;
  background-color: var(--card-bg);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  z-index: 1001;
  transition: bottom 0.3s ease-out;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
}
.bottom-sheet.open {
  bottom: 0;
}
.sheet-handle {
  width: 40px;
  height: 4px;
  background-color: var(--border);
  border-radius: 2px;
  margin: 12px auto;
  cursor: pointer;
}
.sheet-content {
  padding: 0 20px 20px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.sheet-content h3 {
  margin: 0 0 4px 0;
  font-size: 1.2rem;
}
.sheet-sub {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0 0 16px 0;
}
.sheet-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}
.exercise-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.exercise-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ex-name {
  flex: 2;
  font-weight: 500;
}
.ex-sets {
  flex: 1;
  color: var(--text-secondary);
  text-align: center;
}
.ex-weight {
  flex: 1;
  text-align: right;
  color: var(--text-secondary);
}
.diet-info {
  margin-top: 16px;
  padding: 12px;
  background-color: var(--bg-secondary);
  border-radius: 8px;
  font-size: 0.95rem;
}

/* Tab Containers */
.heatmap-container, .weight-container, .stats-container {
  padding: 16px;
}
.heatmap-container h3, .weight-container h3, .stats-container h3 {
  margin-top: 0;
  margin-bottom: 16px;
  text-align: center;
}

/* Heatmap */
.heatmap-scroll {
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.heatmap-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.heatmap-month-group {
  display: flex;
  align-items: center;
}
.heatmap-month-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-right: 8px;
  min-width: 25px;
  text-align: right;
}
.heatmap-month-weeks {
  display: flex;
  gap: 3px;
}
.heatmap-week {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.heatmap-cell {
  width: 16px;
  height: 16px;
  border-radius: 2px;
  background-color: var(--level-0);
}
.heatmap-cell.level-1 { background-color: var(--level-1); }
.heatmap-cell.level-2 { background-color: var(--level-2); }
/* P2-18: current week highlight in heatmap */
.heatmap-week.current-week {
  background-color: rgba(59, 130, 246, 0.1);
  border-radius: 3px;
  outline: 1px dashed var(--accent);
  outline-offset: 1px;
}
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  justify-content: flex-end;
  margin-top: 8px;
}

/* Charts */
.chart-wrapper {
  position: relative;
  height: 250px;
  width: 100%;
}
.pie-wrapper {
  height: 200px;
}
.weight-summary {
  display: flex;
  justify-content: space-around;
  margin-top: 20px;
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: 8px;
  text-align: center;
}
.stat-box span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.stat-box b {
  font-size: 1.2rem;
  color: var(--accent);
}

/* Muscle SVG */
.muscle-view-toggle {
  text-align: center;
  margin-top: 16px;
}
.muscle-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 20px;
  color: var(--text-secondary);
  cursor: pointer;
}
.muscle-svg-container {
  margin-top: 16px;
  padding: 10px;
  background: var(--bg-secondary);
  border-radius: 8px;
}
.muscle-svg-container svg {
  width: 100%;
  max-width: 300px;
  height: auto;
}

/* P1-14: Skeleton loading */
.skeleton-container {
  padding: 16px;
}
.skeleton-header {
  height: 48px;
  background: var(--bg-secondary);
  border-radius: 8px;
  margin-bottom: 12px;
  animation: sk-pulse 1.5s ease-in-out infinite;
}
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 20px;
}
.sk-box {
  aspect-ratio: 1;
  background: var(--bg-secondary);
  border-radius: 8px;
  animation: sk-pulse 1.5s ease-in-out infinite;
}
.skeleton-bar {
  height: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  margin-bottom: 12px;
  animation: sk-pulse 1.5s ease-in-out infinite;
}
.skeleton-bar.short { width: 60%; }
@keyframes sk-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* P1-7: Pull-to-refresh */
.ptr-indicator {
  overflow: hidden;
  transition: height 0.2s ease;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.ptr-indicator.ptr-active .ptr-content {
  opacity: 1;
}
.ptr-content {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.ptr-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ptr-spin 0.7s linear infinite;
}
@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}

