:root {
  /* Scale */
  --header-scale: 0.9;
  --chat-scale: 0.9;

  /* Base sizes (الأصل قبل التصغير) */
  --top-bar-base: 26px;
  --header-base: 75px;

  /* Calculated sizes (بعد التصغير) */
  --top-bar-height: calc(var(--top-bar-base) * var(--header-scale));
  --header-height: calc(var(--header-base) * var(--header-scale));
}


#chat-sidebar {
  position: fixed;
  right: 0;
  top: calc(var(--top-bar-height) + var(--header-height));
  bottom: 0;
 width: calc(350px * var(--chat-scale));

  background: linear-gradient(to top,
      #1e1e1e 0%,
      #161622 40%,
      #0f0f1f 100%
  );

  backdrop-filter: none;
  z-index: 998;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #1b1b2a;
  border-bottom-left-radius: 6px;
}


/* =========================================
   CHAT MESSAGES — RUSTY DARK
========================================= */

.chat-messages {
  flex: 1;
  height: 400px;
  overflow-y: auto;

  padding: calc(16px * var(--chat-scale));
  display: flex;
  flex-direction: column;
  gap: calc(16px * var(--chat-scale));

  direction: rtl;
  text-align: left;

  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.12) transparent;

  /* تلاشي الرسائل من الأعلى */
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0px,
    black 45px,
    black 100%
  );

  mask-image: linear-gradient(
    to bottom,
    transparent 0px,
    black 45px,
    black 100%
  );
}

/* 🌧 Rain فوق الشات بدون تحريك الرسائل */
#rain-container{
    position:absolute;

    top:10px;
    left:10px;
    right:10px;

    z-index:20;
}
/* =========================================
   CHAT MESSAGES — RUSTY DARK
========================================= */

.chat-messages {
  flex: 1;
  height: 400px;
  overflow-y: auto;

  padding: calc(16px * var(--chat-scale));
  display: flex;
  flex-direction: column;
  gap: calc(16px * var(--chat-scale));

  direction: rtl;
  text-align: left;

  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.12) transparent;

  /* تلاشي الرسائل من الأعلى */
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0px,
    black 45px,
    black 100%
  );

  mask-image: linear-gradient(
    to bottom,
    transparent 0px,
    black 45px,
    black 100%
  );
}

/* ================= MESSAGE ================= */

.chat-msg {
  position: relative;

  width: 100%;
  max-width: 100%;

  padding: 3px 0;

  direction: ltr;
  color: #fff;

  background: transparent;
  border: none;

  opacity: 0;
  transform: translateX(-8px);
  animation: chatEnter .32s cubic-bezier(.16,1,.3,1) forwards;
}

@keyframes chatEnter {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}


/* ================= AVATAR ================= */

.chat-avatar {
  width: calc(42px * var(--chat-scale));
  height: calc(42px * var(--chat-scale));

  flex-shrink: 0;
  object-fit: cover;

  /* مربع حديث */
  border-radius: 5px;

  border: 1px solid rgba(255,255,255,.12);

  box-shadow:
    0 6px 18px rgba(0,0,0,.45);

  filter: saturate(.88);

  transition:
    transform .22s cubic-bezier(.16,1,.3,1),
    filter .22s ease,
    border-color .22s ease;
}


/* خط صغير بجانب الصورة */
.chat-msg::before {
  content: "";

  position: absolute;
  left: -6px;
  top: 5px;

  width: 2px;
  height: 32px;

  background: linear-gradient(180deg, #7b3ff6, #a974ff);

  opacity: .35;

  transform: scaleY(.35);
  transform-origin: center;

  transition:
    transform .25s cubic-bezier(.16,1,.3,1),
    opacity .25s ease;
}


.chat-msg:hover::before {
  transform: scaleY(1);
  opacity: 1;
}


.chat-msg:hover .chat-avatar {
  transform: translateX(2px);
  filter: saturate(1.1);

  border-color: #a974ff;
}


/* ================= CONTENT ================= */

.chat-msg > div {
  width: 100%;
  max-width: 100%;
  min-width: 0;

  display: flex;
  flex-direction: column;

  word-break: break-word;
}


/* ================= PLAYER NAME ================= */

.chat-name {
  display: inline-block;
  width: fit-content;

  margin: 0 0 calc(5px * var(--chat-scale)) 0;

  color: #f4f5f7;

  font-size: calc(13.5px * var(--chat-scale));
  font-weight: 800;

  line-height: 1;

  letter-spacing: .6px;

  text-transform: uppercase;

  text-shadow:
    0 2px 8px rgba(0,0,0,.7);

  transition:
    color .2s ease,
    letter-spacing .25s ease;
}


.chat-msg:hover .chat-name {
  color: #a974ff;
  letter-spacing: .9px;
}


/* ================= MESSAGE TEXT ================= */

.chat-text {
  color: rgba(218,221,228,.82);

  font-size: calc(13px * var(--chat-scale));
  font-weight: 400;

  line-height: 1.5;

  letter-spacing: .12px;

  white-space: normal;
  overflow-wrap: anywhere;
}


/* ================= SCROLLBAR ================= */

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.12);
  border-radius: 20px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #7b3ff6, #a974ff);
}

/* ✅ باقي الكود كما هو */

.chat-input-container {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  background-color: rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-wrapper {
  position: relative;
  background-color: #1b1b1b;
  border-radius: 6px;
  padding: 10px;
}

.chat-input {
  width: 100%;
  min-height: calc(60px * var(--chat-scale));
  background-color: transparent;
  border: none;
  resize: none;
  color: white;
  font-size: calc(0.9rem * var(--chat-scale));
 padding-right: calc(45px * var(--chat-scale));
  outline: none;
  margin: 0;
  font-family: inherit;
}

.chat-input::placeholder {
  color: #777;
  font-style: italic;
}

.emoji-button {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: #999;
  font-size: 18px;
  cursor: pointer;
}

.chat-options {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 4px;
  margin-top: -4px;
}

.online-counter {
  margin-left: auto;
}

.language-selector {
  background-color: #2d2d2d;
  color: white;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-send-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;

  width: calc(34px * var(--chat-scale));
  height: calc(34px * var(--chat-scale));

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 8px;
  border: 1px solid rgba(162, 89, 255, 0.25);

  background: linear-gradient(135deg,#7c4dff,#a259ff);
  cursor: pointer;

  transition: 0.25s ease;
  box-shadow: 0 0 10px rgba(124,77,255,0.25);
}

/* الأيقونة */
.chat-send-btn svg {
  width: 16px;
  height: 16px;
  fill: white;
  transform: translateX(1px);
}

/* hover */
.chat-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 0 14px rgba(162,89,255,0.6);
}

/* disabled */
.chat-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.online-counter{
  display: flex;
  align-items: center;
  gap: 8px;

  padding: 5px 12px;
  border-radius: 20px;

  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);

  font-size: 12px;
  font-weight: 600;
  letter-spacing: .5px;

  color: #bbb;
}

/* الرقم */
.online-number{
  color: #fff;
  font-weight: 700;
}

/* LIVE DOT */
.pulse{
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  position: relative;
}

.pulse::after{
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #2ecc71;
  animation: onlinePulse 1.8s infinite;
  opacity: .6;
}

@keyframes onlinePulse{
  0%{ transform: scale(1); opacity: .6; }
  70%{ transform: scale(2.5); opacity: 0; }
  100%{ opacity: 0; }
}


/* 🔘 الزر البنفسجي — ملتصق أكثر بالشات */
#chat-toggle-btn {
  position: fixed;
  bottom: 20px;
  right: calc(350px * var(--chat-scale));
  width: 42px;
  height: 42px;
  background: #272727; /* نفس لون الشات */
  border-left: 2px solid #7c4dff;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px 0 0 10px;
  cursor: pointer;
  transition: right 0.4s ease, background 0.3s ease;
  z-index: 1200;
  box-shadow: 0 0 10px rgba(124, 77, 255, 0.3);
}

#chat-toggle-btn:hover {
  background: #2d2d2d;
}

/* 💬 الأيقونة */
#chat-toggle-btn .toggle-icon {
  font-size: 18px;
  transition: transform 0.3s ease;
}

/* 🧩 حركة الشات */
#chat-sidebar {
  transition: transform 0.4s ease; /* ← يضيف أنيميشن للفتح كمان */
}

/* 🧩 حالة الشات مغلق */
#chat-sidebar.closed {
  transform: translateX(100%);
}

/* 🔁 الزر يتحرك مع الشات لكنه يبقى ظاهر جزئياً */
#chat-sidebar.closed ~ #chat-toggle-btn {
  right: 0; /* يبقى جزء ظاهر من الزر فقط */
}

/* 🔁 يدور الأيقونة لما يكون مغلق */
#chat-sidebar.closed ~ #chat-toggle-btn .toggle-icon {
  transform: rotate(180deg);
}


/* ==== language dropdown ==== */
#language-btn {
  display:flex;
  align-items:center;
  gap:8px;
  padding:6px 10px;
  background:#2d2d2d;
  border-radius:6px;
  cursor:pointer;
  position:relative;
  z-index:1200;
  border:1px solid rgba(162,89,255,0.12);
}
#language-btn .flag {
  width:20px;
  height:14px;
  object-fit:cover;
  display:inline-block;
}
#language-btn .lang-text {
  font-size:0.9rem;
  font-weight:600;
}
#language-btn .caret {
  margin-left:6px;
  opacity:0.8;
  font-size:0.9rem;
}

/* البانل يفتح فوق الزر */
#language-panel {
  display:none;
  position:absolute;
  bottom:calc(100% + 8px);
  left:0;
  background:#1e1e1e;
  border:1px solid #a259ff33;
  border-radius:8px;
  box-shadow:0 10px 30px rgba(0,0,0,0.6);
  overflow:hidden;
  transform-origin:bottom center;
  min-width:140px;
}

/* عنصر اللغتين */
#language-panel .item {
  display:flex;
  align-items:center;
  gap:8px;
  padding:10px 12px;
  cursor:pointer;
  white-space:nowrap;
  transition:background 0.15s, transform 0.12s;
}
#language-panel .item:hover {
  background:#2a2a2a;
  transform:translateX(6px);
}

/* أنيميشن فتح / غلق */
@keyframes langOpen {
  from { opacity:0; transform: translateY(8px) scale(0.98); }
  to { opacity:1; transform: translateY(0) scale(1); }
}
@keyframes langClose {
  from { opacity:1; transform: translateY(0) scale(1); }
  to { opacity:0; transform: translateY(8px) scale(0.98); }
}

/* تأثير الشيمر عند تحميل الشات */
.chat-loading {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.05) 25%,
    rgba(255,255,255,0.15) 50%,
    rgba(255,255,255,0.05) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  z-index: 50;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.emoji-popup {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 95%;
  max-height: 160px;
  background-color: #222;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  overflow-y: auto;
  z-index: 1000;
}

/* سكرول لطيف */
.emoji-popup::-webkit-scrollbar {
  width: 6px;
}
.emoji-popup::-webkit-scrollbar-track {
  background: transparent;
}
.emoji-popup::-webkit-scrollbar-thumb {
  background-color: #555;
  border-radius: 4px;
}

/* كل عنصر */
.emoji-item {
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.2s ease;
}
.emoji-item:hover {
  transform: scale(1.2);
}

/* ✅ خط فاصل */
.emoji-divider {
  width: 100%;
  height: 1px;
  background-color: #444;
  margin: 8px 0;
}

/* ✅ الأعلام مفصولة أكثر */
.emoji-flag {
  margin-right: 6px;
  margin-bottom: 6px;
}
/* ==================================================
   COINFLIP CHAT PREVIEW — RUSTYEGG
================================================== */

.cf-chat-preview {
  width: 100%;
  margin-top: 8px;
  overflow: hidden;

  background:
    linear-gradient(145deg, rgba(123,63,246,.08), transparent 45%),
    #15151d;

  border: 1px solid rgba(255,255,255,.08);
  border-radius: 7px;

  cursor: pointer;

  box-shadow:
    0 8px 24px rgba(0,0,0,.28),
    inset 0 1px 0 rgba(255,255,255,.025);

  transition:
    transform .22s cubic-bezier(.16,1,.3,1),
    border-color .22s ease,
    box-shadow .22s ease;
}

.cf-chat-preview:hover {
  transform: translateY(-2px);

  border-color: rgba(169,116,255,.35);

  box-shadow:
    0 12px 30px rgba(0,0,0,.4),
    0 0 18px rgba(123,63,246,.08);
}


/* ================= TOP ================= */

.cf-preview-top {
  height: 27px;
  padding: 0 9px;

  display: flex;
  align-items: center;
  justify-content: space-between;

  background: rgba(255,255,255,.025);
  border-bottom: 1px solid rgba(255,255,255,.055);
}

.cf-preview-status {
  position: relative;

  padding-left: 10px;

  font-size: 8px;
  font-weight: 900;
  letter-spacing: 1.1px;
}

.cf-preview-status::before {
  content: "";

  position: absolute;
  left: 0;
  top: 50%;

  width: 5px;
  height: 5px;

  border-radius: 50%;

  transform: translateY(-50%);
}

.cf-preview-status.active {
  color: #56e887;
}

.cf-preview-status.active::before {
  background: #56e887;
  box-shadow: 0 0 7px rgba(86,232,135,.7);
}

.cf-preview-status.ended {
  color: #ff626d;
}

.cf-preview-status.ended::before {
  background: #ff626d;
  box-shadow: 0 0 7px rgba(255,98,109,.55);
}

.cf-preview-value {
  color: #fff;

  font-size: 11px;
  font-weight: 900;

  letter-spacing: .3px;
}


/* ================= BATTLE ================= */

.cf-preview-battle {
  position: relative;

  min-height: 74px;

  padding: 10px 9px;

  display: grid;
  grid-template-columns: 1fr 38px 1fr;
  align-items: center;
  gap: 4px;
}


/* ================= USER ================= */

.cf-preview-user {
  min-width: 0;

  display: flex;
  flex-direction: column;
  align-items: center;

  gap: 6px;
}

.cf-preview-avatar-wrap {
  position: relative;

  width: 40px;
  height: 40px;
}

.cf-preview-avatar,
.cf-preview-empty {
  width: 40px;
  height: 40px;

  object-fit: cover;

  border-radius: 5px;

  border: 1px solid rgba(255,255,255,.13);

  box-shadow:
    0 5px 14px rgba(0,0,0,.4);
}

.cf-preview-empty {
  display: flex;
  align-items: center;
  justify-content: center;

  color: rgba(255,255,255,.25);

  font-size: 17px;
  font-weight: 900;

  background: rgba(255,255,255,.035);

  border-style: dashed;
}


/* SMALL COIN */

.cf-preview-coin {
  position: absolute;

  right: -5px;
  bottom: -4px;

  width: 19px;
  height: 19px;

  object-fit: cover;

  border-radius: 50%;

  background: #111118;

  box-shadow:
    0 2px 7px rgba(0,0,0,.7);
}


/* PLAYER NAME */

.cf-preview-name {
  width: 100%;
  max-width: 90px;

  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;

  text-align: center;

  color: rgba(240,241,245,.82);

  font-size: 9px;
  font-weight: 800;

  letter-spacing: .25px;
}


/* ================= CENTER ================= */

.cf-preview-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.cf-preview-vs {
  color: rgba(255,255,255,.22);

  font-size: 9px;
  font-weight: 900;

  letter-spacing: 1px;
}

.cf-preview-winner-coin {
  width: 30px;
  height: 30px;

  object-fit: cover;

  border-radius: 50%;

  filter:
    drop-shadow(0 0 7px rgba(169,116,255,.3));
}


/* ================= FOOTER ================= */

.cf-preview-footer {
  height: 29px;

  padding: 0 9px;

  display: flex;
  align-items: center;
  justify-content: space-between;

  border-top: 1px solid rgba(255,255,255,.055);

  background: rgba(0,0,0,.12);
}

.cf-preview-type {
  display: flex;
  align-items: center;
  gap: 6px;

  color: rgba(255,255,255,.35);

  font-size: 8px;
  font-weight: 800;

  letter-spacing: .8px;
}

.cf-preview-dot {
  width: 4px;
  height: 4px;

  border-radius: 50%;

  background: linear-gradient(135deg, #7b3ff6, #a974ff);

  box-shadow:
    0 0 6px rgba(169,116,255,.6);
}

.cf-preview-view {
  display: flex;
  align-items: center;
  gap: 5px;

  color: #a974ff;

  font-size: 8px;
  font-weight: 900;

  letter-spacing: .6px;

  transition:
    gap .2s ease,
    color .2s ease;
}

.cf-preview-view span {
  font-size: 15px;
  line-height: 1;
}

.cf-chat-preview:hover .cf-preview-view {
  gap: 8px;
  color: #c6a1ff;
}


/* يمنع خط الرسالة البنفسجي من التأثير على البريفيو */
.chat-msg:has(.cf-chat-preview)::before {
  height: 42px;
}