/* ==========================================================================
   MedVyra — one shared question layout for EVERY qbank.
   Loaded last on bm / fmge / neetpg / qbank-test / special / special2 /
   video / zv / grandtest so it wins over each page's own <style> block.

   Goals (the student's words):
     - every qbank's question screen looks the same
     - fits a phone or an iPad
     - ONLY vertical scrolling; never extend horizontally
     - smooth: no layout jump when an option is picked / explanation opens
   ========================================================================== */

/* ---------- 1. no horizontal scroll, anywhere ---------- */
html, body {
  overflow-x: hidden !important;
  max-width: 100% !important;
}
*, *::before, *::after { box-sizing: border-box; }

:root { --mvq-pad: clamp(14px, 3.6vw, 22px); }

/* The screen is only a positioning shell - NO padding of its own, so the
   card (or the page wrapper) is the single source of width. */
#testScreen, .screen {
  width: 100% !important;
  /* a hard 760px cap (not min()) so no page rule can widen it on iPad */
  max-width: 760px !important;
  margin-left: auto !important;
  margin-right: auto !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}
@media (max-width: 760px) {
  #testScreen, .screen { max-width: 100% !important; }
}
/* neetpg/fmge put `#testScreen` INSIDE a `.screen` AND are themselves
   `.screen`; the page's own `.screen{max-width:820px}` outranked the bare
   selector above, so name both together for a decisive weight. */
.screen#testScreen, #testScreen.screen, body #testScreen.screen {
  max-width: 760px !important;
}
@media (max-width: 760px) {
  .screen#testScreen, #testScreen.screen, body #testScreen.screen { max-width: 100% !important; }
}
/* any wrapper that directly holds the question screen must not add its own
   inset - that was why zv/special were narrower than neetpg/fmge */
.wrap:has(> #testScreen),
.wrap:has(> .screen),
.mvapp > #testScreen:first-child,
.mvapp > .screen:first-child {
  padding-left: 0 !important;
  padding-right: 0 !important;
  max-width: none !important;
}
/* The card is the single source of width. `margin` is zeroed too: some pages
   rely on a `.screen{margin:0 auto}` that zv does not have, which is why zv's
   card came out wider than the rest. */
#testScreen > .card, #testScreen .card, #testScreen.card {
  width: 100% !important;
  max-width: 760px !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  padding: var(--mvq-pad) !important;
  overflow: hidden;               /* nothing inside may push out */
}

/* ---------- 2. long words / images can never widen the page ---------- */
#qText, .qtext, #qExplanation, .qexp, #qOptions, .opt, .opt span, .opt .option-text,
.qnum, .chips, .qchip, .test-head {
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;                   /* lets flex children shrink */
}
img, video, canvas, iframe {
  max-width: 100% !important;
  height: auto !important;
}
#qImgBox img, #qImgBox video {
  display: block;
  width: 100% !important;
  max-width: 100% !important;
  border-radius: 12px;
  margin: 10px auto;
}

/* ---------- 3. the question card: one consistent rhythm ----------
   The qbanks use two different DOM shapes, which is why the question
   page looked different in each one:
     Type A:  <div id="testScreen" class="card glass">      (zv, special, bm)
     Type B:  <div id="testScreen" class="screen"><div class="card glass">
   Normalise both to the same width, padding and radius. */
#testScreen { padding-top: 10px !important; }

/* Type A - the screen itself is the card */
#testScreen.card {
  width: 100% !important;
  max-width: min(760px, 100%) !important;
  margin-inline: auto !important;
  padding: var(--mvq-pad) !important;
  border-radius: 18px !important;
}
/* Type B - the card is the child */
#testScreen .card,
#testScreen > .card {
  width: 100% !important;
  max-width: 100% !important;
  padding: var(--mvq-pad) !important;
  border-radius: 18px !important;
  overflow: hidden;
}
@media (min-width: 700px) {
  #testScreen.card, #testScreen .card {
    padding: 22px !important;
    border-radius: 20px !important;
  }
}
.test-head,
#testScreen .test-head {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.test-head .back { flex: 0 0 auto; }
.test-head .chips {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end;
  margin-left: auto;
}

/* progress dots: never a horizontal bar of 200 dots */
.qdots, #qDots {
  display: flex !important;
  flex-wrap: wrap !important;
  justify-content: center !important;
  gap: 6px !important;
  max-width: 100%;
  margin: 8px 0 !important;
}

/* timer bar stays a full-width block, then its label */
.timerbar, .timerfill { max-width: 100% !important; }
.timertxt { display: block; }

/* ---------- 4. the stem ---------- */
.qnum, #qNum {
  display: inline-block;
  margin: 10px 0 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  color: var(--muted, #5f6b7a);
}
#qText, .qtext {
  display: block;
  width: 100% !important;
  font-size: clamp(15px, 3.9vw, 16.5px) !important;
  line-height: 1.72 !important;
  margin: 0 0 14px !important;
  text-align: left;
}

/* ---------- 5. options: identical box, identical tap target ---------- */
#qOptions, .qoptions {
  display: flex !important;
  flex-direction: column !important;   /* ALWAYS one option per row - fixes the
                                          "layout differs per qbank" complaint */
  gap: 10px !important;
  width: 100% !important;
  margin: 0 !important;
}
.opt, #qOptions > button, .qoption {
  display: flex !important;
  align-items: flex-start !important;
  gap: 10px !important;
  width: 100% !important;
  max-width: 100% !important;
  padding: 13px 15px !important;
  border-radius: 12px !important;
  border: 2px solid rgba(45, 112, 182, .16) !important;
  background: #fff !important;
  color: var(--ink, #1a2332) !important;
  font-size: clamp(14px, 3.7vw, 15px) !important;
  line-height: 1.55 !important;
  text-align: left !important;
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) {
  .opt:hover:not(.correct):not(.wrong) {
    border-color: var(--blue, #62c8df) !important;
    transform: translateX(2px);
  }
}
.opt .letter, .opt > span:first-child, .option-letter {
  flex: 0 0 auto;
  min-width: 22px !important;
  font-weight: 800 !important;
  color: var(--blue, #2d70b6) !important;
}
.opt .option-text, .opt > span:last-child { flex: 1 1 auto; min-width: 0; }

/* answered states: same geometry, colour only - so nothing reflows */
.opt.correct {
  border-color: rgba(13, 144, 79, .55) !important;
  background: rgba(13, 144, 79, .10) !important;
}
.opt.wrong {
  border-color: rgba(211, 47, 47, .5) !important;
  background: rgba(211, 47, 47, .09) !important;
}
.opt.correct .letter, .opt.wrong .letter { color: inherit !important; }

/* ---------- 6. explanation: same look everywhere ---------- */
#qExplanation, .qexp {
  display: block;
  width: 100% !important;
  margin-top: 14px !important;
  padding: 14px 15px !important;
  border-radius: 12px !important;
  background: rgba(13, 144, 79, .07) !important;
  border: 1px solid rgba(13, 144, 79, .22) !important;
  font-size: clamp(13.5px, 3.5vw, 14.5px) !important;
  line-height: 1.72 !important;
}
#qExplanation.hidden, .qexp.hidden { display: none !important; }

/* ---------- 7. nav buttons: wrap into rows, never overflow ---------- */
.test-nav, #testScreen .test-nav {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 9px !important;
  width: 100% !important;
  margin-top: 16px !important;
}
.test-nav > button, .test-nav > a {
  flex: 1 1 auto;
  min-width: 104px;
  max-width: 100%;
  white-space: nowrap;
}
@media (max-width: 430px) {
  .test-nav > button, .test-nav > a { flex: 1 1 calc(50% - 5px); min-width: 0; }
}

/* ---------- 8. iPad / tablet: keep one readable column ---------- */
@media (min-width: 700px) {
  #testScreen, .screen { max-width: 780px !important; }
  #qText, .qtext { font-size: 17px !important; }
  .opt { font-size: 15.5px !important; padding: 15px 18px !important; }
}

/* ---------- 9. small phones ---------- */
@media (max-width: 380px) {
  .opt { padding: 12px 12px !important; }
  #qText, .qtext { font-size: 14.5px !important; }
  .qdots .dot { width: 5px !important; height: 5px !important; }
}

/* ---------- 10. the bottom tab bar must not cover the last button ---------- */
body.mvapp-hasbar #testScreen,
body.mvapp-hasbar .screen {
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
}
