* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  background: #0a0a0a; overflow: hidden; font-family: 'Segoe UI', Arial, sans-serif; user-select: none;
  overscroll-behavior: none; touch-action: none; height: 100%;
}

#hud {
  position: fixed; top: 0; left: 0; right: 0; height: 60px;
  padding-top: env(safe-area-inset-top);
  height: calc(60px + env(safe-area-inset-top));
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border-bottom: 2px solid #0d3b66;
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 24px; padding-right: 24px; z-index: 10; color: white; gap: 12px;
}

@media (max-width: 640px) {
  #hud { height: calc(40px + env(safe-area-inset-top)); padding-left: 8px; padding-right: 8px; gap: 4px; }
  .hud-block { min-width: 44px; }
  .hud-lbl { font-size: 6px; margin-bottom: 0; }
  .hud-val { font-size: 11px; }
  #hud-score { font-size: 16px; gap: 4px; }
  .tbadge { width: 16px; height: 16px; border-width: 1px; }
  #poss-val { font-size: 10px; padding: 3px 6px; min-width: 66px; border-radius: 7px; }
}

@media (max-width: 380px) {
  #hud { height: calc(36px + env(safe-area-inset-top)); padding-left: 6px; padding-right: 6px; gap: 3px; }
  .hud-block { min-width: 38px; }
  .hud-val { font-size: 10px; }
  #hud-score { font-size: 14px; gap: 3px; }
  .tbadge { width: 14px; height: 14px; }
  #poss-val { font-size: 9px; padding: 2px 5px; min-width: 56px; }
}
.hud-block { display: flex; flex-direction: column; align-items: center; min-width: 80px; }
.hud-lbl { font-size: 9px; letter-spacing: 1px; text-transform: uppercase; color: #777; margin-bottom: 2px; }
.hud-val { font-size: 15px; font-weight: bold; }
#hud-score { display: flex; align-items: center; gap: 8px; font-size: 26px; font-weight: 900; }
.tbadge { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); }
#sy { color: #FFD700; } #sb { color: #87CEEB; }
#timer-val { font-family: 'Courier New', monospace; font-size: 19px; color: #fff; }
#poss-val {
  font-size: 16px;
  font-weight: bold;
  padding: 8px 14px;
  border-radius: 10px;
  animation: pulsePossession 1.5s ease-in-out infinite;
  min-width: 140px;
  text-align: center;
  transition: all .3s ease;
}
#poss-val.poss-yellow {
  background: rgba(255,215,0,.15);
  border: 2px solid #FFD700;
  color: #FFD700;
}
#poss-val.poss-blue {
  background: rgba(135,206,235,.15);
  border: 2px solid #87CEEB;
  color: #87CEEB;
}
@keyframes pulsePossession {
  0%, 100% { box-shadow: 0 0 12px currentColor; transform: scale(1); }
  50% { box-shadow: 0 0 20px currentColor; transform: scale(1.05); }
}

#toast-container {
  position: fixed; top: 80px; left: 50%; transform: translateX(-50%); z-index: 20; pointer-events: none;
}
.toast-pill {
  background: rgba(20, 28, 58, 0.95);
  border: 1px solid rgba(100, 160, 255, 0.25);
  color: #d8e8ff; font-size: 13px; padding: 9px 16px;
  border-radius: 24px; max-width: 240px; text-align: center; line-height: 1.4;
  animation: toastIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.1) forwards;
}
.toast-pill.toast-warning { border-color: rgba(255, 180, 50, 0.45); color: #ffe0a0; }
.toast-pill.toast-goal { border-color: rgba(255, 215, 0, 0.55); color: #FFD700; font-size: 15px; font-weight: bold; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.92); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 640px) {
  #toast-container { top: calc(46px + env(safe-area-inset-top)); }
  .toast-pill { font-size: 11px; padding: 5px 10px; max-width: 190px; line-height: 1.25; border-radius: 16px; }
  .toast-pill.toast-goal { font-size: 12px; }
}
@media (max-width: 380px) {
  #toast-container { top: calc(40px + env(safe-area-inset-top)); }
  .toast-pill { font-size: 10px; padding: 4px 8px; max-width: 160px; border-radius: 13px; }
  .toast-pill.toast-goal { font-size: 11px; }
}

#canvas-wrap {
  position: fixed; top: calc(60px + env(safe-area-inset-top)); left: 0; right: 0; bottom: 0;
}
canvas { display: block; touch-action: none; }

@media (max-width: 640px) {
  #canvas-wrap { top: calc(40px + env(safe-area-inset-top)); }
}
@media (max-width: 380px) {
  #canvas-wrap { top: calc(36px + env(safe-area-inset-top)); }
}

/* ── Pre-game menu ─────────────────────────────────── */
#menu-overlay {
  position: fixed; inset: 0; display: flex; align-items: center;
  justify-content: center; z-index: 100; overflow-y: auto; padding: 20px;
  background:
    radial-gradient(ellipse at 25% 50%, rgba(0,50,10,.55) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 50%, rgba(0,20,50,.55) 0%, transparent 55%),
    #07090f;
}
#menu-overlay::before {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 72px 72px;
}
#menu-overlay.hidden { display: none; }

.menu-box {
  background: rgba(6, 10, 22, 0.93);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 20px; padding: 28px 32px 24px;
  color: white; max-width: 880px; width: 100%;
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 28px 80px rgba(0,0,0,.85);
  animation: menuIn .4s cubic-bezier(.175,.885,.32,1.1);
  position: relative;
}
@keyframes menuIn { from { transform: scale(.94) translateY(8px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

/* Header */
.menu-header { text-align: center; margin-bottom: 22px; }
.menu-title {
  font-size: 22px; font-weight: 900; color: #fff;
  letter-spacing: 5px; text-transform: uppercase;
}
.menu-title-gold { color: #FFD700; }

/* ── Team VS section ── */
.menu-vs-section {
  display: flex; align-items: stretch;
  border-radius: 14px; overflow: hidden;
  border: 1px solid rgba(255,255,255,.07);
  margin-bottom: 18px; min-height: 210px;
}

.menu-team-side {
  flex: 1; display: flex; align-items: center;
  padding: 22px 10px;
  transition: background .45s ease, border-top .45s ease;
}

.team-nav-btn {
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.13);
  color: rgba(255,255,255,.65);
  font-size: 26px; width: 36px; height: 36px;
  border-radius: 50%; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s, transform .1s;
  padding: 0; line-height: 1; z-index: 1;
}
.team-nav-btn:hover  { background: rgba(255,255,255,.18); color: #fff; transform: scale(1.12); }
.team-nav-btn:active { transform: scale(.93); }

.team-showcase { flex: 1; text-align: center; }

.team-badge-xl {
  width: 86px; height: 86px; border-radius: 50%;
  margin: 0 auto 14px;
  border: 3px solid rgba(255,255,255,.15);
  transition: background .35s, box-shadow .35s, border-color .35s;
}

.team-name-xl {
  font-size: 19px; font-weight: 900; color: #fff;
  letter-spacing: 1px; margin-bottom: 6px;
  transition: text-shadow .35s;
  text-shadow: 0 2px 10px rgba(0,0,0,.7);
}

.team-side-label {
  font-size: 8px; letter-spacing: 2.5px;
  text-transform: uppercase; color: rgba(255,255,255,.28);
}

/* VS divider */
.menu-vs-divider {
  width: 58px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px 0; gap: 10px;
  background: rgba(0,0,0,.35);
  border-left:  1px solid rgba(255,255,255,.05);
  border-right: 1px solid rgba(255,255,255,.05);
}
.vs-line {
  width: 1px; flex: 1;
  background: linear-gradient(to bottom, transparent, rgba(255,215,0,.35), transparent);
}
.vs-text {
  font-size: 20px; font-weight: 900; color: #FFD700;
  letter-spacing: 4px;
  text-shadow: 0 0 18px rgba(255,215,0,.55);
}

/* ── Settings bar ── */
.menu-settings-bar {
  display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px;
}
.setting-group {
  display: flex; align-items: center; gap: 12px;
}
.setting-lbl {
  font-size: 8px; letter-spacing: 2px; text-transform: uppercase;
  color: rgba(255,255,255,.28); white-space: nowrap; min-width: 52px;
}
.setting-tabs { display: flex; gap: 5px; flex: 1; }
.stab {
  flex: 1; padding: 7px 10px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  color: rgba(255,255,255,.45);
  border-radius: 8px; font-size: 11px; font-weight: 600;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.stab:hover  { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.22); }
.stab.selected {
  background: rgba(255,215,0,.1);
  border-color: #FFD700; color: #FFD700;
}

/* Start button */
.menu-start-btn {
  display: block; width: 100%;
  background: linear-gradient(135deg, #FFD700, #FFA500);
  color: #000; border: none; padding: 15px;
  font-size: 18px; font-weight: 900; border-radius: 12px; cursor: pointer;
  transition: transform .1s, box-shadow .1s; letter-spacing: 2px;
  box-shadow: 0 4px 20px rgba(255,215,0,.3);
}
.menu-start-btn:hover  { transform: scale(1.02); box-shadow: 0 6px 32px rgba(255,215,0,.5); }
.menu-start-btn:active { transform: scale(.98); }

/* ── Half-time / Full-time overlay ─────────────────── */
#overlay {
  position: fixed; inset: 0; display: none; align-items: center;
  justify-content: center; background: rgba(0,0,0,.75); z-index: 100;
}
#overlay.on { display: flex; }
.obox {
  background: linear-gradient(135deg,#1a1a2e,#0d3b66);
  border: 2px solid #FFD700; border-radius: 20px; padding: 48px 64px;
  text-align: center; color: white; box-shadow: 0 0 40px rgba(255,215,0,.3);
  animation: oIn .3s ease;
}
@keyframes oIn { from{transform:scale(.8);opacity:0} to{transform:scale(1);opacity:1} }
.otitle { font-size: 52px; font-weight: 900; color: #FFD700; margin-bottom: 12px; }
.osub { font-size: 16px; color: #aaa; margin-bottom: 20px; }
.oscr { font-size: 40px; font-weight: bold; margin-bottom: 28px; }
.oscr .ty { color: #FFD700; } .oscr .tb { color: #87CEEB; }
.obtn {
  background: #FFD700; color: #000; border: none; padding: 14px 40px;
  font-size: 18px; font-weight: bold; border-radius: 10px; cursor: pointer;
  transition: transform .1s;
}
.obtn:hover { transform: scale(1.05); }

#gflash {
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background: rgba(255,215,0,0); transition: background .15s;
}
#gflash.on { background: rgba(255,215,0,.35); }

#cam-btns {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex; flex-direction: column; gap: 4px;
}
#cam-btns button {
  background: rgba(20,20,30,.85); color: #fff; border: 1px solid #555;
  border-radius: 10px; padding: 9px 14px; font-size: 13px; font-weight: bold;
  cursor: pointer; transition: transform .1s, background .15s;
  white-space: nowrap; min-height: 44px;
}
#cam-btns button:hover { background: rgba(40,40,60,.95); transform: scale(1.04); }
#cam-btns button.cam-active { border-color: #FFD700; background: rgba(255,215,0,.15); }

#zoom-btns {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(158px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex; flex-direction: column; gap: 4px;
}
#zoom-btns button {
  width: 44px; height: 44px;
  background: rgba(20,20,30,.85); color: #fff; border: 1px solid #555;
  border-radius: 8px; font-size: 20px; font-weight: bold; line-height: 1;
  cursor: pointer; transition: transform .1s, background .15s;
}
#zoom-btns button:hover { background: rgba(40,40,60,.95); transform: scale(1.08); }

@media (max-width: 380px) {
  #cam-btns button { padding: 8px 10px; font-size: 11px; }
  #zoom-btns { bottom: calc(140px + env(safe-area-inset-bottom)); }
}

/* ── Multiplayer UI ─────────────────────────────────── */
.menu-overlay-active {
  position: fixed; inset: 0; display: flex; align-items: center;
  justify-content: center; z-index: 100; overflow-y: auto; padding: 20px;
  background:
    radial-gradient(ellipse at 25% 50%, rgba(0,50,10,.55) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 50%, rgba(0,20,50,.55) 0%, transparent 55%),
    #07090f;
}
.menu-overlay-active::before {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 72px 72px;
}
.menu-overlay-active.hidden { display: none; }

#mode-select-overlay,
#lobby-overlay,
#create-room-overlay,
#waiting-room-overlay,
#join-room-overlay {
  position: fixed; inset: 0; display: flex; align-items: center;
  justify-content: center; z-index: 100; overflow-y: auto; padding: 20px;
  background:
    radial-gradient(ellipse at 25% 50%, rgba(0,50,10,.55) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 50%, rgba(0,20,50,.55) 0%, transparent 55%),
    #07090f;
}
#mode-select-overlay::before,
#lobby-overlay::before,
#create-room-overlay::before,
#waiting-room-overlay::before,
#join-room-overlay::before {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 72px 72px;
}

#mode-select-overlay.hidden,
#lobby-overlay.hidden,
#create-room-overlay.hidden,
#waiting-room-overlay.hidden,
#join-room-overlay.hidden {
  display: none;
}

.hidden { display: none !important; }

/* ── Responsive: narrow screens (phones) ─────────────── */
@media (max-width: 640px) {
  .menu-box { padding: 20px 16px 18px; border-radius: 14px; }
  .menu-title { font-size: 16px; letter-spacing: 3px; }

  .menu-vs-section { flex-direction: column; min-height: 0; }
  .menu-vs-divider {
    flex-direction: row; width: auto; padding: 6px 0;
    border-left: none; border-right: none;
    border-top: 1px solid rgba(255,255,255,.05);
    border-bottom: 1px solid rgba(255,255,255,.05);
  }
  .vs-line { width: auto; height: 1px; flex: 1; background: linear-gradient(to right, transparent, rgba(255,215,0,.35), transparent); }
  .menu-team-side { padding: 14px 8px; }
  .team-badge-xl { width: 60px; height: 60px; margin-bottom: 8px; }
  .team-name-xl { font-size: 15px; }

  .setting-group { flex-wrap: wrap; }
  .setting-lbl { min-width: 100%; }
  .setting-tabs { flex-wrap: wrap; }
  .stab { min-height: 44px; flex-basis: 30%; }

  .team-nav-btn, .obtn, .menu-start-btn { min-height: 44px; }
}

/* Room-code input: keep it scrolled into view above the virtual keyboard */
#room-code-input { font-size: 16px; }
