/* ========================================
   仿小米计算器 — 全局样式与主题变量
   ======================================== */

/* ---------- CSS 变量：深色模式（默认） ---------- */
:root {
  --bg-primary: #000000;
  --bg-display: #000000;
  --bg-btn-num: #2a2a2a;
  --bg-btn-func: #1a1a1a;
  --bg-btn-op: #1a1a1a;
  --bg-btn-equal: #ff6b35;
  --text-primary: #ffffff;
  --text-secondary: #8e8e93;
  --text-func: #a8d8a8;
  --text-op: #ff6b35;
  --text-equal: #ffffff;
  --btn-active-scale: 0.92;
  --btn-radius: 24px;
  --shadow-btn: 0 2px 8px rgba(0, 0, 0, 0.3);
  --transition-speed: 0.2s;
}

/* ---------- CSS 变量：浅色模式 ---------- */
[data-theme="light"] {
  --bg-primary: #f5f5f7;
  --bg-display: #f5f5f7;
  --bg-btn-num: #ffffff;
  --bg-btn-func: #e8e8ed;
  --bg-btn-op: #e8e8ed;
  --bg-btn-equal: #ff6b35;
  --text-primary: #1c1c1e;
  --text-secondary: #8e8e93;
  --text-func: #34c759;
  --text-op: #ff6b35;
  --text-equal: #ffffff;
  --shadow-btn: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* ---------- 全局重置 ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
               'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica,
               Arial, sans-serif;
  background-color: var(--bg-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color var(--transition-speed) ease;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ========================================
   计算器容器
   ======================================== */
.calculator {
  width: 100%;
  max-width: 420px;
  height: 100vh;
  max-height: 812px;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  transition: background-color var(--transition-speed) ease;
  position: relative;
  overflow: hidden;
}

/* ========================================
   顶栏
   ======================================== */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 8px;
  flex-shrink: 0;
}

.top-bar-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  transition: color var(--transition-speed) ease;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg-btn-func);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed) ease;
}

.theme-toggle:active {
  transform: scale(0.9);
}

/* 深色模式显示月亮图标，隐藏太阳图标 */
.icon-sun { display: none; }
.icon-moon { display: block; }

[data-theme="light"] .icon-sun { display: block; }
[data-theme="light"] .icon-moon { display: none; }

/* ========================================
   显示区域
   ======================================== */
.display {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 24px 20px;
  min-height: 0;
  overflow: hidden;
}

.history {
  font-size: 18px;
  color: var(--text-secondary);
  text-align: right;
  min-height: 28px;
  line-height: 28px;
  word-break: break-all;
  overflow-y: auto;
  max-height: 80px;
  padding-bottom: 4px;
  transition: color var(--transition-speed) ease;
}

.current {
  font-size: 56px;
  font-weight: 300;
  color: var(--text-primary);
  text-align: right;
  line-height: 1.15;
  word-break: break-all;
  min-height: 64px;
  transition: color var(--transition-speed) ease, font-size 0.15s ease;
}

/* 数字太长时自动缩小字号 */
.current.shrink-1 { font-size: 44px; }
.current.shrink-2 { font-size: 34px; }
.current.shrink-3 { font-size: 26px; }

/* ========================================
   按钮网格
   ======================================== */
.buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 12px 16px 32px;
  flex-shrink: 0;
}

.btn {
  height: 64px;
  border: none;
  border-radius: var(--btn-radius);
  font-size: 24px;
  font-weight: 400;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
  box-shadow: var(--shadow-btn);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

/* 按钮按下涟漪动画 */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--ripple-x, 50%) var(--ripple-y, 50%),
              rgba(255,255,255,0.15) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.btn:active::after {
  opacity: 1;
}

.btn:active {
  transform: scale(var(--btn-active-scale));
}

/* ---------- 数字键 ---------- */
.btn-num {
  background-color: var(--bg-btn-num);
  color: var(--text-primary);
}

/* ---------- 0 键横跨两列 ---------- */
.btn-zero {
  grid-column: span 2;
  border-radius: var(--btn-radius);
}

/* ---------- 功能键 (C / ⌫ / %) ---------- */
.btn-func {
  background-color: var(--bg-btn-func);
  color: var(--text-func);
  font-size: 20px;
}

/* ---------- 运算符键 (÷ × − +) ---------- */
.btn-op {
  background-color: var(--bg-btn-op);
  color: var(--text-op);
  font-size: 28px;
  font-weight: 500;
}

/* 运算符选中高亮 */
.btn-op.active {
  background-color: var(--text-op);
  color: var(--bg-primary);
}

/* ---------- 等号键 — 小米标志性橘红色 ---------- */
.btn-equal {
  background-color: var(--bg-btn-equal);
  color: var(--text-equal);
  font-size: 32px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(255, 107, 53, 0.35);
}

.btn-equal:active {
  box-shadow: 0 2px 8px rgba(255, 107, 53, 0.5);
  background-color: #e55a28;
}

/* ========================================
   响应式适配
   ======================================== */
@media (max-height: 680px) {
  .btn {
    height: 54px;
    font-size: 20px;
  }
  .current {
    font-size: 44px;
  }
  .buttons {
    gap: 8px;
    padding: 8px 12px 20px;
  }
}

@media (min-width: 500px) {
  .calculator {
    border-radius: 32px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    height: 90vh;
  }
}

/* ========================================
   过渡动画
   ======================================== */
.display-flash {
  animation: flash 0.15s ease;
}

@keyframes flash {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}
