/* Enhanced Typography Styles */

.text-optimized {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "kern" 1, "liga" 1;
    font-kerning: normal;
}

.text-justified {
    text-align: justify;
    text-justify: inter-word;
    hyphens: auto;
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    -ms-hyphens: auto;
    word-break: break-word;
    overflow-wrap: break-word;
    text-align-last: left;
}

.text-justified-balanced {
    text-align: justify;
    text-justify: distribute;
    word-spacing: -0.05em;
    letter-spacing: 0.01em;
    hyphens: manual;
    hyphenate-limit-chars: 6 3 2;
    hyphenate-limit-lines: 2;
    hyphenate-limit-zone: 8%;
    hyphenate-limit-last: always;
}

.text-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1em;
    overflow: hidden;
    position: relative;
}

.text-responsive {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    transition: font-size 0.3s ease;
}

/* Title specific styles */
.title-optimized {
    text-align: center;
    letter-spacing: -0.02em;
    line-height: 1.1;
    word-break: break-word;
    font-weight: 700;
    text-wrap: balance;
}

/* Body text styles */
.body-text-optimized {
    line-height: 1.6;
    orphans: 3;
    widows: 3;
    text-wrap: pretty;
}

/* Short text (< 100 chars) */
.text-short {
    text-align: center;
    letter-spacing: normal;
    word-spacing: normal;
}

/* Medium text (100-500 chars) */
.text-medium {
    text-align: left;
    hyphens: auto;
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    -ms-hyphens: auto;
}

/* Long text (> 500 chars) */
.text-long {
    text-align: justify;
    text-justify: inter-word;
    hyphens: auto;
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    -ms-hyphens: auto;
    hyphenate-limit-chars: 6 3 2;
}

/* Prevent orphans and widows */
.text-no-orphans {
    orphans: 3;
    widows: 3;
}

/* Language-specific hyphenation */
[lang="en"] {
    quotes: '"' '"' ''' ''';
    hyphenate-character: '‐';
}

[lang="ro"] {
    quotes: '„' '"' '‚' ''';
    hyphenate-character: '‐';
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .text-justified {
        hyphens: manual;
        word-spacing: normal;
    }
    
    .text-justified-balanced {
        text-align: left;
        hyphens: none;
    }
    
    .body-text-optimized {
        line-height: 1.5;
    }
}

/* High DPI screen optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .text-optimized {
        -webkit-font-smoothing: subpixel-antialiased;
        text-rendering: geometricPrecision;
    }
}

/* Fallback for browsers without hyphenation support */
@supports not (hyphens: auto) {
    .text-justified,
    .text-justified-balanced {
        word-break: break-word;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
}

/* CSS variables for dynamic sizing */
:root {
    --text-scale-ratio: 1.2;
    --text-base-size: 16px;
    --text-line-height-ratio: 1.6;
    --text-max-width: 65ch;
}

.text-fluid {
    font-size: clamp(
        var(--text-base-size),
        calc(var(--text-base-size) + 1vw),
        calc(var(--text-base-size) * var(--text-scale-ratio))
    );
    line-height: var(--text-line-height-ratio);
    max-width: var(--text-max-width);
}

/* Prevent text overflow with ellipsis */
.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.text-truncate-multiline {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Optimize reading experience */
.text-reading-optimized {
    font-size: clamp(1rem, 2.5vw, 1.25rem);
    line-height: 1.6;
    max-width: 65ch;
    margin-left: auto;
    margin-right: auto;
    text-align: left;
    hyphens: auto;
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    -ms-hyphens: auto;
}

/* Dark mode optimizations */
@media (prefers-color-scheme: dark) {
    .text-optimized {
        -webkit-font-smoothing: antialiased;
        letter-spacing: 0.02em;
    }
}