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

    /* pH Colors */
    --ph-acid: #e74c3c;
    --ph-neutral: #2ecc71;
    --ph-base: #9b59b6;

    --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);
    flex-wrap: wrap;
    gap: 10px;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #e74c3c, #2ecc71, #9b59b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.action-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 25px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.action-btn:hover {
    background: var(--border-color);
    transform: scale(1.02);
}

.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(--ph-neutral);
    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: 280px 1fr 300px;
    gap: 15px;
    flex: 1;
}

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

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

/* Category Buttons */
.substance-categories {
    display: flex;
    gap: 5px;
}

.category-btn {
    flex: 1;
    padding: 8px 5px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-tertiary);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.category-btn:hover {
    border-color: var(--ph-neutral);
}

.category-btn.active[data-category="acids"] {
    background: var(--ph-acid);
    border-color: var(--ph-acid);
    color: white;
}

.category-btn.active[data-category="bases"] {
    background: var(--ph-base);
    border-color: var(--ph-base);
    color: white;
}

.category-btn.active[data-category="neutral"] {
    background: var(--ph-neutral);
    border-color: var(--ph-neutral);
    color: white;
}

/* Substances List */
.substances-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 300px;
    overflow-y: auto;
}

.substance-option {
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.substance-option:hover {
    border-color: var(--ph-neutral);
}

.substance-option.selected {
    border-color: var(--ph-neutral);
    background: rgba(46, 204, 113, 0.15);
}

.substance-ph {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
    background: var(--bg-secondary);
}

/* Add Controls */
.add-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 15px;
    background: var(--bg-tertiary);
    border-radius: 10px;
}

.control-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 5px;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-row input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-secondary);
    -webkit-appearance: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ph-neutral);
    cursor: pointer;
}

.slider-row span {
    min-width: 60px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: right;
}

.add-btn {
    padding: 12px;
    background: linear-gradient(135deg, var(--ph-neutral), #27ae60);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.add-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(46, 204, 113, 0.4);
}

/* History */
.history-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.history-list {
    font-size: 0.8rem;
    color: var(--text-secondary);
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    margin-bottom: 4px;
}

.empty-msg {
    font-style: italic;
    opacity: 0.6;
}

/* ===== Lab Container ===== */
.lab-container {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;
}

/* pH Scale */
.ph-scale-container {
    width: 100%;
    max-width: 600px;
}

.ph-scale {
    height: 50px;
    border-radius: 25px;
    background: linear-gradient(to right,
            #ff0000 0%,
            #ff4500 7%,
            #ff8c00 14%,
            #ffd700 21%,
            #adff2f 28%,
            #7fff00 35%,
            #00ff00 42%,
            #00fa9a 50%,
            #00ced1 57%,
            #1e90ff 64%,
            #4169e1 71%,
            #8a2be2 78%,
            #9400d3 85%,
            #4b0082 100%);
    position: relative;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.2);
}

.ph-indicator {
    position: absolute;
    top: -8px;
    width: 4px;
    height: 66px;
    background: var(--text-primary);
    border-radius: 2px;
    left: 50%;
    transform: translateX(-50%);
    transition: left 0.5s ease;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.ph-indicator::after {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 10px solid var(--text-primary);
}

.ph-labels {
    display: flex;
    justify-content: space-between;
    padding: 8px 5px 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.ph-categories {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.acid-strong {
    color: #e74c3c;
}

.acid-weak {
    color: #e67e22;
}

.neutral {
    color: #2ecc71;
}

.base-weak {
    color: #3498db;
}

.base-strong {
    color: #9b59b6;
}

/* Beaker */
.beaker-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.beaker {
    width: 200px;
    height: 280px;
    background: linear-gradient(to right,
            rgba(255, 255, 255, 0.1),
            rgba(255, 255, 255, 0.3),
            rgba(255, 255, 255, 0.1));
    border: 4px solid rgba(200, 200, 200, 0.5);
    border-top: none;
    border-radius: 0 0 20px 20px;
    position: relative;
    overflow: hidden;
}

.beaker::before {
    content: '';
    position: absolute;
    top: -15px;
    left: -20px;
    right: -20px;
    height: 20px;
    background: rgba(200, 200, 200, 0.5);
    border-radius: 5px;
}

.beaker-liquid {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0%;
    background: linear-gradient(to bottom, rgba(46, 204, 113, 0.6), rgba(46, 204, 113, 0.8));
    transition: height 0.5s ease, background 0.5s ease;
    border-radius: 0 0 16px 16px;
}

.bubbles {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.bubble {
    position: absolute;
    bottom: -20px;
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    animation: bubbleRise 2s infinite ease-in;
}

@keyframes bubbleRise {
    0% {
        transform: translateY(0) scale(1);
        opacity: 0.8;
    }

    100% {
        transform: translateY(-300px) scale(0.5);
        opacity: 0;
    }
}

.beaker-marks {
    position: absolute;
    right: 10px;
    top: 0;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.6rem;
    color: rgba(100, 100, 100, 0.7);
}

.volume-display {
    font-size: 1rem;
    color: var(--text-secondary);
}

.volume-display strong {
    color: var(--text-primary);
    font-size: 1.2rem;
}

/* pH Display */
.ph-display {
    text-align: center;
}

.ph-value-container {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 10px;
}

.ph-label {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.ph-value {
    font-size: 4rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--ph-neutral), #27ae60);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    transition: var(--transition);
}

.solution-type {
    font-size: 1.2rem;
    font-weight: 600;
    margin-top: 5px;
    padding: 8px 25px;
    border-radius: 20px;
    display: inline-block;
    background: rgba(46, 204, 113, 0.2);
    color: var(--ph-neutral);
}

.solution-type.acidic {
    background: rgba(231, 76, 60, 0.2);
    color: var(--ph-acid);
}

.solution-type.basic {
    background: rgba(155, 89, 182, 0.2);
    color: var(--ph-base);
}

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

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

.concentration-info {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

.info-card h4 {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 5px;
}

.info-card p {
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

/* Examples */
.example-section h3,
.daily-examples h3,
.formula-box h3,
.explanation-box h3 {
    font-size: 0.85rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.examples-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.example-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 0.8rem;
}

.example-icon {
    font-size: 1.1rem;
}

/* Formula */
.formula-box {
    background: var(--bg-tertiary);
    padding: 15px;
    border-radius: 10px;
    text-align: center;
}

.formula {
    font-size: 1.3rem;
    font-weight: 700;
    font-family: 'Times New Roman', serif;
    color: var(--text-primary);
}

/* Explanation */
.explanation-box {
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.1), rgba(39, 174, 96, 0.1));
    border-left: 4px solid var(--ph-neutral);
    padding: 15px;
    border-radius: 10px;
}

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

/* Daily Examples */
.daily-examples {
    background: var(--bg-tertiary);
    padding: 15px;
    border-radius: 10px;
}

.daily-scale {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.daily-item {
    font-size: 0.75rem;
    padding: 5px 8px;
    border-radius: 5px;
    background: var(--bg-secondary);
}

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

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

    .substances-panel {
        order: 1;
    }

    .lab-container {
        order: 2;
    }

    .info-panel {
        order: 3;
    }
}
