/* ----- Base Styles & Variables ----- */
:root {
  --bg-dark: #0f172a;
  --panel-bg: rgba(30, 41, 59, 0.7);
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --secondary: #ec4899;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --correct: #22c55e;
  --incorrect: #ef4444;
  --border: rgba(255, 255, 255, 0.1);
}

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

/* Custom FI Coin (Professional 3D) */
.fi-coin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: 
    linear-gradient(135deg, rgba(255,255,255,0.6) 0%, rgba(255,255,255,0) 40%, rgba(255,255,255,0.2) 100%),
    radial-gradient(circle at 30% 30%, #ffdf00, #d4af37, #b8860b);
  border-radius: 50%;
  color: #fff;
  font-weight: 900;
  font-size: 0.75rem;
  font-family: 'Outfit', sans-serif;
  text-shadow: 1px 1px 2px rgba(139, 101, 8, 0.9), -1px -1px 0px rgba(255,255,255,0.4);
  border: 1px solid #a67c00;
  box-shadow: 
    inset 0 3px 4px rgba(255, 255, 255, 0.9), 
    inset 0 -3px 4px rgba(139, 101, 8, 0.9), 
    0 4px 8px rgba(0,0,0,0.5);
  margin-right: 8px;
  letter-spacing: -0.5px;
  position: relative;
}
.fi-coin::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px; right: 3px; bottom: 3px;
  border-radius: 50%;
  border: 1px dashed rgba(184, 134, 11, 0.5);
  pointer-events: none;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: 
    radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.15), transparent 25%),
    radial-gradient(circle at 85% 30%, rgba(236, 72, 153, 0.15), transparent 25%);
}

.screen {
  display: none;
  width: 100%;
  max-width: 800px;
  padding: 20px;
  animation: fadeIn 0.4s ease-out;
}
.screen.active {
  display: block;
}

/* ----- Home Screen ----- */
.rules-container {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 16px;
  padding: 20px;
  max-width: 400px;
  margin: 0 auto 30px;
}
.rules-title {
  color: var(--primary);
  font-family: 'Outfit', sans-serif;
  margin-bottom: 15px;
  font-size: 1.2rem;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.rules-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rules-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.95rem;
  text-align: left;
  background: rgba(0,0,0,0.2);
  padding: 12px 15px;
  border-radius: 10px;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.rules-list li:hover {
  transform: translateX(5px);
  color: var(--text-main);
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.1);
}
.rules-list li span {
  font-size: 1.2rem;
}

.medium-selector-container {
  max-width: 400px;
  margin: 0 auto 30px;
  text-align: center;
}
.medium-title {
  color: var(--text-main);
  font-family: 'Outfit', sans-serif;
  margin-bottom: 12px;
  font-size: 1.1rem;
}
.medium-options {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  padding: 6px;
  position: relative;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.05);
}
.medium-option {
  flex: 1;
  position: relative;
  cursor: pointer;
}
.medium-option input {
  display: none;
}
.medium-label {
  display: block;
  padding: 12px 10px;
  text-align: center;
  color: var(--text-muted);
  font-weight: 600;
  border-radius: 8px;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  z-index: 2;
  font-size: 0.95rem;
}
.medium-option input:checked + .medium-label {
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.4);
  transform: scale(1.05);
}
.medium-option:hover .medium-label:not(.medium-option input:checked + .medium-label) {
  color: var(--text-main);
  background: rgba(255,255,255,0.05);
}

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

.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.text-center { text-align: center; }

/* ----- Typography ----- */
.game-title {
  font-family: 'Outfit', sans-serif;
  font-size: 3rem;
  line-height: 1.1;
  margin-bottom: 10px;
}
.gradient-text {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.game-subtitle {
  color: var(--text-muted);
  margin-bottom: 30px;
}

/* ----- Forms & Buttons ----- */
button {
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  border: none;
  outline: none;
}
.btn-primary {
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  font-size: 1.1rem;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 25px rgba(99, 102, 241, 0.4);
}
.btn-secondary {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  transition: background 0.2s;
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}
.btn-small {
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 0.9rem;
}

/* ----- In-Game HUD ----- */
#screen-game {
  max-width: 1000px;
}
.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 15px 30px;
  border-radius: 20px;
  margin-bottom: 30px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.player-hud {
  display: flex;
  align-items: center;
  gap: 15px;
}
.hud-name {
  font-weight: 600;
  font-size: 1.1rem;
}
.hud-score {
  font-family: 'Outfit', sans-serif;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
  background: rgba(255,255,255,0.1);
  padding: 4px 16px;
  border-radius: 12px;
}
.hud-center {
  text-align: center;
}
.q-counter {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(0,0,0,0.3);
  padding: 8px 20px;
  border-radius: 50px;
}
.global-timer {
  font-family: 'Outfit', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  color: #fbbf24;
  text-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
  margin-bottom: 5px;
}
.global-timer.danger {
  color: var(--incorrect);
  animation: pulseTimer 1s infinite;
}

@keyframes pulseTimer {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* ----- Layout for Ads in Game Screen ----- */
.game-layout {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}
.game-main-content {
  flex: 1;
  max-width: 1000px;
  width: 100%;
}
.ad-sidebar {
  width: 160px;
  min-height: 600px;
  background: rgba(0,0,0,0.2);
  border-radius: 12px;
  border: 1px dashed rgba(255,255,255,0.1);
  display: flex;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.ad-bottom {
  display: none;
  margin-top: 20px;
  border-radius: 10px;
  overflow: hidden;
  min-height: 90px;
  background: rgba(0,0,0,0.2);
}

/* ----- Question Area ----- */
.question-container {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 30px;
  position: relative;
  overflow: hidden;
}

#question-text {
  font-size: 1.4rem;
  line-height: 1.5;
  margin-bottom: 30px;
  margin-top: 10px;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}
.option-btn {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  padding: 20px;
  border-radius: 12px;
  text-align: left;
  font-size: 1.1rem;
  color: var(--text-main);
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.option-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-2px);
}
.option-btn:active:not(:disabled) {
  transform: translateY(0);
}
.option-btn:disabled {
  cursor: not-allowed;
  opacity: 0.8;
}
.option-btn.selected-correct {
  background: rgba(34, 197, 94, 0.2);
  border-color: var(--correct);
  box-shadow: 0 0 15px rgba(34, 197, 94, 0.3);
}
.option-btn.selected-wrong {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--incorrect);
}
.option-btn.actual-correct {
  background: rgba(34, 197, 94, 0.1);
  border-color: var(--correct);
}

.action-buttons {
  margin-top: 25px;
  text-align: right;
  display: none;
}
.btn-next {
  background: var(--primary);
  color: white;
  padding: 12px 30px;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  transition: all 0.2s;
}
.btn-next:hover {
  background: var(--primary-hover);
  transform: translateX(5px);
}

/* ----- Leaderboard ----- */
.leaderboard-list {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 5px;
}
.leaderboard-list::-webkit-scrollbar {
  width: 6px;
}
.leaderboard-list::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
}
.leaderboard-list::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 4px;
}
.leaderboard-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.2);
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  transition: transform 0.2s;
}
.leaderboard-item:hover {
  transform: translateX(5px);
  background: rgba(255,255,255,0.05);
}
.rank {
  font-size: 1.5rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  color: var(--text-muted);
  width: 40px;
}
.rank.rank-1 { color: #fbbf24; }
.rank.rank-2 { color: #94a3b8; }
.rank.rank-3 { color: #b45309; }
.student-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 0;
}
.student-name {
  font-weight: 600;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.student-score {
  font-family: 'Outfit', sans-serif;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  white-space: nowrap;
  flex-shrink: 0;
}
.student-time {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-left: 10px;
}

/* ----- Results ----- */
.result-title {
  font-size: 3rem;
  font-family: 'Outfit', sans-serif;
  margin-bottom: 10px;
}
.result-message {
  font-size: 1.2rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.final-score-box {
  background: rgba(0,0,0,0.2);
  padding: 30px;
  border-radius: 16px;
  border: 1px dashed var(--primary);
  margin-bottom: 30px;
}
.final-score-box h3 {
  font-size: 1.2rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.final-score-value {
  font-size: 4rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 900;
  color: var(--primary);
}

/* ----- Animations ----- */
.anim-float {
  animation: float 4s ease-in-out infinite;
}
@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
  100% { transform: translateY(0px); }
}

.btn-glow {
  position: relative;
}
.btn-glow::after {
  content: '';
  position: absolute;
  top: -2px; left: -2px; right: -2px; bottom: -2px;
  background: linear-gradient(135deg, var(--primary), var(--secondary), var(--primary));
  z-index: -1;
  border-radius: 14px;
  filter: blur(8px);
  opacity: 0.6;
  animation: pulseGlow 2s ease-in-out infinite;
}
@keyframes pulseGlow {
  0%, 100% { opacity: 0.4; transform: scale(0.98); }
  50% { opacity: 0.8; transform: scale(1.02); }
}

.hearts-container {
  display: flex;
  gap: 5px;
  margin-top: 5px;
  font-size: 1.2rem;
}
.hearts-container span {
  transition: transform 0.3s;
}
.heart-broken {
  filter: grayscale(100%);
  opacity: 0.3;
}

.streak-bonus {
  position: absolute;
  top: 20px;
  right: 20px;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  padding: 5px 12px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: 0 4px 10px rgba(239, 68, 68, 0.4);
  animation: streakPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 10;
}

@keyframes streakPop {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes heartBreak {
  0% { transform: scale(1); }
  50% { transform: scale(1.5); filter: grayscale(100%); opacity: 0.5; }
  100% { transform: scale(1); filter: grayscale(100%); opacity: 0.3; }
}
.anim-heart-break {
  animation: heartBreak 0.5s forwards;
}
@keyframes heartHeal {
  0% { transform: scale(1); filter: grayscale(100%); opacity: 0.3; }
  50% { transform: scale(1.5); filter: grayscale(0%); opacity: 1; }
  100% { transform: scale(1); filter: grayscale(0%); opacity: 1; }
}
.anim-heart-heal {
  animation: heartHeal 0.5s forwards;
}

@media (max-width: 1100px) {
  .ad-sidebar { display: none !important; }
  .ad-bottom { 
    display: flex !important; 
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    z-index: 1000 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    background: var(--bg-dark) !important;
    border-top: 1px solid var(--border) !important;
    justify-content: center !important;
    align-items: center !important;
  }
  body {
    padding-bottom: 90px !important;
  }
}

@media (max-width: 600px) {
  .glass-panel { padding: 20px; }
  .game-title { font-size: 2.2rem; }
  .game-hud {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 12px;
  }
  .player-hud.p1 {
    grid-column: 1 / 2;
  }
  .player-hud.p2 {
    grid-column: 2 / 3;
    justify-content: flex-end;
  }
  .hud-center {
    grid-column: 1 / 3;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .global-timer {
    font-size: 1.6rem;
    margin-bottom: 0;
  }
  .hud-score {
    font-size: 1.2rem;
    padding: 4px 12px;
  }
  .hearts-container {
    font-size: 0.9rem;
  }
  .hud-name {
    font-size: 0.9rem;
  }
  .avatar {
    width: 32px !important;
    height: 32px !important;
    font-size: 1rem !important;
  }
  .options-grid { grid-template-columns: 1fr; }
  .question-container { padding: 15px; }
  #question-text { font-size: 1.1rem; margin-bottom: 15px; }
  .option-btn { padding: 12px; font-size: 1rem; }
}

/* Leaderboard Tabs */
.lb-tab {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}
.lb-tab:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}
.lb-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}
