* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

body {
  background: #f8fafc;
  color: #1e293b;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ----- TOP BAR (compact) ----- */
.top-bar {
  background: linear-gradient(135deg, #0b2b4f 0%, #123a66 100%);
  color: white;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: nowrap;
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}

.logo-square {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  border: 2px solid #facc15;
  flex-shrink: 0;
  background-image: url('assets/images/logo192x192.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;
  font-size: 0;
}

.brand-text h1 {
  font-size: 1.4rem;
  letter-spacing: 0.5px;
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
}

.brand-text h1 small {
  font-size: 0.95rem;
  font-weight: 400;
  color: #cbd5e1;
  display: block;
  margin-top: 0.1rem;
}

.top-bar-right {
  margin-left: auto;
  min-width: 140px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  background: rgba(255,255,255,0.05);
  border-radius: 30px;
  padding: 0.1rem 1rem;
  color: #94a3b8;
  font-size: 0.85rem;
  font-style: italic;
  border: 1px dashed #475569;
}

.lang-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.8rem;
  border-radius: 20px;
  background: rgba(234, 179, 8, 0.15);
  color: #eab308;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid #eab308;
  transition: background 0.2s;
}
.lang-switch-btn:hover {
  background: rgba(234, 179, 8, 0.3);
  color: #facc15;
}

/* Keep brand text on the right of logo on mobile */
@media (max-width: 700px) {
  .top-bar {
    flex-wrap: nowrap;
    gap: 0.6rem;
    padding: 0.5rem 0.7rem;
  }
  .logo-square { width: 44px; height: 44px; border-radius: 10px; }
  .brand-text h1 { font-size: 1.05rem; }
  .brand-text h1 small { font-size: 0.75rem; }
  .top-bar-right {
    min-width: unset;
    padding: 0.1rem 0.6rem;
    font-size: 0.7rem;
  }
}

/* ----- SUBHEADING BANNER ----- */
.subhead-banner {
  background: #0f2e4f;
  color: #e2e8f0;
  text-align: center;
  padding: 0.4rem 1rem;
  font-size: 1rem;
  font-style: italic;
  letter-spacing: 0.4px;
  border-bottom: 2px solid #eab308;
}

.subhead-banner span { display: inline-block; padding: 0 0.6rem; }
.subhead-banner i { color: #eab308; margin: 0 0.5rem; font-style: normal; }

/* ----- NAVIGATION (compact) ----- */
.main-nav {
  background: white;
  box-shadow: 0 3px 10px rgba(0,0,0,0.03);
  padding: 0 1rem;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 50;
}

.main-nav ul {
  display: flex;
  list-style: none;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.main-nav a {
  text-decoration: none;
  color: #1e293b;
  font-weight: 600;
  font-size: 1rem;
  padding: 0.7rem 0.1rem;
  display: inline-block;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}
.main-nav a:hover, .main-nav a.active {
  color: #0b2b4f;
  border-bottom-color: #eab308;
}

/* ----- CONTAINER (narrower side padding) ----- */
.container {
  max-width: 1600px;
  margin: 1.2rem auto;
  padding: 0 0.4rem;
  flex: 1;
  width: 100%;
}

h2 {
  font-size: 1.8rem;
  font-weight: 700;
  color: #0b2b4f;
  margin-bottom: 0.9rem;
  border-left: 6px solid #eab308;
  padding-left: 0.8rem;
}

h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #0f3b66;
  margin: 1rem 0 0.6rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.1rem;
  margin: 1.2rem 0;
}

.subject-card,
a.subject-card {
  background: white;
  border-radius: 18px;
  padding: 1.2rem 1rem;
  box-shadow: 0 8px 16px -6px rgba(0,0,0,0.06);
  border: 1px solid #e9eef3;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  text-decoration: none;
  color: inherit;
}
.subject-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 14px 24px -8px rgba(11,43,79,0.15);
  border-color: #cbd5e1;
}
.subject-card i { font-size: 2rem; color: #eab308; margin-bottom: 0.6rem; }
.subject-card h3 { margin: 0.3rem 0 0.3rem; font-size: 1.15rem; color: #0f3b66; }
.subject-card p { color: #475569; font-size: 0.9rem; }

/* ----- BREADCRUMB ----- */
.breadcrumb {
  font-size: 0.9rem;
  color: #64748b;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.breadcrumb a { color: #0b2b4f; text-decoration: none; font-weight: 600; }
.breadcrumb a:hover { color: #eab308; }
.breadcrumb span { color: #94a3b8; }

/* ----- BUTTONS (compact) ----- */
.btn {
  background: #0b2b4f;
  color: white;
  border: none;
  padding: 0.55rem 1.2rem;
  border-radius: 30px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 4px 10px rgba(11,43,79,0.18);
  text-decoration: none;
}
.btn:hover { background: #123a66; transform: scale(1.02); }
.btn-outline {
  background: transparent;
  color: #0b2b4f;
  border: 2px solid #0b2b4f;
  box-shadow: none;
}
.btn-outline:hover { background: #f1f5f9; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* ----- EXERCISE PANEL ----- */
.exercise-panel {
  background: white;
  border-radius: 20px;
  padding: 0.8rem 0.7rem;
  box-shadow: 0 12px 25px -10px rgba(0,0,0,0.1);
  border: 1px solid #dce5ec;
  margin-top: 0.8rem;
}

.question-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
  padding-bottom: 0.6rem;
  gap: 0.5rem;
}

/* Motivational line in the question header */
.header-motto {
  font-size: 1rem;
  font-weight: 600;
  color: #0b2b4f;
  font-style: italic;
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

/* Two-column layout: text left, image right (desktop) */
.question-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 0.8rem;
  align-items: start;
}

.question-layout.has-image {
  grid-template-columns: minmax(0, 1fr) minmax(200px, 320px);
}

.question-main {
  min-width: 0;   /* allows flex/grid child to shrink properly */
}

.question-image-col {
  position: sticky;
  top: 1rem;
  align-self: start;
}

.question-image-col .question-image {
  margin: 0;
}

.question-image-col .question-image img {
  width: 100%;
  height: auto;
  max-width: 100%;
  display: block;
  border-radius: 8px;
}

/* ----- TOPIC / SUBTOPIC / LEVEL BUTTONS ----- */
.topic-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.8rem 0 1rem;
}
.topic-btn {
  background: white;
  border: 2px solid #cbd5e1;
  color: #0b2b4f;
  padding: 0.5rem 1rem;
  border-radius: 30px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: inherit;
}
.topic-btn i { color: #eab308; }
.topic-btn:hover {
  border-color: #eab308;
  background: #fffbeb;
  transform: translateY(-2px);
}
.topic-btn.active-topic {
  background: #0b2b4f;
  color: white;
  border-color: #0b2b4f;
}
.topic-btn.active-topic i { color: #eab308; }

.subtopic-section {
  background: #f8fafc;
  border-radius: 16px;
  padding: 1rem;
  border: 1px dashed #cbd5e1;
  margin-bottom: 1rem;
}
.subtopic-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.subtopic-btn {
  background: white;
  border: 2px solid #cbd5e1;
  color: #0b2b4f;
  padding: 0.45rem 0.9rem;
  border-radius: 26px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: inherit;
  text-align: left;
}
.subtopic-btn strong { color: #eab308; font-weight: 800; margin-right: 0.2rem; }
.subtopic-btn:hover {
  border-color: #eab308;
  background: #fffbeb;
  transform: translateY(-2px);
}
.subtopic-btn.active-subtopic {
  background: #0b2b4f;
  color: white;
  border-color: #0b2b4f;
}
.subtopic-btn.active-subtopic strong { color: #eab308; }

.level-section {
  background: #fffbeb;
  border-radius: 16px;
  padding: 0.9rem 1rem;
  border: 1px dashed #facc15;
  margin-bottom: 1rem;
}
.level-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.level-btn {
  background: white;
  border: 2px solid #facc15;
  color: #78350f;
  padding: 0.5rem 1.2rem;
  border-radius: 26px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: inherit;
}
.level-btn i { color: #eab308; }
.level-btn:hover {
  background: #fef3c7;
  transform: translateY(-2px);
}
.level-btn.active-level {
  background: #eab308;
  color: #0b2b4f;
  border-color: #eab308;
}
.level-btn.active-level i { color: #0b2b4f; }

/* ----- BACK BUTTON ----- */
.back-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}
.btn-back {
  background: #f1f5f9;
  color: #0b2b4f;
  border: 2px solid #cbd5e1;
  padding: 0.35rem 0.9rem;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: inherit;
  transition: all 0.2s;
}
.btn-back:hover {
  background: #e2e8f0;
  border-color: #eab308;
}

/* ----- STEPS / ANSWER LINES ----- */
.step-container { margin: 0.8rem 0; padding: 0.4rem 0; }

.answer-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
  font-size: 1.05rem;
  line-height: 2.1;
  padding: 0.35rem 0.35rem;
  border-radius: 8px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.answer-line:hover { background: #f8fafc; }
.answer-line.has-blanks { background: #f8fafc; }

.math-seg {
  display: inline;
  white-space: nowrap;   /* keep math fragment together */
}

.line-hint {
  flex-basis: 100%;
  font-size: 0.85rem;
  color: #b45309;
  background: #fef3c7;
  padding: 0.25rem 0.7rem;
  border-radius: 8px;
  margin-top: 0.2rem;
  font-style: italic;
  display: none;
}
.line-hint.visible { display: inline-block; }

/* ----- INLINE BLANK INPUTS ----- */
.blank-input {
  display: inline-block;
  min-width: 40px;
  padding: 0.15rem 0.35rem;
  border: 2px solid #cbd5e1;
  border-radius: 8px;
  font-size: 1rem;
  font-family: 'Courier New', monospace;
  text-align: center;
  background: #f9fcff;
  transition: border 0.15s;
  margin: 0 0.15rem;
  vertical-align: middle;
}
.blank-input:focus {
  border-color: #eab308;
  outline: none;
  box-shadow: 0 0 0 3px rgba(234,179,8,0.2);
}
.blank-input.correct {
  border-color: #10b981;
  background: #ecfdf5;
  color: #065f46;
}
.blank-input.wrong {
  border-color: #ef4444;
  background: #fef2f2;
}
.blank-input:disabled {
  cursor: default;
  opacity: 0.95;
}

/* Per-blank Submit button */
.blank-submit {
  background: #0b2b4f;
  color: white;
  border: none;
  padding: 0.1rem 0.5rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  margin-left: 0.15rem;
  vertical-align: middle;
  font-family: inherit;
}
.blank-submit:hover { background: #123a66; }
.blank-submit:disabled { opacity: 0.4; cursor: not-allowed; }

/* Hint button per line */
.line-hint-btn {
  background: transparent;
  border: 1.5px dashed #eab308;
  color: #b45309;
  padding: 0.1rem 0.55rem;
  border-radius: 14px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  margin-left: 0.3rem;
  vertical-align: middle;
  font-family: inherit;
}
.line-hint-btn:hover { background: #fef3c7; }

.feedback-icon {
  font-size: 1.05rem;
  margin-left: 0.2rem;
  vertical-align: middle;
}
.fa-check-circle { color: #10b981; }
.fa-times-circle { color: #ef4444; }

/* ----- EXERCISE ACTIONS ----- */
.exercise-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  align-items: center;
  padding-top: 0.8rem;
  border-top: 1px solid #e2e8f0;
}
.score-display {
  font-size: 1.15rem;
  font-weight: 700;
  background: #f1f5f9;
  padding: 0.35rem 1rem;
  border-radius: 30px;
  color: #0b2b4f;
  margin-left: auto;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn:disabled:hover {
  background: transparent;
  transform: none;
}

/* Floating up-arrow button (bottom-right) */
.scroll-top-btn {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #0b2b4f;
  color: white;
  border: 2px solid #eab308;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  z-index: 100;
  transition: transform 0.2s, background 0.2s;
}
.scroll-top-btn:hover {
  background: #123a66;
  transform: scale(1.08);
}
.scroll-top-btn i { color: #eab308; }

/* Question stem */
.question-stem {
  font-size: 1.05rem;
  margin-bottom: 0.8rem;
  white-space: pre-wrap;
  line-height: 1.7;
}

/* Final feedback */
.final-feedback {
  margin-top: 0.8rem;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 1rem;
  display: inline-block;
}
.final-feedback.correct {
  background: #ecfdf5;
  color: #065f46;
  border-left: 4px solid #10b981;
}

/* ----- QUESTION IMAGES ----- */
figure.question-image {
  margin: 0.8rem auto;
  padding: 0.5rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  text-align: center;
  display: block;
}
figure.question-image img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  margin: 0 auto;
}
figure.question-image figcaption {
  margin-top: 0.4rem;
  font-size: 0.85rem;
  font-style: italic;
  color: #64748b;
}

/* ----- FOOTER ----- */
.footer {
  background: #0b2b4f;
  color: #cbd5e1;
  padding: 1.2rem 1rem;
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.9rem;
  border-top: 5px solid #eab308;
}
.footer a { color: #eab308; text-decoration: none; margin: 0 0.4rem; }
.footer a:hover { text-decoration: underline; }
.social-links {
  margin: 0.6rem 0;
  display: flex;
  justify-content: center;
  gap: 1.3rem;
  font-size: 1.15rem;
}

.text-muted { color: #64748b; }

/* ----- RESPONSIVE ----- */
@media (max-width: 700px) {
  .main-nav ul { gap: 0.8rem; }
  .main-nav a { font-size: 0.9rem; padding: 0.55rem 0.1rem; }
  .container { padding: 0 0.3rem; }
  .exercise-panel { padding: 0.7rem; border-radius: 14px; }
  .answer-line { font-size: 0.98rem; line-height: 2; }
  .blank-input { font-size: 0.95rem; }
  .math-seg { white-space: normal; }
  .header-motto {
    font-size: 0.9rem;
  }
  .question-layout.has-image {
    grid-template-columns: 1fr;
  }
  .question-image-col {
    position: static;
    order: -1;   /* forces image above text on mobile */
  }  
  h2 { font-size: 1.4rem; }
}