:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --info-bg: #dbeafe;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.2rem; margin: 0 0 .8rem; }
h3 { font-size: 1.05rem; }
code, pre { font-family: Consolas, "Courier New", monospace; }
code { background: #eef2f7; padding: 0 .3em; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.2rem 0; }

/* Barre du haut */
.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  background: #111827; color: #fff; padding: .7rem 1.5rem;
}
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.2rem; }
.topbar nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.topbar nav a, .topbar .link { color: #d1d5db; }
.topbar nav a:hover, .topbar .link:hover { color: #fff; text-decoration: none; }

.container { max-width: 1050px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.3rem 1.5rem; margin-bottom: 1.2rem; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card.narrow { max-width: 400px; margin: 3rem auto; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.2rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.grid.two { margin-bottom: 1.2rem; }

.muted { color: var(--muted); }

/* Formulaires */
label { display: block; margin-bottom: .9rem; font-weight: 500; font-size: .95rem; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
input:not([type=checkbox]):not([type=radio]), textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .7rem;
  border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; background: #fff;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { font-family: Consolas, monospace; font-size: .9rem; resize: vertical; }
form.inline { display: inline; }

.btn {
  display: inline-block; padding: .55rem 1.1rem; border-radius: 6px; border: 1px solid #cbd5e1;
  background: #fff; color: var(--text); font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
button.link { background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }

/* Messages */
.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-success { background: var(--success-bg); color: #14532d; }
.flash-error { background: var(--danger-bg); color: #7f1d1d; }
.flash-info, .flash-message { background: var(--info-bg); color: #1e3a8a; }

/* Badges, tableaux */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem;
         background: #e5e7eb; color: #374151; }
.badge.done { background: var(--success-bg); color: #166534; }
.badge.running { background: var(--info-bg); color: #1e40af; }
.tag { display: inline-block; font-size: .75rem; padding: 0 .45rem; border-radius: 4px;
       background: var(--success-bg); color: #166534; margin-left: .4rem; }

table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions details { display: inline-block; text-align: left; }
.row-actions summary { list-style: none; }
.row-actions summary::-webkit-details-marker { display: none; }
.edit-form { position: absolute; z-index: 10; background: #fff; border: 1px solid var(--border);
             border-radius: 8px; padding: 1rem; width: 280px; right: 2rem; box-shadow: 0 6px 20px rgba(0,0,0,.12); }

.assign-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px;
               padding: .5rem .8rem; margin: .6rem 0; }
.assign-list label.check { margin: .25rem 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1.2rem; margin-bottom: 1.2rem; }
.stats .card { margin: 0; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-value { font-size: 2rem; font-weight: 700; }

pre.format { background: #0f172a; color: #e2e8f0; padding: 1rem; border-radius: 8px; overflow-x: auto; font-size: .88rem; }

/* Quiz */
.quiz-card h2 { margin-bottom: .2rem; }
.quiz-header-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.quiz-header h1 { margin: 0; }

.timer { display: flex; flex-direction: column; align-items: flex-end; padding: .4rem .9rem;
         border-radius: 8px; background: #f1f5f9; transition: background .3s, color .3s; }
.timer-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.timer-value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.timer.warning { background: var(--warning-bg); color: var(--warning); }
.timer.critical { background: var(--danger-bg); color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }

.progress-row { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }
.progress { flex: 1; height: 12px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.progress.big { height: 16px; margin: 1rem 0; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), #22c55e); transition: width .4s; }
.progress-label { white-space: nowrap; font-size: .9rem; }

.question-text { white-space: pre-line; }
.choices { display: flex; flex-direction: column; gap: .6rem; margin: 1.2rem 0; }
.choice { display: flex; align-items: center; gap: .8rem; margin: 0; padding: .8rem 1rem; font-weight: 400;
          border: 1px solid var(--border); border-radius: 8px; cursor: pointer; transition: background .15s, border-color .15s; }
.choice:hover { background: #f8fafc; border-color: #93c5fd; }
.choice:has(input:checked) { background: #eff6ff; border-color: var(--primary); }
.choice input { width: 1.15rem; height: 1.15rem; accent-color: var(--primary); flex-shrink: 0; }

.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.actions .danger { margin-left: auto; }

.navigator { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: 1.4rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.nav-item { width: 2.3rem; height: 2.3rem; border-radius: 6px; border: 1px solid #cbd5e1; background: #fff;
            font: inherit; font-size: .85rem; cursor: pointer; }
.nav-item.answered { background: var(--success-bg); border-color: #86efac; color: #166534; }
.nav-item.current { outline: 2px solid var(--primary); outline-offset: 1px; font-weight: 700; }
.nav-item:disabled { opacity: .45; cursor: not-allowed; }

/* Résultats */
.filters { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.filters label { margin: 0; flex: 1; min-width: 200px; }
.filters .btn:first-of-type { margin-left: auto; }
select { display: block; width: 100%; margin-top: .3rem; padding: .5rem .6rem; border: 1px solid #cbd5e1;
         border-radius: 6px; font: inherit; background: #fff; }
h2 .btn.small { float: right; font-weight: 400; }
.score-cell { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.score-pct { font-weight: 600; font-size: .85rem; }
.score-pct.good, .score-big.good, .ok-text { color: var(--success); }
.score-pct.bad, .score-big.bad, .ko-text { color: var(--danger); }
.mini-bar { width: 80px; height: 6px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.mini-bar > div { height: 100%; background: var(--primary); }
.score-big { font-size: 2.2rem; font-weight: 800; }
.score-big small { font-size: 1rem; font-weight: 600; }
.attempt-summary { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; }
.correction { border-left: 4px solid var(--border); }
.correction.ok { border-left-color: var(--success); }
.correction.ko { border-left-color: var(--danger); }
.correction-choices li.given:not(.correct) { background: var(--danger-bg); color: #7f1d1d; }
.result-summary { text-align: center; }
.done-icon { width: 4rem; height: 4rem; margin: .5rem auto 1rem; border-radius: 50%;
             display: flex; align-items: center; justify-content: center;
             font-size: 2rem; background: var(--success-bg); color: var(--success); }
.correction-choices { list-style: none; padding: 0; margin: .5rem 0 0; }
.correction-choices li { padding: .25rem .5rem; border-radius: 4px; }
.correction-choices li.correct { color: #166534; font-weight: 600; }
.preview-question { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.preview-question:last-child { border-bottom: 0; }
.preview-question p { margin: 0; }

@media (max-width: 600px) {
  .actions .danger { margin-left: 0; }
  .progress-row { flex-direction: column; align-items: stretch; gap: .4rem; }
  table { font-size: .85rem; }
}

/* Réponses des participants */
h1 .btn { font-size: .9rem; font-weight: 400; vertical-align: middle; margin-left: .6rem; }
.small { font-size: .8rem; }
.nowrap { white-space: nowrap; }
.answers-toolbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.answers-toolbar p { margin-top: 0; flex: 1; min-width: 260px; }
.table-scroll { overflow-x: auto; }
.answers-matrix th, .answers-matrix td { text-align: center; vertical-align: middle; }
.answers-matrix .sticky { text-align: left; position: sticky; left: 0; background: var(--card); z-index: 1; min-width: 160px; }
.answers-matrix .qcol a { color: var(--muted); }
.cell { font-weight: 700; font-family: Consolas, monospace; min-width: 2.6rem; cursor: help; }
.cell-ok { background: var(--success-bg); color: #166534; }
.cell-ko { background: var(--danger-bg); color: #991b1b; }
.cell-empty { color: #9ca3af; }
.legend { padding: 0 .35rem; border-radius: 4px; font-weight: 600; }
.distribution td { vertical-align: middle; }
.distribution tr.correct td:first-child { color: #166534; }
.dist-bar { width: 30%; }
.mini-bar.wide { width: 100%; height: 10px; }
.mini-bar .bar-ok { background: var(--success); }
.mini-bar .bar-ko { background: #f87171; }

/* Suivi en direct (tableau de bord) */
.live-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.live-header h2 { margin: 0; display: flex; align-items: center; gap: .5rem; }
.live-dot { width: .7rem; height: .7rem; border-radius: 50%; background: var(--success);
            box-shadow: 0 0 0 0 rgba(22,163,74,.6); animation: live-pulse 2s infinite; }
.live-dot.offline { background: var(--danger); animation: none; }
@keyframes live-pulse { 70% { box-shadow: 0 0 0 .5rem rgba(22,163,74,0); } 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); } }
.live-table td, .live-table th { vertical-align: middle; }
.th-sub { font-weight: 400; font-size: .75rem; }
.live-timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem;
              padding: .15rem .5rem; border-radius: 6px; background: #f1f5f9; }
.live-timer.warning { background: var(--warning-bg); color: var(--warning); }
.live-timer.critical { background: var(--danger-bg); color: var(--danger); }
.live-finished td { opacity: .7; }

.mini-bar.marked { position: relative; overflow: visible; }
.mini-bar.marked > div { border-radius: 999px; }
.bar-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: #111827; }
.status-cell { display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; }
.status { display: inline-block; padding: .15rem .55rem; border-radius: 6px; font-size: .75rem;
          font-weight: 800; letter-spacing: .04em; white-space: nowrap; }
.status-running { background: var(--info-bg); color: #1e40af; }
.status-done { background: #e5e7eb; color: #111827; }
.status-passed { background: var(--success); color: #fff; }
.status-failed { background: var(--danger-bg); color: #991b1b; }

/* Tirage des questions */
.draw-settings { border: 1px solid var(--border); border-radius: 8px; padding: .8rem 1rem .2rem; margin: 0 0 1rem; }
.draw-settings legend { font-weight: 600; padding: 0 .3rem; }
.draw-settings .small { display: block; font-weight: 400; margin-top: .2rem; }
.draw-help { padding-left: 1.1rem; margin: -.3rem 0 .8rem; }
.tag.info { background: var(--info-bg); color: #1e40af; }
.cell-absent { color: #cbd5e1; background: repeating-linear-gradient(45deg, #fff, #fff 4px, #f8fafc 4px, #f8fafc 8px); }

/* Statistiques par question */
.live-header select { width: auto; min-width: 240px; margin-top: 0; }
.stats-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem 1rem; padding: .8rem 1rem;
                 background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; margin: .6rem 0; }
.stats-filters label { margin: 0; font-size: .88rem; }
.stats-filters select { width: auto; }
.stats-filters .pct-input { display: flex; align-items: center; gap: .3rem; }
.stats-filters .pct-input input { width: 5rem; margin-top: 0; }
.stats-filters input[type=range] { flex: 1; min-width: 140px; margin-bottom: .55rem; accent-color: var(--primary); }
.quick-filters { display: flex; gap: .4rem; flex-wrap: wrap; width: 100%; }
.qstats-table td { vertical-align: middle; }
.qstats-text { min-width: 260px; max-width: 520px; }
.qstats-table tr.row-excluded td:not(:last-child) { opacity: .45; }

/* Consigne anti-IA : présente dans la page (lue par les assistants), invisible à l'écran */
.ai-note { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
           overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
           border: 0; user-select: none; -webkit-user-select: none; }
.integrity-notice { margin: 1rem 0 0; }

/* Vigilance IA */
.vigilance-card.alert { border-left: 4px solid var(--danger); }
.vigilance-card h2 { display: flex; align-items: center; gap: .6rem; }
.vig-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: .8rem; }
.vig-grid > div { display: flex; flex-direction: column; }
.vig-value { font-size: 1.6rem; font-weight: 700; }
.events { margin-top: .6rem; }
.correction .status { margin-left: .4rem; vertical-align: middle; }
.live-table td.vig-alert { background: #fff5f5; }

/* Résultats papier */
.tag.paper { background: #fef3c7; color: #92400e; }
.steps { padding-left: 1.2rem; }
.steps li { margin-bottom: 1rem; }
tr.row-error td { background: #fff5f5; }
.paper-grid td { vertical-align: middle; padding: .35rem .5rem; }
.paper-question { cursor: help; }
.paper-letters { white-space: nowrap; }
.letter { display: inline-flex; align-items: center; gap: .2rem; margin: 0 .5rem 0 0; font-weight: 700; cursor: pointer; }
.letter input { width: 1.05rem; height: 1.05rem; accent-color: var(--primary); }
.clear-answer { color: var(--muted); margin-left: .3rem; }
.date-field { max-width: 220px; }
.sticky-actions { position: sticky; bottom: 0; z-index: 5; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
@media print { .topbar, .btn, .flash { display: none !important; } .card { box-shadow: none; border: 0; } }

/* Course : participants sur une piste d'athlétisme */
.race-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; }
.race-head h1 { margin: 0; }
.race-controls { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.race-controls select { width: auto; max-width: calc(100vw - 2rem); }
.race-track { --lane-num: 2.2rem; --runner: 2.8rem;
              background: repeating-linear-gradient(90deg, #3f9142 0 3rem, #47a04a 3rem 6rem);
              border-radius: 18px; padding: .8rem 1.2rem 1.4rem; box-shadow: inset 0 0 0 4px #2f7a33, 0 6px 18px rgba(0,0,0,.12); }
.race-ruler { position: relative; height: 1.6rem; margin-left: var(--lane-num); }
.race-ruler span { position: absolute; left: calc(.4rem + var(--m) * (100% - var(--runner) - .8rem) + var(--runner) / 2); transform: translateX(-50%);
                   color: #fff; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
                   text-shadow: 0 1px 2px rgba(0,0,0,.4); white-space: nowrap; }
.race-ruler span:first-child { left: .4rem; transform: none; }
.race-ruler span:last-child { left: auto; right: 0; transform: none; }
.race-lanes { border-radius: 8px; overflow: hidden; box-shadow: 0 3px 0 #8f3b22; }
.lane { display: flex; height: 4.8rem; background: #c75b39; border-top: 2px solid rgba(255,255,255,.85); }
.lane:last-child { border-bottom: 2px solid rgba(255,255,255,.85); }
.lane:nth-child(even) { background: #c05434; }
.lane-num { width: var(--lane-num); flex: none; display: grid; place-items: center; background: #9f4126;
            color: #fff; font-weight: 800; font-size: 1.1rem; }
.lane-run { position: relative; flex: 1;
            background: linear-gradient(90deg, #fff 0 4px, transparent 4px),
                        linear-gradient(90deg, transparent calc(25% - 1px), rgba(255,255,255,.18) 0 calc(25% + 1px), transparent 0,
                                        transparent calc(50% - 1px), rgba(255,255,255,.18) 0 calc(50% + 1px), transparent 0,
                                        transparent calc(75% - 1px), rgba(255,255,255,.18) 0 calc(75% + 1px), transparent 0); }
/* Ligne d'arrivée en damier */
.lane-run::after { content: ""; position: absolute; top: 0; bottom: 0; right: calc(var(--runner) + .3rem); width: .9rem;
                   background: repeating-conic-gradient(#fff 0 25%, #1f2937 0 50%) 0 0 / .45rem .45rem; }
.runner { position: absolute; top: .35rem; z-index: 1; left: calc(.4rem + var(--p, 0) * (100% - var(--runner) - .8rem));
          width: var(--runner); display: flex; flex-direction: column; align-items: center;
          transition: left 1.4s cubic-bezier(.34, 1.25, .64, 1); }
.runner-body { width: var(--runner); height: var(--runner); border-radius: 50%; display: grid; place-items: center;
               background: var(--c); border: 3px solid #fff; font-size: 1.55rem; line-height: 1;
               box-shadow: 0 4px 0 rgba(0,0,0,.22); }
.runner.running .runner-body { animation: runner-hop .45s ease-in-out infinite alternate; }
.runner.arrived .runner-body { animation: runner-cheer .5s ease-in-out 1.4s 3; }
.runner-tag { margin-top: .2rem; padding: 0 .45rem; border-radius: 999px; background: var(--c); color: #fff;
              font-size: .72rem; font-weight: 700; white-space: nowrap; max-width: 10rem; overflow: hidden; text-overflow: ellipsis;
              box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.runner.arrived .runner-tag { align-self: flex-end; }
.runner.at-start .runner-tag { align-self: flex-start; }
.runner-medal { position: absolute; top: -.3rem; left: -.7rem; font-size: 1.25rem; z-index: 2;
                filter: drop-shadow(0 1px 1px rgba(0,0,0,.35)); }
@keyframes runner-hop { from { transform: translateY(0) rotate(-6deg); } to { transform: translateY(-6px) rotate(6deg); } }
@keyframes runner-cheer { 50% { transform: translateY(-12px) scale(1.12); } }
.race-empty { padding: 2.5rem 1rem; text-align: center; color: #fff; font-weight: 600; background: #c75b39; }
.race-help { margin-top: .8rem; }

.race-podium { display: flex; justify-content: center; align-items: flex-end; gap: .6rem; margin-bottom: 1.2rem; }
.podium-step { width: 9rem; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
               border-radius: 14px 14px 4px 4px; padding: .5rem .5rem .7rem; color: #1f2937; box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.podium-1 { order: 2; height: 9rem; background: linear-gradient(#fde68a, #f59e0b); }
.podium-2 { order: 1; height: 7.5rem; background: linear-gradient(#f1f5f9, #94a3b8); }
.podium-3 { order: 3; height: 6.5rem; background: linear-gradient(#fed7aa, #c2410c); }
.podium-medal { font-size: 1.4rem; }
.podium-char { font-size: 2.2rem; line-height: 1.1; }
.podium-name { font-weight: 700; font-size: .85rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.confetti { position: absolute; width: .45rem; height: .75rem; border-radius: 2px; pointer-events: none; z-index: 50;
            animation: confetti-burst 1.6s ease-out forwards; }
@keyframes confetti-burst {
  40% { transform: translate(calc(var(--dx) * .6), var(--dy)) rotate(calc(var(--r) * .5)); opacity: 1; }
  100% { transform: translate(var(--dx), calc(var(--dy) + 260px)) rotate(var(--r)); opacity: 0; }
}
@media (max-width: 640px) {
  .race-track { --lane-num: 1.6rem; --runner: 2.3rem; padding: .6rem .6rem 1rem; }
  .runner-body { font-size: 1.25rem; }
  .runner-tag { max-width: 6.5rem; }
  .podium-step { width: 6.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  .runner { transition: none; }
  .runner-body, .confetti { animation: none !important; }
}
