/* MathMaster — واجهة المسح والتصحيح (js/scan.js) */

body.mm-scan-open {
  overflow: hidden;
}
/* زرّا الرجوع والتطبيقات اللذان يحقنهما قالب الموقع (z-index أقصى) يغطّيان ✕ الماسح */
body.mm-scan-open #ls-game-nav,
body.mm-scan-open #ls-game-back {
  display: none !important;
}

.mm-scan {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  background: #0f0b16;
  color: #fff;
  font-family: "Tajawal", sans-serif;
}

/* ── الشريط العلويّ ── */
.mm-scan-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(0, 0, 0, 0.35);
}
.mm-scan-title {
  flex: 1;
  font-weight: 800;
  font-size: 17px;
}
.mm-scan-session {
  font-size: 13px;
  opacity: 0.8;
}
.mm-scan-close {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

/* ── الكاميرا ── */
.mm-scan-camera {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.mm-scan-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
.mm-scan-stage video,
.mm-scan-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.mm-scan-stage video {
  object-fit: contain;
}
/* إطار توجيه بنسبة A4 */
.mm-scan-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 86%;
  aspect-ratio: 794 / 1123;
  max-width: 92%;
  transform: translate(-50%, -50%);
  border: 2px dashed rgba(255, 255, 255, 0.45);
  border-radius: 10px;
  pointer-events: none;
}
.mm-scan.no-camera .mm-scan-stage video,
.mm-scan.no-camera .mm-scan-frame,
.mm-scan.no-camera .mm-scan-shutter,
.mm-scan.no-camera .mm-scan-btn.spacer {
  display: none;
}
.mm-scan.no-camera .mm-scan-actions {
  display: flex;
  justify-content: center;
}
.mm-scan-hint {
  padding: 10px 16px;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  min-height: 1.6em;
}
.mm-scan-hint.ok {
  color: #81c784;
}
.mm-scan-actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 16px 18px;
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}
.mm-scan-shutter {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 5px solid #fff;
  background: rgba(255, 255, 255, 0.25);
  cursor: pointer;
}
.mm-scan-shutter:active {
  background: #fff;
}

/* ── الأزرار ── */
.mm-scan-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  font: inherit;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  border: 1px solid transparent;
}
.mm-scan-btn.primary {
  background: var(--primary, #4a148c);
  color: #fff;
}
.mm-scan-btn.ghost {
  background: transparent;
  color: inherit;
  border-color: currentColor;
}
.mm-scan-btn.spacer {
  visibility: hidden;
}
.mm-scan-btn.copied::after {
  content: " ✓";
}

/* ── المعالجة والخطأ ── */
.mm-scan-busy,
.mm-scan-error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
}
.mm-scan-error p {
  max-width: 420px;
  line-height: 1.7;
  margin: 0;
}
.mm-scan-spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: mm-scan-spin 0.8s linear infinite;
}
@keyframes mm-scan-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── النتيجة ── */
.mm-scan-result {
  flex: 1;
  overflow-y: auto;
  background: #f4f2f8;
  color: #1a1a1a;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.mm-scan-result > * {
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}
.mm-scan-score {
  text-align: center;
  margin-bottom: 10px;
}
.mm-scan-model {
  font-size: 15px;
  color: #555;
}
.mm-scan-model strong {
  font-family: "Outfit", sans-serif;
  color: var(--primary, #4a148c);
  letter-spacing: 0.04em;
}
.mm-scan-big {
  font-family: "Outfit", "Tajawal", sans-serif;
  font-size: 40px;
  font-weight: 800;
  color: var(--primary, #4a148c);
  line-height: 1.2;
}
.mm-scan-big small {
  font-size: 18px;
  color: #666;
}
.mm-scan-warn {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 12px;
  border-radius: 8px;
  background: #fff3e0;
  color: #e65100;
  font-weight: 700;
  font-size: 14px;
}
.mm-scan-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  font-size: 12px;
  color: #555;
  margin-bottom: 8px;
}
.mm-scan-legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2.5px solid;
  border-radius: 50%;
  vertical-align: -2px;
  margin-inline-end: 4px;
}
.mm-scan-preview canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  background: #fff;
}
.mm-scan-table {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  font-size: 15px;
}
.mm-scan-table th,
.mm-scan-table td {
  padding: 7px 8px;
  text-align: center;
  border-bottom: 1px solid #eee;
}
.mm-scan-table th {
  background: var(--primary, #4a148c);
  color: #fff;
  font-size: 13px;
}
.mm-scan-table select {
  font: inherit;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 8px;
  border: 1px solid #ccc;
  background: #fff;
}
.mm-scan-table tr.st-correct .mm-scan-st {
  color: #2e7d32;
  font-weight: 900;
}
.mm-scan-table tr.st-wrong .mm-scan-st {
  color: #c62828;
  font-weight: 900;
}
.mm-scan-table tr.st-blank,
.mm-scan-table tr.st-multiple,
.mm-scan-table tr.st-unreadable,
.mm-scan-table tr.st-faint {
  background: #fff8ef;
}
.mm-scan-table tr.st-blank .mm-scan-st,
.mm-scan-table tr.st-multiple .mm-scan-st,
.mm-scan-table tr.st-unreadable .mm-scan-st {
  color: #e65100;
  font-weight: 700;
  font-size: 13px;
}
.mm-scan-note {
  font-size: 13px;
  color: #666;
  text-align: center;
}
.mm-scan-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}
.mm-scan-result .mm-scan-btn.ghost {
  color: var(--primary, #4a148c);
}
/* تظليل خفيف: الحالة (✓/✗) تبقى بلونها، ويُضاف «خفيف» */
.mm-scan-table tr.st-faint .mm-scan-st {
  font-size: 13px;
}

