:root {
    --accent-color: #E95420;
    --background: #f8fafc;
    --border-color: #e2e8f0;
    --font-family-mono: monospace;
    --font-family-sans: Ubuntu, sans-serif;
    --primary-color: #2563eb;
    --primary-text-color-when-primary-color-is-bg: #ffffff;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --surface: #fbfbfb;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    scroll-behavior: smooth;
}

body {
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
    background-color: var(--background);
    color: var(--text-primary);
    font-family: var(--font-family-sans), sans-serif;
    line-height: 1.7;
    text-rendering: optimizeLegibility;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: 700;
    line-height: 1.25;
    margin-bottom: 1rem;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; margin-top: 3rem; }
h3 { font-size: 1.5rem; margin-top: 2rem; }
h4 { font-size: 1.25rem; margin-top: 1.5rem; }

p {
    color: var(--text-primary);
    margin-bottom: 1.5rem;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* Layout */
.container {
    margin: 0 auto;
    max-width: 800px;
    padding: 0 1.5rem;
}

.main-content {
    display: grid;
    gap: 2rem;
    grid-template-columns: 1fr;
}

/* --- Fallback Styles for Web Components --- */

/* Styles for article-header before it's defined by JavaScript */
article-header:not(:defined) {
    border-bottom: 1px solid var(--border-color);
    display: block;
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    text-align: center;
}

/* Style the slotted h1 */
article-header:not(:defined) > [slot="title"] {
    color: var(--text-primary);
    font-size: 2.5rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 1rem;
}

/* Style the slotted subtitle */
article-header:not(:defined) > [slot="subtitle"] {
    color: var(--text-secondary);
    font-size: 1.25rem;
    font-weight: 400;
    margin-bottom: 2rem;
}

/* Style the meta-data spans */
article-header:not(:defined) > [slot="author"],
article-header:not(:defined) > [slot="date"] {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0 0.5rem;
}

/* Hide the initials in the fallback since we can't show the avatar */
article-header:not(:defined) > [slot="author-initials"] {
    display: none;
}


/* Content sections */
.content-section {
    margin-bottom: 3rem;
}

.content-section:last-child {
    margin-bottom: 0;
}

/* Code blocks - fallback styles until syntax highlighter loads */
pre[class*="language-"],
pre code {
    -webkit-overflow-scrolling: touch;
    background: #1e293b !important; /* Dark background as fallback */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    color: #e2e8f0 !important; /* Light text as fallback */
    font-family: var(--font-family-mono), serif;
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0;
    overflow-x: auto;
    padding: 1rem;
    scrollbar-color: #64748b #1e293b;
    scrollbar-width: thin;
    transition: all 0.3s ease; /* Smooth transition when Prism loads */
}

/* Custom scrollbar for webkit browsers */
pre[class*="language-"]::-webkit-scrollbar {
    height: 8px;
}

pre[class*="language-"]::-webkit-scrollbar-track {
    background: #1e293b;
}

pre[class*="language-"]::-webkit-scrollbar-thumb {
    background-color: #64748b;
    border-radius: 4px;
}

pre[class*="language-"]::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}

/* When Prism.js loads, it will override these styles gracefully */
.prism-loaded pre[class*="language-"] {
    transition: none; /* Remove transition after Prism loads */
}

code[class*="language-"],
pre code {
    font-family: var(--font-family-mono), serif;
    font-size: 0.875rem;
}

/* Enhanced fallback for better readability */
pre code {
    background: transparent !important;
    border: none !important;
    color: inherit !important;
    display: block;
    padding: 0 !important; /* Reset padding since pre handles it */
}

:not(pre) > code {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--primary-color);
    font-family: var(--font-family-mono), monospace;
    font-size: 0.875rem;
    padding: 0.25rem 0.375rem;
}

/* Lists */
ul, ol {
    margin-bottom: 1.5rem;
    margin-left: 2rem;
}

li {
    margin-bottom: 0.5rem;
}

/* Blockquotes */
blockquote {
    background: var(--surface);
    border-left: 4px solid var(--primary-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-style: italic;
    margin: 2rem 0;
    padding: 1.5rem;
}

/* Responsive design */
/* Tablet styles */
@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
        max-width: 100vw;
    }

    .main-content {
        gap: 1.5rem;
    }

    h1 {
        font-size: 2rem;
        line-height: 1.2;
        margin-bottom: 0.75rem;
    }
    h2 {
        font-size: 1.75rem;
        line-height: 1.3;
        margin-top: 2.5rem;
    }
    h3 {
        font-size: 1.375rem;
        line-height: 1.3;
        margin-top: 1.75rem;
    }
    h4 {
        font-size: 1.125rem;
        margin-top: 1.25rem;
    }

    .content-section {
        margin-bottom: 2rem;
    }

    /* Better spacing for lists on tablet */
    ul, ol {
        margin-bottom: 1.25rem;
        margin-left: 1.5rem;
    }

    blockquote {
        margin: 1.5rem 0;
        padding: 1.25rem;
    }
}

/* Mobile phone styles */
@media (max-width: 480px) {
    .container {
        box-sizing: border-box;
        max-width: 100vw;
        padding: 0 0.75rem;
    }

    /* Mobile typography - optimized for readability */
    body {
        font-size: 16px; /* Ensure minimum readable size */
        line-height: 1.6;
    }

    h1 {
        font-size: 1.75rem;
        line-height: 1.2;
        margin-bottom: 0.5rem;
    }
    h2 {
        font-size: 1.5rem;
        line-height: 1.25;
        margin-bottom: 0.75rem;
        margin-top: 2rem;
    }
    h3 {
        font-size: 1.25rem;
        line-height: 1.3;
        margin-bottom: 0.5rem;
        margin-top: 1.5rem;
    }
    h4 {
        font-size: 1.125rem;
        margin-bottom: 0.5rem;
        margin-top: 1.25rem;
    }

    /* Improved paragraph spacing for mobile */
    p {
        margin-bottom: 1.25rem;
    }

    .content-section {
        margin-bottom: 1.5rem;
    }

    /* Mobile-optimized code blocks */
    pre[class*="language-"] {
        -webkit-overflow-scrolling: touch;
        border-left: none;
        border-radius: 0;
        border-right: none;
        font-size: 0.875rem;
        line-height: 1.5;
        margin: 1rem 0;
        overflow-x: auto;
        padding: 1rem 0.75rem;
        position: relative;
        white-space: pre;
        word-wrap: normal;
        scroll-behavior: smooth;
        box-sizing: border-box;
        width: 100%;
        max-width: calc(100vw - 0px);
    }

    /* Improved mobile code block scroll hint */
    pre[class*="language-"]::after {
        background: linear-gradient(90deg, transparent 0%, rgba(30, 41, 59, 0.9) 20%, rgba(30, 41, 59, 0.9) 80%, transparent 100%);
        border-radius: 4px;
        color: #94a3b8;
        content: "← scroll to see more →";
        font-family: var(--font-family-sans), sans-serif;
        font-size: 0.6875rem;
        opacity: 0.8;
        padding: 0.25rem 0.5rem;
        pointer-events: none;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
        z-index: 1;
        backdrop-filter: blur(2px);
    }

    /* Hide scroll hint when code doesn't overflow */
    pre[class*="language-"]:not([data-overflowing])::after {
        display: none;
    }

    /* Add JavaScript to detect overflow and show/hide scroll hint */
    pre[class*="language-"] {
        /* This will be handled by JavaScript */
    }

    /* Inline code optimization for mobile */
    :not(pre) > code {
        font-size: 0.8125rem;
        padding: 0.1875rem 0.3125rem;
        word-break: break-word;
    }

    /* Mobile list styling */
    ul, ol {
        margin-bottom: 1rem;
        margin-left: 1.25rem;
        padding-left: 0;
    }

    li {
        line-height: 1.5;
        margin-bottom: 0.375rem;
    }

    /* Mobile blockquote */
    blockquote {
        border-radius: 0;
        font-size: 1rem;
        line-height: 1.6;
        margin: 1.25rem 0;
        padding: 1.25rem;
        box-sizing: border-box;
        position: relative;
        width: 100%;
        max-width: calc(100vw - 0px);
    }

    /* Touch-friendly interactive elements */
    a {
        -webkit-tap-highlight-color: rgba(37, 99, 235, 0.2);
        align-items: center;
        display: inline-flex;
        margin: 0;
        min-height: 44px; /* Apple's recommended touch target size */
        padding: 0.25rem 0;
        tap-highlight-color: rgba(37, 99, 235, 0.2);
        word-break: break-word;
    }

    /* Better mobile table handling */
    table {
        border-collapse: collapse;
        margin: 1rem 0;
        width: 100%;
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    table th,
    table td {
        border: 1px solid var(--border-color);
        padding: 0.5rem;
        text-align: left;
        font-size: 0.8125rem;
        line-height: 1.4;
    }

    table th {
        background-color: var(--surface);
        font-weight: 600;
    }

    /* Touch-friendly buttons and interactive elements */
    button,
    input[type="button"],
    input[type="submit"],
    .button,
    .btn {
        -webkit-tap-highlight-color: rgba(37, 99, 235, 0.2);
        min-height: 44px;
        min-width: 44px;
        padding: 0.75rem 1rem;
        tap-highlight-color: rgba(37, 99, 235, 0.2);
    }

    /* Improved touch scrolling for all scrollable elements */
    * {
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent zoom on input focus (iOS) */
    input, textarea, select {
        font-size: 16px;
    }
}

/* Extra small mobile phones */
@media (max-width: 360px) {
    .container {
        max-width: 100vw;
        padding: 0 0.5rem;
    }

    h1 { font-size: 1.625rem; }
    h2 { font-size: 1.375rem; }
    h3 { font-size: 1.125rem; }

    pre[class*="language-"] {
        font-size: 0.8125rem;
        margin: 0;
        padding: 1rem 0.5rem;
        width: 100%;
    }

    blockquote {
        margin: 1rem 0;
        padding: 1rem;
        width: 100%;
    }

    /* Extra small mobile adjustments */
    a {
        margin: 0;
        padding: 0.1875rem 0;
    }
}

/* Mobile-first performance optimizations */
@media (max-width: 768px) {
    /* Reduce motion for users who prefer it */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }

    /* Improve focus visibility for touch users */
    :focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }

    /* Better selection highlighting for mobile */
    ::selection {
        background-color: var(--primary-color);
        color: white;
    }

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

/* Print styles */
@media print {
    pre[class*="language-"] {
        break-inside: avoid;
    }
}