/* ============================================
   KAFABALL - Global Styles (v2)
   ============================================ */

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.8);
  --bg-glass: rgba(255, 255, 255, 0.05);
  --border-glass: rgba(255, 255, 255, 0.1);
  --text-primary: #f0f4f8;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --red-team: #e56e56;
  --red-team-bg: rgba(229, 110, 86, 0.15);
  --red-team-border: rgba(229, 110, 86, 0.3);
  --blue-team: #5689e5;
  --blue-team-bg: rgba(86, 137, 229, 0.15);
  --blue-team-border: rgba(86, 137, 229, 0.3);
  --spec-color: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.4);
  --success: #22c55e;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --warning: #f59e0b;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(229, 110, 86, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 60% 80%, rgba(86, 137, 229, 0.06) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ============ Screens ============ */
.screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============ Glass Card ============ */
.glass-card {
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius);
}

/* ============ Buttons ============ */
.btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 14px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #6366f1);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-glass);
  color: var(--text-secondary);
  border: 1px solid var(--border-glass);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #dc2626);
  color: white;
}

.btn-danger:hover {
  background: linear-gradient(135deg, var(--danger-hover), #ef4444);
}

.btn-large {
  padding: 14px 32px;
  font-size: 16px;
  border-radius: var(--radius);
}

.btn-small {
  padding: 6px 14px;
  font-size: 12px;
}

.btn-icon {
  font-size: 20px;
  font-weight: 300;
}

/* ============ Inputs ============ */
input[type="text"],
input[type="number"],
input[type="password"] {
  font-family: var(--font);
  font-size: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ============ Entry Screen ============ */
.entry-container {
  width: 100%;
  max-width: 440px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.logo-section {
  text-align: center;
  padding: 20px 0;
}

.logo-icon {
  font-size: 64px;
  animation: bounce 2s ease infinite;
}

@keyframes bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

.logo-text {
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 6px;
  background: linear-gradient(135deg, var(--red-team), var(--accent), var(--blue-team));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-top: 8px;
}

.logo-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 4px;
}

.name-input-section {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.name-input-section label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  font-weight: 600;
}

.actions-section {
  display: flex;
  justify-content: center;
}

/* ============ Room Browser Screen ============ */
#browser-screen.active {
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.browser-container {
  width: 100%;
  max-width: 1100px;
  padding: 30px;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  height: 100vh;
}

.browser-left {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.browser-right {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-secondary);
  font-weight: 600;
}

.room-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.no-rooms {
  text-align: center;
  color: var(--text-muted);
  padding: 30px;
  font-size: 14px;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  cursor: pointer;
  transition: all 0.2s ease;
}

.room-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--accent);
  transform: translateX(4px);
}

.room-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.room-name {
  font-weight: 600;
  font-size: 15px;
}

.room-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
}

.room-players {
  color: var(--success);
  font-weight: 500;
}

.room-state-badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.room-state-badge.waiting {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.room-state-badge.playing {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warning);
}

.room-lock-icon {
  margin-left: 8px;
  font-size: 14px;
}

.room-join-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  font-weight: 600;
}

/* ============ Modal ============ */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal {
  padding: 32px;
  min-width: 340px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal h2 {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ============ Lobby Screen ============ */
#lobby-screen.active {
  display: flex;
  flex-direction: column;
}

.lobby-container {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
}

.lobby-header {
  display: flex;
  align-items: center;
  gap: 16px;
}

.lobby-title {
  flex: 1;
  font-size: 20px;
  font-weight: 700;
}

.teams-container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.team-column {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border-glass);
  background: var(--bg-glass);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.team-column.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
}

.team-header {
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.red-header {
  background: var(--red-team-bg);
  color: var(--red-team);
  border-bottom: 2px solid var(--red-team);
}

.blue-header {
  background: var(--blue-team-bg);
  color: var(--blue-team);
  border-bottom: 2px solid var(--blue-team);
}

.spec-header {
  background: rgba(148, 163, 184, 0.1);
  color: var(--spec-color);
  border-bottom: 2px solid var(--spec-color);
}

.team-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.red-dot {
  background: var(--red-team);
  box-shadow: 0 0 8px var(--red-team);
}

.blue-dot {
  background: var(--blue-team);
  box-shadow: 0 0 8px var(--blue-team);
}

.spec-dot {
  background: var(--spec-color);
}

.player-list {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  min-height: 60px;
}

.player-item {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.03);
  transition: background 0.2s, transform 0.15s;
  user-select: none;
}

.player-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.player-item.draggable {
  cursor: grab;
}

.player-item.draggable:active {
  cursor: grabbing;
}

.player-item.dragging {
  opacity: 0.5;
  transform: scale(0.95);
}

.player-name {
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(245, 158, 11, 0.2);
  color: var(--warning);
  font-weight: 700;
}

.player-actions {
  display: flex;
  gap: 4px;
}

/* ============ Chat ============ */
.chat-section {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 180px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  padding-right: 4px;
}

.chat-msg {
  padding: 4px 0;
  line-height: 1.4;
}

.chat-msg .chat-sender {
  font-weight: 600;
  margin-right: 6px;
}

.chat-msg .chat-sender.red {
  color: var(--red-team);
}

.chat-msg .chat-sender.blue {
  color: var(--blue-team);
}

.chat-msg .chat-sender.spectator {
  color: var(--spec-color);
}

.chat-msg .chat-sender.system {
  color: var(--warning);
  font-weight: 800;
}

.chat-msg .chat-text {
  color: var(--text-secondary);
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-input-row input {
  flex: 1;
  font-size: 13px;
  padding: 8px 12px;
}

/* ============ Game Screen ============ */
#game-screen.active {
  display: block;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #1a472a;
}

#game-hud {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 10;
  padding: 8px 24px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  border: 1px solid var(--border-glass);
}

.hud-score {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 28px;
  font-weight: 800;
}

.hud-red-score {
  color: var(--red-team);
}

.hud-blue-score {
  color: var(--blue-team);
}

.hud-separator {
  color: var(--text-muted);
  font-weight: 300;
}

.hud-time {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.hud-state {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--warning);
}

.game-chat {
  position: fixed;
  bottom: 10px;
  left: 10px;
  width: 350px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.game-chat-messages {
  max-height: 150px;
  overflow-y: auto;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
}

.game-chat-messages .chat-msg {
  background: rgba(0, 0, 0, 0.5);
  padding: 3px 8px;
  border-radius: 4px;
  backdrop-filter: blur(4px);
}

#game-chat-input {
  font-size: 13px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
}

.btn-toggle-lobby {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 10;
}

/* ============ In-Game Lobby Overlay ============ */
.ingame-lobby-overlay {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  height: 100%;
  z-index: 20;
  transition: right 0.3s ease;
  pointer-events: none;
}

.ingame-lobby-overlay.active {
  right: 0;
  pointer-events: all;
}

.ingame-lobby-panel {
  height: 100%;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(10, 14, 23, 0.95);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--border-glass);
  border-radius: 0;
}

.ingame-lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ingame-lobby-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.ingame-teams-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
}

.ingame-team-column {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
  background: var(--bg-glass);
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ingame-team-column.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
}

.ingame-team-column .team-header {
  padding: 8px 12px;
  font-size: 11px;
}

.ingame-team-column .player-list {
  min-height: 40px;
  padding: 6px;
}

.ingame-lobby-actions {
  padding-top: 8px;
  display: flex;
  justify-content: center;
}

/* ============ Scrollbar ============ */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ============ Goal Animation ============ */
.goal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: none;
  animation: goalFlash 2s ease forwards;
}

.goal-text {
  font-size: 80px;
  font-weight: 900;
  letter-spacing: 10px;
  text-transform: uppercase;
  animation: goalPulse 0.6s ease;
  text-shadow: 0 0 40px currentColor;
}

.goal-text.red {
  color: var(--red-team);
}

.goal-text.blue {
  color: var(--blue-team);
}

@keyframes goalFlash {
  0% {
    background: rgba(0, 0, 0, 0);
  }

  10% {
    background: rgba(0, 0, 0, 0.4);
  }

  80% {
    background: rgba(0, 0, 0, 0.4);
  }

  100% {
    background: rgba(0, 0, 0, 0);
  }
}

@keyframes goalPulse {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ============ Match End Animation ============ */
.match-end-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(10, 14, 23, 0.85);
  padding: 40px 60px;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border-glass);
  backdrop-filter: blur(15px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  animation: matchEndSlideUp 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.match-end-title {
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: white;
  text-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.match-end-winner {
  font-size: 24px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.match-end-winner.red {
  color: var(--red-team);
  text-shadow: 0 0 15px var(--red-team);
}

.match-end-winner.blue {
  color: var(--blue-team);
  text-shadow: 0 0 15px var(--blue-team);
}

.match-end-score {
  font-size: 64px;
  font-weight: 900;
  color: white;
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

@keyframes matchEndSlideUp {
  0% {
    transform: translateY(50px) scale(0.9);
    opacity: 0;
  }

  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .teams-container {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr 1fr;
  }

  .browser-container {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .logo-text {
    font-size: 32px;
    letter-spacing: 4px;
  }

  .logo-icon {
    font-size: 48px;
  }

  .game-chat {
    width: calc(100% - 20px);
  }

  .ingame-lobby-overlay {
    width: 100%;
    right: -100%;
  }
}