/* ===== FAKKAR — BASE, BOARD, QUESTION & SHARED UI ===== */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}

button { font-family: inherit; }
button:focus-visible,
input:focus-visible,
[role="button"]:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ===== BACKGROUND ===== */
.animated-bg { position: fixed; inset: 0; z-index: -1; background: var(--bg); overflow: hidden; }
.animated-bg::before,
.animated-bg::after { content: ''; position: absolute; border-radius: 50%; }
.animated-bg::before {
  width: 600px; height: 600px;
  background: radial-gradient(circle, var(--primary-glow) 0%, transparent 70%);
  top: -200px; right: -100px;
  animation: bgFloat1 12s ease-in-out infinite;
}
.animated-bg::after {
  width: 500px; height: 500px;
  background: radial-gradient(circle, var(--indigo-glow) 0%, transparent 70%);
  bottom: -150px; left: -100px;
  animation: bgFloat2 15s ease-in-out infinite;
}

/* ===== SCREENS ===== */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  z-index: 5;
}
.screen.active { display: flex; animation: screenIn 0.45s cubic-bezier(0.4, 0, 0.2, 1); }
#lobbyScreen,
#categorySelectionScreen { padding: 0; align-items: stretch; justify-content: stretch; }

/* ===== THEME TOGGLE ===== */
.theme-toggle {
  flex-shrink: 0;
  width: 48px; height: 48px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  transition: var(--transition);
}
.theme-toggle:hover { transform: scale(1.1); box-shadow: var(--shadow-md); }
.theme-toggle.floating { position: fixed; top: 20px; inset-inline-end: 20px; z-index: 1000; }
/* Lobby + selection headers carry their own toggle; the board header has no room for one */
body[data-screen="lobbyScreen"] .theme-toggle.floating,
body[data-screen="categorySelectionScreen"] .theme-toggle.floating,
body[data-screen="categoriesScreen"] .theme-toggle.floating { display: none; }

/* ===== BACK BUTTON ===== */
.back-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.7rem 1.4rem;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-2); font-size: 1rem; font-weight: 600;
  cursor: pointer; transition: var(--transition); box-shadow: var(--shadow-sm);
}
.back-btn:hover { border-color: var(--primary); color: var(--primary-dark); transform: translateX(-2px); }

/* ===== GAME BOARD ===== */
#categoriesScreen { flex-direction: column; padding: 0; align-items: stretch; justify-content: flex-start; }

.game-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 15;
}
.game-back-btn { font-size: 0.8rem; padding: 0.45rem 0.9rem; flex-shrink: 0; }

.scoreboard { display: flex; justify-content: space-between; align-items: center; flex: 1; gap: 1rem; min-width: 0; }

.team-score {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--surface-2); border: 1.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 0.6rem 1.2rem;
  min-width: 220px; transition: var(--transition);
}
.team-score.team-alpha { border-inline-start: 4px solid var(--primary); }
.team-score.team-beta  { border-inline-start: 4px solid var(--indigo); }

.score-content { flex: 1; min-width: 0; }
.score-content h3 {
  font-size: 0.85rem; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 0.1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.score { font-size: 1.8rem; font-weight: 800; font-family: var(--font-display); color: var(--text); }
.team-icon { font-size: 1.6rem; }

.score-controls { display: flex; flex-direction: column; gap: 3px; }
.score-btn {
  width: 32px; height: 22px; border: none; border-radius: 6px;
  font-size: 0.9rem; font-weight: 800; line-height: 1; color: white;
  cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.score-btn.add      { background: var(--green); }
.score-btn.subtract { background: var(--red); }
.score-btn:hover    { transform: scale(1.12); }

.turn-indicator {
  background: var(--primary); color: var(--text-inv);
  padding: 0.7rem 2rem; border-radius: var(--radius-full);
  font-size: 1.1rem; font-weight: 700; font-family: var(--font-display);
  box-shadow: 0 4px 16px var(--primary-glow);
  animation: pulse 2.5s ease-in-out infinite;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%;
}

.categories-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(auto, 1fr);
  gap: 1rem;
  padding: 1rem 1.25rem 1.25rem;
  overflow-y: auto;
}

.category {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem; display: flex; flex-direction: column; transition: var(--transition);
}
.category:hover { box-shadow: var(--shadow-md); border-color: var(--primary); }

.category-header {
  display: flex; align-items: center; gap: 0.7rem;
  margin-bottom: 0.75rem; padding-bottom: 0.7rem;
  border-bottom: 1.5px solid var(--border);
}
.category-icon { font-size: 1.5rem; }
.category h3 {
  font-size: 1.05rem; font-weight: 800; font-family: var(--font-display); color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.category-columns { display: flex; gap: 0.75rem; flex: 1; }
.point-options { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }

.team-label {
  flex-shrink: 0;
  font-size: 0.75rem; font-weight: 700; text-align: center;
  padding: 0.4rem; border-radius: var(--radius-sm); margin-bottom: 0.2rem;
  text-transform: uppercase; letter-spacing: 0.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.point-options:first-child .team-label { background: rgba(245,166,35,0.12); color: var(--primary-dark); }
.point-options:last-child  .team-label { background: var(--indigo-glow); color: var(--indigo); }

.point-option {
  flex: 1; border: 1.5px solid var(--border);
  border-radius: var(--radius-md); background: var(--surface-2);
  color: var(--text); font-size: 1.4rem; font-weight: 800;
  font-family: var(--font-display); cursor: pointer;
  transition: var(--transition); display: flex;
  align-items: center; justify-content: center; min-height: 40px;
}
.point-option:hover:not(:disabled) {
  background: var(--primary); border-color: var(--primary); color: white;
  transform: scale(1.04); box-shadow: 0 4px 14px var(--primary-glow);
}
.point-option:disabled { opacity: 0.2; cursor: not-allowed; }

/* Highlight the team whose turn it is */
.categories-grid[data-turn="0"] .point-options:first-child .point-option:not(:disabled),
.categories-grid[data-turn="1"] .point-options:last-child  .point-option:not(:disabled) {
  border-color: var(--primary);
  animation: teamGlow 2.5s ease-in-out infinite;
}

/* ===== QUESTION ===== */
.question-card {
  max-width: 800px; width: 100%; max-height: 100%; overflow-y: auto;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-xl);
  padding: 3rem; text-align: center;
}

.question-meta { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1.5rem; }
.q-team, .q-points, .q-category {
  padding: 0.4rem 1.1rem;
  border-radius: var(--radius-full);
  font-size: 0.9rem; font-weight: 700;
  font-family: var(--font-display);
  border: 1.5px solid;
}
.q-team     { background: var(--primary-glow); border-color: var(--primary); color: var(--primary-dark); }
.q-points   { background: var(--indigo-glow); border-color: var(--indigo); color: var(--indigo); }
.q-category { background: var(--surface-2); border-color: var(--border); color: var(--text-2); font-family: var(--font-body); }

.timer-container { display: flex; justify-content: center; margin-bottom: 2rem; }
.timer-ring {
  --progress: 0deg;
  position: relative; width: 110px; height: 110px; border-radius: 50%; padding: 5px;
  background: conic-gradient(var(--primary) var(--progress), var(--border) 0deg);
}
.timer-fill { width: 100%; height: 100%; border-radius: 50%; background: var(--surface); }
.timer-content { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.timer-label { font-size: 0.7rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }
.timer { font-size: 2rem; font-weight: 800; font-family: var(--font-display); color: var(--text); }

.question-text {
  font-size: 1.8rem; font-weight: 700; line-height: 1.5; color: var(--text);
  margin-bottom: 1.5rem; font-family: var(--font-display);
  overflow-wrap: anywhere;
}
.answer-container {
  display: none;
  background: linear-gradient(135deg, rgba(16,185,129,0.08), rgba(16,185,129,0.04));
  border: 2px solid var(--green); border-radius: var(--radius-lg);
  padding: 1.6rem; margin: 1.5rem 0; font-size: 1.5rem; font-weight: 700;
  color: var(--text); font-family: var(--font-display);
  overflow-wrap: anywhere;
}
.answer-container.visible { display: block; animation: slideUp 0.4s ease; }
.question-image { display: block; max-width: 100%; max-height: 40vh; height: auto; margin: 1rem auto 0; border-radius: var(--radius-md); }

.question-controls { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; margin-top: 1.5rem; }

.control-btn {
  padding: 0.9rem 1.8rem; font-size: 1rem; font-weight: 700;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full); cursor: pointer; transition: var(--transition);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm);
}
.control-btn:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.control-btn.primary { background: var(--primary); border-color: var(--primary); color: white; box-shadow: 0 4px 14px var(--primary-glow); }
.control-btn.primary:hover { background: var(--primary-dark); }
.control-btn.secondary { background: var(--indigo); border-color: var(--indigo); color: white; }
.timer-btn { background: var(--surface-2); color: var(--text-2); }

/* ===== WHO GOT IT ===== */
.answer-control-card,
.winner-card {
  max-width: 520px; width: 100%;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-xl);
  padding: 3rem; text-align: center;
}
.answer-control-card h2 { font-size: 1.8rem; font-weight: 800; font-family: var(--font-display); color: var(--text); margin-bottom: 2rem; }

.team-buttons { display: flex; flex-direction: column; gap: 1rem; }
.team-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 1.2rem 1.5rem; font-size: 1.05rem; font-weight: 700;
  border: none; border-radius: var(--radius-lg); cursor: pointer; transition: var(--transition);
}
.team-btn:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.team-btn.alpha   { background: var(--primary); color: white; }
.team-btn.beta    { background: var(--indigo); color: white; }
.team-btn.neutral { background: var(--surface-2); color: var(--text-2); border: 1.5px solid var(--border); }
.btn-icon { font-size: 1.3rem; }

/* ===== WINNER ===== */
.winner-card { padding: 3.5rem 2rem; }
.winner-animation { font-size: 4rem; display: flex; justify-content: center; gap: 1rem; margin-bottom: 1.5rem; }
.trophy { animation: bounce 1.5s ease-in-out infinite; }
.celebration { animation: wiggle 0.8s ease-in-out infinite; }
.winner-message { font-size: 1.8rem; font-weight: 800; font-family: var(--font-display); color: var(--text); margin-bottom: 1.5rem; line-height: 1.3; overflow-wrap: anywhere; }

.final-scores { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 2rem; }
.final-score {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.8rem 1.2rem; border-radius: var(--radius-md);
  background: var(--surface-2); border: 1.5px solid var(--border);
  font-weight: 700;
}
.final-score.alpha { border-inline-start: 4px solid var(--primary); }
.final-score.beta  { border-inline-start: 4px solid var(--indigo); }
.final-score-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.final-score-points { font-family: var(--font-display); font-size: 1.3rem; color: var(--text); }

/* ===== NOTIFICATIONS ===== */
.notification {
  position: fixed; bottom: 20px; inset-inline-end: 20px; z-index: 9999;
  max-width: min(360px, calc(100vw - 40px));
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem 1.4rem; color: var(--text);
  box-shadow: var(--shadow-lg);
  transform: translateY(20px); opacity: 0; pointer-events: none;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.notification.show { transform: translateY(0); opacity: 1; }
.notification.warning { border-inline-start: 4px solid #F59E0B; }
.notification.success { border-inline-start: 4px solid var(--green); }
.notification.error   { border-inline-start: 4px solid var(--red); }
.notification.info    { border-inline-start: 4px solid var(--indigo); }
.notification-content { display: flex; align-items: center; gap: 0.75rem; font-weight: 600; font-size: 0.95rem; }

/* ===== ANIMATIONS ===== */
@keyframes screenIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes slideUp  { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse    { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }
@keyframes teamGlow { 0%, 100% { box-shadow: none; border-color: var(--primary); } 50% { box-shadow: 0 0 12px var(--primary-glow); border-color: var(--primary-dark); } }
@keyframes bounce   { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-18px); } 60% { transform: translateY(-9px); } }
@keyframes wiggle   { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(8deg); } 75% { transform: rotate(-8deg); } }
@keyframes float    { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes shimmer  { 0% { left: -100%; } 100% { left: 100%; } }
@keyframes gradientShift { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
@keyframes bgFloat1 { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(-30px, 40px) scale(1.05); } }
@keyframes bgFloat2 { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(40px, -30px) scale(1.08); } }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .categories-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .theme-toggle { width: 42px; height: 42px; font-size: 1.1rem; }
  .theme-toggle.floating { top: 12px; inset-inline-end: 12px; }
  .notification { bottom: 12px; right: 12px; left: 12px; max-width: none; }

  /* Board header: [back] [turn pill] on the first row, both scores on the second */
  .game-header { flex-wrap: wrap; padding: 0.6rem 0.75rem; gap: 0.5rem; }
  .game-back-btn { padding: 0.4rem 0.7rem; }
  .scoreboard { display: contents; }
  .turn-indicator { flex: 1 1 60%; max-width: none; text-align: center; font-size: 0.85rem; padding: 0.45rem 1rem; animation: none; }
  .team-score { order: 1; min-width: 0; flex: 1 1 40%; padding: 0.5rem 0.7rem; gap: 0.5rem; }
  .team-score .team-icon { display: none; }
  .score { font-size: 1.4rem; }

  .categories-grid { padding: 0.75rem; gap: 0.75rem; }
  .category { padding: 1rem; }
  .point-option { font-size: 1.15rem; min-height: 44px; }

  .question-card, .answer-control-card, .winner-card { padding: 2rem 1.25rem; }
  .question-text { font-size: 1.35rem; }
  .answer-container { font-size: 1.2rem; padding: 1.2rem; }
  .control-btn { padding: 0.75rem 1.2rem; font-size: 0.9rem; }
  .answer-control-card h2 { font-size: 1.4rem; }
  .winner-message { font-size: 1.4rem; }
}

@media (max-width: 560px) {
  .categories-grid { grid-template-columns: 1fr; grid-auto-rows: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ===== RIGHT-TO-LEFT (Arabic) ===== */
[dir="rtl"] .back-btn:hover { transform: translateX(2px); }
