:root {
    --primary-color: #1976D2;
    --primary-variant: #004BA0;
    --secondary-color: #03DAC6;
    --background: #FFFFFF;
    --surface: #FFFFFF;
    --error: #B00020;
    --on-primary: #FFFFFF;
    --on-secondary: #000000;
    --on-background: #000000;
    --on-surface: #000000;
    --on-error: #FFFFFF;
    --on-surface-rgb: 0, 0, 0;
}

body {
    font-family: 'Roboto', sans-serif;
    line-height: 1.6;
    color: var(--on-background);
    background-color: var(--background);
    margin: 0;
    padding: 0;
    transition: background-color 0.3s, color 0.3s;
    box-sizing: border-box; /* Ensure all elements use border-box */
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

h1 {
    margin: 0;
    color: var(--on-surface);
    font-weight: 300;
    font-size: 2.5rem;
}

#darkModeToggle {
    background: none;
    border: none;
    color: var(--on-surface);
    font-size: 1.5rem;
    cursor: pointer;
}

main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.input-section, .results-section {
    background-color: var(--surface);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.input-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.toggle-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

.toggle-container button {
    margin: 0 0.25rem;
}

.input-group {
    display: grid;
    gap: 1rem; /* Space between input fields */
}

input {
    width: 100%; /* Ensure input boxes do not exceed their container width */
    max-width: 100%; /* Prevent overflow */
    padding: 0.75rem; /* Add padding inside input boxes */
    border: 1px solid rgba(var(--on-surface-rgb), 0.1); /* Light border */
    border-radius: 4px; /* Rounded corners for input boxes */
    background-color: rgba(var(--on-surface-rgb), 0.05); /* Light background */
    color: var(--on-surface); /* Text color */
    font-size: 1rem;
    box-sizing: border-box; /* Include padding and border in input width */
}

input::placeholder {
    color: rgba(var(--on-surface-rgb), 0.5); /* Subtle placeholder text */
}

button {
    background-color: var(--primary-color);
    color: var(--on-primary);
    border: none;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.1s;
    border-radius: 4px;
    font-weight: 500;
    font-size: 1rem;
}

button:hover {
    background-color: var(--primary-variant);
}

button:active {
    transform: scale(0.98);
}

button.active {
    background-color: var(--primary-variant);
}

#calculate {
    width: 100%;
    margin-top: 1rem;
    background-color: var(--secondary-color);
    color: var(--on-secondary);
}

.result-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    background-color: rgba(var(--on-surface-rgb), 0.08);
    border-radius: 4px;
    font-size: 1.1rem;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

#percentChange,
#xIncrease {
    color: var(--secondary-color);
}

#profitLoss.positive {
    color: #00C853; /* Green for profit */
}

#profitLoss.negative {
    color: var(--error); /* Red for loss */
}

.dark-mode {
    --primary-color: #BB86FC;
    --primary-variant: #3700B3;
    --secondary-color: #03DAC6;
    --background: #121212;
    --surface: #1E1E1E;
    --error: #CF6679;
    --on-primary: #000000;
    --on-secondary: #000000;
    --on-background: #FFFFFF;
    --on-surface: #FFFFFF;
    --on-error: #000000;
    --on-surface-rgb: 255, 255, 255;
}

.dark-mode button {
    color: var(--on-surface);
}

.light-mode {
    --primary-color: #1976D2;
    --primary-variant: #004BA0;
    --secondary-color: #03DAC6;
    --background: #FFFFFF;
    --surface: #FFFFFF;
    --error: #B00020;
    --on-primary: #FFFFFF;
    --on-secondary: #000000;
    --on-background: #000000;
    --on-surface: #000000;
    --on-error: #FFFFFF;
    --on-surface-rgb: 0, 0, 0;
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    main {
        grid-template-columns: 1fr; /* Single-column layout for smaller screens */
    }

    h1 {
        font-size: 2rem;
    }

    .input-section,
    .results-section {
        padding: 1rem;
    }

    button,
    input {
        font-size: 0.9rem;
        padding: 0.6rem 1rem;
    }

    .result-item {
        font-size: 1rem;
    }
}

@media (min-width: 1921px) {
    .container {
        max-width: 1600px;
    }

    h1 {
        font-size: 3rem;
    }

    button,
    input {
        font-size: 1.2rem;
        padding: 0.9rem 1.8rem;
    }

    .result-item {
        font-size: 1.3rem;
    }
}