:root {
  /* 실제 시험지 느낌: 밝은 회색 책상 위에 흰 종이 */
  --bg: #eef1f5;
  --surface: #ffffff;        /* 흰 종이 (문제 카드/시작 카드/팔레트) */
  --surface-2: #f4f6fa;      /* 옅은 회색 내부 박스 (보기/칩/셀) */
  --border: #dbe1ea;
  --border-strong: #c7cedb;
  --text: #1f2430;
  --text-dim: #667085;
  --primary: #2b6ae0;
  --primary-dark: #1f56c0;
  --primary-tint: #e9f0fd;
  --primary-border: #bcd3fb;
  --correct: #16a34a;
  --correct-tint: #e6f6ec;
  --correct-border: #a9e2bd;
  --wrong: #dc2626;
  --wrong-tint: #fdeaea;
  --wrong-border: #f3bcbc;
  --warn: #c47d00;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(24, 39, 75, 0.08);
  --shadow-soft: 0 2px 10px rgba(24, 39, 75, 0.05);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Malgun Gothic", "Noto Sans KR", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: radial-gradient(1200px 620px at 50% -12%, #ffffff 0%, var(--bg) 62%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.view { min-height: 100vh; }
[hidden] { display: none !important; }

/* ---------- 버튼 ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover:not(:disabled) { background: #f1f4f9; border-color: #b3bccd; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: #fff; border-color: var(--wrong); color: var(--wrong); }
.btn-danger:hover:not(:disabled) { background: var(--wrong-tint); }
.btn-lg { padding: 14px 28px; font-size: 17px; width: 100%; }

.error { color: var(--wrong); font-size: 14px; }

/* ---------- 시작 화면 ---------- */
#view-start {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}
.start-card {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
}
.brand { color: var(--primary); font-weight: 700; letter-spacing: 0.3px; }
.start-card h1 { margin: 6px 0 12px; font-size: 34px; }
.lead { color: var(--text-dim); margin: 0 0 24px; }

.start-meta { display: flex; gap: 12px; margin-bottom: 28px; }
.meta-box {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 10px;
  text-align: center;
}
.meta-box span { display: block; font-size: 26px; font-weight: 700; }
.meta-box small { color: var(--text-dim); font-size: 13px; }

.cat-select { margin-bottom: 26px; }
.cat-select-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; gap: 6px; }
.cat-all { font-weight: 600; cursor: pointer; user-select: none; }
.cat-all input { margin-right: 6px; transform: translateY(1px); accent-color: var(--primary); }
.hint { color: var(--text-dim); font-size: 12.5px; }
.cat-list { display: flex; flex-direction: column; gap: 8px; }
.cat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  cursor: pointer;
  user-select: none;
}
.cat-item:hover { border-color: var(--border-strong); }
.cat-item input { transform: translateY(1px); accent-color: var(--primary); }
.cat-item .cat-name { font-weight: 600; }
.cat-item .cat-count { margin-left: auto; color: var(--text-dim); font-size: 13px; }
.cat-item .cat-desc { color: var(--text-dim); font-size: 12.5px; width: 100%; margin-top: 2px; }

/* ---------- 타임어택 토글 ---------- */
.mode-toggle {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 4px 0 24px;
}
.mode-text { display: flex; flex-direction: column; gap: 2px; }
.mode-label { font-weight: 700; font-size: 15px; }
.mode-label b { color: var(--primary); margin-left: 4px; }
.mode-label b.off { color: var(--text-dim); }
.mode-desc { color: var(--text-dim); font-size: 12.5px; }

.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #ccd3df;
  border-radius: 999px; transition: background 0.15s;
}
.slider::before {
  content: ""; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.15s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--primary); outline-offset: 2px; }

.timer.untimed { color: var(--text-dim); border-color: var(--border); background: var(--surface-2); }
.score-time { color: var(--text-dim); font-size: 14px; }

/* ---------- 회차 선택 ---------- */
.section-title { font-size: 18px; margin: 6px 0 4px; }
.section-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 14px; }

.quick-select { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.quick-label { color: var(--text-dim); font-size: 12.5px; font-weight: 600; margin-right: 2px; }
.chip {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.chip:hover { background: var(--primary-tint); border-color: var(--primary); color: var(--primary-dark); }
.chip:active { transform: translateY(1px); }
.chip-clear { color: var(--text-dim); }
.chip-clear:hover { background: var(--wrong-tint); border-color: var(--wrong); color: var(--wrong); }

.session-groups { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.year-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.year-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.year-toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 15px; }
.year-toggle b { font-size: 15.5px; }
.year-toggle small { color: var(--text-dim); font-weight: 500; }
.year-toggle input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.year-count { color: var(--text-dim); font-size: 12px; white-space: nowrap; }

.session-row { display: flex; flex-wrap: wrap; gap: 8px; }
.sess-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.sess-item:hover { border-color: var(--primary); box-shadow: var(--shadow-soft); }
.sess-item:has(input:checked) { border-color: var(--primary); background: var(--primary-tint); }
.sess-item input { accent-color: var(--primary); cursor: pointer; }
.sess-name { font-weight: 600; font-size: 14px; }
.sess-count { color: var(--text-dim); font-size: 12px; }

.opt-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 16px; font-size: 14px; cursor: pointer; user-select: none; }
.opt-row input { accent-color: var(--primary); }
.opt-row small { color: var(--text-dim); }

.start-bar {
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 22px;
}
.selected-summary { flex: 1; min-width: 180px; font-size: 14px; color: var(--text); }
.selected-summary b { color: var(--primary-dark); }
.selected-summary small { color: var(--text-dim); font-weight: 500; }
.start-bar .btn-lg { width: auto; flex: 0 0 auto; }

/* 주제별 랜덤 연습 (접이식) */
.practice { border-top: 1px solid var(--border); padding-top: 16px; }
.practice > summary {
  cursor: pointer; font-weight: 700; font-size: 15px; list-style: none;
  padding: 6px 0; user-select: none;
}
.practice > summary::-webkit-details-marker { display: none; }
.practice > summary::before { content: "▸ "; color: var(--text-dim); }
.practice[open] > summary::before { content: "▾ "; }
.practice > summary small { color: var(--text-dim); font-weight: 500; }
.practice .cat-select { margin-top: 12px; margin-bottom: 6px; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--text-dim); font-size: 13px; margin: 24px 0 18px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* 출제 이력(미제출 상태 힌트) */
.appear-hint {
  margin-top: 18px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  color: var(--text-dim);
  font-size: 12.5px;
}

/* ---------- OX 문항 ---------- */
.ox-choices { flex-direction: row; gap: 14px; }
.ox-choice {
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 26px 16px;
  background: #fff;
}
.ox-mark { font-size: 42px; font-weight: 800; line-height: 1; color: #9aa4b5; }
.ox-label { font-size: 14px; color: var(--text-dim); font-weight: 600; }
.ox-choice.selected .ox-mark, .ox-choice.selected .ox-label { color: var(--primary); }
.ox-choice.correct .ox-mark, .ox-choice.correct .ox-label { color: var(--correct); }
.ox-choice.wrong .ox-mark, .ox-choice.wrong .ox-label { color: var(--wrong); }

/* ---------- 시험 바 ---------- */
.exam-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}
.exam-title { font-weight: 700; }
.exam-bar-right { display: flex; align-items: center; justify-content: flex-end; gap: 14px; }
.progress { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.timer {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 4px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.timer.warn { color: var(--warn); border-color: var(--warn); }
.timer.danger { color: var(--wrong); border-color: var(--wrong); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------- 시험 본문 ---------- */
.exam-body {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}
.palette-wrap {
  position: sticky;
  top: 78px;
  align-self: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-soft);
}
.palette-head { font-weight: 600; margin-bottom: 12px; color: var(--text-dim); font-size: 13px; }
.palette {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.pnum {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.pnum:hover { border-color: var(--primary); }
.pnum.answered { color: var(--text); border-color: var(--primary); background: var(--primary-tint); }
.pnum.correct { background: var(--correct-tint); border-color: var(--correct); color: var(--correct); }
.pnum.wrong { background: var(--wrong-tint); border-color: var(--wrong); color: var(--wrong); }
.pnum.current { outline: 2px solid var(--primary); outline-offset: 1px; color: var(--text); }

.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 16px; font-size: 12px; color: var(--text-dim); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; border: 1px solid var(--border); }
.dot-current { background: transparent; outline: 2px solid var(--primary); outline-offset: -1px; }
.dot-answered { background: var(--primary-tint); border-color: var(--primary); }
.dot-correct { background: var(--correct); border-color: var(--correct); }
.dot-wrong { background: var(--wrong); border-color: var(--wrong); }

/* ---------- 문제 카드 (흰 시험지) ---------- */
.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 34px;
  box-shadow: var(--shadow);
  min-height: 320px;
}
.q-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.q-index { font-size: 22px; font-weight: 700; }
.q-cat {
  font-size: 12.5px;
  color: var(--primary);
  background: var(--primary-tint);
  border: 1px solid var(--primary-border);
  padding: 3px 10px;
  border-radius: 999px;
}
.q-text { font-size: 19px; font-weight: 600; margin: 4px 0 24px; white-space: pre-wrap; line-height: 1.7; }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-size: 15.5px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.choice:hover:not(:disabled) { border-color: var(--primary); box-shadow: var(--shadow-soft); }
.choice.selected { border-color: var(--primary); background: var(--primary-tint); }
.choice.correct { border-color: var(--correct); background: var(--correct-tint); }
.choice.wrong { border-color: var(--wrong); background: var(--wrong-tint); }
.choice:disabled { cursor: default; box-shadow: none; }
.choice .marker {
  flex: 0 0 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
}
.choice.selected .marker { border-color: var(--primary); color: var(--primary); }
.choice.correct .marker { border-color: var(--correct); color: var(--correct); background: #fff; }
.choice.wrong .marker { border-color: var(--wrong); color: var(--wrong); background: #fff; }

.q-actions { margin-top: 22px; display: flex; align-items: center; gap: 14px; }
.q-actions .verdict { font-weight: 700; }
.verdict.ok { color: var(--correct); }
.verdict.no { color: var(--wrong); }

.explanation {
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
}
.explanation h4 { margin: 0 0 6px; font-size: 14px; color: var(--primary); }
.explanation p { margin: 0; color: var(--text); white-space: pre-wrap; }
.explanation .source { margin-top: 8px; color: var(--text-dim); font-size: 12.5px; }

.nav-buttons { display: flex; justify-content: space-between; margin-top: 20px; }

/* ---------- 결과 화면 ---------- */
.results-content { max-width: 820px; margin: 0 auto; padding: 40px 20px 80px; }
.score-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.score-ring { font-size: 58px; font-weight: 800; color: var(--primary); }
.score-sub { color: var(--text-dim); font-size: 17px; }
.score-actions { margin-top: 22px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.cat-scores { display: grid; gap: 12px; margin-bottom: 28px; }
.cat-score-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: var(--shadow-soft);
}
.cat-score-top { display: flex; justify-content: space-between; margin-bottom: 8px; font-weight: 600; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

.review-head { font-size: 20px; font-weight: 700; margin: 8px 0 16px; }
.review-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-soft);
}
.review-item.correct { border-left: 3px solid var(--correct); }
.review-item.wrong { border-left: 3px solid var(--wrong); }
.review-q { font-weight: 600; margin-bottom: 10px; }
.review-q .num { color: var(--text-dim); margin-right: 6px; }
.review-choice { padding: 6px 10px; border-radius: 8px; font-size: 14.5px; margin: 4px 0; }
.review-choice.correct { background: var(--correct-tint); color: var(--correct); }
.review-choice.wrong { background: var(--wrong-tint); color: var(--wrong); }
.review-choice .tag { font-size: 12px; opacity: 0.85; margin-left: 6px; }
.review-exp { margin-top: 10px; color: var(--text-dim); font-size: 14px; white-space: pre-wrap; }

/* ---------- 모달 / 토스트 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(24, 33, 54, 0.42);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(24, 39, 75, 0.25);
  padding: 26px 24px 20px;
}
.modal-msg { margin: 0 0 20px; font-size: 16px; line-height: 1.55; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 20px);
  z-index: 120;
  padding: 13px 22px;
  border-radius: 10px;
  background: #2a3346;
  border: 1px solid #2a3346;
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--wrong); border-color: var(--wrong); color: #fff; }

/* ---------- 반응형 ---------- */
@media (max-width: 820px) {
  .exam-body { grid-template-columns: 1fr; }
  .palette-wrap { position: static; }
  .palette { grid-template-columns: repeat(10, 1fr); }
  .exam-bar { grid-template-columns: auto 1fr auto; }
  .exam-title { display: none; }
  .start-card { padding: 28px 22px; }
  .question-card { padding: 24px 20px; }
}
