/* ===== VARIABLES ===== */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-card: rgba(22, 27, 34, 0.8);
  --bg-glass: rgba(22, 27, 34, 0.6);
  --border: rgba(48, 54, 61, 0.8);
  --border-light: rgba(48, 54, 61, 0.4);
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-glow: rgba(88, 166, 255, 0.3);
  --success: #3fb950;
  --success-glow: rgba(63, 185, 80, 0.3);
  --warning: #d29922;
  --danger: #f85149;
  --purple: #bc8cff;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --nav-height: 70px;
  --header-height: 56px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
input, button, select, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; }

/* ===== SCREENS ===== */
.screen { min-height: 100dvh; }
.hidden { display: none !important; }

/* ===== AUTH ===== */
.auth-container {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-logo { text-align: center; margin-bottom: 32px; }
.logo-icon { font-size: 64px; margin-bottom: 12px; }
.auth-logo h1 { font-size: 32px; font-weight: 800; }
.auth-logo .accent { color: var(--accent); }
.subtitle { color: var(--text-secondary); margin-top: 4px; font-size: 14px; }
#auth-form-container {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(16px);
}
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
}
.auth-tab.active {
  background: var(--accent);
  color: #fff;
}
.input-group { margin-bottom: 16px; }
.input-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.input-group input, .input-group select {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  transition: border-color 0.2s;
}
.input-group input:focus, .input-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: block; }
.turnstile-container { margin: 16px 0; display: flex; justify-content: center; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; min-height: 18px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 48px;
  font-size: 15px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #79b8ff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #56d364; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-outline:hover { background: var(--accent-glow); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.btn-large { width: 100%; padding: 16px; font-size: 16px; min-height: 52px; }
.btn-xl { width: 100%; padding: 20px; font-size: 18px; font-weight: 700; min-height: 60px; border-radius: var(--radius); }
.icon-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--bg-tertiary); }

/* ===== HEADER ===== */
#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(13, 17, 23, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}
#page-title { font-size: 18px; font-weight: 700; }

/* ===== BOTTOM NAV ===== */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(13, 17, 23, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-light);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s;
  min-height: 48px;
  padding: 8px 4px;
}
.nav-btn.active { color: var(--accent); }
.nav-btn:hover { color: var(--text-primary); }
.nav-icon { font-size: 22px; }
.nav-label { font-size: 11px; font-weight: 600; }

/* ===== CONTENT ===== */
#content {
  padding: calc(var(--header-height) + 12px) 16px calc(var(--nav-height) + 12px);
  min-height: 100dvh;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(12px);
  margin-bottom: 12px;
  transition: transform 0.15s, border-color 0.15s;
}
.card:hover { border-color: var(--accent); }
.card-clickable { cursor: pointer; }
.card-clickable:active { transform: scale(0.98); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-title { font-size: 16px; font-weight: 700; }
.card-subtitle { font-size: 13px; color: var(--text-secondary); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-blue { background: rgba(88,166,255,0.15); color: var(--accent); }
.badge-green { background: rgba(63,185,80,0.15); color: var(--success); }
.badge-orange { background: rgba(210,153,34,0.15); color: var(--warning); }
.badge-red { background: rgba(248,81,73,0.15); color: var(--danger); }
.badge-purple { background: rgba(188,140,255,0.15); color: var(--purple); }

/* ===== CHIPS ===== */
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px 0;
  -webkit-overflow-scrolling: touch;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  transition: all 0.2s;
  min-height: 36px;
  white-space: nowrap;
}
.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ===== SEARCH ===== */
.search-bar {
  position: relative;
  margin-bottom: 12px;
}
.search-bar input {
  width: 100%;
  padding: 14px 16px 14px 44px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-bar::before {
  content: '🔍';
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
}

/* ===== WORKOUT PAGE ===== */
.workout-hero {
  text-align: center;
  padding: 48px 0 24px;
}
.workout-hero h2 { font-size: 24px; margin-bottom: 8px; }
.workout-hero p { color: var(--text-secondary); margin-bottom: 24px; }
.start-btn {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 0 auto;
  transition: all 0.3s;
  box-shadow: 0 0 30px var(--accent-glow);
}
.start-btn:hover { background: var(--accent); color: #fff; transform: scale(1.05); }
.start-btn .btn-emoji { font-size: 36px; }

/* Active workout */
.session-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.session-timer { font-size: 24px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.rest-timer-bar {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 12px;
  text-align: center;
}
.rest-timer-bar .time { font-size: 36px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.rest-timer-bar .label { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; }

/* Log form */
.log-form { margin-bottom: 16px; }
.log-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.log-row .num-input {
  width: 80px;
  padding: 14px 8px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}
.log-row .num-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.log-row label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-weight: 600;
  min-width: 50px;
}
.quick-adjust {
  display: flex;
  gap: 6px;
  margin: 8px 0;
  flex-wrap: wrap;
}
.quick-adjust button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  min-height: 40px;
  min-width: 48px;
}
.quick-adjust button:hover { border-color: var(--accent); color: var(--accent); }

.session-summary {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  text-align: center;
}
.summary-stat .value { font-size: 24px; font-weight: 800; color: var(--accent); }
.summary-stat .label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; }

/* Logged sets */
.logged-sets { margin-top: 12px; }
.logged-set {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: 14px;
}
.logged-set .set-num { color: var(--text-muted); font-weight: 600; }
.logged-set .set-detail { color: var(--text-primary); font-weight: 600; }

/* ===== EXERCISE LIBRARY ===== */
.exercise-grid {
  display: grid;
  gap: 12px;
}
.exercise-card {
  display: flex;
  gap: 12px;
  align-items: center;
}
.exercise-card .ex-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.exercise-card .ex-info { flex: 1; min-width: 0; }
.exercise-card .ex-name { font-weight: 600; font-size: 15px; }
.exercise-card .ex-meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

/* ===== EXERCISE DETAIL ===== */
.ex-detail-header { margin-bottom: 20px; }
.ex-detail-header h2 { font-size: 24px; margin-bottom: 8px; }
.ex-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.muscle-svg-container {
  display: flex;
  justify-content: center;
  margin: 20px 0;
}
.muscle-svg-container svg {
  max-width: 200px;
  height: auto;
}
.detail-section { margin-bottom: 20px; }
.detail-section h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.step-list { list-style: none; counter-reset: steps; }
.step-list li {
  counter-increment: steps;
  padding: 10px 12px 10px 42px;
  position: relative;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.5;
}
.step-list li::before {
  content: counter(steps);
  position: absolute;
  left: 12px;
  top: 10px;
  width: 22px;
  height: 22px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.tip-list, .mistake-list { list-style: none; }
.tip-list li, .mistake-list li {
  padding: 8px 12px 8px 32px;
  position: relative;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 4px;
}
.tip-list li::before {
  content: '✅';
  position: absolute;
  left: 8px;
  top: 8px;
}
.mistake-list li::before {
  content: '⚠️';
  position: absolute;
  left: 8px;
  top: 8px;
}
.similar-exercises {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.similar-card {
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.similar-card:hover { border-color: var(--accent); }
.similar-card .name { font-weight: 600; font-size: 13px; }
.similar-card .cat { font-size: 11px; color: var(--text-muted); }

/* ===== DISCOVER ===== */
.section-title {
  font-size: 18px;
  font-weight: 700;
  margin: 20px 0 12px;
}
.section-title:first-child { margin-top: 0; }
.discover-card {
  position: relative;
  overflow: hidden;
}
.discover-card .reason {
  font-size: 12px;
  color: var(--accent);
  font-style: italic;
  margin-top: 6px;
}

/* ===== STATS ===== */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  backdrop-filter: blur(12px);
}
.stat-card .stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 4px;
}
.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-weight: 600;
}
.stat-card.highlight { border-color: var(--success); }
.stat-card.highlight .stat-value { color: var(--success); }
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  backdrop-filter: blur(12px);
}
.chart-container h3 { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.chart-container svg { width: 100%; }

/* PR Table */
.pr-table { width: 100%; border-collapse: collapse; }
.pr-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.pr-table td {
  padding: 10px 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-light);
}
.pr-table .pr-value { font-weight: 700; color: var(--success); }

/* Heatmap */
.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(52, 1fr);
  gap: 2px;
}
.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--bg-tertiary);
  min-width: 0;
}
.heatmap-cell.l1 { background: rgba(63,185,80,0.2); }
.heatmap-cell.l2 { background: rgba(63,185,80,0.4); }
.heatmap-cell.l3 { background: rgba(63,185,80,0.7); }
.heatmap-cell.l4 { background: var(--success); }

/* ===== PROFILE ===== */
.profile-section { margin-bottom: 24px; }
.profile-section h3 { font-size: 16px; font-weight: 700; margin-bottom: 12px; }

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  top: calc(var(--header-height) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 400px;
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s;
  pointer-events: auto;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--accent); color: #fff; }

@keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-12px); } }

/* ===== LOADING ===== */
.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: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { text-align: center; color: var(--text-secondary); padding: 24px; }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}
.empty-state .emoji { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { color: var(--text-primary); margin-bottom: 8px; }

/* ===== BACK BUTTON ===== */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: none;
  border: none;
  margin-bottom: 16px;
  padding: 8px 0;
  min-height: 44px;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 768px) {
  #content { max-width: 600px; margin: 0 auto; }
  .exercise-grid { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: repeat(4, 1fr); }
}

/* Donut chart */
.donut-container {
  display: flex;
  align-items: center;
  gap: 16px;
}
.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Exercise selector in workout */
.exercise-selector {
  position: relative;
}
.exercise-selector .results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
}
.exercise-selector .result-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  font-size: 14px;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.exercise-selector .result-item:hover {
  background: var(--bg-tertiary);
}
.exercise-selector .result-item:last-child { border-bottom: none; }

/* History cards */
.history-card .date { color: var(--text-muted); font-size: 12px; }
.history-card .name { font-weight: 600; }
.history-card .meta { color: var(--text-secondary); font-size: 13px; }
