/* ═══ Quizix Player — Premium Dark UI ═══ */
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;800;900&display=swap');

:root {
  --bg: #0b0b1a;
  --bg2: #0f0f24;
  --surface: rgba(255,255,255,0.04);
  --surface2: rgba(255,255,255,0.07);
  --border: rgba(255,255,255,0.08);
  --text: #f0f2ff;
  --muted: #8891b2;
  --primary: #6366f1;
  --primary-glow: rgba(99,102,241,0.35);
  --red: #e21b3c;
  --blue: #1368ce;
  --yellow: #d89e00;
  --green: #26890c;
  --gold: #facc15;
  --silver: #d1d5db;
  --bronze: #b45309;
  --radius: 18px;
}

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

html, body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Tajawal', system-ui, sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background: radial-gradient(ellipse 900px 600px at 50% -5%, rgba(99,102,241,0.12) 0%, transparent 70%),
              radial-gradient(ellipse 600px 400px at 80% 100%, rgba(168,85,247,0.08) 0%, transparent 60%);
  pointer-events: none; z-index: 0;
}

#app {
  position: relative; z-index: 1;
  min-height: 100dvh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 16px;
}

/* ─── Panel ─── */
.panel {
  max-width: 780px; width: 100%;
  background: linear-gradient(180deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0.02) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  backdrop-filter: blur(12px);
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}

/* ─── Sections ─── */
.state-section { display: none; animation: fadeUp .4s cubic-bezier(.2,.9,.3,1); }
.state-section.active { display: block; }
.state-section.exit {
  display: block;
  animation: fadeOut .25s ease forwards;
  pointer-events: none;
}
@keyframes fadeUp { from { opacity:0; transform:translateY(16px) scale(.98); } to { opacity:1; transform:translateY(0) scale(1); } }
@keyframes fadeOut { from { opacity:1; transform:translateY(0) scale(1); } to { opacity:0; transform:translateY(-12px) scale(.97); } }

/* ─── Typography ─── */
h1 { font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 900; margin-bottom: 4px; }
.sub { color: var(--muted); font-size: .92rem; margin-bottom: 18px; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 10px; }

/* ─── Logo ─── */
.logo-area { text-align: center; margin-bottom: 24px; }
.logo-area h1 { font-size: 2.4rem; background: linear-gradient(135deg, #6366f1, #a855f7, #ec4899); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; letter-spacing: -.02em; }
.logo-area .tagline { color: var(--muted); font-size: .95rem; }

/* ─── Form ─── */
label { display: block; margin-bottom: 5px; font-size: .88rem; color: var(--muted); font-weight: 600; }
.form-input {
  width: 100%; padding: 13px 16px;
  border-radius: 12px; border: 1px solid var(--border);
  background: rgba(0,0,0,0.35); color: var(--text);
  font-family: inherit; font-size: 1.05rem; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.form-input:focus { border-color: rgba(99,102,241,0.6); box-shadow: 0 0 0 3px var(--primary-glow); }
.form-row { display: flex; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.form-group { margin-bottom: 14px; }

/* ─── Avatar Picker ─── */
.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.avatar-opt {
  width: 54px; height: 54px; border-radius: 16px;
  border: 2.5px solid transparent; background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: .2s; position: relative;
  padding: 4px; overflow: hidden;
}
.avatar-opt svg { width: 100%; height: 100%; border-radius: 12px; }
.avatar-opt:hover { border-color: rgba(255,255,255,.15); transform: scale(1.08); }
.avatar-opt.selected { border-color: #a855f7; background: rgba(168,85,247,0.15); box-shadow: 0 0 18px rgba(168,85,247,0.35); transform: scale(1.12); }

.avatar-svg svg { width: 100%; height: 100%; border-radius: 50%; display: block; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 24px; border: none; border-radius: 14px;
  font-family: inherit; font-weight: 800; font-size: 1rem;
  cursor: pointer; transition: .15s; color: #fff;
}
.btn-primary {
  background: linear-gradient(135deg, #6366f1, #a855f7);
  box-shadow: 0 8px 32px rgba(99,102,241,0.35);
  flex: 1; min-width: 180px;
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-2px); }
.btn-primary:active { transform: translateY(1px) scale(.98); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.3); }

/* ─── Badge ─── */
.badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: .9rem; font-weight: 700;
}
.pulse-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #22c55e;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform:scale(1); opacity:1; } 50% { transform:scale(1.4); opacity:.6; } }

/* ─── Lobby Players Grid ─── */
.lobby-players {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px;
}
.lobby-player {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  animation: playerJoin .4s cubic-bezier(.2,.9,.3,1);
  font-weight: 700; font-size: .9rem;
}
.lobby-player .avatar { font-size: 1.4rem; }
@keyframes playerJoin { from { opacity:0; transform:scale(.7) translateY(8px); } to { opacity:1; transform:scale(1) translateY(0); } }

.player-auto-status { margin-top: 16px; animation: fadeUp .4s ease; }
.player-auto-status .hint { margin: 0; }
.player-auto-status .hint strong { color: #a78bfa; }

/* ─── Countdown ─── */
.countdown-num {
  font-size: clamp(5rem, 22vw, 11rem);
  font-weight: 900; text-align: center;
  background: linear-gradient(180deg, #fff 30%, rgba(99,102,241,0.6));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  animation: countPulse .6s ease-in-out infinite alternate;
  filter: drop-shadow(0 0 40px rgba(99,102,241,0.4));
}
@keyframes countPulse { from { transform:scale(1); } to { transform:scale(1.08); } }

/* ─── Question ─── */
.q-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.q-number { font-size: .82rem; color: var(--muted); font-weight: 700; }
.q-text {
  font-size: clamp(1.15rem, 3vw, 1.5rem);
  line-height: 1.5; margin-bottom: 16px; font-weight: 800;
}
.timer-wrap { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.timer-bar {
  flex: 1; height: 14px; border-radius: 999px;
  background: rgba(255,255,255,0.06); overflow: hidden;
  border: 1px solid var(--border);
}
.timer-fill {
  height: 100%; width: 100%;
  transform-origin: right center; transform: scaleX(1);
  background: linear-gradient(90deg, #ef4444, #eab308, #22c55e);
  transition: transform .1s linear; border-radius: 999px;
}
.timer-label { font-variant-numeric: tabular-nums; min-width: 48px; text-align: left; font-weight: 900; font-size: 1.1rem; }

/* ─── Answer Options ─── */
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .options { grid-template-columns: 1fr; } }

.opt {
  border: none; border-radius: 16px;
  padding: 20px 16px; font-size: 1.05rem; font-weight: 800;
  color: #fff; cursor: pointer; min-height: 88px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  text-align: center; position: relative; overflow: hidden;
  transition: transform .12s, filter .12s, box-shadow .12s;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,0.25);
}
.opt::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.1) 0%, transparent 50%);
  pointer-events: none;
}
.opt:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-3px); box-shadow: inset 0 -6px 0 rgba(0,0,0,0.25), 0 12px 30px rgba(0,0,0,0.3); }
.opt:active:not(:disabled) { transform: translateY(2px) scale(.97); box-shadow: inset 0 -2px 0 rgba(0,0,0,0.25); }
.opt:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.15); }
.opt.red { background: var(--red); }
.opt.blue { background: var(--blue); }
.opt.yellow { background: var(--yellow); color: #111; }
.opt.green { background: var(--green); }
.opt .opt-icon { font-size: 1.3rem; }

.opt.picked { box-shadow: 0 0 0 4px rgba(255,255,255,0.4), inset 0 -6px 0 rgba(0,0,0,0.25); }
.opt.correct-reveal { box-shadow: 0 0 0 4px #22c55e, 0 0 24px rgba(34,197,94,0.4); }
.opt.wrong-reveal { box-shadow: 0 0 0 4px #ef4444; opacity: .6; }

.locked-msg {
  margin-top: 14px; padding: 14px; border-radius: 14px;
  background: rgba(0,0,0,0.3); border: 1px solid var(--border);
  font-weight: 800; text-align: center; font-size: .95rem;
  display: none;
}

/* ─── Feedback ─── */
.feedback {
  border-radius: var(--radius); padding: 28px; text-align: center;
}
.feedback .fb-icon { font-size: 3.5rem; margin-bottom: 8px; }
.feedback .fb-text { font-size: 1.4rem; font-weight: 900; }
.feedback .fb-points { font-size: 1.1rem; font-weight: 700; margin-top: 6px; }
.feedback.ok { background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.3); }
.feedback.bad { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); }
.fb-messages { margin-top: 12px; color: var(--muted); font-weight: 700; font-size: .95rem; }
.fb-messages div { margin-top: 4px; }

/* ─── Streak Banner ─── */
.streak-banner {
  display: none; margin-top: 12px; padding: 10px 16px;
  border-radius: 12px; background: linear-gradient(90deg, rgba(250,204,21,0.15), rgba(239,68,68,0.1));
  border: 1px solid rgba(250,204,21,0.3);
  font-weight: 800; text-align: center; font-size: .95rem;
  animation: streakGlow 1s ease infinite alternate;
}
.streak-banner.show { display: block; }
@keyframes streakGlow { from { box-shadow: 0 0 8px rgba(250,204,21,0.2); } to { box-shadow: 0 0 20px rgba(250,204,21,0.4); } }

/* ─── Leaderboard ─── */
.lb { display: flex; flex-direction: column; gap: 10px; }
.lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: 14px;
  background: rgba(0,0,0,0.2); border: 1px solid var(--border);
  transition: transform .5s cubic-bezier(.2,.9,.2,1), background .3s, opacity .3s;
}
.lb-row.top1 { background: linear-gradient(90deg, rgba(250,204,21,0.18), transparent); border-color: rgba(250,204,21,0.35); }
.lb-row.top2 { background: linear-gradient(90deg, rgba(209,213,219,0.15), transparent); border-color: rgba(209,213,219,0.25); }
.lb-row.top3 { background: linear-gradient(90deg, rgba(180,83,9,0.15), transparent); border-color: rgba(180,83,9,0.25); }
.lb-row.me { border-color: rgba(99,102,241,0.5); background: linear-gradient(90deg, rgba(99,102,241,0.12), transparent); }

.rank-badge {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1rem;
  background: rgba(255,255,255,0.06);
}
.rank-badge.r1 { background: rgba(250,204,21,0.2); color: #facc15; }
.rank-badge.r2 { background: rgba(209,213,219,0.15); color: #d1d5db; }
.rank-badge.r3 { background: rgba(180,83,9,0.15); color: #f59e0b; }

.lb-avatar { font-size: 1.5rem; }
.lb-info { flex: 1; min-width: 0; }
.lb-name { font-weight: 800; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-streak { font-size: .78rem; color: var(--muted); }
.lb-score { font-weight: 900; font-variant-numeric: tabular-nums; font-size: 1.1rem; }
.lb-delta { font-size: .75rem; font-weight: 700; margin-right: 6px; }
.lb-delta.up { color: #22c55e; }
.lb-delta.down { color: #ef4444; }

.you-pill {
  margin-top: 14px; display: none;
  padding: 10px 16px; border-radius: 999px;
  background: rgba(99,102,241,0.12); border: 1px solid rgba(99,102,241,0.3);
  font-weight: 800; text-align: center;
}
.you-pill.show { display: block; }

/* ─── Next Flash ─── */
.next-flash {
  text-align: center; font-weight: 900; font-size: 1.5rem;
  padding: 40px 16px;
  background: radial-gradient(circle at 50% 40%, rgba(99,102,241,0.25), transparent);
  animation: nextPulse .8s ease infinite alternate;
}
@keyframes nextPulse { from { opacity:.7; } to { opacity:1; } }

/* ─── Finished ─── */
.podium { display: flex; justify-content: center; gap: 12px; margin: 20px 0; align-items: flex-end; }
.podium-slot {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 12px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  min-width: 90px; animation: podiumRise .6s cubic-bezier(.2,.9,.3,1) backwards;
}
.podium-slot:nth-child(1) { animation-delay: .2s; }
.podium-slot:nth-child(2) { animation-delay: 0s; }
.podium-slot:nth-child(3) { animation-delay: .4s; }
.podium-slot.gold { border-color: rgba(250,204,21,0.4); background: rgba(250,204,21,0.08); order: 2; padding-bottom: 32px; }
.podium-slot.silver { border-color: rgba(209,213,219,0.3); order: 1; padding-bottom: 20px; }
.podium-slot.bronze { border-color: rgba(180,83,9,0.3); order: 3; padding-bottom: 12px; }
.podium-avatar { font-size: 2.2rem; }
.podium-name { font-weight: 800; font-size: .85rem; }
.podium-score { font-weight: 900; font-size: .9rem; color: var(--muted); }
.podium-medal { font-size: 1.5rem; }
@keyframes podiumRise { from { opacity:0; transform:translateY(30px) scale(.8); } to { opacity:1; transform:translateY(0) scale(1); } }

/* ─── Toast ─── */
.toast-box {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  padding: 12px 22px; border-radius: 14px; z-index: 100;
  background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5; font-weight: 700; font-size: .9rem;
  animation: toastIn .3s ease;
  display: none; backdrop-filter: blur(8px);
}
.toast-box.show { display: block; }
@keyframes toastIn { from { opacity:0; transform:translateX(-50%) translateY(10px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }

/* ─── Confetti ─── */
.confetti-container { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 99; overflow: hidden; }
.confetti-piece {
  position: absolute; width: 10px; height: 10px; top: -10px;
  animation: confettiFall 2.5s ease-in forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg) scale(0.3); opacity: 0; }
}

/* ─── Shake ─── */
.shake { animation: shake .45s ease-in-out; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-6px)} 40%{transform:translateX(6px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }

/* ─── Explanation ─── */
.fb-explanation {
  display: none;
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: rgba(99,102,241,0.1);
  border: 1px solid rgba(99,102,241,0.25);
  color: var(--muted);
  font-size: .92rem;
  font-weight: 600;
  line-height: 1.5;
}

/* ─── Post-Game Summary ─── */
.my-summary { margin-top: 18px; }
.summary-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.summary-title {
  font-weight: 900;
  font-size: 1.1rem;
  margin-bottom: 14px;
  text-align: center;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.summary-item {
  text-align: center;
  padding: 10px 4px;
  background: rgba(255,255,255,0.03);
  border-radius: 12px;
}
.summary-val {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--primary);
}
.summary-label {
  font-size: .78rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ─── Responsive ─── */
@media (max-width: 520px) {
  .panel { padding: 18px; border-radius: 14px; }
  .avatar-picker { gap: 5px; }
  .avatar-opt { width: 46px; height: 46px; }
  .podium-slot { min-width: 75px; padding: 12px 8px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
}
