/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', sans-serif;
  background: #1a1a2e;
  background-image: radial-gradient(circle at 30% 70%, #16213e 0%, #1a1a2e 60%);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: #fff;
  user-select: none;
  overflow-x: hidden;
}

/* ===== TOP BAR ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  gap: 0.5rem;
  flex-shrink: 0;
  z-index: 10;
}

.btn-back {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.15);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  transition: background 0.2s;
  white-space: nowrap;
}
.btn-back:hover { background: rgba(255,255,255,0.3); }

.game-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.topbar-right {
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0.85;
  white-space: nowrap;
}

/* ===== MULTIPLAYER MENU ===== */
.multiplayer-menu {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1.5rem 1rem;
  gap: 1.5rem;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.menu-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.menu-section h2 {
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.5rem;
}

.mode-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  background: rgba(255,255,255,0.08);
  border: 2px solid transparent;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn:hover {
  background: rgba(255,255,255,0.12);
}

.mode-btn.active {
  border-color: #ff6b35;
  background: rgba(255,107,53,0.15);
}

.mode-icon {
  font-size: 2rem;
}

.mode-label {
  font-size: 0.85rem;
  font-weight: 600;
}

.multiplayer-options {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  background: rgba(255,255,255,0.05);
  padding: 1.25rem;
  border-radius: 16px;
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.option-group label {
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.9;
}

.player-count-selector {
  display: flex;
  gap: 0.5rem;
}

.player-count-selector .btn {
  flex: 1;
  padding: 0.6rem;
  background: rgba(255,255,255,0.1);
  border: 2px solid transparent;
  border-radius: 10px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.player-count-selector .btn:hover {
  background: rgba(255,255,255,0.15);
}

.player-count-selector .btn.active {
  border-color: #ff6b35;
  background: rgba(255,107,53,0.2);
}

.or-divider {
  text-align: center;
  font-size: 0.85rem;
  opacity: 0.6;
  position: relative;
}

.or-divider::before,
.or-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: rgba(255,255,255,0.2);
}

.or-divider::before { left: 0; }
.or-divider::after { right: 0; }

.join-room-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.join-room-group input {
  padding: 0.75rem 1rem;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  text-align: center;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.join-room-group input::placeholder {
  color: rgba(255,255,255,0.4);
  text-transform: none;
  letter-spacing: normal;
}

.join-room-group input:focus {
  outline: none;
  border-color: #ff6b35;
}

/* ===== WAITING ROOM ===== */
.waiting-room {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1.5rem 1rem;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.waiting-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  align-items: center;
}

.waiting-content h2 {
  font-size: 1.4rem;
  font-weight: 800;
}

.room-code-display {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(255,255,255,0.1);
  padding: 0.75rem 1rem;
  border-radius: 12px;
}

.code-label {
  font-size: 0.85rem;
  opacity: 0.8;
}

.code-value {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 4px;
  font-family: 'Courier New', monospace;
  color: #ff6b35;
}

.btn-copy {
  padding: 0.4rem 0.8rem;
  font-size: 0.75rem;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-copy:hover {
  background: rgba(255,255,255,0.25);
}

.players-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.player-slot {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: rgba(255,255,255,0.08);
  border-radius: 12px;
  border: 2px solid transparent;
  transition: all 0.2s;
}

.player-slot.waiting {
  opacity: 0.6;
}

.player-slot.filled {
  background: rgba(67,160,71,0.15);
  border-color: #43a047;
}

.slot-color {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.slot-status {
  font-weight: 600;
  font-size: 0.9rem;
}

.waiting-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.waiting-hint {
  font-size: 0.85rem;
  opacity: 0.7;
  text-align: center;
}

/* ===== GAME WRAPPER ===== */
.game-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 0.5rem 0;
  gap: 0.5rem;
  min-height: 0;
}

/* ===== PLAYERS BAR ===== */
.players-bar {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 460px;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(255,255,255,0.08);
  border: 2px solid transparent;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 700;
  transition: border-color 0.2s, background 0.2s;
}

.player-chip.active {
  background: rgba(255,255,255,0.15);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.3);
}
.player-chip-red.active   { border-color: #e53935; box-shadow: 0 0 8px rgba(229,57,53,0.4); }
.player-chip-blue.active  { border-color: #1e88e5; box-shadow: 0 0 8px rgba(30,136,229,0.4); }
.player-chip-green.active { border-color: #43a047; box-shadow: 0 0 8px rgba(67,160,71,0.4); }
.player-chip-yellow.active{ border-color: #fdd835; box-shadow: 0 0 8px rgba(253,216,53,0.4); }

.player-chip.is-me .chip-name {
  color: #ff6b35;
}

.chip-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chip-name {
  opacity: 0.9;
}

.chip-score {
  font-size: 0.72rem;
  opacity: 0.7;
}

/* ===== BOARD AREA ===== */
.board-area {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex-shrink: 0;
}

#ludo-canvas {
  border-radius: 12px;
  box-shadow: 0 6px 32px rgba(0,0,0,0.6);
  width: min(450px, 96vw, 60vh);
  height: min(450px, 96vw, 60vh);
  cursor: pointer;
  display: block;
}

/* ===== CONTROLS ===== */
.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding-bottom: 0.5rem;
}

.dice-area {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.dice {
  font-size: 2.4rem;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
  transition: transform 0.1s;
  min-width: 2.4rem;
  text-align: center;
}

.dice.rolling {
  animation: rollDice 0.5s ease;
}

@keyframes rollDice {
  0%   { transform: rotate(0deg)   scale(1); }
  25%  { transform: rotate(90deg)  scale(1.2); }
  50%  { transform: rotate(180deg) scale(0.9); }
  75%  { transform: rotate(270deg) scale(1.15); }
  100% { transform: rotate(360deg) scale(1); }
}

/* ===== BUTTONS ===== */
.btn {
  padding: 0.45rem 1.4rem;
  border: none;
  border-radius: 999px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s, background 0.2s;
}
.btn:active { transform: scale(0.95); }

.btn-primary {
  background: linear-gradient(135deg, #ff6b35, #f5576c);
  color: #fff;
  box-shadow: 0 3px 12px rgba(255,107,53,0.4);
}
.btn-primary:hover:not(:disabled) { opacity: 0.88; }

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.15);
}

.btn-large {
  padding: 0.8rem 2rem;
  font-size: 1rem;
}

.btn:disabled {
  background: #444;
  color: #888;
  box-shadow: none;
  cursor: not-allowed;
}

#btn-roll {
  background: linear-gradient(135deg, #e53935, #c62828);
  color: #fff;
  box-shadow: 0 3px 12px rgba(229,57,53,0.4);
}
#btn-roll:hover:not(:disabled) { opacity: 0.88; }
#btn-roll:disabled {
  background: #444;
  color: #888;
  box-shadow: none;
}

#btn-new-game {
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 0.8rem;
  padding: 0.35rem 1rem;
}
#btn-new-game:hover { background: rgba(255,255,255,0.2); }

.turn-msg {
  font-size: 0.88rem;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  text-align: center;
  min-height: 1.2em;
}

/* ===== WAITING MESSAGE ===== */
.waiting-msg {
  font-size: 0.9rem;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  text-align: center;
  padding: 0.5rem;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(5px);
}
.modal-overlay.hidden { display: none; }

.modal {
  text-align: center;
  background: #1e2a3a;
  border-radius: 20px;
  padding: 2rem 2.5rem;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  animation: popIn 0.35s cubic-bezier(.34,1.56,.64,1);
  max-width: 90vw;
}

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.modal-icon { font-size: 3.5rem; margin-bottom: 0.5rem; }
.modal h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 0.3rem;
}
.modal p {
  font-size: 1rem;
  color: rgba(255,255,255,0.7);
  margin-bottom: 0.4rem;
}
.modal-stats {
  font-size: 0.88rem;
  color: rgba(255,255,255,0.55);
  margin-bottom: 1rem;
  line-height: 1.6;
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .game-title { font-size: 0.95rem; }
  .player-chip { font-size: 0.72rem; padding: 0.18rem 0.5rem; }
  .dice { font-size: 2rem; }
  #btn-roll { font-size: 0.82rem; padding: 0.4rem 1.1rem; }
  .turn-msg { font-size: 0.8rem; }

  .multiplayer-menu {
    padding: 1rem;
  }

  .mode-btn {
    padding: 0.75rem;
  }

  .mode-icon {
    font-size: 1.5rem;
  }

  .mode-label {
    font-size: 0.75rem;
  }

  .room-code-display {
    flex-direction: column;
    gap: 0.5rem;
  }

  .code-value {
    font-size: 1.2rem;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  .topbar { padding: 0.25rem 0.75rem; }
  .game-title { display: none; }
  .players-bar { display: none; }
  .game-wrapper { flex-direction: row; flex-wrap: wrap; gap: 0.3rem; padding: 0.3rem; align-items: flex-start; justify-content: center; }
  .board-area { flex: 0 0 auto; }
  #ludo-canvas { width: min(320px, 55vw, 80vh); height: min(320px, 55vw, 80vh); }
  .controls { flex: 1; justify-content: center; min-width: 120px; max-width: 160px; }
  .dice { font-size: 1.8rem; }

  .multiplayer-menu,
  .waiting-room {
    flex-direction: row;
    align-items: flex-start;
    padding: 0.5rem;
  }

  .menu-section {
    flex: 1;
    max-width: 300px;
  }
}

/* ===== SEO GAME INFO ===== */
.game-info {
  max-width: 780px;
  margin: 1rem auto;
  padding: 1rem 1.2rem;
  background: rgba(0,0,0,0.15);
  border-radius: 12px;
  color: rgba(255,255,255,0.85);
  font-size: 0.88rem;
  line-height: 1.6;
}
.game-info h2 { font-size: 1.1rem; font-weight: 800; margin-bottom: 0.5rem; }
.game-info h3 { font-size: 0.95rem; font-weight: 700; margin: 0.8rem 0 0.3rem; }
.game-info ul { padding-left: 1.2rem; }
.game-info li { margin-bottom: 0.2rem; }
