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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    min-height: 100vh;
    padding: 20px;
}

.weakacid-container {
    max-width: 1600px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #b91c1c 0%, #dc2626 100%);
    color: white;
    padding: 40px;
    text-align: center;
}

header h1 {
    font-size: 2.2rem;
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    font-size: 1.05rem;
    opacity: 0.9;
}

main {
    padding: 30px;
}

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

.left-panel,
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chart-display {
    background: #f8fafc;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chart-display h3 {
    color: #1e293b;
    font-size: 1.05rem;
    margin-bottom: 15px;
    font-weight: 600;
}

canvas {
    width: 100%;
    border-radius: 8px;
    background: white;
    display: block;
}

#titrationCanvas {
    height: 300px;
}

#phScaleCanvas {
    height: 120px;
}

#moleculeCanvas {
    height: 280px;
}

.curve-info,
.indicator-info,
.molecule-legend {
    display: flex;
    justify-content: space-between;
    margin-top: 15px;
    padding: 12px;
    background: white;
    border-radius: 8px;
    flex-wrap: wrap;
    gap: 10px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #475569;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: #475569;
}

.molecule-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-block;
}

.molecule-icon.ha {
    background: #ef4444;
}

.molecule-icon.h {
    background: #3b82f6;
}

.molecule-icon.a {
    background: #22c55e;
}

.color-box {
    width: 30px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    display: inline-block;
    vertical-align: middle;
}

.values-display {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
}

.values-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.value-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.value-label {
    font-size: 0.8rem;
    color: #78716c;
    font-weight: 500;
}

.value-value {
    font-size: 1.1rem;
    color: #1e293b;
    font-weight: 700;
}

.value-value.red { color: #ef4444; }
.value-value.blue { color: #3b82f6; }
.value-value.green { color: #22c55e; }

.controls-panel {
    background: #fef2f2;
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.controls-panel h3 {
    color: #1e293b;
    font-size: 1.4rem;
    margin-bottom: 20px;
    font-weight: 700;
}

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

.control-group {
    background: white;
    border-radius: 10px;
    padding: 18px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.control-group h4 {
    color: #dc2626;
    font-size: 0.95rem;
    margin-bottom: 12px;
    font-weight: 600;
    padding-bottom: 8px;
    border-bottom: 2px solid #fecaca;
}

.control-group label {
    display: block;
    margin-bottom: 10px;
    color: #475569;
    font-size: 0.85rem;
}

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

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #dc2626;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.4);
    transition: all 0.2s;
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: #b91c1c;
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #dc2626;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.4);
    transition: all 0.2s;
}

.control-group input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.1);
    background: #b91c1c;
}

.slider-hint {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-bottom: 12px;
    font-style: italic;
}

.select-input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #fecaca;
    border-radius: 8px;
    background: white;
    color: #475569;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.select-input:focus {
    border-color: #dc2626;
}

.indicator-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding: 10px;
    background: #fef2f2;
    border-radius: 6px;
}

.titration-btn {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #fecaca;
    border-radius: 8px;
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    color: #dc2626;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 8px;
}

.titration-btn:hover {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border-color: #dc2626;
    transform: translateY(-1px);
}

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

.preset-btn {
    width: 100%;
    padding: 10px 15px;
    border: 2px solid #fecaca;
    border-radius: 8px;
    background: white;
    color: #dc2626;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 8px;
}

.preset-btn:hover {
    background: #fef2f2;
    border-color: #dc2626;
    transform: translateY(-1px);
}

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

.formulas-section {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.formulas-section h3 {
    color: #1e293b;
    font-size: 1.15rem;
    margin-bottom: 15px;
    font-weight: 600;
}

.formula-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.formula-item {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    background: #fef2f2;
    border-radius: 6px;
    border-left: 3px solid #dc2626;
}

.formula-label {
    font-weight: 600;
    color: #dc2626;
    min-width: 180px;
    font-size: 0.9rem;
}

.formula {
    font-family: 'Courier New', monospace;
    color: #475569;
    font-size: 0.9rem;
}

.explanation {
    background: #fef2f2;
    border-radius: 12px;
    padding: 30px;
}

.explanation h2 {
    color: #b91c1c;
    font-size: 1.6rem;
    margin-bottom: 20px;
    font-weight: 700;
}

.explanation h3 {
    color: #dc2626;
    font-size: 1.2rem;
    margin-top: 20px;
    margin-bottom: 12px;
    font-weight: 600;
}

.explanation p {
    color: #475569;
    line-height: 1.7;
    margin-bottom: 12px;
    font-size: 0.95rem;
}

.explanation strong {
    color: #1e293b;
    font-weight: 600;
}

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

    header h1 {
        font-size: 1.8rem;
    }

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

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

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    header {
        padding: 30px 20px;
    }

    header h1 {
        font-size: 1.4rem;
    }

    .subtitle {
        font-size: 0.85rem;
    }

    main {
        padding: 20px;
    }

    .curve-info,
    .indicator-info,
    .molecule-legend {
        flex-direction: column;
        gap: 8px;
    }

    .indicator-preview {
        flex-direction: column;
        align-items: flex-start;
    }
}
