/* =========================================================
   Long-equation guard for exam math (inline & display).
   MathJax renders some equations (e.g. long partial-fraction
   identities) wider than a phone screen, which used to stretch
   the whole page sideways. When an equation can't fit the
   available width we collapse it to a "View equation" button
   that opens the full equation in a scrollable popup.
   ========================================================= */

/* Baseline guard: even before the JS upgrade runs, never let a
   display equation push the layout wider than its column. */
#exam-form mjx-container[display="true"] {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Collapsed placeholder that replaces an over-wide equation. */
.ce-eq-longwrap { display: block; margin: 8px 0; }
.ce-eq-longwrap.is-inline { display: inline; margin: 0; }
.ce-eq-holder { display: none; }

.ce-eq-viewbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  border: 1px solid rgba(24, 57, 138, 0.28);
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: #18398a;
  padding: 6px 12px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  vertical-align: middle;
}
.ce-eq-viewbtn:hover { background: #18398a; color: #fff; border-color: #18398a; }
.ce-eq-viewbtn .ce-eq-ico { font-size: 14px; }

body.dark-mode .ce-eq-viewbtn {
  background: rgba(96, 165, 250, 0.12);
  border-color: rgba(147, 197, 253, 0.35);
  color: #bfdbfe;
}
body.dark-mode .ce-eq-viewbtn:hover { background: #1e40af; color: #fff; }

/* ---- Full-equation popup ---- */
body.ce-eq-modal-open { overflow: hidden; }

.ce-eq-modal {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.55);
  opacity: 0;
  transition: opacity 0.15s ease;
}
.ce-eq-modal.is-open { opacity: 1; }

.ce-eq-modal-card {
  width: min(680px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.45);
  overflow: hidden;
}
body.dark-mode .ce-eq-modal-card { background: #0f1420; color: #e5edff; }

.ce-eq-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(24, 57, 138, 0.14);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 700;
  color: #18398a;
}
body.dark-mode .ce-eq-modal-head { color: #bfdbfe; border-bottom-color: rgba(147, 197, 253, 0.2); }

.ce-eq-modal-close {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.ce-eq-modal-close:hover { background: rgba(24, 57, 138, 0.1); }
body.dark-mode .ce-eq-modal-close:hover { background: rgba(147, 197, 253, 0.14); }

.ce-eq-modal-body {
  padding: 18px 16px;
  overflow: auto;            /* scroll the equation both ways if huge */
  -webkit-overflow-scrolling: touch;
}
.ce-eq-modal-scroll {
  min-width: min-content;    /* let the equation dictate its width so it can scroll */
  text-align: center;
}
.ce-eq-modal-scroll mjx-container {
  margin: 0 auto;
  max-width: none !important; /* override the baseline guard inside the popup */
  overflow: visible !important;
}

.ce-eq-modal-hint {
  padding: 8px 14px 12px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 12px;
  opacity: 0.7;
  text-align: center;
}
