:root {
  --bg: #10161b;
  --panel: #1a232b;
  --panel2: #222f39;
  --text: #e8eef2;
  --muted: #8fa3ad;
  --pitch1: #2f8f46;
  --pitch2: #27803c;
  --goal: #1c5c2c;
  --accent: #ffd54a;
  --blue: #4fc3f7;
  --red: #ef5350;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid #000;
}
h1 { font-size: 1.25rem; margin: 0; }
button {
  background: var(--accent); color: #222; border: 0; border-radius: 8px;
  padding: 9px 16px; font-size: 0.95rem; font-weight: 700; cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; color: var(--text); border: 1px solid #3a4a55; font-weight: 500; }
button.big { width: 100%; padding: 14px; font-size: 1.05rem; margin: 6px 0; }
input {
  background: #0d1318; color: var(--text); border: 1px solid #3a4a55;
  border-radius: 8px; padding: 9px 12px; font-size: 1rem;
}
a { color: var(--blue); }

/* MENÚ */
#menu {
  flex: 1; display: flex; flex-direction: column; gap: 44px;
  align-items: center; justify-content: center; padding: 30px 16px;
  background:
    radial-gradient(ellipse 90% 55% at 50% -10%, rgba(47,143,70,.28), transparent 70%),
    var(--bg);
}
.hero { text-align: center; }
.hero-icons { font-size: 3.4rem; letter-spacing: 12px; }
.hero h2 {
  margin: 8px 0 10px; font-size: clamp(1.9rem, 5vw, 3rem); font-weight: 900;
  background: linear-gradient(90deg, #b9f6ca, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { color: var(--muted); font-size: 1.05rem; line-height: 1.55; margin: 0; }
.hero strong { color: var(--accent); }
.menu-cards {
  display: flex; gap: 24px; align-items: stretch; justify-content: center;
  flex-wrap: wrap; width: 100%;
}
.card {
  background: var(--panel); border: 1px solid #2c3d49; border-radius: 14px;
  padding: 26px; width: 340px; max-width: 92vw;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.card h2 { margin-top: 0; font-size: 1.15rem; }
.card .hint { margin-top: auto; padding-top: 12px; }
.joinrow { display: flex; gap: 8px; }
.joinrow input { flex: 1; text-transform: uppercase; letter-spacing: 2px; text-align: center; }
.hint { color: var(--muted); font-size: 0.85rem; }

/* PARTIDA */
#game {
  flex: 1; display: flex; gap: 20px; padding: 16px;
  align-items: flex-start; justify-content: center; flex-wrap: wrap;
}
#board-wrap { position: relative; }
#board {
  display: grid; grid-template-columns: repeat(8, 1fr);
  width: min(88vmin, 620px); aspect-ratio: 1;
  border: 4px solid #f5f5f5; border-radius: 6px; overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.sq {
  position: relative; display: flex; align-items: center; justify-content: center;
  cursor: default; user-select: none;
}
.sq.l { background: var(--pitch1); }
.sq.d { background: var(--pitch2); }
.sq.goal { box-shadow: inset 0 0 0 3px #f5f5f5cc; background: var(--goal); }
.sq.sel { outline: 3px solid var(--accent); outline-offset: -3px; }
.sq.hl { cursor: pointer; }
.sq.hl::after {
  content: ""; width: 34%; height: 34%; border-radius: 50%;
  position: absolute; opacity: .9;
}
.sq.hl-move::after, .sq.hl-pickup::after { background: #b9f6ca; }
.sq.hl-dribble::after { background: var(--accent); }
.sq.hl-capture::after { background: var(--red); width: 78%; height: 78%; opacity: .45; }
.sq.hl-pass::after { background: var(--blue); }
.sq.hl-clear::after { background: #e1bee7; }
.sq.hl-shot::after {
  background: transparent; border: 4px solid var(--accent);
  width: 70%; height: 70%; animation: pulse 1s infinite;
}
@keyframes pulse { 50% { transform: scale(1.12); } }

.piece {
  width: 78%; height: 78%; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: clamp(14px, 3.4vmin, 26px);
  cursor: pointer; position: relative; z-index: 2;
  box-shadow: 0 3px 6px rgba(0,0,0,.45);
}
.team-w { background: #f5f5f5; color: #1b1b1b; border: 2px solid #9e9e9e; }
.team-b { background: #212121; color: #f5f5f5; border: 2px solid #616161; }
.piece.carrier { box-shadow: 0 0 0 4px var(--accent), 0 3px 6px rgba(0,0,0,.45); }
.ball-badge {
  position: absolute; right: -10%; bottom: -10%; font-size: clamp(12px, 2.6vmin, 20px);
}
.ball-loose { font-size: clamp(16px, 4vmin, 30px); z-index: 2; position: relative; }

/* Panel lateral */
#side {
  width: 300px; max-width: 92vw; background: var(--panel);
  border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
#scoreboard { text-align: center; font-size: 2.6rem; font-weight: 800; }
#scoreboard .dash { color: var(--muted); margin: 0 10px; }
#turninfo { text-align: center; font-weight: 700; }
#roominfo { font-size: .9rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
#roominfo strong { color: var(--accent); letter-spacing: 2px; }
#peer-status.off { color: var(--red); }
#feed {
  font-size: .85rem; color: var(--muted); max-height: 140px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
#feed div { background: var(--panel2); border-radius: 6px; padding: 5px 8px; }
#chatbox { display: flex; flex-direction: column; gap: 8px; }
#chatlog {
  max-height: 120px; overflow-y: auto; font-size: .85rem;
  display: flex; flex-direction: column; gap: 4px;
}
#chatlog div { background: var(--panel2); border-radius: 6px; padding: 4px 8px; }
#chatlog .who { font-weight: 700; margin-right: 6px; }

/* Toast y fin de partida */
#toast {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: clamp(2rem, 9vmin, 4.5rem); font-weight: 900; pointer-events: none;
  text-shadow: 0 4px 18px rgba(0,0,0,.8); z-index: 5; animation: pop .4s;
}
@keyframes pop { from { transform: scale(.5); opacity: 0; } }
#gameover {
  position: absolute; inset: 0; background: rgba(10,15,18,.88);
  display: flex; flex-direction: column; gap: 18px; align-items: center; justify-content: center;
  z-index: 6; border-radius: 6px;
}
#gameover-text { font-size: clamp(1.4rem, 5vmin, 2.4rem); font-weight: 900; text-align: center; padding: 0 12px; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px;
}
.modal-card {
  background: var(--panel); border-radius: 14px; padding: 26px;
  max-width: 640px; max-height: 86vh; overflow-y: auto; position: relative;
}
.modal-card .close { position: absolute; top: 10px; right: 10px; }
.modal-card li { margin: 4px 0; }

@media (max-width: 720px) {
  #game { flex-direction: column; align-items: center; }
  #board { width: 96vw; }
  #side { width: 96vw; }
}
