* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  color: #e2e8f0;
  min-height: 100vh;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.panel {
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(71, 85, 105, 0.6);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  backdrop-filter: blur(8px);
}

.header-panel {
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
  border-color: rgba(59, 130, 246, 0.4);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
}

.connection-status {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 500;
}
.connection-status.connected {
  background: rgba(34, 197, 94, 0.25);
  color: #86efac;
}
.connection-status.connecting {
  background: rgba(234, 179, 8, 0.25);
  color: #fde047;
}
.connection-status.disconnected {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.stats > div {
  background: rgba(15, 23, 42, 0.6);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  border: 1px solid rgba(71, 85, 105, 0.4);
}

.stats span {
  font-weight: 700;
  color: #93c5fd;
}

h2 {
  margin: 0 0 12px 0;
  font-size: 1rem;
  font-weight: 600;
  color: #cbd5e1;
}

.current-call-panel {
  text-align: center;
  padding: 20px;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
  border: 2px solid rgba(245, 158, 11, 0.5);
}

.current-call-label {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 8px;
}

.current-call-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: #e2e8f0;
  letter-spacing: 0.1em;
}

.current-call-value.highlight {
  color: #fbbf24;
  text-shadow: 0 0 24px rgba(251, 191, 36, 0.6);
  animation: pulse-call 0.5s ease-out;
}

@keyframes pulse-call {
  0% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.game-board-with-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-start;
  overflow-x: auto;
}

.game-board-section {
  flex: 0 0 auto;
}

.game-board-section h2,
.my-cards-inline h2 {
  margin: 0 0 12px 0;
  font-size: 1rem;
  font-weight: 600;
  color: #cbd5e1;
}

.my-cards-inline {
  flex: 1 1 200px;
  min-width: 0;
}

.my-cards-inline .my-cards-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  align-content: start;
  max-width: 420px;
}

.my-cards-inline .bingo-card-wrap {
  min-width: 0;
}

.my-cards-inline .bingo-card-grid {
  width: 100%;
  max-width: 120px;
}

.bingo-board {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: nowrap;
}

.bingo-board-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 36px;
}

.bingo-board-header {
  font-size: 1.25rem;
  font-weight: 800;
  color: #f59e0b;
  text-align: center;
  padding: 6px 0;
}

.bingo-board-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  background: #1e293b;
  border: 1px solid rgba(71, 85, 105, 0.6);
  border-radius: 6px;
  color: #94a3b8;
}

.bingo-board-cell.called {
  background: linear-gradient(135deg, #166534 0%, #15803d 100%);
  border-color: #22c55e;
  color: #dcfce7;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}

.watch-only-msg {
  padding: 24px;
  text-align: center;
  color: #94a3b8;
  font-size: 1rem;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 12px;
  border: 2px dashed rgba(71, 85, 105, 0.6);
}

.cards-panel h2 {
  margin-bottom: 12px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
}

.card-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border: 2px solid rgba(71, 85, 105, 0.6);
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  color: #e2e8f0;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.card-btn:hover:not(.locked) {
  transform: scale(1.05);
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.4);
  border-color: rgba(59, 130, 246, 0.6);
  background: linear-gradient(180deg, #334155 0%, #1e293b 100%);
}

.card-btn:active:not(.locked) {
  transform: scale(0.98);
}

.card-btn.mine {
  background: linear-gradient(180deg, #15803d 0%, #166534 100%) !important;
  border: 2px solid #22c55e !important;
  color: #dcfce7 !important;
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.6);
  opacity: 1 !important;
}

.card-btn.mine:hover {
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.7);
}

.card-btn.taken:not(.mine) {
  background: linear-gradient(180deg, #78350f 0%, #92400e 100%) !important;
  color: #fef3c7 !important;
}

.card-btn.system-selected {
  border: 2px solid #f59e0b !important;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
  opacity: 1 !important;
}

.card-btn.locked {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.card-btn.system-selected.locked {
  opacity: 1 !important;
}

.card-btn.just-selected {
  animation: card-just-selected 1.2s ease-out;
  border-color: rgba(245, 158, 11, 0.9) !important;
}

@keyframes card-just-selected {
  0% {
    box-shadow: 0 0 24px rgba(245, 158, 11, 0.95);
    transform: scale(1.12);
    background: rgba(120, 53, 15, 0.5) !important;
  }
  50% {
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.8);
    transform: scale(1.06);
  }
  100% {
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
    transform: scale(1);
  }
}

.my-cards-panel {
  display: block;
}

.my-cards-panel:empty .my-cards-container,
.my-cards-container:empty {
  display: none;
}

.my-cards-container {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-start;
}

.my-cards-standalone {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.bingo-card-wrap {
  background: rgba(15, 23, 42, 0.9);
  border: 2px solid rgba(34, 197, 94, 0.5);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.2);
}

.bingo-card-wrap h3 {
  margin: 0 0 8px 0;
  font-size: 0.85rem;
  color: #86efac;
}

.bingo-card-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  width: min(180px, 100%);
}

.bingo-card-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  background: #1e293b;
  border: 1px solid rgba(71, 85, 105, 0.6);
  border-radius: 6px;
  color: #e2e8f0;
}

.bingo-card-cell.called {
  background: linear-gradient(135deg, #166534 0%, #15803d 100%);
  border-color: #22c55e;
  color: #dcfce7;
}

.bingo-card-cell.free {
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
  color: #93c5fd;
}

.events {
  max-height: 180px;
  overflow: auto;
  font-size: 0.8rem;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 10px;
  padding: 8px;
  border: 1px solid rgba(71, 85, 105, 0.3);
}

.event {
  border-bottom: 1px solid rgba(71, 85, 105, 0.3);
  padding: 6px 0;
  color: #94a3b8;
}

.event:last-child {
  border-bottom: none;
}

.winner-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.winner-modal.open {
  opacity: 1;
  visibility: visible;
}

.winner-modal-content {
  background: linear-gradient(160deg, #1e3a5f 0%, #0f172a 100%);
  border: 2px solid rgba(251, 191, 36, 0.6);
  border-radius: 24px;
  padding: 28px;
  max-width: 360px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 48px rgba(251, 191, 36, 0.3);
  animation: modal-in 0.4s ease-out;
}

@keyframes modal-in {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.winner-modal-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: #fbbf24;
  margin-bottom: 12px;
  text-shadow: 0 0 20px rgba(251, 191, 36, 0.5);
}

.winner-modal-name {
  font-size: 1.1rem;
  color: #e2e8f0;
  margin-bottom: 8px;
}

.winner-modal-card {
  font-size: 0.9rem;
  color: #86efac;
  margin-bottom: 8px;
}

.winner-modal-prize {
  font-size: 1.5rem;
  font-weight: 800;
  color: #22c55e;
  margin-bottom: 16px;
}

.winner-modal-board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.winner-modal-grid-label {
  font-size: 0.85rem;
  color: #94a3b8;
  font-weight: 600;
}

.winner-modal-card-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  width: min(160px, 100%);
  margin: 0 auto;
}

.winner-modal-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  background: #1e293b;
  border: 1px solid rgba(71, 85, 105, 0.6);
  border-radius: 4px;
  color: #94a3b8;
}

.winner-modal-cell.called {
  background: linear-gradient(135deg, #166534 0%, #15803d 100%);
  color: #dcfce7;
}

.winner-modal-cell.free {
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
  color: #93c5fd;
}

.bingo-board-col.small .bingo-board-cell {
  font-size: 0.6rem;
}

@media (max-width: 640px) {
  .cards-grid {
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
  }
  .card-btn {
    font-size: 0.55rem;
  }
  .stats {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
  }
  .stats > div {
    padding: 6px 4px;
    font-size: 0.7rem;
  }
  .game-board-with-cards {
    flex-wrap: nowrap;
    align-items: flex-start;
  }
  .game-board-section {
    flex: 0 0 58%;
    max-width: 58%;
  }
  .my-cards-inline {
    flex: 1 1 0;
    max-width: 42%;
  }
  .bingo-board {
    flex-wrap: nowrap;
    justify-content: space-between;
    overflow-x: hidden;
  }
  .bingo-board-col {
    flex: 1 1 0;
    min-width: 0;
  }
  .bingo-board-header {
    font-size: 1rem;
    padding: 4px 0;
  }
  .my-cards-inline .my-cards-container {
    max-width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: 10px;
  }
  .my-cards-inline .my-cards-container.two-cards-stacked {
    grid-template-columns: 1fr;
  }
  .my-cards-inline .bingo-card-grid {
    width: min(140px, 42vw);
    max-width: none;
  }
  .bingo-card-cell {
    font-size: 0.45rem;
  }
}
