/* Response box + Equation Builder, styled after the LEAP 2025 online Equation Builder
   (Equation Builder Guide for Grades 6-8). Colors are sampled from the official screenshots. */

/* ---------- response box ---------- */
.rb {
  position: relative;
  font-family: Arial, Helvetica, sans-serif;
  color: #000;
}
.rb-strip {
  display: flex;
  align-items: center;
  height: 28px;
  padding: 0 3px;
  background: #d6d1ca;
  border: 1px solid #1c1c1c;
}
.rb-eq {
  width: 30px;
  height: 21px;
  padding: 0;
  font: bold 11px Arial, Helvetica, sans-serif;
  letter-spacing: 0.3px;
  color: #111;
  background: #e9e6e1;
  border: 1px solid;
  border-color: #fff #8d8a85 #8d8a85 #fff;
  box-shadow: 0 0 0 1px #c3beb6;
  cursor: pointer;
}
.rb-eq:hover { background: #f6f4f1; }
.rb-eq:active { border-color: #8d8a85 #fff #fff #8d8a85; }
.rb-eq:disabled { color: #8a8782; cursor: default; }
.rb-eq:focus-visible, .eqb-btn:focus-visible, .eqb-ok:focus-visible, .eqb-cancel:focus-visible, .eqb-help:focus-visible {
  outline: 2px solid #1a56c4;
  outline-offset: 1px;
}
.rb-box {
  min-height: 200px;
  max-height: 460px;
  overflow-y: auto;
  padding: 10px 9px;
  background: #fff;
  border: 1px solid #b9c9d8;
  border-top: none;
  font: 17px/1.5 Arial, Helvetica, sans-serif;
  color: #000;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
  cursor: text;
}
.rb-box:focus { border-color: #8fb3d6; }
.rb-box:empty::before {
  content: attr(data-placeholder);
  color: #8b8b8b;
  pointer-events: none;
}
.rb-disabled .rb-box { background: #f3f3f3; color: #444; cursor: default; }
.rb-chip {
  display: inline-block;
  max-width: 100%;
  margin: 0 1px;
  padding: 0 2px;
  border-radius: 2px;
  cursor: default;
  -webkit-user-select: all;
  user-select: all;
}
.rb-box[contenteditable="true"] .rb-chip:hover { background: #e9f1ff; box-shadow: 0 0 0 1px #9dbcec; }

/* ---------- equation builder dialog ---------- */
.eqb {
  position: absolute;
  z-index: 40;
  top: -34px;
  left: 50%;
  transform: translateX(-50%);
  width: min(738px, 100%);
  box-sizing: border-box;
  background: #fff;
  border: 2px solid #000;
  font-family: Arial, Helvetica, sans-serif;
  color: #000;
  text-align: left;
}
.eqb-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 30px;
  padding: 0 0 0 3px;
  background: #66aaff;
  color: #fff;
  font: bold 19px/30px Arial, Helvetica, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}
.eqb-help {
  height: 30px;
  padding: 0 9px;
  font: 900 19px/30px "Arial Black", Arial, Helvetica, sans-serif;
  color: #000;
  background: none;
  border: none;
  cursor: pointer;
}
.eqb-toolbar { padding: 7px 5px 0 6px; }
.eqb-row { display: flex; flex-wrap: wrap; gap: 5px 5px; }
.eqb-row + .eqb-row { margin-top: 6px; }
.eqb-group { display: inline-flex; padding-left: 1px; }
.eqb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  margin-left: -1px;
  padding: 0;
  font: 21px/1 "Times New Roman", Times, "Cambria Math", serif;
  color: #2b2b2b;
  background: #fff;
  border: 1px solid #848484;
  border-radius: 0;
  cursor: pointer;
}
.eqb-btn:hover { background: #e6f0ff; position: relative; }
.eqb-btn:active { background: #cfe1ff; }
.eqb-btn svg { display: block; }
.eqb-input {
  position: relative;
  height: 74px;
  margin: 7px 6px 0 6px;
  padding: 3px 6px;
  overflow-x: hidden;
  overflow-y: scroll;
  background: #fff;
  border: 1px solid #a8a8a8;
  font-size: 19px;
  cursor: text;
}
.eqb-input.focused {
  border-color: #66afe9;
  box-shadow: 0 0 5px 1px rgba(102, 175, 233, 0.75);
}
.eqb-keys {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 22px;
  padding: 0;
  border: none;
  outline: none;
  resize: none;
  overflow: hidden;
  opacity: 0;
  font-size: 16px; /* keeps phones from zooming in */
  pointer-events: none;
}
.eqb-display { min-height: 100%; -webkit-user-select: none; user-select: none; }
.eqb-foot {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 2px 6px 27px 6px;
}
.eqb-count { font: 11px/14px Arial, Helvetica, sans-serif; color: #555; }
.eqb-actions { display: inline-flex; gap: 4px; margin-top: 7px; }
.eqb-ok, .eqb-cancel {
  height: 27px;
  padding: 0 7px;
  font: 13px Arial, Helvetica, sans-serif;
  color: #1d1d1d;
  background: #ddd;
  border: 2px solid;
  border-color: #f2f2f2 #afafaf #afafaf #f2f2f2;
  border-radius: 0;
  cursor: pointer;
}
.eqb-ok:hover, .eqb-cancel:hover { background: #e8e8e8; }
.eqb-ok:active, .eqb-cancel:active { border-color: #afafaf #f2f2f2 #f2f2f2 #afafaf; }
.eqb-helpbox {
  position: absolute;
  top: 32px;
  right: 4px;
  z-index: 2;
  width: min(360px, calc(100% - 8px));
  box-sizing: border-box;
  padding: 8px 12px;
  background: #fffbe6;
  border: 1px solid #000;
  font: 13px/1.4 Arial, Helvetica, sans-serif;
}
.eqb-helpbox p { margin: 6px 0; }

/* ---------- math rendering ---------- */
.m-root {
  font-family: "Times New Roman", Times, "Cambria Math", "STIX Two Math", serif;
  font-size: 1.16em;
  line-height: 1.25;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.eqb-display.m-root { font-size: 1.16em; }
.m-tpl .m-row { white-space: pre; overflow-wrap: normal; }
.m-ch.m-it { font-style: italic; }
.m-ch.m-op { margin: 0 0.17em; }

/* fraction: two equal-height rows so the bar always sits on the middle line */
.m-frac {
  display: inline-grid;
  grid-template-rows: 1fr 1fr;
  vertical-align: middle;
  margin: 0 0.14em;
  font-size: 0.88em;
  text-align: center;
}
.m-frac > .m-num { align-self: end; padding: 0 0.22em 0.04em; }
.m-frac > .m-den { align-self: start; padding: 0.06em 0.22em 0; border-top: max(1px, 0.065em) solid currentColor; }

/* exponent */
.m-pow { display: inline-flex; align-items: flex-start; }
.m-pow > .m-exp { margin: -0.32em 0 0 0.05em; font-size: 0.7em; }

/* parentheses and absolute value grow with what is inside */
.m-paren, .m-abs, .m-sqrt, .m-nroot { display: inline-flex; align-items: stretch; margin: 0 0.05em; }
.m-paren > .m-body, .m-abs > .m-body { align-self: baseline; padding: 0 0.06em; }
.m-fence {
  flex: none;
  width: 0.3em;
  margin: 0.06em 0;
  border: 0 solid currentColor;
}
.m-fence-l { border-left-width: 0.09em; border-radius: 100% 0 0 100% / 50% 0 0 50%; }
.m-fence-r { border-right-width: 0.09em; border-radius: 0 100% 100% 0 / 0 50% 50% 0; }
.m-bar {
  flex: none;
  width: 0;
  margin: 0.08em 0.1em;
  border-left: max(1px, 0.065em) solid currentColor;
}

/* roots */
.m-radical { flex: none; align-self: stretch; width: 0.62em; height: auto; min-height: 1em; overflow: visible; }
.m-radicand {
  align-self: baseline;
  margin-top: 0.03em;
  padding: 0.06em 0.12em 0 0.08em;
  border-top: max(1px, 0.065em) solid currentColor;
}
.m-nroot > .m-index { align-self: flex-start; margin: -0.05em -0.38em 0 0; font-size: 0.6em; }

/* empty boxes in a template */
.m-empty::before {
  content: "";
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  border: 1px solid #6b6b6b;
}
.m-empty-active {
  min-width: 0.6em;
  background: #dbe9ff;
  box-shadow: 0 0 0 1px #9dbcec;
}
.m-row.m-empty, .m-row.m-empty-active { text-align: center; }

/* typing cursor in the builder */
.m-caret {
  display: inline-block;
  width: 0;
  height: 1.05em;
  margin: 0 -0.75px;
  border-left: 1.5px solid #000;
  vertical-align: -0.2em;
  animation: m-blink 1.06s steps(1) infinite;
}
.eqb-input:not(.focused) .m-caret { visibility: hidden; }
@keyframes m-blink { 50% { opacity: 0; } }

/* read-only content (text with equations) */
.content-view {
  font: 17px/1.5 Arial, Helvetica, sans-serif;
  color: #000;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.content-view .m-root { padding: 0 1px; }

@media (max-width: 520px) {
  .eqb-btn { width: 32px; }
}
