/* ====================================================================
   بنت السبيت — تصميم الطاولة
==================================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { color-scheme: dark; }

:root {
  --felt: #0d5c46;
  --felt-dark: #0a4635;
  --bg: #072e24;
  --gold: #d4af37;
  --cream: #f7f3e8;
  --card-red: #c0392b;
  --card-black: #1e2430;
  --danger: #e74c3c;
  --safe: #2ecc71;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Cairo', sans-serif;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--bg) 100%);
  color: var(--cream);
  user-select: none;
}

.hidden { display: none !important; }

/* ---------- الشاشات المنبثقة ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 25, 19, 0.82);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.start-card, .modal {
  background: linear-gradient(160deg, #10453a, #0a3329);
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 20px;
  padding: 28px 24px;
  width: min(440px, 94vw);
  max-height: 90vh; overflow-y: auto;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.logo { font-size: 64px; color: var(--gold); line-height: 1; }
.start-card h1 { font-size: 34px; font-weight: 900; color: var(--gold); margin: 8px 0 2px; }
.subtitle { opacity: .75; margin-bottom: 20px; }
.modal h2 { color: var(--gold); font-weight: 800; margin-bottom: 14px; }
.rules-body { text-align: right; line-height: 1.9; font-size: 14.5px; margin-bottom: 16px; }
.rules-body p { margin-bottom: 8px; }
.rules-body b { color: var(--gold); }

input[type=text] {
  width: 100%; padding: 12px 16px; border-radius: 12px;
  border: 1px solid rgba(212,175,55,.5); background: rgba(0,0,0,.25);
  color: var(--cream); font-family: inherit; font-size: 17px; text-align: center;
  margin-bottom: 14px; outline: none;
}
input[type=text]:focus { border-color: var(--gold); }

.btn {
  font-family: inherit; font-weight: 700; cursor: pointer;
  border: none; border-radius: 12px; padding: 10px 22px; font-size: 15px;
  transition: transform .12s, filter .12s;
}
.btn:active { transform: scale(.96); }
.btn.primary { background: linear-gradient(160deg, #e5c04b, #b8912a); color: #221a05; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--cream); border: 1px solid rgba(247,243,232,.35); }
.btn.big { width: 100%; padding: 14px; font-size: 18px; margin-bottom: 10px; }
.btn.small { padding: 6px 14px; font-size: 13px; }
.btn:disabled { opacity: .4; cursor: default; }
.btn-row { display: flex; gap: 10px; justify-content: center; }
.btn-row .btn { min-width: 110px; }

/* ---------- تخطيط الطاولة ---------- */
#table { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: rgba(0,0,0,.28);
}
.brand { font-weight: 900; color: var(--gold); font-size: 16px; }
.round-info { font-size: 13px; opacity: .85; }

.felt { position: relative; flex: 1; min-height: 0; }

/* ---------- المقاعد ---------- */
.seat {
  position: absolute; display: flex; flex-direction: column; align-items: center; gap: 3px;
  z-index: 5;
}
.seat-top   { top: 8px; left: 50%; transform: translateX(-50%); }
.seat-left  { left: 8px; top: 42%; transform: translateY(-50%); }
.seat-right { right: 8px; top: 42%; transform: translateY(-50%); }
.seat-me    { position: static; flex-direction: row; justify-content: center; gap: 10px; padding: 2px 0; }

.seat .avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(0,0,0,.35); border: 2px solid rgba(212,175,55,.45);
  display: flex; align-items: center; justify-content: center; font-size: 24px;
  position: relative;
}
.seat.turn .avatar { border-color: var(--gold); box-shadow: 0 0 14px rgba(212,175,55,.75); }
.seat .pname { font-size: 13px; font-weight: 700; }
.seat .pstats { font-size: 11px; opacity: .8; display: flex; gap: 6px; }
.seat-me .pname, .seat-me .pstats { display: inline-block; }
.seat-me { font-size: 13px; }

.badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.badge {
  font-size: 9px; font-weight: 800; padding: 1px 6px; border-radius: 20px;
  background: var(--danger); color: #fff; line-height: 1.5;
}
.badge.minus { background: #8e44ad; }
.badge.cardback-count { background: rgba(0,0,0,.4); border: 1px solid rgba(255,255,255,.2); }

/* ---------- منطقة اللمة ---------- */
.trick-area {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
}
.trick-slot { position: absolute; left: 50%; top: 56%; transition: all .25s ease; z-index: 9; }
.trick-slot .card { --card-w: var(--trick-w); box-shadow: 0 12px 26px rgba(0,0,0,.55); }
/* معيّن مُجمّع حول المركز — يتكيّف مع أي شاشة (0=أسفل، 1=يمين، 2=أعلى، 3=يسار) */
.slot-0 { transform: translate(-50%, calc(-50% + var(--trick-w) * 0.84)); }
.slot-2 { transform: translate(-50%, calc(-50% - var(--trick-w) * 0.84)); }
.slot-1 { transform: translate(calc(-50% + var(--trick-w) * 0.98), -50%); }
.slot-3 { transform: translate(calc(-50% - var(--trick-w) * 0.98), -50%); }

.table-msg {
  position: absolute; bottom: 2%; left: 50%; transform: translateX(-50%);
  font-size: 13.5px; font-weight: 700; color: var(--gold);
  background: rgba(0,0,0,.4); border-radius: 20px; padding: 4px 16px;
  white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
.table-msg:empty { display: none; }

/* أحجام الورق — مرنة مع الشاشة (يد اللاعب + الورق المرمي أكبر) */
:root {
  --card-w: clamp(56px, 16vw, 82px);   /* ورق اليد */
  --trick-w: clamp(70px, 19vw, 94px);  /* الورق المرمي على الطاولة — أكبر */
}

/* ---------- الورق ---------- */
.card {
  width: var(--card-w); height: calc(var(--card-w) * 1.4); border-radius: calc(var(--card-w) * 0.12);
  background: linear-gradient(180deg, #ffffff 0%, #f4f1e8 100%);
  border: 1px solid #c9c2ac;
  box-shadow: 0 5px 12px rgba(0,0,0,.42);
  position: relative; display: flex; align-items: center; justify-content: center;
  font-weight: 900;
  flex-shrink: 0;
}
.card .corner {
  position: absolute; top: calc(var(--card-w) * 0.07); right: calc(var(--card-w) * 0.1);
  font-size: calc(var(--card-w) * 0.32); line-height: .95; text-align: center; font-weight: 900;
}
.card .corner small { display: block; font-size: calc(var(--card-w) * 0.28); }
.card .center-sym { font-size: calc(var(--card-w) * 0.58); opacity: .92; }
.card.red { color: var(--card-red); }
.card.black { color: var(--card-black); }
.card.selectable { cursor: pointer; }
.card.disabled { filter: brightness(.62); }
.card.selected { transform: translateY(calc(var(--card-w) * -0.26)); box-shadow: 0 12px 22px rgba(0,0,0,.5), 0 0 0 3px var(--gold); z-index: 4; }
.card.point-card { box-shadow: 0 3px 8px rgba(0,0,0,.35), inset 0 0 0 2px rgba(192,57,43,.55); }

.card-back {
  width: 34px; height: 48px; border-radius: 6px;
  background: repeating-linear-gradient(45deg, #7c1f1f, #7c1f1f 4px, #641616 4px, #641616 8px);
  border: 2px solid #d8cfb6; box-shadow: 0 2px 5px rgba(0,0,0,.4);
}

/* ---------- يدي ---------- */
.my-area { padding: 4px 6px calc(10px + env(safe-area-inset-bottom)); background: rgba(0,0,0,.22); }
.action-bar { display: flex; justify-content: center; gap: 10px; min-height: 40px; align-items: center; padding: 4px 0; }
.hand {
  display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 6px 6px 2px;
}
.hand-row { display: flex; justify-content: center; align-items: flex-end; }
.hand-row .card { margin-left: calc(var(--card-w) * -0.40); transition: transform .15s, box-shadow .15s; }
.hand-row .card:first-child { margin-left: 0; }
.hand-row .card.selectable:hover { transform: translateY(calc(var(--card-w) * -0.17)); z-index: 3; }
.hand-row .card.selected:hover { transform: translateY(calc(var(--card-w) * -0.26)); }
/* الورقة المسموح لعبها تبان بإطار ذهبي خفيف (بدون هوفر على الجوال) */
.hand-row .card.selectable { box-shadow: 0 5px 12px rgba(0,0,0,.42), 0 0 0 2px rgba(217,180,74,.5); }

/* ---------- نافذة القرار ---------- */
.small-modal { width: min(360px, 92vw); }
.prompt-card { display: flex; justify-content: center; margin: 12px 0 18px; }
.prompt-card .card { width: 72px; height: 102px; }
.prompt-card .card .center-sym { font-size: 40px; }

/* ---------- القيد ---------- */
#scoreTable table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 14px; }
#scoreTable th, #scoreTable td { padding: 7px 6px; text-align: center; border-bottom: 1px solid rgba(247,243,232,.12); }
#scoreTable th { color: var(--gold); font-weight: 800; }
#scoreTable tr.totals td { font-weight: 900; color: var(--gold); border-top: 2px solid rgba(212,175,55,.5); }
#scoreTable td.neg { color: var(--safe); }

/* ---------- نهاية الجولة ---------- */
.round-scores { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.rs-row {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(0,0,0,.25); border-radius: 12px; padding: 9px 14px; font-size: 14.5px;
}
.rs-row .rs-pts { font-weight: 900; font-size: 17px; }
.rs-row .rs-pts.neg { color: var(--safe); }
.rs-row .rs-pts.pos { color: #f1c40f; }
.rs-note { font-size: 11px; opacity: .75; }
.winner-banner { font-size: 22px; font-weight: 900; color: var(--gold); margin-bottom: 8px; }

/* ---------- توست ---------- */
.toast {
  position: fixed; top: 54px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.85); border: 1px solid rgba(212,175,55,.5);
  color: var(--cream); font-weight: 700; font-size: 14px;
  padding: 9px 20px; border-radius: 30px; z-index: 60;
  animation: toastIn .25s ease;
  max-width: 90vw; text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- جوال ---------- */
@media (max-width: 620px) {
  .seat .avatar { width: 36px; height: 36px; font-size: 18px; }
  .seat-left, .seat-right { top: 30%; }   /* نرفع المقاعد الجانبية فوق منطقة اللمة */
}

/* ---------- أزرار القرار (تدبيل / قري) ---------- */
.btn.toggle { border: 1px solid rgba(212,175,55,.55); background: rgba(0,0,0,.3); color: var(--cream); }
.btn.toggle.active { background: linear-gradient(160deg, #e5c04b, #b8912a); color: #221a05; box-shadow: 0 0 10px rgba(212,175,55,.6); }
.badge.dealer { background: rgba(0,0,0,.45); border: 1px solid rgba(212,175,55,.6); color: var(--gold); }

/* ---------- الورقة الآكلة + آخر لمة ---------- */
.card.winner-card { box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(212,175,55,.9); z-index: 3; }
.last-trick {
  position: absolute; top: 6px; right: 10px; z-index: 6;
  background: rgba(0,0,0,.42); border: 1px solid rgba(212,175,55,.35);
  border-radius: 10px; padding: 5px 9px; font-size: 11px;
}
.lt-title { color: var(--gold); font-weight: 700; margin-bottom: 3px; }
.lt-cards { display: flex; gap: 4px; }
.lt-card {
  background: var(--cream); border-radius: 4px; padding: 1px 5px;
  font-weight: 800; font-size: 11.5px;
}
.lt-card.red { color: var(--card-red); }
.lt-card.black { color: var(--card-black); }
.lt-card.win { outline: 2px solid var(--gold); }
@media (max-width: 620px) { .last-trick { top: 4px; right: 6px; } }

/* ---------- مكافآت نهاية اللعبة ---------- */
.reward-box { background: rgba(0,0,0,.3); border: 1px solid var(--gold-soft, rgba(212,175,55,.35)); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.rw-line { font-weight: 800; font-size: 15px; margin: 3px 0; }
.rw-line.up { color: #2ecc71; }
.rw-line.down { color: #e74c3c; }
.rw-line small { opacity: .7; font-weight: 400; }
.rw-ach { margin-top: 6px; color: var(--gold); font-weight: 800; font-size: 14px; }
