/* Mesa de feltro */
.mesa-wrapper {
    background:
        radial-gradient(ellipse 80% 60% at 50% 40%, rgba(255, 255, 255, .06), transparent 60%),
        linear-gradient(180deg, rgba(0, 0, 0, .12) 0%, transparent 18%),
        repeating-linear-gradient(
            0deg,
            rgba(0, 0, 0, .03) 0 2px,
            transparent 2px 4px
        ),
        linear-gradient(160deg, #1b7a32 0%, #146b28 45%, #0f5420 100%) !important;
}

.peca,
.domino-peca {
    --domino-w: 64px;
    --domino-h: 128px;
    --domino-radius: 10px;
    --domino-face: linear-gradient(165deg, #fffef9 0%, #f3ebe0 38%, #e8dfd2 100%);
    --domino-edge: #2a211c;
    background: var(--domino-face);
    border: 2px solid var(--domino-edge);
    border-radius: var(--domino-radius);
    display: flex;
    cursor: default;
    transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, .92) inset,
        0 -2px 0 rgba(0, 0, 0, .06) inset,
        0 10px 20px rgba(0, 0, 0, .28),
        0 4px 8px rgba(0, 0, 0, .16);
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}

/* Textura sutil de marfim */
.peca::before,
.domino-peca::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background:
        radial-gradient(circle at 18% 12%, rgba(255, 255, 255, .55), transparent 38%),
        repeating-linear-gradient(
            -18deg,
            rgba(255, 255, 255, .04) 0 2px,
            rgba(0, 0, 0, .015) 2px 4px
        );
    pointer-events: none;
    z-index: 1;
}

.peca::after,
.domino-peca::after {
    content: "";
    position: absolute;
    inset: 5px;
    border-radius: calc(var(--domino-radius) - 4px);
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, .5),
        inset 0 -6px 12px rgba(120, 100, 78, .08);
    pointer-events: none;
    z-index: 2;
}

.peca.horizontal {
    --domino-w: 128px;
    --domino-h: 64px;
    width: var(--domino-w);
    height: var(--domino-h);
    flex-direction: row;
}

.peca.vertical {
    width: var(--domino-w);
    height: var(--domino-h);
    flex-direction: column;
}

.peca.clicavel {
    cursor: pointer;
}

.peca.mesa-peca {
    position: absolute;
    cursor: default;
    z-index: 1;
}

.peca.mesa-peca:hover {
    z-index: 2;
}

.peca.clicavel:hover {
    transform: translateY(-8px) rotate(-1deg);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, .95) inset,
        0 14px 28px rgba(0, 0, 0, .32),
        0 6px 12px rgba(0, 0, 0, .18);
}

.peca-lado {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    place-items: center;
    padding: 8px;
    position: relative;
    z-index: 3;
    background: linear-gradient(180deg, rgba(255, 255, 255, .14) 0%, rgba(0, 0, 0, .03) 100%);
}

/* Sulco entre as metades */
.horizontal .peca-lado:first-child::after,
.vertical .peca-lado:first-child::after {
    content: "";
    position: absolute;
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, .08) 0%,
        rgba(40, 32, 28, .95) 45%,
        rgba(255, 255, 255, .25) 50%,
        rgba(40, 32, 28, .95) 55%,
        rgba(0, 0, 0, .08) 100%
    );
    pointer-events: none;
    z-index: 4;
}

.horizontal .peca-lado:first-child::after {
    top: 6px;
    bottom: 6px;
    right: -1px;
    width: 3px;
}

.vertical .peca-lado:first-child::after {
    left: 6px;
    right: 6px;
    bottom: -1px;
    height: 3px;
    background: linear-gradient(
        180deg,
        rgba(0, 0, 0, .08) 0%,
        rgba(40, 32, 28, .95) 45%,
        rgba(255, 255, 255, .25) 50%,
        rgba(40, 32, 28, .95) 55%,
        rgba(0, 0, 0, .08) 100%
    );
}

.horizontal .peca-lado:first-child {
    border-right: none;
}

.vertical .peca-lado:first-child {
    border-bottom: none;
}

/* Pinos (pips) 3D */
.pip {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 32% 28%, #6e6e6e 0%, #3a3a3a 38%, #1a1a1a 72%, #000 100%);
    box-shadow:
        inset 0 1px 2px rgba(255, 255, 255, .22),
        inset 0 -1px 2px rgba(0, 0, 0, .35),
        0 1px 2px rgba(0, 0, 0, .22);
}

.peca.horizontal .pip {
    width: 10px;
    height: 10px;
}

.pip.pos-tl { grid-area: 1 / 1; }
.pip.pos-tc { grid-area: 1 / 2; }
.pip.pos-tr { grid-area: 1 / 3; }
.pip.pos-ml { grid-area: 2 / 1; }
.pip.pos-c  { grid-area: 2 / 2; }
.pip.pos-mr { grid-area: 2 / 3; }
.pip.pos-bl { grid-area: 3 / 1; }
.pip.pos-bc { grid-area: 3 / 2; }
.pip.pos-br { grid-area: 3 / 3; }

/* Mao do jogador */
.mao-pecas {
    display: flex;
    gap: 0;
    justify-content: center;
    flex-wrap: wrap;
    align-items: flex-end;
    padding: 8px 4px 4px;
    min-height: 150px;
}

.mao-pecas .peca {
    width: var(--domino-w);
    height: var(--domino-h);
    flex-direction: column;
    margin-left: -10px;
    transform-origin: bottom center;
}

.mao-pecas .peca:first-child {
    margin-left: 0;
}

.mao-pecas .peca:nth-child(odd) {
    transform: rotate(-3deg);
}

.mao-pecas .peca:nth-child(even) {
    transform: rotate(3deg);
}

.mao-pecas .peca.clicavel:hover {
    transform: translateY(-10px) rotate(0deg) scale(1.03);
    z-index: 5;
}

.mao-pecas .peca.selecionada {
    transform: translateY(-12px) rotate(0deg) scale(1.04) !important;
    z-index: 6;
}

.mao-pecas .peca .peca-lado:first-child {
    border-bottom: none;
    border-right: none;
}

/* Estados interativos */
.peca.jogavel {
    border-color: #00c853;
    box-shadow:
        0 0 0 2px rgba(0, 200, 83, .35),
        0 10px 22px rgba(0, 200, 83, .28),
        0 4px 8px rgba(0, 0, 0, .16);
}

.peca.selecionada {
    border-color: #ffc107;
    box-shadow:
        0 0 0 3px rgba(255, 193, 7, .55),
        0 12px 26px rgba(255, 193, 7, .32),
        0 4px 10px rgba(0, 0, 0, .2);
}

/* Verso das pecas no monte */
.monte-slot-peca,
.domino-back {
    display: block;
    width: 56px;
    height: 108px;
    border-radius: 10px;
    border: 2px solid #3d342c;
    background:
        radial-gradient(circle at 28% 18%, rgba(255, 255, 255, .45) 0, transparent 42%),
        linear-gradient(165deg, #f5efe4 0%, #ddd2c0 55%, #c9bba8 100%);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, .75) inset,
        0 6px 14px rgba(0, 0, 0, .2),
        inset 0 -8px 14px rgba(120, 100, 78, .12);
    position: relative;
    overflow: hidden;
}

.monte-slot-peca::before,
.domino-back::before {
    content: "";
    position: absolute;
    top: 10px;
    bottom: 10px;
    left: 50%;
    width: 3px;
    border-radius: 999px;
    transform: translateX(-50%);
    background: linear-gradient(180deg, #8a8074 0%, #5c564e 100%);
    box-shadow: 0 0 4px rgba(255, 255, 255, .25);
    z-index: 2;
}

.monte-slot-peca::after,
.domino-back::after {
    content: "";
    position: absolute;
    inset: 7px;
    border-radius: 7px;
    border: 1px dashed rgba(90, 78, 66, .35);
    background:
        repeating-linear-gradient(
            45deg,
            rgba(120, 100, 78, .06) 0 4px,
            transparent 4px 8px
        );
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
    z-index: 1;
}

/* Icone do titulo reutiliza visual de peca */
.titulo-icone {
    width: 62px;
    height: 34px;
    border-radius: 8px;
    background: linear-gradient(165deg, #fffef9 0%, #e8dfd2 100%);
    border: 2px solid #2a211c;
    box-shadow:
        0 8px 18px rgba(0, 0, 0, .28),
        inset 0 1px 0 rgba(255, 255, 255, .85);
    position: relative;
    display: inline-flex;
    align-items: stretch;
    overflow: hidden;
    transform: rotate(-8deg);
}

.titulo-icone::before {
    content: "";
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 50%;
    width: 2px;
    background: linear-gradient(180deg, #5c564e, #2a211c);
    transform: translateX(-50%);
    z-index: 2;
}

.titulo-icone-lado {
    flex: 1;
    position: relative;
}

.titulo-icone-lado::before,
.titulo-icone-lado::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #5b5b5b 0%, #161616 72%, #000 100%);
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, .2);
}

.titulo-icone-lado:first-child::before { top: 8px; left: 9px; }
.titulo-icone-lado:first-child::after { bottom: 8px; right: 9px; }
.titulo-icone-lado:last-child::before { top: 8px; left: 50%; transform: translateX(-50%); }
.titulo-icone-lado:last-child::after { bottom: 8px; left: 50%; transform: translateX(-50%); }

@media (max-width: 860px) {
    .peca.horizontal {
        --domino-w: 104px;
        --domino-h: 52px;
    }

    .peca.vertical,
    .mao-pecas .peca {
        --domino-w: 52px;
        --domino-h: 104px;
    }

    .pip {
        width: 9px;
        height: 9px;
    }

    .peca.horizontal .pip {
        width: 8px;
        height: 8px;
    }

    .mao-pecas .peca {
        margin-left: -8px;
    }
}
