/* ============================================================================
   ✨ برد شطرنج - نسخه سبک و نرم (Light & Smooth v2.0) ✨
   ============================================================================
   ✅ سبک‌تر و سریع‌تر
   ✅ بدون انیمیشن‌های سنگین
   ✅ باگ‌ها رفع شده
   ✅ تجربه روان و حرفه‌ای
   ========================================================================== */

/* ============================================================
   01. کانتینر اصلی برد - ساده و شیک
   ============================================================ */
#board {
    position: relative;
    flex: 1;
    width: 100%;
    min-width: 0;
    aspect-ratio: 1 / 1;
    -webkit-user-select: none;
    user-select: none;
    border-radius: 16px;
    overflow: hidden;
    isolation: isolate;
    z-index: 1;
    
    /* فریم ساده با سایه ملایم */
    background: rgba(10, 14, 26, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    
    /* سایه‌های نرم */
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.5),
        0 0 60px rgba(79, 140, 255, 0.08);
    
    transition: box-shadow 0.3s ease;
}

/* ============================================================
   02. سطح برد - تمیز و خوانا
   ============================================================ */
cg-board {
    position: absolute;
    inset: 0;
    box-sizing: border-box;
    cursor: pointer;
    line-height: 0;
    border-radius: inherit;
    overflow: hidden;
    
    /* رنگ‌های پایه با کیفیت */
    background-color: #3a4a6a;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='2' fill='none'%3E%3Crect width='1' height='1' x='0' y='0' fill='%23e8edf5'/%3E%3Crect width='1' height='1' x='1' y='0' fill='%232a3a5a'/%3E%3Crect width='1' height='1' x='0' y='1' fill='%232a3a5a'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%23e8edf5'/%3E%3C/svg%3E");
    background-size: 25% 25%;
    
    /* سایه داخلی ملایم */
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.3);
}

/* ============================================================
   03. مهره‌ها - روان و زیبا
   ============================================================ */
cg-board piece,
#board piece {
    position: absolute;
    top: 0;
    left: 0;
    width: 12.5%;
    height: 12.5%;
    background-size: 85% 85%;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 2;
    will-change: transform;
    pointer-events: none;
    
    /* ساده‌ترین سایه برای عملکرد بهتر */
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
    transition: filter 0.15s ease;
}

/* مهره در حال کشیدن - با سایه بیشتر */
#board piece.dragging {
    z-index: 10;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.5));
    transform: scale(1.06);
    transition: none;
    cursor: grabbing;
}

/* مهره در حال انیمیشن */
#board piece.anim {
    transition: transform 0.12s ease;
}

/* مهره شبح */
#board piece.ghost {
    opacity: 0.25;
}

/* ============================================================
   04. تصاویر مهره‌ها (سبک cburnett)
   ============================================================ */
#board piece.white.pawn   { background-image: url('../assets/pieces/cburnett/wP.svg'); }
#board piece.white.knight { background-image: url('../assets/pieces/cburnett/wN.svg'); }
#board piece.white.bishop { background-image: url('../assets/pieces/cburnett/wB.svg'); }
#board piece.white.rook   { background-image: url('../assets/pieces/cburnett/wR.svg'); }
#board piece.white.queen  { background-image: url('../assets/pieces/cburnett/wQ.svg'); }
#board piece.white.king   { background-image: url('../assets/pieces/cburnett/wK.svg'); }

#board piece.black.pawn   { background-image: url('../assets/pieces/cburnett/bP.svg'); }
#board piece.black.knight { background-image: url('../assets/pieces/cburnett/bN.svg'); }
#board piece.black.bishop { background-image: url('../assets/pieces/cburnett/bB.svg'); }
#board piece.black.rook   { background-image: url('../assets/pieces/cburnett/bR.svg'); }
#board piece.black.queen  { background-image: url('../assets/pieces/cburnett/bQ.svg'); }
#board piece.black.king   { background-image: url('../assets/pieces/cburnett/bK.svg'); }

/* ============================================================
   05. هایلایت خانه‌ها - ساده و کارآمد
   ============================================================ */
cg-board square {
    position: absolute;
    top: 0;
    left: 0;
    width: 12.5%;
    height: 12.5%;
    pointer-events: none;
    transition: background 0.12s ease;
}

/* حرکت آخر - هایلایت ملایم */
cg-board square.last-move {
    background: rgba(255, 215, 0, 0.15);
    box-shadow: inset 0 0 0 1px rgba(255, 215, 0, 0.2);
}

/* خانه انتخاب شده - آبی شفاف */
cg-board square.selected {
    background: rgba(79, 140, 255, 0.2);
    box-shadow: inset 0 0 0 2px rgba(79, 140, 255, 0.3);
}

/* کیش - قرمز ملایم */
cg-board square.check {
    background: rgba(255, 60, 60, 0.2) !important;
    box-shadow: inset 0 0 0 2px rgba(255, 60, 60, 0.3) !important;
}

/* نقطه‌های حرکت قانونی */
cg-board square.move-dest {
    background: radial-gradient(circle at center, rgba(79, 140, 255, 0.4) 25%, rgba(79, 140, 255, 0.15) 25%, transparent 32%);
}

/* نقطه‌های گرفتن */
cg-board square.move-dest.oc {
    background: radial-gradient(circle at center, transparent 55%, rgba(79, 140, 255, 0.25) 60%, rgba(79, 140, 255, 0.25) 75%, transparent 80%);
    box-shadow: inset 0 0 0 1px rgba(79, 140, 255, 0.2);
}

/* هاور خانه - بسیار ملایم */
cg-board square:hover {
    background: rgba(255, 255, 255, 0.04);
}

/* ============================================================
   06. مختصات - خوانا و زیبا
   ============================================================ */
.cg-coordinates {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    font-family: 'Chakra Petch', monospace;
    font-size: 10px;
    font-weight: 600;
}

.cg-coordinates .rank,
.cg-coordinates .file {
    position: absolute;
    padding: 2px 4px;
}

.cg-coordinates .rank {
    left: 3px;
    transform: translateY(-50%);
}

.cg-coordinates .file {
    bottom: 3px;
    transform: translateX(-50%);
}

/* خانه‌های تیره */
.cg-coordinates .dark-text {
    color: rgba(255, 255, 255, 0.5);
}

/* خانه‌های روشن */
.cg-coordinates .light-text {
    color: rgba(0, 0, 0, 0.3);
}

/* ============================================================
   07. شکل‌های ترسیمی - ساده و سریع
   ============================================================ */
.cg-shapes {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}

.cg-shapes line {
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.7;
}

.cg-shapes line.arrow-green {
    stroke: #00cc66;
    stroke-width: 4px;
}

.cg-shapes polygon.arrow-green {
    fill: #00cc66;
    opacity: 0.7;
}

.cg-shapes line.arrow-red {
    stroke: #ff3355;
    stroke-width: 4px;
}

.cg-shapes polygon.arrow-red {
    fill: #ff3355;
    opacity: 0.7;
}

/* ============================================================
   08. آنوتیشن‌ها - دایره‌های ساده
   ============================================================ */
.cg-shapes text {
    font-family: 'Chakra Petch', monospace;
    font-weight: 900;
    font-size: 18px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    dominant-baseline: central;
    text-anchor: middle;
}

.cg-shapes circle.paleBlue {
    fill: rgba(0, 48, 136, 0.12);
    stroke: rgba(0, 48, 136, 0.2);
    stroke-width: 2px;
    r: 20px;
}

.cg-shapes circle.paleGreen {
    fill: rgba(21, 120, 27, 0.12);
    stroke: rgba(21, 120, 27, 0.2);
    stroke-width: 2px;
    r: 20px;
}

.cg-shapes circle.paleRed {
    fill: rgba(255, 0, 0, 0.12);
    stroke: rgba(255, 0, 0, 0.2);
    stroke-width: 2px;
    r: 20px;
}

.cg-shapes circle.paleYellow {
    fill: rgba(230, 143, 0, 0.12);
    stroke: rgba(230, 143, 0, 0.2);
    stroke-width: 2px;
    r: 20px;
}

/* ============================================================
   09. تم‌های مختلف - ۶ تم اصلی
   ============================================================ */

/* تم سبز */
[data-board-theme="green"] cg-board {
    background-color: #2d5a3a;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='2' fill='none'%3E%3Crect width='1' height='1' x='0' y='0' fill='%23e8f0e0'/%3E%3Crect width='1' height='1' x='1' y='0' fill='%232d5a3a'/%3E%3Crect width='1' height='1' x='0' y='1' fill='%232d5a3a'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%23e8f0e0'/%3E%3C/svg%3E");
}

/* تم آبی */
[data-board-theme="blue"] cg-board {
    background-color: #2a4a7a;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='2' fill='none'%3E%3Crect width='1' height='1' x='0' y='0' fill='%23ddeeff'/%3E%3Crect width='1' height='1' x='1' y='0' fill='%232a4a7a'/%3E%3Crect width='1' height='1' x='0' y='1' fill='%232a4a7a'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%23ddeeff'/%3E%3C/svg%3E");
}

/* تم چوب */
[data-board-theme="wood"] cg-board {
    background-color: #6b4a2a;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='2' fill='none'%3E%3Crect width='1' height='1' x='0' y='0' fill='%23deb887'/%3E%3Crect width='1' height='1' x='1' y='0' fill='%236b4a2a'/%3E%3Crect width='1' height='1' x='0' y='1' fill='%236b4a2a'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%23deb887'/%3E%3C/svg%3E");
}

/* تم مرمر */
[data-board-theme="marble"] cg-board {
    background-color: #6a5a4a;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='2' fill='none'%3E%3Crect width='1' height='1' x='0' y='0' fill='%23f5f0e8'/%3E%3Crect width='1' height='1' x='1' y='0' fill='%236a5a4a'/%3E%3Crect width='1' height='1' x='0' y='1' fill='%236a5a4a'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%23f5f0e8'/%3E%3C/svg%3E");
}

/* تم تاریک */
[data-board-theme="dark"] cg-board {
    background-color: #1a1a2e;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='2' fill='none'%3E%3Crect width='1' height='1' x='0' y='0' fill='%233a3a5a'/%3E%3Crect width='1' height='1' x='1' y='0' fill='%231a1a2e'/%3E%3Crect width='1' height='1' x='0' y='1' fill='%231a1a2e'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%233a3a5a'/%3E%3C/svg%3E");
}

/* تم طلایی */
[data-board-theme="gold"] cg-board {
    background-color: #5a4a0a;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2' height='2' fill='none'%3E%3Crect width='1' height='1' x='0' y='0' fill='%23ffd700'/%3E%3Crect width='1' height='1' x='1' y='0' fill='%235a4a0a'/%3E%3Crect width='1' height='1' x='0' y='1' fill='%235a4a0a'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%23ffd700'/%3E%3C/svg%3E");
}

/* ============================================================
   10. مهره‌های اتوماتیک
   ============================================================ */
cg-auto-pieces piece {
    position: absolute;
    top: 0;
    left: 0;
    width: 12.5%;
    height: 12.5%;
    background-size: 85% 85%;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0;
    pointer-events: none;
    z-index: 1;
}

cg-auto-pieces piece.anim {
    transition: all 0.12s ease;
}

cg-auto-pieces piece.fading {
    transition: opacity 0.2s ease;
}

/* ============================================================
   11. واکنش‌گرایی - روان و ساده
   ============================================================ */
@media (max-width: 1024px) {
    #board {
        border-radius: 14px;
        box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
    }
    
    .cg-coordinates {
        font-size: 9px;
    }
}

@media (max-width: 768px) {
    #board {
        border-radius: 12px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    }
    
    .cg-coordinates {
        font-size: 8px;
    }
    
    .cg-coordinates .rank {
        left: 2px;
    }
    
    .cg-coordinates .file {
        bottom: 2px;
    }
    
    /* ===== کاهش سایز آنوتیشن‌ها ===== */
    .cg-shapes text {
        font-size: 14px;
    }
    
    .cg-shapes circle.paleBlue,
    .cg-shapes circle.paleGreen,
    .cg-shapes circle.paleRed,
    .cg-shapes circle.paleYellow {
        r: 16px;
    }
}

@media (max-width: 480px) {
    #board {
        border-radius: 10px;
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
    }
    
    .cg-coordinates {
        font-size: 7px;
    }
    
    .cg-coordinates .rank {
        left: 2px;
    }
    
    .cg-coordinates .file {
        bottom: 2px;
    }
    
    /* ===== کاهش سایز مهره‌ها ===== */
    #board piece {
        background-size: 80% 80%;
    }
    
    /* ===== کاهش سایز آنوتیشن‌ها ===== */
    .cg-shapes text {
        font-size: 11px;
    }
    
    .cg-shapes circle.paleBlue,
    .cg-shapes circle.paleGreen,
    .cg-shapes circle.paleRed,
    .cg-shapes circle.paleYellow {
        r: 13px;
        stroke-width: 1.5px;
    }
    
    /* ===== نقطه‌های حرکت ===== */
    cg-board square.move-dest {
        background: radial-gradient(circle at center, rgba(79, 140, 255, 0.35) 22%, rgba(79, 140, 255, 0.12) 22%, transparent 30%);
    }
}

@media (max-width: 360px) {
    #board {
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    }
    
    .cg-coordinates {
        font-size: 6px;
    }
    
    #board piece {
        background-size: 76% 76%;
    }
    
    .cg-shapes text {
        font-size: 9px;
    }
    
    .cg-shapes circle.paleBlue,
    .cg-shapes circle.paleGreen,
    .cg-shapes circle.paleRed,
    .cg-shapes circle.paleYellow {
        r: 10px;
        stroke-width: 1px;
    }
}

/* ============================================================
   12. دسترسی‌پذیری - حرکت کاهش‌یافته
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    #board,
    #board piece,
    cg-board square,
    .cg-shapes line,
    .cg-shapes polygon {
        transition-duration: 0.01ms !important;
    }
}

/* ============================================================
   13. کنتراست بالا
   ============================================================ */
@media (prefers-contrast: high) {
    cg-board square.last-move {
        background: rgba(255, 255, 255, 0.25);
        box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4);
    }
    
    cg-board square.check {
        background: rgba(255, 0, 0, 0.4) !important;
        box-shadow: inset 0 0 0 2px rgba(255, 0, 0, 0.6) !important;
    }
    
    .cg-shapes line.arrow-green {
        stroke: #00ff00;
        stroke-width: 3px;
    }
    
    .cg-shapes line.arrow-red {
        stroke: #ff0000;
        stroke-width: 3px;
    }
}

/* ============================================================
   14. چاپ
   ============================================================ */
@media print {
    #board {
        border: 2px solid #333 !important;
        box-shadow: none !important;
        background: none !important;
    }
    
    #board piece {
        filter: none !important;
    }
    
    .cg-shapes {
        display: none !important;
    }
    
    .cg-coordinates {
        color: #333 !important;
        text-shadow: none !important;
    }
}

/* ============================================================
   15. اسکرول‌بار
   ============================================================ */
#board ::-webkit-scrollbar {
    width: 3px;
}

#board ::-webkit-scrollbar-track {
    background: transparent;
}

#board ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

/* ============================================================
   16. لمسی - بهینه‌سازی
   ============================================================ */
@media (hover: none) and (pointer: coarse) {
    #board piece.dragging {
        transform: scale(1.04);
    }
    
    /* افزایش سایز نقطه‌های حرکت برای لمس */
    cg-board square.move-dest {
        background: radial-gradient(circle at center, rgba(79, 140, 255, 0.45) 28%, rgba(79, 140, 255, 0.15) 28%, transparent 36%);
    }
}