/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

:root {
    --primary: #2c3e50;
    --secondary: #3498db;
    --accent: #e74c3c;
    --light: #ecf0f1;
    --dark: #1a2530;
    --success: #2ecc71;
    --warning: #f39c12;
    --glass: rgba(255, 255, 255, 0.1);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
    --border-radius: 20px;
    --border-radius-small: 12px;
}

body {
    background: linear-gradient(135deg, #1a2980, #26d0ce);
    color: var(--light);
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: var(--glass);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: fadeIn 0.8s ease-out;
}

header h1 {
    font-size: 2.8rem;
    margin-bottom: 10px;
    background: linear-gradient(to right, #fff, #a5d8ff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    display: inline-block;
    animation: slideInDown 0.8s ease-out;
}

header p {
    font-size: 1.2rem;
    opacity: 0.9;
    max-width: 800px;
    margin: 0 auto;
    animation: fadeIn 1s ease-out 0.3s both;
}

/* Lab Container */
.lab-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
    animation: fadeIn 1s ease-out 0.5s both;
}

/* Control Panel */
.control-panel {
    background: var(--glass);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: var(--transition);
}

.control-panel:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.control-panel h2 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: #fff;
    border-bottom: 2px solid var(--secondary);
    padding-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Reaction Selector */
.reaction-selector {
    margin-bottom: 25px;
}

.selector-group {
    margin-bottom: 20px;
    animation: fadeInUp 0.5s ease-out;
}

.selector-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Custom Select */
.custom-select {
    position: relative;
    width: 100%;
}

.custom-select select {
    width: 100%;
    padding: 15px;
    border-radius: var(--border-radius-small);
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.2);
    color: white;
    font-size: 1rem;
    appearance: none;
    cursor: pointer;
    transition: var(--transition);
}

.custom-select select:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
    background: rgba(0, 0, 0, 0.3);
}

.custom-select select option {
    background: #1a2f4a;
    color: #fff;
    padding: 10px;
    border-bottom: 1px solid #2c4a6e;
}

.custom-select select option:hover {
    background: #2980b9;
}

.custom-select select option:checked {
    background: linear-gradient(0deg, #3498db 0%, #2980b9 100%);
    color: #fff;
    font-weight: 500;
}

.custom-select::after {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    color: var(--secondary);
    pointer-events: none;
    transition: var(--transition);
}

.custom-select:hover::after {
    color: #2980b9;
}

/* Buttons */
.reaction-controls {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 30px;
}

.btn {
    padding: 15px 25px;
    border-radius: var(--border-radius-small);
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex: 1;
    min-width: 160px;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: var(--secondary);
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(52, 152, 219, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(255, 255, 255, 0.1);
}

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

.btn-accent:hover {
    background: #c0392b;
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(231, 76, 60, 0.3);
}

/* Reaction Display */
.reaction-display {
    background: var(--glass);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

.reaction-display:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.reaction-title {
    font-size: 1.8rem;
    margin-bottom: 15px;
    color: #fff;
    border-bottom: 2px solid var(--accent);
    padding-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.reaction-equation {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.8rem;
    font-weight: bold;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    transition: var(--transition);
}

.reaction-equation.active {
    animation: highlight 0.5s ease-out;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(52, 152, 219, 0.3);
}

.reaction-info {
    flex-grow: 1;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 15px;
    padding: 20px;
    overflow-y: auto;
    max-height: 470px;
}

.reaction-info h3 {
    margin-bottom: 15px;
    color: var(--secondary);
    font-size: 1.4rem;
}

.reaction-info p {
    line-height: 1.6;
    margin-bottom: 15px;
}

/* Reaction Details */
.reaction-details {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.detail-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 15px;
    transition: var(--transition);
    animation: fadeInUp 0.5s ease-out;
}

.detail-card:hover {
    transform: translateY(-3px);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.detail-card h4 {
    color: var(--warning);
    margin-bottom: 8px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-card p {
    font-size: 0.95rem;
    line-height: 1.5;
}

/* Reaction Visualization */
.reaction-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    gap: 20px;
    flex-wrap: wrap;
    min-height: 120px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 15px;
    padding: 15px;
    animation: fadeIn 0.8s ease-out;
}

.chemical-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
}

.chemical-container:hover {
    transform: scale(1.05);
}

.chemical {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    transition: var(--transition);
    animation: float 3s ease-in-out infinite;
}

.chemical:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.chemical-1 {
    background: linear-gradient(135deg, #3498db, #2c3e50);
    animation-delay: 0s;
}

.chemical-2 {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    animation-delay: 0.2s;
}

.chemical-3 {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    animation-delay: 0.4s;
}

.chemical-4 {
    background: linear-gradient(135deg, #f39c12, #e67e22);
    animation-delay: 0.6s;
}

.reaction-plus {
    font-size: 1.5rem;
    color: white;
    font-weight: bold;
    animation: fadeIn 0.5s ease-out;
}

.reaction-arrow {
    font-size: 2rem;
    color: var(--warning);
    animation: slideInRight 0.5s ease-out;
}

.reaction-arrow i {
    animation: bounce 1s infinite;
}

/* Reaction Count */
.reaction-count {
    text-align: center;
    margin-top: 20px;
    font-size: 1.1rem;
    opacity: 0.9;
    padding: 10px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    animation: fadeIn 1s ease-out;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 30px;
    padding: 20px;
    background: var(--glass);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
    opacity: 0.8;
    animation: fadeIn 1s ease-out 0.7s both;
}

footer p {
    margin-bottom: 10px;
}

footer p:last-child {
    margin-bottom: 0;
}

/* Loading and Error States */
.loading {
    text-align: center;
    padding: 20px;
    font-size: 1.2rem;
    color: var(--secondary);
    animation: pulse 1.5s infinite;
}

.error {
    background: rgba(231, 76, 60, 0.2);
    border: 1px solid #e74c3c;
    border-radius: 10px;
    padding: 15px;
    margin: 10px 0;
    text-align: center;
    color: #fff;
    animation: shake 0.5s ease-in-out;
}

.error i {
    margin-right: 10px;
    color: #e74c3c;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateX(0);
    }
    50% {
        transform: translateX(5px);
    }
}

@keyframes highlight {
    0% {
        background: rgba(0, 0, 0, 0.2);
        box-shadow: 0 0 0 rgba(52, 152, 219, 0);
    }
    50% {
        background: rgba(52, 152, 219, 0.1);
        box-shadow: 0 0 20px rgba(52, 152, 219, 0.3);
    }
    100% {
        background: rgba(0, 0, 0, 0.3);
        box-shadow: 0 0 0 rgba(52, 152, 219, 0);
    }
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

/* Responsive Design */
@media (max-width: 1024px) {
    .lab-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 2.2rem;
    }
    
    .lab-container {
        gap: 20px;
    }
    
    .control-panel, .reaction-display {
        padding: 20px;
    }
    
    .btn {
        min-width: 100%;
    }
    
    .reaction-equation {
        font-size: 1.4rem;
        padding: 15px;
        min-height: 100px;
    }
    
    .reaction-visual {
        gap: 10px;
    }
    
    .chemical {
        width: 60px;
        height: 60px;
        font-size: 0.9rem;
    }
    
    .reaction-details {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    header p {
        font-size: 1rem;
    }
    
    .reaction-equation {
        font-size: 1.2rem;
        padding: 10px;
    }
    
    .reaction-details {
        grid-template-columns: 1fr;
    }
    
    .reaction-title, .control-panel h2 {
        font-size: 1.5rem;
    }
    
    .reaction-info h3 {
        font-size: 1.2rem;
    }
    
    .chemical {
        width: 50px;
        height: 50px;
        font-size: 0.8rem;
    }
    
    .reaction-arrow {
        font-size: 1.5rem;
    }
}

/* Scrollbar Styling */
.reaction-info::-webkit-scrollbar {
    width: 8px;
}

.reaction-info::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.reaction-info::-webkit-scrollbar-thumb {
    background: var(--secondary);
    border-radius: 10px;
}

.reaction-info::-webkit-scrollbar-thumb:hover {
    background: #2980b9;
}

/* Tooltip Style */
.tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
}

.tooltip .tooltip-text {
    visibility: hidden;
    width: 200px;
    background-color: var(--dark);
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.9rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.tooltip .tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: var(--dark) transparent transparent transparent;
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Chemical Label */
.chemical-label {
    font-size: 0.8rem;
    text-align: center;
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.9;
}

.product-plus {
    font-size: 1.2rem;
    opacity: 0.7;
}

/* Home Button */
.btn-home {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--secondary);
    color: white;
    text-decoration: none;
    border-radius: var(--border-radius-small);
    font-weight: 600;
    transition: var(--transition);
}

.btn-home:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

/* Disabled Button */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Warning Toast */
.warning-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(243, 156, 18, 0.95);
    color: #fff;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    z-index: 10000;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    animation: slideInDown 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 8px;
}

.warning-toast.fade-out {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
    transition: all 0.3s ease;
}

/* Accessibility: Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Selection Color */
::selection {
    background-color: rgba(52, 152, 219, 0.5);
    color: white;
}

::-moz-selection {
    background-color: rgba(52, 152, 219, 0.5);
    color: white;
}