/* =========================
   Variables & Dark Mode
========================= */
:root {
  --primary: #007bff;
  --primary-hover: #0056b3;
  --secondary: #6c757d;
  --secondary-hover: #5a6268;
  --success: #28a745;
  --danger: #dc3545;
  --light: #f8f9fa;
  --dark: #343a40;
  --card-bg: #ffffff;
  --text: #333333;
  --border: #dee2e6;
  --shadow: rgba(0, 0, 0, 0.1);
}

.dark-mode {
  --card-bg: #2d2d2d;
  --text: #e0e0e0;
  --border: #444444;
  --shadow: rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  padding: 15px;
  background-color: #f5f5f5;
  color: var(--text);
  transition: background-color 0.3s, color 0.3s;
  line-height: 1.5;
}
body.dark-mode { background-color: #1a1a1a; }

/* =========================
   Header & Breadcrumb
========================= */
.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}
.icon-button {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 5px;
  color: var(--text);
}
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  padding: 10px;
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: 0 1px 3px var(--shadow);
  margin: 0;
  font-size: 0.9rem;
}
.breadcrumb li { display: flex; align-items: center; margin-right: 8px; }
.breadcrumb li:not(:last-child)::after {
  content: "›";
  margin-left: 8px;
  color: var(--secondary);
}
.breadcrumb li a {
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
}
.breadcrumb li a:hover { text-decoration: underline; }

/* =========================
   Layout & Page Display
========================= */
.page { display: none; }
.page.active { display: block; }
h1 { font-size: 1.8rem; margin: 15px 0; text-align: center; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 15px;
  margin-bottom: 20px;
}
.topic-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 30px;
  margin-bottom: 20px;
}

/* =========================
   Cards (Grades & Subjects)
========================= */
.card, .subject-card, .grade-card {
  border-radius: 12px;
  background: var(--card-bg);
  box-shadow: 0 10px 15px -3px var(--shadow),
              0 4px 6px -2px var(--shadow);
  transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}
.card:hover, .subject-card:hover, .grade-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 25px -5px var(--shadow),
              0 10px 10px -5px var(--shadow);
}
.card-header {
  padding: 1.5rem;
  color: #ffffff;
  font-size: 1.5rem;
  font-weight: bold;
}
.card-body {
  padding: 1.5rem;
  background-color: #ffffff;
}
.card-body p {
  color: #4A5568;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.subject-list { list-style: none; padding: 0; margin-bottom: 1.5rem; }
.subject-list li { margin-bottom: 0.5rem; }
.subject-link {
  color: #555879;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s;
}
.subject-link:hover { color: #3B060A; }
.button-container { display: flex; justify-content: flex-end; }
.view-all-button {
  background-color: white;
  color: #3B060A;
  border: 2px solid #3B060A;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.3s ease;
}
.view-all-button:hover { background-color: #f1f1f1; }
.subject-card h2 {
  color: #ffffff;
  font-size: 1.3rem;
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
}
.subject-card button {
  margin-top: 1rem;
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 30px;
  font-weight: bold;
  color: white;
  cursor: pointer;
  background: inherit;
  transition: background-color 0.3s ease;
}
.subject-card button:hover { filter: brightness(0.9); }

/* =========================
   Topics & Subtopics
========================= */
.topic-section {
  background: #ffffff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}
.topic-section:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}
.topic-header {
  font-size: 1.2rem;
  font-weight: bold;
  color: #28ceab;
  margin-bottom: 15px;
}
.subtopic-list { display: flex; flex-direction: column; gap: 10px; padding-left: 10px; }
.subtopic-item { display: flex; align-items: center; font-size: 0.95rem; }
.subtopic-item::before { content: "•"; margin-right: 8px; color: #555879; }
.subtopic-button {
  background: none;
  border: none;
  text-align: left;
  padding: 8px 12px;
  color: #333;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 6px;
  width: 100%;
}
.subtopic-button:hover {
  background-color: rgba(40, 206, 171, 0.1);
  color: #28ceab;
  transform: translateX(5px);
}

/* =========================
   Quiz Page
========================= */
.quiz-container {
  padding: 20px;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 2px 10px var(--shadow);
  width: 90%;
  max-width: 400px;
  margin: 1rem auto;
}
.quiz-container h3 { font-size: 1.3rem; margin-bottom: 20px; }
.options-container { display: flex; flex-direction: column; gap: 12px; margin: 20px 0; }
.option-card {
  display: flex;
  align-items: center;
  padding: 15px;
  background-color: var(--light);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s ease;
}
.option-card:hover {
  background-color: #e9ecef;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px var(--shadow);
}
.option-input { margin-right: 12px; }
.input-container { margin: 20px 0; }
.input-container input {
  width: 100%;
  padding: 12px 15px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
}
.button-group { display: flex; gap: 15px; margin-top: 25px; }
.button-group button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
}
#submit-answer { background-color: var(--success); color: white; }
#submit-answer:hover { background-color: #218838; }
#timer { text-align: center; font-weight: bold; margin-top: 15px; color: var(--danger); font-size: 1.1rem; }

/* =========================
   Score Summary
========================= */
.summary-container {
  background: #fff;
  width: 100%;
  max-width: 400px;
  padding: 30px 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  margin: 20px auto;
}
.final-score {
  text-align: center;
  margin-bottom: 25px;
}
.final-progress-bar {
  background: #e0e0e0;
  border-radius: 20px;
  height: 15px;
  overflow: hidden;
  margin-top: 10px;
}
.final-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #28ceab, #28a745);
  width: 0;
  transition: width 0.6s ease-in-out;
  border-radius: 20px;
}
.card {
  background: #fff;
  padding: 20px;
  margin-bottom: 15px;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.card h2 {
  font-size: 1.05rem;
  margin-bottom: 8px;
  color: #222;
}
.answer { font-weight: bold; }
.status { font-style: italic; }
.explanation {
  font-size: 0.9rem;
  color: #333;
}
.correct { background-color: #d3f9d8; }
.incorrect { background-color: #ffe0e0; }
.unanswered { background-color: #fff3cd; }

/* =========================
   Skeleton Loader
========================= */
.skeleton-card {
  background: #e2e2e2;
  border-radius: 12px;
  height: 180px;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }
.skeleton-header { height: 50px; background: #ccc; }
.skeleton-body { padding: 15px; }
.skeleton-line {
  height: 10px;
  background: #ccc;
  border-radius: 4px;
  margin-bottom: 10px;
}
.dark-mode .skeleton-card,
.dark-mode .skeleton-header,
.dark-mode .skeleton-line { background: #444; }

/* =========================
   Buttons & Popup
========================= */
button { cursor: pointer; transition: all 0.2s ease; }
.back-btn {
  display: block;
  width: 100%;
  max-width: 200px;
  margin: 20px auto;
  padding: 12px;
  background-color: var(--secondary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
}
.back-btn:hover { background-color: var(--secondary-hover); }
.popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card-bg);
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 5px 25px var(--shadow);
  z-index: 1000;
  text-align: center;
  max-width: 90%;
  width: 400px;
}
.popup-content { display: flex; flex-direction: column; gap: 20px; }
.popup button {
  padding: 12px 24px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
}

/* =========================
   Responsive
========================= */
@media (max-width: 768px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
  h1 { font-size: 1.5rem; }
  .button-group { flex-direction: column; gap: 10px; }
  .topic-container { grid-template-columns: 1fr; gap: 20px; }
}
@media (max-width: 480px) {
  body { padding: 10px; }
  .grid { grid-template-columns: 1fr; gap: 10px; }
  h1 { font-size: 1.3rem; }
  .popup { width: 95%; padding: 20px; }
}

/* Flag button styling */
.flag-btn {
  background: transparent;
  border: 1px solid #dc3545;
  color: #dc3545;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 10px;
  transition: all 0.2s;
}

.flag-btn:hover {
  background: #dc3545;
  color: white;
}

.flag-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.no-mathjax {
  font-family: inherit !important;
  font-size: inherit !important;
  color: inherit !important;
  background: inherit !important;
}