:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface2: #efece4;
  --text: #1c1b19;
  --muted: #6b675f;
  --line: #e4dfd3;
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --u1: #e4572e;
  --u2: #2a7f8f;
  --danger: #c0392b;
  --ok: #2e8b57;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 18px rgba(0, 0, 0, .04);
  --nav-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1f1d1a;
    --surface2: #2a2723;
    --text: #f2efe8;
    --muted: #a39e93;
    --line: #34312c;
    --accent: #ff7a50;
    --accent-ink: #1a0e08;
    --u1: #ff7a50;
    --u2: #4fb3c2;
    --danger: #ff6b5b;
    --ok: #5cc48a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

body.locked { overflow: hidden; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 24px; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 16px; }
p { margin: 0; }
a { color: inherit; }

.splash { text-align: center; margin-top: 40vh; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; padding: 24px 0; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.gap { gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid2, .grid3 { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); }
.grid3 { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); }

/* En-tête */
.top { display: flex; align-items: center; gap: 10px; min-height: 52px; margin-bottom: 12px; }
.top h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .right { display: flex; gap: 6px; }
.run-top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(env(safe-area-inset-top) + 8px) 0 8px; margin-top: calc(-8px - env(safe-area-inset-top)); }
.run-top h1 { font-size: 20px; }

/* Boutons */
button { font: inherit; color: inherit; }
.btn, .icon-btn, .chip, .bravo, .check, .pick, .tab, .seg button, .stepper button {
  -webkit-user-select: none; user-select: none; touch-action: manipulation; cursor: pointer;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.big { min-height: 54px; font-size: 17px; width: 100%; }
.btn.block { display: flex; width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .5; }
.btn:active, .icon-btn:active, .check:active { transform: scale(.97); }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 12px; background: transparent; color: var(--text); text-decoration: none;
}
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.btn .ic { width: 18px; height: 18px; }

/* Cartes */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card > h2 { margin-bottom: 10px; }
.section { margin: 22px 0 10px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hint { display: flex; align-items: center; gap: 8px; background: var(--surface2); }
.hint p { flex: 1; font-size: 14px; }
.resume { display: flex; align-items: center; gap: 12px; text-decoration: none; border-color: var(--accent); }
.resume div { flex: 1; display: flex; flex-direction: column; }
.resume span { color: var(--muted); font-size: 14px; }
.resume .ic { color: var(--accent); }
.empty { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.link-row { display: block; padding: 14px 16px; text-decoration: none; font-weight: 600; }

/* Objectif commun */
.big-num { font-size: 40px; font-weight: 750; letter-spacing: -.02em; margin: 6px 0 10px; font-variant-numeric: tabular-nums; }
.big-num span { font-size: 18px; color: var(--muted); font-weight: 600; }
.bar { display: flex; height: 10px; border-radius: 99px; background: var(--surface2); overflow: hidden; gap: 2px; }
.bar i { display: block; height: 100%; }
.legend { display: flex; gap: 16px; margin-top: 10px; font-size: 14px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.u1 { background: var(--u1); color: #fff; }
.u2 { background: var(--u2); color: #fff; }

/* Semaine */
.week-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.week-row + .week-row { border-top: 1px solid var(--line); }
.who { width: 72px; font-weight: 600; }
.pips { flex: 1; display: flex; gap: 6px; flex-wrap: wrap; }
.pip { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: inline-block; }
.pip.on { border-color: transparent; }
.pip.extra { width: 14px; height: 14px; align-self: center; }

/* Point de la semaine */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-width: 40px; height: 40px; padding: 0 8px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-variant-numeric: tabular-nums;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.checkin p + .chips { margin-top: 10px; }
.checkin .others { margin-top: 10px; display: flex; gap: 14px; font-size: 14px; color: var(--muted); }

/* Programmes */
.routine { display: flex; flex-direction: column; gap: 12px; }
.routine .actions { display: flex; gap: 8px; justify-content: flex-end; }
.ex-list { color: var(--muted); margin-top: 6px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; background: var(--surface2); padding: 4px; border-radius: 12px; }
.tab { flex: 1; text-align: center; padding: 8px; border-radius: 9px; text-decoration: none; font-weight: 600; color: var(--muted); }
.tab.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Formulaires */
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 600; }
input, textarea, select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-size: 14px; color: var(--muted); font-weight: 600; padding: 0; margin-bottom: 8px; }
.seg { display: flex; background: var(--surface2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.item { margin-bottom: 10px; display: flex; flex-direction: column; gap: 10px; }
.item .row.between b { flex: 1; min-width: 0; }
.item .icon-btn { width: 36px; height: 36px; }
.note-input { min-height: 40px; font-size: 16px; }
.search { margin-bottom: 12px; }
.stepper { display: inline-flex; align-items: center; gap: 12px; }
.stepper button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 20px; }
.stepper b { min-width: 20px; text-align: center; font-variant-numeric: tabular-nums; }

/* Séance en cours */
.note summary { cursor: pointer; font-weight: 600; }
.note p { margin-top: 8px; white-space: pre-line; color: var(--muted); }
.group h2 { margin-bottom: 4px; }
.group .hint-text { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.set { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.group h2 + .set, .group .hint-text + .set { border-top: 0; }
.set-label { flex: 1; min-width: 0; font-weight: 600; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.set-label .link { font: inherit; font-weight: 600; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.set-label small { font-weight: 400; color: var(--muted); font-size: 13px; }
.set-label .hold { margin-top: 6px; min-height: 34px; }
.val { flex-direction: row; align-items: center; gap: 4px; }
.val input { width: 68px; text-align: center; padding: 8px 4px; font-variant-numeric: tabular-nums; font-weight: 600; }
.val span { font-size: 13px; width: 30px; }
.check {
  width: 48px; height: 48px; border-radius: 14px; flex: none; display: grid; place-items: center;
  border: 2px solid var(--line); background: var(--surface); color: var(--muted);
}
.set.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.set.done .set-label, .set.done .val input { color: var(--muted); }
.rest {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 16px);
  width: min(528px, calc(100% - 32px)); z-index: 20;
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 18px;
  background: var(--text); color: var(--bg); box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.rest b { flex: 1; font-size: 26px; font-variant-numeric: tabular-nums; }
.rest .btn { color: var(--bg); border-color: transparent; background: rgba(127, 127, 127, .25); }

/* Fil */
.post header { gap: 10px; margin-bottom: 10px; align-items: flex-start; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; flex: none; }
.stats { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.stats span { background: var(--surface2); border-radius: 99px; padding: 4px 10px; font-size: 13px; font-weight: 600; }
.summary { list-style: none; margin: 0 0 10px; padding: 0; font-size: 14px; }
.summary li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; }
.quote { border-left: 3px solid var(--line); padding-left: 10px; margin-bottom: 10px; color: var(--muted); white-space: pre-line; }
.bravo {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px;
}
.bravo.on { color: var(--accent); border-color: var(--accent); }
.bravo.on .ic { fill: currentColor; }
.comments { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.comments:empty { display: none; }
.comment-form { display: flex; gap: 6px; margin-top: 10px; }
.comment-form input { min-height: 40px; padding: 8px 12px; }

/* Progrès */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.kpis b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.kpis span { font-size: 13px; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; }
.chart .lbl { font-size: 10px; fill: var(--muted); text-anchor: middle; }
.chart .target { stroke: var(--text); stroke-dasharray: 4 4; stroke-width: 1; opacity: .5; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.fill-u1 { fill: var(--u1); }
.fill-u2 { fill: var(--u2); }
.fill-muted { fill: var(--line); }
.chart .ln { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .ln.feeling { stroke: var(--accent); }
.chart .ln.pain { stroke: var(--text); stroke-dasharray: 5 4; opacity: .7; }
.chart .pt.feeling { fill: var(--accent); }
.chart .pt.pain { fill: var(--text); opacity: .7; }
.key { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.key i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 4px; border-radius: 2px; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { display: flex; justify-content: space-between; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.list-plain li:first-child { border-top: 0; }

/* Connexion */
.auth { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; gap: 16px; text-align: center; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 18px; }
.brand svg { width: 72px; height: 72px; }
.brand h1 { font-size: 32px; }
.dev { display: flex; gap: 8px; margin-top: 24px; flex-wrap: wrap; justify-content: center; }
.dev p { width: 100%; }
.dev input { max-width: 180px; }

/* Bibliothèque */
.ex-card h3 { margin-bottom: 2px; }
.ex-card p { font-size: 14px; color: var(--muted); margin-top: 6px; }
.ex-card .row.between { align-items: flex-start; }

/* Navigation basse */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; max-width: 140px; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 12px; font-weight: 600; text-decoration: none; color: var(--muted);
}
.nav a[aria-current="page"] { color: var(--accent); }

/* Bandeau, notifications, feuille */
.banner {
  position: sticky; top: 0; z-index: 30; text-align: center; font-size: 14px; font-weight: 600;
  padding: calc(env(safe-area-inset-top) + 6px) 16px 6px; background: var(--surface2); color: var(--muted);
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600;
  max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
}
#sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
  max-width: 560px; margin: 0 auto; background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
}
.sheet-head { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; position: sticky; top: -18px; background: var(--bg); padding-top: 4px; }
.pick-list { display: flex; flex-direction: column; }
.pick {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 12px 4px; border: 0; border-bottom: 1px solid var(--line); background: transparent;
}
.new-ex { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }

@media (hover: hover) {
  .btn:hover { filter: brightness(.97); }
  .pick:hover, .link-row:hover { background: var(--surface2); }
}
