:root {
  --primary: #8b5cf6;
  --primary-dark: #7c3aed;
  --primary-light: #a78bfa;
  --accent: #c4b5fd;
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* 4) SVG / SHAPE SCALING FIXES */
svg {
  max-width: 100%;
  height: auto;
  display: block;
  /* Prevents inline spacing issues */
}

/* prevent auto-zoom on iOS inputs */
input,
textarea,
select {
  font-size: 16px !important;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  /* 2) SAFE AREA SUPPORT & 3) VIEWPORT HEIGHT */
  min-height: 100vh;
  min-height: 100dvh;
  /* iOS Safari 15+ */
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  /* Landscape support */
  padding-right: env(safe-area-inset-right);
  -webkit-user-select: none;
  user-select: none;
  overflow-x: hidden;
  /* Prevent horizontal scroll */
}

/* Re-enable select for inputs */
input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Typography */
h1,
h2,
h3,
h4 {
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-main);
}

h1 {
  font-size: 1.875rem;
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.25rem;
}

.text-sm {
  font-size: 0.875rem;
}

.text-xs {
  font-size: 0.75rem;
}

.text-muted {
  color: var(--text-muted);
}

.font-bold {
  font-weight: 600;
}

/* Layout */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

.header {
  padding: 16px 0;
  margin-bottom: 16px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.hero-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
}

.hero-card h2,
.hero-card p {
  color: white;
}

.hero-card button {
  background: white;
  color: var(--primary-dark);
  font-weight: 600;
  border: none;
  margin-top: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
}

.btn-sm {
  padding: 4px 12px;
  font-size: 0.75rem;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
}

/* Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 12px;
  z-index: 1000;
  /* Ensure high z-index */
  /* Safe area padding for home indicator */
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.75rem;
  gap: 4px;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Progress Ring */
.progress-ring circle {
  transition: stroke-dashoffset 0.35s;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

/* Week List */
.week-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.week-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.1s;
}

.week-card:active {
  transform: scale(0.98);
}

.progress-bar {
  height: 6px;
  background: var(--bg-body);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  width: 0%;
  transition: width 0.3s ease;
}

/* Exercise Item */
.exercise-item {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px 0;
  border-bottom: 1px solid var(--bg-body);
}

.exercise-item:last-child {
  border-bottom: none;
}

.checkbox-wrapper {
  padding-top: 2px;
}

.custom-checkbox {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: white;
}

.custom-checkbox.checked {
  background: var(--primary);
  border-color: var(--primary);
}

.exercise-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.exercise-title {
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.sets-reps-badge {
  display: inline-flex;
  align-items: center;
  background-color: var(--primary-light);
  color: #fff;
  /* White text on light purple might be low contrast? var(--primary) is #8b5cf6. var(--primary-light) is #a78bfa. */
  /* Let's use var(--primary) for background and white text for better contrast, or accent */
  background-color: var(--primary);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.exercise-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.completed .exercise-title {
  color: var(--text-muted);
  text-decoration: line-through;
}

.thumbnail {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #eee;
  object-fit: cover;
}

.video-btn {
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

.notes-area {
  margin-top: 8px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.875rem;
  resize: none;
}

/* Utility */
.hidden {
  display: none !important;
}

.fade-in {
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

input[type="text"],
input[type="search"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: 1rem;
}

input:focus,
textarea:focus {
  outline: 2px solid var(--primary-light);
  border-color: var(--primary);
}