/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #e94560;
  --primary-dark: #c81e45;
  --bg-dark: #1a1a2e;
  --bg-card: #16213e;
  --bg-surface: #0f3460;
  --text: #eee;
  --text-dim: #aaa;
  --correct: #00c853;
  --wrong: #ff1744;
  --streak: #ffc107;
  --font: 'Rubik', sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text);
  direction: rtl;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* --- Screens --- */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  overflow-y: auto;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* --- Screen 1: Join --- */
.join-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 28px;
  background: rgba(26, 26, 46, 0.85);
}

.logo-icon {
  display: block;
  margin: 0 auto 8px;
  width: 64px;
  height: 64px;
  border-radius: 16px;
}

.logo h1 {
  font-size: 4rem;
  font-weight: 900;
  letter-spacing: 8px;
  text-align: center;
  color: var(--primary);
  text-shadow: 0 0 30px rgba(233, 69, 96, 0.5);
}

.tagline {
  text-align: center;
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.game-description {
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-dim);
  max-width: 340px;
  line-height: 1.6;
  opacity: 0.8;
}

/* Alert status */
.alert-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: 500;
}

.alert-status.waiting {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
}

.alert-status.active {
  background: rgba(233, 69, 96, 0.2);
  color: var(--primary);
  animation: pulse-status 1.5s ease-in-out infinite;
}

.alert-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
}

.alert-status.active .alert-dot {
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

@keyframes pulse-status {
  0%, 100% { box-shadow: 0 0 0 0 rgba(233, 69, 96, 0); }
  50% { box-shadow: 0 0 0 8px rgba(233, 69, 96, 0.15); }
}

/* Player count */
.player-count {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  background: rgba(255, 193, 7, 0.12);
  border: 1px solid rgba(255, 193, 7, 0.3);
  padding: 10px 24px;
  border-radius: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.player-count.hidden {
  display: none;
}

#player-count-value {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--streak);
}

/* Join form */
.join-form {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.join-form label {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-weight: 500;
}

.join-form input {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 1.1rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
  direction: rtl;
}

.join-form input:focus {
  border-color: var(--primary);
}

.join-form input::placeholder {
  color: rgba(255, 255, 255, 0.25);
}

/* Primary button */
.btn-primary {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: white;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
  margin-top: 8px;
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Invite button */
.btn-invite {
  width: 100%;
  padding: 14px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: transparent;
  color: var(--text-dim);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-invite:active {
  background: rgba(255, 255, 255, 0.06);
}

/* Install hint */
.install-hint {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s;
  padding: 8px 16px;
}

.install-hint:active {
  opacity: 1;
}

.install-hint.hidden {
  display: none;
}

/* --- Screen 2: Play --- */
#screen-play {
  background-color: var(--bg-dark);
}

.play-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.score-display, .streak-display, .question-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.score-label, .streak-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.score-value {
  font-size: 1.6rem;
  font-weight: 900;
}

.streak-value {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--streak);
}

.streak-display.hot .streak-value {
  text-shadow: 0 0 12px rgba(255, 193, 7, 0.7);
  animation: streak-glow 0.6s ease-in-out infinite alternate;
}

@keyframes streak-glow {
  from { text-shadow: 0 0 8px rgba(255, 193, 7, 0.4); }
  to { text-shadow: 0 0 20px rgba(255, 193, 7, 0.8); }
}

.question-counter {
  font-size: 0.85rem;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.08);
  padding: 6px 14px;
  border-radius: 20px;
}

/* Live players floating indicator */
.live-players-float {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  padding: 6px 14px;
  border-radius: 20px;
  z-index: 5;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--correct);
  box-shadow: 0 0 6px var(--correct);
  animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

#live-players-value {
  color: var(--text);
  font-weight: 700;
}

/* Play body */
.play-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 20px;
  gap: 16px;
  background: radial-gradient(ellipse at center, rgba(10, 10, 30, 0.7) 0%, transparent 80%);
}

.difficulty-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.diff-easy {
  background: rgba(0, 200, 83, 0.2);
  color: var(--correct);
  border: 1px solid rgba(0, 200, 83, 0.4);
}

.diff-medium {
  background: rgba(255, 193, 7, 0.2);
  color: var(--streak);
  border: 1px solid rgba(255, 193, 7, 0.4);
}

.diff-hard {
  background: rgba(233, 69, 96, 0.2);
  color: var(--primary);
  border: 1px solid rgba(233, 69, 96, 0.4);
}

.question-text {
  font-size: 1.7rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.5;
  max-width: 600px;
  padding: 8px 16px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

/* Options */
.options-container {
  width: 100%;
  max-width: 500px;
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
  gap: 12px;
}

.option-btn {
  width: 100%;
  padding: 8px 12px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  background: rgba(20, 20, 40, 0.88);
  backdrop-filter: blur(12px);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  line-height: 1.3;
  min-height: 56px;
}

.option-btn:active {
  transform: scale(0.97);
}

.option-btn.correct {
  background: rgba(0, 200, 83, 0.35);
  border-color: var(--correct);
  color: var(--correct);
  animation: btnFlashCorrect 0.3s ease-out;
}

.option-btn.wrong {
  background: rgba(255, 23, 68, 0.35);
  border-color: var(--wrong);
  color: var(--wrong);
  animation: btnFlashWrong 0.3s ease-out;
}

@keyframes btnFlashCorrect {
  0% { background: rgba(0, 200, 83, 0.7); transform: scale(1.03); }
  100% { background: rgba(0, 200, 83, 0.35); transform: scale(1); }
}

@keyframes btnFlashWrong {
  0% { background: rgba(255, 23, 68, 0.7); transform: scale(0.97); }
  100% { background: rgba(255, 23, 68, 0.35); transform: scale(1); }
}

/* All options stack vertically, same width */

/* Score pop animations */
.score-pop {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 2.2rem;
  pointer-events: none;
  z-index: 200;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  animation: scorePop 0.7s ease-out forwards;
}

.pop-correct {
  color: var(--correct);
}

.pop-wrong {
  color: var(--wrong);
  font-size: 2.8rem;
}

.pop-bonus {
  color: var(--streak);
  font-size: 1.6rem;
  animation: scorePop 1s ease-out forwards;
}

.pop-penalty {
  color: var(--wrong);
  font-size: 1.4rem;
  animation: scorePop 0.8s ease-out forwards;
}

@keyframes scorePop {
  0% {
    opacity: 1;
    transform: translate(-50%, 40%) scale(0.5);
  }
  25% {
    opacity: 1;
    transform: translate(-50%, 0%) scale(1.4);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -160%) scale(1);
  }
}

/* Round ending notice */
.round-ending {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(233, 69, 96, 0.9);
  padding: 10px 24px;
  border-radius: 30px;
  font-size: 0.95rem;
  font-weight: 500;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.round-ending.hidden {
  display: none;
}

.grace-countdown {
  font-weight: 900;
  font-size: 1.2rem;
}

/* --- Screen 3: Results --- */
.results-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px;
  gap: 20px;
  background: rgba(26, 26, 46, 0.9);
  overflow-y: auto;
}

.results-container h2 {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--primary);
}

/* Your summary bar */
.your-summary {
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  background: var(--bg-card);
  border-radius: 14px;
  padding: 14px 8px;
  border: 1px solid rgba(233, 69, 96, 0.3);
}

.your-summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.your-summary-val {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--text);
}

.your-summary-lbl {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.your-summary-divider {
  width: 1px;
  height: 32px;
  background: rgba(255, 255, 255, 0.1);
}

/* Leaderboard section */
.leaderboard-section {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
}

.leaderboard-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.leaderboard-count {
  font-size: 0.85rem;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.08);
  padding: 4px 12px;
  border-radius: 20px;
}

/* Leaderboard rows */
.leaderboard {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: 10px;
  font-size: 0.95rem;
  transition: background 0.2s;
}

.leaderboard-row.you {
  background: rgba(233, 69, 96, 0.2);
  border: 1px solid var(--primary);
}

.leaderboard-rank {
  font-weight: 900;
  font-size: 1.2rem;
  min-width: 32px;
  text-align: center;
  color: var(--text-dim);
}

.leaderboard-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.leaderboard-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-detail {
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-score {
  font-weight: 900;
  font-size: 1.1rem;
  min-width: 36px;
  text-align: left;
}

.leaderboard-row.you .leaderboard-score {
  color: var(--primary);
}

.leaderboard-gap {
  text-align: center;
  color: var(--text-dim);
  font-size: 1.2rem;
  padding: 2px 0;
  letter-spacing: 4px;
}

/* Secondary button */
.btn-secondary {
  width: 100%;
  max-width: 420px;
  padding: 14px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.05rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-secondary:active {
  background: rgba(255, 255, 255, 0.08);
}

.results-container .btn-primary {
  max-width: 420px;
}

.next-round-hint {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-dim);
  opacity: 0.7;
  line-height: 1.5;
}

/* --- Utilities --- */
@media (max-height: 600px) {
  .logo-icon { width: 48px; height: 48px; }
  .logo h1 { font-size: 2.8rem; }
  .play-body { padding: 12px 16px; gap: 20px; }
  .question-text { font-size: 1.3rem; }
  .option-btn { padding: 14px 18px; font-size: 1rem; }
}

@media (min-width: 768px) {
  .question-text { font-size: 2rem; }
  .option-btn { font-size: 1.3rem; }
}
