/* ============================================
   Python 转型教程 - 暗夜图书馆主题
   深色护眼设计风格
   ============================================ */

/* CSS 变量定义 */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #1c2128;
  --bg-code: #0d1117;
  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent-blue: #58a6ff;
  --accent-green: #3fb950;
  --accent-yellow: #d29922;
  --accent-red: #f85149;
  --accent-purple: #bc8cff;
  --border: #30363d;
  --border-light: #21262d;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  --radius: 8px;
  --radius-sm: 4px;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  --font-body: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;
  --sidebar-width: 280px;
  --transition: all 0.25s ease;
}

/* 基础重置 */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.8;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* 自定义滚动条 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

::selection {
  background: rgba(88, 166, 255, 0.3);
  color: var(--text-primary);
}

/* ============================================
   布局系统
   ============================================ */

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

/* 侧边栏 */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  transition: var(--transition);
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-blue);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-brand::before {
  content: '🐍';
  font-size: 1.3rem;
}

.sidebar-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-family: var(--font-mono);
}

.sidebar-nav {
  padding: 12px 0;
}

.nav-section {
  margin-bottom: 8px;
}

.nav-section-title {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 8px 20px;
}

.nav-list {
  list-style: none;
}

.nav-item {
  position: relative;
}

.nav-link {
  display: block;
  padding: 8px 20px 8px 28px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  transition: var(--transition);
  border-left: 2px solid transparent;
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-left-color: var(--text-muted);
}

.nav-link.active {
  color: var(--accent-blue);
  background: rgba(88, 166, 255, 0.08);
  border-left-color: var(--accent-blue);
  font-weight: 500;
}

.nav-link .chapter-num {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-right: 8px;
}

.nav-link.active .chapter-num {
  color: var(--accent-blue);
}

/* 移动端菜单按钮 */
.menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  width: 40px;
  height: 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

/* 主内容区 */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
}

.content-wrapper {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 48px 80px;
}

/* 面包屑 */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: var(--transition);
}

.breadcrumb a:hover {
  color: var(--accent-blue);
}

.breadcrumb-separator {
  opacity: 0.5;
}

/* 章节简介 */
.chapter-intro {
  font-size: 1.05rem;
  color: var(--text-secondary);
  border-left: 3px solid var(--accent-blue);
  padding-left: 16px;
  margin-bottom: 2em;
}

/* ============================================
   排版样式
   ============================================ */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-mono);
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-primary);
  margin-top: 2em;
  margin-bottom: 0.8em;
}

h1 { font-size: 2rem; margin-top: 0; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1rem; }

h2 {
  padding-bottom: 0.4em;
  border-bottom: 1px solid var(--border);
}

h2::before {
  content: '#';
  color: var(--accent-blue);
  margin-right: 0.4em;
  opacity: 0.7;
}

h3::before {
  content: '##';
  color: var(--accent-green);
  margin-right: 0.4em;
  opacity: 0.6;
  font-size: 0.85em;
}

p {
  margin-bottom: 1.2em;
  color: var(--text-primary);
}

a {
  color: var(--accent-blue);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

strong {
  color: #e6edf3;
  font-weight: 600;
}

/* 列表 */
ul, ol {
  margin-bottom: 1.2em;
  padding-left: 1.8em;
}

li {
  margin-bottom: 0.4em;
}

li::marker {
  color: var(--accent-blue);
}

ol li::marker {
  color: var(--accent-green);
  font-family: var(--font-mono);
  font-weight: 600;
}

/* 分割线 */
hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 2.5em 0;
}

/* ============================================
   代码块
   ============================================ */

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--accent-purple);
  word-break: break-word;
}

pre {
  position: relative;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 1.5em;
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
  color: var(--text-primary);
  font-size: 0.85rem;
  line-height: 1.7;
}

/* 代码块标题栏 */
.code-block {
  position: relative;
  margin-bottom: 1.5em;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.code-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.code-dots {
  display: flex;
  gap: 6px;
}

.code-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.code-dots .dot-red { background: #ff5f56; }
.code-dots .dot-yellow { background: #ffbd2e; }
.code-dots .dot-green { background: #27c93f; }

.code-lang {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.code-copy {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  cursor: pointer;
  transition: var(--transition);
}

.code-copy:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

.code-copy.copied {
  color: var(--accent-green);
  border-color: var(--accent-green);
}

.code-block pre {
  margin: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* PrismJS 深色主题自定义 */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata { color: #8b949e; }

.token.punctuation { color: #c9d1d9; }

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol { color: #79c0ff; }

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin { color: #a5d6ff; }

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string { color: #d2a8ff; }

.token.atrule,
.token.attr-value,
.token.keyword { color: #ff7b72; }

.token.function,
.token.class-name { color: #d2a8ff; }

.token.regex,
.token.important,
.token.variable { color: #ffa657; }

/* ============================================
   提示框组件
   ============================================ */

.callout {
  position: relative;
  padding: 16px 20px;
  margin-bottom: 1.5em;
  border-radius: var(--radius);
  border-left: 4px solid;
  background: var(--bg-secondary);
}

.callout-icon {
  font-size: 1.1rem;
  margin-right: 8px;
}

.callout-title {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
}

.callout p:last-child {
  margin-bottom: 0;
}

.callout-info {
  border-left-color: var(--accent-blue);
  background: rgba(88, 166, 255, 0.06);
}
.callout-info .callout-title { color: var(--accent-blue); }

.callout-tip {
  border-left-color: var(--accent-green);
  background: rgba(63, 185, 80, 0.06);
}
.callout-tip .callout-title { color: var(--accent-green); }

.callout-warning {
  border-left-color: var(--accent-yellow);
  background: rgba(210, 153, 34, 0.06);
}
.callout-warning .callout-title { color: var(--accent-yellow); }

.callout-danger {
  border-left-color: var(--accent-red);
  background: rgba(248, 81, 73, 0.06);
}
.callout-danger .callout-title { color: var(--accent-red); }

/* ============================================
   步骤列表
   ============================================ */

.steps {
  counter-reset: step;
  list-style: none;
  padding-left: 0;
}

.step {
  position: relative;
  padding-left: 48px;
  margin-bottom: 1.5em;
}

.step::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 2px;
  width: 30px;
  height: 30px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-blue);
}

.step-title {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.4em;
}

/* ============================================
   表格
   ============================================ */

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5em;
  font-size: 0.9rem;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border: 1px solid var(--border);
}

th {
  background: var(--bg-tertiary);
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
}

tr:nth-child(even) {
  background: rgba(33, 38, 45, 0.4);
}

/* ============================================
   底部导航
   ============================================ */

.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4em;
  padding-top: 2em;
  border-top: 1px solid var(--border);
  gap: 16px;
}

.page-nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: var(--transition);
  flex: 1;
}

.page-nav-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-blue);
  text-decoration: none;
}

.page-nav-btn.next {
  justify-content: flex-end;
}

.page-nav-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.page-nav-btn .nav-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.page-nav-btn .nav-title {
  font-weight: 600;
}

.page-nav-center {
  padding: 12px 16px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ============================================
   回到顶部
   ============================================ */

.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
  z-index: 90;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  background: var(--bg-tertiary);
  color: var(--accent-blue);
  border-color: var(--accent-blue);
}

/* ============================================
   封面页特殊样式
   ============================================ */

.cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 40px;
  position: relative;
  overflow: hidden;
}

.cover::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(88, 166, 255, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(63, 185, 80, 0.05), transparent);
  pointer-events: none;
}

.cover-content {
  position: relative;
  z-index: 1;
  max-width: 700px;
}

.cover-icon {
  font-size: 4rem;
  margin-bottom: 24px;
  display: inline-block;
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.cover h1 {
  font-size: 2.8rem;
  font-weight: 700;
  margin-bottom: 0.3em;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.cover .subtitle {
  font-size: 1.15rem;
  color: var(--text-secondary);
  margin-bottom: 1.5em;
}

.cover .description {
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 560px;
  margin: 0 auto 2.5em;
  line-height: 1.8;
}

.cover-meta {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 3em;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.cover-meta span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.start-reading {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 32px;
  background: var(--accent-blue);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius);
  text-decoration: none;
  transition: var(--transition);
  box-shadow: 0 4px 16px rgba(88, 166, 255, 0.25);
}

.start-reading:hover {
  background: #4d9ef7;
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(88, 166, 255, 0.35);
  text-decoration: none;
}

/* 封面目录 */
.cover-toc {
  margin-top: 4em;
  width: 100%;
  max-width: 600px;
}

.cover-toc h2 {
  font-size: 1.1rem;
  text-align: center;
  margin-bottom: 1.5em;
  border: none;
}

.cover-toc h2::before {
  content: none;
}

.toc-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.toc-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-secondary);
  transition: var(--transition);
  text-align: left;
}

.toc-card:hover {
  border-color: var(--accent-blue);
  background: var(--bg-hover);
  text-decoration: none;
  transform: translateY(-2px);
}

.toc-card-num {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-blue);
  min-width: 32px;
}

.toc-card-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* ============================================
   响应式
   ============================================ */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  .main {
    margin-left: 0;
  }

  .content-wrapper {
    padding: 60px 20px 40px;
  }

  .menu-toggle {
    display: flex;
  }

  .cover h1 {
    font-size: 1.8rem;
  }

  .toc-grid {
    grid-template-columns: 1fr;
  }

  .page-nav {
    flex-direction: column;
  }

  .page-nav-btn {
    width: 100%;
  }

  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.25rem; }
}

/* 打印样式 */
@media print {
  .sidebar, .menu-toggle, .back-to-top, .page-nav, .code-copy, .search-box {
    display: none !important;
  }

  .main {
    margin-left: 0;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 13pt;
    line-height: 1.6;
  }

  pre, code {
    background: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  a {
    color: #1a0dab;
    text-decoration: underline;
  }

  h1, h2, h3 {
    color: #000;
    page-break-after: avoid;
  }

  h2::before, h3::before {
    color: #666;
  }

  .callout {
    border: 1px solid #ccc;
    background: #fafafa;
    break-inside: avoid;
  }

  .content-wrapper {
    max-width: 100%;
    padding: 20px;
    animation: none;
  }

  @page {
    margin: 2cm;
  }
}

/* ============================================
   深色模式 / 亮色模式切换
   ============================================ */

/* 亮色模式变量 */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #e8eaed;
  --bg-hover: #f0f0f0;
  --bg-code: #f6f8fa;
  --text-primary: #24292f;
  --text-secondary: #57606a;
  --text-muted: #8b949e;
  --border: #d0d7de;
  --border-light: #d8dee4;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .cover h1 {
  -webkit-text-fill-color: unset;
  background: none;
  color: var(--text-primary);
}

[data-theme="light"] .start-reading {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 主题切换按钮 */
.theme-toggle {
  position: fixed;
  bottom: 76px;
  right: 24px;
  width: 44px;
  height: 44px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: var(--transition);
  z-index: 90;
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--accent-yellow);
  border-color: var(--accent-yellow);
}

/* ============================================
   搜索功能
   ============================================ */

.search-box {
  padding: 8px 12px;
  margin: 8px 16px;
}

.search-box input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
  transition: var(--transition);
}

.search-box input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.nav-link.search-hidden {
  display: none;
}

.search-empty {
  display: none;
  padding: 16px 20px;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}

.search-empty.visible {
  display: block;
}

/* ============================================
   锚点链接
   ============================================ */

.header-anchor {
  display: inline-block;
  opacity: 0;
  margin-left: 8px;
  color: var(--accent-blue);
  text-decoration: none;
  font-size: 0.8em;
  transition: opacity 0.2s ease;
  vertical-align: middle;
}

h2:hover .header-anchor,
h3:hover .header-anchor {
  opacity: 0.7;
}

.header-anchor:hover {
  opacity: 1;
  text-decoration: none;
}

/* ============================================
   data-table 样式增强
   ============================================ */

.data-table {
  font-size: 0.875rem;
}

.data-table thead th {
  background: var(--bg-tertiary);
  position: sticky;
  top: 0;
}

/* ============================================
   动效
   ============================================ */

.fade-in {
  animation: fadeIn 0.6s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.content-wrapper {
  animation: fadeIn 0.5s ease-out;
}

/* 目录链接悬停发光效果 */
.nav-link.active::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--accent-blue);
  border-radius: 2px 0 0 2px;
}
