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

body {
  background: radial-gradient(circle at center, #001428 0%, #000 100%);
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff
}

/* 默认桌面布局 */
header {
  width: 100%;
  max-width: 900px;
  padding: .8rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, .05);
  backdrop-filter: blur(10px)saturate(160%);
  border-radius: 18px;
  margin-top: 1rem;
  z-index: 10;
  flex-shrink: 0;
}

h1 {
  font-size: 1.3rem
}

#timer {
  font-size: 1.1rem
}

#scoreContainer {
  display: flex;
  gap: 1rem;
  font-size: 1rem;
  font-weight: 600;
}

.player1-score {
  color: #00d4ff;
  text-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.player2-score {
  color: #ff3366;
  text-shadow: 0 0 10px rgba(255, 51, 102, 0.5);
}

#gameContainer {
  flex: 1;
  width: 100%;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 10px;
  /* background: rgba(0,0,0,0.2);*/
  /* Optional debug bg */
}

#webcam,
#gameCanvas {
  position: absolute;
  /* Centering via translate is robust for absolute items */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scaleX(-1);

  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;

  object-fit: contain;
  /* Ensure aspect ratio is preserved */
  border-radius: 24px;
  /* Rounded corners */
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* 移动设备布局 (手机和平板) */
@media screen and (max-width: 1024px) {
  body {
    position: relative;
    overflow: hidden;
    height: 100vh
  }

  /* 移动端Header也使用Flex布局一部分，不悬浮遮挡 */
  header {
    width: 100%;
    max-width: none;
    padding: .6rem 1rem;
    background: rgba(255, 255, 255, .1);
    border-radius: 0;
    margin-top: 0;
    position: relative;
    height: 60px;
    flex-shrink: 0;
  }

  #gameContainer {
    margin-top: 0;
    width: 100%;
    height: calc(100vh - 60px);
    padding: 10px;
    /* Add padding on mobile */
  }

  h1 {
    font-size: 1.1rem
  }

  button {
    padding: .4rem 1rem !important;
    font-size: .9rem !important;
    border-radius: 1rem !important;
    touch-action: manipulation
  }

  #timer {
    font-size: 1rem
  }

  #webcam,
  #gameCanvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scaleX(-1);

    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;

    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    border-radius: 20px;
    object-fit: contain;
  }

  #gameCanvas {
    pointer-events: none
  }

  #scoreBoard {
    font-size: .9rem
  }

  #loadingBox {
    padding: 1.5rem 2rem;
    max-width: 350px
  }

  #loadingBox h2 {
    font-size: 1.2rem;
    margin-bottom: 1.2rem
  }

  #loadingText {
    font-size: .9rem
  }
}

h1 {
  font-weight: 600;
  letter-spacing: .05em
}

button {
  background: linear-gradient(145deg, #ff8233, #ff5522);
  border: none;
  padding: .55rem 1.6rem;
  border-radius: 1.2rem;
  font-size: 1rem;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .5);
  transition: transform .15s, filter .15s
}

button:hover {
  filter: brightness(1.15)
}

button:active {
  transform: scale(.95)
}

#timer {
  font-weight: 600
}

#loadingContainer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 998;
  transition: opacity .3s ease
}

#loadingBox {
  background: rgba(255, 255, 255, .08);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 2rem 3rem;
  text-align: center;
  max-width: 400px;
  width: 90%
}

#loadingBox h2 {
  font-size: 1.3rem;
  margin-bottom: 1.5rem;
  color: #fff
}

#progressBar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, .2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 1rem
}

#progressFill {
  height: 100%;
  background: linear-gradient(90deg, #ff8233, #ff5522);
  width: 0%;
  transition: width .3s ease;
  border-radius: 4px
}

#loadingText {
  font-size: 1rem;
  color: #ccc;
  margin: 0
}

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999
}

.hidden {
  display: none
}

#resultBox {
  background: rgba(255, 255, 255, .08);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 2rem 3rem;
  text-align: center;
  max-width: 320px
}

#resultBox h2 {
  font-size: 1.5rem;
  margin-bottom: .6rem
}

#resultBox p {
  margin: .4rem 0 1.2rem;
  font-size: 1.2rem
}

#overlay.hidden {
  display: none
}

/* 游戏设置界面样式 */
#settingsOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 998;
}

#settingsOverlay.hidden {
  display: none;
}

#settingsBox {
  background: linear-gradient(145deg, rgba(30, 30, 50, 0.95), rgba(20, 20, 40, 0.95));
  backdrop-filter: blur(15px);
  border-radius: 24px;
  padding: 2rem 2.5rem;
  text-align: center;
  max-width: 420px;
  width: 90%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#settingsBox h2 {
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, #ffd700, #ff8c00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.setting-group {
  margin-bottom: 1.5rem;
}

.setting-group label {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 0.8rem;
  color: #fff;
  text-align: left;
}

.setting-options {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.setting-btn {
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: #ccc;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 70px;
}

.setting-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
}

.setting-btn.active {
  background: linear-gradient(135deg, #ff8c00, #ffd700);
  border-color: #ffd700;
  color: #000;
  font-weight: bold;
  box-shadow: 0 4px 15px rgba(255, 140, 0, 0.4);
}

.difficulty-desc {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  padding: 0.8rem;
  margin: 1rem 0 1.5rem;
}

.difficulty-desc p {
  color: #aaa;
  font-size: 0.9rem;
  margin: 0;
}

#confirmSettingsBtn {
  padding: 1rem 2.5rem;
  font-size: 1.2rem;
  border: none;
  border-radius: 16px;
  background: linear-gradient(135deg, #00d4ff, #0099cc);
  color: #fff;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
  box-shadow: 0 6px 20px rgba(0, 212, 255, 0.4);
}

#confirmSettingsBtn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 212, 255, 0.6);
}

#confirmSettingsBtn:active {
  transform: translateY(0);
}

/* 游戏加载遮罩 */
#gameLoadingOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

#gameLoadingOverlay.hidden {
  display: none;
}

.game-loading-content {
  text-align: center;
}

.loading-spinner {
  width: 80px;
  height: 80px;
  border: 6px solid rgba(255, 255, 255, 0.2);
  border-top-color: #00d4ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1.5rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-message {
  color: #fff;
  font-size: 1.4rem;
  font-weight: 600;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* 倒计时遮罩 */
#countdownOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1001;
}

#countdownOverlay.hidden {
  display: none;
}

#countdownNumber {
  font-size: 200px;
  font-weight: bold;
  color: #fff;
  text-shadow: 
    0 0 30px #00d4ff,
    0 0 60px #00d4ff,
    0 0 90px #00d4ff;
  animation: countdownPop 1s ease-in-out;
}

@keyframes countdownPop {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}