/* 全局字体和背景设置 */

/* --- 专业的字体排版系统 --- */

/* 1. 使用 :root 定义全局变量，方便管理 */
:root {
    --font-serif: "Noto Serif SC", serif;
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "Fira Code", monospace;
}

/* 2. 全局基础样式 */
body {
    font-family: var(--font-serif); /* 正文默认使用衬线字体 */
    font-size: 18px; /* 稍微增大基础字号，提升舒适度 */
    line-height: 1.8; /* 增大行高，让段落呼吸 */
    background-color: #f8f9fa; /* 一个更柔和的浅灰色背景 */
    color: #212529; /* 一个非常专业且对比度舒适的深灰色 */
    margin: 0;
    padding: 2em 0; /* 使用 em 单位，让上下留白与字号关联 */

    transition: background-color 0.3s ease, color 0.3s ease;
}

/* 3. 内容区域的精细化排版 */
main#chapter-content {
    max-width: 42rem; /* 使用 rem 单位限制行长，约 65-75 个字符，是公认的最佳行长 */
    width: 90%;
    background-color: #ffffff;
    padding: 3rem 4rem; /* 同样使用 rem 单位，保证缩放时布局和谐 */
    border: 1px solid #dee2e6; /* 使用边框代替阴影，更具书籍感 */
    border-radius: 4px;

    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* 针对内容中不同元素的字体应用 */

/* 标题使用非衬线字体，形成对比 */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    line-height: 1.3;
    margin-top: 1.5em;
    margin-bottom: 0.8em;
}

/* 段落之间增加间距 */
p {
    margin-bottom: 1.2em;
}


/* ===================================== */
/* == 针对数学和代码的特殊样式 ==*/
/* ===================================== */

/* 针对 KaTeX 渲染出的块级公式容器 */
.katex-display {
    overflow-x: auto;      /* 核心！当内容溢出时，显示水平滚动条 */
    overflow-y: hidden;    /* 隐藏通常不需要的垂直滚动条 */
    padding: 1em 0;        /* 增加一些上下内边距 */
    padding-bottom: 10px;  /* 在底部留出一点空间给滚动条，避免紧贴公式 */
    -webkit-overflow-scrolling: touch; /* 在 iOS 上实现平滑的滚动惯性 */
}

/* KaTeX 渲染出的数学公式 */
.katex {
    font-family: var(--font-mono) !important; /* 强制公式使用等宽字体 */
    font-size: 1.1em; /* 让公式稍微大一点，更清晰 */
}

/* Markdown 中的行内代码 `code` */
code {
    font-family: var(--font-mono);
    background-color: #e9ecef;
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 85%; /* 让行内代码比正文小一点 */
}


/* ===================================== */
/* == 导航和按钮 ==*/
/* ===================================== */

/* 导航和按钮等 UI 元素也使用非衬线字体 */
.nav-buttons, .nav-buttons button, .back-to-home {
    font-family: var(--font-sans);
}

/* 导航按钮区域的样式 */
.nav-buttons button{
    margin-top: 20px;
    margin-bottom: 20px;
}

/* 按钮的样式 */
.nav-buttons button{
    background-color: #007bff; /* 蓝色背景 */
    color: white; /* 白色文字 */
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    border-radius: 5px;
    cursor: pointer; /* 鼠标悬停时显示为手形 */
    margin: 0 10px; /* 按钮之间的间距 */

    /* 新增：为按钮的背景色变化添加 0.2 秒的过渡 */
    transition: background-color 0.2s ease;
}

/* 鼠标悬停在按钮上时的样式 */
.nav-buttons button:hover {
    background-color: #0056b3; /* 悬停时颜色变深 */
}

/* 禁用按钮的样式 */
.nav-buttonsbutton:disabled {
    background-color: #cccccc; /* 灰色背景 */
    cursor: not-allowed; /* 鼠标悬停时显示为禁止标志 */
}

/* "返回目录" 链接的样式 */
.back-to-home {
    display: inline-block;
    margin-bottom: 40px;
    color: #007bff;
    text-decoration: none;
}

.back-to-home:hover {
    text-decoration: underline;
}

/* 主题切换按钮的容器样式 */
.theme-switcher-container {
    position: absolute; /* 使用绝对定位 */
    top: 20px;
    right: 20px;
}

/* 主题切换按钮的样式 */
#theme-toggle-btn {
    padding: 8px 12px;
    background-color: #e0e0e0;
    border: 1px solid #ccc;
    border-radius: 20px;
    cursor: pointer;
}

/* 夜间模式下的切换按钮 */
body.dark-mode #theme-toggle-btn {
    background-color: #333;
    color: #e0e0e0;
    border-color: #555;
}


/* ===================================== */
/* == 浮动窗口 ==*/
/* ===================================== */
/* 触发链接的样式 */

.mpe-trigger-link {
  color: #0d6efd;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
}

/* 浮动窗口的容器样式 */
.mpe-draggable-window {
  position: fixed; /* 固定定位，不随页面滚动 */
  background-color: #f9f9f9;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1000; /* 确保在顶层 */
  width: 450px;
  min-height: 150px;
  display: none; /* 默认隐藏 */
  flex-direction: column;
}

/* 窗口头部 (这是拖动手柄！) */
.mpe-window-header {
  padding: 10px 15px;
  cursor: move; /* 鼠标样式变为可移动 */
  background-color: #f1f1f1;

  /* 新增：为弹窗头部背景添加过渡 */
  transition: background-color 0.3s ease;

  border-bottom: 1px solid #ccc;
  border-radius: 8px 8px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
}

/* 窗口标题 */
.mpe-window-title {
  color: #333;
}

/* 关闭按钮 */
.mpe-window-close {
  cursor: pointer;
  font-size: 20px;
  color: #888;
  padding: 0 5px;
}
.mpe-window-close:hover {
  color: #000;
}

/* 窗口内容区域 */
.mpe-window-content {
  padding: 15px;
  flex-grow: 1; /* 占据剩余空间 */
  overflow-y: auto; /* 内容过多时可滚动 */
  font-size: 14px;
  line-height: 1.6;
}

/* ===================================== */
/* == 弹窗的夜间模式样式 == */
/* ===================================== */

/* 当body是dark-mode时，针对弹窗容器的样式 */
body.dark-mode .mpe-draggable-window {
  background-color: #2a2a2e; /* 一个比内容区稍亮的深灰色 */
  border-color: #444;
}

/* 弹窗头部的样式 */
body.dark-mode .mpe-window-header {
  background-color: #333;
  border-bottom-color: #444;
}

/* 弹窗标题的样式 */
body.dark-mode .mpe-window-title {
  color: #e0e0e0;
}

/* 弹窗关闭按钮的样式 */
body.dark-mode .mpe-window-close {
  color: #aaa;
}
body.dark-mode .mpe-window-close:hover {
  color: #fff;
}

/* 弹窗内容区域的样式 */
body.dark-mode .mpe-window-content {
  color: #d0d0d0; /* 内容文字使用比正文稍暗一点的灰色 */
}

/* 弹窗内的链接样式 */
body.dark-mode .mpe-window-content a {
    color: #9e87f5; /* 调整链接颜色以适应深色背景 */
}


/* ======================================================= */
/* == Responsive Design: 移动端体验优化 == */
/* ======================================================= */

/* Apply these styles ONLY when the screen width is 768px or less (tablets and phones) */
@media (max-width: 768px) {

    /* 1. Adjust base font size and body padding for smaller screens */
    body {
        font-size: 17px; /* A comfortable reading size for mobile */
        padding: 1em 0;  /* Reduce the overall top/bottom margin */
    }

    /* 2. Make the main content area use more screen real estate */
    main#chapter-content {
        width: 100%; /* Allow content to span the full width */
        padding: 2.5rem 1.5rem; /* Reduce side padding, keep vertical padding */
        border-left: none;  /* Remove side borders to feel more native */
        border-right: none;
        border-radius: 0; /* Remove rounded corners for a full-bleed look */
    }

    /* 3. Make titles slightly smaller to fit better */
    h1, h2, h3 {
        line-height: 1.4;
    }

    /* 4. Adapt the interactive popup window for narrow screens */
    .mpe-draggable-window {
        width: 90vw; /* Make the window 90% of the viewport width */
        /* The JavaScript will automatically handle centering */
    }

    /* 5. Adjust the position of the theme switcher to be less intrusive */
    .theme-switcher-container {
        top: 10px;
        right: 10px;
    }
    #theme-toggle-btn {
        padding: 6px 10px;
    }

}

/* ===================================== */
/* == Slide-out Sidebar Navigation    == */
/* ===================================== */

/* The Page Wrapper: Contains all visible content */
.page-wrapper {
    width: 100%;
    min-height: 100vh;
    transition: transform 0.3s ease;

    /* 新增：从 body 移过来的居中样式 */
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2em 0; /* 将上下留白应用在这里 */
}

/* The Hamburger Icon Button */
.sidebar-toggle-btn {
    position: fixed; /* Stays on screen */
    top: 20px;
    left: 20px;
    z-index: 1200; /* Must be on top of everything */
    width: 40px;
    height: 35px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding: 8px 6px;
}
.sidebar-toggle-btn span {
    display: block;
    height: 2px;
    width: 100%;
    background: #333;
}

/* The Sidebar Panel Itself */
.sidebar-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px; /* Width of the sidebar */
    height: 100%;
    background-color: #f8f9fa;
    border-right: 1px solid #dee2e6;
    z-index: 1300;
    padding: 20px;
    overflow-y: auto;

    /* CORE LOGIC: Hide it off-screen to the left */
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}
.sidebar-nav h2 { margin-top: 0; }

/* The Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1250; /* Above wrapper, below sidebar */
    opacity: 0;
    visibility: hidden; /* Hide it completely */
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* --- THE ACTIVE STATE --- */
/* When the body has the .sidebar-open class, these styles activate */

body.sidebar-open .sidebar-nav {
    transform: translateX(0); /* Slide the sidebar in */
}
body.sidebar-open .page-wrapper {
    transform: translateX(300px); /* Push the content to the right */
}
body.sidebar-open .sidebar-overlay {
    opacity: 1;
    visibility: visible; /* Show the overlay */
}


/* ===================================== */
/* == 块引用 (Blockquote) 的样式 == */
/* ===================================== */

blockquote {
    margin: 1.5em 0; /* 上下外边距 */
    padding: 0.5em 1.5em; /* 上下和左右的内边距 */

    border-left: 4px solid #dee2e6; /* 核心！左侧的灰色边框 */
    background-color: #f8f9fa;     /* 一个非常淡的背景色 */
    color: #6c757d;                 /* 柔和的文字颜色 */

    /* 可选：让引文使用斜体 */
    /* font-style: italic; */
}

/* 修正块引用内部段落的边距，避免双重边距 */
blockquote p:last-of-type {
    margin-bottom: 0;
}