*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0a;
  --bg-card: #141414;
  --bg-card-hover: #1a1a1a;
  --bg-glass: rgba(255,255,255,0.04);
  --bg-glass-hover: rgba(255,255,255,0.08);
  --accent: #FF6B35;
  --accent-light: #FF8F5E;
  --accent-dark: #E05A28;
  --gradient: linear-gradient(135deg, #FF6B35, #F7931E);
  --gradient-glow: linear-gradient(135deg, rgba(255,107,53,0.3), rgba(247,147,30,0.3));
  --text: #f0f0f0;
  --text-secondary: #888;
  --text-muted: #555;
  --green: #4CAF50;
  --green-glow: rgba(76,175,80,0.3);
  --red: #FF4444;
  --blue: #4A90D9;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Outfit', 'Inter', sans-serif;
}

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: calc(72px + var(--safe-bottom));
}

/* ===== Utilities ===== */
.hidden { display: none !important; }
.fade-in { animation: fadeIn 0.3s ease; }
.slide-up { animation: slideUp 0.35s cubic-bezier(0.16,1,0.3,1); }
.slide-right { animation: slideRight 0.3s ease; }
.pulse { animation: pulse 2s infinite; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideRight { from { transform: translateX(-20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
@keyframes countdown { from { stroke-dashoffset: 0; } to { stroke-dashoffset: 283; } }
@keyframes breathe { 0%,100% { box-shadow: 0 0 20px rgba(255,107,53,0.3); } 50% { box-shadow: 0 0 40px rgba(255,107,53,0.6); } }

/* ===== Typography ===== */
.heading-xl { font-family: var(--font-display); font-size: 2rem; font-weight: 800; line-height: 1.1; }
.heading-lg { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.heading-md { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; }
.text-sm { font-size: 0.85rem; color: var(--text-secondary); }
.text-xs { font-size: 0.75rem; color: var(--text-muted); }
.text-accent { color: var(--accent); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 28px; border: none; border-radius: var(--radius);
  font-family: var(--font); font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s ease;
  text-decoration: none;
}
.btn-primary {
  background: var(--gradient); color: #fff;
  box-shadow: 0 4px 20px rgba(255,107,53,0.3);
}
.btn-primary:active { transform: scale(0.96); box-shadow: 0 2px 10px rgba(255,107,53,0.4); }
.btn-secondary {
  background: var(--bg-glass); color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
}
.btn-secondary:active { background: var(--bg-glass-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 8px; }
.btn-ghost:active { color: var(--text); }
.btn-round {
  width: 56px; height: 56px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.btn-sm { padding: 10px 20px; font-size: 0.9rem; border-radius: var(--radius-sm); }
.btn-full { width: 100%; }
.btn-icon { width: 44px; height: 44px; border-radius: 50%; padding: 0; background: var(--bg-glass); border: none; color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.btn-icon:active { background: var(--bg-glass-hover); transform: scale(0.92); }

/* ===== Header / Navbar ===== */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; padding-top: calc(16px + var(--safe-top));
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,10,0.85); backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.header-title { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; }
.header-back { display: flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 600; background: none; border: none; cursor: pointer; font-size: 0.95rem; font-family: var(--font); }

/* ===== Bottom Nav ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  display: flex; justify-content: space-around; align-items: center;
  padding: 8px 16px; padding-bottom: calc(8px + var(--safe-bottom));
  background: rgba(10,10,10,0.92); backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255,255,255,0.06);
  z-index: 200;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 12px; border: none; background: none; cursor: pointer;
  color: var(--text-muted); font-size: 0.65rem; font-family: var(--font);
  font-weight: 500; transition: color 0.2s;
}
.nav-item.active { color: var(--accent); }
.nav-item svg { width: 24px; height: 24px; }

/* ===== Page: Home ===== */
.page { padding: 0 20px 20px; }
.home-greeting { padding: 20px 0 8px; }
.home-greeting h1 { font-family: var(--font-display); font-size: 1.6rem; font-weight: 800; }
.home-greeting p { color: var(--text-secondary); margin-top: 4px; }
.home-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin: 16px 0;
}
.stat-card {
  background: var(--bg-card); border-radius: var(--radius-sm);
  padding: 14px 12px; text-align: center;
  border: 1px solid rgba(255,255,255,0.04);
}
.stat-value { font-family: var(--font-display); font-size: 1.4rem; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.5px; }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 24px 0 12px;
}
.section-title h2 { font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; }

/* ===== Category Cards ===== */
.category-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.category-card {
  position: relative; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16/11; cursor: pointer;
  transition: transform 0.2s; border: 1px solid rgba(255,255,255,0.06);
}
.category-card:active { transform: scale(0.97); }
.category-card img {
  width: 100%; height: 100%; object-fit: cover;
  filter: brightness(0.6);
}
.category-card-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 60%);
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 14px;
}
.category-card-name { font-family: var(--font-display); font-size: 1rem; font-weight: 700; }
.category-card-count { font-size: 0.75rem; color: var(--text-secondary); }
.category-card.full-width { grid-column: 1 / -1; aspect-ratio: 21/9; }

/* ===== Workout List ===== */
.level-tabs {
  display: flex; gap: 8px; margin: 16px 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.level-tab {
  padding: 10px 20px; border-radius: 999px; border: none;
  font-family: var(--font); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  background: var(--bg-glass); color: var(--text-secondary);
  transition: all 0.2s; flex-shrink: 0;
}
.level-tab.active { background: var(--gradient); color: #fff; }

.workout-info {
  display: flex; gap: 20px; margin: 12px 0 16px;
  padding: 14px 16px; background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.04);
}
.workout-info-item { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--text-secondary); }
.workout-info-item svg { width: 18px; height: 18px; color: var(--accent); }

.exercise-list { display: flex; flex-direction: column; gap: 2px; }
.exercise-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0; border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer; transition: background 0.15s;
}
.exercise-item:active { background: var(--bg-glass); }
.exercise-number {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-glass); display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; color: var(--text-secondary);
  flex-shrink: 0;
}
.exercise-details { flex: 1; min-width: 0; }
.exercise-name { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exercise-meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }
.exercise-meta span { color: var(--accent); }

/* ===== Active Workout ===== */
.workout-screen {
  position: fixed; inset: 0; z-index: 500;
  background: var(--bg); display: flex; flex-direction: column;
}
.workout-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; padding-top: calc(16px + var(--safe-top));
}
.workout-progress-bar {
  height: 4px; background: rgba(255,255,255,0.08);
  border-radius: 2px; margin: 0 20px;
}
.workout-progress-fill {
  height: 100%; background: var(--gradient); border-radius: 2px;
  transition: width 0.3s ease;
}
.workout-body {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 20px; text-align: center; overflow-y: auto;
}
.exercise-animation {
  width: 200px; height: 200px; margin: 0 auto 24px;
  background: var(--bg-card); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 3px solid rgba(255,255,255,0.06);
  position: relative;
}
.exercise-animation .exercise-icon {
  font-size: 4rem; animation: exerciseBounce 1s ease-in-out infinite;
}
@keyframes exerciseBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.exercise-title { font-family: var(--font-display); font-size: 1.5rem; font-weight: 800; margin-bottom: 8px; }
.exercise-instruction { color: var(--text-secondary); font-size: 0.9rem; max-width: 340px; margin: 0 auto 24px; line-height: 1.5; max-height: 80px; overflow-y: auto; }

/* Timer Circle */
.timer-container { position: relative; width: 160px; height: 160px; margin: 0 auto 20px; }
.timer-circle {
  transform: rotate(-90deg);
  width: 160px; height: 160px;
}
.timer-bg { fill: none; stroke: rgba(255,255,255,0.06); stroke-width: 6; }
.timer-progress { fill: none; stroke: url(#timerGradient); stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset 0.3s linear; }
.timer-text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.timer-value { font-family: var(--font-display); font-size: 3rem; font-weight: 900; }
.timer-label { font-size: 0.8rem; color: var(--text-secondary); text-transform: uppercase; }

/* Rep Counter */
.rep-counter { margin: 0 auto 20px; text-align: center; }
.rep-value { font-family: var(--font-display); font-size: 4rem; font-weight: 900; color: var(--accent); }
.rep-label { font-size: 0.9rem; color: var(--text-secondary); }

.workout-controls {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
}
.btn-workout-main {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--gradient); border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s;
  box-shadow: 0 4px 24px rgba(255,107,53,0.4);
}
.btn-workout-main:active { transform: scale(0.92); }
.btn-workout-main svg { width: 32px; height: 32px; fill: #fff; }
.btn-workout-nav {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--bg-glass); border: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-secondary); transition: all 0.2s;
}
.btn-workout-nav:active { background: var(--bg-glass-hover); }

/* ===== Rest Screen ===== */
.rest-screen {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 20px;
}
.rest-screen h2 { font-family: var(--font-display); font-size: 1.3rem; color: var(--text-secondary); margin-bottom: 20px; text-transform: uppercase; letter-spacing: 2px; }
.rest-timer { font-family: var(--font-display); font-size: 6rem; font-weight: 900; color: var(--accent); line-height: 1; }
.rest-next { margin-top: 32px; color: var(--text-secondary); font-size: 0.9rem; }
.rest-next strong { color: var(--text); display: block; margin-top: 4px; font-size: 1.1rem; }
.btn-skip-rest { margin-top: 24px; }

/* ===== Complete Screen ===== */
.complete-screen {
  position: fixed; inset: 0; z-index: 600;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 20px;
}
.complete-trophy { font-size: 5rem; margin-bottom: 16px; animation: pulse 2s infinite; }
.complete-title { font-family: var(--font-display); font-size: 2rem; font-weight: 900; margin-bottom: 8px; }
.complete-subtitle { color: var(--text-secondary); margin-bottom: 32px; }
.complete-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  width: 100%; max-width: 340px; margin-bottom: 40px;
}
.complete-stat { text-align: center; }
.complete-stat-value { font-family: var(--font-display); font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.complete-stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; margin-top: 2px; }

/* ===== Page: History / Report ===== */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 16px 0; }
.calendar-day {
  aspect-ratio: 1; border-radius: var(--radius-xs);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; color: var(--text-muted);
}
.calendar-day.has-workout { background: var(--gradient-glow); color: var(--accent); font-weight: 700; }
.calendar-day.today { border: 1px solid var(--accent); color: var(--text); }
.calendar-weekday { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }

.history-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px; background: var(--bg-card); border-radius: var(--radius-sm);
  margin-bottom: 8px; border: 1px solid rgba(255,255,255,0.04);
}
.history-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gradient); flex-shrink: 0; }
.history-details { flex: 1; }
.history-title { font-weight: 600; font-size: 0.95rem; }
.history-meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }

/* ===== Exercise Detail Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(8px);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-content {
  background: var(--bg-card); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 480px; max-height: 80vh;
  padding: 24px 20px; padding-bottom: calc(24px + var(--safe-bottom));
  overflow-y: auto; animation: slideUp 0.3s ease;
}
.modal-handle {
  width: 36px; height: 4px; background: rgba(255,255,255,0.2);
  border-radius: 2px; margin: 0 auto 20px;
}
.modal-close { position: absolute; top: 16px; right: 16px; }

/* ===== Settings Page ===== */
.setting-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.setting-label { font-weight: 500; }
.setting-desc { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }
.setting-value { color: var(--accent); font-weight: 600; }

/* Toggle Switch */
.toggle {
  width: 48px; height: 28px; border-radius: 14px;
  background: rgba(255,255,255,0.12); position: relative;
  cursor: pointer; transition: background 0.2s;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: ''; position: absolute; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; top: 3px; left: 3px;
  transition: transform 0.2s;
}
.toggle.on::after { transform: translateX(20px); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ===== Responsive ===== */
@media (min-width: 481px) {
  #app { border-left: 1px solid rgba(255,255,255,0.04); border-right: 1px solid rgba(255,255,255,0.04); }
}
