:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1f2420;
  --muted: #6b716b;
  --line: #e3e0d8;
  --green: #2f7d4a;
  --green-soft: #e6f2ea;
  --red: #c8402c;
  --red-soft: #fbe9e5;
  --amber: #b7791f;
  --amber-soft: #fdf3dc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 40, 30, 0.06), 0 6px 20px rgba(30, 40, 30, 0.05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.3; text-wrap: balance; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; } h4 { font-size: .95rem; }
p { margin: 0 0 .8em; }
a { color: var(--green); }
code { background: #f0eee8; padding: .1em .35em; border-radius: 5px; font-size: .9em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .warn { color: var(--amber); } .pre { white-space: pre-wrap; }
.center { text-align: center; } .grow { flex: 1; }
.boot { padding: 3rem; text-align: center; color: var(--muted); }

/* 구조 */
.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; }
.brand small { color: var(--muted); font-weight: 500; }
.who { font-size: .9rem; color: var(--muted); white-space: nowrap; }
.page { max-width: 760px; margin: 0 auto; padding: 1rem 1rem 5rem; }
.page.wide { max-width: 1080px; }
.page > h2 { margin-top: 1.5rem; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: min(380px, 100%); display: grid; gap: .8rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.row { display: flex; gap: .5rem; align-items: center; } .row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: .8rem; } .row.top { align-items: flex-start; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.grid2 > .card { margin-bottom: 0; } section.grid2 { margin-bottom: 1rem; }
.backlink { display: inline-block; margin-bottom: .8rem; text-decoration: none; }
.eyebrow { font-size: .8rem; font-weight: 600; color: var(--green); margin-bottom: .2em; }

/* 입력 */
label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: .4rem; } .check input { width: auto; }
.btn { font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }
.btn:hover { border-color: #c9c5ba; } .btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); border-color: #ecc4bc; } .btn.danger:not(.small):not(:disabled) { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; } .btn.small { padding: .3rem .65rem; font-size: .85rem; } .btn.block { width: 100%; padding: .75rem; }
.link { font: inherit; background: none; border: 0; color: var(--green); cursor: pointer; padding: 0 .2rem; text-decoration: underline; }
.tag { font-style: normal; font-size: .75rem; padding: .1rem .45rem; border-radius: 99px; background: #eeece5; color: var(--muted); white-space: nowrap; }
.tag.new, .tag.live { background: var(--green-soft); color: var(--green); } .tag.changed { background: var(--amber-soft); color: var(--amber); } .tag.removed { background: var(--red-soft); color: var(--red); }
.notice { background: var(--amber-soft); border-radius: 10px; padding: .7rem .9rem; margin: .6rem 0; font-size: .92rem; }
.notice textarea { margin: .5rem 0; font-size: .9rem; }
.code { font-size: 1rem; letter-spacing: .08em; font-weight: 700; }

/* 표 */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.nowrap td, table.nowrap th, td.nw { white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: #faf9f5; }
td.actions { white-space: nowrap; text-align: right; } td.actions .btn { margin-left: .25rem; }
td .memo { min-width: 120px; padding: .3rem .5rem; font-size: .85rem; }
.tabs { display: flex; gap: .25rem; padding: .5rem 1rem 0; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { font: inherit; font-weight: 600; padding: .6rem 1rem; border: 0; background: none; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--green); border-color: var(--green); }
.log { background: #1f2420; color: #d9e6dc; border-radius: 10px; padding: .7rem .9rem; font-size: .85rem; white-space: pre-wrap; margin-bottom: .8rem; }

/* 학생 처음 화면 */
.subjects { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.subject { font: inherit; text-align: left; display: grid; gap: .15rem; padding: 1rem; border-radius: var(--radius); border: 2px solid var(--line); background: var(--card); cursor: pointer; color: var(--ink); }
.subject b { font-size: 1.1rem; } .subject span { color: var(--muted); font-size: .85rem; } .subject em { font-style: normal; font-size: .8rem; color: var(--green); }
.subject.empty em { color: var(--muted); } .subject.on { border-color: var(--green); background: var(--green-soft); }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: .4rem; margin-bottom: 1rem; }
.level { font: inherit; font-weight: 700; padding: .6rem .2rem; border-radius: 10px; border: 2px solid var(--line); background: #fff; cursor: pointer; display: grid; color: var(--ink); }
.level small { font-weight: 400; color: var(--muted); font-size: .7rem; } .level.on { border-color: var(--green); background: var(--green-soft); } .level:disabled { opacity: .45; cursor: default; }
.list { display: grid; gap: .5rem; }
.item { font: inherit; text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; color: var(--ink); text-decoration: none; }
.item:hover { border-color: var(--green); } .item .right { text-align: right; white-space: nowrap; color: var(--green); font-weight: 600; }
.custom { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .3rem .6rem; border: 1px solid var(--line); border-radius: 99px; color: var(--ink); font-size: .85rem; cursor: pointer; }
.chip input { width: auto; } .chip small { color: var(--red); }

/* 시험 */
.examtop { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto auto; gap: .6rem; align-items: center; padding: .5rem .8rem; }
.exam-title { display: grid; min-width: 0; } .exam-title > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer { font: 700 1.35rem/1 ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; padding: .35rem .6rem; border-radius: 8px; background: var(--green-soft); color: var(--green); }
.timer.warn { background: var(--amber-soft); color: var(--amber); } .timer.danger { background: var(--red); color: #fff; }
.page.exam { padding-bottom: 9rem; }
.qnav { display: flex; align-items: baseline; gap: .6rem; margin-bottom: .5rem; } .qnav b { font-size: 1.2rem; }
.question { padding: .6rem; }
.crop { position: relative; overflow: hidden; width: 100%; background: #fff; border-radius: 8px; }
.crop img { position: absolute; max-width: none; height: auto; user-select: none; -webkit-user-drag: none; }
.qtext { white-space: pre-wrap; padding: .4rem; }
.hint { font-size: .85rem; color: var(--amber); padding: 0 .4rem; }
.choices { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; margin: .8rem 0; }
.choices.text { grid-template-columns: 1fr; }
.choice { font: inherit; display: flex; align-items: center; justify-content: center; gap: .6rem; padding: .7rem .5rem; min-height: 52px; border-radius: 12px; border: 2px solid var(--line); background: #fff; cursor: pointer; color: var(--ink); text-align: left; }
.choices.text .choice { justify-content: flex-start; padding: .7rem .9rem; }
.choice .num { font-size: 1.4rem; line-height: 1; } .choice.on { border-color: var(--green); background: var(--green); color: #fff; }
.palette { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--card); border-top: 1px solid var(--line); padding: .5rem .6rem calc(.5rem + env(safe-area-inset-bottom)); display: flex; gap: .3rem; overflow-x: auto; }
.palette button { font: inherit; font-size: .85rem; font-weight: 600; flex: 0 0 auto; width: 2.2rem; height: 2.2rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--muted); }
.palette button.done { background: var(--green-soft); border-color: #b9dcc5; color: var(--green); } .palette button.cur { outline: 2px solid var(--ink); }
.omr { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .3rem 1.5rem; }
.omr-row { display: flex; align-items: center; gap: .35rem; padding: .15rem 0; }
.omr-n { font: inherit; font-weight: 700; width: 2.4rem; background: none; border: 0; color: var(--ink); cursor: pointer; text-align: right; padding-right: .4rem; }
.bubble { font: inherit; font-size: .85rem; width: 2.3rem; height: 2.3rem; border-radius: 50%; border: 1.5px solid #b9b5aa; background: #fff; cursor: pointer; color: var(--muted); }
.bubble.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.fullpage { width: 100%; height: auto; border: 1px solid var(--line); }

/* 결과 */
.result-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.score { text-align: right; display: grid; } .score strong { font-size: 2.6rem; line-height: 1; color: var(--green); }
.score span { color: var(--muted); font-size: .85rem; } .score em { font-style: normal; font-weight: 700; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 40%) 1fr auto; gap: .6rem; align-items: center; font-size: .88rem; padding: .25rem 0; }
.bar { height: 8px; background: #eeece5; border-radius: 99px; overflow: hidden; } .bar i { display: block; height: 100%; border-radius: 99px; }
.bar i.low { background: var(--red); } .bar i.mid { background: #d9a13a; } .bar i.high { background: var(--green); }
.bar-val { font-variant-numeric: tabular-nums; color: var(--muted); }
.qcard { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: 12px; margin-bottom: .6rem; }
.qcard.ng { border-left-color: var(--red); }
.qcard summary { cursor: pointer; padding: .7rem .9rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; }
.qcard .mark { font-weight: 700; color: var(--green); } .qcard.ng .mark { color: var(--red); } .qcard .ans { margin-left: auto; font-size: .88rem; }
.qbody { padding: 0 .9rem .9rem; }
.choice-list { list-style: none; padding: 0; margin: .6rem 0; display: grid; gap: .2rem; }
.choice-list li { padding: .25rem .5rem; border-radius: 6px; }
.choice-list .right { background: var(--green-soft); font-weight: 600; } .choice-list .wrong { background: var(--red-soft); text-decoration: line-through; }
.explain { background: #faf9f5; border-radius: 10px; padding: .7rem .9rem; font-size: .93rem; }
.md h2, .md h3, .md h4, .md h5 { margin-top: 1.1em; } .md ul, .md ol { padding-left: 1.3rem; margin: 0 0 .8em; } .md li { margin: .15em 0; } .md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }

/* 문항 검수 */
.keytable { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .95rem; }
.qedit.off { opacity: .55; } .qedit label { margin-top: .5rem; }
.boxedit { position: relative; touch-action: none; cursor: crosshair; user-select: none; border: 1px solid var(--line); }
.boxedit img { display: block; width: 100%; height: auto; pointer-events: none; }
.boxedit .sel { position: absolute; border: 2px solid var(--red); background: rgba(200, 64, 44, .12); pointer-events: none; }
.share-row { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .5rem 0; border-bottom: 1px solid var(--line); word-break: break-all; }

/* 모달, 알림 */
.modal-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(20, 24, 20, .5); display: grid; place-items: center; padding: 1rem; overflow-y: auto; }
.modal { background: var(--card); border-radius: var(--radius); padding: 1.2rem; width: min(480px, 100%); max-height: calc(100dvh - 2rem); overflow-y: auto; display: grid; gap: .6rem; }
.modal.wide { width: min(900px, 100%); }
#toast { position: fixed; left: 50%; bottom: 5rem; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: .65rem 1.1rem; border-radius: 99px; font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 30; max-width: calc(100vw - 2rem); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); } #toast.error { background: var(--red); }

/* 인쇄 (PDF 저장) */
#print-root { display: none; }
@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; }
  .top, .tabs, .examtop, .palette, #toast, .backlink, .btn, .modal-wrap { display: none !important; }
  .card { box-shadow: none; break-inside: avoid; }
  .page { max-width: none; padding: 0; }
  details.qcard { break-inside: avoid; }
  #print-root:not(:empty) { display: block; }
  #print-root:not(:empty) ~ *, body:has(#print-root:not(:empty)) #app { display: none !important; }
  .print-page { display: block; width: 100%; max-height: 277mm; object-fit: contain; break-after: page; }
  .print-head { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 2mm; margin-bottom: 4mm; }
  .print-cols { columns: 2; column-gap: 8mm; column-rule: 1px solid #999; }
  .print-q { break-inside: avoid; margin-bottom: 6mm; font-size: 10pt; }
  .print-q .crop { margin-top: 1mm; }
}
@media (max-width: 560px) {
  .examtop { grid-template-columns: 1fr auto; } .examtop .row { grid-column: 1 / -1; justify-content: flex-end; }
  td.actions { white-space: normal; } td.actions .btn { margin: .15rem 0 .15rem .25rem; }
}
