/*
 * 一木笔记 使用手册 · 样式
 *
 * ==== 设计取向 ====
 *
 * 通栏分栏：侧栏贴左、正文贴右，中间一条线，不再把正文收成一张浮在灰底上的
 * 卡片。精致靠当前条目淡底、首页多列卡片、四种提示条，不靠外圈留白。
 *
 * ==== 色值来自 App 的语义 token ====
 *
 * 下面这些变量与 app/src/main/res/values/colors.xml 里的 md_* 逐个对应，
 * 夜间那一套对应 md_*_night。改色请从那边同步过来，不要在这里另调一个近似值 ——
 * 手册与 App 放在一起看时颜色不一致会很明显。
 *
 * ==== 夜间 ====
 *
 * 默认跟随系统（prefers-color-scheme），右上角可手动切换并记在 localStorage。
 * 手动优先于系统：读手册的人可能白天在暗处、晚上在亮处。
 */

:root {
    /* 容器族：越"高"层级越高。浅色下越高越深 */
    --surface: #F2F3F5;
    --paper: #FFFFFF;
    --container: #EEEFF1;
    --container-high: #E8E9EB;
    --input-fill: #F5F6F8;

    /* 文字族：四档，不要跳档 */
    --on-surface: #1C1B1B;
    --on-surface-variant: #484555;
    --outline: #797587;
    --outline-variant: #C9C4D8;

    /* 描边与分割 */
    --card-line: #E8E9EB;
    --divider: rgba(0, 0, 0, .06);

    /* 主色与状态色 */
    --primary: #17181B;
    --link: #3B6EF5;
    --link-soft: #E8EEFE;
    --danger: #E5484D;
    --danger-soft: #FDECEC;
    --warning: #F5A623;
    --warning-soft: #FEF3E0;
    --success: #2BA84A;
    --success-soft: #E6F5EA;

    --radius: 14px;
    --radius-sm: 9px;
    --sidebar-w: 280px;
    --toc-w: 220px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 10px 28px rgba(16, 24, 40, .06);
    --shadow-hover: 0 4px 16px rgba(16, 24, 40, .08);
}

html[data-theme="dark"] {
    --surface: #1A1A1E;
    --paper: #202024;
    --container: #26262B;
    --container-high: #2D2D33;
    --input-fill: #232327;

    --on-surface: #E6E1E1;
    --on-surface-variant: #C9C4D8;
    --outline: #A5A0AE;
    --outline-variant: #6E6A78;

    --card-line: #34343A;
    --divider: rgba(255, 255, 255, .08);

    --primary: #4A4A52;
    --link: #6E9BFF;
    --link-soft: #1E2740;
    --danger: #FF6B6E;
    --danger-soft: #3A2224;
    --warning: #FFB74D;
    --warning-soft: #3A2E1C;
    --success: #5BC97A;
    --success-soft: #1E3325;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .18);
    --shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 12px 32px rgba(0, 0, 0, .28);
    --shadow-hover: 0 4px 18px rgba(0, 0, 0, .32);
}

::selection {
    background: var(--link-soft);
    color: var(--on-surface);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--paper);
    color: var(--on-surface);
    /* 中文优先用系统的屏显字体；PingFang / 微软雅黑之外不再指定，避免落到宋体 */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    /* 中文行距要比西文松：1.8 宽栏也能读完一行 */
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ==================================================================
   布局：左侧栏 + 内容 + 右侧本页目录
   ================================================================== */

.layout {
    display: flex;
    align-items: stretch;
    width: 100%;
    min-height: 100vh;
}

/* ---------------- 左侧栏 ---------------- */

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 24px 0 72px;
    background: var(--surface);
    border-right: 1px solid var(--divider);
}

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--outline-variant);
    border-radius: 8px;
    border: 2px solid var(--surface);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 20px;
    text-decoration: none;
    color: var(--on-surface);
}

.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex: 0 0 32px;
    display: block;
    object-fit: cover;
    box-shadow: var(--shadow-sm);
}

.brand-text {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -.01em;
}

.brand-sub {
    font-size: 11.5px;
    color: var(--outline);
    font-weight: 400;
    margin-left: 1px;
}

/* 搜索：纯前端过滤侧栏条目，不需要索引也不需要后端 */
.nav-search {
    margin: 0 16px 16px;
    position: relative;
}

.nav-search input {
    width: 100%;
    height: 36px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--input-fill);
    color: var(--on-surface);
    font-size: 13px;
    font-family: inherit;
    padding: 0 10px 0 32px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.nav-search input:focus {
    border-color: var(--link);
    box-shadow: 0 0 0 3px var(--link-soft);
}

.nav-search input::placeholder {
    color: var(--outline-variant);
}

.nav-search svg {
    position: absolute;
    left: 10px;
    top: 10px;
    width: 15px;
    height: 15px;
    stroke: var(--outline);
    fill: none;
    stroke-width: 1.6;
    pointer-events: none;
}

.nav-group {
    margin-bottom: 4px;
}

.nav-group-title {
    padding: 14px 22px 6px;
    font-size: 11px;
    font-weight: 650;
    color: var(--outline);
    letter-spacing: .06em;
    text-transform: uppercase;
}

.nav a {
    display: block;
    margin: 1px 10px;
    padding: 7px 12px;
    font-size: 13.5px;
    color: var(--on-surface-variant);
    text-decoration: none;
    border-radius: 8px;
    transition: color .12s, background .12s;
}

.nav a:hover {
    color: var(--on-surface);
    background: var(--input-fill);
}

.nav a.current {
    color: var(--link);
    font-weight: 650;
    background: var(--link-soft);
}

/* 还没写的条目：灰掉且不可点。做成占位而不是隐藏，是为了让读者看到手册的全貌，
   知道「这一节将来会有」而不是以为软件没这个功能 */
.nav span.todo {
    display: block;
    margin: 1px 10px;
    padding: 7px 12px;
    font-size: 13.5px;
    color: var(--outline-variant);
    cursor: default;
    border-radius: 8px;
}

.nav span.todo::after {
    content: "待补充";
    font-size: 10.5px;
    margin-left: 6px;
    padding: 1px 5px;
    border: 1px solid var(--outline-variant);
    border-radius: 4px;
    vertical-align: 1px;
}

.nav-empty {
    padding: 10px 20px;
    font-size: 12.5px;
    color: var(--outline);
}

/* ---------------- 内容 ---------------- */

.main {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 100vh;
    padding: 0;
    display: flex;
    align-items: stretch;
    background: var(--paper);
}

.article {
    flex: 1 1 auto;
    min-width: 0;
    background: var(--paper);
    padding: 40px clamp(36px, 4vw, 72px) 80px;
}

/* ---------------- 右侧本页目录 ---------------- */

.toc {
    width: var(--toc-w);
    flex: 0 0 var(--toc-w);
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    padding: 36px 18px 32px;
    background: var(--paper);
    border-left: 1px solid var(--divider);
}

.toc-title {
    font-size: 11px;
    font-weight: 650;
    color: var(--outline);
    margin: 0 4px 10px;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.toc a {
    display: block;
    font-size: 13px;
    line-height: 1.5;
    padding: 6px 10px;
    color: var(--outline);
    text-decoration: none;
    border-radius: 7px;
}

.toc a:hover {
    color: var(--on-surface);
    background: var(--input-fill);
}

.toc a.active {
    color: var(--link);
    font-weight: 650;
    background: var(--link-soft);
}

.toc a.lv3 {
    padding-left: 20px;
    font-size: 12px;
}

/* ==================================================================
   正文排版
   ================================================================== */

.article h1 {
    font-size: clamp(26px, 2.1vw, 32px);
    line-height: 1.28;
    font-weight: 650;
    letter-spacing: -.03em;
    margin: 0 0 12px;
}

.lede {
    font-size: 16.5px;
    color: var(--on-surface-variant);
    margin: 0 0 36px;
    line-height: 1.7;
}

.article h2 {
    font-size: 20px;
    font-weight: 650;
    letter-spacing: -.02em;
    margin: 44px 0 14px;
    padding-top: 28px;
    border-top: 1px solid var(--divider);
}

.article h1 + .lede + h2 {
    border-top: 0;
    padding-top: 4px;
    margin-top: 8px;
}

/*
 * 锚点跳转的落点要往下让一点。
 *
 * 不让的话：窄屏上 50px 的 sticky 顶栏会把刚跳过去的标题整行盖住，用户以为跳错了；
 * 宽屏上标题会正好贴在视口最上沿，读起来也局促。
 */
.article h2, .article h3 {
    scroll-margin-top: 70px;
}

.article h3 {
    font-size: 15.5px;
    font-weight: 650;
    margin: 28px 0 8px;
}

.article h4 {
    font-size: 14.5px;
    font-weight: 650;
    color: var(--on-surface-variant);
    margin: 22px 0 6px;
}

/* 标题锚点：hover 时才露出，平时不占视觉 */
.anchor {
    margin-left: 8px;
    font-size: .62em;
    color: var(--outline-variant);
    text-decoration: none;
    opacity: 0;
    transition: opacity .12s;
    font-weight: 400;
}

h2:hover .anchor, h3:hover .anchor {
    opacity: 1;
}

.article p {
    margin: 0 0 14px;
}

.article ul, .article ol {
    margin: 0 0 14px;
    padding-left: 22px;
}

.article li {
    margin-bottom: 5px;
}

.article li > ul, .article li > ol {
    margin-top: 5px;
    margin-bottom: 0;
}

.article a {
    color: var(--link);
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

.article a:hover {
    border-bottom-color: var(--link);
}

.article strong {
    font-weight: 650;
}

.article hr {
    border: 0;
    border-top: 1px solid var(--divider);
    margin: 30px 0;
}

/* 次要说明：比正文小一档、灰一档 */
.muted {
    font-size: 13.5px;
    color: var(--outline);
}

/* ---------------- 代码 ---------------- */

code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: .875em;
    background: var(--input-fill);
    border-radius: 5px;
    padding: 2px 5px;
    word-break: break-word;
}

pre {
    background: var(--input-fill);
    border: 1px solid var(--divider);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    overflow-x: auto;
    margin: 0 0 16px;
    line-height: 1.65;
}

pre code {
    background: none;
    padding: 0;
    font-size: 12.8px;
    white-space: pre;
    word-break: normal;
}

/* 代码块右上角的复制按钮，由 manual.js 挂上 */
.code-box {
    position: relative;
}

.code-copy {
    position: absolute;
    top: 8px;
    right: 8px;
    height: 25px;
    padding: 0 9px;
    font-size: 11.5px;
    font-family: inherit;
    color: var(--outline);
    background: var(--paper);
    border: 1px solid var(--card-line);
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s;
}

.code-box:hover .code-copy {
    opacity: 1;
}

.code-copy:hover {
    color: var(--on-surface);
}

/* ---------------- 提示条 ---------------- */

/*
 * 四种：note（补充）/ tip（建议）/ warn（注意）/ danger（可能出错或不可逆）。
 * 只用左侧 3px 竖条 + 一行小标签上色，不铺满底色 —— 铺满会让一页里几个提示条
 * 抢掉正文的注意力，而它们说的多半是「读一次就够」的话。
 */
.callout {
    border: 1px solid var(--card-line);
    border-left: 3px solid var(--outline-variant);
    background: var(--input-fill);
    border-radius: var(--radius-sm);
    padding: 13px 16px;
    margin: 0 0 16px;
    font-size: 14.5px;
}

.callout > :last-child {
    margin-bottom: 0;
}

.callout-label {
    display: block;
    font-size: 11.5px;
    font-weight: 650;
    letter-spacing: .02em;
    margin-bottom: 4px;
    color: var(--outline);
}

.callout.note {
    border-color: rgba(59, 110, 245, .14);
    border-left-color: var(--link);
    background: var(--link-soft);
}

.callout.note .callout-label {
    color: var(--link);
}

.callout.tip {
    border-color: rgba(43, 168, 74, .16);
    border-left-color: var(--success);
    background: var(--success-soft);
}

.callout.tip .callout-label {
    color: var(--success);
}

.callout.warn {
    border-color: rgba(245, 166, 35, .2);
    border-left-color: var(--warning);
    background: var(--warning-soft);
}

.callout.warn .callout-label {
    color: var(--warning);
}

.callout.danger {
    border-color: rgba(229, 72, 77, .16);
    border-left-color: var(--danger);
    background: var(--danger-soft);
}

.callout.danger .callout-label {
    color: var(--danger);
}

html[data-theme="dark"] .callout.note {
    border-color: rgba(110, 155, 255, .22);
}

html[data-theme="dark"] .callout.tip {
    border-color: rgba(91, 201, 122, .22);
}

html[data-theme="dark"] .callout.warn {
    border-color: rgba(255, 183, 77, .22);
}

html[data-theme="dark"] .callout.danger {
    border-color: rgba(255, 107, 110, .22);
}

/* ---------------- 表格 ---------------- */

.table-box {
    overflow-x: auto;
    margin: 4px 0 22px;
    padding: 2px 6px 2px 16px;
    background: var(--input-fill);
    border: 1px solid var(--card-line);
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th, td {
    text-align: left;
    padding: 9px 12px 9px 0;
    border-bottom: 1px solid var(--divider);
    vertical-align: top;
}

th {
    font-weight: 650;
    font-size: 12.5px;
    color: var(--outline);
    border-bottom: 1px solid var(--card-line);
    white-space: nowrap;
}

tr:last-child td {
    border-bottom: 0;
}

td code {
    white-space: nowrap;
}

/* ---------------- 截图 ---------------- */

/*
 * 截图统一走这个结构，好处是换图不用碰样式：
 *
 *   <figure class="shot">
 *     <img src="images/mcp-create.png" alt="创建 MCP 连接">
 *     <figcaption>设置 → MCP 连接 → 新建</figcaption>
 *   </figure>
 *
 * 手机截图很高，所以给了 max-height 并居中 —— 不限高的话一张竖屏截图会占满整屏，
 * 读者得滚很久才看到下一句话。要放宽屏截图（如电脑端配置界面）加 class="wide"。
 */
.shot {
    margin: 4px 0 20px;
    text-align: center;
}

.shot img {
    max-width: 100%;
    max-height: 520px;
    border: 1px solid var(--card-line);
    border-radius: 10px;
    background: var(--paper);
    box-shadow: var(--shadow-sm);
}

.shot.wide img {
    max-height: none;
    width: 100%;
}

.shot figcaption {
    font-size: 12.5px;
    color: var(--outline);
    margin-top: 8px;
}

/* 还没放图时的占位。留着它比留一张破图好 —— 破图会让人以为手册坏了 */
.shot-todo {
    margin: 4px 0 20px;
    padding: 26px 16px;
    border: 1px dashed var(--outline-variant);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 12.5px;
    color: var(--outline-variant);
    background: var(--input-fill);
}

/* ---------------- 步骤 ---------------- */

/*
 * 带序号圆点的步骤列表。用 ol 而不是手写数字：插入一步时不用改后面所有编号。
 */
ol.steps {
    list-style: none;
    padding: 0;
    counter-reset: step;
    margin: 0 0 18px;
}

ol.steps > li {
    counter-increment: step;
    position: relative;
    padding-left: 38px;
    margin-bottom: 20px;
}

ol.steps > li:not(:last-child)::after {
    content: "";
    position: absolute;
    left: 11px;
    top: 28px;
    bottom: -16px;
    width: 1px;
    background: var(--divider);
}

ol.steps > li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 2px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--link-soft);
    color: var(--link);
    font-size: 12px;
    font-weight: 650;
    line-height: 24px;
    text-align: center;
    z-index: 1;
    box-shadow: inset 0 0 0 1px rgba(59, 110, 245, .16);
}

ol.steps > li > :first-child {
    margin-top: 0;
}

ol.steps > li h3 {
    margin: 0 0 6px;
    font-size: 15px;
}

/* ---------------- 上一页 / 下一页 ---------------- */

.pager {
    display: flex;
    gap: 14px;
    margin-top: 48px;
    padding-top: 26px;
    border-top: 1px solid var(--divider);
}

.pager a {
    flex: 1 1 0;
    min-width: 0;
    border: 1px solid var(--card-line);
    border-radius: 12px;
    padding: 14px 16px;
    text-decoration: none;
    color: var(--on-surface);
    background: var(--paper);
    box-shadow: var(--shadow-sm);
    transition: border-color .15s, box-shadow .15s, transform .15s;
}

.pager a:hover {
    border-color: var(--outline-variant);
    box-shadow: var(--shadow-hover);
    transform: translateY(-1px);
}

.pager .dir {
    display: block;
    font-size: 11.5px;
    color: var(--outline);
    margin-bottom: 2px;
}

.pager .name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pager a.next {
    text-align: right;
}

/* ---------------- 首页卡片：把宽栏用成多列，而不是把一段话拉到 1200px ---------------- */

.mode-grid,
.feature-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 6px 0 24px;
}

.mode-card,
.feature-card {
    display: block;
    padding: 16px 16px 15px;
    background: var(--input-fill);
    border: 1px solid var(--card-line);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, box-shadow .15s, transform .15s, background .15s;
}

.mode-card:hover,
.feature-card:hover {
    border-color: var(--outline-variant);
    background: var(--paper);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.mode-kicker,
.feature-kicker {
    display: block;
    font-size: 11.5px;
    font-weight: 650;
    color: var(--link);
    letter-spacing: .04em;
    margin-bottom: 6px;
}

.mode-card strong,
.feature-card strong {
    display: block;
    font-size: 15px;
    font-weight: 650;
    margin-bottom: 6px;
    color: var(--on-surface);
}

.mode-card p,
.feature-card p {
    margin: 0;
    font-size: 13.5px;
    line-height: 1.65;
    color: var(--on-surface-variant);
}

.article a.mode-card,
.article a.feature-card {
    color: inherit;
    border-bottom: 0;
}

/* ==================================================================
   顶栏（窄屏）与主题切换
   ================================================================== */

.topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 20;
    align-items: center;
    gap: 10px;
    height: 50px;
    padding: 0 14px;
    background: var(--paper);
    border-bottom: 1px solid var(--divider);
}

.icon-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    cursor: pointer;
    color: var(--on-surface-variant);
    padding: 0;
}

.icon-btn:hover {
    background: var(--divider);
    color: var(--on-surface);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.theme-toggle {
    position: fixed;
    left: 16px;
    bottom: 16px;
    top: auto;
    right: auto;
    z-index: 30;
    background: var(--paper);
    border: 1px solid var(--card-line);
    box-shadow: var(--shadow-sm);
    border-radius: 10px;
}

html[data-theme="dark"] .icon-sun,
.icon-moon {
    display: none;
}

html[data-theme="dark"] .icon-moon {
    display: block;
}

.scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    z-index: 15;
}

/* ==================================================================
   响应式
   ================================================================== */

/* 本页目录先撤：它是锦上添花，而正文宽度是刚需 */
@media (max-width: 1180px) {
    .toc {
        display: none;
    }

    .article {
        padding: 32px 28px 64px;
    }
}

@media (max-width: 900px) {
    .topbar {
        display: flex;
    }

    .layout {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 18;
        background: var(--paper);
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 0 0 0 1px var(--divider);
    }

    body.nav-open .sidebar {
        transform: none;
    }

    body.nav-open .scrim {
        display: block;
    }

    .theme-toggle {
        display: none;
    }

    .main {
        min-height: calc(100vh - 50px);
    }

    .article {
        padding: 22px 18px 48px;
    }

    .article h1 {
        font-size: 22px;
    }

    .article h2 {
        font-size: 17.5px;
        margin-top: 32px;
    }

    .pager {
        flex-direction: column;
    }

    .pager a.next {
        text-align: left;
    }

    .mode-grid,
    .feature-grid {
        grid-template-columns: 1fr;
    }
}

/* 打印：撤掉一切导航，只留正文 */
@media print {
    .sidebar, .toc, .topbar, .theme-toggle, .pager, .scrim, .code-copy {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .article {
        border: 0;
        max-width: none;
        padding: 0;
        box-shadow: none;
    }
}
