/* ===== 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);

    /* Solution Colors */
    --accent-color: #1abc9c;
    --water-color: rgba(52, 152, 219, 0.4);

    --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: #1abc9c;
}

.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(--accent-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 280px;
    gap: 15px;
    flex: 1;
}

/* ===== Controls Panel ===== */
.controls-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.controls-panel h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

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

/* Substance Grid */
.substance-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.substance-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.substance-btn:hover {
    border-color: var(--accent-color);
}

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

.substance-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

/* Slider Container */
.slider-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.slider-container input[type="range"] {
    width: 100%;
    height: 10px;
    border-radius: 5px;
    background: var(--bg-tertiary);
    -webkit-appearance: none;
}

.slider-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.slider-value {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.action-btn {
    padding: 10px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.action-btn:hover {
    border-color: var(--accent-color);
    transform: translateX(3px);
}

.action-btn.secondary {
    background: transparent;
    border: 2px solid var(--border-color);
}

/* Concentration Display */
.concentration-display {
    background: linear-gradient(135deg, rgba(26, 188, 156, 0.1), rgba(22, 160, 133, 0.1));
    border-radius: 12px;
    padding: 15px;
    margin-top: auto;
}

.concentration-value {
    text-align: center;
    margin: 10px 0;
}

.concentration-value span:first-child {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--accent-color);
}

.concentration-unit {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent-color);
}

.concentration-bar {
    height: 12px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    overflow: hidden;
    margin: 10px 0;
}

.concentration-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), #16a085);
    border-radius: 6px;
    transition: width 0.5s ease;
    width: 15%;
}

.concentration-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ===== Simulation Container ===== */
.simulation-container {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.simulation-header {
    text-align: center;
    padding: 10px 15px;
    background: linear-gradient(135deg, rgba(26, 188, 156, 0.1), rgba(22, 160, 133, 0.1));
    border-radius: 10px;
    border-left: 4px solid #1abc9c;
}

.simulation-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1abc9c;
    margin-bottom: 6px;
}

.simulation-header p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    max-width: 600px;
    margin: 0 auto;
}

.simulation-wrapper {
    flex: 1;
    position: relative;
    background: linear-gradient(180deg, #e8f4f8 0%, #d0e8f0 100%);
    border-radius: 12px;
    overflow: hidden;
    min-height: 450px;
    border: 3px solid var(--border-color);
}

[data-theme="dark"] .simulation-wrapper {
    background: linear-gradient(180deg, #1a2a35 0%, #152530 100%);
}

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

/* Beaker Scale */
.beaker-scale {
    position: absolute;
    right: 20px;
    top: 80px;
    bottom: 80px;
    width: 40px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-secondary);
}

/* Volume Indicator */
.volume-indicator {
    position: absolute;
    left: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: top 0.5s ease;
}

.volume-line {
    width: 20px;
    height: 2px;
    background: var(--accent-color);
}

.volume-label {
    font-size: 0.8rem;
    color: var(--accent-color);
    font-weight: 600;
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Values Bar */
.values-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

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

.value-item.highlight {
    background: linear-gradient(135deg, rgba(26, 188, 156, 0.2), rgba(22, 160, 133, 0.15));
    border: 2px solid var(--accent-color);
}

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

.value-number {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.value-item.highlight .value-number {
    color: var(--accent-color);
}

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

.info-panel h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.info-card {
    background: var(--bg-tertiary);
    border-radius: 10px;
    padding: 12px;
}

.info-card h3 {
    font-size: 0.85rem;
    margin-bottom: 6px;
}

.info-card p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.info-card.highlight {
    background: linear-gradient(135deg, rgba(26, 188, 156, 0.15), rgba(22, 160, 133, 0.1));
    border-left: 4px solid var(--accent-color);
}

.info-card.warning {
    background: linear-gradient(135deg, rgba(241, 196, 15, 0.15), rgba(243, 156, 18, 0.1));
    border-left: 4px solid #f1c40f;
}

.mini-formula {
    margin-top: 8px;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: 6px;
    text-align: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--accent-color);
}

.saturation-info {
    margin-top: 8px;
    padding: 6px;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* Formula Card */
.formula-card {
    background: var(--bg-tertiary);
    border-radius: 10px;
    padding: 12px;
}

.formula-card h3 {
    font-size: 0.85rem;
    margin-bottom: 10px;
}

.formula {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 10px;
}

.formula-text {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-color);
    flex-shrink: 0;
}

.fraction {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.9rem;
    line-height: 1.3;
    text-align: center;
}

.numerator {
    border-bottom: 2px solid var(--text-primary);
    padding: 0 6px 3px 6px;
    white-space: nowrap;
}

.denominator {
    padding: 3px 6px 0 6px;
    white-space: nowrap;
}

.formula-legend {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.formula-legend p {
    margin: 3px 0;
}

/* Legend Card */
.legend-card {
    background: var(--bg-tertiary);
    border-radius: 10px;
    padding: 12px;
}

.legend-card h3 {
    font-size: 0.85rem;
    margin-bottom: 8px;
}

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

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

.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.15);
}

.legend-dot.solute {
    background: var(--accent-color);
}

.legend-dot.water {
    background: #3498db;
}

.legend-dot.sediment {
    background: #7f8c8d;
}

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

    .values-bar {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

    .controls-panel {
        order: 1;
    }

    .simulation-container {
        order: 2;
        min-height: 400px;
    }

    .info-panel {
        order: 3;
    }

    .values-bar {
        grid-template-columns: repeat(2, 1fr);
    }
}