/* ============================================================
   人工智能 Python 实现学习网站 · 灰色文艺主题
   Gray Literary Theme
   ============================================================ */

:root {
    /* —— 灰阶色板（暖灰 / 宣纸色系）—— */
    --paper:        #faf8f5;   /* 页面底色：宣纸白 */
    --paper-2:      #f2efe9;   /* 次级底色 */
    --paper-3:      #eae6de;   /* 卡片悬浮底 */
    --ink:          #2e2c29;   /* 主墨色 */
    --ink-soft:     #57534d;   /* 次级文字 */
    --ink-faint:    #8c867c;   /* 弱化文字 */
    --line:         #ddd8ce;   /* 细线 */
    --line-strong:  #c4bdb1;   /* 粗线 */
    --accent:       #6f6860;   /* 主点缀灰 */
    --accent-deep:  #4c463f;   /* 深点缀 */
    --accent-soft:  #b7afa3;   /* 浅点缀 */
    --code-bg:      #322f2b;   /* 代码块深炭灰 */
    --code-head:    #403c37;   /* 代码块标题栏 */
    --code-text:    #e7e2d8;   /* 代码文字 */
    --code-comment: #8f887c;
    --code-key:     #c8b9a0;   /* 关键字：暖驼 */
    --code-str:     #a9b39a;   /* 字符串：灰绿 */
    --code-num:     #c9a78e;   /* 数字：陶土 */
    --code-fn:      #b8b2a6;   /* 函数名 */
    --shadow:       0 2px 18px rgba(60, 55, 48, .07);
    --shadow-lg:    0 10px 40px rgba(60, 55, 48, .12);
    --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", Georgia, "Times New Roman", serif;
    --sans:  "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    --mono:  "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", Monaco, monospace;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--serif);
    background: var(--paper);
    color: var(--ink);
    line-height: 1.95;
    font-size: 16.5px;
    letter-spacing: .02em;
    -webkit-font-smoothing: antialiased;
}

/* 纸张纹理：极淡的细颗粒感 */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: .5;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(120,110,95,.025) 0, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(120,110,95,.02) 0, transparent 40%);
}

a { color: var(--accent-deep); text-decoration: none; transition: color .25s; }
a:hover { color: #000; }

img { max-width: 100%; }

::selection { background: #c9c2b5; color: #23211d; }

/* ============================================================
   顶部导航
   ============================================================ */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(250, 248, 245, .86);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}

.nav-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 28px;
    height: 66px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--serif);
    font-size: 19px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: .12em;
    white-space: nowrap;
}

.brand .seal {
    width: 34px; height: 34px;
    border: 1.5px solid var(--accent-deep);
    border-radius: 6px;
    display: grid;
    place-items: center;
    font-size: 15px;
    color: var(--accent-deep);
    background: var(--paper-2);
    font-family: var(--serif);
}

.brand small {
    font-size: 11px;
    font-weight: 400;
    color: var(--ink-faint);
    letter-spacing: .22em;
    display: block;
    line-height: 1.2;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none;
}

.nav-links a {
    padding: 7px 13px;
    font-size: 14.5px;
    color: var(--ink-soft);
    border-radius: 4px;
    letter-spacing: .08em;
}

.nav-links a:hover { color: var(--ink); background: var(--paper-3); }
.nav-links a.active { color: #fff; background: var(--accent-deep); }

.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--line-strong);
    border-radius: 5px;
    width: 40px; height: 36px;
    cursor: pointer;
    color: var(--ink-soft);
    font-size: 17px;
}

/* ============================================================
   首页 Hero
   ============================================================ */
.hero {
    position: relative;
    max-width: 1180px;
    margin: 0 auto;
    padding: 110px 28px 80px;
    text-align: center;
    z-index: 1;
}

.hero .overline {
    font-size: 13px;
    letter-spacing: .55em;
    text-indent: .55em;
    color: var(--ink-faint);
    margin-bottom: 30px;
}

.hero h1 {
    font-size: clamp(34px, 5.4vw, 58px);
    font-weight: 700;
    letter-spacing: .14em;
    line-height: 1.4;
}

.hero h1 em {
    font-style: normal;
    position: relative;
    color: var(--accent-deep);
}
.hero h1 em::after {
    content: "";
    position: absolute;
    left: 2%; right: 2%; bottom: 4px;
    height: 10px;
    background: rgba(140, 130, 115, .22);
    z-index: -1;
}

.hero .sub {
    max-width: 680px;
    margin: 34px auto 0;
    color: var(--ink-soft);
    font-size: 17px;
    line-height: 2.1;
}

.hero-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin: 44px auto 0;
    color: var(--accent-soft);
}
.hero-divider .line { width: 90px; height: 1px; background: var(--line-strong); }
.hero-divider .dot { width: 6px; height: 6px; border: 1px solid var(--accent-soft); transform: rotate(45deg); }

.hero-actions {
    margin-top: 46px;
    display: flex;
    gap: 18px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    display: inline-block;
    padding: 13px 34px;
    font-family: var(--serif);
    font-size: 15.5px;
    letter-spacing: .18em;
    border-radius: 3px;
    border: 1px solid var(--accent-deep);
    cursor: pointer;
    transition: all .3s;
}
.btn-primary { background: var(--accent-deep); color: #f5f2ec; }
.btn-primary:hover { background: #000; border-color: #000; color: #fff; }
.btn-ghost { background: transparent; color: var(--accent-deep); }
.btn-ghost:hover { background: var(--paper-3); }

/* 首页数据条 */
.hero-meta {
    margin-top: 70px;
    display: flex;
    justify-content: center;
    gap: 0;
    flex-wrap: wrap;
}
.hero-meta .item {
    padding: 6px 34px;
    border-right: 1px solid var(--line);
}
.hero-meta .item:last-child { border-right: none; }
.hero-meta b { display: block; font-size: 27px; font-weight: 700; color: var(--accent-deep); }
.hero-meta span { font-size: 13px; color: var(--ink-faint); letter-spacing: .15em; }

/* ============================================================
   章节卡片（首页）
   ============================================================ */
.section-head {
    max-width: 1180px;
    margin: 0 auto;
    padding: 30px 28px 40px;
    text-align: center;
}
.section-head h2 {
    font-size: 30px;
    letter-spacing: .3em;
    text-indent: .3em;
    font-weight: 700;
}
.section-head p {
    margin-top: 14px;
    color: var(--ink-faint);
    font-size: 14.5px;
    letter-spacing: .1em;
}

.chapter-grid {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 28px 90px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
    gap: 26px;
    position: relative;
    z-index: 1;
}

.chapter-card {
    display: block;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 34px 30px 30px;
    position: relative;
    transition: transform .35s ease, box-shadow .35s ease, border-color .35s;
    overflow: hidden;
}
.chapter-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 3px;
    background: linear-gradient(90deg, var(--accent-soft), transparent);
    opacity: 0;
    transition: opacity .35s;
}
.chapter-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
    border-color: var(--line-strong);
}
.chapter-card:hover::before { opacity: 1; }

.chapter-card .num {
    font-family: Georgia, serif;
    font-size: 40px;
    color: var(--paper-3);
    line-height: 1;
    letter-spacing: .05em;
    transition: color .35s;
}
.chapter-card:hover .num { color: var(--accent-soft); }

.chapter-card h3 {
    margin-top: 18px;
    font-size: 20.5px;
    letter-spacing: .1em;
    font-weight: 700;
    color: var(--ink);
}
.chapter-card .cn-title { color: var(--ink-faint); font-size: 13px; letter-spacing: .3em; margin-top: 5px; }
.chapter-card p {
    margin-top: 16px;
    font-size: 14.5px;
    color: var(--ink-soft);
    line-height: 1.95;
}
.chapter-card .tags {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.tag {
    font-family: var(--sans);
    font-size: 11.5px;
    padding: 3px 11px;
    border: 1px solid var(--line-strong);
    border-radius: 20px;
    color: var(--ink-faint);
    letter-spacing: .05em;
}
.chapter-card .enter {
    margin-top: 22px;
    font-size: 13.5px;
    color: var(--accent-deep);
    letter-spacing: .2em;
}
.chapter-card .enter span { transition: margin-left .3s; }
.chapter-card:hover .enter span { margin-left: 8px; }

/* ============================================================
   章节页布局：侧边目录 + 正文
   ============================================================ */
.page-wrap {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 28px 80px;
    display: flex;
    gap: 44px;
    position: relative;
    z-index: 1;
}

.toc {
    width: 248px;
    flex-shrink: 0;
    position: sticky;
    top: 92px;
    align-self: flex-start;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    font-size: 14px;
}
.toc .toc-title {
    font-size: 12.5px;
    letter-spacing: .35em;
    color: var(--ink-faint);
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 10px;
}
.toc ul { list-style: none; }
.toc li a {
    display: block;
    padding: 7px 12px;
    color: var(--ink-faint);
    border-left: 2px solid transparent;
    line-height: 1.6;
    border-radius: 0 4px 4px 0;
}
.toc li a:hover { color: var(--ink); background: var(--paper-2); }
.toc li a.active {
    color: var(--accent-deep);
    border-left-color: var(--accent-deep);
    background: var(--paper-2);
    font-weight: 700;
}
.toc li.toc-h3 a { padding-left: 30px; font-size: 13px; }
.toc .toc-chapters {
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px dashed var(--line-strong);
}
.toc .toc-chapters a {
    display: block;
    padding: 6px 0;
    font-size: 13px;
    color: var(--ink-faint);
}
.toc .toc-chapters a.current { color: var(--accent-deep); font-weight: 700; }

.content {
    flex: 1;
    min-width: 0;
    max-width: 820px;
}

/* 章节页头 */
.chapter-hero {
    padding: 64px 0 46px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 48px;
    position: relative;
}
.chapter-hero .crumb {
    font-size: 13px;
    color: var(--ink-faint);
    letter-spacing: .18em;
    margin-bottom: 26px;
}
.chapter-hero .crumb a { color: var(--ink-faint); }
.chapter-hero .big-num {
    font-family: Georgia, serif;
    font-size: 64px;
    line-height: 1;
    color: var(--paper-3);
    position: absolute;
    right: 0;
    top: 56px;
    font-style: italic;
}
.chapter-hero h1 {
    font-size: 37px;
    letter-spacing: .12em;
    font-weight: 700;
    line-height: 1.5;
}
.chapter-hero .lead {
    margin-top: 20px;
    color: var(--ink-soft);
    font-size: 16px;
    line-height: 2.1;
}

/* ============================================================
   正文排版
   ============================================================ */
.content h2 {
    font-size: 26px;
    letter-spacing: .08em;
    margin: 58px 0 22px;
    padding-left: 16px;
    border-left: 4px solid var(--accent-deep);
    line-height: 1.5;
    scroll-margin-top: 90px;
}
.content h3 {
    font-size: 20.5px;
    letter-spacing: .06em;
    margin: 40px 0 16px;
    color: var(--accent-deep);
    scroll-margin-top: 90px;
}
.content h4 {
    font-size: 17.5px;
    margin: 28px 0 12px;
    letter-spacing: .05em;
    scroll-margin-top: 90px;
}
.content p { margin: 14px 0; color: #3a3733; }
.content strong { color: var(--ink); font-weight: 700; }
.content ul, .content ol { margin: 14px 0 14px 6px; padding-left: 26px; }
.content li { margin: 8px 0; }
.content li::marker { color: var(--accent-soft); }

/* 引用 */
.content blockquote {
    margin: 24px 0;
    padding: 18px 26px;
    background: var(--paper-2);
    border-left: 3px solid var(--accent-soft);
    color: var(--ink-soft);
    font-size: 15.5px;
    border-radius: 0 6px 6px 0;
}
.content blockquote p { margin: 6px 0; }

/* 提示框 */
.box {
    margin: 24px 0;
    padding: 18px 22px 18px 20px;
    border-radius: 6px;
    font-size: 15px;
    border: 1px solid var(--line);
    background: #fff;
    position: relative;
}
.box .box-title {
    font-weight: 700;
    letter-spacing: .12em;
    font-size: 14px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.box-note    { border-left: 3px solid var(--accent); }
.box-tip     { border-left: 3px solid #7e8f7c; background: #f6f7f3; }
.box-warn    { border-left: 3px solid #a98b6f; background: #faf6f0; }
.box-def     { border-left: 3px solid var(--accent-deep); background: var(--paper-2); }
.box p:last-child { margin-bottom: 0; }
.box p:first-child { margin-top: 0; }

/* 表格 */
.table-wrap { overflow-x: auto; margin: 24px 0; }
.content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14.5px;
    background: #fff;
    border: 1px solid var(--line);
}
.content th {
    background: var(--paper-2);
    text-align: left;
    padding: 12px 16px;
    font-weight: 700;
    letter-spacing: .08em;
    border-bottom: 2px solid var(--line-strong);
    white-space: nowrap;
}
.content td {
    padding: 11px 16px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.content tr:last-child td { border-bottom: none; }
.content tbody tr:hover { background: var(--paper-2); }

/* 行内代码 */
code {
    font-family: var(--mono);
    font-size: .88em;
    background: var(--paper-3);
    color: #6b5d4d;
    padding: 2px 7px;
    border-radius: 4px;
    word-break: break-word;
}

/* ============================================================
   代码块
   ============================================================ */
.code-block {
    margin: 26px 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid #24221f;
}
.code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--code-head);
    padding: 9px 16px;
    font-family: var(--sans);
}
.code-head .dots { display: flex; gap: 7px; }
.code-head .dots i {
    width: 10px; height: 10px; border-radius: 50%;
    background: #6f6a61; display: block;
}
.code-head .dots i:nth-child(2) { background: #8a8275; }
.code-head .dots i:nth-child(3) { background: #a59c8c; }
.code-head .fname {
    color: #b8b1a4;
    font-size: 12.5px;
    letter-spacing: .12em;
    flex: 1;
    text-align: center;
}
.code-head .copy-btn {
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.14);
    color: #c7c0b3;
    font-size: 12px;
    padding: 3px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--sans);
    letter-spacing: .1em;
    transition: background .25s;
}
.code-head .copy-btn:hover { background: rgba(255,255,255,.18); }
.code-head .copy-btn.done { background: #7e8f7c; border-color: #7e8f7c; color: #fff; }

.code-block pre {
    background: var(--code-bg);
    padding: 20px 22px;
    overflow-x: auto;
    line-height: 1.75;
    font-size: 14px;
}
.code-block pre code {
    background: none;
    color: var(--code-text);
    padding: 0;
    font-size: 14px;
    line-height: 1.75;
    font-family: var(--mono);
    white-space: pre;
}

/* Python 语法配色（由 main.js 高亮） */
.tok-com { color: var(--code-comment); font-style: italic; }
.tok-key { color: var(--code-key); font-weight: 600; }
.tok-str { color: var(--code-str); }
.tok-num { color: var(--code-num); }
.tok-fn  { color: #d3c6b3; }
.tok-bui { color: #c2b49a; }
.tok-dec { color: #b0a089; }

/* 输出结果块 */
.console-block {
    margin: 18px 0 26px;
    border: 1px dashed var(--line-strong);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}
.console-block .con-title {
    font-family: var(--sans);
    font-size: 12.5px;
    letter-spacing: .2em;
    color: var(--ink-faint);
    padding: 8px 16px;
    background: var(--paper-2);
    border-bottom: 1px dashed var(--line-strong);
}
.console-block pre {
    padding: 16px 20px;
    font-family: var(--mono);
    font-size: 13.5px;
    line-height: 1.8;
    color: #4a463f;
    overflow-x: auto;
    white-space: pre;
}

/* 公式块 */
.formula {
    text-align: center;
    margin: 24px 0;
    padding: 20px;
    background: var(--paper-2);
    border-radius: 6px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 17px;
    color: var(--accent-deep);
    letter-spacing: .04em;
    overflow-x: auto;
}
.formula sub, .formula sup { font-size: .72em; }

/* 步骤列表 */
.steps { list-style: none; margin: 22px 0; padding: 0; counter-reset: step; }
.steps li {
    counter-increment: step;
    position: relative;
    padding: 6px 0 18px 52px;
    border-left: 1px solid var(--line);
    margin-left: 17px;
}
.steps li:last-child { border-left-color: transparent; }
.steps li::before {
    content: counter(step);
    position: absolute;
    left: -18px; top: 4px;
    width: 35px; height: 35px;
    background: var(--paper);
    border: 1.5px solid var(--accent-deep);
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-family: Georgia, serif;
    font-size: 15px;
    color: var(--accent-deep);
}

/* 卡片栅格（正文中的小卡片） */
.mini-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin: 22px 0;
}
.mini-card {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 7px;
    padding: 20px;
}
.mini-card h5 {
    font-size: 15.5px;
    letter-spacing: .08em;
    margin-bottom: 8px;
    color: var(--accent-deep);
}
.mini-card p { font-size: 14px; margin: 0; color: var(--ink-soft); }

/* 章末导航 */
.chapter-nav {
    margin-top: 80px;
    padding-top: 34px;
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.chapter-nav a {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 22px 24px;
    background: #fff;
    transition: all .3s;
    display: block;
}
.chapter-nav a:hover { border-color: var(--line-strong); box-shadow: var(--shadow); transform: translateY(-3px); }
.chapter-nav .dir { font-size: 12.5px; letter-spacing: .3em; color: var(--ink-faint); }
.chapter-nav .t { margin-top: 8px; font-size: 16px; font-weight: 700; letter-spacing: .08em; }
.chapter-nav .next { text-align: right; }

/* 小结 */
.summary {
    margin-top: 70px;
    padding: 30px 34px;
    background: linear-gradient(160deg, var(--paper-2), #fff);
    border: 1px solid var(--line);
    border-radius: 10px;
}
.summary h3 { margin-top: 0; }
.summary ul { margin-bottom: 0; }

/* ============================================================
   页脚
   ============================================================ */
.site-footer {
    border-top: 1px solid var(--line);
    background: var(--paper-2);
    padding: 54px 28px 40px;
    text-align: center;
    position: relative;
    z-index: 1;
}
.site-footer .f-brand {
    font-size: 18px;
    letter-spacing: .3em;
    font-weight: 700;
}
.site-footer p {
    margin-top: 12px;
    font-size: 13.5px;
    color: var(--ink-faint);
    line-height: 2;
}
.site-footer .f-line {
    width: 50px; height: 1px;
    background: var(--line-strong);
    margin: 22px auto;
}

/* 返回顶部 */
.back-top {
    position: fixed;
    right: 30px; bottom: 34px;
    width: 44px; height: 44px;
    border: 1px solid var(--line-strong);
    background: rgba(255,255,255,.9);
    border-radius: 50%;
    cursor: pointer;
    color: var(--accent-deep);
    font-size: 17px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .35s, transform .35s;
    z-index: 90;
    box-shadow: var(--shadow);
}
.back-top.show { opacity: 1; pointer-events: auto; }
.back-top:hover { transform: translateY(-4px); background: var(--accent-deep); color: #fff; }

/* 阅读进度条 */
.read-progress {
    position: fixed;
    top: 0; left: 0;
    height: 2.5px;
    width: 0;
    background: var(--accent);
    z-index: 200;
    transition: width .1s;
}

/* 滚动显现 */
.reveal {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity .8s ease, transform .8s ease;
}
.reveal.visible { opacity: 1; transform: none; }

/* 滚动条美化 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cfc8bb; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #b3aa9b; }

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 980px) {
    .toc { display: none; }
    .page-wrap { display: block; padding: 0 20px 60px; }
    .content { max-width: 100%; }
}

@media (max-width: 760px) {
    body { font-size: 15.5px; }
    .nav-toggle { display: block; }
    .nav-links {
        position: absolute;
        top: 66px; left: 0; right: 0;
        background: var(--paper);
        border-bottom: 1px solid var(--line);
        flex-direction: column;
        align-items: stretch;
        padding: 10px 20px 18px;
        gap: 2px;
        display: none;
    }
    .nav-links.open { display: flex; }
    .nav-links a { padding: 11px 14px; }
    .hero { padding: 70px 22px 56px; }
    .hero-meta .item { flex: 1 1 45%; border-right: none; padding: 12px; }
    .chapter-grid { grid-template-columns: 1fr; padding: 0 20px 60px; }
    .chapter-hero { padding: 40px 0 34px; }
    .chapter-hero h1 { font-size: 27px; padding-right: 70px; }
    .chapter-hero .big-num { font-size: 48px; top: 36px; }
    .content h2 { font-size: 22px; }
    .chapter-nav { grid-template-columns: 1fr; }
    .chapter-nav .next { text-align: left; }
}
