* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #000000;
    color: white;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.container {
    height: 100dvh;
    height: 100vh; /* fallback */
    display: flex;
    flex-direction: column;
    max-width: 500px;
    margin: 0 auto;
}

.history-section {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.history-item {
    text-align: right;
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 5px 12px;
    border-radius: 10px;
}

.history-item:hover {
    background-color: #1a1a1a;
}

.history-expression {
    color: #555555;
    font-size: 20px;
    white-space: pre-wrap; /* 保留换行符同时自动换行 */
    overflow-wrap: break-word; /* 优先使用现代属性 */
}

.clear-history-btn{
    position: absolute;
    top: 25px;
    left: 20px;
    cursor: pointer;
    width: 65px;
    height: 30px;
    border: none;
    border-radius: 5px;
    background-color: #8a5204;
    color: white;
    font-size: 14px;
    transition: background-color 0.2s;
}

.clear-history-btn:hover {
    background-color: #ffb143;
}

.clear-history-btn:active {
    transform: scale(0.95);
}

.display-section {
    flex: 0 1 auto;
    max-height: 200px;
    display: flex;
    flex-direction: column;
    padding: 10px 20px 0 20px;
    text-align: right;
    border-top: 1px solid #333;
}

.expression {
    font-size: 25px;
    font-weight: bold;
    color: #fcacac;
    text-align: right;
    border: none;
    background: transparent;
    width: 100%;
    outline: none;
    padding: 5px;
    margin-bottom: 5px;
    resize: none; /* 防止用户手动调整大小 */
    overflow-y: auto;
    font-family: inherit; /* 继承父元素的字体 */
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-all;
    max-height: 120px; /* 限制最大高度 */
}

.result {
    color: white;
    font-size: 50px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 10px 30px;
    background: #000;
    margin-bottom: 30px;
}

.key {
    aspect-ratio: 1;
    border: none;
    border-radius: 50%;
    font-size: 32px;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 75px;
}

.key:active {
    transform: scale(0.95);
}

.key.number {
    background: #333;
    color: white;
}

.key.number:active {
    background: #4a4a4a;
}

.key.operator {
    background: #ff9500;
    color: white;
}

.key.operator:active {
    background: #ffb143;
}

.key.operator.active {
    background: white;
    color: #ff9500;
}

.key.function {
    background: #a6a6a6;
    color: black;
}

.key.function:active {
    background: #d9d9d9;
}

.key.equals {
    background: #ff0000;
    color: white;
}

.key.equals:active {
    background: #cc00ff;
}

.key.backspace::before {
    content: "⌫";
    font-size: 24px;
}

@media (max-height: 700px) {
    .history-section {
        max-height: 120px;
    }
    .result {
        font-size: 36px;
    }
    .key {
        min-height: 60px;
        font-size: 28px;
    }
}

@media (max-width: 380px) {
    .keypad {
        gap: 8px;
        padding: 15px;
    }
    .key {
        min-height: 65px;
        font-size: 24px;
    }
}

/* 滚动条样式 */
.history-section::-webkit-scrollbar {
    width: 4px;
}

.history-section::-webkit-scrollbar-track {
    background: transparent;
}

.history-section::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 2px;
}