/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Thème Peloton — Dark Studio, Focused Power */
  --bg: #181a1d;
  --surface: #202327;
  --surface2: #282b30;
  --surface3: #34373d;
  --accent: #df1c2f;
  --accent-dim: rgba(223,28,47,.15);
  --accent2: var(--accent);
  --text: #ffffff;
  --text2: #a8acb1;
  --text3: #65666a;
  --border: #2e3137;
  --ink: #101216;
  --success: #22c55e;
  --danger: #ef4444;
  --info: #3b82f6;
  --font: 'Inter', -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif;
  --font-display: var(--font);
  --shadow-pop: none;
  --header-h: 56px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ─────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
#app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding-top: env(safe-area-inset-top, 0px);
}

#page-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.timer-badge {
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--accent);
  display: none;
}
.timer-badge.visible { display: block; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 20px;
  padding: 6px;
  cursor: pointer;
  line-height: 1;
  border-radius: 8px;
  transition: background .15s;
}
.icon-btn:active { background: var(--surface2); }

/* ── Main Content ──────────────────────────────────────────────────────────── */
#page-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  padding-bottom: 8px;
}

/* ── Bottom Nav ────────────────────────────────────────────────────────────── */
#bottom-nav {
  display: flex;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 6px 0 0;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn.active { color: var(--accent); }

.nav-icon {
  font-size: 22px;
  line-height: 1;
  display: block;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

/* ── Common Components ─────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 12px 20px;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active { opacity: .8; transform: scale(.97); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--danger); }
.btn-success { background: rgba(34,197,94,.15); color: var(--success); }
.btn-ghost { background: none; color: var(--text2); border: 1px solid var(--border); }
.btn-full { width: 100%; }
.btn-sm { font-size: 13px; padding: 8px 14px; }
.btn-lg { font-size: 17px; padding: 15px 28px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.card + .card { margin-top: 10px; }

.card-header {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.card-body { padding: 12px 14px; }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.badge-muscle { background: var(--accent-dim); color: var(--accent2); }
.badge-equipment { background: var(--surface3); color: var(--text2); }
.badge-easy { background: rgba(34,197,94,.15); color: var(--success); }
.badge-medium { background: rgba(249,115,22,.15); color: var(--accent); }
.badge-hard { background: rgba(239,68,68,.15); color: var(--danger); }

.divider { height: 1px; background: var(--border); margin: 10px 0; }

.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text3);
  margin: 18px 0 8px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  gap: 12px;
}

.empty-state .es-icon { font-size: 52px; opacity: .5; }
.empty-state .es-title { font-size: 18px; font-weight: 700; color: var(--text2); }
.empty-state .es-sub { font-size: 14px; color: var(--text3); line-height: 1.5; }

/* ── Workout Tab ───────────────────────────────────────────────────────────── */

.workout-start-screen { padding: 8px 0; }

.workout-header-card {
  background: linear-gradient(135deg, #1a1a1a, #222);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.workout-header-card .wh-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.workout-header-card .wh-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}

.workout-meta {
  display: flex;
  gap: 16px;
}

.wm-item {
  font-size: 13px;
  color: var(--text2);
}

.wm-item span {
  color: var(--text);
  font-weight: 600;
}

/* Exercise card within workout */
.ex-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 10px;
  overflow: hidden;
}

.ex-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  gap: 8px;
}

.ex-card-info { flex: 1; min-width: 0; }

.ex-card-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ex-card-meta {
  font-size: 12px;
  color: var(--text3);
  margin-top: 2px;
}

.ex-card-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }

/* Sets table */
.sets-table { width: 100%; border-collapse: collapse; }

.sets-header {
  display: grid;
  grid-template-columns: 32px 1fr 1fr 36px;
  gap: 6px;
  padding: 6px 14px;
  background: var(--surface2);
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.set-row {
  display: grid;
  grid-template-columns: 32px 1fr 1fr 36px;
  gap: 6px;
  padding: 6px 14px;
  align-items: center;
  border-top: 1px solid var(--border);
  transition: background .15s;
}

.set-row.completed { background: rgba(34,197,94,.05); }

.set-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--text3);
  text-align: center;
}

.set-row.completed .set-num { color: var(--success); }

.set-input-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.set-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  padding: 6px 4px;
  width: 100%;
  -moz-appearance: textfield;
}
.set-input::-webkit-outer-spin-button,
.set-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.set-input:focus { border-color: var(--accent); outline: none; background: var(--surface3); }
.set-row.completed .set-input { border-color: var(--success); }

.set-unit { font-size: 12px; color: var(--text3); white-space: nowrap; }

.set-check {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: transparent;
  transition: all .2s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.set-check.done { background: var(--success); border-color: var(--success); color: #fff; }

.add-set-row {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.prev-data {
  font-size: 11px;
  color: var(--text3);
  padding: 4px 14px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
}

/* Actions bar */
.workout-actions {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 16px;
}

/* Note de séance (texte libre) */
.workout-notes {
  width: 100%;
  margin-top: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  resize: vertical;
  min-height: 54px;
  box-sizing: border-box;
}
.workout-notes:focus { border-color: var(--accent); outline: none; background: var(--surface3); }
.workout-notes::placeholder { color: var(--text3); }

/* Guide de l'app */
.guide-step { text-align: center; padding: 8px 0 4px; }
.guide-icon { font-size: 44px; line-height: 0; margin-bottom: 10px; color: var(--accent); }
.guide-title { font-size: 17px; font-weight: 800; margin: 0 0 8px; }
.guide-text { font-size: 14px; color: var(--text2); line-height: 1.5; margin: 0; }
.guide-dots { letter-spacing: 4px; color: var(--accent); font-size: 11px; margin-top: 14px; }
.guide-nav { display: flex; gap: 8px; margin-top: 16px; }
.guide-nav button { flex: 1; }

/* Alternatives sur la fiche exercice */
.alt-list { display: flex; flex-direction: column; gap: 6px; }
.alt-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.alt-item:active { background: var(--surface3); }
.alt-item .alt-name { flex: 1; }
.alt-item .alt-arrow { color: var(--text3); font-size: 18px; }

/* Récap de fin de séance */
.recap-prs { display: flex; flex-direction: column; gap: 6px; }
.recap-pr-item {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

.add-exercise-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: none;
  color: var(--text2);
  font-size: 15px;
  font-weight: 600;
  padding: 16px;
  cursor: pointer;
  width: 100%;
  transition: border-color .2s, color .2s;
  -webkit-tap-highlight-color: transparent;
}
.add-exercise-btn:active { border-color: var(--accent); color: var(--accent); }

/* Template picker */
.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.template-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.template-card:active { border-color: var(--accent); }

.template-card .tc-day {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.template-card .tc-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  /* couleur explicite : sinon le texte hérite du défaut <button>
     (bleu sur iOS, noir illisible sur Android/Chrome) */
  color: var(--text);
}

.template-card .tc-count {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
}

/* Recent workouts list */
.recent-workout-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.recent-workout-item:active { background: var(--surface2); }

.rwi-info { flex: 1; min-width: 0; }
.rwi-name { font-size: 15px; font-weight: 700; }
.rwi-meta { font-size: 12px; color: var(--text3); margin-top: 3px; }
.rwi-arrow { color: var(--text3); font-size: 18px; flex-shrink: 0; margin-left: 8px; }

/* ── Exercises Tab ─────────────────────────────────────────────────────────── */

.search-bar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  gap: 8px;
  margin-bottom: 10px;
}

.search-bar .search-icon { font-size: 16px; color: var(--text3); flex-shrink: 0; }

.search-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  padding: 12px 0;
  outline: none;
}

.search-input::placeholder { color: var(--text3); }

.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }

.filter-chip {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.exercise-item {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  gap: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .15s;
}
.exercise-item:active { border-color: var(--accent); }

.ex-item-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.ex-item-body { flex: 1; min-width: 0; }
.ex-item-name { font-size: 15px; font-weight: 700; }
.ex-item-sub { font-size: 12px; color: var(--text3); margin-top: 2px; }

.ex-item-add {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  transition: transform .15s;
  -webkit-tap-highlight-color: transparent;
}
.ex-item-add:active { transform: scale(.88); }
.ex-item-add.hidden { visibility: hidden; }

/* Badges typographiques par groupe musculaire (rouge / jaune alternés) */
[data-muscle="Poitrine"] .ex-item-icon { background: var(--accent); color: #fff; }
[data-muscle="Poitrine"] .ex-item-icon::after { content: "PEC"; }
[data-muscle="Dos"] .ex-item-icon { background: var(--accent); color: #fff; }
[data-muscle="Dos"] .ex-item-icon::after { content: "DOS"; }
[data-muscle="Épaules"] .ex-item-icon { background: var(--accent); color: #fff; }
[data-muscle="Épaules"] .ex-item-icon::after { content: "EPL"; }
[data-muscle="Biceps"] .ex-item-icon { background: var(--accent); color: #fff; }
[data-muscle="Biceps"] .ex-item-icon::after { content: "BIC"; }
[data-muscle="Triceps"] .ex-item-icon { background: var(--accent); color: #fff; }
[data-muscle="Triceps"] .ex-item-icon::after { content: "TRI"; }
[data-muscle="Quadriceps"] .ex-item-icon { background: var(--accent); color: #fff; }
[data-muscle="Quadriceps"] .ex-item-icon::after { content: "QUA"; }
[data-muscle="Ischio-jambiers"] .ex-item-icon { background: var(--accent); color: #fff; }
[data-muscle="Ischio-jambiers"] .ex-item-icon::after { content: "ISJ"; }
[data-muscle="Fessiers"] .ex-item-icon { background: var(--accent); color: #fff; }
[data-muscle="Fessiers"] .ex-item-icon::after { content: "FES"; }
[data-muscle="Mollets"] .ex-item-icon { background: var(--accent); color: #fff; }
[data-muscle="Mollets"] .ex-item-icon::after { content: "MOL"; }
[data-muscle="Abdominaux"] .ex-item-icon { background: var(--accent); color: #fff; }
[data-muscle="Abdominaux"] .ex-item-icon::after { content: "ABS"; }

/* ── Progress Tab ──────────────────────────────────────────────────────────── */

.progress-select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 14px;
  margin-bottom: 12px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.time-range-row {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.range-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 12px;
  font-weight: 700;
  padding: 7px 0;
  cursor: pointer;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.range-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  margin-bottom: 12px;
}

.chart-card h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

.chart-canvas { width: 100%; }

.pr-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.pr-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.pr-card .pr-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.pr-card .pr-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.pr-card .pr-sub {
  font-size: 12px;
  color: var(--text3);
  margin-top: 4px;
}

/* SVG Chart */
.svg-chart { width: 100%; height: 160px; overflow: visible; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: url(#chartGrad); opacity: 0.35; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-grid-line { stroke: var(--border); stroke-width: 1; opacity: 0.6; }
.chart-label { fill: var(--text3); font-size: 10px; font-family: -apple-system, sans-serif; }
.chart-value-label { fill: var(--text); font-size: 10px; font-weight: 600; font-family: -apple-system, sans-serif; }

/* Interactivité des courbes — marqueur + tooltip */
.chart-hit { fill: transparent; cursor: crosshair; touch-action: none; }
.chart-marker { stroke: var(--text3); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-marker-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2.5; }
.chart-tooltip {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 9px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.25;
}
.chart-tooltip strong { color: var(--text); font-size: 14px; }
.chart-tooltip span { color: var(--text3); font-size: 11px; }

/* No data state */
.no-data {
  text-align: center;
  padding: 32px;
  color: var(--text3);
  font-size: 14px;
}

/* ── History Tab ───────────────────────────────────────────────────────────── */

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
}

.hi-left { flex: 1; }

.hi-date {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 3px;
}

.hi-name {
  font-size: 16px;
  font-weight: 700;
}

.hi-meta {
  font-size: 12px;
  color: var(--text3);
  margin-top: 3px;
}

.hi-chevron {
  color: var(--text3);
  font-size: 18px;
  transition: transform .2s;
}

.history-item.open .hi-chevron { transform: rotate(90deg); }

.hi-body {
  display: none;
  border-top: 1px solid var(--border);
  padding: 12px 14px;
}

.history-item.open .hi-body { display: block; }

.hi-exercise-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 4px 0;
  color: var(--text2);
}

.hi-exercise-row span:first-child { font-weight: 600; color: var(--text); }

.hi-note {
  font-size: 13px;
  color: var(--text2);
  font-style: italic;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: 8px;
}

.hi-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* ── Modal ─────────────────────────────────────────────────────────────────── */

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

#modal-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

#modal-sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32,0,.67,0);
  padding-bottom: var(--safe-bottom);
}

#modal-overlay.visible #modal-sheet {
  transform: translateY(0);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--surface3);
  border-radius: 2px;
  margin: 12px auto 0;
  flex-shrink: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  flex-shrink: 0;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  width: 30px;
  height: 30px;
  background: var(--surface2);
  border: none;
  border-radius: 50%;
  color: var(--text2);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 16px;
  flex: 1;
}

/* Exercise detail modal */
.ex-detail-muscles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px;
}

.ex-detail-desc {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text2);
  margin-bottom: 14px;
}

.ex-detail-tips { margin-bottom: 16px; }

.ex-detail-tips h4 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.tip-item {
  display: flex;
  gap: 8px;
  font-size: 13px;
  color: var(--text2);
  line-height: 1.4;
  padding: 4px 0;
}

.tip-item::before {
  content: "→";
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 1px;
}

/* ── Rest Timer Toast ──────────────────────────────────────────────────────── */

#rest-timer {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
  white-space: nowrap;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}

#rest-timer.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: all;
}

.rt-label { font-size: 13px; color: var(--text3); }
.rt-time {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 52px;
  text-align: center;
}
.rt-skip {
  background: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
}
/* Boutons icône du compteur de repos (pause/reprise, remise à zéro) */
.rt-ctrl {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
.rt-ctrl .ic { width: 18px; height: 18px; }
.rt-ctrl:active { background: var(--surface); }

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.fw-700 { font-weight: 700; }
.text-accent { color: var(--accent); }
.text-muted { color: var(--text3); }
.text-sm { font-size: 13px; }
.text-center { text-align: center; }

/* ── Icônes ligne (Lucide) ─────────────────────────────────────────────────── */
/* .ic = 1em par défaut : suit le font-size du contexte. Surcharges ci-dessous
   pour les conteneurs sans font-size pertinent. */
.ic {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.14em;
  flex-shrink: 0;
}
.modal-close .ic { width: 16px; height: 16px; }
.set-check .ic { width: 18px; height: 18px; }
.sync-status .ic { width: 13px; height: 13px; }

/* ── Morpho stars ──────────────────────────────────────────────────────────── */
.ex-star {
  display: inline-flex;
  align-items: center;
  color: #f5b301;
  margin-right: 3px;
}
.ex-star .ic { width: 14px; height: 14px; }

.filter-chip.chip-reco {
  border-color: var(--accent);
  color: var(--accent2);
}
.filter-chip.chip-reco.active {
  background: var(--accent);
  color: #fff;
}

/* ── Exercise diagram ──────────────────────────────────────────────────────── */
.diagram-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 6px;
  margin-bottom: 12px;
}

.exercise-diagram {
  width: 100%;
  height: 180px;
  display: block;
}

.diagram-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 8px 2px;
  font-size: 11px;
  color: var(--text3);
  flex-wrap: wrap;
}
.diagram-legend span { display: flex; align-items: center; gap: 5px; }
.leg-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.leg-ghost { background: #555; }
.leg-solid { background: var(--accent); }
.leg-muscle {
  margin-left: auto;
  color: var(--accent2);
  font-weight: 700;
}

/* ── Visuels d'exercice (photos free-exercise-db) ──────────────────────────── */
.exercise-images {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.ex-img-fig {
  flex: 1;
  min-width: 0;
  margin: 0;
}
.ex-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  display: block;
}
.ex-img-fig figcaption {
  font-size: 11px;
  color: var(--text3);
  text-align: center;
  margin-top: 5px;
  font-weight: 600;
}
.ex-img-loading, .ex-img-none {
  flex: 1;
  padding: 28px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--text3);
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  line-height: 1.5;
}

/* ── Morpho note box ───────────────────────────────────────────────────────── */
.morpho-note {
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 10px 0 4px;
  border-left: 3px solid var(--text3);
  background: var(--surface2);
}
.morpho-note-label {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}
.morpho-note-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text2);
}
.morpho-note.morpho-star {
  border-left-color: var(--accent);
  background: var(--accent-dim);
}
.morpho-note.morpho-star .morpho-note-label { color: var(--accent2); }
.morpho-note.morpho-good {
  border-left-color: var(--success);
  background: rgba(34,197,94,.08);
}
.morpho-note.morpho-good .morpho-note-label { color: var(--success); }
.morpho-note.morpho-caution {
  border-left-color: var(--danger);
  background: rgba(239,68,68,.08);
}
.morpho-note.morpho-caution .morpho-note-label { color: var(--danger); }
.morpho-note.morpho-neutral .morpho-note-label { color: var(--text3); }

/* ── Profile button & modal ────────────────────────────────────────────────── */
.profile-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent2);
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.profile-btn:active { opacity: .7; }

.profile-hero {
  background: linear-gradient(135deg, var(--accent), #a3121e);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  margin-bottom: 6px;
}
.profile-height {
  font-size: 40px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}
.profile-height span { font-size: 18px; font-weight: 600; opacity: .8; }
.profile-tag {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,.9);
  margin-top: 6px;
}

.trait-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.trait-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
}
.trait-label { font-size: 13px; font-weight: 700; margin: 0 0 3px; }
.trait-desc { font-size: 11px; line-height: 1.4; color: var(--text3); }

.leviers-list { display: flex; flex-direction: column; gap: 6px; }
.levier-item {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text2);
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  border-left: 3px solid var(--accent);
}

.profile-reco {
  margin-top: 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text2);
  background: var(--accent-dim);
  border-radius: var(--radius);
  padding: 12px;
}
.profile-reco strong { color: var(--accent2); }

/* ── Écran d'authentification ──────────────────────────────────────────────── */
#auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 300;
  padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 24px);
}

.auth-box {
  width: 100%;
  max-width: 380px;
  margin: auto;
}

.auth-loading, .auth-error {
  margin: auto;
  color: var(--text3);
  font-size: 15px;
  text-align: center;
}
.auth-error { color: var(--danger); }

.auth-logo {
  display: flex;
  justify-content: center;
  margin: 0 0 8px;
  color: var(--accent);
}
.auth-logo img, .auth-logo .ic { height: 64px; width: auto; }

.auth-title {
  font-size: 24px;
  font-weight: 800;
  text-align: center;
  letter-spacing: -0.5px;
}

.auth-sub {
  font-size: 13px;
  color: var(--text3);
  text-align: center;
  margin: 4px 0 22px;
  line-height: 1.4;
}

.auth-field { margin-bottom: 14px; }

.auth-field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.auth-field input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  padding: 13px 14px;
  outline: none;
}
.auth-field input:focus { border-color: var(--accent); }

.auth-msg {
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
  margin-bottom: 8px;
  line-height: 1.4;
}

/* Séparateur « ou » + bouton Google sur l'écran de connexion */
.auth-or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  color: var(--text3);
  font-size: 12px;
  text-transform: uppercase;
}
.auth-or::before, .auth-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.btn-google {
  background: #fff;
  color: #1f1f1f;
  gap: 10px;
}
.btn-google:active { opacity: .85; }
.google-g { width: 18px; height: 18px; flex-shrink: 0; }

/* Onboarding */
.ob-group { margin-bottom: 16px; }

.ob-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.seg-row {
  display: flex;
  gap: 6px;
}

.seg-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  padding: 11px 4px;
  cursor: pointer;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.seg-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ob-hint {
  font-size: 12px;
  color: var(--text3);
  text-align: center;
  margin-top: 10px;
  line-height: 1.4;
}

/* Aide visuelle d'auto-évaluation morpho */
.ob-help-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0 0;
  text-decoration: underline;
}

.ob-help {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.ob-help[hidden] { display: none; }

.ob-help-intro {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.45;
  margin: 0 0 6px;
}

.ob-help-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}
.ob-help-row span { color: var(--text3); }
.ob-help-row b { color: var(--accent); white-space: nowrap; }

/* Admin */
.admin-create {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
}

.admin-user-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 6px;
}
.admin-user-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.admin-user-name { font-size: 14px; font-weight: 700; }
.admin-user-meta { font-size: 11px; color: var(--text3); margin-top: 2px; }
.admin-user-google { display: flex; gap: 6px; margin-top: 8px; }
.adm-gmail {
  flex: 1;
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
}
.adm-gmail:focus { outline: none; border-color: var(--accent); }

.profile-user {
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}

/* ── Animations ────────────────────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.animate-in { animation: fadeIn .2s ease-out both; }

@keyframes checkPop { 0% { transform: scale(1); } 50% { transform: scale(1.25); } 100% { transform: scale(1); } }
.check-pop { animation: checkPop .25s ease-out; }

/* ════════════════════════════════════════════════════════════════════════════
   THÈME — Peloton : Dark Studio, Focused Power
   Charcoal #181a1d · accent rouge #df1c2f · Inter · fort contraste · zéro ombre
   ════════════════════════════════════════════════════════════════════════════ */

/* Boutons — CTA pilule */
.btn { border-radius: var(--radius-pill); }

/* Nav — pop discret de l'icône active (la couleur active vient du style de base) */
.nav-btn.active .nav-icon { transform: scale(1.1); }

/* Carte d'en-tête de séance */
.workout-header-card { background: var(--surface); }
.workout-header-card .wh-title { color: var(--accent); }

/* Indicateur de synchronisation */
.sync-status {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.sync-status.sync-pending { color: var(--text3); }
.sync-status.sync-error { background: var(--accent); color: #fff; }

/* Progression — sous-modes */
.seg-row.prog-modes { margin-bottom: 14px; }

/* ── Bannière nouveau record — épurée, sans rotation ni ombre ─────────────── */
#pr-banner {
  position: fixed;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%) scale(.7);
  z-index: 400;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .3s cubic-bezier(.2, 1.5, .4, 1);
}
#pr-banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.pr-banner-in {
  background: var(--accent);
  border-radius: var(--radius);
  padding: 18px 26px;
  text-align: center;
}
.pr-banner-title {
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.3px;
}
.pr-banner-sub {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,.9);
  margin-top: 3px;
}

/* ── Tableau de bord — barres par groupe musculaire ───────────────────────── */
.muscle-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.muscle-bar-label {
  font-size: 12px;
  font-weight: 600;
  width: 92px;
  flex-shrink: 0;
}
.muscle-bar-track {
  flex: 1;
  height: 14px;
  background: var(--surface2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.muscle-bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
}
.muscle-bar-val {
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  width: 26px;
  text-align: right;
}

/* ── Phase 2 — finition des composants ────────────────────────────────────── */

/* Hiérarchie typographique — resserrement des grands textes (touche premium) */
#page-title, .modal-title { letter-spacing: -0.2px; }
.wh-name { letter-spacing: -0.3px; }
.pr-value, .rt-time, .profile-height, .profile-user { letter-spacing: -0.5px; }

/* CTA principal — plus généreux */
.btn-lg { padding: 16px 28px; font-weight: 700; }

/* Cartes — coins plus doux et homogènes */
.card, .ex-card, .exercise-item, .recent-workout-item,
.history-item, .template-card, .chart-card, .pr-card { border-radius: 16px; }

/* Carte « séance en cours » — liseré d'accent discret */
.workout-header-card { border-color: var(--accent); }

/* Valeur chiffrée des stats — du punch */
.pr-card .pr-value { font-size: 30px; }

/* Focus net sur la barre de recherche */
.search-bar:focus-within { border-color: var(--accent); }

/* Icônes SVG — nav & profil (remplacent les emojis) */
.nav-icon svg { width: 24px; height: 24px; display: block; }
.profile-btn svg { width: 19px; height: 19px; }

/* Schéma anatomique dans la fiche exercice (body-muscles) */
.ex-musclemap {
  background: var(--surface2);
  border-radius: var(--radius);
  margin: 4px 0 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
}
/* !important : la lib pose width:100%/height:auto en style inline → corps géant rogné */
.ex-musclemap svg {
  height: 300px !important;
  width: auto !important;
  max-height: none !important;
  max-width: none !important;
}
/* deux silhouettes (face + dos) : on réduit pour qu'elles tiennent côte à côte */
.ex-musclemap--dual svg {
  height: 250px !important;
}

/* ── Programmes persos ─────────────────────────────────────────────────────── */
/* Carte d'un programme perso : zone cliquable + bouton « modifier » en coin */
.template-card.tc-custom { position: relative; text-align: left; cursor: pointer; }
.tc-edit {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text2);
  cursor: pointer;
}
.tc-edit .ic { width: 14px; height: 14px; }

/* ── Éditeur de programme ──────────────────────────────────────────────────── */
.pe-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text3);
  margin-bottom: 4px;
}
.pe-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  padding: 10px 12px;
  margin-bottom: 4px;
}
.pe-input:focus { outline: none; border-color: var(--accent); }

.pe-row {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 8px;
}
.pe-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.pe-row-name { font-size: 14px; font-weight: 700; }
.pe-row-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 6px;
}
.pe-row-fields label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
}
.pe-field {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 7px 6px;
  text-align: center;
}
.pe-field:focus { outline: none; border-color: var(--accent); }

.pe-pick-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.pe-pick {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
}
.pe-pick:active { border-color: var(--accent); }
.pe-pick-name { font-size: 14px; font-weight: 600; color: var(--text); }
.pe-pick-muscle { font-size: 11px; color: var(--text3); flex-shrink: 0; }
