@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;800;900&display=swap');

:root {
  --primary: #7C6FD4;
  --primary-dark: #6358B8;
  --primary-light: #B0A8E8;
  --secondary: #5BA4B5;
  --accent: #C97B9A;
  --accent-dark: #A8607D;
  --success: #5BAD8F;
  --danger: #D4726B;
  --warning: #D4B86A;
  --bg: #0A0A14;
  --bg-card: #131321;
  --bg-card-hover: #1A1A2E;
  --bg-input: #111120;
  --text: #F0EEF6;
  --text-dim: #9B97AD;
  --text-muted: #5C5872;
  --glass: rgba(255, 255, 255, 0.035);
  --glass-border: rgba(255, 255, 255, 0.07);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-full: 50px;
}

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

html { font-size: 16px; }

body {
  font-family: 'Tajawal', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  direction: rtl;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ===== Background ===== */
.bg-effects {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 0; overflow: hidden;
}

.bg-effects .orb {
  position: absolute; border-radius: 50%;
  filter: blur(100px); opacity: 0.15;
  animation: float 10s ease-in-out infinite;
}

.bg-effects .orb:nth-child(1) {
  width: 350px; height: 350px;
  background: #B06E88; top: -80px; right: -60px;
}
.bg-effects .orb:nth-child(2) {
  width: 300px; height: 300px;
  background: #5E8FAD; bottom: -60px; left: -60px;
  animation-delay: -4s;
}
.bg-effects .orb:nth-child(3) {
  width: 220px; height: 220px;
  background: #6358B8; top: 45%; left: 55%;
  animation-delay: -7s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(20px, -20px) scale(1.05); }
  66% { transform: translate(-15px, 15px) scale(0.95); }
}

/* ===== Screens ===== */
.screen {
  display: none; min-height: 100dvh;
  position: relative; z-index: 1;
  padding: 20px; max-width: 500px; margin: 0 auto;
}
.screen.active { display: flex; flex-direction: column; }

/* ===== Logo ===== */
.logo { text-align: center; padding: 24px 0 16px; }

.logo h1 { font-size: 3.5rem; font-weight: 900; line-height: 1.2; }

.title-bnt {
  background: linear-gradient(135deg, #F0B8CF, #D98BA6, #C4728F);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.title-wld {
  background: linear-gradient(135deg, #B0D8EE, #88BAD4, #6A9DBD);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo .subtitle {
  color: var(--text-muted); font-size: 0.95rem;
  margin-top: 4px; font-weight: 500;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 22px; margin-bottom: 14px;
  backdrop-filter: blur(10px);
}

.card-title {
  font-size: 1.05rem; font-weight: 700;
  margin-bottom: 14px; color: var(--text);
  display: flex; align-items: center; gap: 10px;
}

.card-title .icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}

/* ===== Buttons ===== */
.btn {
  width: 100%; padding: 16px 24px; border: none;
  border-radius: var(--radius); font-family: 'Tajawal', sans-serif;
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
  transition: all 0.2s ease; display: flex;
  align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, #7C6FD4, #6358B8);
  color: white; box-shadow: 0 4px 20px rgba(124, 111, 212, 0.2);
}
.btn-primary:hover { box-shadow: 0 6px 25px rgba(124, 111, 212, 0.3); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--glass); color: var(--text-dim);
  border: 1px solid var(--glass-border);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white; box-shadow: 0 4px 20px rgba(201, 123, 154, 0.2);
}

.btn-success {
  background: linear-gradient(135deg, #5BAD8F, #4A9A7E);
  color: white; box-shadow: 0 4px 20px rgba(91, 173, 143, 0.2);
}

.btn-pink {
  background: linear-gradient(135deg, #D98BA6, #C4728F);
  color: white; box-shadow: 0 4px 20px rgba(196, 114, 143, 0.25);
}
.btn-pink:hover { box-shadow: 0 6px 25px rgba(196, 114, 143, 0.35); transform: translateY(-1px); }

.btn-blue {
  background: linear-gradient(135deg, #88BAD4, #6A9DBD);
  color: white; box-shadow: 0 4px 20px rgba(106, 157, 189, 0.25);
}
.btn-blue:hover { box-shadow: 0 6px 25px rgba(106, 157, 189, 0.35); transform: translateY(-1px); }

.btn-sm { padding: 10px 20px; font-size: 0.9rem; border-radius: var(--radius-sm); }

.btn-end-game {
  width: 100%;
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--glass-border); border-radius: var(--radius-sm);
  padding: 10px 14px; font-family: 'Tajawal', sans-serif;
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  transition: all 0.2s;
}
.btn-end-game:active { background: rgba(212, 114, 107, 0.1); color: var(--danger); border-color: rgba(212, 114, 107, 0.3); }

/* ===== Inputs ===== */
.input-group { margin-bottom: 14px; }
.input-group label {
  display: block; font-size: 0.85rem; font-weight: 600;
  color: var(--text-dim); margin-bottom: 6px;
}

.input {
  width: 100%; padding: 14px 16px;
  background: var(--bg-input); border: 2px solid var(--glass-border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: 'Tajawal', sans-serif; font-size: 1rem;
  font-weight: 500; transition: border-color 0.2s; direction: rtl;
}
.input:focus { outline: none; border-color: var(--primary-light); }
.input::placeholder { color: var(--text-muted); }

/* ===== Room Screen ===== */
.room-header { text-align: center; padding: 10px 0 5px; }

.room-code { text-align: center; padding: 16px 0 20px; }
.room-code .code {
  font-size: 2.8rem; font-weight: 900;
  letter-spacing: 14px; direction: ltr;
  font-family: 'Tajawal', monospace;
  background: linear-gradient(135deg, var(--primary-light), #D98BA6);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.room-code .label {
  color: var(--text-muted); font-size: 0.85rem; margin-bottom: 6px; font-weight: 600;
}

.copy-btn {
  background: var(--glass); border: 1px solid var(--glass-border);
  color: var(--text-dim); padding: 8px 18px;
  border-radius: var(--radius-full); font-family: 'Tajawal', sans-serif;
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
  margin-top: 8px; transition: all 0.2s;
}
.copy-btn:active { background: var(--primary); color: white; }

/* ===== Players List ===== */
.players-list { list-style: none; padding: 0; }

.players-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--glass);
  border-radius: var(--radius-sm); margin-bottom: 8px;
  font-weight: 600; animation: slideIn 0.3s ease-out;
  border: 1px solid transparent;
}

.players-list li .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.85rem; color: white;
}

.players-list li .host-badge {
  margin-right: auto; font-size: 0.7rem;
  background: rgba(212, 184, 106, 0.15); color: var(--warning);
  padding: 3px 10px; border-radius: var(--radius-full); font-weight: 700;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Waiting Dots ===== */
.waiting-dots { display: inline-flex; gap: 4px; }
.waiting-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary-light); animation: bounce 1.4s ease-in-out infinite;
}
.waiting-dots span:nth-child(2) { animation-delay: 0.2s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== Letter Spinner ===== */
.letter-spinner { text-align: center; padding: 30px 20px; }

.round-badge {
  display: inline-block; padding: 6px 20px;
  background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: var(--radius-full); font-size: 0.9rem;
  font-weight: 700; color: var(--text-dim); margin-bottom: 30px;
}

.letter-display {
  width: 150px; height: 150px; margin: 0 auto 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #C4728F, #6A9DBD);
  display: flex; align-items: center; justify-content: center;
  font-size: 4.2rem; font-weight: 900; color: white;
  box-shadow: 0 0 50px rgba(196, 114, 143, 0.3), 0 0 50px rgba(106, 157, 189, 0.3);
  animation: pulse-glow 2s ease-in-out infinite;
}

.letter-display.spinning { animation: spin-letter 0.1s linear infinite; }
.letter-display.landed { animation: land 0.5s ease-out forwards; }

.letter-hint { font-size: 1rem; color: var(--text-muted); font-weight: 600; }

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 40px rgba(196, 114, 143, 0.2), 0 0 40px rgba(106, 157, 189, 0.2); }
  50% { box-shadow: 0 0 70px rgba(196, 114, 143, 0.4), 0 0 70px rgba(106, 157, 189, 0.4); }
}
@keyframes spin-letter { 0% { transform: scale(1); } 50% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes land { 0% { transform: scale(1.3); } 50% { transform: scale(0.92); } 100% { transform: scale(1); } }

/* ===== Game Header ===== */
.game-header {
  text-align: center; padding: 8px 0 14px;
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
}
.game-header-round {
  font-size: 0.82rem; color: var(--text-muted);
  font-weight: 600; letter-spacing: 0.5px;
}
.game-letter-circle {
  width: 76px; height: 76px; border-radius: 50%;
  background: linear-gradient(135deg, #C4728F, #7C6FD4, #6A9DBD);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.4rem; font-weight: 900; color: white;
  box-shadow: 0 4px 24px rgba(196, 114, 143, 0.3), 0 4px 24px rgba(106, 157, 189, 0.2);
  animation: pulse-glow 2.5s ease-in-out infinite;
}

/* ===== Timer ===== */
.timer {
  position: fixed; top: 20px; left: 20px; z-index: 100;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--bg-card); border: 3px solid var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 800;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  transition: border-color 0.3s, color 0.3s;
}
.timer.warning { border-color: var(--warning); color: var(--warning); animation: timer-pulse 0.5s ease-in-out infinite; }
.timer.danger { border-color: var(--danger); color: var(--danger); animation: timer-pulse 0.3s ease-in-out infinite; }

@keyframes timer-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* ===== Game Cards ===== */
.game-cards { flex: 1; overflow-y: auto; padding-bottom: 130px; }

.answer-card {
  background: var(--bg-card); border: 1px solid var(--glass-border);
  border-radius: var(--radius); padding: 14px 16px;
  margin-bottom: 10px; transition: all 0.2s;
}
.answer-card .category-name {
  font-size: 1.1rem; font-weight: 800; margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
}
.answer-card .answer-input {
  width: 100%; padding: 12px 14px;
  background: var(--bg-input); border: 2px solid transparent;
  border-radius: var(--radius-sm); color: var(--text);
  font-family: 'Tajawal', sans-serif; font-size: 1rem;
  font-weight: 500; transition: border-color 0.2s;
}
.answer-card .answer-input:focus { outline: none; border-color: var(--primary-light); }
.answer-card .answer-input.filled { border-color: var(--success); }

/* ===== Submit Bar ===== */
.submit-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 14px 20px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  z-index: 50; display: flex; justify-content: center;
}
.submit-bar .btn { max-width: 500px; }

/* ===== Vote Screen ===== */
.vote-header { text-align: center; padding: 16px 0; }

.vote-step {
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
  margin-bottom: 8px;
}

.vote-header .category-badge {
  display: inline-block; padding: 10px 28px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: var(--radius-full); font-size: 1.3rem;
  font-weight: 800; margin-bottom: 10px;
}

.vote-instruction {
  font-size: 0.95rem; font-weight: 700; color: var(--text);
  margin-bottom: 4px;
}

.vote-hint {
  font-size: 0.78rem; font-weight: 500; color: var(--text-muted);
  margin-bottom: 10px;
}

.vote-header .progress-dots {
  display: flex; justify-content: center; gap: 5px; margin-top: 8px;
}
.vote-header .progress-dots .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--glass-border); transition: all 0.3s;
}
.vote-header .progress-dots .dot.active {
  background: var(--primary-light); width: 22px; border-radius: 4px;
}
.vote-header .progress-dots .dot.done { background: var(--success); }

/* ===== Vote Answer Cards ===== */
.vote-answers { display: flex; flex-direction: column; gap: 10px; }

.vote-answer-card {
  padding: 16px 18px; background: var(--bg-card);
  border: 2px solid var(--glass-border); border-radius: var(--radius);
  font-size: 1.1rem; font-weight: 700; cursor: pointer;
  transition: all 0.2s; display: flex;
  align-items: center; justify-content: space-between;
  -webkit-user-select: none; user-select: none;
}
.vote-answer-card:active { transform: scale(0.97); }

.vote-answer-card.accepted {
  border-color: var(--success);
  background: rgba(91, 173, 143, 0.08);
  box-shadow: 0 0 20px rgba(91, 173, 143, 0.1);
}

.vote-answer-card.duplicate {
  border-color: var(--danger);
  background: rgba(212, 114, 107, 0.08);
  opacity: 0.5; cursor: not-allowed; text-decoration: line-through;
}

.vote-answer-card .vote-status { font-size: 1.2rem; }
.vote-answer-card .empty-answer { color: var(--text-muted); font-style: italic; }

.vote-answer-card .own-tag {
  font-size: 0.7rem; font-weight: 600; color: var(--text-muted);
  background: var(--glass); padding: 2px 8px; border-radius: var(--radius-full);
}

/* ===== Vote Results ===== */
.vote-result-card {
  padding: 14px 16px; background: var(--bg-card);
  border: 2px solid var(--glass-border); border-radius: var(--radius);
  margin-bottom: 8px; display: flex; align-items: center;
  gap: 12px; animation: fadeIn 0.3s ease-out;
}
.vote-result-card .answer-text { flex: 1; font-size: 1rem; font-weight: 600; }
.vote-result-card .player-name { font-size: 0.78rem; color: var(--text-dim); }

.vote-result-card .score-badge {
  padding: 4px 14px; border-radius: var(--radius-full);
  font-weight: 800; font-size: 0.95rem;
}
.vote-result-card .score-badge.plus { background: rgba(91, 173, 143, 0.15); color: var(--success); }
.vote-result-card .score-badge.zero { background: rgba(212, 114, 107, 0.15); color: var(--danger); }

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

/* ===== Rankings ===== */
.rankings { padding: 20px 0; }
.rankings .rankings-title {
  text-align: center; font-size: 1.4rem; font-weight: 800; margin-bottom: 20px;
  color: var(--text);
}

.rank-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius); margin-bottom: 10px;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  animation: slideUp 0.4s ease-out;
}
.rank-item:nth-child(1) { border-color: rgba(255, 215, 0, 0.3); background: rgba(255, 215, 0, 0.04); }
.rank-item:nth-child(2) { border-color: rgba(192, 192, 192, 0.3); background: rgba(192, 192, 192, 0.04); }
.rank-item:nth-child(3) { border-color: rgba(205, 127, 50, 0.3); background: rgba(205, 127, 50, 0.04); }

.rank-number {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1rem; background: var(--glass);
}
.rank-item:nth-child(1) .rank-number { background: linear-gradient(135deg, #FFD700, #FFA500); color: #333; }
.rank-item:nth-child(2) .rank-number { background: linear-gradient(135deg, #C0C0C0, #A0A0A0); color: #333; }
.rank-item:nth-child(3) .rank-number { background: linear-gradient(135deg, #CD7F32, #A0522D); color: #fff; }

.rank-name { flex: 1; font-weight: 700; font-size: 1.05rem; }
.rank-score { font-weight: 800; font-size: 1.15rem; color: var(--primary-light); }

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

/* ===== Game Over ===== */
.game-over-screen { text-align: center; padding: 30px 0; width: 100%; }

.winner-crown { font-size: 3.5rem; margin-bottom: 8px; animation: crown-bounce 1.5s ease-in-out infinite; }
@keyframes crown-bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

.winner-name {
  font-size: 2.2rem; font-weight: 900;
  background: linear-gradient(135deg, #FFD700, #FFA500);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; margin-bottom: 4px;
}
.winner-label { color: var(--text-dim); font-size: 1rem; margin-bottom: 24px; font-weight: 600; }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 20px; right: 20px; left: 20px;
  max-width: 380px; margin: 0 auto; padding: 12px 18px;
  border-radius: var(--radius); font-weight: 700;
  font-size: 0.9rem; z-index: 200; text-align: center;
  animation: toastIn 0.3s ease-out; pointer-events: none;
  backdrop-filter: blur(10px);
}
.toast.info { background: rgba(124, 111, 212, 0.9); color: white; }
.toast.warning { background: rgba(212, 184, 106, 0.9); color: #1a1a2e; }
.toast.success { background: rgba(91, 173, 143, 0.9); color: white; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Finished Overlay ===== */
.finished-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10, 10, 20, 0.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 150; backdrop-filter: blur(8px);
  animation: fadeIn 0.3s ease-out;
}
.finished-overlay .finished-content { text-align: center; padding: 30px; }
.finished-overlay .finished-icon { font-size: 3rem; margin-bottom: 12px; }
.finished-overlay .finished-text { font-size: 1.2rem; font-weight: 700; }

/* ===== Responsive ===== */
@media (min-width: 768px) {
  .screen { max-width: 460px; padding: 30px; }
  .logo h1 { font-size: 4rem; }
  .letter-display { width: 170px; height: 170px; font-size: 4.8rem; }
}

@media (max-width: 380px) {
  html { font-size: 14px; }
  .logo h1 { font-size: 2.8rem; }
  .letter-display { width: 130px; height: 130px; font-size: 3.5rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 4px; }

/* Safe area */
@supports (padding-top: env(safe-area-inset-top)) {
  .screen { padding-top: calc(20px + env(safe-area-inset-top)); padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .submit-bar { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .timer { top: calc(20px + env(safe-area-inset-top)); }
}

/* Avatars */
.avatar-1 { background: linear-gradient(135deg, #7C6FD4, #B0A8E8); }
.avatar-2 { background: linear-gradient(135deg, #5BA4B5, #88C9D8); }
.avatar-3 { background: linear-gradient(135deg, #C97B9A, #E4A8BE); }
.avatar-4 { background: linear-gradient(135deg, #D4B86A, #E8D494); }
.avatar-5 { background: linear-gradient(135deg, #D4726B, #E89E98); }
.avatar-6 { background: linear-gradient(135deg, #5BAD8F, #8CCAB2); }
.avatar-7 { background: linear-gradient(135deg, #6A9DBD, #9DC4DA); }
.avatar-8 { background: linear-gradient(135deg, #C4728F, #D998AE); }
