@font-face {
  font-family: "Caveat";
  src: url("../fonts/Caveat.ttf") format("truetype");
  font-weight: 400 700;
  font-display: block;
}

:root {
  --main: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --encre: #2b2a33;
  --encre-douce: #5a5560;
  --papier: #fbfaf5;
  --papier-ancien: #f3ead6;
  --ficelle: #c0262d;
  --pin-sachot: #d8323a;
  --pin-billy: #2f6fd1;
  --pin-famille: #f2b51d;
  --pin-autre: #3a9a5b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--main);
  color: var(--encre);
  background: #3b2616;
}

/* ---------- Cadre bois + liège ---------- */

#cadre {
  position: fixed;
  inset: 0;
  padding: 14px;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.08) 0 2px, transparent 2px 9px),
    linear-gradient(135deg, #8a5a32, #6b4223 45%, #8f6038 70%, #5e3a1e);
}

#viewport, .liege {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.35), inset 0 0 40px rgba(60,30,5,.55);
  background-color: #c4955f;
  /* liège : bruit fractal généré, aucune image externe */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' seed='7' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .38  0 0 0 0 .22  0 0 0 0 .08  0 0 0 1.6 -.55'/></filter><rect width='100%' height='100%' filter='url(%23n)'/><filter id='m'><feTurbulence type='fractalNoise' baseFrequency='.06' numOctaves='2' seed='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .95  0 0 0 0 .8  0 0 0 0 .55  0 0 0 .5 -.12'/></filter><rect width='100%' height='100%' filter='url(%23m)'/></svg>");
  background-size: 300px 300px;
}
#viewport.panning { cursor: grabbing; }

#world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#strings {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 100000;
}
#strings path {
  fill: none;
  stroke: var(--ficelle);
  stroke-width: 2.4;
  stroke-linecap: round;
  filter: drop-shadow(1px 3px 2px rgba(0,0,0,.35));
}
#strings path.faible { stroke-width: 1.6; opacity: .65; }
#strings circle { fill: #7d1218; }

/* ---------- Polaroid ---------- */

.polaroid {
  position: absolute;
  width: 170px;
  padding: 12px 12px 0;
  background: var(--papier);
  border-radius: 2px;
  box-shadow:
    0 1px 1px rgba(0,0,0,.18),
    2px 6px 10px rgba(30,15,0,.35);
  cursor: pointer;
  user-select: none;
  transition: transform .18s ease, box-shadow .18s ease, opacity .25s ease, filter .25s ease;
}
.polaroid.ancien {
  background: var(--papier-ancien);
  background-image: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.35), transparent 60%),
                    radial-gradient(ellipse at 80% 90%, rgba(150,110,50,.12), transparent 55%);
}
.polaroid:hover {
  transform: rotate(0deg) scale(1.06) !important;
  box-shadow: 0 2px 2px rgba(0,0,0,.18), 6px 16px 22px rgba(30,15,0,.4);
}
.polaroid.dragging {
  transition: none;
  transform: rotate(0deg) scale(1.1) !important;
  box-shadow: 0 2px 2px rgba(0,0,0,.18), 12px 26px 30px rgba(30,15,0,.45);
  cursor: grabbing;
}
.polaroid.posee { animation: pose .45s ease-out; }
@keyframes pose {
  0% { transform: rotate(calc(var(--r) - 4deg)) scale(1.08); }
  45% { transform: rotate(calc(var(--r) + 2deg)) scale(1); }
  100% { transform: rotate(var(--r)); }
}

.polaroid .photo {
  width: 146px;
  height: 146px;
  overflow: hidden;
  position: relative;
  background: #2d2620;
}
.polaroid .photo:not(.vide) {
  background-color: #2d2620;
  background-repeat: no-repeat;
  filter: sepia(.12) contrast(1.02);
}
.polaroid .photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Sans photo : initiales sur fond sépia */
.polaroid .photo.vide {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at center, transparent 35%, rgba(40,20,5,.55) 100%),
    linear-gradient(160deg, hsl(var(--h) 38% 62%), hsl(calc(var(--h) - 8) 42% 44%));
}
.polaroid .photo.vide span {
  font-size: 60px;
  font-weight: 600;
  color: rgba(255,245,225,.82);
  text-shadow: 0 2px 6px rgba(50,25,0,.45);
  letter-spacing: 1px;
}

.polaroid .legende {
  height: 58px;
  padding: 5px 2px 0;
  text-align: center;
  line-height: 1;
}
.polaroid .nom {
  font-size: 23px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.polaroid .nom.long { font-size: 19px; }
.polaroid .nom.tres-long { font-size: 16px; }
.polaroid .dates {
  margin-top: 4px;
  font-size: 17px;
  color: var(--encre-douce);
  white-space: nowrap;
}
.polaroid .dates.long { font-size: 14.5px; }

/* ---------- Punaises ---------- */

.punaise {
  position: absolute;
  top: -7px;
  left: 50%;
  width: 20px;
  height: 20px;
  margin-left: -10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 8%, var(--c) 30%, color-mix(in srgb, var(--c), #000 45%) 100%);
  box-shadow: 2px 4px 4px rgba(0,0,0,.4);
  z-index: 2;
}
.punaise.rouge,  .branche-SACHOT  > .punaise { --c: var(--pin-sachot); }
.punaise.bleue,  .branche-BILLY   > .punaise { --c: var(--pin-billy); }
.punaise.jaune,  .branche-FAMILLE > .punaise { --c: var(--pin-famille); }
.punaise.verte,  .branche-AUTRE   > .punaise { --c: var(--pin-autre); }

/* ---------- États : filtre et sélection ---------- */

.polaroid.estompe { opacity: .18; filter: grayscale(.8); }
#world.selection .polaroid:not(.choisi):not(.proche) { opacity: .35; filter: grayscale(.6); }
.polaroid.choisi {
  outline: 3px solid rgba(255,230,120,.9);
  outline-offset: 3px;
}
.polaroid.trouve { animation: trouve 1.2s ease-out 2; }
@keyframes trouve {
  0%, 100% { outline: 0 solid rgba(255,230,120,0); }
  50% { outline: 10px solid rgba(255,230,120,.85); }
}

/* ---------- Étiquettes de génération ---------- */

.etiquette {
  position: absolute;
  padding: 8px 22px 6px;
  background: #fffbe9;
  font-size: 34px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 2px 6px 10px rgba(30,15,0,.3);
  transform: translateX(-50%) rotate(var(--r));
  pointer-events: none;
}
.etiquette small {
  display: block;
  font-size: 20px;
  font-weight: 400;
  color: var(--encre-douce);
}
.etiquette::before, .etiquette::after {   /* ruban adhésif */
  content: "";
  position: absolute;
  top: -10px;
  width: 54px;
  height: 20px;
  background: rgba(240,230,200,.65);
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.etiquette::before { left: -14px; transform: rotate(-28deg); }
.etiquette::after { right: -14px; transform: rotate(28deg); }
.etiquette.branche { font-size: 64px; padding: 10px 40px 6px; }
#labels.cache { display: none; }

/* ---------- Notes de l'interface ---------- */

.note {
  position: fixed;
  background: #fffdf3;
  box-shadow: 3px 8px 16px rgba(20,10,0,.45);
  padding: 18px 20px 14px;
  z-index: 10;
}
.note .punaise { top: -6px; }

#toolbar {
  top: 30px;
  left: 34px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 20px;
  max-width: calc(100vw - 68px);
  transform: rotate(-.6deg);
}
#toolbar h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
}

input, select, button {
  font-family: var(--main);
  font-size: 20px;
  color: var(--encre);
}
.recherche { position: relative; }
#search {
  width: 250px;
  padding: 3px 8px;
  border: none;
  border-bottom: 2px solid #b9ad94;
  background: transparent;
  outline: none;
}
#search:focus { border-bottom-color: var(--ficelle); }
#suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  width: 340px;
  margin: 4px 0 0;
  padding: 4px 0;
  list-style: none;
  background: #fffdf3;
  box-shadow: 2px 6px 14px rgba(20,10,0,.35);
  max-height: 60vh;
  overflow: auto;
}
#suggestions li {
  padding: 4px 12px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
#suggestions li small { color: var(--encre-douce); font-size: 16px; margin-left: auto; }
#suggestions li.actif, #suggestions li:hover { background: #f4e7c4; }
.point { width: 11px; height: 11px; border-radius: 50%; flex: none; background: var(--c); }

.filtres { display: flex; gap: 16px; }
.filtres label { font-size: 19px; color: var(--encre-douce); display: flex; align-items: center; gap: 6px; }
select {
  border: none;
  border-bottom: 2px solid #b9ad94;
  background: transparent;
  padding: 0 2px;
  cursor: pointer;
}
.boutons { display: flex; gap: 8px; }
button {
  padding: 2px 12px;
  border: 1.5px solid #6b5f4f;
  border-radius: 4px 6px 5px 4px;
  background: #fff7dc;
  cursor: pointer;
  box-shadow: 1px 2px 0 #6b5f4f;
}
button:hover, a.bouton:hover, summary.bouton:hover { background: #fde9a8; }
a.bouton, summary.bouton {
  padding: 2px 12px;
  border: 1.5px solid #6b5f4f;
  border-radius: 4px 6px 5px 4px;
  background: #c9e6b5;
  box-shadow: 1px 2px 0 #6b5f4f;
  font-size: 20px;
  color: var(--encre);
  text-decoration: none;
}
a.bouton[hidden] { display: none; }
a.bouton-arbre, summary.bouton-arbre { background: #fff7dc; }
button:active { transform: translate(1px, 2px); box-shadow: none; }

#legende {
  left: 34px;
  bottom: 30px;
  transform: rotate(.8deg);
  font-size: 19px;
}
#legende-branches { display: flex; flex-wrap: wrap; gap: 4px 16px; }
#legende-branches span { display: inline-flex; align-items: center; gap: 6px; }
#legende .aide { margin: 6px 0 0; font-size: 16px; color: var(--encre-douce); line-height: 1.15; }

#zoom {
  position: fixed;
  right: 34px;
  bottom: 30px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}
#zoom button { width: 44px; height: 44px; font-size: 28px; padding: 0; line-height: 1; }

/* Fiche bristol */
.bristol {
  right: 34px;
  top: var(--sous-barre, 130px);
  width: 330px;
  max-height: calc(100vh - var(--sous-barre, 130px) - 110px);
  overflow: auto;
  transform: rotate(.7deg);
  background:
    repeating-linear-gradient(#fffdf6 0 25px, #cfe0ee 25px 26px),
    #fffdf6;
  background-position: 0 52px;
  font-size: 20px;
  line-height: 26px;
}
.bristol::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 26px;
  width: 1.5px;
  background: #e6a1a1;
}
#info-contenu { padding-left: 18px; }
#info h2 { margin: 0 0 4px; font-size: 30px; line-height: 30px; }
#info .prenoms { color: var(--encre-douce); font-size: 18px; margin: 0 0 6px; }
#info p { margin: 0; }
#info .lien { color: #1d4f9c; cursor: pointer; text-decoration: underline dotted; }
#info .lien:hover { color: var(--ficelle); }
#info .rubrique { margin-top: 4px; font-weight: 700; }
.vignettes-info { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.vignettes-info img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border: 3px solid #fff;
  box-shadow: 1px 2px 4px rgba(0,0,0,.3);
}
.ouvrir-fiche {
  margin: 2px 0 4px;
  padding: 0 10px;
  font-size: 19px;
  background: #c9e6b5;
}
#info-fermer {
  position: absolute;
  right: 8px;
  top: 6px;
  border: none;
  box-shadow: none;
  background: none;
  font-size: 26px;
  padding: 0 6px;
}

#legende .aide.partage { max-width: 380px; color: #7a4a10; }

/* ---------- Version en ligne : la personne connectée ---------- */
#session {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px 3px 10px;
  background: rgba(255, 253, 246, .92);
  box-shadow: 1px 2px 6px rgba(0,0,0,.35);
  font-size: 18px;
}
#session button { padding: 1px 9px; font-size: 16px; }

/* ---------- Bouton à menu (« Télécharger ») ---------- */
.menu-bouton { position: relative; display: inline-block; }
.menu-bouton[hidden] { display: none; }
.menu-bouton > summary { list-style: none; cursor: pointer; display: inline-block; }
.menu-bouton > summary::-webkit-details-marker { display: none; }
.menu-bouton > summary::after { content: " ▾"; font-size: .8em; }
.menu-bouton .menu-choix {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 950;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 270px;
  padding: 8px 6px;
  background: #fffdf6;
  box-shadow: 2px 6px 14px rgba(0,0,0,.35);
}
.menu-choix a { padding: 4px 10px; border-radius: 3px; font-size: 20px; color: var(--encre); text-decoration: none; white-space: nowrap; }
.menu-choix a:hover { background: #fde9a8; }
.menu-choix small { color: var(--encre-douce); font-size: 15px; }
