/* 字體顯示優化 - 減少字體載入延遲 */

/* 1. 為所有字體設置 font-display: swap */
@font-face {
    font-family: 'Glyphicons Halflings';
    font-display: swap;
    src: url('../fonts/glyphicons-halflings-regular.eot');
    src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
         url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'),
         url('../fonts/glyphicons-halflings-regular.woff') format('woff'),
         url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'),
         url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

@font-face {
    font-family: 'FontAwesome';
    font-display: swap;
    src: url('../fonts/fontawesome-webfont.eot?v=4.4.0');
    src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.4.0') format('embedded-opentype'),
         url('../fonts/fontawesome-webfont.woff2?v=4.4.0') format('woff2'),
         url('../fonts/fontawesome-webfont.woff?v=4.4.0') format('woff'),
         url('../fonts/fontawesome-webfont.ttf?v=4.4.0') format('truetype'),
         url('../fonts/fontawesome-webfont.svg?v=4.4.0#fontawesomeregular') format('svg');
}

/* 2. 為系統字體設置 font-display */
body, html {
    font-display: swap;
}

/* 3. 為所有文字元素設置 font-display */
* {
    font-display: swap;
}

/* 4. 預載入關鍵字體 */
.preload-fonts {
    font-family: 'Glyphicons Halflings', 'FontAwesome', system-ui, -apple-system, sans-serif;
    font-display: swap;
    visibility: hidden;
    position: absolute;
    left: -9999px;
}

/* 5. 字體載入完成後的過渡效果 */
.fonts-loading {
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

.fonts-loaded {
    opacity: 1;
}

/* 6. 防止字體載入時的文字閃爍 */
.no-js .fonts-loading {
    opacity: 1;
}

/* 7. 為圖標字體設置備用字體 */
.glyphicon {
    font-family: 'Glyphicons Halflings', monospace;
    font-display: swap;
}

.fa {
    font-family: 'FontAwesome', monospace;
    font-display: swap;
}

/* 8. 優化字體渲染 */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* 9. 字體載入狀態指示器 */
.font-loading-indicator {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, #007bff 0%, #007bff 50%, transparent 50%);
    background-size: 200% 100%;
    animation: loading-progress 2s infinite;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.fonts-loading .font-loading-indicator {
    opacity: 1;
}

.fonts-loaded .font-loading-indicator {
    opacity: 0;
}

@keyframes loading-progress {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* 10. 字體載入錯誤處理 */
.font-load-error {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* 11. 響應式字體優化 */
@media (max-width: 768px) {
    body {
        font-size: 14px;
        line-height: 1.4;
    }
}

@media (min-width: 769px) {
    body {
        font-size: 16px;
        line-height: 1.6;
    }
}