/* 数学飞机大战 V2 - 狂暴进化版 */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a1a;
  font-family: 'Courier New', monospace;
}

#gameCanvas {
  display: block;
  background: linear-gradient(180deg, #0a0a1a 0%, #1a1a3e 50%, #2a1a4e 100%);
}

/* ==================== HUD 系统 ==================== */
#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* 顶部信息栏 */
#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
  z-index: 100;
  pointer-events: auto;
  font-size: 12px;
  gap: 5px;
  flex-wrap: wrap;
}

.hud-item {
  background: rgba(0, 0, 0, 0.6);
  padding: 6px 10px;
  border-radius: 6px;
  border: 2px solid;
  transition: all 0.3s;
}

.hud-item.gold {
  border-color: #ffd700;
  color: #ffd700;
}

.hud-item.red {
  border-color: #ff6b6b;
  color: #ff6b6b;
}

.hud-item.cyan {
  border-color: #00ffff;
  color: #00ffff;
}

.hud-item.clickable {
  cursor: pointer;
}

.hud-item.clickable:hover {
  transform: scale(1.05);
  filter: brightness(1.2);
}

/* 金币动画 */
@keyframes coin-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.coin-icon {
  display: inline-block;
  animation: coin-bounce 0.5s ease-in-out infinite;
}

/* ==================== 商店系统 ==================== */
#shop-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 400px;
  background: linear-gradient(145deg, #1a1a3e, #0a0a1a);
  border: 3px solid #ffd700;
  border-radius: 16px;
  padding: 20px;
  z-index: 300;
  display: none;
  pointer-events: auto;
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
}

#shop-panel.show {
  display: block;
  animation: shop-popup 0.3s ease-out;
}

@keyframes shop-popup {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.shop-title {
  text-align: center;
  color: #ffd700;
  font-size: 24px;
  margin-bottom: 15px;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.shop-coins {
  text-align: center;
  color: #ffa500;
  font-size: 18px;
  margin-bottom: 20px;
}

.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid #444;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.shop-item:hover {
  background: rgba(255, 215, 0, 0.1);
  border-color: #ffd700;
  transform: translateX(5px);
}

.shop-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.shop-item-icon {
  font-size: 28px;
  margin-right: 12px;
}

.shop-item-info {
  flex: 1;
}

.shop-item-name {
  color: #fff;
  font-weight: bold;
  font-size: 14px;
}

.shop-item-desc {
  color: #888;
  font-size: 11px;
}

.shop-item-price {
  color: #ffa500;
  font-weight: bold;
  font-size: 16px;
}

.shop-close {
  width: 100%;
  padding: 12px;
  margin-top: 15px;
  background: linear-gradient(145deg, #ff6b6b, #cc4444);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.shop-close:hover {
  filter: brightness(1.2);
}

/* ==================== Boss系统 ==================== */
#boss-hud {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  max-width: 400px;
  z-index: 90;
  display: none;
  pointer-events: none;
}

#boss-hud.show {
  display: block;
}

.boss-name {
  text-align: center;
  color: #ff4444;
  font-size: 18px;
  font-weight: bold;
  text-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
  margin-bottom: 5px;
}

.boss-hp-bar {
  width: 100%;
  height: 20px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #ff4444;
  border-radius: 10px;
  overflow: hidden;
}

.boss-hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff4444, #ff8888);
  transition: width 0.3s ease-out;
  box-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
}

/* Boss警告 */
#boss-warning {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ff0000;
  font-size: 48px;
  font-weight: bold;
  text-shadow: 0 0 20px rgba(255, 0, 0, 0.8);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
}

#boss-warning.show {
  animation: boss-warning-flash 2s ease-in-out;
}

@keyframes boss-warning-flash {
  0%, 100% { opacity: 0; }
  10%, 30%, 50% { opacity: 1; }
  20%, 40% { opacity: 0.3; }
}

/* ==================== 成就系统 ==================== */
#achievement-popup {
  position: absolute;
  top: 100px;
  right: -300px;
  background: linear-gradient(145deg, #2a1a4e, #1a0a2e);
  border: 2px solid #ffd700;
  border-radius: 12px;
  padding: 15px 20px;
  z-index: 250;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
  transition: right 0.5s ease-out;
}

#achievement-popup.show {
  right: 10px;
}

.achievement-icon {
  font-size: 32px;
}

.achievement-text {
  color: #fff;
}

.achievement-title {
  font-size: 14px;
  color: #ffd700;
  font-weight: bold;
}

.achievement-name {
  font-size: 12px;
  color: #aaa;
}

/* ==================== 数字键盘 ==================== */
#math-panel {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  border: 2px solid #ffd700;
  border-radius: 12px;
  text-align: center;
  bottom: 210px;  /* 提高位置避免挡住飞机 */
  padding: 10px 18px;
  min-width: 140px;
  z-index: 50;
  transition: opacity 0.2s ease;
}

#math-panel.inputting {
  opacity: 0.4;  /* 输入时变淡 */
}

#question {
  color: #fff;
  font-size: 18px;
  margin-bottom: 4px;
  font-weight: bold;
  transition: opacity 0.2s ease;
}

#question.dimmed {
  opacity: 0.3;
}

#answer-display {
  color: #ffd700;
  font-size: 28px;
  min-height: 34px;
  letter-spacing: 6px;
  font-weight: bold;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

/* 连击显示 */
#combo {
  position: absolute;
  top: 50px;
  right: 10px;
  text-align: right;
  font-size: 18px;
  text-shadow: 2px 2px 0 #000;
  pointer-events: none;
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  padding: 5px 10px;
  border-radius: 8px;
}

#combo-count {
  color: #ff6b6b;
  font-weight: bold;
}

#combo-text {
  color: #ffd700;
}

/* ==================== 技能特效 ==================== */
.skill-active {
  animation: skill-pulse 0.5s ease-in-out infinite;
}

@keyframes skill-pulse {
  0%, 100% { box-shadow: 0 0 10px currentColor; }
  50% { box-shadow: 0 0 30px currentColor; }
}

/* 冻结效果 */
.freeze-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 200, 255, 0.2);
  z-index: 80;
  pointer-events: none;
  display: none;
}

.freeze-overlay.show {
  display: block;
  animation: freeze-in 0.3s ease-out;
}

@keyframes freeze-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* 护盾效果 */
.shield-overlay {
  position: absolute;
  bottom: 200px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 80px;
  border: 4px solid #00ff88;
  border-radius: 50%;
  z-index: 45;
  display: none;
  animation: shield-rotate 2s linear infinite;
}

.shield-overlay.show {
  display: block;
}

@keyframes shield-rotate {
  from { transform: translateX(-50%) rotate(0deg); }
  to { transform: translateX(-50%) rotate(360deg); }
}

/* ==================== 狂暴模式 ==================== */
#fever-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ff0000;
  font-size: 36px;
  font-weight: bold;
  text-shadow: 0 0 20px rgba(255, 0, 0, 0.8);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
}

#fever-indicator.show {
  animation: fever-text 0.5s ease-out forwards;
}

@keyframes fever-text {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* ==================== 数字键盘 ==================== */
#keypad {
  position: absolute;
  bottom: 15px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(6, 50px);
  grid-template-rows: repeat(2, 55px);
  gap: 8px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 12px;
  pointer-events: auto;
  z-index: 50;
}

.key {
  width: 50px;
  height: 55px;
  font-size: 22px;
  background: linear-gradient(145deg, #3a3a5a, #1a1a3e);
  border: 2px solid #555;
  border-radius: 10px;
  color: #fff;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.1s;
  box-shadow: 0 4px 0 #000;
}

.key:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #000;
}

.key[data-num="0"] {
  grid-column: span 2;
  width: 108px;
}

.key.clear {
  background: linear-gradient(145deg, #5a2a2a, #2a1a1a);
  border-color: #ff4444;
  color: #ff4444;
}

/* ==================== 开始/结束画面 ==================== */
#overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  z-index: 400;
  pointer-events: auto;
}

#overlay h1 {
  color: #ffd700;
  font-size: 42px;
  margin-bottom: 20px;
  text-shadow: 3px 3px 0 #ff4444, 0 0 30px rgba(255, 215, 0, 0.5);
}

#overlay .subtitle {
  color: #ff6b6b;
  font-size: 18px;
  margin-bottom: 10px;
}

#overlay .features {
  color: #aaa;
  font-size: 13px;
  line-height: 1.8;
  text-align: center;
  margin: 15px 0;
}

#overlay .features span {
  color: #ffd700;
}

.btn {
  margin-top: 25px;
  padding: 18px 50px;
  font-size: 26px;
  background: linear-gradient(145deg, #ff6b6b, #cc4444);
  border: none;
  border-radius: 35px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 0 #992222, 0 0 20px rgba(255, 107, 107, 0.4);
  transition: all 0.1s;
}

.btn:hover {
  filter: brightness(1.1);
}

.btn:active {
  transform: translateY(6px);
  box-shadow: 0 0 0 #992222;
}

/* 成就展示 */
.achievements-showcase {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 300px;
}

.achievements-showcase .achievement-badge {
  font-size: 24px;
  opacity: 0.3;
  filter: grayscale(1);
  transition: all 0.3s;
}

.achievements-showcase .achievement-badge.unlocked {
  opacity: 1;
  filter: grayscale(0);
  animation: badge-glow 2s ease-in-out infinite;
}

@keyframes badge-glow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* ==================== 特效层 ==================== */
.nuke-flash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(255,255,255,0.95) 0%, rgba(255,200,0,0.6) 30%, transparent 70%);
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  transition: opacity 0.1s ease-out;
}

.nuke-flash.show {
  opacity: 1;
}

/* 伤害数字 */
.damage-number {
  position: absolute;
  color: #ff4444;
  font-size: 20px;
  font-weight: bold;
  text-shadow: 0 0 5px rgba(0,0,0,0.8);
  pointer-events: none;
  z-index: 60;
  animation: damage-float 1s ease-out forwards;
}

@keyframes damage-float {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-50px) scale(1.5); }
}

/* 金币飞行动画 */
.coin-float {
  position: absolute;
  color: #ffd700;
  font-size: 20px;
  font-weight: bold;
  pointer-events: none;
  z-index: 60;
  animation: coin-float-anim 1s ease-out forwards;
}

@keyframes coin-float-anim {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-80px) scale(0.5); }
}

/* 触摸提示 */
.touch-hint {
  transition: opacity 0.3s ease;
}

/* 隐藏的控制按钮 */
#controls {
  display: none;
}

/* 飞机选择器 */
.plane-selector {
  display: flex;
  gap: 15px;
  margin: 20px 0;
  justify-content: center;
}

.plane-option {
  width: 80px;
  height: 80px;
  background: rgba(255, 255, 255, 0.1);
  border: 3px solid #444;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
}

.plane-option:hover {
  border-color: #ffd700;
  background: rgba(255, 215, 0, 0.1);
}

.plane-option.selected {
  border-color: #00ff88;
  background: rgba(0, 255, 136, 0.1);
  box-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
}

.plane-option .plane-icon {
  font-size: 32px;
}

.plane-option .plane-name {
  font-size: 10px;
  color: #aaa;
  margin-top: 4px;
}
