/* Telegram tema dəyişənləri (--tg-theme-*) telegram-web-app.js tərəfindən avtomatik təyin olunur */
:root {
  --bg: var(--tg-theme-bg-color, #15121b);
  --card: var(--tg-theme-secondary-bg-color, #1f1b29);
  --text: var(--tg-theme-text-color, #f3f0f8);
  --hint: var(--tg-theme-hint-color, #9d97ab);
  --accent: var(--tg-theme-button-color, #c0392b);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(128, 128, 128, 0.25);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body {
  padding: 12px 12px calc(12px + var(--safe-b));
  min-height: var(--tg-viewport-stable-height, 100vh);
}
.hidden { display: none !important; }
.center { display: grid; place-content: center; justify-items: center; min-height: 70vh; text-align: center; color: var(--hint); gap: 8px; }

.app { display: grid; gap: 12px; max-width: 560px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--radius); padding: 12px; }
h2 { margin: 0; color: var(--text); }
h3 { margin: 0 0 8px; font-size: 15px; }
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-head h3 { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.muted { color: var(--hint); margin: 8px 0 0; font-size: 13px; }
.small-text { font-size: 12px; }

input:not([type="checkbox"]) {
  flex: 1; min-width: 0; width: 100%;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font: inherit;
}

.btn {
  background: var(--accent); color: var(--accent-text);
  border: 0; border-radius: 10px; padding: 10px 14px;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:active, .icon-btn:active { transform: scale(0.96); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.me { display: flex; gap: 10px; align-items: center; min-width: 0; }
.me-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; gap: 6px; margin-top: 2px; }
.chip { background: var(--bg); border-radius: 999px; padding: 2px 10px; font-size: 13px; }
body.is-owner #chipCoins { color: #f5c542; font-weight: 700; }

.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  background: var(--bg); display: grid; place-items: center;
  overflow: hidden; font-size: 18px; font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; cursor: pointer; }
.switch-row small { display: block; color: var(--hint); font-size: 12px; }
.switch-row input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 46px; height: 28px; padding: 0; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line);
  position: relative; transition: background 0.2s;
}
.switch-row input::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--hint); transition: transform 0.2s, background 0.2s;
}
.switch-row input:checked { background: var(--accent); }
.switch-row input:checked::after { transform: translateX(18px); background: #fff; }

#connState[data-state="open"] { color: #4cd07d; }
#connState[data-state="reconnecting"] { color: #e8b64a; }

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.player { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.player.offline { opacity: 0.45; }
.pname { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pname small { display: block; color: var(--hint); font-weight: 400; }
.actions { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line); background: transparent;
  color: var(--text); font-size: 16px; cursor: pointer;
}
.empty { color: var(--hint); }

.gift-tray { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.gift {
  flex: none; display: grid; justify-items: center; gap: 2px;
  padding: 8px 12px; border-radius: 12px; border: 2px solid transparent;
  background: var(--bg); color: var(--text); cursor: pointer;
}
.gift.selected { border-color: var(--accent); }
.gift-emoji { font-size: 28px; line-height: 1.1; }
.gift-price { font-size: 12px; color: var(--hint); }

.chat-log {
  list-style: none; margin: 0 0 8px; padding: 0;
  height: 180px; overflow-y: auto; display: grid; align-content: start; gap: 4px;
}
.chat-log li { word-break: break-word; }
.chat-log .sys { color: var(--hint); font-size: 13px; }
.chat-log .mine b { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: rgba(0, 0, 0, 0.85); color: #fff;
  padding: 10px 16px; border-radius: 12px; max-width: 90vw; z-index: 100;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

dialog {
  border: 0; border-radius: var(--radius);
  background: var(--card); color: var(--text);
  padding: 16px; width: min(92vw, 360px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog .row { margin-top: 12px; }
dialog .row .btn { flex: 1; }

/* ---------------- Hədiyyə animasiyaları (yalnız transform/opacity: GPU-dostu) ---------------- */
.fx-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.fx { position: absolute; left: 0; right: 0; text-align: center; will-change: transform, opacity; }
.fx-emoji { font-size: 64px; line-height: 1; filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.45)); }
.fx-caption {
  display: inline-block; margin-top: 6px; padding: 4px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 13px; max-width: 80vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* float: aşağıdan yuxarı süzülür */
.fx-float { bottom: -90px; animation: fx-float 3.2s ease-out forwards; }
@keyframes fx-float {
  0%   { transform: translate(var(--x, 0), 0) scale(0.6); opacity: 0; }
  12%  { opacity: 1; }
  100% { transform: translate(calc(var(--x, 0) + 24px), -75vh) scale(1.25); opacity: 0; }
}

/* drop: yuxarıdan düşüb yerində sıçrayır */
.fx-drop { top: -110px; animation: fx-drop 2.4s cubic-bezier(0.3, 1.4, 0.5, 1) forwards; }
@keyframes fx-drop {
  0%   { transform: translateY(0) rotate(-12deg); opacity: 0; }
  15%  { opacity: 1; }
  60%  { transform: translateY(48vh) rotate(8deg); }
  100% { transform: translateY(48vh) rotate(0); opacity: 0; }
}

/* zoom: mərkəzdə böyüyür */
.fx-zoom { top: 36%; animation: fx-zoom 2.6s ease-out forwards; }
.fx-zoom .fx-emoji { font-size: 110px; }
@keyframes fx-zoom {
  0%   { transform: scale(0.2); opacity: 0; }
  25%  { transform: scale(1.5); opacity: 1; }
  70%  { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1.8); opacity: 0; }
}

/* burst: partlayış (hissəciklər JS tərəfindən yaradılır) */
.fx-burst { top: 38%; animation: fx-life 2.6s linear forwards; }
@keyframes fx-life { from { opacity: 1; } to { opacity: 1; } }
.fx-burst .fx-emoji { animation: fx-pop 0.6s ease-out; }
@keyframes fx-pop { 0% { transform: scale(0.2); } 60% { transform: scale(1.4); } 100% { transform: scale(1); } }
.fx-burst .p { position: absolute; left: 50%; top: 20px; font-size: 32px; animation: fx-particle 1.8s ease-out forwards; }
@keyframes fx-particle {
  0%   { transform: translate(-50%, 0) scale(0.3); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), var(--dy)) scale(1.2); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .fx { animation-duration: 1.2s !important; }
}
