* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #3B82F6;
  --primary-dark: #2563EB;
  --light-bg: #DBEAFE;
  --gray: #E5E7EB;
  --gray-dark: #9CA3AF;
  --card-width: 52px;
  --card-height: 72px;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #F3F4F6;
  color: #1F2937;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* --- Overlay / Join Dialog --- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.dialog {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.18);
}

.dialog h2 {
  text-align: center;
  font-size: 1.3rem;
  color: #111827;
}

.dialog input[type="text"] {
  padding: 10px 14px;
  border: 2px solid var(--gray);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
}

.dialog input[type="text"]:focus {
  border-color: var(--primary);
}

.spectator-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #6B7280;
  cursor: pointer;
}

.btn-primary {
  padding: 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}

.btn-primary:hover { background: var(--primary-dark); }

/* --- App Layout --- */

.app {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 16px;
  gap: 12px;
}

/* --- Table Grid (3x3) --- */

.table-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 120px 1fr 120px;
  grid-template-rows: 1fr auto auto auto 1fr;
  grid-template-areas:
    ".      .      ."
    "top    top    top"
    "left   center right"
    "bottom bottom bottom"
    ".      .      .";
  gap: 8px;
  min-height: 380px;
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
}

.grid-top    { grid-area: top; }
.grid-left   { grid-area: left;   display: flex; align-items: center; justify-content: center; }
.grid-center { grid-area: center; display: flex; align-items: center; justify-content: center; }
.grid-right  { grid-area: right;  display: flex; align-items: center; justify-content: center; }
.grid-bottom { grid-area: bottom; }

/* --- Player Rows (top / bottom) --- */

.player-row {
  display: flex;
  justify-content: center;
  gap: 28px;
  flex-wrap: wrap;
  padding: 8px 0;
}

.player-col {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Table Surface (center) --- */

.table-surface {
  background: var(--light-bg);
  border-radius: 20px;
  width: 100%;
  max-width: 420px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
}

.table-status {
  font-size: 0.95rem;
  color: #6B7280;
  transition: font-size .2s;
}

.table-status.warning {
  font-size: 1.4rem;
  font-weight: 700;
  color: #EF4444;
  animation: blink-warning 1s ease-in-out infinite;
}

@keyframes blink-warning {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.btn-action {
  padding: 10px 28px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
}

.btn-action:active { transform: scale(0.97); }

#reveal-btn {
  background: var(--primary);
  color: #fff;
}

#reveal-btn:hover { background: var(--primary-dark); }

.btn-new-round {
  background: #10B981;
  color: #fff;
}

.btn-new-round:hover { background: #059669; }

/* --- Player Card Component --- */

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.player-card {
  width: var(--card-width);
  height: var(--card-height);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  transition: transform .2s, box-shadow .2s;
}

.player-card.not-voted {
  background: var(--gray);
  border: 2px solid #D1D5DB;
  color: transparent;
}

.player-card.last-voter {
  background: linear-gradient(135deg, #EF4444 25%, #3B82F6 25%, #3B82F6 50%, #EF4444 50%, #EF4444 75%, #3B82F6 75%);
  background-size: 14px 14px;
  border: 2px solid #EF4444;
  color: transparent;
  animation: pulse-alarm 1s ease-in-out infinite;
}

@keyframes pulse-alarm {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 rgba(239,68,68,0); }
  50% { transform: scale(1.06); box-shadow: 0 0 12px rgba(239,68,68,0.4); }
}

.player-card.voted {
  background: linear-gradient(135deg, #3B82F6 25%, #2563EB 25%, #2563EB 50%, #3B82F6 50%, #3B82F6 75%, #2563EB 75%);
  background-size: 14px 14px;
  border: 2px solid var(--primary-dark);
  color: transparent;
}

.player-card.revealed {
  background: #fff;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.player-card.spectator {
  background: transparent;
  border: 2px dashed var(--gray-dark);
  color: var(--gray-dark);
  font-size: 1.3rem;
}

.player-name {
  font-size: 0.98rem;
  color: #374151;
  font-weight: 500;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.player-name.is-you {
  color: var(--primary);
  font-weight: 700;
}

/* --- Vote Results --- */

.vote-results {
  background: #fff;
  border-radius: 12px;
  padding: 14px 24px;
  display: flex;
  gap: 32px;
  justify-content: center;
  flex-wrap: wrap;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.vote-result-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.result-card {
  width: 52px;
  height: 72px;
  border-radius: var(--radius);
  background: #fff;
  border: 2px solid var(--primary);
  color: var(--primary);
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-card-avg {
  border-color: #10B981;
  color: #10B981;
}

.vote-result-count {
  font-size: 0.85rem;
  font-weight: 600;
  color: #6B7280;
}

/* --- Voting Panel --- */

.voting-panel {
  background: #fff;
  border-radius: 14px;
  padding: 14px 12px;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.voting-cards {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.vote-option {
  width: 50px;
  height: 68px;
  border-radius: 8px;
  border: 2px solid var(--primary);
  background: #fff;
  color: var(--primary);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, transform .1s, box-shadow .15s;
  user-select: none;
}

.vote-option:hover {
  background: #EFF6FF;
  transform: translateY(-3px);
  box-shadow: 0 4px 10px rgba(59,130,246,0.18);
}

.vote-option.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
  transform: translateY(-5px);
  box-shadow: 0 4px 14px rgba(59,130,246,0.3);
}

/* --- Responsive --- */

@media (max-width: 640px) {
  .table-grid {
    grid-template-columns: 60px 1fr 60px;
  }
  .player-row { gap: 14px; }
  .vote-option { width: 42px; height: 58px; font-size: 0.85rem; }
}
