/* ---------------------------------------------------------------
   Maten Health — design layer on top of Bootstrap 5.3 colour modes.
   Tokens are defined for light, then overridden for [data-bs-theme=dark].
   --------------------------------------------------------------- */
:root {
  color-scheme: light;

  --mh-ink:        #0d1b2a;   /* primary text — flips with the theme */
  --mh-brand:      #1f6feb;
  --mh-brand-hover:#1a5fd0;
  --mh-brand-2:    #0ea5a4;   /* decorative use only */
  --mh-mark-2:     #0b7f7e;   /* gradient end where text sits on top */
  --mh-on-brand:   #ffffff;   /* text that sits ON a brand-coloured fill */
  --mh-surface:    #ffffff;
  --mh-surface-2:  #f6f8fb;
  --mh-border:     #e3e8ef;
  --mh-muted:      #5b6b7f;
  --mh-shadow:     0 1px 2px rgba(13,27,42,.06), 0 8px 24px rgba(13,27,42,.06);
  --mh-shadow-lg:  0 2px 4px rgba(13,27,42,.06), 0 18px 48px rgba(13,27,42,.12);
  --mh-radius:     14px;

  /* Status hues, plus the text colour that stays legible on top of them. */
  --mh-ok:         #15803d;
  --mh-bad:        #dc2626;
  --mh-warn:       #f59e0b;
  --mh-on-status:  #ffffff;
  --mh-status-tint: 10%;

  /* The hero is an always-dark surface in BOTH themes, so its colours must NOT
     be derived from --mh-ink (which inverts). Using --mh-ink here previously
     turned the hero near-white in dark mode with near-white text on it. */
  --mh-hero-bg:    #0d1b2a;
  --mh-hero-fg:    #eaf2ff;
  --mh-hero-lead:  #b9cbe4;
  --mh-hero-dim:   #9fb6d4;
  --mh-hero-line:  rgba(255,255,255,.18);
  --mh-hero-chip:  rgba(255,255,255,.10);
  --mh-hero-chip-border: rgba(255,255,255,.16);
  --mh-hero-chip-fg: #cfe0f7;

  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bs-body-color: #17222f;
  --bs-body-bg: var(--mh-surface-2);
  /* Bootstrap 5.3 reads --bs-link-color-rgb, not --bs-link-color. */
  --bs-link-color: #1a5fd0;
  --bs-link-color-rgb: 26, 95, 208;
  --bs-link-hover-color: var(--mh-brand-hover);
  --bs-link-hover-color-rgb: 26, 95, 208;
}

[data-bs-theme="dark"] {
  color-scheme: dark;

  --mh-ink:        #e7eef7;
  --mh-brand:      #5b9dff;
  --mh-brand-hover:#7fb2ff;
  --mh-brand-2:    #2dd4bf;
  --mh-mark-2:     #2dd4bf;
  /* #5b9dff is light: white text on it is only 2.7:1. Dark text is 7:1. */
  --mh-on-brand:   #06101f;
  --mh-surface:    #131a24;
  --mh-surface-2:  #0d131b;
  --mh-border:     #253143;
  --mh-muted:      #9bacc2;
  --mh-shadow:     0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --mh-shadow-lg:  0 2px 4px rgba(0,0,0,.4), 0 18px 48px rgba(0,0,0,.5);

  /* Brighter status hues so they read against a dark surface, with dark text
     on top of the solid fills. */
  --mh-ok:         #34d399;
  --mh-bad:        #f87171;
  --mh-warn:       #fbbf24;
  --mh-on-status:  #06101f;
  --mh-status-tint: 18%;

  --mh-hero-bg:    #0b1526;
  /* hero foreground tokens deliberately inherit the light block: the hero is
     dark in both themes, so its text stays light in both. */

  --bs-body-color: #dce6f2;
  --bs-body-bg: var(--mh-surface-2);
  --bs-link-color: var(--mh-brand);
  --bs-link-color-rgb: 91, 157, 255;
  --bs-link-hover-color: var(--mh-brand-hover);
  --bs-link-hover-color-rgb: 127, 178, 255;
}

body { background: var(--bs-body-bg); }
.text-body-secondary { color: var(--mh-muted) !important; }

/* ---------- chrome ---------- */
.site-nav {
  background: color-mix(in srgb, var(--mh-surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--mh-border);
}
.brand-mark {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--mh-brand), var(--mh-mark-2));
  color: var(--mh-on-brand); font-size: 1.05rem;
}
.brand-mark-sm { width: 26px; height: 26px; font-size: .85rem; border-radius: 8px; }
.brand-text { font-weight: 700; letter-spacing: -.01em; color: var(--mh-ink); }
.navbar-nav .nav-link { font-weight: 500; color: var(--mh-muted); }
.navbar-nav .nav-link.active,
.navbar-nav .nav-link:hover { color: var(--mh-brand); }

.btn-primary {
  /* Bootstrap 5.3 hardcodes --bs-btn-bg on .btn-primary, so setting --bs-primary
     alone does nothing — these are the variables the component actually reads. */
  --bs-btn-color: var(--mh-on-brand);
  --bs-btn-bg: var(--mh-brand);
  --bs-btn-border-color: var(--mh-brand);
  --bs-btn-hover-color: var(--mh-on-brand);
  --bs-btn-hover-bg: var(--mh-brand-hover);
  --bs-btn-hover-border-color: var(--mh-brand-hover);
  --bs-btn-active-color: var(--mh-on-brand);
  --bs-btn-active-bg: var(--mh-brand-hover);
  --bs-btn-active-border-color: var(--mh-brand-hover);
  --bs-btn-disabled-color: var(--mh-on-brand);
  --bs-btn-disabled-bg: var(--mh-brand);
  --bs-btn-disabled-border-color: var(--mh-brand);
}
.badge.text-bg-primary { background-color: var(--mh-brand) !important; color: var(--mh-on-brand) !important; }

.btn-ghost {
  border: 1px solid var(--mh-border);
  background: var(--mh-surface);
  color: var(--bs-body-color);
}
.btn-ghost:hover { background: var(--mh-surface-2); color: var(--mh-brand); }

.avatar {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--mh-brand), var(--mh-mark-2));
  color: var(--mh-on-brand); font-size: .72rem; font-weight: 700; letter-spacing: .02em;
}

.site-footer { background: var(--mh-surface); border-top: 1px solid var(--mh-border); }

/* ---------- surfaces ---------- */
.card, .panel {
  background: var(--mh-surface);
  border: 1px solid var(--mh-border);
  border-radius: var(--mh-radius);
  box-shadow: var(--mh-shadow);
}
.panel { padding: 1.25rem; }
.panel-tight { padding: 1rem; }

/* ---------- hero ---------- */
.hero {
  background:
    radial-gradient(1100px 460px at 12% -10%, rgba(31,111,235,.20), transparent 60%),
    radial-gradient(900px 420px at 88% 0%, rgba(14,165,164,.18), transparent 60%),
    var(--mh-hero-bg);
  color: var(--mh-hero-fg);
  border-bottom: 1px solid var(--mh-border);
}
.hero .lead { color: var(--mh-hero-lead); }
/* The hero is dark in both themes, so anything Bootstrap themes by colour mode
   has to be pinned back to light-on-dark inside it. */
.hero .breadcrumb {
  --bs-breadcrumb-divider-color: rgba(255,255,255,.4);
  --bs-breadcrumb-item-active-color: rgba(255,255,255,.6);
}
.hero .breadcrumb a { color: var(--mh-hero-lead); text-decoration: none; }
.hero .breadcrumb a:hover { color: var(--mh-hero-fg); }
/* Cards nested inside the hero paint their own themed background, so they must
   NOT inherit the hero's light-on-dark text colour — in light mode that put
   near-white text on a white panel. */
.hero .panel,
.hero .card,
.hero .course-card {
  color: var(--bs-body-color);
}
.hero-stat { border-left: 2px solid var(--mh-hero-line); padding-left: 1rem; }
.hero-stat .n { font-size: 1.6rem; font-weight: 700; line-height: 1; color: #fff; }
.hero-stat .l { font-size: .78rem; color: var(--mh-hero-dim); text-transform: uppercase; letter-spacing: .06em; }
.eyebrow {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .74rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  padding: .3rem .7rem; border-radius: 999px;
  background: var(--mh-hero-chip); border: 1px solid var(--mh-hero-chip-border);
  color: var(--mh-hero-chip-fg);
}

/* ---------- course cards ---------- */
.course-card {
  display: flex; flex-direction: column; height: 100%;
  border-radius: var(--mh-radius); overflow: hidden;
  background: var(--mh-surface); border: 1px solid var(--mh-border);
  box-shadow: var(--mh-shadow);
  transition: transform .15s ease, box-shadow .15s ease;
}
.course-card:hover { transform: translateY(-3px); box-shadow: var(--mh-shadow-lg); }
.course-card .accent-bar { height: 4px; background: var(--accent, var(--mh-brand)); }
.course-emoji {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  font-size: 1.4rem;
  background: color-mix(in srgb, var(--accent, var(--mh-brand)) 14%, transparent);
}
.chip {
  display: inline-block; font-size: .74rem; font-weight: 600;
  padding: .22rem .6rem; border-radius: 999px;
  background: var(--mh-surface-2); border: 1px solid var(--mh-border); color: var(--mh-muted);
}
.chip-accent {
  background: color-mix(in srgb, var(--accent, var(--mh-brand)) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent, var(--mh-brand)) 30%, transparent);
  color: var(--accent, var(--mh-brand));
}
/* Course accents are stored per course and never vary with the theme, so the
   chip text is darkened on light surfaces and lightened on dark ones — at their
   raw value they land around 3:1 against the tinted chip background. */
.chip-accent {
  color: color-mix(in srgb, var(--accent, var(--mh-brand)) 75%, #000000);
}
[data-bs-theme="dark"] .chip-accent {
  color: color-mix(in srgb, var(--accent, var(--mh-brand)) 65%, #ffffff);
}

/* ---------- quiz ---------- */
.option-btn {
  display: flex; gap: .8rem; width: 100%; text-align: left;
  padding: .85rem 1rem; margin-bottom: .6rem;
  border: 1.5px solid var(--mh-border); border-radius: 12px;
  background: var(--mh-surface); color: var(--bs-body-color);
  transition: border-color .12s ease, background .12s ease;
}
.option-btn:hover:not(:disabled) { border-color: var(--mh-brand); background: var(--mh-surface-2); }
.option-btn .letter {
  flex: 0 0 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--mh-surface-2); border: 1px solid var(--mh-border);
  font-weight: 700; font-size: .8rem;
}
.option-btn.selected { border-color: var(--mh-brand); background: color-mix(in srgb, var(--mh-brand) 8%, transparent); }
.option-btn.selected .letter {
  background: var(--mh-brand); border-color: var(--mh-brand); color: var(--mh-on-brand);
}
.option-btn.correct {
  border-color: var(--mh-ok);
  background: color-mix(in srgb, var(--mh-ok) var(--mh-status-tint), transparent);
}
.option-btn.correct .letter {
  background: var(--mh-ok); border-color: var(--mh-ok); color: var(--mh-on-status);
}
.option-btn.wrong {
  border-color: var(--mh-bad);
  background: color-mix(in srgb, var(--mh-bad) var(--mh-status-tint), transparent);
}
.option-btn.wrong .letter {
  background: var(--mh-bad); border-color: var(--mh-bad); color: var(--mh-on-status);
}
.option-btn:disabled { opacity: 1; cursor: default; }

.q-progress { height: 6px; border-radius: 999px; background: var(--mh-border); overflow: hidden; }
.q-progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--mh-brand), var(--mh-brand-2)); transition: width .2s ease; }

.q-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: .35rem; }
.q-dot {
  aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--mh-border);
  background: var(--mh-surface); font-size: .75rem; font-weight: 600;
  display: grid; place-items: center; color: var(--mh-muted);
}
.q-dot.answered { background: color-mix(in srgb, var(--mh-brand) 16%, transparent); border-color: var(--mh-brand); color: var(--mh-brand); }
.q-dot.correct  {
  background: color-mix(in srgb, var(--mh-ok) 18%, transparent);
  border-color: var(--mh-ok); color: var(--mh-ok);
}
.q-dot.wrong    {
  background: color-mix(in srgb, var(--mh-bad) 18%, transparent);
  border-color: var(--mh-bad); color: var(--mh-bad);
}
.q-dot.current  { outline: 2px solid var(--mh-brand); outline-offset: 1px; }

/* ---------- AI panel ---------- */
.ai-panel { border: 1px dashed var(--mh-border); border-radius: 12px; background: var(--mh-surface-2); }
.ai-text { white-space: pre-wrap; line-height: 1.65; }
.ai-text strong { color: var(--mh-ink); }
.ai-bubble { border-radius: 12px; padding: .6rem .85rem; margin-bottom: .5rem; max-width: 92%; }
.ai-bubble.user { margin-left: auto; background: color-mix(in srgb, var(--mh-brand) 12%, transparent); }
.ai-bubble.model { background: var(--mh-surface); border: 1px solid var(--mh-border); }
.ai-log { max-height: 340px; overflow-y: auto; }

/* ---------- score ring ---------- */
.score-ring {
  --pct: 0;
  width: 132px; height: 132px; border-radius: 50%;
  background: conic-gradient(var(--ring, var(--mh-brand)) calc(var(--pct) * 1%), var(--mh-border) 0);
  display: grid; place-items: center;
}
.score-ring > div {
  width: 104px; height: 104px; border-radius: 50%; background: var(--mh-surface);
  display: grid; place-items: center; line-height: 1.1;
}
.score-ring .pct { font-size: 1.9rem; font-weight: 700; }

.stat-tile { background: var(--mh-surface-2); border: 1px solid var(--mh-border); border-radius: 12px; padding: .9rem 1rem; }
.stat-tile .n { font-size: 1.45rem; font-weight: 700; line-height: 1.1; }
.stat-tile .l { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--mh-muted); }

/* Bootstrap 5.3 re-tunes only its *-text-emphasis / *-bg-subtle variables for
   dark mode; --bs-success-rgb and friends stay at their light-mode values, so
   .text-success and .text-danger come out too dark to read on a dark surface. */
[data-bs-theme="dark"] .text-success { color: var(--mh-ok) !important; }
[data-bs-theme="dark"] .text-danger  { color: var(--mh-bad) !important; }
[data-bs-theme="dark"] .text-warning { color: var(--mh-warn) !important; }

/* ---------- Google sign-in ---------- */
/* Colours come from Google's sign-in branding guidelines: a white button with a
   #1f1f1f label on light, #131314 with #e3e3e3 on dark. They are fixed values
   rather than theme tokens because the mark is Google's, not ours. */
.btn-google {
  --g-bg: #ffffff;
  --g-fg: #1f1f1f;
  --g-border: #747775;
  --g-hover: #f7f8f8;

  display: inline-flex; align-items: center; justify-content: center; gap: .65rem;
  padding: .65rem 1rem;
  border: 1px solid var(--g-border); border-radius: 10px;
  background: var(--g-bg); color: var(--g-fg);
  font-size: .95rem; font-weight: 500; text-decoration: none;
  transition: background .12s ease, box-shadow .12s ease;
}
[data-bs-theme="dark"] .btn-google {
  --g-bg: #131314;
  --g-fg: #e3e3e3;
  --g-border: #8e918f;
  --g-hover: #1e1f20;
}
.btn-google:hover { background: var(--g-hover); color: var(--g-fg); }
.btn-google:focus-visible {
  outline: 2px solid var(--mh-brand); outline-offset: 2px;
}
.btn-google-icon { display: inline-grid; place-items: center; flex: 0 0 18px; }

.auth-divider {
  display: flex; align-items: center; gap: .75rem;
  margin: 1.25rem 0; color: var(--mh-muted); font-size: .82rem;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1 1 auto; height: 1px; background: var(--mh-border);
}

.form-control, .form-select { border-color: var(--mh-border); }
.form-control:focus, .form-select:focus {
  border-color: var(--mh-brand);
  box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--mh-brand) 20%, transparent);
}
.sticky-side { position: sticky; top: 84px; }
@media (max-width: 991.98px) { .sticky-side { position: static; } }
