/* Typography Optimization for Better Readability */

/* Import system font stack for optimal performance */
:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', 'Monaco', 'Andale Mono', 'Ubuntu Mono', monospace;
    
    /* Typography scale - Major Third (1.25) */
    --text-xs: 0.8rem;
    --text-sm: 0.889rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.563rem;
    --text-3xl: 1.953rem;
    --text-4xl: 2.441rem;
    --text-5xl: 3.052rem;
    
    /* Line heights */
    --leading-tight: 1.25;
    --leading-snug: 1.375;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;
    --leading-loose: 1.75;
    
    /* Letter spacing */
    --tracking-tighter: -0.05em;
    --tracking-tight: -0.025em;
    --tracking-normal: 0;
    --tracking-wide: 0.025em;
    --tracking-wider: 0.05em;
    --tracking-widest: 0.1em;
    
    /* Optimized line lengths */
    --measure-narrow: 45ch;
    --measure-base: 65ch;
    --measure-wide: 80ch;
}

/* Base typography improvements */
html {
    font-size: 100%; /* 16px base */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Responsive font sizes */
@media (min-width: 640px) {
    html { font-size: 106.25%; } /* 17px */
}

@media (min-width: 1024px) {
    html { font-size: 112.5%; } /* 18px */
}

/* Body text optimization */
body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    font-weight: 400;
    letter-spacing: var(--tracking-normal);
    font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
}

/* Paragraph optimization */
p {
    max-width: var(--measure-base);
    margin-bottom: 1.5rem;
    hanging-punctuation: first last;
    hyphens: auto;
}

/* Optimize long-form content */
.section p,
.timeline-content p,
.project-card p {
    line-height: var(--leading-loose);
    color: var(--text-secondary);
}

/* Headings optimization */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    font-weight: 700;
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    margin-top: 0;
}

h1 {
    font-size: clamp(var(--text-3xl), 5vw, var(--text-5xl));
    letter-spacing: var(--tracking-tighter);
    font-weight: 800;
}

h2 {
    font-size: clamp(var(--text-xl), 3vw, var(--text-2xl));
    margin-bottom: 1.25rem;
    font-weight: 700;
}

h3 {
    font-size: clamp(var(--text-lg), 2vw, var(--text-xl));
    margin-bottom: 0.75rem;
    font-weight: 600;
}

/* Small text optimization */
.hero-meta-label,
.cert-date,
.timeline-date {
    font-size: var(--text-sm);
    letter-spacing: var(--tracking-wide);
    font-weight: 500;
}

/* Monospace text optimization */
code, pre, .terminal-nav, .filter-btn {
    font-family: var(--font-mono);
    font-size: 0.9em;
    letter-spacing: normal;
    font-feature-settings: 'calt' 0; /* Disable ligatures for code */
}

/* Improve readability for dense content */
.bullet-list {
    line-height: var(--leading-loose);
}

.bullet-list li {
    margin-bottom: 0.75rem;
}

/* Tags and labels */
.tag {
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

/* Links optimization */
a {
    text-decoration-skip-ink: auto;
    text-underline-offset: 0.2em;
    transition: all 0.2s ease;
}

/* Button text optimization */
.btn-primary, .btn-secondary, button {
    font-weight: 600;
    letter-spacing: var(--tracking-normal);
    font-size: var(--text-sm);
}

/* Quote styling for better readability */
blockquote {
    font-style: italic;
    font-size: var(--text-lg);
    line-height: var(--leading-relaxed);
    color: var(--text-secondary);
    border-left: 4px solid var(--accent);
    padding-left: 1.5rem;
    margin: 2rem 0;
    max-width: var(--measure-narrow);
}

/* Lists optimization */
ul, ol {
    max-width: var(--measure-base);
    padding-left: 1.5rem;
}

li {
    line-height: var(--leading-relaxed);
}

/* Improve number readability */
.metric-value,
.hero-meta-value {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* Optimize for different reading conditions */

/* Dark mode typography adjustments */
[data-theme="dark"] {
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
}

[data-theme="dark"] body {
    font-weight: 400;
    letter-spacing: 0.01em; /* Slightly wider spacing for dark mode */
}

/* High contrast mode */
@media (prefers-contrast: high) {
    body {
        font-weight: 500;
    }
    
    h1, h2, h3, h4, h5, h6 {
        font-weight: 800;
    }
}

/* Print typography */
@media print {
    body {
        font-size: 12pt;
        line-height: 1.6;
        font-family: 'Georgia', 'Times New Roman', serif;
    }
    
    h1, h2, h3, h4, h5, h6 {
        font-family: 'Arial', 'Helvetica', sans-serif;
        page-break-after: avoid;
    }
    
    p {
        orphans: 3;
        widows: 3;
    }
}

/* Optimize for different screen densities */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    body {
        -webkit-font-smoothing: subpixel-antialiased;
    }
}

/* Language-specific optimizations */
:lang(ja) body,
:lang(zh) body,
:lang(ko) body {
    line-height: 1.8;
    letter-spacing: 0.02em;
}

/* Improve readability indicators */
.section-lead {
    font-size: var(--text-lg);
    line-height: var(--leading-relaxed);
    color: var(--text-secondary);
    font-weight: 500;
    max-width: var(--measure-narrow);
}

/* Optimize dense information areas */
.skills-grid,
.project-meta {
    font-size: var(--text-sm);
}

/* Better spacing between text blocks */
.section > * + * {
    margin-top: 1.5rem;
}

h2 + p,
h3 + p {
    margin-top: 0.75rem;
}

/* Improve readability on ultra-wide screens */
@media (min-width: 1920px) {
    body {
        font-size: 1.125rem;
    }
    
    .section {
        padding: 2.5rem;
    }
}

/* Mobile typography optimization */
@media (max-width: 640px) {
    html {
        font-size: 100%; /* Keep 16px on mobile to prevent zoom */
    }
    
    h1 {
        font-size: var(--text-3xl);
    }
    
    h2 {
        font-size: var(--text-xl);
    }
    
    h3 {
        font-size: var(--text-lg);
    }
    
    /* Improve tap target readability */
    .btn-primary,
    .btn-secondary,
    .filter-btn {
        font-size: var(--text-base);
    }
}

/* Add reading mode styles */
.reading-mode {
    --measure-base: 55ch;
    font-size: 1.125rem;
    line-height: 1.8;
}

.reading-mode p {
    margin-bottom: 2rem;
}

/* Optimize for dyslexia */
.dyslexia-friendly {
    font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif;
    letter-spacing: 0.12em;
    word-spacing: 0.16em;
    line-height: 2;
}