*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
@supports (height: 100dvh) { html, body { height: 100dvh; } }

body {
  margin: 0;
  display: grid;
  grid-template-columns: var(--lateral-largeur) minmax(0, 1fr) var(--droite-largeur);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  background: var(--velours-0);
  color: var(--encre);
  font: var(--t-14)/1.5 var(--texte);
  -webkit-font-smoothing: antialiased;
}
body[data-gauche="ferme"] { grid-template-columns: 0 minmax(0, 1fr) var(--droite-largeur); }
body[data-droite="ferme"] { grid-template-columns: var(--lateral-largeur) minmax(0, 1fr) 0; }
body[data-gauche="ferme"][data-droite="ferme"] { grid-template-columns: 0 minmax(0, 1fr) 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-12); }

.visuellement-cache {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* ---------- Le velours, de part et d'autre ---------- */

.lateral {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 55% at 50% 0%, rgba(31, 84, 158, 0.5), transparent 70%),
    linear-gradient(180deg, var(--velours-1), var(--velours-0));
  color: var(--sur-velours);
}
body[data-gauche="ferme"] .lateral-gauche,
body[data-droite="ferme"] .lateral-droite { display: none; }

.lateral-tete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.9rem 0.9rem 0.7rem;
  border-bottom: 1px solid rgba(220, 180, 92, 0.2);
}
.marque { display: inline-flex; align-items: center; gap: 0.5rem; min-width: 0; }
.marque-blason { width: 1.75rem; height: 1.75rem; }
.marque-mot {
  font: 900 var(--t-16)/1 var(--titre);
  letter-spacing: 0.02em;
  background: linear-gradient(120deg, var(--or-0), var(--or-1) 35%, var(--or-2) 65%, var(--or-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.marque-projet {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--or-1);
  font: 700 var(--t-16)/1.2 var(--titre);
}

.lateral-corps { flex: 1; min-height: 0; overflow-y: auto; padding: 0.4rem 0.6rem 0.7rem; }
.lateral-pied { flex: none; padding: 0.5rem 0.6rem max(0.6rem, env(safe-area-inset-bottom)); border-top: 1px solid rgba(220, 180, 92, 0.2); }

.section-titre {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0;
  padding: 0.9rem 0.45rem 0.35rem;
  color: var(--or-2);
  font: 700 var(--t-11)/1 var(--titre);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.rangees { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.2rem; }
.rangees > li, .discussions > li, .taches-vives > li { min-width: 0; }

.rangee {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.45rem 0.5rem;
  border: 0;
  border-radius: var(--r-12);
  background: none;
  color: var(--sur-velours);
  font: 500 var(--t-13)/1.2 var(--texte);
  text-align: left;
  cursor: pointer;
  transition: background 0.2s var(--doux);
}
.rangee:hover { background: rgba(243, 246, 255, 0.09); }

.pastille {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: var(--r-8);
  background: rgba(243, 246, 255, 0.1);
  box-shadow: inset 0 0 0 1px rgba(220, 180, 92, 0.25);
  color: var(--or-1);
  font-size: 0.9rem;
}
.pastille-turquoise { color: var(--azur); }
.pastille-violet { color: #b9c9ff; }
.pastille-corail { color: var(--or-0); }

.rangee-texte { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rangee-marque { color: var(--sur-velours-3); font: 700 var(--t-11) var(--titre); font-variant-numeric: tabular-nums; }
.rangee-vide { padding: 0.5rem; color: var(--sur-velours-3); font-size: var(--t-12); }

/* ---------- Projets et discussions ---------- */

.projet-groupe { margin-bottom: 0.35rem; }
.projet-entete {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.5rem;
  border: 0;
  border-radius: var(--r-12);
  background: none;
  color: var(--sur-velours);
  font: 700 var(--t-14)/1.2 var(--titre);
  text-align: left;
  cursor: pointer;
  transition: background 0.2s var(--doux);
}
.projet-entete:hover { background: rgba(243, 246, 255, 0.09); }
.projet-groupe[data-actif="true"] .projet-entete {
  background: linear-gradient(180deg, var(--or-1), var(--or-3));
  color: #2a1a04;
  box-shadow: var(--relief), 0 2px 0 rgba(0, 0, 0, 0.3);
}
.projet-groupe[data-actif="true"] .pastille {
  background: rgba(42, 26, 4, 0.14);
  box-shadow: none;
  color: #2a1a04;
}
.projet-groupe[data-actif="true"] .rangee-marque { color: rgba(42, 26, 4, 0.66); }

.discussions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.1rem;
  margin: 0.25rem 0 0 0.85rem;
  padding: 0 0 0 0.6rem;
  list-style: none;
  border-left: 1px solid rgba(220, 180, 92, 0.25);
}
.discussion {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 0;
  border-radius: var(--r-8);
  background: none;
  color: var(--sur-velours-2);
  font: var(--t-13)/1.3 var(--texte);
  text-align: left;
  cursor: pointer;
}
.discussion:hover { background: rgba(243, 246, 255, 0.08); color: var(--sur-velours); }
.discussion[aria-current="true"] { background: rgba(220, 180, 92, 0.16); color: var(--or-0); font-weight: 700; }
.discussion .point { flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--or-2); }
.discussion .icone { color: var(--or-2); font-size: 0.9rem; }
.discussion-titre { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Tâches et notes, à droite ---------- */

.taches-vives { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.25rem; margin: 0; padding: 0; list-style: none; }
.tache-vive {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 0.35rem 0.4rem;
  border-radius: var(--r-12);
  background: rgba(243, 246, 255, 0.05);
}
.tache-vive:hover { background: rgba(243, 246, 255, 0.1); }
.tache-vive .coche {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.5rem; height: 1.5rem;
  margin-top: 1px;
  border: 0;
  border-radius: var(--r-8);
  background: rgba(243, 246, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(220, 180, 92, 0.25);
  color: var(--sur-velours-3);
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.2s var(--rebond);
}
.tache-vive .coche:hover { transform: scale(1.1); }
.tache-vive[data-etat="cours"] .coche { background: rgba(220, 180, 92, 0.22); color: var(--or-1); }
.tache-vive[data-etat="cours"] .coche .icone { animation: tourne 1.6s linear infinite; }
.tache-vive[data-etat="fait"] .coche { background: rgba(78, 199, 119, 0.2); box-shadow: none; color: var(--vert); }
.tache-vive[data-etat="echec"] .coche { background: rgba(255, 107, 107, 0.2); box-shadow: none; color: var(--rouge); }
@keyframes tourne { to { rotate: 1turn; } }
.tache-vive input {
  flex: 1;
  min-width: 0;
  padding: 0.2rem 0.1rem;
  border: 0;
  background: none;
  color: var(--sur-velours);
  font: var(--t-13)/1.4 var(--texte);
}
.tache-vive input:focus { outline: none; border-bottom: 1px solid var(--or-2); }
.tache-vive[data-etat="fait"] input { color: var(--sur-velours-2); text-decoration: line-through; }
.tache-vive .retirer { opacity: 0; }
.tache-vive:hover .retirer, .tache-vive .retirer:focus-visible { opacity: 1; }

.notes-vives {
  width: 100%;
  min-height: 9rem;
  margin-top: 0.3rem;
  padding: 0.6rem 0.7rem;
  border: 0;
  border-radius: var(--r-16);
  background: rgba(243, 246, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(220, 180, 92, 0.18);
  color: var(--sur-velours);
  font: var(--t-13)/1.5 var(--texte);
  resize: vertical;
}
.notes-vives::placeholder { color: var(--sur-velours-3); }
.notes-vives:focus { outline: none; box-shadow: inset 0 0 0 1px var(--or-2); }
.lateral .note { color: var(--sur-velours-3); }

/* ---------- La scène ---------- */

.principal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  margin: 0.6rem;
  border-radius: var(--r-28);
  background: var(--fond);
  box-shadow: var(--ombre-scene), inset 0 0 0 1px rgba(220, 180, 92, 0.35);
  overflow: hidden;
}

.outils {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  padding-top: max(0.7rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--trait);
}
.outils-titre { display: grid; min-width: 0; margin-right: auto; }
.outils-titre strong { font: 700 var(--t-16)/1.2 var(--titre); }
.outils-titre span {
  color: var(--encre-3);
  font: var(--t-11) var(--code);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.fil-discussion { overflow-y: auto; padding: 1rem clamp(1rem, 4vw, 2.2rem) 0.5rem; }
.fil-discussion > * { max-width: 44rem; margin-inline: auto; }

.accueil { padding: 9vh 0 0; text-align: center; }
.accueil .blason { width: 5.5rem; height: 5.5rem; filter: drop-shadow(0 10px 24px rgba(5, 13, 42, 0.28)); }
.accueil-question { margin: 1rem 0 0.4rem; font: 700 var(--t-28)/1.1 var(--titre); }
.accueil-aide { margin: 0 auto; max-width: 26rem; color: var(--encre-2); font-size: var(--t-14); }
.accueil-aide strong { color: var(--encre); }

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0.05em 0.35em;
  border-radius: var(--r-8);
  background: var(--papier-creux);
  box-shadow: inset 0 0 0 1px var(--trait);
  font: 700 var(--t-11) var(--titre);
  text-align: center;
}

.pupitre { padding: 0.3rem clamp(1rem, 4vw, 2.2rem) 0.9rem; padding-bottom: max(0.9rem, env(safe-area-inset-bottom)); }
.pupitre > * { max-width: 44rem; margin-inline: auto; }

.voile { display: none; }

@media (max-width: 860px) {
  .outils { flex-wrap: wrap; row-gap: 0.45rem; }
  .outils-titre { flex: 1 1 55%; order: -1; }
  .outils > .bouton-icone { order: -1; }
  .choix { flex: 1 1 30%; min-width: 0; }
  .choix select { width: 100%; }
}

@media (max-width: 1100px) {
  body, body[data-gauche="ferme"], body[data-droite="ferme"], body[data-gauche="ferme"][data-droite="ferme"] {
    grid-template-columns: minmax(0, 1fr);
  }
  .principal { margin: 0; border-radius: 0; grid-column: 1; box-shadow: none; }
  .lateral {
    position: fixed;
    top: 0; bottom: 0;
    z-index: 20;
    width: min(19rem, 86vw);
    padding-top: env(safe-area-inset-top);
    box-shadow: var(--ombre-scene);
    transition: transform 0.35s var(--rebond);
    display: flex;
  }
  body[data-gauche="ferme"] .lateral-gauche,
  body[data-droite="ferme"] .lateral-droite { display: flex; }
  .lateral-gauche { left: 0; border-radius: 0 var(--r-28) var(--r-28) 0; transform: translateX(-102%); }
  .lateral-droite { right: 0; border-radius: var(--r-28) 0 0 var(--r-28); transform: translateX(102%); }
  body[data-gauche="ouvert"] .lateral-gauche { transform: none; }
  body[data-droite="ouvert"] .lateral-droite { transform: none; }
  body[data-gauche="ouvert"] .voile, body[data-droite="ouvert"] .voile {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(5, 13, 42, 0.55);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
