* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  /* --vh est recalculé en JS (chat.js) pour tenir compte du clavier virtuel mobile */
  --vh: 1vh;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0f1420;
  color: #e6e9f0;
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
  height: 100dvh; /* écrase la valeur ci-dessus sur les navigateurs qui le supportent */
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation; /* évite le délai de double-tap sur mobile */
}

.screen {
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hidden { display: none !important; }

.login-box {
  background: #171d2e;
  padding: 28px 24px;
  border-radius: 12px;
  width: min(92vw, 420px);
  max-height: calc(100% - 32px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid #262e45;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}

.login-box h1 { text-align: center; color: #6ea8ff; margin-bottom: 8px; font-size: clamp(18px, 5vw, 24px); }

.legal-notice {
  font-size: 12px;
  color: #9aa4bd;
  background: #10162400;
  border-left: 3px solid #6ea8ff;
  padding: 8px 10px;
  line-height: 1.4;
}
.legal-notice a { color: #6ea8ff; }

input[type="text"], input[type="password"], select {
  background: #0f1420;
  border: 1px solid #2b3450;
  color: #e6e9f0;
  padding: 12px;
  border-radius: 8px;
  font-size: 16px; /* >=16px : empêche le zoom automatique au focus sur iOS Safari */
  width: 100%;
  min-height: 44px; /* taille de cible tactile recommandée */
}

.age-check { font-size: 12px; color: #9aa4bd; display: flex; align-items: flex-start; gap: 8px; line-height: 1.4; }
.age-check input { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }

.age-check { font-size: 12px; color: #9aa4bd; display: flex; align-items: center; gap: 6px; }

button {
  background: #6ea8ff;
  color: #0f1420;
  border: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  font-size: 15px;
}
button:hover { background: #8fbcff; }

.error { color: #ff6e6e; font-size: 13px; min-height: 16px; }

.link-btn {
  background: none;
  color: #6a7292;
  font-size: 12px;
  font-weight: 400;
  padding: 4px 0;
  text-align: left;
  text-decoration: underline;
  align-self: flex-start;
  min-height: unset;
}
.link-btn:hover { color: #6ea8ff; background: none; }

#chat-screen {
  flex-direction: column;
  align-items: stretch;
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
  height: 100dvh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #171d2e;
  border-bottom: 1px solid #262e45;
  padding-top: calc(12px + env(safe-area-inset-top));
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 6px;
  row-gap: 4px;
}
header h2 { font-size: 16px; }

.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.online-badge {
  font-size: 11px;
  color: #6ee89a;
  background: #12291d;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

#messages {
  flex: 1;
  min-height: 0; /* essentiel en flexbox pour que overflow-y fonctionne correctement */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-row { display: flex; gap: 8px; max-width: 88%; animation: fadeIn 0.15s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #0f1420;
  flex-shrink: 0;
}

.msg-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.msg { padding: 8px 12px; border-radius: 10px; background: #1b2338; word-wrap: break-word; overflow-wrap: break-word; font-size: 14px; }
.msg .pseudo { font-weight: 700; color: #6ea8ff; margin-right: 6px; }
.msg .time { font-size: 10px; color: #6a7292; margin-left: 8px; }
.msg .report-btn { font-size: 10px; color: #ff6e6e; margin-left: 8px; cursor: pointer; background: none; padding: 0; min-height: unset; }
.msg.system { align-self: center; color: #6a7292; font-size: 12px; background: none; }

.msg-actions { display: flex; align-items: center; gap: 6px; padding-left: 2px; position: relative; }
.react-trigger {
  background: none;
  padding: 4px 6px;
  font-size: 13px;
  color: #6a7292;
  border-radius: 6px;
  min-height: unset;
}
.react-trigger:hover { background: #1b2338; color: #e6e9f0; }

.react-popup {
  display: none;
  gap: 4px;
  background: #171d2e;
  border: 1px solid #262e45;
  border-radius: 10px;
  padding: 6px;
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  z-index: 5;
}
.react-popup.open { display: flex; }
.react-popup button {
  background: none;
  font-size: 18px;
  padding: 6px;
  border-radius: 6px;
  min-height: 36px;
  min-width: 36px;
}
.react-popup button:hover { background: #262e45; }

.reactions-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.reaction-pill {
  background: #1b2338;
  border: 1px solid #262e45;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: #c7cde3;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: unset;
}
.reaction-pill:hover { background: #262e45; }
.reaction-pill.mine { border-color: #6ea8ff; background: #1a2740; }

#message-form {
  display: flex;
  padding: 10px 12px;
  gap: 8px;
  background: #171d2e;
  position: relative;
  align-items: center;
  flex-shrink: 0;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
#message-input { flex: 1; min-width: 0; }
#message-form button[type="submit"] { flex-shrink: 0; padding: 10px 16px; }

#emoji-btn {
  background: #1b2338;
  color: inherit;
  font-size: 18px;
  padding: 8px 10px;
  border-radius: 8px;
  flex-shrink: 0;
  min-width: 44px;
}
#emoji-btn:hover { background: #262e45; }

#emoji-picker {
  position: absolute;
  bottom: 56px;
  left: 12px;
  right: 12px;
  margin: 0 auto;
  background: #171d2e;
  border: 1px solid #262e45;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-width: 280px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
#emoji-picker.hidden { display: none; }
#emoji-picker button {
  background: none;
  font-size: 20px;
  padding: 6px;
  border-radius: 6px;
  line-height: 1;
  min-height: 36px;
}
#emoji-picker button:hover { background: #262e45; }

/* ---------- Ajustements pour petits écrans (mobile) ---------- */
@media (max-width: 480px) {
  .login-box { padding: 20px 16px; gap: 10px; }
  header { padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); }
  header h2 { font-size: 14px; }
  #messages { padding: 10px 8px; gap: 8px; }
  .msg-row { max-width: 94%; gap: 6px; }
  .msg { font-size: 13px; padding: 7px 10px; }
  .avatar { width: 26px; height: 26px; font-size: 11px; }
  #emoji-picker { grid-template-columns: repeat(6, 1fr); max-width: none; }
}
