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

:root {
    --primary-color: #1a1a2e;
    --accent-color: #4361ee;
    --light-accent: #4895ef;
    --dark-accent: #3f37c9;
    --success-color: #4cc9f0;
    --warning-color: #f72585;
    --danger-color: #7209b7;
    --light-bg: #f8f9fa;
    --medium-bg: #e9ecef;
    --dark-bg: #1a1a2e;
    --text-color: #212529;
    --light-text: #f8f9fa;
    --border-radius: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.light-scattering-container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, #4361ee 0%, #3f37c9 100%);
    color: white;
    padding: 40px 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    font-weight: 300;
    letter-spacing: 1px;
}

header .subtitle {
    font-size: 1.1em;
    opacity: 0.9;
    max-width: 800px;
    margin: 0 auto;
}

/* Main Content */
main {
    padding: 30px;
}

/* Mode Selector */
.mode-selector {
    background: var(--light-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
}

.mode-selector h3 {
    margin-bottom: 15px;
    color: var(--primary-color);
}

.mode-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.mode-btn {
    padding: 12px 24px;
    border: 2px solid var(--accent-color);
    background: white;
    color: var(--accent-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1em;
    flex: 1;
    min-width: 140px;
    font-weight: 500;
}

.mode-btn:hover {
    background: var(--accent-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(67, 97, 238, 0.3);
}

.mode-btn.active {
    background: var(--accent-color);
    color: white;
}

/* Canvas Wrapper */
.canvas-wrapper {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    margin-bottom: 30px;
}

@media (max-width: 1024px) {
    .canvas-wrapper {
        grid-template-columns: 1fr;
    }
}

.canvas-container {
    background: linear-gradient(180deg, #0a0a1a 0%, #1a1a2e 100%);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

#scatteringCanvas {
    width: 100%;
    height: 500px;
    border-radius: 8px;
}

/* Stats Panel */
.stats-panel {
    background: var(--light-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.stats-panel h4 {
    margin-bottom: 15px;
    color: var(--primary-color);
    font-size: 1.1em;
}

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

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.stat-label {
    font-size: 0.9em;
    color: #666;
}

.stat-value {
    font-weight: 600;
    color: var(--accent-color);
    font-size: 1.1em;
}

.stat-unit {
    font-size: 0.85em;
    color: #999;
    margin-left: 4px;
}

.color-preview {
    padding: 4px 12px;
    border-radius: 20px;
    color: white;
    font-size: 0.9em;
}

/* Formula Display */
.formula-display {
    background: white;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.formula-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.formula-text {
    font-size: 1.1em;
    font-weight: 500;
}

.formula-fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 5px;
}

.numerator {
    border-bottom: 2px solid #333;
    padding: 2px 8px;
    text-align: center;
    font-weight: 600;
}

.denominator {
    padding: 2px 8px;
    text-align: center;
    font-weight: 600;
}

.formula-calculation {
    font-size: 0.9em;
    color: #666;
    font-style: italic;
}

/* Controls Panel */
.controls-panel {
    background: var(--light-bg);
    padding: 25px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
}

.controls-panel h3 {
    margin-bottom: 20px;
    color: var(--primary-color);
}

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

.control-group {
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.control-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-weight: 500;
    color: var(--primary-color);
}

.control-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(90deg, #e0e0e0 0%, var(--accent-color) 100%);
    outline: none;
    -webkit-appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(67, 97, 238, 0.4);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(67, 97, 238, 0.4);
}

.range-info {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.8em;
    color: #666;
}

.info-label {
    font-weight: 500;
}

.info-text {
    font-style: italic;
}

/* Spectrum Bar */
.spectrum-bar {
    position: relative;
    height: 20px;
    margin-top: 10px;
    border-radius: 10px;
    overflow: hidden;
}

.spectrum-gradient {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
        #8b00ff 0%,
        #4b0082 10%,
        #0000ff 25%,
        #00ff00 50%,
        #ffff00 65%,
        #ffa500 80%,
        #ff0000 100%
    );
    border-radius: 10px;
}

.wavelength-marker {
    position: absolute;
    top: 0;
    width: 4px;
    height: 100%;
    background: white;
    border: 2px solid #333;
    border-radius: 2px;
    transform: translateX(-50%);
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

.wavelength-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 0.75em;
    color: #666;
}

/* Buttons */
.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.control-button {
    padding: 12px 20px;
    border: 2px solid var(--accent-color);
    background: white;
    color: var(--accent-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.95em;
    font-weight: 500;
}

.control-button:hover {
    background: var(--accent-color);
    color: white;
    transform: translateY(-2px);
}

.control-button.active {
    background: var(--accent-color);
    color: white;
}

.control-button.reset {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.control-button.reset:hover {
    background: var(--danger-color);
    color: white;
}

/* Presets Panel */
.presets-panel {
    background: white;
    padding: 15px;
    border-radius: 10px;
}

.presets-panel h4 {
    margin-bottom: 12px;
    color: var(--primary-color);
}

.preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.preset-btn {
    padding: 8px 16px;
    border: 1px solid var(--light-accent);
    background: var(--light-bg);
    color: var(--dark-accent);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9em;
}

.preset-btn:hover {
    background: var(--light-accent);
    color: white;
    border-color: var(--light-accent);
}

/* Wavelength Panel */
.wavelength-panel {
    background: var(--light-bg);
    padding: 25px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
}

.wavelength-panel h3 {
    margin-bottom: 20px;
    color: var(--primary-color);
}

.wavelength-comparison {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.wavelength-option {
    background: white;
    padding: 15px;
    border-radius: 10px;
    text-align: center;
}

.color-box {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    margin: 0 auto 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.violet-box {
    background: linear-gradient(135deg, #8b00ff, #9400d3);
}

.blue-box {
    background: linear-gradient(135deg, #4169e1, #1e90ff);
}

.green-box {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
}

.red-box {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

.wavelength-option h4 {
    font-size: 1em;
    margin-bottom: 5px;
    color: var(--primary-color);
}

.wavelength-info {
    font-size: 0.85em;
    color: #666;
    margin-bottom: 10px;
}

.scattering-bar {
    height: 12px;
    background: #e0e0e0;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 8px;
}

.scattering-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.5s ease;
}

.violet-fill {
    width: 100%;
    background: linear-gradient(90deg, #8b00ff, #9400d3);
}

.blue-fill {
    width: 63%;
    background: linear-gradient(90deg, #4169e1, #1e90ff);
}

.green-fill {
    width: 19%;
    background: linear-gradient(90deg, #2ecc71, #27ae60);
}

.red-fill {
    width: 11%;
    background: linear-gradient(90deg, #e74c3c, #c0392b);
}

.intensity-value {
    font-weight: 600;
    color: var(--accent-color);
}

.spectrum-explanation {
    background: white;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    color: #555;
    font-style: italic;
}

/* Applications Panel */
.applications-panel {
    background: var(--light-bg);
    padding: 25px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
}

.applications-panel h3 {
    margin-bottom: 20px;
    color: var(--primary-color);
}

.applications-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.application-card {
    background: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.application-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.application-icon {
    font-size: 3em;
    margin-bottom: 10px;
}

.application-card h4 {
    margin-bottom: 10px;
    color: var(--primary-color);
}

.application-card p {
    font-size: 0.9em;
    color: #666;
    line-height: 1.5;
}

/* Explanation Section */
.explanation {
    background: var(--light-bg);
    padding: 30px;
    border-radius: var(--border-radius);
}

.explanation h2 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.8em;
}

.explanation h3 {
    color: var(--dark-accent);
    margin-top: 25px;
    margin-bottom: 12px;
    font-size: 1.3em;
}

.explanation p {
    color: #444;
    line-height: 1.8;
    margin-bottom: 15px;
}

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

    header .subtitle {
        font-size: 0.95em;
    }

    .mode-btn {
        min-width: 120px;
        font-size: 0.9em;
    }

    .controls-grid {
        grid-template-columns: 1fr;
    }

    .applications-grid {
        grid-template-columns: 1fr;
    }

    .wavelength-comparison {
        grid-template-columns: 1fr;
    }
}
