@import url('../../shared/zts.css');

/* Police maison — rend 2x trop grand nativement : size-adjust 50% normalise */
@font-face {
  font-family: 'ZoneTotalSport';
  src: url('../../fonts/ZoneTotalSport.ttf') format('truetype');
  size-adjust: 50%;
  font-display: swap;
}

:root { --stage-max: 1180px; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body, 'Quicksand', sans-serif);
  background:
    radial-gradient(circle at 20% 0%, #CCFAFF 0, transparent 45%),
    radial-gradient(circle at 90% 10%, #FFF6B0 0, transparent 40%),
    var(--paper, #FFFEF7);
  color: var(--ink, #1A1A2E);
  display: flex; flex-direction: column;
  min-height: 100%;
}
[data-metier="camps"] body, body[data-metier="camps"] { }

/* ---------- barre du haut ---------- */
.studio-top {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
  padding: 8px 16px;
  background: var(--metier, #00E5FF);
  border-bottom: 4px solid var(--ink);
  box-shadow: 0 4px 0 rgba(26,26,46,.15);
}
.studio-top h1 {
  font-family: var(--font-impact, 'Luckiest Guy'), cursive;
  font-size: clamp(30px, 4.5vw, 52px); margin: 0; letter-spacing: 2px;
  color: var(--ink); text-align: center; white-space: nowrap;
  text-shadow: 3px 3px 0 #fff, 5px 5px 0 rgba(26,26,46,.25);
}
.top-left { justify-self: start; min-width: 0; }
.top-right { justify-self: end; display: flex; gap: 8px; align-items: center; }
.studio-top .game-name {
  display: inline-block;
  font-family: var(--font-fun, 'Fredoka'), sans-serif; font-weight: 700;
  background: #fff; border: 3px solid var(--ink); border-radius: 10px;
  padding: 4px 12px; box-shadow: 3px 3px 0 var(--ink); max-width: 26vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- boutons ---------- */
.btn {
  font-family: var(--font-bang, 'Bangers'), 'Impact', cursive;
  font-size: 15px; letter-spacing: .5px;
  border: 3px solid var(--ink); border-radius: 10px;
  padding: 6px 12px; cursor: pointer; background: #fff; color: var(--ink);
  box-shadow: 4px 4px 0 var(--ink); transition: transform .06s, box-shadow .06s;
  white-space: nowrap; user-select: none;
}
.btn:hover  { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 var(--ink); }
.btn:active { transform: translate(2px,2px);  box-shadow: 1px 1px 0 var(--ink); }
.btn--eps   { background: #00E5FF; }
.btn--camps { background: #FF6B00; color: #fff; }
.btn--sdg   { background: #39FF14; }
.btn--jaune { background: #FFEA00; }
.btn--play  { background: #39FF14; }
.btn.small  { font-size: 13px; padding: 4px 9px; box-shadow: 3px 3px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: 3px 3px 0 var(--ink); }

/* ---------- menus déroulants ---------- */
.menu { position: relative; }
.menu-list {
  display: none; position: absolute; top: calc(100% + 8px); right: 0; z-index: 90;
  flex-direction: column; gap: 4px; min-width: 230px; padding: 8px;
  background: #fff; border: 3px solid var(--ink); border-radius: 12px;
  box-shadow: 5px 5px 0 var(--ink);
}
.menu.open .menu-list { display: flex; }
.menu-list button {
  font-family: var(--font-fun,'Fredoka'),sans-serif; font-weight: 700; font-size: 13.5px;
  text-align: left; background: none; border: none; border-radius: 8px;
  padding: 9px 10px; cursor: pointer; color: var(--ink);
}
.menu-list button:hover { background: var(--cream,#FFFBE8); outline: 2px solid var(--ink); }

/* ---------- corps ---------- */
.studio-body { flex: 1; display: flex; min-height: 0; }

.palette {
  width: 158px; flex-shrink: 0; padding: 10px 8px; overflow-y: auto;
  background: #fff; border-right: 4px solid var(--ink);
  display: flex; flex-direction: column; gap: 7px;
}
#palette { display: flex; flex-direction: column; gap: 7px; }

/* actions principales déplacées en haut de la colonne gauche */
.side-actions {
  display: flex; flex-direction: column; gap: 8px;
  padding-bottom: 10px; margin-bottom: 4px;
  border-bottom: 3px dashed rgba(26,26,46,.25);
}
.side-actions .btn { width: 100%; font-size: 13.5px; padding: 8px 6px; text-align: center; }
.side-actions .menu { width: 100%; }
.side-actions .menu-list { left: 0; right: auto; top: calc(100% + 6px); }
.palette h3 {
  font-family: var(--font-impact,'Luckiest Guy'),cursive; font-size: 12px;
  margin: 6px 2px 0; color: var(--ink); opacity: .7; letter-spacing: .5px;
}
/* accordéon */
.pal-group { display: flex; flex-direction: column; gap: 7px; }
.pal-head {
  font-family: var(--font-impact,'Luckiest Guy'),cursive; font-size: 12.5px;
  text-align: left; background: var(--cream,#FFFBE8); border: 2px solid var(--ink);
  border-radius: 8px; padding: 6px 8px; cursor: pointer; color: var(--ink);
  letter-spacing: .5px; box-shadow: 2px 2px 0 var(--ink);
}
.pal-head:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--ink); }
.pal-group.closed .pal-items { display: none; }
.pal-items { display: flex; flex-direction: column; gap: 7px; }
.pal-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: var(--font-fun,'Fredoka'),sans-serif; font-size: 10.5px; font-weight: 700;
  border: 3px solid var(--ink); border-radius: 10px; background: var(--cream,#FFFBE8);
  padding: 6px 3px; cursor: grab; box-shadow: 3px 3px 0 var(--ink);
  transition: transform .06s, box-shadow .06s; text-align: center; line-height: 1.05;
}
.pal-item:hover  { transform: translate(-2px,-2px); box-shadow: 5px 5px 0 var(--ink); }
.pal-item:active { transform: translate(1px,1px);  box-shadow: 2px 2px 0 var(--ink); }
.pal-item.active { outline: 3px dashed var(--rose,#FF2D87); outline-offset: 2px; }
.pal-item svg { width: 34px; height: 34px; pointer-events: none; }

/* persos importés : ✕ de suppression au survol */
.pal-perso { position: relative; }
.perso-x {
  display: none; position: absolute; top: -8px; right: -8px;
  width: 18px; height: 18px; border-radius: 999px; background: #FF2D2D; color: #fff;
  border: 2px solid var(--ink); font-size: 10px; line-height: 14px; text-align: center;
  font-family: var(--font-body,'Quicksand'),sans-serif; font-weight: 700;
}
.pal-perso:hover .perso-x { display: block; }

/* ---------- scène ---------- */
.stage-col { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-scroll { flex: 1; overflow: auto; display: flex; justify-content: center; align-items: center; padding: 12px; min-height: 0; }
.stage {
  position: relative; aspect-ratio: 3300 / 2550;
  max-width: min(var(--stage-max), 100%); max-height: 100%; width: auto;
  border: 4px solid var(--ink); border-radius: 14px; overflow: hidden;
  box-shadow: 6px 6px 0 var(--ink); background: #fff;
}
.stage img.terrain { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.stage svg.overlay { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

.el { cursor: grab; }
.el.dragging { cursor: grabbing; }
.el.selected > .sel-box { display: block; }
.sel-box { display: none; }
.handle { cursor: pointer; }

/* titre de scène — bandeau blanc au-dessus du terrain, police maison.
   Div contenteditable (PAS un input : un input rogne les glyphes/contours
   qui débordent — le L de la police ZTS était coupé). */
.scene-title {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 4; width: fit-content; min-width: 200px; max-width: 86%;
  text-align: center; white-space: nowrap; overflow: visible;
  font-family: 'ZoneTotalSport','Luckiest Guy',cursive; font-size: 52px; line-height: 1.15;
  color: var(--ink); background: rgba(255,255,255,.94);
  border: 3px solid var(--ink); border-radius: 12px;
  box-shadow: 4px 4px 0 rgba(26,26,46,.35);
  padding: 6px 24px; outline: none; cursor: text;
  paint-order: stroke fill; /* contour derriere le remplissage, comme l'export */
}
.scene-title:focus { border-color: var(--rose,#FF2D87); }
.scene-title:empty::before {
  content: attr(data-ph);
  font-family: var(--font-fun,'Fredoka'),sans-serif; font-size: 14px;
  color: rgba(26,26,46,.45); -webkit-text-stroke: 0; text-shadow: none;
}
.scene-title:empty:not(:focus) {
  background: rgba(255,255,255,.55); border-style: dashed; box-shadow: none;
  padding: 8px 12px;
}
body.projection .scene-title, body.calib .scene-title { display: none; }

/* bouton + panneau de style du titre */
.title-style-btn {
  position: absolute; top: 14px; left: calc(50% + min(31%, 290px) + 8px);
  z-index: 4;
}
body.projection .title-style-btn, body.calib .title-style-btn { display: none; }
.title-panel {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  width: 230px; background: #fff; border: 3px solid var(--ink); border-radius: 12px;
  box-shadow: 4px 4px 0 var(--ink); padding: 10px; display: none; z-index: 6;
  font-family: var(--font-body,'Quicksand'),sans-serif; font-size: 12.5px;
}
.title-panel.show { display: block; }
.title-panel h4 { margin: 0 0 6px; font-family: var(--font-impact,'Luckiest Guy'),cursive; font-size: 13px; }
.title-panel label { display: block; margin: 6px 0 2px; font-weight: 700; }

/* langue : les blocs marqués data-lang ne s'affichent que dans la langue active */
body[data-lang="fr"] [data-lang="en"] { display: none !important; }
body[data-lang="en"] [data-lang="fr"] { display: none !important; }

/* mode groupement d'actions */
.jouee-chip.pick { background: #FFEA00; outline: 3px solid var(--ink); outline-offset: 1px; }
.jouee-chip.group { border-width: 3px; background: #EDE4FF; }
.jouee-chip.group.done { background: var(--rose,#FF2D87); }
#btnJoueeGroup.arming { background: #FFEA00; }

/* indice terrain vide */
.empty-hint {
  display: none; position: absolute; top: 38%; left: 50%; transform: translate(-50%,-50%);
  z-index: 4; pointer-events: none; text-align: center;
  font-family: var(--font-fun,'Fredoka'),sans-serif; font-weight: 700; font-size: 17px;
  color: var(--ink); background: rgba(255,251,232,.95); border: 3px dashed var(--ink);
  border-radius: 14px; padding: 14px 20px; box-shadow: 4px 4px 0 rgba(26,26,46,.25);
}
.empty-hint small { font-weight: 500; font-size: 12.5px; opacity: .75; }
.empty-hint.show { display: block; }

/* guide rapide */
.help-body { padding: 6px 18px 18px; overflow-y: auto; font-family: var(--font-body,'Quicksand'),sans-serif; font-size: 14px; }
.help-steps { margin: 10px 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 9px; }
.help-keys { border-collapse: collapse; width: 100%; }
.help-keys td { padding: 5px 8px; border-top: 2px dashed rgba(26,26,46,.2); }
.help-keys td:first-child { white-space: nowrap; width: 110px; }
.help-keys kbd {
  font-family: inherit; font-weight: 700; font-size: 12px; background: var(--cream,#FFFBE8);
  border: 2px solid var(--ink); border-radius: 6px; padding: 1px 7px; box-shadow: 2px 2px 0 var(--ink);
}

/* placeholder quand pas de terrain */
.stage.empty { min-height: 300px; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-fun,'Fredoka'),sans-serif; color: #888; }

/* ---------- inspecteur ---------- */
.inspector {
  position: absolute; top: 10px; right: 10px; width: 190px;
  background: #fff; border: 3px solid var(--ink); border-radius: 12px;
  box-shadow: 4px 4px 0 var(--ink); padding: 10px; display: none; z-index: 5;
  font-family: var(--font-body,'Quicksand'),sans-serif; font-size: 12.5px;
}
.inspector.show { display: block; }
.inspector h4 { margin: 0 0 6px; font-family: var(--font-impact,'Luckiest Guy'),cursive; font-size: 13px; }
.inspector label { display: block; margin: 6px 0 2px; font-weight: 700; }
.inspector input[type=text], .inspector textarea, .inspector select {
  width: 100%; border: 2px solid var(--ink); border-radius: 7px; padding: 4px 6px; font: inherit;
}
.inspector textarea { resize: vertical; min-height: 52px; }
.inspector .row { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 7px; }
.swatches { display: flex; gap: 5px; margin-top: 3px; }
.swatch { width: 24px; height: 24px; border: 2px solid var(--ink); border-radius: 6px; cursor: pointer; }
.swatch.on { outline: 3px solid var(--rose,#FF2D87); outline-offset: 1px; }

/* ---------- étapes ---------- */
.steps-bar {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px; overflow-x: auto;
  background: #fff; border-top: 4px solid var(--ink);
}
.step-chip {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
  border: 3px solid var(--ink); border-radius: 10px; background: var(--cream,#FFFBE8);
  padding: 5px 10px; cursor: pointer; box-shadow: 3px 3px 0 var(--ink);
  font-family: var(--font-fun,'Fredoka'),sans-serif; font-weight: 700; font-size: 13px;
}
.step-chip .num {
  background: var(--ink); color: #fff; border-radius: 999px; width: 20px; height: 20px;
  display: grid; place-items: center; font-size: 12px; font-family: var(--font-impact,'Luckiest Guy'),cursive;
}
.step-chip.active { background: var(--metier,#00E5FF); outline: 3px dashed var(--ink); }
.step-title-in { border: none; background: transparent; font: inherit; width: 90px; }
.step-chip.active .step-title-in { font-weight: 700; }

.toast {
  position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 10px;
  font-family: var(--font-fun,'Fredoka'),sans-serif; font-weight: 700; z-index: 50;
  box-shadow: 4px 4px 0 rgba(0,0,0,.3); opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* calibration */
.calib-banner {
  display: none; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--rose,#FF2D87); color: #fff; border-bottom: 4px solid var(--ink);
  font-family: var(--font-fun,'Fredoka'),sans-serif; font-weight: 700;
}
body.calib .calib-banner { display: flex; }
.corner-handle { fill: var(--rose,#FF2D87); stroke: #fff; stroke-width: 3; cursor: move; }

/* ---------- mode projection (plein écran TNI) ---------- */
.proj-title, .proj-bar { display: none; }

body.projection .studio-top,
body.projection .palette,
body.projection .steps-bar,
body.projection .calib-banner,
body.projection .inspector { display: none !important; }

body.projection { background: #10101c; }
body.projection .stage-scroll { padding: 0; align-items: center; }
body.projection .stage {
  max-width: none; max-height: 100vh; width: auto;
  border: none; border-radius: 0; box-shadow: none; background: #10101c;
  margin: auto;
}

body.projection .proj-title {
  display: block; position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 60; pointer-events: none;
  font-family: var(--font-impact,'Luckiest Guy'),cursive;
  font-size: clamp(22px, 3.4vw, 44px); letter-spacing: 1px; color: #fff;
  text-shadow: 3px 3px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink);
  white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}

body.projection .proj-bar {
  display: flex; position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  z-index: 60; gap: 10px; align-items: center;
  background: rgba(255,255,255,.92); border: 3px solid var(--ink); border-radius: 14px;
  padding: 8px 12px; box-shadow: 4px 4px 0 var(--ink);
  opacity: .35; transition: opacity .2s;
}
body.projection .proj-bar:hover, body.projection .proj-bar:focus-within { opacity: 1; }
.proj-step {
  font-family: var(--font-impact,'Luckiest Guy'),cursive; font-size: 17px; min-width: 46px;
  text-align: center; color: var(--ink);
}

/* ---------- jouée (gestes enregistrés) ---------- */
.jouee-bar {
  display: none; align-items: center; gap: 8px; padding: 7px 14px;
  background: #FFF4FA; border-top: 3px dashed var(--ink); overflow-x: auto;
}
.jouee-bar.show { display: flex; }
#joueeChips { display: flex; gap: 6px; align-items: center; }
.jouee-chip {
  position: relative; min-width: 28px; height: 28px; flex-shrink: 0; cursor: pointer;
  border: 2px solid var(--ink); border-radius: 999px; background: #fff;
  font-family: var(--font-impact,'Luckiest Guy'),cursive; font-size: 13px; color: var(--ink);
  display: grid; place-items: center; box-shadow: 2px 2px 0 var(--ink); padding: 0 7px;
}
.jouee-chip.done { background: var(--rose,#FF2D87); color: #fff; }
.jouee-chip.next { outline: 3px dashed var(--rose,#FF2D87); outline-offset: 2px; }
.jouee-chip .chip-x {
  display: none; position: absolute; top: -9px; right: -9px;
  width: 17px; height: 17px; border-radius: 999px; background: #FF2D2D; color: #fff;
  border: 2px solid var(--ink); font-size: 9px; line-height: 13px; text-align: center;
  font-family: var(--font-body,'Quicksand'),sans-serif; font-weight: 700;
}
.jouee-chip:hover .chip-x { display: block; }
.btn--rec { background: #fff; }
.btn--rec.recording { background: #FF2D2D !important; color: #fff !important; animation: recPulse 1.2s infinite; }

/* curseur invisible pendant toute animation (lecture ou jouée) */
body.animating, body.animating * { cursor: none !important; }

/* bouton REC actif */
.btn.recording { background: #FF2D2D !important; color: #fff !important; animation: recPulse 1.2s infinite; }
@keyframes recPulse { 0%,100% { box-shadow: 4px 4px 0 var(--ink); } 50% { box-shadow: 4px 4px 0 var(--ink), 0 0 0 6px rgba(255,45,45,.35); } }

/* modale sélecteur de jeu */
.modal { position: fixed; inset: 0; background: rgba(26,26,46,.55); display: none; z-index: 100; padding: 4vh 4vw; }
.modal.show { display: flex; }
.modal-card {
  margin: auto; background: var(--paper,#FFFEF7); border: 4px solid var(--ink); border-radius: 16px;
  box-shadow: 8px 8px 0 var(--ink); width: min(760px, 100%); max-height: 92vh; display: flex; flex-direction: column;
}
.modal-card header { padding: 14px 18px; border-bottom: 3px solid var(--ink); display: flex; gap: 10px; align-items: center; }
.modal-card header h2 { margin: 0; font-family: var(--font-impact,'Luckiest Guy'),cursive; font-size: 20px; flex: 1; }
.modal-card .search { width: 100%; border: 3px solid var(--ink); border-radius: 10px; padding: 8px 12px; font: inherit; margin: 12px 18px 6px; width: calc(100% - 36px); }
.game-list { overflow-y: auto; padding: 6px 18px 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.game-row {
  display: flex; gap: 8px; align-items: center; text-align: left; cursor: pointer;
  border: 3px solid var(--ink); border-radius: 10px; background: #fff; padding: 8px 10px;
  box-shadow: 3px 3px 0 var(--ink); font-family: var(--font-body,'Quicksand'),sans-serif;
}
.game-row:hover { transform: translate(-2px,-2px); box-shadow: 5px 5px 0 var(--ink); }
.game-row .ico { font-size: 20px; }
.game-row .tt { font-weight: 700; font-size: 13px; line-height: 1.1; }
.game-row .uni { font-size: 10px; opacity: .7; text-transform: uppercase; }

@media (max-width: 700px) {
  .palette { width: 120px; }
  .game-list { grid-template-columns: 1fr; }
  .inspector { width: 160px; }
}
