/* ==========================================================================
   ATLAS QUIZ: spot checks on real clinical EEG pages
   ==========================================================================

   Behaviour is in assets/js/components/atlas-quiz.js, which also carries the
   markup contract. Structure:

     .atlas-quiz
       .aq-ask                question
       .aq-scroll             horizontal scroller
         .aq-frame            hugs the image; % coordinates are measured off it
           img.aq-page
           .aq-zone           option rectangles, invisible until answered
           .aq-mark           annotation, revealed on answering
           .aq-pin            where the learner clicked
       .aq-answers            chips, built by the script
       .aq-verdict
       .aq-explain

   The atlas pages are photographs of a recording, so the paper stays white in
   dark mode exactly as .var-stage does. The ink is fixed rather than
   theme-dependent, and inverting it would misrepresent what a reader sees at
   the machine.
   ========================================================================== */

.atlas-quiz {
  margin: 1rem 0 1.2rem;
  border: 1px solid #dfe6ee;
  border-left: 3px solid #0b6ab8;
  border-radius: 10px;
  background: #f7fafd;
  padding: 0.85rem 0.95rem 0.75rem;
  min-width: 0;
}

.aq-ask {
  margin: 0 0 0.6rem !important;
  font-size: 0.9rem !important;
  line-height: 1.5;
  color: #24303c;
}

.aq-tag {
  display: inline-block;
  margin-right: 0.45rem;
  border-radius: 999px;
  background: #0b6ab8;
  color: #fff;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.16rem 0.5rem;
  vertical-align: 0.06em;
}

/* --- the page -------------------------------------------------------- */

/* fit-content keeps the white paper the width of the page sitting on it. The
   pages are narrower than the column, and a full-width sheet with the trace
   pushed into its left half reads as a layout mistake. */
.aq-scroll {
  overflow-x: auto;
  width: fit-content;
  max-width: 100%;
  background: #fff;
  border: 1px solid #e3e9f0;
  border-radius: 8px;
  padding: 0.4rem;
}

/* Must hug the image, because a zone's percentages are the image's
   percentages. A frame wider than the picture puts every click target off by
   the difference. inline-block shrink-wraps it to the page's own width.
   Below 620px the 16 channel labels collide, which is the same floor
   .var-figure uses; narrower than that the scroller takes over. */
.aq-frame {
  position: relative;
  display: inline-block;
  min-width: 620px;
  max-width: 100%;
  vertical-align: top;
}

/* These are screenshots of a recording at a fixed resolution, so stretching
   them past 1:1 buys width and loses the trace. Natural size is the ceiling. */
.aq-page {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.atlas-quiz.is-pointable .aq-frame { cursor: crosshair; }
.atlas-quiz.is-pointable.is-answered .aq-frame { cursor: default; }

/* --- zones ----------------------------------------------------------- */

/* Invisible while the question is open: the whole point is that the learner
   finds the region, so drawing the options would answer it for them. */
.aq-zone,
.aq-mark {
  position: absolute;
  pointer-events: none;
  border-radius: 3px;
  border: 2px solid transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.aq-zone.aq-no-rect { display: none; }

.aq-zone.is-answer,
.aq-mark.is-answer {
  border-color: #1f9d55;
  background: rgba(31, 157, 85, 0.13);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.75) inset;
}

.aq-zone.is-near {
  border-color: #d68910;
  background: rgba(214, 137, 16, 0.12);
}

.aq-zone.is-chosen:not(.is-answer):not(.is-near) {
  border-color: #c0392b;
  background: rgba(192, 57, 43, 0.12);
}

.aq-zone.is-chosen.is-answer { border-width: 3px; }

.aq-pin {
  position: absolute;
  width: 13px;
  height: 13px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  border: 2px solid #1d1d1f;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
  pointer-events: none;
}

/* --- answers --------------------------------------------------------- */

.aq-answers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.6rem 0 0;
}

.aq-chip {
  appearance: none;
  border: 1px solid #cfdae6;
  border-radius: 8px;
  background: #fff;
  color: #33424f;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease;
}

.aq-chip:hover:not(:disabled) { background: #eef5fb; border-color: #9db9d4; }
.aq-chip:focus-visible { outline: 2px solid #0b6ab8; outline-offset: 2px; }
.aq-chip:disabled { cursor: default; opacity: 0.85; }

.aq-chip.is-correct {
  border-color: #1f9d55;
  background: #e9f7ef;
  color: #1a6b3d;
  opacity: 1;
}

.aq-chip.is-chosen.is-wrong {
  border-color: #c0392b;
  background: #fdecea;
  color: #97281c;
  opacity: 1;
}

.aq-chip.is-chosen.is-near {
  border-color: #d68910;
  background: #fdf3e3;
  color: #8a5806;
  opacity: 1;
}

/* --- verdict and explanation ----------------------------------------- */

.aq-verdict {
  margin: 0.55rem 0 0 !important;
  font-size: 0.875rem !important;
  line-height: 1.55;
  color: #45515e;
}

.aq-verdict:empty { display: none; }

.aq-flag { font-weight: 700; }
.aq-verdict.is-correct .aq-flag { color: #1a6b3d; }
.aq-verdict.is-near .aq-flag { color: #8a5806; }
.aq-verdict.is-wrong .aq-flag { color: #97281c; }
.aq-verdict.is-hint { color: #6e6e73; font-style: italic; }

.aq-again {
  appearance: none;
  margin-top: 0.5rem;
  border: 1px solid #cfdae6;
  border-radius: 8px;
  background: #fff;
  color: #33424f;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.32rem 0.65rem;
  cursor: pointer;
}

.aq-again:hover { background: #eef5fb; border-color: #9db9d4; }
.aq-again:focus-visible { outline: 2px solid #0b6ab8; outline-offset: 2px; }

.aq-explain {
  margin-top: 0.6rem;
  border-left: 3px solid #0b6ab8;
  padding-left: 0.7rem;
}

.aq-explain p {
  margin: 0 0 0.4rem !important;
  font-size: 0.875rem !important;
  line-height: 1.65;
  color: #45515e;
}

.aq-explain p:last-child { margin-bottom: 0 !important; }

/* --- dark ------------------------------------------------------------ */

body.dark .atlas-quiz {
  background: #232c36;
  border-color: #3a3a3c;
  border-left-color: #2997ff;
}

body.dark .aq-ask { color: #e5e5ea; }
body.dark .aq-tag { background: #2997ff; color: #10233a; }
body.dark .aq-scroll { background: #fff; border-color: #48484a; }
body.dark .aq-chip { background: #2c2c2e; border-color: #48484a; color: #e5e5ea; }
body.dark .aq-chip:hover:not(:disabled) { background: #3a3a3c; }
body.dark .aq-chip.is-correct { background: #14361f; border-color: #2ea86a; color: #9ce3b8; }
body.dark .aq-chip.is-chosen.is-wrong { background: #3a1a17; border-color: #e2705f; color: #f3b5ab; }
body.dark .aq-chip.is-chosen.is-near { background: #3a2c12; border-color: #e0a740; color: #f0d29a; }
body.dark .aq-verdict { color: #d6d6db; }
body.dark .aq-verdict.is-correct .aq-flag { color: #7fd8a3; }
body.dark .aq-verdict.is-near .aq-flag { color: #f0c274; }
body.dark .aq-verdict.is-wrong .aq-flag { color: #f0a498; }
body.dark .aq-verdict.is-hint { color: #a1a1a6; }
body.dark .aq-again { background: #2c2c2e; border-color: #48484a; color: #e5e5ea; }
body.dark .aq-again:hover { background: #3a3a3c; }
body.dark .aq-explain { border-left-color: #2997ff; }
body.dark .aq-explain p { color: #d6d6db; }

/* --- narrow ---------------------------------------------------------- */

@media (max-width: 768px) {
  .atlas-quiz { padding: 0.7rem 0.65rem 0.6rem; }
  .aq-ask { font-size: 0.9rem !important; line-height: 1.6; }
  .aq-chip { flex: 1 1 45%; font-size: 0.875rem; padding: 0.5rem 0.6rem; }
  .aq-verdict,
  .aq-explain p { font-size: 0.875rem !important; }
  .aq-scroll { padding: 0.3rem; }
}
