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

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

.container {
    text-align: center;
    padding: 20px;
    padding-top: 150px;
    padding-bottom: 100px;
}

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

.dice-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    position: fixed;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

.dice-type-btn {
    padding: 12px 20px;
    font-size: 1.1em;
    font-weight: bold;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.dice-type-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: translateY(-2px);
}

.dice-type-btn.active {
    background: linear-gradient(145deg, #4CAF50, #45a049);
    border-color: #4CAF50;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

/* Dice Count Selector */
.dice-count-selector {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    position: fixed;
    top: 69px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

.dice-count-control {
    width: 45px;
    height: 45px;
    font-size: 1.5em;
    font-weight: bold;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.dice-count-control:hover:not(:disabled) {
    background: rgba(255,255,255,0.3);
    transform: translateY(-2px);
}

.dice-count-control:active:not(:disabled) {
    transform: translateY(0);
}

.dice-count-control:disabled {
    background: rgba(150,150,150,0.2);
    cursor: not-allowed;
    opacity: 0.4;
}

.dice-count-display {
    min-width: 100px;
    font-size: 1.2em;
    font-weight: bold;
    color: white;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.dice-container {
    width: 150px;
    height: 150px;
    perspective: 1000px;
    margin: 0 auto 50px;
    position: relative;
    overflow: visible;
}

.dice-wrapper {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s ease;
}

.dice-wrapper.active {
    opacity: 1;
    visibility: visible;
}

/* Dynamic dice layout */
.dice-display-flex {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    width: 100%;
    height: 100%;
    flex-wrap: wrap;
    transform: translate3d(0, 0, 0);
}

/* Linear layout for 1-3 dice */
.dice-container.count-1 { width: 150px; height: 150px; }
.dice-container.count-2 { width: 280px; height: 150px; }
.dice-container.count-3 { width: 420px; height: 150px; }

/* Grid layout for 4-6 dice */
.dice-container.count-4,
.dice-container.count-5,
.dice-container.count-6 {
    width: 420px;
    height: 300px;
}

.dice-container.count-4 .dice-display-flex,
.dice-container.count-5 .dice-display-flex,
.dice-container.count-6 .dice-display-flex {
    display: grid;
    grid-template-columns: repeat(3, 120px);
    gap: 30px;
}

/* Dice sizing based on count */
.dice-container.count-1 .dice { width: 150px; height: 150px; }
.dice-container.count-2 .dice,
.dice-container.count-3 .dice { width: 120px; height: 120px; }
.dice-container.count-4 .dice,
.dice-container.count-5 .dice,
.dice-container.count-6 .dice { width: 120px; height: 120px; }

/* Face sizing */
.dice-container.count-1 .face { width: 150px; height: 150px; }
.dice-container.count-2 .face,
.dice-container.count-3 .face,
.dice-container.count-4 .face,
.dice-container.count-5 .face,
.dice-container.count-6 .face { width: 120px; height: 120px; }

/* Adjust translateZ for different sizes */
.dice-container.count-1 .front  { transform: rotateY(0deg) translateZ(75px); }
.dice-container.count-1 .back   { transform: rotateX(180deg) translateZ(75px); }
.dice-container.count-1 .right  { transform: rotateY(90deg) translateZ(75px); }
.dice-container.count-1 .left   { transform: rotateY(-90deg) translateZ(75px); }
.dice-container.count-1 .top    { transform: rotateX(90deg) translateZ(75px); }
.dice-container.count-1 .bottom { transform: rotateX(-90deg) translateZ(75px); }

.dice-container.count-2 .front,
.dice-container.count-3 .front,
.dice-container.count-4 .front,
.dice-container.count-5 .front,
.dice-container.count-6 .front  { transform: rotateY(0deg) translateZ(60px); }

.dice-container.count-2 .back,
.dice-container.count-3 .back,
.dice-container.count-4 .back,
.dice-container.count-5 .back,
.dice-container.count-6 .back   { transform: rotateX(180deg) translateZ(60px); }

.dice-container.count-2 .right,
.dice-container.count-3 .right,
.dice-container.count-4 .right,
.dice-container.count-5 .right,
.dice-container.count-6 .right  { transform: rotateY(90deg) translateZ(60px); }

.dice-container.count-2 .left,
.dice-container.count-3 .left,
.dice-container.count-4 .left,
.dice-container.count-5 .left,
.dice-container.count-6 .left   { transform: rotateY(-90deg) translateZ(60px); }

.dice-container.count-2 .top,
.dice-container.count-3 .top,
.dice-container.count-4 .top,
.dice-container.count-5 .top,
.dice-container.count-6 .top    { transform: rotateX(90deg) translateZ(60px); }

.dice-container.count-2 .bottom,
.dice-container.count-3 .bottom,
.dice-container.count-4 .bottom,
.dice-container.count-5 .bottom,
.dice-container.count-6 .bottom { transform: rotateX(-90deg) translateZ(60px); }

/* Dot sizing */
.dice-container.count-1 .dot { width: 20px; height: 20px; }
.dice-container.count-2 .dot,
.dice-container.count-3 .dot,
.dice-container.count-4 .dot,
.dice-container.count-5 .dot,
.dice-container.count-6 .dot { width: 16px; height: 16px; }

/* Dot positions for single dice (150px face) - Desktop */
.dice-container.count-1 .face-1 .dot:nth-child(1) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.dice-container.count-1 .face-2 .dot:nth-child(1) { top: 35px; left: 35px; }
.dice-container.count-1 .face-2 .dot:nth-child(2) { bottom: 35px; right: 35px; }

.dice-container.count-1 .face-3 .dot:nth-child(1) { top: 35px; left: 35px; }
.dice-container.count-1 .face-3 .dot:nth-child(2) { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.dice-container.count-1 .face-3 .dot:nth-child(3) { bottom: 35px; right: 35px; }

.dice-container.count-1 .face-4 .dot:nth-child(1) { top: 35px; left: 35px; }
.dice-container.count-1 .face-4 .dot:nth-child(2) { top: 35px; right: 35px; }
.dice-container.count-1 .face-4 .dot:nth-child(3) { bottom: 35px; left: 35px; }
.dice-container.count-1 .face-4 .dot:nth-child(4) { bottom: 35px; right: 35px; }

.dice-container.count-1 .face-5 .dot:nth-child(1) { top: 35px; left: 35px; }
.dice-container.count-1 .face-5 .dot:nth-child(2) { top: 35px; right: 35px; }
.dice-container.count-1 .face-5 .dot:nth-child(3) { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.dice-container.count-1 .face-5 .dot:nth-child(4) { bottom: 35px; left: 35px; }
.dice-container.count-1 .face-5 .dot:nth-child(5) { bottom: 35px; right: 35px; }

.dice-container.count-1 .face-6 .dot:nth-child(1) { top: 35px; left: 35px; }
.dice-container.count-1 .face-6 .dot:nth-child(2) { top: 35px; right: 35px; }
.dice-container.count-1 .face-6 .dot:nth-child(3) { top: 50%; left: 35px; transform: translateY(-50%); }
.dice-container.count-1 .face-6 .dot:nth-child(4) { top: 50%; right: 35px; transform: translateY(-50%); }
.dice-container.count-1 .face-6 .dot:nth-child(5) { bottom: 35px; left: 35px; }
.dice-container.count-1 .face-6 .dot:nth-child(6) { bottom: 35px; right: 35px; }

/* Adjust dot positions for 120px dice */
.dice-container.count-2 .face-1 .dot:nth-child(1),
.dice-container.count-3 .face-1 .dot:nth-child(1),
.dice-container.count-4 .face-1 .dot:nth-child(1),
.dice-container.count-5 .face-1 .dot:nth-child(1),
.dice-container.count-6 .face-1 .dot:nth-child(1) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.dice-container.count-2 .face-2 .dot:nth-child(1),
.dice-container.count-3 .face-2 .dot:nth-child(1),
.dice-container.count-4 .face-2 .dot:nth-child(1),
.dice-container.count-5 .face-2 .dot:nth-child(1),
.dice-container.count-6 .face-2 .dot:nth-child(1) { top: 24px; left: 24px; }

.dice-container.count-2 .face-2 .dot:nth-child(2),
.dice-container.count-3 .face-2 .dot:nth-child(2),
.dice-container.count-4 .face-2 .dot:nth-child(2),
.dice-container.count-5 .face-2 .dot:nth-child(2),
.dice-container.count-6 .face-2 .dot:nth-child(2) { bottom: 24px; right: 24px; }

.dice-container.count-2 .face-3 .dot:nth-child(1),
.dice-container.count-3 .face-3 .dot:nth-child(1),
.dice-container.count-4 .face-3 .dot:nth-child(1),
.dice-container.count-5 .face-3 .dot:nth-child(1),
.dice-container.count-6 .face-3 .dot:nth-child(1) { top: 24px; left: 24px; }

.dice-container.count-2 .face-3 .dot:nth-child(2),
.dice-container.count-3 .face-3 .dot:nth-child(2),
.dice-container.count-4 .face-3 .dot:nth-child(2),
.dice-container.count-5 .face-3 .dot:nth-child(2),
.dice-container.count-6 .face-3 .dot:nth-child(2) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.dice-container.count-2 .face-3 .dot:nth-child(3),
.dice-container.count-3 .face-3 .dot:nth-child(3),
.dice-container.count-4 .face-3 .dot:nth-child(3),
.dice-container.count-5 .face-3 .dot:nth-child(3),
.dice-container.count-6 .face-3 .dot:nth-child(3) { bottom: 24px; right: 24px; }

.dice-container.count-2 .face-4 .dot:nth-child(1),
.dice-container.count-3 .face-4 .dot:nth-child(1),
.dice-container.count-4 .face-4 .dot:nth-child(1),
.dice-container.count-5 .face-4 .dot:nth-child(1),
.dice-container.count-6 .face-4 .dot:nth-child(1) { top: 24px; left: 24px; }

.dice-container.count-2 .face-4 .dot:nth-child(2),
.dice-container.count-3 .face-4 .dot:nth-child(2),
.dice-container.count-4 .face-4 .dot:nth-child(2),
.dice-container.count-5 .face-4 .dot:nth-child(2),
.dice-container.count-6 .face-4 .dot:nth-child(2) { top: 24px; right: 24px; }

.dice-container.count-2 .face-4 .dot:nth-child(3),
.dice-container.count-3 .face-4 .dot:nth-child(3),
.dice-container.count-4 .face-4 .dot:nth-child(3),
.dice-container.count-5 .face-4 .dot:nth-child(3),
.dice-container.count-6 .face-4 .dot:nth-child(3) { bottom: 24px; left: 24px; }

.dice-container.count-2 .face-4 .dot:nth-child(4),
.dice-container.count-3 .face-4 .dot:nth-child(4),
.dice-container.count-4 .face-4 .dot:nth-child(4),
.dice-container.count-5 .face-4 .dot:nth-child(4),
.dice-container.count-6 .face-4 .dot:nth-child(4) { bottom: 24px; right: 24px; }

.dice-container.count-2 .face-5 .dot:nth-child(1),
.dice-container.count-3 .face-5 .dot:nth-child(1),
.dice-container.count-4 .face-5 .dot:nth-child(1),
.dice-container.count-5 .face-5 .dot:nth-child(1),
.dice-container.count-6 .face-5 .dot:nth-child(1) { top: 24px; left: 24px; }

.dice-container.count-2 .face-5 .dot:nth-child(2),
.dice-container.count-3 .face-5 .dot:nth-child(2),
.dice-container.count-4 .face-5 .dot:nth-child(2),
.dice-container.count-5 .face-5 .dot:nth-child(2),
.dice-container.count-6 .face-5 .dot:nth-child(2) { top: 24px; right: 24px; }

.dice-container.count-2 .face-5 .dot:nth-child(3),
.dice-container.count-3 .face-5 .dot:nth-child(3),
.dice-container.count-4 .face-5 .dot:nth-child(3),
.dice-container.count-5 .face-5 .dot:nth-child(3),
.dice-container.count-6 .face-5 .dot:nth-child(3) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.dice-container.count-2 .face-5 .dot:nth-child(4),
.dice-container.count-3 .face-5 .dot:nth-child(4),
.dice-container.count-4 .face-5 .dot:nth-child(4),
.dice-container.count-5 .face-5 .dot:nth-child(4),
.dice-container.count-6 .face-5 .dot:nth-child(4) { bottom: 24px; left: 24px; }

.dice-container.count-2 .face-5 .dot:nth-child(5),
.dice-container.count-3 .face-5 .dot:nth-child(5),
.dice-container.count-4 .face-5 .dot:nth-child(5),
.dice-container.count-5 .face-5 .dot:nth-child(5),
.dice-container.count-6 .face-5 .dot:nth-child(5) { bottom: 24px; right: 24px; }

.dice-container.count-2 .face-6 .dot:nth-child(1),
.dice-container.count-3 .face-6 .dot:nth-child(1),
.dice-container.count-4 .face-6 .dot:nth-child(1),
.dice-container.count-5 .face-6 .dot:nth-child(1),
.dice-container.count-6 .face-6 .dot:nth-child(1) { top: 24px; left: 24px; }

.dice-container.count-2 .face-6 .dot:nth-child(2),
.dice-container.count-3 .face-6 .dot:nth-child(2),
.dice-container.count-4 .face-6 .dot:nth-child(2),
.dice-container.count-5 .face-6 .dot:nth-child(2),
.dice-container.count-6 .face-6 .dot:nth-child(2) { top: 24px; right: 24px; }

.dice-container.count-2 .face-6 .dot:nth-child(3),
.dice-container.count-3 .face-6 .dot:nth-child(3),
.dice-container.count-4 .face-6 .dot:nth-child(3),
.dice-container.count-5 .face-6 .dot:nth-child(3),
.dice-container.count-6 .face-6 .dot:nth-child(3) { top: 50%; left: 24px; transform: translateY(-50%); }

.dice-container.count-2 .face-6 .dot:nth-child(4),
.dice-container.count-3 .face-6 .dot:nth-child(4),
.dice-container.count-4 .face-6 .dot:nth-child(4),
.dice-container.count-5 .face-6 .dot:nth-child(4),
.dice-container.count-6 .face-6 .dot:nth-child(4) { top: 50%; right: 24px; transform: translateY(-50%); }

.dice-container.count-2 .face-6 .dot:nth-child(5),
.dice-container.count-3 .face-6 .dot:nth-child(5),
.dice-container.count-4 .face-6 .dot:nth-child(5),
.dice-container.count-5 .face-6 .dot:nth-child(5),
.dice-container.count-6 .face-6 .dot:nth-child(5) { bottom: 24px; left: 24px; }

.dice-container.count-2 .face-6 .dot:nth-child(6),
.dice-container.count-3 .face-6 .dot:nth-child(6),
.dice-container.count-4 .face-6 .dot:nth-child(6),
.dice-container.count-5 .face-6 .dot:nth-child(6),
.dice-container.count-6 .face-6 .dot:nth-child(6) { bottom: 24px; right: 24px; }

/* Container transitions */
.dice-container {
    transition: width 0.5s ease, height 0.5s ease;
}

.dice {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
    backface-visibility: hidden;
}

.dice.rolling {
    animation: rollAnimation 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes rollAnimation {
    0% {
        transform: translate3d(0, 0, -75px) scale(1);
    }
    25% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(180deg) rotateY(180deg);
    }
    50% {
        transform: translate3d(0, 0, 500px) scale(4.0) rotateX(360deg) rotateY(360deg);
    }
    75% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(540deg) rotateY(540deg);
    }
    100% {
        transform: translate3d(0, 0, -75px) scale(1);
    }
}

/* D4-specific animation with correct base position */
@keyframes rollAnimationD4 {
    0% {
        transform: translate3d(0, 0, -50px) scale(1);
    }
    25% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(180deg) rotateY(180deg);
    }
    50% {
        transform: translate3d(0, 0, 500px) scale(4.0) rotateX(360deg) rotateY(360deg);
    }
    75% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(540deg) rotateY(540deg);
    }
    100% {
        transform: translate3d(0, 0, -50px) scale(1);
    }
}

.d4-dice.rolling {
    animation: rollAnimationD4 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Two-dice animation with adjusted base position */
@keyframes rollAnimationTwoDice {
    0% {
        transform: translate3d(0, 0, -60px) scale(1);
    }
    25% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(180deg) rotateY(180deg);
    }
    50% {
        transform: translate3d(0, 0, 500px) scale(4.0) rotateX(360deg) rotateY(360deg);
    }
    75% {
        transform: translate3d(0, 0, 350px) scale(3.0) rotateX(540deg) rotateY(540deg);
    }
    100% {
        transform: translate3d(0, 0, -60px) scale(1);
    }
}

#d6-double .dice.rolling {
    animation: rollAnimationTwoDice 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* D6 Dice Styles - Enhanced 3D Realism */
.d6-dice .face {
    position: absolute;
    width: 150px;
    height: 150px;
    border: 2px solid #c62828;
    background: #faf8f4;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    box-shadow:
        0 8px 20px rgba(0,0,0,0.3),
        0 2px 6px rgba(0,0,0,0.2);
    overflow: hidden;
    will-change: transform;
    backface-visibility: hidden;
}

/* Simplify shadows during rolling for better performance */
.dice.rolling .face {
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.d6-dice .front  { transform: rotateY(0deg) translateZ(75px); }
.d6-dice .back   { transform: rotateX(180deg) translateZ(75px); }
.d6-dice .right  { transform: rotateY(90deg) translateZ(75px); }
.d6-dice .left   { transform: rotateY(-90deg) translateZ(75px); }
.d6-dice .top    { transform: rotateX(90deg) translateZ(75px); }
.d6-dice .bottom { transform: rotateX(-90deg) translateZ(75px); }

.dot {
    width: 20px;
    height: 20px;
    background: radial-gradient(circle at 35% 35%, #b33030, #8b1e1e 60%, #6b1010);
    border-radius: 50%;
    position: absolute;
    box-shadow:
        inset 0 2px 4px rgba(0,0,0,0.6),
        inset 0 -1px 2px rgba(255,255,255,0.2),
        inset 0 0 8px rgba(0,0,0,0.4),
        0 1px 2px rgba(0,0,0,0.3);
    will-change: transform;
}

/* Enhanced recessed dot effect with pseudo-element */
.dot::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    background: radial-gradient(circle at 40% 40%, rgba(200,80,80,0.3), transparent 60%);
    border-radius: 50%;
    pointer-events: none;
}

/* D6 Dot Positions */
.face-1 .dot:nth-child(1) { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.face-2 .dot:nth-child(1) { top: 30px; left: 30px; }
.face-2 .dot:nth-child(2) { bottom: 30px; right: 30px; }

.face-3 .dot:nth-child(1) { top: 30px; left: 30px; }
.face-3 .dot:nth-child(2) { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.face-3 .dot:nth-child(3) { bottom: 30px; right: 30px; }

.face-4 .dot:nth-child(1) { top: 30px; left: 30px; }
.face-4 .dot:nth-child(2) { top: 30px; right: 30px; }
.face-4 .dot:nth-child(3) { bottom: 30px; left: 30px; }
.face-4 .dot:nth-child(4) { bottom: 30px; right: 30px; }

.face-5 .dot:nth-child(1) { top: 30px; left: 30px; }
.face-5 .dot:nth-child(2) { top: 30px; right: 30px; }
.face-5 .dot:nth-child(3) { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.face-5 .dot:nth-child(4) { bottom: 30px; left: 30px; }
.face-5 .dot:nth-child(5) { bottom: 30px; right: 30px; }

.face-6 .dot:nth-child(1) { top: 30px; left: 30px; }
.face-6 .dot:nth-child(2) { top: 30px; right: 30px; }
.face-6 .dot:nth-child(3) { top: 50%; left: 30px; transform: translateY(-50%); }
.face-6 .dot:nth-child(4) { top: 50%; right: 30px; transform: translateY(-50%); }
.face-6 .dot:nth-child(5) { bottom: 30px; left: 30px; }
.face-6 .dot:nth-child(6) { bottom: 30px; right: 30px; }

/* D4 Dice Styles (Proper Tetrahedron) - Based on flipsimu.com implementation */
.d4-dice {
    transform-style: preserve-3d;
    transform: translateZ(-50px);
}

.d4-face {
    position: absolute;
    width: 0;
    height: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    transform-origin: center top;
    left: 50%;
    top: 50%;
    margin-left: -75px;
    margin-top: -65px;
    /* CSS border triangle: creates equilateral triangle - scaled 1.5x */
    border-left: 75px solid transparent;
    border-right: 75px solid transparent;
    border-bottom: 129.9px solid #faf8f4;
    /* Red edge lines to show separate pyramid faces */
    filter:
        drop-shadow(-2px -2px 0 #c62828)
        drop-shadow(2px -2px 0 #c62828)
        drop-shadow(0 2px 0 #c62828);
    will-change: transform;
    backface-visibility: hidden;
}

/* Simplify D4 filters during rolling for better performance */
.d4-dice.rolling .d4-face {
    filter: drop-shadow(0 0 1px #c62828);
}

.d4-face .number {
    position: absolute;
    top: 67px;
    font-size: 2.3em;
    font-weight: bold;
    color: #a82a2a;
    text-shadow:
        0 1px 0 rgba(255,255,255,0.3),
        0 -1px 2px rgba(0,0,0,0.8),
        1px 0 2px rgba(0,0,0,0.6),
        -1px 0 2px rgba(0,0,0,0.6),
        0 2px 4px rgba(0,0,0,0.5),
        inset 0 1px 1px rgba(0,0,0,0.4);
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4));
}

.d4-face-4 .number {
    transform: rotateZ(-180deg);
}

/* Position the 4 triangular faces using proper tetrahedron geometry */
/* Faces 1-3: Three sides at 120° intervals with 19.471221° tilt */
.d4-face-1 {
    border-bottom-color: #faf8f4;
    transform: rotateY(0deg) rotateX(19.471221deg);
}

.d4-face-2 {
    border-bottom-color: #faf8f4;
    transform: rotateY(120deg) rotateX(19.471221deg);
}

.d4-face-3 {
    border-bottom-color: #faf8f4;
    transform: rotateY(240deg) rotateX(19.471221deg);
}

/* Face 4 - Bottom face with complex transform - scaled 1.5x */
.d4-face-4 {
    border-bottom-color: #faf8f4;
    transform: rotateX(-90deg) rotateZ(180deg) translateY(-86.6px) translateZ(122.37px);
    /* Red edge lines for bottom face */
    filter:
        drop-shadow(-2px 2px 0 #c62828)
        drop-shadow(2px 2px 0 #c62828)
        drop-shadow(0 -2px 0 #c62828);
}

/* Override for bottom face during rolling */
.d4-dice.rolling .d4-face-4 {
    filter: drop-shadow(0 0 1px #c62828);
}

/* Button Styles */
button {
    padding: 20px 40px;
    font-size: 1.8em;
    font-weight: bold;
    background: linear-gradient(145deg, #4CAF50, #45a049);
    color: #fff;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 30px;
}

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

button:active {
    transform: translateY(0);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

button:disabled {
    background: linear-gradient(145deg, #cccccc, #999999);
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

/* Result Display */
.result-display {
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 15px;
    padding: 20px;
    position: fixed;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

#result {
    font-size: 1.5em;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* Cast shadow beneath dice - creates ground shadow effect */
.dice-container::before {
    content: '';
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 20px;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0.4), rgba(0,0,0,0.2) 40%, transparent 70%);
    border-radius: 50%;
    opacity: 0.8;
    transition: all 0.5s ease;
    z-index: -1;
    filter: blur(8px);
}

/* Disable shadow during rolling for better performance */
.dice-container.rolling::before {
    opacity: 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    h1 {
        font-size: 2em;
    }

    .dice-selector {
        gap: 6px;
        flex-wrap: nowrap;
        max-width: 98vw;
        padding: 0 5px;
        width: auto;
    }

    .dice-type-btn {
        padding: 9px 10px;
        font-size: 0.9em;
        min-width: auto;
        flex: 1 1 auto;
        white-space: nowrap;
    }

    .about-btn {
        padding: 9px 8px !important;
        font-size: 0.9em !important;
        flex: 0.9 1 auto !important;
    }

    /* Mobile: Vertical dice layout for 1-3 dice */
    .dice-display-flex {
        flex-direction: column;
        gap: 20px;
        flex-wrap: nowrap;
    }

    /* Mobile: Single column for 1-3 dice */
    .dice-container.count-1 {
        width: 150px;
        height: 150px;
    }

    .dice-container.count-2 {
        width: 150px;
        height: 290px; /* 120px * 2 + 20px gap + padding */
    }

    .dice-container.count-3 {
        width: 150px;
        height: 410px; /* 120px * 3 + 40px gaps + padding */
    }

    /* Mobile: 2-column grid layout for 4-6 dice */
    .dice-container.count-4,
    .dice-container.count-5,
    .dice-container.count-6 {
        width: 270px; /* 120px * 2 + 30px gap */
    }

    .dice-container.count-4 {
        height: 270px; /* 2x2 grid: 120px * 2 + 30px gap */
    }

    .dice-container.count-5 {
        height: 390px; /* 2 cols, 3 rows: 120px * 3 + 60px gaps */
    }

    .dice-container.count-6 {
        height: 390px; /* 2x3 grid: 120px * 3 + 60px gaps */
    }

    .dice-container.count-4 .dice-display-flex,
    .dice-container.count-5 .dice-display-flex,
    .dice-container.count-6 .dice-display-flex {
        display: grid;
        grid-template-columns: repeat(2, 120px);
        gap: 30px;
        justify-content: center;
        align-items: center;
    }

    /* Mobile: All dice use same size (120px) */
    .dice-container.count-1 .dice {
        width: 120px;
        height: 120px;
    }

    .dice-container.count-2 .dice,
    .dice-container.count-3 .dice,
    .dice-container.count-4 .dice,
    .dice-container.count-5 .dice,
    .dice-container.count-6 .dice {
        width: 120px;
        height: 120px;
    }

    /* Mobile: All faces use 120px */
    .dice-container.count-1 .face {
        width: 120px;
        height: 120px;
    }

    .dice-container.count-2 .face,
    .dice-container.count-3 .face,
    .dice-container.count-4 .face,
    .dice-container.count-5 .face,
    .dice-container.count-6 .face {
        width: 120px;
        height: 120px;
    }

    /* Mobile: All dice use -60px translateZ */
    .dice-container.count-1 .front  { transform: rotateY(0deg) translateZ(60px); }
    .dice-container.count-1 .back   { transform: rotateX(180deg) translateZ(60px); }
    .dice-container.count-1 .right  { transform: rotateY(90deg) translateZ(60px); }
    .dice-container.count-1 .left   { transform: rotateY(-90deg) translateZ(60px); }
    .dice-container.count-1 .top    { transform: rotateX(90deg) translateZ(60px); }
    .dice-container.count-1 .bottom { transform: rotateX(-90deg) translateZ(60px); }

    /* Dot positions for single dice on mobile (120px face when resized) */
    .dice-container.count-1 .face-2 .dot:nth-child(1) { top: 24px; left: 24px; }
    .dice-container.count-1 .face-2 .dot:nth-child(2) { bottom: 24px; right: 24px; }

    .dice-container.count-1 .face-3 .dot:nth-child(1) { top: 24px; left: 24px; }
    .dice-container.count-1 .face-3 .dot:nth-child(3) { bottom: 24px; right: 24px; }

    .dice-container.count-1 .face-4 .dot:nth-child(1) { top: 24px; left: 24px; }
    .dice-container.count-1 .face-4 .dot:nth-child(2) { top: 24px; right: 24px; }
    .dice-container.count-1 .face-4 .dot:nth-child(3) { bottom: 24px; left: 24px; }
    .dice-container.count-1 .face-4 .dot:nth-child(4) { bottom: 24px; right: 24px; }

    .dice-container.count-1 .face-5 .dot:nth-child(1) { top: 24px; left: 24px; }
    .dice-container.count-1 .face-5 .dot:nth-child(2) { top: 24px; right: 24px; }
    .dice-container.count-1 .face-5 .dot:nth-child(4) { bottom: 24px; left: 24px; }
    .dice-container.count-1 .face-5 .dot:nth-child(5) { bottom: 24px; right: 24px; }

    .dice-container.count-1 .face-6 .dot:nth-child(1) { top: 24px; left: 24px; }
    .dice-container.count-1 .face-6 .dot:nth-child(2) { top: 24px; right: 24px; }
    .dice-container.count-1 .face-6 .dot:nth-child(3) { top: 50%; left: 24px; transform: translateY(-50%); }
    .dice-container.count-1 .face-6 .dot:nth-child(4) { top: 50%; right: 24px; transform: translateY(-50%); }
    .dice-container.count-1 .face-6 .dot:nth-child(5) { bottom: 24px; left: 24px; }
    .dice-container.count-1 .face-6 .dot:nth-child(6) { bottom: 24px; right: 24px; }
}

/* About Button Styles */
.about-btn {
    background: rgba(255, 191, 0, 0.3) !important;
    border-color: rgba(255, 191, 0, 0.5) !important;
}

.about-btn:hover {
    background: rgba(255, 191, 0, 0.4) !important;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    padding: 40px;
    max-width: 800px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    z-index: 10001;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideIn 0.3s ease;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 2em;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* Modal Header */
.modal-header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

.modal-tagline {
    font-size: 1.2em;
    margin-bottom: 10px;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.modal-note {
    font-size: 0.95em;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 15px;
}

.enterprise-badge {
    display: inline-block;
    background: linear-gradient(145deg, #4CAF50, #45a049);
    color: white;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
    margin-top: 10px;
}

/* Modal Columns */
.modal-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 30px;
    margin-bottom: 30px;
}

.modal-column h3 {
    font-size: 1.1em;
    margin-bottom: 12px;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
    padding-bottom: 6px;
}

.modal-column ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.modal-column ul li {
    margin-bottom: 8px;
}

.modal-column ul li a {
    color: rgba(255, 255, 255, 0.95);
    text-decoration: none;
    transition: all 0.3s ease;
    display: inline-block;
    font-size: 0.95em;
}

.modal-column ul li a:hover {
    color: white;
    transform: translateX(5px);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Modal Bottom */
.modal-bottom {
    text-align: center;
    padding-top: 20px;
    border-top: 2px solid rgba(255, 255, 255, 0.3);
}

.copyright {
    font-size: 0.95em;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 10px;
}

.modal-message {
    font-size: 0.9em;
    color: rgba(255, 255, 255, 0.8);
    font-style: italic;
}

/* Modal Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Extra Small Mobile Screens */
@media (max-width: 480px) {
    .dice-selector {
        gap: 5px;
        top: 3px;
        max-width: 99vw;
        padding: 0 3px;
    }

    .dice-type-btn {
        padding: 8px 6px;
        font-size: 0.85em;
        min-width: auto;
        flex: 1 1 auto;
    }

    .about-btn {
        padding: 8px 5px !important;
        font-size: 0.85em !important;
        flex: 0.85 1 auto !important;
    }

    .dice-count-selector {
        top: 60px;
    }
}

/* Ultra Small Screens (iPhone SE, etc.) */
@media (max-width: 375px) {
    .dice-selector {
        gap: 4px;
        padding: 0 2px;
    }

    .dice-type-btn {
        padding: 7px 5px;
        font-size: 0.8em;
    }

    .about-btn {
        padding: 7px 4px !important;
        font-size: 0.8em !important;
    }

    .dice-count-selector {
        top: 55px;
    }
}

/* Modal Mobile Responsive */
@media (max-width: 768px) {
    .modal-content {
        padding: 25px;
        width: 95%;
        max-height: 90vh;
    }

    .modal-close {
        width: 40px;
        height: 40px;
        font-size: 1.8em;
        top: 10px;
        right: 10px;
    }

    .modal-header {
        margin-bottom: 20px;
        padding-bottom: 15px;
    }

    .modal-tagline {
        font-size: 1em;
    }

    .modal-note {
        font-size: 0.85em;
    }

    .enterprise-badge {
        font-size: 0.8em;
        padding: 6px 15px;
    }

    .modal-columns {
        grid-template-columns: 1fr;
        gap: 20px;
        margin-bottom: 20px;
    }

    .modal-column h3 {
        font-size: 1em;
        margin-bottom: 10px;
    }

    .modal-column ul li {
        margin-bottom: 7px;
    }

    .modal-column ul li a {
        font-size: 0.9em;
    }

    .copyright {
        font-size: 0.85em;
    }

    .modal-message {
        font-size: 0.8em;
    }
}
