:root {
  --mth-primary: #3659cf;
  --mth-primary-strong: #2a46a4;
  --mth-secondary: #ef476f;
  --mth-accent: #ffb703;
  --mth-success: #2ead62;
  --mth-info: #1d8fe1;
  --mth-surface: #ffffff;
  --mth-surface-soft: #f6f8fc;
  --mth-surface-soft-2: #eef2fb;
  --mth-text: #1f2430;
  --mth-text-muted: #5e6676;
  --mth-border: #dce2ee;
  --mth-shadow-soft: 0 10px 24px rgba(27, 39, 70, 0.08);
  --mth-shadow-lift: 0 16px 36px rgba(31, 36, 48, 0.14);
  --mth-radius-sm: 12px;
  --mth-radius-md: 16px;
  --mth-radius-lg: 20px;
}

html {
  font-size: 16px;
  position: relative;
  min-height: 100%;
}

body {
  font-family: "Source Sans 3", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--mth-text);
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 183, 3, 0.14), transparent 34%),
    radial-gradient(circle at 88% 5%, rgba(54, 89, 207, 0.2), transparent 32%),
    linear-gradient(180deg, var(--mth-surface-soft) 0%, #fbfcff 35%, var(--mth-surface) 100%);
  min-height: 100vh;
  margin: 0;
}

h1,
h2,
h3,
h4,
h5,
h6,
.navbar-brand {
  font-family: "Nunito", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  letter-spacing: 0.01em;
}

h1,
.h1 {
  font-size: clamp(2.05rem, 3vw, 2.5rem);
  line-height: 1.2;
}

h2,
.h2 {
  font-size: clamp(1.65rem, 2.2vw, 2rem);
  line-height: 1.25;
}

h3,
.h3,
.display-4 {
  font-size: clamp(1.45rem, 2vw, 1.85rem);
  line-height: 1.3;
}

a {
  color: var(--mth-primary);
}

a:hover {
  color: var(--mth-primary-strong);
}

.container,
.container-fluid {
  position: relative;
  z-index: 1;
}

main.pb-3 {
  padding-bottom: 2.5rem;
}

.navbar {
  border: 0;
  box-shadow: var(--mth-shadow-soft);
}

.navbar.bg-primary,
.navbar.navbar-dark {
  background: linear-gradient(95deg, #314da8 0%, var(--mth-primary) 48%, #1d8fe1 100%) !important;
}

.navbar .navbar-brand {
  font-size: 1.35rem;
  font-weight: 800;
}

.navbar .nav-link,
.navbar .navbar-text {
  font-weight: 700;
  color: rgba(255, 255, 255, 0.94) !important;
}

.navbar .nav-link:hover,
.navbar .nav-link:focus {
  color: #ffffff !important;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.card {
  border: 1px solid var(--mth-border);
  border-radius: var(--mth-radius-md);
  box-shadow: var(--mth-shadow-soft);
  background: var(--mth-surface);
}

.card-header {
  background: linear-gradient(180deg, #ffffff 0%, var(--mth-surface-soft) 100%);
  border-bottom: 1px solid var(--mth-border);
  border-top-left-radius: var(--mth-radius-md) !important;
  border-top-right-radius: var(--mth-radius-md) !important;
}

.btn {
  border-radius: var(--mth-radius-sm);
  min-height: 44px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.btn-lg {
  min-height: 50px;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, #4b67da 0%, var(--mth-primary) 100%);
  border: 1px solid #3552c3;
  box-shadow: 0 8px 18px rgba(53, 82, 195, 0.25);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  color: #fff;
  background: linear-gradient(180deg, #4060d8 0%, #314da8 100%);
  border-color: #2b4390;
}

.btn-outline-primary {
  border-color: #4b67da;
  color: #3956c9;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
  background: #3f5dcc;
  color: #fff;
  border-color: #3f5dcc;
}

.btn-success {
  background: linear-gradient(180deg, #37b86d 0%, var(--mth-success) 100%);
  border-color: #289d58;
}

.btn-warning {
  color: #1f2430;
  background: linear-gradient(180deg, #ffc445 0%, var(--mth-accent) 100%);
  border-color: #eba400;
}

.btn-info {
  color: #fff;
  background: linear-gradient(180deg, #37a2ef 0%, var(--mth-info) 100%);
  border-color: #1986d7;
}

.form-control,
.form-select {
  border: 1px solid var(--mth-border);
  border-radius: var(--mth-radius-sm);
  padding: 0.7rem 0.85rem;
  min-height: 46px;
}

textarea.form-control {
  min-height: 120px;
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus,
.form-select:focus {
  box-shadow: 0 0 0 0.25rem rgba(54, 89, 207, 0.22);
  border-color: #5f77d9;
}

.alert {
  border: 0;
  border-radius: var(--mth-radius-sm);
  box-shadow: var(--mth-shadow-soft);
}

.badge {
  border-radius: 999px;
  padding: 0.45em 0.75em;
}

.progress {
  border-radius: 999px;
  background-color: #e9eef8;
}

.progress-bar {
  background: linear-gradient(90deg, #4f6fe0 0%, #1d8fe1 100%);
}

.accordion-item {
  border: 1px solid var(--mth-border);
  border-radius: var(--mth-radius-sm) !important;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.accordion-button {
  font-weight: 700;
}

.accordion-button:not(.collapsed) {
  color: var(--mth-primary-strong);
  background: #eef2ff;
}

.hero-section {
  border-radius: var(--mth-radius-lg) !important;
  background:
    radial-gradient(circle at 80% 10%, rgba(255, 183, 3, 0.35), transparent 28%),
    linear-gradient(115deg, #2f4aa4 0%, #3b5fd1 52%, #1f9ce8 100%) !important;
  box-shadow: var(--mth-shadow-lift);
  animation: mth-rise-in 420ms ease-out;
}

.hero-section .lead {
  font-size: clamp(1.05rem, 1.8vw, 1.25rem);
}

.footer {
  position: static;
  width: 100%;
  margin-top: 3rem;
  padding: 1rem 0;
  line-height: 1.55;
  border-top: 1px solid var(--mth-border);
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(2px);
}

.footer .container {
  color: var(--mth-text-muted);
}

/* Exam mode shell */
body.exam-mode {
  background:
    radial-gradient(circle at 88% 8%, rgba(255, 183, 3, 0.2), transparent 34%),
    linear-gradient(180deg, #edf2ff 0%, #f5f8ff 45%, #ffffff 100%);
}

.exam-mode .navbar.navbar-light {
  background: #ffffff !important;
}

.exam-mode .navbar .navbar-brand,
.exam-mode .navbar .nav-link {
  color: #253147 !important;
}

.exam-warning-inline {
  font-size: 0.95rem;
  color: #5f4300;
  padding: 0.25rem 1rem;
}

/* Enhanced exam interface styles */
.passage-container .passage-text {
  line-height: 1.7;
  font-size: 1.05em;
  max-height: 420px;
  overflow-y: auto;
}

.question-content {
  font-size: 1.1em;
  line-height: 1.55;
}

.markup-instructions {
  border-left: 4px solid var(--mth-info);
}

.free-response-container textarea {
  resize: vertical;
  min-height: 120px;
}

.option-letter.option-n {
  background-color: var(--mth-accent);
  color: #212529;
  font-weight: 700;
}

.answer-option:hover {
  background-color: #f8fbff;
  border-radius: 0.6rem;
  padding: 0.5rem;
  margin-left: -0.5rem;
  margin-right: -0.5rem;
}

.answer-option.selected {
  background-color: #eaf1ff;
  border-left: 4px solid var(--mth-primary);
}

.section-nav {
  border-bottom: 2px solid var(--mth-border);
  margin-bottom: 2rem;
}

.section-nav .nav-link {
  color: #6c757d;
  border: none;
  border-bottom: 2px solid transparent;
  font-weight: 600;
}

.section-nav .nav-link.active {
  color: var(--mth-primary);
  border-bottom-color: var(--mth-primary);
}

.section-nav .nav-link:hover {
  border-bottom-color: var(--mth-border);
}

.badge.bg-warning {
  color: #212529;
}

.question-header {
  padding: 1rem 0;
  border-bottom: 1px solid var(--mth-border);
  margin-bottom: 1rem;
}

/* Inline exam page style harmonization */
.exam-container .exam-header,
.exam-container .exam-navigation {
  background: #f5f8ff !important;
  border-color: var(--mth-border) !important;
}

.exam-container .question-container,
.exam-container .punctuation-exercise,
.exam-container .comprehension-set-question-block,
.exam-container .section-overview-block {
  border-color: var(--mth-border) !important;
  border-radius: var(--mth-radius-sm) !important;
}

/* Dashboard/Admin metric tiles */
.card.bg-primary,
.card.bg-success,
.card.bg-info,
.card.bg-warning {
  border: 0;
  color: #fff !important;
}

.card.bg-primary {
  background: linear-gradient(140deg, #4e6ee4 0%, #3659cf 100%) !important;
}

.card.bg-success {
  background: linear-gradient(140deg, #3ac273 0%, #2ead62 100%) !important;
}

.card.bg-info {
  background: linear-gradient(140deg, #3caef5 0%, #1d8fe1 100%) !important;
}

.card.bg-warning {
  background: linear-gradient(140deg, #ffcb56 0%, #ffb703 100%) !important;
  color: #1f2430 !important;
}

.card.bg-warning .text-white,
.card.bg-warning .h5,
.card.bg-warning .h6,
.card.bg-warning .small {
  color: #1f2430 !important;
}

/* Pricing cards */
.price-circle {
  background: radial-gradient(circle at 30% 20%, #ffffff, #f0f5ff);
  border: 1px solid var(--mth-border);
  border-radius: var(--mth-radius-md);
  padding: 1rem 0.6rem;
}

/* Lists and callouts */
.list-group-item {
  border-color: var(--mth-border);
}

.list-group-item:first-child {
  border-top-left-radius: var(--mth-radius-sm);
  border-top-right-radius: var(--mth-radius-sm);
}

.list-group-item:last-child {
  border-bottom-left-radius: var(--mth-radius-sm);
  border-bottom-right-radius: var(--mth-radius-sm);
}

/* Modal polish */
.modal-content {
  border: 1px solid var(--mth-border);
  border-radius: var(--mth-radius-md);
  box-shadow: var(--mth-shadow-lift);
}

.modal-header,
.modal-footer {
  border-color: var(--mth-border);
}

@keyframes mth-rise-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 991.98px) {
  .navbar .navbar-nav .nav-link {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
  }

  .hero-section {
    padding: 2.5rem 1rem !important;
  }

  .footer {
    padding-top: 1.25rem;
    padding-bottom: 1.25rem;
  }
}

@media (max-width: 767.98px) {
  html {
    font-size: 15px;
  }

  .btn,
  .btn-lg {
    min-height: 46px;
  }

  .card {
    border-radius: 14px;
  }
}

/* Shared Child Learning Plan wizard (Register + Profile Settings) */
.wizard-progress-wrap {
  background: linear-gradient(135deg, #f3f8ff 0%, #eefaf2 100%);
  border: 1px solid #dbe7ff;
  border-radius: 16px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.wizard-progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.wizard-step {
  display: none;
}

.wizard-step.active {
  display: block;
}

.choice-grid {
  display: grid;
  gap: 0.75rem;
}

.choice-grid.levels {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-card {
  border: 1px solid #d9e2f2;
  border-radius: 14px;
  padding: 0.85rem;
  background: #fff;
  cursor: pointer;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.choice-card.active {
  border-color: #3065f3;
  background: #eef3ff;
  box-shadow: 0 0 0 2px rgba(48, 101, 243, 0.15);
}

.choice-card .title {
  font-weight: 700;
  color: #183153;
}

.choice-card .subtitle {
  font-size: 0.85rem;
  color: #5b6f8f;
}

.step-headline {
  font-size: 1.35rem;
  font-weight: 700;
  color: #10233f;
  margin-bottom: 0.35rem;
}

.step-sub {
  color: #5f6f86;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.recommend-badge {
  display: inline-block;
  background: #e8f7eb;
  color: #1e7a36;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  margin-top: 0.4rem;
}

.preview-card {
  border: 1px solid #d9e2f2;
  border-radius: 14px;
  background: #f8fbff;
  padding: 1rem;
}

.preview-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px dashed #d3dded;
  padding: 0.45rem 0;
  font-size: 0.93rem;
}

.preview-row:last-child {
  border-bottom: 0;
}

.sticky-cta {
  position: sticky;
  bottom: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(4px);
  border-top: 1px solid #e5eaf5;
  padding-top: 0.8rem;
  margin-top: 1rem;
}

.wizard-complete-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--mth-success);
  color: #fff;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.35rem 0.85rem;
  margin-bottom: 0.85rem;
}

.wizard-complete-badge.pop {
  animation: mth-badge-pop 480ms ease-out;
}

@keyframes mth-badge-pop {
  0% {
    transform: scale(0.85);
    opacity: 0;
  }
  60% {
    transform: scale(1.06);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

@media (min-width: 768px) {
  .choice-grid.levels {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .wizard-complete-badge.pop {
    animation: none;
  }
}

/* Fixed-height wrapper required by Chart.js when responsive:true and
   maintainAspectRatio:false are combined - without a constrained container,
   the canvas and its parent grow into each other on every resize/redraw. */
.chart-container {
  position: relative;
  height: 260px;
  width: 100%;
}

/* Kids Dashboard - deliberately larger, warmer, more colour-forward than the
   Parent Dashboard, since a 9-11 year old is reading it, not an adult. */
.kids-dashboard {
  font-size: 1.05rem;
}

.kids-dashboard h3 {
  font-size: 1.5rem;
}

.kids-level-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--mth-surface-soft-2);
  border: 2px solid var(--mth-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  flex: none;
}

.kids-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.3rem 0.7rem;
}

.kids-badge-level {
  background: rgba(54, 89, 207, 0.12);
  color: var(--mth-primary-strong);
}

.kids-badge-milestone {
  background: rgba(255, 183, 3, 0.16);
  color: #8a6a24;
}

.kids-badge-today {
  background: rgba(239, 71, 111, 0.12);
  color: var(--mth-secondary);
}

.kids-stat-tile {
  border-radius: var(--mth-radius-md);
  padding: 1.1rem 1rem;
  height: 100%;
  color: #fff;
  text-align: center;
}

.kids-stat-icon {
  font-size: 1.3rem;
  opacity: 0.9;
  margin-bottom: 0.35rem;
  display: block;
}

.kids-stat-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  opacity: 0.9;
}

.kids-stat-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
}

.kids-stat-value-text {
  font-size: 1.3rem;
}

.kids-stat-primary {
  background: linear-gradient(140deg, #4e6ee4 0%, var(--mth-primary) 100%);
}

.kids-stat-success {
  background: linear-gradient(140deg, #3ac273 0%, var(--mth-success) 100%);
}

.kids-stat-info {
  background: linear-gradient(140deg, #3caef5 0%, var(--mth-info) 100%);
}

.kids-start-btn {
  animation: mth-start-btn-pulse 2.4s ease-in-out infinite;
}

.kids-recommend-card {
  border-width: 2px;
}

@keyframes mth-start-btn-pulse {
  0%, 100% {
    box-shadow: 0 8px 18px rgba(53, 82, 195, 0.25);
  }
  50% {
    box-shadow: 0 8px 22px rgba(53, 82, 195, 0.45);
  }
}

@media (prefers-reduced-motion: reduce) {
  .kids-start-btn {
    animation: none;
  }
}

/* Exam Results hero score */
.results-hero {
  border: 0;
  animation: mth-results-hero-in 480ms ease-out;
}

.results-hero-good {
  background: linear-gradient(135deg, rgba(46, 173, 98, 0.08) 0%, #ffffff 60%);
}

.results-hero-warn {
  background: linear-gradient(135deg, rgba(255, 183, 3, 0.1) 0%, #ffffff 60%);
}

.results-hero-bad {
  background: linear-gradient(135deg, rgba(239, 71, 111, 0.08) 0%, #ffffff 60%);
}

.score-ring {
  --pct: 0;
  --ring-track: #e9eef8;
  width: 148px;
  height: 148px;
  border-radius: 50%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(var(--ring-color) calc(var(--pct) * 1%), var(--ring-track) 0);
  animation: mth-ring-pop 600ms ease-out;
}

.score-ring-good {
  --ring-color: var(--mth-success);
}

.score-ring-warn {
  --ring-color: var(--mth-accent);
}

.score-ring-bad {
  --ring-color: var(--mth-secondary);
}

.score-ring-inner {
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--mth-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-ring-value {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
  color: var(--mth-text);
}

.score-ring-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--mth-text-muted);
  margin-top: 0.2rem;
}

.results-headline {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--mth-text);
}

.results-summary {
  color: var(--mth-text-muted);
  font-size: 1.02rem;
}

.results-mini-stat {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--mth-border);
  border-radius: var(--mth-radius-sm);
  padding: 0.6rem 0.75rem;
  text-align: center;
}

.results-mini-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--mth-text-muted);
}

.results-mini-value {
  font-size: 1.25rem;
  font-weight: 700;
}

@keyframes mth-results-hero-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes mth-ring-pop {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .results-hero,
  .score-ring {
    animation: none;
  }
}

/* "With StudyBuddy" checkbox + label + info icon - explicit flex row so the checkbox, label
   text, and icon all sit on the same horizontal baseline as each other and as a sibling button,
   instead of relying on Bootstrap's inline-block form-check-inline sizing. */
.studybuddy-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.studybuddy-toggle .form-check-input {
  margin-top: 0;
}
.studybuddy-toggle .form-check-label {
  margin-bottom: 0;
  white-space: nowrap;
}
.studybuddy-info-icon {
  line-height: 1;
  text-decoration: none;
}

/* Shared chat transcript styling for the AI copilots (StudyBuddy, Parent Advisor). */
.study-buddy-transcript {
  overflow-y: auto;
  min-height: 200px;
}
.sb-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  margin-bottom: 8px;
  max-width: 90%;
  white-space: pre-wrap;
}
.sb-user {
  background: #cfe2ff;
  margin-left: auto;
  text-align: right;
}
.sb-model {
  background: #f1f1f1;
}