@font-face {
  font-family: Pretendard;
  src: url('/fonts/PretendardVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
:root {
  --ground: #e9ecef;
  --paper: #ffffff;
  --ink: #1c1f26;
  --muted: #5d6470;
  --line: #c9ced6;
  --red: #be1e37;
  --red-band: #fdf0f1;
  --blue: #23509f;
  --blue-band: #eff3fb;
  --ok: #17694a;
  --warn: #9a5b00;
  --print: var(--red);
  --band: var(--red-band);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: 15px/1.5 Pretendard, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #f0a800; outline-offset: 1px; }
input, select, textarea {
  width: 100%; min-height: 42px; padding: 8px 10px; background: #fff;
  border: 1px solid var(--line); border-radius: 4px;
}
textarea { resize: vertical; font-size: 14px; }
.btn {
  min-height: 42px; padding: 0 16px; border: 1px solid var(--ink); border-radius: 4px;
  background: #fff; font-weight: 600; cursor: pointer; touch-action: manipulation; white-space: nowrap;
}
.btn:hover { background: #f1f3f5; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: #363b47; }
.btn.quiet { border-color: var(--line); font-weight: 500; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.danger.armed { background: var(--red); color: #fff; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; }

/* 로그인 */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-sheet { width: min(380px, 100%); background: var(--paper); padding: 32px 28px; border-top: 6px solid var(--red); display: grid; gap: 14px; }
.login-year { color: var(--red); font-weight: 600; font-size: 14px; }
.login-sheet h1 { font-size: 26px; margin-bottom: 8px; letter-spacing: -.01em; }
.login-sheet label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
.form-error { color: var(--red); font-size: 14px; font-weight: 500; }
.form-error:empty { display: none; }

/* 상단 */
.top { position: sticky; top: 0; z-index: 20; background: var(--paper); border-bottom: 1px solid var(--line); padding: 10px 20px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
.top-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { font-size: 19px; font-weight: 800; letter-spacing: -.02em; }
.top-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 13px; font-weight: 600; color: var(--ok); display: inline-flex; align-items: center; gap: 6px; }
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.off { color: var(--warn); }
.controls { display: grid; grid-template-columns: 1fr 1.5fr auto 1.1fr auto; gap: 10px; margin-top: 10px; align-items: end; }
.controls label { display: grid; gap: 2px; font-size: 13px; font-weight: 600; color: var(--muted); }
.controls input, .controls select { color: var(--ink); font-size: 15px; font-weight: 500; }
.print-1 { color: var(--red) !important; }
.print-2 { color: var(--blue) !important; }
.view-switch { border: 0; padding: 0; margin: 0; }
.view-switch legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 2px; }
.view-switch { display: flex; }
.view-switch label { display: block; }
.view-switch input { position: absolute; opacity: 0; width: 1px; min-height: 0; }
.view-switch span { display: grid; place-items: center; height: 42px; padding: 0 12px; border: 1px solid var(--line); margin-left: -1px; color: var(--ink); cursor: pointer; font-weight: 500; font-size: 14px; }
.view-switch input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.view-switch input:focus-visible + span { outline: 3px solid #f0a800; }

.page { max-width: 1320px; margin: 0 auto; padding: 16px 20px 80px; }
.progress { margin: 14px 2px 10px; color: var(--muted); font-size: 14px; }
.progress b { color: var(--ink); }

/* 질문 안내 */
.guide { background: var(--paper); border: 1px solid var(--line); }
.guide summary { padding: 11px 16px; font-weight: 700; cursor: pointer; }
.guide-body { padding: 4px 18px 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 8px 32px; }
.guide-body h3 { font-size: 15px; margin: 14px 0 6px; }
.guide-body ol { margin: 0; padding-left: 22px; }
.guide-body li { margin-bottom: 5px; max-width: 62ch; }
.rubric { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.rubric th { width: 42px; vertical-align: top; text-align: center; font-size: 15px; padding: 5px 0; }
.rubric td { padding: 5px 0 5px 6px; border-bottom: 1px solid #eceef1; }

/* 카드: OMR 답안지 */
.cards { display: grid; gap: 16px; }
.card { background: var(--paper); display: grid; grid-template-columns: 1fr 1fr 244px; grid-template-areas: 'head head head' 's1 s2 side'; }
.card-head { grid-area: head; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 2px solid var(--ink); }
.exam { font-size: 22px; font-weight: 800; letter-spacing: .02em; }
.who { font-size: 18px; font-weight: 700; }
.school { color: var(--muted); font-size: 14px; }
.dept-tag { color: var(--muted); font-size: 14px; }
.head-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.status { font-size: 13px; font-weight: 700; padding: 3px 9px; border: 1.5px solid currentColor; color: var(--muted); }
.status.done { color: var(--ok); }
.status.partial { color: var(--warn); }

.sheet { padding: 10px 14px 14px; background: linear-gradient(var(--band), var(--band)) top / 100% 40px no-repeat; border-right: 1px solid var(--line); min-width: 0; }
.sheet[data-no='1'] { grid-area: s1; --print: var(--red); --band: var(--red-band); }
.sheet[data-no='2'] { grid-area: s2; --print: var(--blue); --band: var(--blue-band); }
.sheet-title { display: flex; justify-content: space-between; align-items: baseline; color: var(--print); font-weight: 700; height: 30px; gap: 8px; }
.sheet-title .ev-name { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group { display: flex; justify-content: space-between; color: var(--print); font-size: 13px; font-weight: 700; margin-top: 8px; padding-bottom: 3px; border-bottom: 1.5px solid var(--print); }
.score-row { display: grid; grid-template-columns: minmax(70px, 1fr) repeat(4, 50px); align-items: center; gap: 2px; padding: 3px 0; border-bottom: 1px solid color-mix(in srgb, var(--print) 22%, white); }
.score-row .lbl { font-size: 13.5px; line-height: 1.25; padding-right: 4px; }
.bub {
  height: 38px; width: 46px; justify-self: center; background: #fff; color: var(--print);
  border: 1.5px solid var(--print); border-radius: 50%;
  font-weight: 700; font-size: 15px; cursor: pointer; padding: 0; touch-action: manipulation;
  transition: background-color .08s, color .08s;
}
.bub[aria-checked='true'] { background: var(--ink); border-color: var(--ink); color: #fff; }
.sheet-sum { display: flex; justify-content: flex-end; gap: 16px; margin-top: 8px; font-size: 14px; color: var(--muted); }
.sheet-sum b { color: var(--ink); font-size: 16px; }

.side { grid-area: side; padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 12px; }
.evidence { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.evidence label { font-size: 13px; font-weight: 600; color: var(--muted); display: grid; gap: 2px; }
.evidence input { color: var(--ink); font-size: 17px; font-weight: 700; text-align: center; }
.calc { font-size: 13px; color: var(--muted); grid-column: 1 / -1; }
.calc.cap { color: var(--warn); font-weight: 600; }
.tally { display: grid; grid-template-columns: 1fr auto; row-gap: 3px; font-size: 14px; }
.tally dt { color: var(--muted); }
.tally dd { margin: 0; font-weight: 700; text-align: right; }
.final { border-top: 2px solid var(--ink); padding-top: 6px; display: flex; justify-content: space-between; align-items: baseline; }
.final span { font-weight: 700; }
.final strong { font-size: 34px; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
.card-foot { margin-top: auto; display: grid; gap: 6px; }
.save-note { font-size: 13px; color: var(--muted); min-height: 19px; }
.save-note.dirty { color: var(--red); font-weight: 600; }
.save-note.wait { color: var(--warn); font-weight: 600; }
.conflict { font-size: 13px; color: var(--warn); font-weight: 600; display: grid; gap: 4px; }
.save-row { display: flex; gap: 8px; }
.save-row .primary { flex: 1; }
body[data-view='1'] .sheet[data-no='2'], body[data-view='2'] .sheet[data-no='1'] { display: none; }
body[data-view='1'] .card, body[data-view='2'] .card { grid-template-columns: 1fr 244px; grid-template-areas: 'head head' 's1 side'; }
body[data-view='2'] .sheet[data-no='2'] { grid-area: s1; }

.empty { background: var(--paper); padding: 44px 20px; text-align: center; display: grid; gap: 14px; justify-items: center; }

/* 대화상자 */
.dlg { width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); border: 0; padding: 22px; border-top: 6px solid var(--ink); color: var(--ink); }
.dlg::backdrop { background: rgb(28 31 38 / .5); }
.dlg h2 { font-size: 20px; margin-bottom: 12px; }
.dlg h3 { font-size: 15px; margin-bottom: 6px; }
.dlg-sec { margin-bottom: 18px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.field-grid label, label.block { display: grid; gap: 3px; font-size: 14px; font-weight: 600; }
.field-grid .wide { grid-column: 1 / -1; }
.field-grid input, .field-grid select, label.block textarea { font-weight: 400; }
.tabs { display: flex; margin-bottom: 12px; border-bottom: 1.5px solid var(--ink); }
.tab { border: 0; background: none; padding: 8px 14px; cursor: pointer; font-weight: 500; color: var(--muted); min-height: 40px; }
.tab.on { background: var(--ink); color: #fff; font-weight: 700; }
.hint { color: var(--muted); font-size: 13.5px; margin: 4px 0 10px; }
.dlg-foot { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.spacer { flex: 1; }
.device-list { list-style: none; margin: 0; padding: 0; }
.device-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid #eceef1; flex-wrap: wrap; }
.device-list .d-name { font-weight: 600; }
.device-list .d-when { color: var(--muted); font-size: 13px; flex-basis: 100%; }
.device-list .d-btns { margin-left: auto; display: flex; gap: 6px; }
.install-steps { margin: 6px 0 0; padding-left: 20px; }
.panel-sec { margin: 18px 0 0; }
.panel-tag { color: var(--muted); font-size: 14px; }
.card-edit { border: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 13px; padding: 8px 2px; }

.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; font-weight: 500; z-index: 60; display: flex; gap: 14px; align-items: center; width: max-content; max-width: calc(100vw - 32px); }
.toast button { background: none; border: 1px solid #fff; color: #fff; padding: 4px 10px; cursor: pointer; font-weight: 600; }

@media (max-width: 1080px) {
  .controls { grid-template-columns: 1fr 1fr 1fr; }
  .card, body[data-view='1'] .card, body[data-view='2'] .card { grid-template-columns: 1fr 1fr; grid-template-areas: 'head head' 's1 s2' 'side side'; }
  body[data-view='1'] .card, body[data-view='2'] .card { grid-template-columns: 1fr; grid-template-areas: 'head' 's1' 'side'; }
  .sheet[data-no='2'] { border-right: 0; }
  .sheet { border-bottom: 1px solid var(--line); }
  .side { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; }
  .card-foot { grid-column: 1 / -1; }
  .final { grid-column: 2; }
  .tally { grid-column: 2; }
  .evidence { grid-row: 1 / span 2; align-self: start; }
}
@media (max-width: 760px) {
  .card { grid-template-columns: 1fr; grid-template-areas: 'head' 's1' 's2' 'side'; }
  .sheet { border-right: 0; }
  .top { position: static; padding-left: 16px; padding-right: 16px; }
  .page { padding: 12px 16px 80px; }
  .controls { grid-template-columns: 1fr; }
  .head-right { margin-left: 0; width: 100%; justify-content: space-between; }
  .view-switch label { flex: 1; }
  .top-actions { margin-left: 0; width: 100%; }
  .top-actions .btn { flex: 1; padding: 0 8px; }
  .side { grid-template-columns: 1fr; }
  .final, .tally, .evidence { grid-column: auto; grid-row: auto; }
  .score-row { grid-template-columns: minmax(60px, 1fr) repeat(4, 48px); }
  .bub { width: 44px; }
  .field-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
