@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #00ff88;
  --secondary: #00d4ff;
  --danger: #ff0000;
  --warning: #ffaa00;
  --success: #00ff88;
  --dark: #0a0e27;
  --darker: #050714;
  --light: #ffffff;
  --gray: #8892b0;
  --purple: #9c88ff;
}

body {
  font-family: "Poppins", system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #0a0e27 0%, #050714 100%);
  color: var(--light);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Cyber Grid Background */
.cyber-grid {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(rgba(0, 255, 136, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 255, 136, 0.1) 1px, transparent 1px);
  background-size: 50px 50px;
  animation: gridMove 20s linear infinite;
  pointer-events: none;
  z-index: 1;
}

@keyframes gridMove {
  0% {
    transform: translate(0, 0);
  }
  100% {
    transform: translate(50px, 50px);
  }
}

/* Particles */
.particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.particle {
  position: absolute;
  width: 2px;
  height: 2px;
  background: var(--primary);
  border-radius: 50%;
  animation: float 15s linear infinite;
  opacity: 0.6;
}

@keyframes float {
  0% {
    transform: translateY(100vh) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.6;
  }
  90% {
    opacity: 0.6;
  }
  100% {
    transform: translateY(-100px) rotate(360deg);
    opacity: 0;
  }
}
/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 15px 25px;
  border-radius: 8px;
  color: white;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  background: linear-gradient(135deg, #00c851 0%, #007e33 100%);
}

.toast-error {
  background: linear-gradient(135deg, #ff4444 0%, #cc0000 100%);
}

.toast-info {
  background: linear-gradient(135deg, #33b5e5 0%, #0099cc 100%);
}

.toast-warning {
  background: linear-gradient(135deg, #ffbb33 0%, #ff8800 100%);
}
/* Navigation */
nav {
  position: fixed;
  top: 0;
  width: 100%;
  background: rgba(10, 14, 39, 0.95);
  backdrop-filter: blur(10px);
  padding: 1rem 2rem;
  z-index: 1000;
  border-bottom: 2px solid var(--primary);
  box-shadow: 0 4px 30px rgba(0, 255, 136, 0.3);
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: bold;
  background: linear-gradient(45deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.nav-link {
  color: var(--light);
  text-decoration: none;
  position: relative;
  transition: all 0.3s;
  padding: 0.5rem 1rem;
  border-radius: 5px;
  font-weight: 500;
}

.nav-link:hover,
.nav-link.active {
  color: var(--primary);
  background: rgba(0, 255, 136, 0.1);
  transform: translateY(-2px);
}

.sign-in-btn {
  background: linear-gradient(
    45deg,
    var(--primary),
    var(--secondary)
  ) !important;
  color: var(--dark) !important;
  font-weight: bold !important;
  border-radius: 25px !important;
  padding: 0.8rem 1.5rem !important;
  text-transform: uppercase !important;
  letter-spacing: 1px !important;
  border: 2px solid var(--primary) !important;
  transition: all 0.3s ease !important;
  margin-left: 1rem !important;
}

.sign-in-btn:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 10px 25px rgba(0, 255, 136, 0.4) !important;
}

.nav-user-area {
  display: flex;
  align-items: center;
  gap: 1rem;

  /* CRITICAL FIX: Reserve horizontal space immediately */
  min-width: 180px; /* Slightly increased widt*/
  height: 40px; /* Reserves vertical space */
}

.loading-hidden {
  visibility: hidden !important;
  opacity: 0 !important;
  /* This moves the element out of the layout flow completely */
  position: absolute !important;
  top: -9999px; /* Pushes the hidden element far off-screen */
}

/* avatar ปุ่มด้านขวา */
.profile-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0.8rem;
  border-radius: 999px;
  background: rgba(0, 255, 136, 0.15);
  border: 1px solid rgba(0, 255, 136, 0.6);
  text-decoration: none;
  color: var(--light);
  font-weight: 500;
  transition: all 0.25s ease;
}

.profile-pill:hover {
  background: rgba(0, 255, 136, 0.25);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 255, 136, 0.4);
}

.nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary);
  box-shadow: 0 0 10px rgba(0, 255, 136, 0.6);
}

#navUsername {
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9rem;
  color: var(--light);
  opacity: 0.9;
}

/* Main Content */
.main-content {
  margin-top: 80px;
  position: relative;
  z-index: 10;
}

/* Hero Section */
.hero-section {
  min-height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 2rem;
}

.hero-content {
  max-width: 900px;
  animation: fadeInUp 1s ease-out;
  text-align: center;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hero-title {
  font-size: 4.5rem;
  font-weight: 800;
  margin-bottom: 1.5rem;
  background: linear-gradient(
    45deg,
    var(--primary),
    var(--secondary),
    var(--purple)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: glow 3s ease-in-out infinite alternate;
  line-height: 1.2;
}

@keyframes glow {
  from {
    filter: drop-shadow(0 0 20px rgba(0, 255, 136, 0.5));
  }
  to {
    filter: drop-shadow(0 0 40px rgba(0, 212, 255, 0.8));
  }
}

.hero-subtitle {
  font-size: 1.5rem;
  color: var(--gray);
  margin-bottom: 1rem;
  font-weight: 300;
}

.hero-description {
  font-size: 1.1rem;
  color: var(--light);
  margin-bottom: 3rem;
  line-height: 1.8;
}

.hero-buttons {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-primary,
.btn-secondary {
  padding: 1rem 2.5rem;
  font-size: 1.1rem;
  font-weight: bold;
  border-radius: 30px;
  text-decoration: none;
  transition: all 0.3s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary {
  background: linear-gradient(45deg, var(--primary), var(--secondary));
  color: var(--dark);
  border: 2px solid var(--primary);
  margin: 0 auto;
}

.btn-primary:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 35px rgba(0, 255, 136, 0.5);
}

.btn-secondary {
  background: transparent;
  color: var(--light);
  border: 2px solid var(--primary);
}

.btn-secondary:hover {
  background: rgba(0, 255, 136, 0.1);
  transform: translateY(-5px);
}

/* Features Section */
.features-section {
  padding: 6rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.section-header {
  text-align: center;
  margin-bottom: 4rem;
}

.section-title {
  font-size: 2.5rem;
  font-weight: bold;
  color: var(--primary);
  margin-bottom: 1rem;
}

.section-subtitle {
  font-size: 1.2rem;
  color: var(--gray);
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
}

.feature-card {
  background: rgba(10, 14, 39, 0.8);
  border: 2px solid rgba(0, 255, 136, 0.3);
  border-radius: 20px;
  padding: 2.5rem;
  transition: all 0.3s;
  backdrop-filter: blur(10px);
}

.feature-card:hover {
  transform: translateY(-10px);
  border-color: var(--primary);
  box-shadow: 0 20px 60px rgba(0, 255, 136, 0.4);
}

.feature-icon {
  font-size: 3.5rem;
  margin-bottom: 1.5rem;
  display: block;
}

.feature-title {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--light);
  margin-bottom: 1rem;
}

.feature-description {
  color: var(--gray);
  line-height: 1.7;
}

/* Stats Section */
.stats-section {
  padding: 6rem 2rem;
  background: rgba(0, 255, 136, 0.05);
  border-top: 2px solid rgba(0, 255, 136, 0.2);
  border-bottom: 2px solid rgba(0, 255, 136, 0.2);
}

.stats-container {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 3rem;
}

.stat-item {
  text-align: center;
  padding: 2rem;
  background: rgba(10, 14, 39, 0.8);
  border: 2px solid rgba(0, 255, 136, 0.3);
  border-radius: 15px;
  transition: all 0.3s;
}

.stat-item:hover {
  transform: scale(1.05);
  border-color: var(--primary);
}

.stat-value {
  font-size: 3.5rem;
  font-weight: bold;
  background: linear-gradient(45deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}

.stat-label {
  font-size: 1.2rem;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* CTA Section */
.cta-section {
  padding: 6rem 2rem;
  text-align: center;
  max-width: 900px;
  margin: 0 auto;
}

.cta-title {
  font-size: 3rem;
  font-weight: bold;
  margin-bottom: 1.5rem;
  background: linear-gradient(45deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.cta-description {
  font-size: 1.2rem;
  color: var(--light);
  margin-bottom: 2.5rem;
  line-height: 1.8;
}

/* Footer */
footer {
  background: rgba(10, 14, 39, 0.95);
  border-top: 2px solid var(--primary);
  padding: 3rem 2rem;
  position: relative;
  z-index: 10;
}

.footer-content {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 3rem;
}

.footer-section h3 {
  color: var(--primary);
  margin-bottom: 1.5rem;
  font-size: 1.3rem;
}

.footer-section p,
.footer-section a {
  color: var(--gray);
  line-height: 2;
  text-decoration: none;
  display: block;
}

.footer-section a:hover {
  color: var(--primary);
}

.footer-bottom {
  max-width: 1400px;
  margin: 3rem auto 0;
  padding-top: 2rem;
  border-top: 1px solid rgba(0, 255, 136, 0.2);
  text-align: center;
  color: var(--gray);
}

/* Responsive */
@media (max-width: 768px) {
  .hero-title {
    font-size: 2.5rem;
  }

  .hero-subtitle {
    font-size: 1.2rem;
  }

  .hero-buttons {
    flex-direction: column;
  }

  .nav-links {
    flex-direction: column;
    gap: 0.5rem;
  }

  .nav-container {
    flex-direction: column;
    gap: 1rem;
  }

  .sign-in-btn {
    margin-left: 0 !important;
  }

  .features-grid {
    grid-template-columns: 1fr;
  }

  .stat-value {
    font-size: 2.5rem;
  }

  .cta-title {
    font-size: 2rem;
  }
}

/* ------------------------------------------------------------------ */
/* --- 1. สไตล์สำหรับ Profile Pill (แก้ไขปัญหาความกว้างชื่อผู้ใช้) --- */
/* ------------------------------------------------------------------ */

/* สำหรับเม็ดโปรไฟล์ทั้งหมด (รวม avatar และ username) */
.profile-pill {
  display: flex;
  align-items: center;
  max-width: 150px; /* จำกัดความกว้างรวมของเม็ดโปรไฟล์ */
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis; /* แสดง ... เมื่อชื่อยาวเกิน */
}

/* สำหรับ Avatar */
.nav-avatar {
  flex-shrink: 0; /* Avatar ไม่ย่อ */
  width: 30px;
  height: 30px;
  border-radius: 50%;
}

/* สำหรับชื่อผู้ใช้โดยเฉพาะ */
#navUsername {
  flex-shrink: 1; /* ชื่อผู้ใช้ยอมย่อ */
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding-left: 0.5rem; /* ระยะห่างจาก avatar */
}

/* ------------------------------------------------------------------ */
/* --- 2. สไตล์สำหรับ Hamburger Menu (Mobile Toggle) --- */
/* ------------------------------------------------------------------ */

/* ซ่อนปุ่ม Hamburger บนหน้าจอเดสก์ท็อป */
.hamburger-menu {
  display: none;
}

/* ลบสไตล์การโฟกัสเริ่มต้นที่ไม่ต้องการบนปุ่ม */
#hamburgerBtn:focus,
#hamburgerBtn:active {
  outline: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

/* --- MEDIA QUERY สำหรับหน้าจอขนาดเล็ก (Mobile) --- */

@media (max-width: 768px) {
  /* 1. จัดโครงสร้าง nav-container บนมือถือ */
  .nav-container {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    /* เพิ่ม gap จาก leaderboard.css */
    gap: 0.5rem;
  }

  /* 2. แสดงปุ่มแฮมเบอร์เกอร์และจัดตำแหน่ง */
  .hamburger-menu {
    display: block;
    order: 2; /* ให้อยู่ทางขวา */
  }

  .logo {
    order: 1; /* ให้อยู่ทางซ้าย */
  }

  .hero-buttons {
    /* สำคัญ: ใช้ text-align: center กับ container เพื่อจัดองค์ประกอบ inline-block/inline ให้อยู่ตรงกลาง */
    text-align: center;
    width: 100%; /* ตรวจสอบให้แน่ใจว่า div ใช้ความกว้างเต็มที่ */
    margin-top: 20px; /* เพิ่มระยะห่างด้านบนถ้าต้องการ */
  }

  /* สไตล์ปุ่ม Hamburger (ลดขนาดอิโมจิเล็กน้อยเพื่อให้สอดคล้องกับ leaderboard ที่มีการปรับ) */
  #hamburgerBtn {
    background: transparent !important;
    border: none !important;
    appearance: none;
    -webkit-appearance: none;
    outline: none !important;
    box-shadow: none !important;
    font-size: 2rem; /* ปรับลดจาก 2.5rem */
    color: var(--primary) !important; /* ใช้สีหลักที่คุณกำหนด */
    cursor: pointer;
    padding: 0.2rem 0.5rem 0.2rem 1rem !important;
  }

  /* 3. ซ่อนลิงก์เมนูหลักตามค่าเริ่มต้นบนมือถือ */
  .nav-links {
    display: none;
    width: 100%; /* บังคับให้เมนูเต็มความกว้างด้านล่าง */
    flex-direction: column; /* จัดเรียงลิงก์ในแนวตั้ง */
    align-items: center;
    padding-top: 1rem;
    order: 3; /* บังคับให้เมนูอยู่แถวล่างสุด */
  }

  /* จัดการลิงก์ภายในเมนูสำหรับมือถือ */
  .nav-links .nav-link {
    padding: 0.5rem 0;
    width: 100%;
    text-align: center;
  }

  /* ****************************************************** */
  /* *** สไตล์ Nav User Area และ Profile Pill (CRITICAL FIX) *** */
  /* ****************************************************** */
  .nav-user-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-top: 1rem;
  }

  .nav-user-area .sign-in-btn {
    /* CRITICAL FIX 1: Ensure it's a block element to use margin: auto correctly */
    display: block !important;
    /* CRITICAL FIX 2: Ensure text is centered within the button */
    text-align: center !important;
    /* Ensure spacing and width */
    margin: 0.5rem auto !important;
    width: 90%;
    max-width: 300px;
  }

  .nav-user-area .profile-pill {
    /* Set the pill width and center it */
    width: 50%;
    max-width: 250px;
    margin: 0.5rem auto;

    /* Use flex on the pill itself to center content (avatar/username) */
    display: flex;
    justify-content: center;
    padding: 1rem;
  }

  /* 4. KEY: แสดงเมนูเมื่อ nav-container มีคลาส 'menu-active' */
  .nav-container.menu-active .nav-links {
    display: flex;
    padding-bottom: 1rem;
  }
}
/* ==========================================
   Auth Modal Styles
   ========================================== */
.auth-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s ease;
  align-items: center;
  justify-content: center;
}

.auth-modal.active {
  display: flex;
  opacity: 1;
}

.auth-modal-content {
  background: linear-gradient(135deg, rgba(10, 14, 39, 0.95), rgba(5, 7, 20, 0.95));
  border: 2px solid var(--primary);
  border-radius: 16px;
  padding: 3rem;
  max-width: 500px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 40px rgba(0, 255, 136, 0.3);
  animation: modalSlideIn 0.3s ease;
  position: relative;
}

@keyframes modalSlideIn {
  from {
    transform: translateY(-30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.auth-modal-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 255, 136, 0.1);
  border: 2px solid var(--primary);
  border-radius: 50%;
  color: var(--primary);
}

.auth-modal-icon svg {
  width: 48px;
  height: 48px;
  stroke: var(--primary);
}

.auth-modal-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--light);
  margin-bottom: 1rem;
  text-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
}

.auth-modal-description {
  font-size: 1.1rem;
  color: var(--gray);
  margin-bottom: 2rem;
  line-height: 1.6;
}

.auth-modal-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.auth-modal-btn {
  padding: 0.875rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: 'Poppins', sans-serif;
  min-width: 140px;
  text-decoration: none;
  display: inline-block;
}

.auth-modal-btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: var(--dark);
  box-shadow: 0 4px 15px rgba(0, 255, 136, 0.4);
}

.auth-modal-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 255, 136, 0.6);
}

.auth-modal-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--light);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.auth-modal-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

/* Feature Card Cursor */
.feature-card {
  cursor: pointer;
  transition: transform 0.3s ease;
}

.feature-card:hover {
  transform: translateY(-5px);
}

/* Responsive */
@media (max-width: 768px) {
  .auth-modal-content {
    padding: 2rem;
    max-width: 90%;
  }

  .auth-modal-title {
    font-size: 1.5rem;
  }

  .auth-modal-description {
    font-size: 1rem;
  }

  .auth-modal-buttons {
    flex-direction: column;
  }

  .auth-modal-btn {
    width: 100%;
  }
}