:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f1f5f9;
  --text-2: #b6c2d4;
  --muted: #7c8aa0;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.15);
  /* palette dataviz validée (surface sombre #1e293b) */
  --viz-force: #d95926;
  --viz-course: #3987e5;
  --viz-mixte: #0ca30c;
  --grid: #2c3a52;
  --radius: 16px;
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; }

.boot { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100dvh; gap: 12px; color: var(--muted); }
.boot-logo { font-size: 56px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.15); opacity: 0.7; } }

/* ---------- Écran connexion ---------- */
.auth-screen { display: flex; flex-direction: column; justify-content: center; min-height: 100dvh; padding: 32px 24px calc(32px + env(safe-area-inset-bottom)); }
.auth-hero { text-align: center; margin-bottom: 32px; }
.auth-hero .logo { font-size: 64px; }
.auth-hero h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.5px; margin-top: 8px; }
.auth-hero h1 span { color: var(--accent); }
.auth-hero p { color: var(--text-2); margin-top: 6px; }

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

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 16px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.btn {
  display: block; width: 100%; padding: 15px; border: none; border-radius: 14px;
  background: var(--accent); color: #fff; font-size: 17px; font-weight: 700; cursor: pointer;
  transition: transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.small { width: auto; padding: 9px 16px; font-size: 14px; display: inline-block; }
.btn.danger { background: #7f1d1d; }
.btn:disabled { opacity: 0.5; }

.link-row { text-align: center; margin-top: 16px; color: var(--muted); font-size: 14px; }
.link-row a { color: var(--accent); font-weight: 600; text-decoration: none; }
.error-msg { background: rgba(220, 38, 38, 0.15); border: 1px solid rgba(220, 38, 38, 0.4); color: #fca5a5; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }

/* ---------- Structure app ---------- */
.screen { padding: calc(16px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.topbar h2 { font-size: 24px; font-weight: 800; }
.chip { display: inline-flex; align-items: center; gap: 5px; background: var(--surface-2); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; max-width: 560px; margin: 0 auto;
  background: rgba(15, 23, 42, 0.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border); padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; background: none; border: none; color: var(--muted); font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; padding: 4px 0;
}
.tabbar button .ico { font-size: 22px; }
.tabbar button.active { color: var(--accent); }

/* ---------- Aujourd'hui ---------- */
.hello { font-size: 22px; font-weight: 800; }
.hello small { display: block; font-size: 14px; color: var(--text-2); font-weight: 500; margin-top: 2px; }

.xp-card { display: flex; align-items: center; gap: 14px; }
.xp-level { font-size: 36px; }
.xp-info { flex: 1; }
.xp-info .lvl-name { font-weight: 800; font-size: 16px; }
.xp-info .lvl-sub { font-size: 12px; color: var(--muted); }
.xp-bar { height: 8px; background: var(--bg); border-radius: 99px; margin-top: 7px; overflow: hidden; }
.xp-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), #fbbf24); border-radius: 99px; transition: width 0.6s ease; }
.streak { text-align: center; }
.streak .n { font-size: 22px; font-weight: 800; }
.streak .l { font-size: 11px; color: var(--muted); }

.phase-banner { border-left: 4px solid; padding: 12px 14px; border-radius: 12px; background: var(--surface); margin-bottom: 14px; }
.phase-banner .p-name { font-weight: 800; font-size: 15px; }
.phase-banner .p-desc { font-size: 13px; color: var(--text-2); margin-top: 3px; }

.week-progress { display: flex; gap: 8px; margin: 4px 0 14px; }
.wp-dot { flex: 1; text-align: center; padding: 10px 4px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.wp-dot.done { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.wp-dot .d-ico { display: block; font-size: 18px; margin-bottom: 2px; }

.session-card { border: 1px solid var(--border); }
.session-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.session-head h3 { font-size: 19px; font-weight: 800; }
.session-type { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.session-type.force { background: rgba(217, 89, 38, 0.18); color: #f0906a; }
.session-type.course { background: rgba(57, 135, 229, 0.18); color: #7db2ee; }
.session-type.mixte { background: rgba(12, 163, 12, 0.18); color: #5fce5f; }
.session-focus { color: var(--text-2); font-size: 14px; margin: 6px 0 12px; }
.warmup { background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--text-2); margin-bottom: 12px; }

.exo { border-top: 1px solid var(--border); padding: 12px 0; }
.exo-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.exo-name { font-weight: 700; font-size: 15px; }
.exo-scheme { color: var(--accent); font-weight: 700; font-size: 14px; white-space: nowrap; }
.exo-note { font-size: 13px; color: var(--muted); margin-top: 3px; }
.exo-rpe { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.exo-inputs { display: flex; gap: 8px; margin-top: 9px; }
.exo-inputs input { padding: 9px 10px; font-size: 15px; }
.circuit-box { background: var(--bg); border-radius: 12px; padding: 12px; margin-top: 8px; }
.circuit-box .rounds { font-weight: 800; color: var(--accent); margin-bottom: 8px; font-size: 14px; }
.circuit-box .c-exo { padding: 6px 0; border-top: 1px solid var(--border); font-size: 14px; }
.circuit-box .c-exo small { color: var(--muted); display: block; font-size: 12px; }
.run-block { background: var(--bg); border-radius: 12px; padding: 14px; margin-top: 8px; }
.run-block .r-name { font-weight: 800; font-size: 16px; }
.run-block .r-detail { font-size: 14px; color: var(--text-2); margin-top: 4px; }

.tip-box { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: #fdba74; margin-top: 12px; }
.done-banner { text-align: center; padding: 20px; }
.done-banner .big { font-size: 44px; }

.rest-timer {
  position: fixed; right: 16px; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 40;
  width: 64px; height: 64px; border-radius: 50%; border: none;
  background: var(--surface-2); color: var(--text); font-weight: 800; font-size: 13px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4); cursor: pointer; border: 1px solid var(--border);
}
.rest-timer.running { background: var(--accent); color: #fff; font-size: 17px; }

/* ---------- Planning ---------- */
.phase-legend { display: flex; gap: 6px; margin-bottom: 14px; }
.phase-legend .pl { flex: 1; text-align: center; font-size: 11px; font-weight: 700; padding: 7px 2px; border-radius: 8px; color: #0b1120; cursor: pointer; opacity: 0.85; }
.phase-legend .pl.active { opacity: 1; outline: 2px solid #fff; }
.week-scroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 14px; scrollbar-width: none; }
.week-scroll::-webkit-scrollbar { display: none; }
.week-pill {
  min-width: 52px; text-align: center; padding: 9px 6px; border-radius: 12px; cursor: pointer;
  background: var(--surface); border: 2px solid transparent; border-top: 4px solid;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.week-pill.current { border-color: var(--accent); }
.week-pill.selected { background: var(--surface-2); outline: 2px solid #fff; }
.week-pill small { display: block; font-size: 10px; color: var(--muted); font-weight: 500; }
.week-meta { display: flex; gap: 10px; margin-bottom: 12px; }
.week-meta .wm { flex: 1; background: var(--surface); border-radius: 12px; padding: 10px; text-align: center; border: 1px solid var(--border); }
.week-meta .wm .v { font-weight: 800; font-size: 17px; }
.week-meta .wm .l { font-size: 11px; color: var(--muted); }
.mini-session { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.mini-session .ms-ico { font-size: 26px; }
.mini-session .ms-body { flex: 1; }
.mini-session .ms-title { font-weight: 700; font-size: 15px; }
.mini-session .ms-sub { font-size: 12px; color: var(--muted); }
.mini-session .ms-check { font-size: 20px; }

/* ---------- Progrès ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat-tile .st-v { font-size: 24px; font-weight: 800; }
.stat-tile .st-v small { font-size: 13px; color: var(--text-2); font-weight: 600; }
.stat-tile .st-l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-tile .st-delta { font-size: 12px; font-weight: 700; }
.st-delta.good { color: #4ade80; }
.st-delta.bad { color: #fca5a5; }

.chart-card h4 { font-size: 15px; font-weight: 800; margin-bottom: 2px; }
.chart-card .ch-sub { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.chart-card svg { width: 100%; height: auto; display: block; }
.chart-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 24px 0; }
details.data-table { margin-top: 8px; }
details.data-table summary { font-size: 12px; color: var(--muted); cursor: pointer; }
details.data-table table { width: 100%; font-size: 13px; margin-top: 8px; border-collapse: collapse; }
details.data-table td, details.data-table th { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: left; color: var(--text-2); }

.heatmap { display: grid; grid-template-rows: repeat(7, 13px); grid-auto-flow: column; grid-auto-columns: 13px; gap: 3px; overflow-x: auto; padding-bottom: 6px; }
.hm-cell { width: 13px; height: 13px; border-radius: 3px; background: var(--bg); }
.hm-legend { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.hm-legend span { display: inline-flex; align-items: center; gap: 5px; }
.hm-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 8px; text-align: center; }
.badge .b-e { font-size: 30px; }
.badge .b-n { font-size: 12px; font-weight: 700; margin-top: 4px; }
.badge .b-d { font-size: 10px; color: var(--muted); margin-top: 2px; }
.badge.locked { opacity: 0.35; filter: grayscale(1); }

.weight-form { display: flex; gap: 8px; align-items: flex-end; }
.weight-form .field { flex: 1; margin: 0; }

/* ---------- Onboarding ---------- */
.onb { display: flex; flex-direction: column; min-height: 100dvh; padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom)); }
.onb-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 24px; }
.onb-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-2); }
.onb-dots i.on { background: var(--accent); }
.onb h2 { font-size: 26px; font-weight: 800; margin-bottom: 6px; }
.onb .onb-sub { color: var(--text-2); margin-bottom: 20px; }
.onb-body { flex: 1; }
.equip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.equip-item {
  background: var(--surface); border: 2px solid var(--border); border-radius: 14px;
  padding: 16px 12px; text-align: center; cursor: pointer; font-weight: 600; font-size: 14px;
}
.equip-item .e-ico { font-size: 28px; display: block; margin-bottom: 6px; }
.equip-item.on { border-color: var(--accent); background: var(--accent-soft); }
.big-input { font-size: 30px !important; text-align: center; font-weight: 800; padding: 18px !important; }
.choice-list .choice {
  background: var(--surface); border: 2px solid var(--border); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 10px; cursor: pointer; font-weight: 600;
}
.choice-list .choice.on { border-color: var(--accent); background: var(--accent-soft); }
.celebrate { text-align: center; padding-top: 40px; }
.celebrate .c-emoji { font-size: 72px; }
.celebrate h2 { margin: 12px 0 6px; }
.goal-line { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 15px; }
.goal-line b { color: var(--accent); }

/* ---------- Modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 90; display: flex; align-items: flex-end; }
.modal { background: var(--bg); width: 100%; max-width: 560px; margin: 0 auto; border-radius: 20px 20px 0 0; max-height: 88dvh; overflow-y: auto; padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.modal-close { position: sticky; top: 0; float: right; background: var(--surface-2); border: none; color: var(--text); width: 34px; height: 34px; border-radius: 50%; font-size: 16px; cursor: pointer; }

#toast-zone { position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 0; right: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--surface-2); border: 1px solid var(--accent); color: var(--text);
  padding: 12px 20px; border-radius: 99px; font-weight: 700; font-size: 15px;
  animation: toast-in 0.3s ease, toast-out 0.4s ease 2.6s forwards;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
@keyframes toast-in { from { transform: translateY(-20px); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(-20px); opacity: 0; } }

h4.section { font-size: 15px; font-weight: 800; margin: 18px 0 10px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.5px; }
.muted { color: var(--muted); font-size: 13px; }
.spacer { height: 10px; }

/* ---------- Bibliothèque d'exercices ---------- */
.lib-search { margin-bottom: 10px; }
.chip-scroll { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chip-scroll::-webkit-scrollbar { display: none; }
.fchip {
  flex: 0 0 auto; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.fchip.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 6px; }
.lib-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px; cursor: pointer; }
.lib-card img { width: 100%; aspect-ratio: 1; border-radius: 10px; background: #fff; object-fit: contain; }
.lc-name { font-weight: 700; font-size: 13px; margin-top: 8px; line-height: 1.25; text-transform: capitalize; }
.lc-sub { font-size: 11px; color: var(--muted); margin-top: 2px; text-transform: capitalize; }
.lib-pager { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 8px; }

.exo-detail .ed-gif { width: 100%; max-width: 240px; display: block; margin: 0 auto 12px; border-radius: 14px; background: #fff; }
.exo-detail h3 { text-transform: capitalize; }
.ed-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; text-transform: capitalize; }
.ed-steps { margin: 14px 0 0 18px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: var(--text-2); }

/* GIFs dans les séances */
.exo-gif { float: right; width: 76px; height: 76px; border-radius: 10px; background: #fff; margin: 0 0 6px 10px; object-fit: contain; }
.circuit-box .c-exo { display: flex; gap: 10px; align-items: center; }
.c-thumb { width: 44px; height: 44px; border-radius: 8px; background: #fff; object-fit: contain; flex: 0 0 auto; }
