:root {
    --bg-color: #000;
    --display-bg: #000;
    --text-color: #fff;
    --number-bg: #333;
    --number-bg-active: #737373;
    --operator-bg: #f1a33c;
    --operator-bg-active: #f8d1a1;
    --function-bg: #a5a5a5;
    --function-bg-active: #e0e0e0;
    --function-text-color: #000;
    --button-gap: 10px; /* 調整按鈕間距 */
    --border-radius: 50%; /* 預設圓形 */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    /* 添加下面這行 */
    overflow: hidden; /* 禁止 html 元素本身的滾動條 */
}

body {
    background-color: var(--bg-color);
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Roboto", sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-end; /* 將計算機置於底部 */
    /* 將 min-height 改為 height */
    /* min-height: 100%; */
    height: 100%;      /* 確保 body 佔滿整個視窗高度 */
    padding-bottom: 20px; /* 底部留一些空間 */
    /* 添加下面兩行 */
    overflow: hidden; /* 禁止 body 內容溢出滾動 */
    touch-action: none; 
}

.calculator {
    background-color: var(--bg-color);
    width: 100%;
    max-width: 400px; /* 控制最大寬度 */
    /* height: 80vh; */ /* 可以限制高度，或讓內容自適應 */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 確保圓角效果 */
    padding: 0 var(--button-gap); /* 左右留出間距 */
}

.display {
    background-color: var(--display-bg);
    color: var(--text-color);
    text-align: right;
    padding: 20px var(--button-gap);
    display: flex;
    flex-direction: column;
    justify-content: flex-end; /* 從底部對齊 */
    min-height: 100px; /* 至少給顯示區一個高度 */
    flex-grow: 1; /* 讓顯示區可以擴展 */
    margin-bottom: var(--button-gap);
}

.history {
    font-size: 1.2em; /* 稍微小一點 */
    color: #bbb; /* 稍微暗一點 */
    min-height: 1.5em; /* 確保有空間顯示 */
    overflow-wrap: break-word; /* 長內容換行 */
    word-break: break-all; /* 強制斷詞 */
    margin-bottom: 5px;
}

.current-input {
    font-size: 3em; /* 主要數字大一點 */
    font-weight: 300;
    min-height: 1.5em;
    overflow-wrap: break-word;
    word-break: break-all;
    /* 動態調整字體大小，避免溢出 */
    /* overflow: hidden;
    white-space: nowrap; */
    /* 更進階的可以用 JS 調整 */
}

.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--button-gap);
    padding: 0; /* 移除內邊距，依賴外部容器 */
    width: 100%;
}

.button {
    background-color: var(--number-bg);
    color: var(--text-color);
    border: none;
    font-size: 1.8em; /* 調整按鈕文字大小 */
    cursor: pointer;
    aspect-ratio: 1 / 1; /* 保持方形，圓角後變圓 */
    border-radius: var(--border-radius);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.1s ease;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0); /* 移除移動端點擊高亮 */
}

.button:active {
    background-color: var(--number-bg-active);
}

.button.operator {
    background-color: var(--operator-bg);
    color: var(--text-color);
}
.button.operator:active {
    background-color: var(--operator-bg-active);
}

.button.function {
    background-color: var(--function-bg);
    color: var(--function-text-color);
}
.button.function:active {
    background-color: var(--function-bg-active);
}

.button.zero {
    grid-column: span 2;
    aspect-ratio: auto; /* 取消固定比例 */
    width: 100%; /* 寬度佔滿 */
    border-radius: 50px; /* 膠囊形狀 */

}

/* 響應式：在非常小的螢幕上稍微縮小字體 */
@media (max-height: 600px) {
    .current-input {
        font-size: 2.5em;
    }
    .button {
        font-size: 1.5em;
    }
    .history {
        font-size: 1em;
    }
}