* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  overflow: hidden;
}

.calculator {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 10px;
  max-width: 500px;
  margin: 0 auto;
}

/* 显示屏 */
.display {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  padding: 20px 15px;
  background: #000;
  min-height: 0;
  overflow: hidden;
}

.expression-text {
  color: #999;
  font-weight: 300;
  text-align: right;
  line-height: 1.2;
  margin-bottom: 5px;
  min-height: 24px;
  max-width: 100%;
  overflow: hidden;
  word-break: break-all;
  transition: font-size 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: font-size, color, opacity;
}

.display-text {
  color: #fff;
  font-weight: 200;
  text-align: right;
  line-height: 1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: font-size 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: font-size, color, opacity;
}

/* 输入状态 */
.expression-text.input-mode {
  font-size: 36px;
  color: #fff;
  opacity: 1;
}

.display-text.input-mode {
  font-size: 28px;
  color: #999;
  opacity: 1;
}

/* 结果状态 */
.expression-text.result-mode {
  font-size: 28px;
  color: #999;
  opacity: 1;
}

.display-text.result-mode {
  font-size: 50px;
  color: #fff;
  opacity: 1;
}

/* 初始状态 */
.expression-text.initial-mode {
  font-size: 0;
  opacity: 0;
  height: 0;
  margin-bottom: 0;
}

.display-text.initial-mode {
  font-size: 60px;
  color: #fff;
  opacity: 1;
}

/* 按钮区域 */
.buttons {
  flex: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 500px;
}

.button-row {
  display: flex;
  gap: 10px;
  flex: 1;
}

/* 按钮基础样式 */
.btn {
  flex: 1;
  border-radius: 40px;
  border: none;
  font-size: 28px;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s ease, transform 0.1s ease;
  position: relative;
  overflow: hidden;
  outline: none;
  -webkit-appearance: none;
}

.btn:active {
  transform: scale(0.95);
}

/* 数字按钮 */
.btn-number {
  background: #333;
  color: #fff;
}

.btn-number:hover {
  background: #444;
}

.btn-number:active {
  background: #666;
}

/* 功能按钮 */
.btn-function {
  background: #a6a6a6;
  color: #000;
}

.btn-function:hover {
  background: #bbb;
}

.btn-function:active {
  background: #d9d9d9;
}

/* 运算符按钮 */
.btn-operator {
  background: #ff9500;
  color: #fff;
}

.btn-operator:hover {
  background: #ffaa33;
}

.btn-operator:active {
  background: #ffb143;
}

.btn-operator.active-op {
  background: #fff;
  color: #ff9500;
}

/* 0按钮特殊样式 */
.btn-zero {
  flex: 2;
  justify-content: flex-start;
  padding-left: 28px;
}

/* 响应式 */
@media screen and (max-height: 600px) {
  .display-text.initial-mode { font-size: 48px; }
  .display-text.result-mode { font-size: 40px; }
  .btn { font-size: 22px; }
  .buttons { gap: 6px; }
  .button-row { gap: 6px; }
}

@media screen and (min-width: 501px) {
  .buttons {
    max-height: 600px;
  }
}

/* 历史记录按钮 */
.btn-history {
  position: absolute;
  top: 12px;
  right: 15px;
  background: none;
  border: none;
  color: #666;
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: color 0.2s, background 0.2s;
  z-index: 10;
  line-height: 1;
}
.btn-history:hover { color: #fff; background: #222; }
.btn-history.active { color: #ff9500; }

/* 历史记录面板 */
.history-panel {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000;
  z-index: 20;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.history-panel.open {
  transform: translateX(0);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #222;
  flex-shrink: 0;
}
.history-header h2 {
  color: #fff;
  font-size: 20px;
  font-weight: 500;
}
.history-close {
  background: none;
  border: none;
  color: #999;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
}
.history-close:hover { color: #fff; background: #222; }

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }

.history-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid #111;
  gap: 12px;
}
.history-item:hover { background: #111; }
.history-item:active { background: #1a1a1a; }
.history-item-content {
  flex: 1;
  min-width: 0;
}
.history-item-expr {
  color: #888;
  font-size: 14px;
  margin-bottom: 4px;
  word-break: break-all;
}
.history-item-result {
  color: #fff;
  font-size: 22px;
  font-weight: 300;
}
.history-item-delete {
  background: none;
  border: none;
  color: #555;
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.history-item-delete:hover { color: #ff6b6b; background: #1a1a1a; }

.history-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #444;
  font-size: 16px;
}

.history-footer {
  padding: 12px 20px;
  border-top: 1px solid #222;
  flex-shrink: 0;
}
.btn-clear-history {
  width: 100%;
  padding: 12px;
  background: #1a1a1a;
  border: none;
  color: #ff6b6b;
  font-size: 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-clear-history:hover { background: #222; }
.btn-clear-history:active { background: #2a2a2a; }

.calculator {
  position: relative;
}
