* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  overflow: hidden;
  background: #fff;
}

canvas {
  position: relative;
  display: block;
  width: 100vw;
  height: 100vh;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}

#multiplayer, #instructions {
  position: fixed;
  bottom: 16px;
  max-width: min(280px, calc(50vw - 24px));
  font: 12px/1.4 system-ui, sans-serif;
  color: #666;
}
#multiplayer { left: 16px; top: 16px; bottom: auto; }
#instructions { right: 16px; text-align: right; pointer-events: none; }
#multiplayer p { margin: 6px 0; }
#multiplayer button {
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: #162c20;
  text-decoration: underline;
  text-underline-offset: 3px;
  font: inherit;
  cursor: pointer;
}
#multiplayer input { width: 100%; min-width: 0; padding: 6px; margin-top: 4px; border: 1px solid #ddd; background: #ffffffdf; font: inherit; }
#instructions small { font: inherit; }

/* Match the visible screen when mobile browser toolbars change height. */
@supports (height: 100dvh) {
  html, body { min-height: 100dvh; }
  canvas { height: 100dvh; }
}

.goal-art { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.goal { position: absolute; bottom: -45px; width: clamp(300px, 49.5vw, 616px); max-height: 88vh; object-fit: contain; }
.goal { left: max(-95px, -7.2vw); transform: scaleX(-1); }
body.player-two .goal { left: auto; right: max(-95px, -7.2vw); transform: none; }

/* Hide the source image’s bottom caption strip. */
.goal { clip-path: inset(0 0 8% 0); }

#score { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); font: 700 28px monospace; color: #92712d; pointer-events: none; }

.combo-popup {
  text-align: center;
  position: fixed;
  z-index: 4;
  pointer-events: none;
  color: #e9bb52;
  font: clamp(40px, 9vw, 84px)/1 adidas_unity, Impact, sans-serif;
  letter-spacing: -.025em;
  -webkit-text-stroke: .5px #855a16;
  text-shadow: 0 2px 0 #fff0b7, 0 4px 0 #8f651e, 0 6px 0 #382a1633;
  white-space: nowrap;
}

.combo-popup-power {
  display: block;
  margin-bottom: 3px;
  text-align: center;
  font: 700 clamp(12px, 2.4vw, 20px)/1 system-ui, sans-serif;
  letter-spacing: .08em;
  -webkit-text-stroke: 0;
}

.combo-popup-streak {
  display: block;
  margin-top: 4px;
  text-align: center;
  font: 700 clamp(14px, 2vw, 20px)/1 system-ui, sans-serif;
  letter-spacing: .06em;
  -webkit-text-stroke: 0;
}

#goal-celebration {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  font: clamp(32px, 11vw, 160px)/1 adidas_unity, Impact, sans-serif;
  letter-spacing: -.035em;
  color: #e9bb52;
  -webkit-text-stroke: 1px #855a16;
  text-shadow: 0 2px 0 #fff0b7, 0 5px 0 #8f651e, 0 9px 0 #382a1633;
}

.player-name { position: fixed; bottom: 16px; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 18px/1.2 system-ui, sans-serif; color: #92712d; pointer-events: none; }
.name-left { left: 18px; }
.name-right { right: 18px; text-align: right; }
#username-label { font-size: 11px; }

/* Each screen shows only its own player's name beside its goal. */
body:not(.player-two) #player-two { display: none; }
body.player-two #player-one { display: none; }

body.connected #multiplayer { display: none; }
body.connected .player-name { top: 16px; bottom: auto; left: 18px; right: auto; text-align: left; }

#multiplayer[hidden] { display: none !important; }

body.connected.player-two .player-name { left: auto; right: 18px; text-align: right; }

#coin-flip { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; background: #ffffffe8; pointer-events: none; font: 700 22px system-ui, sans-serif; color: #876021; }
#coin-flip[hidden] { display: none; }
#coin { width: 120px; height: 120px; display: grid; place-items: center; border-radius: 50%; border: 7px double #976d22; background: linear-gradient(145deg, #fff1bc, #c39232 55%, #ffe8a0); box-shadow: 0 6px 0 #78531a; font: 700 20px monospace; }
#coin-result { max-width: 90vw; text-align: center; overflow-wrap: anywhere; }

#coin { padding: 10px; text-align: center; overflow-wrap: anywhere; font-size: 16px; line-height: 1.1; }

#multiplayer { max-height: calc(100dvh - 32px); overflow-y: auto; }

#room-options label { display: block; margin-top: 10px; font-size: 11px; }
#room-code, #display-code { text-transform: uppercase; letter-spacing: .15em; }
#display-code { font: 700 28px monospace; margin: 8px 0; }
#room-details { margin-top: 10px; overflow-wrap: anywhere; }
#end-session { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); border: 0; background: #ffffffcc; color: #777; padding: 6px 10px; font: 11px system-ui; cursor: pointer; }

.room-actions { display: flex; align-items: center; gap: 20px; }

#swap-sides { position: fixed; bottom: 12px; right: 16px; border: 0; background: #ffffffcc; color: #777; padding: 6px 10px; font: 12px system-ui; cursor: pointer; }
