/* ============================================================================
 * bulletproof.css — Layer 4: 방탄 UI (CSS 템플릿)
 * 미션: M-AUTO-QA-5LAYER-20260510 / Layer 4
 *
 * 박대표 verbatim:
 *   - "Playwright X / 방탄 UI 의무"
 *   - 5/11 11:00 베타 출시 / 0 오류 의무
 *
 * 기능:
 *   1. MathJax 강제 렌더링 (수식 깨짐 0)
 *   2. overflow-wrap: break-word (텍스트 박스 0)
 *   3. CSS Grid 1열 (모바일 우선)
 *   4. max-width: 100%; object-fit: contain (이미지 깨짐 0)
 *   5. max-height: 400px (과학 이미지 세로 보호)
 *   6. AI SVG = display: none (영구 차단)
 * ========================================================================== */

/* ── 0. AI SVG 영구 차단 (박대표 영구 거부 룰) ─────────────────────────── */
.ai-generated-svg,
[data-source="ai-svg"],
[data-generator="ai-svg"],
svg[data-ai-generated="true"] {
  display: none !important;
}

/* ── 1. 페이지 베이스 (모바일 우선 / 1열 Grid) ─────────────────────────── */
.bp-root {
  display: grid;
  grid-template-columns: 1fr;        /* 1열 강제 (모바일 우선) */
  gap: 1rem;
  max-width: 100%;
  padding: 1rem;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR",
               "Apple SD Gothic Neo", sans-serif;
  line-height: 1.6;
  color: #1f2937;
}

/* 노트북/태블릿 (768px+) — 박대표 노트북 주력 */
@media (min-width: 768px) {
  .bp-root {
    grid-template-columns: minmax(0, 1fr);
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem;
  }
}

/* ── 2. 문제 카드 (overflow 차단) ──────────────────────────────────────── */
.bp-question {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 1.25rem;
  word-break: keep-all;             /* 한글 띄어쓰기 보호 */
  overflow-wrap: break-word;         /* 긴 영어/URL 박스 탈출 0 */
  hyphens: auto;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.bp-question p,
.bp-question div,
.bp-question span,
.bp-question li {
  overflow-wrap: break-word;
  word-break: keep-all;
  max-width: 100%;
}

/* 긴 영어 단어 / URL 강제 줄바꿈 */
.bp-question pre,
.bp-question code,
.bp-question .url,
.bp-question .ltr-text {
  word-break: break-all;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* ── 3. 이미지 방탄 (4/30 SetC 깨짐 사고 영구 차단) ───────────────────── */
.bp-image,
.bp-question img,
.bp-resource img {
  display: block;
  max-width: 100%;
  height: auto;
  max-height: 400px;                 /* 과학 이미지 세로 보호 */
  object-fit: contain;               /* 비율 유지 + 박스 안 fit */
  margin: 1rem auto;
  border-radius: 8px;
  background: #f9fafb;               /* 로딩 중 placeholder */
}

/* 수학 도형 등 정확한 비율 의무 시 */
.bp-image--exact,
.bp-question img.exact-ratio {
  object-fit: scale-down;
  image-rendering: crisp-edges;       /* 수학 SVG 픽셀 선명 */
}

/* ── 4. MathJax 강제 렌더링 (수식 깨짐 0) ───────────────────────────────── */
mjx-container,
.MathJax,
.mjx-chtml {
  max-width: 100% !important;
  overflow-x: auto;                  /* 긴 수식 가로 스크롤 OK */
  overflow-y: hidden;
  display: inline-block !important;
  vertical-align: middle;
}

mjx-container[display="true"] {
  display: block !important;
  margin: 0.75rem 0 !important;
  text-align: center;
}

/* 미렌더링 fallback — \( ... \) 노출 차단 */
.bp-math-fallback {
  font-family: "Cambria Math", "STIX Two Math", "Times New Roman", serif;
  font-style: italic;
  background: #fef3c7;
  padding: 0.125rem 0.25rem;
  border-radius: 4px;
}

/* ── 5. 정답 입력 / 버튼 (모바일 터치 보호) ──────────────────────────── */
.bp-answer-input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid #d1d5db;
  border-radius: 8px;
  background: #ffffff;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  /* 모바일 zoom 차단 (font-size ≥16px 의무) */
  font-size: max(16px, 1rem);
}

.bp-answer-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.bp-button {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  min-height: 44px;                  /* 터치 타겟 44pt 의무 */
  min-width: 88px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  background: #2563eb;
  color: #ffffff;
  -webkit-tap-highlight-color: transparent;
}

.bp-button:hover:not(:disabled) { background: #1d4ed8; }
.bp-button:active:not(:disabled) { transform: scale(0.98); }
.bp-button:disabled { background: #9ca3af; cursor: not-allowed; }

/* ── 6. 자료 카드 (외부 OER iframe 박스) ────────────────────────────────── */
.bp-resource {
  position: relative;
  width: 100%;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  overflow: hidden;
}

.bp-resource iframe {
  display: block;
  width: 100%;
  border: 0;
  aspect-ratio: 16 / 9;              /* PhET / YouTube 표준 */
  max-height: 480px;
}

/* PhET 시뮬 (정사각형에 가까운 비율) */
.bp-resource--sim iframe {
  aspect-ratio: 4 / 3;
}

/* 출처 표기 (라이선스 attribution 의무) */
.bp-resource__attribution {
  font-size: 0.75rem;
  color: #6b7280;
  padding: 0.5rem 0.75rem;
  background: #f3f4f6;
  border-top: 1px solid #e5e7eb;
}

.bp-resource__attribution a {
  color: #4b5563;
  text-decoration: underline;
}

/* ── 7. 표 / 코드 (overflow 차단) ──────────────────────────────────────── */
.bp-question table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;                  /* 표 가로 스크롤 OK · 박스 깨짐 X */
  -webkit-overflow-scrolling: touch;
}

.bp-question table th,
.bp-question table td {
  padding: 0.5rem 0.75rem;
  border: 1px solid #e5e7eb;
  text-align: left;
  vertical-align: top;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.bp-question pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
  background: #f3f4f6;
  padding: 0.75rem;
  border-radius: 6px;
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  font-size: 0.875rem;
}

/* ── 8. 접근성 / prefers-reduced-motion ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .bp-button { transition: none; }
  .bp-button:active { transform: none; }
}

/* ── 9. 인쇄 (학부모 출력 대응) ───────────────────────────────────────── */
/* 5/19 박대표 verbatim "다크 모드는 전부 다 없애야지" = @media (prefers-color-scheme: dark) 블록 영구 제거 (= 라이트 모드 단일 영구 표준) */
@media print {
  .bp-root {
    max-width: 100%;
    padding: 0;
  }
  .bp-button,
  .bp-answer-input { display: none; }
  .bp-image { max-height: none; }
  mjx-container { overflow: visible !important; }
}
