/* Typography - Professional Reading Experience
   Fonts: Inter (body/headings) + JetBrains Mono (code)
   Self-hosted WOFF2 variable fonts for performance */

/* ===== @font-face Declarations ===== */

@font-face {
    font-family: 'Inter';
    src: url('../fonts/InterVariable.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Inter';
    src: url('../fonts/InterVariable-Italic.woff2') format('woff2');
    font-weight: 100 900;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: 'JetBrains Mono';
    src: url('../fonts/JetBrainsMono-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'JetBrains Mono';
    src: url('../fonts/JetBrainsMono-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* ===== CSS Variables ===== */

:root {
    /* Font Families */
    --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system,
        BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
        Arial, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular,
        'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

    /* Font Sizes */
    --text-xs: 0.75rem;      /* 12px */
    --text-sm: 0.875rem;     /* 14px */
    --text-base: 1.125rem;   /* 18px - optimal for sustained reading */
    --text-lg: 1.25rem;      /* 20px */
    --text-xl: 1.5rem;       /* 24px */
    --text-2xl: 1.875rem;    /* 30px */
    --text-3xl: 2.25rem;     /* 36px */
    --text-4xl: 3rem;        /* 48px */

    /* Line Heights */
    --leading-tight: 1.25;
    --leading-snug: 1.375;
    --leading-normal: 1.5;
    --leading-relaxed: 1.65;  /* Body text sweet spot for Inter */
    --leading-loose: 1.8;

    /* Letter Spacing */
    --tracking-tight: -0.02em;
    --tracking-normal: 0;
    --tracking-wide: 0.02em;
}

/* ===== Base Typography ===== */

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'liga' 1, 'calt' 1, 'kern' 1;
}

/* ===== Headings ===== */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    font-weight: 650;
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    margin-top: 2.5em;
    margin-bottom: 0.8em;
}

h1 {
    font-size: var(--text-3xl);
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 1em;
    border-bottom: 3px solid var(--color-primary);
    padding-bottom: 0.5em;
}

h2 {
    font-size: var(--text-2xl);
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.4em;
}

h3 {
    font-size: var(--text-xl);
    font-weight: 600;
}

h4 {
    font-size: var(--text-lg);
    font-weight: 600;
}

h5, h6 {
    font-size: var(--text-base);
    font-weight: 600;
}

/* ===== Paragraphs ===== */

p {
    margin: 1.25em 0;
    max-width: 72ch; /* Optimal 65-75 char line length */
}

/* ===== Links ===== */

a {
    color: var(--color-primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

a:hover {
    border-bottom-color: var(--color-primary);
}

/* ===== Lists ===== */

ul, ol {
    margin: 1.25em 0;
    padding-left: 1.75em;
}

li {
    margin: 0.5em 0;
    line-height: var(--leading-normal);
}

li > ul, li > ol {
    margin: 0.5em 0;
}

/* ===== Blockquotes ===== */

blockquote {
    margin: 2em 0;
    padding: 1em 1.5em;
    border-left: 4px solid var(--color-primary);
    background: var(--color-bg-secondary);
    font-style: italic;
}

blockquote p {
    margin: 0.5em 0;
}

/* ===== Code ===== */

code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--color-code-bg);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    border: 1px solid var(--color-border);
    font-variant-ligatures: none; /* disable ligatures in inline code */
}

pre {
    margin: 2em 0;
    padding: 1.25em 1.5em;
    background: var(--color-code-block-bg);
    border-radius: 8px;
    overflow-x: auto;
    line-height: 1.5;
    white-space: pre;
    word-wrap: normal;
    max-width: 100%;
}

/* Better scrollbar for code blocks */
pre::-webkit-scrollbar {
    height: 8px;
}

pre::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

pre::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

pre::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

pre code {
    background: none;
    padding: 0;
    border: none;
    font-size: 0.9375rem; /* 15px - slightly smaller than body for code */
    color: var(--color-code-text);
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
    font-variant-ligatures: none;
}

/* ===== Tables ===== */

table {
    width: 100%;
    max-width: 100%;
    margin: 2em 0;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

th, td {
    padding: 0.75em 1em;
    text-align: left;
    border: 1px solid var(--color-border);
}

th {
    background: var(--color-bg-secondary);
    font-weight: 600;
}

tr:nth-child(even) {
    background: var(--color-bg-secondary);
}

/* ===== Inline Styles ===== */

strong {
    font-weight: 650;
    color: var(--color-text-strong);
}

em {
    font-style: italic;
}

/* ===== Horizontal Rule ===== */

hr {
    border: none;
    border-top: 2px solid var(--color-border);
    margin: 3em 0;
}

/* ===== Selection ===== */

::selection {
    background: var(--color-primary);
    color: white;
}

/* ===== Responsive Typography ===== */

@media (max-width: 768px) {
    :root {
        --text-base: 1rem;      /* 16px on mobile */
        --text-xl: 1.25rem;
        --text-2xl: 1.5rem;
        --text-3xl: 1.75rem;
    }

    p {
        max-width: 100%;
    }
}
