/* ============================================================
   CppLearner · 例题讲解模块样式
   与知识点模块共享主题变量,在 style.css 之后加载
   ============================================================ */

/* ============================================
   整体布局
   ============================================ */
.ex-layout {
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - var(--header-h));
  position: relative;
}

/* ============================================
   左侧题目列表
   ============================================ */
.ex-sidebar {
  border-right: 1px solid var(--paper-line);
  padding: 32px 0 32px 32px;
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
}

.ex-sidebar-title {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-mute);
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ex-chapter-label {
  font-family: var(--font-serif);
  font-size: 12px;
  color: var(--vermilion);
  letter-spacing: 2px;
  margin: 18px 0 10px 4px;
  font-weight: 500;
}

.ex-item-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 16px;
}

.ex-item {
  padding: 11px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.18s;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13.5px;
  color: var(--ink-soft);
  user-select: none;
  position: relative;
  border: 1px solid transparent;
}

.ex-item:hover {
  background: var(--paper-warm);
  color: var(--ink-deep);
}

.ex-item.active {
  background: var(--jade-glow);
  color: var(--jade);
  font-weight: 500;
  border-color: var(--jade);
}

.ex-item.active::before {
  content: '';
  position: absolute;
  left: -32px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  background: var(--vermilion);
  border-radius: 0 2px 2px 0;
}

.ex-item-num {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 13px;
  color: var(--vermilion);
  min-width: 22px;
  line-height: 1.5;
  flex-shrink: 0;
}

.ex-item-name {
  flex: 1;
  line-height: 1.5;
}

/* ============================================
   中间主内容区
   ============================================ */
.ex-main {
  padding: 40px 56px 80px;
  max-width: 960px;
  width: 100%;
  box-sizing: border-box;
}

/* — 例题头部 — */
.ex-header {
  margin-bottom: 36px;
  padding-bottom: 22px;
  border-bottom: 2px solid var(--jade);
  position: relative;
}

.ex-header::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 60px;
  height: 2px;
  background: var(--vermilion);
  border-radius: 1px;
}

.ex-tag-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.ex-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}

.ex-badge.chapter {
  background: var(--vermilion-bg);
  color: var(--vermilion);
}

.ex-badge.tag {
  background: var(--paper-warm);
  color: var(--ink-soft);
  border: 1px solid var(--paper-line);
}

.ex-title {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 700;
  color: var(--ink-deep);
  line-height: 1.25;
  margin-bottom: 0;
}

/* ============================================
   各卡片区块
   ============================================ */
.ex-card {
  margin-bottom: 28px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--paper-line);
}

.ex-card-header {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--paper-line);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.ex-card-header:hover {
  background: var(--paper-warm);
}

.ex-card-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.ex-card.problem .ex-card-icon { background: var(--gold); }
.ex-card.analysis .ex-card-icon { background: var(--jade); }
.ex-card.code-card .ex-card-icon { background: var(--vermilion); }
.ex-card.output .ex-card-icon { background: #6b7280; }
.ex-card.keypoints .ex-card-icon { background: #7c3aed; }

.ex-card-label {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-deep);
  flex: 1;
}

.ex-card-chevron {
  font-size: 12px;
  color: var(--ink-mute);
  transition: transform 0.2s;
}

.ex-card.collapsed .ex-card-chevron {
  transform: rotate(-90deg);
}

.ex-card-body {
  padding: 20px 24px;
  background: var(--paper);
}

.ex-card.collapsed .ex-card-body {
  display: none;
}

/* — 题目描述 — */
.ex-card.problem .ex-card-body {
  background: var(--paper-warm);
}

.ex-problem-text {
  font-size: 14.5px;
  line-height: 2;
  color: var(--ink-deep);
  white-space: pre-line;
}

/* — 分析区 — */
.ex-analysis-text {
  font-size: 14.5px;
  line-height: 2;
  color: var(--ink-deep);
  white-space: pre-line;
}

/* — 代码区 — */
.ex-code-frame {
  background: var(--code-bg);
  border-radius: 6px;
  overflow: hidden;
}

.ex-code-frame-header {
  background: rgba(0,0,0,0.25);
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.ex-code-lang {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(196, 221, 210, 0.7);
  letter-spacing: 1px;
}

.ex-code-copy-btn {
  background: rgba(196,221,210,0.1);
  color: rgba(196,221,210,0.9);
  border: 1px solid rgba(196,221,210,0.2);
  padding: 3px 12px;
  font-size: 11px;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
  transition: all 0.2s;
}

.ex-code-copy-btn:hover {
  background: rgba(196,221,210,0.2);
  color: var(--paper);
}

.ex-code-copy-btn.copied {
  color: var(--jade);
  border-color: var(--jade);
}

.ex-code-pre {
  margin: 0;
  padding: 18px 22px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.7;
  color: #c4ddd2;
  white-space: pre;
  overflow-x: auto;
}

/* — 运行结果 — */
.ex-card.output .ex-card-body {
  background: var(--code-bg);
  padding: 0;
}

.ex-output-pre {
  margin: 0;
  padding: 18px 22px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  color: #a8c4b0;
  white-space: pre;
}

/* — 知识要点 — */
.ex-keypoints-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ex-keypoints-list li {
  padding: 10px 16px;
  background: var(--paper-warm);
  border-radius: 6px;
  border-left: 3px solid #7c3aed;
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink-deep);
  position: relative;
}

.ex-keypoints-list li::before {
  content: attr(data-n);
  position: absolute;
  left: -1px;
  top: -1px;
  background: #7c3aed;
  color: white;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 0 0 4px 0;
  line-height: 1.4;
}

/* — 导航按钮 — */
.ex-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--paper-line);
  gap: 12px;
}

.ex-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 6px;
  border: 1px solid var(--paper-line);
  background: var(--paper-warm);
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.ex-nav-btn:hover {
  background: var(--jade-glow);
  border-color: var(--jade);
  color: var(--jade);
}

.ex-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.ex-nav-btn:disabled:hover {
  background: var(--paper-warm);
  border-color: var(--paper-line);
  color: var(--ink-soft);
}

.ex-nav-counter {
  font-family: var(--font-serif);
  font-size: 13px;
  color: var(--ink-mute);
}

/* — 空状态 — */
.ex-empty {
  text-align: center;
  padding: 100px 40px;
  color: var(--ink-mute);
}

.ex-empty-icon {
  font-size: 52px;
  opacity: 0.4;
  margin-bottom: 18px;
}

.ex-empty-title {
  font-family: var(--font-serif);
  font-size: 20px;
  color: var(--jade);
  margin-bottom: 8px;
}

.ex-empty-text {
  font-size: 13.5px;
  line-height: 1.8;
}

/* ============================================
   响应式
   ============================================ */
@media (max-width: 900px) {
  .ex-layout {
    grid-template-columns: 1fr;
  }

  .ex-main {
    padding: 24px 20px 80px;
  }

  .ex-title {
    font-size: 22px;
  }

  /* ex-sidebar 变成抽屉 */
  .ex-sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    height: calc(100vh - var(--header-h));
    width: 288px;
    z-index: 250;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 24px 0 24px 24px;
    box-shadow: 4px 0 24px rgba(26,41,37,0.15);
    border-right: none;
    background: var(--paper);
  }

  .ex-sidebar.drawer-open {
    transform: translateX(0);
  }

  .ex-item.active::before {
    left: -24px;
  }
}

@media (max-width: 600px) {
  .ex-main {
    padding: 20px 16px 80px;
  }

  .ex-nav-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .ex-nav-btn {
    justify-content: center;
  }
}
