:root {
    --primary-color: #10b981;
    --primary-hover: #059669;
    --primary-light: #ecfdf5;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-color: #3b82f6;
    --divider-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif; }

body { background-color: var(--bg-color); color: var(--text-primary); padding: 20px; line-height: 1.6; }

.app-container { max-width: 800px; margin: 0 auto; width: 100%; }

header { text-align: left; margin-bottom: 30px; }
h1 { font-size: 2.2rem; font-weight: 700; color: var(--text-primary); margin-bottom: 10px; overflow-wrap: anywhere; }
.header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.subtitle { color: var(--text-secondary); font-size: 1rem; overflow-wrap: anywhere; }

.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.home-btn {
    display: inline-flex;
    align-items: center;
    background: white;
    border: 1px solid var(--divider-color);
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    font-weight: 500;
}
.home-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--primary-light);
}
.lang-switcher { display: flex; gap: 4px; }
.lang-btn {
    background: white; border: 1px solid var(--divider-color);
    border-radius: 8px; padding: 5px 12px; font-size: 0.75rem;
    cursor: pointer; transition: all 0.2s; font-weight: 500;
}
.lang-btn.active { background: var(--primary-color); color: white; border-color: var(--primary-color); }

.quick-btn {
    background: var(--bg-color);
    border: 1px solid var(--divider-color);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.quick-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--primary-light);
}

.panel-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.panel-title {
    font-size: 1.1rem;
    margin: 0;
}

.reset-btn {
    border-style: dashed;
}

.converter-card {
    background: var(--card-bg); border-radius: 16px;
    padding: 30px; box-shadow: var(--shadow); border: 1px solid var(--divider-color);
    margin-bottom: 30px;
}

.category-title { font-size: 1.1rem; font-weight: 600; display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.step-badge {
    background: var(--primary-color); color: white;
    width: 24px; height: 24px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 0.8rem;
}

.guidance-active {
    border-color: var(--primary-color) !important;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
    animation: pulse-primary 1.5s infinite;
}

@keyframes pulse-primary {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.section-header-flex { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.quick-btn-reagent { max-width: 140px; font-size: 0.75rem; padding: 6px; border-radius: 8px; border: 1px solid var(--primary-color); color: var(--primary-color); }

.input-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.adv-field { display: flex; }
.input-group { display: flex; flex-direction: column; gap: 8px; }
label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }

.advanced-toggle-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    border: 1px solid var(--divider-color);
    border-radius: 18px;
    background:
        radial-gradient(circle at top left, rgba(16, 185, 129, 0.15), transparent 42%),
        linear-gradient(135deg, #f8fffc 0%, #ffffff 62%);
}

.advanced-toggle-copy {
    display: flex;
    align-items: center;
}

.advanced-pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.advanced-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.18);
    color: var(--primary-hover);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.toggle-adv-btn {
    border-color: rgba(16, 185, 129, 0.35);
    color: var(--primary-color);
    background: white;
    gap: 10px;
    padding: 10px 16px;
    white-space: nowrap;
}

.toggle-adv-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary-hover);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    transition: transform 0.25s ease, background-color 0.25s ease;
}

.show-adv .toggle-adv-icon {
    transform: rotate(135deg);
    background: rgba(16, 185, 129, 0.18);
}

.advanced-panel {
    display: grid;
    grid-template-rows: 0fr;
    opacity: 0;
    transform: translateY(-8px);
    transition: grid-template-rows 0.35s ease, opacity 0.25s ease, transform 0.25s ease;
}

.show-adv .advanced-panel {
    grid-template-rows: 1fr;
    opacity: 1;
    transform: translateY(0);
}

.advanced-panel-inner {
    overflow: hidden;
}

.advanced-panel-shell {
    margin-top: 18px;
    padding: 22px;
    border-radius: 18px;
    background: #f8fffc;
    border: 1px solid rgba(16, 185, 129, 0.18);
}

.advanced-panel-kicker {
    margin-bottom: 16px;
    color: var(--primary-hover);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.advanced-grid {
    display: grid;
    gap: 16px;
}

.advanced-card {
    padding: 18px;
    border-radius: 14px;
    border: 1px solid var(--divider-color);
    background: white;
}

.dilution-card {
    border-color: rgba(16, 185, 129, 0.18);
}

.dilution-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.dilution-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.08);
    color: var(--primary-hover);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.dilution-title {
    font-size: 1rem;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.dilution-subtitle {
    color: var(--text-secondary);
    font-size: 0.84rem;
    line-height: 1.5;
}

.dilution-formula-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: #f1f5f9;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.dilution-unit-row {
    display: grid;
    grid-template-columns: minmax(0, 220px) 1fr;
    gap: 16px;
    align-items: end;
    margin-bottom: 16px;
}

.dilution-unit-select {
    width: 100%;
    padding-right: 34px;
}

.dilution-inline-hint {
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.5;
    padding-bottom: 6px;
}

.dilution-grid {
    margin-bottom: 16px;
}

.dilution-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.dilution-note {
    flex: 1;
    min-height: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.5;
}

.dilution-note[data-state="result"] {
    color: var(--primary-hover);
    font-weight: 600;
}

.dilution-note[data-state="warn"],
.dilution-note[data-state="invalid"] {
    color: #b45309;
}

.dilution-clear-btn {
    flex-shrink: 0;
}

.advanced-input-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.advanced-input-grid-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.advanced-divider {
    margin-top: 22px;
}

.unit-input-pair { display: flex; gap: 5px; width: 100%; }
.unit-input-pair input { flex: 1; min-width: 0; }

input, select {
    width: 100%;
    padding: 12px 16px;
    font-size: 1.1rem;
    border: 2px solid var(--divider-color);
    border-radius: 8px;
    outline: none;
    transition: all 0.2s ease;
    background: var(--card-bg);
    color: var(--text-primary);
    font-family: 'Inter', monospace;
    -webkit-appearance: none;
}
input:focus, select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.formula-preview {
    margin-top: 6px; font-size: 0.95rem; font-weight: 600;
    color: var(--primary-color); min-height: 1.4rem;
}
.formula-preview sub { font-size: 0.7rem; vertical-align: baseline; position: relative; bottom: -0.2em; }

.unit-select { 
    width: 75px; flex-shrink: 0; padding: 10px 8px; font-size: 0.85rem; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 8px center;
}

.divider { border: 0; border-top: 1px solid var(--divider-color); margin: 30px 0; }

/* Result Highlight */
.result-highlight { background: var(--primary-light); border-radius: 20px; padding: 25px; margin-top: 30px; display: none; }
.result-highlight.visible { display: block; }
.result-value { font-size: 1.5rem; font-weight: 700; color: var(--primary-color); }

/* Info Section (Formula Display) */
.info-section { background: white; border-radius: 16px; padding: 30px; margin-bottom: 30px; border: 1px solid var(--divider-color); box-shadow: var(--shadow); }
.info-section h2 { font-size: 1.2rem; margin-bottom: 20px; color: var(--text-primary); }

.formula-display { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; }
.formula-card { flex: 1; min-width: 150px; background: var(--bg-color); padding: 15px; border-radius: 12px; text-align: center; }
.formula-header { font-size: 0.8rem; font-weight: 700; color: var(--text-secondary); margin-bottom: 10px; text-transform: uppercase; }
.formula-body { font-weight: 700; font-size: 1rem; color: var(--primary-color); display: flex; align-items: center; justify-content: center; gap: 5px; }

.fraction { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; }
.num { border-bottom: 2px solid var(--primary-color); padding: 0 10px; }
.den { padding: 0 10px; }

.formula-defs {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px dashed var(--divider-color);
}

.steps-list {
    list-style: none;
    display: grid;
    gap: 14px;
    padding: 0;
}

.steps-item {
    padding: 16px 18px;
    border-radius: 14px;
    border: 1px solid var(--divider-color);
    background: linear-gradient(180deg, #ffffff 0%, #f8fffc 100%);
}

.steps-item strong {
    display: block;
    margin-bottom: 6px;
    color: var(--text-primary);
    font-size: 0.92rem;
}

.steps-item p {
    color: var(--text-secondary);
    font-size: 0.86rem;
    line-height: 1.6;
}

.def-list {
    list-style: none;
    padding: 0;
}

.def-list li {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    display: flex;
    gap: 8px;
    line-height: 1.4;
}

.def-list li strong {
    color: var(--primary-color);
    white-space: nowrap;
}

/* Workflow Section */
.workflow-section {
    margin-bottom: 30px;
}

.workflow-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--primary-light);
    padding: 15px;
    border-radius: 12px;
    border: 1px dashed var(--primary-color);
}

.workflow-step {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
}

.step-num {
    width: 28px;
    height: 28px;
    background: var(--bg-color);
    border: 1.5px solid var(--divider-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.workflow-step.highlight .step-num {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.workflow-step.highlight strong {
    color: var(--primary-color);
}

.step-text {
    display: flex;
    flex-direction: column;
}

.step-text strong {
    font-size: 0.85rem;
    color: var(--text-primary);
}

.step-text p {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.workflow-arrow {
    color: var(--divider-color);
    font-size: 1.2rem;
    font-weight: 700;
}

/* Knowledge Grid */
.knowledge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-top: 5px;
}

.knowledge-card {
    background: var(--bg-color);
    border: 1px solid var(--divider-color);
    border-radius: 12px;
    padding: 18px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.knowledge-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.1);
    border-color: var(--primary-color);
}

.knowledge-header {
    margin-bottom: 8px;
}

.knowledge-symbol {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
    font-family: 'Inter', monospace;
    background: rgba(16, 185, 129, 0.08);
    padding: 3px 10px;
    border-radius: 6px;
}

.knowledge-field {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
    margin-top: 10px;
}

.knowledge-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Ad Placeholders */
.ad-placeholder { background: #f1f5f9; border-radius: 12px; display: flex; align-items: center; justify-content: center; margin: 20px 0; min-height: 90px; border: 1px dashed var(--divider-color); }
.ad-text { color: var(--text-secondary); font-size: 0.8rem; }

footer { text-align: center; padding: 30px 0; color: var(--text-secondary); font-size: 0.85rem; }

.lock-hint {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-left: 5px;
    opacity: 0;
    transition: opacity 0.3s;
}
.lock-hint.visible { opacity: 1; }

.locked-field {
    background-color: #f1f5f9 !important;
    border-color: var(--divider-color) !important;
    cursor: not-allowed;
    color: var(--text-secondary);
}

@media (max-width: 600px) {
    body { overflow-x: hidden; }
    .input-grid { grid-template-columns: 1fr; }
    .header-row { flex-direction: column; gap: 15px; }
    h1 { font-size: 1.9rem; }
    .formula-display { flex-direction: column; }
    .formula-card { min-width: 0; width: 100%; }
    .def-list li { display: block; }
    .def-list li strong { display: inline; white-space: normal; }
    .panel-toolbar,
    .advanced-toggle-card,
    .workflow-container {
        flex-direction: column;
        align-items: stretch;
    }
    .toggle-adv-btn {
        width: 100%;
        justify-content: center;
    }
    .workflow-arrow {
        transform: rotate(90deg);
    }
    .advanced-card {
        padding: 16px;
    }
    .dilution-head,
    .dilution-foot {
        flex-direction: column;
        align-items: stretch;
    }
    .dilution-unit-row {
        grid-template-columns: 1fr;
    }
    .dilution-formula-badge,
    .dilution-clear-btn {
        width: 100%;
        justify-content: center;
    }
}
