/*
Theme Name: Terminal
Theme URI: https://example.com/terminal
Author: Your Name
Author URI: https://example.com
Description: 一个现代终端风格的 WordPress 主题，采用 Night Owl 配色方案，适合技术博客和极客站点
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: terminal
Tags: terminal, night-owl, tech, geek, monospace, dark
*/

/* ========================================
   Night Owl 配色方案
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Fira+Code:wght@400;500;700&display=swap');

:root {
    /* Night Owl 主题配色 */
    --terminal-bg: #011627;
    --terminal-bg-lighter: #01203d;
    --terminal-text: #d6deeb;
    --terminal-prompt: #c792ea;
    --terminal-input: #ffffff;
    --terminal-border: #5f7e97;
    --terminal-link: #80CBC4;
    --terminal-link-hover: #7fdbca;
    --terminal-error: #ef5350;
    --terminal-warning: #ffcb8b;
    --terminal-success: #addb67;
    --terminal-function: #82aaff;
    --terminal-variable: #ecc48d;
    --terminal-string: #ecc48d;
    --terminal-keyword: #c792ea;
    --terminal-comment: #637777;
    --terminal-secondary: #7e8e91;
    --terminal-selection: #1d3b53;
    --cursor-blink: 1s;
}

/* ========================================
   基础样式
   ======================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    color: var(--terminal-text);
    background-color: var(--terminal-bg);
    overflow-x: hidden;
}

/* 选择文本的颜色 */
::selection {
    background-color: var(--terminal-selection);
    color: var(--terminal-text);
}

/* 轻微的扫描线效果 - Night Owl 风格 */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.03),
        rgba(0, 0, 0, 0.03) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 1000;
}

/* ========================================
   终端窗口样式
   ======================================== */

.terminal-window {
    max-width: 1200px;
    margin: 2rem auto;
    border: 2px solid var(--terminal-border);
    box-shadow: 0 0 20px rgba(95, 126, 151, 0.2);
    background: var(--terminal-bg);
    border-radius: 8px;
}

/* 单篇文章页面扩展终端窗口宽度 */
body.single-post .terminal-window {
    max-width: 1400px;
}

/* 只对终端头部应用圆角遮罩效果 */
.terminal-header {
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    overflow: hidden;
}

.terminal-header {
    background: var(--terminal-bg-lighter);
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--terminal-border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.terminal-buttons {
    display: flex;
    gap: 0.5rem;
}

.terminal-button {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(95, 126, 151, 0.5);
}

.terminal-button.close { background: #ef5350; }
.terminal-button.minimize { background: #ffcb8b; }
.terminal-button.maximize { background: #addb67; }

.terminal-title {
    flex: 1;
    text-align: center;
    color: var(--terminal-text);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* ========================================
   导航栏
   ======================================== */

.site-header {
    background: var(--terminal-bg);
    border-bottom: 2px solid var(--terminal-border);
    padding: 1rem 2rem;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 2rem;
}

.site-branding {
    flex: 1;
}

.site-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--terminal-text);
}

.site-title::before {
    content: '> ';
    color: var(--terminal-prompt);
}

.site-title a {
    color: var(--terminal-text);
    text-decoration: none;
    animation: typing 2s steps(20);
    overflow: hidden;
    white-space: nowrap;
}

@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

.main-navigation {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.main-navigation ul {
    list-style: none;
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.main-navigation a {
    color: var(--terminal-link);
    text-decoration: none;
    position: relative;
}

.main-navigation a::before {
    content: '$ ';
    color: var(--terminal-prompt);
}

.main-navigation a:hover {
    color: var(--terminal-text);
    text-decoration: underline;
}

/* ========================================
   搜索表单
   ======================================== */

.header-search {
    flex-shrink: 0;
    align-self: flex-start;
}

.header-search .search-form {
    margin: 0;
}

.header-search .search-form > div {
    display: flex;
    align-items: center;
    border: 1px solid var(--terminal-border);
    background: rgba(0, 255, 0, 0.05);
    padding: 0.5rem;
    border-radius: 4px;
    min-width: 300px;
}

.header-search label {
    color: var(--terminal-prompt);
    margin-right: 0.5rem;
    white-space: nowrap;
    font-size: 13px;
}

.header-search .search-field {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--terminal-text);
    outline: none;
    font-family: inherit;
    font-size: 13px;
    padding: 0.25rem;
}

.header-search .search-field::placeholder {
    color: var(--terminal-secondary);
    opacity: 0.6;
}

.header-search .search-submit {
    background: var(--terminal-border);
    color: var(--terminal-bg);
    border: none;
    padding: 0.3rem 1rem;
    cursor: pointer;
    font-family: inherit;
    margin-left: 0.5rem;
    border-radius: 3px;
    font-size: 12px;
    transition: all 0.3s ease;
}

.header-search .search-submit:hover {
    background: var(--terminal-link);
    color: var(--terminal-bg);
}


/* ========================================
   内容区域
   ======================================== */

.site-content {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

/* 单篇文章页面 - 扩展宽度以容纳目录 */
body.single-post .site-content {
    max-width: 1400px;
}

/* ========================================
   文章列表
   ======================================== */

.posts-list {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.post-card {
    border: 1px solid var(--terminal-border);
    padding: 1.5rem;
    background: var(--terminal-bg-lighter);
    position: relative;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.post-card:hover {
    border-color: var(--terminal-link);
    box-shadow: 0 0 15px rgba(128, 203, 196, 0.1);
}

.post-card::before {
    content: '[POST #' attr(data-id) ']';
    position: absolute;
    top: -10px;
    left: 10px;
    background: var(--terminal-bg);
    padding: 0 0.5rem;
    color: var(--terminal-keyword);
    font-size: 10px;
}

.post-meta {
    color: var(--terminal-secondary);
    font-size: 12px;
    margin-bottom: 1rem;
}

.post-meta::before {
    content: '# ';
    color: var(--terminal-comment);
}

.post-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    line-height: 1.3;
}

.post-title::before {
    content: '>> ';
    color: var(--terminal-prompt);
}

.post-title a {
    color: var(--terminal-text);
    text-decoration: none;
}

.post-title a:hover {
    color: var(--terminal-link);
    text-decoration: underline;
}

.post-excerpt {
    color: var(--terminal-secondary);
    margin-bottom: 1rem;
    padding-left: 2rem;
}

.read-more {
    display: inline-block;
    color: var(--terminal-link);
    text-decoration: none;
    border: 1px solid var(--terminal-link);
    padding: 0.3rem 1rem;
    transition: all 0.3s;
}

.read-more::before {
    content: '[ ';
}

.read-more::after {
    content: ' ]';
}

.read-more:hover {
    background: var(--terminal-link);
    color: var(--terminal-bg);
}

/* ========================================
   单篇文章
   ======================================== */

.single-post {
    border: 1px solid var(--terminal-border);
    padding: 2rem;
    background: var(--terminal-bg-lighter);
    border-radius: 4px;
}

.entry-header {
    margin-bottom: 2rem;
    border-bottom: 1px dashed var(--terminal-border);
    padding-bottom: 1rem;
}

.entry-title {
    font-size: 2rem;
    line-height: 1.2;
    margin-bottom: 1rem;
    color: var(--terminal-function);
}

.entry-title::before {
    content: '>>> ';
    color: var(--terminal-prompt);
}

.entry-content {
    color: var(--terminal-text);
}

.entry-content h2 {
    margin: 2rem 0 1rem;
    color: var(--terminal-function);
}

.entry-content h2::before {
    content: '## ';
    color: var(--terminal-keyword);
}

.entry-content h3 {
    margin: 1.5rem 0 0.75rem;
    color: var(--terminal-link);
}

.entry-content h3::before {
    content: '### ';
    color: var(--terminal-keyword);
}

.entry-content p {
    margin-bottom: 1rem;
    text-indent: 2rem;
}

.entry-content a {
    color: var(--terminal-link);
    text-decoration: underline;
}

.entry-content a:hover {
    color: var(--terminal-link-hover);
}

.entry-content code {
    background: rgba(130, 170, 255, 0.1);
    color: var(--terminal-string);
    padding: 0.2rem 0.4rem;
    border: 1px solid rgba(130, 170, 255, 0.2);
    border-radius: 3px;
}

.entry-content pre {
    background: rgba(1, 32, 61, 0.6);
    border: 1px solid var(--terminal-border);
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
    position: relative;
    border-radius: 4px;
}

.entry-content pre::before {
    content: '$ cat code.txt';
    display: block;
    color: var(--terminal-comment);
    margin-bottom: 0.5rem;
    font-size: 12px;
}

.entry-content pre code {
    background: none;
    border: none;
    color: var(--terminal-text);
}

.entry-content blockquote {
    border-left: 2px solid var(--terminal-border);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--terminal-secondary);
}

.entry-content blockquote::before {
    content: '> ';
}

.entry-content ul,
.entry-content ol {
    margin: 1rem 0;
    padding-left: 3rem;
}

.entry-content li {
    margin: 0.5rem 0;
}

.entry-content li::marker {
    color: var(--terminal-prompt);
}

/* ========================================
   侧边栏
   ======================================== */

.sidebar {
    border: 1px solid var(--terminal-border);
    padding: 1rem;
    background: var(--terminal-bg-lighter);
    border-radius: 4px;
}

.widget {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed rgba(95, 126, 151, 0.3);
}

.widget:last-child {
    border-bottom: none;
}

.widget-title {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--terminal-function);
}

.widget-title::before {
    content: '[[ ';
    color: var(--terminal-keyword);
}

.widget-title::after {
    content: ' ]]';
    color: var(--terminal-keyword);
}

.widget ul {
    list-style: none;
}

.widget li {
    padding: 0.3rem 0;
}

.widget li::before {
    content: '→ ';
    color: var(--terminal-success);
}

.widget a {
    color: var(--terminal-link);
    text-decoration: none;
}

.widget a:hover {
    color: var(--terminal-link-hover);
    text-decoration: underline;
}

/* ========================================
   页脚
   ======================================== */

.site-footer {
    border-top: 2px solid var(--terminal-border);
    padding: 2rem;
    text-align: center;
    margin-top: 4rem;
}

.site-footer::before {
    content: '─────────────────────────────────────────────────';
    display: block;
    color: var(--terminal-border);
    margin-bottom: 1rem;
    opacity: 0.5;
}

.site-footer p {
    color: var(--terminal-secondary);
    font-size: 12px;
}

.site-footer a {
    color: var(--terminal-link);
    text-decoration: none;
}

/* ========================================
   光标效果
   ======================================== */

.cursor {
    display: inline-block;
    width: 8px;
    height: 16px;
    background: var(--terminal-link);
    animation: blink var(--cursor-blink) infinite;
    margin-left: 2px;
}

@keyframes blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* ========================================
   分页
   ======================================== */

.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 2rem;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    padding: 0.5rem 1rem;
    border: 1px solid var(--terminal-border);
    text-decoration: none;
    color: var(--terminal-text);
    background: var(--terminal-bg-lighter);
    border-radius: 4px;
    transition: all 0.3s ease;
}

.pagination a:hover {
    background: var(--terminal-link);
    color: var(--terminal-bg);
    border-color: var(--terminal-link);
}

.pagination .current {
    background: var(--terminal-function);
    color: var(--terminal-bg);
    border-color: var(--terminal-function);
}

/* ========================================
   响应式设计
   ======================================== */

@media (max-width: 768px) {
    .terminal-window {
        margin: 1rem;
        border: 1px solid var(--terminal-border);
    }

    .site-content {
        padding: 1rem;
    }

    .entry-title {
        font-size: 1.5rem;
    }

    .main-navigation ul {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .header-top {
        flex-direction: column;
        gap: 1rem;
    }
    
    .header-search .search-form > div {
        min-width: auto;
        width: 100%;
    }
    
    .header-search label {
        font-size: 11px;
    }
    
    .header-search .search-field {
        font-size: 12px;
    }
}

/* ========================================
   加载动画
   ======================================== */

.loading::after {
    content: '';
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { content: '.'; }
    33% { content: '..'; }
    66% { content: '...'; }
}

/* ========================================
   404 页面
   ======================================== */

.error-404 {
    text-align: center;
    padding: 4rem 2rem;
}

.error-404 h1 {
    font-size: 4rem;
    color: var(--terminal-error);
    margin-bottom: 1rem;
}

.error-404 h1::before {
    content: '[ERROR ';
}

.error-404 h1::after {
    content: ']';
}

/* ========================================
   辅助类
   ======================================== */

.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.text-glow {
    text-shadow: 0 0 10px var(--terminal-link);
}

/* ========================================
   浮动目录（TOC）
   ======================================== */

.single-with-toc {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
    align-items: start;
}

.single-with-toc .site-main {
    min-width: 0; /* 防止内容溢出 */
}

.table-of-contents {
    position: -webkit-sticky; /* Safari 支持 */
    position: sticky;
    top: 1rem; /* 距离顶部的距离 */
    align-self: start;
    max-height: calc(100vh - 2rem); /* 最大高度，确保不超出视口 */
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--terminal-bg-lighter);
    border: 1px solid var(--terminal-border);
    border-radius: 4px;
    padding: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10; /* 确保在其他内容上方 */
}

/* 性能优化 */
.table-of-contents {
    will-change: transform;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.toc-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--terminal-function);
    font-weight: 700;
    font-size: 0.875rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--terminal-border);
}

.toc-icon {
    font-size: 1rem;
}

.toc-nav {
    font-size: 0.875rem;
}

.toc-nav ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.toc-nav li {
    margin: 0;
    padding: 0;
}

.toc-nav a {
    display: block;
    padding: 0.4rem 0;
    color: var(--terminal-secondary);
    text-decoration: none;
    transition: all 0.3s ease;
    border-left: 2px solid transparent;
    padding-left: 0.75rem;
}

.toc-nav a:hover {
    color: var(--terminal-link);
    border-left-color: var(--terminal-link);
    background: rgba(128, 203, 196, 0.05);
}

.toc-nav a.active {
    color: var(--terminal-link);
    border-left-color: var(--terminal-link);
    background: rgba(128, 203, 196, 0.1);
}

/* 二级标题缩进 */
.toc-nav .toc-h3 a {
    padding-left: 1.5rem;
    font-size: 0.8125rem;
}

/* 三级标题缩进 */
.toc-nav .toc-h4 a {
    padding-left: 2.25rem;
    font-size: 0.75rem;
}

/* 滚动条样式 */
.table-of-contents::-webkit-scrollbar {
    width: 6px;
}

.table-of-contents::-webkit-scrollbar-track {
    background: var(--terminal-bg);
}

.table-of-contents::-webkit-scrollbar-thumb {
    background: var(--terminal-border);
    border-radius: 3px;
}

.table-of-contents::-webkit-scrollbar-thumb:hover {
    background: var(--terminal-link);
}

/* 响应式：小屏幕隐藏目录 */
@media (max-width: 1024px) {
    .single-with-toc {
        grid-template-columns: 1fr;
    }
    
    .table-of-contents {
        display: none;
    }
}

/* 为文章内容的标题添加滚动偏移 */
.entry-content h2,
.entry-content h3,
.entry-content h4 {
    scroll-margin-top: 2rem;
}

