:root {
  color-scheme: light dark;
  --bg: oklch(98% 0.005 250);
  --surface: oklch(100% 0 0);
  --surface-2: oklch(96% 0.008 250);
  --border: oklch(90% 0.01 250);
  --text: oklch(22% 0.02 260);
  --muted: oklch(50% 0.02 260);
  --accent: oklch(62% 0.16 165);
  --accent-ink: oklch(99% 0 0);
  --accent-soft: oklch(94% 0.05 165);
  --ok: oklch(62% 0.16 150);
  --warn: oklch(72% 0.16 70);
  --bad: oklch(60% 0.2 25);
  --info: oklch(62% 0.13 240);
  --radius: 14px;
  --shadow: 0 1px 2px oklch(0% 0 0 / 0.06), 0 8px 24px oklch(0% 0 0 / 0.06);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(17% 0.015 260);
    --surface: oklch(21% 0.018 260);
    --surface-2: oklch(25% 0.02 260);
    --border: oklch(32% 0.02 260);
    --text: oklch(94% 0.01 260);
    --muted: oklch(70% 0.02 260);
    --accent: oklch(74% 0.15 165);
    --accent-ink: oklch(18% 0.02 165);
    --accent-soft: oklch(32% 0.06 165);
    --shadow: 0 1px 2px oklch(0% 0 0 / 0.3), 0 8px 24px oklch(0% 0 0 / 0.25);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.5rem, 2.5vw, 2rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75em; }
small, .muted { color: var(--muted); }

/* --- Layout ---------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  background: color-mix(in oklch, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.brand svg { width: 28px; height: 28px; color: var(--accent); }
.topbar nav { margin-left: auto; display: flex; gap: 0.5rem; }
main { max-width: 1240px; margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1rem, 2vw, 1.5rem);
  box-shadow: var(--shadow);
}
.card h2 { display: flex; align-items: center; gap: 0.5rem; }

/* --- Boutons & formulaires ------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 42px; padding: 0.55rem 1rem;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform 0.1s, background 0.2s;
}
.btn:hover { background: var(--border); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.big { min-height: 56px; font-size: 1.1rem; padding: 0.75rem 1.5rem; }
.btn.ghost { background: transparent; border-color: transparent; }

form fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem 1.25rem; margin: 0 0 1rem; background: var(--surface); }
form legend { font-weight: 700; padding: 0 0.4rem; }
.fields { display: grid; gap: 0.9rem 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
label.field { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.9rem; }
label.field span.hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.55rem 0.7rem; min-height: 42px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.unit-input { position: relative; }
.unit-input input { padding-right: 2.6rem; }
.unit-input em { position: absolute; right: 0.7rem; top: 50%; translate: 0 -50%; font-style: normal; color: var(--muted); font-size: 0.85rem; pointer-events: none; }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip-check { position: relative; }
.chip-check input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip-check span { display: inline-block; padding: 0.45rem 0.8rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); font-size: 0.88rem; }
.chip-check input:checked + span { background: var(--accent-soft); border-color: var(--accent); }
.chip-check input:focus-visible + span { outline: 2px solid var(--accent); }
.radio-cards { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.radio-card { position: relative; border: 1px solid var(--border); border-radius: 12px; padding: 0.8rem 1rem; background: var(--surface-2); cursor: pointer; }
.radio-card input { position: absolute; opacity: 0; }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card strong { display: block; }
.radio-card small { display: block; }
details.howto { margin-top: 0.75rem; font-size: 0.9rem; }
details.howto summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details.howto ul { margin: 0.5rem 0 0; padding-left: 1.2rem; }

/* --- Badges, score, barres de plage --------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 700; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: color-mix(in oklch, var(--ok) 40%, transparent); }
.badge.low, .badge.high { color: var(--bad); border-color: color-mix(in oklch, var(--bad) 40%, transparent); }
.badge.info, .badge.na { color: var(--muted); }
.badge.better { color: var(--ok); }
.badge.worse { color: var(--bad); }
.badge.p1 { background: var(--bad); color: white; border: 0; }
.badge.p2 { background: var(--warn); color: oklch(20% 0.02 70); border: 0; }
.badge.p3 { background: var(--surface-2); }

.score-ring { --v: 0; --c: var(--accent); width: 112px; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--c) calc(var(--v) * 1%), var(--surface-2) 0); flex-shrink: 0; }
.score-ring > div { width: 82%; aspect-ratio: 1; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; }
.score-ring b { font-size: 1.9rem; line-height: 1; }
.score-ring small { font-size: 0.7rem; }

.metric { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 0.75rem; padding: 0.8rem 0; border-bottom: 1px solid var(--border); }
.metric:last-child { border-bottom: 0; }
.metric .name { font-weight: 600; }
.metric .val { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.1rem; text-align: right; }
.metric .bar { grid-column: 1 / -1; }
.metric .help { grid-column: 1 / -1; font-size: 0.82rem; color: var(--muted); }
.rangebar { width: 100%; height: 34px; display: block; }
.rangebar .track { fill: var(--surface-2); }
.rangebar .zone { fill: color-mix(in oklch, var(--ok) 35%, transparent); }
.rangebar .marker { fill: var(--text); }
.rangebar .marker.bad { fill: var(--bad); }
.rangebar .prev { fill: var(--muted); opacity: 0.6; }
.rangebar text { font-size: 10px; fill: var(--muted); font-family: var(--font); }

.rec { display: grid; grid-template-columns: auto 1fr auto; gap: 0.25rem 0.9rem; padding: 1rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.rec + .rec { margin-top: 0.75rem; }
.rec.now { border-color: var(--accent); background: var(--accent-soft); }
.rec .num { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--surface); border: 1px solid var(--border); }
.rec .action { font-weight: 700; font-size: 1.02rem; }
.rec .amount { font-weight: 800; font-size: 1.2rem; font-variant-numeric: tabular-nums; color: var(--accent); white-space: nowrap; }
.rec .detail { grid-column: 2 / -1; font-size: 0.88rem; color: var(--muted); }
.rec .meta { grid-column: 2 / -1; display: flex; gap: 0.4rem; flex-wrap: wrap; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.rider-card { display: flex; gap: 1rem; align-items: center; text-decoration: none; color: inherit; }
.rider-card:hover { border-color: var(--accent); }
.avatar { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 1.2rem; background: var(--accent-soft); color: var(--accent); flex-shrink: 0; }

table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th, table.data td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
table.data td.num { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 30px 1fr; gap: 0.6rem; align-items: start; }
.steps li::before { content: counter(s); width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 0.85rem; }

.hero { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); align-items: center; margin-bottom: 1.5rem; }
.hero p.lead { font-size: 1.1rem; color: var(--muted); }

/* --- Séance live ----------------------------------------------------------- */
.live-grid { grid-template-columns: minmax(260px, 340px) 1fr; }
@media (max-width: 860px) { .live-grid { grid-template-columns: 1fr; } }
.qr-box { display: grid; gap: 0.75rem; justify-items: center; text-align: center; }
.qr-box .qr { width: min(260px, 100%); background: white; padding: 10px; border-radius: 12px; }
.qr-box .qr svg { display: block; width: 100%; height: auto; }
.code { font-family: ui-monospace, monospace; font-size: 1.6rem; font-weight: 800; letter-spacing: 0.2em; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.status-dot.on { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in oklch, var(--ok) 25%, transparent); }
.live-canvas { width: 100%; aspect-ratio: 16 / 9; background: oklch(15% 0.02 260); border-radius: 12px; display: block; }
.live-metrics { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.live-metric { padding: 0.6rem 0.8rem; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.live-metric b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.live-metric.ok b { color: var(--ok); }
.live-metric.bad b { color: var(--bad); }
.live-metric small { font-size: 0.75rem; }
.banner { padding: 0.8rem 1rem; border-radius: 10px; background: var(--accent-soft); border: 1px solid var(--accent); font-weight: 600; }
.banner.warn { background: color-mix(in oklch, var(--warn) 18%, var(--surface)); border-color: var(--warn); }
.countdown { font-size: 4rem; font-weight: 900; text-align: center; font-variant-numeric: tabular-nums; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width 0.3s; }

.snapshots { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.snapshots figure { margin: 0; }
.snapshots img { width: 100%; border-radius: 10px; display: block; background: black; }
.snapshots figcaption { font-size: 0.82rem; color: var(--muted); margin-top: 0.3rem; }
.chart { width: 100%; height: 180px; display: block; }
.chart .grid line { stroke: var(--border); }
.chart text { font-size: 10px; fill: var(--muted); font-family: var(--font); }

.toast { position: fixed; bottom: 1rem; left: 50%; translate: -50% 0; padding: 0.75rem 1.1rem; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 600; z-index: 100; box-shadow: var(--shadow); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

/* --- Schémas ----------------------------------------------------------------- */
.diagram-grid { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); margin-top: 0.75rem; }
.diagram-card { margin: 0; padding: 0.6rem 0.75rem 0.75rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.diagram-card figcaption { font-size: 0.82rem; color: var(--muted); }
.diagram-card figcaption strong { display: block; color: var(--text); font-size: 0.9rem; }
.diagram { display: block; width: 100%; height: auto; overflow: visible; }
.diagram.wide { max-width: 640px; margin: 0 auto; }
.diagram .d-body { stroke: var(--text); stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.diagram .d-obj { stroke: var(--muted); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.diagram .d-obj-fill { fill: var(--surface); stroke: var(--muted); stroke-width: 1.5; }
.diagram .d-print { fill: color-mix(in oklch, var(--muted) 45%, transparent); }
.diagram .d-key-fill { fill: var(--accent); }
.diagram .d-key-stroke { stroke: var(--accent); stroke-width: 4; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.diagram .d-dim line, .diagram .d-dim polyline { stroke: var(--accent); stroke-width: 2; fill: none; stroke-linecap: round; }
.diagram .d-dim text, .diagram .d-label text { fill: var(--accent); font: 800 13px var(--font); }
.diagram .d-guide { stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 3 3; opacity: 0.8; }
.diagram .d-note { fill: var(--muted); font: 600 10px var(--font); }
.bike-legend { display: grid; gap: 0.35rem 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); margin: 0.75rem 0 0; padding: 0; list-style: none; font-size: 0.86rem; }
.bike-legend b { display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 0.4rem; border-radius: 6px; background: var(--accent); color: var(--accent-ink); font-size: 0.78rem; }

/* --- Comptes ----------------------------------------------------------------- */
.auth { width: min(440px, 100%); margin: 1.5rem auto 0; }
.auth__head { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; margin-bottom: 1.25rem; text-align: center; }
.auth__head svg { border-radius: 18px; box-shadow: var(--shadow); }
.auth__head h1 { margin: 0.4rem 0 0; font-size: 1.6rem; }
.auth__head p { margin: 0; color: var(--muted); }
.auth__form { display: grid; gap: 1rem; }
.auth__form .btn { width: 100%; }
.auth__alt { margin: 1rem 0 0; text-align: center; font-size: 0.92rem; color: var(--muted); }
.auth__faint { text-align: center; font-size: 0.9rem; color: var(--muted); }
.auth__separator { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.auth__separator::before, .auth__separator::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.form-error { margin: 0; padding: 0.6rem 0.8rem; border-radius: 8px; background: color-mix(in oklch, var(--bad) 14%, var(--surface)); color: var(--bad); font-weight: 600; font-size: 0.9rem; }
.form-error[hidden] { display: none; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.topbar__user { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.3rem 0.7rem 0.3rem 0.3rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text); text-decoration: none; font-weight: 600; }
.topbar__user:hover { border-color: var(--accent); }
.topbar__avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.topbar__name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar nav { align-items: center; flex-wrap: wrap; }

/* --- Pied de page ------------------------------------------------------------- */
.app-footer { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.4rem 1.25rem; padding: 1.5rem 1rem 2rem; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--border); margin-top: 2rem; }
.app-footer a { color: inherit; font-weight: 600; position: relative; }
.app-footer a:hover { color: var(--accent); }
.footer__dot { display: inline-block; width: 8px; height: 8px; margin-left: 0.3rem; border-radius: 50%; background: var(--accent); vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@media (max-width: 640px) {
  .topbar__name { display: none; }
  .topbar__user { padding: 0.2rem; }
  .rec { grid-template-columns: auto 1fr; }
  .rec .amount { grid-column: 2; }
}

@media print {
  .topbar, .app-footer, .no-print, .btn { display: none !important; }
  body { background: white; color: black; }
  .card { box-shadow: none; break-inside: avoid; }
}

@view-transition { navigation: auto; }
