/* ============================================================================
   مافیا سیندیکیت — استایل مینی‌اپ (Dark Gaming / RTL / Glassmorphism)
   پالت رسمی سند UI/UX v3.0:
   پس‌زمینه #0D0F12 | کارت #1A1D24 | حاشیه #262B36
   قرمز مافیایی #E53935 | سبز #4CAF50 | طلایی #FFD700 | آبی #1E88E5 | بنفش #AB47BC
   ============================================================================ */

:root {
  --bg: #0d0f12;
  --surface: #141720;
  --card: #1a1d24;
  --card-elevated: #232731;
  --border: #262b36;
  --border-glow: rgba(255, 255, 255, 0.14);
  --text: #f5f7fb;
  --text-2: #9ea8b6;
  --text-3: #626c7a;
  --mafia: #e53935;
  --mafia-soft: rgba(229, 57, 53, 0.16);
  --alive: #4caf50;
  --alive-soft: rgba(76, 175, 80, 0.16);
  --gold: #ffd700;
  --gold-soft: rgba(255, 215, 0, 0.16);
  --blue: #1e88e5;
  --blue-soft: rgba(30, 136, 229, 0.16);
  --violet: #ab47bc;
  --radius: 14px;
  --gutter: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  user-select: none;
  padding-top: calc(env(safe-area-inset-top, 0px) + 96px);
}

::-webkit-scrollbar { display: none; }
.dir-ltr { direction: ltr; }

/* ------------------------------- هدر بالایی ------------------------------- */

.top-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  background: rgba(20, 23, 32, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) var(--gutter) 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.header-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.header-row.second { justify-content: space-between; }

.header-user { display: flex; align-items: center; gap: 8px; min-width: 0; }
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--card-elevated);
  border: 1.5px solid var(--border-glow);
  flex-shrink: 0;
}
.header-user-info { display: flex; flex-direction: column; min-width: 0; }
.header-name { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-status { font-size: 10.5px; font-weight: 600; color: var(--alive); }
.header-status.dead { color: var(--mafia); }
.header-status.god { color: var(--gold); }

.header-left { display: flex; align-items: center; gap: 6px; }

.room-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--card-elevated);
  border: 1px solid var(--border);
  color: var(--gold);
  padding: 6px 10px;
  border-radius: 10px;
  font: 700 12px/1 'Vazirmatn', sans-serif;
  min-height: 36px;
  cursor: pointer;
}
.room-chip .copy-hint { font-size: 10px; color: var(--text-3); background: var(--card); padding: 2px 5px; border-radius: 5px; }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--card-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

.phase-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
}
.phase-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.phase-badge.waiting .dot { background: var(--text-2); }
.phase-badge.reveal .dot { background: var(--gold); animation: pulse 1.2s infinite; }
.phase-badge.night { color: #b39ddb; border-color: rgba(179, 157, 219, 0.4); }
.phase-badge.night .dot { background: #b39ddb; animation: pulse 1.2s infinite; }
.phase-badge.day { color: var(--alive); border-color: rgba(76, 175, 80, 0.4); }
.phase-badge.day .dot { background: var(--alive); animation: pulse 1.2s infinite; }
.phase-badge.finished { color: var(--text-2); }
.protocol-tag { font-size: 10px; color: var(--text-3); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* --------------------------------- چیدمان --------------------------------- */

main {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 var(--gutter) 32px;
  display: flex;
  flex-direction: column;
  gap: var(--gutter);
}

.screen { display: flex; flex-direction: column; gap: var(--gutter); animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}
.card.center { align-items: center; text-align: center; }

.card-title { margin: 0; font-size: 15px; font-weight: 800; }

.hero-card {
  background: linear-gradient(160deg, var(--card) 0%, #1d1013 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.hero-emblem { font-size: 46px; filter: drop-shadow(0 0 14px rgba(229, 57, 53, 0.5)); }
.hero-title { margin: 0; font-size: 22px; font-weight: 900; color: var(--mafia); }
.hero-sub { margin: 0; color: var(--text-2); font-size: 13px; }
.auth-ok { display: flex; align-items: center; gap: 6px; color: var(--alive); font-size: 12px; font-weight: 700; }

.notice-card {
  background: rgba(255, 215, 0, 0.06);
  border: 1px solid rgba(255, 215, 0, 0.25);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 2;
}
.notice-card p { margin: 4px 0; }

/* --------------------------------- اجزا ---------------------------------- */

.btn {
  border: 1px solid var(--border-glow);
  background: var(--card-elevated);
  color: var(--text);
  font: 700 14px/1.2 'Vazirmatn', sans-serif;
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
  min-height: 44px;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, #b71c1c, var(--mafia)); border-color: rgba(229, 57, 53, 0.6); box-shadow: 0 4px 18px rgba(229, 57, 53, 0.3); }
.btn.confirm { background: linear-gradient(135deg, #1b5e20, var(--alive)); border-color: rgba(76, 175, 80, 0.6); box-shadow: 0 4px 18px rgba(76, 175, 80, 0.3); }
.btn.day { background: linear-gradient(135deg, #1565c0, var(--blue)); border-color: rgba(30, 136, 229, 0.6); }
.btn.night { background: linear-gradient(135deg, #4527a0, #7e57c2); border-color: rgba(126, 87, 194, 0.6); }
.btn.danger-soft { background: var(--mafia-soft); color: #ff8a80; border-color: rgba(229, 57, 53, 0.4); }
.btn.ghost { background: var(--card); }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: 12.5px; border-radius: 10px; }
.btn.gold { background: var(--gold-soft); color: var(--gold); border-color: rgba(255, 215, 0, 0.4); }
.btn.w-100 { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }
.btn-col { display: flex; flex-direction: column; gap: 8px; }

.input {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font: 500 15px/1.4 'Vazirmatn', sans-serif;
  padding: 12px 14px;
  min-height: 48px;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--mafia); }
.input::placeholder { color: var(--text-3); }

.muted { color: var(--text-2); font-size: 13px; margin: 0; }
.small { font-size: 12px; }
.center { text-align: center; }
.chip {
  font-size: 11px; font-weight: 700;
  background: var(--card-elevated);
  border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px;
  color: var(--text-2);
}
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.progress {
  height: 8px; border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--mafia), #ff7043);
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* ------------------------------ لابی و صندلی‌ها ---------------------------- */

.seats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
.seat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  text-align: center;
  min-height: 76px;
  justify-content: center;
}
.seat .seat-num {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--card-elevated); color: var(--text-2);
  font-size: 10.5px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.seat .seat-name { font-size: 11.5px; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .seat-badge { font-size: 9.5px; font-weight: 700; color: var(--text-3); }
.seat.god .seat-num { background: var(--gold-soft); color: var(--gold); }
.seat.god { border-color: rgba(255, 215, 0, 0.35); }
.seat.dead { opacity: 0.45; }
.seat.ready .seat-badge { color: var(--alive); }
.seat.me { border-color: var(--mafia); box-shadow: 0 0 0 1px var(--mafia-soft); }

.chat-box {
  max-height: 220px;
  min-height: 120px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}
.chat-msg {
  background: var(--card-elevated);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 12.5px;
  line-height: 1.6;
  max-width: 88%;
  align-self: flex-start;
}
.chat-msg.mine { align-self: flex-end; background: var(--mafia-soft); border: 1px solid rgba(229, 57, 53, 0.3); }
.chat-msg .sender { font-size: 10px; font-weight: 800; color: var(--gold); display: block; margin-bottom: 2px; }
.chat-msg.reply { border-right: 2px solid var(--blue); }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row .input { min-height: 44px; flex: 1; }

/* ------------------------------ کارت افشای نقش ----------------------------- */

.flip-wrap {
  width: 230px; height: 320px;
  perspective: 1000px;
  cursor: pointer;
  margin: 6px 0;
}
.flip-inner {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}
.flip-wrap.revealed .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 18px;
}
.flip-back {
  background:
    repeating-linear-gradient(45deg, #1a1d24 0 10px, #14171f 10px 20px);
  border: 2px solid var(--border-glow);
  font-size: 15px; font-weight: 800;
}
.flip-back .big-emoji { font-size: 52px; filter: drop-shadow(0 0 16px rgba(229, 57, 53, 0.6)); }
.flip-front {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, var(--card-elevated), #10131a);
  border: 2px solid var(--border-glow);
  text-align: center;
}
.flip-front .role-emoji { font-size: 56px; }
.flip-front .role-name { font-size: 20px; font-weight: 900; }
.flip-front .role-faction { font-size: 11px; font-weight: 800; padding: 4px 12px; border-radius: 999px; }
.flip-front .role-desc { font-size: 11.5px; color: var(--text-2); line-height: 1.9; max-height: 118px; overflow-y: auto; }
.faction-mafia { background: var(--mafia-soft); color: #ff8a80; }
.faction-citizen { background: var(--blue-soft); color: #64b5f6; }
.faction-god { background: var(--gold-soft); color: var(--gold); }

/* --------------------------- نوار چرخه و تریبون ---------------------------- */

.cycle-card {
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(135deg, var(--card), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 800; font-size: 14px;
}
.cycle-card .cycle-sub { font-size: 11px; color: var(--text-2); font-weight: 600; }
.cycle-card.night { border-color: rgba(179, 157, 219, 0.35); box-shadow: 0 0 24px rgba(126, 87, 194, 0.15); }
.cycle-card.day { border-color: rgba(76, 175, 80, 0.35); box-shadow: 0 0 24px rgba(76, 175, 80, 0.12); }

.speaker-card {
  border-color: rgba(255, 215, 0, 0.4);
  background: linear-gradient(150deg, var(--card), rgba(255, 215, 0, 0.05));
}
.speaker-name { font-size: 17px; font-weight: 900; color: var(--gold); }
.timer-num { font-size: 26px; font-weight: 900; direction: ltr; font-variant-numeric: tabular-nums; }
.speaker-note { font-size: 11.5px; color: var(--text-3); }

/* --------------------------------- چالش ---------------------------------- */

.challenge-card { border-color: rgba(171, 71, 188, 0.4); }
.challenge-title { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 14px; }
.challenge-status { font-size: 12.5px; line-height: 2; }
.status-pending { color: var(--gold); }
.status-granted { color: var(--alive); }
.status-rejected { color: #ff8a80; }
.status-done { color: var(--text-2); }
.status-none { color: var(--text-2); }

/* ------------------------------- رأی‌گیری --------------------------------- */

.vote-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.vote-item.selected { border-color: var(--mafia); background: var(--mafia-soft); }
.vote-item .vote-name { font-size: 13px; font-weight: 700; }
.vote-item .vote-count { font-size: 12px; font-weight: 900; color: var(--gold); min-width: 26px; text-align: center; }
.vote-bar { height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.vote-bar > div { height: 100%; background: linear-gradient(90deg, var(--gold), #ffa000); transition: width 0.3s; }
.voters-line { font-size: 10.5px; color: var(--text-3); margin-top: 4px; line-height: 1.8; }
.quota-hint { font-size: 11px; color: var(--text-2); background: var(--surface); padding: 8px 10px; border-radius: 10px; line-height: 1.9; }

/* ------------------------------ پنل گرداننده ------------------------------ */

.god-grid { display: flex; flex-direction: column; gap: 14px; }
.god-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.god-block h3 { margin: 0; font-size: 13px; font-weight: 800; color: var(--gold); }

.wake-toggles { display: flex; gap: 8px; }
.wake-btn {
  flex: 1;
  min-height: 48px;
  border-radius: 12px;
  border: 1.5px solid rgba(229, 57, 53, 0.5);
  background: var(--mafia-soft);
  color: #ff8a80;
  font: 800 12.5px/1.2 'Vazirmatn', sans-serif;
  cursor: pointer;
  transition: all 0.2s;
}
.wake-btn.active {
  border-color: rgba(76, 175, 80, 0.6);
  background: var(--alive-soft);
  color: #81c784;
  box-shadow: 0 0 14px rgba(76, 175, 80, 0.25);
}

.players-mini-list { display: flex; flex-direction: column; gap: 6px; max-height: 190px; overflow-y: auto; }
.player-mini {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12.5px;
}
.player-mini.speaking { border-color: var(--gold); background: var(--gold-soft); }
.player-mini .pm-actions { display: flex; gap: 6px; }

.log-box {
  max-height: 240px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  font-size: 11px;
}
.log-line {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  line-height: 1.8;
  color: var(--text-2);
}
.log-line b { color: var(--text); }

.night-calc-line {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 12.5px;
}

/* ----------------------------- انتخاب هدف شب ------------------------------ */

.target-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.target-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 10px 6px;
  color: var(--text);
  font: 700 12px/1.3 'Vazirmatn', sans-serif;
  min-height: 52px;
  cursor: pointer;
}
.target-btn.selected { border-color: var(--mafia); background: var(--mafia-soft); box-shadow: 0 0 12px rgba(229, 57, 53, 0.25); }
.target-btn.doctor-selected { border-color: var(--alive); background: var(--alive-soft); }
.target-btn:disabled { opacity: 0.4; }

.fire-btn {
  background: linear-gradient(135deg, #7f0000, var(--mafia));
  border: 1.5px solid rgba(229, 57, 53, 0.7);
  box-shadow: 0 0 24px rgba(229, 57, 53, 0.45);
  font-weight: 900;
  font-size: 15px;
}

.inquiry-result {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 12px;
}
.result-mafia { color: #ff8a80; font-weight: 900; }
.result-citizen { color: #64b5f6; font-weight: 900; }

.quick-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.quick-chip {
  background: var(--card-elevated);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: 999px;
  font: 700 11px/1 'Vazirmatn', sans-serif;
  padding: 7px 12px;
  cursor: pointer;
  min-height: 32px;
}

/* -------------------------------- پروفایل -------------------------------- */

.profile-avatar { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); }
.stats-row { display: flex; gap: 10px; width: 100%; }
.stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.stat-num { font-size: 20px; font-weight: 900; color: var(--gold); }
.stat-label { font-size: 10.5px; color: var(--text-2); }

/* --------------------------------- مودال ---------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  width: 100%; max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border-glow);
  border-radius: 18px;
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: none; } }
.modal h3 { margin: 0; font-size: 15px; }
#modalBody { font-size: 13.5px; color: var(--text-2); line-height: 2; }

/* --------------------------------- توست ---------------------------------- */

#toastRoot {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: rgba(35, 39, 49, 0.95);
  border: 1px solid var(--border-glow);
  color: var(--text);
  font-size: 12.5px; font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.25s ease;
  max-width: 90%;
  text-align: center;
}
.toast.error { border-color: rgba(229, 57, 53, 0.6); color: #ff8a80; }
.toast.success { border-color: rgba(76, 175, 80, 0.6); color: #81c784; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ------------------------------ پایان بازی -------------------------------- */

.finished-card { border-color: rgba(255, 215, 0, 0.5); align-items: center; text-align: center; }
.winner-title { font-size: 20px; font-weight: 900; margin: 0; }
.win-citizen { color: #64b5f6; }
.win-mafia { color: #ff8a80; }
.win-draw { color: var(--gold); }
.reveal-list { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.reveal-line {
  display: flex; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-size: 12.5px;
}

/* ----------------------------- اسکرول‌بار سفارشی --------------------------- */

.chat-box, .log-box, .players-mini-list, .role-desc { scrollbar-width: thin; }
.chat-box::-webkit-scrollbar, .log-box::-webkit-scrollbar, .players-mini-list::-webkit-scrollbar { width: 4px; }
.chat-box::-webkit-scrollbar-thumb, .log-box::-webkit-scrollbar-thumb, .players-mini-list::-webkit-scrollbar-thumb {
  background: var(--border-glow); border-radius: 999px;
}

/* ------------------------------ موبایل / تبلت ----------------------------- */

@media (max-width: 360px) {
  .seats-grid { grid-template-columns: repeat(2, 1fr); }
  .flip-wrap { width: 200px; height: 290px; }
}
@media (min-width: 480px) {
  main { padding-bottom: 48px; }
}
