:root {
  color-scheme: dark light;
  font-family: 'Nunito', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --red: #d84f4f;
  --blue: #1f62d3;
  --grass-light: #4caf50;
  --grass-dark: #2e7d32;
  --shadow: rgba(0, 0, 0, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #1b2735, #090a0f 80%);
  color: #f8f9fa;
  overflow: hidden;
}

.app {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}


.scoreboard-container {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
}

.scoreboard-mini {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: clamp(1.1rem, 3vw, 1.8rem);
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.8), 0 2px 4px rgba(0, 0, 0, 0.6);
  padding: 0.75rem 1.5rem;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.scoreboard-mini .team {
  font-size: 0.75em;
  opacity: 0.9;
  letter-spacing: 0.05em;
}

.scoreboard-mini .team-red {
  color: var(--red);
}

.scoreboard-mini .team-blue {
  color: var(--blue);
}

.scoreboard-mini .score {
  font-size: 1.2em;
  min-width: 1.2em;
  text-align: center;
  color: #fff;
}

.scoreboard-mini .separator {
  opacity: 0.6;
  font-weight: 600;
}

.team-logo {
  width: 35px;
  height: 35px;
  object-fit: contain;
  background: white;
  padding: 4px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.controls-container {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 5;
}

.controls-container button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.1rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  transition: transform 120ms ease, box-shadow 120ms ease, background 150ms ease;
}

.controls-container button:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
  background: rgba(0, 0, 0, 0.65);
}

.controls-container button:active:not(:disabled) {
  transform: translateY(0) scale(0.95);
}

.controls-container button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.controls-container button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.controls-container button#formation-btn {
  background: linear-gradient(135deg, rgba(195, 240, 255, 0.9), rgba(116, 213, 255, 0.9));
  color: #05324b;
  border-color: rgba(116, 213, 255, 0.4);
}

.controls-container button#formation-btn:hover {
  background: linear-gradient(135deg, rgba(195, 240, 255, 1), rgba(116, 213, 255, 1));
}

.controls-container button#ambient-toggle[aria-pressed="true"] {
  background: rgba(76, 175, 80, 0.7);
  border-color: rgba(76, 175, 80, 0.5);
}

.controls-container button#ambient-toggle[aria-pressed="false"] {
  background: rgba(158, 158, 158, 0.5);
  border-color: rgba(158, 158, 158, 0.3);
}

.scoreboard {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  font-weight: 700;
}

.scoreboard .team:first-child {
  color: var(--red);
}

.scoreboard .team:last-child {
  color: var(--blue);
}

.turn {
  margin-top: 0.5rem;
  text-align: center;
  font-size: 1rem;
  letter-spacing: 0.05em;
  opacity: 0.9;
}

.controls {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}


button {
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.6rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: linear-gradient(135deg, #ffb347, #ffcc33);
  color: #212529;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}

button:active {
  transform: translateY(1px) scale(0.99);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.instructions {
  margin-top: 0.75rem;
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.8);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.field-wrapper {
  position: relative;
  width: 1024px;
  height: 576px;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  width: 1024px !important;
  height: 576px !important;
  border-radius: 28px;
  /* Crítico para macOS: evitar scaling automático en Retina */
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  background: repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.07) 0,
      rgba(255, 255, 255, 0.07) 2px,
      transparent 2px,
      transparent 60px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 2px,
      transparent 2px,
      transparent 60px
    ),
    linear-gradient(120deg, var(--grass-light), var(--grass-dark));
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.45);
  border: 6px solid rgba(255, 255, 255, 0.2);
}

.goal-banner,
.match-banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  color: #fff;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  text-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
}

.goal-banner[hidden],
.match-banner[hidden] {
  display: none !important;
}

.goal-banner {
  font-size: clamp(3rem, 8vw, 5rem);
  opacity: 0;
  transition: opacity 0.25s ease;
  background: radial-gradient(circle, rgba(0, 0, 0, 0.7), transparent 70%);
  font-weight: 900;
}

.goal-banner.visible {
  opacity: 1;
  animation: goal-super-pop 1.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.match-banner {
  background: radial-gradient(circle, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.95));
  border-radius: 28px;
  padding: 2rem;
  gap: 1rem;
  pointer-events: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}

.match-banner p {
  margin: 0;
  font-size: clamp(1.2rem, 4vw, 2rem);
}

.match-banner button {
  pointer-events: auto;
}

.formation-modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}
.formation-modal[hidden] {
  display: none;
}

.formation-panel {
  background: rgba(6, 8, 20, 0.95);
  border-radius: 24px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(360px, 100% - 2rem);
  text-align: center;
}

.formation-options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.formation-card {
  padding: 0.75rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}

.formation-card:hover {
  background: rgba(255, 255, 255, 0.2);
}

@keyframes goal-super-pop {
  0% {
    transform: scale(0.3) rotate(-10deg);
    opacity: 0;
  }
  30% {
    transform: scale(1.3) rotate(5deg);
    opacity: 1;
  }
  50% {
    transform: scale(1.1) rotate(-3deg);
    opacity: 1;
  }
  70% {
    transform: scale(1.2) rotate(2deg);
    opacity: 1;
  }
  85% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: scale(0.9);
    opacity: 0;
  }
}

@keyframes trophy-bounce {
  0% {
    transform: translateY(0) scale(1) rotate(-5deg);
  }
  100% {
    transform: translateY(-15px) scale(1.1) rotate(5deg);
  }
}

/* Chat remoto */
.remote-chat {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 320px;
  background: rgba(14, 16, 30, 0.95);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

.remote-chat[hidden] {
  display: none;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-weight: 600;
  font-size: 0.9rem;
}

.chat-toggle-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.chat-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.chat-messages {
  flex: 1;
  max-height: 250px;
  min-height: 150px;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chat-message {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
  word-wrap: break-word;
  max-width: 85%;
  animation: message-appear 0.2s ease;
}

@keyframes message-appear {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message.own {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  align-self: flex-end;
  margin-left: auto;
}

.chat-message.other {
  background: rgba(255, 255, 255, 0.1);
  align-self: flex-start;
}

.chat-message-author {
  font-weight: 600;
  font-size: 0.75rem;
  opacity: 0.8;
  margin-bottom: 0.25rem;
  display: block;
}

.chat-input-container {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  color: white;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.chat-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.chat-input:focus {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.15);
}

.chat-send-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 1.2rem;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.6);
}

.chat-send-btn:active {
  transform: scale(0.95);
}

.remote-chat.minimized .chat-messages,
.remote-chat.minimized .chat-input-container {
  display: none;
}

@media (max-width: 640px) {
  .hud {
    padding: 1rem;
  }

  .controls {
    flex-direction: column;
  }

  button {
    width: 100%;
  }
  
  .remote-chat {
    width: calc(100% - 40px);
    max-width: 320px;
  }
}

.mode-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 14, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  transition: opacity 0.3s ease;
  z-index: 10;
}

.mode-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.mode-panel {
  width: min(480px, 100%);
  background: rgba(14, 16, 30, 0.9);
  border-radius: 24px;
  padding: 2rem 1.5rem;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.panel-view[hidden] {
  display: none;
}

.mode-panel h1,
.mode-panel h2 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.7rem, 5vw, 2.3rem);
}

.panel-view--remote {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.mode-info {
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.8);
  min-height: 2.6rem;
}

.mode-options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.mode-card {
  width: 100%;
  border: none;
  border-radius: 18px;
  padding: 1rem 1.2rem;
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

.mode-card strong {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}

.mode-card span {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.75);
}

.mode-card:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.15);
}

.mode-card--ghost {
  border: 1px dashed rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.04);
}

/* Team Selection - Horizontal Layout */
.selected-teams-preview {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  justify-content: center;
}

.selected-team-box {
  flex: 1;
  max-width: 180px;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  text-align: center;
}

.selected-team-box small {
  display: block;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 0.5rem;
}

.selected-team-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.selected-team-logo {
  width: 50px;
  height: 50px;
  object-fit: contain;
  background: white;
  padding: 5px;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.selected-team-name {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
}

.team-selector-toggle {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  justify-content: center;
}

.team-toggle-btn {
  padding: 0.5rem 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.team-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
}

.team-toggle-btn.active {
  background: rgba(46, 204, 113, 0.2);
  border-color: #2ecc71;
  color: #2ecc71;
  font-weight: 600;
}

.teams-grid-horizontal {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  margin-bottom: 1rem;
}

.team-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.4rem;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.team-card:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.team-card.selected {
  background: rgba(46, 204, 113, 0.2);
  border-color: #2ecc71;
  box-shadow: 0 0 8px rgba(46, 204, 113, 0.4);
}

.team-card-logo {
  width: 45px;
  height: 45px;
  object-fit: contain;
  margin-bottom: 0.25rem;
  background: white;
  padding: 4px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.team-card-name {
  font-size: 0.65rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

#confirm-teams-btn {
  margin-top: 0.5rem;
}

.mode-note {
  display: block;
  margin-top: 1.2rem;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
}

.ghost-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  align-self: flex-start;
}

.ghost-btn:hover {
  border-color: rgba(255, 255, 255, 0.5);
}

.remote-state {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.remote-state[hidden] {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.field input {
  flex: 1;
  padding: 0.5rem 0.8rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
  font-size: 1rem;
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.player-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.player-card .meta {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.player-card small {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
}

.player-card button {
  padding: 0.4rem 0.9rem;
  border-radius: 12px;
  font-size: 0.85rem;
}

.player-card button[disabled] {
  opacity: 0.4;
}

.challenge-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#remote-incoming,
#remote-outgoing {
  padding: 0.75rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
}

#remote-incoming p,
#remote-outgoing p {
  margin: 0 0 0.6rem;
  font-size: 0.9rem;
}

.incoming-actions {
  display: flex;
  gap: 0.5rem;
}


.match-banner:not([hidden]) {
  animation: match-enter 0.5s ease forwards;
}

@keyframes match-enter {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
