html {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  min-height: 100vh;
  max-height: 100vh;
}

/* 功能表縮小狀態 */
#gameInfo.collapsed {
  width: auto;
  min-width: 48px;
  padding: 8px;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

#gameInfo.collapsed #menuButtons {
  display: none !important;
}

#gameInfo.collapsed .score-info {
  display: none !important;
}

#gameInfo.collapsed .level-info {
  display: none !important;
}

#gameInfo.collapsed #toggleMenuBtn {
  transform: rotate(180deg);
  margin: 0;
}

/* 功能表切換按鈕樣式 */
#toggleMenuBtn {
  transition: transform 0.3s ease;
  min-width: 24px;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

#toggleMenuBtn:hover {
  background: rgba(0,0,0,0.1) !important;
  color: #2a5 !important;
}

#toggleMenuBtn:focus {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
}

body {
  background: #eaf6ff;
  font-family: 'Segoe UI', Arial, sans-serif;
  text-align: center;
  margin: 0;
  padding: 0;
  overflow: hidden;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  max-height: 100vh;
}
#ui {
  margin: 8px auto 4px auto;
  font-size: 20px;
  background: rgba(255,255,255,0.8);
  display: inline-block;
  border-radius: 8px;
  padding: 8px 24px;
  box-shadow: 0 2px 8px #b0d0f0;
  flex-shrink: 0;
}
#ui span {
  margin: 0 16px;
  font-weight: bold;
}
#container {
  max-width: 100%;
  height: 100vh;
  min-height: 100vh;
  max-height: 100vh;
  padding: 0;
  margin: 0 auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#canvasWrap {
  width: 100%;
  max-width: 100%;
  flex: 1;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  min-height: 0;
}
#gameCanvas {
  width: 100%;
  max-width: 1600px;
  max-height: 100vh;
  height: auto;
  aspect-ratio: 16/9;
  display: block;
  margin: 0 auto;
  background: #eaf6ff;
  border: 2px solid #b0d0f0;
  border-radius: 12px;
  box-shadow: 0 4px 16px #b0d0f0;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  object-fit: contain;
  box-sizing: border-box;
}

/* 電腦版全螢幕處理 */
@media (min-width: 901px) {
  #container {
    justify-content: flex-start;
    height: 100vh;
    padding: 0;
    margin: 0;
  }
  
  #gameCanvas {
    max-height: 100vh;
    height: 100vh;
    width: auto;
    aspect-ratio: 16/9;
    margin: 0;
  }
  
  #canvasWrap {
    height: 100vh;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-height: 0;
  }
  
  #result {
    display: none;
  }
}
#result {
  font-size: 36px;
  font-weight: bold;
  margin: 8px;
  color: #d22;
  min-height: 48px;
  flex-shrink: 0;
}

#desc {
  margin: 12px auto;
  max-width: 500px;
  background: rgba(255,255,255,0.7);
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 16px;
  color: #333;
  box-shadow: 0 2px 8px #b0d0f0;
  z-index: 1000;
}
#showDescBtn {
  /* 現在在遊戲信息區域內，使用內聯樣式 */
}

/* 手機版按鈕觸控優化 */
@media (max-width: 900px) {
  #ui {
    font-size: 16px;
    padding: 6px 8px;
  }
  #result {
    font-size: 24px;
    min-height: 32px;
  }

  #desc {
    font-size: 14px;
    padding: 8px 8px;
  }
  h1 {
    font-size: 22px;
  }
  

  
  /* 確保按鈕在手機版有足夠的觸控區域 */
  #showLeaderboardBtn,
  #skipToLevelBtn,
  #showDescBtn {
    min-width: 80px;
    min-height: 36px;
    padding: 8px 12px;
    font-size: 14px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* 手機版切換按鈕觸控優化 */
  #toggleMenuBtn {
    min-width: 32px !important;
    min-height: 32px !important;
    font-size: 18px !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
  }
  
  /* 手機版縮小狀態優化 */
  #gameInfo.collapsed {
    min-width: 40px !important;
    padding: 6px !important;
    background: transparent !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }
  
  /* 模態框按鈕觸控優化 */
  #leaderboardModal button,
  #skipLevelModal button,
  #desc button {
    min-width: 44px;
    min-height: 44px;
    padding: 12px 16px;
    font-size: 16px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    border-radius: 8px;
  }
  
  /* 上下按鈕特殊觸控優化 */
  #decreaseLevelBtn,
  #increaseLevelBtn {
    min-width: 48px;
    min-height: 48px;
    padding: 8px 12px;
    font-size: 20px;
    font-weight: bold;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* 排行榜按鈕容器確保單行顯示 */
  #leaderboardModal > div:last-child {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    justify-content: center !important;
    align-items: center !important;
  }
  
  #leaderboardModal > div:last-child button {
    white-space: nowrap !important;
    flex-shrink: 1 !important;
    min-width: 0 !important;
    font-size: 12px !important;
    padding: 8px 12px !important;
  }
  
  /* 關閉按鈕特殊處理 */
  #closeLeaderboardBtn,
  #closeSkipLevelBtn,
  #closeDescBtn {
    min-width: 48px;
    min-height: 48px;
    font-size: 20px;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* 載入指示器按鈕觸控優化 */
  #skipLoadingBtn {
    min-width: 120px;
    min-height: 44px;
    padding: 12px 20px;
    font-size: 16px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    border-radius: 8px;
  }
}
@media (max-width: 600px) {
  #gameCanvas {
    max-width: 100vw;
    width: 100vw;
    height: auto;
    border: none;
    border-radius: 0;
    display: block;
    margin: 0;
    position: relative;
    object-fit: contain;
  }
  #ui {
    font-size: 13px;
    padding: 4px 2px;
  }
  #result {
    font-size: 18px;
    min-height: 24px;
  }

  #desc {
    font-size: 12px;
    padding: 6px 2px;
  }
  h1 {
    font-size: 16px;
  }
  #container {
    height: 100vh;
    padding: 0;
    margin: 0;
    overflow: hidden;
  }
  #canvasWrap {
    flex: 1;
    min-height: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
  }
  
  /* 確保手機版不會有滾動條 */
  body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
  }
  
  /* 手機版確保完全填滿 */
  html {
    height: 100%;
    width: 100%;
    overflow: hidden;
  }
}

/* 手機橫屏特殊處理 */
@media (max-width: 600px) and (orientation: landscape) {
  /* 確保橫屏時完全填滿螢幕 */
  body {
    overflow: hidden !important;
    position: fixed !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    margin: 0 !important;
    padding: 0 !important;
    top: 0 !important;
    left: 0 !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
  }
  
  /* 橫屏時確保視口正確設置 */
  html {
    height: 100vh !important;
    height: 100dvh !important;
    width: 100vw !important;
    overflow: hidden !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
  }
  
  /* 橫屏時處理安全區域 - 移除padding避免空白 */
  #container {
    padding: 0 !important;
    margin: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }
  
  /* 橫屏時確保canvasWrap完全填滿並置中 */
  #canvasWrap {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    padding: 0 !important;
    margin: 0 !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    flex: 1 !important;
    box-sizing: border-box !important;
  }
  
  /* 橫屏時維持16:9比例，確保完全適應螢幕高度且不被裁切 */
  #gameCanvas {
    width: auto !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: calc(100vh * 16 / 9) !important;
    max-width: calc(100dvh * 16 / 9) !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    aspect-ratio: 16/9 !important;
    object-fit: contain !important;
    display: block !important;
    margin: 0 auto !important;
    position: relative !important;
    background: #eaf6ff !important;
    border: none !important;
    border-radius: 0 !important;
    /* 確保不會超出螢幕邊界 */
    box-sizing: border-box !important;
    /* 強制防止裁切 */
    transform: translateZ(0) !important;
    -webkit-transform: translateZ(0) !important;
    /* 確保置中 */
    align-self: center !important;
    justify-self: center !important;
  }
  
  /* 隱藏result避免佔用空間 */
  #result {
    display: none !important;
  }
  
  /* 橫屏時調整遊戲信息顯示 */
  #gameInfo {
    top: 8px !important;
    left: 8px !important;
    padding: 6px 12px !important;
    font-size: 14px !important;
    z-index: 1000 !important;
  }
  
  /* 橫屏時縮小狀態無容器 */
  #gameInfo.collapsed {
    background: transparent !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }
  
  #gameInfo div:first-child {
    font-size: 16px !important;
  }
  
  #gameInfo div:last-child {
    font-size: 14px !important;
    margin-top: 2px !important;
  }
  
  /* 橫屏時確保desc的z-index正確 */
  #desc {
    z-index: 1000 !important;
  }
} 

/* 手機直屏特殊處理 - 重置橫屏樣式並確保正確置中 */
@media (max-width: 600px) and (orientation: portrait) {
  /* 重置body樣式 */
  body {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    top: 0 !important;
    left: 0 !important;
  }
  
  /* 重置html樣式 */
  html {
    height: 100% !important;
    width: 100% !important;
    overflow: hidden !important;
  }
  
  /* 重置container樣式 */
  #container {
    height: 100vh !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    position: static !important;
    width: 100% !important;
  }
  
  /* 重置canvasWrap樣式並確保置中 */
  #canvasWrap {
    flex: 1 !important;
    min-height: 0 !important;
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    position: static !important;
    top: auto !important;
    left: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }
  
  /* 重置gameCanvas樣式並確保置中 */
  #gameCanvas {
    max-width: 100vw !important;
    width: 100vw !important;
    height: auto !important;
    border: none !important;
    border-radius: 0 !important;
    display: block !important;
    margin: 0 auto !important;
    position: relative !important;
    object-fit: contain !important;
    background: #eaf6ff !important;
    box-sizing: border-box !important;
    /* 重置transform */
    transform: none !important;
    -webkit-transform: none !important;
    /* 確保置中 */
    align-self: center !important;
    justify-self: center !important;
    /* 確保垂直置中 */
    max-height: calc(100vh - 120px) !important;
  }
  
  /* 顯示result */
  #result {
    display: block !important;
    font-size: 18px !important;
    min-height: 24px !important;
  }
  
  /* 重置遊戲信息顯示 */
  #gameInfo {
    position: static !important;
    top: auto !important;
    left: auto !important;
    padding: 6px 12px !important;
    font-size: 14px !important;
    z-index: 1000 !important;
  }
  
  /* 重置desc樣式 */
  #desc {
    z-index: 1000 !important;
  }
}

/* 手機直屏額外重置 - 針對其他橫版媒體查詢 */
@media (orientation: portrait) and (max-width: 900px) {
  /* 重置所有橫版的強制樣式 */
  html, body {
    height: 100vh !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  #container {
    height: 100vh !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
    position: static !important;
    width: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    margin: 0 !important;
    padding: 0 !important;
    top: auto !important;
    left: auto !important;
  }
  
  #canvasWrap {
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    width: 100% !important;
    position: static !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 !important;
    top: auto !important;
    left: auto !important;
  }
  
  #gameCanvas {
    /* 重置所有橫版的強制樣式 */
    height: auto !important;
    max-height: calc(100vh - 120px) !important;
    width: 100vw !important;
    max-width: 100vw !important;
    position: relative !important;
    display: block !important;
    margin: 0 auto !important;
    object-fit: contain !important;
    background: #eaf6ff !important;
    border: none !important;
    border-radius: 0 !important;
    box-sizing: border-box !important;
    /* 重置所有transform */
    transform: none !important;
    -webkit-transform: none !important;
    /* 重置backface-visibility */
    -webkit-backface-visibility: visible !important;
    backface-visibility: visible !important;
    /* 確保置中 */
    align-self: center !important;
    justify-self: center !important;
    /* 重置position */
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
  }
  
  #result {
    display: block !important;
  }
}

/* iOS Safari 直屏特殊處理 */
@supports (-webkit-touch-callout: none) {
  @media (orientation: portrait) and (max-width: 900px) {
    body {
      position: fixed !important;
      width: 100% !important;
      height: 100% !important;
      overflow: hidden !important;
      -webkit-overflow-scrolling: touch !important;
    }
    
    #container {
      position: static !important;
      width: 100% !important;
      height: 100vh !important;
      overflow: hidden !important;
      -webkit-overflow-scrolling: touch !important;
    }
    
    #canvasWrap {
      width: 100% !important;
      height: 100% !important;
      display: flex !important;
      justify-content: center !important;
      align-items: center !important;
      overflow: hidden !important;
    }
    
    #gameCanvas {
      /* iOS Safari 直屏優化 */
      -webkit-transform: none !important;
      transform: none !important;
      -webkit-backface-visibility: visible !important;
      backface-visibility: visible !important;
      /* 直屏時的正常尺寸 */
      max-height: calc(100vh - 120px) !important;
      height: auto !important;
      width: 100vw !important;
      max-width: 100vw !important;
      margin: 0 auto !important;
    }
  }
}

#leaderboardModal,
#desc,
#skipLevelModal {
  pointer-events: auto !important;
}

#canvasWrap.modal-open {
  pointer-events: none !important;
}

/* 排行榜表格優化 */
#leaderboardList table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
  font-family: Arial, sans-serif;
}

#leaderboardList th {
  text-align: center;
  padding: 8px;
  color: #2a5;
  font-weight: bold;
  border-bottom: 2px solid #2a5;
}

#leaderboardList td {
  text-align: center;
  padding: 8px;
  border-bottom: 1px solid #eee;
}

#leaderboardList tr:hover {
  background-color: rgba(42, 170, 85, 0.05);
}

/* 手機版排行榜優化 */
@media (max-width: 900px) {
  #leaderboardList table {
    font-size: 14px;
  }
  
  #leaderboardList th,
  #leaderboardList td {
    padding: 6px 4px;
    font-size: 13px;
  }
  
  #leaderboardList th {
    font-size: 14px;
  }
}

/* 手機版小螢幕進一步優化 */
@media (max-width: 480px) {
  #leaderboardList table {
    font-size: 12px;
  }
  
  #leaderboardList th,
  #leaderboardList td {
    padding: 4px 2px;
    font-size: 11px;
  }
  
  #leaderboardList th {
    font-size: 12px;
  }
  
  /* 調整排行榜模態框寬度 */
  #leaderboardModal {
    min-width: 280px !important;
    padding: 20px 24px !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
  }
  
  /* 小螢幕上下按鈕進一步優化 */
  #decreaseLevelBtn,
  #increaseLevelBtn {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 6px 8px !important;
    font-size: 18px !important;
  }
}

/* 通用手機橫版處理 - 確保任何寬度都不會出現空白區域且保持16:9比例 */
@media (orientation: landscape) and (max-height: 600px) {
  body {
    overflow: hidden !important;
    position: fixed !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    margin: 0 !important;
    padding: 0 !important;
    top: 0 !important;
    left: 0 !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
  }
  
  html {
    height: 100vh !important;
    height: 100dvh !important;
    width: 100vw !important;
    overflow: hidden !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
  }
  
  #container {
    padding: 0 !important;
    margin: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }
  
  #canvasWrap {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    padding: 0 !important;
    margin: 0 !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    flex: 1 !important;
    box-sizing: border-box !important;
  }
  
  /* 確保16:9比例且完全適應螢幕，避免裁切 */
  #gameCanvas {
    width: auto !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: calc(100vh * 16 / 9) !important;
    max-width: calc(100dvh * 16 / 9) !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    aspect-ratio: 16/9 !important;
    object-fit: contain !important;
    display: block !important;
    margin: 0 auto !important;
    position: relative !important;
    background: #eaf6ff !important;
    border: none !important;
    border-radius: 0 !important;
    box-sizing: border-box !important;
    /* 確保不會超出螢幕邊界 */
    transform: translateZ(0) !important;
    -webkit-transform: translateZ(0) !important;
    /* 確保置中 */
    align-self: center !important;
    justify-self: center !important;
  }
  
  #result {
    display: none !important;
  }
  
  /* iOS Safari 特殊處理 */
  @supports (-webkit-touch-callout: none) {
    body {
      position: fixed !important;
      width: 100vw !important;
      height: 100vh !important;
      overflow: hidden !important;
    }
    
    #container {
      position: fixed !important;
      width: 100vw !important;
      height: 100vh !important;
      overflow: hidden !important;
    }
    
    #gameCanvas {
      /* iOS Safari 特殊優化 */
      -webkit-transform: translateZ(0) !important;
      transform: translateZ(0) !important;
      -webkit-backface-visibility: hidden !important;
      backface-visibility: hidden !important;
    }
  }
}

/* 額外的手機橫版優化 - 確保所有手機橫版都能正確顯示16:9比例 */
@media (orientation: landscape) and (max-width: 900px) {
  #gameCanvas {
    /* 確保16:9比例且完全適應螢幕，沒有上下間距 */
    width: auto !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: calc(100vh * 16 / 9) !important;
    max-width: calc(100dvh * 16 / 9) !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    aspect-ratio: 16/9 !important;
    object-fit: contain !important;
    box-sizing: border-box !important;
    /* 防止裁切 */
    transform: translateZ(0) !important;
    -webkit-transform: translateZ(0) !important;
    /* 確保置中 */
    align-self: center !important;
    justify-self: center !important;
    margin: 0 auto !important;
  }
  
  #canvasWrap {
    /* 確保容器完全填滿螢幕 */
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }
  
  /* 隱藏可能造成裁切的元素 */
  #result {
    display: none !important;
  }
}

/* iOS Safari 特殊處理 - 防止底部裁切 */
@supports (-webkit-touch-callout: none) {
  @media (orientation: landscape) {
    body {
      /* 確保iOS Safari正確處理視口 */
      position: fixed !important;
      width: 100vw !important;
      height: 100vh !important;
      height: 100dvh !important;
      overflow: hidden !important;
      -webkit-overflow-scrolling: touch !important;
    }
    
    #container {
      /* 確保容器在iOS Safari中正確顯示 */
      position: fixed !important;
      width: 100vw !important;
      height: 100vh !important;
      height: 100dvh !important;
      overflow: hidden !important;
      -webkit-overflow-scrolling: touch !important;
    }
    
    #canvasWrap {
      /* 確保canvasWrap在iOS Safari中正確顯示 */
      width: 100vw !important;
      height: 100vh !important;
      height: 100dvh !important;
      display: flex !important;
      justify-content: center !important;
      align-items: center !important;
      overflow: hidden !important;
    }
    
    #gameCanvas {
      /* iOS Safari 特殊優化，防止底部裁切 */
      -webkit-transform: translateZ(0) !important;
      transform: translateZ(0) !important;
      -webkit-backface-visibility: hidden !important;
      backface-visibility: hidden !important;
      /* 完全沒有上下間距，填滿整個視口 */
      max-height: 100vh !important;
      max-height: 100dvh !important;
      height: 100vh !important;
      height: 100dvh !important;
      /* 確保16:9比例 */
      max-width: calc(100vh * 16 / 9) !important;
      max-width: calc(100dvh * 16 / 9) !important;
    }
  }
}

/* 強力手機橫版防裁切處理 */
@media (orientation: landscape) and (max-width: 900px) and (max-height: 600px) {
  #gameCanvas {
    /* 完全沒有上下間距，填滿整個視口 */
    height: 100vh !important;
    height: 100dvh !important;
    max-width: calc(100vh * 16 / 9) !important;
    max-width: calc(100dvh * 16 / 9) !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    /* 強制居中且不超出邊界 */
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) translateZ(0) !important;
    -webkit-transform: translate(-50%, -50%) translateZ(0) !important;
    /* 確保置中 */
    align-self: center !important;
    justify-self: center !important;
    margin: 0 auto !important;
  }
  
  #canvasWrap {
    /* 確保容器完全填滿且居中 */
    position: relative !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }
}

/* 最終保障：確保所有手機橫版都能正確顯示16:9比例 */
@media (orientation: landscape) and (max-width: 900px) {
  /* 強制設置視口高度 */
  html, body {
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
  }
  
  /* 確保容器完全填滿 */
  #container {
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    overflow: hidden !important;
  }
  
  /* 確保canvasWrap居中且填滿 */
  #canvasWrap {
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    width: 100vw !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    overflow: hidden !important;
    position: relative !important;
    box-sizing: border-box !important;
  }
  
  /* 確保遊戲畫布保持16:9比例且完全填滿視口 */
  #gameCanvas {
    /* 完全沒有上下間距，填滿整個視口 */
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    max-width: calc(100vh * 16 / 9) !important;
    max-width: calc(100dvh * 16 / 9) !important;
    width: auto !important;
    aspect-ratio: 16/9 !important;
    object-fit: contain !important;
    display: block !important;
    margin: 0 auto !important;
    position: relative !important;
    background: #eaf6ff !important;
    border: none !important;
    border-radius: 0 !important;
    box-sizing: border-box !important;
    /* 強制硬體加速 */
    transform: translateZ(0) !important;
    -webkit-transform: translateZ(0) !important;
    -webkit-backface-visibility: hidden !important;
    backface-visibility: hidden !important;
    /* 確保置中 */
    align-self: center !important;
    justify-self: center !important;
  }
  
  /* 隱藏可能造成裁切的元素 */
  #result {
    display: none !important;
  }
}

@media (orientation: landscape) and (max-width: 900px) {
  #container {
    width: 100vw !important;
    height: 100vh !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }
  #canvasWrap {
    width: 100vw !important;
    height: 100vh !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }
  #gameCanvas {
    display: block !important;
    margin: auto !important;
    position: static !important;
    left: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    -webkit-transform: none !important;
    align-self: center !important;
    justify-self: center !important;
  }
}