:root {
  --red: #e53935;
  --green: #43a047;
  --yellow: #fdd835;
  --blue: #1e88e5;
  --bg: #f7f1e3;
  --card: #ffffff;
  --text: #2c2c2c;
  --muted: #6d6d6d;
  --border: #d7ccc8;
  --primary: #7b1fa2;
  --primary-hover: #4a126c;
  --secondary: #efebe9;
  --secondary-hover: #d7ccc8;
  --danger: #c62828;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  --shadow-hover: 0 10px 28px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top left, #fff8e1, #efe0c2 60%, #e6d2a8);
  color: var(--text);
  min-height: 100vh;
}

#app {
  min-height: 100vh;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

/* Lobby */
.lobby-card {
  background: linear-gradient(145deg, #ffffff, #fff8e1);
  border-radius: 24px;
  box-shadow: var(--shadow-hover);
  padding: 36px;
  width: 100%;
  max-width: 520px;
  border: 1px solid rgba(123, 31, 162, 0.1);
}

.lobby-card h1 {
  margin: 0 0 8px;
  font-size: 2.4rem;
  color: var(--primary);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.08);
}

.subtitle {
  color: var(--muted);
  margin-bottom: 14px;
  font-size: 1rem;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 18px;
}

.connection-status.connecting {
  background: #fff3e0;
  color: #e65100;
}

.connection-status.connected {
  background: #e8f5e9;
  color: #2e7d32;
}

.connection-status.error {
  background: #ffebee;
  color: #c62828;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.4s infinite;
}

.connection-status.connected .status-dot,
.connection-status.error .status-dot {
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.error-banner {
  background: #ffebee;
  color: #c62828;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 600;
  margin-bottom: 16px;
  border: 1px solid #ef9a9a;
}

.name-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 22px;
}

.name-row label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--primary);
}

input[type='text'] {
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  outline: none;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type='text']:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(123, 31, 162, 0.12);
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  flex: 1;
  text-transform: uppercase;
}

.btn {
  padding: 14px 20px;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.btn:active {
  transform: translateY(0) scale(0.98);
}

.btn.primary {
  background: linear-gradient(135deg, #9c27b0, var(--primary));
  color: #fff;
}

.btn.primary:hover {
  background: linear-gradient(135deg, #ab47bc, #6a1b9a);
}

.btn.secondary {
  background: linear-gradient(135deg, #ffffff, var(--secondary));
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.secondary:hover {
  background: linear-gradient(135deg, #ffffff, var(--secondary-hover));
}

.btn.danger {
  background: linear-gradient(135deg, #ef5350, var(--danger));
  color: #fff;
}

.btn.danger:hover {
  background: linear-gradient(135deg, #e57373, #a31818);
}

.btn.small {
  padding: 10px 14px;
  font-size: 0.85rem;
  border-radius: 10px;
}

.btn.full {
  width: 100%;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.hidden {
  display: none !important;
}

#room-panel {
  margin-top: 26px;
  padding-top: 26px;
  border-top: 2px dashed var(--border);
  animation: fadeIn 0.4s ease;
}

#room-panel h2 {
  margin: 0 0 6px;
  font-size: 1.4rem;
}

.invite-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 14px;
}

.invite-link {
  display: flex;
  gap: 8px;
  margin-bottom: 22px;
}

.invite-link input {
  flex: 1;
  font-size: 0.9rem;
  background: #fff;
}

#player-list,
#game-player-list {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
}

#player-list li,
#game-player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  transition: transform 0.15s;
}

#player-list li:hover,
#game-player-list li:hover {
  transform: translateX(4px);
}

.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.5);
}

.color-dot.red { background: var(--red); }
.color-dot.green { background: var(--green); }
.color-dot.yellow { background: var(--yellow); }
.color-dot.blue { background: var(--blue); }

.host-badge {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
}

.lobby-controls {
  text-align: center;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Game Layout */
.game-layout {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 18px;
  padding: 18px;
  min-height: 100vh;
}

.sidebar,
.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: linear-gradient(145deg, #ffffff, #fffdf5);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(123, 31, 162, 0.08);
}

.card h2,
.card h3 {
  margin: 0 0 14px;
}

.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

#board {
  max-width: 100%;
  max-height: calc(100vh - 120px);
  border-radius: 18px;
  box-shadow: var(--shadow-hover);
}

.board-hint {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

#turn-indicator {
  font-size: 1.25rem;
  text-align: center;
  font-weight: 700;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.06);
}

.dice-box {
  width: 84px;
  height: 84px;
  margin: 0 auto 18px;
  background: linear-gradient(145deg, #ffffff, #f5f5f5);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  font-weight: 800;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12), inset 0 -4px 8px rgba(0, 0, 0, 0.06);
  border: 2px solid #e0e0e0;
}

.message {
  text-align: center;
  color: var(--muted);
  min-height: 44px;
  font-weight: 500;
}

.sound-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

/* Chat */
.chat-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  min-height: 200px;
  max-height: calc(100vh - 320px);
  background: #fff;
}

.emoji-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.emoji-btn {
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1.1rem;
  padding: 6px 10px;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s;
}

.emoji-btn:hover {
  transform: scale(1.15);
  background: var(--secondary);
}

.emoji-btn:active {
  transform: scale(0.95);
}

.chat-message {
  margin-bottom: 10px;
  font-size: 0.9rem;
  word-break: break-word;
  padding: 6px 10px;
  border-radius: 10px;
  background: #f5f5f5;
}

.chat-message strong {
  color: var(--primary);
}

.chat-message.emoji-message {
  background: #fff8e1;
  text-align: center;
}

.chat-message .emoji-text {
  font-size: 1.6rem;
  display: inline-block;
  animation: emojiPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes emojiPop {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form input {
  flex: 1;
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  animation: fadeIn 0.3s ease;
}

.overlay-content {
  background: linear-gradient(145deg, #ffffff, #fff8e1);
  padding: 40px;
  border-radius: 24px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(123, 31, 162, 0.15);
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.overlay-content h2 {
  margin: 0 0 24px;
  font-size: 2rem;
  color: var(--primary);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* Responsive */
@media (max-width: 1100px) {
  .game-layout {
    grid-template-columns: 240px 1fr;
    grid-template-rows: auto 1fr;
  }

  .chat-panel {
    grid-column: 1 / -1;
    flex-direction: row;
  }

  .chat-card {
    width: 100%;
    max-height: 220px;
  }

  .chat-messages {
    max-height: 120px;
  }
}

@media (max-width: 680px) {
  .game-layout {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }

  .sidebar {
    order: 2;
  }

  .board-area {
    order: 1;
  }

  .chat-panel {
    order: 3;
    flex-direction: column;
  }

  #board {
    width: 100%;
    height: auto;
  }

  .lobby-card {
    padding: 24px;
  }

  .lobby-card h1 {
    font-size: 1.9rem;
  }
}
