/* ===== CSS Variables & Reset ===== */
:root {
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8eef4;
    --text-primary: #1a1a2e;
    --text-secondary: #5a6270;
    --border-color: #d0d8e0;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);

    /* Particle Colors */
    --proton-color: #e63946;
    --neutron-color: #6c757d;
    --electron-color: #339af0;

    --radius: 12px;
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252540;
    --text-primary: #f0f4f8;
    --text-secondary: #a0a8b8;
    --border-color: #2a2a45;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: var(--transition);
}

/* ===== App Container ===== */
.app-container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 15px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    margin-bottom: 15px;
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #4f883d;
}

.header-controls {
    display: flex;
    gap: 10px;
}

.control-btn {
    width: 42px;
    height: 42px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.control-btn:hover {
    border-color: var(--electron-color);
    transform: scale(1.05);
}

.control-btn svg {
    width: 20px;
    height: 20px;
    color: var(--text-primary);
}

.moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon {
    display: block;
}

.compress-icon {
    display: none;
}

.fullscreen-active .expand-icon {
    display: none;
}

.fullscreen-active .compress-icon {
    display: block;
}

/* ===== Main Content ===== */
.main-content {
    display: grid;
    grid-template-columns: 260px 1fr 300px;
    gap: 15px;
    flex: 1;
}

/* ===== Controls Panel ===== */
.controls-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    overflow-y: auto;
}

.controls-panel h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Slider Groups */
.slider-group {
    margin-bottom: 20px;
}

.slider-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.slider-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.slider-value {
    font-size: 1rem;
    font-weight: 700;
    min-width: 40px;
    text-align: right;
}

.proton-color {
    color: var(--proton-color);
}

.neutron-color {
    color: var(--neutron-color);
}

.electron-color {
    color: var(--electron-color);
}

/* Range Sliders */
.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    outline: none;
    transition: var(--transition);
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.proton-slider::-webkit-slider-thumb {
    background: var(--proton-color);
    box-shadow: 0 0 10px rgba(230, 57, 70, 0.5);
}

.neutron-slider::-webkit-slider-thumb {
    background: var(--neutron-color);
    box-shadow: 0 0 10px rgba(108, 117, 125, 0.5);
}

.electron-slider::-webkit-slider-thumb {
    background: var(--electron-color);
    box-shadow: 0 0 10px rgba(51, 154, 240, 0.5);
}

/* Examples Section */
.examples-section {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 2px solid var(--border-color);
}

.examples-section h3,
.legend-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
}

.examples-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.example-btn {
    padding: 12px 8px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.example-btn:hover {
    border-color: var(--electron-color);
    background: var(--bg-primary);
    transform: scale(1.05);
}

/* Legend */
.legend-section {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 2px solid var(--border-color);
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-particle {
    width: 16px;
    height: 16px;
    border-radius: 50%;
}

.legend-particle.proton {
    background: linear-gradient(135deg, #ff6b6b, var(--proton-color));
    box-shadow: 0 0 8px rgba(230, 57, 70, 0.5);
}

.legend-particle.neutron {
    background: linear-gradient(135deg, #adb5bd, var(--neutron-color));
    box-shadow: 0 0 8px rgba(108, 117, 125, 0.5);
}

.legend-particle.electron {
    background: linear-gradient(135deg, #74c0fc, var(--electron-color));
    box-shadow: 0 0 8px rgba(51, 154, 240, 0.5);
}

/* ===== Visualization Container ===== */
.visualization-container {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 500px;
    overflow: hidden;
    touch-action: none;
}

.zoom-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 5;
    display: flex;
    gap: 8px;
}

.zoom-btn {
    width: 38px;
    height: 38px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.85);
    color: var(--text-primary);
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    backdrop-filter: blur(3px);
}

[data-theme="dark"] .zoom-btn {
    background: rgba(26, 26, 46, 0.85);
}

.zoom-btn:hover {
    border-color: var(--electron-color);
    transform: translateY(-1px);
}

.zoom-btn:active {
    transform: translateY(0);
}

#atomCanvas {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.shell-labels {
    position: absolute;
    pointer-events: none;
}

/* ===== Info Panel ===== */
.info-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    overflow-y: auto;
}

.info-panel h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Element Display */
.element-display {
    text-align: center;
    padding: 25px;
    background: var(--bg-tertiary);
    border-radius: 16px;
    margin-bottom: 20px;
}

.element-symbol {
    font-size: 4rem;
    font-weight: 800;
    line-height: 1.2;
    padding-bottom: 5px;
    background: linear-gradient(135deg, var(--proton-color), var(--electron-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.element-name {
    font-size: 1.3rem;
    font-weight: 600;
    margin-top: 10px;
}

.element-name-en {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

/* Atom State */
.atom-state {
    text-align: center;
    margin-bottom: 20px;
}

.state-badge {
    display: inline-block;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.state-badge.neutral {
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.2), rgba(39, 174, 96, 0.2));
    color: #27ae60;
    border: 2px solid #27ae60;
}

.state-badge.cation {
    background: linear-gradient(135deg, rgba(230, 57, 70, 0.2), rgba(192, 57, 43, 0.2));
    color: var(--proton-color);
    border: 2px solid var(--proton-color);
}

.state-badge.anion {
    background: linear-gradient(135deg, rgba(51, 154, 240, 0.2), rgba(41, 128, 185, 0.2));
    color: var(--electron-color);
    border: 2px solid var(--electron-color);
}

/* Info Grid */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.info-item {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: 10px;
    text-align: center;
}

.info-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
    text-transform: uppercase;
}

.info-value {
    font-size: 1.2rem;
    font-weight: 700;
}

/* Electron Configuration */
.electron-config {
    margin-bottom: 20px;
}

.electron-config h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
}

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

.shell-badge {
    background: linear-gradient(135deg, var(--electron-color), #1c7ed6);
    color: white;
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Isotope Warning */
.isotope-info {
    margin-bottom: 20px;
}

.isotope-warning {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    background: linear-gradient(135deg, rgba(241, 196, 15, 0.15), rgba(243, 156, 18, 0.15));
    border: 2px solid #f39c12;
    border-radius: 10px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.warning-icon {
    font-size: 1.2rem;
}

/* Explanation Box */
.explanation-box {
    background: linear-gradient(135deg, rgba(51, 154, 240, 0.1), rgba(41, 128, 185, 0.1));
    border-left: 4px solid var(--electron-color);
    padding: 15px;
    border-radius: 10px;
}

.explanation-box h3 {
    font-size: 0.85rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.explanation-box p {
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 220px 1fr 260px;
    }
}

@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto 400px auto;
    }

    .controls-panel {
        order: 1;
    }

    .visualization-container {
        order: 2;
    }

    .info-panel {
        order: 3;
    }

    .examples-grid {
        grid-template-columns: repeat(8, 1fr);
    }
}
