.court-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 5px;
  justify-content: center;
  margin-top: 20px;
  width: 100%;
}

.court-visual {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  background: #eee;
  aspect-ratio: 1/1;
  border-radius: 12px;
}

.reserve-court {
  border-width: 3px;
  border-style: dashed;
  border-color: #ffa500;
}

.reserve-court img {
  opacity: 0.7;
}

.reserve-court .court-label {
  color: #ff6600;
  font-weight: bold;
}

.court-next-btn {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  font-size: 18px;
  padding: 10px 24px;
  border-radius: 8px;
  background: #007bff;
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

.court-next-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.reserve-next-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  font-size: 18px;
  padding: 10px 10px;
  border-radius: 8px;
  background: rgba(255, 165, 0, 0.7);
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

#player-game-counts-info {
  margin-top: 20px;
  padding: 15px;
  background-color: #f0f2f5;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.court-visual img {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  border-radius: 12px;
  object-fit: cover;
}
.court-names-top,
.court-names-bottom {
  position: absolute;
  z-index: 2;
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  left: 0;
  right: 0;
  padding: 0;
  margin: 0;
  gap: 0;
}
.court-names-top {
  top: 12%;
}
.court-names-bottom {
  bottom: 12%;
}
.court-player-name {
  color: #fff;
  font-weight: bold;
  text-shadow: 1px 1px 4px #000;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 6px; /* 減少內部填充 */
  border-radius: 6px;
  flex-basis: 44%;
  flex-shrink: 1;
  flex-grow: 0;
  max-width: 45%;
  min-width: 0;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(12px, 2.5vw, 16px); /* 調整字體大小範圍 */
  box-sizing: border-box;
  margin: 0;
}
.court-label {
  position: absolute;
  z-index: 3;
  top: 2%;
  left: 0;
  width: 100%;
  text-align: center;
  color: #222;
  font-size: clamp(13px, 2vw, 18px);
  font-weight: bold;
}
body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f0f2f5;
  color: #333;
  margin: 0;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
}

.container {
  background-color: #fff;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 1000px; /* 增加最大寬度，允許更多場地並排 */
}

h1 {
  color: #0056b3;
  text-align: center;
  margin-bottom: 30px;
}

h2 {
  color: #0056b3;
  border-bottom: 2px solid #0056b3;
  padding-bottom: 10px;
  margin-top: 30px;
  margin-bottom: 20px;
}

.input-section,
.options-section,
.action-buttons,
.lineup-display-section {
  margin-bottom: 30px;
}

#player-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 15px;
}

.player-input,
select#game-mode,
.court-input {
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 16px;
  box-sizing: border-box; /* Ensure padding doesn't expand element */
}

.court-input {
  width: 100px; /* Or any specific width you prefer */
  margin-bottom: 15px;
}

.player-entry {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: center;
}

.player-name-input {
  flex-grow: 1;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 15px;
}

.player-level-input {
  width: 120px; /* Adjust as needed */
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 15px;
}

.player-input:focus,
select#game-mode:focus,
.court-input:focus,
.player-name-input:focus,
.player-level-input:focus {
  border-color: #0056b3;
  outline: none;
  box-shadow: 0 0 5px rgba(0, 86, 179, 0.3);
}

button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s ease;
  margin-right: 10px;
}

button#add-player-btn {
  background-color: #28a745;
}

button#add-player-btn:hover {
  background-color: #218838;
}

button#generate-lineup-btn:hover {
  background-color: #0056b3;
}

button#reset-btn {
  background-color: #dc3545;
}

button#reset-btn:hover {
  background-color: #c82333;
}

.action-buttons {
  text-align: center;
  margin-top: 20px;
}

#lineup-result {
  background-color: #e9ecef;
  padding: 20px;
  border-radius: 5px;
  min-height: 100px;
  font-size: 18px;
  line-height: 1.6;
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  justify-content: center;
  align-items: flex-start;
}

@media (min-width: 1201px) {
  /* 大螢幕 - 使用固定列數而非自適應 */
  .court-container {
    grid-template-columns: repeat(4, 1fr); /* 預設4列，每列佔25% */
    max-width: 100%; /* 確保容器不超過父元素 */
    margin-left: auto;
    margin-right: auto;
    gap: 15px; /* 增加場地之間的間距 */
  }
  
  /* 我們將在JS中動態設置class以控制列數 */
  .court-container.court-count-2 {
    grid-template-columns: repeat(2, 1fr); /* 當只有2個項目時，每個佔50% */
  }
  
  .court-container.court-count-3 {
    grid-template-columns: repeat(3, 1fr); /* 當只有3個項目時，每個佔33.33% */
  }
  
  .court-container.court-count-4 {
    grid-template-columns: repeat(4, 1fr); /* 當有4個項目時，每個佔25% */
    gap: 10px; /* 場地多時減少間距 */
  }
}

@media (max-width: 1200px) {
  .court-container {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 5px;
  }
  
  /* 在中等螢幕上也應用court-count類別 */
  .court-container.court-count-4 {
    grid-template-columns: repeat(2, 1fr); /* 在較小螢幕上改為2列 */
  }
}

@media (max-width: 900px) {
  .court-container {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 5px;
  }
  
  /* 在更小的螢幕上所有場地都單獨一行 */
  .court-container.court-count-3,
  .court-container.court-count-4 {
    grid-template-columns: 1fr; /* 單列顯示 */
  }
  
  /* 調整場地高度以避免太長的垂直滾動 */
  .court-visual {
    aspect-ratio: 1/0.8;
  }
}

#lineup-result p {
  margin: 10px 0;
  padding: 8px;
  background-color: #fff;
  border-left: 4px solid #007bff;
}

#lineup-result p:nth-child(odd) {
  background-color: #f8f9fa;
}

.disabled {
  opacity: 0.5;
}

#court-row-container {
  min-height: 200px;
}

/* 4個或更多場地的特殊樣式調整 */
.court-container.court-count-4 .court-visual {
  aspect-ratio: 1/0.9; /* 稍微降低高度比例 */
}

.court-container.court-count-4 .court-next-btn {
  padding: 8px 20px; /* 縮小按鈕大小 */
  font-size: 16px; /* 縮小文字大小 */
}

.court-container.court-count-4 .court-names-top {
  top: 15%; /* 調整位置 */
}

.court-container.court-count-4 .court-names-bottom {
  bottom: 15%; /* 調整位置 */
}

/* 特別處理.container在有多場地時的樣式 */
@media (min-width: 992px) {
  .container {
    padding: 30px 15px; /* 左右減少內邊距 */
  }
  
  /* 當screen寬度≥992px，且有4場地時，允許容器更寬 */
  .court-count-4 {
    max-width: 100%; /* 完全填滿容器 */
  }
}
