/* ============ 색상 토큰 ============ */
:root {
  --font-scale: 1;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #dde3ea;
  --text: #1c2430;
  --text-2: #5a6676;
  --brand: #1e4f91;
  --brand-ink: #ffffff;
  --blue: #2563eb;
  --blue-bg: #e8f0ff;
  --green: #15803d;
  --green-bg: #e7f6ec;
  --red: #c62828;
  --red-bg: #fdecec;
  --amber: #b45309;
  --amber-bg: #fff4e0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --surface: #1a2029; --surface-2: #222a35; --border: #2f3a48;
    --text: #e6ebf1; --text-2: #9aa7b6; --brand: #5b8fd6; --brand-ink: #0d1117;
    --blue: #6aa0ff; --blue-bg: #1c2b47; --green: #4ccb7a; --green-bg: #153222;
    --red: #ff7a7a; --red-bg: #3a1c1f; --amber: #f2b45a; --amber-bg: #3a2c14;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --surface: #1a2029; --surface-2: #222a35; --border: #2f3a48;
  --text: #e6ebf1; --text-2: #9aa7b6; --brand: #5b8fd6; --brand-ink: #0d1117;
  --blue: #6aa0ff; --blue-bg: #1c2b47; --green: #4ccb7a; --green-bg: #153222;
  --red: #ff7a7a; --red-bg: #3a1c1f; --amber: #f2b45a; --amber-bg: #3a2c14;
  --shadow: none; color-scheme: dark;
}

/* ============ 기본 ============ */
* { box-sizing: border-box; }
html { font-size: calc(16px * var(--font-scale)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  line-height: 1.6; min-height: 100vh; display: flex; flex-direction: column;
  word-break: keep-all; overflow-wrap: anywhere;
}
a { color: var(--blue); }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; flex: 1; outline: none; }
.loading, .muted { color: var(--text-2); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
u { text-decoration-thickness: 2px; text-underline-offset: 3px; font-weight: 700; }

/* ============ 상단바 ============ */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 700; }
.brand-mark { background: var(--brand); color: var(--brand-ink); border-radius: 6px; padding: 2px 6px; font-size: .8rem; letter-spacing: .5px; }
.topnav { display: flex; gap: 4px; margin-left: auto; }
.topnav a { text-decoration: none; color: var(--text-2); padding: 6px 10px; border-radius: 8px; font-weight: 600; }
.topnav a.active, .topnav a:hover { color: var(--text); background: var(--surface-2); }
.topbar-tools { display: flex; gap: 4px; }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 8px; height: 34px; min-width: 34px; padding: 0 6px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn sup { font-size: .7em; }
@media (max-width: 640px) {
  .brand-text { display: none; }
  .topbar-inner { gap: 8px; }
  .topnav a { padding: 6px 8px; font-size: .95rem; }
}

.footer { text-align: center; color: var(--text-2); font-size: .8rem; padding: 16px; border-top: 1px solid var(--border); }

/* ============ 공통 요소 ============ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 10px 18px; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
  min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.08); background: var(--brand); }
.btn-danger { color: var(--red); border-color: var(--red); }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: .9rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--text-2); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 1.5rem; margin: 0; }
.notice { background: var(--amber-bg); color: var(--amber); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: .92rem; }
.empty { text-align: center; padding: 40px 16px; color: var(--text-2); }

/* ============ 메인 ============ */
.hero { margin-bottom: 20px; }
.hero h1 { font-size: 1.6rem; }
.hero p { color: var(--text-2); margin: 0; }
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.subject-card { display: flex; flex-direction: column; gap: 12px; }
.subject-card h2 { font-size: 1.2rem; margin: 0; }
.subject-card .tag { font-size: .8rem; color: var(--text-2); }
.subject-card.mock { border-color: var(--brand); border-width: 2px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 1.2rem; }
.stat span { font-size: .78rem; color: var(--text-2); }
.subject-card .btn { margin-top: auto; }
.exam-info { margin-top: 20px; }
.exam-info table { width: 100%; border-collapse: collapse; }
.exam-info th, .exam-info td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; }

/* ============ 설정 ============ */
.setup { max-width: 720px; margin: 0 auto; }
.setup h1 { font-size: 1.4rem; }
.field { margin: 18px 0; }
.field > label, .field > .label { display: block; font-weight: 700; margin-bottom: 8px; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-opt { position: relative; }
.mode-opt input { position: absolute; opacity: 0; }
.mode-opt label { display: block; border: 2px solid var(--border); border-radius: 12px; padding: 14px; cursor: pointer; height: 100%; }
.mode-opt label b { display: block; font-size: 1.05rem; }
.mode-opt label span { font-size: .88rem; color: var(--text-2); }
.mode-opt input:checked + label { border-color: var(--blue); background: var(--blue-bg); }
.mode-opt input:focus-visible + label { outline: 2px solid var(--blue); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--blue); }
.num-input { width: 110px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.chapter-list { display: grid; gap: 2px; max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; }
@media (max-width: 520px) { .mode-grid { grid-template-columns: 1fr; } }

/* ============ 풀이 화면 ============ */
.quiz-head { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.quiz-head-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.quiz-title { font-weight: 700; font-size: 1.05rem; }
.quiz-count { font-variant-numeric: tabular-nums; color: var(--text-2); font-weight: 600; }
.timer { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.15rem; padding: 2px 12px; border-radius: 8px; background: var(--surface-2); }
.timer.warn { background: var(--red-bg); color: var(--red); }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: var(--blue); transition: width .2s; }

.quiz-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.question-card { padding: 24px; }
.q-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.q-text { font-size: 1.2rem; font-weight: 600; margin-bottom: 20px; white-space: pre-line; }
.q-num { color: var(--brand); font-weight: 800; margin-right: 6px; }
.choices { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left;
  background: var(--surface); border: 2px solid var(--border); border-radius: 12px;
  padding: 14px 16px; cursor: pointer; font-size: 1.08rem; line-height: 1.55; min-height: 54px;
}
.choice:hover:not(:disabled) { border-color: var(--blue); }
.choice:disabled { cursor: default; }
.choice .mark { flex: 0 0 auto; font-weight: 800; width: 1.6em; color: var(--text-2); }
.choice.selected { border-color: var(--blue); background: var(--blue-bg); }
.choice.selected .mark { color: var(--blue); }
.choice.correct { border-color: var(--green); background: var(--green-bg); }
.choice.correct .mark { color: var(--green); }
.choice.wrong { border-color: var(--red); background: var(--red-bg); }
.choice.wrong .mark { color: var(--red); }
.choice .tail { margin-left: auto; font-weight: 800; font-size: .9rem; white-space: nowrap; }
.feedback { margin-top: 18px; border-radius: 12px; padding: 14px 16px; border: 1px solid var(--border); background: var(--surface-2); }
.feedback.ok { border-color: var(--green); }
.feedback.no { border-color: var(--red); }
.feedback h3 { font-size: 1.05rem; margin-bottom: 6px; }
.feedback.ok h3 { color: var(--green); }
.feedback.no h3 { color: var(--red); }
.feedback p { margin: 4px 0; }
.ref { font-size: .9rem; color: var(--text-2); }
.ref b { color: var(--text); }
.q-nav { display: flex; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.q-nav .spacer { flex: 1; }
.flag-btn.on { background: var(--amber-bg); border-color: var(--amber); color: var(--amber); }
.kbd-hint { font-size: .8rem; color: var(--text-2); margin-top: 12px; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: .78rem; background: var(--surface-2); }

/* OMR 답안표 */
.omr { position: sticky; top: 76px; padding: 14px; }
.omr h3 { font-size: 1rem; display: flex; justify-content: space-between; align-items: center; }
.omr-sum { font-size: .82rem; color: var(--text-2); margin-bottom: 8px; }
.omr-group { font-size: .78rem; color: var(--text-2); margin: 10px 0 4px; font-weight: 700; }
.omr-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
.omr-cell {
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 6px; cursor: pointer; background: var(--surface); font-size: .88rem; font-variant-numeric: tabular-nums; min-height: 30px;
}
.omr-cell .n { font-weight: 700; width: 2em; color: var(--text-2); }
.omr-cell .a { font-weight: 800; }
.omr-cell.empty-ans { background: var(--surface-2); }
.omr-cell.empty-ans .a { color: var(--text-2); font-weight: 400; }
.omr-cell.answered .a { color: var(--blue); }
.omr-cell.current { outline: 2px solid var(--blue); outline-offset: -1px; }
.omr-cell.flag::after { content: "★"; margin-left: auto; color: var(--amber); font-size: .8rem; }
.omr-cell.ok { background: var(--green-bg); border-color: var(--green); }
.omr-cell.ok .a { color: var(--green); }
.omr-cell.ng { background: var(--red-bg); border-color: var(--red); }
.omr-cell.ng .a { color: var(--red); }
.omr .btn { width: 100%; margin-top: 12px; }
.omr-toggle { display: none; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; font-size: .75rem; color: var(--text-2); margin-top: 8px; }

@media (max-width: 900px) {
  .quiz-layout { grid-template-columns: 1fr; }
  .omr { position: static; }
  .omr-toggle { display: inline-flex; }
  .omr.collapsed .omr-body { display: none; }
  .omr-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
  .question-card { padding: 18px 16px; }
  .q-text { font-size: 1.1rem; }
  .choice { font-size: 1rem; padding: 12px 14px; }
}

/* ============ 결과 ============ */
.result-top { display: grid; grid-template-columns: 260px 1fr; gap: 16px; margin-bottom: 16px; }
.score-box { text-align: center; display: flex; flex-direction: column; justify-content: center; }
.score-box .big { font-size: 3.2rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score-box .big small { font-size: 1.2rem; color: var(--text-2); }
.verdict { display: inline-block; margin: 10px auto 0; padding: 6px 18px; border-radius: 999px; font-weight: 800; font-size: 1.1rem; }
.verdict.pass { background: var(--green-bg); color: var(--green); }
.verdict.fail { background: var(--red-bg); color: var(--red); }
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.tbl th { font-size: .85rem; color: var(--text-2); font-weight: 600; }
.tbl td.num, .tbl th.num { text-align: right; }
.fail-txt { color: var(--red); font-weight: 700; }
.pass-txt { color: var(--green); font-weight: 700; }
.result-list { display: grid; gap: 12px; margin-top: 16px; }
.r-item { border-left: 5px solid var(--border); }
.r-item.ok { border-left-color: var(--green); }
.r-item.ng { border-left-color: var(--red); }
.r-item .r-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.ox { font-weight: 900; font-size: 1.3rem; width: 1.4em; text-align: center; }
.ox.o { color: var(--green); }
.ox.x { color: var(--red); }
.r-choices { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 4px; }
.r-choices li { padding: 6px 10px; border-radius: 8px; display: flex; gap: 8px; }
.r-choices li.correct { background: var(--green-bg); color: var(--green); font-weight: 600; }
.r-choices li.wrong { background: var(--red-bg); color: var(--red); }
.r-choices li .tail { margin-left: auto; font-size: .8rem; font-weight: 800; white-space: nowrap; }
.explain { background: var(--surface-2); border-radius: 10px; padding: 10px 14px; margin-top: 8px; }
.explain p { margin: 4px 0; }
.filter-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 16px 0 4px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 600; font-size: .9rem; }
.chip.active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
@media (max-width: 720px) {
  .result-top { grid-template-columns: 1fr; }
}

/* ============ 오답노트 / 기록 ============ */
.note-item { display: grid; gap: 6px; }
.note-item .q-text { font-size: 1.02rem; margin: 0; }
.note-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.chart-wrap { width: 100%; overflow: hidden; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-wrap .axis { stroke: var(--border); }
.chart-wrap .grid { stroke: var(--border); stroke-dasharray: 3 4; }
.chart-wrap .line { fill: none; stroke: var(--blue); stroke-width: 2.5; }
.chart-wrap .dot { fill: var(--surface); stroke: var(--blue); stroke-width: 2; }
.chart-wrap .dot.fail { stroke: var(--red); }
.chart-wrap .passline { stroke: var(--green); stroke-dasharray: 6 4; stroke-width: 1.5; }
.chart-wrap text { fill: var(--text-2); font-size: 11px; }
.table-scroll { overflow-x: auto; }

/* ============ 모달 ============ */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal[hidden] { display: none; }
.modal-box { background: var(--surface); border-radius: 14px; padding: 22px; width: 100%; max-width: 440px; border: 1px solid var(--border); }
.modal-box h2 { font-size: 1.2rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
