/*
 * Training App — thème clair par défaut, sombre automatique (réglage du téléphone).
 * Une seule chose est mise en avant : les gros chiffres de l'écran de la machine.
 * Tout le reste reste calme : fond neutre, cartes blanches, un seul accent orange.
 */
:root {
  color-scheme: light dark;
  --bg: #f4f4f6;
  --surface: #ffffff;
  --surface-2: #ececf0;
  --fg: #1f1f24;
  --muted: #6b6b76;
  --line: #e4e4ea;
  --accent: #d63c00;
  --on-accent: #ffffff;
  --accent-soft: #fdece4;
  --err: #c0182d;
  --ok: #17794a;
  --overlay: rgba(244, 244, 246, .97);
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 8px 24px rgba(20, 20, 30, .06);
  --focus: 0 0 0 3px rgba(214, 60, 0, .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101013;
    --surface: #1b1b20;
    --surface-2: #2a2a31;
    --fg: #f2f2f5;
    --muted: #a0a0ab;
    --line: #2b2b33;
    --accent: #ff6a2b;
    --on-accent: #1a0c02;
    --accent-soft: #2b1a11;
    --err: #ff8a98;
    --ok: #5ad39a;
    --overlay: rgba(16, 16, 19, .97);
    --shadow: none;
    --focus: 0 0 0 3px rgba(255, 106, 43, .45);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
}

main { max-width: 520px; margin: 0 auto; padding: 0 16px 56px; }

h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; margin: 18px 0 16px; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 0 0 12px; }
p { margin: 0 0 12px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
ol { padding-left: 0; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }

/* --- Menu : tous les liens restent visibles (ils passent à la ligne), page courante en pastille pleine --- */
nav {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 2px;
  margin: 0 -8px; padding: 10px 0 4px;
}
nav form { margin: 0; }
nav a, nav button.link {
  padding: 8px 13px; border-radius: 999px;
  color: var(--muted); font-weight: 600; font-size: .95rem; white-space: nowrap;
}
nav a:hover { text-decoration: none; color: var(--fg); }
nav a[aria-current="page"] { background: var(--fg); color: var(--bg); }

/* --- Cartes --- */
.card, form.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  margin: 14px 0;
  box-shadow: var(--shadow);
}
a.card { display: block; color: var(--fg); }
a.card:hover { text-decoration: none; }

/* --- Formulaires --- */
label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: .9rem; font-weight: 600; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 13px 14px; font: inherit; font-size: 1rem;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 12px;
}
textarea { display: block; resize: vertical; line-height: 1.4; }
.note { white-space: pre-line; padding: 10px 12px; background: var(--accent-soft); border-radius: 12px; }
input[type=file] { width: 100%; padding: 10px 0; color: var(--muted); font: inherit; font-size: .95rem; }
input[type=file]::file-selector-button {
  margin-right: 12px; padding: 10px 14px; border: 0; border-radius: 10px;
  background: var(--surface-2); color: var(--fg); font: inherit; font-weight: 600; cursor: pointer;
}

button, .btn {
  display: inline-block; min-height: 48px; margin-top: 16px; padding: 13px 20px;
  border: 0; border-radius: 14px;
  background: var(--accent); color: var(--on-accent);
  font: inherit; font-size: 1rem; font-weight: 700; text-align: center; cursor: pointer;
  transition: transform .08s;
}
button:active, .btn:active { transform: scale(.98); }
/* Boutons et compteurs : pas de sélection de texte, de menu de copie ni de zoom au double appui sur téléphone. */
button, .btn, .counter {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { text-decoration: none; }
a.btn { color: var(--on-accent); }
button.secondary, .btn.secondary { background: var(--surface-2); color: var(--fg); }
button.secondary { width: 100%; margin-top: 8px; }
button[hidden], .secondary[hidden] { display: none; }
form.card button + button, form.card button + .btn { margin-left: 8px; }
form.card button + button.secondary { margin-left: 0; }

button.link {
  min-height: 0; margin: 0; padding: 0; background: none; border-radius: 0;
  color: var(--accent); font-weight: 600;
}

fieldset.muscles {
  display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px;
  margin: 14px 0 0; padding: 4px 14px 8px;
  border: 1px solid var(--line); border-radius: 14px;
}
fieldset.muscles legend { padding: 0 6px; color: var(--muted); font-size: .9rem; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 12px; margin: 0; padding: 12px 0; color: var(--fg); font-size: 1rem; font-weight: 500; }
label.check input { width: 24px; height: 24px; flex: none; accent-color: var(--accent); }

details.image-admin summary { padding: 8px 0; color: var(--accent); font-weight: 600; cursor: pointer; }

/* --- Messages --- */
.muted { color: var(--muted); font-size: .9rem; }
.error { color: var(--err); font-weight: 600; }
.ok { color: var(--ok); font-weight: 600; }
code { word-break: break-all; }

table { width: 100%; border-collapse: collapse; }
td, th { padding: 10px 4px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }

/* --- Courbes (SVG généré par le serveur) --- */
.chart-axis { stroke: var(--line); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 10px; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--accent); }

/* --- Choix de machine --- */
.machine { margin: 8px 0; }
button.choice {
  display: flex; align-items: center; width: 100%; min-height: 0; margin: 0; padding: 12px;
  background: var(--surface); color: var(--fg); text-align: left;
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.choice-text { display: flex; flex-direction: column; min-width: 0; }
.choice-text strong { font-size: 1.05rem; }

/* --- Images --- */
.machine-img { display: block; width: 100%; max-height: 260px; object-fit: cover; border-radius: 16px; margin: 0 0 12px; }
.thumb { flex: none; width: 72px; height: 72px; object-fit: cover; border-radius: 12px; margin-right: 12px; vertical-align: middle; }
[data-zoom] { cursor: zoom-in; }
.zoom-overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center; padding: 12px;
  background: rgba(0, 0, 0, .92); cursor: zoom-out;
}
.zoom-overlay img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 12px; }
.zoom-close { position: absolute; top: 12px; right: 12px; margin: 0; padding: 0; width: 48px; height: 48px; border-radius: 24px; background: rgba(255, 255, 255, .18); color: #fff; font-size: 1.4rem; line-height: 1; }

/* --- Écran de la machine : les gros chiffres --- */
.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 2px 0 14px; }
.counters-1 { grid-template-columns: 1fr; }
.counters-2, .counters-4 { grid-template-columns: repeat(2, 1fr); }
#free-text { margin-bottom: 12px; }
.counter {
  display: grid; grid-template-columns: 1fr 1fr;
  grid-template-areas: "label label" "value value" "minus plus";
  gap: 6px; padding: 10px 8px 8px; text-align: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: 16px;
}
.counter > span { grid-area: label; color: var(--muted); font-size: .8rem; font-weight: 600; }
.counter .value {
  grid-area: value; font-size: 2.35rem; font-weight: 800; line-height: 1.05;
  letter-spacing: -.03em; font-variant-numeric: tabular-nums;
}
button.step {
  min-height: 48px; margin: 0; padding: 0; font-size: 1.6rem; line-height: 1;
  background: var(--surface-2); color: var(--fg); border-radius: 12px;
}
/* Un léger glissement du doigt ne doit pas devenir un défilement, qui couperait la répétition. */
button.step { touch-action: none; }
button.step[data-dir="-1"] { grid-area: minus; }
button.step[data-dir="1"] { grid-area: plus; }
button.big { width: 100%; min-height: 64px; margin-top: 4px; font-size: 1.15rem; border-radius: 16px; }

#edit-banner { margin: 8px 0 0; }
.rest { margin-top: 14px; padding: 12px; text-align: center; background: var(--accent-soft); border-radius: 16px; }
.rest p { margin: 0; color: var(--muted); font-weight: 600; }
.rest output { display: block; color: var(--fg); font-size: 2.4rem; font-weight: 800; line-height: 1.1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }

.overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--overlay); text-align: center; font-size: 2.3rem; font-weight: 800; line-height: 1.15; letter-spacing: -.02em;
}
.overlay[hidden] { display: none; }
.overlay button { min-width: 180px; min-height: 64px; font-size: 1.3rem; border-radius: 16px; }

/* --- Liste des séries : numéro en pastille, résumé en gras --- */
ol { counter-reset: set; }
ol > li { list-style: none; counter-increment: set; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0; padding: 12px 6px; border-bottom: 1px solid var(--line); }
ol > li:last-child { border-bottom: 0; }
ol > li::before {
  content: counter(set); flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--muted); font-size: .85rem; font-weight: 700;
}
.set-text { flex: 1; font-weight: 700; font-variant-numeric: tabular-nums; }
li .set-actions, li .set-confirm { white-space: nowrap; }
li .set-actions[hidden], li .set-confirm[hidden] { display: none; }
li .set-actions .link, li .set-confirm .link { padding: 8px 6px; }
li.editing { background: var(--accent-soft); border-radius: 12px; box-shadow: inset 0 0 0 2px var(--accent); }
.setrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 1; }
.setrow input[type=number] { width: 5.5ch; padding: 8px; border-radius: 10px; }
.setrow input[type=text] { width: 7.5ch; padding: 8px; border-radius: 10px; }
.setrow input[name=free_text] { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  button, .btn { transition: none; }
  button:active, .btn:active { transform: none; }
}
