/* 데이터 엔지니어 학습 문제 풀이 앱 */

:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1c232c;
  --border: #2a323d;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, .14);
  --good: #3fb950;
  --bad: #f85149;
  --warn: #d29922;
  --basic: #3fb950;
  --intermediate: #d29922;
  --advanced: #f85149;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic",
          "Apple SD Gothic Neo", "Noto Sans KR", Roboto, sans-serif;
  --mono: "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --surface: #ffffff;
    --surface-2: #f0f3f6;
    --border: #d7dee6;
    --text: #1c2128;
    --muted: #626c78;
    --accent: #0969da;
    --accent-soft: rgba(9, 105, 218, .1);
    --good: #1a7f37;
    --bad: #cf222e;
    --warn: #9a6700;
    --basic: #1a7f37;
    --intermediate: #9a6700;
    --advanced: #cf222e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 40px 20px 80px; }
.wrap-narrow { max-width: 780px; }

code { font-family: var(--mono); font-size: .88em; background: var(--surface-2);
       padding: 1px 6px; border-radius: 5px; }
.muted { color: var(--muted); font-size: .9rem; }

/* ---------- head ---------- */
.page-head { margin-bottom: 32px; }
.eyebrow { margin: 0; color: var(--accent); font-size: .78rem; font-weight: 600;
           letter-spacing: .1em; text-transform: uppercase; }
.page-head h1 { margin: 6px 0 8px; font-size: 2rem; letter-spacing: -.02em; }
.lede { margin: 0; color: var(--muted); }
.section-title { margin: 36px 0 14px; font-size: .85rem; font-weight: 600;
                 letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.back { display: inline-block; margin-bottom: 14px; color: var(--muted);
        text-decoration: none; font-size: .9rem; }
.back:hover { color: var(--accent); }

.banner { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; }
.banner-error { background: rgba(248, 81, 73, .12); border: 1px solid var(--bad); color: var(--bad); }

.empty-state {
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 44px 32px; text-align: center;
}
.empty-state h2 { margin-top: 0; }

/* ---------- 카테고리 그리드 ---------- */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.cat-card { position: relative; display: block; cursor: pointer; }
.cat-card input { position: absolute; opacity: 0; width: 0; height: 0; }
.cat-body {
  display: block; height: 100%; padding: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); transition: border-color .15s, background .15s, transform .1s;
}
.cat-card:hover .cat-body { border-color: var(--accent); transform: translateY(-1px); }
.cat-card input:checked + .cat-body {
  border-color: var(--accent); background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.cat-card input:focus-visible + .cat-body { outline: 2px solid var(--accent); outline-offset: 2px; }
.cat-all .cat-body { border-style: dashed; }

.cat-name { display: block; font-weight: 650; font-size: 1.02rem; }
.cat-total { display: block; color: var(--accent); font-size: .84rem; font-weight: 600; }
.cat-meta { display: block; color: var(--muted); font-size: .78rem; }

.bar { display: flex; gap: 2px; height: 4px; margin-top: 10px; border-radius: 2px; overflow: hidden; }
.bar-seg { display: block; border-radius: 2px; }
.seg-basic { background: var(--basic); }
.seg-intermediate { background: var(--intermediate); }
.seg-advanced { background: var(--advanced); }

/* ---------- 옵션 ---------- */
.options {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.field { display: flex; flex-direction: column; gap: 5px; font-size: .8rem; color: var(--muted); }
.field select {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; font-size: .92rem; font-family: inherit; min-width: 150px;
}
.options .btn { margin-left: auto; }

.btn {
  display: inline-block; border: 1px solid transparent; border-radius: 8px;
  padding: 10px 20px; font-size: .93rem; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none; transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-submit { background: var(--good); }

.legend { margin-top: 30px; color: var(--muted); font-size: .88rem; }
.legend summary { cursor: pointer; }
.legend-list { list-style: none; display: flex; flex-wrap: wrap; gap: 16px; padding: 10px 0; margin: 0; }
.legend-list.errors { display: block; font-family: var(--mono); font-size: .76rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

/* ---------- 퀴즈 ---------- */
.quiz-head { margin-bottom: 22px; }
.quiz-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 1.1rem; }
.chips { display: inline-flex; gap: 6px; }

.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: .72rem; font-weight: 600; color: var(--muted);
}
.chip-cat { color: var(--accent); border-color: var(--accent); }
.chip-basic { color: var(--basic); border-color: var(--basic); }
.chip-intermediate { color: var(--intermediate); border-color: var(--intermediate); }
.chip-advanced { color: var(--advanced); border-color: var(--advanced); }
.chip-score { color: var(--accent); border-color: var(--accent); }

.progress-wrap { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.progress { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
.progress-text { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px; margin-bottom: 18px;
}
.q-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.q-id { margin-left: auto; font-family: var(--mono); font-size: .72rem; color: var(--muted); }
.q-text { margin: 0 0 20px; font-size: 1.15rem; line-height: 1.6; letter-spacing: -.01em; }

.choices { display: flex; flex-direction: column; gap: 9px; list-style: none; padding: 0; margin: 0; }
.choice {
  display: flex; align-items: flex-start; gap: 11px; padding: 13px 15px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; cursor: pointer; transition: border-color .12s, background .12s;
}
label.choice:hover { border-color: var(--accent); }
.choice input { position: absolute; opacity: 0; width: 0; height: 0; }
.choice.picked { border-color: var(--accent); background: var(--accent-soft); }
.choice-key {
  flex: 0 0 22px; height: 22px; display: grid; place-items: center;
  border-radius: 5px; background: var(--bg); border: 1px solid var(--border);
  font-size: .74rem; font-weight: 700; color: var(--muted);
}
.choice.picked .choice-key { background: var(--accent); color: #fff; border-color: var(--accent); }
.choice-text { flex: 1; }

.answer-input {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px; padding: 14px;
  font-family: inherit; font-size: .96rem; line-height: 1.65; resize: vertical;
}
.answer-input:focus { outline: none; border-color: var(--accent); }
.hint { color: var(--muted); font-size: .82rem; margin: 10px 0 0; }
.loading { color: var(--muted); }

.quiz-foot {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 14px;
  padding: 14px 0; background: linear-gradient(transparent, var(--bg) 30%);
}
.quiz-foot .btn-primary, .quiz-foot .btn-submit { margin-left: 0; }
.answered-note { flex: 1; text-align: center; color: var(--muted); font-size: .84rem; }

/* ---------- 결과 ---------- */
.result-head { border-bottom: 1px solid var(--border); padding-bottom: 26px; }
.score-hero { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; margin: 20px 0; }
.score-ring {
  width: 128px; height: 128px; flex: 0 0 auto; border-radius: 50%;
  display: grid; place-content: center; text-align: center;
  border: 6px solid var(--border); background: var(--surface);
}
.ring-good { border-color: var(--good); }
.ring-mid { border-color: var(--warn); }
.ring-low { border-color: var(--bad); }
.score-num { font-size: 2.1rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.score-num small { font-size: .95rem; font-weight: 600; color: var(--muted); }
.score-sub { display: block; font-size: .78rem; color: var(--muted); margin-top: 5px; }

.stats { display: flex; flex-wrap: wrap; gap: 26px; margin: 0; }
.stats dt { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stats dd { margin: 2px 0 0; font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; }

.result-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.result-actions.bottom { margin-top: 30px; }

.review { border-left: 3px solid var(--border); }
.review.ok { border-left-color: var(--good); }
.review.bad { border-left-color: var(--bad); }
.review.skip { border-left-color: var(--muted); }
.verdict { font-size: .74rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.review.ok .verdict { background: rgba(63, 185, 80, .16); color: var(--good); }
.review.bad .verdict { background: rgba(248, 81, 73, .16); color: var(--bad); }
.review.skip .verdict { background: var(--surface-2); color: var(--muted); }
.review .q-text { font-size: 1.05rem; }

.review-choices .choice { cursor: default; }
.review-choices .choice.is-answer { border-color: var(--good); background: rgba(63, 185, 80, .1); }
.review-choices .choice.is-wrong { border-color: var(--bad); background: rgba(248, 81, 73, .1); }
.tag { margin-left: auto; font-size: .7rem; font-weight: 700; padding: 1px 8px;
       border-radius: 999px; white-space: nowrap; }
.tag-answer { background: var(--good); color: #fff; }
.tag-yours { background: var(--surface); border: 1px solid var(--border); color: var(--muted); margin-left: 6px; }

.kw-block { background: var(--surface-2); border-radius: 9px; padding: 14px 16px; margin-bottom: 16px; }
.kw-title { margin: 0 0 8px; font-size: .86rem; font-weight: 650; }
.kw-list { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.kw { font-size: .78rem; padding: 2px 10px; border-radius: 999px; border: 1px solid; }
.kw-hit { color: var(--good); border-color: var(--good); background: rgba(63, 185, 80, .1); }
.kw-miss { color: var(--muted); border-color: var(--border); text-decoration: line-through; }

.answer-block { margin-bottom: 14px; }
.answer-block h4, .explain h4 {
  margin: 0 0 6px; font-size: .76rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.answer-block p, .explain p { margin: 0; white-space: pre-wrap; }
.user-answer { color: var(--muted); }
.answer-block.model p { background: var(--surface-2); border-radius: 9px; padding: 14px 16px; }
.explain { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 16px; }

/* ---------- 첫 화면 진입점 (문제 풀이 / 학습) ---------- */
.entry-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.entry-card {
  display: block; padding: 22px 24px; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s, background .15s, transform .1s;
}
.entry-card:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.entry-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.entry-kicker {
  display: block; color: var(--accent); font-size: .72rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
}
.entry-name { display: block; font-size: 1.25rem; font-weight: 700; margin: 2px 0 6px; }
.entry-desc { display: block; color: var(--muted); font-size: .88rem; }
.entry-disabled { opacity: .55; pointer-events: none; }

/* ---------- 학습 카테고리 카드 ---------- */
.learn-card {
  display: block; padding: 16px; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s, background .15s, transform .1s;
}
.learn-card:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.learn-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.learn-preview {
  list-style: none; margin: 10px 0 0; padding: 10px 0 0;
  border-top: 1px solid var(--border); color: var(--muted); font-size: .78rem;
}
.learn-preview li { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.learn-preview li::before { content: "· "; }
.learn-preview .more { color: var(--accent); }

/* ---------- 학습 모듈 화면 ---------- */
.learn-head { margin-bottom: 22px; }
.learn-layout { display: grid; gap: 24px; grid-template-columns: 260px minmax(0, 1fr); align-items: start; }

.learn-nav {
  position: sticky; top: 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  max-height: calc(100vh - 60px); overflow-y: auto;
}
.learn-toc { list-style: none; margin: 0; padding: 0; }
.toc-item {
  display: flex; gap: 9px; align-items: baseline;
  padding: 8px 10px; border-radius: 8px; margin-bottom: 2px;
  color: var(--text); text-decoration: none; font-size: .88rem; line-height: 1.4;
}
.toc-item:hover { background: var(--surface-2); }
.toc-item.current { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.toc-order {
  flex: 0 0 22px; height: 20px; display: grid; place-items: center;
  border-radius: 5px; background: var(--bg); border: 1px solid var(--border);
  font-size: .7rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums;
}
.toc-item.current .toc-order { background: var(--accent); color: #fff; border-color: var(--accent); }
.toc-title { flex: 1; }

.learn-main { min-width: 0; }
.learn-article { padding: 28px 30px; }
.learn-title { margin: 0 0 10px; font-size: 1.5rem; letter-spacing: -.02em; line-height: 1.35; }
.learn-source {
  margin: 0 0 18px; padding: 10px 14px; font-size: .84rem;
  background: var(--surface-2); border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0;
}
.learn-summary {
  margin: 0 0 24px; color: var(--muted); font-size: .96rem;
  white-space: pre-wrap; word-break: break-word;
}
.learn-section { border-top: 1px solid var(--border); padding-top: 20px; margin-top: 22px; }
.learn-section:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.learn-section h3 { margin: 0 0 12px; font-size: 1.1rem; letter-spacing: -.01em; }
.learn-para { margin: 0 0 14px; white-space: pre-wrap; word-break: break-word; }

.code-block {
  position: relative; margin: 0 0 16px; padding: 14px 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
  overflow-x: auto; font-family: var(--mono); font-size: .84rem; line-height: 1.55;
}
.code-block code { background: none; padding: 0; font-size: inherit; }
.code-block[data-lang]::before {
  content: attr(data-lang); position: absolute; top: 6px; right: 10px;
  font-size: .66rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}

.key-points { margin-top: 16px; }
.key-point-list { margin: 0; padding-left: 20px; font-size: .9rem; }
.key-point-list li { margin-bottom: 4px; }

.learn-cta {
  border-top: 1px solid var(--border); margin-top: 26px; padding-top: 18px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
}
.learn-cta .muted { margin: 0; flex: 1; min-width: 200px; }

.learn-pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; }
.learn-pager .btn { max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 860px) {
  .learn-layout { grid-template-columns: 1fr; }
  .learn-nav { position: static; max-height: none; }
}

/* ---------- 학습 진행률 (localStorage 기반, learn_index / learn_roadmap) ---------- */
.progress-mini { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.progress-mini .progress { flex: 1; }
.progress-mini .progress-text { font-size: .74rem; white-space: nowrap; }

.learn-links { display: flex; gap: 10px; margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--border); }
.learn-links a { color: var(--muted); font-size: .78rem; text-decoration: none; }
.learn-links a:hover { color: var(--accent); }

.learn-toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---------- 학습목표 체크리스트 ---------- */
.objectives-block {
  background: var(--surface-2); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 20px;
}
.objectives-title { margin: 0 0 10px; font-size: .86rem; font-weight: 650; }
.objectives-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; }
.objectives-list li { display: flex; align-items: flex-start; gap: 9px; font-size: .92rem; }
.objectives-list li::before {
  content: ""; flex: 0 0 15px; height: 15px; margin-top: 2px;
  border: 1.5px solid var(--muted); border-radius: 4px;
}

/* ---------- 회상 복습 카드 ---------- */
.recall-toggle {
  display: inline-flex; align-items: center; gap: 7px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px; font-size: .78rem; color: var(--muted); cursor: pointer;
}
.recall-toggle:hover { border-color: var(--accent); color: var(--text); }
.recall-toggle.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.key-point-list.recall-mode li {
  cursor: pointer; border-radius: 6px; padding: 2px 6px; margin: -2px -6px 4px;
  transition: background .12s;
}
.key-point-list.recall-mode li:hover { background: var(--surface); }
.key-point-list.recall-mode li.hidden-text { color: transparent; background: var(--surface); text-shadow: none; }
.key-point-list.recall-mode li.hidden-text::selection { color: transparent; }

/* ---------- 읽음 표시 ---------- */
.read-toggle {
  display: flex; align-items: center; gap: 8px; margin-top: 22px; padding-top: 16px;
  border-top: 1px solid var(--border); font-size: .9rem; color: var(--text); cursor: pointer;
  user-select: none;
}
.read-toggle input { width: 16px; height: 16px; accent-color: var(--good); cursor: pointer; }

/* ---------- 로드맵 ---------- */
.roadmap-head-actions { display: flex; gap: 10px; margin: 6px 0 0; }
.roadmap-source { margin-bottom: 26px; }
.roadmap-source-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.roadmap-source-head h2 { margin: 0; font-size: 1.1rem; }
.roadmap-source-authors { color: var(--muted); font-size: .8rem; }
.roadmap-module-list { display: flex; flex-direction: column; gap: 6px; }
.roadmap-module-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  text-decoration: none; color: var(--text); transition: border-color .12s, background .12s;
}
.roadmap-module-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.roadmap-module-item .toc-order { flex: 0 0 auto; }
.roadmap-module-item .rmi-title { flex: 1; font-size: .92rem; }
.roadmap-module-item .rmi-ref { color: var(--muted); font-size: .76rem; white-space: nowrap; }
.roadmap-module-item .rmi-read {
  flex: 0 0 auto; width: 18px; height: 18px; border-radius: 50%;
  border: 1.5px solid var(--border); display: none;
}
.roadmap-module-item.is-read .rmi-read { display: block; background: var(--good); border-color: var(--good); }

/* ---------- 용어 사전 ---------- */
.glossary-list { display: flex; flex-direction: column; gap: 14px; }
.glossary-entry {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
}
.glossary-term { margin: 0 0 6px; font-size: 1.02rem; font-weight: 650; }
.glossary-def { margin: 0 0 4px; font-size: .92rem; }
.glossary-def + .glossary-def { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.glossary-src { color: var(--muted); font-size: .76rem; }
.glossary-src a { color: inherit; }

@media (max-width: 560px) {
  .wrap { padding: 24px 14px 60px; }
  .options .btn { margin-left: 0; width: 100%; }
  .score-hero { gap: 18px; }
  .learn-article { padding: 20px 18px; }
  .learn-pager { flex-direction: column; }
  .learn-pager .btn { max-width: none; text-align: center; }
}
