:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #16a34a;
  --bg: #f5f5f9;
  --card-bg: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --soft: #f0f0f7;
  --shadow: 0 14px 35px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(79, 70, 229, 0.13), transparent 32rem),
    var(--bg);
  color: var(--text);
}
button, input, textarea, select { font: inherit; }
button, .btn, .option-btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 12px calc(60px + env(safe-area-inset-bottom));
}

h1 { font-size: clamp(1.35rem, 4.8vw, 1.9rem); margin: 0.2em 0; line-height: 1.1; }
h2 { font-size: 1.08rem; margin: 0 0 12px; }
h3 { margin: 0 0 4px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.session-heading { display: flex; align-items: center; gap: 12px; min-width: 0; }

.card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.centered-card { max-width: 380px; margin: 80px auto; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  margin: 10px 0 5px;
  color: var(--muted);
}
input, textarea, select {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 11px;
  font-size: 1rem;
  font-family: inherit;
  background: white;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12); }

.form-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
.inline-form { display: flex; flex-direction: column; gap: 8px; }
.inline-form input { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: none;
  border-radius: 11px;
  padding: 11px 18px;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  color: white;
  margin-top: 10px;
  min-height: 42px;
}
.btn:disabled { opacity: 0.68; cursor: wait; }
.btn-sm { padding: 8px 12px; font-size: 0.86rem; margin-top: 0; min-height: 36px; }
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #6b7280; }
.btn-danger { background: var(--danger); }
.btn-warning { background: var(--warning); }
.btn-linklike { background: none; border: none; color: var(--primary); font-size: 0.9rem; cursor: pointer; padding: 0; margin: 6px 0; text-decoration: underline; min-height: auto; }

.muted { color: var(--muted); font-size: 0.9rem; }
.link-muted { color: var(--primary); text-decoration: none; font-size: 0.92rem; font-weight: 700; }

.link-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--soft);
  padding: 10px 11px;
  border-radius: 10px;
  margin: 8px 0;
  word-break: break-all;
  font-size: 0.9rem;
}

.flash-container { max-width: 760px; margin: 12px auto 0; padding: 0 16px; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; font-size: 0.9rem; }
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-success { background: #dcfce7; color: #166534; }

.list { display: flex; flex-direction: column; gap: 6px; }
.session-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.row-actions > * { flex: 1 1 auto; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }

.hidden { display: none !important; }

/* Icône atelier */
.session-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: white;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
  flex: 0 0 auto;
}
.session-icon-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-weight: 900;
  background: #eef2ff;
}
.admin-session-icon { width: 54px; height: 54px; }
.big-session-icon { width: 82px; height: 82px; border-radius: 22px; }

/* Loaders */
.loader {
  width: 38px;
  height: 38px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}
.small-loader { width: 26px; height: 26px; border-width: 3px; }
.mini-loader {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
.mini-loader-light { border-color: rgba(255,255,255,0.45); border-top-color: #fff; }
.inline-loader { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Étudiant mobile-first --- */
.student-page {
  width: min(100%, 520px);
  margin: 0 auto;
  min-height: calc(100vh - 32px);
}
.student-hero {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 10px;
}
.eyebrow {
  margin: 0 0 2px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  font-weight: 900;
  font-size: 0.76rem;
}
.atelier-title { margin: 0; }
.name-card { text-align: left; padding: 13px; }
.name-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.name-form .btn { width: 100%; }

.connection-status, .socket-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 0.86rem;
  font-weight: 800;
  background: #f3f4f6;
  color: var(--muted);
}
.connection-status .dot, .socket-banner .dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #9ca3af;
  box-shadow: 0 0 0 4px rgba(156, 163, 175, 0.18);
}
.connection-status.connected, .socket-banner.connected { background: #dcfce7; color: #166534; }
.connection-status.connected .dot, .socket-banner.connected .dot { background: var(--success); box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.16); }
.connection-status.error, .socket-banner.error { background: #fee2e2; color: #991b1b; }
.connection-status.error .dot, .socket-banner.error .dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.15); }
.connection-status.connecting .dot, .socket-banner.connecting .dot { animation: pulse 0.9s infinite alternate; }
@keyframes pulse { from { opacity: 0.4; } to { opacity: 1; } }

.quiz-app {
  min-height: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 18px;
}
.waiting-icon { font-size: 2.4rem; }

.timer-zone { width: 100%; margin-bottom: 12px; }
.timer-bar-wrap { width: 100%; height: 11px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.timer-bar { height: 100%; background: var(--primary); transition: width 0.16s linear; }
.timer-bar.timer-ending { background: var(--danger); }
.timer-text {
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  color: var(--primary);
  font-size: 1.55rem;
  text-align: center;
}
.timer-text.timer-ending { color: var(--danger); }
.question-meta { display: flex; flex-wrap: wrap; gap: 7px; width: 100%; justify-content: flex-start; }
.question-text {
  font-size: clamp(1.18rem, 5vw, 1.55rem);
  font-weight: 900;
  line-height: 1.22;
  margin: 8px 0 8px;
  text-align: left;
  align-self: stretch;
}
.answer-options { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 15px 14px;
  background: white;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 750;
  line-height: 1.25;
  text-align: left;
  width: 100%;
  min-height: 58px;
  color: var(--text);
}
.choice-marker {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid var(--border);
  flex: 0 0 auto;
  background: white;
}
.option-btn.selected {
  border-color: var(--primary);
  background: #eef2ff;
  transform: translateY(-1px);
}
.option-btn.selected .choice-marker {
  border-color: var(--primary);
  background: radial-gradient(circle, var(--primary) 0 45%, white 48%);
}
.option-btn:disabled { opacity: 0.68; cursor: default; transform: none; }
.submit-answer-btn { width: 100%; margin-top: 8px; min-height: 52px; font-size: 1rem; }
.result-badge { font-size: 1.35rem; font-weight: 900; }
.result-badge.correct { color: var(--success); }
.result-badge.wrong { color: var(--danger); }

/* --- Admin atelier avec onglets --- */
.share-card { display: flex; align-items: stretch; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.share-card > div { flex: 1; min-width: min(260px, 100%); }
.share-actions { display: flex; align-items: center; justify-content: flex-start; gap: 8px; flex-wrap: wrap; }
.share-actions .btn { flex: 1 1 140px; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 6px;
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: var(--shadow);
}
.tab-btn {
  border: none;
  border-radius: 11px;
  padding: 11px 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
  font-size: 0.88rem;
}
.tab-btn:hover { background: #f3f4f6; color: var(--text); }
.tab-btn.active { background: var(--primary); color: #fff; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.stats-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 15px; padding: 16px; box-shadow: var(--shadow); }
.stat-label { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 800; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card strong { display: block; font-size: 2.05rem; line-height: 1; color: var(--primary); }
.stat-card small { color: var(--muted); }

.live-active .qtext { font-size: 1rem; }
.live-active-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pill { display: inline-flex; align-items: center; border-radius: 999px; background: var(--soft); color: var(--muted); font-size: 0.82rem; font-weight: 800; padding: 6px 10px; }
.admin-timer { color: var(--primary); font-weight: 900; font-variant-numeric: tabular-nums; }
.admin-timer.timer-ending { color: var(--danger); }

.profile-form { display: flex; flex-direction: column; gap: 14px; }
.profile-icon-preview { display: flex; align-items: center; justify-content: center; }
.profile-fields { flex: 1; }

.qlist { display: flex; flex-direction: column; gap: 10px; }
.qitem { border: 1px solid var(--border); border-radius: 14px; padding: 13px; background: white; }
.qitem.status-active { border-color: var(--primary); background: #eef2ff; }
.qitem-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.qtitle-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-number { font-weight: 900; color: var(--text); }
.qtext { font-weight: 750; margin: 8px 0; line-height: 1.35; }
.badge { font-size: 0.73rem; font-weight: 900; padding: 4px 9px; border-radius: 999px; color: white; }
.badge-pending { background: #9ca3af; }
.badge-active { background: var(--success); }
.badge-closed { background: #6b7280; }
.choices-preview { margin: 7px 0; padding-left: 18px; font-size: 0.92rem; color: var(--muted); }
.choices-preview .correct { color: var(--success); font-weight: 800; }

.choice-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.choice-row input[type="text"] { flex: 1; }
.choice-row input[type="checkbox"] { width: 22px; height: 22px; flex: 0 0 auto; }

.q-actions { align-items: center; }
.timer-action-form { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; width: 100%; }
.timer-action-form input { flex: 1; min-width: 120px; padding: 8px 9px; font-size: 0.88rem; }
.timer-panel-form { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.compact-inline-form { align-items: stretch; }

.leaderboard { list-style: none; padding: 0; margin: 0; }
.leaderboard li { display: flex; justify-content: space-between; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.leaderboard li:last-child { border-bottom: none; }
.leaderboard .rank { font-weight: 900; color: var(--primary); margin-right: 8px; }

.table-wrap { width: 100%; overflow-x: auto; }
.participants-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.participants-table th, .participants-table td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.participants-table th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.participants-table code, .participant-card code { background: var(--soft); border-radius: 6px; padding: 3px 6px; }
.badge-soft { display: inline-block; margin-left: 6px; padding: 2px 7px; border-radius: 999px; background: #f3f4f6; color: var(--muted); font-size: 0.72rem; font-weight: 800; }

.participants-cards { display: flex; flex-direction: column; gap: 10px; }
.participant-card { border: 1px solid var(--border); background: white; border-radius: 14px; padding: 12px; }
.participant-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.participant-card-grid { display: grid; grid-template-columns: 1fr auto; gap: 7px 10px; font-size: 0.9rem; }
.participant-card-grid span { color: var(--muted); }
.desktop-table { display: none; }

/* --- QR code de partage --- */
.qr-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 18px; }
.qr-modal.hidden { display: none; }
.qr-modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(4px); }
.qr-modal-card { position: relative; width: min(440px, 100%); background: var(--card-bg); border: 1px solid var(--border); border-radius: 18px; padding: 18px; box-shadow: 0 24px 70px rgba(15, 23, 42, 0.25); }
.qr-modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.qr-close { width: 38px; height: 38px; border: none; border-radius: 999px; background: #f3f4f6; color: var(--text); font-size: 1.4rem; line-height: 1; cursor: pointer; }
.qr-preview { display: flex; justify-content: center; background: #f8fafc; border: 1px dashed var(--border); border-radius: 16px; padding: 18px; margin: 14px 0; }
.qr-preview img { width: min(280px, 100%); height: auto; image-rendering: crisp-edges; }
.qr-link-text { font-size: 0.85rem; text-align: center; }
.qr-actions { justify-content: center; }
body.modal-open { overflow: hidden; }

@media (min-width: 520px) {
  .container { padding: 20px 16px 60px; }
  .name-form { flex-direction: row; }
  .name-form .btn { width: auto; }
  .inline-form { flex-direction: row; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .profile-form { flex-direction: row; align-items: center; }
  .row-actions > * { flex: 0 1 auto; }
  .share-actions .btn { flex: 0 1 auto; }
}

@media (min-width: 820px) {
  .grid-2 { grid-template-columns: 1.3fr 1fr; }
  .questions-layout { grid-template-columns: 1.15fr 0.85fr; }
  .form-row { grid-template-columns: 1fr 1fr 1fr; }
  .desktop-table { display: block; }
  .participants-cards { display: none; }
  .timer-action-form { width: auto; }
  .timer-action-form input { width: 145px; flex: 0 0 auto; }
  .tabs { top: 10px; }
  .quiz-app { min-height: 390px; }
}

@media (max-width: 380px) {
  .tab-btn { font-size: 0.8rem; padding: 10px 4px; }
  .card { padding: 13px; border-radius: 14px; }
  .option-btn { padding: 14px 12px; }
}
