* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

body, html {
    width: 100%;
    height: 100%;
    background-color: #a46429;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
}

/* WARM WOODEN TABLE THEME */
#app-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 720px;
    margin: 0 auto;
    background: radial-gradient(circle at 50% 50%, #c47c38 0%, #8c4e18 100%);
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    -webkit-align-items: center;
    align-items: center;
    overflow: hidden;
}

@media (max-width: 1024px) {
    #app-container {
        max-width: 100%;
    }
}

.hidden {
    display: none !important;
}

/* ================= 1. TOP & BOTTOM CONTROL BARS & CORNER DICE CUPS ================= */

#top-bar, #bottom-bar {
    width: 100%;
    padding: 10px 18px;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    z-index: 10;
}

/* 4 CORNER WOODEN DICE CUPS */
.corner-cup {
    width: 74px;
    height: 74px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, #5a310e, #2d1605);
    box-shadow: inset 0 6px 8px rgba(0,0,0,0.8), 0 4px 6px rgba(0,0,0,0.4);
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}

.corner-cup:active {
    transform: scale(0.9);
}

/* Active Turn Glowing Pulsing Cup */
.corner-cup.active-cup {
    animation: pulseCup 0.8s infinite alternate;
}

.corner-cup.red-cup.active-cup { box-shadow: inset 0 6px 8px rgba(0,0,0,0.8), 0 0 18px #e74c3c; }
.corner-cup.green-cup.active-cup { box-shadow: inset 0 6px 8px rgba(0,0,0,0.8), 0 0 18px #2ecc71; }
.corner-cup.yellow-cup.active-cup { box-shadow: inset 0 6px 8px rgba(0,0,0,0.8), 0 0 18px #f1c40f; }
.corner-cup.blue-cup.active-cup { box-shadow: inset 0 6px 8px rgba(0,0,0,0.8), 0 0 18px #3498db; }

@keyframes pulseCup {
    0% { transform: scale(1); }
    100% { transform: scale(1.12); }
}

/* 3D Dice inside Cup */
.dice-in-cup {
    width: 52px;
    height: 52px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.6);
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    font-size: 34px;
    font-weight: 900;
    color: #e74c3c;
    text-shadow: 1px 1px 0px #000;
    line-height: 52px;
    text-align: center;
}

.corner-cup.rolling .dice-in-cup {
    animation: shakeCupDice 0.4s infinite;
}

@keyframes shakeCupDice {
    0% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(20deg) scale(1.15); }
    50% { transform: rotate(-20deg) scale(1.15); }
    75% { transform: rotate(12deg) scale(1.08); }
    100% { transform: rotate(0deg) scale(1); }
}

/* Center Round Action Buttons (100% ABSOLUTE CENTERING FOR IOS 9 SAFARI) */
.round-btn {
    position: relative;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(180deg, #00d2ff, #0083b0);
    border: 3px solid #fff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    color: #fff;
    cursor: pointer;
    overflow: hidden;
}

.round-btn .btn-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%);
    font-size: 28px;
    line-height: 1;
    display: block;
    text-align: center;
    pointer-events: none;
}

.round-btn:active {
    transform: scale(0.9);
}

/* IPAD & TABLET SPECIFIC LARGER SIZING (MIN-WIDTH 768px) */
@media (min-width: 768px) {
    #top-bar, #bottom-bar {
        padding: 14px 28px;
    }
    .corner-cup {
        width: 86px;
        height: 86px;
    }
    .dice-in-cup {
        width: 60px;
        height: 60px;
        font-size: 40px;
        line-height: 60px;
    }
    .round-btn {
        width: 72px;
        height: 72px;
        border-width: 4px;
    }
    .round-btn .btn-icon {
        font-size: 38px;
    }
}

/* ================= 2. FULL WIDTH LUDO BOARD ================= */

#board-container {
    flex: 1;
    width: 100%;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    padding: 0;
    position: relative;
    overflow: hidden;
}

#ludo-board {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #fff;
    border: 5px solid #2c3e50;
    box-shadow: 0 10px 25px rgba(0,0,0,0.7);
}

/* 4 Home Yards (40% x 40% each) */
.yard {
    position: absolute;
    width: 40%;
    height: 40%;
    padding: 8%;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
}

.red-yard { top: 0; left: 0; background: #e74c3c; }
.green-yard { top: 0; right: 0; background: #2ecc71; }
.blue-yard { bottom: 0; left: 0; background: #3498db; }
.yellow-yard { bottom: 0; right: 0; background: #f1c40f; }

.yard-box {
    width: 100%;
    height: 100%;
    background: #fff;
    border-radius: 12px;
    position: relative;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.3);
}

.token-spot {
    position: absolute;
    width: 35%;
    height: 35%;
    border-radius: 50%;
    border: 2px dashed #ccc;
}

#spot-red-0, #spot-green-0, #spot-yellow-0, #spot-blue-0 { top: 10%; left: 10%; }
#spot-red-1, #spot-green-1, #spot-yellow-1, #spot-blue-1 { top: 10%; right: 10%; }
#spot-red-2, #spot-green-2, #spot-yellow-2, #spot-blue-2 { bottom: 10%; left: 10%; }
#spot-red-3, #spot-green-3, #spot-yellow-3, #spot-blue-3 { bottom: 10%; right: 10%; }

/* Walkways Containers */
.walkway { position: absolute; background: #fff; }
.v-walkway { width: 20%; height: 40%; }
.h-walkway { width: 40%; height: 20%; }

.top-walkway { top: 0; left: 40%; }
.bottom-walkway { bottom: 0; left: 40%; }
.left-walkway { top: 40%; left: 0; }
.right-walkway { top: 40%; right: 0; }

/* Grid Cells inside Walkways */
.cell {
    position: absolute;
    border: 1px solid #ddd;
    box-sizing: border-box;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    background: #fff;
}

.cell.path-red { background: #e74c3c !important; }
.cell.path-green { background: #2ecc71 !important; }
.cell.path-yellow { background: #f1c40f !important; }
.cell.path-blue { background: #3498db !important; }

.cell.star-cell::after {
    content: "⭐";
    font-size: 14px;
    opacity: 0.85;
}

/* ================= 3. CENTER HOME SVG TRIANGLES & CENTER SCORE DICE ================= */

#home-center {
    position: absolute;
    top: 40%; left: 40%;
    width: 20%; height: 20%;
    background: #fff;
    border: 1px solid #333;
    overflow: visible;
}

.home-svg {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
}

/* CENTER SCORE DICE DISPLAY BOX */
#dice-container {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 5px 12px rgba(0,0,0,0.6), 0 0 0 3px #f1c40f;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    cursor: pointer;
    z-index: 50;
    transition: transform 0.1s;
}

#dice-container.rolling {
    animation: shakeDiceCenter 0.4s infinite;
}

@keyframes shakeDiceCenter {
    0% { transform: translate(-50%, -50%) rotate(0deg) scale(1); }
    25% { transform: translate(-50%, -50%) rotate(15deg) scale(1.1); }
    50% { transform: translate(-50%, -50%) rotate(-15deg) scale(1.1); }
    75% { transform: translate(-50%, -50%) rotate(10deg) scale(1.05); }
    100% { transform: translate(-50%, -50%) rotate(0deg) scale(1); }
}

#dice-number-display {
    font-size: 32px;
    font-weight: 900;
    color: #e74c3c;
    text-shadow: 1px 1px 0px #000;
    line-height: 48px;
    text-align: center;
}

/* ================= 4. REAL 3D PAWN GOTI DESIGN ================= */

#tokens-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

.goti {
    position: absolute;
    width: 6.66%;
    height: 8.5%;
    cursor: pointer;
    pointer-events: auto;
    transition: left 0.15s linear, top 0.15s linear, transform 0.15s ease;
    z-index: 25;
    margin-top: -1.5%;
}

.goti::before {
    content: "";
    position: absolute;
    top: 0;
    left: 15%;
    width: 70%;
    height: 44%;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.9);
    box-sizing: border-box;
    z-index: 2;
}

.goti::after {
    content: "";
    position: absolute;
    top: 32%;
    left: 5%;
    width: 90%;
    height: 65%;
    border-radius: 40% 40% 45% 45% / 80% 80% 25% 25%;
    border: 1px solid rgba(255,255,255,0.9);
    box-sizing: border-box;
    z-index: 1;
}

.goti.goti-red::before, .goti.goti-red::after { background: #e74c3c; box-shadow: inset -2px -2px 3px rgba(0,0,0,0.4); }
.goti.goti-green::before, .goti.goti-green::after { background: #2ecc71; box-shadow: inset -2px -2px 3px rgba(0,0,0,0.4); }
.goti.goti-yellow::before, .goti.goti-yellow::after { background: #f1c40f; box-shadow: inset -2px -2px 3px rgba(0,0,0,0.4); }
.goti.goti-blue::before, .goti.goti-blue::after { background: #3498db; box-shadow: inset -2px -2px 3px rgba(0,0,0,0.4); }

.goti.selectable {
    animation: pulsePawn 0.6s infinite alternate;
    z-index: 35;
}

@keyframes pulsePawn {
    0% { transform: scale(1); }
    100% { transform: scale(1.25) translateY(-3px); }
}

.goti.step-hop {
    animation: gotiHop 0.15s ease-in-out;
}

@keyframes gotiHop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3) translateY(-6px); }
    100% { transform: scale(1); }
}

.goti.killed {
    animation: gotiKillAnim 0.5s ease-in-out forwards;
}

@keyframes gotiKillAnim {
    0% { transform: scale(1) rotate(0deg); opacity: 1; }
    50% { transform: scale(1.3) rotate(180deg); opacity: 0.8; }
    100% { transform: scale(0.2) rotate(360deg); opacity: 0; }
}

/* ================= 5. MODALS & COLOR SELECTION ================= */

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    z-index: 100;
}

.ludo-modal-card {
    position: relative;
    width: 90%;
    max-width: 360px;
    background: #1e1b2e;
    border: 3px solid #f1c40f;
    border-radius: 20px;
    padding: 25px 18px;
    text-align: center;
    color: #fff;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

.modal-close-btn {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,0.15);
    border-radius: 50%;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    font-size: 16px;
    color: #fff;
    cursor: pointer;
    line-height: 32px;
}

.ludo-modal-card h2 {
    font-size: 26px;
    color: #f1c40f;
    margin-bottom: 5px;
}

.section-title {
    font-size: 13px;
    color: #aaa;
    margin: 12px 0 8px 0;
    text-align: left;
    font-weight: bold;
}

.color-picker-row {
    display: -webkit-flex;
    display: flex;
    gap: 6px;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    margin-bottom: 12px;
}

.color-pill {
    flex: 1;
    padding: 8px 4px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: bold;
    color: #fff;
    background: rgba(255,255,255,0.1);
    border: 2px solid transparent;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.color-pill.pill-red { background: rgba(231, 76, 60, 0.3); }
.color-pill.pill-green { background: rgba(46, 204, 113, 0.3); }
.color-pill.pill-yellow { background: rgba(241, 196, 15, 0.3); }
.color-pill.pill-blue { background: rgba(52, 152, 219, 0.3); }

.color-pill.selected {
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255,255,255,0.8);
    transform: scale(1.05);
}

.mode-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: bold;
    color: #fff;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}

.green-btn { background: linear-gradient(180deg, #2ecc71, #27ae60); }
.orange-btn { background: linear-gradient(180deg, #e67e22, #d35400); }
.blue-btn { background: linear-gradient(180deg, #3498db, #2980b9); }
.purple-btn { background: linear-gradient(180deg, #9b59b6, #8e44ad); }
