/* ============================================
   WOOD ROYALE - Premium Oak Board CSS
   Realistic wood textures with warm tones
   ============================================ */

/* === CSS VARIABLES === */
:root {
    --gold-main: #d4a864;
    --gold-light: #e8c080;
    --gold-dark: #8b5a2b;
    --wood-dark: #1a1510;
    --wood-mid: #2a1f15;
    --wood-light: #3d2d1e;
    --wood-accent: rgba(139,90,43,0.4);
}

/* === GAME CONTAINER === */
.game-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 48px);
    max-width: 1000px;
    margin: 0 auto;
    padding: 2px 0;
}

/* Player Bars - Wood */
.player-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    background: linear-gradient(145deg, rgba(30,22,15,0.95), rgba(20,16,12,0.95));
    border: 1px solid rgba(139,90,43,0.25);
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    flex-shrink: 0;
}
.opponent-bar { margin-bottom: 2px; }
.my-bar { margin-top: 2px; }

.player-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(50,35,25,0.9), rgba(25,18,12,0.95));
    border: 2px solid rgba(139,90,43,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.05);
}
.opp-avatar { border-color: rgba(180,80,80,0.5); color: #c25454; }
.my-avatar { border-color: rgba(80,180,100,0.5); color: #54c270; }

.player-name {
    font-size: 13px;
    font-weight: 600;
    flex: 1;
    color: #ccc;
}

.player-timer {
    font-family: 'Cinzel', serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--gold-light);
    text-shadow: 0 0 10px rgba(212,168,122,0.3);
}

.pip-count {
    font-size: 10px;
    color: #666;
    background: rgba(30,30,40,0.6);
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid rgba(212,168,122,0.1);
}

/* === BOARD CONTAINER === */
.board-container {
    flex: 1;
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    background: url('/assets/oak-board.jpg') center/cover;
    min-height: 0;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    box-shadow:
        0 15px 50px rgba(0,0,0,0.7),
        0 5px 15px rgba(0,0,0,0.5),
        inset 0 2px 4px rgba(255,255,255,0.1),
        inset 0 -2px 4px rgba(0,0,0,0.3);
}
.board-container::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 16px;
    border: 3px solid var(--wood-accent);
    box-shadow: inset 0 0 20px rgba(0,0,0,0.3);
    pointer-events: none;
    z-index: 20;
}

/* === THE BOARD - Oak Wood Surface === */
.bg-board {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 12px;
    display: flex;
    flex-direction: column;
    background: url('/assets/oak-board.jpg') center/cover;
    border-radius: 10px;
    overflow: hidden;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    cursor: default;
    box-shadow:
        inset 0 0 40px rgba(0,0,0,0.5),
        inset 0 0 100px rgba(0,0,0,0.3),
        0 0 0 2px rgba(101,67,33,0.5);
}
/* When bearoff is visible, make room */
.board-container.bearoff-active .bg-board {
    right: 56px;
    border-radius: 10px 0 0 10px;
}
.bg-board-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}
/* Fold line / hinge crease between halves */
.bg-board-main::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 3px;
    transform: translateY(-50%);
    background: linear-gradient(90deg, rgba(0,0,0,0.3), rgba(0,0,0,0.15) 10%, rgba(0,0,0,0.05) 50%, rgba(0,0,0,0.15) 90%, rgba(0,0,0,0.3));
    box-shadow: 0 1px 2px rgba(0,0,0,0.2), 0 -1px 1px rgba(255,240,200,0.05);
    z-index: 10;
    pointer-events: none;
}

/* Dark overlay for depth */
.bg-board::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(30,20,10,0.2);
    border-radius: inherit;
    pointer-events: none;
    z-index: 1;
}

/* Inner gold border line */
.bg-board::after {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border-radius: 6px;
    border: 2px solid rgba(212,168,100,0.3);
    pointer-events: none;
    z-index: 2;
    box-shadow: 
        0 0 10px rgba(212,168,100,0.1),
        inset 0 0 10px rgba(212,168,100,0.05);
}

/* === HALVES === */
.bg-half {
    flex: 1;
    display: flex;
    position: relative;
    direction: ltr; /* CRITICAL: override RTL so quads are left-to-right visually */
}
.bg-top {
    border-bottom: 3px solid rgba(101,67,33,0.6);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* === QUADRANTS === */
.bg-quad {
    flex: 1;
    display: flex;
    padding: 0 6px;
}

/* === BAR - Oak Wood === */
.bg-bar {
    width: 52px;
    background: url('/assets/oak-board.jpg') center/cover;
    border-left: 2px solid rgba(101,67,33,0.5);
    border-right: 2px solid rgba(101,67,33,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 0;
    position: relative;
    box-shadow:
        inset 5px 0 15px rgba(0,0,0,0.4),
        inset -5px 0 15px rgba(0,0,0,0.4);
}
.bg-bar::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(40,25,15,0.4);
    pointer-events: none;
}

/* Direction arrows on bars */
.bg-bar::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 16px;
    z-index: 2;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
/* Top bar: opponent's direction - red arrow */
.bg-bar-top::after {
    content: 'â†’';
    color: rgba(220,80,80,0.6);
}
.bg-bar-top.bar-arrow-left::after { content: 'â†'; }
.bg-bar-top.bar-arrow-right::after { content: 'â†’'; }

/* Bottom bar: my direction - green arrow toward home */
.bg-bar-bottom::after {
    content: 'â†’';
    color: rgba(76,200,80,0.6);
}
.bg-bar-bottom.bar-arrow-left::after { content: 'â†'; }
.bg-bar-bottom.bar-arrow-right::after { content: 'â†’'; }

/* === POINTS (triangles) === */
.bg-point {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.bg-point-top {
    justify-content: flex-start;
}
.bg-point-bottom {
    justify-content: flex-end;
}

/* Triangle */
.bg-tri {
    position: absolute;
    left: 2%;
    right: 2%;
    height: 85%;
}
.bg-point-top .bg-tri {
    top: 0;
    clip-path: polygon(50% 100%, 0% 0%, 100% 0%);
}
.bg-point-bottom .bg-tri {
    bottom: 0;
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

/* Triangle colors */
.bg-pt-dark .bg-tri {
    background: linear-gradient(180deg, #6b1a1a 0%, #8b2525 40%, #5a1515 100%);
}
.bg-pt-light .bg-tri {
    background: linear-gradient(180deg, #f5e6c8 0%, #e8d5a8 40%, #dcc89a 100%);
}
.bg-point-bottom.bg-pt-dark .bg-tri {
    background: linear-gradient(0deg, #6b1a1a 0%, #8b2525 40%, #5a1515 100%);
}
.bg-point-bottom.bg-pt-light .bg-tri {
    background: linear-gradient(0deg, #f5e6c8 0%, #e8d5a8 40%, #dcc89a 100%);
}

/* Pieces container */
.bg-pieces {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 0;
}
.bg-point-bottom .bg-pieces {
    flex-direction: column-reverse;
}

/* === PIECES - True Black & White === */
.bg-piece {
    width: clamp(24px, 3.5vw, 42px);
    height: clamp(24px, 3.5vw, 42px);
    border-radius: 50%;
    position: relative;
    cursor: grab;
    flex-shrink: 0;
    margin-bottom: 2px;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

/* White piece - clean white with silver accents */
.bg-p-white {
    background: radial-gradient(ellipse at 35% 30%, 
        #ffffff 0%, #f8f8f8 20%, #e8e8e8 50%, #d8d8d8 80%, #c8c8c8 100%);
    border: 2px solid rgba(180,180,180,0.6);
    box-shadow:
        inset 0 3px 10px rgba(255,255,255,0.9),
        inset 0 -4px 8px rgba(0,0,0,0.12),
        0 4px 12px rgba(0,0,0,0.4),
        0 2px 4px rgba(0,0,0,0.3);
}

/* Inner decorative ring on white */
.bg-p-white::before {
    content: '';
    position: absolute;
    top: 15%; left: 15%; right: 15%; bottom: 15%;
    border-radius: 50%;
    border: 1.5px solid rgba(160,160,160,0.4);
    background: radial-gradient(ellipse at 35% 30%, rgba(255,255,255,0.6) 0%, transparent 60%);
    pointer-events: none;
}

/* Black piece - deep black with subtle blue tint */
.bg-p-black {
    background: radial-gradient(ellipse at 35% 30%, 
        #3a3a3a 0%, #2a2a2a 25%, #1a1a1a 55%, #0a0a0a 100%);
    border: 2px solid rgba(60,60,60,0.6);
    box-shadow:
        inset 0 3px 10px rgba(80,80,80,0.3),
        inset 0 -4px 8px rgba(0,0,0,0.5),
        0 4px 12px rgba(0,0,0,0.5),
        0 2px 4px rgba(0,0,0,0.4);
}

/* Inner ring on black */
.bg-p-black::before {
    content: '';
    position: absolute;
    top: 15%; left: 15%; right: 15%; bottom: 15%;
    border-radius: 50%;
    border: 1.5px solid rgba(80,80,80,0.3);
    background: radial-gradient(ellipse at 35% 30%, rgba(255,255,255,0.06) 0%, transparent 50%);
    pointer-events: none;
}

/* Shine highlight on piece */
.bg-p-shine {
    position: absolute;
    width: 14px;
    height: 10px;
    top: 6px;
    left: 8px;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(255,255,255,0.5) 0%, transparent 70%);
    pointer-events: none;
}
.bg-p-black .bg-p-shine {
    background: radial-gradient(ellipse, rgba(255,255,255,0.1) 0%, transparent 70%);
}

/* Ring decoration */
.bg-p-ring {
    position: absolute;
    inset: 5px;
    border-radius: 50%;
    border: 1px solid rgba(200,180,150,0.15);
    pointer-events: none;
}
.bg-p-black .bg-p-ring {
    border-color: rgba(120,100,150,0.12);
}

/* Top piece */
.bg-p-top {
    z-index: 3;
}

/* Hover */
.bg-piece:hover {
    transform: scale(1.1) translateY(-2px);
}
.bg-p-white:hover {
    box-shadow:
        inset 0 3px 10px rgba(255,255,255,0.8),
        0 8px 25px rgba(0,0,0,0.5),
        0 4px 10px rgba(0,0,0,0.4);
}
.bg-p-black:hover {
    box-shadow:
        inset 0 3px 10px rgba(100,75,50,0.3),
        0 8px 25px rgba(0,0,0,0.5),
        0 4px 10px rgba(0,0,0,0.4);
}

/* Dragging */
.bg-p-drag {
    cursor: grabbing !important;
    transform: scale(1.15) !important;
    filter: brightness(1.15);
}
.bg-p-drag.bg-p-white {
    box-shadow: 0 10px 35px rgba(0,0,0,0.5), 0 0 25px rgba(240,230,210,0.25) !important;
}
.bg-p-drag.bg-p-black {
    box-shadow: 0 10px 35px rgba(0,0,0,0.7), 0 0 25px rgba(80,70,120,0.2) !important;
}

/* === HIGHLIGHT (valid move) === */
.bg-highlight {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: clamp(24px, 4vw, 36px);
    height: clamp(24px, 4vw, 36px);
    border-radius: 50%;
    background: radial-gradient(circle,
        rgba(120,255,160,0.45) 0%,
        rgba(80,220,120,0.2) 40%,
        rgba(60,200,100,0.08) 65%,
        transparent 75%);
    border: 2px solid rgba(120,255,160,0.55);
    box-shadow:
        0 0 8px rgba(100,240,140,0.35),
        0 0 20px rgba(80,220,120,0.15),
        inset 0 0 6px rgba(120,255,160,0.2);
    animation: hlPulse 2s ease-in-out infinite;
    pointer-events: auto;
    cursor: pointer;
    z-index: 5;
}
.bg-point-top .bg-highlight {
    bottom: auto;
    top: 8px;
}

/* Entire point glows when it's a valid destination */
.bg-point.bg-valid-dest {
    cursor: pointer;
}
/* Elegant emerald glow on triangle for valid destinations */
.bg-point.bg-valid-dest .bg-tri {
    filter: brightness(1.15) saturate(1.1);
    box-shadow: inset 0 0 20px rgba(100,240,140,0.18);
}
/* Soft inner emerald edge overlay */
.bg-point.bg-valid-dest .bg-tri::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg,
        rgba(100,240,140,0.18) 0%,
        rgba(80,220,120,0.08) 40%,
        transparent 70%);
    pointer-events: none;
}
.bg-point-bottom.bg-valid-dest .bg-tri::after {
    background: linear-gradient(0deg,
        rgba(100,240,140,0.18) 0%,
        rgba(80,220,120,0.08) 40%,
        transparent 70%);
}
/* Subtle pulsing glow effect on valid dest */
.bg-point.bg-valid-dest::after {
    content: '';
    position: absolute;
    inset: 0;
    background: transparent;
    box-shadow: inset 0 0 15px rgba(100,240,140,0.08);
    animation: destGlow 2s ease-in-out infinite;
    pointer-events: none;
    z-index: 4;
}
@keyframes destGlow {
    0%, 100% { box-shadow: inset 0 0 12px rgba(100,240,140,0.06); }
    50% { box-shadow: inset 0 0 25px rgba(100,240,140,0.14); }
}
@keyframes hlPulse {
    0%, 100% {
        transform: translateX(-50%) scale(1);
        opacity: 0.85;
        box-shadow: 0 0 8px rgba(100,240,140,0.3), 0 0 20px rgba(80,220,120,0.12), inset 0 0 6px rgba(120,255,160,0.15);
    }
    50% {
        transform: translateX(-50%) scale(1.1);
        opacity: 1;
        box-shadow: 0 0 14px rgba(100,240,140,0.5), 0 0 30px rgba(80,220,120,0.2), inset 0 0 10px rgba(120,255,160,0.25);
    }
}

/* === BEAROFF TRAY - Right side of board === */
.bg-bearoff {
    position: absolute;
    right: 0;
    top: 12px;
    bottom: 12px;
    width: 44px;
    background: url('/assets/oak-board.jpg') center/cover;
    border-left: 2px solid rgba(101,67,33,0.6);
    border-radius: 0 10px 10px 0;
    display: flex;
    flex-direction: column;
    z-index: 15;
    box-shadow: 
        inset 3px 0 12px rgba(0,0,0,0.5),
        inset 0 0 20px rgba(0,0,0,0.3);
    /* Hidden until bearing off */
    opacity: 0;
    overflow: hidden;
    transition: opacity 0.3s ease, width 0.3s ease;
}
.bg-bearoff.visible {
    opacity: 1;
    width: 44px;
    overflow: visible;
}
.bg-bearoff::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(20,14,8,0.35);
    pointer-events: none;
    border-radius: 0 10px 10px 0;
}
/* Separator line between black and white halves */
.bg-bearoff::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 4px;
    right: 4px;
    height: 1px;
    background: rgba(139,90,43,0.4);
    z-index: 1;
}
.bg-bo-w, .bg-bo-b {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 3px;
    gap: 2px;
    position: relative;
    z-index: 1;
}
.bg-bo-b { justify-content: flex-start; }
.bg-bo-w { justify-content: flex-end; }

.bg-piece-borne {
    width: 32px;
    height: 8px;
    border-radius: 4px;
    flex-shrink: 0;
}
.bg-borne-white {
    background: linear-gradient(180deg, #f0e8d8, #d5c8b0);
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.bg-borne-black {
    background: linear-gradient(180deg, #3d2d1e, #201510);
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* Bearoff highlight */
.bg-bo-hl {
    background: rgba(100,240,140,0.12) !important;
    border-left: 2px solid rgba(100,240,140,0.45) !important;
    box-shadow: inset 0 0 25px rgba(100,240,140,0.12), 0 0 12px rgba(100,240,140,0.1);
    cursor: pointer;
    animation: bearoffPulse 2s ease-in-out infinite;
}
@keyframes bearoffPulse {
    0%,100% { box-shadow: inset 0 0 20px rgba(100,240,140,0.1); }
    50% { box-shadow: inset 0 0 35px rgba(100,240,140,0.22), 0 0 15px rgba(100,240,140,0.12); }
}

/* === DICE AREA === */
.board-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.dice-area {
    position: absolute;
    top: 50%;
    right: 40px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
    z-index: 10;
}

/* === DICE ARENA - Transparent (rolls on board) === */
.dice-arena {
    position: relative;
    width: 200px;
    height: 90px;
    background: transparent;
    border-radius: 10px;
    border: none;
    box-shadow: none;
    overflow: visible;
}

/* No felt texture */
.dice-arena::before {
    display: none;
}

/* === 3D CRYSTAL DICE === */
.dice-container {
    position: absolute;
    perspective: 1000px;
    width: 44px;
    height: 44px;
    transition: none;
}

.dice3d {
    width: 44px;
    height: 44px;
    position: relative;
    transform-style: preserve-3d;
    cursor: pointer;
}

.dice3d .dface {
    backface-visibility: hidden;
}

.dice3d.spinning .dface {
    backface-visibility: visible;
}

/* Rich Mahogany Wood dice face */
.dface {
    position: absolute;
    width: 44px;
    height: 44px;
    border-radius: 5px;
    display: grid;
    padding: 7px;
    /* Solid mahogany wood */
    background: linear-gradient(145deg, #6b2e2e 0%, #5a2020 40%, #4a1818 70%, #3d1212 100%);
    border: 1.5px solid rgba(120,60,40,0.7);
    box-shadow: 
        inset 0 1px 3px rgba(255,200,180,0.15),
        inset 0 -2px 4px rgba(0,0,0,0.3),
        0 2px 6px rgba(0,0,0,0.4);
}

/* Top face - slight highlight */
.dface.df5 {
    background: linear-gradient(145deg, #7a3535 0%, #6b2e2e 40%, #5a2020 100%);
    border-color: rgba(140,70,50,0.7);
}

/* Wood grain shine */
.dface::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 40%, transparent 60%, rgba(255,255,255,0.03) 100%);
    pointer-events: none;
    border-radius: 4px;
}

/* Gold pips */
.dface .pip {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 25%, 
        #fff8dc 0%,
        #ffd700 15%,
        #daa520 40%, 
        #b8860b 70%,
        #996515 100%);
    border: 0.5px solid rgba(139, 90, 43, 0.5);
    box-shadow: 
        inset 0 1px 2px rgba(255,250,200,0.7),
        inset 0 -1px 1px rgba(100,60,0,0.4),
        0 1px 2px rgba(0,0,0,0.4);
    align-self: center;
    justify-self: center;
}

/* Face positions */
.df1 { transform: rotateY(0deg) translateZ(22px); grid-template: 1fr / 1fr; }
.df2 { transform: rotateY(180deg) translateZ(22px); grid-template: 1fr 1fr / 1fr; }
.df2 .pip:first-child { justify-self: end; align-self: start; }
.df2 .pip:last-child { justify-self: start; align-self: end; }
.df3 { transform: rotateY(-90deg) translateZ(22px); grid-template: 1fr 1fr 1fr / 1fr; }
.df3 .pip:first-child { justify-self: end; align-self: start; }
.df3 .pip:nth-child(2) { justify-self: center; align-self: center; }
.df3 .pip:last-child { justify-self: start; align-self: end; }
.df4 { transform: rotateY(90deg) translateZ(22px); grid-template: 1fr 1fr / 1fr 1fr; }
.df5 { transform: rotateX(90deg) translateZ(22px); grid-template: 1fr 1fr 1fr / 1fr 1fr; }
.df5 .pip:nth-child(3) { grid-column: 1 / -1; justify-self: center; }
.df6 { transform: rotateX(-90deg) translateZ(22px); grid-template: 1fr 1fr 1fr / 1fr 1fr; }

/* === ROLL BUTTON === */
.btn-dice {
    padding: 10px 24px;
    background: rgba(60,35,20,0.7);
    color: var(--gold-main);
    border: 1.5px solid rgba(139,90,43,0.4);
    border-radius: 6px;
    font-family: 'Cinzel', serif;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 2px;
    text-transform: uppercase;
    transition: all 0.25s;
    box-shadow: 0 0 15px rgba(212,168,122,0.05);
}
.btn-dice:hover:not(:disabled) {
    background: rgba(212,168,122,0.08);
    border-color: rgba(212,168,122,0.5);
    box-shadow: 0 0 25px rgba(212,168,122,0.15);
    color: var(--gold-light);
}
.btn-dice:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
/* Pulsing glow when it's your turn to roll */
.dice-btn-pulse {
    animation: diceBtnPulse 1.5s ease infinite;
    border-color: rgba(212,168,100,0.6) !important;
    background: rgba(80,50,25,0.8) !important;
}
@keyframes diceBtnPulse {
    0%, 100% { box-shadow: 0 0 10px rgba(212,168,100,0.2); }
    50% { box-shadow: 0 0 25px rgba(212,168,100,0.5), 0 0 40px rgba(212,168,100,0.2); }
}

/* Dice results display */
.dice-results {
    display: flex;
    gap: 16px;
    perspective: 300px;
}

/* Legacy 3D Dice wrappers (keeping for compatibility) */
.dice3d-wrapper {
    width: 44px;
    height: 44px;
    perspective: 200px;
    animation: diceDropIn 0.3s ease both;
}
.dice3d-wrapper.dice3d-landed {
    animation: diceBounce 0.3s ease;
}
.dice3d-wrapper.dice3d-used {
    opacity: 0.2;
}

@keyframes diceDropIn {
    0% { transform: translateY(-40px) scale(0.5); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes diceBounce {
    0% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
    70% { transform: translateY(2px); }
    100% { transform: translateY(0); }
}

.dice3d-cube {
    width: 44px;
    height: 44px;
    position: relative;
    transform-style: preserve-3d;
}

/* Legacy dice face styling (mahogany) */
.dice3d-face {
    position: absolute;
    width: 44px;
    height: 44px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    background: linear-gradient(145deg, #6b2e2e 0%, #5a2020 40%, #4a1818 70%, #3d1212 100%);
    border: 1.5px solid rgba(120,60,40,0.7);
    box-shadow: 
        inset 0 1px 3px rgba(255,200,180,0.15),
        inset 0 -2px 4px rgba(0,0,0,0.3);
}
.dice3d-face::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 40%);
    border-radius: 4px;
    pointer-events: none;
}

.dice3d-face-1 { transform: rotateY(0deg) translateZ(22px); }
.dice3d-face-6 { transform: rotateY(180deg) translateZ(22px); }
.dice3d-face-2 { transform: rotateX(90deg) translateZ(22px); }
.dice3d-face-5 { transform: rotateX(-90deg) translateZ(22px); }
.dice3d-face-3 { transform: rotateY(-90deg) translateZ(22px); }
.dice3d-face-4 { transform: rotateY(90deg) translateZ(22px); }

/* Gold pips for legacy dice */
.dice3d-dots {
    width: 32px;
    height: 32px;
}
.dice3d-dots circle {
    fill: #d4a520;
    filter: drop-shadow(0 0 2px rgba(212,165,32,0.5));
}

/* === DOUBLE BUTTON === */
.double-area {
    position: absolute;
    top: 50%;
    left: 60px;
    transform: translateY(-50%);
    pointer-events: auto;
}
.btn-double {
    padding: 6px 12px;
    background: rgba(194,84,84,0.15);
    color: #c25454;
    border: 1px solid rgba(194,84,84,0.25);
    border-radius: 4px;
    font-weight: 700;
    cursor: pointer;
    font-family: 'Cinzel', serif;
    font-size: 11px;
    transition: all 0.2s;
}
.btn-double:hover {
    background: rgba(194,84,84,0.25);
    border-color: rgba(194,84,84,0.4);
}

/* === GAME CONTROLS === */
.game-controls {
    display: flex;
    gap: 6px;
    justify-content: center;
    padding: 3px 0;
    flex-shrink: 0;
}

/* === BAR PIECES OVERLAY === */
.bar-pieces {
    display: none;
}

/* === POINT NUMBERS === */
.bg-point-num {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    font-weight: 800;
    color: rgba(255,240,200,0.55);
    pointer-events: none;
    z-index: 3;
    font-family: 'Cinzel', serif;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.bg-point-top .bg-point-num { top: 1px; }
.bg-point-bottom .bg-point-num { bottom: 1px; }

/* Home zone indicator */
.bg-home-zone {
    position: absolute;
    left: 0;
    right: 0;
    height: 4px;
    pointer-events: none;
    z-index: 3;
    border-radius: 2px;
}
.bg-point-bottom .bg-home-zone { bottom: 0; }
.bg-point-top .bg-home-zone { top: 0; }

/* My home - green glow */
.bg-home-mine {
    background: linear-gradient(90deg, transparent 5%, rgba(76,200,80,0.6) 50%, transparent 95%);
    box-shadow: 0 0 8px rgba(76,200,80,0.4), 0 0 3px rgba(76,200,80,0.6);
}
/* Opponent home - red/dim */
.bg-home-opp {
    background: linear-gradient(90deg, transparent 10%, rgba(200,80,80,0.25) 50%, transparent 90%);
    box-shadow: 0 0 4px rgba(200,80,80,0.15);
}

/* Selected piece glow */
.bg-piece.bg-p-selected {
    filter: brightness(1.2);
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(212,168,100,0.5) !important;
}

/* === FLIP BUTTON - Left center of board === */
.bg-flip-btn {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    background: rgba(30,20,12,0.85);
    border: 1.5px solid rgba(139,90,43,0.4);
    border-radius: 50%;
    color: rgba(212,168,100,0.7);
    font-size: 14px;
    cursor: pointer;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.bg-flip-btn:hover, .bg-flip-btn:active {
    background: rgba(139,90,43,0.4);
    border-color: rgba(212,168,100,0.6);
    color: rgba(212,168,100,1);
}

/* Dice used state */
.dice-used {
    opacity: 0.25;
    filter: grayscale(0.5);
    transition: opacity 0.3s, filter 0.3s;
}

/* === SPECTATE === */
.spectate-container {
    max-width: 900px;
    margin: 0 auto;
}
.spectate-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(194,84,84,0.85);
    color: white;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    animation: livePulse 2s infinite;
    z-index: 10;
}
@keyframes livePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* === CHAT === */
.game-chat {
    background: rgba(20,16,12,0.95);
    border: 1px solid rgba(139,90,43,0.15);
    border-radius: 8px;
    margin-top: 4px;
    overflow: hidden;
}
.chat-messages {
    height: 100px;
    overflow-y: auto;
    padding: 6px 10px;
    font-size: 12px;
}
.chat-msg {
    margin-bottom: 3px;
}
.chat-msg-name {
    color: var(--gold-main);
    font-weight: 700;
}
.chat-msg-text {
    color: #bbb;
    margin-right: 4px;
}
.chat-msg-sys {
    color: #666;
    font-style: italic;
}
.chat-input-row {
    display: flex;
    gap: 4px;
    padding: 4px 6px;
    border-top: 1px solid rgba(212,168,122,0.08);
}
.chat-input-row input {
    flex: 1;
    font-size: 12px;
    padding: 4px 8px;
    background: rgba(20,20,30,0.9);
    border: 1px solid rgba(212,168,122,0.12);
    border-radius: 4px;
    color: #ccc;
}
.chat-input-row input:focus {
    border-color: rgba(212,168,122,0.3);
    outline: none;
}
.chat-input-row button {
    font-size: 11px;
    padding: 4px 10px;
}

/* === RESPONSIVE === */
@media (max-width: 600px) {
    .game-container {
        height: calc(100vh - 44px);
        height: calc(100dvh - 44px);
        padding: 1px 2px;
    }
    .board-container {
        max-height: none;
        aspect-ratio: auto;
        flex: 1;
        min-height: 0;
        border-radius: 8px;
    }
    .player-bar {
        padding: 3px 8px;
        gap: 6px;
        border-radius: 4px;
    }
    .player-avatar {
        width: 24px;
        height: 24px;
        font-size: 11px;
    }
    .player-name { font-size: 12px; }
    .player-timer { font-size: 13px; }
    .pip-count { font-size: 9px; }
    .opponent-bar, .my-bar { margin: 1px 0; }
    .bg-piece {
        width: clamp(22px, 7.5vw, 32px);
        height: clamp(22px, 7.5vw, 32px);
    }
    .bg-p-shine {
        width: 10px;
        height: 7px;
        top: 4px;
        left: 6px;
    }
    .bg-bar {
        width: 24px;
    }
    .bg-bar::after {
        font-size: 14px;
    }
    .bg-bearoff {
        top: 2px;
        bottom: 2px;
    }
    .bg-bearoff.visible {
        width: 28px;
    }
    .bg-piece-borne {
        width: 20px;
        height: 5px;
    }
    .bg-board {
        top: 2px;
        left: 2px;
        right: 2px;
        bottom: 2px;
        border-radius: 6px;
    }
    .board-container.bearoff-active .bg-board {
        right: 32px;
        border-radius: 6px 0 0 6px;
    }
    .bg-flip-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
        left: 6px;
    }
    .bg-point-num { font-size: 7px; }
    .bg-home-label { font-size: 6px; }
    .bg-pieces { padding: 2px 0; }
    .dice-area {
        right: 30px;
    }
    .dice-arena {
        width: 120px;
        height: 52px;
        background: transparent;
        border: none;
        box-shadow: none;
    }
    .dice-container {
        width: 26px;
        height: 26px;
    }
    .dice3d {
        width: 26px;
        height: 26px;
    }
    .dface {
        width: 26px;
        height: 26px;
        padding: 3px;
    }
    .dface .pip {
        width: 4px;
        height: 4px;
    }
    .df1, .df2, .df3, .df4, .df5, .df6 {
        transform-origin: center;
    }
    .df1 { transform: rotateY(0deg) translateZ(13px); }
    .df2 { transform: rotateY(180deg) translateZ(13px); }
    .df3 { transform: rotateY(-90deg) translateZ(13px); }
    .df4 { transform: rotateY(90deg) translateZ(13px); }
    .df5 { transform: rotateX(90deg) translateZ(13px); }
    .df6 { transform: rotateX(-90deg) translateZ(13px); }
    .btn-dice { font-size: 11px; padding: 5px 12px; }
    .game-controls { padding: 2px 0; gap: 4px; }
    .game-controls .btn { font-size: 11px; padding: 4px 8px; }
}

/* Desktop - limit max height */
@media (min-width: 601px) {
    .board-container {
        max-height: calc(100vh - 180px);
    }
}

/* === GAME OVERLAYS === */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes arrowPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

/* === LANDSCAPE MODE === */
@media (orientation: landscape) and (max-height: 500px) {
    /* Hide navs in landscape */
    .tg-nav, .sidebar, .g-footer { display: none !important; }
    
    /* Full screen game container */
    .game-container {
        height: 100vh !important;
        height: 100dvh !important;
        padding: 0 !important;
        padding-bottom: 0 !important;
    }
    
    /* Compact game header */
    .gm-header { min-height: 36px !important; padding: 2px 6px !important; }
    .gm-ava { width: 28px !important; height: 28px !important; font-size: 12px !important; }
    .gm-level-badge { width: 12px !important; height: 12px !important; font-size: 7px !important; }
    .gm-pname { font-size: 10px !important; }
    .gm-timer { font-size: 11px !important; }
    .gm-vs-badge { width: 24px !important; height: 24px !important; font-size: 8px !important; }
    
    /* Bottom controls compact */
    .game-controls { min-height: 34px !important; padding: 2px 6px !important; }
    .g-ctrl-btn { padding: 3px 8px !important; font-size: 10px !important; }
    
    /* Board takes maximum space */
    .board-container {
        flex: 1 !important;
        max-height: none !important;
        aspect-ratio: auto !important;
        border-radius: 4px !important;
        margin: 0 2px !important;
    }
    
    /* Pieces slightly smaller for landscape */
    .bg-piece {
        width: clamp(18px, 5vh, 32px) !important;
        height: clamp(18px, 5vh, 32px) !important;
    }
    
    /* Bar narrower */
    .bg-bar { width: 24px !important; }
    .bg-bar::after { font-size: 12px !important; }
    
    /* Dice smaller */
    .dice-container { width: 28px !important; height: 28px !important; }
    .dice3d { width: 28px !important; height: 28px !important; }
    .dface { width: 28px !important; height: 28px !important; }
    
    /* Point numbers tiny */
    .bg-point-num { font-size: 7px !important; }
    
    /* Flip button tiny */
    .bg-flip-btn { width: 24px !important; height: 24px !important; font-size: 10px !important; left: 4px !important; }
}

/* Landscape for non-game pages (lobby etc) */
@media (orientation: landscape) and (max-height: 500px) {
    .page { padding-bottom: 0 !important; }
    .lobby-container { padding: 8px !important; }
}

/* === BOARD SEMI-CIRCLE CUTOUTS === */
/* Concave wood scoops at the base of each point - pieces sit inside */
.bg-point::after {
    content: '';
    position: absolute;
    width: 60%;
    aspect-ratio: 2 / 1;
    border-radius: 0 0 50% 50%;
    left: 20%;
    z-index: 1;
    pointer-events: none;
}
.bg-point-top::after {
    top: 0;
    border-radius: 0 0 50% 50%;
    background: radial-gradient(ellipse at 50% 0%, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.04) 60%, transparent 100%);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}
.bg-point-bottom::after {
    bottom: 0;
    border-radius: 50% 50% 0 0;
    background: radial-gradient(ellipse at 50% 100%, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.04) 60%, transparent 100%);
    box-shadow: inset 0 -2px 4px rgba(0,0,0,0.1);
}

/* Board inner frame / rail */
.bg-board {
    box-shadow:
        inset 0 0 0 3px rgba(160,120,70,0.3),
        inset 0 0 15px rgba(0,0,0,0.3),
        0 8px 30px rgba(0,0,0,0.5);
}

/* === PORTRAIT MODE OVERRIDE === */
@media (orientation: portrait) {
    .game-container {
        flex-direction: column !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-width: 100% !important;
        padding: 0 !important;
    }
    .board-container {
        flex: 1 !important;
        min-height: 0 !important;
        max-height: calc(100dvh - 150px) !important;
        aspect-ratio: auto !important;
        border-radius: 6px !important;
    }
    .bg-board {
        top: 2px;
        left: 2px;
        right: 2px;
        bottom: 2px;
    }
    .bg-piece {
        width: clamp(22px, 7.5vw, 34px) !important;
        height: clamp(22px, 7.5vw, 34px) !important;
    }
    .bg-bar {
        width: 20px !important;
    }
}
