/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow-x: hidden;
}

/* Container setup for iframe compatibility */
.container {
    width: 100%;
    height: 100vh;
    max-height: 450px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* Responsive height adjustment */
@media (min-height: 500px) {
    .container {
        height: 90vh;
        max-height: none;
    }
}

/* Control Panel Styles */
.control-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px solid #e9ecef;
    align-items: center;
    justify-content: space-between;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 150px;
}

.control-group label {
    font-weight: 600;
    font-size: 0.9em;
    color: #495057;
    white-space: nowrap;
}

/* Slider Styles */
.slider {
    width: 100px;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    transition: all 0.3s ease;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.slider::-webkit-slider-thumb:hover {
    background: #5a6fd8;
    transform: scale(1.1);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Select Input */
.select-input {
    padding: 6px 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: white;
    font-size: 0.9em;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.select-input:focus {
    outline: none;
    border-color: #667eea;
}

/* Button Styles */
.button-group {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

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

/* Results Panel */
.results-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
}

/* Player Section */
.player-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.player-card {
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
    position: relative;
}

.player-card:hover {
    transform: translateY(-2px);
}

.alex-card {
    background: linear-gradient(135deg, #84fab0 0%, #8fd3f4 100%);
    border-left: 4px solid #28a745;
}

.ben-card {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    border-left: 4px solid #fd7e14;
}

.player-card h3 {
    font-size: 1.1em;
    margin-bottom: 10px;
    color: #333;
}

.stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: help;
}

.stat-label {
    font-size: 0.85em;
    color: #666;
    font-weight: 500;
}

.stat-value {
    font-size: 0.9em;
    font-weight: 700;
    color: #333;
    background: rgba(255, 255, 255, 0.7);
    padding: 2px 6px;
    border-radius: 4px;
}

.dice-display {
    font-size: 2em;
    text-align: center;
    animation: pulse 2s infinite;
}

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

/* Combined Histogram Container - Modified for reduced height */
.histogram-container {
    margin-top: 10px;
}

.combined-histogram-section {
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    /* Modified: Reduced overall height to minimize scrolling */
    max-height: 280px;
}

/* Histogram header with toggles */
.histogram-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.histogram-header h4 {
    font-size: 0.95em;
    color: #495057;
    margin: 0;
}

/* Toggle controls for histogram visibility */
.histogram-toggles {
    display: flex;
    gap: 15px;
    align-items: center;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.toggle-label:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.toggle-label input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

.toggle-text {
    color: #495057;
}

/* Color indicators for each player */
.color-indicator {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid #ccc;
}

.alex-color {
    background-color: rgba(40, 167, 69, 0.5); /* 50% transparent Alex color */
}

.ben-color {
    background-color: rgba(253, 126, 20, 0.5); /* 50% transparent Ben color */
}

/* Canvas styling - Modified for reduced height */
canvas {
    width: 100%;
    height: auto;
    max-height: 200px; /* Added: Limit maximum canvas height */
    border-radius: 4px;
    border: 1px solid #e9ecef;
}

/* Status Panel */
.status-panel {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-top: 3px solid #667eea;
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 4px;
}

#progressText {
    font-size: 0.85em;
    color: #666;
    font-weight: 500;
    white-space: nowrap;
}

.insight-panel {
    background: rgba(102, 126, 234, 0.1);
    padding: 10px;
    border-radius: 6px;
    border-left: 4px solid #667eea;
}

.insight-text {
    font-size: 0.85em;
    color: #495057;
    margin: 0;
    line-height: 1.4;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .container {
        padding: 8px;
        gap: 8px;
    }
    
    .control-panel {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 12px;
    }
    
    .control-group {
        justify-content: space-between;
        min-width: auto;
    }
    
    .button-group {
        justify-content: center;
    }
    
    .player-section {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .btn {
        padding: 12px 16px;
        font-size: 0.85em;
    }
    
    .slider {
        width: 80px;
    }
    
    /* Mobile histogram header */
    .histogram-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    
    .histogram-toggles {
        justify-content: center;
    }
    
    /* Modified: Further reduce histogram height on mobile */
    .combined-histogram-section {
        max-height: 240px;
    }
    
    canvas {
        max-height: 160px;
    }
}

/* Tooltip Enhancement */
[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.8em;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
}

/* Animation for running simulation */
.running .dice-display {
    animation: spin 0.5s linear infinite;
}

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