:root {
	--fond: #f4f5f7;
	--surface: #ffffff;
	--texte: #15181d;
	--texte-2: #5d6470;
	--accent: #e8590c;
	--accent-texte: #ffffff;
	--erreur: #c92a2a;
	--bord: #e1e4e8;
	color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
	:root {
		--fond: #111418;
		--surface: #1b1f25;
		--texte: #f1f3f5;
		--texte-2: #9aa3ae;
		--accent: #ff7a2e;
		--accent-texte: #111418;
		--erreur: #ff6b6b;
		--bord: #2a3038;
	}
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
	background: var(--fond);
	color: var(--texte);
	font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	min-height: 100vh;
	padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
	-webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

h1 { font-size: 1.8rem; margin: 0.4rem 0 0; }

.centre {
	max-width: 420px;
	margin: 0 auto;
	padding: 12vh 20px 40px;
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
	gap: 14px;
}

.logo { border-radius: 22px; }

.sous-titre { color: var(--texte-2); margin: 0 0 18px; }

.bouton-principal {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	width: 100%;
	min-height: 54px;
	border: 0;
	border-radius: 14px;
	background: var(--accent);
	color: var(--accent-texte);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

.bouton-principal:disabled { opacity: 0.55; }

.bouton-discret {
	border: 0;
	background: none;
	color: var(--accent);
	font: inherit;
	font-size: 0.95rem;
	padding: 8px 4px;
	cursor: pointer;
}

.message { min-height: 1.4em; color: var(--texte-2); margin: 0; }
.message.erreur { color: var(--erreur); }

.note { color: var(--texte-2); font-size: 0.85rem; }

.champ {
	display: flex;
	flex-direction: column;
	gap: 6px;
	width: 100%;
	text-align: left;
	color: var(--texte-2);
	font-size: 0.9rem;
}

.champ input {
	font: inherit;
	font-size: 17px;
	padding: 12px 14px;
	border-radius: 12px;
	border: 1px solid var(--bord);
	background: var(--surface);
	color: var(--texte);
}

.barre {
	position: sticky;
	top: 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 16px;
	background: var(--fond);
	border-bottom: 1px solid var(--bord);
}

.barre .titre { font-weight: 700; font-size: 1.15rem; }

.contenu { max-width: 720px; margin: 0 auto; padding: 16px; }

.bonjour { font-size: 1.4rem; font-weight: 700; margin: 6px 0 16px; }

.tuiles {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 12px;
}

.tuile {
	background: var(--surface);
	border: 1px solid var(--bord);
	border-left: 5px solid var(--accent);
	border-radius: 14px;
	padding: 16px 14px;
	min-height: 104px;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.tuile-nom { font-weight: 700; font-size: 1.1rem; }
.tuile-detail { color: var(--texte-2); font-size: 0.85rem; }

.tuile-crossfit { border-left-color: #e8590c; }
.tuile-boxe-thai { border-left-color: #c92a2a; }
.tuile-trial { border-left-color: #2f9e44; }
.tuile-autre { border-left-color: #1c7ed6; }

a.tuile { color: inherit; text-decoration: none; }
a.tuile:active { transform: scale(0.98); }
.tuile-a-venir { opacity: 0.5; }

.barre a.bouton-discret { text-decoration: none; }
.barre-espace { width: 70px; }

/* --- suivi --- */
.case-jour {
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 16px;
	background: var(--surface);
	border: 1px solid var(--bord);
	border-radius: 16px;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

.case-jour input,
.cal-jour input {
	position: absolute;
	opacity: 0;
	width: 1px;
	height: 1px;
}

.case-jour-boite {
	flex: none;
	width: 40px;
	height: 40px;
	border-radius: 12px;
	border: 2px solid var(--bord);
	display: grid;
	place-items: center;
	transition: background 0.15s, border-color 0.15s;
}

.case-jour input:checked + .case-jour-boite {
	background: var(--accent);
	border-color: var(--accent);
}

.case-jour input:checked + .case-jour-boite::after {
	content: "";
	width: 12px;
	height: 22px;
	border: solid var(--accent-texte);
	border-width: 0 4px 4px 0;
	transform: translateY(-2px) rotate(45deg);
}

.case-jour input:focus-visible + .case-jour-boite { outline: 3px solid var(--accent); outline-offset: 2px; }

.case-jour-texte { display: flex; flex-direction: column; }
.case-jour-texte span { color: var(--texte-2); font-size: 0.9rem; }

.stats {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 10px;
	margin: 6px 0 16px;
}

.stat {
	background: var(--surface);
	border: 1px solid var(--bord);
	border-radius: 14px;
	padding: 12px 10px;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.stat-val { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-lib { color: var(--texte-2); font-size: 0.78rem; line-height: 1.25; }

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

.carte h2 { font-size: 1rem; margin: 0 0 12px; }

.graphe {
	display: grid;
	grid-template-columns: repeat(12, minmax(0, 1fr));
	gap: 4px;
	height: 150px;
	align-items: end;
}

.graphe-col {
	height: 100%;
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	align-items: center;
	gap: 3px;
}

.graphe-barre {
	width: 100%;
	max-width: 22px;
	min-height: 2px;
	background: var(--accent);
	opacity: 0.55;
	border-radius: 4px 4px 0 0;
}

.graphe-courante .graphe-barre { opacity: 1; }
.graphe-val { font-size: 0.72rem; font-weight: 600; min-height: 1em; }
.graphe-lib { font-size: 0.6rem; color: var(--texte-2); white-space: nowrap; }

.mois-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.mois-nav h2 { margin: 0; }
.mois-nav .bouton-discret { font-size: 1.5rem; padding: 0 12px; text-decoration: none; }
.mois-nav .inactif { opacity: 0.25; }

.calendrier {
	display: grid;
	grid-template-columns: repeat(7, minmax(0, 1fr));
	gap: 6px;
}

.cal-entete { text-align: center; font-size: 0.75rem; color: var(--texte-2); font-weight: 600; }

.cal-jour { position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }

.cal-jour span {
	display: grid;
	place-items: center;
	aspect-ratio: 1;
	border-radius: 10px;
	border: 1.5px solid var(--bord);
	font-variant-numeric: tabular-nums;
	font-size: 0.95rem;
	transition: background 0.15s;
}

.cal-auj span { border-color: var(--accent); font-weight: 700; }
.cal-jour input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); font-weight: 700; }
.cal-jour input:disabled + span { opacity: 0.3; }
.cal-jour input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 1px; }

.tuiles > li { display: flex; }
.tuiles > li > .tuile { flex: 1; }

/* --- accueil : stats --- */
:root {
	--c-crossfit: #e8590c;
	--c-boxe-thai: #c92a2a;
	--c-trial: #2f9e44;
	--c-calisthenie: #7048e8;
	--c-course: #f59f00;
	--c-autre: #1c7ed6;
}

@media (prefers-color-scheme: dark) {
	:root {
		--c-crossfit: #ff7a2e;
		--c-boxe-thai: #ff6b6b;
		--c-trial: #51cf66;
		--c-calisthenie: #9775fa;
		--c-course: #fcc419;
		--c-autre: #4dabf7;
	}
}

.tuile-chiffres { font-size: 0.95rem; }
.tuile-chiffres strong { font-size: 1.15rem; }

.carte-accueil { margin-top: 16px; }

.graphe-pile {
	width: 100%;
	max-width: 22px;
	min-height: 2px;
	display: flex;
	flex-direction: column-reverse;
	border-radius: 4px 4px 0 0;
	overflow: hidden;
	background: var(--bord);
}

.graphe-seg { display: block; flex-basis: 0; }

.serie-crossfit { background: var(--c-crossfit); }
.serie-boxe-thai { background: var(--c-boxe-thai); }
.serie-trial { background: var(--c-trial); }
.serie-calisthenie { background: var(--c-calisthenie); }
.serie-course { background: var(--c-course); }
.serie-autre { background: var(--c-autre); }

.legende {
	list-style: none;
	margin: 12px 0 0;
	padding: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 6px 16px;
	font-size: 0.85rem;
	color: var(--texte-2);
}

.legende li { display: flex; align-items: center; gap: 6px; }
.puce { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.carte-accueil .note { margin: 10px 0 0; }

.tuile-crossfit { border-left-color: var(--c-crossfit); }
.tuile-boxe-thai { border-left-color: var(--c-boxe-thai); }
.tuile-trial { border-left-color: var(--c-trial); }
.tuile-calisthenie { border-left-color: var(--c-calisthenie); }
.tuile-course { border-left-color: var(--c-course); }
.tuile-autre { border-left-color: var(--c-autre); }

/* --- details : charges / sorties --- */
.carte h3 { font-size: 0.9rem; color: var(--texte-2); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: 0.04em; }

.formulaire {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 10px;
	align-items: end;
}

.formulaire .champ-large,
.formulaire .bouton-principal,
.formulaire .message { grid-column: 1 / -1; }

.formulaire .champ input { width: 100%; min-width: 0; -webkit-appearance: none; appearance: none; min-height: 46px; }
.formulaire .note { margin: 0; }

.liste-records,
.liste-entrees { list-style: none; margin: 0; padding: 0; }

.liste-records li,
.liste-entrees li {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 0;
	border-top: 1px solid var(--bord);
}

.rec-mvt { flex: 1; min-width: 0; }
.rec-kg { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--c-crossfit); }
.rec-date { color: var(--texte-2); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.ent-date { color: var(--texte-2); font-size: 0.85rem; font-variant-numeric: tabular-nums; width: 3em; flex: none; }
.ent-texte { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.bouton-suppr {
	flex: none;
	width: 36px;
	height: 36px;
	border: 0;
	border-radius: 10px;
	background: none;
	color: var(--texte-2);
	font-size: 1.4rem;
	line-height: 1;
	cursor: pointer;
}

#charges, #sorties { scroll-margin-top: 70px; }

/* --- WOD --- */
.champ textarea {
	font: inherit;
	font-size: 17px;
	padding: 12px 14px;
	border-radius: 12px;
	border: 1px solid var(--bord);
	background: var(--surface);
	color: var(--texte);
	width: 100%;
	resize: vertical;
	line-height: 1.4;
}

.champ-titre { display: block; color: var(--texte-2); font-size: 0.9rem; margin-bottom: 6px; }

.lignes-exercices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

.ligne-exercice {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 64px 70px 36px;
	gap: 6px;
	align-items: center;
}

.ligne-exercice input,
.ligne-exercice select {
	font: inherit;
	font-size: 17px; /* >= 16px : evite le zoom automatique de Safari iOS */
	min-width: 0;
	width: 100%;
	min-height: 44px;
	padding: 8px 10px;
	border-radius: 10px;
	border: 1px solid var(--bord);
	background: var(--surface);
	color: var(--texte);
}

.ligne-exercice select { padding: 8px 4px; }

.tableau-defile { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.tableau-exercices { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.tableau-exercices th { text-align: left; color: var(--texte-2); font-weight: 600; font-size: 0.78rem; padding: 6px 8px 6px 0; }
.tableau-exercices td { padding: 8px 8px 8px 0; border-top: 1px solid var(--bord); white-space: nowrap; }
.tableau-exercices td:first-child { white-space: normal; }
.tableau-exercices .note { font-size: 0.75rem; }

.liste-wod { list-style: none; margin: 0; padding: 0; }
.liste-wod > li { padding: 10px 0; border-top: 1px solid var(--bord); }
.wod-entete { display: flex; align-items: center; gap: 10px; }
.wod-score { flex: 1; font-weight: 700; color: var(--c-crossfit); }
.wod-texte { white-space: pre-wrap; margin: 4px 0 6px; font-size: 0.92rem; }
.wod-exercices { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.wod-exercices li { background: var(--fond); border: 1px solid var(--bord); border-radius: 999px; padding: 3px 10px; font-size: 0.85rem; }

#wod { scroll-margin-top: 70px; }
