/* ==========================================================================
   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-section-primer,
.aq-primer {
  margin: 0 0 0.85rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  background: #eef5fb;
  border: 1px solid #d4e4f0;
  color: #3f5263;
  font-size: 0.86rem;
  line-height: 1.52;
}

.aq-section-primer {
  margin-bottom: 1rem;
}

.aq-primer strong,
.aq-section-primer strong {
  color: #1f4f73;
}

.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%;
  margin-left: auto;
  margin-right: auto;
  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 {
  border-color: #1f9d55;
  background: rgba(31, 157, 85, 0.13);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.75) inset;
}

/* The zone says which chain; the mark says exactly where in it. Same red
   box-and-pill as the annotated clinical pages in the montage section, so the
   learner meets one visual language for "the finding is here". */
.aq-mark {
  box-sizing: border-box;
  border-radius: 6px;
  z-index: 2;
}

.aq-mark.is-answer {
  border-color: #c0392b;
  background: rgba(192, 57, 43, 0.08);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.16);
}

.aq-mark[data-kind="ref"].is-answer {
  border-color: #2b6fb5;
  border-style: dashed;
  background: rgba(43, 111, 181, 0.06);
  box-shadow: 0 0 0 3px rgba(43, 111, 181, 0.12);
}

.aq-mark-tag {
  position: absolute;
  left: 100%;
  top: 50%;
  margin-left: 12px;
  transform: translateY(-50%);
  padding: 0.18rem 0.5rem;
  border: 1px solid #c0392b;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: #c0392b;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.aq-mark-tag::before {
  content: "";
  position: absolute;
  right: 100%;
  top: 50%;
  width: 10px;
  height: 1px;
  background: currentColor;
}

.aq-mark.is-answer .aq-mark-tag { opacity: 1; }
.aq-mark[data-kind="ref"] .aq-mark-tag { border-color: #2b6fb5; color: #2b6fb5; }

.aq-mark[data-tag="left"] .aq-mark-tag {
  left: auto;
  right: 100%;
  margin: 0 12px 0 0;
}
.aq-mark[data-tag="left"] .aq-mark-tag::before { right: auto; left: 100%; }

/* For a mark that spans the whole row there is no "beside": the caption sits
   inside the box at its right end, where the trace has already made its point. */
.aq-mark[data-tag="inside"] .aq-mark-tag {
  left: auto;
  right: 6px;
  margin: 0;
}
.aq-mark[data-tag="inside"] .aq-mark-tag::before { display: none; }

/* For a tall mark (an onset column) the caption hangs off the top corner
   rather than the middle of the traces. */
.aq-mark[data-tag="top"] .aq-mark-tag {
  top: 4px;
  transform: none;
}

.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;
  z-index: 3;
  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;
  justify-content: center;
  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 {
    display: flex;
    flex-direction: column;
    padding: 0.7rem 0.65rem 0.6rem;
  }
  .aq-ask { order: 0; font-size: 0.9rem !important; line-height: 1.6; }
  .aq-answers { order: 1; }
  .aq-scroll { order: 2; padding: 0.3rem; }
  .aq-verdict { order: 3; }
  .aq-explain { order: 4; }
  .aq-chip {
    flex: 1 1 45%;
    font-size: 0.875rem;
    padding: 0.5rem 0.6rem;
    min-height: 44px;
  }
  .aq-verdict,
  .aq-explain p { font-size: 0.875rem !important; }
}
