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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #ff6b9d 0%, #c44569 40%, #f8b739 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* ===== SCREENS ===== */
.screen { display: none; width: 100%; justify-content: center; align-items: center; min-height: 100vh; }
.screen.active { display: flex; }

/* ===== CARD ===== */
.card {
  background: rgba(255,255,255,0.95);
  border-radius: 24px;
  padding: 36px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 480px;
  text-align: center;
}

/* ===== SETUP SCREEN ===== */
.setup-card .title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #c44569, #f8b739);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}
.setup-card .subtitle { color: #888; margin-bottom: 24px; font-size: 0.95rem; }

.form-group { margin-bottom: 20px; text-align: left; }
.form-group label { display: block; font-weight: 600; color: #555; margin-bottom: 8px; font-size: 0.9rem; }
.form-group input[type="text"] {
  width: 100%; padding: 12px 16px; border: 2px solid #f0d0dc; border-radius: 12px;
  font-size: 1rem; outline: none; transition: border-color 0.2s;
}
.form-group input[type="text"]:focus { border-color: #c44569; }

/* Pion grid */
.pion-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 4px;
  max-height: 165px; overflow-y: auto; overflow-x: hidden;
  padding-right: 4px; /* for scrollbar */
}
/* Custom scrollbar for pion-grid */
.pion-grid::-webkit-scrollbar { width: 6px; }
.pion-grid::-webkit-scrollbar-track { background: #fdf0f5; border-radius: 4px; }
.pion-grid::-webkit-scrollbar-thumb { background: #f0d0dc; border-radius: 4px; }
.pion-grid::-webkit-scrollbar-thumb:hover { background: #c44569; }

.pion-option {
  font-size: 1.6rem; padding: 8px; border-radius: 10px; cursor: pointer;
  border: 2px solid transparent; transition: all 0.2s; background: #fdf0f5; text-align: center;
  user-select: none;
}
.pion-option:hover { border-color: #c44569; transform: scale(1.1); background: #fde8f0; }
.pion-option.selected { border-color: #c44569; background: #fde8f0; box-shadow: 0 0 0 3px rgba(196,69,105,0.2); transform: scale(1.1); z-index: 2; position: relative; }

/* Setup buttons */
.setup-buttons { margin-top: 8px; }
.divider { color: #bbb; margin: 16px 0; font-size: 0.85rem; position: relative; }
.divider::before, .divider::after {
  content: ''; position: absolute; top: 50%; width: 42%; height: 1px; background: #eee;
}
.divider::before { left: 0; }
.divider::after { right: 0; }

.join-section { display: flex; gap: 8px; }
.join-section input { flex: 1; padding: 12px 16px; border: 2px solid #f0d0dc; border-radius: 12px; font-size: 1rem; outline: none; text-transform: uppercase; letter-spacing: 2px; text-align: center; transition: border-color 0.2s; }
.join-section input:focus { border-color: #c44569; }

/* ===== BUTTONS ===== */
.btn {
  padding: 13px 28px; border: none; border-radius: 12px; font-size: 1rem;
  font-weight: 700; cursor: pointer; transition: all 0.2s; letter-spacing: 0.3px;
}
.btn-primary {
  background: linear-gradient(135deg, #c44569, #e8627c);
  color: white; width: 100%;
  box-shadow: 0 4px 15px rgba(196,69,105,0.4);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(196,69,105,0.5); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { background: #ccc; box-shadow: none; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: linear-gradient(135deg, #f8b739, #f5a623);
  color: white; padding: 12px 20px;
  box-shadow: 0 4px 15px rgba(248,183,57,0.4);
}
.btn-secondary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(248,183,57,0.5); }

.btn-small { padding: 8px 16px; font-size: 0.85rem; width: auto; margin-top: 8px; }

.error-msg { color: #e74c3c; margin-top: 12px; font-size: 0.9rem; min-height: 1.2em; }

/* ===== LOBBY SCREEN ===== */
.lobby-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.btn-back { background: none; border: none; font-size: 1rem; color: #888; cursor: pointer; padding: 8px; border-radius: 8px; transition: background 0.2s; }
.btn-back:hover { background: #f0f0f0; color: #555; }
.lobby-header h2 { color: #c44569; margin: 0; flex: 1; text-align: center; }
.room-code-display { background: #fdf0f5; border-radius: 16px; padding: 20px; margin-bottom: 24px; }
.room-code-label { display: block; color: #888; font-size: 0.85rem; margin-bottom: 8px; }
.room-code { font-size: 2.8rem; font-weight: 900; letter-spacing: 8px; color: #c44569; }

.lobby-players { display: flex; gap: 16px; justify-content: center; margin-bottom: 20px; flex-wrap: wrap; }
.lobby-player {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: #fdf0f5; border-radius: 12px; padding: 16px 24px;
}
.lobby-player .pion { font-size: 2rem; }
.lobby-player .name { font-weight: 700; color: #c44569; font-size: 0.9rem; }
.lobby-player .you-badge { font-size: 0.7rem; background: #c44569; color: white; padding: 2px 8px; border-radius: 20px; }

.waiting-msg { color: #aaa; font-size: 0.9rem; animation: pulse 2s infinite; }

/* ===== RPS SCREEN ===== */
.rps-card h2 { color: #c44569; margin-bottom: 8px; }
.rps-subtitle { color: #888; margin-bottom: 24px; font-size: 0.9rem; }

.rps-players { display: flex; gap: 20px; justify-content: center; margin-bottom: 28px; flex-wrap: wrap; }
.rps-player { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rps-player .pion { font-size: 2.5rem; }
.rps-player .name { font-weight: 700; color: #555; font-size: 0.9rem; }
.rps-player .choice-display { font-size: 1.8rem; min-height: 2rem; }

.rps-buttons { display: flex; gap: 12px; justify-content: center; margin-bottom: 20px; flex-wrap: wrap; }
.rps-btn {
  font-size: 1.1rem; padding: 14px 22px; background: #fdf0f5; color: #c44569;
  border: 2px solid #f0d0dc; border-radius: 14px; width: auto;
  transition: all 0.2s;
}
.rps-btn:hover { background: #fde8f0; border-color: #c44569; transform: scale(1.05); }
.rps-btn.selected { background: #c44569; color: white; border-color: #c44569; }
.rps-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.rps-result { min-height: 60px; font-size: 1.1rem; color: #c44569; font-weight: 700; line-height: 1.5; }

/* ===== GAME SCREEN ===== */
#game-screen {
  display: none; align-items: flex-start; justify-content: center;
  padding: 16px; min-height: 100vh;
}
#game-screen.active { display: flex; }

.game-layout {
  display: flex; gap: 20px; align-items: stretch;
  width: 100%; max-width: 1200px; flex-wrap: wrap; justify-content: center;
}

/* BOARD – 2D DOM container */
.board-wrapper {
  flex: 0 0 auto;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.30);
  background: #fdf0f5;
  border: 4px solid #c44569;
}

.board-2d {
  width:  min(560px, 94vw);
  height: min(560px, 94vw);
  display: block;
  outline: none;
  position: relative;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.board-tile {
  box-sizing: border-box;
  border: 1px solid rgba(196, 69, 105, 0.2);
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 4px;
  font-size: clamp(0.6rem, 3.5vw, 0.8rem);
  font-weight: 700;
  color: #888;
}

.board-tile.highlighted {
  background-color: rgba(248, 183, 57, 0.4) !important;
  box-shadow: inset 0 0 10px rgba(248, 183, 57, 0.6);
}

.type-normal { background: #faf6f0; }
.type-snake { background: #ffe0e0; }
.type-ladder { background: #dcf5dc; }
.type-special { background: #f0ddff; }

.board-pion {
  font-size: clamp(1.2rem, 5vw, 2rem);
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,0.3));
  transform: translate(-50%, -50%);
  margin-top: 0;
  margin-left: 0;
}

/* SIDE PANEL */
.side-panel {
  flex: 0 0 220px;
  background: rgba(255,255,255,0.95);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 250px;
  height: 100%; min-height: 560px;
}
.panel-title { color: #c44569; font-size: 1.1rem; font-weight: 800; text-align: center; }

.turn-indicator {
  background: linear-gradient(135deg, #fde8f0, #fdf0f5);
  border-radius: 12px; padding: 12px; text-align: center;
  border: 2px solid #f0d0dc;
}
#turn-text { font-weight: 700; color: #c44569; font-size: 0.9rem; }

/* Dice wrap */
.dice-2d-wrap {
  width: 100%;
  height: 120px;
  border-radius: 16px;
  background: #fdf0f5;
  box-shadow: 0 4px 12px rgba(196,69,105,0.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 5rem;
  perspective: 500px;
}
.dice-emoji {
  transition: transform 0.5s ease-out;
}

.move-info {
  text-align: center; font-size: 0.82rem; color: #888; min-height: 1.5em;
  background: #fafafa; border-radius: 8px; padding: 8px;
}

.players-panel { display: flex; flex-direction: column; gap: 10px; }
.player-info {
  display: flex; align-items: center; gap: 10px;
  background: #fdf0f5; border-radius: 10px; padding: 10px;
  border: 2px solid transparent; transition: border-color 0.3s;
}
.player-info.active-turn { border-color: #c44569; }
.player-info .pi-pion { font-size: 1.6rem; }
.player-info .pi-details { flex: 1; }
.player-info .pi-name { font-weight: 700; color: #444; font-size: 0.85rem; }
.player-info .pi-pos { color: #888; font-size: 0.78rem; }

.btn-roll { font-size: 1.1rem; padding: 16px; }

.legend { display: flex; flex-direction: column; gap: 6px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: #666; }
.legend-dot { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }
.snake-dot { background: #ffe5e5; border: 1px solid #ffb3b3; }
.ladder-dot { background: #e5f9e5; border: 1px solid #b3e6b3; }
.special-dot { background: #f5e5ff; border: 1px solid #d9b3ff; }

/* CHAT AREA */
.chat-container {
  flex: 0 0 220px;
  min-width: 250px;
  display: flex; flex-direction: column; 
  background: rgba(255,255,255,0.95);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  /* Make heights flexible to match content / layout perfectly if side panel grows, but default to same. */
  height: 100%; min-height: 560px;
  overflow: hidden;
}
.chat-messages {
  flex: 1; padding: 10px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  background: #fafafa; font-size: 0.85rem;
}
.chat-info { color: #aaa; text-align: center; font-style: italic; font-size: 0.8rem; margin-bottom: 4px; }
.chat-msg { background: #fdf0f5; padding: 6px 10px; border-radius: 10px; border-bottom-left-radius: 2px; align-self: flex-start; max-width: 90%; word-break: break-word;}
.chat-msg.me { background: #e8ebf7; border-radius: 10px; border-bottom-right-radius: 2px; align-self: flex-end; }
.chat-msg .c-name { font-weight: 700; font-size: 0.75rem; color: #888; margin-bottom: 2px; }
.chat-msg .c-text { color: #333; }

.chat-input-form { display: flex; border-top: 1px solid #eee; background: #fff; }
.chat-input-form input {
  flex: 1; border: none; padding: 8px 10px; outline: none; font-size: 0.9rem;
}
.btn-chat {
  background: #c44569; color: white; padding: 0 12px; border-radius: 0;
  font-size: 0.85rem; transition: background 0.2s;
}
.btn-chat:hover { background: #a23856; box-shadow: none; transform: none; }
.btn-chat:active { box-shadow: none; transform: none; }

/* ===== QUESTION MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: white; border-radius: 24px; padding: 36px;
  max-width: 440px; width: 100%; text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.3);
  animation: modalIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
.modal-header {
  font-size: 1.8rem; font-weight: 900; margin-bottom: 20px;
  background: linear-gradient(135deg, #c44569, #f8b739);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.modal-body {
  font-size: 1.1rem; color: #444; line-height: 1.6; margin-bottom: 28px;
  padding: 20px; background: #fdf0f5; border-radius: 14px;
}

/* ===== WIN SCREEN ===== */
.win-card { position: relative; overflow: hidden; }
.win-emoji { font-size: 5rem; margin-bottom: 16px; animation: bounce 1s infinite; }
.win-card h2 { font-size: 1.8rem; color: #c44569; margin-bottom: 8px; }
.win-card p { color: #888; margin-bottom: 24px; }
#confetti-container { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti-piece {
  position: absolute; width: 10px; height: 10px; border-radius: 50%;
  animation: confettiFall linear forwards;
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container { position: fixed; top: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 9999; }
.toast { background: white; color: #333; padding: 16px 20px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); font-weight: 500; font-size: 0.95rem; display: flex; align-items: center; gap: 12px; min-width: 250px; max-width: 350px; transform: translateX(120%); transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s; opacity: 0; border-left: 5px solid #c44569; }
.toast.toast-error { border-left-color: #e74c3c; }
.toast.toast-success { border-left-color: #27ae60; }
.toast.visible { transform: translateX(0); opacity: 1; }
.toast-icon { font-size: 1.2rem; }

/* ===== ANIMATIONS ===== */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes diceRoll {
  0% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.3) rotate(-20deg); }
  50% { transform: scale(0.9) rotate(40deg); }
  75% { transform: scale(1.1) rotate(-10deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.rolling {
  animation: diceRoll 0.4s ease-in-out infinite;
}

@keyframes modalIn {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

@keyframes confettiFall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .game-layout { max-width: 900px; }
  .chat-container { height: 300px; }
}

@media (max-width: 768px) {
  .game-layout { flex-direction: column; align-items: center; }
  .board-wrapper { width: 100%; }
  .board-2d { width: 100%; height: auto; aspect-ratio: 1; }
  .side-panel { flex: 0 0 auto; width: 100%; max-width: 600px; flex-direction: row; flex-wrap: wrap; gap: 10px; height: auto; min-height: auto; }
  .chat-container { flex: 0 0 auto; width: 100%; max-width: 600px; height: 250px; min-height: 250px; }
  .panel-title { width: 100%; }
  .turn-indicator, .dice-2d-wrap, .move-info { flex: 1 1 120px; }
  .players-panel { flex: 1 1 200px; flex-direction: row; }
  .btn-roll { flex: 1 1 120px; align-self: flex-end; }
  .legend { display: none; }
  .card { padding: 24px 20px; }
  .pion-grid { grid-template-columns: repeat(6, 1fr); }
}

@media (max-width: 480px) {
  .card { padding: 20px 16px; }
  .join-section { flex-direction: column; }
  .join-section input { width: 100%; text-align: center; }
  .btn-secondary { width: 100%; }
  .room-code { font-size: 2.2rem; letter-spacing: 4px; }
  .pion-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; max-height: 145px; }
  .pion-option { font-size: 1.4rem; padding: 6px; }
  .setup-card .title { font-size: 1.6rem; }
  .turn-indicator, .dice-2d-wrap, .move-info { flex: 1 1 100%; }
  .btn-roll { flex: 1 1 100%; margin-top: 10px; }
  .players-panel { flex: 1 1 100%; flex-direction: column; }
}
