:root {
  --green-900: #0b3d2e;
  --green-700: #116149;
  --green-500: #1f9d6e;
  --green-100: #e3f5ec;
  --gold: #f5b301;
  --gold-soft: #fff4cc;
  --cream: #fffaf0;
  --ink: #1b2a24;
  --red: #e5484d;
  --radius: 22px;
}

* { box-sizing: border-box; }

body {
  font-family: 'Fredoka', 'Segoe UI', Arial, sans-serif;
  background: linear-gradient(160deg, var(--green-900), var(--green-700) 60%, #158058);
  color: var(--ink);
  text-align: center;
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Corak geometri Islamik lembut di latar belakang */
.pattern {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23ffffff' stroke-width='2'%3E%3Crect x='20' y='20' width='40' height='40'/%3E%3Crect x='20' y='20' width='40' height='40' transform='rotate(45 40 40)'/%3E%3Ccircle cx='40' cy='40' r='8'/%3E%3C/g%3E%3C/svg%3E");
}

#webcam { display: none; }

/* ---------- Bar atas ---------- */
.topbar {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1000px;
  margin: 0 auto;
  padding: 18px 24px;
  color: #fff;
}

.brand { display: flex; align-items: center; gap: 12px; text-align: left; }
.brand-icon {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  font-size: 30px;
  background: var(--gold);
  color: var(--green-900);
  border-radius: 16px;
}
.brand h1 { margin: 0; font-size: 22px; }
.brand p { margin: 0; color: var(--gold); font-weight: 600; }

.stats { display: flex; align-items: center; gap: 12px; }
.stat {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 6px 14px;
  min-width: 80px;
}
.stat span { display: block; font-size: 12px; opacity: 0.8; }
.stat strong { font-size: 20px; }

.stars span { font-size: 24px; color: rgba(255, 255, 255, 0.25); }
.stars span.on { color: var(--gold); }
.stars.big span { font-size: 54px; color: #ddd; }
.stars.big span.on { color: var(--gold); text-shadow: 0 2px 0 #c58f00; }

/* ---------- Skrin ---------- */
.screen { display: none; position: relative; padding: 10px 20px 40px; }
.screen.active { display: block; animation: pop 0.35s ease; }

@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.card {
  max-width: 900px;
  margin: 0 auto;
  background: var(--cream);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
  border-bottom: 8px solid var(--gold);
}

.hero h2 { font-size: 34px; color: var(--green-700); margin: 10px 0; }
.hero p { font-size: 20px; line-height: 1.5; max-width: 640px; margin: 10px auto; }
.hero .hint { font-size: 15px; opacity: 0.7; }

.bismillah {
  font-family: 'Amiri', serif;
  font-size: 44px;
  color: var(--green-700);
}

.topics { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 22px 0; }
.topics span {
  background: var(--green-100);
  color: var(--green-700);
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 600;
}

/* ---------- Pilihan tahun ---------- */
.choose { font-weight: 700; color: var(--green-700); margin-bottom: 0; }
.level-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; }
.btn-level { display: inline-flex; align-items: center; flex-direction: column; gap: 4px; min-width: 230px; }
.btn-level small { font-size: 17px; font-weight: 600; opacity: 0.85; }
.btn-level.level-5 { background: #2f80ed; border-color: #1c5fb8; box-shadow: 0 6px 0 #1c5fb8; }
.btn-level.level-2 { background: #f2994a; border-color: #c4742a; box-shadow: 0 6px 0 #c4742a; }
.btn-level.level-3 { background: #9b51e0; border-color: #7a38b8; box-shadow: 0 6px 0 #7a38b8; }
.btn-level.level-4 { background: #eb5a8c; border-color: #bf3a68; box-shadow: 0 6px 0 #bf3a68; }
.btn-level.level-6 { background: #0c8599; border-color: #086273; box-shadow: 0 6px 0 #086273; }
.btn-start.btn-home { background: #fff; color: var(--green-700); }

/* ---------- Kuiz ---------- */
.topic-tag {
  display: inline-block;
  padding: 6px 18px;
  border-radius: 999px;
  background: var(--green-500);
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.topic-tag[data-topic="Ibadah"] { background: #2f80ed; }
.topic-tag[data-topic="Al-Quran"] { background: #9b51e0; }
.topic-tag[data-topic="Sirah"] { background: #f2994a; }
.topic-tag[data-topic="Adab"] { background: #eb5a8c; }
.topic-tag[data-topic="Jawi"] { background: #0c8599; }

.arabic {
  font-family: 'Amiri', serif;
  font-size: 64px;
  line-height: 1.6;
  color: var(--green-900);
  margin: 10px auto 0;
  padding: 4px 24px;
  background: var(--gold-soft);
  border-radius: 18px;
  display: inline-block;
}
.arabic:empty { display: none; }

#question {
  font-size: 32px;
  line-height: 1.35;
  margin: 18px 0 6px;
  color: var(--ink);
}

.options-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin: 28px 0 18px;
}

.btn-option {
  font-family: inherit;
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 4px solid var(--green-500);
  border-radius: 20px;
  cursor: pointer;
  transition: transform 0.15s, background-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 6px 0 var(--green-700);
}

.btn-option.answer {
  min-height: 150px;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-option .letter {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--green-500);
  color: #fff;
  font-size: 22px;
}

.btn-option:hover,
.btn-option.hovered {
  background: var(--gold-soft);
  border-color: var(--gold);
  transform: scale(1.05);
  box-shadow: 0 6px 0 #c58f00;
}
.btn-option.hovered .letter { background: var(--gold); color: var(--green-900); }

.btn-option.correct { background: #d3f9d8; border-color: #2f9e44; box-shadow: 0 6px 0 #2b8a3e; }
.btn-option.correct .letter { background: #2f9e44; }
.btn-option.wrong { background: #ffe3e3; border-color: var(--red); box-shadow: 0 6px 0 #c92a2a; }
.btn-option.wrong .letter { background: var(--red); }

.btn-start {
  margin-top: 14px;
  padding: 26px 56px;
  font-size: 30px;
  background: var(--green-500);
  color: #fff;
  border-color: var(--green-700);
}
.btn-start:hover, .btn-start.hovered { color: var(--green-900); }

.progress-bar-container {
  width: 100%;
  background-color: #e6e1d3;
  height: 14px;
  border-radius: 8px;
  overflow: hidden;
}

#progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), #ff8a00);
  transition: width 0.1s linear;
}

#status-text { font-size: 17px; color: #5b6b63; }

/* ---------- Skrin tamat ---------- */
.trophy { font-size: 90px; }
.final-score { font-size: 64px; font-weight: 700; color: var(--green-700); }

/* ---------- Maklum balas ---------- */
.feedback {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(11, 61, 46, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 20;
  padding: 20px;
}
.feedback.show { opacity: 1; }
.feedback-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 30px 40px;
  max-width: 560px;
  transform: scale(0.85);
  transition: transform 0.25s;
  border-bottom: 8px solid var(--green-500);
}
.feedback.show .feedback-card { transform: scale(1); }
.feedback.is-wrong .feedback-card { border-bottom-color: var(--red); }
.feedback-emoji { font-size: 72px; }
.feedback h3 { font-size: 28px; margin: 8px 0; color: var(--green-700); }
.feedback.is-wrong h3 { color: #c92a2a; }
.feedback p { font-size: 20px; line-height: 1.5; margin: 0; }

/* ---------- Kursor jari ---------- */
#finger-cursor {
  position: fixed;
  left: -30px;
  top: -30px;
  width: 60px;
  height: 60px;
  pointer-events: none;
  z-index: 30;
  display: none;
}
#finger-cursor svg { width: 100%; height: 100%; transform: rotate(-90deg); }
#finger-cursor .ring-bg { fill: rgba(245, 179, 1, 0.35); stroke: #fff; stroke-width: 5; }
#finger-cursor .ring { fill: none; stroke: var(--gold); stroke-width: 7; stroke-linecap: round; }

/* ---------- Pratonton kamera ---------- */
.camera-preview {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 200px;
  border-radius: 16px;
  overflow: hidden;
  border: 4px solid #fff;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
  background: #000;
  z-index: 10;
}
#output_canvas { display: block; width: 100%; height: auto; }
#camera-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 10px;
  color: #fff;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.6);
}

@media (max-width: 720px) {
  .topbar { flex-direction: column; gap: 10px; }
  .options-container { grid-template-columns: 1fr; }
  .btn-option.answer { min-height: 90px; flex-direction: row; }
  #question { font-size: 24px; }
  .camera-preview { width: 120px; }
}
