* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(160deg, #0b3d1f, #061f10);
  color: #f0f0f0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.hidden { display: none !important; }

.card {
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}

.lobby-card { max-width: 640px; text-align: left; }

h1 { margin: 0 0 6px; font-size: 28px; }
h2 { margin: 0 0 6px; }
h3 { margin: 18px 0 8px; font-size: 15px; color: #cfe8d8; text-transform: uppercase; letter-spacing: 0.05em; }

.subtitle { color: #b9d9c4; margin-bottom: 18px; }

input[type="text"], input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 16px;
  margin-bottom: 12px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(0.98); }

.btn-primary { background: #2ecc71; color: #06210f; }
.btn-secondary { background: rgba(255,255,255,0.15); color: #fff; }

.error-text { color: #ff8a8a; min-height: 18px; font-size: 14px; margin: 6px 0; }
.disclaimer { font-size: 12px; color: #9fbcaa; margin-top: 16px; }
.hint { font-size: 13px; color: #a9c9b6; }

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.balance { font-size: 16px; font-weight: 700; color: #ffd45e; }

.team-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.team-chip {
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.team-chip.selected { border-color: #ffd45e; box-shadow: 0 0 0 2px #ffd45e inset; }

.entry-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
}
.entry-row input { width: 120px; margin-bottom: 0; }

.chip {
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08);
  color: #fff;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
}
.chip.selected { background: #2ecc71; color: #06210f; border-color: #2ecc71; font-weight: 700; }

.action-row { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }

.leaderboard { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; }
.leaderboard td { padding: 4px 6px; border-bottom: 1px solid rgba(255,255,255,0.08); }

.spinner {
  width: 42px; height: 42px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: #2ecc71;
  border-radius: 50%;
  margin: 18px auto;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#waitingInfo { color: #b9d9c4; }

.match-hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: rgba(0,0,0,0.55);
  z-index: 5;
}
.hud-center { display: flex; flex-direction: column; align-items: center; }
#hudScore { font-size: 22px; font-weight: 800; }
#hudTimer { font-size: 14px; color: #cfe8d8; }
.team-badge { font-weight: 700; padding: 6px 14px; border-radius: 8px; font-size: 14px; }

#screen-match { flex-direction: column; padding-top: 70px; }

#canvasWrap {
  position: relative;
  max-width: 96vw;
  max-height: 58vh;
  line-height: 0;
}

#reconnectBanner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  border: 1px solid rgba(255,212,94,0.6);
  color: #ffd45e;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  max-width: 92%;
  z-index: 6;
}

canvas {
  background: #1a7a34;
  border-radius: 10px;
  max-width: 96vw;
  max-height: 58vh;
  width: auto;
  height: auto;
  display: block;
  box-shadow: 0 12px 30px rgba(0,0,0,0.5);
  touch-action: none;
}

.controls-hint { color: #cfe8d8; font-size: 13px; margin-top: 10px; text-align: center; }

/* Touch controls: a bar BELOW the field (never on top of it, so fingers
   never cover the ball/action) -- only shown on touch-primary devices
   (phones/tablets); mouse/keyboard users never see them. */
#touchControls { display: none; }

@media (pointer: coarse) {
  #touchControls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 96vw;
    margin-top: 14px;
    padding: 0 10px;
  }
  #joystickBase {
    position: relative;
    width: 132px;
    height: 132px;
    flex-shrink: 0;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    border: 2px solid rgba(255,255,255,0.2);
    touch-action: none;
    user-select: none;
  }
  #joystickStick {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 60px;
    height: 60px;
    margin-left: -30px;
    margin-top: -30px;
    border-radius: 50%;
    background: rgba(46,204,113,0.55);
    border: 2px solid rgba(255,255,255,0.5);
    pointer-events: none;
    transition: transform 0.03s linear;
  }

  #kickBtn {
    width: 78px;
    height: 78px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.2);
    font-size: 30px;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
    flex-shrink: 0;
  }
  #kickBtn:active, #kickBtn.active-touch { background: rgba(231,76,60,0.75); }
}

.end-score { font-size: 32px; font-weight: 800; margin: 10px 0; }
#endPot { color: #ffd45e; font-weight: 700; }
#endBalance { color: #cfe8d8; }
