/* ============================================================
   无限画布 UI 清晰度优化补丁
   - 中文字体优化（微软雅黑 + 苹方回退）
   - 字体渲染抗锯齿（深浅色分别优化）
   - DPI 缩放优化
   - 背景网格更细腻
   ============================================================ */

/* 全局字体优化：中文优先用系统高质量中文字体 */
html, body {
    font-family:
        "Microsoft YaHei",      /* Win: 微软雅黑 */
        "PingFang SC",          /* Mac: 苹方 */
        "Hiragino Sans GB",     /* Mac: 冬青黑体 */
        "Source Han Sans SC",   /* 思源黑体 */
        "Noto Sans CJK SC",     /* Noto 黑体 */
        "Inter",                /* 英文：项目自带 */
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif !important;
    text-rendering: optimizeLegibility !important;
    font-feature-settings: "cv11", "ss01";
}

/* 确保所有文本元素继承优化字体 */
* {
    text-shadow: 0 0 0.3px transparent; /* 亚像素渲染辅助，让边缘更锐利 */
}

/* 标题字体加粗优化 */
h1, h2, h3, h4, h5, h6,
.font-bold, .font-semibold, .font-medium {
    font-family:
        "Microsoft YaHei",
        "PingFang SC",
        "Hiragino Sans GB",
        "Source Han Sans SC",
        "Inter",
        sans-serif !important;
    font-weight: 600 !important;
}

/* 等宽字体优化 */
code, pre, .font-mono, textarea[class*="mono"] {
    font-family:
        "JetBrains Mono",
        "Cascadia Code",
        "Fira Code",
        "Consolas",
        "Microsoft YaHei",
        monospace !important;
}

/* 输入框文字优化 */
input, textarea, select, button {
    font-family:
        "Microsoft YaHei",
        "PingFang SC",
        "Inter",
        sans-serif !important;
}

/* ============================================================
   浅色主题：文字更黑更实 + 背景柔和不刺眼
   （浅色背景下 antialiased 会让文字发灰，所以不用）
   ============================================================ */
html:not(.studio-theme-dark) body,
body:not(.studio-theme-dark) {
    -webkit-font-smoothing: subpixel-antialiased !important;
    -moz-osx-font-smoothing: auto !important;
    color: #1a1a1a !important;
}

/* 浅色主题主文字：更深更实 */
body:not(.studio-theme-dark),
html:not(.studio-theme-dark) body,
body:not(.studio-theme-dark) h1,
body:not(.studio-theme-dark) h2,
body:not(.studio-theme-dark) h3,
body:not(.studio-theme-dark) .text-black {
    color: #1a1a1a !important;
}

/* 浅色主题次要文字：从灰调深，避免发虚 */
body:not(.studio-theme-dark) .text-gray-400,
body:not(.studio-theme-dark) .text-gray-500,
body:not(.studio-theme-dark) .setting-meta,
body:not(.studio-theme-dark) .label-nano,
html:not(.studio-theme-dark) body .text-gray-400,
html:not(.studio-theme-dark) body .text-gray-500 {
    color: #5a5a5a !important;
}

body:not(.studio-theme-dark) .text-gray-300,
html:not(.studio-theme-dark) body .text-gray-300 {
    color: #6b6b6b !important;
}

body:not(.studio-theme-dark) .text-gray-600,
html:not(.studio-theme-dark) body .text-gray-600 {
    color: #4a4a4a !important;
}

body:not(.studio-theme-dark) .text-gray-700,
html:not(.studio-theme-dark) body .text-gray-700 {
    color: #2d2d2d !important;
}

/* 浅色主题画布背景：不是纯白，柔和米灰，眼睛更舒服 */
body:not(.studio-theme-dark) .shell,
html:not(.studio-theme-dark) body .shell,
body:not(.studio-theme-dark) .canvas-gate,
html:not(.studio-theme-dark) body .canvas-gate {
    background-color: #f7f7f5 !important;
    background-image:
        radial-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 1px) !important;
    background-size: 20px 20px !important;
}

/* 浅色主题卡片和面板：更清晰的边框 + 更白的底色 */
body:not(.studio-theme-dark) .console-card,
body:not(.studio-theme-dark) .work-panel,
body:not(.studio-theme-dark) .tool-panel,
body:not(.studio-theme-dark) .control-panel,
body:not(.studio-theme-dark) .setting-row,
body:not(.studio-theme-dark) .composer,
html:not(.studio-theme-dark) body .console-card {
    background-color: #ffffff !important;
    border-color: #e0e0e0 !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
}

/* 浅色主题按钮更清晰 */
body:not(.studio-theme-dark) .glass-btn,
body:not(.studio-theme-dark) .btn-action-dark,
body:not(.studio-theme-dark) .send-btn,
body:not(.studio-theme-dark) .gen-btn,
body:not(.studio-theme-dark) .comfy-run,
body:not(.studio-theme-dark) .primary-btn {
    background-color: #1a1a1a !important;
    color: #ffffff !important;
    border-color: #1a1a1a !important;
}

/* 浅色主题输入框 */
body:not(.studio-theme-dark) input,
body:not(.studio-theme-dark) textarea,
body:not(.studio-theme-dark) select {
    background-color: #ffffff !important;
    border-color: #d0d0d0 !important;
    color: #1a1a1a !important;
}

body:not(.studio-theme-dark) input::placeholder,
body:not(.studio-theme-dark) textarea::placeholder {
    color: #9a9a9a !important;
}

/* ============================================================
   暗色主题：抗锯齿 + 更高对比度
   ============================================================ */
body.studio-theme-dark,
html.studio-theme-dark body {
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
}

/* 暗色主题：网格点改淡（fontSize缩放不影响固定px背景，故降低透明度） */
html.studio-theme-dark {
    --grid: rgba(255,255,255,0.2) !important;
}
html.studio-theme-dark .shell {
    background-color: #0a0a0a !important;
    background-image: radial-gradient(var(--grid) 1px, transparent 1px) !important;
    background-size: 24px 24px !important;
}

/* 暗色主题文字对比度 */
body.studio-theme-dark .text-gray-400,
body.studio-theme-dark .text-gray-500,
body.studio-theme-dark .setting-meta,
body.studio-theme-dark .label-nano,
html.studio-theme-dark body .text-gray-400,
html.studio-theme-dark body .text-gray-500 {
    color: #b0b0b0 !important;
}

body.studio-theme-dark .text-gray-300,
html.studio-theme-dark body .text-gray-300 {
    color: #c8c8c8 !important;
}

/* 主文字更纯净的白色 */
body.studio-theme-dark,
html.studio-theme-dark body,
body.studio-theme-dark h1,
body.studio-theme-dark h2,
body.studio-theme-dark h3 {
    color: #f0f0f0 !important;
}

/* 暗色主题按钮和卡片边框更清晰 */
body.studio-theme-dark .console-card,
body.studio-theme-dark .work-panel,
body.studio-theme-dark .tool-panel,
body.studio-theme-dark .control-panel,
html.studio-theme-dark body .console-card {
    border-color: #2e2e2e !important;
}

/* ============================================================
   高 DPI 屏幕优化
   ============================================================ */
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi) {
    html, body {
        image-rendering: -webkit-optimize-contrast;
    }
}
