* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --bg3: #0f3460;
  --accent: #e94560;
  --accent2: #533483;
  --text: #eee;
  --text-dim: #999;
  --green: #4caf50;
  --yellow: #ffc107;
  --radius: 10px;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.screen { display: flex; align-items: center; justify-content: center; height: 100vh; }
.hidden { display: none !important; }

.btn {
  padding: 12px 28px; border: none; border-radius: var(--radius);
  font-size: 16px; font-weight: 600; cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}
.btn:hover { transform: scale(1.03); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-small { padding: 8px 14px; font-size: 14px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; }

/* ========= JOIN ========= */
#join-screen, #lobby-screen { position: relative; overflow: hidden; }
#bg-canvas, .bg-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}
.join-container {
  text-align: center; position: relative; z-index: 1;
  background: rgba(26, 26, 46, 0.85);
  padding: 48px 44px; border-radius: 24px;
  border: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: floatIn 0.7s ease-out;
}
@keyframes floatIn {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.logo {
  font-size: 56px; margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent), var(--yellow), var(--green), #2196f3, var(--accent2));
  background-size: 200% 200%;
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  animation: gradientShift 4s ease infinite;
}
@keyframes gradientShift { 0%,100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.subtitle { color: var(--text-dim); margin-bottom: 24px; font-size: 18px; }
.join-waiting { margin-bottom: 20px; animation: fadeInUp 0.4s ease; }
.join-waiting-text { color: var(--green); font-size: 14px; margin-bottom: 10px; }
.join-waiting-players { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.join-waiting-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg3); padding: 6px 12px; border-radius: 20px;
  font-size: 13px; border: 1px solid rgba(255,255,255,0.1); animation: fadeInUp 0.3s ease;
}
.join-waiting-chip svg { flex-shrink: 0; }
.join-waiting-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: blink 1.4s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } }
.join-form { display: flex; flex-direction: column; gap: 14px; width: 300px; margin: 0 auto; }
.join-form input {
  padding: 14px 18px; border: 2px solid #333; border-radius: var(--radius);
  background: var(--bg2); color: var(--text); font-size: 17px; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.join-form input:focus { border-color: var(--accent); box-shadow: 0 0 16px rgba(233,69,96,0.3); }
.join-form .btn-primary {
  font-size: 18px; padding: 14px 28px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 4px 20px rgba(233,69,96,0.4);
}
.join-form .btn-primary:hover { transform: scale(1.05); box-shadow: 0 6px 28px rgba(233,69,96,0.5); }

/* ========= ONLINE BADGE ========= */
.total-players-badge {
  position: absolute; top: -12px; right: -18px;
  background: var(--green); color: #fff;
  font-size: 12px; font-weight: 800;
  padding: 4px 10px; border-radius: 20px;
  box-shadow: 0 2px 10px rgba(76,175,80,0.5);
  animation: onlinePulse 2s ease-in-out infinite;
  pointer-events: none; z-index: 2;
  white-space: nowrap;
}
.total-players-badge:empty { display: none; }
@keyframes onlinePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ========= ROOM BROWSER (bottom of join screen) ========= */
.room-browser-bottom {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 1; width: 90%; max-width: 560px;
}
.room-list-bottom {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}
.room-item {
  display: flex; align-items: center; gap: 10px;
  background: rgba(26,26,46,0.85); padding: 10px 16px; border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.1); cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  backdrop-filter: blur(12px);
}
.room-item:hover { border-color: var(--accent); background: rgba(15,52,96,0.9); transform: scale(1.04); }
.room-item-name { font-size: 14px; font-weight: 600; }
.room-item-badge {
  font-size: 10px; padding: 2px 6px; border-radius: 6px;
  background: var(--green); color: #fff; font-weight: 700; text-transform: uppercase; flex-shrink: 0;
}
.room-item-badge.in-game { background: var(--accent); }
.room-item-count { font-size: 13px; color: var(--text-dim); flex-shrink: 0; }

/* Toggle public button */
.btn-toggle-public {
  margin-top: 10px; padding: 12px 28px; font-size: 16px;
  background: var(--bg3); color: var(--text); border: none;
  border-radius: var(--radius); cursor: pointer; font-weight: 600;
  transition: background 0.2s, transform 0.1s;
}
.btn-toggle-public:hover { background: var(--accent2); transform: scale(1.03); }
.btn-toggle-public:active { transform: scale(0.97); }
.btn-toggle-public.is-public { background: var(--green); color: #fff; }

/* ========= LOBBY ========= */
.lobby-container {
  text-align: center; position: relative; z-index: 1;
  background: rgba(26,26,46,0.85);
  padding: 40px 44px; border-radius: 24px;
  border: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(16px); box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: floatIn 0.7s ease-out;
}
.lobby-container h2 { margin-bottom: 24px; }
.lobby-players { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-bottom: 20px; }
.lobby-player {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--bg2); padding: 16px 20px; border-radius: var(--radius);
}
.lobby-player .avatar { width: 48px; height: 48px; border-radius: 50%; }
.lobby-player.host { border: 2px solid var(--yellow); }
.lobby-player-status { font-size: 11px; color: var(--green); opacity: 0.8; }
.lobby-waiting { color: var(--text-dim); margin-bottom: 16px; font-size: 15px; }
.lobby-info { color: var(--text-dim); margin-bottom: 16px; }
.lobby-share { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.lobby-link-text { color: var(--yellow); font-size: 13px; word-break: break-all; background: var(--bg); padding: 8px 14px; border-radius: var(--radius); }
.btn-copy { background: var(--bg3); border: 1px solid var(--yellow); color: var(--yellow); }
.btn-copy:hover { background: var(--yellow); color: var(--bg); }

/* ========= GAME LAYOUT ========= */
.game-layout {
  display: flex; flex-direction: column;
  height: 100vh; width: 100vw;
}

/* --- Player strip (top) --- */
.players-strip {
  display: flex; gap: 10px;
  padding: 10px 16px;
  background: var(--bg2);
  justify-content: center;
  flex-wrap: wrap;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.player-card {
  background: var(--bg3);
  border-radius: 14px;
  padding: 0;
  display: flex; flex-direction: column; align-items: center;
  position: relative;
  border: 3px solid transparent;
  transition: border-color 0.2s;
  width: 110px;
  flex-shrink: 0;
  overflow: hidden;
}
.player-card.drawing { border-color: var(--yellow); }
.player-card.disconnected { opacity: 0.35; }
.player-card.guessed { border-color: var(--green); }

/* Avatar / Video area — large, fills the card top */
.avatar-area {
  width: 110px; height: 82px;
  position: relative;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.avatar-area .avatar-small {
  display: flex; align-items: center; justify-content: center;
}
.avatar-video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

/* Player info bar under avatar */
.player-card .player-info {
  width: 100%;
  padding: 4px 6px 6px;
  text-align: center;
  background: var(--bg3);
}
.player-card .player-name {
  font-size: 11px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-card .player-score {
  font-size: 11px; color: var(--yellow); font-weight: 700;
}
.player-card .drawing-icon {
  position: absolute; top: 4px; right: 6px; font-size: 16px;
  background: rgba(0,0,0,0.5); border-radius: 50%;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
}

/* Media buttons — overlaid on avatar area */
.media-btns {
  position: absolute; bottom: 4px; right: 4px;
  display: flex; gap: 3px; z-index: 2;
}
.media-btn {
  width: 28px; height: 28px;
  border: none; border-radius: 8px;
  background: rgba(0,0,0,0.55);
  color: var(--text-dim);
  font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
  padding: 0; line-height: 1;
  backdrop-filter: blur(4px);
}
.media-btn:hover { background: rgba(0,0,0,0.7); color: #fff; }
.media-btn.active { background: var(--green); color: #fff; }

/* --- Main area: canvas + chat --- */
.game-main {
  flex: 1; display: flex; min-height: 0;
}
.center {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.canvas-container {
  flex: 1; background: #fff;
  position: relative; overflow: hidden;
}
.canvas-container canvas { display: block; }

/* --- Bottom bar: palette+tools (left) | word (center) | timer (right) --- */
.game-bottom-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px;
  background: var(--bg2);
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.bottom-tools-area {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  flex-shrink: 0;
}
.bottom-word-area {
  flex: 1;
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  min-width: 0;
}
.word-display {
  font-size: 22px; letter-spacing: 3px; font-family: monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.timer-display {
  font-size: 20px; font-weight: 700; color: var(--yellow);
  width: 48px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg3); border-radius: 8px;
  flex-shrink: 0;
}
.timer-display.warning { color: var(--accent); animation: pulse 0.5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.15); } }
.color-palette {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 3px;
}
.color-swatch {
  width: 24px; height: 24px; border-radius: 5px;
  border: 2px solid transparent;
  cursor: pointer; transition: transform 0.1s, border-color 0.1s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.color-swatch.active { border-color: #fff; transform: scale(1.25); box-shadow: 0 0 8px rgba(255,255,255,0.3); }
.color-swatch:hover { transform: scale(1.15); }

.draw-tools {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.brush-sizes { display: flex; gap: 4px; }
.brush-size {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid #555;
  background: var(--bg3); color: var(--text); cursor: pointer;
  font-size: 10px; font-weight: 700;
}
.brush-size.active { border-color: var(--accent); background: var(--accent); }
.brush-size:hover { border-color: var(--accent); }
.tool-btn {
  padding: 5px 12px; border: 2px solid #555; border-radius: var(--radius);
  background: var(--bg3); color: var(--text); cursor: pointer;
  font-size: 12px; font-weight: 600;
}
.tool-btn:hover { border-color: var(--accent); }
.tool-btn.active { border-color: var(--accent); background: var(--accent); }

/* ========= CHAT ========= */
.chat-panel {
  width: 260px; background: var(--bg2);
  display: flex; flex-direction: column;
  border-left: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.chat-msg { font-size: 13px; line-height: 1.4; }
.chat-msg .name { font-weight: 700; }
.chat-msg.correct { color: var(--green); font-weight: 600; }
.chat-msg.system { color: var(--text-dim); font-style: italic; }
.chat-input-row {
  display: flex; gap: 6px; padding: 8px 10px;
  border-top: 1px solid #333;
}
.chat-input-row input {
  flex: 1; padding: 8px 12px; border: none; border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: 14px; outline: none;
}

/* ========= OVERLAYS ========= */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.overlay-content {
  background: var(--bg2); padding: 32px 40px; border-radius: 16px;
  text-align: center; max-width: 420px;
}
.word-choices { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; justify-content: center; }
.word-choice-btn {
  padding: 14px 24px; background: var(--bg3);
  border: 2px solid var(--accent); border-radius: var(--radius);
  color: var(--text); font-size: 18px; cursor: pointer;
}
.word-choice-btn:hover { background: var(--accent); }
#final-scores { margin: 16px 0; }
.score-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 16px; }
.score-row .score-val { color: var(--yellow); font-weight: 700; }

/* ========= TOAST ========= */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg3); padding: 10px 18px; border-radius: var(--radius);
  font-size: 14px; animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.5s forwards;
  border-left: 4px solid var(--accent);
}
.toast.success { border-left-color: var(--green); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(50%); } }

/* Wrong guess */
.wrong-guess-pop {
  position: fixed; z-index: 300;
  font-size: 22px; font-weight: 800;
  color: var(--accent);
  text-shadow: 0 0 8px rgba(233,69,96,0.6), 0 2px 4px rgba(0,0,0,0.5);
  pointer-events: none; transform: translate(-50%, 0);
  animation: wrongPop 0.85s ease-out forwards;
}
@keyframes wrongPop {
  0% { opacity: 1; transform: translate(-50%, 0) scale(0.5) rotate(-5deg); }
  20% { opacity: 1; transform: translate(-50%, -10px) scale(1.3) rotate(3deg); }
  100% { opacity: 0; transform: translate(-50%, -70px) scale(0.8) rotate(-2deg); }
}

/* ========= RESPONSIVE ========= */
@media (max-width: 768px) {
  .game-main { flex-direction: column; }
  .chat-panel { width: 100%; max-height: 130px; border-left: none; border-top: 1px solid rgba(255,255,255,0.06); }
  .players-strip { gap: 6px; padding: 6px 8px; }
  .player-card { width: 80px; }
  .avatar-area { width: 80px; height: 60px; }
  .game-bottom-bar { padding: 6px 8px; gap: 8px; }
  .color-swatch { width: 20px; height: 20px; }
}
