/*
 * =================================================================
 *     Frank's Blog - Master Stylesheet (v21.0 Pixel Perfect)
 * =================================================================
 * 
 *  TABLE OF CONTENTS:
 *  1. Variables & Theme Setup
 *  2. Base & Reset
 *  3. Layout
 *  4. Navigation & Controls (Fixed Alignment)
 *  5. Typography & Article
 *  6. Sidebar & TOC
 *  7. Modules
 */


/* =========================================
 *  1. VARIABLES & THEME SETUP
 * ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700;1,400&family=Noto+Sans+SC:wght@400;500;700&family=Noto+Serif+SC:wght@400;600;700&display=swap');

:root {
    --c-bg-body: #FFFFFF;
    --c-bg-soft: #F8F9FA;
    --c-bg-card: #FFFFFF;
    --c-text: #212529;
    --c-text-muted: #6c757d;
    --c-border: #dee2e6;
    --c-primary: #0d6efd;
    --c-nav-bg: rgba(255, 255, 255, 0.95);
    --c-nav-hover: rgba(0, 0, 0, 0.05);
    --img-brightness: 1;
    --c-sidebar-bg: rgba(255, 255, 255, 0.98);
    --c-sidebar-hover: rgba(0, 0, 0, 0.04);
    --c-sidebar-active-bg: rgba(13, 110, 253, 0.06);
    --font-serif: 'Lora', 'Noto Serif SC', serif;
    --font-sans: 'Noto Sans SC', 'Helvetica Neue', 'Arial', sans-serif;
    --navbar-height: 60px;
}

[data-theme="dark"] {
    --c-bg-body: #1c1c1e;
    --c-bg-soft: #2c2c2e;
    --c-bg-card: #2c2c2e;
    --c-text: #f2f2f7;
    --c-text-muted: #aeaeb2;
    --c-border: #38383a;
    --c-primary: #5e9eff;
    --c-nav-bg: rgba(28, 28, 30, 0.85);
    --c-nav-hover: rgba(255, 255, 255, 0.1);
    --img-brightness: 0.85;
    --c-sidebar-bg: rgba(28, 28, 30, 0.98);
    --c-sidebar-hover: rgba(255, 255, 255, 0.08);
    --c-sidebar-active-bg: rgba(94, 158, 255, 0.1);
}


/* =========================================
 *  2. BASE & RESET
 * ========================================= */
html { font-size: 1rem; }
body {
    font-family: var(--font-sans); color: var(--c-text); background-color: var(--c-bg-body);
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
a { color: var(--c-primary); text-decoration: none; transition: color 0.2s ease; }
a:hover { text-decoration: underline; }
img { transition: filter 0.3s ease; filter: brightness(var(--img-brightness)); }


/* =========================================
 *  3. LAYOUT
 * ========================================= */
.navbar.sticky-top {
    background-color: var(--c-nav-bg) !important;
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--c-border);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}
.navbar-toggler { padding: 0; border: none; box-shadow: none !important; }
@media (min-width: 992px) {
    .row { min-height: calc(100vh - var(--navbar-height)); }
    #sidebarMenu.offcanvas-lg {
        height: calc(100vh - var(--navbar-height)); position: sticky;
        top: var(--navbar-height); overflow-y: auto;
    }
}


/* =========================================
 *  4. NAVIGATION & CONTROLS (FIXED)
 * ========================================= */

/* --- 4.1 通用圆形按钮 (月亮, 菜单) --- */
.nav-round-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 50%;
    border: 1px solid transparent; background: transparent;
    color: var(--c-text-muted); transition: all 0.2s ease;
    cursor: pointer; text-decoration: none; padding: 0; /* 强制去padding */
}
.nav-round-btn:hover {
    background-color: var(--c-nav-hover); color: var(--c-text); transform: scale(1.05);
}
.nav-round-btn:active {
    transform: scale(0.95); background-color: var(--c-border);
}
/* [修复] 强制图标绝对居中，消除 line-height 偏差 */
.nav-round-btn i {
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100%; line-height: 1; margin: 0;
}

/* --- 4.2 左上角智能按钮 --- */
.smart-nav-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 50%;
    color: var(--c-text-muted); transition: all 0.2s ease;
    text-decoration: none; border: 1px solid transparent; padding: 0;
}
.smart-nav-link:hover {
    background-color: var(--c-nav-hover); color: var(--c-text); transform: scale(1.05);
}
.smart-nav-link:active {
    background-color: var(--c-border); transform: scale(0.95);
}
.smart-nav-link i { font-size: 1.1rem; line-height: 1; }

/* --- 4.3 语言切换 (响应式变形) --- */
.lang-capsule-btn {
    display: inline-flex; align-items: center; justify-content: center;
    height: 34px; 
    background-color: var(--c-bg-soft); color: var(--c-text-muted);
    font-size: 0.85rem; font-weight: 500; text-decoration: none;
    border: 1px solid var(--c-border); transition: all 0.2s ease;
    
    /* 桌面端默认样式 (胶囊) */
    padding: 0 12px; border-radius: 17px; width: auto;
}
.lang-capsule-btn:hover {
    background-color: var(--c-border); border-color: var(--c-border);
    color: var(--c-text); transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.lang-capsule-btn i {
    font-size: 1rem; line-height: 1;
    /* 桌面端：图标右侧有间距 */
    margin-right: 6px; 
}

/* [核心修复] 移动端：变成正圆形，完美对齐 */
@media (max-width: 575.98px) {
    .lang-capsule-btn {
        width: 34px; /* 强制正圆宽度 */
        padding: 0;  /* 去掉内边距 */
        border-radius: 50%; /* 变成圆 */
        background-color: transparent; /* 移动端背景透明，更轻量 */
        border-color: transparent; /* 去掉边框 */
    }
    .lang-capsule-btn i {
        margin-right: 0; /* [关键] 去掉右侧间距，图标才能居中 */
        font-size: 1.1rem; /* 稍微放大图标 */
    }
    /* 移动端悬浮态 */
    .lang-capsule-btn:active {
        background-color: var(--c-border);
    }
}

/* --- 4.4 字体控制组 (iOS Segmented Style - v22.0 Fixed) --- */
.font-controls-group {
    display: inline-flex; align-items: center; justify-content: center;
    background-color: var(--c-bg-soft);
    border-radius: 100px; padding: 3px; gap: 2px; height: 36px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.03);
    border: 1px solid var(--c-border);
}

.font-controls-group .nav-round-btn {
    width: 34px; height: 30px; border-radius: 100px; border: none;
    background: transparent; color: var(--c-text-muted);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); padding: 0;
    
    /* [核心修复] 使用 Flexbox 强制绝对居中，不依赖 line-height */
    display: flex; align-items: center; justify-content: center;
}

.font-controls-group .nav-round-btn:hover {
    background-color: var(--c-bg-body);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); transform: scale(1); color: var(--c-text);
}
.font-controls-group .nav-round-btn:active {
    background-color: var(--c-border); box-shadow: none; transform: scale(0.96);
}


/* --- 4.4 字体控制组 (v24.0 Liquid Glass Style) --- */

/* 容器：深邃的凹槽感 */
.font-controls-group {
    display: inline-flex; align-items: center; justify-content: center;
    
    /* 背景色：比普通背景更深一点，制造凹陷感 */
    background-color: rgba(0, 0, 0, 0.03); 
    
    /* 边框：极细 */
    border: 1px solid rgba(0, 0, 0, 0.05);
    
    border-radius: 100px; 
    padding: 2px; 
    height: 36px;
    
    /* 关键：内阴影制造深度 */
    box-shadow: inset 0 1px 4px rgba(0,0,0,0.05);
    
    position: relative;
}

/* 深色模式下的容器：发光的玻璃槽 */
[data-theme="dark"] .font-controls-group {
    background-color: rgba(0, 0, 0, 0.2); /* 更黑的底 */
    border: 1px solid rgba(255, 255, 255, 0.1); /* 亮边框 */
    box-shadow: inset 0 1px 4px rgba(0,0,0,0.4); /* 深内阴影 */
}

/* 按钮基础 */
.font-controls-group .nav-round-btn {
    width: 36px; height: 30px; 
    border-radius: 100px; border: none;
    background: transparent; 
    padding: 0;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); /* 果冻回弹动画 */
}

/* --- 视觉层级设计 --- */

/* 小 A：轻盈、半透明 */
.small-a-btn {
    color: var(--c-text);
    opacity: 0.5; /* 只有一半亮度，表示"小" */
    transform: scale(0.9);
}

/* 大 A：饱满、高亮 */
.large-a-btn {
    color: var(--c-text);
    opacity: 1; /* 全亮，表示"大" */
}

/* --- 交互动效 --- */

/* 悬停时：按钮浮起 */
.font-controls-group .nav-round-btn:hover {
    background-color: var(--c-bg-card); /* 变亮 */
    box-shadow: 0 2px 8px rgba(0,0,0,0.15); /* 投影 */
    opacity: 1; /* 悬浮时都变亮 */
    transform: scale(1);
}

/* 点击时：下压 */
.font-controls-group .nav-round-btn:active {
    transform: scale(0.92);
    box-shadow: none;
    background-color: rgba(0,0,0,0.05);
}
[data-theme="dark"] .font-controls-group .nav-round-btn:active {
    background-color: rgba(255,255,255,0.1);
}

/* --- 中间的分隔线 --- */
.font-separator {
    width: 1px;
    height: 12px;
    background-color: var(--c-text-muted);
    opacity: 0.2;
    margin: 0 2px;
}


/* 主题动效 */
.theme-icon-anim { transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55); }
#theme-toggle-btn:hover .theme-icon-anim { transform: rotate(15deg); }
#theme-toggle-btn:active .theme-icon-anim { transform: rotate(-15deg) scale(0.9); }
[data-theme="dark"] #theme-toggle-btn { color: #ffcc00; }
[data-theme="dark"] #theme-toggle-btn:hover { background-color: rgba(255, 204, 0, 0.1); }


/* =========================================
 *  5. TYPOGRAPHY & ARTICLE
 * ========================================= */
.article-body {
    max-width: 800px; margin: 0 auto;
    font-size: 1.125rem; line-height: 1.8;
}
.article-body .page-title {
    font-family: var(--font-sans); font-size: 2.8rem; font-weight: 700;
    margin-bottom: 1rem; line-height: 1.3; color: var(--c-text);
}
.article-body h1, .article-body h2, .article-body h3, .article-body h4 {
    font-family: var(--font-sans); font-weight: 700; line-height: 1.4;
    margin-top: 2.5em; margin-bottom: 1em; color: var(--c-text);
}
.article-body h2 { 
    font-size: 2rem; border-bottom: 1px solid var(--c-border); padding-bottom: 0.4em; 
}
.article-body h3 { font-size: 1.6rem; }
.article-body p { margin-bottom: 1.5em; }
.article-body .blockquote {
    margin: 2em 0; padding: 1.5em 2em; background-color: var(--c-bg-soft);
    border-left: 4px solid var(--c-primary); border-radius: 0.25rem;
    font-size: 0.95em; color: var(--c-text-muted);
}


/* =========================================
 *  6. SIDEBAR & TOC
 * ========================================= */
#sidebarMenu.offcanvas-lg, .offcanvas {
    background-color: var(--c-sidebar-bg) !important;
    backdrop-filter: blur(10px); border-right: none !important;
    box-shadow: 10px 0 30px rgba(0,0,0,0.05); color: var(--c-text) !important;
}
[data-theme="dark"] .offcanvas { box-shadow: 10px 0 30px rgba(0,0,0,0.3); }
.offcanvas-header { padding: 1.5rem 1.5rem 1rem 1.5rem; border-bottom: 1px solid transparent; }
.offcanvas-title, #sidebarMenu h5 {
    font-family: var(--font-sans); font-weight: 800; font-size: 1.5rem; letter-spacing: -0.02em;
    color: var(--c-text) !important; opacity: 0.9;
}
.btn-close { transition: filter 0.3s ease; }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

#sidebarMenu a, .toc-tree a, .list-group-item {
    display: block; position: relative; padding: 0.8rem 1rem; margin-bottom: 4px;
    font-family: var(--font-sans); font-size: 1.05rem; line-height: 1.6;
    color: var(--c-text-muted) !important; background-color: transparent !important;
    border: none !important; border-radius: 8px; text-decoration: none;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
#sidebarMenu a:hover, .toc-tree a:hover, .list-group-item:hover, .list-group-item-action:hover {
    background-color: var(--c-sidebar-hover) !important; color: var(--c-text) !important;
    padding-left: 1.2rem;
}
#sidebarMenu .active > a, #sidebarMenu a.active, .list-group-item.active {
    color: var(--c-primary) !important; font-weight: 600; background-color: var(--c-sidebar-active-bg) !important;
}
#sidebarMenu .active > a::before, #sidebarMenu a.active::before, .list-group-item.active::before {
    content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    height: 60%; width: 3px; background-color: var(--c-primary); border-radius: 0 4px 4px 0;
}
.toc-tree ul ul a, .list-group-item .ms-4 { padding-left: 2rem !important; font-size: 0.95rem; opacity: 0.8; }
#sidebarMenu::-webkit-scrollbar { width: 4px; }
#sidebarMenu::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,0.1); border-radius: 4px; }
[data-theme="dark"] #sidebarMenu::-webkit-scrollbar-thumb { background-color: rgba(255,255,255,0.1); }


/* =========================================
 *  7. MODULES
 * ========================================= */
.lightbox-modal {
    display: none; position: fixed !important; z-index: 10000; 
    left: 0; top: 0; width: 100vw; height: 100vh; overflow: hidden; 
    background-color: rgba(0,0,0,0.95); opacity: 0; transition: opacity 0.3s ease;
    flex-direction: column !important; justify-content: center !important;
    align-items: center !important; text-align: center !important; 
}
.lightbox-content {
    display: block !important; position: relative !important; margin: 0 auto !important; 
    padding: 0 !important; max-width: 90vw !important; max-height: 80vh !important; 
    width: auto !important; height: auto !important; object-fit: contain;
    box-shadow: 0 0 20px rgba(0,0,0,0.5); border-radius: 4px;
    transform: scale(0.95); transition: transform 0.3s; z-index: 10001; 
}
.lightbox-caption {
    display: block !important; position: relative !important;
    margin-top: 15px !important; margin-bottom: 0 !important;
    padding: 0 20px; width: 100%; color: #f1f1f1 !important; 
    font-size: 1rem !important; line-height: 1.5 !important;
    text-align: center !important; font-family: -apple-system, sans-serif;
    font-weight: normal !important; z-index: 10001;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.lightbox-close {
    position: absolute !important; top: max(20px, env(safe-area-inset-top)); 
    right: max(20px, env(safe-area-inset-right)); width: 50px; height: 50px;
    background: rgba(0, 0, 0, 0.4); border: 2px solid rgba(255,255,255,0.2);
    border-radius: 50%; cursor: pointer; z-index: 10002; 
    display: flex; justify-content: center; align-items: center;
    transition: all 0.2s; backdrop-filter: blur(5px);
}
.lightbox-close::before, .lightbox-close::after {
    content: ''; position: absolute; width: 24px; height: 2px;
    background-color: white; border-radius: 2px;
}
.lightbox-close::before { transform: rotate(45deg); }
.lightbox-close::after { transform: rotate(-45deg); }
.lightbox-close:hover { background: rgba(255, 255, 255, 0.1); transform: scale(1.1); }

#reading-progress-bar { transition: width 0.1s linear, background-color 0.4s ease !important; }
.progress-complete { background-color: #2eb872 !important; box-shadow: 0 0 10px rgba(46, 184, 114, 0.6); }

#back-to-top {
    border-color: var(--c-border) !important; background-color: var(--c-nav-bg) !important; color: var(--c-text) !important;
}
#back-to-top i { color: var(--c-text) !important; }
#back-to-top:hover {
    transform: translateY(-5px); background-color: var(--c-bg-body) !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
}

.callout {
    padding: 1.5rem; margin: 2rem 0; border: 1px solid var(--c-border);
    border-left-width: 5px; border-radius: 4px; background-color: var(--c-bg-soft);
    position: relative; color: var(--c-text);
}
.callout-info { border-left-color: #0d6efd; background-color: rgba(13, 110, 253, 0.08); }
.callout-warning { border-left-color: #ffc107; background-color: rgba(255, 193, 7, 0.08); }
.callout-quote { border-left-color: #6c757d; font-style: italic; font-family: serif; background-color: var(--c-bg-soft); }