/* =============================
   Modern Theme Variables
   ============================= */
:root {
  --bg-gradient-1: #1a163d;
  --bg-gradient-2: #150d2d;
  --bg-gradient-3: #24073f;
  --bg-glow: rgba(120, 64, 255, 0.16);
  --surface: rgba(28, 20, 53, 0.68);
  --surface-2: rgba(41, 25, 70, 0.76);
  --surface-3: rgba(28, 19, 49, 0.55);
  --border: rgba(138, 112, 255, 0.28);
  --border-strong: rgba(130, 76, 255, 0.65);
  --text: #f7f7ff;
  --text-soft: rgba(247, 247, 255, 0.82);
  --primary-500: #7c5cff;
  --primary-600: rgba(139,92,246,0.95);
  --primary-700: #5a34f2;
  --primary-800: rgba(43,0,80,0.95);
  --accent-500: #2dd4bf;
  --accent-600: #14b8a6;
  --glow-1: rgba(122, 76, 255, 0.55);
  --glow-2: rgba(45, 212, 191, 0.55);
  --success-500: #34d399;
  --danger-500: #fb7185;
  --gold-500: #facc15;
  --glass-blur: 20px;
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 22px;
  --shadow-sm: 0 12px 22px rgba(10, 5, 30, 0.25);
  --shadow-md: 0 18px 38px rgba(9, 8, 30, 0.38);
  --shadow-lg: 0 40px 80px rgba(4, 2, 20, 0.5);
  --transition-fast: 160ms ease;
  --transition-mid: 280ms cubic-bezier(.21,.98,.6,1.01);
}

/* =============================
   Base & Layout
   ============================= */
body {
  margin: 0;
  font-family: 'Cairo', sans-serif;
  background: radial-gradient(circle at 20% 20%, var(--bg-gradient-1) 0%, var(--bg-gradient-2) 40%, var(--bg-gradient-3) 100%);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--glow-1) 0%, transparent 70%);
  filter: blur(0px);
  opacity: 0.6;
  pointer-events: none;
  z-index: -2;
  animation: floatGlow 18s var(--transition-mid) infinite;
}

body::before {
  top: -140px;
  right: -120px;
}

body::after {
  bottom: -160px;
  left: -140px;
  background: radial-gradient(circle, var(--glow-2) 0%, transparent 70%);
  animation-delay: -9s;
}



.background-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 80px 80px;
  opacity: 0.25;
  z-index: -3;
  mask-image: radial-gradient(circle at center, rgba(255,255,255,0.9), transparent 80%);
}

.background-logo {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: url('img/bg.png') no-repeat center;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  opacity: 0.1;
  mix-blend-mode: screen;
  filter: drop-shadow(0 25px 55px rgba(54, 0, 94, 0.45));
  z-index: -1;
}

#top-navbar {
  height: 72px;
  background: linear-gradient(135deg, rgba(18, 3, 46, 0.88), rgba(38, 19, 79, 0.66));
  border-bottom: 1px solid rgba(140, 111, 255, 0.28);
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 0 28px;
  backdrop-filter: blur(var(--glass-blur));
  position: relative;
  top: 0;
  inset-inline: 0;
  z-index: 1500;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transform: translateY(-20px);
  animation: fadeInNavbar 0.5s ease forwards;
}

.navbar-left,
.navbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.navbar-right {
  margin-left: 88px;
}

.game-logo {
  height: 40px;
  border-radius: var(--radius-sm);
}

.info-btn {
  background: rgba(124, 92, 255, 0.14);
  border: 1px solid rgba(124, 92, 255, 0.32);
  font-size: 20px;
  color: var(--text);
  cursor: pointer;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: inset 0 0 12px rgba(124, 92, 255, 0.15);
}
.info-btn:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 0 22px rgba(124, 92, 255, 0.45); }

.main-container {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  gap: 24px;
  padding: 28px 32px 38px;
  position: relative;
  z-index: 2;
}

.sidebar {
  position: relative;
  padding: 20px;
  background: linear-gradient(160deg, rgba(32, 16, 68, 0.88), rgba(20, 12, 46, 0.74));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  backdrop-filter: blur(var(--glass-blur));
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  isolation: isolate;
  opacity: 0;
  transform: translateX(20px);
  animation: fadeInSidebar 0.6s ease forwards;
}

.sidebar.left {
  animation-delay: 0.2s;
}

.sidebar.right {
  animation-delay: 0.3s;
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: -80% -40% auto;
  height: 60%;
  background: radial-gradient(circle, rgba(124, 92, 255, 0.35) 0%, transparent 70%);
  transform: translateY(-40%);
  opacity: 0.6;
  pointer-events: none;
  z-index: -1;
  animation: auroraSweep 16s ease-in-out infinite;
}

.sidebar h2 {
  margin: 0;
  padding-bottom: 14px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: var(--text);
  position: relative;
}

.sidebar h2::after {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  bottom: 0;
  inline-size: 72px;
  block-size: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary-600), var(--primary-800));
  box-shadow: 0 0 12px rgba(124, 92, 255, 0.35);
}

.sidebar.left { border-inline-end: 0; }
.sidebar.right { border-inline-start: 0; }

#game-container {
  position: relative;
  background: linear-gradient(150deg, rgba(24, 14, 52, 0.88), rgba(28, 19, 48, 0.72));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  text-align: center;
  display: block;
  overflow: hidden;
  isolation: isolate;
  opacity: 0;
  transform: scale(0.95);
  animation: fadeInGameContainer 0.5s ease forwards;
}

#game-container::before {
  content: "";
  position: absolute;
  inset: -60% 20% auto;
  height: 70%;
  background: radial-gradient(circle, rgba(45, 212, 191, 0.32) 0%, transparent 65%);
  opacity: 0.7;
  filter: blur(0px);
  pointer-events: none;
  animation: driftGlow 22s linear infinite;
}

#twitch-login-screen,
#rounds-selection-screen {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 72px);
}

.login-container,
.rounds-container {
  min-width: fit-content;
  inline-size: min(100%, 540px);
  background: linear-gradient(150deg, rgba(24, 12, 58, 0.28), rgba(18, 10, 38, 0.42));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.login-container::before,
.rounds-container::before {
  content: "";
  position: absolute;
  inset: auto 12% -40% 12%;
  height: 60%;
  background: radial-gradient(circle, rgba(124, 92, 255, 0.35) 0%, transparent 65%);
  opacity: 0.8;
  filter: blur(0px);
  pointer-events: none;
}

.login-container h1,
.rounds-container h1 {
  margin: 0 0 22px 0;
  font-size: 30px;
  line-height: 1.3;
  color: var(--text);
  text-shadow: 0 10px 32px rgba(0, 0, 0, 0.35);
}

/* =============================
   Buttons
   ============================= */
.twitch-btn,
#confirm-rounds-btn,
#logout-btn,
#reset-btn,
#new-game-btn,
#end-game-logout-btn,
#show-answers-btn,
#next-btn,
#close-modal-btn {
  position: relative;
  background: linear-gradient(120deg, var(--primary-600), var(--primary-700) 48%);
  color: var(--text);
  border: 0;
  border-radius: var(--radius-md);
  padding: 14px 26px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 18px 35px rgba(88, 64, 210, 0.35);
  transition: transform var(--transition-fast), box-shadow var(--transition-mid), filter var(--transition-fast);
  letter-spacing: 0.2px;
  overflow: hidden;
  isolation: isolate;
}
.twitch-btn:hover,
#confirm-rounds-btn:hover,
#logout-btn:hover,
#reset-btn:hover,
#new-game-btn:hover,
#end-game-logout-btn:hover,
#show-answers-btn:hover,
#next-btn:hover,
#close-modal-btn:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 22px 48px rgba(88, 64, 210, 0.45);
  filter: brightness(1.08);
}

.twitch-btn::after,
#confirm-rounds-btn::after,
#logout-btn::after,
#reset-btn::after,
#new-game-btn::after,
#end-game-logout-btn::after,
#show-answers-btn::after,
#next-btn::after,
#close-modal-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, rgba(255,255,255,0.22), transparent 40%);
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.twitch-btn:hover::after,
#confirm-rounds-btn:hover::after,
#logout-btn:hover::after,
#reset-btn:hover::after,
#new-game-btn:hover::after,
#end-game-logout-btn:hover::after,
#show-answers-btn:hover::after,
#next-btn:hover::after,
#close-modal-btn:hover::after {
  opacity: 0.7;
}

#logout-btn,
#reset-btn {
  background: linear-gradient(140deg, rgba(43, 28, 84, 0.92), rgba(28, 13, 56, 0.82));
  border: 1px solid rgba(120, 94, 255, 0.4);
  box-shadow: 0 12px 28px rgba(17, 12, 40, 0.45);
}

#show-answers-btn {
  display: block;
  margin: 32px auto 0;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#show-answers-btn.show {
  opacity: 1;
  transform: translateY(0);
}

#show-answers-btn.hide {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

#next-btn {
  display: block;
  margin: -32px 0 0 auto;
  opacity: 0;
  transform: translateY(10px) scale(0.95);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

#next-btn.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

#rounds-input {
  width: 120px;
  text-align: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text);
  font-size: 16px;
}

.rounds-input-container { display: grid; gap: 14px; justify-items: center; }

.settings-row {
  display: flex;
  align-items: center;
  gap: 24px;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.settings-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-row label {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.settings-row input[type="number"],
.settings-row select {
  width: 100px;
  text-align: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.settings-row select {
  text-align: center;
  text-align-last: center;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23f7f7ff' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 32px;
}

.settings-row select:hover {
  border-color: rgba(127, 99, 255, 0.5);
  box-shadow: 0 0 8px rgba(124, 92, 255, 0.2);
}

.settings-row select:focus {
  outline: none;
  border-color: var(--primary-600);
  box-shadow: 0 0 12px rgba(124, 92, 255, 0.3);
}

/* =============================
   Cards grid
   ============================= */
#question-text {
  font-size: clamp(28px, 4vw, 24px);
  margin-bottom: 26px;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: transparent;
  background: linear-gradient(90deg, var(--text) 0%, rgba(255,255,255,0.65) 45%);
  -webkit-background-clip: text;
  background-clip: text;
  text-shadow: 0 18px 32px rgba(0, 0, 0, 0.45);
  opacity: 1;
  min-height: 1.5em;
}

#question-text.typing {
  opacity: 1;
}

#question-text.typing::after {
  content: '|';
  animation: blinkCursor 1s infinite;
}

/* =============================
   Progress Bar & Timer
   ============================= */
#question-progress-container {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  width: 100%;
}

#question-progress-bar {
  flex: 1;
  height: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(127, 99, 255, 0.2);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

#question-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-600), var(--accent-500));
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 12px rgba(124, 92, 255, 0.5);
  position: relative;
  overflow: hidden;
}

#question-progress-fill::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

#question-counter {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  padding: 6px 14px;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.2), rgba(45, 212, 191, 0.2));
  border: 1px solid rgba(127, 99, 255, 0.3);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#timer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  background: linear-gradient(135deg, rgba(38, 20, 76, 0.9), rgba(24, 14, 52, 0.82));
  border: 1px solid rgba(127, 99, 255, 0.4);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(11, 7, 24, 0.35);
  white-space: nowrap;
}

#timer-display {
  font-size: 24px;
  font-weight: 900;
  color: var(--accent-500);
  text-shadow: 0 0 15px rgba(45, 212, 191, 0.6);
  line-height: 1;
  transition: color 0.3s ease;
}

#timer-container.warning #timer-display {
  color: var(--gold-500);
  text-shadow: 0 0 20px rgba(250, 204, 21, 0.6);
}

#timer-container.danger #timer-display {
  color: var(--danger-500);
  text-shadow: 0 0 20px rgba(251, 113, 133, 0.6);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

#timer-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#cards-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, 200px);
  gap: 22px;
  align-items: stretch;
  justify-content: center;
  justify-items: center;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

#cards-container.show {
  opacity: 1;
  transform: translateY(0);
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 8px;
  width: 200px;
  height: 100px;
  background: linear-gradient(160deg, rgba(31, 21, 56, 0.9), rgba(25, 18, 44, 0.75));
  border: 1px solid rgba(127, 99, 255, 0.35);
  border-radius: var(--radius-md);
  box-shadow: 0 18px 35px rgba(11, 7, 26, 0.45);
  cursor: pointer;
  transition: transform var(--transition-mid), box-shadow var(--transition-mid), border-color var(--transition-fast);
  overflow: hidden;
  box-sizing: border-box;
  opacity: 0;
  transform: translateY(20px) scale(0.9);
  animation: cardAppear 0.5s ease forwards;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% -10%, rgba(124, 92, 255, 0.22) 0%, transparent 70%);
  opacity: 0.6;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}

.card:hover {
  transform: translateY(-6px) scale(1.01);
  box-shadow: 0 24px 48px rgba(11, 7, 26, 0.55), 0 0 32px rgba(120, 94, 255, 0.25);
  border-color: rgba(127, 99, 255, 0.55);
}

.card:hover::before { opacity: 0.85; }

.card.flipped {
  background: linear-gradient(135deg, var(--primary-600), var(--primary-800));
  border-color: rgba(144, 118, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.12), 0 0 42px rgba(124, 92, 255, 0.45);
  animation: cardFlip 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.card-user { 
  font-size: 10px; 
  opacity: 0.9; 
  line-height: 1.2;
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-answer {
  font-size: clamp(10px, 4vw, 18px);
  font-weight: 900;
  margin: 4px 0;
  color: var(--text);
  text-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  line-height: 1.2;
  text-align: center;
  width: 100%;
  overflow: hidden;
  word-wrap: break-word;
  hyphens: auto;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-points { 
  font-size: 10px; 
  opacity: 0.9; 
  line-height: 1.2;
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card.gold-answer {
  outline: 2px solid rgba(250, 204, 21, 0.55);
  box-shadow: 0 0 24px rgba(250, 204, 21, 0.35);
  background: linear-gradient(135deg, #fde68a33, #f59e0b33);
}

.card.block-answer {
  outline: 2px solid rgba(239, 68, 68, 0.55);
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.35);
  background: linear-gradient(135deg, #fecaca33, #ef444433);
}

.card.powerup-card {
  color: var(--text);
  border-style: dashed;
  border-width: 2px;
  border-color: rgba(255,255,255,0.65);
  background: linear-gradient(135deg, rgba(108, 92, 231, 0.85), rgba(0, 206, 201, 0.85));
  box-shadow: 0 0 38px rgba(13, 148, 136, 0.45);
}
.card.powerup-card .card-instructions { margin-top: 28px; font-size: 13px; opacity: .95; }
.card.powerup-card .card-user { color: #fffa65; font-weight: 800; }
.card.powerup-card::after {
  opacity: 50%;
  content: "🎮 Power Up";
  position: absolute;
  top: 8px;
  inset-inline-end: 8px;
  font-size: 12px;
  background: #00ffc3;
  color: #000;
  padding: 2px 6px;
  border-radius: 6px;
}

/* =============================
   Leaderboard & Chat
   ============================= */
#leaderboard { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }

.leaderboard-entry {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: linear-gradient(145deg, rgba(32, 20, 68, 0.92), rgba(14, 7, 32, 0.78));
  border: 1px solid rgba(127, 99, 255, 0.25);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 24px rgba(10, 5, 28, 0.45);
  font-weight: 800;
  font-size: 15px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  opacity: 0;
  transform: translateY(10px);
  animation: fadeInUp 0.4s ease forwards;
}

.leaderboard-entry:nth-child(1) { animation-delay: 0.1s; }
.leaderboard-entry:nth-child(2) { animation-delay: 0.15s; }
.leaderboard-entry:nth-child(3) { animation-delay: 0.2s; }
.leaderboard-entry:nth-child(4) { animation-delay: 0.25s; }
.leaderboard-entry:nth-child(5) { animation-delay: 0.3s; }
.leaderboard-entry:nth-child(n+6) { animation-delay: 0.35s; }
.leaderboard-entry.gold { background: linear-gradient(135deg, rgba(250, 204, 21, 0.35), rgba(253, 230, 138, 0.18)); border-color: rgba(250, 204, 21, 0.45); box-shadow: 0 16px 32px rgba(250, 204, 21, 0.25); }
.leaderboard-entry.silver { background: linear-gradient(135deg, rgba(226, 232, 240, 0.35), rgba(209, 213, 219, 0.15)); border-color: rgba(226, 232, 240, 0.4); }
.leaderboard-entry.bronze { background: linear-gradient(135deg, rgba(245, 158, 11, 0.35), rgba(217, 119, 6, 0.18)); border-color: rgba(245, 158, 11, 0.35); }

#chat-box { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; max-height: 70vh; }
.chat-message {
  background: linear-gradient(135deg, rgba(34, 19, 68, 0.82), rgba(25, 17, 48, 0.74));
  border: 1px solid rgba(118, 92, 255, 0.35);
  border-radius: var(--radius-sm);
  padding: 12px 15px;
  box-shadow: 0 10px 28px rgba(11, 6, 26, 0.42);
  font-size: 14px;
  opacity: 0;
  transform: translateX(24px);
  animation: slideIn .35s ease forwards;
}
.chat-message.correct-answer { border-inline-start: 4px solid var(--primary-600); background: rgba(34,197,94,0.12); box-shadow: 0 0 12px rgba(34,197,94,0.25); }
.chat-message strong { color: var(--gold-500); }
.chat-message.fade-out { opacity: 0; transform: translateY(-6px); transition: opacity .8s ease, transform .4s ease; }

@keyframes slideIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }

@keyframes floatGlow {
  0% { transform: translate(0, 0) scale(1); opacity: 0.55; }
  25% { transform: translate(-20px, 12px) scale(1.05); opacity: 0.65; }
  50% { transform: translate(-10px, -18px) scale(1); opacity: 0.5; }
  75% { transform: translate(18px, 10px) scale(1.08); opacity: 0.68; }
  100% { transform: translate(0, 0) scale(1); opacity: 0.55; }
}

@keyframes driftGlow {
  0% { transform: translate(-10%, -8%) scale(1); }
  50% { transform: translate(-4%, 4%) scale(1.08); }
  100% { transform: translate(-10%, -8%) scale(1); }
}

@keyframes auroraSweep {
  0% { transform: translateY(-40%) rotate(0deg); opacity: 0.4; }
  50% { transform: translateY(-20%) rotate(2deg); opacity: 0.7; }
  100% { transform: translateY(-40%) rotate(0deg); opacity: 0.4; }
}

/* =============================
   Category selection
   ============================= */
#category-selection-container { margin-top: 20px; width: 100%; }
#category-selection-container h2 {
  margin: 0 0 14px 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 12px 28px rgba(2, 1, 12, 0.45);
}
#categories-list { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }

.category-item {
  width: 140px;
  background: linear-gradient(140deg, rgba(30, 17, 62, 0.85), rgba(19, 11, 40, 0.7));
  border: 1px solid rgba(127, 99, 255, 0.28);
  border-radius: var(--radius-md);
  padding: 16px 14px;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-mid), border-color var(--transition-fast);
  box-shadow: 0 12px 28px rgba(12, 6, 28, 0.4);
}
.category-item:hover {
  transform: translateY(-6px);
  box-shadow: 0 18px 38px rgba(12, 6, 28, 0.55);
  border-color: rgba(127, 99, 255, 0.55);
}
.category-item.selected {
  border-color: var(--primary-600);
  background: linear-gradient(140deg, rgba(124, 92, 255, 0.42), rgba(94, 234, 212, 0.25));
  box-shadow: 0 0 28px rgba(124, 92, 255, 0.35);
}
.category-item h3 { margin: 0 0 8px 0; font-size: 16px; text-align: center; }
.category-progress-container { height: 8px; background: rgba(255,255,255,0.12); border-radius: 999px; overflow: hidden; }
.category-progress-bar { height: 100%; width: 0%; background: #00ff8c; transition: width .4s ease; }

/* =============================
   Modals & Notifications
   ============================= */
.modal { display: none; position: fixed; inset: 0; z-index: 3000; background: rgba(0,0,0,0.55); backdrop-filter: blur(4px); }
.modal-content {
  width: min(92%, 420px);
  margin: 10% auto;
  background: linear-gradient(150deg, rgba(26, 16, 58, 0.92), rgba(18, 10, 38, 0.82));
  border: 1px solid rgba(118, 92, 255, 0.35);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  color: var(--text);
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.close-btn { position: absolute; top: 10px; inset-inline-start: 12px; font-size: 22px; cursor: pointer; }

#notification-bar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: linear-gradient(120deg, rgba(38, 20, 76, 0.9), rgba(24, 14, 52, 0.82));
  border: 1px solid rgba(127, 99, 255, 0.44);
  border-radius: 999px;
  padding: 14px 24px;
  font-weight: 800;
  letter-spacing: 0.3px;
  box-shadow: 0 20px 38px rgba(11, 7, 24, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s ease, transform .35s ease;
}
#notification-bar.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* =============================
   End screen
   ============================= */
#end-game-screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,0.55); }
#end-screen {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  min-width: 300px;
  max-width: 520px;
  animation: fadeIn .6s ease forwards;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

@keyframes cardFlip {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  30% {
    transform: scale(0.75);
    opacity: 0.6;
  }
  60% {
    transform: scale(1.05);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes cardAppear {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes blinkCursor {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInSidebar {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeInGameContainer {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fadeInNavbar {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
#final-leaderboard { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; align-items: stretch; }
#end-game-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }

/* =============================
   Utilities
   ============================= */
#bottom-buttons { display: none !important; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,0.04); border-radius: 999px; }
::-webkit-scrollbar-thumb { background: linear-gradient(180deg, rgba(124, 92, 255, 0.7), rgba(14, 165, 233, 0.7)); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, rgba(124, 92, 255, 0.85), rgba(14, 165, 233, 0.85)); }

.back-btn {
  position: fixed;
  top: 15px;
  left: 15px;
  padding: 6px 12px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  border-radius: 10px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  z-index: 999999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  transition: .25s ease;
}

.back-btn:hover {
  transform: translateX(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}

.back-btn .arrow {
  width: 16px;
  height: 16px;
}

/* =============================
   Responsive
   ============================= */
@media (max-width: 1200px) {
  .main-container { grid-template-columns: 240px 1fr 280px; }
}

@media (max-width: 960px) {
  .main-container { grid-template-columns: 1fr; }
  .sidebar.left, .sidebar.right { order: 2; }
  #game-container { order: 1; }
  #categories-list { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 600px) {
  #categories-list { grid-template-columns: repeat(2, 1fr); }
}

/* Preserve runtime visibility toggling by JS */
#chat-sidebar, #leaderboard-sidebar { display: none; }

/* =============================
   New Game Shop Button
   ============================= */
#shop-container {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid rgba(127, 99, 255, 0.2);
}

#shop-container h3 {
  margin: 0 0 12px 0;
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

#shop-container ul {
  list-style: none;
  padding: 0;
  margin: 0 0 16px 0;
}

#shop-container li {
  padding: 8px 12px;
  margin-bottom: 8px;
  background: rgba(32, 20, 68, 0.5);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-soft);
}

#shop-container code {
  background: rgba(124, 92, 255, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  color: var(--primary-600);
}

.new-game-shop-btn {
  position: relative;
  width: 100%;
  margin-top: 12px;
  background: linear-gradient(120deg, var(--primary-600), var(--primary-700) 48%);
  color: var(--text);
  border: 0;
  border-radius: var(--radius-md);
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(88, 64, 210, 0.35);
  transition: transform var(--transition-fast), box-shadow var(--transition-mid), filter var(--transition-fast);
  letter-spacing: 0.2px;
  overflow: hidden;
  isolation: isolate;
  font-family: 'Cairo', sans-serif;
}

.new-game-shop-btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 18px 38px rgba(88, 64, 210, 0.45);
  filter: brightness(1.08);
}

.new-game-shop-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, rgba(255,255,255,0.22), transparent 40%);
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.new-game-shop-btn:hover::after {
  opacity: 0.7;
}

