:root {
  --bg: #f7fbff;
  --primary: #2b6cb0;
  --accent: #f6ad55;
  --text: #1a202c;
  --card: #ffffff;
  --muted: #718096;
}

* { box-sizing: border-box; }
body {
  margin: 0; font-family: "Segoe UI", Arial, sans-serif; color: var(--text);
  background: linear-gradient(180deg, #e6f0ff 0%, #f7fbff 100%);
}

#app { max-width: 900px; margin: 0 auto; padding: 24px;}

.screen { display: none; animation: fadeIn 250ms ease-in; }
.screen.active { display: block;}

gh1 { margin: 8px 0 12px; font-size: 44px; font-family:georgia; color:black; font-weight: bold;}
gh2 { margin: 8px 0 12px; font-size: 28px; font-family:georgia; color:black; font-weight: bold;}
gp { color: black; }

.btn {
  border: none; padding: 12px 20px; margin: 8px 8px 0 0;
  background: var(--accent); color: #000; border-radius: 10px; cursor: pointer; font-weight: bold;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn:active { transform: translateY(1px); }

.card {
  background: var(--card); border-radius: 16px; padding: 16px; box-shadow: 0 8px 20px rgba(0,0,0,0.08);
}

.mascot { font-size: 64px; }
.badge-silhouette {
  font-size: 72px; filter: grayscale(100%); opacity: 0.5; margin: 12px 0;
}

.question-demo .q { font-weight: bold; margin-bottom: 12px; }
.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.choice { padding: 10px; border: 1px solid #ddd; border-radius: 10px; background: #fff; cursor: pointer; }
.choice.correct { border-color: #2b6cb0; }

.celebrate { font-size: 72px; margin: 10px 0; animation: pop 500ms ease; }

.badge-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px;
}
.badge {
  background: var(--card); border-radius: 14px; padding: 12px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.06); display: flex; flex-direction: column; align-items: flex-start;
}
.badge .icon { font-size: 28px; }
.badge .name { font-weight: bold; margin-top: 6px; }
.badge .tier { font-size: 12px; color: var(--muted); }
.badge.locked { opacity: 0.6; }
.badge.locked .icon { filter: grayscale(100%); }

.hud { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.status { background: #fff; border-radius: 12px; padding: 10px; box-shadow: 0 6px 16px rgba(0,0,0,0.06); }

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { 0% { transform: scale(0.9) } 100% { transform: scale(1) } }

@keyframes bounceIn {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes confetti {
  0% { transform: translateY(-100vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

.badge-earned {
  animation: bounceIn 0.8s ease forwards;
}

.confetti-piece {
  position: fixed;
  top: -10px;
  width: 10px; height: 10px;
  background: red;
  animation: confetti 3s linear forwards;
}

@keyframes glowSpin {
  0%   { transform: scale(0.5) rotate(0deg); opacity: 0; filter: brightness(1); }
  50%  { transform: scale(1.2) rotate(180deg); opacity: 1; filter: brightness(1.5); }
  100% { transform: scale(1) rotate(360deg); opacity: 1; filter: brightness(1); }
}

.badge-unlock {
  display: inline-block;
  font-size: 80px;
  animation: glowSpin 1.2s ease-out forwards;
  text-shadow: 0 0 10px gold, 0 0 20px orange, 0 0 30px yellow;
}

@keyframes fireworks {
  0% { transform: scale(0.2); opacity: 1; }
  80% { transform: scale(1.5); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}

@keyframes badgeFlyIn {
  0% { transform: translateY(-200px) scale(0.5); opacity: 0; }
  60% { transform: translateY(20px) scale(1.2); opacity: 1; }
  100% { transform: translateY(0) scale(1); }
}

@keyframes crownGlow {
  0% { transform: scale(0.8); filter: brightness(1); }
  50% { transform: scale(1.2); filter: brightness(2); }
  100% { transform: scale(1); filter: brightness(1.2); }
}

.firework {
  position: fixed;
  top: 50%; left: 50%;
  font-size: 40px;
  animation: fireworks 1.5s ease-out forwards;
}

.badge-fly {
  display: inline-block;
  font-size: 60px;
  animation: badgeFlyIn 1s ease-out forwards;
}

.crown-badge {
  font-size: 100px;
  animation: crownGlow 2s infinite alternate;
  text-shadow: 0 0 20px gold, 0 0 40px orange, 0 0 60px yellow;
}

.fame-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.fame-card {
  background: linear-gradient(135deg, #ffd700, #ff9d00);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  color: #fff;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
  animation: fadeIn 0.8s ease;
}

.fame-card .icon {
  font-size: 48px;
  animation: pulse 2s infinite alternate;
}

.fame-card .name {
  font-weight: bold;
  margin-top: 8px;
  font-size: 18px;
}

@keyframes pulse {
  from { transform: scale(1); filter: brightness(1); }
  to   { transform: scale(1.2); filter: brightness(1.5); }
}

.share-btn {
  margin-top: 10px;
  background: #2b6cb0;
  color: #fff;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.share-btn:hover {
  background: #1a4f80;
}

/* Modal overlay */
.modal {
  display: none; /* hidden by default */
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 12px; /* breathing room on small screens */
  overflow: auto; /* allow scroll if content is taller */
}

/* Certificate box */
.certificate {
  width: 100%;
  max-width: 600px;          /* cap size on large screens */
  background: #fff;
  border-radius: 12px;
  padding: clamp(16px, 4vw, 40px); /* fluid padding */
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  position: relative;
  overflow: visible;
  margin-bottom: 30px;
  margin-top: 50px;
}

.certificate.bordered {
  position: relative;
  border: 12px solid blue;
  background: #fffdf5;
  background-image: radial-gradient(circle at top left, #fffbe6, #fffdf5);
}

/* Typography scales with screen size */
.certificate h1 {
  font-size: 30px;
  margin-bottom: 0.8em;
  color: #2b6cb0;
}
.certificate h2 {
  font-size: 24px;
  margin: 0.5em 0;
}
.certificate h3 {
  font-size: 20px;
  margin-bottom: 0.8em;
  color: #e67e22;
}

.certificate p {
  font-size: 18px;
}

.cert-icon {
  font-size: 70px;
  margin: 20px 0;
}

/* Watermark scales */
.watermark {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(100px, 28vw, 200px);
  opacity: 0.1;
  color: #2b6cb0;
  pointer-events: none;
  user-select: none;
}

/* Buttons inside modal */
#certificate-modal .btn {
  margin: 12px 8px 0;
  padding: 8px 16px;
}

.fun-border {
  border: 16px solid transparent;
  border-image: url('images/fun-border.png') 30 round; 
  /* fallback if image not available */
  background: #fffdf5;
  position: relative;
}

/* Decorative fallback using emojis if no image */
.fun-border::before {
  content: "📚 ✏️ ⭐ 📖 ✨ 🖍️ 🎨";
  position: absolute;
  top: -30px; left: 50%;
  transform: translateX(-50%);
  font-size: 24px;
}

.fun-border::after {
  content: "📚 ✏️ ⭐ 📖 ✨ 🖍️ 🎨";
  position: absolute;
  bottom: -30px; left: 50%;
  transform: translateX(-50%);
  font-size: 24px;
}

.certificate.fun-border {
  background: #fff;
  border: 8px solid blue;
  border-radius: 20px;
  padding: 40px 20px; /* enough space for content */
  text-align: center;
  position: relative;
  overflow: visible; /* ensures nothing is clipped */
}

/* Default: buttons can sit beside or below depending on your layout */
#certificate-modal {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Certificate itself */
#certificate {
  max-width: 600px;
  width: 100%;
  padding: 20px;
}

/* Buttons wrapper */
#certificate-modal .btn {
  display: block;
  width: 80%;       /* full‑width buttons for touch screens */
  max-width: 300px; /* don’t get too wide */
  margin: 8px;
}

/* Extra safety for very small screens */
@media (max-width: 825px) {
  #certificate {
    max-width: 100%;       /* take full width */
    border-radius: 8px;
    padding: 16px;
  }

  #certificate-modal .btn {
    display: block;
    width: 80%;       /* full‑width buttons for touch screens */
    max-width: 300px; /* don’t get too wide */
    margin: 10px auto;
  }

/* Certificate box */
.certificate {
  width: 100%;
  max-width: 500px;          /* cap size on large screens */
  background: #fff;
  border-radius: 8px;
  padding: clamp(16px, 4vw, 40px); /* fluid padding */
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  position: relative;
  overflow: visible;
  margin-bottom: 30px;
  margin-top: 30px;
}

.certificate.bordered {
  position: relative;
  border: 8px solid blue;
  background: #fffdf5;
  background-image: radial-gradient(circle at top left, #fffbe6, #fffdf5);
}

/* Typography scales with screen size */
.certificate h1 {
  font-size: 24px;
  margin-bottom: 0.8em;
  color: #2b6cb0;
}
.certificate h2 {
  font-size: 20px;
  margin: 0.5em 0;
}
.certificate h3 {
  font-size: 18px;
  margin-bottom: 0.8em;
  color: #e67e22;
}

.certificate p {
  font-size: 16px;
}

.cert-icon {
  font-size: 50px;
  margin: 20px 0;
}

.certificate.fun-border {
  background: #fff;
  border: 8px solid blue;
  border-radius: 20px;
  padding: 10px;
  text-align: center;
  position: relative;
  overflow: visible; /* ensures nothing is clipped */
}

/* Top border emojis */
.fun-border::before {
  content: "📚 ✏️ ⭐ 📖 ✨ 🖍️ 🎨";
  position: absolute;
  top: -30px;
  left: 50%;                  /* anchor in the middle */
  transform: translateX(-50%);/* shift back half its width */
  font-size: 20px;
  white-space: nowrap;        /* keep emojis in one line */
}

/* Bottom border emojis */
.fun-border::after {
  content: "📚 ✏️ ⭐ 📖 ✨ 🖍️ 🎨";
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  white-space: nowrap;
}

#certificate {
  max-width: 500px;
  width: 100%;
  padding: 20px;
}

}


/* On small screens, force buttons below certificate */
@media (max-width: 600px) {
  #certificate-modal {
    flex-direction: column; /* stack vertically */
  }

  #certificate-modal .btn {
    display: block;
    width: 90%;       /* full‑width buttons for touch screens */
    max-width: 300px; /* don’t get too wide */
    margin: 10px auto;
  }

/* Certificate box */
.certificate {
  width: 100%;
  max-width: 400px;          /* cap size on large screens */
  background: #fff;
  border-radius: 8px;
  padding: clamp(16px, 4vw, 40px); /* fluid padding */
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  position: relative;
  overflow: visible;
  margin-bottom: 20px;
  margin-top: 30px;
}

.certificate.bordered {
  position: relative;
  border: 8px solid blue;
  background: #fffdf5;
  background-image: radial-gradient(circle at top left, #fffbe6, #fffdf5);
}

/* Typography scales with screen size */
.certificate h1 {
  font-size: 24px;
  margin-bottom: 0.8em;
  color: #2b6cb0;
}
.certificate h2 {
  font-size: 20px;
  margin: 0.5em 0;
}
.certificate h3 {
  font-size: 18px;
  margin-bottom: 0.8em;
  color: #e67e22;
}

.certificate p {
  font-size: 16px;
}

.cert-icon {
  font-size: 50px;
  margin: 20px 0;
}

.certificate.fun-border {
  background: #fff;
  border: 8px solid blue;
  border-radius: 20px;
  padding: 10px;
  text-align: center;
  position: relative;
  overflow: visible; /* ensures nothing is clipped */
}

/* Top border emojis */
.fun-border::before {
  content: "📚 ✏️ ⭐ 📖 ✨ 🖍️ 🎨";
  position: absolute;
  top: -30px;
  left: 50%;                  /* anchor in the middle */
  transform: translateX(-50%);/* shift back half its width */
  font-size: 20px;
  white-space: nowrap;        /* keep emojis in one line */
}

/* Bottom border emojis */
.fun-border::after {
  content: "📚 ✏️ ⭐ 📖 ✨ 🖍️ 🎨";
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  white-space: nowrap;
}

#certificate {
  max-width: 400px;
  width: 100%;
  padding: 20px;
}

}

/* On small screens, force buttons below certificate */
@media (max-width: 450px) {

/* Certificate box */
.certificate {
  width: 100%;
  max-width: 340px;          /* cap size on large screens */
  background: #fff;
  border-radius: 6px;
  padding: clamp(16px, 4vw, 40px); /* fluid padding */
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  position: relative;
  overflow: visible;
  margin-bottom: 20px;
}

.certificate.bordered {
  position: relative;
  border: 6px solid blue;
  background: #fffdf5;
  background-image: radial-gradient(circle at top left, #fffbe6, #fffdf5);
}

/* Typography scales with screen size */
.certificate h1 {
  font-size: 22px;
  margin-bottom: 0.8em;
  color: #2b6cb0;
}
.certificate h2 {
  font-size: 18px;
  margin: 0.5em 0;
}
.certificate h3 {
  font-size: 16px;
  margin-bottom: 0.8em;
  color: #e67e22;
}

.certificate p {
  font-size: 14px;
}

.cert-icon {
  font-size: 40px;
  margin: 20px 0;
}

.certificate.fun-border {
  background: #fff;
  border: 8px solid blue;
  border-radius: 20px;
  padding: 10px;
  text-align: center;
  position: relative;
  overflow: visible; /* ensures nothing is clipped */
}

/* Top border emojis */
.fun-border::before {
  content: "📚 ✏️ ⭐ 📖 ✨ 🖍️ 🎨";
  position: absolute;
  top: -25px;
  left: 50%;                  /* anchor in the middle */
  transform: translateX(-50%);/* shift back half its width */
  font-size: 20px;
  white-space: nowrap;        /* keep emojis in one line */
}

/* Bottom border emojis */
.fun-border::after {
  content: "📚 ✏️ ⭐ 📖 ✨ 🖍️ 🎨";
  position: absolute;
  bottom: -25px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  white-space: nowrap;
}

#certificate {
  max-width: 340px;
  width: 100%;
  padding: 16px;
}

}

@media (max-width: 350px) {
.certificate h1 {
  font-size: 20px;
}

.certificate.fun-border {
  background: #fff;
  border: 8px solid blue;
  border-radius: 20px;
  padding: 10px;
  text-align: center;
  position: relative;
  overflow: visible; /* ensures nothing is clipped */
}

/* Top border emojis */
.fun-border::before {
  content: "📚 ✏️ ⭐ 📖 ✨ 🖍️ 🎨";
  position: absolute;
  top: -20px;
  left: 50%;                  /* anchor in the middle */
  transform: translateX(-50%);/* shift back half its width */
  font-size: 18px;
  white-space: nowrap;        /* keep emojis in one line */
}

/* Bottom border emojis */
.fun-border::after {
  content: "📚 ✏️ ⭐ 📖 ✨ 🖍️ 🎨";
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  white-space: nowrap;
}

}

@media (max-width: 700px) {
gh2 { font-size: 26px;}
}

@media (max-width: 600px) {
gh1 { font-size: 32px;}
gh2 { font-size: 22px;}
}

@media (max-width: 500px) {
gh2 { font-size: 20px;}
}

@media (max-width: 400px) {
gh1 { font-size: 26px;}
gh2 { font-size: 20px;}
}

