:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --text: #1c2130;
  --muted: #5d6578;
  --border: #dfe3ec;
  --primary: #2563eb;
  --primary-soft: #e3ecff;
  --ok: #15803d;
  --ok-soft: #e3f6e9;
  --bad: #c62828;
  --bad-soft: #fdeaea;
  --warn: #b45309;
  --warn-soft: #fff4de;
  --code-bg: #1e2230;
  --code-text: #e6e8ef;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 14px rgba(20, 30, 60, .05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11141c; --surface: #191d28; --surface-2: #222736; --text: #e7e9f0; --muted: #9aa2b5;
    --border: #2d3345; --primary: #6c9bff; --primary-soft: #1f2c4d; --ok: #4ade80; --ok-soft: #173326;
    --bad: #f87171; --bad-soft: #3a1c1f; --warn: #fbbf24; --warn-soft: #3a2e15; --code-bg: #0c0f16;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #11141c; --surface: #191d28; --surface-2: #222736; --text: #e7e9f0; --muted: #9aa2b5;
  --border: #2d3345; --primary: #6c9bff; --primary-soft: #1f2c4d; --ok: #4ade80; --ok-soft: #173326;
  --bad: #f87171; --bad-soft: #3a1c1f; --warn: #fbbf24; --warn-soft: #3a2e15; --code-bg: #0c0f16;
  --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Noto Sans KR", system-ui, -apple-system, "Malgun Gothic", sans-serif;
  font-size: 16px; line-height: 1.7; word-break: keep-all; overflow-wrap: anywhere;
}
a { color: var(--primary); }
code, pre, .mono { font-family: "JetBrains Mono", Consolas, monospace; }
.container { max-width: 1080px; margin: 0 auto; padding: 24px 16px 60px; min-height: 70vh; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 19px; color: var(--text); text-decoration: none; }
.brand span { color: var(--primary); }
#nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
#nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-weight: 500; font-size: 15px; }
#nav a:hover { background: var(--surface-2); color: var(--text); }
#nav a.active { background: var(--primary-soft); color: var(--primary); }
.theme-btn, .menu-btn { background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 16px; }
.menu-btn { display: none; margin-left: auto; }
@media (max-width: 820px) {
  .menu-btn { display: block; }
  #nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: stretch; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 16px; }
  #nav.open { display: flex; }
  .theme-btn { align-self: flex-start; }
}
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px; border-top: 1px solid var(--border); }

/* generic */
h1 { font-size: 28px; margin: 4px 0 6px; line-height: 1.35; }
h2 { font-size: 21px; margin: 28px 0 12px; }
.lead { color: var(--muted); margin: 0 0 20px; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--primary); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); }
a.card { text-decoration: none; color: inherit; display: block; transition: border-color .15s, transform .15s; }
a.card:hover { border-color: var(--primary); transform: translateY(-2px); }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.card .meta { margin-top: 10px; font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.tag.blue { background: var(--primary-soft); color: var(--primary); }
.num { font-size: 13px; font-weight: 700; color: var(--primary); letter-spacing: .02em; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 8px; padding: 7px 14px; cursor: pointer; font: inherit; font-size: 14px; font-weight: 500; text-decoration: none;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 3px 10px; font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.hero { padding: 28px; margin-bottom: 24px; background: linear-gradient(135deg, var(--primary-soft), var(--surface)); }
.hero h1 { font-size: 30px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 13px; color: var(--muted); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 18px 0 20px; overflow-x: auto; }
.tabs button { background: none; border: none; border-bottom: 2px solid transparent; padding: 10px 16px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* theory */
.layout-side { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
.layout-side > * { min-width: 0; }
.toc { position: sticky; top: 76px; font-size: 14px; }
.toc a { display: block; padding: 6px 10px; color: var(--muted); text-decoration: none; border-radius: 6px; }
.toc a:hover, .toc a.active { background: var(--primary-soft); color: var(--primary); }
@media (max-width: 820px) { .layout-side { grid-template-columns: 1fr; } .toc { position: static; } }
.theory h2 { margin-top: 8px; padding-bottom: 8px; border-bottom: 2px solid var(--primary-soft); }
.theory section { margin-bottom: 36px; }
.theory h3 { font-size: 18px; margin: 24px 0 8px; }
.theory h4 { font-size: 16px; margin: 18px 0 6px; }
.theory table, .q-body table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 14.5px; display: block; overflow-x: auto; }
.theory th, .theory td, .q-body th, .q-body td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.theory th, .q-body th { background: var(--surface-2); }
.theory code, .q-body code, .exp code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.theory pre, pre.code {
  background: var(--code-bg); color: var(--code-text); padding: 14px 16px; border-radius: 10px; overflow-x: auto;
  font-size: 14px; line-height: 1.55; margin: 10px 0;
}
.theory pre code { background: none; padding: 0; color: inherit; }
.tip, .warn { border-radius: 10px; padding: 12px 16px; margin: 12px 0; font-size: 15px; }
.tip { background: var(--primary-soft); border-left: 4px solid var(--primary); }
.warn { background: var(--warn-soft); border-left: 4px solid var(--warn); }

/* questions */
.qlist { display: flex; flex-direction: column; gap: 14px; }
.q { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.q-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.q-body { font-weight: 500; }
.choices { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; }
.choices li button {
  width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font: inherit; color: var(--text); cursor: pointer; display: flex; gap: 8px;
}
.choices li button:hover:not(:disabled) { border-color: var(--primary); }
.choices li button .cn { color: var(--muted); font-weight: 700; flex: none; }
.choices li button.picked { border-color: var(--primary); background: var(--primary-soft); }
.choices li button.correct { border-color: var(--ok); background: var(--ok-soft); }
.choices li button.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choices li button:disabled { cursor: default; }
.exp { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); font-size: 15px; }
.exp .ans { font-weight: 700; color: var(--ok); }
.exp pre { white-space: pre-wrap; }
.result-badge { font-weight: 700; font-size: 14px; }
.result-badge.ok { color: var(--ok); }
.result-badge.bad { color: var(--bad); }
.answer-input { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.answer-input textarea, .answer-input input {
  flex: 1; min-width: 200px; font: inherit; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); resize: vertical;
}
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; flex: 1; min-width: 120px; }
.progress > i { display: block; height: 100%; background: var(--primary); }

/* code runner */
.runner { margin-top: 12px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--code-bg); }
.runner-bar { display: flex; gap: 8px; align-items: center; padding: 6px 10px; background: var(--surface-2); flex-wrap: wrap; }
.runner-bar select { font: inherit; font-size: 14px; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.runner .CodeMirror { height: auto; min-height: 160px; font-family: "JetBrains Mono", Consolas, monospace; font-size: 14px; }
.runner .CodeMirror-scroll { min-height: 160px; max-height: 520px; }
.runner textarea.plain { width: 100%; min-height: 220px; background: var(--code-bg); color: var(--code-text); border: 0; padding: 12px; font: 14px "JetBrains Mono", Consolas, monospace; }
.runner-io { display: grid; grid-template-columns: 1fr 2fr; border-top: 1px solid #2c3242; }
.runner-io > div { padding: 8px 12px; }
.runner-io label { display: block; font-size: 12px; color: #9aa2b5; margin-bottom: 4px; }
.runner-io textarea { width: 100%; min-height: 70px; background: #151924; color: var(--code-text); border: 1px solid #2c3242; border-radius: 6px; font: 13px "JetBrains Mono", monospace; padding: 6px; }
.runner-out { white-space: pre-wrap; color: #d6f5dd; font: 13.5px/1.5 "JetBrains Mono", monospace; min-height: 70px; max-height: 320px; overflow: auto; margin: 0; }
.runner-out .err { color: #ffb4b4; }
.runner-out .info { color: #9aa2b5; }
@media (max-width: 640px) { .runner-io { grid-template-columns: 1fr; } }

/* mock */
.exam-bar {
  position: sticky; top: 56px; z-index: 10; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; box-shadow: var(--shadow);
}
.timer { font: 600 18px "JetBrains Mono", monospace; }
.timer.low { color: var(--bad); }
.subj-head { margin: 26px 0 10px; padding: 8px 14px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.omr { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 4px; }
.omr a { font-size: 12px; text-align: center; padding: 3px 0; border-radius: 5px; background: var(--surface-2); color: var(--muted); text-decoration: none; }
.omr a.done { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.omr a.ok { background: var(--ok-soft); color: var(--ok); }
.omr a.bad { background: var(--bad-soft); color: var(--bad); }
.score-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.score-table th, .score-table td { border: 1px solid var(--border); padding: 8px 10px; text-align: center; }
.score-table th { background: var(--surface-2); }
.pass { color: var(--ok); font-weight: 700; }
.fail { color: var(--bad); font-weight: 700; }
.selfmark { display: inline-flex; gap: 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.link-list { list-style: none; padding: 0; margin: 0; }
.link-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.link-list li:last-child { border-bottom: 0; }
.link-list small { color: var(--muted); display: block; }

/* chapter pages */
.toc-head { font-size: 12px; font-weight: 700; color: var(--muted); padding: 8px 10px 4px; letter-spacing: .02em; }
.toc a.sub { font-size: 13px; padding: 4px 10px 4px 18px; }
.toc { max-height: calc(100vh - 96px); overflow-y: auto; }
.chapter-nav { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
@media (max-width: 820px) { .toc { max-height: none; } #subToc { display: none; } }

/* home info & pass-rate chart (categorical slots 1·2 from the validated reference palette) */
:root { --series-1: #2a78d6; --series-2: #eb6834; --viz-grid: #e6e5e0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --series-1: #3987e5; --series-2: #d95926; --viz-grid: #2d3345; } }
:root[data-theme="dark"] { --series-1: #3987e5; --series-2: #d95926; --viz-grid: #2d3345; }
.note { font-size: 14px; color: var(--muted); margin: 10px 0 0; }
.info-table td:first-child { white-space: nowrap; font-weight: 500; background: var(--surface-2); }
.info-table td { text-align: left; }
.viz-legend { font-size: 14px; color: var(--muted); gap: 16px; }
.viz-legend small { font-size: 12px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw.s1 { background: var(--series-1); } .sw.s2 { background: var(--series-2); }
.viz-wrap { position: relative; margin-top: 8px; }
.viz-svg { width: 100%; height: auto; display: block; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis { fill: var(--muted); font-size: 11px; }
.viz-label { fill: var(--text); font-size: 12px; font-weight: 500; }
.viz-mark { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.viz-cross { stroke: var(--muted); stroke-width: 1; }
.viz-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-line.s1 { stroke: var(--series-1); } .viz-line.s2 { stroke: var(--series-2); }
.viz-dot { stroke: var(--surface); stroke-width: 2; }
.viz-dot.s1 { fill: var(--series-1); } .viz-dot.s2 { fill: var(--series-2); }
.viz-dot.on { r: 6; }
.viz-tip { position: absolute; top: 4px; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; line-height: 1.6; box-shadow: var(--shadow); white-space: nowrap; }
.viz-tip small { color: var(--muted); }
details summary { cursor: pointer; color: var(--primary); font-size: 14px; margin-top: 10px; }
.prep .card .btn { margin-top: 10px; }
.tips { margin: 0; padding-left: 20px; } .tips li { margin: 6px 0; }
