:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #64748b;
  --line: #e2e8f0;
  --paper: #f4f7fb;
  --white: #ffffff;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #15803d;
  --green-soft: #dcfce7;
  --amber: #a16207;
  --amber-soft: #fef3c7;
  --orange: #c2410c;
  --orange-soft: #ffedd5;
  --violet: #7e22ce;
  --violet-soft: #f3e8ff;
  --shadow: 0 12px 32px rgba(15, 23, 42, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; }
body { margin: 0; min-height: 100vh; background: var(--paper); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 2.4vw, 36px);
  color: #fff;
  background: #111827;
  box-shadow: 0 4px 18px rgba(15, 23, 42, .18);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { display: block; height: clamp(32px, 3vw, 42px); width: auto; flex: 0 0 auto; object-fit: contain; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .35)); }
.brand h1 { margin: 0; font-size: clamp(17px, 1.65vw, 23px); line-height: 1.1; }
.brand p { margin: 4px 0 0; color: #cbd5e1; font-size: 12px; }
.header-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.connection-status { display: inline-flex; align-items: center; gap: 7px; color: #cbd5e1; font-size: 12px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; }
.status-dot.online { background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .15); }
.status-dot.offline { background: #fb7185; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.2;
  transition: transform .12s ease, background .12s ease, box-shadow .12s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { color: #fff; background: var(--blue); box-shadow: 0 4px 10px rgba(37, 99, 235, .18); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-dark { color: #fff; background: #334155; }
.btn-dark:hover { background: #475569; }
.btn-light { color: #1e293b; border-color: #cbd5e1; background: #fff; }
.btn-light:hover { background: #f8fafc; }
.btn-soft { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }
.btn-danger { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.btn-small { min-height: 32px; padding: 6px 10px; border-radius: 9px; font-size: 11px; }
.btn-block { width: 100%; }

.page-shell { width: min(1780px, 100%); margin: 0 auto; padding: 20px clamp(14px, 2vw, 30px) 38px; }
.firebase-warning, .notice {
  margin: 14px 0;
  padding: 12px 15px;
  border: 1px solid #fed7aa;
  border-radius: 12px;
  color: #9a3412;
  background: #fff7ed;
  font-size: 13px;
  line-height: 1.5;
}
.notice-blue { border-color: #bfdbfe; color: #1e40af; background: #eff6ff; }
.notice-green { border-color: #bbf7d0; color: #166534; background: #f0fdf4; }

/* Couleurs des îlots (palette de 8, appliquée aux cartes et pastilles) */
.team-color-1 { --team-color: #2563eb; --team-soft: #dbeafe; }
.team-color-2 { --team-color: #16a34a; --team-soft: #dcfce7; }
.team-color-3 { --team-color: #ea580c; --team-soft: #ffedd5; }
.team-color-4 { --team-color: #7c3aed; --team-soft: #ede9fe; }
.team-color-5 { --team-color: #db2777; --team-soft: #fce7f3; }
.team-color-6 { --team-color: #0891b2; --team-soft: #cffafe; }
.team-color-7 { --team-color: #4f46e5; --team-soft: #e0e7ff; }
.team-color-8 { --team-color: #ca8a04; --team-soft: #fef9c3; }

/* Miniatures de diapositives dans les cartes et post-its */
.task-thumb-wrap { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: #eef2f7; border-bottom: 1px solid #edf2f7; }
.task-thumb { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb-fallback { display: none; height: 100%; place-items: center; color: #94a3b8; font-size: 13px; font-weight: 850; }
.task-thumb-wrap.thumb-error .task-thumb { display: none; }
.task-thumb-wrap.thumb-error .thumb-fallback { display: grid; }
/* Cadre coloré complet côté prof : chaque îlot est immédiatement repérable */
#classBoard .task-card { border: 3px solid var(--team-color, #cbd5e1); }
#classBoard .task-card.bonus { border-color: var(--team-color, #d8b4fe); background: #faf5ff; }
.task-card .team-chip { display: inline-block; margin: 0 6px 0 0; padding: 3px 6px; border-radius: 6px; color: var(--team-color, #475569); background: var(--team-soft, #f1f5f9); font-size: 9px; font-weight: 900; letter-spacing: .05em; vertical-align: middle; }
.task-card[draggable="true"] { cursor: grab; }
.task-card.dragging { opacity: .45; }
.task-card.is-locked { cursor: not-allowed; }
.task-done-flag { color: #15803d; font-size: 14px; font-weight: 900; }
.help-ticket[draggable="true"] { cursor: grab; }
.help-ticket.dragging { opacity: .45; }
.kanban-column.drop-target { outline: 2px dashed #3b82f6; outline-offset: -4px; background: #eff6ff; }

/* Effet pile de post-its : colonne gauche (1re au 1er plan) et droite (dernière au 1er plan) */
#classBoard .task-list, #kanbanBoard .task-list { isolation: isolate; }
.stack-card { position: relative; }
.kanban-column[data-column="backlog"] .stack-card { z-index: calc(400 - var(--i, 0)); }
.kanban-column[data-column="done"] .stack-card { z-index: calc(40 + var(--i, 0)); }
.stack-card.tilt-a { transform: translateX(-4px) rotate(-1.3deg); }
.stack-card.tilt-b { transform: translateX(4px) rotate(1.3deg); }
.stack-card:hover { z-index: 999 !important; transform: translateX(0) rotate(0deg) scale(1.02); box-shadow: 0 10px 24px rgba(15, 23, 42, .18); }

/* Cartes compactes au format post-it (prof) */
.task-card.mini { display: flex; align-items: stretch; }
.task-card.mini .task-thumb-wrap { flex: 0 0 auto; width: 118px; border-bottom: none; border-right: 1px solid #edf2f7; }
.task-card.mini .task-card-main { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; justify-content: space-between; gap: 5px; padding: 8px 10px; }
.task-card.mini .task-card-title { font-size: 12.5px; }
.task-card.mini .mini-head { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.task-card.mini .task-card-actions { border-top: none; background: transparent; padding: 0; }
.task-card.mini .mini-actions { display: flex; align-items: center; gap: 7px; }
.task-card.mini .task-open { font-size: 13px; font-weight: 900; }
.task-card.mini .advance-button { font-size: 10px; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin: 8px 0 14px; }
.section-heading h2 { margin: 0; font-size: clamp(19px, 2vw, 27px); letter-spacing: -.025em; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

/* Éléments îlots partagés (bande compacte prof, badges, codes) */
.team-badge { flex: 0 0 auto; padding: 4px 7px; border-radius: 999px; color: #64748b; background: #f1f5f9; font-size: 9px; font-weight: 850; letter-spacing: .04em; text-transform: uppercase; }
.team-badge.active { color: #166534; background: #dcfce7; }
.team-code { display: inline-flex; align-items: center; gap: 7px; margin: 0; padding: 5px 9px; border: 1px dashed #86efac; border-radius: 8px; color: #166534; background: #f0fdf4; font-size: 13px; font-weight: 900; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.team-code:hover { background: #dcfce7; }

/* Fenêtre « Codes des îlots » */
.codes-list { display: grid; gap: 8px; max-height: min(56vh, 520px); overflow-y: auto; }
.codes-item { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-left: 5px solid var(--team-color, #cbd5e1); border-radius: 11px; background: #fff; }
.codes-item.is-behind { border-color: #fdba74; }
.codes-title { font-size: 14px; font-weight: 900; color: var(--team-color, var(--ink)); }
.codes-progress { flex: 1 1 auto; color: var(--muted); font-size: 11px; font-weight: 750; }
.codes-item .team-code { margin: 0; }
@keyframes helpPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(234, 88, 12, .45); } 50% { box-shadow: 0 0 0 9px rgba(234, 88, 12, 0); } }
.help-ticket { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px; border: 2px solid #cbd5e1; border-left-width: 6px; border-radius: 10px; background: #fff; box-shadow: 0 2px 5px rgba(15, 23, 42, .04); }
.help-ticket strong { display: block; font-size: 14px; }
.help-ticket small { display: block; margin-top: 2px; color: #475569; font-size: 10.5px; font-weight: 750; }
.help-ticket.maturity-fresh { border-color: #16a34a; background: #bbf7d0; }
.help-ticket.maturity-middle { border-color: #eab308; background: #fef08a; }
.help-ticket.maturity-ripe { border-color: #ea580c; background: #fed7aa; }
.help-ticket.waiting { animation: helpPulse 1.8s ease-out infinite; }
.help-ticket.helping { border-color: #2563eb; background: #dbeafe; }
.help-ticket.done { border-color: #94a3b8; background: #f1f5f9; opacity: .82; }
.help-ticket button { flex: 0 0 auto; }
.help-ticket-body { min-width: 0; flex: 1 1 auto; }
.help-ticket .task-thumb-wrap { flex: 0 0 auto; width: 104px; border: 1px solid #cbd5e1; border-radius: 8px; border-bottom-width: 1px; }
.help-ticket .thumb-fallback { font-size: 10px; }

/* Bandeau d'alerte des demandes d'aide (prof) */
.help-alert { margin: 0 0 13px; padding: 12px 15px; border: 2px solid #fb923c; border-radius: 13px; color: #9a3412; background: #ffedd5; font-size: 13.5px; line-height: 1.45; animation: helpPulse 2s ease-out infinite; }

.dialog {
  width: min(560px, calc(100vw - 28px));
  max-height: min(88vh, 800px);
  padding: 0;
  border: 0;
  border-radius: 19px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 25px 80px rgba(15, 23, 42, .3);
}
.dialog::backdrop { background: rgba(15, 23, 42, .58); backdrop-filter: blur(3px); }
.dialog-content { padding: 23px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.dialog-header h2 { margin: 0; font-size: 21px; }
.dialog-header p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.close-button { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 9px; color: #475569; background: #f1f5f9; font-size: 20px; }
.form-grid { display: grid; gap: 13px; }
.field label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 800; }
.field input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 10px; outline: none; color: var(--ink); background: #fff; }
.field input:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(59, 130, 246, .14); }
.field textarea { width: 100%; min-height: 96px; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 10px; outline: none; color: var(--ink); background: #fff; font: inherit; font-size: 12.5px; line-height: 1.5; resize: vertical; }
.field textarea:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(59, 130, 246, .14); }
.parse-button { margin-top: 8px; }
.field-help { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.form-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.form-error { display: none; padding: 9px 11px; border-radius: 9px; color: #991b1b; background: #fef2f2; font-size: 12px; }
.form-error.visible { display: block; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 17px; }
.code-dialog { width: min(420px, calc(100vw - 28px)); text-align: center; }
.generated-code { margin: 16px 0; color: #166534; font-size: clamp(48px, 12vw, 76px); font-weight: 950; letter-spacing: .18em; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(430px, calc(100vw - 36px));
  padding: 12px 15px;
  border-radius: 12px;
  color: #fff;
  background: #1e293b;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .16s ease, transform .16s ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: #991b1b; }
.toast.success { background: #166534; }

/* Interface élève */
.student-header { justify-content: center; text-align: center; }
.student-header .brand { justify-content: center; }
.student-shell { width: min(1380px, 100%); margin: 0 auto; padding: 28px clamp(14px, 3vw, 42px) 44px; }
.join-card { width: min(460px, 100%); margin: 7vh auto 0; padding: clamp(22px, 4vw, 34px); border: 1px solid var(--line); border-radius: 22px; background: #fff; box-shadow: var(--shadow); text-align: center; }
.join-icon { display: grid; place-items: center; width: 58px; height: 58px; margin: 0 auto 15px; border-radius: 18px; color: #1d4ed8; background: #dbeafe; font-size: 26px; }
.join-card h2 { margin: 0; font-size: 25px; }
.join-card p { margin: 8px 0 21px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.code-input { width: 100%; min-height: 62px; border: 2px solid #cbd5e1; border-radius: 13px; outline: none; text-align: center; font-size: 30px; font-weight: 900; letter-spacing: .35em; font-variant-numeric: tabular-nums; }
.code-input:focus { border-color: #3b82f6; box-shadow: 0 0 0 4px rgba(59, 130, 246, .12); }
.join-error { min-height: 18px; margin: 8px 0 12px; color: #b91c1c; font-size: 12px; }
.student-topline { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin: 0 0 16px; }
.student-topline h2 { margin: 0; font-size: clamp(22px, 3vw, 31px); }
.student-topline p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.student-summary { display: flex; flex-wrap: wrap; gap: 8px; }
.student-stat { padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 12px; }
.student-stat strong { font-size: 14px; }
.rhythm-banner { display: none; margin: 13px 0; padding: 13px 15px; border: 1px solid #fed7aa; border-radius: 13px; color: #9a3412; background: #fff7ed; font-size: 13px; line-height: 1.45; }
.rhythm-banner.visible { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.kanban-board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; align-items: start; margin-top: 18px; }
.kanban-column { min-height: 340px; max-height: calc(100vh - 262px); display: flex; flex-direction: column; padding: 13px; border: 1px solid var(--line); border-radius: 16px; background: #e9eef6; }
.kanban-column-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 12px; }
.kanban-column-header h3 { margin: 0; font-size: 13px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; }
.kanban-column-header span { min-width: 25px; padding: 4px 7px; border-radius: 999px; color: #475569; background: #fff; font-size: 11px; text-align: center; }
.task-list { display: grid; align-content: start; gap: 9px; }
#classBoard .task-list { flex: 1 1 auto; min-height: 150px; overflow-y: auto; padding-right: 2px; }
#classBoard .task-list::-webkit-scrollbar { width: 6px; }
#classBoard .task-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }
.task-card { overflow: hidden; border: 1px solid #cbd5e1; border-radius: 12px; background: #fff; box-shadow: 0 2px 5px rgba(15, 23, 42, .035); }
.task-card.bonus { border-color: #d8b4fe; background: #faf5ff; }
.task-card-main { display: flex; align-items: center; justify-content: space-between; gap: 9px; padding: 11px 12px; }
.task-card-title { font-size: 14px; font-weight: 850; }
.task-card-tag { display: inline-block; margin-left: 5px; padding: 3px 6px; border-radius: 6px; color: #7e22ce; background: #f3e8ff; font-size: 9px; font-weight: 900; letter-spacing: .04em; }
.task-open { color: #1d4ed8; text-decoration: none; font-size: 11px; font-weight: 800; white-space: nowrap; }
.task-open:hover { text-decoration: underline; }
.task-card-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-top: 1px solid #edf2f7; background: rgba(248, 250, 252, .75); }
.task-card-actions small { color: var(--muted); font-size: 10px; }
.advance-button { padding: 6px 9px; border: 0; border-radius: 8px; color: #fff; background: #2563eb; font-size: 10px; font-weight: 850; }
.advance-button:hover { background: #1d4ed8; }
.task-card.bonus .advance-button { background: #7e22ce; }
.empty-column { padding: 20px 10px; border: 1px dashed #cbd5e1; border-radius: 11px; color: #64748b; background: rgba(255,255,255,.55); font-size: 12px; text-align: center; }
.student-help { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-top: 20px; padding: 15px 17px; border: 2px solid #bfdbfe; border-radius: 15px; background: #eff6ff; transition: background .15s ease, border-color .15s ease; }
.student-help.is-waiting { border-color: #f59e0b; background: #fef9c3; }
.student-help.is-helping { border-color: #2563eb; background: #dbeafe; }
.student-help h3 { margin: 0; font-size: 15px; }
.student-help p { margin: 4px 0 0; color: #475569; font-size: 12px; line-height: 1.4; }
.student-help.is-waiting .help-state { color: #9a3412; }
.help-state { margin: 8px 0 0; color: #1d4ed8; font-size: 12px; font-weight: 800; }
.btn-help-call { color: #7c2d12; background: #fb923c; box-shadow: 0 4px 12px rgba(251, 146, 60, .4); min-height: 48px; padding: 10px 20px; font-size: 14.5px; animation: helpPulse 1.8s ease-out infinite; }
.btn-help-call:hover { background: #f97316; }
.student-footer { margin-top: 25px; color: #94a3b8; font-size: 11px; text-align: center; }
.hidden { display: none !important; }

/* Vue détachée Document Picture-in-Picture */
.pip-shell { min-height: 100vh; padding: 12px; background: #f4f7fb; }
.pip-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 10px; }
.pip-heading h1 { margin: 0; font-size: 18px; }
.pip-heading p { margin: 3px 0 0; color: #64748b; font-size: 10px; }
.pip-teams { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.pip-team { padding: 8px; border: 1px solid #e2e8f0; border-radius: 10px; background: white; }
.pip-team h2 { margin: 0 0 5px; font-size: 12px; }
.pip-team p { margin: 3px 0; color: #64748b; font-size: 9px; }
.pip-meter { height: 4px; margin-top: 6px; overflow: hidden; border-radius: 10px; background: #e2e8f0; }
.pip-meter span { display: block; height: 100%; background: #2563eb; }
.pip-help { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: 9px; }
.pip-help-col { min-width: 0; padding: 8px; border-radius: 9px; background: #e9eef6; }
.pip-help-col h3 { margin: 0 0 6px; font-size: 10px; text-transform: uppercase; }
.pip-help-ticket { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-top: 5px; padding: 6px; border: 1px solid #cbd5e1; border-radius: 7px; background: white; font-size: 10px; }
.pip-help-ticket button { padding: 5px 6px; border: 0; border-radius: 6px; color: white; background: #2563eb; font-size: 9px; font-weight: 800; }
.pip-help-ticket.maturity-fresh { border-color: #16a34a; background: #bbf7d0; }
.pip-help-ticket.maturity-middle { border-color: #eab308; background: #fef08a; }
.pip-help-ticket.maturity-ripe { border-color: #ea580c; background: #fed7aa; }
.pip-help-ticket.helping { border-color: #2563eb; background: #dbeafe; }
.pip-help-ticket.done { background: #f1f5f9; }

@media (max-width: 1120px) {
  #classBoard .kanban-column { max-height: calc(100vh - 240px); }
}
@media (max-width: 760px) {
  .app-header { position: static; align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: flex-start; width: 100%; }
  .kanban-board { grid-template-columns: 1fr; }
  .kanban-column { min-height: 150px; }
  #classBoard .kanban-column { max-height: 480px; }
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .section-heading { align-items: flex-start; flex-direction: column; }
  .student-shell { padding-top: 18px; }
}
