* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Helvetica Neue', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --calculator-bg: #22252d;
    --keys-bg: #292d36;
    --key-bg: #292d36;
    --key-operator-bg: #272b33;
    --key-equal-bg: #26f3cd;
    --text-color: #fff;
    --text-secondary: #a5a5a5;
    --operator-color: #26f3cd;
    --function-color: #ffbf71;
    --memory-color: #ff9eb6;
    --error-color: #ff6b6b;
    --instruction-bg: rgba(255, 255, 255, 0.85);
    --instruction-text: #333;
    --tab-active-bg: #26f3cd;
    --tab-active-text: #272b33;
}

body {
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-color);
}

.calculator-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}

/* 语言切换按钮样式 */
.language-switcher {
    display: flex;
    justify-content: flex-end;
    width: 100%;
    max-width: 25rem;
    margin-bottom: 1rem;
}

.lang-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 0.5rem;
    margin-left: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.lang-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lang-btn.active {
    background: #26f3cd;
    color: #272b33;
}

.calculator {
    width: 100%;
    max-width: 25rem;
    border-radius: 1.25rem;
    overflow: hidden;
    box-shadow: 0 0.625rem 1.875rem rgba(0, 0, 0, 0.3);
    background-color: var(--calculator-bg);
    transition: all 0.3s ease;
}

.calculator__display-container {
    background-color: var(--calculator-bg);
    padding: 1.25rem;
    border-radius: 1.25rem 1.25rem 0 0;
    height: 10rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    transition: height 0.3s ease;
}

.calculator__expression {
    color: var(--text-secondary);
    font-size: 1.3rem;
    text-align: right;
    min-height: 1.875rem;
    margin-bottom: 0.625rem;
    word-wrap: break-word;
    word-break: break-all;
    overflow: hidden;
    transition: all 0.2s ease;
}

.calculator__display {
    color: var(--text-color);
    font-size: 2.5rem;
    text-align: right;
    word-wrap: break-word;
    word-break: break-all;
    overflow: hidden;
    transition: all 0.2s ease;
}

.calculator__keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.625rem;
    padding: 1.25rem;
    background-color: var(--keys-bg);
    border-radius: 1.25rem 1.25rem 0 0;
    margin-top: -1.25rem;
}

button {
    height: 3.4375rem;
    border: none;
    border-radius: 1rem;
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: var(--key-bg);
    color: var(--text-color);
    box-shadow: 0 0.1875rem 0.3125rem rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
}

button:hover {
    transform: translateY(-0.125rem);
    box-shadow: 0 0.3125rem 0.625rem rgba(0, 0, 0, 0.2);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 0.125rem 0.3125rem rgba(0, 0, 0, 0.1);
}

.key--operator {
    background-color: var(--key-operator-bg);
    color: var(--operator-color);
}

.key--function {
    background-color: var(--key-operator-bg);
    color: var(--function-color);
}

.key--memory {
    background-color: var(--key-operator-bg);
    color: var(--memory-color);
}

.key--equal {
    background-color: var(--key-equal-bg);
    color: var(--calculator-bg);
}

.key--zero {
    grid-column: span 1;
}

.is-depressed {
    transform: scale(0.95);
    box-shadow: 0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.1);
}

/* 错误状态显示 */
.calculator__display.error {
    color: var(--error-color);
}

/* 使用说明样式 */
.instructions {
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--instruction-bg);
    border-radius: 1rem;
    color: var(--instruction-text);
    width: 100%;
    max-width: 40rem;
    box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.1);
}

.instructions h2 {
    text-align: center;
    margin-bottom: 1rem;
    color: #333;
}

.tab-container {
    width: 100%;
}

.tab-buttons {
    display: flex;
    border-bottom: 1px solid #ddd;
    margin-bottom: 1rem;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    color: #666;
    cursor: pointer;
    height: auto;
    box-shadow: none;
    border-bottom: 3px solid transparent;
}

.tab-btn:hover {
    color: #333;
    transform: none;
    box-shadow: none;
}

.tab-btn.active {
    color: var(--tab-active-text);
    border-bottom: 3px solid var(--tab-active-bg);
    font-weight: bold;
}

.tab-content {
    padding: 0.5rem;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.tab-pane ul {
    padding-left: 1.5rem;
}

.tab-pane li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

footer {
    margin-top: 2rem;
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
    width: 100%;
}

/* 横屏模式样式调整 */
@media (orientation: landscape) and (max-height: 500px) {
    .calculator-container {
        flex-direction: row;
        align-items: flex-start;
    }

    .language-switcher {
        position: absolute;
        top: 1rem;
        right: 1rem;
    }

    .calculator {
        display: flex;
        max-width: 90%;
        height: 85vh;
    }

    .calculator__display-container {
        width: 35%;
        height: 100%;
        border-radius: 1.25rem 0 0 1.25rem;
        margin-bottom: 0;
    }

    .calculator__keys {
        width: 65%;
        margin-top: 0;
        border-radius: 0 1.25rem 1.25rem 0;
        padding: 0.625rem;
        gap: 0.5rem;
        grid-template-columns: repeat(5, 1fr);
        align-content: center;
        overflow-y: auto;
    }

    button {
        height: 2.5rem;
        font-size: 1.1rem;
    }

    .instructions {
        display: none;
    }
}

/* 大屏幕手机（横向） */
@media (min-width: 668px) and (max-width: 896px) and (orientation: landscape) {
    button {
        height: 2.8rem;
    }
}

/* 平板和大屏设备 */
@media (min-width: 768px) {
    .calculator-container {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 2rem;
    }

    .language-switcher {
        justify-content: flex-end;
        width: 100%;
        max-width: 100%;
    }

    .calculator {
        max-width: 28rem;
    }

    button {
        font-size: 1.6rem;
    }

    .calculator__expression {
        font-size: 1.5rem;
    }

    .calculator__display {
        font-size: 3rem;
    }

    .instructions {
        margin-top: 0;
        max-width: 30rem;
    }
}

/* 较小屏幕手机 */
@media (max-width: 375px) {
    .calculator__display-container {
        height: 8rem;
    }

    button {
        height: 3rem;
        font-size: 1.2rem;
    }

    .calculator__expression {
        font-size: 1.1rem;
    }

    .calculator__display {
        font-size: 2rem;
    }

    .calculator__keys {
        gap: 0.5rem;
        padding: 0.75rem;
    }

    .tab-buttons {
        flex-direction: column;
        border-bottom: none;
    }

    .tab-btn {
        border-bottom: none;
        border-left: 3px solid transparent;
        text-align: left;
    }

    .tab-btn.active {
        border-bottom: none;
        border-left: 3px solid var(--tab-active-bg);
    }
}

/* 超小屏幕设备 */
@media (max-width: 320px) {
    button {
        height: 2.5rem;
        font-size: 1rem;
    }

    .calculator__display-container {
        height: 7rem;
        padding: 0.75rem;
    }

    .calculator__expression {
        font-size: 1rem;
    }

    .calculator__display {
        font-size: 1.75rem;
    }

    .calculator__keys {
        gap: 0.4rem;
        padding: 0.625rem;
    }
}

/* 在高DPI设备上减少阴影和边框半径以提高性能 */
@media (-webkit-min-device-pixel-ratio: 3),
(min-resolution: 3dppx) {
    .calculator {
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.2);
    }

    button {
        box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.1);
    }
}

/* 适应深色模式 */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-gradient-start: #1a1a2e;
        --bg-gradient-end: #16213e;
        --instruction-bg: rgba(40, 44, 52, 0.9);
        --instruction-text: #e0e0e0;
    }

    .instructions h2 {
        color: #e0e0e0;
    }

    .tab-btn {
        color: #aaa;
    }

    .tab-btn:hover {
        color: #e0e0e0;
    }
}

/* 添加触摸反馈效果 */
@media (hover: none) {
    button:hover {
        transform: none;
        box-shadow: 0 0.1875rem 0.3125rem rgba(0, 0, 0, 0.1);
    }
}

/* 让语言按钮高亮显示当前选中的语言 */
html[data-current-lang="zh"] .lang-btn[data-lang="zh"],
html[data-current-lang="en"] .lang-btn[data-lang="en"] {
    background: #26f3cd;
    color: #272b33;
}

a {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}