:root {
  --bg: #f6f6f2;
  --surface: #ffffff;
  --surface-2: #efefe9;
  --ink: #15171c;
  --muted: #5a616e;
  --line: #e1e1da;
  --brand: #1d3fae;
  --brand-ink: #ffffff;
  --brand-soft: #e7ecfb;
  --accent: #f2b705;
  --accent-ink: #1b1400;
  --ok: #157a4a;
  --code-bg: #f1f2ee;
  --ql: #d69a00;
  --qat: #1d3fae;
  --cpa: #0f7a6a;
  --hq: #7a3db8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 22, 28, .05), 0 6px 24px rgba(20, 22, 28, .06);
  --header-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1014; --surface: #161920; --surface-2: #1d2129; --ink: #e8e9ec; --muted: #9aa1ad;
    --line: #2a2e38; --brand: #8aa6ff; --brand-ink: #0b1020; --brand-soft: #1b2442; --accent: #f5c542;
    --ok: #4cc38a; --code-bg: #1b1f27; --ql: #f5c542; --qat: #8aa6ff; --cpa: #4fd1b8; --hq: #c49bff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1014; --surface: #161920; --surface-2: #1d2129; --ink: #e8e9ec; --muted: #9aa1ad;
  --line: #2a2e38; --brand: #8aa6ff; --brand-ink: #0b1020; --brand-soft: #1b2442; --accent: #f5c542;
  --ok: #4cc38a; --code-bg: #1b1f27; --ql: #f5c542; --qat: #8aa6ff; --cpa: #4fd1b8; --hq: #c49bff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--header-h) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 16px; line-height: 1.7; word-break: keep-all; overflow-wrap: anywhere;
}
a { color: var(--brand); text-underline-offset: 3px; }
img { max-width: 100%; }
.wrap { width: min(1200px, 100% - 32px); margin-inline: auto; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50; height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner { height: 100%; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 800; letter-spacing: -.01em; white-space: nowrap; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--ink); color: var(--accent); font-weight: 900; font-size: 17px;
}
.site-nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a {
  display: flex; align-items: baseline; gap: 6px; padding: 8px 12px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-size: .925rem; white-space: nowrap;
}
.site-nav a b { color: var(--ink); font-weight: 800; letter-spacing: .02em; }
.site-nav a:hover { background: var(--surface-2); color: var(--ink); }
.site-nav a[aria-current="page"] { background: var(--ink); color: var(--bg); }
.site-nav a[aria-current="page"] b { color: var(--accent); }
@media (max-width: 960px) { .site-nav a span { display: none; } .site-nav a:last-child span { display: inline; } }
@media (max-width: 640px) {
  :root { --header-h: 104px; }
  .header-inner { flex-direction: column; align-items: stretch; justify-content: center; gap: 6px; }
  .site-nav { margin-left: -8px; margin-right: -16px; padding-right: 16px; }
  .site-nav a { padding: 6px 10px; }
}

/* ---------- common blocks ---------- */
.hero { padding: 72px 0 48px; }
.eyebrow { display: inline-flex; gap: 8px; align-items: center; font-size: .8rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.eyebrow::before { content: ""; width: 18px; height: 2px; background: var(--accent); }
h1, h2, h3, h4 { line-height: 1.3; letter-spacing: -.02em; }
.hero h1 { font-size: clamp(2.2rem, 5.5vw, 4rem); margin: 14px 0 16px; font-weight: 850; }
.hero h1 em { font-style: normal; background: linear-gradient(transparent 62%, color-mix(in srgb, var(--accent) 55%, transparent) 0); }
.lead { font-size: clamp(1.05rem, 2vw, 1.2rem); color: var(--muted); max-width: 46em; margin: 0 0 24px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 650; font-size: .95rem; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; }
.section { padding: 48px 0; }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.section-head h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin: 6px 0 0; }
.section-head p { margin: 0; color: var(--muted); max-width: 36em; }
.page-head { padding: 56px 0 24px; }
.page-head h1 { font-size: clamp(2rem, 4.5vw, 3rem); margin: 12px 0; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); }

/* license cards */
.license-card { position: relative; display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: inherit; overflow: hidden; transition: transform .15s ease, border-color .15s ease; }
.license-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--c, var(--brand)); }
a.license-card:hover { transform: translateY(-2px); border-color: var(--c); }
.license-card .abbr { font-size: 2rem; font-weight: 900; letter-spacing: .02em; color: var(--c); line-height: 1; }
.license-card h3 { margin: 0; font-size: 1.15rem; }
.license-card .en { margin: -6px 0 0; font-size: .85rem; color: var(--muted); }
.license-card p { margin: 0; color: var(--muted); font-size: .95rem; }
.license-card .target { margin-top: auto; padding-top: 12px; border-top: 1px dashed var(--line); font-size: .875rem; }
.license-card .target b { display: block; font-size: .75rem; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; width: fit-content; background: var(--surface-2); color: var(--muted); }
.tag.live { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.tag.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.c-ql { --c: var(--ql); } .c-qat { --c: var(--qat); } .c-cpa { --c: var(--cpa); } .c-hq { --c: var(--hq); }

/* level ladder */
.ladder { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.rung { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; position: relative; }
.rung .lv { font-size: .78rem; font-weight: 800; letter-spacing: .08em; color: var(--muted); }
.rung strong { display: block; margin: 4px 0 6px; font-size: 1.02rem; }
.rung p { margin: 0; font-size: .88rem; color: var(--muted); }
.rung.in-scope { border-color: color-mix(in srgb, var(--ql) 60%, var(--line)); background: color-mix(in srgb, var(--ql) 7%, var(--surface)); }
.rung .who { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 4px; }
.rung .who span { font-size: .72rem; font-weight: 800; padding: 1px 7px; border-radius: 6px; color: var(--c); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); }
@media (max-width: 860px) { .ladder { grid-template-columns: 1fr; } }

/* steps */
.steps { counter-reset: s; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); padding: 0; margin: 0; list-style: none; }
.steps li { counter-increment: s; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 18px 18px 18px; }
.steps li::before { content: counter(s, decimal-leading-zero); display: block; font-weight: 900; color: var(--accent); font-size: 1.1rem; margin-bottom: 6px; }
.steps li strong { display: block; margin-bottom: 4px; }
.steps li p { margin: 0; color: var(--muted); font-size: .92rem; }
.steps li .tag { margin-top: 10px; }

/* grade tiles */
.grade { display: flex; flex-direction: column; gap: 10px; }
.grade .num { font-size: 2.6rem; font-weight: 900; line-height: 1; }
.grade.live { border-color: color-mix(in srgb, var(--ql) 60%, var(--line)); }
.grade.live .num { color: var(--ql); }
.grade ul { margin: 0; padding-left: 1.1em; color: var(--muted); font-size: .94rem; }
.grade.soon { opacity: .8; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 12px; }
.kv div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.kv dt { font-size: .8rem; color: var(--muted); font-weight: 700; }
.kv dd { margin: 4px 0 0; font-size: 1.15rem; font-weight: 800; }
.kv dd small { font-weight: 500; color: var(--muted); font-size: .85rem; display: block; }

.chapters { columns: 2 320px; column-gap: 32px; padding-left: 1.3em; margin: 0; }
.chapters li { break-inside: avoid; padding: 4px 0; }

.notice { border-left: 4px solid var(--accent); background: var(--surface); padding: 16px 20px; border-radius: 0 12px 12px 0; color: var(--muted); }
.notice strong { color: var(--ink); }

/* license plate */
.license-plate {
  flex: none; width: 200px; aspect-ratio: 1.586; border-radius: 14px; padding: 16px;
  background: linear-gradient(135deg, #1a1d24, #2a2f3a); color: #fff; display: flex; flex-direction: column; justify-content: space-between;
  box-shadow: 0 10px 30px rgba(0,0,0,.18); position: relative; overflow: hidden;
}
.license-plate::after { content: ""; position: absolute; right: -30px; top: -30px; width: 120px; height: 120px; border-radius: 50%; background: radial-gradient(circle, rgba(242,183,5,.55), transparent 70%); }
.license-plate small { font-size: .62rem; letter-spacing: .14em; opacity: .75; font-weight: 700; }
.license-plate strong { font-size: 2.4rem; font-weight: 900; color: #f5c542; letter-spacing: .02em; line-height: 1; }

/* footer */
.site-footer { margin-top: 64px; border-top: 1px solid var(--line); padding: 32px 0 48px; color: var(--muted); font-size: .92rem; }
.footer-inner { display: flex; flex-wrap: wrap; gap: 16px 40px; justify-content: space-between; align-items: start; }
.footer-inner strong { color: var(--ink); }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.footer-links a { color: var(--muted); text-decoration: none; font-weight: 650; }
.footer-links a:hover { color: var(--ink); }
.footer-inner .small { flex-basis: 100%; }

/* ---------- textbook ---------- */
.reading-progress { position: fixed; top: var(--header-h); left: 0; right: 0; height: 3px; z-index: 49; pointer-events: none; }
.reading-progress span { display: block; height: 100%; width: 0; background: var(--accent); }
.book-hero { padding: 32px 0 36px; border-bottom: 1px solid var(--line); background: var(--surface); }
.crumbs { display: flex; gap: 8px; flex-wrap: wrap; font-size: .875rem; color: var(--muted); margin-bottom: 20px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }
.book-hero-row { display: flex; gap: 32px; align-items: center; }
.book-hero h1 { font-size: clamp(1.6rem, 3.6vw, 2.4rem); margin: 0 0 10px; }
.meta-chips { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-wrap: wrap; gap: 6px; }
.meta-chips li { font-size: .82rem; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
@media (max-width: 720px) { .book-hero-row { flex-direction: column; align-items: flex-start; gap: 20px; } .license-plate { width: 170px; } }

.book-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 48px; padding-top: 32px; }
.toc {
  position: sticky; top: calc(var(--header-h) + 16px); align-self: start;
  max-height: calc(100vh - var(--header-h) - 32px); overflow-y: auto; padding-right: 8px; font-size: .88rem;
  scrollbar-width: thin;
}
.toc-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 10px 10px; }
.toc-close { display: none; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc-list > li { margin-bottom: 2px; }
.toc-list ol { padding-left: 10px; margin: 2px 0 8px; border-left: 1px solid var(--line); margin-left: 10px; display: none; }
.toc-list > li.open ol { display: block; }
.toc a { display: block; padding: 5px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; line-height: 1.45; }
.toc a:hover { background: var(--surface-2); color: var(--ink); }
.toc a.toc-h2 { color: var(--ink); font-weight: 700; }
.toc a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.toc-fab, .toc-scrim { display: none; }

.prose { max-width: 780px; min-width: 0; font-size: 1.04rem; }
.prose h2.chapter {
  margin: 72px 0 20px; padding-top: 28px; border-top: 2px solid var(--ink); font-size: clamp(1.5rem, 3vw, 1.9rem);
  display: flex; flex-direction: column; gap: 6px;
}
.prose > h2.chapter:first-child { margin-top: 0; }
.chapter-label { font-size: .85rem; font-weight: 800; letter-spacing: .06em; color: var(--brand); }
.prose h3 { font-size: 1.32rem; margin: 48px 0 12px; }
.prose h4 { font-size: 1.08rem; margin: 32px 0 8px; }
.prose h3.exercise-title {
  background: color-mix(in srgb, var(--accent) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  padding: 12px 16px; border-radius: 12px; font-size: 1.15rem;
}
.prose h2, .prose h3, .prose h4 { position: relative; }
.anchor { position: absolute; left: -1.1em; color: var(--line); text-decoration: none; opacity: 0; font-weight: 400; }
.prose h3.exercise-title .anchor, .prose h2.chapter .anchor { display: none; }
h3:hover > .anchor, h4:hover > .anchor { opacity: 1; color: var(--muted); }
.prose p { margin: 0 0 16px; }
.prose strong { font-weight: 750; }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 16px; }
.prose li { margin: 4px 0; }
.prose li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.4em; }
.prose input[type="checkbox"] { width: 1.05em; height: 1.05em; margin-right: 8px; accent-color: var(--brand); vertical-align: -2px; }
.prose blockquote { margin: 20px 0; padding: 14px 18px; border-left: 4px solid var(--brand); background: var(--brand-soft); border-radius: 0 12px 12px 0; }
.prose blockquote p:last-child { margin-bottom: 0; }
.prose code { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; background: var(--code-bg); padding: 2px 6px; border-radius: 6px; }
.prose pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; overflow-x: auto; line-height: 1.6; margin: 0 0 20px; }
.prose pre code { background: none; padding: 0; font-size: .9rem; white-space: pre-wrap; word-break: break-word; }
.table-wrap { overflow-x: auto; margin: 0 0 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.prose table { border-collapse: collapse; width: 100%; font-size: .94rem; }
.prose th, .prose td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.prose th { background: var(--surface-2); font-weight: 750; white-space: nowrap; }
.prose tr:last-child td { border-bottom: 0; }
.prose td:first-child { font-weight: 650; }

@media (max-width: 1000px) {
  .book-layout { grid-template-columns: minmax(0, 1fr); }
  .toc {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); max-height: none; z-index: 70;
    background: var(--surface); border-right: 1px solid var(--line); padding: 16px 12px 32px; transform: translateX(-102%); transition: transform .2s ease;
  }
  .toc.open { transform: none; }
  .toc-close { display: block; border: 0; background: none; color: var(--ink); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; }
  .toc-fab {
    display: inline-flex; position: fixed; right: 16px; bottom: 16px; z-index: 60; gap: 6px;
    padding: 12px 18px; border-radius: 999px; border: 0; background: var(--ink); color: var(--bg); font: inherit; font-weight: 700; box-shadow: var(--shadow); cursor: pointer;
  }
  .toc-scrim:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(0,0,0,.35); }
  .anchor { display: none; }
}

@media print {
  .site-header, .site-footer, .toc, .toc-fab, .toc-scrim, .reading-progress, .book-hero .actions, .crumbs { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .book-layout { display: block; padding: 0; }
  .prose { max-width: none; }
  .prose h2.chapter { break-before: page; border-top: 0; }
  .prose pre, .table-wrap, .prose blockquote { break-inside: avoid; }
  .book-hero { border: 0; }
}
@media (max-width: 640px) { .prose table { min-width: 34em; } }
