* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  overflow: hidden;
  touch-action: none;
}

.screen {
  display: none;
  width: 100%;
  height: 100vh;
  position: absolute;
  top: 0;
  left: 0;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 认证界面 */
.auth-container {
  background: rgba(255, 255, 255, 0.95);
  padding: 40px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-width: 450px;
  width: 90%;
}

.auth-container h1 {
  font-size: 2em;
  color: #667eea;
  margin-bottom: 10px;
}

.subtitle {
  font-size: 1.1em;
  color: #666;
  margin-bottom: 25px;
}

.auth-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 25px;
  border-bottom: 2px solid #eee;
}

.auth-tab {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  font-size: 1em;
  color: #666;
  cursor: pointer;
  transition: all 0.3s;
  border-bottom: 3px solid transparent;
}

.auth-tab.active {
  color: #667eea;
  border-bottom-color: #667eea;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.auth-form input {
  padding: 15px;
  border: 2px solid #ddd;
  border-radius: 10px;
  font-size: 1em;
  transition: border-color 0.3s;
}

.auth-form input:focus {
  outline: none;
  border-color: #667eea;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 15px 30px;
  font-size: 1.1em;
  border-radius: 50px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: white;
  color: #667eea;
  border: 2px solid #667eea;
  padding: 12px 25px;
  font-size: 1em;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #667eea;
  color: white;
}

.btn-small {
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  border: none;
  padding: 8px 15px;
  font-size: 0.9em;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  margin: 0 5px;
}

.btn-small:hover {
  background: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.auth-error {
  color: #e74c3c;
  font-size: 0.9em;
  min-height: 20px;
}

.guest-info {
  background: #f0f0f0;
  padding: 15px;
  border-radius: 10px;
  margin-bottom: 15px;
  color: #666;
}

.user-info {
  background: #e8f5e9;
  padding: 20px;
  border-radius: 10px;
  margin-top: 20px;
}

.user-info p {
  margin: 10px 0;
  color: #2e7d32;
}

.hidden {
  display: none !important;
}

/* 大厅界面 */
.lobby-container {
  background: rgba(255, 255, 255, 0.95);
  padding: 30px;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-width: 700px;
  width: 95%;
  max-height: 90vh;
  overflow-y: auto;
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 2px solid #eee;
}

.lobby-header h2 {
  color: #667eea;
}

.user-display {
  display: flex;
  align-items: center;
  gap: 10px;
}

#lobby-username {
  font-weight: bold;
  color: #764ba2;
}

.lobby-menu {
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.menu-section h3 {
  color: #764ba2;
  margin-bottom: 15px;
}

.join-room-form {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.join-room-form input {
  flex: 1;
  padding: 12px;
  border: 2px solid #ddd;
  border-radius: 10px;
  font-size: 1em;
  text-transform: uppercase;
  letter-spacing: 3px;
  text-align: center;
}

.join-room-form input:focus {
  outline: none;
  border-color: #667eea;
}

/* 关卡选择网格 */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 15px;
}

.level-btn {
  aspect-ratio: 1;
  border: 3px solid #ddd;
  border-radius: 15px;
  background: #f5f5f5;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 1.5em;
}

.level-btn.unlocked {
  border-color: #FFC107;
  background: #fff8e1;
  color: #f57f17;
}

.level-btn.unlocked:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(255, 193, 7, 0.4);
}

.level-btn.selected {
  border-color: #4CAF50;
  background: #e8f5e9;
  color: #2e7d32;
  transform: scale(1.1);
  box-shadow: 0 4px 20px rgba(76, 175, 80, 0.5);
}

.level-btn.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.level-btn .level-num {
  font-size: 0.5em;
  margin-top: 5px;
}

/* 房间信息 */
.room-info {
  background: #f0f0f0;
  padding: 20px;
  border-radius: 15px;
  margin-top: 20px;
  text-align: center;
}

.room-code {
  font-size: 2em;
  font-weight: bold;
  color: #667eea;
  letter-spacing: 5px;
  display: inline-block;
  margin: 10px 0;
  padding: 10px 20px;
  background: white;
  border-radius: 10px;
}

.room-actions {
  margin: 10px 0;
}

.share-tip {
  color: #666;
  font-size: 0.9em;
  margin: 10px 0;
}

.room-players {
  margin: 20px 0;
}

.room-tips {
  background: #e3f2fd;
  padding: 12px 15px;
  border-radius: 10px;
  margin: 15px 0;
}

.tip-text {
  color: #1976d2;
  font-size: 0.9em;
  margin: 0;
}

.player-slot {
  background: white;
  padding: 10px 15px;
  border-radius: 10px;
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.player-slot .character {
  font-size: 1.5em;
  margin-right: 10px;
}

.player-slot .ready-mark {
  color: #4CAF50;
  font-weight: bold;
}

/* 游戏界面 */
#game-screen {
  background: #1a1a2e;
  flex-direction: column;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  width: 100%;
}

.level-info, .score-info, .player-info {
  font-size: 1.1em;
  font-weight: bold;
}

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

#game-canvas {
  background: linear-gradient(180deg, #16213e 0%, #1a1a2e 100%);
  border: 3px solid #667eea;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  max-width: 95%;
  max-height: 70vh;
}

.game-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 15px;
}

/* 移动端控制器 */
.mobile-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 150px;
  display: none;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

.mobile-controls.visible {
  display: block;
}

.mobile-controls * {
  pointer-events: auto;
}

.dpad-container, .jump-container {
  position: absolute;
  bottom: 20px;
}

.dpad-container {
  left: 20px;
}

.jump-container {
  right: 20px;
}

.dpad-move-handle, .jump-move-handle {
  position: absolute;
  top: -25px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.5);
  color: white;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 0.7em;
  cursor: grab;
  user-select: none;
}

.dpad-btn {
  display: inline-block;
  width: 70px;
  height: 70px;
  margin: 0 5px;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 15px;
  color: white;
  font-size: 2em;
  cursor: pointer;
  backdrop-filter: blur(5px);
  transition: background 0.2s;
}

.dpad-btn:active, .dpad-btn.active {
  background: rgba(255, 255, 255, 0.6);
}

.action-btn {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(102, 126, 234, 0.6);
  border: 3px solid rgba(255, 255, 255, 0.5);
  color: white;
  font-size: 1.3em;
  font-weight: bold;
  cursor: pointer;
  backdrop-filter: blur(5px);
  transition: all 0.2s;
}

.action-btn:active, .action-btn.active {
  background: rgba(102, 126, 234, 0.9);
  transform: scale(0.95);
}

/* 横屏适配 */
@media (orientation: landscape) and (max-height: 500px) {
  .mobile-controls {
    height: 100px;
  }
  
  .dpad-btn {
    width: 50px;
    height: 50px;
    font-size: 1.5em;
  }
  
  .action-btn {
    width: 70px;
    height: 70px;
    font-size: 1.1em;
  }
  
  .game-header {
    padding: 10px 15px;
    font-size: 0.9em;
  }
}

/* 竖屏适配 */
@media (orientation: portrait) {
  .mobile-controls {
    height: 120px;
  }
  
  #game-canvas {
    max-height: 45vh;
  }
}

/* 关卡完成/游戏结束 */
.complete-container, .game-over-container {
  background: rgba(255, 255, 255, 0.95);
  padding: 40px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.complete-container h2, .game-over-container h2 {
  color: #667eea;
  font-size: 2.5em;
  margin-bottom: 20px;
}

.congrats {
  font-size: 1.2em;
  color: #764ba2;
  margin: 20px 0;
}

/* Toast 提示 */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 15px 30px;
  border-radius: 50px;
  z-index: 10000;
  animation: toastSlide 0.3s ease;
}

.toast.hidden {
  display: none;
}

@keyframes toastSlide {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* 响应式 */
@media (max-width: 768px) {
  .auth-container, .lobby-container {
    padding: 25px;
    width: 95%;
  }
  
  .auth-container h1 {
    font-size: 1.6em;
  }
  
  .lobby-header {
    flex-direction: column;
    gap: 15px;
    text-align: center;
  }
  
  .join-room-form {
    flex-direction: column;
  }
  
  .level-grid {
    grid-template-columns: repeat(5, 1fr);
  }
  
  #game-canvas {
    max-width: 100%;
  }
}
