/* ============================================================
   主题令牌：全站所有颜色决策集中在此，换肤只需改这一段
   ============================================================ */
:root {
    /* 底色层 */
    --bg: #f4f7fc;
    --bg-deep: #eef3fa;
    --pane-bg: rgba(255, 255, 255, 0.88);
    --pane-bg-solid: #ffffff;
    --subtle-bg: rgba(240, 245, 252, 0.8);
    --header-bg: rgba(255, 255, 255, 0.82);
    --surface: rgba(14, 165, 233, 0.05);
    --surface-hover: rgba(14, 165, 233, 0.11);

    /* 描边 */
    --border: rgba(15, 23, 42, 0.1);
    --border-strong: rgba(14, 165, 233, 0.42);

    /* 主色：primary 为品牌蓝，ink 用于文字（需足够深），lift 用于渐变亮端 */
    --primary: #0ea5e9;
    --primary-ink: #0369a1;
    --primary-lift: #38bdf8;
    --primary-deep: #4f46e5;
    --accent: #7c3aed;
    --success: #059669;
    --success-ink: #047857;

    /* 按钮文字（渐变实心按钮上） */
    --btn-fg: #ffffff;

    /* 光效：亮色下用柔和彩色投影替代发光 */
    --glow: 0 0 0 1px rgba(14, 165, 233, 0.3), 0 4px 16px rgba(14, 165, 233, 0.22);
    --glow-soft: 0 2px 12px rgba(14, 165, 233, 0.16);
    --ring: 0 0 0 3px rgba(14, 165, 233, 0.16);
    --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.06);

    /* 文字 */
    --text: #0f172a;
    --text-dim: #475569;
    --text-mute: #8496ae;

    /* 状态 */
    --error-bg: #fef2f2;
    --error-text: #dc2626;
    --error-border: #fecaca;

    /* 装饰 */
    --grid-line: rgba(15, 23, 42, 0.055);
    --selection-bg: rgba(14, 165, 233, 0.22);
    --scroll-thumb: rgba(15, 23, 42, 0.18);
    --scroll-thumb-hover: rgba(14, 165, 233, 0.5);
    --glow-a: rgba(14, 165, 233, 0.16);
    --glow-b: rgba(124, 58, 237, 0.13);
    --glow-c: rgba(45, 212, 191, 0.12);
    --shine: rgba(255, 255, 255, 0.6);

    --header-h: 52px;
    --radius: 10px;
    /* 内容区统一宽度，页头/工具区/页脚共用，保证左右对齐 */
    --container: 1200px;
    /* 顶栏 + 页头 + 提示条的总占位，JSON 页据此算编辑器高度 */
    --chrome-h: 200px;
    --font-mono: "JetBrains Mono", "Fira Code", "SFMono-Regular", Consolas, Monaco, "Courier New", monospace;
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: light;
}

body {
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

main {
    flex: 1 0 auto;
    /* 必须显式给宽：flex 列布局下，子项的 auto 外边距会抵消 stretch，
       导致带 margin:0 auto 的 main 按 fit-content 收缩 */
    width: 100%;
}

/* 背景层：氛围光晕 */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    pointer-events: none;
    background:
        radial-gradient(1200px 620px at 12% -12%, var(--glow-a), transparent 62%),
        radial-gradient(1000px 560px at 92% -4%, var(--glow-b), transparent 62%),
        radial-gradient(900px 520px at 50% 112%, var(--glow-c), transparent 62%),
        var(--bg-deep);
}

/* 背景层：科技网格 */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 44px 44px;
    -webkit-mask-image: radial-gradient(ellipse 85% 62% at 50% 0%, #000 35%, transparent 100%);
    mask-image: radial-gradient(ellipse 85% 62% at 50% 0%, #000 35%, transparent 100%);
}

::selection {
    background: var(--selection-bg);
    color: var(--text);
}

/* 滚动条 */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border: 2px solid transparent;
    background-clip: padding-box;
    border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scroll-thumb-hover);
    background-clip: padding-box;
}

/* ── 顶栏 ───────────────────────────────── */
.top-bar {
    position: relative;
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 28px;
    background: var(--header-bg);
    backdrop-filter: blur(14px) saturate(150%);
    -webkit-backdrop-filter: blur(14px) saturate(150%);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    overflow: hidden;
    z-index: 100;
}

/* 顶栏底部扫描光 */
.top-bar::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 38%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    animation: scan-sweep 7s linear infinite;
}

@keyframes scan-sweep {
    0% { transform: translateX(-110%); }
    100% { transform: translateX(370%); }
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-family: var(--font-mono);
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.3px;
    /* background-clip:text 只在元素盒内绘制背景，超出盒子的字形因 color:transparent 会直接消失。
       line-height 需覆盖 ascent+descent（否则 j/g/y 的下伸部被切），
       左右内边距用于容纳字形的左右边距（JetBrains Mono 等字体的 j 带左钩）。 */
    line-height: 1.4;
    padding: 0 4px;
    margin-left: -4px; /* 抵消左内边距，保持与顶栏左缘的原有间距 */
    text-decoration: none;
    background: linear-gradient(92deg, var(--primary-ink), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    white-space: nowrap;
}

/* 品牌前的呼吸指示灯 */
.brand::before {
    content: "";
    width: 8px;
    height: 8px;
    flex: none;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.18);
    animation: pulse-dot 2.4s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(0.82); }
}

.brand:hover {
    filter: brightness(1.12);
}

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

.nav-links {
    display: flex;
    align-items: stretch;
    align-self: stretch;
    gap: 2px;
    font-size: 14px;
}

.nav-links a {
    position: relative;
    display: inline-flex;
    align-items: center;
    padding: 0 16px;
    color: var(--text-dim);
    text-decoration: none;
    line-height: 1.4;
    /* 顶部页签用「下划线」而非背景块：导航项占满顶栏高度，
       套圆角会变成一个突兀的高方块，且下划线只能浮在方块内部。
       下划线贴住顶栏底边才能和顶栏连成整体。 */
    transition: color 0.18s ease;
}

.nav-links a::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;          /* 贴住顶栏底边 */
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: transparent;
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 0.22s ease;
}

.nav-links a:hover {
    color: var(--primary-ink);
}

/* 悬停时下划线以浅色预览，给出可点击的反馈 */
.nav-links a:hover::after {
    background: var(--border-strong);
    transform: scaleX(1);
}

.nav-active {
    color: var(--text) !important;
    font-weight: 600;
}

.nav-active::after {
    background: linear-gradient(90deg, var(--primary), var(--accent)) !important;
    transform: scaleX(1) !important;
}

/* ── 页头：面包屑 + 可见 H1 + 副标题 ────── */
.page-head {
    border-bottom: 1px solid var(--border);
    background: var(--subtle-bg);
}

.page-head-inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: 22px 20px 20px;
}

.crumb {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-mute);
}

.crumb-link {
    color: var(--text-dim);
    text-decoration: none;
    transition: color 0.18s ease;
}

.crumb-link:hover {
    color: var(--primary-ink);
}

.crumb-sep {
    color: var(--text-mute);
}

.crumb-current {
    color: var(--primary-ink);
}

.page-title {
    margin: 0 0 8px;
    font-size: 25px;
    font-weight: 700;
    letter-spacing: -0.2px;
    line-height: 1.25;
    background: linear-gradient(92deg, var(--text) 5%, var(--primary-ink) 58%, var(--accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.page-sub {
    margin: 0;
    max-width: 74ch;
    font-size: 13px;
    line-height: 1.65;
    color: var(--text-dim);
}

/* 紧凑变体：JSON 页要把垂直空间让给编辑器 */
.page-head-compact .page-head-inner {
    max-width: none;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px 14px;
    padding: 11px 20px;
}

.page-head-compact .crumb {
    margin-bottom: 0;
    order: -1;
    flex-basis: 100%;
}

.page-head-compact .page-title {
    margin: 0;
    font-size: 16px;
}

.page-head-compact .page-sub {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hidden {
    display: none !important;
}

/* ── 提示 / 反馈 ─────────────────────────── */
.error-banner {
    margin: 0;
    padding: 10px 14px;
    background: var(--error-bg);
    color: var(--error-text);
    font-size: 13px;
    font-family: var(--font-mono);
    border-top: 1px solid var(--error-border);
}

.toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    padding: 11px 22px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text);
    font-size: 14px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    box-shadow: 0 10px 32px rgba(15, 23, 42, 0.16), var(--glow-soft);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 10000;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── 页脚 SEO 内容 ───────────────────────── */
.site-footer {
    position: relative;
    flex: none;
    margin-top: 40px;
    border-top: 1px solid var(--border);
    background: var(--subtle-bg);
}

.site-footer-inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: 34px 20px 32px;
}

.site-footer::before {
    content: "";
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 220px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
}

.site-footer-title {
    position: relative;
    margin: 0 0 12px;
    padding-left: 12px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.site-footer-title::before {
    content: "";
    position: absolute;
    left: 0;
    top: 3px;
    bottom: 3px;
    width: 3px;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--primary), var(--accent));
}

.site-footer-text {
    margin: 0 0 24px;
    font-size: 14px;
    line-height: 1.75;
    color: var(--text-dim);
}

.site-footer-faq {
    margin-bottom: 24px;
}

.site-footer-faq-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 12px;
    margin: 0;
}

.site-footer-faq-item {
    padding: 14px 16px;
    background: var(--pane-bg-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.site-footer-faq-item:hover {
    border-color: var(--border-strong);
    box-shadow: var(--glow-soft);
}

.site-footer-faq-item dt {
    margin: 0 0 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-ink);
}

.site-footer-faq-item dd {
    margin: 0;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-dim);
}

.site-footer-bottom {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    margin-top: 28px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.site-footer-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

.site-footer-nav a {
    color: var(--primary-ink);
    text-decoration: none;
    transition: color 0.2s ease;
}

.site-footer-nav a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.site-footer-sep {
    color: var(--text-mute);
}

.site-footer-copy {
    margin: 0;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-mute);
}

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

.site-footer-copy a:hover {
    color: var(--primary-ink);
}

.page-with-footer .timestamp-workspace,
.page-with-footer .url-workspace {
    min-height: auto;
}

/* ── 404 / 500 ──────────────────────────── */
.error-page .error-main {
    max-width: 640px;
    margin: 72px auto;
    padding: 0 20px;
    text-align: center;
}

.error-page .error-main h1 {
    margin: 0 0 14px;
    font-family: var(--font-mono);
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(92deg, var(--primary-ink), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.error-page .error-main p {
    margin: 0 0 28px;
    color: var(--text-dim);
}

.error-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.error-nav a {
    padding: 9px 18px;
    color: var(--primary-ink);
    text-decoration: none;
    font-size: 14px;
    background: var(--pane-bg-solid);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.error-nav a:hover {
    border-color: var(--border-strong);
    box-shadow: var(--glow-soft);
}

/* ============================================================
   深色主题：只覆盖颜色类令牌，布局类（--header-h/--radius/
   --container/--chrome-h/--font-mono）沿用 :root。
   默认是亮色，只有用户在顶栏手动切换过才会加上 data-theme="dark"。
   ============================================================ */
[data-theme="dark"] {
    --bg: #070b14;
    --bg-deep: #05080f;
    --pane-bg: rgba(13, 20, 32, 0.82);
    --pane-bg-solid: #0d1420;
    --subtle-bg: rgba(7, 11, 20, 0.55);
    --header-bg: rgba(7, 11, 20, 0.72);
    --surface: rgba(125, 211, 252, 0.05);
    --surface-hover: rgba(125, 211, 252, 0.1);

    --border: rgba(125, 211, 252, 0.14);
    --border-strong: rgba(125, 211, 252, 0.32);

    --primary: #22d3ee;
    --primary-ink: #67e8f9;
    --primary-lift: #a5f3fc;
    --primary-deep: #3b82f6;
    --accent: #a78bfa;
    --success: #34d399;
    --success-ink: #6ee7b7;

    /* 深色下渐变按钮用深色文字才够对比 */
    --btn-fg: #04141a;

    --glow: 0 0 0 1px rgba(34, 211, 238, 0.35), 0 0 18px rgba(34, 211, 238, 0.28);
    --glow-soft: 0 0 14px rgba(34, 211, 238, 0.18);
    --ring: 0 0 0 3px rgba(34, 211, 238, 0.16);
    --shadow-card: 0 12px 40px rgba(0, 0, 0, 0.4);

    --text: #dbe6f6;
    --text-dim: #93a7c4;
    --text-mute: #5f7595;

    --error-bg: rgba(248, 113, 113, 0.1);
    --error-text: #fca5a5;
    --error-border: rgba(248, 113, 113, 0.3);

    --grid-line: rgba(125, 211, 252, 0.05);
    --selection-bg: rgba(34, 211, 238, 0.3);
    --scroll-thumb: rgba(125, 211, 252, 0.16);
    --scroll-thumb-hover: rgba(34, 211, 238, 0.4);
    --glow-a: rgba(34, 211, 238, 0.13);
    --glow-b: rgba(99, 102, 241, 0.14);
    --glow-c: rgba(20, 184, 166, 0.09);
    --shine: rgba(255, 255, 255, 0.55);

    color-scheme: dark;
}

/* 少数写死了浅色值、无法靠令牌覆盖的规则 */
[data-theme="dark"] .top-bar {
    box-shadow: none;
}

[data-theme="dark"] .brand::before {
    box-shadow: 0 0 10px var(--primary), 0 0 20px rgba(34, 211, 238, 0.6);
}

[data-theme="dark"] .toast {
    background: rgba(13, 20, 32, 0.94);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55), var(--glow-soft);
}

[data-theme="dark"] .nav-active::after {
    box-shadow: 0 0 10px rgba(34, 211, 238, 0.85);
}

/* ── 主题切换按钮 ───────────────────────── */
.theme-toggle {
    margin-left: auto;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    color: var(--text-dim);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 9px;
    cursor: pointer;
    transition: color 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
}

.theme-toggle:hover {
    color: var(--primary-ink);
    border-color: var(--border-strong);
    background: var(--surface);
}

.theme-toggle:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}

.theme-toggle svg {
    width: 17px;
    height: 17px;
    display: block;
}

/* 亮色时显示「月亮」（点击去深色），深色时显示「太阳」 */
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ── 窄屏适配 ───────────────────────────── */
@media (max-width: 900px) {
    :root {
        --chrome-h: 172px;
    }

    .top-bar {
        gap: 14px;
        padding: 0 14px;
    }

    .brand {
        font-size: 16px;
    }

    .nav-links {
        gap: 0;
        font-size: 13px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .nav-links::-webkit-scrollbar {
        display: none;
    }

    .nav-links a {
        padding: 0 10px;
        white-space: nowrap;
    }

    .theme-toggle {
        width: 30px;
        height: 30px;
    }

    .theme-toggle svg {
        width: 15px;
        height: 15px;
    }

    .page-head-inner {
        padding: 16px 16px 14px;
    }

    .page-title {
        font-size: 20px;
    }

    /* 紧凑页头在窄屏收起副标题，优先保证标题和编辑器空间 */
    .page-head-compact .page-sub {
        display: none;
    }

    .site-footer-inner {
        padding: 26px 16px;
    }

    .site-footer-bottom {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ── 超窄屏：导航横向滚动 + 右侧渐隐提示 ─── */
@media (max-width: 560px) {
    .top-bar {
        gap: 10px;
        padding: 0 12px;
    }

    .brand {
        font-size: 15px;
        gap: 7px;
    }

    .brand::before {
        width: 7px;
        height: 7px;
    }

    .nav-links {
        font-size: 12px;
        /* 右缘渐隐，提示还可以继续横滑 */
        -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
        mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
    }

    .nav-links a {
        padding: 0 8px;
    }

    .page-title {
        font-size: 18px;
    }

    .page-head-compact .page-head-inner {
        padding: 9px 12px;
    }

    .site-footer-faq-list {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .top-bar::after,
    .brand::before {
        animation: none;
    }

    * {
        transition-duration: 0.01ms !important;
    }
}
