* {
    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;
    padding: 20px;
}

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

header {
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.9;
}

main {
    padding: 30px;
}

.visualization-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.crystal-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#threeCanvas {
    width: 100%;
    height: 500px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
}

.crystal-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    width: 100%;
    margin-top: 20px;
    padding: 20px;
    background: #f9fafb;
    border-radius: 8px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.info-item span:first-child {
    font-weight: 600;
    color: #374151;
    font-size: 0.9em;
}

.info-item span:last-child {
    color: #1e40af;
    font-weight: 700;
    font-size: 1.1em;
}

.calculations-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.calc-section {
    background: #f9fafb;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #3b82f6;
}

.calc-section h3 {
    color: #1e40af;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.miller-inputs {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.miller-input {
    flex: 1;
}

.miller-input label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #374151;
}

.miller-input input {
    width: 100%;
    padding: 8px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 1em;
    text-align: center;
}

.miller-input input:focus {
    outline: none;
    border-color: #3b82f6;
}

.calc-result {
    background: white;
    padding: 15px;
    border-radius: 6px;
    font-size: 1.1em;
    line-height: 1.6;
    color: #374151;
}

.formula-display {
    background: white;
    padding: 15px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 1.2em;
    text-align: center;
    margin-bottom: 15px;
    color: #1e40af;
    font-weight: 700;
}

.bragg-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-weight: 600;
    color: #374151;
    font-size: 0.9em;
}

.control-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
    outline: none;
    -webkit-appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-group select {
    padding: 10px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 1em;
    background: white;
    cursor: pointer;
}

.control-group select:focus {
    outline: none;
    border-color: #3b82f6;
}

.checkbox-group {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

#diffractionCanvas {
    width: 100%;
    height: 200px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    background: #1f2937;
}

.controls-panel {
    background: #f9fafb;
    padding: 30px;
    border-radius: 8px;
    margin-top: 30px;
}

.controls-panel h3 {
    color: #1e40af;
    margin-bottom: 20px;
    font-size: 1.5em;
}

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

.button-group {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.control-button {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-button.reset {
    background: #ef4444;
    color: white;
}

.control-button.reset:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(239, 68, 68, 0.3);
}

.control-button.animate {
    background: #10b981;
    color: white;
}

.control-button.animate:hover {
    background: #059669;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(16, 185, 129, 0.3);
}

.formulas-section {
    background: white;
    padding: 25px;
    border-radius: 8px;
    border-left: 4px solid #10b981;
}

.formulas-section h3 {
    color: #1e40af;
    margin-bottom: 20px;
    font-size: 1.3em;
}

.formula-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.formula-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.formula-label {
    font-weight: 600;
    color: #374151;
}

.formula {
    font-family: 'Courier New', monospace;
    background: #f9fafb;
    padding: 10px;
    border-radius: 6px;
    color: #1e40af;
}

.packing-info {
    background: #f0fdf4;
    padding: 15px;
    border-radius: 6px;
    border-left: 4px solid #10b981;
    line-height: 1.8;
}

.explanation {
    background: #fef3c7;
    padding: 30px;
    border-radius: 8px;
    margin-top: 30px;
}

.explanation h2 {
    color: #92400e;
    margin-bottom: 15px;
    font-size: 1.8em;
}

.explanation h3 {
    color: #92400e;
    margin-top: 25px;
    margin-bottom: 15px;
    font-size: 1.3em;
}

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

.explanation ul {
    list-style: none;
    padding-left: 0;
}

.explanation li {
    padding: 15px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    border-left: 4px solid #f59e0b;
    line-height: 1.6;
    color: #78350f;
}

.explanation strong {
    color: #92400e;
}

.condition-status {
    margin-top: 10px;
    font-weight: 700;
    font-size: 1.1em;
}

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

    .crystal-info {
        grid-template-columns: 1fr;
    }

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

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

    .subtitle {
        font-size: 0.9em;
    }

    main {
        padding: 15px;
    }

    .miller-inputs {
        flex-direction: column;
    }
}
