/* MathBox — MathType-style equation editor */
.mb-backdrop { z-index: 900; }
.mb-win {
  width: min(960px, 96vw); max-height: 94vh; display: flex; flex-direction: column;
  background: #fff; color: #1b2433; border-radius: 14px; overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55); font-family: 'Kantumruy Pro', system-ui, -apple-system, sans-serif;
  user-select: none;
}
.mb-title { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #f6f7f9; border-bottom: 1px solid #e3e6eb; }
.mb-title b { font-size: 15px; }
.mb-logo { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 7px; background: #ff4d63; color: #fff; font-weight: 900; }
.mb-modes { display: flex; gap: 2px; margin-left: auto; padding: 3px; background: #e7eaf0; border-radius: 10px; }
.mb-modes button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font: 600 13px/1 inherit; font-family: inherit; color: #4a566a; cursor: pointer; }
.mb-modes button.on { background: #fff; color: #0e5fd8; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.mb-x { border: 0; background: transparent; width: 32px; height: 32px; border-radius: 8px; font-size: 16px; color: #5a6578; cursor: pointer; }
.mb-x:hover { background: #e7eaf0; }

.mb-ribbon { background: #f6f7f9; border-bottom: 1px solid #e3e6eb; padding: 6px 10px 10px; transition: opacity .15s; }
.mb-ribbon.dim { opacity: .45; pointer-events: none; }
.mb-tabs { display: flex; gap: 2px; margin-bottom: 8px; overflow-x: auto; }
.mb-tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px 9px 0 0; font: 600 14px/1 inherit; font-family: inherit; color: #4a566a; cursor: pointer; white-space: nowrap; }
.mb-tabs button:hover { background: #eceff4; }
.mb-tabs button.on { background: #fff; color: #0e5fd8; box-shadow: 0 -1px 0 #e3e6eb inset; }
.mb-palette { display: flex; flex-wrap: wrap; gap: 8px; min-height: 64px; }
.mb-grp { display: flex; flex-wrap: wrap; gap: 2px; padding: 5px; background: #fff; border: 1px solid #e3e6eb; border-radius: 10px; max-width: 100%; }
.mb-sym {
  min-width: 40px; height: 40px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent; color: #1b2433;
  font-size: 15px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.mb-sym:hover { background: #e8f1ff; }
.mb-sym:active { transform: scale(.94); background: #d3e5ff; }
.mb-sym .katex { font-size: 1em; }

.mb-stage { padding: 14px 16px 6px; overflow: auto; min-height: 0; flex: 1; }
.mb-pane[hidden] { display: none; }
.mb-field-wrap { min-height: clamp(100px, 22vh, 150px); border: 2px solid #dbe3ef; border-radius: 12px; padding: 10px 14px; background: #fff; display: flex; align-items: center; }
.mb-field-wrap:focus-within { border-color: #4da3ff; box-shadow: 0 0 0 4px rgba(77, 163, 255, .18); }
.mb-field { width: 100%; font-size: 2.3rem; border: 0; outline: 0; background: transparent; user-select: text; --hue: 215; --caret-color: #0e5fd8; --selection-background-color: #cfe3ff; --contains-highlight-background-color: #eef5ff; }
.mb-loading { color: #6b7688; font-size: 14px; }
.mb-loading.err { color: #d33; }
.mb-hint { margin: 8px 2px 0; font-size: 12.5px; color: #6b7688; }
.mb-hint code { background: #eef1f6; padding: 1px 6px; border-radius: 5px; font-size: 12px; }

.mb-ink-wrap { position: relative; height: clamp(140px, 32vh, 240px); border: 2px solid #dbe3ef; border-radius: 12px; overflow: hidden;
  background-color: #fff;
  background-image: linear-gradient(#e6ebf3 1px, transparent 1px), linear-gradient(90deg, #e6ebf3 1px, transparent 1px);
  background-size: 24px 24px; }
.mb-ink { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.mb-ink-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #aab4c4; font-size: 18px; pointer-events: none; }
.mb-ink-bar { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.mb-ink-msg { flex: 1; font-size: 13px; color: #b45309; }

.mb-tex { width: 100%; min-height: 150px; box-sizing: border-box; padding: 12px 14px; border: 2px solid #dbe3ef; border-radius: 12px; font: 15px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; user-select: text; color: #1b2433; background: #fbfcfe; }
.mb-tex:focus { outline: 0; border-color: #4da3ff; box-shadow: 0 0 0 4px rgba(77, 163, 255, .18); }

.mb-foot { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-top: 1px solid #e3e6eb; background: #f6f7f9; }
.mb-preview { flex: 1; min-width: 0; overflow: auto hidden; white-space: nowrap; font-size: 1.15rem; color: #1b2433; padding: 2px 4px; }
.mb-prev-empty { color: #aab4c4; font-size: 13px; }
.mb-btn { border: 1px solid #d5dbe6; background: #fff; color: #1b2433; padding: 9px 14px; border-radius: 9px; font: 600 13.5px/1 inherit; font-family: inherit; cursor: pointer; white-space: nowrap; }
.mb-btn:hover { background: #eef2f8; }
.mb-btn:disabled { opacity: .55; cursor: wait; }
.mb-btn.primary { background: #0e72ed; border-color: #0e72ed; color: #fff; }
.mb-btn.primary:hover { background: #0b5fc4; }

@media (max-width: 640px) {
  .mb-title b { display: none; }
  .mb-foot { flex-wrap: wrap; }
  .mb-preview { flex-basis: 100%; }
}

/* hide MathLive's own keyboard / menu buttons — our ribbon replaces them */
.mb-field::part(virtual-keyboard-toggle), .mb-field::part(menu-toggle) { display: none; }

.mb-color { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #4a566a; font-weight: 600; }
.mb-color-sel { border: 1px solid #d5dbe6; border-radius: 8px; padding: 7px 8px; background: #fff; font: 600 13px inherit; font-family: inherit; color: #1b2433; }
