* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--sans); background: var(--bg); color: var(--fg); font-size: 16px; line-height: 1.7; }
a { color: var(--accent); }
code, pre, textarea.code { font-family: var(--mono); font-size: 14px; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.spacer { flex: 1; }

#app { display: flex; min-height: 100vh; }

/* ------------------------------------------------ 왼쪽 목차 */
#nav {
  width: var(--nav-w); flex: none; background: var(--pane); border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 16px 14px 40px;
}
.brand { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.brand-home { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; flex: 1; min-width: 0; }
.brand-logo { font-size: 30px; line-height: 1; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-weight: 800; font-size: 17px; line-height: 1.3; }
.brand-sub { font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.icon-btn { background: transparent; border: 1px solid var(--line); color: var(--fg); border-radius: 8px; width: 34px; height: 34px; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

.role-switch { display: flex; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.role-switch button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 6px 4px; border-radius: 8px; font-size: 14px; }
.role-switch button.on { background: var(--accent); color: var(--accent-fg); font-weight: 700; }
.progress { height: 6px; background: var(--card2); border-radius: 4px; overflow: hidden; margin-bottom: 14px; }
#progBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s; }

#toc .ch { margin-bottom: 6px; }
#toc .ch-title { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 8px; font-weight: 700; font-size: 14.5px; cursor: pointer; color: var(--fg); text-decoration: none; }
#toc .ch-title:hover { background: var(--card2); }
#toc .ch-no { color: var(--accent); font-family: var(--mono); font-size: 12px; }
#toc .secs { margin: 2px 0 6px 18px; border-left: 2px solid var(--line); }
#toc .sec { display: block; padding: 4px 10px; font-size: 13.5px; color: var(--muted); text-decoration: none; border-left: 2px solid transparent; margin-left: -2px; }
#toc .sec:hover { color: var(--fg); }
#toc .sec.on { color: var(--accent); border-left-color: var(--accent); font-weight: 700; }
#toc .sec.done::after { content: ' ✓'; color: var(--ok); }

/* ------------------------------------------------ 본문 */
#main { flex: 1; min-width: 0; }
#topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 10px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
#menuBtn { display: none; }
#crumb { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#doc { max-width: 920px; margin: 0 auto; padding: 28px 28px 120px; }

.btn { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-fg); border-radius: 8px; padding: 6px 14px; font-size: 14px; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

h1.sec-title { font-size: 30px; line-height: 1.3; margin: 4px 0 6px; }
.sec-meta { color: var(--muted); font-size: 14px; display: flex; gap: 14px; flex-wrap: wrap; }
.badge { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 10px; font-size: 12.5px; font-weight: 700; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin: 18px 0; }
.box h3 { margin: 0 0 8px; font-size: 16px; }
.goals ul { margin: 0; padding-left: 20px; }
.flow table { width: 100%; }
#doc h2 { font-size: 22px; margin: 36px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--line); }
#doc h2 .num { color: var(--accent); margin-right: 6px; }
#doc table.t { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 15px; }
#doc table.t th, #doc table.t td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
#doc table.t th { background: var(--card2); }
#doc table.t caption { caption-side: bottom; color: var(--muted); font-size: 13px; padding-top: 6px; }
#doc :not(pre) > code { background: var(--code-bg); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-size: .9em; }
mark { background: var(--accent2-soft); color: inherit; padding: 0 2px; border-radius: 3px; }
figure.fig { margin: 18px 0; text-align: center; }
figure.fig svg, figure.fig img { max-width: min(100%, 640px); max-height: 420px; height: auto; }
figure.fig figcaption { color: var(--muted); font-size: 13.5px; margin-top: 6px; }

.callout { border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 var(--radius) var(--radius) 0; padding: 10px 16px; margin: 16px 0; }
.callout .ct { font-weight: 800; margin-bottom: 2px; }
.callout.tip { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.callout.warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.callout.more { border-color: var(--more); background: color-mix(in srgb, var(--more) 10%, transparent); }
.callout p:first-child { margin-top: 0; } .callout p:last-child { margin-bottom: 0; }

/* 코드 블록 */
.code { border: 1px solid var(--line); border-radius: var(--radius); margin: 16px 0; overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 14px; border-bottom: 1px solid var(--line); background: var(--card2); font-size: 13.5px; }
.code-head .ttl { font-weight: 700; flex: 1; }
.code pre { margin: 0; padding: 12px 14px; overflow-x: auto; line-height: 1.55; }
.code .desc { padding: 8px 14px; border-top: 1px dashed var(--line); font-size: 14.5px; color: var(--muted); }
.out { margin: 0; background: var(--term-bg); color: var(--term-fg); padding: 10px 14px; font-family: var(--mono); font-size: 13.5px; white-space: pre-wrap; max-height: 360px; overflow: auto; }
.out .err { color: #ff8a80; } .out .sys { color: #7fb4ff; }
.out-frame { width: 100%; height: 320px; border: 0; background: #fff; display: block; }
.stdin-row { display: flex; gap: 8px; align-items: center; padding: 6px 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.stdin-row textarea { flex: 1; min-height: 30px; height: 30px; resize: vertical; font-family: var(--mono); font-size: 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); padding: 4px 8px; }

/* 하이라이트 */
.hl-k { color: var(--accent); font-weight: 600; } .hl-s { color: #2e8b57; } .hl-n { color: #b5532d; } .hl-c { color: var(--muted); font-style: italic; } .hl-f { color: #8250df; }
:root[data-theme="dark"] .hl-s { color: #7ee2a8; } :root[data-theme="dark"] .hl-n { color: #f0a070; } :root[data-theme="dark"] .hl-f { color: #c4a5ff; }

/* 실습 */
.practice { border: 1px solid var(--line); border-left: 4px solid var(--accent2); background: var(--card); border-radius: var(--radius); margin: 18px 0; overflow: hidden; }
.practice .p-head { display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.practice .p-head .ttl { font-weight: 800; flex: 1; }
.practice .lv { color: var(--accent2); letter-spacing: 1px; }
.practice .p-body { padding: 4px 16px 12px; }
.practice textarea.code { width: 100%; min-height: 180px; border: 1px solid var(--line); border-radius: 8px; background: var(--code-bg); color: var(--fg); padding: 10px 12px; line-height: 1.55; resize: vertical; tab-size: 4; }
.practice .p-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.practice details { margin: 6px 0; }
.practice summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14.5px; }

/* 퀴즈 */
.quiz { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 14px 18px; margin: 14px 0; }
.quiz .q { font-weight: 700; margin-bottom: 8px; }
.quiz .q pre { font-weight: 400; background: var(--code-bg); padding: 8px 12px; border-radius: 6px; }
.quiz label { display: block; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; margin: 5px 0; cursor: pointer; }
.quiz label:hover { border-color: var(--accent); }
.quiz label.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.quiz label.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.quiz input { margin-right: 8px; }
.quiz .ex { margin-top: 8px; font-size: 14.5px; color: var(--muted); }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); }
.pager a { flex: 1; text-decoration: none; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; background: var(--card); color: var(--fg); }
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--muted); }
.pager .next { text-align: right; }
.done-row { text-align: center; margin-top: 26px; }

/* 홈 */
.hero { padding: 30px 30px 26px; border-radius: 16px; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--accent2))); color: #fff; margin-bottom: 26px; }
.hero h1 { margin: 6px 0; font-size: 34px; line-height: 1.25; }
.hero p { margin: 0; opacity: .92; }
.hero .hero-icon { font-size: 44px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card { display: block; text-decoration: none; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .no { color: var(--accent); font-family: var(--mono); font-size: 13px; }
.card h3 { margin: 4px 0 6px; font-size: 18px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }

body.role-student .teacher-only { display: none !important; }
body.role-teacher .student-only { display: none !important; }

@media (max-width: 900px) {
  #nav { position: fixed; z-index: 20; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.25); }
  body.nav-open #nav { transform: none; }
  #menuBtn { display: inline-block; }
  #topbar { padding: 8px 16px; }
  #doc { padding: 20px 16px 100px; }
  h1.sec-title { font-size: 24px; }
  .hero { padding: 22px 18px; } .hero h1 { font-size: 26px; }
}
@media print {
  #nav, #topbar, .p-actions, .code-head button { display: none !important; }
  #doc { max-width: none; }
}

/* 문제 형식 · 시험 */
.quiz .pts { color: var(--muted); font-weight: 400; font-size: 13px; }
.quiz .ox-row { display: flex; gap: 10px; }
.quiz .ox-row label { flex: 1; text-align: center; font-size: 22px; font-weight: 800; }
.quiz .ox-row input { display: none; }
.quiz .ox-row label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.quiz .short-row { display: flex; gap: 8px; }
.quiz .short-row input { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font: inherit; background: var(--card); color: var(--fg); }
.quiz .short-row input.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.quiz .short-row input.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.quiz textarea.code { width: 100%; min-height: 120px; border: 1px solid var(--line); border-radius: 8px; background: var(--code-bg); color: var(--fg); padding: 10px 12px; resize: vertical; }
.exam-bar { position: sticky; top: 56px; z-index: 4; display: flex; align-items: center; gap: 10px; padding: 10px 16px; margin: 18px 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); font-weight: 700; }
.exam-timer { font-family: var(--mono); color: var(--accent); }
.exam .quiz label:has(input:checked) { border-color: var(--accent); }
.exam-acts { display: flex; gap: 10px; justify-content: center; margin: 24px 0; }
.exam-result { text-align: center; padding: 22px; border: 2px solid var(--accent); border-radius: var(--radius); background: var(--accent-soft); }
.exam-result .score { font-size: 56px; font-weight: 900; color: var(--accent); line-height: 1.1; }
.exam-result .score small { font-size: 20px; }
.exam-result .pass { color: var(--ok); } .exam-result .fail { color: var(--danger); }
.exam-result .hist { color: var(--muted); font-size: 13.5px; margin-top: 6px; }

.out .out-img { display: block; max-width: 100%; margin: 8px 0; background: #fff; border-radius: 6px; }
.slide .out .out-img { max-height: 200px; }
