:root {
  --bg: #f4f2ee; --card: #fff; --ink: #1d1b18; --ink2: #6b665e; --line: #e2ded6; --accent: #c8102e; --accent-soft: #fbe9ec; --off: #b9b3a8;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* display:grid/flex 를 준 칸도 hidden 이면 숨긴다 */
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
.primary { background: var(--ink); color: #fff; border: 0; border-radius: 8px; padding: 9px 18px; font-weight: 700; }
.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; }
.sub { color: var(--ink2); font-size: 13px; }

/* 머리 + 단계 */
.top { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; padding: 12px 28px; background: var(--ink); color: #fff; }
.brand, .steps button { white-space: nowrap; }
.brand b { font-size: 20px; letter-spacing: -.3px; }
.brand span { margin-left: 8px; color: #d8d2c6; font-size: 13px; }
.steps { display: flex; gap: 6px; margin-left: auto; }
.steps button { display: flex; align-items: center; gap: 6px; background: transparent; color: #a39d92; border: 0; padding: 6px 12px; border-radius: 20px; }
.steps button i { font-style: normal; width: 20px; height: 20px; border-radius: 50%; border: 1px solid currentColor; display: grid; place-items: center; font-size: 11px; }
.steps button.on { background: #fff; color: var(--ink); font-weight: 700; }
.steps button.done { color: #fff; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 28px 110px; }
.head { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 18px; margin-bottom: 18px; }
.head h1 { font-size: 22px; margin: 0; }
.head .right { margin-left: auto; display: flex; gap: 8px; }
/* 왼쪽 교재 사이드바 — 머리 띠 바로 아래에 붙어 따로 굴러간다(--top-h = 머리 띠 높이, app.js setTopH). 좁은 화면·인쇄에서는 숨김 */
.shell { display: flex; align-items: flex-start; }
.shell > main { flex: 1; min-width: 0; }
.side { flex: none; width: 236px; position: sticky; top: var(--top-h, 56px); height: calc(100vh - var(--top-h, 56px)); display: flex; flex-direction: column; background: var(--card); border-right: 1px solid var(--line); }
.side-tabs { display: flex; flex-wrap: wrap; gap: 5px; padding: 12px 10px 10px; border-bottom: 1px solid var(--line); }
.side-tabs button { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 3px 10px; font-size: 12.5px; white-space: nowrap; }
.side-tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.side-tabs button.none { opacity: .45; }
.side-list { position: relative; flex: 1; min-height: 0; overflow-y: auto; padding: 6px 6px 80px; }   /* 아래 80px = 아래 띠에 가리지 않게 */
.sb { display: flex; align-items: center; gap: 9px; width: 100%; border: 0; background: none; border-radius: 8px; padding: 5px 6px; text-align: left; }
.sb:hover { background: #faf8f4; }
.sb.on { background: var(--accent-soft); }
.sb.zero { opacity: .45; }
.sb-cv { flex: none; width: 36px; height: 48px; border-radius: 3px; overflow: hidden; background: #ddd; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.sb-cv img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sb-cv.tb { display: grid; place-items: center; background: #2f5d3a; color: #fff; font-size: 9px; }
.sb-t { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.sb-t b { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.sb-t small { font-size: 11.5px; color: var(--ink2); }
.sb-g { padding: 10px 8px 3px; font-size: 11.5px; font-weight: 700; color: var(--ink2); }
.sb-none { padding: 30px 10px; text-align: center; color: var(--ink2); font-size: 12.5px; }
@media (max-width: 900px) { .side { display: none; } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 4px 12px; font-size: 13px; }
.chips button.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* 갈래 단추(머리 띠) */
.modes { display: flex; gap: 4px; background: #2f2b26; border-radius: 20px; padding: 3px; }
.modes button { white-space: nowrap; border: 0; background: transparent; color: #d8d2c6; border-radius: 16px; padding: 5px 14px; font-weight: 600; }
.modes button.on { background: var(--accent); color: #fff; }
.modes button:disabled { opacity: .5; }
.modes small { font-size: 10.5px; font-weight: 400; margin-left: 3px; }
/* 워크북 조각(잉프로-S 조각 + api/wb.css) — 글꼴은 잉프로-S 워크북처럼 고딕 */
.wbx .page { font-family: Pretendard, "Malgun Gothic", -apple-system, sans-serif; }
.wbi { break-inside: avoid; padding-bottom: 2mm; }
.wbt { column-span: all; }   /* 워크북 쪽 제목 — 단어정리 2단에서도 두 단에 걸쳐 위에 */
.wbx .cols.pdf-body { overflow: visible; }

.logout { white-space: nowrap; background: transparent; color: #d8d2c6; border: 1px solid #5a554d; border-radius: 16px; padding: 4px 12px; font-size: 12.5px; }

/* 로그인 */
.login-back { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px 26px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.08); }
.login > b { font-size: 24px; letter-spacing: -.3px; }
.login p { margin: 8px 0 6px; color: var(--ink2); font-size: 13px; line-height: 1.6; }
.login input { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: inherit; }
.login .err { min-height: 18px; color: var(--accent); font-size: 12.5px; }

/* 1. 교재 */
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 22px; }
.book { background: transparent; border: 0; padding: 0; text-align: left; }
.book .cv { aspect-ratio: 3 / 4; border-radius: 6px; overflow: hidden; background: #ddd; box-shadow: 0 2px 6px rgba(0,0,0,.12); transition: transform .12s, box-shadow .12s; }
.book .cv img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book:hover .cv { transform: translateY(-3px); box-shadow: 0 8px 18px rgba(0,0,0,.18); }
.book .t { margin-top: 8px; font-weight: 700; }
.book .n { color: var(--ink2); font-size: 12.5px; }
.book.zero { opacity: .45; }
/* 교과서 표(목차에서 바로) */
#books.tb { display: block; }
.tb-sec { margin-bottom: 26px; }
.tb-sec h2 { font-size: 18px; margin: 4px 0 10px; }
.tb-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.tb-grid { display: grid; gap: 0 14px; min-width: min-content; }
.tb-col { display: flex; flex-direction: column; border-right: 1px solid #eee9e0; padding-right: 14px; }
.tb-col:last-child { border-right: 0; padding-right: 0; }
.tb-h { background: #f4f2ee; text-align: center; font-weight: 700; padding: 7px 4px; border-bottom: 1px solid var(--line); line-height: 1.35; }
.tb-h span { display: block; font-weight: 400; font-size: 11.5px; color: var(--ink2); }
.tb-h.zero { color: var(--off); }
.tb-c { display: flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-bottom: 1px solid #eee9e0; background: none; padding: 8px 4px; font-size: 13.5px; white-space: nowrap; }
.tb-c span { font-size: 11.5px; color: #fff; background: var(--accent); border-radius: 9px; padding: 0 6px; line-height: 17px; }
.tb-c:not([disabled]):hover { background: var(--accent-soft); }
.tb-c.zero { color: var(--off); }
.tb-cv { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 18px; background: #2f5d3a; color: #fff; }
.tb-cv small { font-size: 14px; opacity: .85; }
.tb-cv b { font-size: 34px; letter-spacing: -1px; }
.tb-cv span { font-size: 14px; opacity: .85; }

.empty { padding: 60px 0; text-align: center; color: var(--ink2); }
.admin-btn { position: fixed; right: 24px; bottom: 22px; z-index: 15; }

/* 2. 지문 */
.book-head img { width: 54px; height: 72px; object-fit: cover; border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.toc { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 0; }
.node > .row { display: flex; align-items: center; gap: 8px; padding: 7px 16px; }
.node > .row:hover { background: #faf8f4; }
.node .tg { width: 18px; border: 0; background: none; color: var(--ink2); padding: 0; }
.node .nm { font-weight: 600; }
.node .cnt, .slot .cnt { color: var(--ink2); font-size: 12px; }
.node .kids { padding-left: 22px; }
.node.zero > .row { color: var(--off); }
/* 번호칸 = 같은 너비 표(묶음마다 --sw = 가장 긴 칸 폭, app.js slotW). 줄은 1fr 로 고르게 채워 줄마다 같은 자리 */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--sw, 110px), 1fr)); gap: 6px; padding: 4px 16px 10px 42px; }
.slot { display: flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; background: #fff; font-size: 13px; cursor: pointer; user-select: none; min-width: 0; white-space: nowrap; }
.slot .cnt { margin-left: auto; }
.slot.on { border-color: var(--accent); background: var(--accent-soft); }
.slot.zero { color: var(--off); background: #f7f5f1; cursor: default; }
.slot input { margin: 0; }

/* 3. 유형 */
.types { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 18px; align-items: start; }
.tab { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tab > .th { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: #2b2824; color: #fff; font-weight: 700; }
.tab > .th .cnt { margin-left: auto; font-weight: 400; color: #d8d2c6; }
.grp { padding: 6px 14px 2px; color: var(--ink2); font-size: 12px; }
.ty > .row { display: flex; align-items: center; gap: 8px; padding: 6px 14px; }
.ty .nm { font-weight: 600; }
.ty .cnt { margin-left: auto; color: var(--ink2); font-size: 12.5px; }
.ty .tg { border: 0; background: none; color: var(--ink2); padding: 0 2px; }
.ty .labels { padding: 0 14px 6px 40px; }
.ty .labels label { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 13px; }
.ty .labels .cnt { margin-left: auto; }

/* 아래 띠 */
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 18; display: flex; align-items: center; justify-content: center; gap: 18px; padding: 12px; background: rgba(255,255,255,.96); border-top: 1px solid var(--line); }
.bar span { font-weight: 700; }

/* 표지 관리 */
.modal-back { position: fixed; inset: 0; z-index: 40; background: rgba(20,18,15,.45); display: grid; place-items: center; padding: 30px; }
.modal { width: min(1000px, 100%); height: min(720px, 100%); background: #fff; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head .x { margin-left: auto; border: 0; background: none; font-size: 16px; }
.modal-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 340px; }
.admin-tree { overflow: auto; border-right: 1px solid var(--line); padding: 8px 0; }
.admin-tree .an > .row { display: flex; align-items: center; gap: 6px; padding: 4px 12px; cursor: pointer; }
.admin-tree .an > .row:hover { background: #faf8f4; }
.admin-tree .an > .row.on { background: var(--accent-soft); }
.admin-tree .an .kids { padding-left: 18px; }
.admin-tree .an .has { color: var(--accent); font-size: 11px; }
.admin-form { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.admin-form .label { font-size: 12px; color: var(--ink2); margin-top: 6px; }
.admin-form input[type=text], .admin-form input:not([type]) { border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font: inherit; }
.admin-form .picked { font-weight: 600; }
.admin-form #adminPreview { width: 120px; border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.admin-form .primary { margin-top: 10px; }
/* 개발자 설정 탭 */
.modal-head .tabs { display: flex; gap: 4px; margin-left: 12px; }
.modal-head .tabs button { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 4px 12px; font-size: 13px; }
.modal-head .tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.modal-pane { flex: 1; min-height: 0; overflow: auto; }
.ex-bar { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 12px; padding: 10px 18px; background: #fff; border-bottom: 1px solid var(--line); }
.ex-bar .ex-n { margin-left: auto; font-weight: 700; color: var(--accent); white-space: nowrap; }
.ex-bar button { flex: none; white-space: nowrap; }
.ex-tree { padding: 6px 0 20px; }
.ex-tree .en > .row { display: flex; align-items: center; gap: 6px; padding: 3px 14px; }
.ex-tree .en > .row:hover { background: #faf8f4; }
.ex-tree .en .kids { padding-left: 20px; }
.ex-tree .en .tg { width: 18px; border: 0; background: none; color: var(--ink2); padding: 0; }
.ex-tree .en .cnt { color: var(--ink2); font-size: 12px; }
.ex-tree .out > .row .nm, .ex-tree .slot.out { text-decoration: line-through; color: var(--accent); }
.ex-tree .under > .row, .ex-tree .slot.under { opacity: .45; }
.ex-tree .slots { padding: 2px 14px 6px 46px; }
.help { padding: 6px 22px 24px; font-size: 13.5px; line-height: 1.65; }
.help section { border-bottom: 1px solid #f0ede7; padding: 10px 0 12px; }
.help h3 { margin: 6px 0 6px; font-size: 15px; }
.help p, .help ul { margin: 6px 0; }
.help pre { margin: 6px 0; padding: 8px 10px; background: #2b2824; color: #f4f2ee; border-radius: 6px; font: 12.5px/1.5 Consolas, monospace; white-space: pre-wrap; word-break: break-all; }
.help code { background: #f4f2ee; padding: 1px 4px; border-radius: 4px; font-size: 12.5px; }
.chips button.none { opacity: .45; }
.chips button .k { margin-left: 4px; font-size: 11.5px; opacity: .8; }

.cover-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid #f0ede7; font-size: 13px; }
.cover-row img { width: 30px; height: 40px; object-fit: cover; border-radius: 3px; }
.cover-row button { margin-left: auto; border: 0; background: none; color: var(--accent); }

/* 4. 출력 — 종이 */
.opt { display: flex; align-items: center; gap: 5px; }
/* 시험지 = A4 쪽 상자 + 2단(글자 9.5pt, 사용자 2026-11-12). 화면과 인쇄가 같은 mm 크기를 쓴다 — app.js 가 이 상자에 재며 채운다 */
.paper-wrap { overflow: auto; }
.paper { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.page { width: 210mm; height: 297mm; padding: 12mm 13mm 9mm; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12); overflow: hidden; display: flex; flex-direction: column;
  font-family: "Times New Roman", "Malgun Gothic", serif; font-size: 9.5pt; line-height: 1.5; color: #000; }
.pg-head { display: flex; align-items: baseline; border-bottom: 1.5pt solid #000; padding-bottom: 2mm; margin-bottom: 4mm; font-family: "Malgun Gothic", sans-serif; }
.pg-head b { font-size: 14pt; }
.pg-head.small b { font-size: 9pt; }
.pg-head small { margin-left: auto; font-size: 8pt; color: #555; }
.cols { flex: 1; min-height: 0; column-count: 2; column-gap: 7mm; column-rule: 0.6pt solid #000; column-fill: auto; }
.pg-foot { position: relative; text-align: center; font: 8pt "Malgun Gothic", sans-serif; color: #555; padding-top: 2mm; }
.pg-foot .pf { position: absolute; left: 0; max-width: 40%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }   /* 꼬릿말 = 왼쪽, 쪽 번호 = 가운데 */
.arr.hf input { width: 220px; }
.q, .ai { break-inside: avoid; }
.q { padding-bottom: 5mm; }
.q .src { font: 7pt "Malgun Gothic", sans-serif; color: #777; text-align: right; }
.q .st { font-family: "Malgun Gothic", sans-serif; font-weight: 700; margin-bottom: 1.5mm; line-height: 1.4; }
.q .ps { margin: 1.5mm 0; text-align: justify; }
.q .box { border: 0.6pt solid #000; padding: 1.8mm 2.4mm; margin: 2mm 0; }
.q .ch { margin: 1.5mm 0 0; line-height: 1.4; }
.q .ch div { padding-left: 1.3em; text-indent: -1.3em; }
.q .subq { margin: 3mm 0 0; }
.ans-head { column-span: all; font: 700 12pt "Malgun Gothic", sans-serif; border-bottom: 1.5pt solid #000; padding-bottom: 1.5mm; margin-bottom: 3mm; }
.ai { padding: 0 0 3mm; font-size: 8.5pt; line-height: 1.45; }
.ai .an { font-family: "Malgun Gothic", sans-serif; font-weight: 700; }
.ai .an span { margin-left: 2mm; }
.ai .ex { margin-top: .8mm; text-align: justify; }
/* 세트 머리(문제지 안) */
.set-head { column-span: all; font: 700 11pt "Malgun Gothic", sans-serif; padding-bottom: 1.5mm; margin-bottom: 3mm; border-bottom: 0.8pt solid #000; }

/* 출력 위 — 배열·세트 줄, 담은 묶음 */
.arr { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin: -6px 0 12px; }
.arr label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.arr select, .arr input { font: inherit; font-weight: 400; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: #fff; }
.arr input[type=number] { width: 72px; }
.arr .set-n.off { opacity: .45; }
.basket { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; margin-bottom: 18px; }
.bk-head { display: flex; align-items: center; gap: 10px; padding: 4px 0 8px; border-bottom: 1px solid #f0ede7; }
.bk-head .ghost { margin-left: auto; }
.bk-item { display: flex; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid #f0ede7; }
.bk-item:last-child { border-bottom: 0; }
.bk-no { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 12px; }
.bk-t { min-width: 0; }
.bk-t .sub { overflow-wrap: anywhere; }
.bk-n { margin-left: auto; white-space: nowrap; font-weight: 700; }
.bk-x { flex: none; border: 0; background: none; color: var(--accent); }

/* 미리보기 2단(사용자 2026-11-14) — 왼쪽: 배열·머릿말·담은 문제(따라 내려옴) / 오른쪽: 문서. 사이드바까지 3단. 좁으면 위아래로 */
main:has(#s4:not([hidden])) { max-width: 1260px; }
.out { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 24px; align-items: start; }
/* 붙는 자리 = 머리 띠 + main 위 여백(24px) → 처음 자리와 같아 굴려도 조금도 움직이지 않는다 */
.out-opt { position: sticky; top: calc(var(--top-h, 56px) + 24px); max-height: calc(100vh - var(--top-h, 56px) - 40px); overflow-y: auto; }
.out-opt .head { gap: 8px 14px; margin-bottom: 14px; }
.out-opt .head .right { margin-left: 0; width: 100%; }
.out-opt .head .right button { flex: 1; }
.out-opt .arr { margin: 0 0 12px; }
.out-opt .arr.hf label { width: 100%; }
.out-opt .arr.hf input { flex: 1; min-width: 0; width: auto; }
.out-opt .basket { margin-bottom: 0; }
.out-opt .bk-head { flex-wrap: wrap; }
@media (max-width: 1250px) {
  .out { grid-template-columns: minmax(0, 1fr); }
  .out-opt { position: static; max-height: none; overflow: visible; }
  .out-opt .basket { margin-bottom: 18px; }
}

@media print {
  .out { display: block; }
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .top, .bar, .no-print, .admin-btn { display: none !important; }
  main { padding: 0; max-width: none; }
  .shell { display: block; }
  .paper { display: block; }
  .page { box-shadow: none; break-after: page; }
}
