/* ==========================================================================
   SpeedGate — thème sombre, cohérent avec SplitFrame / PaceCoach.
   ========================================================================== */

:root {
  --bg: #0f172a;
  --panel: #111a2e;
  --panel-2: #0b1226;
  --border: #1e293b;
  --text: #e2e8f0;
  --muted: #8b97ab;
  --accent: #22d3ee;   /* cyan — action / en cours */
  --yellow: #facc15;   /* jaune — couleur détectée / repère */
  --good: #34d399;     /* vert — arrêté / succès */
  --danger: #f87171;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Arial, sans-serif;
}

.num {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

button, input { font-family: inherit; }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.wordmark { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; }
.wordmark strong { color: var(--accent); font-weight: 800; }
.logo-mark { width: 28px; height: 28px; border-radius: 8px; }
.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  white-space: nowrap;
}
.back-link:hover { color: var(--text); }

/* ---------- Layout ---------- */
.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

section h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 12px;
}

/* ---------- Caméra ---------- */
.camera-panel { display: flex; flex-direction: column; gap: 8px; }

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  touch-action: none; /* évite le scroll de page quand on glisse sur la vidéo */
}

#video { display: none; } /* source pixel uniquement, jamais affichée */

#canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(10, 14, 26, 0.78);
}
.overlay-hint {
  margin: 0;
  max-width: 40ch;
  font-size: 0.85rem;
  color: var(--muted);
}

/* .camera-overlay fixe display:flex, ce qui annule le display:none par
   défaut de l'attribut [hidden] — on le rétablit explicitement ici. */
.camera-overlay[hidden] {
  display: none;
}

.camera-error {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  margin: 0;
  padding: 8px 12px;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 8px;
  font-size: 0.85rem;
}

.hint-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.hint-line {
  flex: 1;
  min-width: 200px;
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.btn-small {
  padding: 7px 12px;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* ---------- Chrono ---------- */
.timer-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.timer-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
}
.status-idle        { background: rgba(139, 151, 171, 0.15); color: var(--muted); }
.status-calibrating { background: rgba(34, 211, 238, 0.12);  color: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.status-running     { background: rgba(34, 211, 238, 0.18);  color: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.status-stopped     { background: rgba(52, 211, 153, 0.15);  color: var(--good); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.precision-note {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
}

.calibration-info {
  align-self: stretch;
  margin: 0;
  padding: 6px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  font-size: 0.72rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.timer-display {
  font-size: clamp(2.6rem, 12vw, 3.6rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
}

.skater-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.skater-row label {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}
.skater-row input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.95rem;
}
.skater-row input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------- Boutons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn-large { width: 100%; padding: 14px 16px; font-size: 1rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #06222b; }
.btn-secondary { background: var(--panel); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); }

/* ---------- Réglages ---------- */
.settings-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
}
.setting-row { margin-bottom: 16px; }
.setting-row:last-child { margin-bottom: 0; }
.setting-row label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.85rem;
  margin-bottom: 6px;
}
.setting-value { color: var(--accent); }
.setting-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.setting-help {
  margin: 6px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ---------- Historique ---------- */
.history-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
}
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.history-head h2 { margin: 0; }

.history-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.history-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 10px 0;
}
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
}
.history-item .h-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item .h-time {
  color: var(--yellow);
  font-weight: 700;
}
.history-item .h-date {
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}
.history-item.h-live {
  border-color: var(--accent);
}

.disclaimer {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  .status-running { animation: none; }
}
