@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Rajdhani:wght@500;700&display=swap');
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: #0a0a12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  font-family: 'Rajdhani', sans-serif;
  color: #fff;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  position: fixed;
  width: 100%;
  height: 100%;
}
#game-wrapper { position: relative; width: 100vw; height: 100vh; }
canvas {
  cursor: none;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}
#hud {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 64px;
  display: flex;
  pointer-events: none;
  z-index: 2;
}
#hud-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0), rgba(0,0,10,0.95) 30%);
}
.hud-left, .hud-right {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  padding: 8px 14px;
}
.hud-left { flex: 1; gap: 12px; }
.hud-right {
  gap: 0;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  padding-bottom: 10px;
}
.hud-period {
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  color: #0f0;
  opacity: 0.7;
}
.hud-clock {
  font-family: 'Orbitron', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #0f0;
  text-shadow: 0 0 8px rgba(0,255,0,0.3);
}
.hud-arrow { font-size: 20px; opacity: 0.5; }
.hud-score-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Orbitron', sans-serif;
  font-size: 14px;
}
.hud-score-row .name {
  letter-spacing: 2px;
  opacity: 0.7;
  min-width: 40px;
  text-align: right;
}
.hud-score-row .sc {
  font-size: 22px;
  font-weight: 900;
  min-width: 24px;
  text-align: center;
}
.hud-score-row.home .sc { color: #ff4444; }
.hud-score-row.away .sc { color: #4499ff; }

/* Overlay */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(5,5,15,0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(10px);
  overflow-y: auto;
  padding: 20px 0;
}
/* Olympic rings */
#olympic-rings {
  width: 200px;
  height: 90px;
  margin-bottom: 12px;
}
/* Prevent overlay canvases from stretching to 100% */
#overlay canvas, .hud-score-row canvas {
  width: auto;
  height: auto;
  cursor: default;
}
#overlay h1 {
  font-family: 'Orbitron', sans-serif;
  font-size: 52px;
  font-weight: 900;
  background: linear-gradient(135deg, #fff, #8cc8ff, #fff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
  letter-spacing: 3px;
}
#overlay h2 {
  font-family: 'Orbitron', sans-serif;
  font-size: 14px;
  letter-spacing: 10px;
  color: rgba(255,255,255,0.4);
  margin-bottom: 10px;
}

/* ---- Bracket Spider ---- */
#bracket {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0;
  width: min(820px, 95vw);
  margin-bottom: 16px;
  align-items: center;
  position: relative;
}

/* Semi columns */
.br-semi {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
}
.br-label {
  font-family: 'Orbitron', sans-serif;
  font-size: 9px;
  letter-spacing: 3px;
  color: rgba(255,255,255,0.3);
  text-align: center;
  margin-bottom: 2px;
}

/* Team card */
.br-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  background: rgba(255,255,255,0.04);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.25s;
  min-width: 130px;
  position: relative;
}
.br-team:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,200,0,0.4);
  transform: scale(1.05);
}
.br-team:active { transform: scale(0.97); }
.br-team.picked {
  border-color: rgba(255,200,0,0.7);
  background: rgba(255,200,0,0.1);
  box-shadow: 0 0 24px rgba(255,200,0,0.15);
}
.br-team.winner {
  border-color: rgba(100,100,120,0.4);
  background: rgba(255,255,255,0.04);
}
.br-team.loser {
  opacity: 0.25;
  transform: scale(0.95);
  filter: grayscale(0.5);
}
.br-team.locked {
  opacity: 0.15;
  cursor: default;
  pointer-events: none;
}
.br-team.medal-gold {
  border-color: rgba(255,215,0,0.7);
  background: rgba(255,215,0,0.12);
  box-shadow: 0 0 30px rgba(255,215,0,0.25);
}
.br-team.medal-gold .br-name { color: #ffd700; }
.br-team.medal-silver {
  border-color: rgba(192,192,192,0.6);
  background: rgba(192,192,192,0.08);
  box-shadow: 0 0 16px rgba(192,192,192,0.12);
}
.br-team.medal-silver .br-name { color: #c0c0c0; }
.br-team.medal-bronze {
  border-color: rgba(205,127,50,0.6);
  background: rgba(205,127,50,0.08);
  box-shadow: 0 0 16px rgba(205,127,50,0.12);
}
.br-team.medal-bronze .br-name { color: #cd7f32; }
.br-flag {
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 4px;
}
.br-name {
  font-family: 'Orbitron', sans-serif;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 3px;
  color: #fff;
}
.br-score {
  font-family: 'Orbitron', sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: rgba(255,255,255,0.5);
  min-height: 16px;
}

/* Matchup score between two teams */
.br-matchup-score {
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.4);
  letter-spacing: 2px;
  padding: 2px 0;
}

/* Vertical connector between semi teams */
.br-connector-v {
  width: 2px;
  height: 8px;
  background: rgba(255,255,255,0.12);
}

/* Center column */
.br-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 0 6px;
}
.br-final-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.br-final-label {
  font-family: 'Orbitron', sans-serif;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 5px;
  color: rgba(255,215,0,0.35);
  padding: 0 6px;
}
.br-final-team {
  min-width: 100px;
  cursor: default;
}
.br-final-team.locked { pointer-events: none; }
.br-connector-h {
  width: 24px;
  height: 2px;
  background: rgba(255,255,255,0.12);
}
.br-bronze-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.br-bronze-row .br-label { width: 100%; text-align: center; margin-bottom: 0; }
.br-bronze-team {
  min-width: 70px;
  padding: 6px 10px;
  cursor: default;
}
.br-bronze-team .br-flag { width: 50px; height: 30px; }
.br-bronze-team .br-name { font-size: 13px; }
.br-bronze-team .br-score { font-size: 10px; }
.br-bronze-vs {
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  color: rgba(255,255,255,0.15);
}

/* Pick hint */
#pick-hint {
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  letter-spacing: 4px;
  color: rgba(255,200,0,0.5);
  margin-bottom: 8px;
  animation: hintPulse 2s ease-in-out infinite;
}
@keyframes hintPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Medal display — podium style */
#medal-display {
  text-align: center;
  font-family: 'Orbitron', sans-serif;
  margin: 12px 0 4px;
  padding: 16px 30px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
}
#medal-display .podium-title {
  font-size: 10px;
  letter-spacing: 5px;
  color: rgba(255,255,255,0.3);
  margin-bottom: 12px;
}
.medal-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 8px 0;
  letter-spacing: 2px;
}
.medal-row .medal { font-size: 26px; }
.medal-row .medal-team {
  font-weight: 900;
  font-size: 16px;
}
.medal-row.gold { color: #ffd700; }
.medal-row.gold .medal-team { font-size: 22px; text-shadow: 0 0 12px rgba(255,215,0,0.3); }
.medal-row.silver { color: #c0c0c0; }
.medal-row.bronze { color: #cd7f32; }
.matchup-row {
  display: flex;
  align-items: center;
  gap: 30px;
  margin-bottom: 20px;
}
.team-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 120px;
}
.team-card canvas {
  width: 80px;
  height: 50px;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  cursor: default;
}
.team-name {
  font-family: 'Orbitron', sans-serif;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 3px;
}
.team-roster {
  font-size: 11px;
  opacity: 0.5;
  text-align: center;
  line-height: 1.5;
}
.vs-text {
  font-family: 'Orbitron', sans-serif;
  font-size: 28px;
  font-weight: 900;
  color: rgba(255,255,255,0.3);
}
.matchup-picker {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.matchup-btn {
  padding: 8px 20px;
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.5);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.matchup-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.matchup-btn.active {
  background: rgba(200,0,0,0.3);
  color: #fff;
  border-color: rgba(200,0,0,0.5);
}
.hud-score-row canvas {
  vertical-align: middle;
  border-radius: 2px;
}
/* Replay overlay */
#replay-overlay {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 6;
  pointer-events: none;
}
#replay-overlay .replay-label {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Orbitron', sans-serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 6px;
  color: rgba(255,100,100,0.8);
  text-shadow: 0 0 10px rgba(255,0,0,0.3);
  padding: 6px 24px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,100,100,0.3);
  border-radius: 4px;
}

#overlay .start-btn {
  padding: 16px 60px;
  font-size: 18px;
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #c00, #900);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 20px rgba(200,0,0,0.3);
}
#overlay .start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 30px rgba(200,0,0,0.5);
}
#overlay .ch {
  margin-top: 40px;
  display: flex;
  gap: 30px;
  opacity: 0.4;
  font-size: 13px;
}
#overlay .ch kbd {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 2px 8px;
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
}
#goal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255,0,0,0.15), transparent 70%);
}
#goal-overlay .gt {
  font-family: 'Orbitron', sans-serif;
  font-size: 100px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 40px #f00, 0 0 80px rgba(255,0,0,0.5);
  animation: gp 0.15s ease-in-out infinite alternate;
}
@keyframes gp {
  from { transform: scale(1) }
  to { transform: scale(1.08) }
}

/* ---- Touch Controls ---- */
#touch-controls {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}
/* Show on touch devices */
@media (pointer: coarse) {
  #touch-controls { display: block; }
  #overlay .ch { display: none; }
}

/* Joystick zone — left half of screen */
#joystick-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 50%;
  height: 60%;
  pointer-events: auto;
  touch-action: none;
}
#joystick-base {
  position: absolute;
  bottom: 90px;
  left: 40px;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}
#joystick-knob {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: 2px solid rgba(255,255,255,0.3);
  transition: transform 0.05s;
}

/* Action buttons — right side */
#touch-buttons {
  position: absolute;
  right: 16px;
  bottom: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  touch-action: none;
}
.touch-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
}
.touch-btn:active, .touch-btn.pressed {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.5);
}
#btn-shoot {
  width: 80px;
  height: 80px;
  background: rgba(200,0,0,0.2);
  border-color: rgba(200,0,0,0.4);
  font-size: 11px;
  color: rgba(255,100,100,0.9);
}
#btn-shoot:active, #btn-shoot.pressed {
  background: rgba(200,0,0,0.4);
  border-color: rgba(200,0,0,0.7);
}
#btn-sprint {
  width: 56px;
  height: 56px;
  font-size: 8px;
  background: rgba(0,200,100,0.12);
  border-color: rgba(0,200,100,0.3);
}
#btn-sprint:active, #btn-sprint.pressed {
  background: rgba(0,200,100,0.3);
}
#btn-switch {
  width: 52px;
  height: 52px;
  font-size: 9px;
}
/* Layout: shoot big center, pass left, switch top-right, sprint bottom */
#touch-buttons {
  display: grid;
  grid-template-areas:
    ". switch"
    "pass shoot"
    "sprint .";
  grid-template-columns: 68px 80px;
  grid-template-rows: 56px 80px 56px;
  gap: 8px;
  align-items: center;
  justify-items: center;
}
#btn-shoot { grid-area: shoot; }
#btn-pass { grid-area: pass; }
#btn-switch { grid-area: switch; }
#btn-sprint { grid-area: sprint; }

/* Mobile overlay adjustments */
@media (pointer: coarse) {
  #overlay h1 { font-size: 24px; }
  #overlay h2 { font-size: 9px; letter-spacing: 5px; }
  #olympic-rings { width: 120px; height: 54px; margin-bottom: 6px; }
  .br-team { min-width: 90px; padding: 6px 8px; }
  .br-semi .br-flag { width: 60px; height: 37px; }
  .br-name { font-size: 14px; }
  .br-final-label { font-size: 10px; letter-spacing: 4px; }
  .br-final-team { min-width: 70px; }
  .br-final-team .br-flag { width: 50px; height: 30px; }
  .br-final-team .br-name { font-size: 12px; }
  #overlay .start-btn { padding: 14px 40px; font-size: 15px; }
  #hud { height: 50px; }
  .hud-clock { font-size: 16px !important; }
  .hud-score-row { font-size: 11px !important; }
  .hud-score-row .sc { font-size: 16px !important; }
  #goal-overlay .gt { font-size: 60px; }
  #overlay .ch { display: none; }
}
