:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #6b7385;
  --line: #e3e6ee;
  --primary: #3b5bdb;
  --primary-soft: #edf1ff;
  --good: #2f9e44;
  --good-soft: #ebfbee;
  --bad: #e03131;
  --bad-soft: #fff0f0;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --card: #1d2029;
    --text: #e8eaf0;
    --muted: #9aa1b2;
    --line: #2d313d;
    --primary: #7c94ff;
    --primary-soft: #252c48;
    --good: #51cf66;
    --good-soft: #1c2e22;
    --bad: #ff6b6b;
    --bad-soft: #3a2024;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans KR', system-ui, sans-serif;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); white-space: nowrap; }
/* 왼쪽 위 뒤로·앞으로·새로고침 (앱처럼 설치하면 브라우저 버튼이 없어서) */
.brand-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hist-btns { display: flex; gap: 2px; flex: none; }
.hist { width: 34px; height: 34px; padding: 0; font-size: 18px; line-height: 1; border-radius: 8px; }
.hist:hover { background: var(--primary-soft); }
@media (max-width: 420px) { .brand { font-size: 14px; } .hist { width: 30px; height: 30px; font-size: 16px; } }
#nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
#nav a, #nav button { font-size: 14px; }
main { max-width: 820px; margin: 0 auto; padding: 24px 16px 80px; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 15px; font-weight: 500;
  padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  cursor: pointer;
}
button:hover, .btn:hover { border-color: var(--primary); }
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover { filter: brightness(1.08); }
.danger { color: var(--bad); }
.ghost { border-color: transparent; background: transparent; }
.small { padding: 4px 10px; font-size: 13px; }

input[type=text], input[type=password], textarea, select {
  width: 100%;
  font: inherit; font-size: 15px;
  padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label.field { display: block; font-size: 14px; font-weight: 500; margin-bottom: 4px; }

.auth { max-width: 380px; margin: 40px auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tabs button { flex: 1; }
.tabs button.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.set-item { display: block; color: inherit; }
.set-item:hover { border-color: var(--primary); }
.badge {
  display: inline-block; font-size: 12px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary);
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.q-num { font-weight: 700; color: var(--primary); margin-right: 6px; }
.q-prompt { white-space: pre-wrap; font-size: 16px; margin-bottom: 12px; }
.choice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; margin-top: 6px;
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.choice:hover { border-color: var(--primary); }
.choice input { margin-top: 5px; }
.choice.selected { border-color: var(--primary); background: var(--primary-soft); }
.choice.is-answer { border-color: var(--good); background: var(--good-soft); }
.choice.is-wrong { border-color: var(--bad); background: var(--bad-soft); }

.result-card.good { border-left: 4px solid var(--good); }
.result-card.bad { border-left: 4px solid var(--bad); }
.explain {
  margin-top: 10px; padding: 10px 12px;
  background: var(--bg); border-radius: 8px;
  font-size: 14px; white-space: pre-wrap;
}
.score-big { font-size: 44px; font-weight: 700; color: var(--primary); line-height: 1.1; }

.editor-q { position: relative; }
.editor-q .choice-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.editor-q .choice-row input[type=text] { flex: 1; }

.progress { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 8px 0 18px; }
.progress > div { height: 100%; background: var(--primary); transition: width .2s; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 15px; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.rank { font-weight: 700; width: 48px; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 8px; font-size: 14px;
  max-width: calc(100% - 32px);
}

.sticky-submit {
  position: sticky; bottom: 0;
  padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%);
}

/* ---- 추가: 연습·시험·사진·서술형 ---- */
#nav a.on { background: var(--primary-soft); color: var(--primary); }
.user-name { margin-left: 6px; }
.small-text { font-size: 12px; }
.field-label { font-size: 13px; font-weight: 500; color: var(--muted); min-width: 64px; }
.c-good { color: var(--good); }
.c-bad { color: var(--bad); }
input[type=number] {
  font: inherit; font-size: 15px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text);
}
button:disabled { opacity: .45; cursor: not-allowed; }

.outcome-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 14px; }
.outcome {
  display: block; text-align: left; padding: 14px 16px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); font-weight: 400;
}
a.set-oc { color: var(--text); }
a.set-oc:hover { border-color: var(--primary); }
.outcome.on { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; background: var(--primary-soft); }
.oc-code { font-size: 20px; color: var(--primary); }
.oc-title { font-weight: 500; margin-top: 2px; }
.oc-lectures { font-size: 13px; margin: 6px 0 2px; min-height: 20px; }
.outcome .progress { margin: 8px 0 4px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px;
}
.chip input { display: none; }
.chip.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 500; }

.exam { max-width: 1100px; margin: 0 auto; }
main:has(.exam) { max-width: 1100px; }
.exam-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.exam-title { font-size: 20px; font-weight: 700; }
.timer { font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 700; color: var(--muted); }
.exam-body { display: grid; grid-template-columns: 1fr 240px; gap: 14px; align-items: start; }
.exam-q { min-height: 360px; }
.q-meta { margin-bottom: 10px; }
.q-badge { font-weight: 700; color: var(--primary); }
.omr { position: sticky; top: 76px; }
.omr-title { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.omr-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; max-height: 50vh; overflow-y: auto; }
.omr-cell {
  padding: 4px 0; flex-direction: column; gap: 0; font-size: 12px; line-height: 1.3; border-radius: 6px;
}
.omr-cell b { font-size: 14px; min-height: 18px; color: var(--primary); }
.omr-cell.done { background: var(--primary-soft); }
.omr-cell.cur { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.omr-cell.flag span::after { content: '★'; color: #f59f00; margin-left: 2px; }
/* 바로 확인한 문제: 맞음 초록, 틀림 빨강 */
.omr-cell.ok { background: rgba(64, 192, 87, .22); }
.omr-cell.ok b { color: #40c057; }
.omr-cell.ng { background: rgba(250, 82, 82, .22); }
.omr-cell.ng b { color: #fa5252; }
.checked-review { margin-top: 14px; }
.checked-review .result-card { margin: 0; }

.figure { margin: 0 0 12px; }
.figure-canvas {
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff;
  min-height: 80px; display: flex; align-items: center; justify-content: center;
}
.figure-canvas canvas { width: 100%; height: auto; display: block; }
.figure figcaption { font-size: 12px; margin-top: 4px; }
/* QBL 쪽: 쪽 전체가 보이도록 (가로·세로 모두 화면 안에) */
.qbl-fig .figure-canvas { display: block; }
.qbl-fig .figure-canvas canvas { width: 100%; height: auto; max-height: 85vh; object-fit: contain; }
.qbl-fig .row { gap: 6px; flex-wrap: wrap; }
.qbl-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.85); padding: 2vh 2vw; overflow: auto; cursor: zoom-out; }
.qbl-overlay .figure-canvas { max-width: 96vw; margin: 0 auto; background: #fff; display: block; }
.qbl-overlay canvas { width: 100%; height: auto; display: block; }

.result-card.pending { border-left: 4px solid #f59f00; }
.essay-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.essay-box { white-space: pre-wrap; padding: 10px 12px; background: var(--bg); border-radius: 8px; font-size: 14px; min-height: 60px; }
.kp { display: flex; gap: 8px; align-items: center; font-size: 14px; padding: 3px 0; }
.group-head { font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.me-row { background: var(--primary-soft); }

/* ---- 기출: HTML 지문, 보기별 해설, 미디어 ---- */
.q-prompt.rich { white-space: normal; }
.rich p { margin: 0 0 6px; }
.rich p:last-child { margin-bottom: 0; }
.rich ul, .rich ol { margin: 4px 0; padding-left: 20px; }
.rich img, .q-media { display: block; max-width: 100%; max-height: 420px; width: auto; height: auto; object-fit: contain; margin: 8px auto; border-radius: 6px; background: #fff; cursor: zoom-in; }
.rich img.zoomed { max-height: none; cursor: zoom-out; }
.tabs button { white-space: nowrap; }
.rich table { border-collapse: collapse; margin: 6px 0; }
.rich td, .rich th { border: 1px solid var(--line); padding: 4px 8px; font-size: 14px; }
video.q-media, audio.q-media { width: 100%; background: transparent; }
.choice-no { flex: none; }
.choice-text { flex: 1; min-width: 0; }
.choice-text p { margin: 0; }
.choice.review { display: block; cursor: default; }
.choice-tag { flex: none; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; }
.choice-tag.good { background: var(--good); color: #fff; }
.choice-tag.bad { background: var(--bad); color: #fff; }
.choice-exp { margin: 6px 0 0 26px; font-size: 13.5px; color: var(--muted); }
.choice.is-answer .choice-exp, .choice.is-wrong .choice-exp { color: var(--text); }
.explain.rich { white-space: normal; }
.explain.rich b:first-child { display: block; margin-bottom: 4px; }
.ai-note { border-left: 3px solid var(--primary); }
.period-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.period {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); color: var(--text);
}
.period:hover { border-color: var(--primary); }
details.subject { border-bottom: 1px solid var(--line); padding: 8px 0; }
details.subject summary { cursor: pointer; list-style: none; }
details.subject summary::-webkit-details-marker { display: none; }
.jokbo-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 4px; border-top: 1px solid var(--line); color: var(--text); }
.jokbo-row:hover { background: var(--primary-soft); }
.jokbo-title { min-width: 0; }
.invite-link { word-break: break-all; }
code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 13px; }

/* ---- 휴대폰·아이패드 ---- */
html { -webkit-text-size-adjust: 100%; }
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.topbar { padding-top: max(12px, env(safe-area-inset-top)); }
main { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
.toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
.menu-btn { display: none; font-size: 22px; padding: 2px 12px; line-height: 1; }
button, .btn, .choice, .chip, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
@media (pointer: coarse) {
  /* 손가락으로 누르기 쉽게, 아이폰이 입력칸에서 확대하지 않도록 16px */
  input[type=text], input[type=password], input[type=number], textarea, select { font-size: 16px; }
  .choice { padding: 13px 14px; }
  .choice:hover, button:hover, .btn:hover { border-color: var(--line); }
  .primary:hover { border-color: var(--primary); }
  .omr-cell { padding: 7px 0; }
}
@media (max-width: 1000px) {
  .menu-btn { display: inline-flex; }
  .topbar { flex-wrap: wrap; }
  #nav {
    display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 2px;
    padding: 6px 0 4px; border-top: 1px solid var(--line); margin-top: 4px;
    max-height: calc(100vh - 70px); overflow-y: auto;
  }
  body.menu-open #nav { display: flex; }
  #nav a, #nav button { justify-content: flex-start; font-size: 16px; padding: 11px 12px; }
  #nav .user-name { display: block !important; margin: 4px 0 0; }
  .card table, .rich table { display: block; overflow-x: auto; }
}
@media (max-width: 820px) {
  .exam-body { grid-template-columns: 1fr; }
  .omr { position: static; }
  .omr-grid { grid-template-columns: repeat(8, 1fr); max-height: none; }
  .essay-cols { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .omr-grid { grid-template-columns: repeat(5, 1fr); }
  .topbar { padding: max(10px, env(safe-area-inset-top)) 16px 10px; }
  .exam-head { flex-wrap: wrap; }
  .exam-title { font-size: 17px; }
  .score-big { font-size: 36px; }
  .outcome-grid { grid-template-columns: 1fr; }
  .brand { font-size: 16px; }
  main { padding: 16px 16px 60px; }
  .card { padding: 14px 16px; }
}
