/**
 * Multi-Script Font System for AIMangaMaker
 * Optimized font loading for international languages
 *
 * Supports: Latin, German, Chinese (Simplified), Japanese, Korean, Cyrillic, etc.
 * Performance: Uses font-display: swap for fast rendering
 *
 * ALL FONTS HOSTED LOCALLY - No external CDN dependencies
 */

/* ===== COMIC/MANGA FONTS (14 families) ===== */

/* Bangers */
@font-face {
  font-family: 'Bangers';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/bangers/bangers-v25-latin-regular.woff2') format('woff2');
}

/* Carter One */
@font-face {
  font-family: 'Carter One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/carter-one/carter-one-v18-latin-regular.woff2') format('woff2');
}

/* Chewy */
@font-face {
  font-family: 'Chewy';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/chewy/chewy-v18-latin-regular.woff2') format('woff2');
}

/* Comic Neue - Regular */
@font-face {
  font-family: 'Comic Neue';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/comic-neue/comic-neue-v9-latin-regular.woff2') format('woff2');
}

/* Comic Neue - Bold */
@font-face {
  font-family: 'Comic Neue';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/comic-neue/comic-neue-v9-latin-700.woff2') format('woff2');
}

/* Fredoka One */
@font-face {
  font-family: 'Fredoka One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/fredoka-one/fredoka-one-v14-latin-regular.woff2') format('woff2');
}

/* Gloria Hallelujah */
@font-face {
  font-family: 'Gloria Hallelujah';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/gloria-hallelujah/gloria-hallelujah-v24-latin-regular.woff2') format('woff2');
}

/* Kalam - Regular */
@font-face {
  font-family: 'Kalam';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/kalam/kalam-v18-latin-regular.woff2') format('woff2');
}

/* Kalam - Bold */
@font-face {
  font-family: 'Kalam';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/kalam/kalam-v18-latin-700.woff2') format('woff2');
}

/* Luckiest Guy */
@font-face {
  font-family: 'Luckiest Guy';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/luckiest-guy/luckiest-guy-v25-latin-regular.woff2') format('woff2');
}

/* Patrick Hand */
@font-face {
  font-family: 'Patrick Hand';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/patrick-hand/patrick-hand-v25-latin-regular.woff2') format('woff2');
}

/* Permanent Marker */
@font-face {
  font-family: 'Permanent Marker';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/permanent-marker/permanent-marker-v16-latin-regular.woff2') format('woff2');
}

/* Rock Salt */
@font-face {
  font-family: 'Rock Salt';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/rock-salt/rock-salt-v24-latin-regular.woff2') format('woff2');
}

/* Rubik Mono One */
@font-face {
  font-family: 'Rubik Mono One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/rubik-mono-one/rubik-mono-one-v20-latin-regular.woff2') format('woff2');
}

/* Shadows Into Light */
@font-face {
  font-family: 'Shadows Into Light';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/shadows-into-light/shadows-into-light-v22-latin-regular.woff2') format('woff2');
}

/* Special Elite */
@font-face {
  font-family: 'Special Elite';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/special-elite/special-elite-v20-latin-regular.woff2') format('woff2');
}

/* ===== CJK FONTS (Chinese, Japanese, Korean) ===== */

/* Noto Sans SC - Light 300 */
@font-face {
  font-family: 'Noto Sans SC';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('../fonts/noto-sans-sc/noto-sans-sc-v39-chinese-simplified-300.woff2') format('woff2');
}

/* Noto Sans SC - Regular 400 */
@font-face {
  font-family: 'Noto Sans SC';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/noto-sans-sc/noto-sans-sc-v39-chinese-simplified-regular.woff2') format('woff2');
}

/* Noto Sans SC - Medium 500 */
@font-face {
  font-family: 'Noto Sans SC';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/noto-sans-sc/noto-sans-sc-v39-chinese-simplified-500.woff2') format('woff2');
}

/* Noto Sans SC - Bold 700 */
@font-face {
  font-family: 'Noto Sans SC';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/noto-sans-sc/noto-sans-sc-v39-chinese-simplified-700.woff2') format('woff2');
}

/* Noto Sans JP - Light 300 */
@font-face {
  font-family: 'Noto Sans JP';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('../fonts/noto-sans-jp/noto-sans-jp-v55-japanese-300.woff2') format('woff2');
}

/* Noto Sans JP - Regular 400 */
@font-face {
  font-family: 'Noto Sans JP';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/noto-sans-jp/noto-sans-jp-v55-japanese-regular.woff2') format('woff2');
}

/* Noto Sans JP - Medium 500 */
@font-face {
  font-family: 'Noto Sans JP';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/noto-sans-jp/noto-sans-jp-v55-japanese-500.woff2') format('woff2');
}

/* Noto Sans JP - Bold 700 */
@font-face {
  font-family: 'Noto Sans JP';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/noto-sans-jp/noto-sans-jp-v55-japanese-700.woff2') format('woff2');
}

/* Noto Sans KR - Light 300 */
@font-face {
  font-family: 'Noto Sans KR';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('../fonts/noto-sans-kr/noto-sans-kr-v38-korean-300.woff2') format('woff2');
}

/* Noto Sans KR - Regular 400 */
@font-face {
  font-family: 'Noto Sans KR';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/noto-sans-kr/noto-sans-kr-v38-korean-regular.woff2') format('woff2');
}

/* Noto Sans KR - Medium 500 */
@font-face {
  font-family: 'Noto Sans KR';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/noto-sans-kr/noto-sans-kr-v38-korean-500.woff2') format('woff2');
}

/* Noto Sans KR - Bold 700 */
@font-face {
  font-family: 'Noto Sans KR';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/noto-sans-kr/noto-sans-kr-v38-korean-700.woff2') format('woff2');
}

/* ===== FONT VARIABLES ===== */
:root {
    /* Base font stacks (Latin/Cyrillic) */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    --font-mono: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, Courier, monospace;

    /* CJK font stacks */
    --font-zh: 'Noto Sans SC', 'Microsoft YaHei', '微软雅黑', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
    --font-ja: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'ヒラギノ角ゴ ProN W3', 'Yu Gothic', 'YuGothic', Meiryo, sans-serif;
    --font-ko: 'Noto Sans KR', 'Malgun Gothic', '맑은 고딕', 'Apple SD Gothic Neo', sans-serif;
}

/* ===== LANGUAGE-SPECIFIC FONT APPLICATION ===== */

/* Default (English, German, etc.) */
body {
    font-family: var(--font-sans);
}

/* Chinese Simplified */
html[lang="zh"],
html.lang-zh,
.lang-zh {
    font-family: var(--font-zh);
}

html[lang="zh"] body,
html.lang-zh body {
    font-family: var(--font-zh);
}

/* Japanese */
html[lang="ja"],
html.lang-ja,
.lang-ja {
    font-family: var(--font-ja);
}

html[lang="ja"] body,
html.lang-ja body {
    font-family: var(--font-ja);
}

/* Korean */
html[lang="ko"],
html.lang-ko,
.lang-ko {
    font-family: var(--font-ko);
}

html[lang="ko"] body,
html.lang-ko body {
    font-family: var(--font-ko);
}

/* ===== FONT WEIGHT ADJUSTMENTS FOR CJK ===== */
/* CJK fonts look better with slightly reduced weight */

html[lang="zh"] .btn,
html[lang="ja"] .btn,
html[lang="ko"] .btn,
html.lang-zh .btn,
html.lang-ja .btn,
html.lang-ko .btn {
    font-weight: 500; /* Slightly lighter for CJK */
}

html[lang="zh"] h1, html[lang="zh"] h2, html[lang="zh"] h3,
html[lang="ja"] h1, html[lang="ja"] h2, html[lang="ja"] h3,
html[lang="ko"] h1, html[lang="ko"] h2, html[lang="ko"] h3,
html.lang-zh h1, html.lang-zh h2, html.lang-zh h3,
html.lang-ja h1, html.lang-ja h2, html.lang-ja h3,
html.lang-ko h1, html.lang-ko h2, html.lang-ko h3 {
    font-weight: 700;
}

/* ===== LINE HEIGHT ADJUSTMENTS ===== */
/* CJK characters need more vertical spacing */

html[lang="zh"],
html[lang="ja"],
html[lang="ko"],
html.lang-zh,
html.lang-ja,
html.lang-ko {
    line-height: 1.8; /* Increased for CJK readability */
}

html[lang="zh"] p,
html[lang="ja"] p,
html[lang="ko"] p,
html.lang-zh p,
html.lang-ja p,
html.lang-ko p {
    line-height: 1.9;
}

/* ===== LETTER SPACING ADJUSTMENTS ===== */
/* CJK doesn't need letter spacing */

html[lang="zh"] .btn,
html[lang="ja"] .btn,
html[lang="ko"] .btn,
html.lang-zh .btn,
html.lang-ja .btn,
html.lang-ko .btn {
    letter-spacing: 0;
}

/* ===== FALLBACK FONTS FOR MIXED CONTENT ===== */
/* When mixing Latin and CJK characters */

html[lang="zh"] *,
html.lang-zh * {
    font-family: var(--font-zh), var(--font-sans);
}

html[lang="ja"] *,
html.lang-ja * {
    font-family: var(--font-ja), var(--font-sans);
}

html[lang="ko"] *,
html.lang-ko * {
    font-family: var(--font-ko), var(--font-sans);
}

/* ===== MONOSPACE FONTS (Code blocks, etc.) ===== */
code, pre, .code {
    font-family: var(--font-mono);
}

/* ===== FONT LOADING OPTIMIZATION ===== */
/* Prevent FOIT (Flash of Invisible Text) */

@font-face {
    font-family: 'Noto Sans SC';
    font-display: swap; /* Show fallback immediately */
}

@font-face {
    font-family: 'Noto Sans JP';
    font-display: swap;
}

@font-face {
    font-family: 'Noto Sans KR';
    font-display: swap;
}

/* ===== TEXT RENDERING OPTIMIZATION ===== */

html[lang="zh"],
html[lang="ja"],
html[lang="ko"],
html.lang-zh,
html.lang-ja,
html.lang-ko {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== RESPONSIVE FONT SIZES ===== */
/* Adjust for different screen sizes */

@media (max-width: 768px) {
    html[lang="zh"],
    html[lang="ja"],
    html[lang="ko"],
    html.lang-zh,
    html.lang-ja,
    html.lang-ko {
        font-size: 14px; /* Slightly smaller for mobile CJK */
    }
}

/* ===== SPECIAL CHARACTER SUPPORT ===== */
/* Ensure proper rendering of special characters */

html[lang="zh"] .emoji,
html[lang="ja"] .emoji,
html[lang="ko"] .emoji {
    font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', var(--font-zh);
}

/* ===== GERMAN SPECIFIC (Optional) ===== */
/* German uses standard Latin fonts but may benefit from slightly tighter spacing */

html[lang="de"],
html.lang-de {
    font-family: var(--font-sans);
}

/* ===== PERFORMANCE NOTES ===== */
/*
 * Font Loading Strategy:
 * 1. Latin fonts use system fonts (0 network requests, instant)
 * 2. CJK fonts loaded from Google Fonts CDN (cached, ~100-300KB per font)
 * 3. font-display: swap ensures text is always visible
 * 4. Fonts are subset by Google Fonts for optimal size
 *
 * Total Download (worst case, all 3 CJK fonts):
 * - Noto Sans SC: ~250KB
 * - Noto Sans JP: ~300KB
 * - Noto Sans KR: ~280KB
 * Total: ~830KB (only loaded if user switches to those languages)
 *
 * Performance Impact: Minimal
 * - First visit: Font loads in background, fallback shown immediately
 * - Subsequent visits: Cached by browser (0ms)
 */
