/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; font-family: 'Segoe UI', system-ui, sans-serif; background: #0a0a1a; }

/* ===== SCREENS ===== */
.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* ===== SELEZIONE ===== */
.select-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 0%, #1a3a1a 0%, #0a0a1a 70%);
  z-index: 0;
}
.game-title {
  position: relative; z-index: 1;
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 900; letter-spacing: 4px;
  color: #fff; text-shadow: 0 0 30px #4caf50, 0 4px 20px #000;
  margin: 20px 0 10px;
}
.select-container {
  position: relative; z-index: 1;
  display: flex; gap: 20px; align-items: flex-start;
  width: 100%; max-width: 1100px; padding: 0 10px;
  flex: 1; overflow-y: auto;
}
.team-panel {
  flex: 1; background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.team-header {
  font-size: 1.1rem; font-weight: 800; letter-spacing: 2px;
  text-transform: uppercase; padding: 8px 12px;
  border-radius: 8px; text-align: center;
}
.team-header.red  { background: rgba(220,50,50,0.3); color: #ff6b6b; border: 1px solid #ff6b6b44; }
.team-header.blue { background: rgba(50,100,220,0.3); color: #6b9fff; border: 1px solid #6b9fff44; }

.formation-row { display: flex; align-items: center; gap: 10px; color: #aaa; font-size: 0.85rem; }
.formation-row select {
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
  color: #fff; border-radius: 6px; padding: 4px 8px; cursor: pointer;
}

.player-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.player-card {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; cursor: pointer; padding: 6px; border-radius: 10px;
  border: 2px solid transparent;
  transition: all 0.2s; background: rgba(255,255,255,0.04);
}
.player-card:hover { background: rgba(255,255,255,0.1); transform: translateY(-2px); }
.player-card.selected-red   { border-color: #ff6b6b; background: rgba(255,107,107,0.15); }
.player-card.selected-blue  { border-color: #6b9fff; background: rgba(107,159,255,0.15); }
.player-card.disabled { opacity: 0.35; pointer-events: none; }
.player-card img {
  width: 56px; height: 56px; border-radius: 50%; object-fit: cover;
  border: 2px solid rgba(255,255,255,0.2);
}
.player-card .pname { font-size: 0.65rem; color: #ccc; text-align: center; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.selected-players {
  min-height: 36px; border: 1px dashed rgba(255,255,255,0.2);
  border-radius: 8px; padding: 6px 8px;
  color: #777; font-size: 0.8rem; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.sel-chip {
  background: rgba(255,255,255,0.1); border-radius: 20px;
  padding: 2px 10px; font-size: 0.75rem; color: #fff;
}

.vs-middle {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 20px; padding-top: 60px;
}
.vs-text {
  font-size: 2.5rem; font-weight: 900; color: #fff;
  text-shadow: 0 0 20px #fff5;
}
.btn-start {
  padding: 14px 32px; font-size: 1.1rem; font-weight: 800;
  background: linear-gradient(135deg, #4caf50, #2e7d32);
  color: #fff; border: none; border-radius: 12px; cursor: pointer;
  letter-spacing: 2px; text-transform: uppercase;
  box-shadow: 0 4px 20px #4caf5066;
  transition: all 0.2s;
}
.btn-start:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 30px #4caf5099; }
.btn-start:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== HUD ===== */
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  background: linear-gradient(180deg, rgba(0,0,0,0.85) 0%, transparent 100%);
}
.hud-score { display: flex; align-items: center; gap: 10px; font-size: 2rem; font-weight: 900; }
.score-red  { color: #ff6b6b; text-shadow: 0 0 10px #ff6b6b88; }
.score-blue { color: #6b9fff; text-shadow: 0 0 10px #6b9fff88; }
.hud-vs { color: #fff; }
.hud-timer {
  font-size: 1.6rem; font-weight: 800; color: #fff;
  background: rgba(0,0,0,0.5); padding: 4px 14px; border-radius: 8px;
  letter-spacing: 2px;
}
.hud-turn {
  font-size: 0.9rem; font-weight: 700; color: #fff;
  background: rgba(0,0,0,0.5); padding: 4px 12px; border-radius: 8px;
}
.btn-menu {
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
  color: #fff; padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: 0.85rem;
}

/* ===== CAMPO ===== */
#screen-game { justify-content: center; align-items: center; background: #0a1a0a; }
#field-wrapper {
  position: relative;
  /* dimensioni impostate da JS */
}
#field-canvas { display: block; }

/* GIOCATORI */
#players-layer { position: absolute; inset: 0; pointer-events: none; }
.player-token {
  position: absolute;
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer; pointer-events: all;
  transform: translate(-50%, -50%);
  transition: transform 0.15s;
  z-index: 10;
}
.player-token:hover { transform: translate(-50%, -50%) scale(1.1); }
.player-token.active-player { animation: pulse-player 0.6s ease-in-out infinite alternate; }
@keyframes pulse-player {
  from { filter: drop-shadow(0 0 4px currentColor); }
  to   { filter: drop-shadow(0 0 16px currentColor) brightness(1.3); }
}
.token-circle {
  width: 52px; height: 52px; border-radius: 50%;
  border: 3px solid currentColor;
  overflow: hidden; background: #111;
  box-shadow: 0 2px 8px #0008;
}
.token-circle img { width: 100%; height: 100%; object-fit: cover; }
.token-name {
  font-size: 0.6rem; font-weight: 700;
  background: rgba(0,0,0,0.75); color: #fff;
  padding: 1px 5px; border-radius: 4px; margin-top: 2px;
  max-width: 70px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.token-outline {
  position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid currentColor; opacity: 0.4; animation: rotate-outline 4s linear infinite;
}
@keyframes rotate-outline {
  to { transform: rotate(360deg); }
}

/* PALLA */
#ball {
  position: absolute; width: 36px; height: 36px;
  transform: translate(-50%,-50%);
  transition: left 0.05s, top 0.05s;
  z-index: 20; pointer-events: none;
}
#ball img { width: 100%; height: 100%; }

/* PORTE */
.goal-img {
  position: absolute; z-index: 5;
  pointer-events: none;
}
#goal-red  { left: 0; top: 50%; transform: translateY(-50%); height: 90px; }
#goal-blue { right: 0; top: 50%; transform: translateY(-50%); height: 90px; }

/* CERCHIO CENTRALE */
#center-circle {
  position: absolute; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  pointer-events: none; z-index: 1;
}

/* PANNELLO TIRO */
#shoot-panel {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.85); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 16px; padding: 12px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 200;
}
#shoot-panel.hidden { display: none; }
.shoot-info { color: #aaa; font-size: 0.8rem; }
#aim-canvas { cursor: crosshair; border-radius: 50%; border: 1px solid rgba(255,255,255,0.2); }
.power-label { color: #fff; font-size: 0.9rem; font-weight: 700; }

/* FRECCE POTENZA sul campo */
#power-meter {
  position: absolute; z-index: 30; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
#power-meter.hidden { display: none; }
#power-arrow { width: 48px; height: 48px; object-fit: contain; }
#power-bar-wrap {
  width: 60px; height: 8px; background: rgba(255,255,255,0.2);
  border-radius: 4px; overflow: hidden;
}
#power-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #4caf50, #ff5722); border-radius: 4px; transition: width 0.05s; }

/* OVERLAY GOAL */
#goal-overlay {
  position: fixed; inset: 0; z-index: 500;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6);
  animation: goal-appear 0.3s ease;
}
#goal-overlay.hidden { display: none; }
@keyframes goal-appear { from { opacity: 0; transform: scale(0.7); } to { opacity: 1; transform: scale(1); } }
.goal-text {
  font-size: clamp(3rem, 10vw, 6rem); font-weight: 900; color: #fff;
  text-shadow: 0 0 40px #4caf50, 0 0 80px #4caf5088;
  animation: goal-bounce 0.5s ease infinite alternate;
}
@keyframes goal-bounce { to { transform: scale(1.05); } }
.goal-team { font-size: 1.5rem; color: #fff; margin-top: 10px; }

/* OVERLAY FINE */
#end-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
}
#end-overlay.hidden { display: none; }
.end-box {
  background: linear-gradient(135deg, #111, #1a2a1a);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 20px;
  padding: 40px; text-align: center; display: flex; flex-direction: column; gap: 16px;
}
.end-title { font-size: 2rem; font-weight: 900; color: #fff; letter-spacing: 4px; }
.end-score { font-size: 3rem; font-weight: 900; }
.end-winner { font-size: 1.3rem; color: #4caf50; font-weight: 700; }
.btn-restart {
  padding: 12px 28px; background: linear-gradient(135deg, #4caf50, #2e7d32);
  color: #fff; border: none; border-radius: 10px; cursor: pointer;
  font-size: 1rem; font-weight: 700; margin-top: 8px;
}

/* UTILITY */
.hidden { display: none !important; }
