/* ============================================================
   🃏 شلم — میز سبز کلاسیک (مینی‌اپ تلگرام)
   بوم پشمی سبز تیره، ورق‌های سفید با خال قرمز/مشکی، هماهنگ با تم تلگرام
   ============================================================ */

@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-Variable-font-face/fonts/webfonts/Vazirmatn[wght].woff2') format('woff2');
}

:root {
  --bg: #0d2818;
  --felt: #1c6a41;
  --felt-2: #14522f;
  --felt-3: #0f3f25;
  --rim: #6b4423;
  --rim-2: #4a2d15;
  --ink: #f3efe2;
  --ink-dim: #b9c9b4;
  --card-bg: #fbf8ef;
  --card-edge: #c9c2ad;
  --red: #c0392b;
  --black: #20242b;
  --gold: #e3b34c;
  --team-a: #4da3ff;
  --team-b: #ff7b6b;
  --turn: #ffd76a;
  --ok: #58d68d;
}

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

html, body {
  height: 100%;
  font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
  color: var(--ink);
  background: radial-gradient(120% 100% at 50% 0%, #143c26 0%, var(--bg) 70%);
  overscroll-behavior: none;
}

body { user-select: none; -webkit-user-select: none; }
.hidden { display: none !important; }

/* ---------------- دروازه (خارج از تلگرام) ---------------- */
.gate { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.gate-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
  max-width: 340px;
}
.gate-logo { font-size: 56px; margin-bottom: 8px; }
.gate-card h1 { font-size: 20px; margin-bottom: 10px; }
.gate-card p { color: var(--ink-dim); font-size: 14px; line-height: 1.9; margin-bottom: 18px; }
.gate-btn {
  display: inline-block;
  background: linear-gradient(180deg, #2ea6ff, #1f7ed8);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 14px;
  font-size: 15px;
}

/* ---------------- چیدمان کلی ---------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  gap: 6px;
}

/* نوار بالا */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--ink-dim);
}
.tb-title { font-weight: 800; color: var(--gold); font-size: 15px; letter-spacing: 0.3px; }
.tb-item { background: rgba(0, 0, 0, 0.25); padding: 4px 10px; border-radius: 10px; }

/* نوار امتیاز */
#scorebar {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 6px 12px;
}
.score { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.score b { font-size: 19px; font-weight: 800; }
.score .dot { width: 10px; height: 10px; border-radius: 50%; }
.team-a .dot { background: var(--team-a); box-shadow: 0 0 8px var(--team-a); }
.team-b .dot { background: var(--team-b); box-shadow: 0 0 8px var(--team-b); }
.team-a b { color: var(--team-a); }
.team-b b { color: var(--team-b); }
.mid { color: var(--ink-dim); font-size: 12px; }

/* ---------------- میز پشمی ---------------- */
#table { flex: 1; min-height: 0; display: flex; }
.felt {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-radius: 26px;
  padding: 8px 8px;
  background:
    radial-gradient(90% 90% at 50% 40%, var(--felt) 0%, var(--felt-2) 58%, var(--felt-3) 100%);
  border: 5px solid var(--rim);
  outline: 2px solid var(--rim-2);
  box-shadow:
    inset 0 0 40px rgba(0, 0, 0, 0.45),
    inset 0 0 4px rgba(255, 255, 255, 0.06),
    0 12px 30px rgba(0, 0, 0, 0.5);
}
.felt::after {
  content: '';
  position: absolute; inset: 0; border-radius: 20px;
  background: repeating-radial-gradient(circle at 50% 45%, rgba(255,255,255,0.015) 0 2px, transparent 2px 4px);
  pointer-events: none;
}

/* صندلی‌ها — جایگاه ثابت، محتوای چرخان */
.slot-top { display: flex; justify-content: center; }
.slot-bottom { display: flex; justify-content: center; }
.midrow { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 0; }
.slot-left { display: flex; justify-content: flex-start; }
.slot-right { display: flex; justify-content: flex-end; }

.seat {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px;
  border-radius: 14px;
  position: relative;
  max-width: 100%;
  transition: background 0.3s, box-shadow 0.3s;
}

.avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(180deg, #2b3f52, #1d2c3a);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px; color: #fff;
  border: 2.5px solid rgba(255, 255, 255, 0.25);
  flex: 0 0 auto;
}
.seat.team-0 .avatar { border-color: var(--team-a); }
.seat.team-1 .avatar { border-color: var(--team-b); }

.pinfo { display: flex; flex-direction: column; min-width: 0; direction: rtl; }
.pname {
  font-size: 13.5px; font-weight: 700; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 110px;
}
.ptag { font-size: 10.5px; color: var(--ink-dim); }

/* هالهٔ نوبت */
.seat.turn {
  background: rgba(255, 215, 106, 0.10);
  box-shadow: 0 0 0 2px rgba(255, 215, 106, 0.55), 0 0 22px rgba(255, 215, 106, 0.25);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(255, 215, 106, 0.55), 0 0 14px rgba(255, 215, 106, 0.18); }
  50% { box-shadow: 0 0 0 3px rgba(255, 215, 106, 0.9), 0 0 26px rgba(255, 215, 106, 0.35); }
}
.turn-chip {
  font-size: 10px; font-weight: 800; color: #241c04;
  background: var(--turn); border-radius: 8px; padding: 1px 7px;
}

/* نشان حاکم */
.badge-decl {
  position: absolute; top: -4px; inset-inline-start: -2px;
  font-size: 15px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
}

/* دستهٔ ورق بقیهٔ بازیکنان */
.handpile { display: flex; align-items: center; gap: 5px; }
.pile { position: relative; width: 30px; height: 20px; }
.pile::before, .pile::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 4px;
  background: linear-gradient(135deg, #274e8f, #1b3a6d);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
.pile::after { transform: translate(3px, -3px) rotate(6deg); }
.pilecount { font-size: 11px; color: var(--ink-dim); font-weight: 700; }

/* مرکز میز */
.center { position: relative; width: 148px; height: 118px; align-self: center; }
.pot {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 52px; height: 52px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  border: 1.5px dashed rgba(255, 255, 255, 0.35);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
}
.played {
  position: absolute;
  width: 0; height: 0;
  display: flex; align-items: center; justify-content: center;
}
.played .card { position: absolute; transform: translate(-50%, -50%) scale(0.92); box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5); }
.pp-top { top: 4%; left: 50%; }
.pp-bottom { bottom: 4%; left: 50%; }
.pp-left { left: 12%; top: 50%; }
.pp-right { left: 88%; top: 50%; }
.winner-glow .card { box-shadow: 0 0 0 2.5px var(--gold), 0 6px 16px rgba(0, 0, 0, 0.55); }

/* ---------------- ورق‌ها ---------------- */
.card {
  width: 54px; height: 78px;
  border-radius: 9px;
  background: linear-gradient(160deg, #fffef9, var(--card-bg));
  border: 1px solid var(--card-edge);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  position: relative;
  display: flex; flex-direction: column;
  padding: 4px 5px;
  font-family: 'Segoe UI', 'Vazirmatn', sans-serif;
}
.card .rank { font-size: 17px; font-weight: 800; line-height: 1; letter-spacing: -0.5px; }
.card .suit-sm { font-size: 13px; line-height: 1.1; }
.card .suit-big {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; padding-bottom: 6px;
}
.card.red { color: var(--red); }
.card.black { color: var(--black); }
.card.back {
  background: linear-gradient(135deg, #274e8f, #1b3a6d);
  border-color: rgba(255, 255, 255, 0.35);
}

/* دست بازیکن */
#handwrap { flex: 0 0 auto; }
.hand-label {
  font-size: 11.5px; color: var(--ink-dim);
  text-align: center; margin-bottom: 5px;
}
#hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 96px;
  padding-bottom: 4px;
}
#hand .card {
  flex: 0 0 auto;
  margin-inline-start: -26px;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
  touch-action: manipulation;
}
#hand .card:first-child { margin-inline-start: 0; }
#hand .card.playable:hover { transform: translateY(-10px); }
#hand .card.playable:active { transform: translateY(-14px) scale(1.04); }
#hand .card.playable { box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35), 0 0 0 1.5px rgba(255, 255, 255, 0.35); }
#hand .card.dimmed { filter: brightness(0.62) saturate(0.7); }
#hand .card.selected { transform: translateY(-16px); box-shadow: 0 0 0 2.5px var(--ok), 0 8px 16px rgba(0,0,0,0.45); }
#hand .card.gone { opacity: 0; pointer-events: none; }
#hand .card.deal { animation: dealIn 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) backwards; }
@keyframes dealIn {
  0% { transform: translate(-6vw, -34vh) rotate(12deg) scale(0.55); opacity: 0; }
  70% { opacity: 1; }
  100% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
}
#hand .card.shake { animation: shake 0.35s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}

/* ---------------- نوار فاز و عمل‌ها ---------------- */
.phasebar {
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-dim);
  min-height: 18px;
}
.actionbar {
  display: flex; flex-direction: column; gap: 7px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 16px;
  padding: 9px 10px;
}
.chipgrid { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.chip {
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  font-family: inherit;
  font-size: 14.5px; font-weight: 800;
  border-radius: 11px;
  padding: 9px 0;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s;
}
.chip:active { transform: scale(0.96); background: rgba(255, 255, 255, 0.16); }
.chip.wide { font-size: 13.5px; }
.chip.shelem { border-color: rgba(227, 179, 76, 0.6); color: var(--gold); }
.chip.top { border-color: rgba(227, 179, 76, 0.85); color: var(--gold); background: rgba(227, 179, 76, 0.10); }
.chip.pass { border-color: rgba(255, 123, 107, 0.55); color: #ffb0a6; }
.chip.suitbtn { font-size: 16px; }

/* ---------------- نتیجهٔ دست/بازی ---------------- */
.result {
  position: fixed; inset: 0;
  background: rgba(5, 14, 9, 0.72);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
}
.result-card {
  width: 100%; max-width: 340px;
  background: linear-gradient(180deg, #173a27, #102a1c);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  padding: 20px 18px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  animation: pop 0.28s cubic-bezier(0.2, 1.2, 0.4, 1);
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.r-title { font-size: 17px; font-weight: 800; color: var(--gold); margin-bottom: 12px; }
#r-body { font-size: 13.5px; line-height: 2.1; color: var(--ink); }
#r-body .sep { height: 1px; background: rgba(255,255,255,0.1); margin: 8px 0; }
#r-body .win { color: var(--ok); font-weight: 800; }
#r-body .lose { color: #ff9c8f; }
.r-actions { display: flex; gap: 8px; margin-top: 14px; }
.r-actions .chip { flex: 1; }

/* ---------------- توست ---------------- */
.toast {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 22, 15, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--ink);
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 13px;
  max-width: 86vw;
  text-align: center;
  z-index: 60;
  animation: toastIn 0.25s ease;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
}
@keyframes toastIn { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* کارت پرنده (انیمیشن بازی‌شدن کارت) */
.fly-card {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  transition: transform 0.42s cubic-bezier(0.3, 0.9, 0.4, 1), opacity 0.42s;
}

/* مینی‌اپ تمام‌صفحه */
body { padding-top: env(safe-area-inset-top); }

@media (max-height: 640px) {
  .card { width: 48px; height: 70px; }
  #hand { height: 86px; }
  #hand .card { margin-inline-start: -30px; }
  .avatar { width: 38px; height: 38px; font-size: 15px; }
}

/* صندلی‌های کناری — چیدمان ستونی تا نام‌ها نپیچند */
.slot-left .seat, .slot-right .seat {
  flex-direction: column;
  gap: 4px;
  padding: 4px 5px;
}
.slot-left .seat .pinfo, .slot-right .seat .pinfo { align-items: center; }
.slot-left .seat .pname, .slot-right .seat .pname {
  max-width: 70px; text-align: center; font-size: 11.5px;
}
.slot-left .seat .ptag, .slot-right .seat .ptag { font-size: 9.5px; text-align: center; }
.slot-left .seat .avatar, .slot-right .seat .avatar { width: 40px; height: 40px; font-size: 15px; }
.slot-left .seat .handpile, .slot-right .seat .handpile { transform: scale(0.9); }
