/* ===================================================
   الشكّبة الليبية — Hi-fi Prototype
   =================================================== */

:root {
  --libyan-gold: #C9A961;
  --libyan-gold-bright: #FFD700;
  --phoenician-red: #8B2635;
  --mediterranean: #1B4965;
  --sand: #E8DCC4;
  --olive-libya: #6B7F50;
  --terracotta: #C65D32;
  --midnight: #1A1A2E;
  --ivory: #FFF8E7;
  --felt-green: #1F4D3A;
  --felt-dark: #163B2C;
  --felt-deep: #0E2A1F;
  --hayya-glow: #FFD700;
  --wood: #4a2f1c;
  --wood-light: #6b4427;
  --wood-shadow: #2a1810;

  --pace: 600ms;
  --pace-fast: 300ms;
  --pace-slow: 1200ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-back: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Cairo', 'Segoe UI', system-ui, sans-serif;
  background: #0a0a0f;
  color: var(--ivory);
}

button { font-family: inherit; cursor: pointer; border: none; }

.game-score-preview-a11y {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .scene { grid-template-rows: clamp(160px, 20vh, 200px) 1fr clamp(180px, 22vh, 240px); }
  .bot-zone, .player-zone { grid-template-columns: 1fr; }
  .player-zone .profile-with-pile { justify-self: start; flex-direction: row; }
  .captures-pile { width: 64px; height: 88px; }
  .captures-pile .cp-stack { width: 56px; height: 78px; }
  .captures-pile .cp-count { font-size: 24px; }
  .felt { padding: 12px; }
}
@media (max-width: 600px) {
  .scene { grid-template-rows: 150px 1fr 200px; }
  .table-cards-grid { gap: 8px 10px; }
}

/* ============ SCENE ============ */
.scene {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: clamp(180px, 22vh, 240px) 1fr clamp(200px, 26vh, 280px);
  background: var(--bg-base, radial-gradient(ellipse at 50% 50%, #1a2a22 0%, #050807 90%));
  transition: background 600ms ease;
  container-type: inline-size;
  /* iPhone notch / dynamic island: `position: fixed; inset: 0` puts
     the scene at the absolute viewport edge under `viewport-fit=cover`,
     which on a notched iPhone hides whatever sits on the right edge
     (where RTL content anchors). Padding-inline pulls the content
     into the safe area on iOS; resolves to 0 on every other browser
     so desktop / Android layout is untouched. */
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* === BACKGROUND THEMES === */
.scene[data-bg="midnight"],
.theme-live-scene[data-bg="midnight"] {
  --bg-base:
    radial-gradient(ellipse at 30% 20%, rgba(70,30,90,0.35) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(30,60,120,0.3) 0%, transparent 50%),
    linear-gradient(180deg, #0a0a1f 0%, #050510 100%);
}
.scene[data-bg="medina"],
.theme-live-scene[data-bg="medina"] {
  --bg-base:
    radial-gradient(ellipse at 50% 100%, rgba(180,90,40,0.3) 0%, transparent 60%),
    radial-gradient(ellipse at 50% 0%, rgba(40,30,20,0.5) 0%, transparent 60%),
    linear-gradient(180deg, #2a1810 0%, #1a0e08 50%, #0a0604 100%);
}
.scene[data-bg="medina"]::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0px, transparent 60px, rgba(201,169,97,0.025) 60px, rgba(201,169,97,0.025) 61px),
    repeating-linear-gradient(90deg, transparent 0px, transparent 60px, rgba(201,169,97,0.025) 60px, rgba(201,169,97,0.025) 61px);
  pointer-events: none;
  z-index: 1;
}
.scene[data-bg="desert"],
.theme-live-scene[data-bg="desert"] {
  --bg-base:
    radial-gradient(ellipse at 50% 60%, rgba(255,180,80,0.25) 0%, transparent 50%),
    linear-gradient(180deg, #1a0a05 0%, #2a1a0a 30%, #4a2a10 60%, #1a0a05 100%);
}
.scene[data-bg="oasis"],
.theme-live-scene[data-bg="oasis"] {
  --bg-base:
    radial-gradient(ellipse at 50% 30%, rgba(80,140,100,0.3) 0%, transparent 60%),
    radial-gradient(ellipse at 20% 80%, rgba(40,80,60,0.4) 0%, transparent 50%),
    linear-gradient(180deg, #0a1a14 0%, #050a08 100%);
}
.scene[data-bg="velvet"],
.theme-live-scene[data-bg="velvet"] {
  --bg-base:
    radial-gradient(ellipse at 50% 50%, rgba(120,30,40,0.35) 0%, transparent 60%),
    linear-gradient(180deg, #1a0508 0%, #0a0204 100%);
}
/* موسم الحضارة العثمانية — pass-only scene background */
.scene[data-bg="season-othmani-scene"],
.theme-live-scene[data-bg="season-othmani-scene"] {
  --bg-base:
    radial-gradient(ellipse at 50% 12%, rgba(201,150,46,0.32) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 100%, rgba(13,90,68,0.4) 0%, transparent 60%),
    linear-gradient(180deg, #0a201a 0%, #06140f 55%, #030a07 100%);
}

/* Image scenes keep their focal point and overlay in CSS so the game and
   the live bag preview render the same crop. */
.scene[data-bg="bayt-qadim"],
.theme-live-scene[data-bg="bayt-qadim"] {
  --scene-bg-img: url("/static/images/background/%D8%A8%D9%8A%D8%AA%20%D9%82%D8%AF%D9%8A%D9%85.webp");
  --scene-bg-position: center 48%;
  --scene-overlay: linear-gradient(180deg, rgba(7, 9, 15, 0.34), rgba(5, 7, 13, 0.72));
  --bg-base: var(--scene-overlay), var(--scene-bg-img) var(--scene-bg-position) / cover no-repeat;
}
.scene[data-bg="dar-qadima"],
.theme-live-scene[data-bg="dar-qadima"] {
  --scene-bg-img: url("/static/images/background/%D8%AF%D8%A7%D8%B1%20%D9%82%D8%AF%D9%8A%D9%85%D8%A9.webp");
  --scene-bg-position: center 44%;
  --scene-overlay: linear-gradient(180deg, rgba(8, 10, 16, 0.28), rgba(4, 6, 11, 0.75));
  --bg-base: var(--scene-overlay), var(--scene-bg-img) var(--scene-bg-position) / cover no-repeat;
}

/* Free scene themes keep the table area dark enough for card contrast. */
.scene[data-bg="tripoli-dusk"],
.theme-live-scene[data-bg="tripoli-dusk"] {
  --bg-base:
    radial-gradient(ellipse at 50% 18%, rgba(244, 184, 96, 0.2), transparent 35%),
    radial-gradient(ellipse at 18% 72%, rgba(20, 105, 112, 0.3), transparent 45%),
    linear-gradient(165deg, #182a32 0%, #151b27 52%, #090c13 100%);
  --scene-pattern: repeating-linear-gradient(90deg, transparent 0 72px, rgba(231, 195, 124, 0.035) 72px 74px);
}
.scene[data-bg="ghadames-gold"],
.theme-live-scene[data-bg="ghadames-gold"] {
  --bg-base:
    radial-gradient(circle at 50% 22%, rgba(255, 211, 130, 0.2), transparent 30%),
    radial-gradient(ellipse at 50% 100%, rgba(108, 66, 28, 0.45), transparent 58%),
    linear-gradient(180deg, #352619 0%, #1d140e 56%, #0b0806 100%);
  --scene-pattern:
    linear-gradient(45deg, transparent 46%, rgba(226, 187, 111, 0.045) 47% 53%, transparent 54%) 0 0 / 64px 64px,
    linear-gradient(-45deg, transparent 46%, rgba(226, 187, 111, 0.035) 47% 53%, transparent 54%) 0 0 / 64px 64px;
}
.scene[data-bg="mediterranean-night"],
.theme-live-scene[data-bg="mediterranean-night"] {
  --bg-base:
    radial-gradient(ellipse at 70% 16%, rgba(81, 170, 188, 0.22), transparent 40%),
    radial-gradient(ellipse at 25% 82%, rgba(35, 91, 128, 0.34), transparent 48%),
    linear-gradient(155deg, #0d2630 0%, #091822 52%, #05090f 100%);
  --scene-pattern: repeating-radial-gradient(ellipse at 50% 110%, transparent 0 24px, rgba(123, 196, 208, 0.035) 25px 27px);
}

.scene[data-bg="tripoli-dusk"]::before,
.scene[data-bg="ghadames-gold"]::before,
.scene[data-bg="mediterranean-night"]::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--scene-pattern);
  pointer-events: none;
  z-index: 1;
}

/* dramatic spotlight overhead */
.scene::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 35%, rgba(255, 220, 150, 0.10) 0%, transparent 60%),
    radial-gradient(ellipse 100% 80% at 50% 100%, rgba(0,0,0,0.5) 0%, transparent 70%),
    radial-gradient(ellipse 80% 70% at 50% 50%, transparent 40%, rgba(0,0,0,0.55) 100%);
  pointer-events: none;
  z-index: 2;
}

/* ============ PROFILE + PILE LAYOUT ============ */
.profile-with-pile {
  display: flex;
  align-items: center;
  gap: 14px;
}
.bot-zone .profile-with-pile { justify-self: start; }
.player-zone .profile-with-pile { justify-self: end; flex-direction: row-reverse; }

/* ============ CAPTURES PILE (compact) ============ */
.captures-pile {
  position: relative;
  width: 80px;
  height: 110px;
  flex-shrink: 0;
}
.captures-pile .cp-stack {
  position: relative;
  width: 70px;
  height: 100px;
  margin: 0 auto;
}
.captures-pile .cp-shadow {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  /* Default (red leather) — overridden per-variant below. */
  background: linear-gradient(135deg, #8B2635 0%, #6a1a25 60%, #5a1419 100%);
  border: 1.5px solid rgba(201,169,97,0.6);
  box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}
[data-card-back="castle"] .captures-pile .cp-shadow {
  background: #fafaf6 url("/static/images/cards/back-castle.svg") center/contain no-repeat;
  border: 1px solid #1a1a1a;
}
[data-card-back="royal"] .captures-pile .cp-shadow {
  background: linear-gradient(135deg, #1B4965 0%, #143a52 50%, #0d2b40 100%);
  border: 1.5px solid rgba(201,169,97,0.6);
}
[data-card-back="treviso"] .captures-pile .cp-shadow {
  background: #fafaf6 url("/static/images/cards/back-treviso.svg") center/contain no-repeat;
  border: 1px solid #2a2a2a;
}
[data-card-back="vectorized"] .captures-pile .cp-shadow {
  background: #fafaf6 url("/static/images/cards/back-vectorized.svg") center/contain no-repeat;
  border: 1px solid #2a2a2a;
}
.captures-pile .cp-top {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(20,12,8,0.95), rgba(10,6,4,0.98));
  border: 2px solid rgba(201,169,97,0.5);
  box-shadow: 0 6px 14px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,215,0,0.15);
  display: grid;
  place-items: center;
  z-index: 10;
  transform: translate(-2px, -2px);
}
.captures-pile .cp-count {
  position: relative;
  z-index: 1;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(10,6,4,0.85);
  font-family: 'Reem Kufi', sans-serif;
  font-size: 32px;
  font-weight: 800;
  color: #FFD700;
  line-height: 1;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}
.captures-pile .cp-count-label {
  position: absolute;
  z-index: 1;
  bottom: 8px; left: 0; right: 0;
  background: rgba(10,6,4,0.85);
  text-align: center;
  font-family: 'Cairo', sans-serif;
  font-size: 9px;
  color: rgba(255,215,0,0.55);
  letter-spacing: 1px;
}
.captures-pile .cp-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 2px dashed rgba(201,169,97,0.3);
  border-radius: 9px;
  font-family: 'Cairo', sans-serif;
  font-size: 11px;
  color: rgba(255,248,231,0.35);
}
.captures-pile .cp-hayya-pip {
  position: absolute;
  top: -8px; right: -8px;
  width: 24px; height: 24px;
  background: radial-gradient(circle, #dc283c, #8a0e1c);
  border: 2px solid #FFD700;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  z-index: 11;
  box-shadow: 0 0 12px rgba(220,40,60,0.7);
  animation: hayya-pulse 1.6s ease-in-out infinite;
}
@keyframes hayya-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(220,40,60,0.6); }
  50% { box-shadow: 0 0 20px rgba(220,40,60,0.95); }
}
.captures-pile .cp-label {
  position: absolute;
  bottom: -18px; left: 0; right: 0;
  text-align: center;
  font-family: 'Cairo', sans-serif;
  font-size: 10px;
  color: rgba(255,248,231,0.55);
  letter-spacing: 1px;
}
.captures-pile.last-capturer .cp-top {
  border-color: #FFD700;
  box-shadow: 0 0 18px rgba(255,215,0,0.45), 0 6px 14px rgba(0,0,0,0.55);
  animation: last-cap-glow 2s ease-in-out infinite;
}
@keyframes last-cap-glow {
  0%, 100% { box-shadow: 0 0 14px rgba(255,215,0,0.4), 0 6px 14px rgba(0,0,0,0.55); }
  50% { box-shadow: 0 0 22px rgba(255,215,0,0.7), 0 6px 14px rgba(0,0,0,0.55); }
}

.bot-zone-spacer { flex: 1; }

.bot-zone {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  align-items: center;
  padding: clamp(8px, 1.5vh, 16px) clamp(16px, 3vw, 32px) 0;
  gap: clamp(8px, 2vw, 24px);
}

.bot-avatar-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
}

.bot-avatar {
  position: relative;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #f5d989 0%, #c9a961 45%, #8a6e2f 100%);
  box-shadow:
    0 0 0 3px rgba(201, 169, 97, 0.3),
    0 0 0 6px rgba(201, 169, 97, 0.15),
    0 8px 24px rgba(0,0,0,0.4),
    inset 0 -8px 16px rgba(0,0,0,0.25);
  display: grid;
  place-items: center;
  font-size: 38px;
  transition: transform var(--pace-fast) var(--ease-out);
}

.bot-avatar.thinking {
  animation: bot-think 1.4s ease-in-out infinite;
}
.bot-avatar.thinking::before {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid var(--libyan-gold);
  animation: bot-pulse-ring 1.4s ease-out infinite;
}
.bot-avatar.thinking::after {
  content: '';
  position: absolute;
  inset: -18px;
  border-radius: 50%;
  border: 2px solid var(--libyan-gold);
  opacity: 0;
  animation: bot-pulse-ring 1.4s ease-out 0.7s infinite;
}

.bot-avatar.acting {
  animation: bot-act 0.6s var(--ease-back);
}

@keyframes bot-think {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes bot-pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}
@keyframes bot-act {
  0% { transform: scale(1) rotate(0deg); }
  30% { transform: scale(1.15) rotate(-6deg); }
  60% { transform: scale(1.08) rotate(4deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.bot-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bot-name {
  font-family: 'Reem Kufi', 'Cairo', sans-serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--libyan-gold);
}

.bot-status {
  font-size: 13px;
  color: rgba(255, 248, 231, 0.6);
  min-height: 18px;
}

/* speech bubble */
.bubble {
  position: absolute;
  top: 92px;
  right: 20px;
  background: linear-gradient(180deg, #fff8e7 0%, #f0e3c0 100%);
  color: var(--midnight);
  padding: 10px 16px;
  border-radius: 14px;
  font-family: 'Reem Kufi', sans-serif;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(201,169,97,0.4);
  opacity: 0;
  transform: translateY(-8px) scale(0.9);
  pointer-events: none;
  z-index: 10;
}
.bubble::before {
  content: '';
  position: absolute;
  top: -8px;
  right: 28px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid #fff8e7;
}
.bubble.show {
  animation: bubble-pop 2.4s var(--ease-back) forwards;
}
@keyframes bubble-pop {
  0% { opacity: 0; transform: translateY(-8px) scale(0.7); }
  10% { opacity: 1; transform: translateY(0) scale(1.05); }
  20% { transform: translateY(0) scale(1); }
  85% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-12px) scale(0.95); }
}

.bot-hand {
  display: flex;
  justify-content: center;
  perspective: 1200px;
  position: relative;
  height: clamp(140px, 16vh, 180px);
}

.score-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: linear-gradient(180deg, rgba(20,30,25,0.8), rgba(10,15,12,0.9));
  border: 1px solid rgba(201, 169, 97, 0.3);
  border-radius: 18px;
  padding: 14px 22px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  justify-self: end;
}
.bot-zone .score-pill { justify-self: start; }
.score-pill .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: rgba(255,248,231,0.5);
}
.score-pill .num {
  font-family: 'Reem Kufi', sans-serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--libyan-gold);
  line-height: 1;
  font-feature-settings: "tnum";
  white-space: nowrap;
}
.score-pill .label { white-space: nowrap; }
.score-pill.flash .num {
  animation: score-flash 0.8s var(--ease-out);
}
@keyframes score-flash {
  0% { transform: scale(1); color: var(--libyan-gold); }
  40% { transform: scale(1.4); color: var(--libyan-gold-bright); text-shadow: 0 0 20px var(--libyan-gold-bright); }
  100% { transform: scale(1); color: var(--libyan-gold); }
}

/* ============ MIDDLE: TABLE ============ */
.table-zone {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  align-items: center;
  padding: 0 32px;
  gap: 24px;
}

.deck-column {
  justify-self: end;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}
.pile-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.pile-label {
  font-family: 'Reem Kufi', sans-serif;
  font-size: 11px;
  letter-spacing: 2px;
  color: rgba(201,169,97,0.7);
}
.pile-sub {
  font-family: 'Cairo', sans-serif;
  font-size: 10px;
  color: rgba(255,248,231,0.45);
}
.discard-stack {
  position: relative;
  width: 70px;
  height: 100px;
}
.discard-empty {
  position: absolute;
  inset: 0;
  border: 2px dashed rgba(201,169,97,0.25);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-family: 'Cairo', sans-serif;
  font-size: 11px;
  color: rgba(255,248,231,0.3);
}
.discard-card {
  position: absolute;
  inset: 0;
  transition: transform 0.4s cubic-bezier(0.22,1,0.36,1);
}
.discard-card .card.small {
  width: 70px;
  height: 100px;
}
.discard-counter {
  top: -10px;
  right: -10px;
  background: var(--midnight);
  border-color: #c9a961;
  color: #c9a961;
}

.deck-stack {
  justify-self: end;
  position: relative;
  width: 100px;
  height: 150px;
}
.deck-stack .deck-card {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background:
    linear-gradient(135deg, #8B2635 0%, #6a1a25 30%, #5a1419 60%, #7a2230 100%);
  border: 3px solid #c9a961;
  box-shadow:
    inset 0 0 0 1px rgba(255,215,0,0.3),
    inset 0 0 16px rgba(0,0,0,0.4),
    0 4px 12px rgba(0,0,0,0.35);
  overflow: hidden;
}
.deck-stack .deck-card::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1.5px solid rgba(201,169,97,0.7);
  border-radius: 6px;
  background-image:
    radial-gradient(ellipse at center, rgba(255,215,0,0.12), transparent 60%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 90'><g fill='none' stroke='%23d4b56a' stroke-width='0.7' opacity='0.85'><polygon points='30,8 52,30 30,52 8,30'/><polygon points='30,14 46,30 30,46 14,30'/><polygon points='30,20 40,30 30,40 20,30'/><circle cx='30' cy='30' r='2.5' fill='%23d4b56a'/><polygon points='30,38 52,60 30,82 8,60'/><polygon points='30,44 46,60 30,76 14,60'/><polygon points='30,50 40,60 30,70 20,60'/><circle cx='30' cy='60' r='2.5' fill='%23d4b56a'/></g><g fill='%23d4b56a' opacity='0.4'><circle cx='8' cy='8' r='1'/><circle cx='52' cy='8' r='1'/><circle cx='8' cy='82' r='1'/><circle cx='52' cy='82' r='1'/></g></svg>");
  background-size: 100% 100%;
  pointer-events: none;
}
.deck-stack .deck-card::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 22px; height: 22px;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 1px solid rgba(255,215,0,0.6);
  background: radial-gradient(circle, rgba(255,215,0,0.35), transparent 70%);
  pointer-events: none;
}
/* When the deck empties, dim the counter — the stack itself is hidden via JS. */
.deck-stack.empty .deck-counter {
  background: rgba(40,30,15,0.45);
  border-color: rgba(201,169,97,0.25);
  color: rgba(255,248,231,0.4);
}
.deck-counter {
  position: absolute;
  top: -12px;
  right: -12px;
  background: var(--midnight);
  border: 2px solid var(--libyan-gold);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-family: 'Reem Kufi', sans-serif;
  font-weight: 700;
  font-size: 14px;
  color: var(--libyan-gold);
  z-index: 5;
  /* Force LTR so any future "12 / 40" style content reads left-to-right
     even inside the RTL body. Pure single digits render fine either way
     but a defensive direction lock costs nothing. */
  direction: ltr;
  font-feature-settings: "tnum";
}

.captures-stack {
  justify-self: start;
  position: relative;
  width: 100px;
  height: 150px;
  margin-left: 220px;
}
.captures-stack .label {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(255,248,231,0.5);
  white-space: nowrap;
}

/* The felt table */
.felt {
  position: relative;
  height: clamp(280px, 36vh, 380px);
  border-radius: 28px;
  padding: clamp(14px, 2vw, 22px);
  background: var(--frame-bg,
    repeating-linear-gradient(90deg, #5a3820 0px, #6b4427 2px, #4a2f1c 4px, #5a3820 6px),
    linear-gradient(180deg, #6b4427 0%, #4a2f1c 100%));
  box-shadow:
    0 30px 60px rgba(0,0,0,0.6),
    0 0 0 1px rgba(0,0,0,0.4),
    inset 0 0 0 2px rgba(201,169,97,0.15);
  transition: background 500ms ease;
}

/* === TABLE THEMES === */
.felt[data-table="hasira"] {
  --frame-bg:
    repeating-linear-gradient(90deg, #4b2f1d 0 3px, #6a4630 3px 6px, #2f1c12 6px 9px),
    linear-gradient(180deg, #6a4630, #2f1c12);
  --felt-bg-img: url("/static/images/table/%D8%AD%D8%B5%D9%8A%D8%B1%D8%A9.webp");
  --felt-bg-position: center;
  --felt-table-aspect: 13 / 8;
}
.felt[data-table="hasira-zamaniya"] {
  --frame-bg:
    repeating-linear-gradient(90deg, #3a251a 0 3px, #5a3a29 3px 6px, #24160f 6px 9px),
    linear-gradient(180deg, #5a3a29, #24160f);
  --felt-bg-img: url("/static/images/table/%D8%AD%D8%B5%D9%8A%D8%B1%D8%A9%20%D8%B2%D9%85%D9%86%D9%8A%D8%A9.webp");
  --felt-bg-position: center;
  --felt-table-aspect: 13 / 8;
}

.felt[data-table="walnut"] {
  --frame-bg:
    repeating-linear-gradient(90deg, #5a3820 0px, #6b4427 2px, #4a2f1c 4px, #5a3820 6px),
    linear-gradient(180deg, #6b4427 0%, #4a2f1c 100%);
  --felt-c1: #1a4a30;
  --felt-c2: #0e3520;
  --felt-c3: #051a10;
}
.felt[data-table="ebony"] {
  --frame-bg:
    repeating-linear-gradient(90deg, #1a1410 0px, #2a1f18 2px, #14100a 4px, #1a1410 6px),
    linear-gradient(180deg, #2a1f18 0%, #0a0805 100%);
  --felt-c1: #2a1018;
  --felt-c2: #15080c;
  --felt-c3: #080306;
}
.felt[data-table="royal-blue"] {
  --frame-bg:
    linear-gradient(135deg, #2a1a08 0%, #4a3010 50%, #2a1a08 100%);
  --felt-c1: #1a3a6e;
  --felt-c2: #0e2548;
  --felt-c3: #050f25;
}
.felt[data-table="oasis-emerald"] {
  --frame-bg:
    linear-gradient(180deg, #5a4020 0%, #3a2810 50%, #5a4020 100%);
  --felt-c1: #0e6e4e;
  --felt-c2: #084230;
  --felt-c3: #021a14;
}
.felt[data-table="ruby"] {
  --frame-bg:
    linear-gradient(180deg, #1a0a08 0%, #3a1410 100%);
  --felt-c1: #6e1a28;
  --felt-c2: #4a0e18;
  --felt-c3: #1a0408;
}
.felt[data-table="sand"] {
  --frame-bg:
    linear-gradient(180deg, #2a1a08 0%, #4a2a14 100%);
  --felt-c1: #8a6028;
  --felt-c2: #5a4018;
  --felt-c3: #2a1f08;
}
.felt[data-table="tripoli-velvet"] {
  --frame-bg: linear-gradient(135deg, #7a4b25 0%, #3a2112 46%, #8a5a2d 100%);
  --felt-c1: #174f42;
  --felt-c2: #0c332b;
  --felt-c3: #041713;
  --felt-pattern:
    repeating-linear-gradient(135deg, transparent 0 18px, rgba(235, 208, 146, 0.055) 19px 20px),
    repeating-linear-gradient(45deg, transparent 0 18px, rgba(235, 208, 146, 0.035) 19px 20px);
  --felt-pattern-size: auto;
  --felt-pattern-repeat: repeat;
  --felt-pattern-opacity: 0.7;
}
.felt[data-table="ghadames-weave"] {
  --frame-bg: linear-gradient(135deg, #5e351f 0%, #2f1b12 45%, #6b4025 100%);
  --felt-c1: #8a6437;
  --felt-c2: #694522;
  --felt-c3: #2f1c12;
  --felt-pattern:
    linear-gradient(45deg, transparent 42%, rgba(244, 218, 157, 0.12) 43% 57%, transparent 58%) 0 0 / 34px 34px,
    linear-gradient(-45deg, transparent 42%, rgba(21, 77, 78, 0.16) 43% 57%, transparent 58%) 0 0 / 34px 34px;
  --felt-pattern-size: auto;
  --felt-pattern-repeat: repeat;
  --felt-pattern-opacity: 0.78;
}
.felt[data-table="coastal-navy"] {
  --frame-bg: linear-gradient(135deg, #9a7437 0%, #4c3519 50%, #a78042 100%);
  --felt-c1: #174e67;
  --felt-c2: #0d3147;
  --felt-c3: #041522;
  --felt-pattern: repeating-radial-gradient(ellipse at 50% 115%, transparent 0 20px, rgba(151, 218, 226, 0.09) 21px 23px);
  --felt-pattern-size: 88px 44px;
  --felt-pattern-repeat: repeat;
  --felt-pattern-opacity: 0.72;
}
/* === موسم الحضارة العثمانية — pass-only table felts === */
.felt[data-table="season-othmani-felt"] {
  --frame-bg:
    repeating-linear-gradient(90deg, #6b4e16 0px, #8a6a22 2px, #4a3510 4px, #6b4e16 6px),
    linear-gradient(180deg, #7a5a1c 0%, #4a3510 100%);
  --felt-c1: #0d5a44;
  --felt-c2: #073c2e;
  --felt-c3: #021a14;
}
.felt[data-table="season-othmani-finale-felt"] {
  --frame-bg:
    repeating-linear-gradient(90deg, #c9962e 0px, #f0c552 2px, #946716 4px, #c9962e 6px),
    linear-gradient(180deg, #c9962e 0%, #6b4e16 100%);
  --felt-c1: #5e1626;
  --felt-c2: #3c0d18;
  --felt-c3: #1a040a;
}

/* zellij corners */
.felt::before, .felt::after {
  content: '';
  position: absolute;
  width: 56px;
  height: 56px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 56 56'><g fill='none' stroke='%23c9a961' stroke-width='1.2' opacity='0.7'><polygon points='28,4 52,28 28,52 4,28'/><polygon points='28,12 44,28 28,44 12,28'/><circle cx='28' cy='28' r='4'/><line x1='28' y1='4' x2='28' y2='52'/><line x1='4' y1='28' x2='52' y2='28'/></g></svg>");
  pointer-events: none;
  z-index: 4;
}
.felt::before { top: 6px; right: 6px; }
.felt::after { bottom: 6px; left: 6px; }

.felt-inner {
  position: relative;
  height: 100%;
  border-radius: 14px;
  background:
    radial-gradient(ellipse 60% 80% at 50% 35%, rgba(255, 230, 160, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at center, var(--felt-c1, var(--felt-green)) 0%, var(--felt-c2, var(--felt-dark)) 60%, var(--felt-c3, var(--felt-deep)) 100%);
  box-shadow:
    inset 0 8px 24px rgba(0,0,0,0.6),
    inset 0 -4px 16px rgba(0,0,0,0.4),
    inset 0 0 0 2px rgba(201,169,97,0.25);
  overflow: hidden;
  transition: background 500ms ease;
}

.felt-inner::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--felt-pattern, url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'><g fill='none' stroke='%23ffffff' stroke-width='0.4' opacity='0.06'><circle cx='100' cy='100' r='90'/><circle cx='100' cy='100' r='60'/><circle cx='100' cy='100' r='30'/><polygon points='100,10 190,100 100,190 10,100'/></g></svg>"));
  background-size: var(--felt-pattern-size, 180px 180px);
  background-position: center;
  background-repeat: var(--felt-pattern-repeat, no-repeat);
  pointer-events: none;
  opacity: var(--felt-pattern-opacity, 0.5);
}

.table-cards {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.table-cards-grid {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 14px 18px;
  padding: 16px;
}

/* ============ BOTTOM: PLAYER ZONE ============ */
.player-zone {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  align-items: end;
  padding: 0 clamp(16px, 3vw, 32px) clamp(12px, 2vh, 24px);
  gap: clamp(8px, 2vw, 24px);
}

.player-hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  perspective: 1200px;
  position: relative;
  height: clamp(160px, 18vh, 200px);
}

.player-info {
  display: flex;
  align-items: center;
  gap: 16px;
  align-self: end;
  padding-bottom: 10px;
}
.player-info.right { flex-direction: row-reverse; }

.player-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, #6fa6d9 0%, #1B4965 60%, #0d2a3d 100%);
  box-shadow:
    0 0 0 2px rgba(27, 73, 101, 0.4),
    0 6px 16px rgba(0,0,0,0.4);
  display: grid;
  place-items: center;
  font-size: 28px;
  flex-shrink: 0;
}
.player-avatar.acting { animation: bot-act 0.6s var(--ease-back); }

/* When the player has picked a profile picture, the inline JS in
   game.html sets a background-image + .has-user-avatar. Swap the
   default blue gradient for a gold ring so the user's avatar pops
   against the felt and matches the navbar treatment. */
.player-avatar.has-user-avatar {
  background-color: #f3eee0;
  background-blend-mode: normal;
  box-shadow:
    0 0 0 2px var(--gold-deep, #c9a961),
    0 6px 16px rgba(0, 0, 0, 0.4);
}

.player-name {
  font-family: 'Reem Kufi', sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--ivory);
}
.player-turn-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--libyan-gold);
  margin-inline-start: 6px;
  box-shadow: 0 0 10px var(--libyan-gold);
  animation: turn-pulse 1.2s ease-in-out infinite;
}
@keyframes turn-pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.1); }
}
.player-info.dim .player-turn-dot { display: none; }
.player-info.dim { opacity: 0.55; }

/* ============ CARDS ============ */
.card {
  width: clamp(74px, 6.4vw, 96px);
  height: clamp(112px, 9.6vw, 144px);
  border-radius: 10px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--pace-fast) var(--ease-out),
              box-shadow var(--pace-fast) var(--ease-out),
              filter var(--pace-fast) ease;
  user-select: none;
  flex-shrink: 0;
  background: transparent;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  cursor: default;
}
.card.small { width: 72px; height: 108px; }
.card.tiny { width: 56px; height: 84px; }

/* Face-up SVGs define their own white body and rounded outline. */
.card-face, .card-back {
  position: absolute;
  inset: 0;
  border-radius: 10px;
}

.card-face {
  border-radius: 0;
  overflow: visible;
}

.card-back {
  overflow: hidden;
}

/* Default red-leather + gold-diamond design (also kicks in when no
 * data-card-back is set anywhere up the tree). */
.card-back {
  background:
    linear-gradient(135deg, #8B2635 0%, #6a1a25 30%, #5a1419 60%, #7a2230 100%);
  border: 3px solid #c9a961;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,215,0,0.3), inset 0 0 16px rgba(0,0,0,0.4);
}
.card-back::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1.5px solid rgba(201,169,97,0.7);
  border-radius: 6px;
  background-image:
    radial-gradient(ellipse at center, rgba(255,215,0,0.12), transparent 60%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 90'><g fill='none' stroke='%23d4b56a' stroke-width='0.7' opacity='0.85'><polygon points='30,8 52,30 30,52 8,30'/><polygon points='30,14 46,30 30,46 14,30'/><polygon points='30,20 40,30 30,40 20,30'/><circle cx='30' cy='30' r='2.5' fill='%23d4b56a'/><polygon points='30,38 52,60 30,82 8,60'/><polygon points='30,44 46,60 30,76 14,60'/><polygon points='30,50 40,60 30,70 20,60'/><circle cx='30' cy='60' r='2.5' fill='%23d4b56a'/></g><g fill='%23d4b56a' opacity='0.4'><circle cx='8' cy='8' r='1'/><circle cx='52' cy='8' r='1'/><circle cx='8' cy='82' r='1'/><circle cx='52' cy='82' r='1'/></g></svg>");
  background-size: 100% 100%;
}
.card-back::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 22px; height: 22px;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 1px solid rgba(255,215,0,0.6);
  background: radial-gradient(circle, rgba(255,215,0,0.35), transparent 70%);
}

/* === موسم الحضارة العثمانية — pass-only card backs (pure CSS) === */
[data-card-back="season-othmani-cardback"] .card-back,
[data-card-back="season-othmani-cardback"] .deck-stack .deck-card,
[data-card-back="season-othmani-cardback"] .captures-pile .cp-shadow {
  background: linear-gradient(135deg, #0d5a44 0%, #073c2e 55%, #052a20 100%);
  border: 3px solid #c9962e;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(201,150,46,0.4), inset 0 0 18px rgba(0,0,0,0.5);
}
[data-card-back="season-othmani-cardback"] .card-back::before,
[data-card-back="season-othmani-cardback"] .deck-stack .deck-card::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1.2px solid rgba(201,150,46,0.6);
  border-radius: 6px;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='M10 0 L13 7 L20 10 L13 13 L10 20 L7 13 L0 10 L7 7 Z' fill='%23c9962e' fill-opacity='0.3'/></svg>");
  background-size: 20px 20px;
}
[data-card-back="season-othmani-cardback"] .card-back::after,
[data-card-back="season-othmani-cardback"] .deck-stack .deck-card::after {
  content: '۞';
  font-size: 30px;
  color: #e8c45a;
  text-shadow: 0 0 10px rgba(201,150,46,0.6);
}
[data-card-back="season-othmani-ember-cardback"] .card-back,
[data-card-back="season-othmani-ember-cardback"] .deck-stack .deck-card,
[data-card-back="season-othmani-ember-cardback"] .captures-pile .cp-shadow {
  background: linear-gradient(135deg, #5e1626 0%, #3c0d18 55%, #1a040a 100%);
  border: 3px solid #d8a23a;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(216,162,58,0.4), inset 0 0 18px rgba(0,0,0,0.55);
}
[data-card-back="season-othmani-ember-cardback"] .card-back::before,
[data-card-back="season-othmani-ember-cardback"] .deck-stack .deck-card::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1.2px solid rgba(216,162,58,0.55);
  border-radius: 6px;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='M10 0 L13 7 L20 10 L13 13 L10 20 L7 13 L0 10 L7 7 Z' fill='%23d8a23a' fill-opacity='0.28'/></svg>");
  background-size: 20px 20px;
}
[data-card-back="season-othmani-ember-cardback"] .card-back::after,
[data-card-back="season-othmani-ember-cardback"] .deck-stack .deck-card::after {
  content: '۞';
  font-size: 30px;
  color: #f0c45a;
  text-shadow: 0 0 12px rgba(240,120,60,0.6);
}

/* Castle (Chkobbet El Borj) — homage to the classic Dal Negro Treviso back.
 * Uses the dedicated SVG file so the artwork stays sharp at any zoom. */
[data-card-back="castle"] .card-back {
  background: #fafaf6 url("/static/images/cards/back-castle.svg") center/contain no-repeat;
  border: 1px solid #1a1a1a;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05);
}
[data-card-back="castle"] .card-back::before,
[data-card-back="castle"] .card-back::after { content: none; }

/* Royal blue mesh — modernised version of the original back.svg
 * (gold star on diamond-tile blue), drawn with CSS so it stays crisp. */
[data-card-back="royal"] .card-back {
  background:
    linear-gradient(135deg, #1B4965 0%, #143a52 50%, #0d2b40 100%);
  border: 3px solid #C9A961;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(201,169,97,0.35), inset 0 0 18px rgba(0,0,0,0.45);
}
[data-card-back="royal"] .card-back::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1.2px solid rgba(201,169,97,0.65);
  border-radius: 6px;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='M0 10 L10 0 L20 10 L10 20 Z' fill='%23C9A961' fill-opacity='0.32'/></svg>");
  background-size: 22px 22px;
}
[data-card-back="royal"] .card-back::after {
  content: '★';
  font-size: 36px;
  color: #C9A961;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5), 0 0 12px rgba(255,215,0,0.45);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: auto; height: auto;
  border: none;
  background: none;
}

/* Treviso — the actual classic Dal Negro Treviso card back (raster image
 * embedded in an SVG). Heaviest of the four; we keep it because it's the
 * authentic look so many Libyan players grew up with. */
[data-card-back="treviso"] .card-back {
  background: #fafaf6 url("/static/images/cards/back-treviso.svg") center/contain no-repeat;
  border: 1px solid #2a2a2a;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05);
}
[data-card-back="treviso"] .card-back::before,
[data-card-back="treviso"] .card-back::after { content: none; }

/* Vectorized — clean SVG vector trace of the CHKORBET EL BORJ photographic
 * back. Stays sharp at every zoom level (unlike the raster treviso). */
[data-card-back="vectorized"] .card-back {
  background: #fafaf6 url("/static/images/cards/back-vectorized.svg") center/contain no-repeat;
  border: 1px solid #2a2a2a;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05);
}
[data-card-back="vectorized"] .card-back::before,
[data-card-back="vectorized"] .card-back::after { content: none; }

/* The deck/draw pile (الكومة) is built from .deck-card divs that duplicate
 * the default red-leather styling. Keep that as the default but let the
 * picker swap it out the same way it does for face-down hand cards. */
[data-card-back="castle"] .deck-stack .deck-card {
  background: #fafaf6 url("/static/images/cards/back-castle.svg") center/contain no-repeat;
  border: 1px solid #1a1a1a;
}
[data-card-back="castle"] .deck-stack .deck-card::before,
[data-card-back="castle"] .deck-stack .deck-card::after { content: none; }

[data-card-back="royal"] .deck-stack .deck-card {
  background: linear-gradient(135deg, #1B4965 0%, #143a52 50%, #0d2b40 100%);
  border: 3px solid #C9A961;
}
[data-card-back="royal"] .deck-stack .deck-card::before {
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='M0 10 L10 0 L20 10 L10 20 Z' fill='%23C9A961' fill-opacity='0.32'/></svg>");
  background-size: 22px 22px;
  border: 1.2px solid rgba(201,169,97,0.65);
}
[data-card-back="royal"] .deck-stack .deck-card::after {
  content: '★';
  font-size: 30px;
  color: #C9A961;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5), 0 0 12px rgba(255,215,0,0.45);
  width: auto; height: auto;
  border: none;
  background: none;
  transform: translate(-50%, -50%);
}

[data-card-back="treviso"] .deck-stack .deck-card {
  background: #fafaf6 url("/static/images/cards/back-treviso.svg") center/contain no-repeat;
  border: 1px solid #2a2a2a;
}
[data-card-back="treviso"] .deck-stack .deck-card::before,
[data-card-back="treviso"] .deck-stack .deck-card::after { content: none; }

[data-card-back="vectorized"] .deck-stack .deck-card {
  background: #fafaf6 url("/static/images/cards/back-vectorized.svg") center/contain no-repeat;
  border: 1px solid #2a2a2a;
}
[data-card-back="vectorized"] .deck-stack .deck-card::before,
[data-card-back="vectorized"] .deck-stack .deck-card::after { content: none; }

/* Old Medina arches: restrained geometric detail with one clear emblem. */
[data-card-back="medina-arches"] .card-back,
[data-card-back="medina-arches"] .deck-stack .deck-card,
[data-card-back="medina-arches"] .captures-pile .cp-shadow {
  background:
    radial-gradient(circle at 50% 42%, rgba(236, 199, 115, 0.2), transparent 24%),
    repeating-linear-gradient(135deg, transparent 0 14px, rgba(236, 199, 115, 0.07) 15px 16px),
    linear-gradient(145deg, #5e1d2c 0%, #35101c 54%, #17070c 100%);
  border: 2px solid #d5ae5e;
  box-shadow: inset 0 0 0 1px rgba(255, 229, 166, 0.2), inset 0 0 18px rgba(0, 0, 0, 0.48);
}
[data-card-back="medina-arches"] .card-back::before,
[data-card-back="medina-arches"] .deck-stack .deck-card::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(240, 207, 134, 0.62);
  border-radius: 5px;
  background:
    radial-gradient(circle at 50% 0, transparent 0 7px, rgba(229, 190, 105, 0.14) 8px 9px, transparent 10px) 0 4px / 22px 22px repeat;
}
[data-card-back="medina-arches"] .card-back::after,
[data-card-back="medina-arches"] .deck-stack .deck-card::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 25px;
  height: 34px;
  border: 2px solid #e3bd6c;
  border-radius: 50% 50% 8px 8px;
  background:
    linear-gradient(90deg, transparent 46%, rgba(227, 189, 108, 0.72) 47% 53%, transparent 54%),
    radial-gradient(circle at 50% 42%, rgba(255, 225, 154, 0.38), rgba(63, 17, 30, 0.92) 72%);
  box-shadow: 0 0 0 3px rgba(227, 189, 108, 0.12), 0 0 14px rgba(227, 189, 108, 0.3);
  transform: translate(-50%, -50%);
}

/* Ghadames weave: a compact woven tile that remains crisp on small cards. */
[data-card-back="ghadames-weave"] .card-back,
[data-card-back="ghadames-weave"] .deck-stack .deck-card,
[data-card-back="ghadames-weave"] .captures-pile .cp-shadow {
  background-color: #173e41;
  background-image:
    linear-gradient(45deg, transparent 40%, rgba(229, 192, 112, 0.55) 41% 48%, transparent 49%),
    linear-gradient(-45deg, transparent 40%, rgba(185, 91, 61, 0.55) 41% 48%, transparent 49%),
    linear-gradient(135deg, #24595b 0%, #133638 58%, #0b2325 100%);
  background-size: 18px 18px, 18px 18px, cover;
  border: 2px solid #d8b66c;
  box-shadow: inset 0 0 0 1px rgba(255, 237, 189, 0.18), inset 0 0 18px rgba(0, 0, 0, 0.46);
}
[data-card-back="ghadames-weave"] .card-back::before,
[data-card-back="ghadames-weave"] .deck-stack .deck-card::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255, 222, 148, 0.7);
  border-radius: 5px;
  background: rgba(7, 28, 29, 0.12);
}
[data-card-back="ghadames-weave"] .card-back::after,
[data-card-back="ghadames-weave"] .deck-stack .deck-card::after {
  content: '◆';
  position: absolute;
  top: 50%;
  left: 50%;
  width: auto;
  height: auto;
  border: 0;
  background: #123638;
  color: #f0cf82;
  font-size: 28px;
  line-height: 1;
  text-shadow: 0 0 9px rgba(240, 207, 130, 0.72), 0 2px 2px rgba(0, 0, 0, 0.65);
  box-shadow: 0 0 0 5px rgba(18, 54, 56, 0.92), 0 0 0 6px rgba(240, 207, 130, 0.42);
  transform: translate(-50%, -50%);
}

/* Sahara palm: deep olive leather with a lightweight vector emblem. */
[data-card-back="sahara-palm"] .card-back,
[data-card-back="sahara-palm"] .deck-stack .deck-card,
[data-card-back="sahara-palm"] .captures-pile .cp-shadow {
  background:
    radial-gradient(circle at 50% 44%, rgba(221, 183, 102, 0.2), transparent 28%),
    repeating-linear-gradient(90deg, transparent 0 10px, rgba(231, 205, 145, 0.045) 11px 12px),
    linear-gradient(145deg, #36513d 0%, #203528 52%, #0c1711 100%);
  border: 2px solid #d9b568;
  box-shadow: inset 0 0 0 1px rgba(255, 235, 181, 0.18), inset 0 0 20px rgba(0, 0, 0, 0.5);
}
[data-card-back="sahara-palm"] .card-back::before,
[data-card-back="sahara-palm"] .deck-stack .deck-card::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(230, 197, 123, 0.62);
  border-radius: 5px;
  background: radial-gradient(circle at center, transparent 0 42%, rgba(230, 197, 123, 0.08) 43% 45%, transparent 46%);
}
[data-card-back="sahara-palm"] .card-back::after,
[data-card-back="sahara-palm"] .deck-stack .deck-card::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 46px;
  border: 0;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 60'><g fill='none' stroke='%23e3bd6c' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'><path d='M24 52 C22 42 23 31 25 21'/><path d='M25 21 C17 17 11 18 6 23 C13 23 18 25 23 29'/><path d='M25 21 C32 16 39 17 44 22 C36 22 31 24 26 29'/><path d='M25 20 C20 12 20 7 23 3 C27 9 28 14 25 20'/><path d='M24 21 C15 14 10 10 5 11 C10 18 16 21 24 24'/><path d='M26 21 C34 14 39 11 44 12 C39 18 34 22 26 24'/><path d='M18 52 H31'/></g></svg>") center / contain no-repeat;
  filter: drop-shadow(0 0 5px rgba(227, 189, 108, 0.42));
  transform: translate(-50%, -50%);
}

.card.flipped .card-face { transform: rotateY(180deg); }
.card.flipped .card-back { transform: rotateY(0deg); }

/* card hover/select */
.player-hand .card.hand-card {
  cursor: pointer;
  transition: transform 0.35s var(--ease-out),
              box-shadow 0.35s var(--ease-out),
              filter 0.35s ease;
}
/* Mouse-only hand-card lift. The retired fan layout used an undefined
   `--fan-transform` plus rotateX here, which invalidated the selected
   transform and made card angles vary between browsers. Keep this layer
   flat; the later overrides own the final interaction distances. */
@media (hover: hover) and (pointer: fine) {
  .player-hand .card.hand-card:hover {
    transform: translateY(-12px) scale(1.02);
    box-shadow: 0 8px 18px rgba(0,0,0,0.22), 0 0 30px rgba(201,169,97,0.3);
    z-index: 100;
  }
}
.player-hand .card.hand-card.selected {
  transform: translateY(-22px) scale(1.05);
  box-shadow: 0 10px 22px rgba(0,0,0,0.25), 0 0 40px var(--libyan-gold-bright);
  z-index: 200;
}
@keyframes selected-glow {
  0%, 100% { box-shadow: 0 10px 22px rgba(0,0,0,0.25), 0 0 30px var(--libyan-gold); }
  50% { box-shadow: 0 10px 22px rgba(0,0,0,0.25), 0 0 50px var(--libyan-gold-bright); }
}

.card.disabled { filter: none; opacity: 0.72; pointer-events: none; }

/* table card capture-candidate highlight */
.card.capture-candidate {
  animation: capture-pulse 1.4s ease-in-out infinite;
  cursor: pointer;
}
.card.capture-candidate:hover {
  transform: translateY(-10px) scale(1.06) !important;
  z-index: 50;
}
@keyframes capture-pulse {
  0%, 100% { box-shadow: 0 6px 16px rgba(0,0,0,0.4), 0 0 0 2px var(--libyan-gold), 0 0 16px rgba(201,169,97,0.4); }
  50% { box-shadow: 0 6px 16px rgba(0,0,0,0.4), 0 0 0 3px var(--libyan-gold-bright), 0 0 30px rgba(255,215,0,0.7); }
}

.card.capture-selected {
  box-shadow: 0 6px 16px rgba(0,0,0,0.4), 0 0 0 3px var(--libyan-gold-bright), 0 0 40px var(--libyan-gold-bright) !important;
  transform: translateY(-12px) scale(1.08) !important;
}

/* HAYYA permanent glow */
.card.is-hayya .card-face {
  box-shadow: inset 0 0 30px rgba(255, 215, 0, 0.5);
}
.card.is-hayya {
  /* Static glow. `hayya-idle` animated `filter: drop-shadow` (a per-frame GPU
     blur recompute) continuously while the الحية sat on the table — one of the
     most expensive things to animate on a mobile GPU. The static glow keeps the
     الحية visually distinct without the per-frame cost. */
  box-shadow: 0 6px 16px rgba(0,0,0,0.4), 0 0 26px rgba(255,215,0,0.55) !important;
}

/* ============ FLY-CARD ANIMATION ============ */
.fly-card {
  position: fixed;
  z-index: 500;
  pointer-events: none;
  width: 96px;
  height: 144px;
  border-radius: 10px;
  transition: transform var(--pace) var(--ease-out),
              opacity var(--pace) var(--ease-out);
  will-change: transform, opacity;
}

/* trail behind a flying card */
.fly-card .trail {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255,215,0,0.5) 0%, transparent 70%);
  filter: blur(8px);
  opacity: 0;
  animation: trail-fade 0.8s ease-out forwards;
}
@keyframes trail-fade {
  0% { opacity: 0.8; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.6); }
}

/* ============ BIG BANNER ============ */
.banner {
  position: fixed;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  z-index: 800;
  font-family: 'Reem Kufi', sans-serif;
  font-size: 120px;
  font-weight: 800;
  color: var(--libyan-gold-bright);
  text-shadow:
    0 0 30px var(--libyan-gold-bright),
    0 0 60px var(--libyan-gold),
    0 6px 0 #5a3a00,
    0 12px 30px rgba(0,0,0,0.8);
  letter-spacing: 4px;
  pointer-events: none;
  opacity: 0;
}
.banner.show { animation: banner-pop 2.2s var(--ease-back) forwards; }
.banner.opponent { color: var(--terracotta); text-shadow: 0 0 30px var(--terracotta), 0 0 60px var(--phoenician-red), 0 6px 0 #3a0e15, 0 12px 30px rgba(0,0,0,0.8); }
/* Multi-word narrative banners (the round-3 «جرية بجرية والعكرة يجري»).
   The base .banner is 120px + no width/wrap, tuned for SHORT tokens —
   a full sentence overflowed the phone massively (user 2026-05-31:
   "UI/UX سئ جداً كبير"). Cap it responsively, allow wrapping, and bound
   the width so it always fits 375px without horizontal overflow. */
.banner.banner-sentence {
  font-size: clamp(30px, 8vw, 60px);
  letter-spacing: 1px;
  max-width: min(92vw, 640px);
  white-space: normal;
  text-align: center;
  line-height: 1.25;
  overflow-wrap: break-word;
}
@keyframes banner-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-8deg); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(2deg); }
  35% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.2) rotate(0deg); }
}

/* ============ SCREEN FLASH ============ */
.screen-flash {
  position: fixed;
  inset: 0;
  z-index: 700;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255,215,0,0.4) 0%, transparent 60%);
  opacity: 0;
}
.screen-flash.fire { background: radial-gradient(ellipse at center, rgba(200,50,50,0.5) 0%, transparent 60%); }
.screen-flash.show { animation: flash 0.6s ease-out; }
@keyframes flash {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}

/* ============ SHAKE ============ */
.shake { animation: shake 0.5s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10% { transform: translateX(-12px) translateY(4px); }
  20% { transform: translateX(10px) translateY(-3px); }
  30% { transform: translateX(-8px) translateY(2px); }
  40% { transform: translateX(7px); }
  50% { transform: translateX(-5px); }
  60% { transform: translateX(4px); }
  70% { transform: translateX(-2px); }
  80% { transform: translateX(1px); }
}

/* ============ HAYYA SNAKE OVERLAY ============ */
.snake-overlay {
  position: fixed;
  inset: 0;
  z-index: 750;
  pointer-events: none;
  display: grid;
  place-items: center;
  opacity: 0;
}
.snake-overlay.show { animation: snake-show 3s ease-out; }
@keyframes snake-show {
  0% { opacity: 0; }
  10% { opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; }
}
.snake-overlay svg {
  width: 480px;
  height: 480px;
  filter: drop-shadow(0 0 30px rgba(255,215,0,0.8)) drop-shadow(0 0 60px rgba(255,180,0,0.5));
}
.snake-overlay .snake-path {
  stroke-dasharray: 1200;
  stroke-dashoffset: 1200;
  animation: snake-draw 2.4s var(--ease-out) forwards;
}
@keyframes snake-draw {
  0% { stroke-dashoffset: 1200; }
  60% { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: 0; }
}

.whisper {
  position: fixed;
  bottom: 30%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 760;
  font-family: 'Amiri', 'Reem Kufi', serif;
  font-style: italic;
  font-size: 28px;
  color: rgba(255, 215, 0, 0.9);
  text-shadow: 0 0 12px rgba(255, 215, 0, 0.7);
  letter-spacing: 8px;
  opacity: 0;
  pointer-events: none;
}
.whisper.show { animation: whisper-rise 3s ease-out; }
@keyframes whisper-rise {
  0% { opacity: 0; transform: translateX(-50%) translateY(20px); letter-spacing: 4px; }
  30% { opacity: 1; letter-spacing: 12px; }
  70% { opacity: 1; letter-spacing: 14px; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-20px); letter-spacing: 18px; }
}

/* ============ SHAKKBA WAVE ============ */
.gold-wave {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  border-radius: 14px;
  overflow: hidden;
  opacity: 0;
}
.gold-wave.show { animation: wave-show 1.8s ease-out; }
@keyframes wave-show {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}
.gold-wave::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -100%;
  width: 60%;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255,215,0,0.4) 30%,
    rgba(255,255,200,0.95) 50%,
    rgba(255,215,0,0.4) 70%,
    transparent 100%);
  filter: blur(2px);
  animation: wave-sweep 1.8s var(--ease-out);
}
@keyframes wave-sweep {
  0% { left: -100%; }
  100% { left: 110%; }
}

/* particles */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 720;
}
.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--libyan-gold-bright);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--libyan-gold-bright);
}

/* ============ TWEAKS / TRIGGER PANEL ============ */
.trigger-panel {
  position: fixed;
  top: 60px;
  left: 16px;
  z-index: 900;
  background: rgba(15, 20, 18, 0.92);
  border: 1px solid rgba(201, 169, 97, 0.3);
  border-radius: 16px;
  padding: 12px;
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 200px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  transition: transform 0.3s ease, opacity 0.3s ease;
  max-height: calc(100vh - 280px);
  overflow-y: auto;
}
.trigger-panel.collapsed {
  transform: translateX(calc(-100% + 36px));
}
.trigger-panel .toggle-btn {
  position: absolute;
  top: 12px;
  right: -2px;
  background: var(--libyan-gold);
  color: var(--midnight);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.trigger-panel h4 {
  font-family: 'Reem Kufi', sans-serif;
  font-size: 13px;
  color: var(--libyan-gold);
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.trigger-btn {
  background: linear-gradient(180deg, rgba(201,169,97,0.15), rgba(201,169,97,0.05));
  border: 1px solid rgba(201,169,97,0.3);
  color: var(--ivory);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  text-align: start;
  font-family: 'Cairo', sans-serif;
  transition: all 0.2s ease;
}
.trigger-btn:hover {
  background: linear-gradient(180deg, rgba(201,169,97,0.3), rgba(201,169,97,0.15));
  border-color: var(--libyan-gold);
  transform: translateX(-2px);
}
.trigger-btn .ico { margin-inline-end: 6px; }

/* turn indicator badge */
.turn-badge {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  background: rgba(15, 20, 18, 0.85);
  border: 1px solid rgba(201, 169, 97, 0.4);
  border-radius: 30px;
  padding: 8px 24px;
  font-family: 'Reem Kufi', sans-serif;
  font-size: 14px;
  color: var(--libyan-gold);
  backdrop-filter: blur(8px);
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}
.turn-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--libyan-gold);
  box-shadow: 0 0 8px var(--libyan-gold);
  animation: turn-pulse 1.2s ease-in-out infinite;
}

/* arrow indicator from bot to chosen card */
.bot-arrow {
  position: fixed;
  z-index: 450;
  pointer-events: none;
  opacity: 0;
}
.bot-arrow.show { animation: arrow-show 1.6s ease-out; }
@keyframes arrow-show {
  0% { opacity: 0; transform: scale(0.6); }
  20% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.1); }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ POINTS DISPLAY MODES ============ */
/* The host picks one of three modes when creating the table. Engine state
   includes rules.points_display; game.js mirrors it onto the scene as
   data-points. CSS hides the appropriate UI bits below — JS no longer
   needs to per-element toggle because mode changes via re-render. */

/* "total_only": no breakdown chips on any profile, but score numbers
   stay visible. */
.scene[data-points="total_only"] .breakdown-chips,
.scene[data-points="hidden"] .breakdown-chips { display: none !important; }

/* "hidden": no score block at all on any profile, no team scoreline. The
   round-end modal is the only place totals are revealed. */
.scene[data-points="hidden"] .player-score-row,
.scene[data-points="hidden"] .bot-score-row,
.scene[data-points="hidden"] .side-score-row { display: none !important; }
.scene[data-points="hidden"] .captures-pile,
.scene[data-points="hidden"] .side-pile { display: none !important; }
/* Hide the deck-side card-count too — it's effectively a score peek. */
.scene[data-points="hidden"] .deck-counter { display: none !important; }

/* ============================================================================
 *  TEAM 2v2 — four contained seats around the felt   (redesign 2026-06-03)
 * ----------------------------------------------------------------------------
 *  The previous 2v2 layout floated the side opponents, the deck and the team
 *  scoreline as `position: fixed` overlays on top of a centre felt that was
 *  only PADDED to dodge them, so names / ping pills / capture piles / the deck
 *  bled onto the felt (owner: "الأسامي والبنيج داخلين في الطاولة",
 *  "كارطة المأكلة في نصف الطاولة", "الكارطة فوق ايموجي"). This rebuild makes
 *  the scene a real grid where every seat is a self-contained region:
 *
 *      score    : team totals (own row, centred)
 *      partner  : wide bar across the top
 *      leftrail | felt | rightrail
 *      you      : wide bar  +  your hand in its own strip
 *
 *  Nothing overlays the felt; each seat's avatar/name/score/ping/captures stay
 *  inside its own box. Mobile-first (base = 375px), enhanced up at >=760px.
 *  Scoped entirely to .scene[data-mode="team_2v2"] — 1v1 / vs_ai is untouched.
 * ========================================================================== */

/* Side rails are hidden outside 2v2 (the bot-zone is the partner in 2v2). */
.side-zone { display: none; }

/* ---- Scene becomes a 4-row / 3-column areas grid ------------------------- */
.scene[data-mode="team_2v2"] {
  /* Grid line 1 is always the physical left edge. Document direction is
     restored inside the children below so only coordinates stay LTR. */
  direction: ltr;
  grid-template-columns: clamp(78px, 22vw, 130px) minmax(0, 1fr) clamp(78px, 22vw, 130px);
  /* Middle row sizes to its content (not a greedy 1fr) and the three rows
     centre vertically — so the now-compact felt isn't left floating with
     tall rails + big dark gaps above/below it (owner 2026-06-06). */
  grid-template-rows: auto auto auto;
  grid-template-areas:
    "partner  partner partner"
    "leftrail felt  rightrail"
    "you      you   you";
  gap: 6px;
  align-items: stretch;
  align-content: center;
}
/* The top team scoreline is removed in 2v2: every seat already shows its
   own team total (you + partner = your team, both opponents = their team),
   so the فريقك×الخصوم banner was redundant (owner 2026-06-06). */
.scene[data-mode="team_2v2"] #team-scoreline  { display: none; }
.scene[data-mode="team_2v2"] .bot-zone        { grid-area: partner; }
/* Counter-clockwise play (owner 2026-06-06: "اللعب عكس عقارب"). The named
   rails are physical, locale-independent coordinates: +1 stays on the right
   and +3 stays on the left, so play remains you→right→partner→left. */
.scene[data-mode="team_2v2"] .side-zone-left  { grid-area: leftrail; }
.scene[data-mode="team_2v2"] .table-zone      { grid-area: felt; }
.scene[data-mode="team_2v2"] .side-zone-right { grid-area: rightrail; }
.scene[data-mode="team_2v2"] .player-zone     { grid-area: you; }

html[dir="rtl"] .scene[data-mode="team_2v2"] > * { direction: rtl; }
html[dir="ltr"] .scene[data-mode="team_2v2"] > * { direction: ltr; }

/* ---- Top (partner) + bottom (you) become wide horizontal bars ----------- */
.scene[data-mode="team_2v2"] .bot-zone,
.scene[data-mode="team_2v2"] .player-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 8px;
  min-width: 0;
}
.scene[data-mode="team_2v2"] .bot-zone { flex-direction: row; }       /* partner bar */
.scene[data-mode="team_2v2"] .player-zone { flex-direction: column; } /* bar + hand strip */

.scene[data-mode="team_2v2"] .profile-with-pile,
.scene[data-mode="team_2v2"] .player-zone .profile-with-pile,
.scene[data-mode="team_2v2"] .bot-zone .profile-with-pile {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex: 0 1 auto;
  min-width: 0;
}

.scene[data-mode="team_2v2"] .profile-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 5px 10px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(20,30,25,0.85), rgba(10,15,12,0.92));
  border: 1px solid rgba(201,169,97,0.3);
  box-shadow: 0 4px 12px rgba(0,0,0,0.45);
}
.scene[data-mode="team_2v2"] .profile-card .player-avatar,
.scene[data-mode="team_2v2"] .profile-card .bot-avatar {
  width: 44px; height: 44px;
  font-size: 16px; font-weight: 800;
  font-family: 'Reem Kufi', sans-serif;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(201,169,97,0.3);
}
.scene[data-mode="team_2v2"] .profile-card .player-info,
.scene[data-mode="team_2v2"] .profile-card .bot-info {
  display: flex; flex-direction: column;
  align-items: flex-start; text-align: start;
  gap: 1px; min-width: 0;
}
.scene[data-mode="team_2v2"] .profile-card .player-name,
.scene[data-mode="team_2v2"] .bot-name {
  font-size: 13px; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 34vw;
}
.scene[data-mode="team_2v2"] .player-score-row,
.scene[data-mode="team_2v2"] .bot-score-row { display: flex; align-items: baseline; gap: 4px; }
.scene[data-mode="team_2v2"] .profile-card .num {
  font-size: 17px; font-weight: 700; color: var(--libyan-gold);
  direction: ltr; font-feature-settings: "tnum";
}
.scene[data-mode="team_2v2"] .bot-status { display: none; }
.scene[data-mode="team_2v2"] .breakdown-chips { display: none; }

/* Team grouping by colour: your team (you + partner) gold, opponents coral. */
.scene[data-mode="team_2v2"] .bot-zone .profile-card,
.scene[data-mode="team_2v2"] .player-zone .profile-card { border-color: rgba(255,215,0,0.40); }
.scene[data-mode="team_2v2"] .side-profile { border-color: rgba(255,138,150,0.42); }

/* Active player (any of the four seats) gets a brighter ring. */
.scene[data-mode="team_2v2"] .profile-card.active,
.scene[data-mode="team_2v2"] .side-profile.active {
  border-color: var(--libyan-gold-bright);
  box-shadow: 0 0 18px rgba(255,215,0,0.35), 0 4px 12px rgba(0,0,0,0.45);
}

/* ---- Capture piles: compact + contained in every seat ------------------- */
.scene[data-mode="team_2v2"] .captures-pile,
.scene[data-mode="team_2v2"] .side-pile {
  width: 42px; height: 56px; margin: 0; flex-shrink: 0;
}
.scene[data-mode="team_2v2"] .captures-pile .cp-stack,
.scene[data-mode="team_2v2"] .side-pile .cp-stack { width: 38px; height: 50px; }
.scene[data-mode="team_2v2"] .captures-pile .cp-count { font-size: 15px; }
.scene[data-mode="team_2v2"] .captures-pile .cp-label,
.scene[data-mode="team_2v2"] .side-pile .cp-label { font-size: 8px; bottom: -12px; letter-spacing: 0; }
.scene[data-mode="team_2v2"] #bot-profile-pile .cp-label { color: rgba(201,169,97,0.7); }

/* ---- Partner hand (top): small face-down backs, inline in the bar ------- */
.scene[data-mode="team_2v2"] .bot-hand {
  height: auto; min-height: 0; perspective: none;
  display: flex; align-items: center; gap: 3px; flex: 0 0 auto;
}
.scene[data-mode="team_2v2"] .bot-hand .card { width: 30px !important; height: 44px !important; margin: 0 !important; }

/* ---- Your hand (bottom): its own full-width strip, centred -------------- */
.scene[data-mode="team_2v2"] .player-hand {
  height: auto; min-height: 92px; width: 100%;
  display: flex; justify-content: center; align-items: center; gap: 6px;
  perspective: 1000px; padding: 2px 0;
}
.scene[data-mode="team_2v2"] .player-hand .card {
  width: clamp(50px, 15vw, 66px) !important;
  height: clamp(74px, 22vw, 96px) !important;
}

/* ---- Side rails (left/right opponents): real flanking columns ----------- */
.scene[data-mode="team_2v2"] .side-zone {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 5px;
  position: static; transform: none; inset: auto;
  min-width: 0; width: 100%; padding: 4px 2px;
  pointer-events: auto;
}
.side-profile {
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; width: 100%; min-width: 0;
  padding: 6px 4px; border-radius: 12px;
  background: linear-gradient(180deg, rgba(20,30,25,0.85), rgba(10,15,12,0.92));
  border: 1px solid rgba(201,169,97,0.3);
  box-shadow: 0 4px 12px rgba(0,0,0,0.45);
}
.side-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f5d989 0%, #c9a961 45%, #8a6e2f 100%);
  display: grid; place-items: center;
  color: #1A1A2E; font-weight: 800; font-size: 13px;
  font-family: 'Reem Kufi', sans-serif;
  box-shadow: 0 0 0 2px rgba(201,169,97,0.3); flex-shrink: 0;
}
.side-name {
  font-family: 'Reem Kufi', sans-serif; font-size: 11px;
  color: var(--libyan-gold); text-align: center; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.side-score-row { display: flex; align-items: baseline; gap: 4px; font-family: 'Reem Kufi', sans-serif; }
.side-score-row .num {
  font-size: 15px; font-weight: 700; color: var(--libyan-gold);
  direction: ltr; font-feature-settings: "tnum";
}
.side-score-row .num-label { font-size: 9px; color: rgba(255,248,231,0.45); }
.side-hand {
  display: flex; flex-direction: row; align-items: center;
  gap: 2px; margin-top: 2px;
}
.side-hand .card { width: 22px !important; height: 32px !important; margin: 0 !important; }
/* The ping pill (.ping-chip, injected by paintPingChips into each seat) now
   sits inside its seat box — never over the felt. Keep it tight in the rail. */
.scene[data-mode="team_2v2"] .side-profile .ping-chip { margin-top: 2px; font-size: 0.62rem; padding: 1px 5px; }

/* ---- Team scoreline: own row at the very top, centred ------------------- */
.team-scoreline {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(180deg, rgba(20,30,25,0.9), rgba(10,15,12,0.95));
  border: 1.5px solid rgba(201,169,97,0.4);
  border-radius: 999px;
  padding: 4px 14px;
  font-family: 'Reem Kufi', sans-serif;
  box-shadow: 0 8px 24px rgba(0,0,0,0.55);
  pointer-events: none;
}
.team-scoreline[hidden] { display: none; }
.scene[data-mode="team_2v2"] .team-scoreline {
  position: static; transform: none;
  justify-self: center; align-self: center;
  margin: 2px auto 0;
}
.team-pill { display: flex; align-items: center; gap: 6px; }
.team-pill-label { font-size: 11px; color: rgba(255,248,231,0.7); }
.team-pill-score { font-size: 16px; font-weight: 800; font-feature-settings: "tnum"; }
.team-pill.team-a .team-pill-score { color: var(--libyan-gold-bright); }
.team-pill.team-b .team-pill-score { color: #ff8a96; }
.team-vs { color: rgba(255,248,231,0.45); font-size: 13px; }

/* ---- Felt + deck: deck stacked ABOVE the felt in normal flow ------------
 *  At 375px the felt cell is too narrow to seat the deck beside it, and
 *  floating the deck over the felt (position:absolute) put it on top of the
 *  played cards (owner: "تداخل"). So the table-zone is a flex column — the
 *  deck is a compact in-flow strip on top, the felt fills the rest — which
 *  makes it geometrically impossible for the deck to overlap the cards.
 *  (Placing the deck beside the active dealer is the deferred design pass.) */
.scene[data-mode="team_2v2"] .table-zone {
  position: relative; display: flex; flex-direction: column;
  align-items: stretch; justify-content: center; padding: 2px; min-width: 0; gap: 4px;
}
.scene[data-mode="team_2v2"] .table-zone > div:empty { display: none; }
/* Square felt that grows with the cards (owner 2026-06-06: "خليها مربع
   وتكبر بناءاً عالأوراق"). The base felt is `flex:1` + `height:clamp()
   !important` (_overrides.css:1556) which made it a tall mostly-empty
   rectangle. Override the !important height to auto, set `aspect-ratio:1`
   so it's a SQUARE by default (height = the column width), and take the
   card layer OUT of the absolute `inset:0` fill so a busy table that needs
   more than the square pushes the felt TALLER (aspect-ratio yields to
   min-content) — no clipping under felt-inner's overflow:hidden.
   1v1/vs_ai keep the base absolute-centred felt (untouched). */
.scene[data-mode="team_2v2"] .felt {
  flex: 0 0 auto; align-self: stretch; margin: 0; min-width: 0;
  height: auto !important; min-height: 0 !important; max-height: none !important;
  aspect-ratio: 1 / 1;
  display: flex; flex-direction: column; justify-content: center;
}
.scene[data-mode="team_2v2"] .felt-inner { height: auto; min-height: 100%; }
.scene[data-mode="team_2v2"] .table-cards {
  position: static; inset: auto; width: 100%;
}
/* Spectator eye: quiet, pinned to the viewport bottom-right corner instead
   of floating in the deck
   column. Global (not 2v2-scoped) because the chip is now a direct child of
   #game-app in every mode — without fixed positioning it would auto-place
   into the grid. `right`/`bottom` are physical so it lands on the real right
   edge regardless of RTL; z-index on the floating-chrome tier. The centred
   player hand doesn't reach this corner. */
#spectator-chip {
  position: fixed; right: 6px; bottom: 6px; margin: 0; z-index: 600;
  width: 20px; height: 20px; min-height: 0; padding: 0; gap: 1px;
  border-radius: 50%;
  background: rgba(5, 8, 12, 0.24);
  color: rgba(255, 248, 231, 0.78);
  border: 1px solid rgba(255, 248, 231, 0.12);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
  font-size: 0.45rem; line-height: 1;
  align-items: center; justify-content: center;
  opacity: 0.3;
}
#spectator-chip .sc-icon {
  display: block;
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#spectator-chip .sc-count {
  font-size: 0.45rem;
  font-weight: 600;
  line-height: 1;
  opacity: 0.8;
}
/* Deck docked at the bottom-RIGHT corner; the eye is the bottom-left
   companion (player feedback 2026-06-21: "تغيير مكان الكارطة وتبديلها بمكان
   العين" — swap the two bottom corners in 2v2). position:fixed pins it to the
   viewport corner; the deck-column's OWN transform doesn't trap its own fixed
   (only ancestors do, and none are transformed). Out of the table-zone flow,
   so the felt fills the cell. pointer-events:none + a small scale keep it
   unobtrusive and clear of the centred hand. The eye gets the mirror override
   below (left in 2v2 only); 1v1/vs-bot keep their existing layout untouched. */
.scene[data-mode="team_2v2"] .deck-column {
  position: fixed; right: 6px; bottom: 6px; z-index: 600;
  flex: 0 0 auto; flex-direction: column; gap: 1px; align-items: flex-end;
  transform: scale(0.55); transform-origin: bottom right;
  pointer-events: none;
}
/* Eye → bottom-LEFT in 2v2 only (the swapped companion of the deck above).
   Higher specificity than the global #spectator-chip rule; right:auto resets
   the base right:8px so left wins. Other modes keep it bottom-right. */
.scene[data-mode="team_2v2"] #spectator-chip {
  right: auto; left: 8px;
}

/* ---- Tablet / desktop: scale the four seats up ------------------------- */
@media (min-width: 760px) {
  .scene[data-mode="team_2v2"] {
    grid-template-columns: clamp(150px, 18vw, 240px) minmax(0,1fr) clamp(150px, 18vw, 240px);
    gap: 12px;
  }
  .scene[data-mode="team_2v2"] .profile-card .player-avatar,
  .scene[data-mode="team_2v2"] .profile-card .bot-avatar,
  .scene[data-mode="team_2v2"] .side-avatar { width: 56px; height: 56px; font-size: 18px; }
  .scene[data-mode="team_2v2"] .profile-card .player-name,
  .scene[data-mode="team_2v2"] .bot-name,
  .scene[data-mode="team_2v2"] .side-name { font-size: 15px; max-width: none; }
  .scene[data-mode="team_2v2"] .profile-card .num,
  .scene[data-mode="team_2v2"] .side-score-row .num { font-size: 20px; }
  .scene[data-mode="team_2v2"] .captures-pile,
  .scene[data-mode="team_2v2"] .side-pile { width: 54px; height: 74px; }
  .scene[data-mode="team_2v2"] .captures-pile .cp-stack,
  .scene[data-mode="team_2v2"] .side-pile .cp-stack { width: 48px; height: 66px; }
  .scene[data-mode="team_2v2"] .captures-pile .cp-count { font-size: 22px; }
  .scene[data-mode="team_2v2"] .player-hand .card { width: clamp(64px, 7vw, 84px) !important; height: clamp(94px, 10vw, 122px) !important; }
  .scene[data-mode="team_2v2"] .bot-hand .card { width: 40px !important; height: 58px !important; }
  .scene[data-mode="team_2v2"] .side-hand .card { width: 30px !important; height: 44px !important; }
  .scene[data-mode="team_2v2"] .deck-column { transform: scale(0.9); }
}
