/* kru.tm8labs.com — เครื่องสร้างใบงานภาษาไทย · ตัวหนังสือ ≥ 13px เนื้อหา 15–16px (อ่านง่ายทุกวัย) */
:root {
  --bg: #f6f4ee; --card: #ffffff; --ink: #1f2a2b; --muted: #5b6566; --line: #e3dfd3;
  --brand: #0f766e; --brand-2: #115e59; --soft: #e6f4f1; --accent: #f59e0b; --warn: #b45309;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 24px rgba(15,118,110,.08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.7 "IBM Plex Sans Thai", "Sarabun", system-ui, sans-serif; }
a { color: var(--brand); }
.skip { position: absolute; left: -999px; } .skip:focus { left: 12px; top: 12px; background: #fff; padding: 8px 12px; z-index: 9; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

/* หัวเว็บ */
.top { background: #fff; border-bottom: 1px solid var(--line); }
.top .wrap { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 18px; }
.logo .mk { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 17px; }
.logo small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; line-height: 1.2; }
.top nav { margin-left: auto; display: flex; gap: 14px; flex-wrap: wrap; font-size: 15px; }
.top nav a { text-decoration: none; color: var(--muted); } .top nav a:hover { color: var(--brand); }

/* hero */
.hero { padding: 26px 0 8px; }
.hero h1 { margin: 0 0 6px; font-size: clamp(26px, 4vw, 36px); line-height: 1.3; }
.hero p { margin: 0; color: var(--muted); font-size: 17px; max-width: 760px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip { background: var(--soft); color: var(--brand-2); border-radius: 99px; padding: 4px 12px; font-size: 14px; font-weight: 500; }

/* แถบชนิดใบงาน */
.types { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0 14px; }
.types button { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 10px; padding: 9px 14px; font: inherit; font-size: 15px; cursor: pointer; }
.types button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

/* พื้นที่ทำงาน */
.app { display: grid; grid-template-columns: 340px 1fr; gap: 18px; align-items: start; margin-bottom: 28px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); position: sticky; top: 12px; }
.panel h2 { font-size: 17px; margin: 0 0 10px; }
.row { margin-bottom: 12px; }
.row label, .row .lbl { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.row select, .row input[type=text], .row textarea { width: 100%; font: inherit; font-size: 15px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.row textarea { min-height: 76px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.note { font-size: 13.5px; color: var(--muted); margin-top: 4px; }
.note.w { color: var(--warn); }
.btns { display: grid; gap: 8px; margin-top: 14px; }
.btn { display: inline-flex; justify-content: center; align-items: center; gap: 8px; border: 0; border-radius: 12px; padding: 11px 16px; font: inherit; font-size: 16px; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.main { background: var(--brand); color: #fff; } .btn.main:hover { background: var(--brand-2); }
.btn.ghost { background: var(--soft); color: var(--brand-2); }
.btn.pro { background: #fff7e6; color: #92400e; border: 1px solid #fcd9a0; }
.meta { display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: var(--muted); margin-top: 10px; }
.badge { background: var(--accent); color: #fff; border-radius: 6px; padding: 1px 8px; font-size: 13px; font-weight: 700; }
.pro-only { position: relative; }
.pro-only.locked input { background: #f7f5f0; cursor: pointer; }
.pro-only.locked .lbl::after { content: " 🔒 Pro"; color: #92400e; font-weight: 600; }
details.more { border-top: 1px dashed var(--line); padding-top: 10px; margin-top: 6px; }
details.more summary { cursor: pointer; font-size: 15px; font-weight: 600; color: var(--brand-2); margin-bottom: 8px; }

/* ตัวอย่าง A4 */
.preview { min-width: 0; overflow: hidden; }
.pages { transform-origin: top left; width: 210mm; }
.sheet { font-family: var(--wsfont, "Sarabun"), sans-serif; width: 210mm; height: 297mm; background: #fff; color: #111; margin: 0 0 14px; padding: 14mm 14mm 12mm; box-shadow: 0 2px 12px rgba(0,0,0,.12); position: relative; overflow: hidden; display: flex; flex-direction: column; font-size: 16pt; line-height: 1.5; }
.ws-head { border-bottom: 2px solid #111; padding-bottom: 3mm; margin-bottom: 5mm; }
.ws-school { font-size: 12pt; color: #333; text-align: center; margin-bottom: 1mm; }
.ws-title { font-size: 22pt; font-weight: 700; text-align: center; line-height: 1.3; }
.ws-sub { text-align: center; font-size: 13pt; color: #444; }
.ws-name { display: flex; gap: 2mm; align-items: baseline; font-size: 14pt; margin: 2mm 0 1mm; }
.ws-name i { flex: 1; border-bottom: 1px dotted #555; height: 1em; } .ws-name i.s { flex: 0 0 22mm; }
.ws-instr { font-size: 14pt; } .ws-instr b { margin-right: 2mm; }
.ws-body { flex: 1; }
.ws-tip { font-size: 12pt; color: #333; background: #f3f7f6; border-radius: 3mm; padding: 2mm 4mm; margin-top: 3mm; }
.ws-foot { position: absolute; left: 0; right: 0; bottom: 5mm; text-align: center; font-size: 10pt; color: #8a8a8a; font-family: "IBM Plex Sans Thai", sans-serif; }
.ws-table { width: 100%; border-collapse: collapse; font-size: 16pt; }
.ws-table th { background: #eef4f3; font-size: 13pt; font-weight: 700; padding: 1.5mm 2mm; border: 1px solid #333; }
.ws-table td { border: 1px solid #333; padding: 0 2.5mm; height: 13mm; vertical-align: middle; }
.ws-table td:first-child { width: 34%; white-space: nowrap; }
.ws-table.grid td { text-align: center; } .ws-table.grid td:first-child { text-align: left; width: 22%; }
.ws-table.chaek td { font-size: 13pt; height: 13mm; } .ws-table.chaek td:first-child { font-size: 16pt; }
.ws-table .no { display: inline-block; min-width: 9mm; color: #555; font-size: 13pt; }
.ws-table .w { font-weight: 600; }
.ans { color: #b91c1c; font-weight: 600; }
.na { color: #888; }
.cells { display: grid; gap: 2.5mm 8mm; } .cells.two { grid-template-columns: 1fr 1fr; }
.cell { display: flex; align-items: center; gap: 2mm; border-bottom: 1px dotted #aaa; padding: 2.5mm 0; font-size: 17pt; }
.cell .no { min-width: 9mm; color: #555; font-size: 13pt; }
.cell .w { flex: 1; font-weight: 600; }
.picks { display: flex; gap: 3mm; }
.pick { border: 1px solid #999; border-radius: 99px; padding: 0 3mm; font-size: 12pt; }
.pick.on { border: 2px solid #b91c1c; color: #b91c1c; font-weight: 700; }
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 40mm; margin-top: 4mm; }
.mt { display: flex; align-items: center; gap: 3mm; height: 17mm; font-size: 18pt; }
.mt.R { flex-direction: row-reverse; justify-content: flex-end; }
.mt.R .no { order: 2; } .mt .no { color: #555; font-size: 14pt; min-width: 8mm; }
.mt .dot { width: 3mm; height: 3mm; border-radius: 50%; background: #111; margin-left: auto; }
.mt.R .dot { margin: 0 2mm 0 0; }
.trace { font-family: var(--wsfont, "Sarabun"), sans-serif; font-size: 12.5px; display: block; width: 100%; height: auto; margin-bottom: 1mm; }
.trace .g { stroke: #888; stroke-width: .25; } .trace .g2 { stroke: #bbb; stroke-width: .2; stroke-dasharray: 1 1.2; }
.trace .solid { fill: #111; } .trace .dotted { fill: none; stroke: #777; stroke-width: .28; stroke-dasharray: .8 .7; }
.warn { color: var(--warn); }

/* Pro modal */
dialog { border: 0; border-radius: 18px; padding: 0; max-width: 460px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,30,30,.45); }
.modal { padding: 20px; }
.modal h3 { margin: 0 0 6px; font-size: 21px; }
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.plan { border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.plan b { display: block; font-size: 24px; color: var(--brand-2); } .plan span { font-size: 14px; color: var(--muted); }
.plan.best { border-color: var(--accent); background: #fffaf0; }
.modal ul { margin: 6px 0 12px; padding-left: 20px; font-size: 15px; }
.modal form { display: flex; gap: 8px; margin-top: 8px; } .modal form input { flex: 1; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; text-transform: uppercase; }
.reason { color: var(--warn); font-weight: 600; font-size: 15px; }
.x { float: right; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; }

/* เนื้อหา SEO */
.content { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 26px; }
.content h2 { font-size: 22px; margin: 6px 0 8px; } .content h3 { font-size: 18px; margin: 16px 0 4px; }
.content p, .content li { font-size: 16px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; } .links a { background: var(--soft); border-radius: 10px; padding: 6px 12px; text-decoration: none; font-size: 15px; }
footer { color: var(--muted); font-size: 14px; padding: 18px 0 30px; text-align: center; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .panel { position: static; }
}

@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  body > *:not(main), main > *:not(.app), .app > .panel, .content, footer, dialog { display: none !important; }
  main, .app, .preview { display: block !important; margin: 0 !important; padding: 0 !important; max-width: none !important; }
  .wrap { padding: 0 !important; }
  .pages { transform: none !important; margin: 0 !important; width: auto; }
  .sheet { box-shadow: none; margin: 0; page-break-after: always; break-after: page; }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
}

.modal .how { font-size: 15px; margin: 0 0 6px; }
