/**
 * Mother Tongue Journal - Article Stylesheet
 * Version: 2.0
 * Designed for academic linguistic articles with extensive Unicode support
 * Compatible with mother-tongue-journal.org WordPress theme
 * Includes comprehensive print/PDF generation support
 * 
 * Font Stack: Charis SIL (primary) for excellent IPA/linguistic support
 * Fallbacks: Gentium Plus, Times New Roman, Georgia
 */

/* ===== CSS Custom Properties (Variables) ===== */
:root {
    /* Colors - matches existing MT website aesthetic */
    --mt-text-primary: #1a1a1a;
    --mt-text-secondary: #4a4a4a;
    --mt-text-muted: #6a6a6a;
    --mt-background: #fefefe;
    --mt-background-alt: #f8f6f3;
    --mt-accent: #8b4513;           /* Saddle brown - warm, scholarly */
    --mt-accent-light: #d4a574;
    --mt-border: #d0c8b8;
    --mt-link: #5c4033;
    --mt-link-hover: #8b4513;
    
    /* Typography */
    --mt-font-body: 'Charis SIL', 'Gentium Plus', 'Times New Roman', Georgia, serif;
    --mt-font-heading: 'Charis SIL', 'Gentium Plus', Georgia, serif;
    --mt-font-mono: 'Courier New', Courier, monospace;
    
    /* Spacing */
    --mt-line-height: 1.7;
    --mt-paragraph-spacing: 1.25em;
    --mt-section-spacing: 2.5em;
    
    /* Layout */
    --mt-content-width: 42em;
    --mt-content-width-wide: 52em;
}

/* ===== Base Styles ===== */
html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--mt-font-body);
    font-size: 1.0625rem;           /* 17px - optimal for academic reading */
    line-height: var(--mt-line-height);
    color: var(--mt-text-primary);
    background-color: var(--mt-background);
    margin: 0;
    padding: 0;
}

/* ===== Article Container ===== */
article.mt-article {
    max-width: var(--mt-content-width);
    margin: 0 auto;
    padding: 2em 1.5em 4em;
}

/* ===== Article Header ===== */
.mt-article-header {
    text-align: center;
    margin-bottom: var(--mt-section-spacing);
    padding-bottom: var(--mt-section-spacing);
    border-bottom: 1px solid var(--mt-border);
}

.mt-journal-info {
    font-size: 0.9rem;
    color: var(--mt-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 1.5em;
}

.mt-article-title {
    font-family: var(--mt-font-heading);
    font-size: 1.75rem;
    font-weight: normal;
    line-height: 1.3;
    margin: 0 0 0.3em 0;
    color: var(--mt-text-primary);
}

.mt-article-subtitle {
    font-family: var(--mt-font-heading);
    font-size: 1.25rem;
    font-weight: normal;
    font-style: italic;
    margin: 0 0 1.5em 0;
    color: var(--mt-text-secondary);
}

.mt-author {
    font-size: 1.1rem;
    font-variant: small-caps;
    letter-spacing: 0.05em;
    margin-bottom: 0.5em;
}

.mt-author-note {
    font-size: 0.85rem;
    color: var(--mt-text-muted);
    font-style: italic;
}

.mt-dedication {
    font-style: italic;
    font-size: 0.95rem;
    color: var(--mt-text-secondary);
    margin-top: 1.5em;
}

/* ===== Abstract ===== */
.mt-abstract {
    background-color: var(--mt-background-alt);
    padding: 1.5em 2em;
    margin: var(--mt-section-spacing) 0;
    border-left: 3px solid var(--mt-accent);
}

.mt-abstract-title {
    font-weight: bold;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75em;
    color: var(--mt-text-secondary);
}

.mt-abstract p {
    margin: 0;
    font-size: 0.95rem;
    text-align: justify;
    hyphens: auto;
}

.mt-keywords {
    margin-top: 1em;
    font-size: 0.9rem;
}

.mt-keywords-label {
    font-weight: bold;
}

/* ===== Section Headings ===== */
.mt-section-heading {
    font-family: var(--mt-font-heading);
    font-size: 1.1rem;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-align: center;
    margin: var(--mt-section-spacing) 0 1.5em 0;
    color: var(--mt-text-primary);
}

.mt-subsection-heading {
    font-family: var(--mt-font-heading);
    font-size: 1rem;
    font-weight: bold;
    font-style: italic;
    margin: 2em 0 1em 0;
    color: var(--mt-text-primary);
}

/* ===== Body Text ===== */
.mt-article p {
    margin: 0 0 var(--mt-paragraph-spacing) 0;
    text-align: justify;
    hyphens: auto;
}

/* First paragraph after heading - no indent */
.mt-section-heading + p,
.mt-subsection-heading + p,
.mt-abstract + p {
    text-indent: 0;
}

/* ===== Block Quotations ===== */
.mt-blockquote {
    margin: 1.5em 2em;
    padding: 0;
    font-size: 0.95rem;
    color: var(--mt-text-secondary);
}

.mt-blockquote p {
    text-indent: 0;
}

.mt-blockquote-source {
    text-align: right;
    font-style: italic;
    margin-top: 0.5em;
}

/* ===== Linguistic Notation ===== */
/* PIE reconstructions */
.pie, .mt-pie {
    font-style: italic;
}

/* Sanskrit and other language forms */
.sanskrit {
    font-style: italic;
}

/* Language labels */
.lang-label {
    font-variant: small-caps;
    font-size: 0.9em;
}

/* Glosses and translations */
.gloss {
    font-style: normal;
}

.translation {
    font-style: italic;
}

/* Foreign terms */
.foreign {
    font-style: italic;
}

/* Technical terms */
.term {
    font-style: italic;
}

/* Linguistic examples */
.linguistic-example {
    margin: 1.5em 0 1.5em 2em;
    padding-left: 1em;
    border-left: 2px solid var(--mt-accent);
}

.example-number {
    font-weight: bold;
    margin-right: 0.5em;
}

/* ===== Data Tables ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 2em 0;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    border: 1px solid var(--mt-border);
    padding: 0.5em 0.75em;
    text-align: left;
    vertical-align: top;
}

.data-table th {
    background-color: var(--mt-background-alt);
    font-weight: bold;
}

.data-table caption {
    caption-side: top;
    text-align: left;
    font-weight: bold;
    margin-bottom: 0.5em;
}

/* ===== Footnotes ===== */
/* Footnote reference in text */
.mt-fnref {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 0;
    text-decoration: none;
    color: var(--mt-accent);
}

.mt-fnref:hover {
    color: var(--mt-link-hover);
    text-decoration: underline;
}

/* Footnotes section */
.mt-footnotes {
    margin-top: var(--mt-section-spacing);
    padding-top: 1.5em;
    border-top: 1px solid var(--mt-border);
    font-size: 0.85rem;
    line-height: 1.5;
}

.mt-footnotes-title {
    font-size: 0.9rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1em;
    color: var(--mt-text-secondary);
}

.mt-footnote {
    margin-bottom: 0.75em;
    padding-left: 2em;
    text-indent: -2em;
}

.mt-footnote-num {
    font-weight: bold;
    color: var(--mt-accent);
    margin-right: 0.5em;
}

.mt-footnote-backref {
    font-size: 0.8em;
    color: var(--mt-text-muted);
    text-decoration: none;
    margin-left: 0.25em;
}

.mt-footnote-backref:hover {
    color: var(--mt-link-hover);
}

/* ===== Figures ===== */
.mt-figure {
    margin: 2em 0;
    text-align: center;
}

.mt-figure img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--mt-border);
}

.mt-figure-caption {
    font-size: 0.9rem;
    color: var(--mt-text-secondary);
    margin-top: 0.75em;
    text-align: left;
    line-height: 1.4;
}

.mt-figure-caption strong {
    font-weight: bold;
}

/* Figure placeholder for missing images */
.mt-figure-placeholder {
    background-color: var(--mt-background-alt);
    border: 2px dashed var(--mt-border);
    padding: 3em 2em;
    color: var(--mt-text-muted);
    font-style: italic;
}

/* ===== Lists ===== */
.mt-article ol,
.mt-article ul {
    margin: 1em 0 var(--mt-paragraph-spacing) 2em;
    padding: 0;
}

.mt-article li {
    margin-bottom: 0.5em;
}

/* Numbered lists for arguments/points */
.mt-numbered-points {
    counter-reset: point-counter;
    list-style: none;
    margin-left: 0;
    padding-left: 2em;
}

.mt-numbered-points li {
    counter-increment: point-counter;
    position: relative;
    margin-bottom: 1em;
}

.mt-numbered-points li::before {
    content: counter(point-counter) ".";
    position: absolute;
    left: -2em;
    font-weight: bold;
    color: var(--mt-accent);
}

/* Abbreviation lists */
.abbrev-list {
    columns: 2;
    column-gap: 2em;
}

.abbrev-list p {
    text-indent: 0;
    margin: 0.25em 0;
}

/* ===== References/Bibliography ===== */
.mt-references {
    margin-top: var(--mt-section-spacing);
}

.mt-references-title {
    font-family: var(--mt-font-heading);
    font-size: 1.1rem;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-align: center;
    margin-bottom: 1.5em;
}

.mt-reference {
    margin-bottom: 0.75em;
    padding-left: 2em;
    text-indent: -2em;
    font-size: 0.95rem;
}

.mt-reference .author {
    font-variant: normal;
}

.mt-reference .title {
    font-style: italic;
}

.mt-reference .article-title {
    font-style: normal;
}

.mt-reference .journal {
    font-style: italic;
}

/* ===== Links ===== */
.mt-article a {
    color: var(--mt-link);
    text-decoration: none;
}

.mt-article a:hover {
    color: var(--mt-link-hover);
    text-decoration: underline;
}

/* ===== Page Footer ===== */
.mt-article-footer {
    margin-top: var(--mt-section-spacing);
    padding-top: 1.5em;
    border-top: 1px solid var(--mt-border);
    font-size: 0.85rem;
    color: var(--mt-text-muted);
    text-align: center;
}

/* ===== Utility Classes ===== */
.mt-small-caps {
    font-variant: small-caps;
}

.mt-center {
    text-align: center;
}

.mt-indent {
    text-indent: 2em;
}

.mt-no-indent {
    text-indent: 0;
}

/* ============================================= */
/* ===== PRINT / PDF GENERATION STYLES ========= */
/* ============================================= */

/* 
 * These styles optimize output for PDF generation via:
 * - wkhtmltopdf
 * - WeasyPrint  
 * - Browser Print (Ctrl+P)
 * - Puppeteer/Playwright
 *
 * Key features:
 * - @page rules for proper margins and headers/footers
 * - Page break control
 * - Print-optimized typography
 * - No external font dependencies (uses system fonts)
 */

@media print {
    /* Page setup - A4 with academic margins */
    @page {
        size: A4;
        margin: 25mm 20mm 25mm 25mm;
        
        /* Running headers/footers (supported by WeasyPrint, Prince) */
        @top-center {
            content: "Mother Tongue • Issue XXV • 2024";
            font-size: 9pt;
            color: #666;
        }
        @bottom-center {
            content: counter(page);
            font-size: 9pt;
        }
    }
    
    /* First page - no header */
    @page :first {
        @top-center {
            content: none;
        }
    }
    
    /* Base print typography */
    html {
        font-size: 11pt;
    }
    
    body {
        font-family: 'Times New Roman', Georgia, serif;
        font-size: 11pt;
        line-height: 1.5;
        color: black;
        background: white;
    }
    
    /* Remove max-width constraint for print */
    article.mt-article {
        max-width: none;
        padding: 0;
        margin: 0;
    }
    
    /* Ensure proper text color */
    .mt-article-header,
    .mt-section-heading,
    .mt-subsection-heading,
    .mt-article p,
    .mt-abstract,
    .mt-reference {
        color: black;
    }
    
    /* Header styling for print */
    .mt-article-header {
        page-break-after: avoid;
        border-bottom: 0.5pt solid #999;
        padding-bottom: 1.5em;
        margin-bottom: 1.5em;
    }
    
    .mt-journal-info {
        color: #333;
        font-size: 9pt;
    }
    
    .mt-article-title {
        font-size: 16pt;
        line-height: 1.2;
    }
    
    .mt-article-subtitle {
        font-size: 12pt;
    }
    
    .mt-author {
        font-size: 11pt;
    }
    
    .mt-author-note {
        font-size: 9pt;
        color: #333;
    }
    
    /* Abstract styling for print */
    .mt-abstract {
        background-color: #f5f5f5 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        border-left: 2pt solid #666;
        padding: 1em 1.5em;
        margin: 1.5em 0;
    }
    
    .mt-abstract-title {
        color: #333;
        font-size: 9pt;
    }
    
    .mt-abstract p {
        font-size: 10pt;
    }
    
    /* Section headings for print */
    .mt-section-heading {
        font-size: 11pt;
        margin: 1.5em 0 1em 0;
        page-break-after: avoid;
    }
    
    .mt-subsection-heading {
        font-size: 10.5pt;
        margin: 1.5em 0 0.75em 0;
        page-break-after: avoid;
    }
    
    /* Paragraphs */
    .mt-article p {
        orphans: 3;
        widows: 3;
        font-size: 11pt;
    }
    
    /* Linguistic examples - keep together */
    .linguistic-example {
        page-break-inside: avoid;
        border-left: 1.5pt solid #666;
        margin: 1em 0 1em 1.5em;
        padding-left: 0.75em;
    }
    
    .example-number {
        font-weight: bold;
    }
    
    .gloss {
        color: #333;
    }
    
    /* Tables - keep together when possible */
    .data-table {
        page-break-inside: avoid;
        font-size: 9pt;
    }
    
    .data-table th {
        background-color: #e8e8e8 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .data-table th,
    .data-table td {
        border: 0.5pt solid #999;
        padding: 0.4em 0.6em;
    }
    
    /* Footnotes */
    .mt-footnotes {
        font-size: 9pt;
        border-top: 0.5pt solid #999;
    }
    
    .mt-footnote-num {
        color: black;
    }
    
    /* References */
    .mt-references-title {
        font-size: 11pt;
        page-break-after: avoid;
    }
    
    .mt-reference {
        font-size: 9.5pt;
        page-break-inside: avoid;
    }
    
    /* Links - show as plain text */
    .mt-article a {
        color: black;
        text-decoration: none;
    }
    
    /* Optionally show URLs for external links */
    .mt-article a[href^="http"]:not(.mt-journal-info a)::after {
        content: " [" attr(href) "]";
        font-size: 8pt;
        color: #666;
    }
    
    /* Hide decorative elements */
    .mt-journal-info a::after {
        content: none !important;
    }
    
    /* Hide back-references in print */
    .mt-footnote-backref {
        display: none;
    }
    
    /* Article footer */
    .mt-article-footer {
        border-top: 0.5pt solid #999;
        font-size: 9pt;
        color: #333;
        page-break-before: avoid;
    }
    
    /* Abbreviation lists */
    .abbrev-list {
        columns: 2;
        column-gap: 1.5em;
        font-size: 9pt;
    }
    
    /* Force backgrounds to print */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    /* Page break hints */
    h2, h3 {
        page-break-after: avoid;
    }
    
    section {
        page-break-before: auto;
    }
    
    /* Keep figures with captions */
    .mt-figure {
        page-break-inside: avoid;
    }
}

/* ===== Responsive Adjustments ===== */
@media screen and (max-width: 768px) {
    body {
        font-size: 1rem;
    }
    
    article.mt-article {
        padding: 1em;
    }
    
    .mt-article-title {
        font-size: 1.5rem;
    }
    
    .mt-blockquote {
        margin: 1em 1em;
    }
    
    .mt-abstract {
        padding: 1em 1.25em;
    }
    
    .abbrev-list {
        columns: 1;
    }
    
    .data-table {
        font-size: 0.8rem;
    }
}

/* ===== Dark Mode Support (screen only) ===== */
@media screen and (prefers-color-scheme: dark) {
    :root {
        --mt-text-primary: #e8e6e3;
        --mt-text-secondary: #b8b5b0;
        --mt-text-muted: #8a8680;
        --mt-background: #1a1918;
        --mt-background-alt: #252322;
        --mt-accent: #d4a574;
        --mt-accent-light: #8b4513;
        --mt-border: #3d3a36;
        --mt-link: #d4a574;
        --mt-link-hover: #e8c9a8;
    }
}
