* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #05060a; }
body {
  font-family: 'Comic Neue', 'Segoe UI', sans-serif;
  color: #fff; user-select: none; -webkit-user-select: none; touch-action: none;
}
/* Centered play column (a bit wider than a strict phone ratio). */
#stage {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  height: 100%; width: var(--stageW, 100%); overflow: hidden;
  background: #05060a; box-shadow: 0 0 0 2px rgba(255,255,255,0.06), 0 0 60px rgba(0,0,0,0.7);
}
#bg   { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 1; }
#fx   { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 2; pointer-events: none; }

#confetti { position: absolute; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti-piece { position: absolute; top: -6vh; border-radius: 2px; animation: confettiFall linear 1 forwards; will-change: transform, opacity; }
@keyframes confettiFall { 0% { transform: translate(0,0) rotate(0deg); opacity: 1; } 100% { transform: translate(var(--drift,0), 112vh) rotate(var(--rot,360deg)); opacity: 0.85; } }

/* solid outline + soft drop (no hollow stroke) */
.outline { text-shadow: -2px -2px 0 #0a0a12, 2px -2px 0 #0a0a12, -2px 2px 0 #0a0a12, 2px 2px 0 #0a0a12, 3px 3px 0 #0a0a12, 0 5px 10px rgba(0,0,0,0.45); }

/* ---------- Menu button (movable) ---------- */
#menuBtn {
  z-index: 30; font-family: inherit; font-weight: 900; font-size: 17px; letter-spacing: 1px;
  color: #fff; background: linear-gradient(180deg, #8a6bff, #6a45e0);
  border: 2px solid rgba(255,255,255,0.9); border-radius: 12px; padding: 9px 16px; cursor: pointer;
  box-shadow: 0 5px 0 #4a2ba8, 0 8px 16px rgba(0,0,0,0.5);
}
#menuBtn:hover { filter: brightness(1.08); }
#menuBtn:active { transform: translate(-50%, -50%) scale(0.97); }

/* ---------- Movable HUD clusters (positioned inside #stage) ---------- */
.movable { position: absolute; z-index: 20; transform-origin: center center; }
body.editing .movable { outline: 2px dashed rgba(255,255,255,0.6); outline-offset: 6px; cursor: grab; border-radius: 14px; pointer-events: auto; }
body.editing .movable * { pointer-events: none; } /* children don't swallow the drag */
body.editing .movable.grabbing { cursor: grabbing; outline: 2px solid #fff; }

/* ---------- Team header clusters ---------- */
.side-hud { display: flex; flex-direction: column; align-items: center; gap: 9px; pointer-events: none; width: max-content; }
.team-title { font-family: 'Luckiest Guy', cursive; font-weight: 400; font-size: 46px; line-height: 1; letter-spacing: 2px; text-transform: uppercase; }
.team-mid { display: flex; align-items: center; gap: 16px; }
.score-block { display: flex; align-items: baseline; gap: 6px; }
.team-score { font-family: 'Luckiest Guy', cursive; font-weight: 400; font-size: 60px; line-height: 1; color: #fff; }
.score-goal { font-weight: 900; font-size: 18px; color: rgba(255,255,255,0.7); }
.tw-num, .st-num { font-family: 'Luckiest Guy', cursive; font-weight: 400; }
.team-wins {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 5px 14px 6px; border-radius: 12px; background: rgba(6,8,16,0.6);
}
.tw-label { font-weight: 900; font-size: 11px; letter-spacing: 1.5px; }
.tw-num { font-weight: 900; font-size: 26px; color: #fff; line-height: 1; }
.goal-bar { width: 190px; height: 12px; border-radius: 999px; background: rgba(0,0,0,0.5); overflow: hidden; border: 1px solid rgba(255,255,255,0.16); box-shadow: inset 0 1px 2px rgba(0,0,0,0.5); }
.goal-fill { height: 100%; width: 0%; border-radius: 999px; transition: width 0.25s ease; }

.red .team-title { color: #ff5f78; -webkit-text-stroke: 2.5px #2a0308; text-shadow: 0 3px 0 #2a0308, 0 0 12px rgba(255,45,85,0.55); }
.red .team-score { color: #fff; -webkit-text-stroke: 2.5px #2a0308; text-shadow: 0 3px 0 #2a0308, 0 0 11px rgba(255,45,85,0.45); }
.red .tw-label { color: #ff8497; }
.red .goal-fill { background: linear-gradient(90deg, #ff8a3c, #ff2d55); box-shadow: 0 0 8px rgba(255,45,85,0.6); }

.blue .team-title { color: #63c9ff; -webkit-text-stroke: 2.5px #021226; text-shadow: 0 3px 0 #021226, 0 0 12px rgba(30,144,255,0.55); }
.blue .team-score { color: #fff; -webkit-text-stroke: 2.5px #021226; text-shadow: 0 3px 0 #021226, 0 0 11px rgba(30,144,255,0.45); }
.blue .tw-label { color: #86d3ff; }
.blue .goal-fill { background: linear-gradient(90deg, #4dffea, #38b6ff); box-shadow: 0 0 8px rgba(30,144,255,0.6); }

/* ---------- WINS boxes (own movable UI) ---------- */
.wins-box { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 22px 11px; border-radius: 16px; background: rgba(6,8,16,0.66); pointer-events: none; width: max-content; }
.wins-box .tw-label { font-weight: 900; font-size: 13px; letter-spacing: 1.5px; text-transform: uppercase; }
.wins-box .tw-num { font-weight: 900; font-size: 44px; color: #fff; line-height: 1; text-shadow: 0 2px 0 rgba(0,0,0,0.35); }
.red.wins-box { border: 2px solid #ff3b57; box-shadow: 0 0 12px rgba(255,45,85,0.7), 0 0 30px rgba(255,45,85,0.45), inset 0 0 14px rgba(255,45,85,0.2); }
.blue.wins-box { border: 2px solid #38b6ff; box-shadow: 0 0 12px rgba(30,144,255,0.7), 0 0 30px rgba(30,144,255,0.45), inset 0 0 14px rgba(30,144,255,0.2); }
.red.wins-box .tw-label { color: #ff8497; text-shadow: 0 0 8px rgba(255,45,85,0.8); }
.blue.wins-box .tw-label { color: #86d3ff; text-shadow: 0 0 8px rgba(30,144,255,0.8); }
.wins-box .tw-num { -webkit-text-stroke: 2px #0a0a12; }
.red.wins-box .tw-num { text-shadow: 0 2px 0 rgba(0,0,0,0.4), 0 0 8px rgba(255,45,85,0.5); }
.blue.wins-box .tw-num { text-shadow: 0 2px 0 rgba(0,0,0,0.4), 0 0 8px rgba(30,144,255,0.5); }
.wins-box.bump-win .tw-num { animation: winPop 0.6s cubic-bezier(.2,.9,.25,1); }
@keyframes winPop { 0%{transform:scale(1);} 40%{transform:scale(1.7);} 100%{transform:scale(1);} }

/* ---------- Per-side countdown timer ---------- */
.side-timer { position: relative; display: flex; flex-direction: column; align-items: center; padding: 14px 30px 16px; border-radius: 20px; background: linear-gradient(165deg, #16161f 0%, #0c0c13 60%, #08080d 100%); pointer-events: none; width: max-content; overflow: visible; }
.side-timer::before, .side-timer::after { content: ""; position: absolute; inset: -8px; border-radius: 26px; border: 3px solid var(--ring, #fff); pointer-events: none; z-index: -1; animation: ringPulse 1.9s cubic-bezier(.2,.6,.3,1) infinite; }
.side-timer::after { animation-delay: 0.95s; }
@keyframes ringPulse { 0% { transform: scale(0.9); opacity: 0.85; } 100% { transform: scale(1.55); opacity: 0; } }
.side-timer.hidden { display: none; }
.st-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; transform-origin: center center; }
.side-timer.reset-mode .st-inner { animation: timerBounce 0.7s ease-in-out infinite; } /* the "in and out" is on the timer, not the tower */
@keyframes timerBounce { 0%,100% { transform: scale(0.92); } 50% { transform: scale(1.08); } }
.st-label { font-weight: 900; font-size: 14px; letter-spacing: 2px; text-transform: uppercase; }
.st-num { font-family: 'Luckiest Guy', cursive; font-size: 54px; line-height: 1; color: #fff; -webkit-text-stroke: 2.5px #0a0a12; text-shadow: 0 3px 0 rgba(0,0,0,0.4); display: inline-block; }
.st-bar { width: 150px; height: 8px; border-radius: 999px; background: rgba(0,0,0,0.5); overflow: hidden; }
.st-fill { height: 100%; border-radius: 999px; width: 100%; transition: width 1s linear; }
.red.side-timer { --ring: #ff2d55; border: 2px solid rgba(255,60,90,0.95); box-shadow: 0 0 30px rgba(255,45,85,0.6), inset 0 1px 0 rgba(255,255,255,0.06); }
.blue.side-timer { --ring: #38b6ff; border: 2px solid rgba(56,182,255,0.95); box-shadow: 0 0 30px rgba(30,144,255,0.6), inset 0 1px 0 rgba(255,255,255,0.06); }
.red.side-timer .st-label { color: #ff8497; }
.blue.side-timer .st-label { color: #86d3ff; }
.red.side-timer .st-fill { background: linear-gradient(90deg, #ff8a3c, #ff2d55); }
.blue.side-timer .st-fill { background: linear-gradient(90deg, #4dffea, #38b6ff); }
.st-sub { font-weight: 900; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: #ffd14d; text-shadow: 0 0 8px rgba(255,209,77,0.7); margin-top: 3px; animation: subBlink 0.9s ease-in-out infinite; }
.st-sub:empty { display: none; }
@keyframes subBlink { 0%,100% { opacity: 0.55; } 50% { opacity: 1; } }
.side-timer.urgent .st-num { color: #ff5a52; animation: numPulse 0.5s ease infinite alternate; }
@keyframes numPulse { from { transform: scale(1); } to { transform: scale(1.16); } }

/* ---------- Side control buttons (STEAL / RESET) ---------- */
.side-ctrl { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.sc-btn {
  font-family: inherit; font-weight: 900; font-size: 17px; line-height: 1.05; letter-spacing: 0.5px;
  text-transform: uppercase; text-align: center; color: #fff; cursor: pointer;
  padding: 11px 16px; border-radius: 14px; min-width: 108px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.55);
}
.red .sc-btn { background: linear-gradient(180deg, #ff5a72, #c41d40); border: 2px solid #ff8497; box-shadow: 0 5px 0 #7c0f26, 0 8px 16px rgba(0,0,0,0.45); }
.blue .sc-btn { background: linear-gradient(180deg, #45c6ff, #1470c4); border: 2px solid #86d3ff; box-shadow: 0 5px 0 #0a3f78, 0 8px 16px rgba(0,0,0,0.45); }
.sc-btn:hover { filter: brightness(1.1); }
.sc-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.5); }
.sc-btn.reset { background: linear-gradient(180deg, #3a3f52, #23283a); border-color: rgba(255,255,255,0.35); box-shadow: 0 5px 0 #12151f, 0 8px 16px rgba(0,0,0,0.45); }

/* ---------- Flash ---------- */
#flash {
  position: absolute; top: 24%; left: 50%; transform: translate(-50%,-50%) scale(0.6);
  z-index: 45; font-family: 'Luckiest Guy', cursive; font-size: 44px; letter-spacing: 1px; text-transform: uppercase;
  pointer-events: none; opacity: 0; white-space: nowrap; -webkit-text-stroke: 2.5px #0a0a12;
  text-shadow: 0 3px 0 #0a0a12, 0 0 12px currentColor;
}
#flash.show { animation: flashPop 1.1s ease forwards; }
@keyframes flashPop {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(0.6); }
  16% { opacity: 1; transform: translate(-50%,-50%) scale(1.12); }
  28% { transform: translate(-50%,-50%) scale(1); }
  76% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%,-50%) scale(1); }
}

/* ---------- Control panel ---------- */
#panel {
  position: fixed; top: 0; left: 0; height: 100%; width: 400px; max-width: 92vw;
  background: linear-gradient(180deg, #12121c, #0a0a12); border-right: 1px solid rgba(255,255,255,0.12);
  z-index: 60; transform: translateX(-102%); transition: transform 0.28s cubic-bezier(.2,.9,.25,1);
  display: flex; flex-direction: column;
}
#panel.open { transform: translateX(0); box-shadow: 0 0 60px rgba(0,0,0,0.6); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 12px; }
.panel-head h2 { font-size: 22px; font-weight: 900; letter-spacing: 2px; }
#panelClose { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; opacity: 0.7; }
#panelClose:hover { opacity: 1; }
.panel-scroll { overflow-y: auto; padding: 0 16px 40px; flex: 1; }
.panel-card { background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.panel-card h3 { font-size: 15px; font-weight: 900; letter-spacing: 1px; margin-bottom: 12px; }
.red-card { border-color: rgba(255,60,90,0.4); } .red-card h3 { color: #ff5a72; }
.blue-card { border-color: rgba(56,182,255,0.4); } .blue-card h3 { color: #4dc3ff; }
.pl-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; font-size: 13px; margin-bottom: 12px; }
.pl-sw { width: 40px; height: 22px; border-radius: 999px; background: rgba(255,255,255,0.18); position: relative; transition: background 0.2s; flex-shrink: 0; }
.pl-sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.pl-toggle input { display: none; }
.pl-toggle input:checked + .pl-sw { background: #7a5aff; }
.pl-toggle input:checked + .pl-sw::after { transform: translateX(18px); }
.pl-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.pl-num { width: 90px; background: rgba(0,0,0,0.35); border: 1px solid rgba(255,255,255,0.15); color: #fff; border-radius: 8px; padding: 6px 8px; font-family: inherit; font-weight: 700; text-align: right; }
.pl-num.name-input { width: 140px; text-align: left; }
.pl-row input[type=range] { flex: 1; margin-left: 12px; accent-color: #7a5aff; }
.ctrl-row { display: grid; grid-template-columns: 62px 1fr 86px; align-items: center; gap: 8px; margin-bottom: 7px; }
.ctrl-row .amt { width: 100%; background: rgba(0,0,0,0.35); border: 1px solid rgba(255,255,255,0.15); color: #fff; border-radius: 8px; padding: 5px 6px; font-family: inherit; font-weight: 700; text-align: right; font-size: 13px; }
.ctrl-row .lab { font-size: 13px; font-weight: 700; opacity: 0.92; }
.ctrl-row .lab.win { color: #ffd14d; }
.kbd-wrap { display: flex; align-items: center; gap: 4px; }
.kbd-wrap .kbd { flex: 1; text-align: center; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.2); border-radius: 7px; padding: 5px 4px; font-size: 12px; font-weight: 900; cursor: pointer; }
.kbd-wrap .kbd.listening { background: #7a5aff; color: #fff; }
.kbd-unbind { width: 22px; height: 26px; flex-shrink: 0; border: 1px solid rgba(255,90,90,0.5); background: rgba(255,60,60,0.14); color: #ff9a9a; border-radius: 6px; font-size: 15px; font-weight: 900; line-height: 1; cursor: pointer; padding: 0; }
.kbd-unbind:hover { background: rgba(255,60,60,0.32); color: #fff; }
.ctrl-divider { font-size: 11px; letter-spacing: 1px; opacity: 0.5; margin: 10px 0 6px; text-transform: uppercase; }
.pl-textbtn { display: block; width: 100%; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.14); color: #fff; border-radius: 10px; padding: 10px; font-family: inherit; font-weight: 700; cursor: pointer; margin-top: 6px; }
.pl-textbtn:hover { background: rgba(255,255,255,0.12); }
.pl-hint { text-align: center; opacity: 0.5; font-size: 12px; margin-top: 14px; }
