* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  min-height: 100%;
  background: #0d1710;
  color: #eef2ea;
  font-family: 'Segoe UI', system-ui, sans-serif;
}
#app { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
#fileProtocolWarning { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
#fileProtocolWarning code { background: rgba(255,255,255,0.1); padding: 1px 5px; border-radius: 4px; }

#matchScreen, #menuScreen, #joinCodeScreen, #lobbyScreen { display: none; }
#app[data-screen="menu"] #menuScreen { display: flex; }
#app[data-screen="match"] #matchScreen { display: flex; }
#app[data-screen="joincode"] #joinCodeScreen { display: flex; justify-content: center; width: 100%; }
#app[data-screen="lobby"] #lobbyScreen { display: flex; justify-content: center; width: 100%; }

/* ---- Menu ---- */
#menuScreen { width: 100%; justify-content: center; position: relative; overflow: hidden; }
#menuBgCanvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(0.4) blur(1.5px) saturate(0.8);
  image-rendering: pixelated;
  pointer-events: none;
}
/* An absolutely-positioned element (the canvas) stacks above a static one
   regardless of DOM order — the card needs its own position+z-index to
   actually land on top instead of being covered by the background. */
#menuScreen .menuCard { position: relative; z-index: 1; }
.menuCard {
  background: linear-gradient(180deg, #16261a, #101b12);
  border: 2px solid #2c4a2f;
  border-radius: 14px;
  padding: 28px 32px 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}
.menuCard h1 {
  margin: 0 0 2px;
  font-size: 2rem;
  letter-spacing: 1px;
  background: linear-gradient(180deg, #fff, #b7e0a8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { margin: 0 0 20px; color: #9db894; font-size: 0.85rem; }
.logoImg { display: block; max-width: 100%; height: auto; margin: 0 0 18px; }

#soundToggleBtn {
  position: fixed;
  top: 8px; right: 8px;
  z-index: 20;
  padding: 6px 12px;
  font-size: 0.72rem;
  background: rgba(10,20,10,0.65);
  border: 1px solid rgba(255,255,255,0.25);
  color: #cfe3c8;
  border-radius: 6px;
  cursor: pointer;
}
#soundToggleBtn:hover { background: rgba(10,20,10,0.9); color: #fff; }
.optionBlock { margin-bottom: 16px; }
.optionBlock h2 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1.5px; color: #8fae87; margin: 0 0 8px; }
.btnGroup { display: flex; gap: 8px; flex-wrap: wrap; }
.toggleBtn {
  flex: 1 1 auto;
  padding: 9px 10px;
  background: #1c2e1f;
  border: 1px solid #35543a;
  color: #cfe3c8;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s, border-color 0.15s;
}
.toggleBtn:hover { background: #24402a; }
.toggleBtn.active { background: #3f8f4d; border-color: #59c76a; color: #fff; font-weight: 600; }
#teamSizeGroup.hidden, #lengthGroup.hidden, #lobbyTeamSizeGroup.hidden { display: none; }

.errorText {
  margin-top: 10px;
  padding: 8px 10px;
  background: rgba(220,60,60,0.12);
  border: 1px solid rgba(220,60,60,0.4);
  color: #ff9a9a;
  border-radius: 8px;
  font-size: 0.8rem;
}

.codeInput {
  width: 100%;
  padding: 14px;
  margin-bottom: 12px;
  font-size: 1.6rem;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
  background: #1c2e1f;
  border: 1px solid #35543a;
  border-radius: 8px;
  color: #fff;
}
.codeInput:focus { outline: none; border-color: #59c76a; }

.nameInput {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.95rem;
  background: #1c2e1f;
  border: 1px solid #35543a;
  border-radius: 8px;
  color: #fff;
}
.nameInput:focus { outline: none; border-color: #59c76a; }

.roomCode {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.roomCode span {
  flex: 1;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 6px;
  text-align: center;
  background: #1c2e1f;
  border: 1px solid #35543a;
  border-radius: 8px;
  padding: 10px;
}
.secondaryBtn.small { width: auto; margin-top: 0; padding: 10px 16px; }

.playerList { display: flex; flex-direction: column; gap: 6px; }
.playerRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: #1c2e1f;
  border: 1px solid #2c4a2f;
  border-radius: 8px;
  font-size: 0.85rem;
}
.playerTeam { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.5px; padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.playerTeam.team-home { background: rgba(216,30,44,0.25); color: #ff8f97; }
.playerTeam.team-away { background: rgba(36,86,201,0.25); color: #9ec2ff; }
.playerTeam.team-spectate { background: rgba(255,255,255,0.08); color: #9db894; }
.playerRow { flex-wrap: wrap; gap: 6px; }
.playerRowMeta { display: flex; align-items: center; gap: 8px; }
.hostTransferBtns { display: flex; gap: 4px; }
.hostTransferBtns button {
  font-size: 0.65rem;
  padding: 3px 6px;
  background: #14231a;
  border: 1px solid #35543a;
  color: #cfe3c8;
  border-radius: 5px;
  cursor: pointer;
}
.hostTransferBtns button:hover { background: #24402a; }
.hostTransferBtns button.active { background: #3f8f4d; border-color: #59c76a; color: #fff; }

.primaryBtn {
  width: 100%;
  margin-top: 8px;
  padding: 13px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #58cf6a, #2f9440);
  color: #08240c;
  cursor: pointer;
  box-shadow: 0 4px 0 #1f6b2c;
}
.primaryBtn:active { transform: translateY(2px); box-shadow: 0 2px 0 #1f6b2c; }
.primaryBtn:disabled { opacity: 0.55; cursor: default; box-shadow: none; }
.secondaryBtn {
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  font-size: 0.9rem;
  border-radius: 8px;
  border: 1px solid #45624a;
  background: transparent;
  color: #cfe3c8;
  cursor: pointer;
}
.secondaryBtn:hover { background: #1c2e1f; }

.controlsHint {
  margin-top: 18px;
  font-size: 0.72rem;
  color: #7f9c78;
  line-height: 1.5;
  border-top: 1px solid #2c4a2f;
  padding-top: 12px;
}
.creditLine { margin: 10px 0 0; text-align: center; font-size: 0.72rem; color: #7f9c78; }
.creditLine a { color: #b7e0a8; text-decoration: underline; }
.creditLine a:hover { color: #fff; }
.creditLine strong { color: #b7e0a8; }

.overlayCard.infoCard { max-width: 480px; max-height: 80vh; overflow-y: auto; text-align: left; }
.infoCard h2 { text-align: center; }
.infoText { font-size: 0.85rem; color: #cfe3c8; line-height: 1.5; }
.infoText p { margin: 0 0 10px; }
.infoText ul { margin: 0 0 10px; padding-left: 20px; }
.infoText li { margin-bottom: 6px; }

/* ---- Match screen ---- */
#matchScreen { flex-direction: column; align-items: center; gap: 8px; width: 100%; max-width: 100%; }
#tourneyBar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  background: #131f14;
  border: 1px solid #2c4a2f;
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 0.8rem;
  color: #9db894;
}
#tourneyWatchButtons button {
  font-size: 0.75rem;
  padding: 5px 10px;
  background: #1c2e1f;
  border: 1px solid #35543a;
  color: #cfe3c8;
  border-radius: 6px;
  cursor: pointer;
}
#tourneyWatchButtons button.active { background: #3f8f4d; border-color: #59c76a; color: #fff; }
#hud {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #131f14;
  border: 1px solid #2c4a2f;
  border-radius: 10px;
  padding: 8px 18px;
  font-variant-numeric: tabular-nums;
}
.hudSide { display: flex; align-items: center; gap: 10px; min-width: 100px; }
.hudSide.away { justify-content: flex-end; }
.teamName { font-size: 0.75rem; letter-spacing: 1px; color: #9db894; }
.score { font-size: 1.6rem; font-weight: 800; }
.hudMid { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
#clock { font-size: 1.2rem; font-weight: 700; }
#halfLabel { font-size: 0.7rem; color: #9db894; }

#canvasWrap {
  position: relative;
  width: 100%;
  /* Cap width so the 912x536 pitch (aspect ~1.701) always fits vertically,
     but otherwise stretch as wide as the viewport allows. */
  max-width: min(100%, calc((100vh - 110px) * 1.701));
  margin: 0 auto;
  line-height: 0;
}
#persistentMenuBtn {
  position: absolute;
  top: 8px; left: 8px;
  z-index: 5;
  padding: 5px 10px;
  font-size: 0.72rem;
  background: rgba(10,20,10,0.65);
  border: 1px solid rgba(255,255,255,0.25);
  color: #cfe3c8;
  border-radius: 6px;
  cursor: pointer;
}
#persistentMenuBtn:hover { background: rgba(10,20,10,0.9); color: #fff; }
#game { width: 100%; height: auto; display: block; border-radius: 8px; border: 2px solid #2c4a2f; background: #1c2b1a; image-rendering: pixelated; }
#hud { max-width: min(100%, calc((100vh - 110px) * 1.701)); margin: 0 auto; }

.overlayBanner {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(10,20,10,0.85);
  border: 1px solid #59c76a;
  color: #fff;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 2px;
  padding: 8px 22px;
  border-radius: 8px;
  pointer-events: none;
}
.overlayScreen {
  position: absolute; inset: 0;
  z-index: 10;
  background: rgba(6,12,7,0.72);
  display: flex; align-items: center; justify-content: center;
}
.overlayCard {
  background: #14231a;
  border: 2px solid #3f8f4d;
  border-radius: 12px;
  padding: 24px 30px;
  min-width: 240px;
  text-align: center;
}
.overlayCard h2 { margin: 0 0 12px; }
.finalScore { font-size: 2rem; font-weight: 800; margin-bottom: 4px; }
.resultText { color: #9db894; margin-bottom: 14px; }

.hidden { display: none !important; }

@media (max-width: 640px) {
  .menuCard { padding: 20px; }
  .hudSide { min-width: 70px; }
  .score { font-size: 1.2rem; }
}

/* TSG corner logo on main menu */
.tsgCornerLink{position:fixed;top:24px;left:24px;z-index:50;display:block;line-height:0;}
.tsgCornerLogo{height:48px;width:auto;display:block;image-rendering:pixelated;}
@media (max-width:640px){.tsgCornerLogo{height:32px;}.tsgCornerLink{top:12px;left:12px;}}
