:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #eef4fb;
  --text: #172033;
  --muted: #667085;
  --line: #dce4ef;
  --primary: #1769e0;
  --primary-dark: #0f52b8;
  --correct: #14804a;
  --correct-bg: #e8f7ef;
  --wrong: #c5363d;
  --wrong-bg: #fff0f0;
  --warning: #9a6700;
  --shadow: 0 16px 44px rgba(29, 55, 90, .10);
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: "Malgun Gothic", "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 290px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 24px 20px; background: #0e2342; color: #fff; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 4px 22px; border-bottom: 1px solid rgba(255,255,255,.13); }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: #2b7cff; font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: 3px; color: #a9b8d0; font-size: 12px; }
.side-section { padding: 22px 4px; border-bottom: 1px solid rgba(255,255,255,.11); }
.side-section h2 { margin: 0 0 15px; font-size: 13px; color: #b9c7dc; letter-spacing: .08em; text-transform: uppercase; }
.progress-ring { --progress: 0deg; width: 96px; height: 96px; display: grid; place-items: center; margin: 4px auto 18px; border-radius: 50%; background: conic-gradient(#4ea1ff var(--progress), rgba(255,255,255,.13) 0); position: relative; }
.progress-ring::before { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: #0e2342; }
.progress-ring span { position: relative; font-size: 18px; font-weight: 800; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stats-grid div { padding: 10px; background: rgba(255,255,255,.07); border-radius: 10px; }
.stats-grid strong, .stats-grid span { display: block; }
.stats-grid strong { font-size: 18px; }
.stats-grid span { margin-top: 2px; color: #a9b8d0; font-size: 11px; }
.session-options label { display: block; margin: 12px 0; color: #b9c7dc; font-size: 12px; }
select, input { width: 100%; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--text); padding: 10px 11px; outline: none; }
.session-options select { margin-top: 6px; border-color: rgba(255,255,255,.18); background: #172f53; color: white; }
select:focus, input:focus { border-color: #5b9df3; box-shadow: 0 0 0 3px rgba(47,128,237,.15); }
button, .file-button { border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--text); padding: 10px 14px; font-weight: 700; }
.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.wide { width: 100%; margin-top: 8px; }
.compact-actions { display: grid; gap: 8px; }
.compact-actions button, .file-button { width: 100%; background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.14); color: #eaf1fc; text-align: center; font-size: 12px; }
.file-button input { display: none; }
.compact-actions .danger-text { color: #ffb4b8; }
.dataset-note { color: #8295b2; font-size: 10px; line-height: 1.7; padding: 10px 4px; }

.main { min-width: 0; }
.topbar { height: 68px; display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 0 34px; background: rgba(255,255,255,.82); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 20; }
.search-wrap { width: min(410px, 70vw); display: flex; }
.search-wrap input { border-radius: 9px 0 0 9px; }
.search-wrap button { border-left: 0; border-radius: 0 9px 9px 0; }
.icon-button { width: 42px; height: 42px; padding: 0; font-size: 19px; }
.mobile-only { display: none; }

.welcome, .quiz { width: min(980px, calc(100% - 48px)); margin: 0 auto; padding: 58px 0 70px; }
.welcome { min-height: calc(100vh - 68px); display: flex; flex-direction: column; justify-content: center; }
.eyebrow { color: var(--primary); font-weight: 800; letter-spacing: .12em; font-size: 12px; }
.welcome h1 { margin: 12px 0 22px; font-size: clamp(38px, 6vw, 66px); line-height: 1.08; letter-spacing: -.045em; }
.welcome > p:not(.eyebrow) { max-width: 650px; color: var(--muted); line-height: 1.8; }
.welcome-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 32px 0; }
.welcome-cards div { padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: var(--shadow); }
.welcome-cards strong, .welcome-cards span { display: block; }
.welcome-cards strong { font-size: 28px; }
.welcome-cards span { margin-top: 6px; color: var(--muted); font-size: 13px; }
.hero-button { align-self: flex-start; padding: 14px 24px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.hero-button.secondary { background: var(--panel); color: var(--primary); border-color: #9fc2f3; }
.exam-note { margin-top: 14px !important; font-size: 12px; color: var(--muted); }
.exam-result { width: min(760px, calc(100% - 48px)); min-height: calc(100vh - 68px); margin: 0 auto; padding: 70px 0; display: flex; flex-direction: column; justify-content: center; }
.exam-result h1 { margin: 10px 0 22px; font-size: clamp(36px, 6vw, 58px); }
.exam-score { display: flex; align-items: baseline; gap: 16px; margin: 8px 0 18px; }
.exam-score strong { font-size: 42px; }
.exam-score span { color: var(--primary); font-size: 24px; font-weight: 800; }
.exam-result > p:not(.eyebrow) { color: var(--muted); line-height: 1.8; margin-bottom: 26px; }
.exam-mode-banner { margin: 0 0 14px; padding: 10px 12px; border-radius: 9px; background: #eef4ff; color: #24558f; font-size: 12px; font-weight: 700; }

.quiz { padding-top: 34px; }
.quiz-meta, .quiz-nav, .session-progress > div:first-child { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pill { display: inline-flex; padding: 5px 9px; border-radius: 999px; background: #e7f1ff; color: #135ab7; font-size: 11px; font-weight: 800; }
.pill.self { background: #fff3d6; color: #855b00; }
.source-number { margin-left: 8px; color: var(--muted); font-size: 12px; }
.bookmark { border: 0; background: transparent; color: var(--muted); }
.bookmark.active { color: #df9700; }
.question-status { margin: 14px 0; }
.status-badges { display: flex; flex-wrap: wrap; gap: 7px; }
.status-badge { display: inline-flex; align-items: center; min-height: 27px; padding: 5px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; border: 1px solid transparent; }
.status-badge.scope-current { color: #146c43; background: #e8f7ef; border-color: #b8e6cb; }
.status-badge.scope-out { color: #9a3d00; background: #fff0e6; border-color: #ffc79f; }
.status-badge.term-change { color: #24558f; background: #e9f2ff; border-color: #bed8f7; }
.status-badge.legacy-change { color: #8a5200; background: #fff4d6; border-color: #efd187; }
.question-status > p { margin: 8px 0 0; padding: 10px 12px; border-left: 3px solid #d97904; background: #fff8e8; border-radius: 0 8px 8px 0; font-size: 12px; line-height: 1.65; }
.session-progress { margin: 18px 0 16px; color: var(--muted); font-size: 12px; }
.bar { height: 6px; margin-top: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar i { display: block; width: 0; height: 100%; background: var(--primary); border-radius: inherit; transition: width .25s ease; }
.question-card { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: var(--shadow); }
.question-images { padding: 22px; }
.question-images img, .answer-images img { display: block; width: 100%; height: auto; margin: 0 auto 10px; border-radius: 4px; }
.text-fallback { border-top: 1px solid var(--line); padding: 12px 18px; color: var(--muted); font-size: 12px; }
.text-fallback pre { white-space: pre-wrap; font-family: inherit; line-height: 1.7; color: var(--text); }
.answer-controls { margin-top: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.answer-title { margin: 0 0 12px; font-size: 14px; }
.choice-row { display: flex; flex-wrap: wrap; gap: 10px; }
.choice { min-width: 54px; font-size: 16px; }
.choice.selected { border-color: var(--primary); background: #eaf3ff; color: var(--primary-dark); box-shadow: 0 0 0 2px rgba(23,105,224,.12); }
.submit-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-top: 16px; }
.submit-row small { color: var(--muted); }
.self-instruction { margin: 0 0 14px; color: var(--muted); line-height: 1.65; }
.feedback, .explanation { margin-top: 16px; border-radius: 14px; padding: 18px; }
.feedback.correct { border: 1px solid #b8e6cb; background: var(--correct-bg); color: var(--correct); }
.feedback.wrong { border: 1px solid #ffc9cc; background: var(--wrong-bg); color: var(--wrong); }
.feedback.neutral { border: 1px solid #cbdcf1; background: var(--panel-soft); color: #254b78; }
.feedback strong { display: block; margin-bottom: 4px; }
.self-grade { display: flex; gap: 10px; margin-top: 12px; }
.self-grade .correct-button { border-color: #8fd0aa; color: var(--correct); }
.self-grade .wrong-button { border-color: #f0a6aa; color: var(--wrong); }
.explanation { border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); }
.explanation h3 { margin: 0 0 12px; }
.answer-summary { padding: 12px 14px; border-left: 4px solid var(--primary); background: var(--panel-soft); line-height: 1.7; }
.learning-tip { line-height: 1.75; color: var(--text); }
.explanation-section { margin-top: 18px; }
.explanation-section h4, .update-block h4 { margin: 0 0 9px; font-size: 14px; }
.explanation-section > p { line-height: 1.75; }
.choice-analysis { display: grid; gap: 9px; }
.choice-review { padding: 12px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.choice-review header { display: flex; align-items: center; gap: 8px; }
.choice-review header span { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 50%; background: #dfe7f2; font-weight: 800; font-size: 12px; }
.choice-review header strong { font-size: 12px; }
.choice-review p { margin: 8px 0 5px; line-height: 1.55; font-size: 13px; }
.choice-review small { display: block; color: var(--muted); line-height: 1.65; }
.choice-review.right { border-color: #9fd6b6; background: #eefaf3; }
.choice-review.right header span { color: white; background: var(--correct); }
.choice-review.not-right.chosen { border-color: #e79b9f; background: #fff3f3; }
.choice-review.not-right.chosen header span { color: white; background: var(--wrong); }
.analysis-note { margin: 0; line-height: 1.75; }
.update-block { margin-top: 16px; padding: 14px 15px; border-radius: 10px; border: 1px solid var(--line); }
.update-block p { margin: 7px 0; line-height: 1.7; font-size: 13px; }
.update-block.current { border-color: #a9d9bd; background: #effaf4; }
.update-block.scope-warning { border-color: #f0be83; background: #fff7ea; }
.update-block.terminology { border-color: #abcbed; background: #eff6ff; }
.update-block.legacy { border-color: #e9bd69; background: #fff5d9; }
.update-block a { color: var(--primary-dark); font-weight: 700; }
.explanation-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.answer-images { margin-top: 14px; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.quiz-nav { margin-top: 22px; }
.quiz-nav #shortcutHint { color: var(--muted); font-size: 11px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 18px); opacity: 0; pointer-events: none; padding: 11px 18px; border-radius: 10px; background: #111b2c; color: #fff; box-shadow: var(--shadow); transition: .2s ease; z-index: 100; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body.dark { --bg:#0f1726; --panel:#162237; --panel-soft:#1d2d47; --text:#edf4ff; --muted:#9daec5; --line:#2a3b56; --shadow:0 16px 44px rgba(0,0,0,.25); }
body.dark .topbar { background: rgba(15,23,38,.86); }
body.dark .choice.selected { background:#18365d; }
body.dark .answer-images { background:#fff; }
body.dark .question-status > p, body.dark .update-block, body.dark .choice-review { color: #172033; }

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 50; width: 290px; transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-grid; place-items: center; }
  .topbar { justify-content: space-between; padding: 0 16px; }
  .welcome, .quiz { width: min(100% - 24px, 980px); padding-top: 28px; }
  .welcome-cards { grid-template-columns: 1fr; }
  .question-images { padding: 10px; }
  .quiz-nav #shortcutHint { display: none; }
}

@media print {
  .sidebar, .topbar, .answer-controls, .feedback, .explanation, .quiz-nav, .quiz-meta, .session-progress { display:none !important; }
  .app-shell { display:block; }
  .quiz { width:100%; padding:0; }
  .question-card { border:0; box-shadow:none; }
}

/* p3 · interactive HOTSPOT / select-and-place practice */
.hotspot-image-block { margin-bottom: 14px; }
.hotspot-canvas-label { margin: 0 0 7px; font-size: 11px; font-weight: 800; color: var(--primary-dark); }
.hotspot-canvas-label.muted { color: var(--muted); font-weight: 700; }
.hotspot-stage { position: relative; width: 100%; overflow: hidden; border-radius: 6px; }
.hotspot-stage img { margin-bottom: 0; user-select: none; -webkit-user-drag: none; }
.hotspot-stage.interactive { cursor: crosshair; outline: 2px dashed #8db8ef; outline-offset: 3px; background: #fff; }
.hotspot-stage.interactive:hover { outline-color: var(--primary); }
.hotspot-stage.interactive.locked { cursor: default; outline-style: solid; outline-color: #9aa9ba; }
.hotspot-marker-layer { position: absolute; inset: 0; pointer-events: none; }
.hotspot-marker { position: absolute; z-index: 3; width: 30px; height: 30px; min-width: 30px; padding: 0; transform: translate(-50%,-50%); border: 2px solid #fff; border-radius: 50%; background: #1769e0; color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.28); pointer-events: auto; }
.hotspot-marker span { display: grid; place-items: center; width: 100%; height: 100%; font-size: 12px; font-weight: 900; }
.hotspot-stage.locked .hotspot-marker { background: #52647a; }
.hotspot-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); }
.hotspot-toolbar > strong { font-size: 12px; }
.hotspot-toolbar > div { display: flex; gap: 7px; flex-wrap: wrap; }
.hotspot-toolbar button { padding: 7px 10px; font-size: 11px; }

@media (max-width: 620px) {
  .hotspot-toolbar, .submit-row { align-items: stretch; flex-direction: column; }
  .hotspot-toolbar > div { width: 100%; }
  .hotspot-toolbar button { flex: 1; }
}

/* p3 · explanation v2 */
.explanation-focus { padding: 13px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.explanation-focus h4 { margin-bottom: 7px; }
.exam-point { padding: 13px 14px; border-left: 4px solid #7a5bd8; background: #f6f3ff; border-radius: 0 10px 10px 0; }
.answer-image-help { margin: 7px 0 12px; color: #52647a; font-size: 12px; line-height: 1.6; }
body.dark .exam-point { color: #172033; }

/* p5: HOTSPOT readability + decoded answer controls */
.question-images img, .answer-images img { width: auto; max-width: 100%; }
.hotspot-image-block { margin-bottom: 18px; }
.hotspot-canvas-label { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:9px; font-size:12px; font-weight:800; color:#31567f; }
.hotspot-canvas-label.muted { color:var(--muted); }
.image-open-button, .image-open-link { font-size:11px; padding:6px 9px; white-space:nowrap; }
.hotspot-stage { margin:0 auto; width:fit-content; max-width:100%; }
.hotspot-stage img { width:auto; max-width:100%; }
.binary-answer-grid { display:grid; gap:10px; }
.binary-answer-row { display:flex; align-items:center; justify-content:space-between; gap:16px; padding:11px 12px; border:1px solid var(--line); border-radius:10px; background:var(--bg); }
.binary-answer-row > div { display:flex; gap:7px; }
.binary-answer-row button.selected { border-color:var(--primary); background:#eaf3ff; color:var(--primary-dark); box-shadow:0 0 0 2px rgba(23,105,224,.12); }
.source-label { display:inline-flex; margin-left:6px; padding:3px 7px; border-radius:999px; background:#edf3fa; color:#52647a; font-size:10px; font-weight:700; vertical-align:middle; }
.decoded-answer ol { margin:8px 0 0 20px; padding:0; }
.decoded-answer li { margin:7px 0; line-height:1.6; }
.answer-effects { display:grid; gap:9px; }
.answer-effects > h4 { margin-bottom:0; }
.answer-effects article { padding:12px 13px; border:1px solid var(--line); border-radius:10px; background:#f8fbff; }
.answer-effects article strong { display:block; line-height:1.55; }
.answer-effects article p { margin:7px 0 0; color:var(--muted); line-height:1.7; }
.answer-image-item { margin:10px 0 16px; text-align:center; }
.answer-image-item .image-open-link { display:inline-block; margin-top:5px; }
@media (max-width: 720px) {
  .hotspot-canvas-label { align-items:flex-start; flex-direction:column; }
  .binary-answer-row { align-items:flex-start; flex-direction:column; }
}
/* p6 anti-leak / deep explanation */
.core-rule { padding: 14px 16px; border-left: 4px solid #6b55c6; background: #f7f4ff; border-radius: 0 10px 10px 0; }
.core-rule p { margin: 0; line-height: 1.78; }
.decoded-setting-row > div { display: flex; flex-wrap: wrap; gap: 7px; }
.decoded-setting-row button { min-width: 72px; }
.binary-answer-row button.selected { border-color: var(--primary); background: #eaf3ff; color: var(--primary-dark); box-shadow: 0 0 0 2px rgba(23,105,224,.12); }

/* p7 reference-grounded explanations */
.reference-explanation { border: 1px solid #bfd7f4; border-radius: 12px; padding: 16px; background: #f7fbff; }
.reference-explanation > p { line-height: 1.75; }
.reference-steps { display: grid; gap: 10px; margin-top: 12px; }
.reference-steps article { padding: 12px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.reference-steps article strong { display: block; margin-bottom: 6px; }
.reference-steps article p { margin: 0; line-height: 1.72; }
.reference-nuance { margin-top: 12px; padding: 12px 13px; border-left: 4px solid #d08a00; background: #fff9e9; }
.reference-nuance p { margin: 6px 0 0; line-height: 1.7; }
.reference-links { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.reference-links strong { margin-right: 2px; }
.reference-links a { padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 12px; text-decoration: none; }

/* p8: 606문항 커뮤니티 기반 상세 해설 */
.answer-summary span { line-height: 1.7; }
.answer-source-note { display: inline-block; margin: 9px 0 0 8px; padding: 3px 7px; border: 1px solid var(--line); border-radius: 999px; font-size: 11px; opacity: .72; vertical-align: middle; }
.answer-ground { background: color-mix(in srgb, var(--panel) 92%, #eef5ff 8%); }
.application-steps { margin: 10px 0 0 22px; padding: 0; }
.application-steps li { margin: 8px 0; padding-left: 3px; line-height: 1.72; }
.choice-analysis-v2 { display: grid; gap: 8px; margin-top: 10px; }
.choice-analysis-v2 p { margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; line-height: 1.65; background: var(--panel); }
.explanation-caution { border: 1px solid #e0a62f; border-radius: 12px; padding: 14px 15px; background: #fff8e8; }
.explanation-caution p { margin: 7px 0 0; line-height: 1.68; }
.current-difference { border: 1px solid #87b5df; border-radius: 12px; padding: 14px 15px; background: #f2f8ff; }
.current-difference article + article { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.current-difference article p { margin: 6px 0; line-height: 1.68; }
.current-difference article a { font-size: 12px; }
.scope-note { border-left: 4px solid #7b8492; padding-left: 13px; }
.explanation code { padding: 1px 5px; border-radius: 5px; background: rgba(127,127,127,.13); font-size: .93em; }
body.dark .explanation-caution { background: rgba(160,110,20,.16); }
body.dark .current-difference { background: rgba(50,100,150,.14); }
