:root {
  --bg: #0d0d1a;
  --card: #16162a;
  --card2: #1a1a30;
  --border: #2a2a50;
  --primary: #a78bfa;
  --primary-dark: #8b5cf6;
  --pink: #f472b6;
  --cyan: #22d3ee;
  --green: #34d399;
  --orange: #fb923c;
  --yellow: #fbbf24;
  --text: #f0f0ff;
  --muted: #7070a0;
  --radius: 18px;
  --imsg-blue: #0b84ff;
  --imsg-gray: #3a3a3c;
  --imsg-bg: #000000;
  --imsg-bar: #1c1c1e;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(167,139,250,0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(244,114,182,0.07) 0%, transparent 50%),
    radial-gradient(ellipse at 60% 80%, rgba(34,211,238,0.06) 0%, transparent 50%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
}

#app { width: 100%; max-width: 740px; }

.screen { display: none; }
.screen.active { display: block; }

/* CARD */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 32px;
  box-shadow: 0 32px 100px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--pink), var(--cyan), var(--green));
}
.card.center { max-width: 460px; margin: 0 auto; }
.card.wide { max-width: 100%; }

/* TYPOGRAPHY */
h1 {
  font-size: 2.8rem; font-weight: 900; text-align: center; letter-spacing: -1px; margin-bottom: 8px;
  background: linear-gradient(135deg, var(--primary), var(--pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
h2 { font-size: 1.8rem; font-weight: 800; text-align: center; margin-bottom: 20px; }
h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.logo { font-size: 4.5rem; text-align: center; margin-bottom: 4px; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

.subtitle { text-align: center; color: var(--muted); margin-bottom: 28px; line-height: 1.6; }
.muted { color: var(--muted); text-align: center; font-size: 0.9rem; margin-top: 12px; }
.error-msg { color: var(--pink); font-size: 0.9rem; text-align: center; margin-top: 8px; }
.error-msg.hidden, .hidden { display: none !important; }

/* INPUTS */
input[type="text"] {
  width: 100%;
  padding: 13px 16px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  margin-bottom: 12px;
  display: block;
}
input[type="text"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(167,139,250,0.15); }
#room-code-input { text-transform: uppercase; letter-spacing: 4px; font-weight: 700; font-size: 1.1rem; }

/* BUTTONS */
.btn {
  display: block; width: 100%; padding: 15px 24px; border-radius: 14px; border: none;
  font-size: 1rem; font-weight: 700; cursor: pointer; transition: all 0.18s; margin-top: 6px;
}
.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--pink));
  color: #fff; box-shadow: 0 4px 20px rgba(167,139,250,0.3);
}
.btn.primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(167,139,250,0.45); }
.btn.secondary {
  background: rgba(255,255,255,0.07); color: var(--text); border: 1px solid var(--border);
  flex-shrink: 0; width: auto; padding: 13px 20px;
}
.btn.secondary:hover:not(:disabled) { background: rgba(255,255,255,0.12); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; box-shadow: none !important; }
.secondary-btn {
  display: block; width: 100%; padding: 12px 24px; border-radius: 14px;
  border: 2px solid var(--border); background: transparent; color: var(--muted);
  font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all 0.18s; margin-top: 10px;
}
.secondary-btn:hover { border-color: var(--primary); color: var(--text); }

/* JOIN */
.divider {
  text-align: center; color: var(--muted); position: relative; margin: 18px 0; font-size: 0.85rem;
}
.divider::before, .divider::after {
  content: ''; position: absolute; top: 50%; width: calc(50% - 60px); height: 1px; background: var(--border);
}
.divider::before { left: 0; } .divider::after { right: 0; }
.join-row { display: flex; gap: 10px; align-items: flex-start; }
.join-row input { margin-bottom: 0; flex: 1; }

/* ROOM CODE */
.room-code-wrap { text-align: center; margin-bottom: 24px; }
.label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 2px; display: block; margin-bottom: 8px; }
.room-code {
  font-size: 2.8rem; font-weight: 900; letter-spacing: 10px;
  background: linear-gradient(135deg, var(--cyan), var(--primary));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  cursor: pointer; user-select: all; display: inline-block; padding: 8px 16px; border-radius: 12px;
}
.copy-hint { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 4px; }

/* PLAYER CHIPS */
.player-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 20px; }
.player-chips.mini { margin-top: 14px; margin-bottom: 0; }
.chip {
  display: flex; align-items: center; gap: 5px; padding: 7px 14px; border-radius: 50px;
  font-size: 0.88rem; font-weight: 600;
  background: rgba(167,139,250,0.12); border: 1px solid rgba(167,139,250,0.3);
}
.chip.host { border-color: rgba(251,191,36,0.6); background: rgba(251,191,36,0.1); }
.chip.done { border-color: rgba(52,211,153,0.6); background: rgba(52,211,153,0.1); color: var(--green); }

/* PHASE LABEL */
.phase-label {
  text-align: center; font-size: 0.85rem; font-weight: 800; text-transform: uppercase; letter-spacing: 2px; margin-bottom: 16px;
  background: linear-gradient(135deg, var(--cyan), var(--primary), var(--pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

/* TIMER */
.timer-wrap { margin-bottom: 20px; display: flex; align-items: center; gap: 12px; }
.timer-bar { flex: 1; height: 10px; background: rgba(255,255,255,0.06); border-radius: 5px; overflow: hidden; }
.timer-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--green), var(--cyan), var(--primary));
  border-radius: 5px; transition: width 1s linear, background 0.5s;
}
.timer-fill.urgent { background: linear-gradient(90deg, #ef4444, var(--orange)); }
.timer-num { font-size: 1.2rem; font-weight: 900; color: var(--text); min-width: 40px; text-align: right; }

/* ── WRITING SCREEN ─────────────────────────────────────────────── */

/* Emoji choice */
.emoji-choice-wrap { margin-bottom: 18px; }
.choice-label { display: block; text-align: center; color: var(--muted); font-size: 0.9rem; font-weight: 600; margin-bottom: 14px; }
.emoji-options { display: flex; align-items: center; justify-content: center; gap: 16px; }
.emoji-option {
  font-size: 4rem; width: 96px; height: 96px; border-radius: 24px;
  border: 3px solid var(--border); background: rgba(255,255,255,0.04);
  cursor: pointer; transition: all 0.2s; display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.emoji-option:hover { border-color: var(--primary); background: rgba(167,139,250,0.1); transform: scale(1.06); }
.emoji-option.selected {
  border-color: var(--imsg-blue); background: rgba(11,132,255,0.15);
  transform: scale(1.1); box-shadow: 0 0 28px rgba(11,132,255,0.35);
}
.emoji-option.dimmed { opacity: 0.25; transform: scale(0.93); pointer-events: none; }
.or-divider { color: var(--muted); font-size: 0.9rem; font-weight: 700; }

.change-btn {
  background: none; border: none; color: var(--imsg-blue);
  font-size: 0.82rem; font-weight: 700; cursor: pointer; padding: 2px 6px;
  border-radius: 6px; transition: background 0.15s;
}
.change-btn:hover { background: rgba(11,132,255,0.1); }

.target-row {
  display: flex; align-items: center; justify-content: center;
  gap: 14px; margin-bottom: 16px;
}
.target-label { font-size: 0.95rem; color: var(--muted); font-weight: 600; }
.target-emoji {
  font-size: 3rem; line-height: 1;
  animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 4px 16px rgba(167,139,250,0.35));
}
@keyframes popIn {
  0% { transform: scale(0.2) rotate(-20deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* iMessage window */
.imsg-window {
  background: var(--imsg-bg);
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid #2c2c2e;
  margin-bottom: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.imsg-header {
  background: var(--imsg-bar);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #2c2c2e;
}
.imsg-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, #5e5ce6, #bf5af2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
}
.imsg-contact-name { font-weight: 700; font-size: 0.95rem; color: #fff; }
.imsg-status { font-size: 0.75rem; color: #8e8e93; }

.imsg-body {
  min-height: 70px;
  max-height: 160px;
  overflow-y: auto;
  padding: 14px 14px 8px;
  background: var(--imsg-bg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* BUBBLES */
.bubble {
  max-width: 75%;
  padding: 10px 14px;
  font-size: 0.95rem;
  line-height: 1.45;
  word-break: break-word;
}
.bubble.sent {
  background: var(--imsg-blue);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  align-self: flex-end;
}
.bubble.received {
  background: var(--imsg-gray);
  color: #fff;
  border-radius: 18px 18px 18px 4px;
  align-self: flex-start;
}
.bubble.emoji-response {
  font-size: 2rem;
  padding: 6px 10px;
  line-height: 1;
}

.imsg-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--imsg-bar);
  border-top: 1px solid #2c2c2e;
}
.imsg-input-wrap {
  flex: 1;
  background: #2c2c2e;
  border-radius: 20px;
  padding: 1px 4px;
  border: 1px solid #3a3a3c;
}
.imsg-input-wrap textarea {
  width: 100%; background: transparent; border: none; outline: none;
  color: #fff; font-size: 0.95rem; font-family: inherit;
  padding: 8px 10px; resize: none; line-height: 1.4;
  min-height: 36px; max-height: 100px; display: block;
}
.imsg-input-wrap textarea::placeholder { color: #8e8e93; }

.send-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--imsg-blue); border: none; color: #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}
.send-btn:hover:not(:disabled) { transform: scale(1.08); background: #0a78e8; }
.send-btn:disabled { background: #3a3a3c; cursor: not-allowed; }

.char-count { text-align: right; font-size: 0.78rem; color: var(--muted); margin-bottom: 8px; }
.instruction { text-align: center; color: var(--muted); margin-bottom: 14px; font-size: 0.95rem; }

/* ── GUESSING SCREEN ─────────────────────────────────────────────── */

#prompts-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }

.prompt-card {
  background: #111122;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.prompt-card.has-guess {
  border-color: var(--imsg-blue);
  box-shadow: 0 0 20px rgba(11,132,255,0.2);
}

.msg-card-header {
  background: #1c1c2e;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid var(--border);
}
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem; font-weight: 800; color: #fff; flex-shrink: 0;
}
.msg-name { font-weight: 700; font-size: 0.88rem; color: var(--text); }

.msg-card-body { padding: 14px 14px 10px; }

.msg-card-footer {
  padding: 10px 14px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.2);
}
.respond-label { font-size: 0.82rem; color: var(--muted); font-weight: 600; flex-shrink: 0; }
.guess-display {
  width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; border: 2px dashed var(--border);
  background: rgba(255,255,255,0.03); flex-shrink: 0; transition: all 0.2s;
}
.guess-display.filled {
  border-style: solid; border-color: var(--imsg-blue);
  background: rgba(11,132,255,0.15);
  box-shadow: 0 0 14px rgba(11,132,255,0.25);
}
.pick-btn {
  padding: 9px 16px; border-radius: 50px;
  border: 1.5px solid var(--border); background: rgba(255,255,255,0.04);
  color: var(--text); font-size: 0.88rem; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.pick-btn:hover { border-color: var(--imsg-blue); background: rgba(11,132,255,0.1); }

/* AVATAR COLORS */
.avatar-0 { background: linear-gradient(135deg,#5e5ce6,#bf5af2); }
.avatar-1 { background: linear-gradient(135deg,#0b84ff,#30d158); }
.avatar-2 { background: linear-gradient(135deg,#ff375f,#ff9f0a); }
.avatar-3 { background: linear-gradient(135deg,#ffd60a,#ff9f0a); }
.avatar-4 { background: linear-gradient(135deg,#32ade6,#5e5ce6); }
.avatar-5 { background: linear-gradient(135deg,#30d158,#32ade6); }
.avatar-6 { background: linear-gradient(135deg,#ff6961,#bf5af2); }
.avatar-7 { background: linear-gradient(135deg,#ffd60a,#30d158); }

/* ── MODAL ─────────────────────────────────────────────────────────── */

.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.75); backdrop-filter: blur(4px); }
.modal-box {
  position: relative; width: 100%; max-width: 640px; max-height: 72vh;
  background: var(--card2); border-radius: 28px 28px 0 0; padding: 22px;
  display: flex; flex-direction: column; border: 1px solid var(--border); border-bottom: none;
  box-shadow: 0 -20px 60px rgba(0,0,0,0.5);
}
.modal-box::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--imsg-blue), var(--primary), var(--pink));
  border-radius: 28px 28px 0 0;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; font-weight: 700; font-size: 1rem;
}
#modal-close {
  background: rgba(255,255,255,0.08); border: none; color: var(--text);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center; transition: background 0.15s;
}
#modal-close:hover { background: rgba(255,255,255,0.15); }
#emoji-search {
  width: 100%; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--border);
  background: rgba(255,255,255,0.05); color: var(--text); font-size: 0.95rem;
  outline: none; margin-bottom: 12px; display: block; font-family: inherit;
}
#emoji-search:focus { border-color: var(--imsg-blue); }
.emoji-grid { display: flex; flex-wrap: wrap; gap: 4px; overflow-y: auto; padding: 4px; }
.cat-label {
  width: 100%; font-size: 0.7rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 2px; color: var(--muted); padding: 8px 4px 3px;
}
.emoji-btn {
  font-size: 1.8rem; width: 50px; height: 50px; display: flex; align-items: center;
  justify-content: center; border-radius: 12px; border: 2px solid transparent;
  background: rgba(255,255,255,0.03); cursor: pointer; transition: all 0.12s; line-height: 1;
}
.emoji-btn:hover { background: rgba(255,255,255,0.1); transform: scale(1.18); }
.emoji-btn.selected {
  border-color: var(--imsg-blue); background: rgba(11,132,255,0.2);
  transform: scale(1.12); box-shadow: 0 0 12px rgba(11,132,255,0.3);
}

/* ── RESULTS ───────────────────────────────────────────────────────── */

#reveals { display: flex; flex-direction: column; gap: 16px; margin-bottom: 28px; }

.reveal-card {
  background: #111122;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  animation: slideIn 0.4s ease backwards;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

.reveal-header {
  background: #1c1c2e;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 9px;
  border-bottom: 1px solid var(--border);
}
.reveal-body { padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.reveal-response-row { display: flex; align-items: center; gap: 8px; padding: 0 14px 10px; }
.reveal-wanted { font-size: 0.78rem; color: var(--muted); font-weight: 600; }

.reveal-guesses { display: flex; flex-wrap: wrap; gap: 7px; padding: 10px 14px 14px; border-top: 1px solid var(--border); }
.guess-chip {
  display: flex; align-items: center; gap: 5px; padding: 5px 12px;
  border-radius: 50px; font-size: 0.85rem; font-weight: 600;
}
.guess-chip.exact { background: rgba(52,211,153,0.15); border: 1px solid rgba(52,211,153,0.4); color: var(--green); }
.guess-chip.close { background: rgba(251,191,36,0.15); border: 1px solid rgba(251,191,36,0.4); color: var(--yellow); }
.guess-chip.nearby { background: rgba(251,146,60,0.15); border: 1px solid rgba(251,146,60,0.4); color: var(--orange); }
.guess-chip.wrong { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.25); color: #f87171; }
.guess-chip .pts { font-weight: 900; font-size: 0.78rem; opacity: 0.85; }
.no-guesses { font-size: 0.85rem; color: var(--muted); padding: 0 14px 12px; display: block; }

/* LEADERBOARD */
.leaderboard-section { margin-bottom: 24px; }
.lb-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px;
  border-radius: 14px; margin-bottom: 8px;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
}
.lb-item:first-child { background: linear-gradient(135deg,rgba(251,191,36,0.12),rgba(251,146,60,0.08)); border-color: rgba(251,191,36,0.3); }
.lb-item:nth-child(2) { background: rgba(167,139,250,0.07); border-color: rgba(167,139,250,0.2); }
.lb-item:nth-child(3) { background: rgba(251,146,60,0.07); border-color: rgba(251,146,60,0.2); }
.lb-rank { font-size: 1.5rem; width: 38px; text-align: center; }
.lb-name { flex: 1; font-weight: 700; }
.lb-score {
  font-size: 1.2rem; font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

@media (max-width: 520px) {
  .card { padding: 20px 16px; }
  h1 { font-size: 2.2rem; }
  .room-code { font-size: 2.2rem; letter-spacing: 7px; }
  .modal-box { max-height: 80vh; }
  .target-emoji { font-size: 2.4rem; }
}
