:root {
    --primary-color: #007AFF;
    --secondary-color: #34C759;
    --background-color: #F2F2F7;
    --text-color: #1C1C1E;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background-color: var(--background-color);
    color: var(--text-color);
}

.calculator {
    background-color: #fff;
    border-radius: 20px;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    padding: 20px;
    width: 90vw;
    max-width: 500px;
}

.history {
    height: 60px;
    overflow-y: auto;
    text-align: right;
    font-size: 18px;
    color: #888;
    margin-bottom: 10px;
}

.display {
    background-color: #f8f8f8;
    border-radius: 10px;
    font-size: 48px;
    text-align: right;
    padding: 20px;
    margin-bottom: 20px;
    min-height: 80px;
}

.keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.key {
    background-color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    height: 80px;
    width: 80px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.key:active {
    transform: scale(0.95);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

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

.function {
    background-color: #E5E5EA;
}

.wide {
    grid-column: span 2;
    width: auto;
    border-radius: 40px;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: #fff;
    margin: 10% auto;
    padding: 20px;
    border-radius: 20px;
    width: 80%;
    max-width: 500px;
}

#handwritingCanvas {
    width: 100%;
    height: 300px;
    border: 1px solid #ccc;
    border-radius: 10px;
}

.modal-buttons {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
}

.modal-buttons button {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
}

@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #1C1C1E;
        --text-color: #FFFFFF;
    }

    .calculator, .modal-content {
        background-color: #2C2C2E;
    }

    .display {
        background-color: #3A3A3C;
        color: #FFFFFF;
    }

    .key {
        background-color: #3A3A3C;
        color: #FFFFFF;
    }

    .function {
        background-color: #2C2C2E;
    }
}