@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css');

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #101018;
  --bg2: #181828;
  --bg3: #222238;
  --text: #d8d8e8;
  --text2: #8888a8;
  --accent: #7b6cf6;
  --accent-light: #a89cff;
  --green: #38d9a9;
  --orange: #ffa94d;
  --red: #ff6b6b;
  --blue: #4dabf7;
  --border: #2a2a42;
  --max-w: 760px;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.95;
  font-size: 1.18rem;
  word-break: keep-all;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.container { max-width: var(--max-w); margin: 0 auto; padding: 1.5rem; }

header {
  background: rgba(16,16,24,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
header .container { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.5rem; }
header .logo { color: #fff; text-decoration: none; font-weight: 700; font-size: 1rem; display: flex; align-items: center; gap: .3rem; }
header .logo-home { font-size: .75rem; color: var(--text2); font-weight: 400; }
header nav a { margin-left: 1.2rem; color: var(--text2); font-size: .88rem; text-decoration: none; }
header nav a:hover { color: var(--accent-light); }

/* ── Typography ── */
h1 {
  font-size: 2rem;
  margin: 1.8rem 0 .8rem;
  color: #fff;
  font-weight: 700;
  line-height: 1.35;
}
h2 {
  font-size: 1.5rem;
  margin: 2.5rem 0 .7rem;
  color: var(--accent-light);
  font-weight: 700;
  padding-bottom: .45rem;
  border-bottom: 2px solid var(--bg3);
}
h3 {
  font-size: 1.25rem;
  margin: 1.6rem 0 .4rem;
  color: var(--green);
  font-weight: 600;
}
p {
  margin: .7rem 0;
  color: var(--text);
  font-size: 1.18rem;
}
strong { color: #fff; font-weight: 600; }
em { color: var(--accent-light); font-style: normal; }

blockquote {
  border-left: 3px solid var(--accent);
  padding: .7rem 1.2rem;
  margin: 1.2rem 0;
  background: var(--bg2);
  border-radius: 0 10px 10px 0;
  color: var(--text2);
  font-size: .95rem;
}

/* ── Links ── */
a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Code & Diagrams ── */
pre {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem 1.4rem;
  overflow-x: auto;
  margin: 1.2rem 0;
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--text);
}
code {
  font-family: 'SF Mono', 'Fira Code', 'Menlo', monospace;
  font-size: .88em;
}
p code, li code {
  background: var(--bg3);
  padding: .12rem .45rem;
  border-radius: 5px;
  font-size: .88em;
  color: var(--accent-light);
}

/* ── Diagram (visual code blocks) ── */
.diagram {
  background: linear-gradient(145deg, var(--bg2), var(--bg3));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.4rem 1.6rem;
  margin: 1.4rem 0;
  overflow-x: auto;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: .98rem;
  line-height: 1.5;
  color: var(--green);
  position: relative;
}
.diagram::before {
  content: attr(data-label);
  position: absolute;
  top: .5rem;
  right: .8rem;
  font-size: .7rem;
  color: var(--text2);
  font-family: 'Pretendard', sans-serif;
  background: var(--bg);
  padding: .15rem .5rem;
  border-radius: 4px;
}
.diagram .hl { color: var(--orange); }

/* ── Flow diagram ── */
.flow {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin: 1.4rem 0;
}
.flow-step {
  display: flex;
  align-items: flex-start;
  gap: .8rem;
  padding: .6rem 0;
}
.flow-icon {
  width: 36px; height: 36px;
  background: var(--bg3);
  border: 2px solid var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem;
  flex-shrink: 0;
  color: var(--accent-light);
}
.flow-arrow {
  text-align: center;
  color: var(--text2);
  font-size: .8rem;
  padding: .2rem 0 .2rem 1rem;
}
.flow-text { font-size: .95rem; }
.flow-text strong { color: #fff; }
.flow-text small { color: var(--text2); font-size: .85rem; }

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.2rem 0;
  font-size: .92rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
th {
  background: var(--bg3);
  color: var(--accent-light);
  text-align: left;
  padding: .7rem 1rem;
  font-weight: 600;
  font-size: .88rem;
}
td {
  padding: .7rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 1.1rem;
}
tr:hover td { background: rgba(123,108,246,.05); }

/* ── Lists ── */
ul, ol { margin: .7rem 0 .7rem 1.4rem; }
li {
  margin: .4rem 0;
  font-size: 1.15rem;
  line-height: 1.85;
}
li::marker { color: var(--accent); }

/* ── Cards ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin: 1.2rem 0;
}
.card h3 { margin-top: 0; }

/* Highlight card (for key concepts) */
.highlight-card {
  background: linear-gradient(135deg, rgba(123,108,246,.08), rgba(56,217,169,.05));
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 1.3rem 1.5rem;
  margin: 1.5rem 0;
}
.highlight-card p { margin: .3rem 0; }

/* ── Part cards (index) ── */
.part-grid { display: grid; gap: .8rem; margin: 1.5rem 0; }
.part-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem 1.4rem;
  text-decoration: none;
  color: var(--text);
  transition: all .2s;
  display: block;
}
.part-card:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; box-shadow: 0 4px 20px rgba(123,108,246,.12); }
.part-card .part-num { font-size: .75rem; color: var(--accent-light); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.part-card .part-title { font-size: 1.05rem; color: #fff; margin: .25rem 0; font-weight: 700; }
.part-card .part-desc { font-size: .85rem; color: var(--text2); line-height: 1.5; }
.part-card .part-chapters { font-size: .78rem; color: var(--text2); margin-top: .4rem; }
.part-card .progress-bar { height: 3px; background: var(--bg3); border-radius: 2px; margin-top: .6rem; overflow: hidden; }
.part-card .progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s; }

/* ── Part Hero ── */
.part-hero {
  text-align: center;
  padding: 3rem 1.5rem 2rem;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
}
.part-hero-inner { max-width: 600px; margin: 0 auto; }
.part-hero-icon { font-size: 3rem; margin-bottom: .5rem; }
.part-hero-eyebrow {
  font-size: .75rem; font-weight: 700; color: var(--accent-light);
  letter-spacing: .12em; text-transform: uppercase; margin-bottom: .4rem;
}
.part-hero-title {
  font-size: 2rem; font-weight: 800; color: #fff;
  letter-spacing: -.02em; line-height: 1.2; margin: 0;
}
.part-hero-desc { font-size: 1rem; color: var(--text2); margin-top: .5rem; }

/* ── Chapter TOC ── */
.chapter-toc { margin: 2rem 0 1.5rem; }
.chapter-toc-title {
  font-size: 1.1rem; font-weight: 700; color: #fff;
  border: none; padding: 0; margin: 0 0 .8rem;
}
.chapter-toc-list { display: flex; flex-direction: column; gap: .4rem; }

.chapter-btn {
  display: flex; align-items: center; gap: .8rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: .85rem 1.2rem;
  cursor: pointer; font-family: inherit;
  text-align: left; transition: all .2s; width: 100%;
}
.chapter-btn:hover { border-color: var(--accent); background: var(--bg3); }
.chapter-btn.active { border-color: var(--accent); background: rgba(123,108,246,.1); }
.ch-btn-num {
  font-size: .72rem; font-weight: 700; color: var(--accent-light);
  background: var(--bg3); padding: .25rem .6rem; border-radius: 6px;
  white-space: nowrap; flex-shrink: 0;
}
.chapter-btn.active .ch-btn-num { background: var(--accent); color: #fff; }
.ch-btn-title { font-size: .92rem; font-weight: 500; color: var(--text); }
.chapter-btn.active .ch-btn-title { color: #fff; font-weight: 600; }

/* ── Chapter nav (compact, shown inside chapter) ── */
.chapter-nav {
  display: flex; flex-wrap: wrap; gap: .4rem;
  margin: 1.5rem 0; padding: .6rem;
  background: var(--bg2); border-radius: 10px; border: 1px solid var(--border);
}

/* ── Chapter content ── */
.chapter { display: none; animation: fadeIn .3s ease; }
.chapter.active { display: block; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Summary box ── */
.summary-box {
  background: var(--bg2);
  border-left: 4px solid var(--green);
  border-radius: 0 10px 10px 0;
  padding: 1.3rem 1.5rem;
  margin: 2rem 0;
}
.summary-box h3 { color: var(--green); margin-top: 0; font-size: 1rem; }
.summary-box li { font-size: .93rem; }

/* ── Collapsible ── */
details {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 1rem 0;
}
details summary {
  padding: .9rem 1.2rem;
  cursor: pointer;
  font-weight: 600;
  color: var(--orange);
  font-size: .95rem;
}
details summary:hover { color: var(--accent-light); }
details[open] summary { border-bottom: 1px solid var(--border); }
details .detail-content { padding: 1rem 1.2rem; }

/* ── Footer nav ── */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 3rem 0 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.page-nav a {
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: .7rem 1.3rem;
  border-radius: 8px;
  font-size: .9rem;
  transition: all .2s;
}
.page-nav a:hover { border-color: var(--accent); text-decoration: none; }

/* ── Buttons ── */
.ask-btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: .7rem 1.4rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: .95rem;
  margin: .8rem 0;
  text-decoration: none;
  transition: all .2s;
}
.ask-btn:hover { opacity: .9; text-decoration: none; transform: translateY(-1px); }

/* ── Index Page (Apple Style) ── */
.idx-hero {
  text-align: center;
  padding: 5rem 1.5rem 3.5rem;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
}
.idx-hero-inner { max-width: 600px; margin: 0 auto; }
.idx-hero-eyebrow {
  font-size: .8rem; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--accent-light); margin-bottom: .8rem;
}
.idx-hero-title {
  font-size: 3rem; font-weight: 800; color: #fff;
  letter-spacing: -.03em; line-height: 1.15; margin: 0;
}
.idx-hero-sub {
  font-size: 1.2rem; color: var(--text2); margin-top: .6rem; font-weight: 400;
}
.idx-hero-stats {
  display: flex; justify-content: center; align-items: center;
  gap: 1.2rem; margin-top: 2rem;
}
.idx-stat { text-align: center; }
.idx-stat-num { display: block; font-size: 1.8rem; font-weight: 800; color: #fff; }
.idx-stat-label { font-size: .78rem; color: var(--text2); font-weight: 500; }
.idx-stat-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--border); }
.idx-hero-cta {
  display: inline-block; margin-top: 2rem;
  background: var(--accent); color: #fff; padding: .85rem 2.5rem;
  border-radius: 50px; font-size: 1rem; font-weight: 600;
  text-decoration: none; transition: all .25s;
}
.idx-hero-cta:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(123,108,246,.35); text-decoration: none; }

.idx-container { max-width: 900px; margin: 0 auto; padding: 0 1.5rem 3rem; }

.idx-section { margin: 3.5rem 0; }
.idx-section-title {
  font-size: 1.6rem; font-weight: 800; color: #fff;
  border: none; padding: 0; margin: 0 0 .3rem; letter-spacing: -.01em;
}
.idx-section-desc { font-size: .95rem; color: var(--text2); margin: 0 0 1.5rem; }

.idx-grid {
  display: grid; grid-template-columns: 1fr; gap: .7rem;
}

.idx-card {
  display: flex; align-items: flex-start; gap: 1.2rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.3rem 1.5rem;
  text-decoration: none; color: var(--text); transition: all .25s;
}
.idx-card:hover {
  border-color: var(--accent); transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0,0,0,.3); text-decoration: none;
}
.idx-card-icon { font-size: 2rem; flex-shrink: 0; margin-top: .1rem; }
.idx-card-body { flex: 1; min-width: 0; }
.idx-card-num {
  font-size: .7rem; font-weight: 700; color: var(--accent-light);
  letter-spacing: .1em; text-transform: uppercase;
}
.idx-card-title {
  font-size: 1.1rem; font-weight: 700; color: #fff; margin: .15rem 0;
  line-height: 1.35;
}
.idx-card-desc { font-size: .85rem; color: var(--text2); line-height: 1.5; }
.idx-card-meta { font-size: .75rem; color: var(--text2); margin-top: .4rem; }
.idx-card .progress-bar {
  height: 2px; background: var(--bg3); border-radius: 1px;
  margin-top: .6rem; overflow: hidden;
}
.idx-card .progress-fill { height: 100%; background: var(--accent); border-radius: 1px; transition: width .3s; }

/* Glossary banner */
.idx-glossary-banner {
  display: flex; align-items: center; gap: 1.2rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.5rem 2rem; margin-top: 3rem;
}
.idx-glossary-icon { font-size: 2.2rem; flex-shrink: 0; }
.idx-glossary-body { flex: 1; }
.idx-glossary-body h3 { font-size: 1.05rem; color: #fff; margin: 0; font-weight: 700; }
.idx-glossary-body p { font-size: .88rem; color: var(--text2); margin: .2rem 0 0; }
.idx-glossary-btn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--accent-light);
  padding: .6rem 1.4rem; border-radius: 10px; font-size: .88rem; font-weight: 600;
  text-decoration: none; white-space: nowrap; transition: all .2s;
}
.idx-glossary-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); text-decoration: none; }

@media (min-width: 640px) {
  .idx-grid { grid-template-columns: repeat(2, 1fr); }
  .idx-hero-title { font-size: 3.5rem; }
}
@media (max-width: 640px) {
  .idx-hero { padding: 3rem 1rem 2rem; }
  .idx-hero-title { font-size: 2.2rem; }
  .idx-hero-sub { font-size: 1rem; }
  .idx-stat-num { font-size: 1.4rem; }
  .idx-container { padding: 0 1rem 2rem; }
  .idx-glossary-banner { flex-direction: column; text-align: center; gap: .8rem; }
  .idx-card { padding: 1rem 1.2rem; }
  .idx-card-icon { font-size: 1.6rem; }
  .part-hero { padding: 2rem 1rem 1.5rem; }
  .part-hero-icon { font-size: 2.2rem; }
  .part-hero-title { font-size: 1.5rem; }
  .chapter-btn { padding: .7rem 1rem; }
  .ch-btn-title { font-size: .85rem; }
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text2);
  font-size: .8rem;
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}

/* ── Glossary ── */
.glossary-search {
  width: 100%;
  padding: .85rem 1.2rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  margin: 1rem 0;
  transition: border-color .2s;
}
.glossary-search:focus { outline: none; border-color: var(--accent); }
.glossary-item { display: none; }
.glossary-item.show { display: table-row; }

/* ── Quiz ── */
.quiz-section { margin: 2rem 0; }
.quiz-section h3 { color: var(--orange); margin-bottom: 1rem; }
.quiz-item { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 1.2rem 1.4rem; margin: .8rem 0; }
.quiz-item p.quiz-q { font-weight: 600; color: #fff; margin-bottom: .8rem; font-size: .95rem; }
.quiz-options { display: flex; flex-direction: column; gap: .4rem; }
.quiz-opt {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  padding: .6rem 1rem; cursor: pointer; font-size: .9rem; color: var(--text);
  font-family: inherit; text-align: left; transition: all .2s; width: 100%;
}
.quiz-opt:hover { border-color: var(--accent); color: #fff; }
.quiz-opt.correct { background: rgba(56,217,169,.15); border-color: var(--green); color: var(--green); }
.quiz-opt.wrong { background: rgba(255,107,107,.12); border-color: var(--red); color: var(--red); }
.quiz-opt.disabled { pointer-events: none; opacity: .7; }
.quiz-explain { display: none; margin-top: .6rem; padding: .7rem 1rem; background: rgba(56,217,169,.08); border-radius: 8px; font-size: .88rem; color: var(--green); }
.quiz-explain.show { display: block; }
.quiz-score { text-align: center; padding: 1rem; background: var(--bg2); border-radius: 10px; margin-top: 1rem; }
.quiz-score .score-num { font-size: 1.5rem; font-weight: 700; color: var(--accent-light); }

/* ── Feedback Section ── */
.feedback-section {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  padding: 1.5rem; margin: 1.5rem 0; opacity: .4; pointer-events: none; transition: all .3s;
}
.feedback-section.unlocked { opacity: 1; pointer-events: auto; }
.feedback-section.submitted { opacity: .6; }
.feedback-title { font-size: 1.1rem; font-weight: 700; color: #fff; margin-bottom: .8rem; }
.difficulty-group { display: flex; gap: .4rem; flex-wrap: wrap; margin: .6rem 0; }
.difficulty-btn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
  padding: .5rem 1rem; border-radius: 8px; cursor: pointer; font-size: .95rem;
  font-family: inherit; transition: all .2s;
}
.difficulty-btn:hover { border-color: var(--accent); color: #fff; }
.difficulty-btn.selected { background: var(--accent); color: #fff; border-color: var(--accent); }
.feedback-name {
  width: 100%; max-width: 240px; padding: .6rem 1rem; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .95rem; font-family: inherit; margin-bottom: .3rem;
}
.feedback-name:focus { outline: none; border-color: var(--accent); }
.feedback-btn-group { display: flex; gap: .35rem; flex-wrap: wrap; }
.fb-btn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
  padding: .45rem .9rem; border-radius: 8px; cursor: pointer; font-size: .92rem;
  font-family: inherit; transition: all .2s;
}
.fb-btn:hover { border-color: var(--accent); color: #fff; }
.fb-btn.selected { background: var(--accent); color: #fff; border-color: var(--accent); }
.feedback-text {
  width: 100%; padding: .7rem 1rem; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .95rem; font-family: inherit;
  margin: .6rem 0; resize: vertical; min-height: 60px;
}
.feedback-text:focus { outline: none; border-color: var(--accent); }
.feedback-submit {
  background: var(--green); color: #fff; border: none; padding: .6rem 1.5rem;
  border-radius: 8px; font-size: .95rem; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all .2s;
}
.feedback-submit:hover { opacity: .9; }
.feedback-submit:disabled { opacity: .4; cursor: default; }
.feedback-hint { font-size: .85rem; color: var(--text2); margin-top: .5rem; }
.feedback-section.submitted .feedback-hint { color: var(--green); }

/* ── Next Chapter Button ── */
.next-chapter-btn {
  display: block; width: 100%; text-align: center; padding: 1rem;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text2); font-size: 1.05rem; font-weight: 600; cursor: pointer;
  font-family: inherit; margin: 1.5rem 0; transition: all .2s;
  opacity: .4; pointer-events: none;
}
.next-chapter-btn.unlocked {
  opacity: 1; pointer-events: auto; background: var(--accent);
  color: #fff; border-color: var(--accent);
}
.next-chapter-btn.unlocked:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(123,108,246,.3); }

/* ── Question Box ── */
.question-box {
  background: linear-gradient(135deg, rgba(123,108,246,.08), rgba(123,108,246,.03));
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 1.5rem;
  margin: 3rem 0 1.5rem;
  text-align: center;
}
.question-label {
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: .2rem;
}
.question-sub {
  font-size: .9rem;
  color: var(--text2);
  margin: .1rem 0 .3rem;
}
.question-location {
  font-size: .85rem;
  color: var(--text2);
  margin-bottom: .8rem;
}
.question-box .ask-btn {
  font-size: .95rem;
  padding: .7rem 2rem;
}

/* ── SVG Diagrams ── */
.svg-diagram {
  margin: 1.5rem 0;
  border-radius: 12px;
  overflow: hidden;
}
.svg-diagram img {
  width: 100%;
  height: auto;
  display: block;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  body { font-size: 1rem; }
  .container { padding: 1rem; }
  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.1rem; }
  h3 { font-size: 1rem; }
  .hero h1 { font-size: 1.5rem; }
  .hero p { font-size: .95rem; }
  pre, .diagram { font-size: .78rem; padding: 1rem; }
  table { font-size: .85rem; }
  th, td { padding: .5rem .6rem; }
  .chapter-nav { padding: .4rem; }
  .chapter-btn { padding: .4rem .7rem; font-size: .82rem; }
  .page-nav { flex-direction: column; }
  .page-nav a { text-align: center; }
}
