/* ออกข้อสอบบาลีไวยากรณ์ (อัตนัย)
   หน้าจอ = เครื่องมือจัดชุด · ตอนพิมพ์ = กระดาษสอบ A4 อย่างเดียว */
@font-face {
	font-family: 'THSarabunPali';
	src: url('/assets/fonts/THSarabunPali.ttf') format('truetype');
	font-display: swap;
}

:root {
	--em-primary: #7c3f00;
	--em-primary-soft: #f6ede2;
	--em-text: #2b2118;
	--em-text-soft: #7a6a5a;
	--em-line: #e2d6c6;
	--em-danger: #b02a2a;
	--em-bg: #faf6f0;
}
[v-cloak] { display: none; }

.em-body { margin: 0; background: var(--em-bg); color: var(--em-text);
	font-family: 'THSarabunPali', 'Sarabun', system-ui, sans-serif; font-size: 20px; }

/* ── แถบบน ── */
.em-appbar { background: var(--em-primary); color: #fff; position: sticky; top: 0; z-index: 20; }
.em-appbar-inner { max-width: 980px; margin: 0 auto; display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; }
.em-back-btn { color: #fff; opacity: .85; text-decoration: none; font-size: 1.1rem; }
.em-brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; }
.em-brand-mark { background: rgba(255,255,255,.16); border-radius: 10px; width: 38px; height: 38px;
	display: grid; place-items: center; }
.em-brand-text { display: block; font-size: 1.15rem; line-height: 1.1; }
.em-brand-sub { display: block; font-size: .78rem; opacity: .8; }

.em-shell { max-width: 980px; margin: 0 auto; padding: 1rem; }
.em-card { background: #fff; border: 1px solid var(--em-line); border-radius: 14px; padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.em-card-title { font-size: 1.2rem; margin: 0 0 .9rem; display: flex; align-items: center; gap: .5rem; }

.em-field { margin-bottom: .9rem; }
.em-field > label { display: block; font-size: .95rem; color: var(--em-text-soft); margin-bottom: .35rem; }
.em-field > label small { opacity: .75; }
.em-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.em-row > * { flex: 1 1 180px; }
.em-narrow { min-width: 180px; }

.em-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.em-chip { border: 1px solid var(--em-line); background: #fff; color: var(--em-text);
	border-radius: 999px; padding: .2rem .7rem; cursor: pointer; font: inherit; font-size: .92rem; }
.em-chip.on { background: var(--em-primary); border-color: var(--em-primary); color: #fff; }
.em-chip-actions { margin-top: .4rem; display: flex; gap: .4rem; }
.em-mini { border: none; background: none; color: var(--em-primary); cursor: pointer; font: inherit;
	font-size: .88rem; text-decoration: underline; padding: 0; }
.em-mini-r { margin-left: auto; }

.em-select { width: 100%; padding: .4rem .6rem; border: 1px solid var(--em-line); border-radius: 8px;
	font: inherit; background: #fff; color: inherit; }
.em-check { display: block; margin: .6rem 0; font-size: .95rem; }
.em-pool { background: var(--em-primary-soft); border-radius: 8px; padding: .5rem .8rem; margin: .6rem 0; font-size: .95rem; }
.em-warn { color: var(--em-danger); }

.em-btn { border: none; border-radius: 10px; padding: .55rem 1.1rem; font: inherit; cursor: pointer; }
.em-btn-primary { background: var(--em-primary); color: #fff; }
.em-btn-ghost { background: #fff; color: var(--em-primary); border: 1px solid var(--em-primary); }
.em-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.em-hint { font-size: .88rem; color: var(--em-text-soft); }

/* ── รายการข้อ ── */
.em-list { list-style: none; margin: 0; padding: 0; }
.em-item { display: flex; gap: .7rem; align-items: flex-start; padding: .6rem 0; border-top: 1px solid var(--em-line); cursor: grab; }
.em-item-no { background: var(--em-primary-soft); color: var(--em-primary); border-radius: 8px;
	min-width: 2rem; text-align: center; padding: .1rem .3rem; }
.em-item-body { flex: 1; min-width: 0; }
.em-item-meta { font-size: .85rem; color: var(--em-text-soft); }
.em-item-q { line-height: 1.35; }
.em-item-tools { display: flex; gap: .2rem; }
.em-icon { border: 1px solid var(--em-line); background: #fff; border-radius: 8px; width: 2rem; height: 2rem;
	cursor: pointer; color: var(--em-text-soft); }
.em-icon-danger { color: var(--em-danger); }

/* ── เลือกข้อเอง ── */
.em-modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 40; padding: 1rem; }
.em-modal-box { background: #fff; border-radius: 14px; padding: 1rem 1.2rem; max-width: 720px; width: 100%; max-height: 80vh; display: flex; flex-direction: column; }
.em-modal-box h3 { margin: 0 0 .6rem; display: flex; align-items: center; }
.em-picker-list { list-style: none; margin: .6rem 0 0; padding: 0; overflow: auto; }
.em-picker-list li { padding: .5rem 0; border-top: 1px solid var(--em-line); cursor: pointer; }
.em-picker-list li:hover { background: var(--em-primary-soft); }
.em-picker-meta { display: block; font-size: .82rem; color: var(--em-text-soft); }
.em-empty { color: var(--em-text-soft); text-align: center; padding: 1rem; }

/* ── กระดาษสอบ ──
   สไตล์อยู่นอก @media print เพราะใช้ 2 ทาง: พิมพ์ผ่านเบราว์เซอร์ กับสร้าง PDF ด้วย html2pdf
   ถ้าเก็บไว้ใน @media print ตอนสร้าง PDF จะได้กระดาษเปล่า (เคยพลาดมาแล้ว) */
.em-paper { display: none; background: #fff; color: #000; font-size: 16pt; }
/* ⚠ ห้ามใช้ position:fixed หรือ left:-9999px ตอนสร้าง PDF
   html2canvas จะได้กระดาษเปล่า (วัดแล้ว 3 KB เทียบกับ 388 KB)
   ต้องอยู่ในโฟลว์ปกติ แล้วใช้ .em-veil บังตาแทน
   ⚠ และต้องซ่อน UI ทั้งหมดด้วย (body.pdf-mode) ไม่งั้นกระดาษอยู่ท้ายโฟลว์
   จะได้หน้าว่างนำหน้าและเนื้อหาเลื่อนกลางหน้า
   ความกว้าง 184mm = A4 210mm ลบระยะขอบซ้ายขวา 13mm ที่ตั้งไว้ใน html2pdf */
.em-paper.showing { display: block; width: 184mm; }
.pdf-mode .em-shell, .pdf-mode .em-appbar { display: none !important; }
.pdf-mode { margin: 0; }

.em-paper-head { text-align: center; margin-bottom: 1rem; }
.em-paper-head h1 { font-size: 20pt; margin: 0 0 .2rem; }
.em-paper-org { font-size: 15pt; color: #444; }
.em-paper-fields { display: flex; justify-content: space-between; gap: 1rem; margin-top: .8rem; font-size: 14pt; }
.em-paper-note { margin-top: .6rem; text-align: left; border-top: 1px solid #000;
	border-bottom: 1px solid #000; padding: .25rem 0; font-size: 14pt; }
.em-paper-key { font-weight: bold; }

.em-paper-list { list-style: none; margin: 0; padding: 0; }
/* ห้ามให้ข้อหนึ่งถูกตัดคนละหน้า ครูตรวจแล้วสับสน */
.em-paper-item { break-inside: avoid; page-break-inside: avoid; margin-bottom: .9rem; }
.em-paper-q { display: flex; gap: .4rem; line-height: 1.45; }
.em-paper-num { min-width: 1.6rem; }
.em-paper-ctx { display: block; font-style: italic; color: #333; white-space: pre; }
.em-paper-qbody { display: block; }
/* แต่ละบรรทัดเป็นบล็อกและห้ามตัดซ้ำ — กันตัวอักษรทับกันตอนแปลงเป็นภาพ */
.em-paper-ln { display: block; white-space: pre; }

.em-paper-lines { margin: .35rem 0 0 2rem; }
.em-paper-line { border-bottom: 1px dotted #999; height: 1.55em; }

/* "เฉลย" เป็นบล็อกของตัวเอง — html2canvas วาด inline ปนข้อความยาวหลายบรรทัดผิด
   (ตัวอักษรบรรทัดถัดไปทับบรรทัดก่อนหน้า) */
.em-paper-a { margin: .3rem 0 0 2rem; line-height: 1.45; }
.em-paper-a-tag { display: block; font-weight: bold; }

.em-paper-src { font-size: 12pt; color: #555; margin-top: .1rem; }

/* ม่านบังตอนสร้าง PDF — กระดาษต้องอยู่ในจอจริง html2canvas ถึงจะวาดออก */
.em-veil { position: fixed; inset: 0; background: rgba(250,246,240,.96); z-index: 60;
	display: grid; place-items: center; font-size: 1.1rem; color: var(--em-primary); }


@media print {
	@page { size: A4; margin: 16mm 15mm 18mm; }
	.no-print, .em-appbar { display: none !important; }
	.em-body { background: #fff; }
	.em-paper { display: block; width: auto; }
}
