*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1520;
  color: #ede6f0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; }

#app, .screen { width: 100vw; height: 100vh; height: 100dvh; }
.screen { display: flex; }
.screen.hidden { display: none; }

/* ---------- LOADING ---------- */
#loading {
  align-items: center; justify-content: center;
  background: #1a1520;
}
.loading-card {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  animation: fadeIn 0.5s ease;
}
.loading-title {
  font-size: 52px; margin: 0; font-weight: 900;
  background: linear-gradient(135deg, #f2a6b5, #f7c97e, #a8d8a8, #8ec5e8, #c4a7e7);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  background-size: 200% 200%;
  animation: titleShimmer 4s ease-in-out infinite;
}
.loading-dots {
  display: flex; gap: 10px;
}
.loading-dots span {
  width: 12px; height: 12px; border-radius: 50%;
  background: #c4a7e7;
  animation: dotBounce 1.2s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.15s; background: #8ec5e8; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; background: #f2a6b5; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.2); opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- ROOM ENTRY ---------- */
#room-entry {
  align-items: center; justify-content: center;
  flex-direction: column;
}
.room-entry-card {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  max-width: 420px; width: 90%;
  animation: fadeIn 0.5s ease;
}
.room-entry-form {
  width: 100%;
  display: flex; flex-direction: column; gap: 12px;
}
.room-entry-input {
  font-size: 28px; padding: 16px 18px;
  background: #241e2e; border: 2px solid #3a2e48; border-radius: 18px;
  color: #ede6f0; outline: none; text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 6px; text-transform: uppercase;
}
.room-entry-input::placeholder { color: #6a5d75; letter-spacing: 2px; font-size: 18px; }
.room-entry-input:focus { border-color: #c4a7e7; box-shadow: 0 0 0 3px rgba(196,167,231,0.2); }
.room-entry-divider {
  display: flex; align-items: center; gap: 12px;
  color: #6a5d75; font-size: 14px; font-weight: 700;
}
.room-entry-divider::before, .room-entry-divider::after {
  content: ''; flex: 1; height: 1px; background: #3a2e48;
}
.big-secondary {
  width: 100%; padding: 18px 28px; font-size: 18px; border-radius: 20px;
}

/* ---------- ROOM CODE ---------- */
.room-code-block {
  text-align: center; margin-bottom: 18px;
  padding: 16px;
  background: linear-gradient(135deg, rgba(196,167,231,0.10), rgba(142,197,232,0.10));
  border: 2px solid #3a2e48; border-radius: 20px;
}
.room-code-label {
  font-size: 12px; letter-spacing: 2px; text-transform: uppercase;
  color: #9a8da0; font-weight: 800; margin-bottom: 4px;
}
.room-code {
  font-size: 48px; font-weight: 900; letter-spacing: 10px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  color: #ede6f0;
  background: linear-gradient(135deg, #c4a7e7, #8ec5e8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- LOBBY ---------- */
#lobby {
  padding: 32px 48px;
  padding-bottom: max(32px, env(safe-area-inset-bottom, 32px));
  flex-direction: column;
}
.lobby-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 48px;
  flex: 1;
  min-height: 0;
}
.lobby-left h1 {
  font-size: 56px; margin: 0 0 8px; font-weight: 900;
  background: linear-gradient(135deg, #f2a6b5, #f7c97e, #a8d8a8, #8ec5e8, #c4a7e7);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: titleShimmer 6s ease-in-out infinite;
  background-size: 200% 200%;
}
@keyframes titleShimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.subtitle { font-size: 18px; color: #9a8da0; margin: 0 0 24px; }
.add-player { display: flex; gap: 12px; margin-bottom: 18px; }
.add-player input {
  flex: 1; padding: 14px 16px; font-size: 18px;
  background: #241e2e; border: 2px solid #3a2e48; border-radius: 16px;
  color: #ede6f0; outline: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.add-player input:focus { border-color: #c4a7e7; box-shadow: 0 0 0 3px rgba(196,167,231,0.2); }
.add-player button {
  padding: 14px 22px; font-size: 16px; font-weight: 700;
  background: #241e2e; color: #ede6f0; border: 2px solid #3a2e48; border-radius: 16px;
}
.lobby-players { list-style: none; padding: 0; margin: 0 0 24px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.lobby-players li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: #241e2e; border-radius: 16px;
  font-size: 18px; font-weight: 600;
  border-left: 5px solid var(--player-color, #3a2e48);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: transform 0.2s, box-shadow 0.2s;
  overflow: hidden;
}
.lobby-players li:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.25); }
.lobby-players .name { flex: 1; }
.lobby-players .conn-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #4a3e58;
  transition: background 0.3s, box-shadow 0.3s;
}
.lobby-players .conn-dot.on { background: #7ec88b; box-shadow: 0 0 8px rgba(126,200,139,0.5); }
.lobby-players .remove {
  background: transparent; color: #a07080; border: 0; font-size: 18px;
  transition: color 0.2s;
}
.lobby-players .remove:hover { color: #e08090; }

.grid-size-selector { margin-bottom: 16px; }
.grid-size-selector label { display: block; margin-bottom: 8px; }
.grid-size-options { display: flex; gap: 8px; }
.grid-size-btn {
  flex: 1; padding: 10px 14px; font-size: 14px; font-weight: 700;
  background: #241e2e; color: #9a8da0; border: 2px solid #3a2e48; border-radius: 14px;
  cursor: pointer; transition: all 0.2s;
}
.grid-size-btn.active { border-color: #c4a7e7; color: #d4c0f0; background: #2e2440; }
.grid-size-btn:hover:not(.active) { border-color: #4a3e58; background: #2a2236; }

.primary {
  background: linear-gradient(135deg, #c4a7e7, #8ec5e8); color: #1a1520;
  font-weight: 800; border: 0; border-radius: 18px; padding: 14px 22px;
  font-size: 16px; transition: all 0.2s;
  box-shadow: 0 4px 14px rgba(196,167,231,0.3);
}
.primary:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }
.primary:not(:disabled):hover { transform: translateY(-3px) scale(1.02); box-shadow: 0 6px 20px rgba(196,167,231,0.45); }
.primary:not(:disabled):active { transform: translateY(0) scale(0.98); }
.primary.big { padding: 18px 28px; font-size: 20px; border-radius: 20px; }
#start-btn { margin-top: 12px; }
.secondary {
  background: transparent; color: #9a8da0; border: 2px solid #3a2e48;
  border-radius: 14px; padding: 10px 16px; font-size: 13px; font-weight: 600;
  transition: all 0.2s;
}
.secondary:hover { border-color: #a07080; color: #d4a0b0; }
.hint { color: #9a8da0; font-size: 14px; }

.lobby-right h2 { margin: 0 0 6px; font-weight: 800; }
.lobby-right h3 { margin: 18px 0 8px; font-size: 16px; color: #9a8da0; font-weight: 700; }
#qr-wrap {
  background: #fff; border-radius: 20px; padding: 14px;
  width: 320px; margin: 12px 0; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
#qr-wrap img { width: 100%; height: auto; image-rendering: pixelated; }
.qr-url {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 18px; color: #8ec5e8; margin: 4px 0 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.copy-btn {
  background: none; border: 1px solid #3a2e48; border-radius: 8px;
  padding: 4px 8px; font-size: 16px; cursor: pointer;
  transition: all 0.15s;
}
.copy-btn:hover { border-color: #c4a7e7; background: #241e2e; }
.copy-btn:active { transform: scale(0.94); }
#connected-players { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
#connected-players li {
  background: #241e2e; border-radius: 999px; padding: 6px 14px;
  display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

/* ---------- GAME ---------- */
#game {
  flex-direction: row; padding: 16px; gap: 16px; background: #16121e;
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
}
.board-area { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; overflow: hidden; }
.board-view-host { width: 100%; height: 100%; position: relative; }
/* Bigger labels on the spectator board */
.board-area .bv-layout { grid-template-columns: 28px 1fr; grid-template-rows: 22px 1fr; }
.board-area .bv-col-labels, .board-area .bv-row-labels { font-size: 12px; }
.board-area .bv-cell { border-radius: 5px; }

/* ---------- SIDEBAR ---------- */
.sidebar {
  width: 320px;
  display: flex; flex-direction: column; gap: 14px;
  background: #1e1828; border-radius: 20px;
  padding: 18px; overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  border: 1px solid #2e2640;
}
.round-header { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #9a8da0; font-weight: 600; }
.round-header .round-label { flex: 1; }
.icon-btn {
  background: #241e2e; color: #c4a7e7; border: 1px solid #3a2e48;
  border-radius: 10px; padding: 4px 8px; font-size: 16px; cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover { background: #2e2440; }
.icon-btn.muted { color: #6a5d75; opacity: 0.75; }

/* ---------- MODAL ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(10, 8, 14, 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.2s ease;
}
.modal.hidden { display: none; }
.modal-card {
  background: #1e1828; border: 1px solid #3a2e48; border-radius: 20px;
  padding: 22px; width: min(420px, 92vw);
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}
.modal-card h3 { margin: 0; font-size: 22px; font-weight: 800; }
.modal-card .hint { margin: 0; }
.modal-card ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.modal-card ul li button {
  width: 100%;
  background: #241e2e; color: #ede6f0;
  border: 2px solid #3a2e48; border-radius: 14px;
  padding: 12px 14px; font-size: 16px; font-weight: 700;
  text-align: left; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  border-left-width: 5px;
  transition: all 0.15s;
}
.modal-card ul li button:hover { background: #2a2236; }
.modal-card ul li button[disabled] { opacity: 0.4; cursor: not-allowed; }
.modal-card ul li .badge-active { font-size: 11px; color: #c4a7e7; text-transform: uppercase; letter-spacing: 1px; margin-left: auto; font-weight: 800; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .primary { flex: 1; padding: 14px; font-size: 16px; border-radius: 14px; }
.modal-actions .secondary { flex: 0 0 auto; }
.active-card {
  background: linear-gradient(135deg, #2e2440, #1e2838);
  border: 2px solid #3e3458;
  border-radius: 16px;
  padding: 14px;
  animation: softGlow 2s ease-in-out infinite;
}
@keyframes softGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(196,167,231,0); }
  50% { box-shadow: 0 0 16px 4px rgba(196,167,231,0.1); }
}
.active-label { font-size: 12px; color: #9a8da0; text-transform: uppercase; letter-spacing: 1px; font-weight: 700; }
.active-name { font-size: 28px; font-weight: 900; margin-top: 4px; }
.phase-card {
  background: #241e2e; border: 1px solid #3a2e48; border-radius: 14px; padding: 14px;
}
.phase-title { font-size: 18px; font-weight: 800; }
.phase-desc { font-size: 13px; color: #9a8da0; margin-top: 4px; }
.clues { display: flex; flex-direction: column; gap: 6px; }
.clue-row {
  display: flex; align-items: center; gap: 10px;
  background: #241e2e; border-radius: 12px; padding: 10px 12px;
  border: 1px solid #3a2e48;
}
.clue-tag {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, #c4a7e7, #8ec5e8);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; color: #1a1520;
}
.clue-text { font-size: 18px; font-weight: 700; }
.clue-text.skipped { color: #6a5d75; font-style: italic; font-weight: 600; }
.placing-banner {
  background: linear-gradient(135deg, #2e2820, #302828);
  border: 2px solid #5a4838;
  border-radius: 16px;
  padding: 12px;
  animation: placingBounce 1.5s ease-in-out infinite;
}
.placing-banner.hidden { display: none; }
@keyframes placingBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
.placing-label { font-size: 12px; color: #b8a080; text-transform: uppercase; letter-spacing: 1px; font-weight: 700; }
.placing-name { font-size: 22px; font-weight: 900; margin: 4px 0; }
.placing-hint { font-size: 13px; color: #9a8d80; }
.placing-choice { display: flex; gap: 6px; margin-top: 10px; }
.placing-choice.hidden { display: none; }
.choice-btn {
  flex: 1; padding: 8px 10px; font-size: 13px; font-weight: 700;
  background: #241e2e; color: #9a8da0; border: 2px solid #3a2e48; border-radius: 10px;
  transition: all 0.2s;
}
.choice-btn.active { border-color: #8ec5e8; background: #1e2838; color: #a0d0f0; }
.scoreboard h3 { margin: 0 0 8px; font-size: 14px; color: #9a8da0; text-transform: uppercase; letter-spacing: 1px; font-weight: 700; }
#scoreboard { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
#scoreboard li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: #241e2e; border-radius: 12px;
  border-left: 4px solid #3a2e48;
  transition: transform 0.2s;
}
#scoreboard li:hover { transform: translateX(3px); }
#scoreboard li.active { background: linear-gradient(135deg, #2e2440, #1e2838); border-left-color: #c4a7e7; }
#scoreboard .conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4a3e58; flex-shrink: 0;
  transition: all 0.3s;
}
#scoreboard .conn-dot.on { background: #7ec88b; box-shadow: 0 0 6px rgba(126,200,139,0.5); }
#scoreboard .name { flex: 1; font-weight: 700; }
#scoreboard .delta {
  font-size: 12px; color: #7ec88b; font-weight: 800;
  animation: scoreUp 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.5);
}
@keyframes scoreUp {
  0% { transform: translateY(10px) scale(0.5); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
#scoreboard .total { font-weight: 800; font-size: 18px; }
.actions { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.actions button.hidden { display: none; }

/* ---------- END ---------- */
#end {
  flex-direction: column; align-items: center; justify-content: center;
  position: relative;
  background: linear-gradient(135deg, #1a1520, #1e1830);
}
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.end-card {
  background: #1e1828; border: 1px solid #2e2640; border-radius: 28px; padding: 40px 56px;
  text-align: center; z-index: 2; max-width: 600px; width: 80%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.end-card h1 { font-size: 56px; margin: 0; font-weight: 900; }
.winner {
  font-size: 42px; font-weight: 900; margin: 16px 0;
  background: linear-gradient(135deg, #f7c97e, #f2a6b5);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.final-scores { list-style: none; padding: 0; margin: 24px 0; }
.final-scores li {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px; background: #241e2e; border-radius: 14px;
  margin: 8px 0; font-size: 20px;
  border-left: 4px solid #3a2e48;
  transition: transform 0.2s;
}
.final-scores li:hover { transform: translateX(4px); }
.final-scores li:first-child {
  background: linear-gradient(135deg, #2e2820, #302828);
  border-left-color: #f7c97e;
  animation: winnerShine 2s ease-in-out infinite;
}
@keyframes winnerShine {
  0%, 100% { box-shadow: 0 0 0 0 rgba(247,201,126,0); }
  50% { box-shadow: 0 0 20px 4px rgba(247,201,126,0.15); }
}
.final-scores .rank { font-weight: 900; color: #9a8da0; width: 32px; }
.final-scores .name { flex: 1; font-weight: 800; }
.final-scores .score { font-size: 24px; font-weight: 900; color: #f7c97e; }

/* ---------- TOASTS ---------- */
.toasts {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 100;
}
.toast {
  padding: 12px 20px; border-radius: 14px;
  background: #241e2e; border: 1px solid #3a2e48;
  font-size: 14px; font-weight: 700; opacity: 0; transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  color: #ede6f0;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1024px) {
  #lobby { padding: 24px; overflow-y: auto; }
  .lobby-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    flex: 0 0 auto;
  }
  .lobby-left h1 { font-size: 40px; }
  .lobby-left { display: flex; flex-direction: column; gap: 8px; }
  .subtitle { margin: 0; }
  .lobby-players { margin: 0; }
  .grid-size-selector { margin-bottom: 0; }
  .lobby-right { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
  .lobby-right h2 { margin: 0; }
  .lobby-right h3 { margin: 8px 0 0; }
  #qr-wrap { width: 280px; padding: 14px; margin: 8px 0; }
  .qr-url { margin: 0; font-size: 15px; }
  .connected-list h3 { margin: 8px 0 4px; }

  #game { flex-direction: column; overflow: auto; }
  .board-area { flex: 1 1 0; width: 100%; min-height: 50vh; }
  .sidebar {
    width: 100%; flex: 0 0 auto;
    flex-direction: column; gap: 10px;
    padding: 14px;
  }
  .round-header { flex-wrap: wrap; }
  .scoreboard { width: 100%; }
  #scoreboard { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  #scoreboard li { flex: 1 1 auto; min-width: 120px; }
}

@media (max-width: 600px) {
  #lobby { padding: 16px; }
  .lobby-players { grid-template-columns: 1fr; }
  .lobby-left h1 { font-size: 32px; }
  .board-area { min-height: 40vh; }
  .sidebar { flex-direction: column; }
  #scoreboard { flex-direction: column; }
}
