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

:root {
  --bg:      #f0f4ff;
  --bg2:     #e6eeff;
  --card:    #ffffff;
  --card2:   #f7f9ff;
  --border:  #d4deff;
  --red:     #e8197d;  /* bright pink-red (matches Wavelength accent) */
  --orange:  #f97316;
  --purple:  #7c3aed;
  --blue:    #2563eb;
  --cyan:    #0891b2;
  --green:   #059669;
  --yellow:  #d97706;
  --text:    #1e1b4b;
  --muted:   #6b7280;
  --shadow:  0 4px 24px rgba(37,99,235,0.10);
  --shadow2: 0 8px 40px rgba(124,58,237,0.15);
  --glow-r:  0 0 20px rgba(232,25,125,0.35);
}

@keyframes float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}
@keyframes bounce-in {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.12); }
  80%  { transform: scale(0.96); }
  100% { transform: scale(1);   opacity: 1; }
}
@keyframes slide-up {
  from { transform: translateY(28px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}
@keyframes pulse-btn {
  0%,100% { box-shadow: 0 6px 24px rgba(232,25,125,0.35); }
  50%      { box-shadow: 0 10px 40px rgba(232,25,125,0.6); }
}
@keyframes confetti-fall {
  0%   { transform: translateY(-10px) rotate(0deg);   opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
@keyframes pop-in {
  0%   { transform: scale(0.7); opacity: 0; }
  70%  { transform: scale(1.1); }
  100% { transform: scale(1);   opacity: 1; }
}

/* ── Body ────────────────────────────────────────────────────────────────── */
body {
  font-family: 'Heebo', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    radial-gradient(ellipse 70% 50% at 10% 10%, rgba(124,58,237,0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 90% 90%, rgba(37,99,235,0.08) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 50% 0%,  rgba(232,25,125,0.05) 0%, transparent 55%);
}

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
  padding: 24px 16px 40px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.screen.active { display: flex; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.setup-card, .game-card, .end-card {
  position: relative;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 28px;
  padding: 32px 28px;
  max-width: 600px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow2);
  animation: slide-up 0.45s cubic-bezier(0.34,1.56,0.64,1) both;
  overflow: hidden;
}
.setup-card::before, .game-card::before, .end-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--red), var(--purple), var(--blue), var(--cyan));
  border-radius: 28px 28px 0 0;
}

/* ── Logo ────────────────────────────────────────────────────────────────── */
.logo-wrap { text-align: center; }
.logo-emoji {
  font-size: 3.8rem;
  display: block;
  animation: float 3s ease-in-out infinite;
  line-height: 1.2;
}
.logo-img {
  width: 110px;
  height: 110px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 6px 18px rgba(124,58,237,0.25));
}
.logo-wrap h1 {
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: -2px;
  background: linear-gradient(135deg, var(--red) 0%, var(--purple) 50%, var(--blue) 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 4s linear infinite;
}
.tagline { color: var(--muted); font-size: 0.92rem; margin-top: 6px; font-weight: 600; }

/* ── Avatar ──────────────────────────────────────────────────────────────── */
.avatar-section { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.avatar-preview {
  width: 88px; height: 88px; border-radius: 50%;
  border: 3px solid var(--border); background: var(--card2);
  cursor: pointer; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.avatar-preview:hover { border-color: var(--red); box-shadow: var(--glow-r); }
.avatar-placeholder { font-size: 2.2rem; }
.avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 800; color: #fff;
  opacity: 0; transition: opacity 0.2s; border-radius: 50%;
}
.avatar-preview:hover .avatar-overlay { opacity: 1; }

/* ── Player avatar (in grids / rows) ─────────────────────────────────────── */
.player-avatar {
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: #fff;
  background: #334155;
}
.player-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-group { width: 100%; display: flex; flex-direction: column; gap: 7px; }
.form-group label {
  font-size: 0.76rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700;
}
.form-group input {
  width: 100%; padding: 13px 16px;
  background: var(--card2); border: 1.5px solid var(--border);
  border-radius: 12px; color: var(--text);
  font-family: inherit; font-size: 1rem; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus {
  border-color: var(--red); box-shadow: 0 0 0 3px rgba(232,25,125,0.15);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-start {
  width: 100%; padding: 17px;
  background: linear-gradient(135deg, var(--red), var(--purple));
  color: #fff; border: none; border-radius: 16px;
  font-size: 1.15rem; font-weight: 900; cursor: pointer;
  font-family: inherit; letter-spacing: 0.02em;
  animation: pulse-btn 2.5s ease-in-out infinite;
  transition: transform 0.15s;
  box-shadow: 0 6px 24px rgba(232,25,125,0.4);
}
.btn-start:hover  { transform: scale(1.03); }
.btn-start:active { transform: scale(0.98); }

.btn-primary {
  padding: 13px 24px;
  background: linear-gradient(135deg, var(--red), var(--purple));
  color: #fff; border: none; border-radius: 14px;
  font-size: 1rem; font-weight: 800; cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 18px rgba(232,25,125,0.3);
  transition: transform 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn-primary:hover  { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(232,25,125,0.5); }
.btn-primary:active { transform: scale(0.97); }

.btn-outline {
  width: 100%; padding: 14px;
  background: transparent; border: 1.5px solid var(--border);
  color: var(--text); border-radius: 14px;
  font-size: 1rem; font-weight: 800; cursor: pointer;
  font-family: inherit;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.btn-outline:hover { background: var(--card2); border-color: var(--red); transform: scale(1.02); }

.btn-sm { width: auto !important; padding: 9px 20px !important; font-size: 0.88rem !important; }

.btn-back {
  align-self: flex-start; background: none; border: none;
  color: var(--muted); font-size: 0.95rem; font-weight: 700;
  cursor: pointer; font-family: inherit; padding: 0;
  transition: color 0.2s;
}
.btn-back:hover { color: var(--text); }

.btn-copy {
  background: var(--card2); border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 1.2rem; cursor: pointer; padding: 6px 10px;
  transition: transform 0.15s, background 0.15s;
}
.btn-copy:hover { transform: scale(1.15); background: var(--border); }

.btn-refresh {
  background: var(--card2); border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 1.1rem; cursor: pointer; padding: 6px 10px;
  transition: transform 0.2s;
}
.btn-refresh:hover { transform: rotate(90deg); }

.btn-kick {
  background: rgba(220,38,38,0.15); border: 1.5px solid rgba(220,38,38,0.3);
  color: var(--red); border-radius: 6px; padding: 2px 8px;
  font-size: 0.75rem; font-weight: 900; cursor: pointer;
  margin-left: 6px; transition: background 0.15s;
  font-family: inherit; line-height: 1.4;
}
.btn-kick:hover { background: rgba(220,38,38,0.3); }

/* ── Lang / Visibility pickers ───────────────────────────────────────────── */
.visibility-toggle, .lang-picker { display: flex; gap: 8px; width: 100%; }
.vis-btn, .lang-btn {
  flex: 1; padding: 11px; background: var(--card2);
  border: 1.5px solid var(--border); border-radius: 12px;
  font-size: 0.9rem; font-weight: 800; cursor: pointer; font-family: inherit;
  color: var(--muted); transition: all 0.2s;
}
.vis-btn:hover, .lang-btn:hover { border-color: var(--red); color: var(--text); }
.vis-btn.active, .lang-btn.active { border-color: var(--red); background: rgba(232,25,125,0.12); color: var(--text); }

/* ── Room Code Banner ────────────────────────────────────────────────────── */
.room-code-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: linear-gradient(135deg, rgba(232,25,125,0.08), rgba(124,58,237,0.08));
  border: 1.5px solid var(--border); border-radius: 18px;
  padding: 14px 20px; width: 100%;
}
.rc-label { color: var(--muted); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; }
.rc-code {
  font-size: 2.2rem; font-weight: 900; letter-spacing: 10px;
  background: linear-gradient(135deg, var(--red), var(--purple), var(--blue));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  flex: 1; text-align: center;
}
.rc-vis { font-size: 0.78rem; font-weight: 800; padding: 4px 12px; border-radius: 20px; white-space: nowrap; }
.vis-public  { background: rgba(5,150,105,0.14);  color: var(--green);  border: 1.5px solid rgba(5,150,105,0.35); }
.vis-private { background: rgba(217,119,6,0.14);  color: var(--yellow);  border: 1.5px solid rgba(217,119,6,0.35); }

/* ── Lobby ───────────────────────────────────────────────────────────────── */
.lobby-info-row { display: flex; gap: 8px; width: 100%; flex-wrap: wrap; }
.lobby-info-chip {
  background: var(--card2); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 5px 14px;
  font-size: 0.82rem; font-weight: 700; color: var(--muted);
}
.lobby-section-title {
  font-size: 0.9rem; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em; align-self: flex-start;
}
#lobby-players-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.lobby-player-row {
  background: var(--card2); border: 1.5px solid var(--border);
  border-radius: 14px; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  font-size: 0.95rem; font-weight: 700; transition: border-color 0.2s;
}
.lobby-player-row.is-me { border-color: var(--red); }
.lobby-player-name { flex: 1; }

/* ── Game header ─────────────────────────────────────────────────────────── */
.game-header { display: flex; gap: 8px; align-items: center; width: 100%; justify-content: center; }
.round-chip {
  background: linear-gradient(135deg, var(--red), var(--purple));
  color: #fff; border-radius: 30px; padding: 7px 20px;
  font-size: 0.82rem; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase;
  box-shadow: 0 4px 16px rgba(232,25,125,0.4);
  animation: bounce-in 0.5s cubic-bezier(0.34,1.56,0.64,1) both;
}
.phase-chip {
  border-radius: 30px; padding: 7px 20px;
  font-size: 0.82rem; font-weight: 900; letter-spacing: 0.04em;
}
.phase-chip.clue { background: rgba(37,99,235,0.14); color: var(--blue); border: 1.5px solid rgba(37,99,235,0.4); }
.phase-chip.vote { background: rgba(232,25,125,0.2); color: var(--red); border: 1.5px solid rgba(232,25,125,0.4); animation: bounce-in 0.4s ease both; }

/* ── Word reveal ─────────────────────────────────────────────────────────── */
.word-reveal {
  background: linear-gradient(135deg, rgba(232,25,125,0.08), rgba(124,58,237,0.08));
  border: 1.5px solid var(--border); border-radius: 20px;
  padding: 20px 24px; width: 100%; text-align: center;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  animation: bounce-in 0.5s cubic-bezier(0.34,1.56,0.64,1) both;
}
.word-role-label { font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.word-display {
  font-size: 2.2rem; font-weight: 900;
  background: linear-gradient(135deg, var(--red), var(--purple));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.word-display.blank { -webkit-text-fill-color: var(--muted); background: none; font-size: 1.3rem; font-style: italic; }
.word-hint { font-size: 0.8rem; color: var(--muted); font-weight: 600; }

/* ── Clue input ──────────────────────────────────────────────────────────── */
.clue-submit-area { width: 100%; }
.clue-row { display: flex; gap: 10px; width: 100%; align-items: center; }
.clue-row input {
  flex: 1; padding: 13px 16px;
  background: var(--card2); border: 1.5px solid var(--border);
  border-radius: 12px; color: var(--text);
  font-family: inherit; font-size: 1rem; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.clue-row input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(232,25,125,0.12); }

/* ── Players grid — like the reference image ─────────────────────────────── */
.players-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
}

.grid-player {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; position: relative;
  padding: 10px 6px;
  border-radius: 18px;
  border: 2px solid transparent;
  background: var(--card2);
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
  animation: pop-in 0.35s ease both;
}
.grid-player[style*="cursor:pointer"]:hover {
  transform: scale(1.06);
  border-color: var(--red);
  box-shadow: 0 0 16px rgba(232,25,125,0.35);
}
.grid-player.grid-me { border-color: var(--purple); background: rgba(124,58,237,0.1); }
.grid-player.grid-selected {
  border-color: var(--red);
  background: rgba(232,25,125,0.15);
  box-shadow: 0 0 20px rgba(232,25,125,0.35);
}
.grid-player.grid-has-votes { border-color: rgba(217,119,6,0.6); }
.grid-player.grid-dead { opacity: 0.45; filter: grayscale(0.6); }

.grid-player .player-avatar {
  width: 72px; height: 72px; font-size: 2rem;
  border: 3px solid rgba(37,99,235,0.12);
  box-shadow: 0 4px 14px rgba(37,99,235,0.15);
}

.grid-name {
  font-size: 0.8rem; font-weight: 800; color: var(--text);
  text-align: center; max-width: 90px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Clue tag shown above name, like the speech bubble in the screenshot */
.grid-clue-tag {
  background: var(--blue);
  color: #fff; font-size: 0.78rem; font-weight: 800;
  border-radius: 10px; padding: 3px 10px;
  text-align: center; max-width: 100px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: pop-in 0.3s ease both;
}
.grid-clue-tag.pending { background: var(--border); color: var(--muted); font-weight: 600; font-style: italic; }

.grid-vote-count {
  position: absolute; top: 6px; right: 6px;
  background: var(--red); color: #fff;
  font-size: 0.7rem; font-weight: 900;
  border-radius: 20px; padding: 2px 8px;
  animation: bounce-in 0.3s ease both;
}

.grid-voted-label {
  font-size: 1.1rem;
  position: absolute; top: 6px; left: 6px;
}

.grid-score {
  font-size: 0.78rem; font-weight: 800; color: var(--muted);
}
.grid-alive-badge {
  font-size: 0.68rem; font-weight: 900; padding: 2px 8px;
  border-radius: 10px; position: absolute; bottom: 6px; right: 6px;
}
.badge-alive { background: rgba(34,197,94,0.2); color: var(--green); }
.badge-dead  { background: rgba(220,38,38,0.15); color: var(--red); }

/* ── Result / Elim ───────────────────────────────────────────────────────── */
.elim-display {
  width: 100%; text-align: center;
  background: linear-gradient(135deg, rgba(232,25,125,0.1), rgba(124,58,237,0.1));
  border: 1.5px solid rgba(232,25,125,0.3);
  border-radius: 20px; padding: 20px 24px;
  animation: bounce-in 0.5s cubic-bezier(0.34,1.56,0.64,1) both;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.elim-name { font-size: 1.5rem; font-weight: 900; }
.elim-role { font-size: 1rem; font-weight: 800; }
.elim-role.civilian   { color: var(--green); }
.elim-role.undercover { color: var(--red); }
.elim-role.blank      { color: var(--muted); }
.no-elim { font-size: 1.1rem; font-weight: 800; color: var(--yellow); }

/* ── Words reveal ────────────────────────────────────────────────────────── */
.words-reveal { display: flex; gap: 12px; width: 100%; }
.word-card {
  flex: 1; background: var(--card2); border: 1.5px solid var(--border);
  border-radius: 16px; padding: 14px; text-align: center;
  display: flex; flex-direction: column; gap: 6px;
}
.word-card-label { font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.word-card-value { font-size: 1.3rem; font-weight: 900; }
.word-card.civilian-card  { border-color: var(--green); }
.word-card.civilian-card  .word-card-value { color: var(--green); }
.word-card.undercover-card { border-color: var(--red); }
.word-card.undercover-card .word-card-value { color: var(--red); }

/* ── End screen ──────────────────────────────────────────────────────────── */
.end-card { text-align: center; }
.trophy-big {
  font-size: 5rem; animation: float 2.5s ease-in-out infinite;
  display: block; filter: drop-shadow(0 4px 12px rgba(232,25,125,0.5));
}
.end-card h1 {
  font-size: 2.4rem; font-weight: 900;
  background: linear-gradient(135deg, var(--red), var(--purple), var(--blue));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.winner-text {
  font-size: 1.4rem; font-weight: 900; min-height: 32px;
  background: linear-gradient(135deg, var(--red), var(--orange));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.final-scores { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; width: 100%; }
.final-score-item {
  background: var(--card2); border: 1.5px solid var(--border);
  border-radius: 18px; padding: 16px 20px; min-width: 100px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.final-score-item.winner { border-color: var(--yellow); box-shadow: 0 0 20px rgba(217,119,6,0.25); }
.final-score-item .sname { font-size: 0.82rem; color: var(--muted); font-weight: 700; }
.final-score-item .spts  { font-size: 2.4rem; font-weight: 900; }

/* ── Roles reveal ────────────────────────────────────────────────────────── */
.roles-reveal { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.role-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card2); border: 1.5px solid var(--border);
  border-radius: 12px; padding: 10px 14px;
}
.role-badge {
  font-size: 0.78rem; font-weight: 900; padding: 3px 10px; border-radius: 20px;
}
.role-badge.civilian   { background: rgba(34,197,94,0.15); color: var(--green); border: 1.5px solid rgba(34,197,94,0.3); }
.role-badge.undercover { background: rgba(232,25,125,0.15);  color: var(--red);   border: 1.5px solid rgba(232,25,125,0.3); }
.role-badge.blank      { background: rgba(148,163,184,0.1); color: var(--muted); border: 1.5px solid rgba(148,163,184,0.3); }

/* ── Browser ─────────────────────────────────────────────────────────────── */
.browser-header { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.room-list-empty { color: var(--muted); text-align: center; padding: 20px 0; font-weight: 600; }
#room-list { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.room-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card2); border: 1.5px solid var(--border);
  border-radius: 14px; padding: 12px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.room-row:hover { border-color: var(--red); box-shadow: 0 4px 20px rgba(232,25,125,0.15); }
.room-row-info { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.room-row-host { font-size: 0.95rem; font-weight: 800; }
.room-row-meta { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.room-row-code { font-size: 1rem; font-weight: 900; letter-spacing: 3px; color: var(--red); min-width: 56px; text-align: center; }
.btn-join-room {
  background: linear-gradient(135deg, var(--red), var(--purple));
  color: #fff; border: none; border-radius: 10px;
  padding: 9px 18px; font-size: 0.9rem; font-weight: 800;
  cursor: pointer; font-family: inherit;
  box-shadow: 0 3px 12px rgba(232,25,125,0.3);
  transition: transform 0.15s; white-space: nowrap;
}
.btn-join-room:hover { transform: scale(1.05); }

.browser-divider {
  width: 100%; text-align: center; position: relative;
  color: var(--muted); font-size: 0.85rem; font-weight: 600;
}
.browser-divider::before {
  content: ''; position: absolute; top: 50%; left: 0; right: 0;
  height: 1px; background: var(--border);
}
.browser-divider span { background: var(--card); padding: 0 12px; position: relative; }
.browser-actions { display: flex; gap: 12px; width: 100%; }
.browser-actions .btn-primary,
.browser-actions .btn-outline { flex: 1; text-align: center; padding: 13px 8px; }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.screen-title { font-size: 1.5rem; font-weight: 900; }
.screen-hint { color: var(--muted); font-size: 0.9rem; text-align: center; line-height: 1.6; font-weight: 600; }
.setup-title { font-size: 1.6rem; font-weight: 900; }
.home-btns { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.waiting-msg { color: var(--muted); font-size: 0.9rem; text-align: center; font-weight: 600; }
.error-msg   { color: var(--red); font-size: 0.9rem; text-align: center; min-height: 20px; font-weight: 700; }
.submitted-msg { text-align: center; font-size: 0.9rem; font-weight: 700; color: var(--green); }

/* ── Lang toggle (top-right, like Wavelength) ────────────────────────────── */
#lang-toggle-btn {
  position: fixed; top: 14px; right: 14px; z-index: 9999;
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 6px 14px;
  font-family: inherit; font-size: 0.82rem; font-weight: 800;
  color: var(--text); cursor: pointer;
  box-shadow: 0 2px 10px rgba(37,99,235,0.12);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
#lang-toggle-btn:hover {
  background: var(--card2); border-color: var(--red); transform: scale(1.05);
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 36px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card); border: 1.5px solid var(--border);
  color: var(--text); padding: 13px 28px;
  border-radius: 40px; font-size: 1rem; font-weight: 700;
  box-shadow: 0 8px 32px rgba(124,58,237,0.18);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 9999; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Confetti ────────────────────────────────────────────────────────────── */
.confetti-piece {
  position: fixed; border-radius: 2px;
  animation: confetti-fall linear forwards;
  pointer-events: none; z-index: 9998;
}

/* ── Timer bar ─────────────────────────────────────────────────────────── */
.timer-wrap {
  width: 100%;
  margin: 10px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.timer-text {
  align-self: flex-end;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.timer-bar {
  width: 100%;
  height: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--blue));
  transition: width 0.2s linear, background 0.3s;
  border-radius: 6px;
}
.timer-fill.danger { background: linear-gradient(90deg, var(--orange), var(--red)); }

/* ── Turn indicator ────────────────────────────────────────────────────── */
.turn-indicator {
  padding: 10px 14px;
  margin: 0 0 14px;
  border-radius: 12px;
  background: rgba(37,99,235,0.12);
  border: 1px solid rgba(37,99,235,0.35);
  color: var(--text);
  font-weight: 700;
  text-align: center;
  font-size: 1rem;
}
.turn-indicator.my-turn {
  background: linear-gradient(135deg, rgba(232,25,125,0.14), rgba(249,115,22,0.14));
  border-color: rgba(232,25,125,0.5);
  animation: pulse-btn 1.4s infinite;
}

/* ── Current-turn avatar highlight ─────────────────────────────────────── */
.grid-player.grid-current-turn .player-avatar {
  outline: 3px solid var(--cyan);
  box-shadow: 0 0 18px rgba(6,182,212,0.55);
}

/* ── Lobby settings panel ──────────────────────────────────────────────── */
.lobby-settings {
  margin-top: 16px;
  padding: 14px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  gap: 12px;
}
.settings-row label {
  font-weight: 700;
  color: var(--text);
  font-size: 0.95rem;
}
.settings-stepper {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 10px;
}
.step-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-weight: 900;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.step-btn:hover:not(:disabled) { background: var(--blue); color: #fff; border-color: var(--blue); }
.step-val {
  min-width: 28px;
  text-align: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.toggle-btn {
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-btn.on {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}

/* ── In-game settings (host, floating) ─────────────────────────────────── */
.ingame-settings {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 80;
}
[dir="rtl"] .ingame-settings { left: auto; right: 16px; }
.ingame-settings-panel {
  position: absolute;
  top: 48px;
  left: 0;
  min-width: 260px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow2);
}
[dir="rtl"] .ingame-settings-panel { left: auto; right: 0; }

/* ── Vote reveal rows ──────────────────────────────────────────────────── */
.vote-reveal {
  margin: 14px 0;
  padding: 12px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.vote-reveal-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: center;
}
.vote-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px dashed var(--border);
}
.vote-row:last-child { border-bottom: none; }
.vote-voter { font-weight: 700; flex: 1; }
.vote-arrow { color: var(--muted); font-weight: 900; }
.vote-target { font-weight: 700; }
.vote-target.muted { color: var(--muted); font-style: italic; }

/* ── Voter chips overlaid on target cards ─────────────────────────────── */
.voter-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-top: 6px;
  max-width: 100%;
}
.voter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 2px;
  background: rgba(124,58,237,0.18);
  border: 1px solid rgba(124,58,237,0.5);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  max-width: 100%;
}
.voter-chip .player-avatar {
  width: 22px !important;
  height: 22px !important;
  font-size: 0.7rem !important;
  border-width: 1px !important;
}
.voter-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70px;
}

/* Auto-advance countdown */
.result-countdown {
  margin-top: 10px;
  text-align: center;
  font-weight: 800;
  color: var(--muted);
  font-size: 0.95rem;
}
.result-countdown::before { content: '⏱ '; }

/* ── Avatar remove button ──────────────────────────────────────────────── */
.btn-avatar-remove {
  display: block;
  margin: 10px auto 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-avatar-remove:hover { color: var(--red); border-color: var(--red); }

/* ── Tie overlay ───────────────────────────────────────────────────────── */
.tie-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30,27,75,0.35);
  backdrop-filter: blur(6px);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.tie-overlay.show { opacity: 1; }
.tie-box {
  padding: 30px 44px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--card), var(--card2));
  border: 2px solid var(--orange);
  box-shadow: 0 0 60px rgba(249,115,22,0.4);
  text-align: center;
  animation: pop-in 0.4s ease-out;
}
.tie-title {
  font-size: 2.4rem;
  font-weight: 900;
  margin-bottom: 8px;
}
.tie-sub {
  color: var(--muted);
  font-weight: 700;
  font-size: 1.1rem;
}

/* ── Rules button (top-left) ───────────────────────────────────────────── */
#rules-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 60;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(37,99,235,0.12);
  transition: all 0.2s;
}
[dir="rtl"] #rules-btn { left: auto; right: 16px; }
#rules-btn:hover { background: var(--purple); border-color: var(--purple); }

/* Offset in-game settings button so it doesn't overlap rules btn */
.ingame-settings { top: 56px; }

/* ── YOUR-VOTE label (prominent, above avatar) ─────────────────────────── */
.grid-voted-label {
  display: none;
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--red);
  color: white;
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(232,25,125,0.5);
  z-index: 2;
  animation: pop-in 0.25s ease-out;
}
.grid-player { position: relative; }
.grid-player.grid-selected .player-avatar {
  outline: 3px solid var(--red);
  box-shadow: 0 0 24px rgba(232,25,125,0.6);
}

/* ── End-game modal ────────────────────────────────────────────────────── */
.end-modal, .rules-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  background: rgba(30,27,75,0.45);
  backdrop-filter: blur(8px);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.end-modal.show, .rules-modal.show { opacity: 1; pointer-events: all; }
.em-card, .rm-card {
  width: 100%;
  max-width: 560px;
  background: linear-gradient(135deg, var(--card), var(--card2));
  border: 2px solid var(--border);
  border-radius: 24px;
  padding: 28px 22px;
  box-shadow: var(--shadow2);
  animation: slide-up 0.4s ease-out;
}
.em-winner {
  font-size: 2rem;
  font-weight: 900;
  text-align: center;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.em-reason {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 10px;
}
.em-bounty {
  text-align: center;
  font-weight: 800;
  color: var(--green);
  margin-bottom: 16px;
}
.em-words {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}
.em-words .word-card { flex: 1; }
.em-section-title {
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin: 14px 0 8px;
  font-weight: 800;
}
.em-role-row, .em-score-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px dashed var(--border);
}
.em-role-name, .em-score-name { flex: 1; font-weight: 700; }
.em-role-badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.8rem;
  background: var(--bg2);
}
.em-role-badge.undercover { background: rgba(232,25,125,0.15); color: var(--red); }
.em-role-badge.blank      { background: rgba(124,58,237,0.15); color: var(--purple); }
.em-role-badge.civilian   { background: rgba(5,150,105,0.15);  color: var(--green); }
.em-score-row.top { background: rgba(217,119,6,0.10); border-radius: 10px; }
.em-score-pts {
  font-weight: 900;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

/* ── Rules modal ───────────────────────────────────────────────────────── */
.rm-title {
  font-size: 1.6rem;
  font-weight: 900;
  text-align: center;
  margin-bottom: 14px;
}
.rm-body { line-height: 1.6; color: var(--text); }
.rm-body p { margin: 10px 0; }
.rm-body ul, .rm-body ol { margin: 6px 0 10px; padding-inline-start: 22px; }
.rm-body li { margin: 4px 0; }
.rm-body b { color: var(--yellow); }

/* ── Utils ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Mobile (tablet and below) ──────────────────────────────────────────── */
@media (max-width: 768px) {
  body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .screen { padding: 70px 10px 24px; }
  .setup-card, .game-card, .end-card {
    padding: 22px 16px;
    border-radius: 22px;
    gap: 16px;
  }
  .logo-emoji { font-size: 3rem; }
  .logo-img { width: 88px; height: 88px; }
  .logo-wrap h1 { font-size: 2.1rem; letter-spacing: -1px; }
  .tagline { font-size: 0.85rem; }

  /* Fixed top buttons — smaller, less intrusive */
  #lang-toggle-btn { top: 10px; right: 10px; padding: 5px 11px; font-size: 0.75rem; }
  #rules-btn       { top: 10px; left: 10px;  padding: 5px 11px; font-size: 0.75rem; }
  [dir="rtl"] #rules-btn { left: auto; right: 10px; }
  [dir="rtl"] #lang-toggle-btn { right: auto; left: 10px; }

  /* In-game settings button moves below the top row so it doesn't overlap */
  .ingame-settings { top: 48px; left: 10px; }
  [dir="rtl"] .ingame-settings { left: auto; right: 10px; }
  .ingame-settings-panel { min-width: calc(100vw - 32px); max-width: 320px; }

  /* Players grid — 3 columns on mobile, keep it compact */
  .players-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .grid-player { padding: 6px 4px; }
  .grid-player .player-avatar { width: 62px; height: 62px; font-size: 1.6rem; border-width: 2px; }
  .grid-name { font-size: 0.72rem; max-width: 90px; }
  .grid-clue-tag { font-size: 0.72rem; padding: 3px 9px; max-width: 96px; }

  /* Game header / chips */
  .game-header { flex-wrap: wrap; gap: 6px; }
  .round-chip, .phase-chip { font-size: 0.72rem; padding: 6px 14px; }

  /* Word reveal — tighter */
  .word-reveal { padding: 14px 16px; }
  .word-display { font-size: 1.8rem; word-break: break-word; }
  .word-hint { font-size: 0.82rem; }

  /* Clue input stack */
  .clue-row { flex-direction: column; gap: 8px; }
  .clue-row input { width: 100%; }
  .clue-row .btn-primary { width: 100%; padding: 13px; }

  /* Result / end cards — single-column word cards */
  .words-reveal,
  .em-words { flex-direction: column; }
  .word-display { font-size: 1.7rem; }

  /* Settings rows — allow wrapping */
  .settings-row { flex-wrap: wrap; gap: 8px; }
  .settings-row label { font-size: 0.88rem; flex: 1 1 100%; }
  .settings-stepper { flex: 0 0 auto; }

  /* Lobby player list items */
  .lobby-player-row { padding: 8px 10px; gap: 10px; }
  .lobby-player-name { font-size: 0.95rem; }

  /* Room browser list */
  .room-row { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .room-row-code { font-size: 1rem; }

  /* Timer */
  .timer-text { font-size: 0.82rem; }

  /* Turn indicator */
  .turn-indicator { font-size: 0.9rem; padding: 9px 12px; }

  /* Modals — full viewport with padding, scroll internally */
  .end-modal, .rules-modal { padding: 24px 10px; }
  .em-card, .rm-card { padding: 22px 16px; border-radius: 20px; }
  .em-winner { font-size: 1.7rem; }
  .rm-title  { font-size: 1.4rem; }
  .rm-body   { font-size: 0.92rem; }

  /* Vote reveal rows — allow wrap of long names */
  .vote-row { flex-wrap: wrap; gap: 6px; }

  /* Home avatar smaller */
  .avatar-preview { width: 78px; height: 78px; }

  /* Join code input */
  #join-code { font-size: 1.5rem !important; letter-spacing: 6px !important; }

  /* Visibility toggle buttons */
  .visibility-toggle { flex-wrap: wrap; }
}

/* ── Extra-small phones ─────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .screen { padding: 62px 8px 20px; }
  .setup-card, .game-card, .end-card { padding: 18px 12px; border-radius: 18px; }
  .logo-wrap h1 { font-size: 1.8rem; }
  .players-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .grid-player .player-avatar { width: 58px; height: 58px; font-size: 1.5rem; }
  .word-display { font-size: 1.5rem; }
  .btn-start { font-size: 1rem; padding: 14px; }
  .btn-primary { font-size: 0.95rem; padding: 11px 18px; }
  #rules-btn, #lang-toggle-btn { font-size: 0.7rem; padding: 4px 9px; }
}

/* ── Reduce motion for users who prefer it ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
