body {
    margin: 0;
    display: flex;
    flex-direction: column; /* Changed to column to stack calculator and history */
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #f4f4f4;
    font-family: 'Arial', sans-serif;
    color: #333;
    padding: 20px; /* Add some padding around everything */
    box-sizing: border-box;
}

.calculator {
    border: 1px solid #ccc;
    border-radius: 10px;
    padding: 20px;
    background-color: #fff;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    width: 300px;
    margin-bottom: 30px; /* Space between calculator and history */
}

/* New: Previous Calculation Display */
.calculator-previous-display {
    height: 30px;
    background-color: #222;
    color: #aaa; /* Lighter color for previous text */
    font-size: 1em;
    text-align: right;
    padding: 5px 10px;
    border-radius: 5px;
    margin-bottom: 5px; /* Smaller margin to main display */
    box-sizing: border-box;
    overflow: hidden; /* Hide overflow if expression is too long */
    white-space: nowrap; /* Prevent wrapping */
    text-overflow: ellipsis; /* Add ellipsis for long expressions */
}

.calculator-display {
    width: calc(100% - 20px);
    height: 60px;
    background-color: #222;
    color: #fff;
    font-size: 2.5em;
    text-align: right;
    padding: 10px;
    border: none;
    border-radius: 5px;
    margin-bottom: 20px;
    box-sizing: border-box;
}

.calculator-keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.calculator-keys button {
    height: 60px;
    font-size: 1.5em;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background-color: #e0e0e0;
    transition: background-color 0.2s ease;
    color: #333;
}

.calculator-keys button:hover {
    background-color: #d0d0d0;
}

.calculator-keys .key-operator {
    background-color: #f39c12;
    color: #fff;
}

.calculator-keys .key-operator:hover {
    background-color: #e67e22;
}

.calculator-keys .key-clear {
    background-color: #e74c3c;
    color: #fff;
}

.calculator-keys .key-clear:hover {
    background-color: #c0392b;
}

.calculator-keys .key-equal {
    grid-column: span 2;
    background-color: #2ecc71;
    color: #fff;
}

.calculator-keys .key-equal:hover {
    background-color: #27ae60;
}

.calculator-keys .key-operator[data-state="selected"] {
    background-color: #e67e22;
}

/* New: History Area Styling */
.history-container {
    width: 300px; /* Same width as calculator */
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
}

.history-container h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #555;
    text-align: center;
}

.clear-history-btn {
    display: block;
    width: 100%;
    padding: 10px;
    background-color: #3498db; /* Blue */
    color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    margin-bottom: 15px;
    transition: background-color 0.2s ease;
}

.clear-history-btn:hover {
    background-color: #2980b9;
}

.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 200px; /* Fixed height for scrollable history */
    overflow-y: auto; /* Enable vertical scrolling */
    border: 1px solid #eee;
    border-radius: 5px;
    background-color: #fafafa;
}

.history-list li {
    padding: 10px;
    border-bottom: 1px solid #eee;
    font-size: 0.9em;
    color: #666;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-list li:last-child {
    border-bottom: none;
}

.history-list li .expression {
    flex-grow: 1;
    text-align: left;
    margin-right: 10px;
    word-break: break-all; /* Allow long expressions to break */
}

.history-list li .result {
    font-weight: bold;
    color: #333;
    white-space: nowrap; /* Keep result on one line */
}

/* Scrollbar styling for history */
.history-list::-webkit-scrollbar {
    width: 8px;
}

.history-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}