/* ===== CSS Variables ===== */
:root {
  --blue-50: #f8f7ff;
  --blue-100: #ece9ff;
  --blue-200: #ddd6ff;
  --blue-300: #c4b5fd;
  --blue-400: #a78bfa;
  --blue-500: #8b5cf6;
  --blue-600: #7c3aed;
  --blue-700: #6d28d9;
  --blue-800: #5b21b6;
  --blue-900: #4c1d95;

  --white: #ffffff;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;

  --success: #10b981;
  --success-bg: #d1fae5;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --warning: #f59e0b;
  --star: #ffd166;

  --shadow-sm: 0 1px 3px rgba(30, 64, 175, 0.08);
  --shadow-md: 0 4px 16px rgba(30, 64, 175, 0.12);
  --shadow-lg: 0 8px 32px rgba(30, 64, 175, 0.16);
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.25s ease;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background:
linear-gradient(
135deg,
#fff7fb 0%,
#f8f7ff 40%,
#eef6ff 100%
);
  min-height: 100vh;
  color: var(--gray-800);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Page Transitions ===== */
.page {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  animation: fadeIn 0.4s ease;
}

.page.active {
  display: flex;
}

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

/* ===== Header / Logo ===== */
.header {
  padding: 2rem 1.5rem 1rem;
  display: flex;
  justify-content: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-icon {
  width: 56px;
  height: 56px;
  color: var(--blue-600);
  filter: drop-shadow(var(--shadow-md));
}

.logo-icon svg {
  width: 100%;
  height: 100%;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-name {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--blue-800);
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.logo-sub {
  font-size: 1rem;
  font-weight: 600;
  color: var(--blue-500);
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ===== Home Page ===== */
.home-main {
  flex: 1;
  padding: 1rem 1.5rem 2rem;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.hero-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  box-shadow: var(--shadow-md);
  border: 1px solid #ebe7ff;
  margin-bottom: 2rem;
}

.hero-card h1 {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--blue-800);
  margin-bottom: 0.75rem;
}

.hero-card p {
  color: var(--gray-600);
  font-size: 1rem;
  max-width: 480px;
  margin: 0 auto;
}

.student-welcome-card {

  background: white;

  border: 1px solid #dbe7ff;

  border-radius: 20px;

  padding: 24px;

  margin: 30px 0;

  display: flex;

  align-items: center;

  box-shadow:
0 8px 30px rgba(139,92,246,0.08);

}

.tingkatan-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.tingkatan-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  background: var(--white);
  border: 2px solid var(--blue-100);
  border-radius: var(--radius);
  padding: 1.5rem;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  position: relative;
  font-family: inherit;
  width: 100%;
}

.tingkatan-card:hover {
  border-color: var(--blue-400);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  background:
linear-gradient(
180deg,
#ffffff,
#faf7ff
);
}

.tingkatan-card:active {
  transform: translateY(0);
}

.tingkatan-badge {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--blue-700);
}

.tingkatan-desc {
  font-size: 0.9rem;
  color: var(--gray-500);
  padding-right: 2rem;
}

.tingkatan-arrow {
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.5rem;
  color: var(--blue-400);
  font-weight: 700;
  transition: transform var(--transition);
}

.tingkatan-card:hover .tingkatan-arrow {
  transform: translateY(-50%) translateX(4px);
  color: var(--blue-600);
}

.footer {
  padding: 1.5rem;
  text-align: center;
}

.footer p {
  font-size: 0.8rem;
  color: var(--gray-400);
}

/* ===== Chapter Selection Page ===== */
.chapter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--white);
  border-bottom: 1px solid var(--blue-100);
  box-shadow: var(--shadow-sm);
}

.chapter-header-title {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#chapter-tingkatan-label {
  font-weight: 700;
  font-size: 1rem;
  color: var(--blue-800);
}

.chapter-header-sub {
  font-size: 0.75rem;
  color: var(--gray-400);
  font-weight: 500;
}

.header-spacer {
  width: 40px;
  flex-shrink: 0;
}

/* ===== Chapter Preview Page ===== */
.bab-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  gap: 1rem;
}

.bab-loading,
.bab-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
  color: var(--gray-500);
  font-weight: 600;
}

.bab-loading.hidden,
.bab-content.hidden,
.bab-error.hidden {
  display: none;
}

.bab-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

.bab-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--blue-100);
  text-align: center;
  width: 100%;
}

.bab-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.bab-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.35rem;
}

.bab-name {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--blue-800);
  margin-bottom: 1.75rem;
  line-height: 1.3;
}

.bab-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.75rem;
}

.bab-info-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--gray-600);
}

.bab-info-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--blue-600);
}

.bab-error p {
  color: var(--gray-600);
  margin-bottom: 0.5rem;
}

#bab-home-btn {
  width: 100%;
}

/* ===== Quiz Page ===== */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--white);
  border-bottom: 1px solid var(--blue-100);
  box-shadow: var(--shadow-sm);
  gap: 0.75rem;
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--blue-50);
  color: var(--blue-600);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.back-btn:hover {
  background: var(--blue-100);
  color: var(--blue-800);
}

.quiz-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

#quiz-tingkatan-label {
  font-weight: 700;
  font-size: 1rem;
  color: var(--blue-800);
}

.quiz-subtitle {
  font-size: 0.75rem;
  color: var(--gray-400);
  font-weight: 500;
}

.score-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--blue-600);
  color: var(--white);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.score-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.85;
}

.score-value {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
}

.progress-section {
  padding: 1rem 1.5rem 0;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-500);
}

.progress-bar {
  height: 8px;
  background: var(--blue-100);
  border-radius: 100px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue-500), var(--blue-600));
  border-radius: 100px;
  width: 0%;
  transition: width 0.5s ease;
}

.quiz-main {
  flex: 1;
  padding: 1.5rem;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.quiz-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
  color: var(--gray-500);
  font-weight: 600;
}

.quiz-loading.hidden {
  display: none;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--blue-100);
  border-top-color: var(--blue-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.question-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--blue-100);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.question-text {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--gray-800);
  text-align: center;
  line-height: 1.5;
}

.options-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 1rem 1.25rem;
  background: var(--white);
  border: 2px solid var(--blue-100);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  color: var(--gray-700);
  transition: all var(--transition);
  text-align: left;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--blue-400);
  background: var(--blue-50);
}

.option-btn .option-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--blue-100);
  color: var(--blue-700);
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: all var(--transition);
}

.option-btn.correct {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--gray-800);
}

.option-btn.correct .option-letter {
  background: var(--success);
  color: var(--white);
}

.option-btn.wrong {
  border-color: var(--error);
  background: var(--error-bg);
  color: var(--gray-800);
}

.option-btn.wrong .option-letter {
  background: var(--error);
  color: var(--white);
}

.option-btn:disabled {
  cursor: default;
}

.feedback {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1.1rem;
  text-align: center;
  animation: popIn 0.3s ease;
}

.feedback.correct-feedback {
  background: var(--success-bg);
  color: #065f46;
  border: 1px solid var(--success);
}

.feedback.wrong-feedback {
  background: var(--error-bg);
  color: #991b1b;
  border: 1px solid var(--error);
}

.feedback.hidden {
  display: none;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.next-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, var(--blue-600), var(--blue-700));
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-md);
}

.next-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--blue-700), var(--blue-800));
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.next-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.next-btn.hidden {
  display: none;
}

/* ===== Result Page ===== */
.result-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.result-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid #ebe7ff;
  text-align: center;
  max-width: 440px;
  width: 100%;
  animation: fadeIn 0.5s ease;
}

.result-icon {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
}

.result-card h1 {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--blue-800);
  margin-bottom: 0.25rem;
}

.result-subtitle {
  color: var(--gray-500);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.final-score-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.25rem;
  margin-bottom: 0.25rem;
}

.final-score-number {
  font-size: 4rem;
  font-weight: 800;
  color: var(--blue-600);
  line-height: 1;
}

.final-score-total {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--gray-400);
}

.score-percentage {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--blue-500);
  margin-bottom: 1.5rem;
}

.stars-container {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.star {
  font-size: 2rem;
  transition: transform 0.3s ease;
}

.star.filled {
  color: var(--star);
  animation: starPop 0.4s ease backwards;
}

.star.empty {
  color: var(--gray-200);
}

.star.filled:nth-child(1) { animation-delay: 0.1s; }
.star.filled:nth-child(2) { animation-delay: 0.2s; }
.star.filled:nth-child(3) { animation-delay: 0.3s; }
.star.filled:nth-child(4) { animation-delay: 0.4s; }
.star.filled:nth-child(5) { animation-delay: 0.5s; }

@keyframes starPop {
  from { opacity: 0; transform: scale(0) rotate(-30deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

.performance-message {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 2rem;
  min-height: 1.5rem;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.restart-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, var(--blue-600), var(--blue-700));
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-md);
}

.restart-btn:hover {
  background: linear-gradient(135deg, var(--blue-700), var(--blue-800));
  transform: translateY(-1px);
}

.home-btn {
  width: 100%;
  padding: 0.85rem;
  background: transparent;
  color: var(--blue-600);
  border: 2px solid var(--blue-200);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.home-btn:hover {
  background: var(--blue-50);
  border-color: var(--blue-400);
}

/* ===== Responsive ===== */
@media (min-width: 640px) {
  .welcome-card h1 {
    font-size: 2.25rem;
  }

  .question-text {
    font-size: 1.35rem;
  }

  .tingkatan-card {
    padding: 1.75rem 2rem;
  }

  .result-card {
    padding: 3rem 2.5rem;
  }
}

@media (max-width: 380px) {
  .logo-name {
    font-size: 1.4rem;
  }

  .logo-icon {
    width: 44px;
    height: 44px;
  }

  .welcome-card {
    padding: 1.5rem 1.25rem;
  }

  .question-card {
    padding: 1.5rem 1rem;
  }

  .question-text {
    font-size: 1.05rem;
  }

  .final-score-number {
    font-size: 3rem;
  }

  .star {
    font-size: 1.6rem;
  }
}

.welcome-card {

  background: white;

  border: 1px solid #ebe7ff;

  border-radius: 20px;

  padding: 24px;

  margin: 30px 0;

  display: flex;

  align-items: center;

  justify-content: space-between;

  box-shadow:
0 8px 30px rgba(139,92,246,0.08);
}

.welcome-left {

  display: flex;

  align-items: center;

  gap: 20px;
}

.avatar {

  width: 70px;
  height: 70px;

  border-radius: 50%;

  background:
linear-gradient(
135deg,
#f9a8d4,
#a78bfa
);

  font-size: 32px;

  color: white;

  display: flex;
  justify-content: center;
  align-items: center;
}

.welcome-card h3 {

  margin: 0;

  color: #2347b6;
}

.welcome-card p {

  margin-top: 8px;

  color: #666;
}

.name-input-card {

  background: white;

  border-radius: 20px;

  padding: 24px;

  margin: 20px 0 30px;

  box-shadow:
0 8px 30px rgba(139,92,246,0.08);

}

.name-input-card input {

  padding: 12px;

  border: 1px solid #dbe7ff;

  border-radius: 10px;

  width: 250px;

  font-size: 16px;

}

.name-input-card button {

  padding: 12px 18px;

  border: none;

  border-radius: 10px;

  background:
linear-gradient(
135deg,
#a78bfa,
#8b5cf6
);

  color: white;

  cursor: pointer;

  margin-left: 10px;

}

.student-welcome-card button {

  margin-top: 12px;

  padding: 10px 16px;

  border: 1px solid #ebe7ff;

  border-radius: 10px;

  background:
linear-gradient(
135deg,
#a78bfa,
#8b5cf6
);

  color: white;

  cursor: pointer;

  font-size: 14px;

}