/* css/table.css */

#table-section {
    background-color: var(--section-bg);
}

.controls-panel {
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
}

.backgammon-board {
    display: flex;
    width: 100%;
    max-width: 800px;
    height: 500px;
    background-color: #6d4c41;
    /* Brown wooden board */
    border: 15px solid #3e2723;
    border-radius: 8px;
    margin: 0 auto;
    position: relative;
    padding: 10px;
}

.board-half {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
}

.board-bar {
    width: 40px;
    background-color: #3e2723;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
}

.points {
    display: flex;
    height: 45%;
}

.point {
    flex: 1;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
}

/* Triangle shapes for points */
.point.top::before {
    content: '';
    position: absolute;
    top: 0;
    width: 0;
    height: 0;
    border-left: 25px solid transparent;
    border-right: 25px solid transparent;
    border-top: 180px solid rgba(0, 0, 0, 0.2);
}

.point.bottom::before {
    content: '';
    position: absolute;
    bottom: 0;
    width: 0;
    height: 0;
    border-left: 25px solid transparent;
    border-right: 25px solid transparent;
    border-bottom: 180px solid rgba(0, 0, 0, 0.2);
}

/* Coloring alternate points */
.point:nth-child(even)::before {
    border-top-color: rgba(255, 255, 255, 0.1);
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.point.top {
    justify-content: flex-start;
}

.point.bottom {
    justify-content: flex-end;
}

/* Pieces (Checkers) */
.checker {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    margin: 1px 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3), inset 0 2px 4px rgba(255, 255, 255, 0.2);
    position: relative;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s;
    z-index: 5;
}

.checker.white {
    background: radial-gradient(circle at 30% 30%, #fff, #bdc3c7);
    border: 1px solid #7f8c8d;
}

.checker.black {
    background: radial-gradient(circle at 30% 30%, #444, #000);
    border: 1px solid #111;
}

.checker.can-move {
    cursor: pointer;
    box-shadow: 0 0 15px #1abc9c, 0 4px 6px rgba(0, 0, 0, 0.3);
    animation: pulse-teal 1.5s infinite;
}

@keyframes pulse-teal {
    0% {
        box-shadow: 0 0 5px #1abc9c;
    }

    50% {
        box-shadow: 0 0 20px #1abc9c;
    }

    100% {
        box-shadow: 0 0 5px #1abc9c;
    }
}

.checker.selected {
    transform: scale(1.2) translateY(-10px);
    z-index: 10;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5), 0 0 20px #f1c40f;
}

/* 3D Dice Realism */
.table-dice-scene {
    position: absolute;
    top: 50%;
    left: 25%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 150px;
    perspective: 1000px;
    z-index: 20;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

.table-dice-scene.active-roll {
    pointer-events: auto;
    cursor: pointer;
}

.table-dice-scene.active-roll .dice-platform {
    background: rgba(241, 196, 15, 0.05);
    border-radius: 15px;
    padding: 10px;
    animation: lateral-glow 1.8s ease-in-out infinite;
}

@keyframes lateral-glow {
    0%, 100% { box-shadow: 0 0 15px rgba(241, 196, 15, 0.2); }
    50%      { box-shadow: 0 0 35px rgba(241, 196, 15, 0.5); }
}

.dice-platform {
    display: flex;
    gap: 30px;
    transform-style: preserve-3d;
}

.die {
    width: 50px;
    height: 50px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 1.2s cubic-bezier(0.15, 0.45, 0.15, 1.15);
}

.die-face,
.die-face-core {
    position: absolute;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.die-face {
    background: linear-gradient(145deg, #ffffff, #e0e0e0);
    border: 1px solid #ccc;
    border-radius: 8px;
    display: grid;
    grid-template: repeat(3, 1fr) / repeat(3, 1fr);
    padding: 6px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
    backface-visibility: hidden;
    z-index: 2;
}

.die-face-core {
    background-color: #d0d0d0;
    width: 96%;
    height: 96%;
    left: 2%;
    top: 2%;
    border-radius: 6px;
    backface-visibility: visible;
    z-index: 1;
    box-shadow: 0 0 2px 1px #d0d0d0;
}

body.dark-theme .die-face {
    background: linear-gradient(145deg, #4b6584, #34495e);
    border-color: #2c3e50;
}

body.dark-theme .die-face-core {
    background-color: #2c3e50;
    box-shadow: 0 0 2px 1px #2c3e50;
}

.dot {
    background-color: #333;
    border-radius: 50%;
    width: 8px;
    height: 8px;
    align-self: center;
    justify-self: center;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
}

body.dark-theme .dot {
    background-color: #ecf0f1;
}

/* Grid Positioning for Dots */
.face-1 .dot:nth-child(1) {
    grid-area: 2 / 2;
}

.face-2 .dot:nth-child(1) {
    grid-area: 1 / 3;
}

.face-2 .dot:nth-child(2) {
    grid-area: 3 / 1;
}

.face-3 .dot:nth-child(1) {
    grid-area: 1 / 3;
}

.face-3 .dot:nth-child(2) {
    grid-area: 2 / 2;
}

.face-3 .dot:nth-child(3) {
    grid-area: 3 / 1;
}

.face-4 .dot:nth-child(1) {
    grid-area: 1 / 1;
}

.face-4 .dot:nth-child(2) {
    grid-area: 1 / 3;
}

.face-4 .dot:nth-child(3) {
    grid-area: 3 / 1;
}

.face-4 .dot:nth-child(4) {
    grid-area: 3 / 3;
}

.face-5 .dot:nth-child(1) {
    grid-area: 1 / 1;
}

.face-5 .dot:nth-child(2) {
    grid-area: 1 / 3;
}

.face-5 .dot:nth-child(3) {
    grid-area: 2 / 2;
}

.face-5 .dot:nth-child(4) {
    grid-area: 3 / 1;
}

.face-5 .dot:nth-child(5) {
    grid-area: 3 / 3;
}

.face-6 .dot:nth-child(1) {
    grid-area: 1 / 1;
}

.face-6 .dot:nth-child(2) {
    grid-area: 1 / 3;
}

.face-6 .dot:nth-child(3) {
    grid-area: 2 / 1;
}

.face-6 .dot:nth-child(4) {
    grid-area: 2 / 3;
}

.face-6 .dot:nth-child(5) {
    grid-area: 3 / 1;
}

.face-6 .dot:nth-child(6) {
    grid-area: 3 / 3;
}

/* Face Transforms */
.face-1 {
    transform: translateZ(25px);
}

.face-6 {
    transform: rotateY(180deg) translateZ(25px);
}

.face-2 {
    transform: rotateY(90deg) translateZ(25px);
}

.face-5 {
    transform: rotateY(-90deg) translateZ(25px);
}

.face-3 {
    transform: rotateX(90deg) translateZ(25px);
}

.face-4 {
    transform: rotateX(-90deg) translateZ(25px);
}

.core-face-1 {
    transform: translateZ(23px);
}

.core-face-6 {
    transform: rotateY(180deg) translateZ(23px);
}

.core-face-2 {
    transform: rotateY(90deg) translateZ(23px);
}

.core-face-5 {
    transform: rotateY(-90deg) translateZ(23px);
}

.core-face-3 {
    transform: rotateX(90deg) translateZ(23px);
}

.core-face-4 {
    transform: rotateX(-90deg) translateZ(23px);
}

/* Off-board (home area) */
.off-board {
    width: 60px;
    background-color: #2c1b0c;
    border-left: 10px solid #3e2723;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.home {
    height: 45%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    /* Stack pieces from bottom for white (bottom home) */
    padding: 10px 0;
    overflow: hidden;
    position: relative;
    gap: 2px;
}

#home-white {
    justify-content: flex-end;
    background: linear-gradient(to top, rgba(236, 240, 241, 0.1), transparent);
}

#home-black {
    justify-content: flex-start;
    background: linear-gradient(to bottom, rgba(236, 240, 241, 0.1), transparent);
}

.home .checker {
    height: 6px;
    /* Stacked look */
    width: 40px;
    border-radius: 2px;
    margin: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.home-count-label {
    font-size: 14px;
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 2px #000;
    margin-top: 5px;
    z-index: 10;
}

body.dark-theme .home-count-label {
    color: #1abc9c;
}

.home.can-bear-off {
    background-color: rgba(26, 188, 156, 0.2);
    box-shadow: inset 0 0 15px rgba(26, 188, 156, 0.5);
}

.home.suggested {
    background-color: rgba(241, 196, 15, 0.2);
    box-shadow: inset 0 0 20px rgba(241, 196, 15, 0.4);
}

/* Highlight styles */
.point.highlight {
    background-color: rgba(26, 188, 156, 0.2);
    box-shadow: inset 0 0 20px rgba(26, 188, 156, 0.4);
}

.point.suggested {
    background-color: rgba(241, 196, 15, 0.15);
    box-shadow: inset 0 0 25px rgba(241, 196, 15, 0.3);
    border: 1px dashed rgba(241, 196, 15, 0.5);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .container {
        padding-left: 5px;
        padding-right: 5px;
    }

    .backgammon-board {
        width: 100vw;
        height: min(60vh, 100vw * 0.65);
        /* Maintain a horizontal aspect ratio that fits */
        max-width: 100%;
        border-width: 8px;
        flex-direction: row;
        /* Horizontal again for realistic look */
        border-radius: 4px;
        margin: 0 auto;
        padding: 5px;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    }

    .board-half {
        flex: 1;
        height: 100%;
        flex-direction: column;
    }

    .points {
        width: 100%;
        flex-direction: row;
        height: 45%;
    }

    .point {
        width: 100%;
        height: 100%;
    }

    .point.top::before {
        border-top-width: 100px;
        /* Scaled down */
        border-left-width: 10px;
        border-right-width: 10px;
    }

    .point.bottom::before {
        border-bottom-width: 100px;
        border-left-width: 10px;
        border-right-width: 10px;
    }

    .board-bar {
        width: 25px;
        height: 100%;
        flex-direction: column;
        border-left: 2px solid #3e2723;
        border-right: 2px solid #3e2723;
    }

    .bar-half {
        width: 100%;
        height: 50%;
        flex-direction: column;
        gap: 1px;
    }

    .table-dice-scene {
        top: 50%;
        left: 30%;
        width: 100px;
        height: 80px;
    }

    .checker {
        width: 18px;
        /* Significantly smaller for mobile horizontal fitting */
        height: 18px;
        margin: 0;
    }

    .off-board {
        width: 25px;
    }

    .home .checker {
        width: 20px;
        height: 4px;
    }

    .controls-panel {
        padding: 8px !important;
    }

    .controls-panel .btn {
        padding: 8px 4px;
        font-size: 0.75rem;
    }

    .score-display .badge {
        font-size: 0.7rem;
    }
}

/* Fix for stacked modals: ensure modals are properly layered above backdrops */
.modal {
    z-index: 1060 !important;
}

.modal-backdrop {
    z-index: 1050 !important;
}

#universalModal {
    z-index: 2000 !important;
}

#universalModal+.modal-backdrop {
    z-index: 1999 !important;
}

/* Ensure online lobby elements are visible and interactive */
#online-modal .modal-content {
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
}