/* soosik 에디터 화면 스타일 */

* { box-sizing: border-box; }
html, body { height: 100%; }

/* HTML [hidden] 속성이 display:flex / display:grid 규칙에 덮이는 표준 동작 차단 */
[hidden] { display: none !important; }

/* 검색엔진/스크린리더용 (시각적으로만 숨김, DOM 에는 존재) */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── 파일 드래그앤드롭 오버레이 ─────────────────────── */
body.soosik-file-dragging::before {
  content: '.soo 파일을 놓으세요';
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2c3e50;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  z-index: 99999;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: soosik-drop-bounce 0.6s ease-in-out infinite alternate;
}
body.soosik-file-dragging::after {
  content: '';
  position: fixed;
  inset: 12px;
  border: 4px dashed #2c3e50;
  border-radius: 12px;
  pointer-events: none;
  z-index: 99998;
  box-sizing: border-box;
  background: rgba(44, 62, 80, 0.05);
}
@keyframes soosik-drop-bounce {
  from { transform: translate(-50%, 0); }
  to   { transform: translate(-50%, -4px); }
}
body {
  margin: 0;
  font-family: 'Malgun Gothic', '맑은 고딕', 'Apple SD Gothic Neo', sans-serif;
  background: #e8eaed;
  color: #222;
  overflow: hidden;
}

/* ── Toolbar ───────────────────────────────────────── */
.toolbar {
  height: 52px;
  background: linear-gradient(180deg, #34495e, #2c3e50);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  position: relative;
  z-index: 100;
}
.brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.5px;
}
.brand span { font-family: 'Trebuchet MS', sans-serif; }
.tools {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}
.tools.right-tools {
  margin-left: auto;
  flex-wrap: nowrap;
}
.tools.right-tools .icon-btn {
  font-size: 18px;
  padding: 4px 10px;
  line-height: 1;
}
.tools button {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  transition: background 0.12s;
}
.tools button:hover {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.35);
}
.tools button b { font-weight: 800; }
.sep {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,0.25);
  margin: 0 6px;
}

/* 툴바 — 글자 크기/글꼴 드롭다운 */
.tools select.toolbar-select {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  height: 28px;
  max-width: 110px;
}
.tools select.toolbar-select:hover,
.tools select.toolbar-select:focus {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.4);
  outline: none;
}
.tools select.toolbar-select option {
  background: #34495e;
  color: #fff;
}

/* 툴바 — 글자 색깔 입력 */
.tools input[type="color"].toolbar-color {
  width: 32px;
  height: 28px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
  padding: 2px;
  vertical-align: middle;
}
.tools input[type="color"].toolbar-color:hover {
  border-color: rgba(255,255,255,0.4);
}
.dropdown { position: relative; display: inline-block; }
/* 메뉴를 버튼에 딱 붙여서 마우스가 갭으로 빠지는 일이 없게 함 */
.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: #fff;
  color: #222;
  min-width: 220px;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.18);
  display: none;
  overflow: hidden;
  z-index: 200;
}
.dropdown:hover .dropdown-menu,
.dropdown:focus-within .dropdown-menu { display: block; }
.dropdown:hover > button,
.dropdown:focus-within > button { background: rgba(255,255,255,0.2); }
.dropdown-menu a {
  display: block;
  padding: 10px 14px;
  cursor: pointer;
  text-decoration: none;
  color: #222;
  font-size: 13px;
  border-bottom: 1px solid #f0f0f0;
}
.dropdown-menu a:last-child { border-bottom: none; }
.dropdown-menu a:hover { background: #f5f8fb; }

/* ── Workspace ─────────────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: 220px 1fr 280px;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 52px);
}

.sidebar {
  background: #fff;
  border-radius: 8px;
  padding: 14px;
  overflow-y: auto;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.sidebar h3 {
  margin: 14px 0 6px;
  font-size: 12px;
  color: #888;
  border-bottom: 1px solid #eee;
  padding-bottom: 4px;
  letter-spacing: 0.5px;
  text-transform: none;
}
.sidebar h3:first-child { margin-top: 0; }

.sidebar label {
  display: block;
  font-size: 12px;
  color: #555;
  margin: 8px 0;
  font-weight: 500;
}
.sidebar label input[type="text"],
.sidebar label input[type="date"],
.sidebar label input[type="number"],
.sidebar label select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d6d6d6;
  border-radius: 4px;
  font-size: 13px;
  margin-top: 3px;
  font-family: inherit;
  background: #fff;
}
.sidebar label input[type="checkbox"] {
  margin-right: 6px;
  transform: translateY(1px);
}
.sidebar button.full {
  width: 100%;
  padding: 8px 10px;
  margin: 3px 0;
  border: 1px solid #d6d6d6;
  background: #f7f8fa;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: background 0.12s;
}
.sidebar button.full:hover { background: #eef2f7; }

.symbol-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}
.symbol-grid button {
  background: #f7f8fa;
  border: 1px solid #ddd;
  padding: 8px 4px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  min-height: 38px;
  font-family: 'KaTeX_Main', 'Times New Roman', serif;
}
.symbol-grid button:hover {
  background: #eef2f7;
  border-color: #888;
}

.template-list button {
  display: block;
  width: 100%;
  text-align: left;
  background: #f7f8fa;
  border: 1px solid #ddd;
  padding: 6px 10px;
  margin: 3px 0;
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
}
.template-list button:hover { background: #eef2f7; }

/* ── 모달 (도움말 / 사용 팁 팝업) ───────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: soosik-fade 0.15s ease-out;
}
.modal[hidden] { display: none !important; }
@keyframes soosik-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.modal-card {
  background: #fff;
  border-radius: 10px;
  max-width: 720px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid #eee;
  background: #f8f9fb;
}
.modal-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #2c3e50;
}
.modal-close {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #888;
  padding: 4px 10px;
  border-radius: 4px;
  font-family: inherit;
}
.modal-close:hover { background: #ececec; color: #222; }
.modal-body {
  padding: 18px 22px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.65;
  color: #333;
}
.modal-body p { margin: 8px 0; }
.modal-body ul {
  padding-left: 22px;
  margin: 6px 0 14px;
}
.modal-body li { margin: 4px 0; }
.modal-body h3 {
  margin: 16px 0 6px;
  font-size: 13px;
  color: #2c3e50;
}
.modal-body code {
  background: #f3f5f8;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
  color: #c2185b;
}
.modal-body kbd {
  background: #fff;
  border: 1px solid #ccc;
  border-bottom-width: 2px;
  padding: 1px 6px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 11px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.05);
}
.help-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
}
.help-table th, .help-table td {
  border: 1px solid #e6e6e6;
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
.help-table thead th {
  background: #f3f5f8;
  font-weight: 600;
  font-size: 12px;
  color: #555;
}
.help-table tbody tr:hover { background: #fafbfd; }
.modal-body .hint {
  background: #fff8e1;
  border-left: 3px solid #ffc107;
  padding: 8px 12px;
  margin: 12px 0;
  font-size: 12px;
  color: #6b5a20;
}

/* ── 이미지 업로드 모달 (Gemini OCR) ──────────────── */
.modal-card-wide { max-width: 1000px; }

.image-drop-zone {
  border: 2px dashed #b8c2cc;
  border-radius: 10px;
  padding: 70px 24px;
  text-align: center;
  cursor: pointer;
  background: #f8f9fb;
  transition: background 0.15s, border-color 0.15s;
  outline: none;
}
.image-drop-zone:hover,
.image-drop-zone:focus,
.image-drop-zone.dragover {
  border-color: #2c3e50;
  background: #eef2f7;
}
.image-drop-zone .dz-icon {
  font-size: 44px;
  color: #b8c2cc;
  margin-bottom: 8px;
  font-weight: 300;
  line-height: 1;
}
.image-drop-zone:hover .dz-icon,
.image-drop-zone.dragover .dz-icon { color: #2c3e50; }
.image-drop-zone .dz-title {
  font-size: 15px;
  font-weight: 600;
  color: #2c3e50;
  margin: 6px 0;
}
.image-drop-zone .dz-hint {
  font-size: 12px;
  color: #7a8694;
  margin: 4px 0 0;
}
.image-drop-zone .dz-hint b {
  color: #2c3e50;
  background: #fff;
  border: 1px solid #d6d6d6;
  border-radius: 3px;
  padding: 1px 6px;
  font-family: monospace;
  font-weight: 600;
}

.image-preview-area {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 18px;
}
@media (max-width: 760px) {
  .image-preview-area { grid-template-columns: 1fr; }
}
.preview-left, .preview-right {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.preview-section-title {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  letter-spacing: 0.3px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 8px;
}
.image-thumb-wrap {
  background: #fafafa;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  max-height: 420px;
  overflow: auto;
  margin-bottom: 10px;
}
#image-preview {
  max-width: 100%;
  max-height: 400px;
  display: block;
  object-fit: contain;
}

.extract-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 300px;
  position: relative;
}
#extracted-text {
  flex: 1;
  width: 100%;
  min-height: 280px;
  padding: 12px;
  border: 1px solid #d6d6d6;
  border-radius: 6px;
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  background: #fff;
  color: #222;
  box-sizing: border-box;
}
#extracted-text:focus { outline: 2px solid #b3d4fc; outline-offset: -2px; }

.extraction-progress {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  border: 1px solid #d6d6d6;
  border-radius: 6px;
  background: #fafbfd;
  min-height: 280px;
}
.progress-message {
  font-size: 15px;
  color: #2c3e50;
  font-weight: 600;
  margin-bottom: 16px;
}
.progress-message::after {
  content: '';
  display: inline-block;
  width: 14px;
  text-align: left;
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
}
.progress-bar {
  width: 100%;
  max-width: 360px;
  height: 8px;
  background: #e6e9ee;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  margin-bottom: 14px;
}
.progress-bar-fill {
  position: absolute;
  top: 0;
  left: -35%;
  height: 100%;
  width: 35%;
  background: linear-gradient(90deg, #5b9dd9, #2c3e50);
  border-radius: 4px;
  animation: progress-slide 1.4s ease-in-out infinite;
}
@keyframes progress-slide {
  0%   { left: -35%; }
  100% { left: 100%; }
}
.progress-detail {
  color: #777;
  font-size: 12px;
  text-align: center;
  max-width: 380px;
}

.preview-right .actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.preview-right .actions button {
  padding: 10px 14px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: background 0.12s;
}
.preview-right .actions .ghost-btn {
  background: #fff;
  border: 1px solid #d6d6d6;
  color: #333;
}
.preview-right .actions .ghost-btn:hover { background: #f5f7fa; border-color: #999; }
.preview-right .actions .primary-btn {
  flex: 1;
  background: #2c3e50;
  border: 1px solid #2c3e50;
  color: #fff;
}
.preview-right .actions .primary-btn:hover:not(:disabled) { background: #1a2530; }
.preview-right .actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.preview-left .ghost-btn.full {
  width: 100%;
  padding: 8px;
  background: #fff;
  border: 1px solid #d6d6d6;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.preview-left .ghost-btn.full:hover { background: #f5f7fa; }

.status-tag {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.2px;
}
.status-tag.working { background: #e3f2fd; color: #0d47a1; }
.status-tag.ok      { background: #e8f5e9; color: #1b5e20; }
.status-tag.warn    { background: #fff8e1; color: #6b5a20; }
.status-tag.error   { background: #ffebee; color: #b71c1c; }

/* 본문에 삽입된 블록 시각적 구분 (선택사항) */
.exam-body .imported-block {
  /* 별도 시각 효과 없음. 필요 시 좌측 살짝 들여쓰기 등 추가 가능 */
}

/* ── Page (A4/B4 시각화) ───────────────────────────── */
.page-container {
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  background: #d8dbe0;
}
.page {
  padding: 15mm;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  font-size: 11pt;
  line-height: 1.7;
  color: #1a1a1a;
  position: relative;
  background-color: #fff;
  height: auto;
  flex: 0 0 auto;   /* flex 부모에서 컨텐츠 크기대로 자라도록 명시 */
}
/* A4: 297mm마다 진한 경계선 + 컨테이너 색과 같은 회색 띠로 "새 페이지가 생긴 것처럼" 보이게 함 */
.page.a4 {
  width: 210mm;
  min-height: 297mm;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(297mm - 1px),
    #6b7785 calc(297mm - 1px),
    #6b7785 297mm,
    #d8dbe0 297mm,
    #d8dbe0 calc(297mm + 14mm),
    #6b7785 calc(297mm + 14mm),
    #6b7785 calc(297mm + 14mm + 1px),
    transparent calc(297mm + 14mm + 1px)
  );
}
.page.b4 {
  width: 257mm;
  min-height: 364mm;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(364mm - 1px),
    #6b7785 calc(364mm - 1px),
    #6b7785 364mm,
    #d8dbe0 364mm,
    #d8dbe0 calc(364mm + 14mm),
    #6b7785 calc(364mm + 14mm),
    #6b7785 calc(364mm + 14mm + 1px),
    transparent calc(364mm + 14mm + 1px)
  );
}

/* ── 페이지 모서리 가이드 ──
   각 페이지마다 JS 가 동적으로 4개의 코너를 생성하여 top/left/right 를 인라인 스타일로 지정.
   CSS는 보더(L자 모양)만 담당. */
.page-corner {
  position: absolute;
  width: 8mm;
  height: 8mm;
  pointer-events: none;
  z-index: 2;
}
.corner-tl { border-bottom: 1.5px solid #b8c2cc; border-right: 1.5px solid #b8c2cc; }
.corner-tr { border-bottom: 1.5px solid #b8c2cc; border-left:  1.5px solid #b8c2cc; }
.corner-bl { border-top:    1.5px solid #b8c2cc; border-right: 1.5px solid #b8c2cc; }
.corner-br { border-top:    1.5px solid #b8c2cc; border-left:  1.5px solid #b8c2cc; }

/* ── Simple 모드 (index2.php) — 메모장처럼 완전한 흰 종이 한 장 ── */
body.soosik-simple .page-corner { display: none !important; }
body.soosik-simple .page.a4,
body.soosik-simple .page.b4 {
  background-image: none;
}

/* 시험지 헤더 */
.exam-header {
  border-bottom: 2.5px solid #222;
  padding-bottom: 10px;
  margin-bottom: 16px;
}
.exam-title {
  font-size: 18pt;
  font-weight: 700;
  text-align: center;
  margin-bottom: 10px;
  min-height: 28px;
}
.exam-title:empty:before {
  content: attr(data-placeholder);
  color: #bbb;
  font-weight: 400;
  font-size: 14pt;
}
.exam-meta {
  display: flex;
  justify-content: space-around;
  font-size: 10pt;
  color: #444;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 8px;
}
.exam-meta span:empty:before {
  content: attr(data-placeholder);
  color: #bbb;
}
.exam-student-info {
  display: inline-flex;
  gap: 24px;
  font-size: 10pt;
  border: 1px solid #888;
  padding: 6px 12px;
  margin-top: 4px;
}

/* 본문 */
.exam-body {
  min-height: 220mm;
  outline: none;
}
/* 편집 모드에서도 2단/3단 적용 (시험지 양쪽 활용) */
.exam-body.cols-2 {
  column-count: 2;
  column-gap: 10mm;
  column-rule: 1px dashed #d0d4d8;
}
.exam-body.cols-3 {
  column-count: 3;
  column-gap: 8mm;
  column-rule: 1px dashed #d0d4d8;
}
.exam-body p { margin: 0 0 8px; }

/* 문제 블록 */
.exam-body .problem {
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
}
.exam-body .problem-num {
  font-weight: 700;
  min-width: 22px;
  color: #1a3a6a;
}
.exam-body .problem-body { min-width: 0; }
.exam-body .problem-body > .score {
  float: right;
  font-size: 9pt;
  color: #b00020;
  margin-left: 8px;
}

/* 객관식 보기 */
.exam-body .choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 18px;
  margin-top: 6px;
}
.exam-body .choice {
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.exam-body .choice-mark { font-weight: 700; min-width: 16px; }

/* 답란 박스 - 내부에서 엔터 시 줄이 늘어남 (height auto) */
.exam-body .answer-box {
  border: 1px solid #888;
  border-radius: 2px;
  min-height: 60px;
  height: auto;
  margin-top: 8px;
  padding: 6px 8px;
  background: #fafafa;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.exam-body .answer-box:focus { outline: 2px solid #b3d4fc; outline-offset: -2px; background: #fff; }

/* 밑줄 빈칸 */
.exam-body .blank {
  display: inline-block;
  border-bottom: 1.2px solid #333;
  min-width: 60px;
  padding: 0 4px;
}

/* 삽입된 이미지 (도형 / 그래프 / 사진 등) */
.exam-body .image-block {
  text-align: center;
  margin: 8px 0;
  break-inside: avoid;
  page-break-inside: avoid;
}
.exam-body .inserted-image {
  max-width: 100%;
  max-height: 150mm;
  height: auto;
  display: inline-block;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 2px;
  vertical-align: middle;
}
.exam-body .inserted-image:hover {
  border-color: #b3d4fc;
}

/* 인라인 수식 래퍼 */
.soosik-eq {
  display: inline-block;
  vertical-align: middle;
  padding: 0 2px;
  cursor: pointer;
  border-radius: 3px;
}
.soosik-eq:hover {
  background: #fff8d6;
  outline: 1px dashed #d4a73a;
}
.soosik-eq.selected {
  background: #fff3b0;
  outline: 1px solid #d4a73a;
}

/* KaTeX 사이즈 보정 */
.katex { font-size: 1.05em; }
.katex-display { margin: 8px 0; }

/* ── 미리보기 모드 (브라우저 화면에서 인쇄형으로) ── */
body.preview-mode {
  background: #777;
}
body.preview-mode .sidebar,
body.preview-mode .tools {
  display: none !important;
}
body.preview-mode .workspace {
  grid-template-columns: 1fr;
  padding: 20px;
}
body.preview-mode .exam-body.cols-2 {
  column-count: 2;
  column-gap: 12mm;
  column-rule: 1px solid #ddd;
}
body.preview-mode .exam-body.cols-3 {
  column-count: 3;
  column-gap: 10mm;
  column-rule: 1px solid #ddd;
}
body.preview-mode .exam-body .problem,
body.preview-mode .exam-body .answer-box {
  break-inside: avoid;
}
/* 미리보기 모드에서는 가이드/페이지 경계 시각화 숨김 (실제 인쇄와 동일하게) */
body.preview-mode .page-corner { display: none; }
body.preview-mode .page.a4,
body.preview-mode .page.b4 {
  background-image: none;
}
