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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 40px 0;
    color: white;
}

h1 {
    font-size: 3em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.95;
    margin-bottom: 20px;
}

.language-selector {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.lang-btn {
    padding: 8px 16px;
    border: 2px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.1);
    color: white;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
}

.lang-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

.lang-btn.active {
    background: white;
    color: #667eea;
    border-color: white;
}

main {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

section {
    margin-bottom: 40px;
}

h2 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: 1.8em;
}

.dice-selector {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 15px;
}

.dice-presets {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin-bottom: 25px;
    justify-content: center;
}

.preset-btn {
    padding: 15px 25px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    transition: all 0.3s;
    color: #333;
}

.preset-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.preset-btn.active {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-color: transparent;
}

.custom-dice, .dice-count {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
    justify-content: center;
}

.custom-dice label, .dice-count label {
    font-weight: 600;
    color: #555;
}

input[type="number"] {
    padding: 10px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    width: 100px;
    transition: border-color 0.3s;
}

input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
}

.count-btn {
    width: 40px;
    height: 40px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.count-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.roll-section {
    text-align: center;
    padding: 30px 0;
}

.roll-btn {
    padding: 20px 50px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
}

.roll-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 40px rgba(102, 126, 234, 0.5);
}

.roll-btn.rolling {
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px) rotate(-5deg); }
    75% { transform: translateX(10px) rotate(5deg); }
}

.roll-icon {
    font-size: 30px;
}

.modifier-section {
    margin-top: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.modifier-section label {
    font-weight: 600;
    color: #555;
}

.results-section {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 15px;
    animation: fadeIn 0.5s;
}

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

.dice-display {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 30px;
}

.die {
    width: 70px;
    height: 70px;
    background: white;
    border: 3px solid #667eea;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: bold;
    color: #667eea;
    animation: diceRoll 0.5s;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

@keyframes diceRoll {
    0% { transform: rotateX(0) rotateY(0); }
    50% { transform: rotateX(360deg) rotateY(360deg); }
    100% { transform: rotateX(0) rotateY(0); }
}

.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.stat-card h3 {
    color: #666;
    font-size: 14px;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 32px;
    font-weight: bold;
    color: #667eea;
}

.formula-display {
    text-align: center;
    font-size: 18px;
    color: #555;
    padding: 15px;
    background: white;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
}

.history-section {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 15px;
}

.clear-btn {
    padding: 8px 20px;
    background: #ff5252;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    float: right;
    margin-top: -35px;
}

.clear-btn:hover {
    background: #ff3333;
    transform: translateY(-2px);
}

.history-list {
    margin-top: 20px;
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 12px;
    background: white;
    border-radius: 8px;
    margin-bottom: 10px;
    display: flex;
    gap: 15px;
    align-items: center;
    font-size: 14px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.history-time {
    color: #999;
    font-size: 12px;
}

.history-dice {
    font-weight: bold;
    color: #667eea;
}

.history-results {
    color: #555;
}

.history-modifier {
    color: #ff9800;
    font-weight: bold;
}

.history-total {
    margin-left: auto;
    font-weight: bold;
    font-size: 16px;
    color: #333;
}

.stats-section {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 15px;
}

.overall-stats {
    display: flex;
    gap: 30px;
    margin-bottom: 25px;
    justify-content: center;
}

.stat-item {
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 16px;
}

.stat-item span:first-child {
    color: #666;
}

.stat-item span:last-child {
    font-weight: bold;
    color: #667eea;
    font-size: 20px;
}

#distributionChart {
    background: white;
    border-radius: 10px;
    padding: 15px;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: block;
}

footer {
    text-align: center;
    padding: 30px 0;
    color: rgba(255,255,255,0.9);
}

@media (max-width: 768px) {
    h1 {
        font-size: 2em;
    }
    
    .subtitle {
        font-size: 1em;
    }
    
    .dice-presets {
        gap: 10px;
    }
    
    .preset-btn {
        padding: 12px 18px;
        font-size: 16px;
    }
    
    .roll-btn {
        padding: 15px 35px;
        font-size: 20px;
    }
    
    .die {
        width: 60px;
        height: 60px;
        font-size: 24px;
    }
    
    .stats-container {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .history-item {
        font-size: 12px;
        flex-wrap: wrap;
    }
}