* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Space Mono', monospace;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #f0f2f5;
    transition: background 0.3s ease, color 0.3s ease;
}

body.dark-mode {
    background: #121212;
    color: #e0e0e0;
}

.container {
    display: flex;
    align-items: flex-start;
    position: relative;
}

.calculator {
    background: #ffffff;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    width: 320px;
    position: relative;
    z-index: 2;
}

.display {
    width: 100%;
    height: 60px;
    background: #f8f9fa;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 24px;
    text-align: right;
    margin-bottom: 20px;
    color: #333;
}

body.dark-mode .display {
    background: #333;
    color: #e0e0e0;
}

.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

button {
    padding: 15px;
    font-size: 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
    background: #ffffff;
    color: #333;
    border: 1px solid #ddd;
}

body.dark-mode button:not(.operator):not(.equals):not(.clear):not([value="."]) {
    background: #444;
    color: #e0e0e0;
    border: 1px solid #555;
}

.operator, .equals, .clear, button[value="."] {
    background: #ff4444;
    color: white;
}

button:not(.operator):not(.equals):not(.clear):not([value="."]):hover {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.8);
}

.operator:hover, .equals:hover, .clear:hover, button[value="."]:hover {
    box-shadow: 0 0 0 3px rgba(255, 68, 68, 0.5);
}

.history-toggle:hover {
    box-shadow: 0 0 0 3px rgba(255, 68, 68, 0.5);
}

button:not(.operator):not(.equals):not(.clear):not([value="."]):active {
    background: #f0f0f0;
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.operator:active, .equals:active, .clear:active, button[value="."]:active {
    background: #cc0000;
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.history-toggle:active {
    background: #cc0000;
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

button::after {
    content: '';
    position: absolute;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: scale(0);
    pointer-events: none;
    transition: transform 0.5s, opacity 0.5s;
    opacity: 0;
}

button:active::after {
    transform: scale(1);
    opacity: 0.5;
    transition: 0s;
}

.history-panel {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    height: auto;
    background: #ffffff;
    border: 12px solid #ffffff;
    border-radius: 22px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    z-index: 1;
    transition: top 0.3s ease;
}

body.dark-mode .history-panel {
    background: #222;
    border-color: #222;
}

.history-panel.opening-step1 {
    top: 0;
}

.history-panel.closing-step1 {
    top: 100%;
}

.history-content {
    padding: 10px;
    background: #e0e0e0;
    border-radius: 6px;
    overflow-y: auto;
    max-height: 300px;
}

body.dark-mode .history-content {
    background: #333;
}

.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.history-list li {
    padding: 8px 10px;
    font-size: 18px;
    color: #333;
    text-align: right;
    border-bottom: 1px solid #d0d0d0;
}

body.dark-mode .history-list li {
    color: #e0e0e0;
    border-bottom: 1px solid #555;
}

.history-list li:last-child {
    border-bottom: none;
}

.extra-functions-toggle {
    background: #ff4444; /* Match operator button background */
    padding: 10px;
    border-radius: 8px; /* Match operator button border radius */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    font-size: 16px;
    color: white; /* Match operator button text color */
    text-align: center;
    margin-top: 20px;
    user-select: none;
    transition: all 0.2s ease;
}

.extra-functions-toggle:hover {
    box-shadow: 0 0 0 3px rgba(255, 68, 68, 0.5); /* Match operator button hover */
}

.extra-functions-toggle:active {
    background: #cc0000; /* Match operator button active */
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.extra-functions {
    display: none;
    margin-top: 20px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.calculator.active .extra-functions {
    display: grid;
    max-height: 200px; /* Increased max-height */
}

.extra-functions button {
    font-size: 16px;
    padding: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
}

.extra-functions button:hover {
    box-shadow: 0 0 0 3px rgba(255, 68, 68, 0.5);
}

.extra-functions button:active {
    background: #cc0000;
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.extra-functions-toggle::before {
    content: '▼ ';
    margin-right: 5px;
}

.calculator.active .extra-functions-toggle::before {
    content: '▲ ';
}

.dark-mode-toggle {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    transition: color 0.3s ease;
    pointer-events: auto;
}

body.dark-mode .dark-mode-toggle {
    color: #e0e0e0;
}

body.dark-mode .calculator {
    background: #000;
}