/* ===== DICE SYSTEM STYLES ===== */

/* ===== DICE DISPLAY CONTAINER ===== */
.dice-container {
    background: var(--surface-secondary);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing-lg);
    margin: var(--spacing-lg) 0;
    border: 1px solid var(--accent-primary);
    box-shadow: var(--shadow-medium);
}

.dice-display {
    min-height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.dice-waiting {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}

.dice-request {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-lg);
    background: var(--surface-primary);
    border-radius: var(--border-radius-md);
    border: 2px solid var(--accent-primary);
}

/* Turn-based restriction styles */
.dice-request.dice-already-rolled {
    border-color: #FF9800;
    background: rgba(255, 152, 0, 0.02);
    opacity: 0.8;
}

.dice-request.dice-already-rolled .dice-icon.large {
    opacity: 0.5;
    filter: grayscale(50%) drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
    animation: none;
}

.turn-restriction-message {
    max-width: 400px;
    text-align: left;
}

.turn-complete-notice {
    font-size: 0.9rem;
    text-align: center;
}

.dice-visual {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
}

.dice-icon.large {
    font-size: 4rem;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    animation: pulse 2s infinite;
}

.dice-label {
    font-weight: bold;
    color: var(--text-primary);
    font-size: 1.2rem;
}

.roll-btn {
    padding: var(--spacing-md) var(--spacing-lg);
    font-size: 1.1rem;
    font-weight: bold;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-small);
}

.roll-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.roll-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.dice-result {
    text-align: center;
    padding: var(--spacing-md);
    background: var(--surface-secondary);
    border-radius: var(--border-radius-md);
    margin-top: var(--spacing-md);
}

.rolling-animation {
    font-size: 2rem;
    animation: spin 1s linear infinite;
}

.result-number {
    font-size: 3rem;
    font-weight: bold;
    margin-bottom: var(--spacing-sm);
}

.result-number.critical-success {
    color: var(--success-color);
    text-shadow: 0 0 10px var(--success-color);
}

.result-number.critical-failure {
    color: var(--error-color);
    text-shadow: 0 0 10px var(--error-color);
}

.result-text {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== ANIMATIONS ===== */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Enhanced dice request styling */
.dice-request {
    animation: slideInUp 0.5s ease-out;
}

.dice-prompt {
    animation: pulse 2s infinite;
}

.dice-3d.d20 {
    width: 70px;
    height: 70px;
}

.dice-3d.d100 {
    width: 50px;
    height: 50px;
}

/* ===== DICE FACES ===== */
.dice-face {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    color: var(--primary-dark);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
    backface-visibility: hidden;
}

/* D6 Cube Faces */
.dice-3d.d6 .dice-face.front {
    transform: rotateY(0deg) translateZ(30px);
}

.dice-3d.d6 .dice-face.back {
    transform: rotateY(180deg) translateZ(30px);
}

.dice-3d.d6 .dice-face.right {
    transform: rotateY(90deg) translateZ(30px);
}

.dice-3d.d6 .dice-face.left {
    transform: rotateY(-90deg) translateZ(30px);
}

.dice-3d.d6 .dice-face.top {
    transform: rotateX(90deg) translateZ(30px);
}

.dice-3d.d6 .dice-face.bottom {
    transform: rotateX(-90deg) translateZ(30px);
}

/* D4 Tetrahedron */
.dice-3d.d4 .dice-face {
    width: 0;
    height: 0;
    border-radius: 0;
    border-left: 25px solid transparent;
    border-right: 25px solid transparent;
    border-bottom: 43px solid #f8f9fa;
    background: none;
    border-top: 2px solid var(--primary-color);
}

.dice-3d.d4 .dice-face.face1 {
    transform: rotateX(0deg) translateZ(14px);
}

.dice-3d.d4 .dice-face.face2 {
    transform: rotateX(120deg) translateZ(14px);
}

.dice-3d.d4 .dice-face.face3 {
    transform: rotateX(240deg) translateZ(14px);
}

.dice-3d.d4 .dice-face.face4 {
    transform: rotateY(180deg) rotateX(70deg) translateZ(14px);
}

/* D8 Octahedron */
.dice-3d.d8 .dice-face {
    width: 0;
    height: 0;
    border-left: 27px solid transparent;
    border-right: 27px solid transparent;
    border-bottom: 27px solid #f8f9fa;
    background: none;
    border-radius: 0;
}

/* D10 Pentagonal Trapezohedron */
.dice-3d.d10 .dice-face {
    width: 40px;
    height: 50px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
    border-radius: 0;
}

/* D12 Dodecahedron */
.dice-3d.d12 .dice-face {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    clip-path: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%);
    border-radius: 0;
}

/* D20 Icosahedron */
.dice-3d.d20 .dice-face {
    width: 0;
    height: 0;
    border-left: 35px solid transparent;
    border-right: 35px solid transparent;
    border-bottom: 30px solid #f8f9fa;
    background: none;
    border-radius: 0;
}

/* D100 (Percentile) */
.dice-3d.d100 .dice-face {
    width: 100%;
    height: 100%;
    font-size: 0.8rem;
    border-radius: 50%;
}

/* ===== DICE DOTS (for traditional D6) ===== */
.dice-dots {
    display: grid;
    width: 100%;
    height: 100%;
    padding: 6px;
    gap: 2px;
}

.dice-dots.dots-1 {
    grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr;
}

.dice-dots.dots-2 {
    grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr;
}

.dice-dots.dots-3 {
    grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr;
}

.dice-dots.dots-4 {
    grid-template: 1fr 1fr / 1fr 1fr;
}

.dice-dots.dots-5 {
    grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr;
}

.dice-dots.dots-6 {
    grid-template: 1fr 1fr 1fr / 1fr 1fr;
}

.dice-dot {
    background: var(--primary-dark);
    border-radius: 50%;
    width: 8px;
    height: 8px;
    margin: auto;
}

/* Dot positioning for each face */
.dice-dots.dots-1 .dice-dot:nth-child(1) {
    grid-area: 2 / 2;
}

.dice-dots.dots-2 .dice-dot:nth-child(1) {
    grid-area: 1 / 1;
}
.dice-dots.dots-2 .dice-dot:nth-child(2) {
    grid-area: 3 / 3;
}

.dice-dots.dots-3 .dice-dot:nth-child(1) {
    grid-area: 1 / 1;
}
.dice-dots.dots-3 .dice-dot:nth-child(2) {
    grid-area: 2 / 2;
}
.dice-dots.dots-3 .dice-dot:nth-child(3) {
    grid-area: 3 / 3;
}

.dice-dots.dots-4 .dice-dot:nth-child(1) {
    grid-area: 1 / 1;
}
.dice-dots.dots-4 .dice-dot:nth-child(2) {
    grid-area: 1 / 2;
}
.dice-dots.dots-4 .dice-dot:nth-child(3) {
    grid-area: 2 / 1;
}
.dice-dots.dots-4 .dice-dot:nth-child(4) {
    grid-area: 2 / 2;
}

.dice-dots.dots-5 .dice-dot:nth-child(1) {
    grid-area: 1 / 1;
}
.dice-dots.dots-5 .dice-dot:nth-child(2) {
    grid-area: 1 / 3;
}
.dice-dots.dots-5 .dice-dot:nth-child(3) {
    grid-area: 2 / 2;
}
.dice-dots.dots-5 .dice-dot:nth-child(4) {
    grid-area: 3 / 1;
}
.dice-dots.dots-5 .dice-dot:nth-child(5) {
    grid-area: 3 / 3;
}

.dice-dots.dots-6 .dice-dot:nth-child(1) {
    grid-area: 1 / 1;
}
.dice-dots.dots-6 .dice-dot:nth-child(2) {
    grid-area: 1 / 2;
}
.dice-dots.dots-6 .dice-dot:nth-child(3) {
    grid-area: 2 / 1;
}
.dice-dots.dots-6 .dice-dot:nth-child(4) {
    grid-area: 2 / 2;
}
.dice-dots.dots-6 .dice-dot:nth-child(5) {
    grid-area: 3 / 1;
}
.dice-dots.dots-6 .dice-dot:nth-child(6) {
    grid-area: 3 / 2;
}

/* ===== DICE ROLL ANIMATIONS ===== */
@keyframes rollDice {
    0% {
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
    25% {
        transform: rotateX(180deg) rotateY(90deg) rotateZ(45deg) scale(1.1);
    }
    50% {
        transform: rotateX(360deg) rotateY(180deg) rotateZ(90deg) scale(1.2);
    }
    75% {
        transform: rotateX(540deg) rotateY(270deg) rotateZ(135deg) scale(1.1);
    }
    100% {
        transform: rotateX(720deg) rotateY(360deg) rotateZ(180deg) scale(1);
    }
}

@keyframes rollD4 {
    0% {
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
    25% {
        transform: rotateX(120deg) rotateY(90deg) rotateZ(45deg) scale(1.1);
    }
    50% {
        transform: rotateX(240deg) rotateY(180deg) rotateZ(90deg) scale(1.2);
    }
    75% {
        transform: rotateX(360deg) rotateY(270deg) rotateZ(135deg) scale(1.1);
    }
    100% {
        transform: rotateX(480deg) rotateY(360deg) rotateZ(180deg) scale(1);
    }
}

@keyframes rollD20 {
    0% {
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }
    20% {
        transform: rotateX(144deg) rotateY(72deg) rotateZ(36deg) scale(1.05);
    }
    40% {
        transform: rotateX(288deg) rotateY(144deg) rotateZ(72deg) scale(1.1);
    }
    60% {
        transform: rotateX(432deg) rotateY(216deg) rotateZ(108deg) scale(1.15);
    }
    80% {
        transform: rotateX(576deg) rotateY(288deg) rotateZ(144deg) scale(1.1);
    }
    100% {
        transform: rotateX(720deg) rotateY(360deg) rotateZ(180deg) scale(1);
    }
}

/* Apply specific animations to dice types */
.dice-3d.d4.rolling {
    animation: rollD4 1.5s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.dice-3d.d20.rolling {
    animation: rollD20 2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* ===== DICE RESULT DISPLAY ===== */
.dice-result {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--secondary-color);
    color: var(--background-dark);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius);
    font-weight: bold;
    font-size: var(--font-size-lg);
    box-shadow: var(--box-shadow);
    opacity: 0;
    animation: showResult 0.5s ease forwards;
    z-index: 10;
}

.dice-result::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--secondary-color);
}

.dice-result.critical-success {
    background: var(--success-color);
    animation: criticalSuccess 0.8s ease forwards;
}

.dice-result.critical-failure {
    background: var(--error-color);
    animation: criticalFailure 0.8s ease forwards;
}

@keyframes showResult {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(10px) scale(0.8);
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

@keyframes criticalSuccess {
    0%, 100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
    25%, 75% {
        transform: translateX(-50%) translateY(-5px) scale(1.1);
    }
    50% {
        transform: translateX(-50%) translateY(-10px) scale(1.2);
    }
}

@keyframes criticalFailure {
    0%, 100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1) rotate(0deg);
    }
    25% {
        transform: translateX(-50%) translateY(0) scale(1.1) rotate(-2deg);
    }
    50% {
        transform: translateX(-50%) translateY(0) scale(1.2) rotate(2deg);
    }
    75% {
        transform: translateX(-50%) translateY(0) scale(1.1) rotate(-1deg);
    }
}

/* ===== DICE SELECTION BUTTONS ===== */
.dice-selection {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: var(--spacing-lg);
}

.dice-type-btn {
    background: var(--background-light);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-weight: bold;
    font-size: var(--font-size-base);
    min-width: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
}

.dice-type-btn:hover {
    border-color: var(--secondary-color);
    background: var(--background-medium);
    transform: translateY(-2px);
    box-shadow: var(--box-shadow);
}

.dice-type-btn.selected {
    background: var(--secondary-dark);
    border-color: var(--secondary-color);
    color: var(--background-dark);
    box-shadow: var(--box-shadow);
}

.dice-type-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.dice-icon {
    font-size: var(--font-size-xl);
    margin-bottom: var(--spacing-xs);
}

.dice-label {
    font-size: var(--font-size-sm);
    font-weight: bold;
}

/* ===== DICE TRAY (Multiple Dice) ===== */
.dice-tray {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-md);
    min-height: 120px;
    perspective: 1200px;
    flex-wrap: wrap;
}

.dice-tray .dice-3d {
    animation-delay: calc(var(--index) * 0.1s);
}

/* ===== ROLL HISTORY ===== */
.roll-history {
    background: var(--background-light);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    margin-top: var(--spacing-lg);
    max-height: 200px;
    overflow-y: auto;
}

.roll-history h4 {
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
    font-size: var(--font-size-lg);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: var(--spacing-sm);
}

.roll-history-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.roll-history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm);
    background: var(--background-medium);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
}

.roll-description {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.roll-result-value {
    font-weight: bold;
    color: var(--text-primary);
    background: var(--primary-dark);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--border-radius-sm);
}

.roll-result-value.critical {
    background: var(--success-color);
    color: white;
}

.roll-result-value.fumble {
    background: var(--error-color);
    color: white;
}

/* ===== MODIFIER INPUT ===== */
.modifier-input-section {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin: var(--spacing-lg) 0;
    justify-content: center;
}

.modifier-input {
    background: var(--background-light);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    font-weight: bold;
    text-align: center;
    width: 80px;
}

.modifier-input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 2px rgba(218, 165, 32, 0.2);
}

.modifier-label {
    color: var(--text-secondary);
    font-weight: bold;
}

/* ===== ADVANTAGE/DISADVANTAGE ===== */
.advantage-controls {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: center;
    margin: var(--spacing-md) 0;
}

.advantage-btn {
    background: var(--background-light);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--font-size-sm);
    font-weight: bold;
}

.advantage-btn:hover {
    background: var(--background-medium);
}

.advantage-btn.active {
    background: var(--info-color);
    border-color: var(--info-color);
    color: white;
}

.advantage-btn.advantage.active {
    background: var(--success-color);
    border-color: var(--success-color);
}

.advantage-btn.disadvantage.active {
    background: var(--error-color);
    border-color: var(--error-color);
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    .dice-3d-container {
        min-height: 100px;
    }
    
    .dice-3d {
        width: 50px;
        height: 50px;
        margin: 0 var(--spacing-xs);
    }
    
    .dice-3d.d20 {
        width: 60px;
        height: 60px;
    }
    
    .dice-selection {
        gap: var(--spacing-xs);
    }
    
    .dice-type-btn {
        min-width: 50px;
        padding: var(--spacing-sm);
        font-size: var(--font-size-sm);
    }
    
    .dice-tray {
        gap: var(--spacing-sm);
        min-height: 100px;
    }
    
    .modifier-input-section {
        flex-direction: column;
        gap: var(--spacing-sm);
    }
    
    .advantage-controls {
        flex-direction: column;
        align-items: center;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    .dice-3d.rolling {
        animation: none;
        transform: rotateX(360deg) rotateY(360deg);
    }
    
    .dice-result {
        animation: none;
        opacity: 1;
    }
}

/* ===== THINKING STATE ANIMATIONS ===== */
@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}
