/* style.css */
/* ─── Reset & Container ─────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
p, span, button, #bg-message, .panel-header {
    direction: rtl !important;
    font-family: system-ui !important;
}

/* جلوگیری از پهن شدن صفحه و اسکرول افقی در موبایل */
html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
}

#bg-container {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    display: flex;
    flex-direction: column;
    align-items: center; 
    justify-content: flex-start; /* بهتر است روی center باشد تا در دسکتاپ هم وسط بیفتد */
    /* min-height: 100vh; برای اینکه همیشه کل صفحه را پر کند */
}

#bg-container h2 {
    margin-bottom: 12px;
    color: #5a2d0c;
    font-size: 24px;
}

/* ─── Game Area ─── */
#bg-game-area {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 848px !important;
    height: 496px !important;
    
    /* استفاده از نقطه مبدا که پیدا کردید */
    transform-origin: top left !important; 
    
    /* در حالت عادی فقط متغیر اسکیل داینامیک اعمال می‌شود */
    transform: scale(var(--board-scale, 1)) !important;
    
    display: flex;
    align-items: center;
    justify-content: center;
}

/* این کلاس توسط جاوا اسکریپت اسکیل می‌شود، پس فقط موقعیتش را وسط می‌چینیم */
#bg-scale-wrapper {
    position: relative !important;
    margin: 0 auto auto auto !important; /* margin-top صفر و margin-bottom اتوماتیک برای هل دادن به بالا */
    /* اگر والدش flex است: */
    align-self: flex-start !important; 
    
    transform-origin: center top !important; /* لولای تغییر سایز از بالا وسط باشد */
}

/* ─── Bear-off Box ───────────────────────────────────── */
.bg-bearoff {
    width: 60px;
    height: 480px;
    background: #5a2d0c;
    border: 4px solid #3a1a05;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px;
    gap: 0;
}

.bearoff-divider {
    width: 80%;
    height: 2px;
    background: #3a1a05;
    margin: 4px 0;
    flex-shrink: 0;
}

.bearoff-pieces {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    width: 40px;
    padding: 2px 0;
    overflow: hidden;
}

#bearoff-white-pieces {
    flex-direction: column;
    justify-content: flex-start;
}

#bearoff-black-pieces {
    flex-direction: column;
    justify-content: flex-end;
}

.bearoff-pieces .bg-piece {
    width: 40px;
    height: 12px;
    border-radius: 5px;
    flex-shrink: 0;
}

.bg-bearoff.highlight {
    outline: 3px solid #f0c040;
    outline-offset: -3px;
}

/* ─── Main Board ────────────────────────────────────── */
#bg-board {
    width: 780px;
    height: 480px;
    background: #a76534;
    border-top: 8px solid #5a2d0c;
    border-bottom: 8px solid #5a2d0c;
    border-left: 8px solid #5a2d0c;
    position: relative;
    display: grid;
    grid-template-columns: repeat(6, 1fr) 60px repeat(6, 1fr);
    grid-template-rows: 1fr 1fr;
    overflow: visible;
}

.bg-board {
    position: relative;
}

.bg-animation-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: visible;
}

/* ─── Bar ───────────────────────────────────────────── */
.bg-bar {
    grid-column: 7;
    grid-row: 1 / span 2;
    background: #6b3a10;
    box-shadow:
        inset 3px 0 6px rgba(0,0,0,0.4),
        inset -3px 0 6px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    z-index: 2;
    position: relative;
}

.bg-bar-half {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 40px 0;
}

.bar-bottom {
    flex-direction: column-reverse;
}

.bg-bar-mid {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 0;
    flex-shrink: 0;
}

/* ─── Points ────────────────────────────────────────── */
.bg-point {
    position: relative;
    display: flex;
    align-items: center;
    overflow: visible;
    cursor: pointer;
    align-items: center;
}

.bg-point.top {
    grid-row: 1;
    flex-direction: column;
    justify-content: flex-start;
    padding-top: 4px;    /* ← فضای بالا */
}

.bg-point.bottom {
    grid-row: 2;
    flex-direction: column-reverse;
    justify-content: flex-start;
    padding-bottom: 4px;  /* ← فضای پایین */
}

.bg-point::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    width: 0;
    height: 0;
    margin: 0 auto;
    z-index: 0;
}

.bg-point.top::before {
    top: 0;
    border-left: min(22px, 3.5vw) solid transparent;   /* ← responsive */
    border-right: min(22px, 3.5vw) solid transparent;
    border-top: min(180px, 36vh) solid;
}

.bg-point.bottom::before {
    bottom: 0;
    border-left: min(22px, 3.5vw) solid transparent;
    border-right: min(22px, 3.5vw) solid transparent;
    border-bottom: min(180px, 36vh) solid;             /* ← ارتفاع کمتر */
}

.bg-point.top.even::before    { border-top-color: #48150073; }
.bg-point.top.odd::before     { border-top-color: #f0d9b561; }
.bg-point.bottom.even::before { border-bottom-color: #48150073; }
.bg-point.bottom.odd::before  { border-bottom-color: #f0d9b561; }

.bg-point-number {
    position: absolute;
    font-size: 9px;
    font-weight: bold;
    color: rgba(0,0,0,0.4);
    z-index: 3;
    pointer-events: none;
    display: none;
}

.bg-point.top    .bg-point-number { bottom: 4px; }
.bg-point.bottom .bg-point-number { top: 4px; }

.bg-point.highlight {
    background: #00ff2b42;
    /* margin: 0 1px; */
    box-shadow: inset 0 0 0 2px rgba(0, 255, 43, 0.6); /* جایگزین بصری */
}

.bg-point.selected {
    outline: 3px solid #f0c040;
    outline-offset: -3px;
    background: rgba(240, 192, 64, 0.18);
    z-index: 2;
}

.bg-point.valid-target {
    outline: 3px solid #40c070;
    outline-offset: -3px;
    background: rgba(64, 192, 112, 0.18);
    z-index: 2;
}

/* مهره‌های stack شده روی هم */
.bg-piece.stacked {
    position: absolute !important;
    z-index: 10;
}

/* مهره‌های زیرین که مخفی‌اند */
.bg-piece.hidden-under {
    opacity: 0;
    pointer-events: none;
}

/* مهره‌ای که عدد داره باید بالاترین باشه */
.bg-piece.has-count {
    z-index: 15 !important;
}
/* ─── Pieces ────────────────────────────────────────── */
.bg-piece {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 3px solid rgba(0,0,0,0.5);
    position: relative;
    z-index: 1;
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
    transition: transform 0.15s;
}

.bg-piece:hover { transform: scale(1.08); }

.bg-piece.white {
    background: radial-gradient(circle at 35% 35%, #fff, #a49865);
    border-color: #beac7d;
}

.bg-piece.black {
    background: radial-gradient(circle at 35% 35%, #5f2e00, #000);
    border-color: #2b1500;
}

/* مهره‌های stacked: absolute روی آخرین مهره visible */
.bg-piece.stacked {
    position: absolute !important;
    box-shadow: 0px 0px 6px 0px #00000059;
}

/* برای top points: stacked ها پایین مهره پنجم */
.bg-point.top .bg-piece.stacked {
    bottom: 18px;
}

/* برای bottom points: stacked ها بالای مهره پنجم */
.bg-point.bottom .bg-piece.stacked {
    top: 18px;
}

/* مهره‌های مخفی */
.bg-piece.hidden-under {
    visibility: hidden;
    pointer-events: none;
}

/* عدد روی مهره آخر */
.bg-piece.has-count {
    z-index: 15 !important;
}

.bg-piece.has-count::after {
    content: attr(data-count);
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    border-radius: 50%;
}

.bg-piece.white.has-count::after {
    color: #222;
    text-shadow: 0 1px 2px rgba(255,255,255,0.5);
}

/* ─── Bear-off halves ───────────────────────────────── */
#bg-bearoff-column {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 70px;
    margin-left: 8px;
}

.bearoff-half {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2px;
    gap: 4px;
    overflow: hidden;
}

.bearoff-half:first-child {
    border-bottom: 2px solid #3a1a05;
}

.bg-bearoff.highlight-bearoff {
    outline: 3px solid #00ff2b42;
    box-shadow: 0 0 10px rgba(255, 255, 0, 0.7);
}

.bearoff-half.highlight-bearoff {
    outline: 3px solid #00ff2b42;
    box-shadow: 0 0 10px rgba(255, 255, 0, 0.7);
    cursor: pointer;
}

.bearoff-label { display: none; }

/* ─── Controls ──────────────────────────────────────── */
#bg-controls {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#bg-roll {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    font-size: 16px;
    font-weight: bold;
    background: brown;
    color: #f0d9b5;
    border: 2px solid #c29b66;
    cursor: pointer;
    padding: 0;
    line-height: 1.2;
    transition: background 0.2s, opacity 0.2s;
    text-align: center;
}

#bg-roll:hover:not(:disabled) { background: #7a3d1c; }
#bg-roll:disabled { opacity: 0.45; cursor: not-allowed; }

/* ─── Dice ──────────────────────────────────────────── */
#bg-dice-area {
    display: none;
}

.dice {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: 2px solid #333;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 3px;
    box-shadow: 2px 2px 4px rgba(0,0,0,0.4);
}

.dice.white { background: #dbceac; }
.dice.black { background: #2b1500; }

.dice .dot {
    border-radius: 50%;
    margin: auto;
    width: 7px;
    height: 7px;
}

.dice.white .dot { background: #111; }
.dice.black .dot { background: #eee; }
.dice.used { opacity: 0.35; box-shadow: none; }

/* ─── Message ───────────────────────────────────────── */
#bg-message {
    margin-top: 10px;
    font-size: 15px;
    font-weight: bold;
    color: #a4764f;
    min-height: 22px;
}

/* ─── Undo Button ───────────────────────────────────── */
#bg-undo-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #c29b66;
    background: #3a2010;
    color: #f0c040;
    font-size: 14px;
    cursor: pointer;
    position: static;
    transform: none;
    z-index: 10;
    transition: background 0.2s;
    text-align: center;
    padding: 0;
    margin-top: 30px;
}

#bg-undo-btn:hover { background: #5a3020; }

.bg-modal-box h3 {
    color: #ecf0f1;
    font-size: 2em;
    margin: 0 0 10px 0;
}

.bg-modal-box p {
    color: #bdc3c7;
    margin: 0 0 30px 0;
}

.bg-mode-buttons, .bg-difficulty-buttons {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.bg-mode-btn {
    flex: 1;
    padding: 15px 20px;
    font-size: 1.1em;
    border: 2px solid #7f8c8d;
    background: #34495e;
    color: #ecf0f1;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.bg-mode-btn:hover { 
    background: #4a5f7f;
    border-color: #3498db;
    transform: translateY(-2px);
 }

.bg-mode-btn.active {
    background: #3498db;
    border-color: #2980b9;
    box-shadow: 0 0 20px rgba(52, 152, 219, 0.5);
}

.bg-mode-btn.start-btn {
    width: 100%;
    background: #27ae60;
    border-color: #229954;
    font-weight: bold;
}

.bg-mode-btn.start-btn:hover { 
    background: #2ecc71;
    transform: scale(1.05);
 }

.bg-diff-btn {
    background: #3a2510;
    color: #f5deb3;
    border: 2px solid #5a3a1a;
    border-radius: 8px;
    padding: 8px 18px;
    cursor: pointer;
    transition: all 0.2s;
}

.bg-diff-btn:hover { background: #5a3a1a; }

.bg-diff-btn.active {
    background: #8B6914;
    border-color: #f5c842;
    color: #fff;
    font-weight: bold;
}

/* ════════════════════════════════════════════════════════
   ─── FULLSCREEN BUTTON ───────────────────────────────
   ════════════════════════════════════════════════════════ */
#fullscreen-btn {
    position: fixed;
    bottom: 14px;
    left: 14px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid #c29b66;
    background: #3a2010;
    color: #f0c040;
    font-size: 20px;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    transition: background 0.2s, transform 0.15s;
    line-height: 1;
}

#fullscreen-btn:hover {
    background: #5a3020;
    transform: scale(1.1);
}

:root {
    --board-scale: 1;
}

/* برای landscape mobile: اطمینان از نمایش کامل */
@media screen and (max-height: 650px) and (orientation: landscape) {
    
    #bg-container h2 {
        font-size: 14px;
        margin-bottom: 4px;
    }
    
    #bg-message {
        font-size: 12px;
        margin-top: 4px;
    }
}


body.fs-active {
    overflow: hidden;
}

body {
    overflow-x: hidden;
    min-width: 320px;
}

/* ─── Dice Overlay روی تخته ─────────────────────────── */
#bg-dice-overlay {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    right: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    z-index: 10;
    pointer-events: none;
    /* دو ناحیه مساوی */
}

#bg-dice-overlay .dice {
    pointer-events: none;
}

#bg-dice-overlay-white {
    /* نیمه راست تخته */
    position: absolute;
    right: 15%;
    display: flex;
    gap: 6px;
    align-items: center;
}

#bg-dice-overlay-black {
    /* نیمه چپ تخته */
    position: absolute;
    left: 15%;
    display: flex;
    gap: 6px;
    align-items: center;
}

.bg-piece.moving {
    position: fixed;
    z-index: 1000;
    transition: left 0.4s ease, top 0.4s ease;
    pointer-events: none;
}

@keyframes diceRoll {
    0%   { transform: rotateX(0deg)   rotateY(0deg)   rotateZ(0deg); opacity: 0.3; }
    25%  { transform: rotateX(180deg) rotateY(90deg)  rotateZ(45deg); opacity: 0.7; }
    50%  { transform: rotateX(90deg)  rotateY(270deg) rotateZ(180deg); opacity: 0.9; }
    75%  { transform: rotateX(270deg) rotateY(180deg) rotateZ(90deg); opacity: 0.7; }
    100% { transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg); opacity: 1; }
}

.dice.rolling {
    animation: diceRoll 0.4s ease-in-out;
}

/* یا اگر container والد WordPress داره: */
.is-layout-constrained #bg-container {
    max-width: none !important;
}

@media screen and (max-width: 600px) and (orientation: portrait) {

    /* کوچک کردن پنل بالا در موبایل تا جا برای تخته باز شود */
    .game-mode-panel {
        width: 95%;
        padding: 10px;
        margin-bottom: 10px;
    }
}


/* Game Mode Panel - بالای تخته */
.game-mode-panel {
    background: linear-gradient(135deg, #602906 0%, #a4764f 100%);
    border: 2px solid #f39c12;
    border-radius: 16px;
    padding: 20px;
    margin: 0 auto 20px;
    /* min-width: 400px; */
    box-shadow: 0 8px 32px rgba(243, 156, 18, 0.2);
    direction: rtl;
}

.panel-header {
    text-align: center;
    color: #ecf0f1;
    font-size: 18px;
    margin-bottom: 15px;
    font-weight: 600;
}

.mode-toggle {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 20px;
}

.mode-btn {
    flex: 1;
    max-width: 200px;
    padding: 14px 24px;
    font-size: 16px;
    font-weight: 600;
    border: 2px solid #34495e;
    border-radius: 12px;
    background: #2c3e50;
    color: #bdc3c7;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 155px;
    text-align: center;
    margin: 3px;
}

.mode-btn:hover {
    background: #34495e;
    border-color: #f39c12;
    transform: translateY(-2px);
}

.mode-btn.active {
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
    border-color: #f39c12;
    color: #fff;
    box-shadow: 0 4px 15px rgba(243, 156, 18, 0.4);
}

.start-game-btn {
    width: 100%;
    /* max-width: 300px; */
    margin: 0 auto;
    display: block;
    padding: 16px 32px;
    font-size: 18px;
    font-weight: 700;
    background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 20px rgba(243, 156, 18, 0.3);
    text-align: center;
}

.start-game-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(243, 156, 18, 0.5);
}

.start-game-btn:active {
    transform: translateY(-1px);
}

/* Restart Button - پایین تخته */
.restart-btn {
    display: block;
    margin: 20px auto 0;
    padding: 14px 28px;
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.5);
}

.restart-btn:active {
    transform: translateY(0);
}

/* Responsive */
@media screen and (max-width: 600px) {
    .game-mode-panel {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .panel-header {
        font-size: 16px;
        margin-bottom: 12px;
    }
    
    .mode-toggle {
        gap: 10px;
    }
    
    .mode-btn {
        max-width: 100%;
        padding: 12px 20px;
        font-size: 14px;
    }
    
    .start-game-btn {
        padding: 14px 24px;
        font-size: 16px;
    }
    
    .restart-btn {
        padding: 12px 24px;
        font-size: 14px;
    }
}

.e-con>.e-con-inner {
    max-width: 100% !important;
}
/* ================================================== */
/*   بخش ۱: استایل یکپارچه نوار ابزار بالای صفحه      */
/* ================================================== */

/* --- ساختار اصلی نوار ابزار --- */
.game-tools-bar {
    display: flex;
    justify-content: space-between; /* آیتم‌ها در دو سمت قرار می‌گیرند */
    align-items: center;
    padding: 8px 15px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
}

.tool-group-left, .tool-group-right {
    display: flex;
    align-items: center;
    gap: 10px; /* فاصله بین آیتم‌ها */
}

/* --- استایل عمومی دکمه‌های نوار ابزار --- */
.game-tools-bar button {
    background-color: #282828;
    color: #e0e0e0;
    border: 1px solid #555;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 5px;
}
.game-tools-bar button:hover {
    background-color: #444;
    border-color: #777;
}

/* --- استایل اختصاصی دکمه صدا (از کد شما) --- */
#btn-toggle-sound.sound-off {
    color: #ff6b6b;
    border-color: #ff6b6b;
}

/* --- استایل بخش اطلاعات کاربر (راست) --- */
.user-info-display {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ddd;
    font-size: 14px;
}
.user-info-display .user-name {
    font-weight: bold;
}
.user-info-display .user-score {
    color: #ffd700; /* رنگ طلایی برای امتیاز */
}
.user-info-display .user-icon {
    font-size: 22px;
    line-height: 1;
}
.logout-button {
    background: #8c3a3a !important; /* !important برای اولویت بالاتر */
    padding: 5px 8px !important;
    font-size: 18px !important;
    font-weight: bold;
    color: white !important;
}
.logout-button:hover {
    background: #a14d4d !important;
}

/* =============================================== */
/*   بخش ۲: استایل بهبودیافته مودال ورود/ثبت‌نام   */
/* =============================================== */

#bg-auth-modal,
#bg-p2-auth-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: inherit;
}
#bg-auth-modal-content {
    background: #2c2c2c;
    color: #f0f0f0;
    padding: 25px 30px;
    border-radius: 8px;
    width: 320px;
    text-align: center;
    direction: rtl;
    border: 1px solid #555;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}
#bg-auth-modal-content h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #fff;
    font-size: 20px;
}
#bg-auth-modal-content input {
    width: 100%;
    margin-bottom: 12px;
    padding: 10px;
    box-sizing: border-box;
    border-radius: 4px;
    border: 1px solid #555;
    background: #444;
    color: #fff;
    text-align: center;
    font-family: inherit;
    font-size: 14px;
}
#bg-auth-modal-content #btn-submit-auth {
    width: 100%;
    padding: 12px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    margin-top: 10px;
}
#bg-auth-modal-content #btn-submit-auth:hover {
    background-color: #0069d9;
}
#bg-auth-modal-content #btn-submit-auth:disabled {
    background-color: #555;
    cursor: not-allowed;
}
#bg-auth-modal-content #toggle-auth-link {
    display: block;
    margin-top: 15px;
    font-size: 13px;
    color: #aaa;
    text-decoration: none;
}
#bg-auth-modal-content #toggle-auth-link:hover {
    text-decoration: underline;
}
#bg-auth-modal-content .close-modal-btn {
    font-size: 12px;
    background: #6c757d;
    border: none;
    color: white;
    cursor: pointer;
    margin-top: 8px;
    width: 100%;
    padding: 8px;
    border-radius: 5px;
}
#bg-auth-msg {
    min-height: 18px; /* جلوگیری از پرش صفحه */
    color: #ff6b6b;
    font-size: 13px;
}

/* کلاس برای چرخاندن عمودی تخته برای بازیکن سفید در حالت آنلاین */
#bg-game-area.flip-board-vertical {
    transform-origin: top left !important;
    transform: scale(var(--board-scale, 1)) rotateX(180deg) translateY(-100%) !important;
}
/* چرخاندن مجدد عناصر داخل تخته تا وارونه نمایش داده نشوند */
.flip-board-vertical #bg-controls,
.flip-board-vertical #bg-message,
.flip-board-vertical .bg-bar-mid,
.flip-board-vertical #bg-dice-overlay,
.flip-board-vertical .bg-piece.has-count::after {
    transform: rotateX(180deg);
}
.flip-board-vertical .bg-piece {
    box-shadow: 0 -2px 4px rgba(0,0,0,0.4);
}

/* leaderboard */
.bg-accordion-btn {
    width: 100%;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3); /* پس‌زمینه شیشه‌ای تیره */
    color: #fff;
    border: 1px solid #f39c12; /* حاشیه همرنگ دکمه‌ها */
    border-radius: 10px;
    cursor: pointer;
    text-align: right;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s ease;
}
.bg-accordion-btn:hover {
    background: rgba(0, 0, 0, 0.5);
}
.bg-accordion-content {
    max-height: 0; /* برای افکت اسلاید */
    overflow: hidden;
    transition: max-height 0.4s ease-out;
    background: transparent;
    color: #fff;
}
.bg-leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
    margin-top: 15px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.bg-leaderboard-table th, .bg-leaderboard-table td {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px;
}
.bg-leaderboard-table th {
    background-color: rgba(0, 0, 0, 0.4);
    color: #f39c12; /* رنگ نارنجی برای سرستون‌ها */
    font-weight: bold;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

/* rooms status */
.rooms-container {
    margin-top: 15px;
    margin-bottom: 15px;
    text-align: right;
}
.rooms-container h4 {
    margin: 10px 0;
    color: #f39c12; /* همرنگ سرستون‌های لیدربورد و دکمه‌ها */
    border-bottom: 1px dashed rgba(255, 255, 255, 0.2);
    padding-bottom: 5px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.room-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.4); /* تم تیره و شیشه‌ای مشابه جدول */
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 8px;
}
.room-info {
    display: flex;
    flex-direction: column;
    font-size: 14px;
    color: #fff;
}
.room-time {
    font-size: 11px;
    color: #aaa;
    margin-top: 5px;
}
.room-item button {
    background-color: transparent;
    color: #f39c12;
    border: 1px solid #f39c12;
    padding: 6px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s ease;
}
.room-item button:hover:not(:disabled) {
    background-color: #f39c12;
    color: #000;
}
.room-item button:disabled {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: transparent;
    cursor: not-allowed;
    color: #888;
}


.game-mode-panel {
    width: 100%;
    max-width: 500px; /* ✨ طبق درخواست شما روی 500 تنظیم شد */
    background: linear-gradient(135deg, #602906 0%, #a4764f 100%);
    border: 2px solid #f39c12;
    border-radius: 12px;
    padding: 12px !important; /* ✨ کاهش پدینگ اصلی برای حذف فضای خالی */
    margin: 0 auto 10px auto !important; /* ✨ فاصله کمتر بین باکس‌ها */
    box-shadow: 0 4px 15px rgba(243, 156, 18, 0.2);
    direction: rtl;
    box-sizing: border-box;
}

.panel-header {
    text-align: center;
    color: #ecf0f1;
    font-size: 18px;
    margin-bottom: 8px !important; /* ✨ کاهش فاصله تا دکمه‌ها */
    font-weight: 600;
}

/* دکمه‌های آکاردئونی لابی و لیدربورد */
.bg-accordion-btn {
    width: 100%;
    padding: 8px 12px !important; /* ✨ جمع‌وجور شدن دکمه‌های لابی */
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    text-align: right;
    font-size: 16px;
}

@media screen and (max-width: 600px) {
    .game-mode-panel {
        width: 95%;
        max-width: none;
    }
}

/* Toast Container */
#toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
}

/* Toast Message Style */
.custom-toast {
    background-color: #cb4e3a; /* رنگ آجری */
    color: #ffffff;            /* متن سفید */
    padding: 12px 25px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    direction: rtl;
    font-size: 14px;
    margin-top: 10px;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.custom-toast.show {
    opacity: 1;
}

/* #cheat-button {
    display: none !important;
} */

/* استایل‌های نوار اطلاعات بازیکنان آنلاین */
#online-players-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    /* max-width: 700px;  */
    margin: 0 auto 15px auto;
    padding: 0 10px;
    box-sizing: border-box;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    font-size: 1.1em;
    color: #333;
    background: rgba(255, 255, 255, 0.85);
    padding: 5px 15px;
    border-radius: 30px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* بازنویسی استایل مهره‌ها فقط برای این نوار تا از حالت Absolute خارج شوند */
.player-info .info-piece {
    position: relative !important;
    width: 35px !important;
    height: 35px !important;
    transform: none !important;
    box-shadow: 0 3px 5px rgba(0,0,0,0.4) !important;
    margin: 0 !important;
}

/****************/
/* --- استایل‌های چت آنلاین --- */
/****************/
#chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: Tahoma, sans-serif;
    direction: rtl;
}

#chat-toggle {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    background: #25d366; /* رنگ سبز جذاب */
    color: white;
    font-size: 26px;
    border: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    cursor: pointer;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

#chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff3b30;
    color: white;
    font-size: 13px;
    font-weight: bold;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#chat-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 320px;
    max-width: 90vw; /* بهینه‌سازی برای موبایل */
    background: #efeae2;
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
    border: 1px solid #ccc;
}

#chat-window.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

.chat-header {
    background: #075e54;
    color: white;
    padding: 12px 15px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chat-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: white;
}

.chat-messages {
    height: 250px;
    max-height: 40vh; /* جلوگیری از اشغال کل صفحه موبایل */
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg {
    padding: 8px 12px;
    border-radius: 15px;
    max-width: 80%;
    word-wrap: break-word;
    font-size: 0.95em;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.chat-msg.me {
    align-self: flex-start;
    background: #dcf8c6;
    color: #000;
    border-bottom-right-radius: 2px;
}

.chat-msg.opponent {
    align-self: flex-end;
    background: #ffffff;
    color: #000;
    border-bottom-left-radius: 2px;
}

.chat-input-area {
    display: flex;
    padding: 10px;
    background: #f0f0f0;
}

#chat-input {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 20px;
    outline: none;
    font-size: 16px; /* 16px برای جلوگیری از زوم خودکار کیبورد آیفون */
}

#chat-send {
    background: #25d366;
    color: white;
    border: none;
    padding: 0 18px;
    margin-right: 8px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
}

.chat-sender {
    display: block;
    font-size: 0.7em;
    opacity: 0.5;
    margin-bottom: 4px;
    font-weight: bold;
}

.chat-text {
    display: block;
}

.chat-msg.me .chat-sender {
    text-align: right;
    color: #045c26; /* رنگ تیره‌تر برای خوانایی روی پس‌زمینه سبز */
}

.chat-msg.opponent .chat-sender {
    text-align: left; /* نام حریف سمت چپ */
    color: #555;
}


/****************/
/* استایل تایمر بازی */
/****************/
#turn-timer-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 70px;
    height: 70px;
    z-index: 1000;
}

.timer-svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
}

.timer-bg {
    fill: none;
    stroke: rgba(0, 0, 0, 0.2);
    stroke-width: 8;
}

.timer-progress {
    fill: none;
    stroke-width: 8;
    stroke-dasharray: 283;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
}

/* رنگ نوار پیشرفت بر اساس نوبت */
.timer-progress.white-turn { stroke: #ff3232; } /* رنگ نوار برای سفید */
.timer-progress.black-turn { stroke: #ff3232; } /* رنگ نوار برای سیاه */

#timer-checker {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    z-index: 1;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

/* استایل مهره‌ها در مرکز تایمر */
#timer-checker.white {
    background: radial-gradient(circle at 35% 35%, #fff, #a49865);
    border: 2px solid #beac7d;
}

#timer-checker.black {
    background: radial-gradient(circle at 35% 35%, #5f2e00, #000);
    border: 2px solid #2b1500;
}

#timer-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: bold;
    z-index: 3;
    text-shadow: 1px 1px 2px rgba(255,255,255,0.8), -1px -1px 2px rgba(0,0,0,0.5);
}

/* رنگ متن متضاد با مهره */
#timer-checker.white ~ #timer-text { color: #000; }
#timer-checker.black ~ #timer-text { color: #fff; }

.chat-preview-bubble {
    position: absolute;
    bottom: 60px; /* بسته به جایگاه دکمه چت، این مقدار را تنظیم کنید */
    right: 20px; /* یا right: 20px اگر دکمه سمت راست است */
    background-color: rgba(33, 33, 33, 0.9);
    color: #fff;
    padding: 10px 15px;
    border-radius: 15px 15px 0 15px; /* شکل حباب مکالمه */
    font-size: 14px;
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none; /* تا مزاحم کلیک کردن نشود */
    z-index: 9999;
    visibility: hidden;
}

.chat-preview-bubble.show {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
}

/* استایل نام فرستنده در حباب */
.preview-sender {
    font-weight: 800; /* ضخیم‌تر */
    color: #6d6d6d; /* رنگ تیره‌تر */
    margin-left: 4px; /* یک فاصله کوچک با پیام */
}

/* استایل متن پیام در حباب */
.preview-text {
    font-weight: normal;
    color: #cccccc; /* رنگ روشن‌تر نسبت به نام فرستنده */
}


.history-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 9999; display: flex; justify-content: center; align-items: center; }
.history-modal-content { background: linear-gradient(135deg, #602906 0%, #a4764f 100%); padding: 20px; border-radius: 10px; width: 400px; max-width: 90%; color: #000; direction: rtl;     /* کدهای جدید برای محدود کردن ارتفاع و ایجاد اسکرول */
    max-height: 80vh; /* حداکثر ۸۰ درصد از ارتفاع صفحه */
    overflow-y: auto; /* ایجاد اسکرول عمودی در صورت نیاز */ }
.close-history { float: left; font-size: 24px; cursor: pointer; color: red; }
.history-item { padding: 10px; margin-bottom: 8px; border-radius: 5px; border-right: 4px solid #ccc; background: #f9f9f9; display: flex; flex-direction: column; }
.history-modal-title {font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; color: white;}

/* استایل کلی لیست تاریخچه */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 0;
}

/* استایل هر آیتم (هر ردیف بازی) */
.history-item {
    padding: 15px;
    border-radius: 8px;
    position: relative;
    text-align: right;
    direction: rtl;
    border: 1px solid #ccc;
    font-family: inherit;
}

/* پس‌زمینه سبز برای برد */
.hist-win {
    background-color: #bee6cf;
    border-color: #28947e;
}

/* پس‌زمینه قرمز برای باخت */
.hist-lose {
    background-color: #e6c3c1;
    border-color: #a8392e;
}

/* نام برنده (سبز پررنگ) */
.win-box {
    color: #196f3d;
    background-color: #d5f5e3;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
}

/* نام بازنده (قرمز پررنگ) */
.lose-box {
    color: #943126;
    background-color: #fadbd8;
    padding: 2px 8px;
    border-radius: 4px;
}

/* تاریخ بازی */
.hist-date {
    position: absolute;
    left: 15px;
    bottom: 15px;
    font-size: 13px;
    color: #2a2a2a;
    direction: ltr;
}
