/* Cosmic Merge 游戏特有样式 */

/* 宇宙融合主题的画布样式 */
canvas {
  background: 
    linear-gradient(135deg, #0f0f23 0%, #1a1a3a 25%, #2d1b69 50%, #1a1a3a 75%, #0f0f23 100%),
    radial-gradient(circle at 25% 25%, rgba(128, 0, 255, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 75% 75%, rgba(0, 255, 255, 0.1) 0%, transparent 60%);
  border: 2px solid rgba(128, 0, 255, 0.4);
  border-radius: 16px;
  animation: cosmic-pulse 5s ease-in-out infinite;
  display: block;
  touch-action: pan-x pan-y;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  box-sizing: border-box;
}

@keyframes cosmic-pulse {
  0%, 100% { 
    box-shadow: 
      0 0 30px rgba(0, 0, 0, 0.7),
      inset 0 0 50px rgba(128, 0, 255, 0.05);
  }
  50% { 
    box-shadow: 
      0 0 60px rgba(128, 0, 255, 0.4),
      inset 0 0 50px rgba(0, 255, 255, 0.1);
  }
}

/* 重新定义主体容器 */
body {
  /* 防止移动端下拉刷新和左滑返回 */
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  min-height: 0;
  padding: 1rem;
  padding-bottom: 0.5rem;
  box-sizing: border-box;
  position: relative;
  z-index: 2;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* 确保canvas容器能够获得剩余空间 */
main > canvas {
  flex: 1;
  width: 100% !important;
  height: auto !important;
  min-height: 350px;
  max-height: 80vh;
}

/* 分数显示区域优化 */
.score-display {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 500px;
  margin: 0 auto 0.5rem auto;
  padding: 0 1rem;
  box-sizing: border-box;
  z-index: 10;
  position: relative;
  flex-shrink: 0;
  gap: 0.5rem;
}

/* Settings button */
.settings-btn {
  background: linear-gradient(135deg, rgba(128, 0, 255, 0.3), rgba(128, 0, 255, 0.15));
  border: 1px solid rgba(128, 0, 255, 0.4);
  color: #fff;
  width: 45px;
  height: 45px;
  border-radius: 50%;
  font-size: 1.3rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(15px);
  flex-shrink: 0;
}

.settings-btn:hover {
  transform: rotate(90deg) scale(1.1);
  box-shadow: 0 0 20px rgba(128, 0, 255, 0.6);
  border-color: rgba(128, 0, 255, 0.8);
}

.settings-btn:active {
  transform: rotate(90deg) scale(0.95);
}

/* Settings menu */
.settings-menu {
  position: absolute;
  top: 60px;
  right: 1rem;
  background: linear-gradient(135deg, rgba(15, 15, 35, 0.98), rgba(26, 26, 58, 0.98));
  border: 2px solid rgba(128, 0, 255, 0.5);
  border-radius: 15px;
  padding: 1rem;
  min-width: 250px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(128, 0, 255, 0.3);
  backdrop-filter: blur(20px);
  z-index: 1000;
  opacity: 0;
  transform: translateY(-10px) scale(0.95);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.settings-menu.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.settings-header {
  color: #FFD700;
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(128, 0, 255, 0.3);
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.menu-btn {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  padding: 0.8rem 1rem;
  margin: 0.3rem 0;
  background: rgba(128, 0, 255, 0.15);
  border: 1px solid rgba(128, 0, 255, 0.3);
  border-radius: 10px;
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.menu-btn:hover {
  background: rgba(128, 0, 255, 0.3);
  border-color: rgba(128, 0, 255, 0.6);
  transform: translateX(5px);
  box-shadow: 0 4px 15px rgba(128, 0, 255, 0.4);
}

.menu-btn:active {
  transform: translateX(5px) scale(0.98);
}

.menu-btn-danger {
  background: rgba(255, 50, 50, 0.15);
  border-color: rgba(255, 50, 50, 0.3);
}

.menu-btn-danger:hover {
  background: rgba(255, 50, 50, 0.3);
  border-color: rgba(255, 50, 50, 0.6);
  box-shadow: 0 4px 15px rgba(255, 50, 50, 0.4);
}

.btn-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.btn-text {
  flex: 1;
}

/* Toast notification */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: linear-gradient(135deg, rgba(76, 175, 80, 0.95), rgba(56, 142, 60, 0.95));
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 10px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3), 0 0 20px rgba(76, 175, 80, 0.4);
  z-index: 10000;
  font-size: 0.95rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: linear-gradient(135deg, rgba(244, 67, 54, 0.95), rgba(211, 47, 47, 0.95));
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3), 0 0 20px rgba(244, 67, 54, 0.4);
}

.toast.warning {
  background: linear-gradient(135deg, rgba(255, 152, 0, 0.95), rgba(245, 124, 0, 0.95));
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3), 0 0 20px rgba(255, 152, 0, 0.4);
}

.settings-divider {
  height: 1px;
  background: rgba(128, 0, 255, 0.2);
  margin: 0.5rem 0;
}

/* ====== 墨水屏模式样式 ====== */
body.eink-mode {
  background: #fff !important;
}

body.eink-mode header {
  background: #fff !important;
  border-bottom: 2px solid #000;
}

body.eink-mode header h1 {
  color: #000 !important;
  text-shadow: none !important;
}

body.eink-mode header p {
  color: #333 !important;
  text-shadow: none !important;
}

body.eink-mode .score-item {
  background: #fff !important;
  color: #000 !important;
  border: 2px solid #000 !important;
  box-shadow: none !important;
  text-shadow: none !important;
  backdrop-filter: none !important;
}

body.eink-mode .score-item:hover {
  transform: none !important;
  box-shadow: none !important;
}

body.eink-mode .settings-btn {
  background: #fff !important;
  border: 2px solid #000 !important;
  color: #000 !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

body.eink-mode .settings-btn:hover {
  box-shadow: none !important;
}

body.eink-mode canvas {
  background: #fff !important;
  border: 3px solid #000 !important;
  border-radius: 0 !important;
  animation: none !important;
  box-shadow: none !important;
}

body.eink-mode .control-btn {
  background: #fff !important;
  color: #000 !important;
  border: 2px solid #000 !important;
  box-shadow: none !important;
  text-shadow: none !important;
}

body.eink-mode .control-btn:hover {
  background: #f0f0f0 !important;
  transform: none !important;
  box-shadow: none !important;
}

body.eink-mode .settings-menu {
  background: #fff !important;
  border: 2px solid #000 !important;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
  backdrop-filter: none !important;
}

body.eink-mode .settings-header {
  color: #000 !important;
  border-bottom: 1px solid #000 !important;
  text-shadow: none !important;
}

body.eink-mode .menu-btn {
  background: #fff !important;
  border: 1px solid #000 !important;
  color: #000 !important;
}

body.eink-mode .menu-btn:hover {
  background: #f0f0f0 !important;
  border-color: #000 !important;
  box-shadow: none !important;
}

body.eink-mode .menu-btn-danger {
  background: #fff !important;
  border: 1px solid #000 !important;
}

body.eink-mode .menu-btn-danger:hover {
  background: #f0f0f0 !important;
  border-color: #000 !important;
  box-shadow: none !important;
}

body.eink-mode .settings-divider {
  background: #ccc !important;
}

.score-item {
  background: 
    linear-gradient(135deg, rgba(128, 0, 255, 0.2), rgba(128, 0, 255, 0.1)),
    rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 0.8rem 1.2rem;
  border-radius: 25px;
  font-size: 0.9rem;
  font-weight: 600;
  backdrop-filter: blur(15px);
  border: 1px solid rgba(128, 0, 255, 0.3);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  overflow: hidden;
  text-shadow: 0 0 10px rgba(128, 0, 255, 0.5);
}

.score-item:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 
    0 8px 25px rgba(0, 0, 0, 0.3),
    0 0 20px rgba(128, 0, 255, 0.4);
  border-color: rgba(128, 0, 255, 0.6);
}

.score-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.score-item:hover::before {
  left: 100%;
}

/* 分数增加动画 */
@keyframes scoreIncrease {
  0% {
    transform: scale(1);
    color: #fff;
    text-shadow: 0 0 10px rgba(128, 0, 255, 0.5);
  }
  50% {
    transform: scale(1.15);
    color: #00ffff;
    text-shadow: 0 0 20px rgba(0, 255, 255, 0.8);
  }
  100% {
    transform: scale(1);
    color: #fff;
    text-shadow: 0 0 10px rgba(128, 0, 255, 0.5);
  }
}

.score-animate {
  animation: scoreIncrease 0.5s ease-out;
}

/* 游戏特定的头部样式 */
header {
  padding: 1rem;
  flex-shrink: 0;
}

header p {
  color: rgba(255, 255, 255, 0.8);
  font-size: 1rem;
  margin-top: 0.5rem;
  margin-bottom: 0;
  text-shadow: 0 0 10px rgba(128, 0, 255, 0.3);
}

/* 游戏瓦片动画效果 */
.tile-moving {
  transition: transform 0.2s ease-in-out;
}

.tile-appear {
  animation: tileAppear 0.3s ease-out;
}

.tile-merge {
  animation: tileMerge 0.4s ease-out;
}

@keyframes tileAppear {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes tileMerge {
  0% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

/* 移动端优化 */
@media (max-width: 768px) {
  header h1 {
    font-size: 1.8rem;
  }
  
  header p {
    font-size: 0.9rem;
  }
  
  .score-display {
    padding: 0 0.5rem;
    gap: 0.3rem;
  }
  
  .score-item {
    padding: 0.6rem 1rem;
    font-size: 0.8rem;
  }
  
  .settings-btn {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }
  
  .settings-menu {
    right: 0.5rem;
    left: 0.5rem;
    min-width: auto;
  }
  
  .menu-btn {
    padding: 0.7rem 0.8rem;
    font-size: 0.85rem;
  }
  
  .btn-icon {
    font-size: 1.1rem;
  }
  
  .toast {
    max-width: 90%;
    font-size: 0.85rem;
    padding: 0.8rem 1rem;
  }
}