/* ════════════════════════════════════════════════════════════════════
   الضومنة — هوية «القهاوة المغربية»
   جوك أخضر دافئ × قطع عاجية منقوشة × إطار نحاسي
   كلاسات معزولة dm- — تعمل داخل المنصة (#gamePageBody) ومستقلة (index.html)
   ════════════════════════════════════════════════════════════════════ */

/* المتغيرات المحلية للعبة (معزولة داخل المسرح) */
.dm-stage {
  --dm-felt-1: #245741;      /* جوك فاتح */
  --dm-felt-2: #123426;      /* جوك غامق */
  --dm-wood-1: #3a2412;      /* خشب داكن */
  --dm-wood-2: #1f1207;
  --dm-ivory-1: #f7f1de;     /* عاجي */
  --dm-ivory-2: #e4d9bb;
  --dm-pip: #2b1c0c;         /* لون النقاط */
  --dm-brass: #c89a4e;       /* نحاس */
  --dm-brass-2: #a97c33;
  --dm-goldtext: #f2d489;
  --dm-ink: #efe6cd;
  --dm-green-ok: #43c78f;

  position: relative;
  display: block;
  height: 100%;
  width: 100%;
  max-width: 100%;
  margin: 0;
  background:
    radial-gradient(120% 100% at 50% 0%, #24301f 0%, #101812 68%, #0a0f0b 100%);
  overflow: hidden;
  font-family: inherit;
  color: var(--dm-ink);
}
/* داخل المنصة: المسرح يملأ الحاوية (app-fs) — بلا دبل ارتفاع (100vh/dvh
   كان يتجاوز الحاوية المُقاسة عبر fitGameStage فيقص أو يظهر شريط) */
#gamePageBody .dm-stage { height: 100%; }

/* ══════════════ الشاشات ══════════════ */
.dm-screen { display: none; position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; }
.dm-screen.dm-screen-active { display: block; }

/* ══════════════ القائمة — بطاقة قائمة القهوة ══════════════ */
.dm-menu-decor {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(60% 34% at 50% 0%, rgba(200, 154, 78, 0.14), transparent 70%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.012) 0 2px, transparent 2px 14px);
}
.dm-menu-card {
  position: relative; max-width: 400px; margin: 4vh auto 20px; padding: 22px 22px 24px;
  background: linear-gradient(165deg, #17251c 0%, #0f1a13 100%);
  border: 2px solid rgba(200, 154, 78, 0.55);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(242, 212, 137, 0.12), 0 18px 50px rgba(0, 0, 0, 0.55);
  text-align: center;
}
.dm-logo { display: flex; justify-content: center; gap: 10px; margin-bottom: 10px; }
.dm-logo-tile {
  width: 36px; height: 64px; border-radius: 7px; position: relative;
  background: linear-gradient(165deg, var(--dm-ivory-1), var(--dm-ivory-2));
  border: 1px solid rgba(90, 66, 30, 0.5);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.75);
  display: flex; flex-direction: column;
  transform: rotate(-8deg);
}
.dm-logo-tile.tilt { transform: rotate(7deg) translateY(5px); }
.dm-title {
  margin: 2px 0 0; font-size: 30px; font-weight: 900; letter-spacing: 1px;
  color: var(--dm-goldtext);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}
.dm-tagline { margin: 4px 0 16px; color: #b9c4ae; font-size: 12.5px; }

.dm-field { margin: 12px 0; text-align: right; }
.dm-flabel { font-size: 12px; font-weight: 800; color: #cdbf9a; margin-bottom: 6px; }
.dm-seg { display: flex; gap: 6px; flex-wrap: wrap; }
.dm-segbtn {
  flex: 1 1 auto; min-width: 70px; padding: 9px 10px; cursor: pointer;
  background: rgba(10, 16, 12, 0.7); color: #b9c4ae;
  border: 1px solid rgba(200, 154, 78, 0.35); border-radius: 8px;
  font-family: inherit; font-size: 12.5px; font-weight: 700;
  transition: all 0.16s ease;
}
.dm-segbtn:hover { border-color: rgba(200, 154, 78, 0.7); color: #e8ddba; }
.dm-segbtn.selected {
  background: linear-gradient(150deg, rgba(200, 154, 78, 0.24), rgba(169, 124, 51, 0.14));
  border-color: var(--dm-brass); color: var(--dm-goldtext);
  box-shadow: 0 0 12px rgba(200, 154, 78, 0.2), inset 0 0 0 1px rgba(242, 212, 137, 0.15);
}

/* الرهان */
.dm-betrow { display: flex; align-items: center; justify-content: center; gap: 10px; }
.dm-betbtn {
  width: 38px; height: 38px; border-radius: 50%; font-size: 19px; cursor: pointer;
  background: rgba(10, 16, 12, 0.8); color: var(--dm-goldtext);
  border: 1px solid rgba(200, 154, 78, 0.5); font-family: inherit;
}
.dm-betfield {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(10, 16, 12, 0.85); border: 1px solid rgba(200, 154, 78, 0.45);
  border-radius: 20px; padding: 6px 14px; color: #f4e9c8;
}
.dm-coin::before { content: '🪙'; font-size: 13px; }
.dm-betinput {
  width: 64px; background: none; border: none; outline: none; color: #f4e9c8;
  font-family: inherit; font-size: 15px; font-weight: 800; text-align: center;
}
.dm-bethint { margin-top: 7px; color: #9aa78e; font-size: 11px; text-align: center; }

/* أزرار البدء */
.dm-go {
  width: 100%; margin-top: 14px; padding: 13px 18px; cursor: pointer;
  background: linear-gradient(135deg, #d9ab57, #a97c33);
  color: #241703; border: none; border-radius: 10px;
  font-family: inherit; font-size: 16px; font-weight: 900;
  box-shadow: 0 5px 18px rgba(200, 154, 78, 0.32);
  transition: transform 0.14s ease, box-shadow 0.2s;
}
.dm-go:hover { transform: translateY(-1px); box-shadow: 0 7px 24px rgba(200, 154, 78, 0.45); }
.dm-go:active { transform: translateY(1px); }
.dm-go.danger { background: linear-gradient(135deg, #b4523f, #8c3324); color: #ffe9dd; box-shadow: 0 5px 18px rgba(180, 82, 63, 0.3); }
.dm-resume {
  width: 100%; margin-top: 9px; padding: 11px 18px; cursor: pointer;
  background: rgba(10, 16, 12, 0.8); color: var(--dm-goldtext);
  border: 1px solid rgba(200, 154, 78, 0.55); border-radius: 10px;
  font-family: inherit; font-size: 14px; font-weight: 800;
}
.dm-ruleslink {
  margin-top: 14px; background: none; border: none; cursor: pointer;
  color: #9aa78e; font-family: inherit; font-size: 12px; font-weight: 700;
  text-decoration: underline; text-underline-offset: 4px;
}
.dm-ruleslink:hover { color: var(--dm-goldtext); }

/* ══════════════ الطبقات (قواعد/نتائج/تأكيد) ══════════════ */
.dm-layer {
  position: absolute; inset: 0; z-index: 30; padding: 16px;
  background: rgba(6, 10, 8, 0.74); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.dm-sheet {
  width: 100%; max-width: 380px; padding: 22px 20px;
  background: linear-gradient(165deg, #17251c, #0e1811);
  border: 2px solid rgba(200, 154, 78, 0.55); border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(242, 212, 137, 0.1);
  text-align: center; max-height: 92%; overflow-y: auto;
}
.dm-sheet.small { max-width: 330px; }
.dm-sheet-em { font-size: 44px; margin-bottom: 4px; }
.dm-sheet-title { font-size: 18px; font-weight: 900; color: var(--dm-goldtext); margin-bottom: 10px; }
.dm-askrow { display: flex; gap: 8px; }
.dm-askrow .dm-go, .dm-askrow .dm-resume { margin-top: 0; }
.dm-rules-doc { text-align: right; }
.dm-rule {
  font-size: 12.5px; line-height: 1.9; color: #cfd8c2;
  padding: 8px 2px; border-bottom: 1px dashed rgba(200, 154, 78, 0.25);
}
.dm-rule b { color: var(--dm-goldtext); }
.dm-scorerows { display: flex; flex-direction: column; gap: 5px; margin: 8px 0 4px; }
.dm-srow {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(8, 13, 10, 0.7); border: 1px solid rgba(200, 154, 78, 0.25);
  border-radius: 8px; padding: 8px 13px; font-size: 13px; color: var(--dm-ink);
}
.dm-srow b { color: #f2d489; font-size: 14px; }
.dm-srow.total { border-color: rgba(200, 154, 78, 0.5); }
.dm-srow b.gold { color: var(--dm-green-ok); }
.dm-amount { font-size: 22px; font-weight: 900; margin: 2px 0 6px; }
.dm-amount .plus { color: var(--dm-green-ok); }

/* توست مستقل (للوضع المستقل فقط — داخل المنصة يُستخدم توست المنصة) */
.dm-toast {
  position: absolute; top: 52px; left: 50%; transform: translateX(-50%) translateY(-6px);
  z-index: 60; background: rgba(14, 22, 17, 0.95); color: #f2e6c4;
  border: 1px solid rgba(200, 154, 78, 0.5); border-radius: 10px;
  padding: 8px 18px; font-size: 12.5px; font-weight: 800;
  opacity: 0; pointer-events: none; transition: all 0.22s ease;
}
.dm-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.dm-toast.err { color: #f0b3a6; border-color: rgba(200, 90, 70, 0.55); }

/* ══════════════ شاشة اللعب ══════════════ */
#dmPlay { display: none; flex-direction: column; padding: 8px; gap: 6px; }
#dmPlay.dm-screen-active { display: flex; }

/* HUD */
.dm-hud {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: linear-gradient(180deg, #241708, #171006);
  border: 1px solid rgba(200, 154, 78, 0.45); border-radius: 10px;
  padding: 5px 10px;
}
.dm-seat { display: flex; align-items: center; gap: 7px; min-width: 0; }
.dm-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  background: radial-gradient(circle at 34% 30%, rgba(200, 154, 78, 0.4), rgba(15, 10, 4, 0.9));
  border: 1.5px solid rgba(200, 154, 78, 0.55); color: var(--dm-goldtext);
  display: flex; align-items: center; justify-content: center; font-size: 12px;
}
.dm-seatmeta { display: flex; flex-direction: column; min-width: 0; }
.dm-seatmeta.end { align-items: flex-end; }
.dm-seatname { font-size: 11.5px; font-weight: 800; color: #e9ddba; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.dm-seatscore { font-size: 17px; font-weight: 900; color: var(--dm-goldtext); line-height: 1.1; }
.dm-hudmid { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 0; flex: 1; }
.dm-hudround { font-size: 10px; color: #9aa78e; font-weight: 700; white-space: nowrap; }
.dm-hudstatus { font-size: 12px; font-weight: 800; color: #f2e6c4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* مقعد الخصم */
.dm-opprow {
  flex: 0 0 auto; min-height: 46px; display: flex; align-items: center; justify-content: center;
  gap: 5px; padding: 5px 8px;
  background: rgba(10, 16, 12, 0.5); border: 1px dashed rgba(200, 154, 78, 0.25); border-radius: 10px;
  overflow-x: auto; scrollbar-width: none;
}
.dm-back {
  width: 21px; height: 40px; border-radius: 5px; flex: 0 0 auto; position: relative;
  background: linear-gradient(160deg, #33241a, #1c1108);
  border: 1px solid rgba(200, 154, 78, 0.4);
  box-shadow: inset 0 0 0 1px rgba(242, 212, 137, 0.08), 0 2px 4px rgba(0, 0, 0, 0.45);
}
.dm-back::after { content: ''; position: absolute; inset: 4px; border-radius: 3px; border: 1px solid rgba(200, 154, 78, 0.25); }
.dm-htile {
  flex: 0 0 auto; width: 23px; height: 43px; border-radius: 4px; padding: 0; position: relative;
  background: linear-gradient(160deg, var(--dm-ivory-1), var(--dm-ivory-2));
  border: 1px solid rgba(90, 66, 30, 0.5);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
.dm-htile .dm-face { position: absolute; }
.dm-htile:disabled { filter: saturate(0.5) brightness(0.8); }
.dm-htile.can { cursor: pointer; border-color: var(--dm-brass); animation: dmPulse 1.6s infinite; }

/* الطاولة — جوك القهوة */
.dm-table {
  position: relative; flex: 1 1 auto; min-height: 140px; overflow: hidden;
  border-radius: 14px;
  border: 3px solid var(--dm-brass);
  background: linear-gradient(180deg, var(--dm-wood-1), var(--dm-wood-2));
  box-shadow: inset 0 0 0 2px rgba(20, 12, 4, 0.8), 0 0 26px rgba(200, 154, 78, 0.14);
}
.dm-felt {
  position: absolute; inset: 0;
  background:
    radial-gradient(115% 90% at 50% 8%, rgba(255, 255, 255, 0.06) 0%, transparent 55%),
    radial-gradient(130% 105% at 50% 40%, var(--dm-felt-1) 0%, var(--dm-felt-2) 82%);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.42);
}
.dm-felt::after {
  content: ''; position: absolute; inset: 0;
  background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.014) 0 2px, transparent 2px 6px);
  pointer-events: none;
}
.dm-chain { position: absolute; inset: 6px 30px; }
.dm-chain-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: rgba(239, 230, 205, 0.55); font-size: 13px; font-weight: 700;
}

/* القطع العاجية */
.dm-tile {
  position: absolute; border-radius: 5px;
  background: linear-gradient(160deg, var(--dm-ivory-1) 0%, #efe6cb 55%, var(--dm-ivory-2) 100%);
  border: 1px solid rgba(90, 66, 30, 0.55);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: transform 0.2s ease;
}
.dm-tile.k-turn { z-index: 3; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.8); }
.dm-tile.dm-pop { animation: dmPop 0.42s ease; }
@keyframes dmPop { 0% { transform: scale(1.4); filter: brightness(1.4); } 100% { transform: scale(1); } }
.dm-face { display: flex; flex-direction: column; width: 100%; height: 100%; }
.dm-half { flex: 1 1 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 11%; gap: 5%; }
.dm-sep { height: 0; margin: 0 13%; border-top: 1.5px solid rgba(90, 66, 30, 0.5); }
.dp-cell { border-radius: 50%; background: rgba(90, 66, 30, 0.1); display: block; }
.dp-cell.on {
  background: radial-gradient(circle at 36% 30%, #59401f, var(--dm-pip));
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.65), 0 1px 0 rgba(255, 255, 255, 0.5);
}

/* تلميحات الأطراف */
.dm-endhint {
  position: absolute; z-index: 8; min-width: 32px; height: 31px; padding: 0 9px;
  border-radius: 16px; cursor: pointer;
  background: rgba(200, 154, 78, 0.2); border: 2px dashed var(--dm-brass);
  color: var(--dm-goldtext); font-family: inherit; font-size: 14px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  animation: dmHint 1s infinite;
}
@keyframes dmHint { 50% { background: rgba(200, 154, 78, 0.36); transform: scale(1.1); } }

/* البنك — خزنة القهاوة */
.dm-boneyard {
  position: absolute; bottom: 8px; inset-inline-end: 8px; z-index: 6;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 9px; border-radius: 10px; cursor: pointer;
  background: rgba(8, 12, 9, 0.62); border: 1px solid rgba(200, 154, 78, 0.35);
  transition: box-shadow 0.2s, border-color 0.2s;
}
.dm-boneyard.dim { opacity: 0.55; }
.dm-boneyard.pulse { border-color: var(--dm-brass); box-shadow: 0 0 16px rgba(200, 154, 78, 0.5); animation: dmHint 1.1s infinite; }
.dm-by-stack { position: relative; width: 24px; height: 42px; }
.dm-by-stack span {
  position: absolute; inset: 0; border-radius: 4px;
  background: linear-gradient(160deg, #33241a, #1c1108);
  border: 1px solid rgba(200, 154, 78, 0.45);
}
.dm-by-stack span:nth-child(1) { transform: translate(-4px, 4px) rotate(-6deg); }
.dm-by-stack span:nth-child(2) { transform: translate(2px, 1px) rotate(3deg); }
.dm-by-count { font-size: 13px; font-weight: 900; color: var(--dm-goldtext); }
.dm-by-label { font-size: 9.5px; color: #9aa78e; font-weight: 800; }

/* اليد */
.dm-handwrap { flex: 0 0 auto; display: flex; align-items: stretch; gap: 8px; }
.dm-hand {
  flex: 1 1 auto; display: flex; align-items: flex-end; justify-content: center; gap: 7px;
  padding: 9px 10px 7px; overflow-x: auto; overflow-y: visible; scrollbar-width: thin;
  background: rgba(10, 16, 12, 0.55); border: 1px solid rgba(200, 154, 78, 0.3); border-radius: 12px;
}
.dm-hand.myturn { border-color: rgba(67, 199, 143, 0.45); box-shadow: 0 0 16px rgba(67, 199, 143, 0.12); }
/* اليد تستخدم نفس صنف dm-htile لكن بحجم أكبر: */
.dm-hand .dm-htile { width: 47px; height: 86px; border-radius: 7px; }
@keyframes dmPulse { 50% { box-shadow: 0 0 20px rgba(200, 154, 78, 0.8), 0 3px 8px rgba(0, 0, 0, 0.45); } }

/* أدوات */
.dm-tools { flex: 0 0 auto; display: flex; flex-direction: column; justify-content: center; gap: 7px; }
.dm-tool {
  padding: 9px 14px; border-radius: 9px; cursor: pointer;
  background: rgba(10, 16, 12, 0.85); color: var(--dm-goldtext);
  border: 1px solid rgba(200, 154, 78, 0.5);
  font-family: inherit; font-size: 12px; font-weight: 800;
  animation: dmPulse 1.3s infinite;
}
.dm-tool.danger { animation: none; border-color: rgba(200, 90, 70, 0.45); color: #eeb3a4; }
.dm-tool:hover { border-color: rgba(200, 154, 78, 0.85); }

/* ══════════════ الاستجابة ══════════════ */
@media (max-width: 640px) {
  .dm-title { font-size: 25px; }
  .dm-hand .dm-htile { width: 41px; height: 75px; }
  .dm-seatname { max-width: 74px; font-size: 10.5px; }
  .dm-hudstatus { font-size: 11px; }
}
@media (max-height: 700px) {
  .dm-hand .dm-htile { width: 38px; height: 69px; }
  .dm-opprow { min-height: 38px; }
  .dm-back { width: 18px; height: 34px; }
  .dm-hud { padding: 4px 8px; }
  .dm-menu-card { margin-top: 2vh; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .dm-menu-card { max-width: 520px; }
}
