.mf-owner-solution-tools{border:1px solid #c8a761;border-radius:8px;background:#fffaf0;color:#332814;padding:16px;margin:0 0 20px;font:14px/1.5 system-ui,sans-serif}
.mf-owner-solution-tools p{margin:8px 0}.mf-owner-solution-actions{display:flex;flex-wrap:wrap;gap:8px}.mf-owner-solution-actions button{white-space:normal;min-height:42px}.mf-owner-solution-tools small{display:block;margin-top:8px}.mf-publication-withdraw{color:#a32929!important}.mf-owner-solution-status[role=alert]{color:#a32929;font-weight:600}
/* Public stored solutions share the existing detailed-solution reader. */
.mf-solve-btn.mf-solve-public { background:#edf5ef; color:#23543c; border-color:#a3c5ae; }
.mf-stored-notice { padding:16px 18px; margin:0 0 22px; border:1px solid #cddbd2; border-radius:8px; background:#f2f7f3; color:#294e39; font-size:14px; line-height:1.6; }
.mf-stored-notice p { margin:6px 0; }
.mf-stored-notice .mf-stored-warning { padding-top:8px; border-top:1px solid #dce5df; color:#7b4e1d; }
.mf-public-chapter-banner { max-width:1080px; margin:24px auto; }
.mf-public-chapter-banner a { color:inherit; text-decoration:underline; white-space:nowrap; }
.mf-solution-plot { margin:22px 0; text-align:center; }
.mf-solution-plot img { display:block; max-width:100%; height:auto; margin:0 auto; background:white; }
.mf-solution-plot figcaption { font-size:12px; color:#666; margin-top:8px; }
@media (max-width:700px) { .mf-public-chapter-banner { margin:16px; } }
/* ================================================================
   MechForge Admin Layer — matches the gold/paper/steel palette
   ================================================================ */

/* ==============================================================
   NAV BAR — only rendered on problems pages (no .topbar present)
   All other pages inject nav items directly into the existing .topbar
   ============================================================== */
#mfNavBar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 38px;
  background: #1e2d3e;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 14px;
  z-index: 1100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.28);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.70rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
#mfNavBar::-webkit-scrollbar { display: none; }

/* Chapter nav group inside .topbar (reading / index / hub pages) */
#mfChapterNav {
  display: flex;
  align-items: center;
  gap: 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.69rem;
  flex-shrink: 1;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  margin-left: 6px;
}
#mfChapterNav::-webkit-scrollbar { display: none; }

/* Shared link styles for nav bar and chapter nav */
#mfNavBar a,
#mfChapterNav a {
  color: #b8c5d3;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  transition: background 0.14s, color 0.14s;
  font-size: 0.68rem;
  letter-spacing: 0.15px;
}
#mfNavBar a:hover,
#mfChapterNav a:hover {
  background: rgba(184,134,11,0.22);
  color: #e0c067;
}

/* Separators */
#mfNavBar .mf-sep,
#mfChapterNav .mf-sep {
  color: #3d556a;
  padding: 0 1px;
  user-select: none;
  font-size: 0.65rem;
}

/* Chapter prev/next accent */
#mfNavBar .mf-nav-prev,
#mfNavBar .mf-nav-next,
#mfChapterNav .mf-nav-prev,
#mfChapterNav .mf-nav-next {
  color: #c9a83a;
  font-weight: 600;
}

/* Reading ↔ Problems toggle pill */
#mfNavBar .mf-nav-toggle,
#mfChapterNav .mf-nav-toggle {
  background: rgba(184,134,11,0.14);
  color: #c9a415;
  border: 1px solid rgba(184,134,11,0.28);
  border-radius: 4px;
}
#mfNavBar .mf-nav-toggle:hover,
#mfChapterNav .mf-nav-toggle:hover {
  background: rgba(184,134,11,0.28);
  color: #e0c067;
}

/* ==============================================================
   ADMIN SLOT — the owner controls container, always inside
   either #mfNavBar or .topbar
   ============================================================== */
#mfAdminSlot {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
/* Problems page: push slot to the far right of #mfNavBar */
#mfNavBar #mfAdminSlot {
  margin-left: auto;
}
/* Topbar pages: slot flows naturally at the end */
.topbar #mfAdminSlot {
  margin-left: 8px;
}

/* Keep the owner inbox and editing actions reachable on narrow screens. */
#mfAdminSlot:has(.mf-owner-bar) {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: #1e2d3e;
  overflow-x: auto;
  box-sizing: border-box;
  z-index: 1200;
}
body:has(.mf-owner-bar) {
  padding-bottom: 70px;
}
body:has(.mf-owner-bar) #mfMigrateBtn {
  bottom: 76px;
}

/* ==============================================================
   ADMIN LOGIN BUTTON
   ============================================================== */
.mf-admin-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #888;
  padding: 3px 11px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.67rem;
  transition: all 0.14s;
}
.mf-admin-btn:hover {
  background: rgba(255,255,255,0.16);
  color: #ccc;
}

/* ==============================================================
   LOGIN MODAL
   ============================================================== */
.mf-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,14,13,0.58);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
}

.mf-modal {
  background: #f7f4ef;
  border: 1px solid #d4cec5;
  border-radius: 12px;
  padding: 32px 36px;
  width: min(380px, 94vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.22);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mf-modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: #0f0e0d;
  margin: 0 0 6px;
}

.mf-modal-sub {
  font-size: 0.84rem;
  color: #6b6560;
  margin-bottom: 20px;
  font-family: 'Source Serif 4', serif;
}

.mf-pw-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d4cec5;
  border-radius: 6px;
  font-size: 0.95rem;
  background: #fff;
  color: #0f0e0d;
  box-sizing: border-box;
  font-family: 'Source Serif 4', serif;
  outline: none;
  transition: border-color 0.14s, box-shadow 0.14s;
}
.mf-pw-input:focus {
  border-color: #b8860b;
  box-shadow: 0 0 0 3px rgba(184,134,11,0.14);
}

.mf-login-err {
  color: #c0392b;
  font-size: 0.81rem;
  min-height: 20px;
  margin: 8px 0 4px;
  font-family: 'IBM Plex Mono', monospace;
}

.mf-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.mf-btn-secondary {
  flex: 1;
  padding: 9px;
  border: 1px solid #d4cec5;
  background: #ede8df;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.87rem;
  color: #6b6560;
  font-family: 'Source Serif 4', serif;
  transition: background 0.14s;
}
.mf-btn-secondary:hover { background: #d4cec5; }

.mf-btn-primary {
  flex: 1;
  padding: 9px;
  background: #2c3e50;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.87rem;
  color: #fff;
  font-weight: 600;
  font-family: 'Source Serif 4', serif;
  transition: background 0.14s;
}
.mf-btn-primary:hover { background: #b8860b; }

/* ==============================================================
   OWNER BAR (inside admin slot)
   ============================================================== */
.mf-owner-bar {
  display: flex;
  align-items: center;
  gap: 7px;
}

.mf-edit-label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #b8c5d3;
  font-size: 0.68rem;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.mf-edit-label input[type="checkbox"] {
  accent-color: #b8860b;
  cursor: pointer;
  width: 14px;
  height: 14px;
}

.mf-bar-btn {
  padding: 3px 11px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.67rem;
  border: 1px solid transparent;
  transition: all 0.14s;
  white-space: nowrap;
  line-height: 1.5;
}

.mf-bar-btn-save {
  background: #b8860b;
  color: #fff;
  border-color: #906809;
}
.mf-bar-btn-save:hover { background: #906809; }
.mf-bar-btn-save:disabled { background: #888; border-color: #666; cursor: wait; }

.mf-bar-btn-revert {
  background: rgba(255,255,255,0.08);
  color: #aaa;
  border-color: rgba(255,255,255,0.14);
}
.mf-bar-btn-revert:hover { background: rgba(255,255,255,0.16); color: #fff; }

.mf-bar-btn-logout {
  background: transparent;
  color: #566677;
  border-color: rgba(255,255,255,0.08);
  font-size: 0.63rem;
}
.mf-bar-btn-logout:hover {
  background: rgba(192,57,43,0.18);
  color: #c0392b;
  border-color: rgba(192,57,43,0.3);
}

/* ==============================================================
   EDIT MODE — contenteditable visual feedback
   ============================================================== */
body.mf-edit-mode .mf-editable {
  outline: 1px dashed rgba(184,134,11,0.45) !important;
  border-radius: 3px;
  min-height: 1em;
  cursor: text;
  transition: outline 0.1s;
}
body.mf-edit-mode .mf-editable:hover {
  outline: 1px dashed rgba(184,134,11,0.75) !important;
  background: rgba(255,243,205,0.12);
}
body.mf-edit-mode .mf-editable:focus {
  outline: 2px solid #b8860b !important;
  background: rgba(255,243,205,0.28);
}

/* ==============================================================
   DELETE BUTTONS
   ============================================================== */
.mf-del-btn {
  background: rgba(192,57,43,0.82);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.7rem;
  font-family: 'IBM Plex Mono', monospace;
  padding: 2px 7px;
  z-index: 200;
  transition: background 0.13s;
  line-height: 1.4;
}
.mf-del-btn:hover { background: #c0392b; }

.mf-del-blk-wrap {
  position: relative;
}
.mf-del-blk {
  position: absolute;
  top: 6px;
  right: 6px;
}
/* Remove-problem button sits inline at the end of each problem li */
.mf-del-prob-btn {
  position: static;
  display: inline-block;
  margin-left: 8px;
  vertical-align: middle;
}
.mf-del-sec-btn {
  float: right;
  margin-top: 4px;
  clear: right;
}

/* ==============================================================
   INSERT ROWS — appear between blocks in edit mode
   ============================================================== */
.mf-insert-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 0;
  opacity: 0;
  transition: opacity 0.18s;
  min-height: 24px;
}
body.mf-edit-mode .mf-insert-row { opacity: 1; }

.mf-insert-row button {
  background: rgba(44,62,80,0.07);
  border: 1px dashed #d4cec5;
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 0.69rem;
  font-family: 'IBM Plex Mono', monospace;
  color: #2c3e50;
  cursor: pointer;
  transition: all 0.14s;
  white-space: nowrap;
}
.mf-insert-row button:hover {
  background: rgba(184,134,11,0.12);
  border-color: #b8860b;
  color: #b8860b;
}

/* ==============================================================
   DELETED BADGE
   ============================================================== */
.mf-deleted-badge {
  background: rgba(192,57,43,0.09);
  border: 1px solid rgba(192,57,43,0.3);
  color: #c0392b;
  font-size: 0.7rem;
  font-family: 'IBM Plex Mono', monospace;
  padding: 2px 8px;
  border-radius: 3px;
  display: inline-block;
  margin-bottom: 4px;
}

/* ==============================================================
   IMAGE UPLOAD LABEL (edit mode)
   ============================================================== */
.mf-img-upload-label {
  transition: background 0.14s, border-color 0.14s;
}
.mf-img-upload-label:hover {
  background: #f0ece4 !important;
  border-color: #b8860b !important;
  color: #b8860b !important;
}

/* ==============================================================
   SYMBOL KEYBOARD
   ============================================================== */
/* Migrate uploads — floating button, owner-only, bottom-right above Σ */
#mfMigrateBtn {
  position: fixed;
  bottom: 62px;
  right: 18px;
  background: #7c3aed;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.82rem;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  z-index: 3000;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  transition: background 0.14s;
  white-space: nowrap;
}
#mfMigrateBtn:hover { background: #5b21b6; }
#mfMigrateBtn:disabled { background: #888; cursor: wait; }

#mfSymBtn {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: #2c3e50;
  color: #e0c067;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.82rem;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  z-index: 3000;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  transition: background 0.14s;
}
#mfSymBtn:hover { background: #b8860b; }

#mfSymKeyboard {
  position: fixed;
  bottom: 68px;
  right: 18px;
  width: 420px;
  max-height: 320px;
  background: #f7f4ef;
  border: 1px solid #d4cec5;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#mfSymSearch {
  padding: 9px 13px;
  border: none;
  border-bottom: 1px solid #d4cec5;
  background: #ede8df;
  font-size: 0.83rem;
  font-family: 'IBM Plex Mono', monospace;
  outline: none;
  color: #0f0e0d;
  width: 100%;
  box-sizing: border-box;
}

#mfSymGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 9px;
  overflow-y: auto;
  flex: 1;
}

.mf-sym-item {
  background: #fff;
  border: 1px solid #d4cec5;
  border-radius: 4px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 0.95rem;
  min-width: 36px;
  text-align: center;
  transition: all 0.1s;
  color: #0f0e0d;
  font-family: 'Source Serif 4', serif;
  line-height: 1.2;
}
.mf-sym-item:hover {
  background: #fff3cd;
  border-color: #b8860b;
}

/* ==============================================================
   INSTRUCTOR NOTES
   ============================================================== */
body.mf-edit-mode .admin-note {
  display: block !important;
}

.an-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #b8860b;
  display: block;
  margin-bottom: 4px;
}

/* ==============================================================
   TOAST NOTIFICATION
   ============================================================== */
#mfToast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #2c3e50;
  color: #e0c067;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  padding: 10px 22px;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
#mfToast.mf-toast-show { opacity: 1; }

/* ==============================================================
   MOBILE
   ============================================================== */
@media (max-width: 900px) {
  body.mf-has-problem-nav { padding-top: 44px !important; }
  #mfNavBar {
    min-height: 44px;
    font-size: 0.63rem;
    padding: 0 8px;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }
  #mfNavBar a,
  #mfNavBar button {
    min-height: 44px;
    padding: 5px 8px;
    font-size: 0.62rem;
    display: inline-flex;
    align-items: center;
  }
  #mfChapterNav { font-size: 0.62rem; }
  #mfChapterNav a,
  #mfChapterNav button {
    min-height: 44px;
    padding: 5px 8px;
    font-size: 0.62rem;
    display: inline-flex;
    align-items: center;
  }
  #mfSymKeyboard { width: calc(100vw - 36px); right: 8px; }
}

@media (max-width: 480px) {
  /* Prevent horizontal scrolling on mobile */
  html, body {
    max-width: 100vw;
    overflow-x: clip;
  }

  /* Ensure all math blocks can scroll horizontally without breaking page */
  main .katex-display,
  main .formula-body,
  .content .katex-display,
  .content .formula-body,
  #mfSolveBody .katex-display {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    max-width: 100% !important;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
  }

  /* Make sure images and tables are contained */
  main img,
  main svg,
  .content img,
  .content svg,
  .problem-text img,
  .problem-text svg,
  #mfSolveBody img,
  #mfSolveBody svg {
    max-width: 100% !important;
    height: auto !important;
  }

  main table,
  .content table,
  .problem-text table,
  #mfSolveBody table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ==============================================================
   BULK FIGURE UPLOAD MODAL
   ============================================================== */
.mf-bulk-fig-modal {
  max-width: 720px;
  width: 92vw;
  padding: 26px 28px 28px;
}

.mf-bulk-fig-head {
  margin-bottom: 18px;
}

.mf-bulk-fig-drop {
  border: 2px dashed #d4cec5;
  border-radius: 10px;
  padding: 28px 24px;
  text-align: center;
  background: #faf8f4;
  transition: background 0.14s, border-color 0.14s;
  cursor: pointer;
  margin-bottom: 16px;
}
.mf-bulk-fig-drop.dragover {
  border-color: #b8860b;
  background: #fff8e6;
}

.mf-bulk-fig-drop-text {
  font-family: 'Source Serif 4', serif;
  font-size: 1.05rem;
  color: #0f0e0d;
  margin-bottom: 14px;
  line-height: 1.5;
}
.mf-bulk-fig-drop-text strong { color: #2c3e50; }

.mf-bulk-fig-hint {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  color: #6b6560;
  margin-top: 6px;
}

.mf-bulk-fig-status {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  min-height: 20px;
}

.mf-bulk-fig-ok { color: #27ae60; }
.mf-bulk-fig-warn { color: #c0392b; }

.mf-bulk-fig-list {
  max-height: 44vh;
  overflow-y: auto;
  border: 1px solid #d4cec5;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  margin-bottom: 18px;
}

.mf-bulk-fig-empty {
  text-align: center;
  color: #6b6560;
  font-family: 'Source Serif 4', serif;
  padding: 24px 0;
  margin: 0;
}

.mf-bulk-fig-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid #ede8df;
  font-family: 'Source Serif 4', serif;
  font-size: 0.88rem;
}
.mf-bulk-fig-row:last-child { border-bottom: none; }
.mf-bulk-fig-row.unmatched { background: #fff8f8; }

.mf-bulk-fig-thumb {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 5px;
  overflow: hidden;
  background: #f4f1ea;
  border: 1px solid #d4cec5;
}
.mf-bulk-fig-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mf-bulk-fig-info { flex: 1; min-width: 0; }
.mf-bulk-fig-name {
  font-weight: 600;
  color: #0f0e0d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mf-bulk-fig-match {
  font-size: 0.78rem;
  color: #6b6560;
  font-family: 'IBM Plex Mono', monospace;
  margin-top: 2px;
}
.mf-bulk-fig-match code {
  font-size: 0.72rem;
  background: #f4f1ea;
  padding: 1px 4px;
  border-radius: 3px;
}

.mf-bulk-fig-state {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  padding: 4px 9px;
  border-radius: 4px;
  white-space: nowrap;
}
.mf-bulk-fig-state.ready { background: #e8f4fd; color: #2980b9; }
.mf-bulk-fig-state.uploading { background: #fff8e6; color: #b8860b; }
.mf-bulk-fig-state.done { background: #e8f9ee; color: #27ae60; }
.mf-bulk-fig-state.failed,
.mf-bulk-fig-state.warn { background: #fdeaea; color: #c0392b; }

.mf-bulk-fig-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.mf-bulk-fig-actions .mf-btn-secondary,
.mf-bulk-fig-actions .mf-btn-primary {
  flex: 0 0 auto;
  padding: 9px 20px;
}

/* ==============================================================
   PROBLEM FIGURE — upload button (edit mode) + image display (all visitors)
   ============================================================== */

/* Empty figure anchors exist so the owner can attach an image to any problem.
   They must not leave a badge, border, or gap for ordinary visitors. */
.figflag,
.figflag.mf-figure-slot {
  display: none;
  margin: 0;
  padding: 0;
  border: 0;
}

.mf-edit-mode .figflag,
.mf-edit-mode .figflag.mf-figure-slot {
  display: inline-block;
}

/* Upload / replace button shown next to the figflag text */
.mf-pfig-btn {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 9px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  background: #2c3e50;
  color: #e0c067;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  vertical-align: middle;
  transition: background 0.14s;
  white-space: nowrap;
}
.mf-pfig-btn:hover { background: #b8860b; }
.mf-pfig-btn:disabled { opacity: 0.55; cursor: default; }

/* Figure wrapper — spans across both grid columns of the problem list item */
.mf-pfig-wrap {
  grid-column: 1 / -1;
  margin: 10px 0 6px 0;
}

/* The uploaded figure image */
.mf-pfig-img {
  display: block;
  max-width: min(520px, 100%);
  height: auto;
  border-radius: 7px;
  border: 1px solid var(--rule-soft, #e8e2d6);
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  background: #fff;
}

/* ==============================================================
   REPLACE-IMAGE BUTTON — appears on .fig-img / .fig-container in edit mode
   ============================================================== */
.mf-img-replace-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #2c3e50;
  color: #f4f1ea;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  cursor: pointer;
  z-index: 20;
  opacity: 0.88;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}
.mf-img-replace-btn:hover {
  opacity: 1;
  background: #c0392b;
}

/* ==============================================================
   REPLACE BUTTON — overlaid on uploaded problem figure images
   Visible whenever owner is logged in (no edit mode required)
   ============================================================== */
.mf-pfig-wrap {
  position: relative;
}
.mf-pfig-replace-btn {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(44, 62, 80, 0.88);
  color: #e0c067;
  border: none;
  border-radius: 5px;
  padding: 4px 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  cursor: pointer;
  z-index: 20;
  opacity: 1;
  transition: opacity 0.18s, background 0.15s;
  white-space: nowrap;
  pointer-events: auto;
}
.mf-pfig-wrap:hover .mf-pfig-replace-btn {
  opacity: 1;
  pointer-events: auto;
}
.mf-pfig-replace-btn:hover { background: #b8860b; }
.mf-pfig-replace-btn:disabled { opacity: 0.55; cursor: default; pointer-events: none; }

/* ================================================================
   SOLVE POPUP — Detailed Solution modal
   ================================================================ */

#mfSolveOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .58);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 99999;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#mfSolvePanel {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .38);
  width: 100%;
  max-width: 880px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: mfSolveIn .22s cubic-bezier(.22,1,.36,1);
}

@keyframes mfSolveIn {
  from { opacity: 0; transform: scale(.96) translateY(12px); }
  to   { opacity: 1; transform: none; }
}

#mfSolveHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid #ececec;
  background: #fff;
  flex-shrink: 0;
}

#mfSolveTitle {
  font-size: 16px;
  font-weight: 700;
  color: #1a1a1a;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: -.3px;
}

#mfSolveClose {
  background: none;
  border: none;
  font-size: 18px;
  color: #999;
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
  flex-shrink: 0;
  line-height: 1;
}
#mfSolveClose:hover { background: #f2f2f2; color: #222; }

#mfSolveBody {
  flex: 1;
  overflow-y: auto;
  padding: 28px 36px 40px;
  font-size: 15.5px;
  line-height: 1.8;
  color: #1c1c1c;
}

/* Loading spinner */
.mf-solve-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 70px 0;
  color: #aaa;
  font-size: 14px;
}
.mf-solve-spinner {
  width: 42px; height: 42px;
  border: 3px solid #e8e8e8;
  border-top-color: #c0392b;
  border-radius: 50%;
  animation: mfSolveSpin .75s linear infinite;
}
@keyframes mfSolveSpin { to { transform: rotate(360deg); } }

/* Cursor blink while streaming */
.mf-scursor { animation: mfScursorBlink 1s step-end infinite; }
@keyframes mfScursorBlink { 50% { opacity: 0; } }

/* Error */
.mf-serr { color: #c0392b; padding: 24px; text-align: center; font-size: 14px; }
.mf-supgrade { max-width: 520px; margin: 28px auto; padding: 28px; text-align: center; border: 1px solid var(--gold, #b8860b); border-radius: 14px; background: var(--card, #fff); }
.mf-supgrade h3 { margin: 0 0 10px; font-family: "Playfair Display", Georgia, serif; font-size: 24px; }
.mf-supgrade p { margin: 0 0 20px; color: var(--muted, #6b6560); line-height: 1.6; }
.mf-supgrade a { display: inline-flex; justify-content: center; padding: 11px 18px; border-radius: 8px; background: var(--gold, #b8860b); color: #fff; font-family: "IBM Plex Mono", monospace; font-size: 13px; font-weight: 600; text-decoration: none; }
.mf-supgrade a:hover { filter: brightness(.92); }

/* ── Solution content typography ── */
.mf-sp { margin: 0 0 14px; }

#mfSolveBody h2.mf-sh2 {
  font-size: 15.5px;
  font-weight: 700;
  margin: 28px 0 10px;
  color: #c0392b;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: -.2px;
  padding-bottom: 6px;
  border-bottom: 2px solid #fce8e6;
}

#mfSolveBody h3.mf-sh3 {
  font-size: 14.5px;
  font-weight: 600;
  margin: 20px 0 8px;
  color: #333;
}

/* Numbered step cards */
.mf-sstep {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin: 14px 0;
  padding: 14px 18px;
  background: #fafafa;
  border-radius: 10px;
  border-left: 3px solid #c0392b;
  line-height: 1.75;
}
.mf-snum {
  font-weight: 700;
  color: #c0392b;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  flex-shrink: 0;
  padding-top: 1px;
  min-width: 24px;
}
.mf-stext { flex: 1; }

/* Math blocks */
#mfSolveBody .katex-display {
  margin: 20px 0;
  overflow-x: auto;
  padding: 18px 22px;
  background: #f7f8fa;
  border-radius: 10px;
  border: 1px solid #eaeaea;
}
#mfSolveBody .katex { font-size: 1.06em; }

/* ── "Detailed Solution" button on each problem ── */
/* Must span both grid columns (same as .mf-pfig-wrap) so it isn't
   squeezed into the 46px problem-number column */
.mf-solve-btn {
  box-sizing: border-box;
  grid-column: 1 / -1;   /* span full width of the 2-col problem grid */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: fit-content;
  margin-top: 10px;
  padding: 10px 20px;
  min-height: 44px;
  background: transparent;
  border: 2px solid #c0392b;
  border-radius: 8px;
  color: #c0392b;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: .2px;
  white-space: nowrap;
}
.mf-solve-btn:hover {
  background: #c0392b;
  color: #fff;
  box-shadow: 0 3px 10px rgba(192,57,43,.25);
}
.mf-solve-btn:active {
  transform: scale(.98);
}

/* ================================================================
   OWNER SOLUTION EXPORT — selection and complete-only print flow
   ================================================================ */
.mf-solution-select {
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  margin-top: 10px;
  color: #5c5148;
  font: 0.72rem 'IBM Plex Mono', monospace;
  cursor: pointer;
}
.mf-solution-select input {
  width: 16px;
  height: 16px;
  accent-color: #7c3a19;
  cursor: pointer;
}
.mf-export-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
  margin: 0 0 16px;
  padding: 10px 13px;
  border: 1px solid #ddcbbd;
  border-radius: 8px;
  background: #fff8f2;
  color: #57301e;
  font: 0.75rem 'IBM Plex Mono', monospace;
}
.mf-export-bar span { margin-right: auto; }
.mf-export-bar button,
.mf-batch-item button {
  border: 1px solid #7c3a19;
  border-radius: 4px;
  background: #7c3a19;
  color: #fff;
  padding: 5px 9px;
  font: 0.7rem 'IBM Plex Mono', monospace;
  cursor: pointer;
}
.mf-export-bar .mf-export-clear,
.mf-batch-item .mf-batch-remove {
  background: transparent;
  color: #7c3a19;
}
.mf-batch-modal {
  width: min(700px, 94vw);
  max-width: 700px;
}
.mf-batch-list {
  margin: 0;
  padding: 0;
  max-height: 44vh;
  overflow-y: auto;
  border: 1px solid #ded7cf;
  border-radius: 7px;
  background: #fff;
}
.mf-batch-progress {
  margin: 0 0 9px;
  color: #57301e;
  font: 0.72rem 'IBM Plex Mono', monospace;
}
.mf-batch-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-bottom: 1px solid #eee8e1;
  list-style-position: inside;
}
.mf-batch-item:last-child { border-bottom: 0; }
.mf-batch-item span { flex: 1; min-width: 0; }
.mf-batch-item strong,
.mf-batch-item small { display: block; }
.mf-batch-item small { margin-top: 3px; color: #6b6560; font: 0.68rem 'IBM Plex Mono', monospace; }
.mf-batch-generating small { color: #9a6200; }
.mf-batch-complete small { color: #187344; }
.mf-batch-failed { background: #fff5f4; }
.mf-batch-failed small { color: #b42318; }
.mf-batch-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 16px;
}
.mf-batch-actions .mf-btn-primary,
.mf-batch-actions .mf-btn-secondary {
  flex: 0 0 auto;
  padding: 9px 13px;
}
.mf-single-print-btn { flex: 0 0 auto; }

@media (max-width: 640px) {
  #mfSolveBody { padding: 20px 18px 30px; }
  #mfSolveHeader { padding: 14px 16px; }
  #mfSolvePanel { max-height: 96vh; border-radius: 12px; }
  #mfSolveClose { width: 44px; height: 44px; }
  .mf-exact-purchase-actions {
    align-items: stretch;
    flex-direction: column;
  }
  .mf-exact-purchase-actions > * {
    width: 100%;
    min-height: 44px;
  }
  .mf-export-bar span { width: 100%; }
  .mf-batch-actions .mf-btn-primary,
  .mf-batch-actions .mf-btn-secondary { width: 100%; }
}
