/* ============================================
   Linux新手入门 - 样式表
   设计理念：中庸、低调、严谨，注重可读性
   ============================================ */

/* ---- CSS 变量 ---- */
:root {
    --color-bg: #fdfdfc;
    --color-surface: #ffffff;
    --color-text: #2c2c2c;
    --color-text-secondary: #5a5a5a;
    --color-text-muted: #888888;
    --color-link: #2563eb;
    --color-link-hover: #1d4ed8;
    --color-border: #e5e5e0;
    --color-accent: #f59e0b;
    --color-code-bg: #f5f5f0;
    --color-pre-bg: #1e1e1e;
    --color-pre-text: #e0e0d8;
    --color-header-bg: #fafaf7;
    --color-footer-bg: #2c2c2c;
    --color-footer-text: #c0c0b8;
    --color-sidebar-bg: #fafaf7;
    --color-sidebar-active: #eff6ff;
    --color-sidebar-hover: #f0f0eb;
    --color-inline-code: #d9480f;
    --color-warning-bg: #fffbeb;
    --color-warning-border: #fcd34d;
    --color-tip-bg: #f0fdf4;
    --color-tip-border: #86efac;
    --color-note-bg: #eff6ff;
    --color-note-border: #93c5fd;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
    --font-mono: "Cascadia Code", "Fira Code", "JetBrains Mono", "SF Mono", "Consolas", "Source Code Pro", "Noto Sans Mono SC", monospace;

    --max-width: 1280px;
    --sidebar-width: 280px;
    --header-height: auto;
    --content-padding: 2.5rem;
    --line-height: 1.8;
}

/* ---- Reset & Base ---- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background-color: var(--color-bg);
    line-height: var(--line-height);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--color-link);
    text-decoration: none;
    transition: color 0.15s ease;
}

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

/* ---- Header ---- */
.site-header {
    background: var(--color-header-bg);
    border-bottom: 1px solid var(--color-border);
    padding: 1.5rem var(--content-padding);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.site-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.site-title:hover {
    text-decoration: none;
    color: var(--color-text);
}

.tux-logo {
    flex-shrink: 0;
}

.site-subtitle {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-left: 0.25rem;
}

/* ---- Header Ad Banner ---- */
.header-ad {
    position: relative;
    width: 100%;
    margin: 0.65rem 0 0;
    padding: 0.55rem 1rem;
    border: 1px dashed #e0d8c8;
    border-radius: 6px;
    background: transparent;
    transition: border-color 0.2s;
}

.header-ad:hover {
    border-color: #d0c4a8;
}

.ad-badge {
    position: absolute;
    top: -1px;
    left: 8px;
    transform: translateY(-50%);
    background: #f0ede5;
    color: #999;
    font-size: 0.65rem;
    padding: 0.1em 0.5em;
    border-radius: 3px;
    letter-spacing: 0.05em;
    line-height: 1.5;
    pointer-events: none;
}

.ad-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.ad-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-text {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    line-height: 1.5;
    margin-right: 1rem;
}

.ad-cta {
    flex-shrink: 0;
    display: inline-block;
    padding: 0.35em 1em;
    font-size: 0.8rem;
    color: var(--color-link);
    border: 1px solid var(--color-link);
    border-radius: 4px;
    transition: all 0.15s;
    white-space: nowrap;
}

.ad-cta:hover {
    background: var(--color-link);
    color: #fff;
    text-decoration: none;
}

/* ---- Main Layout ---- */
.main-container {
    display: flex;
    max-width: var(--max-width);
    margin: 0 auto;
    width: 100%;
    flex: 1;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--color-sidebar-bg);
    border-right: 1px solid var(--color-border);
    padding: 1.5rem 0;
    position: sticky;
    top: calc(var(--header-height) + 0px);
    /* Adjust based on header */
    height: calc(100vh - 120px);
    overflow-y: auto;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 200;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    color: var(--color-text);
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

/* Welcome hint: attract attention with pulse + label */
.sidebar-toggle.hint {
    background: var(--color-link);
    color: #fff;
    border-color: var(--color-link);
    box-shadow: 0 2px 16px rgba(37, 99, 235, 0.4);
    animation: togglePulse 2s ease-in-out infinite;
}

.sidebar-toggle.hint::before {
    content: "👆 打开目录";
    position: absolute;
    bottom: 56px;
    right: -4px;
    white-space: nowrap;
    font-size: 0.72rem;
    color: var(--color-link);
    font-weight: 600;
    letter-spacing: 0.03em;
    pointer-events: none;
    animation: toggleHintBounce 1.5s ease-in-out infinite;
}

@keyframes togglePulse {
    0%, 100% { transform: scale(1); box-shadow: 0 2px 16px rgba(37, 99, 235, 0.4); }
    50% { transform: scale(1.08); box-shadow: 0 4px 24px rgba(37, 99, 235, 0.6); }
}

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

/* Close button inside sidebar (mobile only) */
.sidebar-close {
    display: none;
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    font-size: 1.25rem;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: 4px;
    line-height: 1;
    padding: 0;
    z-index: 10;
}

.sidebar-close:hover {
    color: var(--color-text);
    background: var(--color-sidebar-hover);
}

.nav-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 1.25rem;
    margin-bottom: 0.75rem;
}

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

.chapter-list li {
    margin: 0;
}

.chapter-link {
    display: flex;
    flex-direction: column;
    padding: 0.6rem 1.25rem;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
    text-decoration: none;
}

.chapter-link:hover {
    background: var(--color-sidebar-hover);
    color: var(--color-text);
    text-decoration: none;
}

.chapter-link.active {
    background: var(--color-sidebar-active);
    color: var(--color-link);
    border-left-color: var(--color-link);
    font-weight: 600;
}

.ch-num {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: 0.1rem;
}

.chapter-link.active .ch-num {
    color: var(--color-link);
}

/* ---- Sidebar Accordion Groups ---- */
.sidebar-group {
    margin-bottom: 0.25rem;
}

.sidebar-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
    border-left: 3px solid transparent;
}

.sidebar-group-header:hover {
    background: var(--color-sidebar-hover);
    color: var(--color-text);
}

.sidebar-group-header .group-icon {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    color: var(--color-text-muted);
}

.sidebar-group-header.open .group-icon {
    transform: rotate(90deg);
}

.sidebar-group-body {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease;
}

.sidebar-group-body.open {
    max-height: 3000px;
}

.sidebar-group-body .chapter-link {
    padding-left: 2rem;
}

/* ---- Content ---- */
.content {
    flex: 1;
    padding: var(--content-padding);
    min-width: 0;
    max-width: 900px;
}

.welcome-message {
    max-width: 700px;
    margin: 3rem auto 0;
}

.welcome-message h2 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
    color: var(--color-text);
}

.welcome-message>p {
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
    font-size: 1.05rem;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-top: 2rem;
}

.feature-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.25rem;
    transition: box-shadow 0.2s ease;
}

.feature-card:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.feature-card h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

.feature-card p {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    line-height: 1.6;
}

/* ---- Article ---- */
.article-content {
    max-width: 750px;
    width: 100%;
    margin: 0 auto;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Ensure all content respects container width */
.article-content img,
.article-content video,
.article-content iframe {
    max-width: 100%;
    height: auto;
}

/* Table wrapper for mobile horizontal scroll */
.article-content .table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1.25rem;
}

.article-content h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--color-text);
    line-height: 1.3;
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 0.75rem;
}

.article-content h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    color: var(--color-text);
    line-height: 1.4;
}

.article-content h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
    color: var(--color-text);
}

.article-content h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--color-text-secondary);
}

.article-content p {
    margin-bottom: 1.1rem;
    color: var(--color-text);
}

.article-content ul,
.article-content ol {
    margin-bottom: 1.1rem;
    padding-left: 1.5rem;
}

.article-content li {
    margin-bottom: 0.35rem;
    color: var(--color-text);
}

.article-content li>ul,
.article-content li>ol {
    margin-top: 0.35rem;
    margin-bottom: 0;
}

.article-content strong {
    font-weight: 600;
}

/* ---- Code ---- */
.article-content code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--color-code-bg);
    padding: 0.15em 0.4em;
    border-radius: 3px;
    color: var(--color-inline-code);
    word-break: break-word;
}

.article-content pre {
    background: var(--color-pre-bg);
    color: var(--color-pre-text);
    padding: 1.25rem 1.5rem;
    border-radius: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1.25rem;
    line-height: 1.6;
    font-size: 0.875rem;
    max-width: 100%;
    white-space: pre;
    word-wrap: normal;
    tab-size: 4;
    -moz-tab-size: 4;
}

.article-content pre code {
    font-family: var(--font-mono);
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
    border-radius: 0;
}

/* ---- Tables ---- */
.article-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.25rem;
    font-size: 0.925rem;
}

.article-content thead {
    background: var(--color-code-bg);
}

.article-content th {
    padding: 0.6rem 0.85rem;
    text-align: left;
    font-weight: 600;
    border: 1px solid var(--color-border);
}

.article-content td {
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--color-border);
}

.article-content tr:nth-child(even) {
    background: var(--color-header-bg);
}

/* ---- Callout Boxes ---- */
.callout {
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    border-left: 4px solid;
    border-radius: 4px;
    font-size: 0.925rem;
}

.callout-tip {
    background: var(--color-tip-bg);
    border-color: var(--color-tip-border);
}

.callout-warning {
    background: var(--color-warning-bg);
    border-color: var(--color-warning-border);
}

.callout-note {
    background: var(--color-note-bg);
    border-color: var(--color-note-border);
}

.callout strong:first-child {
    display: block;
    margin-bottom: 0.35rem;
}

/* ---- Back to Top ---- */
.back-to-top {
    display: block;
    margin-top: 3rem;
    text-align: center;
    padding: 0.75rem;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    border-top: 1px solid var(--color-border);
    transition: color 0.15s;
}

.back-to-top:hover {
    color: var(--color-link);
    text-decoration: none;
}

/* ---- Footer ---- */
.site-footer {
    background: var(--color-footer-bg);
    color: var(--color-footer-text);
    margin-top: auto;
}

.footer-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    padding: 1.5rem var(--content-padding);
}

.footer-section h4 {
    color: #e8e8e0;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.footer-section p {
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    line-height: 1.6;
}

.footer-section a {
    color: #a0c4ff;
}

.footer-section a:hover {
    color: #bfd6ff;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 260px;
        --content-padding: 1.25rem;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 150;
        transform: translateX(-100%);
        box-shadow: 2px 0 16px rgba(0, 0, 0, 0.1);
    }

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

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 140;
    }

    .sidebar-overlay.visible {
        display: block;
    }

    .sidebar-toggle {
        display: flex;
    }

    .sidebar-close {
        display: block;
    }

    .header-inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .header-ad {
        margin: 0.5rem 0 0;
        padding: 0.5rem 0.75rem;
    }

    .ad-inner {
        gap: 0.5rem;
    }

    .ad-text {
        font-size: 0.78rem;
    }

    .ad-cta {
        font-size: 0.75rem;
        padding: 0.3em 0.75em;
    }

    .site-subtitle {
        margin-left: 0;
    }

    .content {
        padding: 1.25rem;
    }

    .article-content {
        max-width: 100%;
    }

    .article-content h1 {
        font-size: 1.5rem;
    }

    .article-content h2 {
        font-size: 1.2rem;
    }

    .article-content h3 {
        font-size: 1.05rem;
    }

    .article-content table {
        font-size: 0.8rem;
    }

    .article-content th,
    .article-content td {
        padding: 0.4rem 0.5rem;
    }

    .footer-inner {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }
}

@media (max-width: 600px) {
    :root {
        --content-padding: 1rem;
    }

    .site-header {
        padding: 0.75rem 1rem;
    }

    .header-ad {
        margin: 0.35rem 0 0;
        padding: 0.4rem 0.6rem;
    }

    .ad-badge {
        font-size: 0.6rem;
    }

    .ad-text {
        font-size: 0.72rem;
        min-width: 0;
    }

    .ad-cta {
        font-size: 0.7rem;
        padding: 0.25em 0.6em;
    }

    .site-title {
        font-size: 1.15rem;
    }

    .tux-logo {
        width: 36px;
        height: 43px;
    }

    .site-subtitle {
        font-size: 0.75rem;
    }

    .content {
        padding: 1rem 0.75rem;
    }

    .feature-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .welcome-message {
        margin: 1.5rem auto 0;
    }

    .welcome-message h2 {
        font-size: 1.25rem;
    }

    .article-content h1 {
        font-size: 1.35rem;
        padding-bottom: 0.5rem;
    }

    .article-content h2 {
        font-size: 1.1rem;
        margin-top: 1.75rem;
    }

    .article-content h3 {
        font-size: 1rem;
    }

    .article-content p,
    .article-content li {
        font-size: 0.925rem;
    }

    .article-content pre {
        padding: 0.75rem 0.85rem;
        font-size: 0.75rem;
        border-radius: 4px;
        margin-bottom: 1rem;
    }

    .article-content table {
        font-size: 0.75rem;
    }

    .article-content th,
    .article-content td {
        padding: 0.35rem 0.4rem;
    }

    .callout {
        padding: 0.75rem 1rem;
        font-size: 0.85rem;
    }

    .nav-title {
        font-size: 0.8rem;
    }

    .sidebar-toggle {
        width: 42px;
        height: 42px;
        bottom: 1rem;
        right: 1rem;
    }

    .back-to-top {
        margin-top: 2rem;
        font-size: 0.8rem;
    }
}

/* ---- Print Styles ---- */
@media print {
    .sidebar,
    .sidebar-toggle,
    .site-footer,
    .back-to-top {
        display: none;
    }

    .content {
        max-width: 100%;
        padding: 0;
    }

    body {
        font-size: 12pt;
    }
}
