* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1000px;
}

.container {
    text-align: center;
    color: white;
}

h1 {
    margin-bottom: 2rem;
    font-size: 2.5rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.dice-container {
    perspective: 1000px;
    margin: 2rem auto;
    width: 200px;
    height: 200px;
}

.dice {
    position: relative;
    width: 200px;
    height: 200px;
    transform-style: preserve-3d;
    transform: rotateX(0deg) rotateY(0deg);
    margin: 0 auto;
}

.face {
    position: absolute;
    width: 200px;
    height: 200px;
    background: linear-gradient(145deg, #ffffff, #f0f0f0);
    border: 2px solid #333;
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 
        inset 0 0 20px rgba(0,0,0,0.1),
        0 10px 30px rgba(0,0,0,0.3);
}

/* Face positioning - Correct dice orientation where opposite faces sum to 7 */
.front {
    transform: translateZ(100px);                    /* Face 1 - front */
}

.right {
    transform: rotateY(90deg) translateZ(100px);     /* Face 2 - right */
}

.top {
    transform: rotateX(90deg) translateZ(100px);     /* Face 3 - top */
}

.bottom {
    transform: rotateX(-90deg) translateZ(100px);    /* Face 4 - bottom (opposite of 3) */
}

.left {
    transform: rotateY(-90deg) translateZ(100px);    /* Face 5 - left (opposite of 2) */
}

.back {
    transform: translateZ(-100px) rotateY(180deg);   /* Face 6 - back (opposite of 1) */
}

/* Dot styling */
.dot {
    width: 30px;
    height: 30px;
    background: radial-gradient(circle, #333 0%, #000 100%);
    border-radius: 50%;
    box-shadow: 
        inset 0 2px 4px rgba(255,255,255,0.3),
        0 2px 4px rgba(0,0,0,0.5);
}

/* White dice (default) */
.white-dice .face {
    background: linear-gradient(145deg, #ffffff, #f0f0f0);
    border: 2px solid #333;
}

.white-dice .dot {
    background: radial-gradient(circle, #333 0%, #000 100%);
    box-shadow: 
        inset 0 2px 4px rgba(255,255,255,0.3),
        0 2px 4px rgba(0,0,0,0.5);
}

/* Red dice */
.red-dice .face {
    background: linear-gradient(145deg, #dc2626, #b91c1c);
    border: 2px solid #991b1b;
    box-shadow: 
        inset 0 0 20px rgba(0,0,0,0.1),
        0 10px 30px rgba(0,0,0,0.3);
}

.red-dice .dot {
    background: radial-gradient(circle, #ffffff 0%, #f3f4f6 100%);
    box-shadow: 
        inset 0 2px 4px rgba(0,0,0,0.1),
        0 2px 4px rgba(0,0,0,0.3);
}

/* Black dice */
.black-dice .face {
    background: linear-gradient(145deg, #1f2937, #111827);
    border: 2px solid #000000;
    box-shadow: 
        inset 0 0 20px rgba(0,0,0,0.2),
        0 10px 30px rgba(0,0,0,0.4);
}

.black-dice .dot {
    background: radial-gradient(circle, #ffffff 0%, #f3f4f6 100%);
    box-shadow: 
        inset 0 2px 4px rgba(0,0,0,0.1),
        0 2px 4px rgba(0,0,0,0.3);
}

/* Face 1 - Single dot (front) */
.front .dot {
    /* Already positioned in center by flexbox */
}

/* Face 2 - Two dots (right) */
.right {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 20px;
    padding: 30px;
}

.right .dot:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
}

.right .dot:nth-child(2) {
    grid-column: 2;
    grid-row: 2;
}

/* Face 3 - Three dots (top) */
.top {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 15px;
    padding: 25px;
}

.top .dot:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
}

.top .dot:nth-child(2) {
    grid-column: 2;
    grid-row: 2;
}

.top .dot:nth-child(3) {
    grid-column: 3;
    grid-row: 3;
}

/* Face 4 - Four dots (bottom) */
.bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 20px;
    padding: 30px;
}

.bottom .dot:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
}

.bottom .dot:nth-child(2) {
    grid-column: 2;
    grid-row: 1;
}

.bottom .dot:nth-child(3) {
    grid-column: 1;
    grid-row: 2;
}

.bottom .dot:nth-child(4) {
    grid-column: 2;
    grid-row: 2;
}

/* Face 5 - Five dots (left) */
.left {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 15px;
    padding: 25px;
}

.left .dot:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
}

.left .dot:nth-child(2) {
    grid-column: 3;
    grid-row: 1;
}

.left .dot:nth-child(3) {
    grid-column: 2;
    grid-row: 2;
}

.left .dot:nth-child(4) {
    grid-column: 1;
    grid-row: 3;
}

.left .dot:nth-child(5) {
    grid-column: 3;
    grid-row: 3;
}

/* Face 6 - Six dots (back) */
.back {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 20px;
    padding: 30px;
}

.back .dot:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
}

.back .dot:nth-child(2) {
    grid-column: 2;
    grid-row: 1;
}

.back .dot:nth-child(3) {
    grid-column: 1;
    grid-row: 2;
}

.back .dot:nth-child(4) {
    grid-column: 2;
    grid-row: 2;
}

.back .dot:nth-child(5) {
    grid-column: 1;
    grid-row: 3;
}

.back .dot:nth-child(6) {
    grid-column: 2;
    grid-row: 3;
}

/* Dice Count Selector */
.dice-count-selector {
    margin: 2rem 0;
    text-align: center;
}

.dice-count-selector h3 {
    color: white;
    margin-bottom: 1rem;
    font-size: 1.2rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.count-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.count-btn {
    background: linear-gradient(145deg, #6c757d, #5a6268);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
}

.count-btn:hover {
    background: linear-gradient(145deg, #5a6268, #6c757d);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.count-btn.active {
    background: linear-gradient(145deg, #28a745, #20c997);
    box-shadow: 0 6px 12px rgba(40, 167, 69, 0.4);
}

.count-btn.active:hover {
    background: linear-gradient(145deg, #20c997, #28a745);
}

/* Dice Area */
.dice-area {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    margin: 2rem 0;
}

/* Dice Info */
.dice-info {
    margin: 2rem 0;
    text-align: center;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.dice-info h3 {
    color: white;
    margin-bottom: 1rem;
    font-size: 1.2rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.dice-info p {
    color: white;
    font-size: 1rem;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
    margin: 0;
}

.variant-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.variant-btn {
    background: linear-gradient(145deg, #6c757d, #5a6268);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
}

.variant-btn:hover {
    background: linear-gradient(145deg, #5a6268, #6c757d);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.variant-btn.active {
    background: linear-gradient(145deg, #28a745, #20c997);
    box-shadow: 0 6px 12px rgba(40, 167, 69, 0.4);
}

.variant-btn.active:hover {
    background: linear-gradient(145deg, #20c997, #28a745);
}

/* Controls */
.controls {
    margin: 2rem 0;
}

.roll-section {
    text-align: center;
    margin-bottom: 2rem;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.roll-btn {
    background: linear-gradient(145deg, #dc3545, #c82333);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 30px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    box-shadow: 0 6px 15px rgba(220, 53, 69, 0.4);
    transition: all 0.3s ease;
    margin-bottom: 15px;
}

.roll-btn:hover:not(:disabled) {
    background: linear-gradient(145deg, #c82333, #dc3545);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(220, 53, 69, 0.6);
}

.roll-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.roll-result {
    color: white;
    font-size: 1.2rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.manual-controls {
    text-align: center;
}

.manual-controls h4 {
    color: white;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.controls button {
    background: linear-gradient(145deg, #4CAF50, #45a049);
    color: white;
    border: none;
    padding: 12px 20px;
    margin: 5px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
}

.controls button:hover {
    background: linear-gradient(145deg, #45a049, #4CAF50);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.controls button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Face labels */
.face-labels {
    display: flex;
    justify-content: space-around;
    margin-top: 2rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.label {
    background: rgba(255,255,255,0.2);
    padding: 10px 15px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 18px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.3);
}

/* Auto-rotate animation - Correct dice orientation where opposite faces sum to 7 */
@keyframes autoRotate {
    0% { transform: rotateX(0deg) rotateY(0deg); }        /* Face 1 (front) */
    16.66% { transform: rotateX(0deg) rotateY(-90deg); }  /* Face 2 (left) */
    33.33% { transform: rotateX(-90deg) rotateY(0deg); }  /* Face 3 (bottom) */
    50% { transform: rotateX(90deg) rotateY(0deg); }      /* Face 4 (top) - opposite of 3 */
    66.66% { transform: rotateX(0deg) rotateY(90deg); }   /* Face 5 (right) - opposite of 2 */
    83.33% { transform: rotateX(0deg) rotateY(180deg); }  /* Face 6 (back) - opposite of 1 */
    100% { transform: rotateX(0deg) rotateY(0deg); }      /* Back to Face 1 */
}

/* Rolling animations - Each animation ends on a specific face value */
/* Face 1 (front) - rotateX(0deg) rotateY(0deg) */
@keyframes rollToFace1 {
    0% { 
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
    25% { 
        transform: rotateX(180deg) rotateY(90deg) rotateZ(45deg);
    }
    50% { 
        transform: rotateX(360deg) rotateY(180deg) rotateZ(90deg);
    }
    75% { 
        transform: rotateX(540deg) rotateY(270deg) rotateZ(135deg);
    }
    100% { 
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
}

/* Face 2 (left) - rotateX(0deg) rotateY(-90deg) */
@keyframes rollToFace2 {
    0% { 
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
    20% { 
        transform: rotateX(120deg) rotateY(60deg) rotateZ(30deg);
    }
    40% { 
        transform: rotateX(240deg) rotateY(120deg) rotateZ(60deg);
    }
    60% { 
        transform: rotateX(360deg) rotateY(180deg) rotateZ(90deg);
    }
    80% { 
        transform: rotateX(480deg) rotateY(240deg) rotateZ(120deg);
    }
    100% { 
        transform: rotateX(0deg) rotateY(-90deg) rotateZ(0deg);
    }
}

/* Face 3 (bottom) - rotateX(-90deg) rotateY(0deg) */
@keyframes rollToFace3 {
    0% { 
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
    15% { 
        transform: rotateX(90deg) rotateY(45deg) rotateZ(22deg);
    }
    30% { 
        transform: rotateX(180deg) rotateY(90deg) rotateZ(45deg);
    }
    45% { 
        transform: rotateX(270deg) rotateY(135deg) rotateZ(67deg);
    }
    60% { 
        transform: rotateX(360deg) rotateY(180deg) rotateZ(90deg);
    }
    75% { 
        transform: rotateX(450deg) rotateY(225deg) rotateZ(112deg);
    }
    90% { 
        transform: rotateX(540deg) rotateY(270deg) rotateZ(135deg);
    }
    100% { 
        transform: rotateX(-90deg) rotateY(0deg) rotateZ(0deg);
    }
}

/* Face 4 (top) - rotateX(90deg) rotateY(0deg) */
@keyframes rollToFace4 {
    0% { 
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
    25% { 
        transform: rotateX(200deg) rotateY(100deg) rotateZ(50deg);
    }
    50% { 
        transform: rotateX(400deg) rotateY(200deg) rotateZ(100deg);
    }
    75% { 
        transform: rotateX(600deg) rotateY(300deg) rotateZ(150deg);
    }
    100% { 
        transform: rotateX(90deg) rotateY(0deg) rotateZ(0deg);
    }
}

/* Face 5 (right) - rotateX(0deg) rotateY(90deg) */
@keyframes rollToFace5 {
    0% { 
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
    30% { 
        transform: rotateX(150deg) rotateY(75deg) rotateZ(37deg);
    }
    60% { 
        transform: rotateX(300deg) rotateY(150deg) rotateZ(75deg);
    }
    100% { 
        transform: rotateX(0deg) rotateY(90deg) rotateZ(0deg);
    }
}

/* Face 6 (back) - rotateX(0deg) rotateY(180deg) */
@keyframes rollToFace6 {
    0% { 
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
    20% { 
        transform: rotateX(180deg) rotateY(90deg) rotateZ(45deg);
    }
    40% { 
        transform: rotateX(360deg) rotateY(180deg) rotateZ(90deg);
    }
    60% { 
        transform: rotateX(540deg) rotateY(270deg) rotateZ(135deg);
    }
    80% { 
        transform: rotateX(720deg) rotateY(360deg) rotateZ(180deg);
    }
    100% { 
        transform: rotateX(0deg) rotateY(180deg) rotateZ(0deg);
    }
}

/* Responsive design */
@media (max-width: 768px) {
    .dice-container {
        width: 150px;
        height: 150px;
    }
    
    .dice {
        width: 150px;
        height: 150px;
    }
    
    .face {
        width: 150px;
        height: 150px;
    }
    
    .dot {
        width: 20px;
        height: 20px;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .controls button {
        padding: 10px 15px;
        font-size: 14px;
    }
}
