:root {
  --bg: #f6f4ee; --paper: #fffdf8; --ink: #1d2433; --muted: #5d6577; --line: #dcd7ca; --line-soft: #ebe7dc;
  --accent: #1f6f5c; --accent-soft: #dcefe8; --accent-ink: #fff;
  --ok: #1f7a4d; --ok-bg: #e4f3ea; --bad: #c2412d; --bad-bg: #fbe8e3; --warn: #b7791f;
  --chip: #efece3; --water: #d4e8f6; --road: #e6e1d4; --bld: #fbf8f0;
  --vessel: #d0443a; --lacteal: #f2d27a; --glass: #cfe0f4;
  --g1: #1f6f5c; --g2: #3b4fb8;
  --shadow: 0 1px 2px rgba(20, 24, 33, .05), 0 6px 20px rgba(20, 24, 33, .06);
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --paper: #1c2028; --ink: #e7e9ee; --muted: #a2a9b8; --line: #343b48; --line-soft: #2a303b;
    --accent: #5cc2a4; --accent-soft: #1f3a33; --accent-ink: #0e1a16;
    --ok: #5cc28a; --ok-bg: #1b3327; --bad: #ff8a75; --bad-bg: #3a2420; --warn: #e8b35a;
    --chip: #262b35; --water: #1f3a52; --road: #2a303b; --bld: #222733;
    --vessel: #ff6b5e; --lacteal: #c9a84a; --glass: #2d4666;
    --g1: #5cc2a4; --g2: #8b9cff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 88px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 16px; line-height: 1.65; word-break: keep-all; overflow-wrap: anywhere;
}
a { color: inherit; }
h1, h2, h3, h4 { line-height: 1.3; margin: 0; letter-spacing: -0.01em; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; }

/* 상단바 */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line-soft); }
.topbar-in { display: flex; align-items: center; justify-content: space-between; height: 58px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 800; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 16px; }
.topnav { display: flex; gap: 4px; }
.topnav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; font-weight: 600; color: var(--muted); }
.topnav a.on, .topnav a:hover { background: var(--chip); color: var(--ink); }

/* 버튼 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); text-decoration: none; font-weight: 700; cursor: pointer; transition: transform .08s, background .15s; white-space: nowrap; }
.btn:hover { background: var(--chip); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.lg { min-height: 52px; padding: 0 28px; font-size: 17px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

/* 홈 */
.hero { padding: 56px 0 28px; max-width: 720px; }
.eyebrow { margin: 0 0 8px; font-weight: 700; color: var(--accent); font-size: 14px; }
.hero h1 { font-size: clamp(28px, 5vw, 42px); font-weight: 800; }
.lead { color: var(--muted); font-size: 17px; margin: 16px 0 0; }
.grade-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin: 12px 0 28px; }
.grade-card { --gc: var(--g1); display: block; text-decoration: none; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 24px; box-shadow: var(--shadow); border-top: 5px solid var(--gc); transition: transform .15s; }
.grade-card.g2, .page-head.g2 { --gc: var(--g2); }
.grade-card:hover { transform: translateY(-2px); }
.gc-top { display: flex; justify-content: space-between; align-items: center; }
.gc-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--gc, var(--g1)); color: var(--paper); font-weight: 800; font-size: 13px; }
.gc-n { color: var(--muted); font-size: 14px; font-weight: 600; }
.grade-card h2 { font-size: 24px; margin: 12px 0 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--chip); border-radius: 999px; padding: 3px 10px; font-size: 14px; font-weight: 600; }
.gc-go { display: inline-block; margin-top: 18px; font-weight: 700; color: var(--gc); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 40px; }
.feat { border: 1px dashed var(--line); border-radius: var(--r); padding: 18px; }
.feat h3 { font-size: 17px; margin-bottom: 6px; }
.feat p { margin: 0; color: var(--muted); font-size: 15px; }

/* 학년 페이지 */
.page-head { --gc: var(--g1); padding: 36px 0 20px; }
.page-head h1 { font-size: clamp(26px, 4vw, 34px); margin: 10px 0 6px; }
.page-head p { margin: 0; color: var(--muted); }
.subj-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 14px; }
.subj-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.sc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sc-head h3 { font-size: 22px; }
.sc-meta { color: var(--muted); font-size: 14px; font-weight: 600; white-space: nowrap; }
.sc-range { margin: 0; font-size: 14px; color: var(--muted); }
.sc-label { display: inline-block; font-size: 12px; font-weight: 800; color: var(--accent); margin-right: 8px; }
.sc-scope { font-size: 14px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.sc-note { margin: 0; font-size: 13px; color: var(--muted); padding-left: 10px; border-left: 3px solid var(--line); }
.ana-note { margin: 6px 0 0; font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--chip); }
.small-note { font-size: 13px; margin-top: 4px !important; }
.rec { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; padding: 8px 12px; background: var(--chip); border-radius: 10px; }
.rec.muted { color: var(--muted); }
.sc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }

.ana { margin: 44px 0 20px; }
.ana > h2 { font-size: 22px; margin-bottom: 6px; }
.ana > p { margin: 0 0 16px; font-size: 15px; }
.ana-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 14px; }
.ana-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; }
.ana-card h3 { font-size: 19px; }
.ana-card h4 { font-size: 14px; margin: 16px 0 6px; color: var(--muted); }
.ana-format { margin: 4px 0 12px; font-size: 14px; color: var(--muted); }
.ana-types { margin: 0; padding-left: 18px; font-size: 14px; }
.ana-tip { margin: 14px 0 0; font-size: 14px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); }
.ana-tip b { margin-right: 6px; color: var(--accent); }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(96px, 150px) 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.bar-label { font-weight: 600; }
.bar-track { height: 10px; background: var(--chip); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar-fill.low { background: var(--bad); }
.bar-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-val em { font-style: normal; color: var(--muted); margin-left: 4px; }

/* 시험 화면 */
.exam-bar { position: sticky; top: 0; z-index: 20; background: var(--paper); border-bottom: 1px solid var(--line); }
.exam-bar-in { display: flex; align-items: center; gap: 10px; min-height: 60px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.eb-title { display: flex; align-items: center; gap: 8px; margin-right: auto; }
.eb-title b { font-size: 17px; }
.mode-tag { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 18px; padding: 4px 10px; border-radius: 8px; background: var(--chip); }
.timer.warn { background: var(--bad-bg); color: var(--bad); }
.progress { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.prog-line { height: 3px; background: var(--line-soft); }
.prog-line span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.exam-body { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 22px; padding-top: 20px; padding-bottom: 60px; align-items: start; }
.exam-note { font-size: 14px; color: var(--muted); background: var(--chip); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.end-actions { display: flex; justify-content: center; padding: 20px 0; }

.omr { position: sticky; top: 84px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.omr-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.omr-toggle { display: none; background: none; border: 0; font-size: 18px; cursor: pointer; }
.omr-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-height: calc(100vh - 160px); overflow: auto; }
.omr-cell { display: flex; flex-direction: column; align-items: center; padding: 4px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); cursor: pointer; font-size: 13px; line-height: 1.2; }
.omr-cell .on { font-weight: 700; color: var(--muted); }
.omr-cell .om { min-height: 18px; font-size: 15px; }
.omr-cell.done { border-color: var(--accent); background: var(--accent-soft); }
.omr-cell.ok { border-color: var(--ok); background: var(--ok-bg); }
.omr-cell.bad { border-color: var(--bad); background: var(--bad-bg); }

/* 문항 */
.q { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 20px 20px 18px; margin-bottom: 14px; scroll-margin-top: 90px; }
.q-head { display: flex; gap: 8px; }
.q-no { font-weight: 800; font-size: 18px; min-width: 28px; }
.q-text { font-size: 17px; font-weight: 500; }
.q-text u { text-underline-offset: 3px; text-decoration-thickness: 2px; font-weight: 700; }
.q-pts { color: var(--muted); font-size: 14px; white-space: nowrap; }
.q-unit { margin: 4px 0 0 36px; font-size: 12px; color: var(--muted); }
.box { margin: 12px 0 0; border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; background: var(--bg); position: relative; }
.box.titled { padding-top: 18px; margin-top: 18px; }
.box-title { position: absolute; top: -11px; left: 50%; transform: translateX(-50%); background: var(--paper); padding: 0 8px; font-size: 14px; font-weight: 700; }
.box .ko { color: var(--muted); font-size: 14px; }
.data-row { text-align: center; font-size: 18px; letter-spacing: .06em; font-variant-numeric: tabular-nums; }
.passage { margin-bottom: 14px; border-left: 4px solid var(--accent); background: var(--bg); padding: 12px 16px; border-radius: 0 10px 10px 0; }
.passage-tag { display: block; font-size: 13px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.passage-body { font-size: 16px; line-height: 1.75; }
.passage-ref { margin: 0 0 8px; font-size: 13px; color: var(--muted); }

.tbl-wrap { overflow-x: auto; margin-top: 12px; }
.tbl { border-collapse: collapse; min-width: 60%; font-size: 15px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 6px 12px; text-align: center; }
.tbl th { background: var(--chip); font-weight: 700; }
.tbl.stem td:first-child { font-weight: 700; width: 60px; }
.tbl.stem td:last-child { text-align: left; letter-spacing: .08em; }

.fig { margin: 14px 0 0; display: flex; justify-content: center; }
.fig-svg { width: 100%; height: auto; color: var(--ink); overflow: visible; }
.fig-svg text { fill: currentColor; font-size: 13px; font-family: inherit; }
.fig-svg text.small { font-size: 11.5px; fill: var(--muted); }
.fig-svg .mm { font-family: KaTeX_Main, "Times New Roman", serif; font-size: 15px; }
.fig-svg .mi { font-family: KaTeX_Math, "Times New Roman", serif; font-style: italic; }
.fig-svg .deg { font-family: Pretendard, -apple-system, "Malgun Gothic", sans-serif; }
.fig-svg .grid { stroke: var(--line); stroke-width: 1; }
.fig-svg .trail { stroke: var(--accent); stroke-width: 3; opacity: .55; stroke-linecap: round; }
.fig-svg .pdot { fill: var(--ink); }
.fig-svg .vel { stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; }
.fig-svg .vel-head { fill: var(--accent); }
.fig-svg .bg-soft { fill: var(--bg); }
.fig-svg .acc { color: var(--accent); }
.fig-svg .acc-stroke { stroke: var(--accent); }
.fig-svg .acc-fill { fill: var(--accent); }
.fig-svg .acc-fill-soft { fill: var(--accent-soft); }
.fig-svg .water { fill: var(--water); }
.fig-svg .road { fill: var(--road); }
.fig-svg .bld { fill: var(--bld); }
.fig-svg .bld-muted { fill: var(--chip); }
.fig-svg .vessel { stroke: var(--vessel); }
.fig-svg .lacteal { fill: var(--lacteal); }
.fig-svg .glass { fill: var(--glass); }
.fig-svg .hatch { fill: var(--chip); }
.fig-svg .vein-fill { fill: var(--glass); }
.fig-svg .artery-fill { fill: var(--vessel); opacity: .7; }

.choices { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; }
.choices.short { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.ch { width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 9px 12px; border: 1px solid var(--line-soft); border-radius: 10px; background: transparent; cursor: pointer; font-size: 16px; line-height: 1.55; transition: background .12s, border-color .12s; }
.ch:hover:not(:disabled) { background: var(--chip); border-color: var(--line); }
.ch .cm { font-size: 18px; line-height: 1.4; flex: none; }
.ch.sel { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.ch.correct { border-color: var(--ok); background: var(--ok-bg); font-weight: 700; }
.ch.wrong { border-color: var(--bad); background: var(--bad-bg); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--bad) 60%, transparent); }
.ch:disabled { cursor: default; color: inherit; }
.fb { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line-soft); }
.fb-ans { font-weight: 700; margin-left: 8px; }
.fb-exp { margin: 6px 0 0; font-size: 15px; }
.why { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.why-title { margin: 0 0 6px; font-size: 13px; font-weight: 800; color: var(--muted); }
.why ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.why li { display: flex; gap: 8px; font-size: 14.5px; line-height: 1.6; padding: 6px 8px; border-radius: 8px; }
.why li.right { background: var(--ok-bg); }
.why li.mine:not(.right) { background: var(--bad-bg); }
.why .cm { flex: none; font-size: 16px; line-height: 1.5; }
.why-tag { display: inline-block; font-size: 11px; font-weight: 800; padding: 0 7px; border-radius: 999px; background: var(--chip); color: var(--muted); margin-right: 4px; vertical-align: 1px; }
.why li.right .why-tag:first-child { background: var(--ok); color: var(--paper); }
.why-tag.me { background: var(--bad); color: var(--paper); }
.why li.right .why-tag.me { background: var(--ok); }
.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 13px; font-weight: 800; }
.tag.ok { background: var(--ok); color: var(--paper); }
.tag.bad { background: var(--bad); color: var(--paper); }

/* 수식 (KaTeX) */
.katex { font-size: 1.08em; }
.katex-display { margin: .6em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.fb-exp .katex-display { text-align: left; }
.fb-exp .katex-display > .katex { text-align: left; padding-left: 1em; }
.ch .katex { font-size: 1.05em; }

/* 결과 */
.result { padding-top: 28px; padding-bottom: 20px; }
.res-head { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 24px; box-shadow: var(--shadow); }
.score-ring { --deg: 0deg; width: 150px; height: 150px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--accent) var(--deg), var(--chip) 0); flex: none; }
.score-ring > div { width: 118px; height: 118px; border-radius: 50%; background: var(--paper); display: grid; place-items: center; align-content: center; }
.score-ring b { font-size: 44px; line-height: 1; font-variant-numeric: tabular-nums; }
.score-ring span { font-size: 14px; color: var(--muted); }
.res-info { flex: 1 1 300px; }
.res-info h1 { font-size: 26px; margin-bottom: 6px; }
.res-info p { margin: 4px 0; }
.res-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.res-units { margin: 24px 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; }
.res-units h2, .review h2 { font-size: 20px; margin-bottom: 12px; }
.review-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.review-head h2 { margin: 0; }
.seg-ctl { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg-ctl button { border: 0; background: var(--paper); padding: 8px 14px; cursor: pointer; font-weight: 600; }
.seg-ctl button.on { background: var(--accent); color: var(--accent-ink); }
.only-wrong .q[data-ok="1"] { display: none; }

/* 안내 */
.landing .hero { padding: 28px 0 8px; }
.landing .hero h1 { font-size: clamp(26px, 4.5vw, 36px); margin: 0; }
.landing .features { margin: 8px 0 0; }
.landing .grade-grid { margin-bottom: 8px; }
.landing #start { scroll-margin-top: 80px; }
.prose { max-width: 760px; padding-top: 36px; padding-bottom: 20px; }
.prose h1 { font-size: 30px; margin-bottom: 18px; }
.prose h2 { font-size: 20px; margin: 28px 0 8px; }
.prose li { margin-bottom: 6px; }

.foot { border-top: 1px solid var(--line-soft); margin-top: 48px; padding: 22px 0 36px; color: var(--muted); font-size: 13px; }
.foot p { margin: 4px 0; }

/* 모바일 */
@media (max-width: 899px) {
  .exam-body { grid-template-columns: 1fr; }
  .omr { position: fixed; left: 12px; right: 12px; bottom: 12px; top: auto; z-index: 30; box-shadow: 0 8px 30px rgba(0, 0, 0, .2); padding: 10px 14px; }
  .omr-toggle { display: block; }
  .omr .omr-grid { display: none; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); max-height: 40vh; }
  .omr.open .omr-grid { display: grid; }
  .omr-head { margin: 0; }
  .omr.open .omr-head { margin-bottom: 10px; }
  .omr.open .omr-toggle { transform: rotate(180deg); }
  .exam-body { padding-bottom: 110px; }
}
@media (max-width: 560px) {
  .q { padding: 16px 14px; }
  .q-unit { margin-left: 0; }
  .exam-bar-in { gap: 8px; }
  .eb-title { order: -1; width: 100%; margin-right: 0; }
  .exam-bar [data-act="leave"] { margin-right: auto; }
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-row .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .res-head { padding: 18px; }
  .score-ring { width: 120px; height: 120px; }
  .score-ring > div { width: 94px; height: 94px; }
  .score-ring b { font-size: 36px; }
}
@media print {
  .topbar, .exam-bar, .omr, .end-actions, .foot, .res-actions, .seg-ctl { display: none !important; }
  body { background: #fff; color: #000; }
  .q { break-inside: avoid; border-color: #bbb; }
}
