:root{
  --bg: #0b0f19;
  --panel: rgba(255,255,255,.06);
  --border: rgba(255,255,255,.12);
  --text: rgba(255,255,255,.92);
  --muted: rgba(255,255,255,.62);
  --shadow: 0 18px 60px rgba(0,0,0,.45);
  --radius: 18px;
}
*{ box-sizing: border-box; }
html,body{ height:100%; }

body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 20% 10%, rgba(99,102,241,.25), transparent 60%),
    radial-gradient(900px 500px at 80% 0%, rgba(34,197,94,.20), transparent 55%),
    radial-gradient(1000px 650px at 70% 100%, rgba(236,72,153,.18), transparent 60%),
    var(--bg);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
}

.app{
  width:min(900px, 100%);
  height:min(760px, calc(100vh - 36px));
  display:flex;
  flex-direction:column;
  border:1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.04));
  box-shadow: var(--shadow);
  overflow:hidden;
  backdrop-filter: blur(10px);
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:14px 16px;
  border-bottom:1px solid var(--border);
  background: rgba(0,0,0,.18);
}

.brand{ display:flex; align-items:center; gap:10px; min-width:0; }
.logo{
  width:34px; height:34px;
  border-radius:50%;
  display:grid; place-items:center;
  background: rgba(255,255,255,.10);
  border:1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.title strong{ font-size:14px; letter-spacing:.2px; white-space:nowrap; }

.actions{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap: wrap;
  justify-content:flex-end;
}

.btn{
  border:1px solid var(--border);
  background: rgba(255,255,255,.08);
  color: var(--text);
  padding:9px 12px;
  border-radius: 12px;
  cursor:pointer;
  font-weight:600;
  font-size: 13px;
  transition: transform .05s ease, background .15s ease;
  user-select:none;
}
.btn:hover{ background: rgba(255,255,255,.12); }
.btn:active{ transform: translateY(1px); }
.btn.secondary{ color: var(--muted); font-weight:700; }

.btn.danger{
  border-color: rgba(239,68,68,.35);
  background: rgba(239,68,68,.14);
}
.btn.danger:hover{ background: rgba(239,68,68,.20); }

.status{
  display:flex; align-items:center; gap:8px;
  padding:8px 10px;
  border-radius: 999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.status.online{
  color: rgba(180,255,210,.95);
  border-color: rgba(34,197,94,.35);
  background: rgba(34,197,94,.14);
}
.status.offline{
  color: rgba(255,190,190,.95);
  border-color: rgba(239,68,68,.35);
  background: rgba(239,68,68,.14);
}

/* HUD game */
.hud{
  display:flex;
  align-items:center;
  gap:10px;
  padding:8px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.78);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.hud.dead{
  color: rgba(255,190,190,.95);
  border-color: rgba(239,68,68,.35);
  background: rgba(239,68,68,.14);
}

/* =============================
   Zone Images + Historique
============================== */
.imageArea{
  display:none;
  padding: 14px 16px;
  border-bottom:1px solid var(--border);
  background: rgba(0,0,0,.10);

  /* ✅ important : le panneau reste "normal", et peut scroller si besoin */
  max-height: calc(100vh - 180px);
  overflow: auto;
}
.imageHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom: 10px;
}
.imageHeader .title{
  font-weight: 900;
  color: rgba(255,255,255,.86);
  letter-spacing: .2px;
}

.imageControls{
  display:flex;
  gap:10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  align-items:center;
}
.imageControls input{
  flex: 1 1 320px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: var(--text);
  padding: 12px 12px;
  border-radius: 14px;
  outline:none;
  font-size: 14px;
  min-width: 260px;
}

.hint{
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 10px;
}

.imageHistory{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap:10px;
}
.thumb{
  border:1px solid rgba(255,255,255,.12);
  border-radius: 14px;
  overflow:hidden;
  background: rgba(255,255,255,.06);
  box-shadow: 0 10px 28px rgba(0,0,0,.18);
  cursor:pointer;
  transition: transform .08s ease, background .15s ease;
}
.thumb:hover{
  transform: translateY(-1px);
  background: rgba(255,255,255,.08);
}
.thumb img{
  width:100%;
  height: 120px;
  object-fit: cover;
  display:block;
}
.thumbMeta{
  padding: 8px 10px;
  font-size: 11px;
  color: var(--muted);
  display:flex;
  justify-content: space-between;
  gap:10px;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}

/* =============================
   Lightbox (✅ image entière, sans scroll)
============================== */
.lightbox{
  position: fixed;
  inset: 0;
  display:none;
  align-items:center;
  justify-content:center;
  background: rgba(0,0,0,.70);
  z-index: 999;
  padding: 18px;
  backdrop-filter: blur(10px);
}
.lightboxCard{
  width: min(1100px, 100%);
  max-height: min(86vh, 900px);
  border:1px solid rgba(255,255,255,.14);
  background: rgba(15,18,30,.72);
  border-radius: 18px;
  box-shadow: 0 20px 70px rgba(0,0,0,.55);
  overflow:hidden;
  display:flex;
  flex-direction: column;
}
.lightboxTop{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding: 12px 14px;
  border-bottom:1px solid rgba(255,255,255,.10);
}
.lightboxTop .t{
  font-weight: 900;
  color: rgba(255,255,255,.86);
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightboxBody{
  padding: 14px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* ✅ plus de scrollbar */
  background: radial-gradient(circle, rgba(255,255,255,0.06), rgba(0,0,0,0.35));
}
.lightboxBody img{
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain; /* ✅ image en entier */
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.10);
  display:block;
}

/* =============================
   Chat
============================== */
.chat{
  flex:1; overflow:auto;
  padding: 18px 16px;
  display:flex; flex-direction:column;
  gap:12px;
  scroll-behavior:smooth;
}
.bubbleRow{ display:flex; gap:10px; align-items:flex-end; }
.bubbleRow.you{ justify-content:flex-end; }
.bubbleRow.bot{ justify-content:flex-start; }

.avatar{
  width:30px; height:30px;
  border-radius:50%;
  display:grid; place-items:center;
  background: rgba(255,255,255,.10);
  border:1px solid var(--border);
  color: rgba(255,255,255,.9);
  font-size: 14px;
}

.bubble{
  max-width: min(680px, 82%);
  padding: 12px 13px;
  border-radius: 16px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.07);
  box-shadow: 0 10px 28px rgba(0,0,0,.20);
  font-size: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.you{
  background: linear-gradient(180deg, rgba(99,102,241,.28), rgba(99,102,241,.16));
  border-color: rgba(99,102,241,.35);
}

.meta{
  margin-top:6px;
  font-size: 11px;
  color: var(--muted);
  display:flex;
  gap:10px;
  align-items:center;
}

.footer{
  border-top:1px solid var(--border);
  background: rgba(0,0,0,.16);
  padding: 12px;
}
form{ display:flex; gap:10px; align-items:center; }

input#input{
  flex:1;
  border:1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: var(--text);
  padding: 12px 12px;
  border-radius: 14px;
  outline: none;
  font-size: 14px;
}

.send{
  display:flex; align-items:center; gap:10px;
  padding: 12px 14px;
  border-radius: 14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.10);
  color: var(--text);
  cursor:pointer;
  font-weight:700;
}

.spinner{
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25);
  border-top-color: rgba(255,255,255,.90);
  animation: spin 0.85s linear infinite;
  display:none;
}
.send.loading .spinner{ display:block; }
@keyframes spin { to { transform: rotate(360deg); } }

.personaWrap{ position: relative; }

.personaMenu{
  position: absolute;
  top: 64px;
  right: 16px;
  background: rgba(0,0,0,.55);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  display:none;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  z-index: 50;
  min-width: 220px;
}
.personaMenu button{ width: 100%; margin: 6px 0; text-align:left; }

/* =============================
   Outils (panneau)
============================== */
.toolsPanel{
  position: absolute;
  top: 64px;
  right: 16px;
  width: min(420px, calc(100vw - 32px));
  background: rgba(0,0,0,.55);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  z-index: 55;
}
.toolsHeader{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.toolsTitle{
  font-weight: 900;
  color: rgba(255,255,255,.88);
  letter-spacing: .2px;
}
.toolGrid{
  display:grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.toolCard{
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  border-radius: 14px;
  padding: 12px;
  display:flex;
  flex-direction: column;
  gap: 10px;
}
.toolTop{ display:flex; flex-direction: column; gap: 4px; }
.toolName{ font-weight: 900; color: rgba(255,255,255,.88); }
.toolDesc{ color: var(--muted); font-size: 12px; font-weight: 650; line-height: 1.3; }

/* Slider (dans le panneau) */
.illWrap{
  display:flex;
  align-items:center;
  gap:10px;
  padding:8px 10px;
  border-radius: 999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.06);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.illWrap input[type="range"]{
  width: 140px;
  accent-color: rgba(255,255,255,.65);
}
.illLabel{ white-space: nowrap; }

.toolsPanel .illWrap{
  width: 100%;
  border-radius: 14px;
  justify-content: space-between;
  gap: 10px;
}
.toolsPanel .illWrap input[type="range"]{ flex: 1; width: auto; }
.illValue{
  min-width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: rgba(255,255,255,.82);
}

/* Images auto (aventure) */
.bubble img.chatImage,
.bubble img{
  max-width: 100%;
  height: auto;
  border-radius: 14px;
  display: block;
}

.microHint{
  padding: 8px 14px 0 14px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 650;
  opacity: .85;
}
.microHint strong{ color: rgba(255,255,255,.80); }

select, option{
  color: rgba(255,255,255,.92);
  background: #0b0f19;
}

/* =========================
   SMALL FIX
========================== */
@media (max-width: 520px){
  .bubble{ max-width: 92%; }
  .chat{ padding: 14px 12px; }
  .topbar{ flex-wrap: wrap; }
}

/* =========================
   MOBILE UX UPGRADE
========================== */
@media (max-width: 640px){
  body{ padding:0; }
  .app{ width:100%; height:100vh; border-radius:0; }
  .topbar{ padding:10px 10px; gap:6px; }
  .actions{ gap:6px; }
  .btn{ padding:8px 10px; font-size:12px; border-radius:10px; }
  .status{ font-size:11px; padding:6px 8px; }
  .hud{ font-size:11px; padding:6px 8px; }

  /* Topbar actions: 1 seule ligne + scroll horizontal */
  .actions{
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    justify-content: flex-end;
  }
  .actions::-webkit-scrollbar{ height: 0; }

  /* reset un peu moins agressif visuellement */
  #btnReset{ opacity: .95; }

  .chat{ padding:12px 10px 90px; gap:10px; }
  .bubble{ max-width:94%; font-size:15px; line-height:1.45; padding:12px; border-radius:14px; }
  .avatar{ width:26px; height:26px; font-size:12px; }
  .meta{ font-size:10px; }

  .footer{
    position:fixed;
    bottom:0; left:0; right:0;
    padding:10px;
    background:rgba(10,12,20,.95);
    backdrop-filter:blur(8px);
  }
  form{ gap:8px; }
  input#input{ font-size:16px; padding:12px; }
  .send{ padding:12px; }

  .imageArea{ padding:10px; }
  .imageControls input{ font-size:16px; }
  .imageHistory{ grid-template-columns: repeat(2, 1fr); gap:8px; }
  .thumb img{ height:100px; }

  .lightbox{ padding:8px; }
  .lightboxCard{ border-radius:12px; max-height:92vh; }
  .lightboxTop{ padding:8px 10px; }

  /* Menus en bottom-sheet */
  .toolsPanel{
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 88px;
    top: auto;
    max-height: min(70vh, 560px);
    overflow: auto;
    z-index: 55;
  }
  .personaMenu{
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 88px;
    top: auto;
    min-width: 0;
    z-index: 56; /* au-dessus de toolsPanel */
  }
}

/* ===== STOP : plus visible / cliquable ===== */
#stopBtn{
  opacity: 1;
  font-weight: 800;
  letter-spacing: .2px;
  border: 1px solid rgba(239,68,68,.55);
  background: rgba(239,68,68,.12);
  color: rgba(255,255,255,.92);
  box-shadow: 0 8px 18px rgba(0,0,0,.25);
  transform: translateY(0);
  transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}

#stopBtn:hover{
  background: rgba(239,68,68,.18);
  border-color: rgba(239,68,68,.75);
  box-shadow: 0 10px 22px rgba(0,0,0,.28);
  transform: translateY(-1px);
}

#stopBtn:active{
  transform: translateY(0);
  box-shadow: 0 6px 14px rgba(0,0,0,.22);
}

#stopBtn.stop-armed{
  animation: stopPulse .9s ease-in-out infinite;
}

@keyframes stopPulse{
  0%,100%{ box-shadow: 0 8px 18px rgba(239,68,68,.10), 0 8px 18px rgba(0,0,0,.25); }
  50%    { box-shadow: 0 10px 24px rgba(239,68,68,.22), 0 8px 18px rgba(0,0,0,.25); }
}

#stopBtn:disabled{
  opacity: .35;
  cursor: not-allowed;
  animation: none;
}
