* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Courier New', monospace;
  background: #000;
  color: #fff;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

#auth-bar {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 100;
}

#rotate-hint {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #000;
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #00ff00;
  font-family: 'Courier New', monospace;
}

.rotate-icon {
  font-size: 60px;
  margin-bottom: 20px;
  animation: rotate-anim 1.5s ease-in-out infinite;
}

@media (orientation: landscape) and (max-height: 500px) {
  #rotate-hint { display: flex !important; }
  #loading-screen, #menu-screen, #leaderboard-screen, #achievements-screen, #game-canvas { display: none !important; }
}

@keyframes rotate-anim {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}

/* === 菜单背景动画 === */
#loading-screen, #menu-screen, #leaderboard-screen, #achievements-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#loading-screen, #leaderboard-screen, #achievements-screen {
  background: #000;
}

#menu-screen {
  background: linear-gradient(180deg, #000022 0%, #0a0030 40%, #1a0040 100%);
  overflow: hidden;
}

/* 菜单背景粒子 */
#menu-screen::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 30% 50%, rgba(255,255,255,0.3), transparent),
    radial-gradient(2px 2px at 50% 10%, rgba(100,100,255,0.5), transparent),
    radial-gradient(1px 1px at 70% 60%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 90% 30%, rgba(255,255,255,0.4), transparent),
    radial-gradient(2px 2px at 20% 80%, rgba(100,200,255,0.4), transparent),
    radial-gradient(1px 1px at 60% 90%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 80% 70%, rgba(200,200,255,0.3), transparent),
    radial-gradient(2px 2px at 40% 40%, rgba(150,100,255,0.3), transparent),
    radial-gradient(1px 1px at 15% 55%, rgba(255,255,255,0.2), transparent);
  animation: starfield 8s linear infinite;
  pointer-events: none;
}

@keyframes starfield {
  0% { transform: translateY(0); opacity: 0.8; }
  50% { opacity: 1; }
  100% { transform: translateY(-20px); opacity: 0.8; }
}

/* Logo入场动画 */
#menu-screen img {
  animation: logoEnter 0.8s ease-out;
}

@keyframes logoEnter {
  0% { transform: scale(0.3); opacity: 0; filter: brightness(3); }
  60% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); filter: brightness(1); }
}

.pixel-title {
  font-size: 24px;
  text-shadow: 2px 2px 0 #00ff00, 0 0 20px rgba(0,255,0,0.3);
  margin-bottom: 20px;
  letter-spacing: 2px;
  animation: titleGlow 2s ease-in-out infinite;
}

@keyframes titleGlow {
  0%, 100% { text-shadow: 2px 2px 0 #00ff00, 0 0 10px rgba(0,255,0,0.2); }
  50% { text-shadow: 2px 2px 0 #00ff00, 0 0 25px rgba(0,255,0,0.5); }
}

/* === 按钮升级 === */
.pixel-button {
  background: linear-gradient(180deg, #00ff00 0%, #00cc00 100%);
  color: #000;
  padding: 12px 40px;
  margin: 8px;
  border: 3px solid #000;
  box-shadow: 4px 4px 0 rgba(0,255,0,0.3), inset 0 1px 0 rgba(255,255,255,0.3);
  cursor: pointer;
  font-size: 18px;
  font-weight: bold;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}

.pixel-button::after {
  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.4s;
}

.pixel-button:hover::after {
  left: 100%;
}

.pixel-button:hover {
  background: linear-gradient(180deg, #33ff33 0%, #00dd00 100%);
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 rgba(0,255,0,0.3);
}

.pixel-button:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 rgba(0,255,0,0.3);
}

.daily-btn {
  background: linear-gradient(180deg, #ff8800 0%, #ff6600 100%);
  box-shadow: 4px 4px 0 rgba(255,100,0,0.3), inset 0 1px 0 rgba(255,255,255,0.3);
}

.daily-btn:hover {
  background: linear-gradient(180deg, #ffaa33 0%, #ff7700 100%);
}

.share-btn {
  background: linear-gradient(180deg, #ff8800 0%, #ff6600 100%);
  margin-top: 16px;
  font-size: 14px;
  padding: 8px 24px;
  box-shadow: 3px 3px 0 rgba(255,100,0,0.3);
}

.share-btn:hover {
  background: linear-gradient(180deg, #ffaa33 0%, #ff7700 100%);
}

.pixel-loader {
  width: 60px;
  height: 60px;
  border: 8px solid #00ff00;
  border-top: 8px solid transparent;
  border-radius: 0;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* === 统计面板 === */
.stats-panel {
  margin-top: 20px;
  background: rgba(0,20,0,0.6);
  border: 2px solid rgba(0,255,0,0.4);
  padding: 16px 20px;
  min-width: 250px;
  backdrop-filter: blur(4px);
}

.stat-item {
  display: flex;
  justify-content: space-between;
  margin: 8px 0;
  font-size: 16px;
}

.stat-label {
  color: #00ff00;
}

/* === 排行榜 === */
#leaderboard-list {
  width: 90%;
  max-width: 500px;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  background: #111;
  border: 4px solid #00ff00;
  padding: 10px;
  margin: 20px 0;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  padding: 10px;
  margin: 5px 0;
  background: #222;
  border: 2px solid #444;
}

.leaderboard-rank {
  font-size: 20px;
  font-weight: bold;
  color: #00ff00;
  width: 40px;
  text-align: center;
}

.leaderboard-avatar {
  width: 40px;
  height: 40px;
  border: 2px solid #00ff00;
  margin: 0 10px;
  border-radius: 50%;
  object-fit: cover;
}

.leaderboard-avatar-placeholder {
  width: 40px;
  height: 40px;
  border: 2px solid #00ff00;
  margin: 0 10px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #333;
  font-size: 16px;
  color: #00ff00;
}

.leaderboard-info {
  flex: 1;
  min-width: 0;
}

.leaderboard-name {
  font-size: 16px;
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  font-size: 14px;
  color: #00ff00;
}

.guest-hint {
  color: #666;
  font-size: 12px;
  margin-top: 12px;
  text-align: center;
}

/* === 设置面板 === */
.settings-panel {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  justify-content: center;
}

.settings-toggle {
  background: rgba(50,50,50,0.6);
  color: #666;
  padding: 8px 14px;
  border: 2px solid #444;
  cursor: pointer;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  transition: all 0.15s;
}

.settings-toggle.active {
  background: rgba(0,40,0,0.6);
  color: #00ff00;
  border-color: #00ff00;
  box-shadow: 0 0 8px rgba(0,255,0,0.2);
}

.settings-toggle:active {
  transform: scale(0.95);
}

.top-rank {
  font-size: 24px !important;
}

#game-canvas {
  width: 100%;
  height: 100%;
}

canvas {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* === 成就 === */
#achievements-list {
  width: 90%;
  max-width: 500px;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  background: #111;
  border: 4px solid #00ff00;
  padding: 10px;
  margin: 20px 0;
}

.achievement-item {
  display: flex;
  align-items: center;
  padding: 10px;
  margin: 5px 0;
  background: #1a1a1a;
  border: 2px solid #333;
  opacity: 0.5;
}

.achievement-item.unlocked {
  opacity: 1;
  border-color: #ffff00;
  background: #1a1a0a;
}

.ach-icon {
  font-size: 28px;
  width: 40px;
  text-align: center;
  flex-shrink: 0;
}

.ach-info {
  flex: 1;
  min-width: 0;
  margin: 0 10px;
}

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

.ach-desc {
  font-size: 12px;
  color: #888;
  margin-top: 2px;
}

.ach-check, .ach-lock {
  font-size: 20px;
  width: 30px;
  text-align: center;
  flex-shrink: 0;
}
