/* === BetterMe Workout App — Design System === */
:root {
  --bg: #0d0d0d;
  --bg-card: #1a1a1a;
  --bg-elevated: #242424;
  --text: #f0f0f0;
  --text-secondary: #999;
  --accent: #ff4d4d;
  --accent-light: #ff6b6b;
  --accent-dark: #cc3333;
  --green: #4ade80;
  --yellow: #fbbf24;
  --blue: #60a5fa;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --header-h: 56px;
}

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

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* === Header === */
#app-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(13,13,13,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; height: var(--header-h);
}
.logo {
  font-size: 1.25rem; font-weight: 800;
  color: var(--accent); text-decoration: none;
  display: flex; align-items: center; gap: 6px;
}
.logo span { color: var(--text); }
#main-nav { display: flex; gap: 8px; margin-left: auto; }
.nav-link {
  color: var(--text-secondary); text-decoration: none;
  padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500;
  transition: all 0.2s;
}
.nav-link:hover, .nav-link.active { color: var(--text); background: var(--bg-elevated); }

/* === Buttons === */
.btn-icon {
  background: var(--bg-elevated); border: none; color: var(--text);
  width: 36px; height: 36px; border-radius: 50%;
  cursor: pointer; font-size: 0.875rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.btn-icon:hover { background: var(--bg-card); }
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 14px 32px; border-radius: var(--radius);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  width: 100%; max-width: 400px; margin: 24px auto; display: block;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover { background: var(--accent-light); }
.btn-primary:active { transform: scale(0.97); }

/* === Language toggle === */
body[data-lang="vi"] .en { display: none !important; }
body[data-lang="en"] .vi { display: none !important; }

/* === Pages === */
.page { max-width: 1200px; margin: 0 auto; padding: 20px; }
.page-header { margin-bottom: 20px; }
.page-header h1 { font-size: 1.5rem; font-weight: 800; }
.back-btn {
  color: var(--text-secondary); text-decoration: none;
  font-size: 0.875rem; display: inline-block; margin-bottom: 8px;
}
.back-btn:hover { color: var(--text); }

/* === Hero === */
.hero {
  text-align: center; padding: 40px 20px 32px;
}
.hero h1 { font-size: 2rem; font-weight: 800; margin-bottom: 8px; }
.hero p { color: var(--text-secondary); font-size: 1.05rem; }

/* === Card Grid === */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none; color: var(--text);
  display: block;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.card-img {
  width: 100%; aspect-ratio: 16/9; object-fit: cover;
  background: var(--bg-elevated);
}
.card-body { padding: 14px 16px; }
.card-title { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.card-subtitle { font-size: 0.8rem; color: var(--text-secondary); }
.card-meta {
  display: flex; gap: 12px; margin-top: 8px;
  font-size: 0.75rem; color: var(--text-secondary);
}
.card-badge {
  display: inline-block; padding: 2px 8px;
  background: var(--accent); color: #fff;
  border-radius: 4px; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase;
}

/* Category card */
.cat-card {
  background: linear-gradient(135deg, var(--bg-card), var(--bg-elevated));
  padding: 28px 24px; text-align: center;
}
.cat-card .cat-icon { font-size: 2.5rem; margin-bottom: 12px; }
.cat-card .cat-name { font-size: 1.1rem; font-weight: 700; }
.cat-card .cat-count { font-size: 0.85rem; color: var(--text-secondary); margin-top: 4px; }

/* === Workout Detail === */
.workout-cover {
  width: 100%; max-height: 300px; object-fit: cover;
  border-radius: var(--radius); margin-bottom: 16px;
}
.workout-meta {
  display: flex; gap: 16px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.meta-item { font-size: 0.9rem; color: var(--text-secondary); }
.workout-description { color: var(--text-secondary); line-height: 1.6; margin-bottom: 20px; }

/* Equipment */
.equipment-list {
  display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px;
}
.equip-tag {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-elevated); padding: 6px 12px;
  border-radius: 20px; font-size: 0.8rem;
}
.equip-tag img { width: 20px; height: 20px; border-radius: 4px; }

/* Phases */
.phases-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.phase-card {
  background: var(--bg-card); border-radius: var(--radius-sm);
  padding: 16px; border-left: 4px solid var(--accent);
}
.phase-card[data-type="warm_up"] { border-color: var(--yellow); }
.phase-card[data-type="cool_down"] { border-color: var(--blue); }
.phase-card[data-type="rest"] { border-color: var(--green); }
.phase-name { font-weight: 700; font-size: 0.95rem; margin-bottom: 6px; }
.phase-exercises { font-size: 0.8rem; color: var(--text-secondary); }

/* === Player === */
.page-player {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding: 0; max-width: none;
}
.player-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
}
.player-progress { flex: 1; }
.progress-bar {
  height: 4px; background: var(--bg-elevated); border-radius: 2px; overflow: hidden;
}
.progress-fill { height: 100%; background: var(--accent); transition: width 0.3s; width: 0%; }
#player-phase-label { font-size: 0.75rem; color: var(--text-secondary); margin-top: 4px; display: block; }

.player-video-wrap {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  background: #000; overflow: hidden;
}
.player-video-wrap video, .player-video-wrap img {
  width: 100%; height: 100%; object-fit: contain;
}

.player-info { padding: 12px 16px; text-align: center; }
#player-exercise-name { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; }
.exercise-bilingual { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; }

.timer-circle {
  width: 120px; height: 120px; margin: 0 auto; position: relative;
}
.timer-circle svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-bg { fill: none; stroke: var(--bg-elevated); stroke-width: 6; }
.timer-progress {
  fill: none; stroke: var(--accent); stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}
.timer-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums;
}
.reps-display {
  text-align: center; margin-top: 8px;
  font-size: 1rem; color: var(--text-secondary);
}
#reps-count { font-size: 2.5rem; font-weight: 800; color: var(--text); display: block; }

.player-controls {
  display: flex; justify-content: center; align-items: center; gap: 24px;
  padding: 16px;
}
.btn-ctrl {
  background: var(--bg-elevated); border: none; color: var(--text);
  width: 48px; height: 48px; border-radius: 50%;
  cursor: pointer; font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
}
.btn-ctrl-main {
  width: 64px; height: 64px; font-size: 1.5rem;
  background: var(--accent);
}
.next-up {
  text-align: center; padding: 8px 16px 16px;
  font-size: 0.85rem; color: var(--text-secondary);
}

/* === Exercise Library === */
.search-bar { margin-bottom: 20px; }
.search-bar input {
  width: 100%; padding: 12px 16px;
  background: var(--bg-card); border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius); color: var(--text);
  font-size: 0.95rem; font-family: var(--font);
}
.search-bar input::placeholder { color: var(--text-secondary); }
.search-bar input:focus { outline: none; border-color: var(--accent); }

.exercise-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.exercise-card {
  background: var(--bg-card); border-radius: var(--radius-sm);
  overflow: hidden; cursor: pointer; text-decoration: none; color: var(--text);
  transition: transform 0.2s;
}
.exercise-card:hover { transform: translateY(-2px); }
.exercise-card img {
  width: 100%; aspect-ratio: 4/3; object-fit: cover;
  background: var(--bg-elevated);
}
.exercise-card .card-body { padding: 10px 12px; }
.exercise-card .card-title { font-size: 0.85rem; }

/* Exercise detail */
.exercise-video-wrap {
  margin-bottom: 20px;
}
.exercise-video-wrap video {
  width: 100%; max-height: 400px; border-radius: var(--radius);
  background: #000;
}
.steps-list { margin-bottom: 20px; }
.steps-list h3 { font-size: 1rem; font-weight: 700; margin-bottom: 12px; }
.step-item {
  display: flex; gap: 12px; margin-bottom: 12px;
  padding: 12px; background: var(--bg-card); border-radius: var(--radius-sm);
}
.step-num {
  width: 28px; height: 28px; flex-shrink: 0;
  background: var(--accent); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
}
.step-text { font-size: 0.9rem; line-height: 1.5; }
.step-vi { color: var(--text-secondary); font-style: italic; margin-top: 4px; font-size: 0.85rem; }

.tips-section, .mistakes-section {
  background: var(--bg-card); border-radius: var(--radius-sm);
  padding: 16px; margin-bottom: 16px;
}
.tips-section h3, .mistakes-section h3 {
  font-size: 0.95rem; margin-bottom: 10px;
}
.tips-section { border-left: 4px solid var(--green); }
.mistakes-section { border-left: 4px solid var(--yellow); }

/* Pagination */
.pagination {
  display: flex; justify-content: center; gap: 8px; margin-top: 24px;
}
.pagination button {
  background: var(--bg-card); border: none; color: var(--text);
  padding: 8px 14px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 0.85rem;
}
.pagination button.active { background: var(--accent); }
.pagination button:hover:not(.active) { background: var(--bg-elevated); }

/* === Filters === */
.filters { margin-bottom: 16px; }
.filters select {
  background: var(--bg-card); border: 1px solid rgba(255,255,255,0.1);
  color: var(--text); padding: 8px 12px; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 0.85rem;
}

/* === Loading === */
.loading {
  text-align: center; padding: 40px;
  color: var(--text-secondary);
}
.loading::after {
  content: ''; display: block; margin: 12px auto 0;
  width: 32px; height: 32px;
  border: 3px solid var(--bg-elevated);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Responsive === */
@media (max-width: 640px) {
  .hero h1 { font-size: 1.5rem; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .exercise-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .player-info { padding: 8px 12px; }
  #player-exercise-name { font-size: 1rem; }
}
