/* 科学计算器 - 极简工具风格 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #f5f5f5;
    --surface: #fff;
    --border: #e0e0e0;
    --text: #1a1a1a;
    --text-muted: #666;
    --num-bg: #fafafa;
    --num-hover: #f0f0f0;
    --fn-bg: #eee;
    --fn-hover: #e5e5e5;
    --op-bg: #e0e0e0;
    --op-hover: #d5d5d5;
    --clear-bg: #d32f2f;
    --clear-hover: #b71c1c;
    --equals-bg: #1976d2;
    --equals-hover: #1565c0;
    --screen-bg: #1e1e1e;
    --screen-text: #e8e8e8;
    --screen-muted: #9e9e9e;
    --radius: 6px;
    --radius-sm: 4px;
}

body {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px;
    -webkit-font-smoothing: antialiased;
    color: var(--text);
}

/* 主内容区与说明区统一宽度，整体居中 */
.container {
    display: flex;
    gap: 24px;
    max-width: 960px;
    width: 100%;
    align-items: flex-start;
    justify-content: center;
}

.calculator {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    width: 100%;
    min-width: 0;
    max-width: 640px;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.header h1 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.history-btn {
    background: var(--fn-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    color: var(--text);
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.history-btn:hover {
    background: var(--fn-hover);
}

.history-btn:active {
    background: var(--op-bg);
}

.display-container {
    background: var(--screen-bg);
    border-radius: var(--radius-sm);
    padding: 20px 24px;
    margin-bottom: 20px;
}

.display {
    text-align: right;
    min-height: 80px;
}

.expression {
    font-size: 0.875rem;
    color: var(--screen-muted);
    margin-bottom: 8px;
    min-height: 20px;
}

.result {
    font-size: 2.25rem;
    font-weight: 400;
    letter-spacing: -0.02em;
    word-break: break-all;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    color: var(--screen-text);
    font-variant-numeric: tabular-nums;
}

.scientific-buttons {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 8px;
}

.btn {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    background: var(--num-bg);
    color: var(--text);
}

.btn:active {
    opacity: 0.92;
}

.btn.number {
    background: var(--num-bg);
}

.btn.number:hover {
    background: var(--num-hover);
}

.btn.operator {
    background: var(--op-bg);
    color: var(--text);
}

.btn.operator:hover {
    background: var(--op-hover);
}

.btn.function {
    background: var(--fn-bg);
    font-size: 0.8125rem;
}

.btn.function:hover {
    background: var(--fn-hover);
}

.btn.clear {
    background: var(--clear-bg);
    color: #fff;
    border-color: var(--clear-bg);
}

.btn.clear:hover {
    background: var(--clear-hover);
    border-color: var(--clear-hover);
}

.btn.equals {
    background: var(--equals-bg);
    color: #fff;
    border-color: var(--equals-bg);
}

.btn.equals:hover {
    background: var(--equals-hover);
    border-color: var(--equals-hover);
}

.btn.zero {
    grid-column: span 2;
}

.history-panel {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    width: 280px;
    max-height: 420px;
    border: 1px solid var(--border);
    display: none;
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.history-panel.show {
    display: block;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.history-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.clear-history {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.clear-history:hover {
    background: var(--fn-bg);
}

.history-list {
    max-height: 340px;
    overflow-y: auto;
}

.history-item {
    background: var(--num-bg);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 6px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: background-color 0.12s ease;
}

.history-item:hover {
    background: var(--fn-bg);
}

.history-expression {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-bottom: 2px;
}

.history-result {
    color: var(--text);
    font-size: 0.9375rem;
    font-weight: 500;
}

.no-history {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin-top: 24px;
}

/* 使用说明区域：与计算器同宽，居中且不随布局偏移 */
.info-section {
    width: 100%;
    margin: 32px 0 24px;
    padding: 0 16px;
}

.info-container {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px 24px;
    border: 1px solid var(--border);
    width: 100%;
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
}

.info-container h2 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.steps-section {
    margin-bottom: 20px;
}

.steps-section h3 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.steps-list {
    margin: 0;
    padding-left: 1.25rem;
    color: var(--text);
    font-size: 0.8125rem;
    line-height: 1.65;
}

.steps-list li {
    margin-bottom: 4px;
}

.steps-list li:last-child {
    margin-bottom: 0;
}

.examples-section {
    margin-bottom: 20px;
}

.examples-section h3 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.examples-grid {
    display: grid;
    gap: 8px;
}

.example-item {
    background: var(--num-bg);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    border: 1px solid var(--border);
}

.example-title {
    font-weight: 500;
    font-size: 0.8125rem;
    color: var(--text);
    margin-bottom: 4px;
}

.example-expr {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-bottom: 2px;
}

.example-result {
    color: var(--equals-bg);
    font-size: 0.75rem;
    font-weight: 500;
}

.faq-section {
    margin-bottom: 20px;
}

.faq-section h3 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.faq-list {
    display: grid;
    gap: 8px;
}

.faq-item {
    background: var(--num-bg);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    border: 1px solid var(--border);
    overflow: visible;
}

.faq-q {
    font-weight: 500;
    font-size: 0.8125rem;
    color: var(--text);
    margin-bottom: 4px;
}

.faq-a {
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.55;
    word-wrap: break-word;
}

.keyboard-shortcuts {
    margin-bottom: 0;
}

.keyboard-shortcuts h3 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 6px 16px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border: none;
    background: none;
}

.shortcut-item .key {
    background: var(--fn-bg);
    color: var(--text);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.75rem;
    min-width: 42px;
    text-align: center;
    border: 1px solid var(--border);
}

.shortcut-item .desc {
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.35;
    flex: 1;
}

.footer {
    margin-top: 20px;
    margin-bottom: 24px;
    text-align: center;
}

.footer p {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.footer a {
    color: var(--text-muted);
    text-decoration: none;
}

.footer a:hover {
    color: var(--text);
}

@media (max-width: 768px) {
    .container {
        flex-direction: column;
        align-items: center;
    }

    .calculator {
        margin-bottom: 16px;
    }

    .history-panel {
        width: 100%;
        max-width: 100%;
    }

    .scientific-buttons {
        grid-template-columns: repeat(5, 1fr);
    }

    .btn {
        height: 42px;
        font-size: 0.875rem;
    }

    .result {
        font-size: 1.75rem;
    }

    .info-container {
        padding: 16px 20px;
    }

    .shortcuts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .scientific-buttons {
        grid-template-columns: repeat(4, 1fr);
    }

    .btn {
        height: 40px;
        font-size: 0.8125rem;
    }

    .result {
        font-size: 1.5rem;
    }
}

.error {
    color: var(--clear-bg) !important;
}

/* 滚动条样式 */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: var(--fn-bg);
    border-radius: 2px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--op-bg);
    border-radius: 2px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--op-hover);
}
