:root {
  --teal: #1db6c9;
  --teal-dark: #128a99;
  --teal-soft: #e6f7f9;
  --orange: #ffa800;
  --orange-soft: #fff4dc;
  --ink: #1f2a33;
  --ink-2: #4b5a66;
  --ink-3: #8696a3;
  --line: #dde5ea;
  --bg: #f4f7f9;
  --card: #ffffff;
  --danger: #e2453c;
  --danger-soft: #fdecea;
  --ok: #1e9e5a;
  --ok-soft: #e5f6ec;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 40, 60, .08), 0 4px 16px rgba(20, 40, 60, .05);
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.6; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--teal-dark); }
.hidden { display: none !important; }

/* 공통 컴포넌트 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 9px 16px; cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--teal); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.accent { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 14px; }
.btn.lg { padding: 13px 24px; font-size: 17px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fff;
}
.input:focus { outline: 2px solid var(--teal); outline-offset: -1px; border-color: var(--teal); }
.err { color: var(--danger); font-size: 14px; min-height: 1.4em; }
.muted { color: var(--ink-3); }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: var(--teal-soft); color: var(--teal-dark);
}
.badge.orange { background: var(--orange-soft); color: #b37400; }
.badge.gray { background: #eef1f3; color: var(--ink-2); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.notice-box { white-space: pre-wrap; word-break: keep-all; background: var(--teal-soft); border-radius: 10px; padding: 16px 18px; }

.modal-back {
  position: fixed; inset: 0; background: rgba(15, 25, 35, .45); display: flex;
  align-items: center; justify-content: center; padding: 16px; z-index: 100;
}
.modal { background: #fff; border-radius: 14px; max-width: 440px; width: 100%; padding: 26px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal h3 { margin: 0 0 10px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 8px; z-index: 200; font-size: 15px; max-width: calc(100% - 32px);
}

/* ───────── 응시자 화면 ───────── */
.center-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 420px; }
.login-card .logo { display: block; width: 220px; max-width: 70%; margin: 0 auto 10px; }
.login-card h1 { text-align: center; font-size: 20px; margin: 4px 0 4px; }
.login-card .sub { text-align: center; color: var(--ink-3); margin: 0 0 22px; font-size: 14px; }

.exam-header {
  position: sticky; top: 0; z-index: 50; background: #fff; border-bottom: 1px solid var(--line);
}
.exam-header .inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 14px; }
.exam-header img { height: 34px; }
.exam-header .title { flex: 1; min-width: 0; }
.exam-header .title b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exam-header .title small { color: var(--ink-3); font-size: 13px; }
.timer {
  font-variant-numeric: tabular-nums; font-size: 24px; font-weight: 800; color: var(--teal-dark);
  background: var(--teal-soft); padding: 4px 14px; border-radius: 10px; letter-spacing: .5px;
}
.timer.warn { color: #b37400; background: var(--orange-soft); }
.timer.danger { color: var(--danger); background: var(--danger-soft); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.progressbar { height: 4px; background: var(--line); }
.progressbar > div { height: 100%; background: var(--orange); transition: width .3s; }

.exam-body { max-width: 1100px; margin: 0 auto; padding: 20px 16px 120px; display: grid; grid-template-columns: 1fr 230px; gap: 20px; align-items: start; }
.side { position: sticky; top: 84px; }
.side .card { padding: 16px; }
.qnav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 10px 0 14px; }
.qnav button {
  border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 0; font-size: 13px; cursor: pointer; font-weight: 600;
}
.qnav button.done { background: var(--teal); border-color: var(--teal); color: #fff; }
.save-state { font-size: 13px; color: var(--ink-3); margin-top: 10px; text-align: center; }
.save-state.bad { color: var(--danger); font-weight: 600; }

.section-title { font-size: 18px; margin: 26px 0 12px; padding-left: 10px; border-left: 4px solid var(--orange); }
.section-title:first-child { margin-top: 0; }
.q { margin-bottom: 16px; scroll-margin-top: 90px; }
.q .q-head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 12px; }
.q .q-no { font-weight: 800; color: var(--teal-dark); font-size: 18px; flex: none; }
.q .q-text { white-space: pre-wrap; word-break: keep-all; font-weight: 600; flex: 1; }
.q .q-meta { flex: none; font-size: 12px; color: var(--ink-3); }
.opts { display: grid; gap: 8px; }
.opt {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border: 1.5px solid var(--line);
  border-radius: 10px; cursor: pointer; transition: border-color .12s, background .12s; word-break: keep-all;
}
.opt:hover { border-color: var(--teal); }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt .mark {
  flex: none; width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--ink-3);
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; color: var(--ink-2);
}
.opt.multi .mark { border-radius: 6px; }
.opt.sel { border-color: var(--teal); background: var(--teal-soft); }
.opt.sel .mark { background: var(--teal); border-color: var(--teal); color: #fff; }
.opt input:focus-visible + .mark { outline: 2px solid var(--orange); outline-offset: 2px; }
.hint { font-size: 13px; color: #b37400; margin: -4px 0 10px; font-weight: 600; }
textarea.essay { width: 100%; min-height: 200px; resize: vertical; border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 14px; line-height: 1.7; }
textarea.essay:focus { outline: none; border-color: var(--teal); }
.charcount { text-align: right; font-size: 12px; color: var(--ink-3); margin-top: 4px; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); z-index: 40;
}
.bottom-bar .inner { max-width: 1100px; margin: 0 auto; padding: 12px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; }

.status-page { max-width: 640px; margin: 0 auto; padding: 40px 16px; }
.status-page .icon { width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; font-size: 30px; }
.status-page h2 { text-align: center; margin: 0 0 6px; }
.status-page p.lead { text-align: center; color: var(--ink-2); margin: 0 0 22px; }
.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0 0 18px; }
.info-grid dt { color: var(--ink-3); }
.info-grid dd { margin: 0; font-weight: 600; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--teal-soft); border-top-color: var(--teal); border-radius: 50%; animation: spin 1s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .exam-body { grid-template-columns: 1fr; }
  .side { position: static; order: -1; }
  .side .qnav { grid-template-columns: repeat(10, 1fr); }
  .exam-header img { height: 26px; }
  .timer { font-size: 19px; padding: 3px 10px; }
  .card { padding: 18px; }
}
@media (max-width: 480px) {
  .side .qnav { grid-template-columns: repeat(5, 1fr); }
  .exam-header .title small { display: none; }
}

/* ───────── 관리자 화면 ───────── */
.admin-top { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; }
.admin-top .inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 18px; height: 60px; }
.admin-top img { height: 32px; }
.admin-top nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.admin-top nav button {
  border: 0; background: none; padding: 18px 14px; cursor: pointer; font-weight: 600; color: var(--ink-2);
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.admin-top nav button.on { color: var(--teal-dark); border-bottom-color: var(--teal); }
.admin-main { max-width: 1280px; margin: 0 auto; padding: 22px 16px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 21px; flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 860px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

table.tbl { width: 100%; border-collapse: collapse; background: #fff; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { background: #f7fafb; color: var(--ink-2); font-weight: 700; position: sticky; top: 0; }
.tbl tr:hover td { background: #fafcfd; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; max-height: 70vh; }

.exam-list { display: grid; gap: 12px; }
.exam-item { display: flex; gap: 16px; align-items: center; cursor: pointer; }
.exam-item:hover { outline: 2px solid var(--teal-soft); }
.exam-item .t { flex: 1; min-width: 0; }
.exam-item .t b { font-size: 17px; }

.stat { background: #fff; border-radius: 10px; padding: 14px 16px; border: 1px solid var(--line); }
.stat .k { font-size: 13px; color: var(--ink-3); }
.stat .v { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }

.control-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 16px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.control-bar .big-timer { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--teal-dark); min-width: 140px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #c5d0d7; margin-right: 6px; }
.dot.on { background: var(--ok); }

.qedit { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 10px; background: #fff; }
.qedit .qe-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.qedit .qe-no { font-weight: 800; color: var(--teal-dark); min-width: 34px; }
.qedit .opt-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.qedit .opt-row label { display: flex; align-items: center; gap: 4px; font-size: 13px; white-space: nowrap; color: var(--ink-2); }
.qedit .opt-row .input { padding: 7px 10px; }
.qedit.warn { border-color: var(--orange); }

.grade-q { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; background: #fff; }
.grade-q .resp { white-space: pre-wrap; background: #f7fafb; border-radius: 8px; padding: 12px; margin: 8px 0; min-height: 40px; word-break: keep-all; }
.grade-q.right { border-left: 4px solid var(--ok); }
.grade-q.wrong { border-left: 4px solid var(--danger); }
.grade-q.essay { border-left: 4px solid var(--orange); }
.model { font-size: 14px; background: var(--orange-soft); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; }

@media print {
  .admin-top, .no-print, .bottom-bar { display: none !important; }
  body { background: #fff; }
  .card, .grade-q { box-shadow: none; break-inside: avoid; }
}
