/* =============================================================================
   app.css — 4×4×48
   Thème sombre par défaut, bascule clair/sombre manuelle (SPEC §10 amendé v0.2).
   Une info dominante par regard. Cibles tactiles ≥48px. Aucune animation
   décorative — seules les transitions fonctionnelles (pression, coche) sont
   autorisées, et coupées sous prefers-reduced-motion.
   ============================================================================= */

:root {
  --bg: #0b0d10;
  --bg-elevated: #15181d;
  --bg-elevated-2: #1c2027;
  --border: #262b33;
  --text: #e8e6e1;
  --text-dim: #9aa0a8;
  --accent: #4f8cf7;
  --accent-dim: #2f66d0;
  --accent-text: #ffffff;
  --danger: #ff5a5f;
  --danger-bg: #2a1112;
  --ok: #5fd17a;
  --focus: #7fd0ff;
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 48px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

/* Thème clair — bascule manuelle uniquement : pas de détection
   prefers-color-scheme, sombre reste le défaut au premier chargement. */
:root[data-theme="light"] {
  --bg: #f4f2ee;
  --bg-elevated: #ffffff;
  --bg-elevated-2: #edeae4;
  --border: #ddd8ce;
  --text: #1c1d1f;
  --text-dim: #62666d;
  --accent: #2f66d0;
  --accent-dim: #1f4aa3;
  --accent-text: #ffffff;
  --danger: #b8272c;
  --danger-bg: #fbe6e6;
  --ok: #276b3f;
  --focus: #0a6f96;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.06), 0 8px 24px rgba(20, 20, 30, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

.tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

button {
  font: inherit;
  color: inherit;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: var(--tap);
  padding: 10px 16px;
  cursor: pointer;
  transition: background-color 0.12s ease, transform 0.06s ease, border-color 0.12s ease;
}
button:hover { border-color: var(--accent); }
button:active { transform: scale(0.98); }
button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: default; transform: none; }
button:disabled:hover { border-color: var(--border); }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: var(--tap);
}
input:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
textarea { min-height: 72px; resize: vertical; }

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

h1, h2, h3 { margin: 0 0 8px; letter-spacing: -0.01em; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------------------------------------------------------------- Layout */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg); /* repli si color-mix() indisponible */
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.topbar__nav {
  display: flex;
  gap: 6px;
  flex: 1;
  flex-wrap: wrap;
}

.navbtn { background: transparent; border-color: transparent; }
.navbtn[aria-current="true"] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}

main {
  flex: 1;
  padding: 16px 16px 32px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

/* Vues à une colonne (Configuration, Fin) : gardent la largeur de lecture v0.1. */
.narrow {
  max-width: 640px;
  margin: 0 auto;
}

footer {
  padding: 12px 16px calc(16px + var(--safe-b));
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: 13px;
}

.footer__status { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- Setup */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
}
.field-row label { color: var(--text-dim); font-size: 14px; }
.field-row input { width: 100%; }

.muted { color: var(--text-dim); font-size: 14px; }

/* ---------------------------------------------------------------- Hero */

.hero {
  text-align: center;
  padding: 12px 0 24px;
}

.hero__tour {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text-dim);
}

.hero__countdown {
  font-size: 76px;
  font-weight: 800;
  line-height: 1;
  margin: 4px 0;
  word-break: keep-all;
}

.hero__next {
  font-size: 18px;
  color: var(--text-dim);
}

.hero__progress {
  height: 8px;
  background: var(--bg-elevated-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 18px auto 0;
  max-width: 480px;
}
.hero__progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

/* ---------------------------------------------------------------- Défi — deux colonnes */

.challenge-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.85fr) minmax(320px, 1.3fr) minmax(260px, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 1000px) {
  /* Le suivi de course et l'historique passent sous la colonne principale
     plutôt que de l'écraser : deux colonnes tant qu'il y a la place. */
  .challenge-grid { grid-template-columns: 1fr 1fr; }
  .challenge-history { grid-column: 1 / -1; order: 2; }
  .challenge-main { order: 1; }
  .challenge-right { order: 1; }
}
@media (max-width: 760px) {
  .challenge-grid { grid-template-columns: 1fr; }
  .challenge-history, .challenge-main, .challenge-right { grid-column: auto; }
  .challenge-main { order: 1; }
  .challenge-history { order: 2; }
  .challenge-right { order: 3; }
}

.phase-block__title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 2px;
}
.phase-block__subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 12px;
}

.phase-chrono {
  font-size: 44px;
  font-weight: 800;
  margin: 8px 0 16px;
}

.phase-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 18px 0 4px;
}
.phase-actions .btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  font-size: 18px;
  font-weight: 700;
  padding: 18px 16px;
  box-shadow: var(--shadow);
}
.btn-secondary {
  background: transparent;
  color: var(--text-dim);
  border: 1px dashed var(--border);
  font-weight: 400;
  box-shadow: none;
}

.phase-recap {
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--text-dim);
}
.phase-recap div { margin-bottom: 4px; }

/* Panneau à onglets — segmenté, style pilule */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--bg-elevated-2);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: calc(var(--radius-sm) - 3px);
  padding: 9px 12px;
  font-size: 13px;
  min-height: 40px;
  flex: 1 1 auto;
}
.tab-btn:hover { border-color: transparent; background: var(--bg-elevated-2); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.tab-btn[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.tab-panels {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 10px;
  max-height: 76vh;
  overflow-y: auto;
}
.tab-panel[hidden] { display: none; }

.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.ref-table th, .ref-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.ref-table th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.ref-phase {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 12px;
}
.ref-phase h3 { font-size: 16px; margin-bottom: 4px; }
.ref-phase .muted { margin-bottom: 8px; }
.ref-phase ul { margin: 4px 0 10px; padding-left: 20px; }
.ref-phase li { margin-bottom: 4px; font-size: 14px; }

/* ---------------------------------------------------------------- Checklist */

.category {
  margin-bottom: 18px;
}
.category__title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 600;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  min-height: var(--tap);
}
.check-item:last-child { border-bottom: none; }

.check-item input[type="checkbox"] {
  width: 26px;
  height: 26px;
  min-height: 26px;
  flex-shrink: 0;
  accent-color: var(--accent);
  margin-top: 2px;
}

.check-item label {
  flex: 1;
  padding-top: 2px;
}
.check-item.is-checked label {
  color: var(--text-dim);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.info-line {
  padding: 6px 4px;
  color: var(--text-dim);
  font-size: 15px;
}

.phase-attention {
  background: var(--bg-elevated-2); /* repli si color-mix() indisponible */
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-elevated));
  border-left: 3px solid var(--accent);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}

/* ---------------------------------------------------------------- Préparation globale (palier bloquant) */

.prep-progress { margin: 14px 0; }
.prep-progress__bar {
  height: 10px;
  background: var(--bg-elevated-2);
  border-radius: 999px;
  overflow: hidden;
}
.prep-progress__fill { height: 100%; background: var(--accent); border-radius: inherit; }
.prep-progress__label { margin-top: 6px; font-size: 14px; color: var(--text-dim); }

.check-all-btn { width: 100%; margin-bottom: 10px; font-size: 14px; min-height: 40px; }

/* ---------------------------------------------------------------- Échauffement guidé */

.exo-guide { margin: 10px 0 4px; }
.exo-label { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.exo-countdown { font-size: 52px; font-weight: 800; margin: 4px 0 12px; }
.exo-progress {
  height: 8px;
  background: var(--bg-elevated-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 16px;
}
.exo-progress__fill { height: 100%; background: var(--accent); border-radius: inherit; }
.exo-done { font-size: 20px; font-weight: 700; color: var(--ok); margin: 12px 0; }

/* ---------------------------------------------------------------- Suivi course à pied */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}
.stat {
  text-align: center;
  padding: 12px 4px;
  background: var(--bg-elevated-2);
  border-radius: var(--radius-sm);
}
.stat__value { font-size: 20px; font-weight: 800; }
.stat__label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- Past laps */

details.past-lap {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  padding: 0;
  overflow: hidden;
}
details.past-lap summary {
  padding: 12px 14px;
  cursor: pointer;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  font-weight: 600;
  list-style: none;
}
details.past-lap summary::-webkit-details-marker { display: none; }
details.past-lap .past-lap__body { padding: 0 14px 14px; }

/* ---------------------------------------------------------------- Blessures */

.filter-input { width: 100%; margin-bottom: 14px; font-size: 18px; }

.blessure {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 12px;
}
.blessure h3 { color: var(--accent); font-size: 18px; }
.blessure dl { margin: 6px 0 0; }
.blessure dt { color: var(--text-dim); font-size: 13px; text-transform: uppercase; margin-top: 8px; }
.blessure dd { margin: 2px 0 0; }

.disclaimer {
  font-size: 13px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}

/* ---------------------------------------------------------------- Modals */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px;
  padding-bottom: calc(24px + var(--safe-b));
}
@media (min-width: 600px) {
  .modal { border-radius: var(--radius); }
}

.modal__close {
  width: 100%;
  margin-top: 16px;
}

.reset-danger-zone {
  color: var(--danger);
  border-color: var(--danger);
}

/* ---------------------------------------------------------------- End screen */

.end-summary li { margin-bottom: 6px; }
