/* 웹북 스타일시트 — 참고 사이트(dknife.github.io/PythonExpress)의 디자인 언어를 바탕으로 구성 */
:root {
  --bg: #F8F8F8;
  --bg-2: #EDEDED;
  --white: #FFFFFF;
  --text: #222222;
  --text-2: #313131;
  --text-light: #767676;
  --accent: #2E7D6B;       /* 포인트 컬러 */
  --cyan: #0693E3;
  --mint: #7BDCB5;
  --yellow: #FFF083;
  --border: #E4E4E4;
  --btn: #222222;
  --btn-hover: #383838;
  --radius: 8px;
  --radius-lg: 16px;
  --sidebar-w: 300px;
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ---- fixed top bar ---- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 54px;
  background: rgba(248,248,248,0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.4rem; z-index: 50;
}
.topbar .home {
  color: #fff; background: var(--btn);
  text-decoration: none; font-weight: 600;
  padding: 0.32rem 1rem; border-radius: var(--radius);
  font-size: 0.85rem; transition: background 0.3s ease;
}
.topbar .home:hover { background: var(--btn-hover); }
.topbar .home { flex: 0 0 auto; }
.topbar .book-title {
  font-weight: 800; letter-spacing: -0.02em;
  min-width: 0; flex: 0 1 auto;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.topbar .ch-indicator {
  font-size: 0.85rem; color: var(--text-light);
  min-width: 0; flex: 0 1 auto;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.nav-toggle {
  margin-left: auto; display: none;
  background: var(--btn); border: none;
  color: #fff; border-radius: var(--radius);
  padding: 0.35rem 0.9rem; cursor: pointer;
  font: inherit; font-size: 0.85rem;
  transition: background 0.3s ease;
}
.nav-toggle:hover { background: var(--btn-hover); }

/* ---- mobile nav backdrop (dims content behind the off-canvas TOC drawer) ---- */
.nav-backdrop {
  position: fixed; top: 54px; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.35);
  opacity: 0; visibility: hidden;
  transition: opacity 0.3s var(--ease);
  z-index: 39;
}
body.nav-open .nav-backdrop { opacity: 1; visibility: visible; }
@media (min-width: 901px) { .nav-backdrop { display: none; } }

/* ---- layout ---- */
.layout { display: flex; padding-top: 54px; }
.sidebar {
  position: fixed; top: 54px; bottom: 0; left: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 1.4rem 1rem 3rem;
  font-size: 0.88rem;
}
.content {
  margin-left: var(--sidebar-w);
  flex: 1; min-width: 0;
  max-width: 900px;
  padding: 3rem 3.4rem 5rem;
  background: var(--white);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* ---- sidebar nav ---- */
.nav-part {
  font-size: 0.7rem; font-weight: 800; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--accent);
  margin: 1.3rem 0 0.4rem; padding: 0 0.55rem;
}
.nav-ch-link {
  display: block; padding: 0.34rem 0.55rem; border-radius: var(--radius);
  color: var(--text-2); text-decoration: none; font-weight: 500;
  transition: background 0.3s ease, color 0.3s ease;
}
.nav-ch-link:hover { background: var(--bg-2); }
.nav-ch.current > .nav-ch-link {
  background: var(--btn); color: #fff; font-weight: 600;
}
.nav-ch.disabled > .nav-ch-link {
  color: var(--text-light); pointer-events: none; cursor: default;
}
.nav-num { color: var(--text-light); font-size: 0.76rem; margin-right: 0.2rem; font-weight: 700; }
.nav-ch.current .nav-num { color: var(--yellow); }
.nav-secs { margin: 0.3rem 0 0.6rem 0.9rem; border-left: 2px solid var(--bg-2); }
.nav-sec {
  display: block; padding: 0.22rem 0.75rem; color: var(--text-light);
  text-decoration: none; font-size: 0.83rem;
  transition: color 0.3s ease;
}
.nav-sec:hover, .nav-sec.active { color: var(--accent); }

/* ---- chapter head ---- */
.chapter-head { margin-bottom: 2.6rem; }
.chapter-head .ch-label {
  font-size: 0.8rem; font-weight: 800; letter-spacing: 0.16em;
  color: var(--accent);
  margin-bottom: 0.3rem;
}
.chapter-head h1 {
  font-size: 2.4rem; color: var(--text);
  font-weight: 800; letter-spacing: -0.03em; line-height: 1.25;
}
.chapter-head .ch-lead {
  margin-top: 0.6rem; color: var(--text-light); font-size: 1.02rem;
}
.chapter-head::after {
  content: ''; display: block; width: 56px; height: 4px;
  background: var(--accent); border-radius: 2px; margin-top: 1rem;
}

/* ---- headings ---- */
h2 {
  color: var(--text); font-size: 1.6rem; font-weight: 700;
  letter-spacing: -0.02em; line-height: 1.25;
  margin: 3rem 0 1.1rem;
  scroll-margin-top: 74px;
}
h2::after {
  content: ''; display: block; width: 34px; height: 3px;
  background: var(--accent); border-radius: 2px; margin-top: 0.45rem;
}
h3 {
  color: var(--text-2); font-size: 1.14rem; font-weight: 700;
  letter-spacing: -0.01em; line-height: 1.3;
  margin: 2.2rem 0 0.8rem;
  padding-left: 0.7rem; border-left: 3px solid var(--accent);
  scroll-margin-top: 74px;
}
h4 {
  color: var(--text-2); font-size: 1rem; font-weight: 700;
  margin: 1.6rem 0 0.5rem;
}
p { margin: 0 0 1rem; color: var(--text-2); }
strong { color: var(--text); }
p.source-note { font-size: 0.82rem; color: var(--text-light); margin-top: -0.6rem; }
p.fig-caption-standalone { text-align: center; color: var(--text-light); font-size: 0.9rem; }

/* ---- code ---- */
pre, code { font-family: 'D2Coding', Consolas, 'JetBrains Mono', monospace; }
code {
  background: var(--bg-2); border-radius: 4px; padding: 0.08em 0.35em;
  font-size: 0.86em; color: var(--text);
}
pre { margin: 1.2rem 0; }
pre code { background: none; padding: 0; font-size: 0.84rem; color: inherit; white-space: pre; }
.content pre.line-numbers,
.content pre.line-numbers > code[class*="language-"] {
  font-family: 'D2Coding', Consolas, 'JetBrains Mono', monospace;
  font-size: 0.84rem;
}
pre.line-numbers {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
}
.listing { margin: 1.2rem 0; }

/* ---- boxes ---- */
.box {
  border-radius: var(--radius-lg); padding: 1.15rem 1.35rem; margin: 1.6rem 0;
  background: var(--bg);
}
.box p:last-child { margin-bottom: 0; }
.box .chip {
  display: inline-block;
  font-size: 0.7rem; font-weight: 800; color: #fff;
  padding: 0.14rem 0.65rem; border-radius: 20px; margin-bottom: 0.55rem;
  letter-spacing: 0.04em;
}
.box.keypoint { background: var(--yellow); }
.box.keypoint .chip { background: var(--btn); }
.box.keypoint p { color: var(--text); }
.box.caution { background: #FFF0EA; }
.box.caution .chip { background: #D9531E; }
.box.note { background: #EAF5FC; }
.box.note .chip { background: var(--cyan); }

/* ---- lists ---- */
ul, ol { margin: 0 0 1rem 1.5rem; color: var(--text-2); }
li { margin-bottom: 0.45rem; }
li::marker { color: var(--accent); font-weight: 700; }
li > pre, li > .listing, li > .center, li > .table-wrap, li > .box { margin-top: 0.6rem; }
ol.steps > li { margin-bottom: 1.1rem; }
ol.steps { counter-reset: step; }
ol.steps > li::marker { font-weight: 800; }

/* ---- figures & tables ---- */
figure.fig { margin: 1.8rem 0; text-align: center; }
figure.fig img, img.gfx { max-width: 100%; height: auto; border-radius: var(--radius); }
figure.fig figcaption {
  text-align: center; font-size: 0.84rem; color: var(--text-light);
  margin: 0.6rem 0 0;
}
.center { text-align: center; margin: 1.4rem 0; }
.center img { margin: 0 auto 0.4rem; max-width: 100%; border-radius: var(--radius); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.table-wrap { margin: 1.6rem 0; overflow-x: auto; }
.table-wrap table {
  border-collapse: collapse; margin: 0 auto; min-width: 60%;
  font-size: 0.9rem;
  background: var(--white);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.table-wrap th {
  background: var(--btn); color: #fff; font-weight: 600;
  padding: 0.55rem 1rem; text-align: left; font-size: 0.85rem;
}
.table-wrap td { padding: 0.5rem 1rem; border-bottom: 1px solid var(--bg-2); color: var(--text-2); }
.table-wrap tr:last-child td { border-bottom: none; }

/* ---- pager ---- */
.pager-row {
  display: flex; justify-content: space-between; margin-top: 4rem;
  padding-top: 1.6rem; border-top: 1px solid var(--border);
  gap: 0.8rem; flex-wrap: wrap;
}
.pager {
  display: inline-flex; align-items: center; min-height: 48px;
  padding: 12px 22px; border-radius: var(--radius);
  background: var(--btn); color: #fff;
  text-decoration: none; font-weight: 600; font-size: 0.92rem;
  line-height: 1.35; text-align: center;
  transition: background 0.3s ease, transform 0.3s var(--ease);
  flex: 1 1 auto; max-width: 100%;
}
.pager.next { justify-content: flex-end; margin-left: auto; }
.pager:hover { background: var(--btn-hover); transform: translateY(-2px); }

/* ---- home / index page ---- */
.home-hero { text-align: center; padding: 2rem 0 1rem; }
.home-hero h1 { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.03em; }
.home-hero p { color: var(--text-light); margin-top: 0.8rem; font-size: 1.05rem; }
.home-cta {
  display: inline-flex; align-items: center; height: 50px; margin-top: 1.4rem;
  padding: 0 28px; border-radius: var(--radius);
  background: var(--accent); color: #fff; text-decoration: none;
  font-weight: 700; font-size: 1rem;
}
.chapter-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem; margin: 2.4rem 0;
}
.chapter-card {
  display: block; padding: 1.2rem 1.3rem; border-radius: var(--radius-lg);
  background: var(--white); border: 1px solid var(--border);
  text-decoration: none; color: inherit;
  transition: box-shadow 0.3s ease, transform 0.3s var(--ease);
}
.chapter-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,0.1); transform: translateY(-2px); }
.chapter-card.disabled { opacity: 0.55; pointer-events: none; }
.chapter-card .num { font-size: 0.76rem; font-weight: 800; color: var(--accent); letter-spacing: 0.08em; }
.chapter-card .title { margin-top: 0.35rem; font-weight: 700; font-size: 1.05rem; }
.chapter-card .status { margin-top: 0.5rem; font-size: 0.78rem; color: var(--text-light); }

/* ---- responsive ---- */
html, body { overflow-x: hidden; max-width: 100%; }
.table-wrap, pre.line-numbers { -webkit-overflow-scrolling: touch; }

@media (max-width: 1024px) {
  .content { padding: 2.2rem 2rem 4rem; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.3s var(--ease);
    z-index: 40; box-shadow: 4px 0 24px rgba(0,0,0,0.14); background: var(--white); }
  body.nav-open .sidebar { transform: translateX(0); }
  .content { margin-left: 0; padding: 1.6rem 1.2rem 4rem; }
  .nav-toggle { display: block; }
  .topbar .ch-indicator { display: none; }
  .chapter-head h1 { font-size: 1.8rem; }
  h2 { font-size: 1.35rem; }
  body.nav-open { overflow: hidden; }
}
@media (max-width: 560px) {
  .topbar { padding: 0 0.9rem; gap: 0.6rem; }
  .topbar .book-title { font-size: 0.92rem; }
  .content { padding: 1.3rem 1rem 3.2rem; border-radius: 0; }
  .chapter-head h1 { font-size: 1.5rem; }
  .pager-row { flex-direction: column; }
  .pager { width: 100%; justify-content: center; }
  .pager.next { margin-left: 0; }
  .table-wrap table { min-width: 100%; font-size: 0.82rem; }
  pre.line-numbers { padding: 0.8rem 0.9rem; }
}

/* ---- interactive python cells (Pyodide) ---- */
.chapter-actions { display:flex; justify-content:flex-end; margin: 0 0 1.6rem; gap:0.6rem; }
.colab-btn {
  display:inline-flex; align-items:center; gap:0.4rem;
  background:#F9AB00; color:#1a1a1a; font-weight:700; font-size:0.85rem;
  padding:0.45rem 1rem; border-radius:6px; text-decoration:none;
  border:none; cursor:pointer;
}
.colab-btn:hover { background:#e69d00; }

.pycell { margin: 1.3rem 0; border:1px solid var(--border); border-radius: var(--radius); overflow:hidden; background:var(--bg); }
.pycell-toolbar { display:flex; align-items:center; gap:0.5rem; padding:0.4rem 0.7rem; background:var(--bg-2); border-bottom:1px solid var(--border); }
.pycell-lang { font-size:0.72rem; font-weight:800; color:var(--text-light); letter-spacing:0.06em; text-transform:uppercase; margin-right:auto; }
.pycell-btn { border:none; border-radius:6px; padding:0.28rem 0.75rem; font-size:0.82rem; font-weight:700; cursor:pointer; transition:background .2s ease; font-family:inherit; }
.pycell-run { background:var(--accent); color:#fff; }
.pycell-run:hover { background:#245c50; }
.pycell-run:disabled { opacity:.55; cursor:default; }
.pycell-reset { background:transparent; color:var(--text-light); border:1px solid var(--border); }
.pycell-reset:hover { background:var(--white); color:var(--text); }
.pycell-editor .CodeMirror {
  font-family:'D2Coding', Consolas, 'JetBrains Mono', monospace;
  font-size:0.86rem; line-height:1.55; height:auto;
}
.pycell-output { border-top:1px dashed var(--border); padding:0; font-size:0.85rem; background:#fff; display:none; }
.pycell-output.show { display:block; padding:0.8rem 0.9rem; }
.pycell-status { color:var(--text-light); font-style:italic; }
.pycell-stdout { background:#0d1117; color:#c9d1d9; padding:0.6rem 0.8rem; border-radius:6px; overflow-x:auto; white-space:pre-wrap; margin:0 0 0.6rem; font-family:'D2Coding',Consolas,monospace; }
.pycell-error { background:#FFF0EA; color:#B3261E; padding:0.6rem 0.8rem; border-radius:6px; overflow-x:auto; white-space:pre-wrap; margin:0; font-family:'D2Coding',Consolas,monospace; }
.pycell-result { overflow-x:auto; margin:0 0 0.6rem; }
.pycell-result table { border-collapse:collapse; font-size:0.82rem; }
.pycell-result th, .pycell-result td { border:1px solid var(--border); padding:0.3rem 0.6rem; white-space:nowrap; }
.pycell-result th { background:var(--bg-2); }
.pycell-fig { max-width:100%; display:block; margin:0 0 0.6rem; border-radius:6px; }

@media (max-width: 560px) {
  .chapter-actions { justify-content: stretch; }
  .colab-btn { width:100%; justify-content:center; }
}

/* ---- inline text links (URLs mentioned in the book text) ---- */
.content p a, .content li a, .content em a, .fig-caption-standalone a, .source-note a {
  color: var(--accent); text-decoration: underline; text-underline-offset: 2px;
  word-break: break-all;
}
.content p a:hover, .content li a:hover, .content em a:hover,
.fig-caption-standalone a:hover, .source-note a:hover { color: #245c50; }

/* ---- clickable link box (code listings that are just a bare URL) ---- */
.listing.url-link { padding: 0; }
.url-link-anchor {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.7rem 0.9rem; background: var(--bg); border-radius: var(--radius);
  color: var(--accent); font-weight: 600; text-decoration: none;
  font-family: 'D2Coding', Consolas, 'JetBrains Mono', monospace; font-size: 0.9rem;
  word-break: break-all;
}
.url-link-anchor:hover { background: var(--bg-2); text-decoration: underline; }

/* ---- copy button (pycell toolbar + static code listings) ---- */
.pycell-copy { background: transparent; color: var(--text-light); border: 1px solid var(--border); }
.pycell-copy:hover { background: var(--white); color: var(--text); }
.pycell-copy:disabled { opacity: .7; cursor: default; }

.listing-static { position: relative; }
.static-copy-btn {
  position: absolute; top: 0.5rem; right: 0.5rem;
  border: 1px solid var(--border); border-radius: 6px;
  background: rgba(255,255,255,0.9); color: var(--text-light);
  font-size: 0.76rem; font-weight: 700; padding: 0.22rem 0.6rem;
  cursor: pointer; opacity: 0; transition: opacity .15s ease, background .15s ease;
}
.listing-static:hover .static-copy-btn, .static-copy-btn:focus { opacity: 1; }
.static-copy-btn:hover { background: var(--white); color: var(--text); }
.static-copy-btn:disabled { opacity: 1; cursor: default; }

@media (hover: none) {
  .static-copy-btn { opacity: 1; }
}
