:root {
    /* Typography */
    --font-sans:
        system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue",
        Arial, sans-serif;
    --font-mono:
        "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas,
        "Courier New", monospace;

    /* Color System - Light Theme */
    --bg: #ffffff;
    --bg-alt: #f8faf9;
    --bg-subtle: #f1f5f3;
    --fg: #1d1f21;
    --fg-muted: #5c6268;
    --fg-subtle: #8a9199;
    --border: #e2e6e8;
    --border-strong: #c9cfd2;
    --accent: #0a6d3d;
    --accent-hover: #0d7e47;
    --accent-subtle: #e8f5f0;
    --code-bg: #f5f7f8;
    --code-border: #e1e4e6;
    --inline-code-bg: #eef2f3;

    /* Semantic Colors */
    --danger: #b3261e;
    --danger-bg: #fdeaea;
    --success: #0d7e47;
    --success-bg: #e8f5f0;
    --info: #155fa0;
    --info-bg: #e8f2fd;
    --warning: #9d6b00;
    --warning-bg: #fff8e1;

    /* Spacing & Layout */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Border Radius */
    --radius-xs: 2px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);

    /* Focus & Interaction */
    --focus-ring: 2px solid #1d7fd4;
    --focus-offset: 2px;

    /* Layout Constants */
    --content-max: 65ch;
    --content-wide: 80ch;
    --line-height-tight: 1.25;
    --line-height-normal: 1.6;
    --line-height-relaxed: 1.8;

    /* Animation */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;
    --transition-slow: 0.3s ease;

    color-scheme: light;
}

/* Dark Theme */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1117;
        --bg-alt: #161b22;
        --bg-subtle: #21262d;
        --fg: #e6edf3;
        --fg-muted: #9ca3af;
        --fg-subtle: #6e7681;
        --border: #30363d;
        --border-strong: #3a454a;
        --accent: #2ea043;
        --accent-hover: #3fb950;
        --accent-subtle: #0d2818;
        --code-bg: #161b22;
        --code-border: #30363d;
        --inline-code-bg: #262c36;

        /* Semantic Colors - Dark */
        --danger: #f85149;
        --danger-bg: #2d1117;
        --success: #3fb950;
        --success-bg: #0d2818;
        --info: #58a6ff;
        --info-bg: #0c1929;
        --warning: #d29922;
        --warning-bg: #2d2408;

        /* Adjusted Shadows */
        --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3);
        --shadow-lg:
            0 10px 15px rgba(0, 0, 0, 0.4), 0 4px 6px rgba(0, 0, 0, 0.3);

        color-scheme: dark;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --border: #000;
        --border-strong: #000;
        --fg-muted: var(--fg);
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    :root {
        --transition-fast: 0s;
        --transition-normal: 0s;
        --transition-slow: 0s;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Base Styles */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--fg);
    line-height: var(--line-height-normal);
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    max-width: var(--content-max);
    margin-inline: auto;
    padding: 0 clamp(1rem, 3vw, 1.5rem) var(--space-2xl);
    hanging-punctuation: first last;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    word-wrap: break-word;
    hyphens: auto;
}

/* Skip Link for Accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--accent);
    color: white;
    padding: var(--space-sm) var(--space-md);
    text-decoration: none;
    border-radius: var(--radius-sm);
    z-index: 1000;
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: 6px;
}

/* Header */
/* header.page-header wrapper removed (metadata list is now a direct child of body) */

/* Links */
a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: transparent;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
    transition: all var(--transition-fast);
    border-radius: var(--radius-xs);
}

a:hover {
    color: var(--accent-hover);
    text-decoration-color: currentColor;
}

a:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
    text-decoration-color: currentColor;
}

/* External link indicator */
a[href^="http"]:not([href*="localhost"]):not([href*="127.0.0.1"])::after {
    content: "↗";
    font-size: 0.8em;
    margin-left: 0.2em;
    opacity: 0.7;
}

/* Metadata List */
ul.metadata {
    list-style: none;
    padding: 0;
    margin: var(--space-lg) 0 var(--space-xl);
    display: grid;
    gap: var(--space-sm) var(--space-md);
    grid-template-columns: minmax(10ch, 15ch) 1fr;
    background: var(--bg-alt);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

ul.metadata > li {
    display: contents;
}

ul.metadata > li > strong {
    font-weight: 600;
    color: var(--fg-muted);
    text-align: right;
    padding-right: var(--space-sm);
    line-height: var(--line-height-tight);
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

ul.metadata > li > strong + * {
    line-height: var(--line-height-tight);
}

ul.metadata a {
    word-break: break-word;
    hyphens: auto;
}

@media (max-width: 640px) {
    ul.metadata {
        grid-template-columns: 1fr;
        gap: var(--space-sm);
        padding: var(--space-md);
    }

    ul.metadata > li {
        display: block;
        padding: var(--space-md);
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
    }

    ul.metadata > li > strong {
        display: inline-block;
        width: auto;
        text-align: left;
        padding: 0;
        margin-right: var(--space-sm);
    }
}

/* Content Styles */
.content {
    font-size: 1rem;
    line-height: var(--line-height-normal);
}

/* Headings */
.content h1,
.content h2,
.content h3,
.content h4,
.content h5,
.content h6 {
    font-weight: 600;
    line-height: var(--line-height-tight);
    scroll-margin-top: 6rem;
    position: relative;
    color: var(--fg);
    letter-spacing: -0.025em;
}

.content h1 {
    font-size: clamp(1.75rem, 4vw + 1rem, 2.5rem);
    margin: var(--space-2xl) 0 var(--space-lg);
}

.content h1:first-child {
    margin-top: 0;
}

.content h2 {
    font-size: clamp(1.4rem, 3vw + 1rem, 2rem);
    margin: var(--space-xl) 0 var(--space-md);
}

.content h3 {
    font-size: clamp(1.2rem, 2.5vw + 1rem, 1.5rem);
    margin: var(--space-lg) 0 var(--space-sm);
}

.content h4 {
    font-size: 1.1rem;
    margin: var(--space-lg) 0 var(--space-sm);
}

.content h5,
.content h6 {
    font-size: 1rem;
    margin: var(--space-md) 0 var(--space-sm);
}

/* Paragraph and Flow Content */
.content p,
.content ul,
.content ol,
.content blockquote,
.content pre,
.content table,
.content figure {
    margin: var(--space-md) 0;
}

.content p:first-child {
    margin-top: 0;
}

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

/* Lists */
.content ul,
.content ol {
    padding-left: var(--space-lg);
}

.content li {
    margin: var(--space-xs) 0;
}

.content li::marker {
    color: var(--accent);
}

.content ul ul,
.content ol ol,
.content ul ol,
.content ol ul {
    margin: var(--space-xs) 0;
}

/* Blockquotes */
.content blockquote {
    margin: var(--space-xl) 0;
    padding: var(--space-md) var(--space-lg);
    border-left: 4px solid var(--accent);
    background: var(--bg-alt);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    font-style: italic;
    position: relative;
}

.content blockquote::before {
    content: "“";
    font-size: 4rem;
    color: var(--accent);
    position: absolute;
    top: -0.5rem;
    left: var(--space-md);
    line-height: 1;
    opacity: 0.3;
}

.content blockquote > *:first-child {
    margin-top: 0;
}

.content blockquote > *:last-child {
    margin-bottom: 0;
}

/* Code */
code,
pre {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-feature-settings:
        "liga" 1,
        "calt" 1;
}

pre {
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    padding: var(--space-lg);
    overflow: auto;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    line-height: var(--line-height-tight);
    position: relative;
    tab-size: 2;
}

pre::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

pre::-webkit-scrollbar-track {
    background: var(--code-bg);
}

pre::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-sm);
}

pre::-webkit-scrollbar-thumb:hover {
    background: var(--fg-muted);
}

code {
    background: var(--inline-code-bg);
    padding: 0.125em 0.375em;
    border-radius: var(--radius-xs);
    border: 1px solid var(--code-border);
    font-size: 0.85em;
    word-break: break-word;
}

pre code {
    background: none;
    padding: 0;
    border: 0;
    font-size: inherit;
    word-break: normal;
}

/* Tables */
.content table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.9rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.content table th,
.content table td {
    padding: var(--space-md) var(--space-sm);
    border: 1px solid var(--border);
    vertical-align: top;
    text-align: left;
}

.content table th {
    background: var(--bg-alt);
    font-weight: 600;
    color: var(--fg);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.content table tbody tr:hover {
    background: var(--bg-subtle);
}

.content table tbody tr:nth-child(even) {
    background: var(--bg-alt);
}

/* Responsive Tables */
@media (max-width: 768px) {
    .content table {
        font-size: 0.8rem;
    }

    .content table th,
    .content table td {
        padding: var(--space-sm) var(--space-xs);
    }
}

/* Horizontal Rule */
hr {
    border: 0;
    border-top: 2px solid var(--border);
    margin: var(--space-2xl) 0;
    background: linear-gradient(90deg, var(--border) 0%, transparent 100%);
    height: 1px;
}

/* Images and Media */
img,
video,
iframe {
    max-width: 100%;
    height: auto;
    /*border-radius: var(--radius-sm);*/
    /*box-shadow: var(--shadow-sm);*/
}*/

.content figure {
    margin: var(--space-xl) 0;
    text-align: center;
}

.content figcaption {
    margin-top: var(--space-sm);
    font-size: 0.9em;
    color: var(--fg-muted);
    font-style: italic;
    text-align: center;
}

/* Keyboard Input */
kbd {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    background: var(--inline-code-bg);
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--code-border);
    border-radius: var(--radius-sm);
    box-shadow:
        inset 0 -1px 0 var(--border),
        0 1px 2px rgba(0, 0, 0, 0.1);
    font-weight: 600;
    white-space: nowrap;
}

/* Focus Styles */
:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
    border-radius: var(--radius-xs);
}

/* Selection Styles */
::selection {
    background: var(--accent-subtle);
    color: var(--accent);
}

/* Utility Classes */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.text-balance {
    text-wrap: balance;
}

.text-pretty {
    text-wrap: pretty;
}

/* Wide-screen two-column layout (no-JS version)
   On viewports >= 1100px the layout becomes a 2-column grid:
   - Main article in first column (fluid)
   - Metadata (ul.metadata) in a sticky sidebar on the right
   This keeps existing markup; simply include this CSS.
*/
@media (min-width: 1100px) {
    body {
        max-width: 1200px;
        display: grid;
        grid-template-columns: minmax(0, 1fr) 320px;
        column-gap: clamp(2rem, 5vw, 3.5rem);
        align-items: start;
        min-height: 100vh;
        align-content: center;
        padding-block: var(--space-xl) var(--space-2xl);
    }

    /* Sidebar metadata panel */
    ul.metadata {
        grid-column: 2;
        margin: 0 0 var(--space-2xl);
        position: sticky;
        top: var(--space-xl);
        max-height: calc(100vh - var(--space-xl) * 2);
        overflow: auto;
        padding: var(--space-lg) var(--space-lg) var(--space-xl);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
        scrollbar-gutter: stable;
    }

    /* Ensure content occupies left column (share first row with sidebar) */
    .content {
        grid-column: 1;
        grid-row: 1; /* Prevent auto-placement from pushing content below metadata */
    }

    /* Slightly tighten label styling when in sidebar */
    ul.metadata > li > strong {
        font-size: 0.75rem;
        letter-spacing: 0.05em;
    }

    /* Scrollbar aesthetics inside the panel (WebKit) */
    ul.metadata::-webkit-scrollbar {
        width: 10px;
    }
    ul.metadata::-webkit-scrollbar-thumb {
        background: var(--border-strong);
        border-radius: var(--radius-sm);
    }
    ul.metadata::-webkit-scrollbar-thumb:hover {
        background: var(--fg-muted);
    }
}

/* Narrow-screen floating metadata navbar */
@media (max-width: 1099px) {
    ul.metadata {
        position: sticky;
        top: 0;
        z-index: 60;
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: var(--space-sm);
        padding: var(--space-sm) var(--space-md);
        margin: 0 0 var(--space-lg);
        background: var(--bg);
        border: 0;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
        box-shadow: var(--shadow-xs);
        scrollbar-width: thin;
    }
    ul.metadata > li {
        display: inline-flex;
        align-items: center;
        gap: var(--space-xs);
        background: var(--bg-alt);
        padding: var(--space-xs) var(--space-sm);
        border: 1px solid var(--border);
        border-radius: var(--radius-full);
        white-space: nowrap;
        font-size: 0.75rem;
        line-height: 1.2;
    }
    ul.metadata > li > strong {
        text-align: left;
        margin: 0;
        padding: 0;
        display: inline;
        font-size: 0.7rem;
        letter-spacing: 0.05em;
    }
    ul.metadata::-webkit-scrollbar {
        height: 8px;
    }
    ul.metadata::-webkit-scrollbar-thumb {
        background: var(--border-strong);
        border-radius: var(--radius-sm);
    }
}
/* Print Styles */
@media print {
    :root {
        --bg: #fff;
        --fg: #000;
        --border: #ccc;
        --accent: #000;
    }

    body {
        background: var(--bg);
        color: var(--fg);
        font-size: 12pt;
        line-height: 1.4;
        max-width: none;
        padding: 0;
    }

    a {
        color: var(--fg);
        text-decoration: underline;
    }

    a[href^="http"]:not([href*="localhost"])::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        word-break: break-all;
    }

    header.page-header {
        border-bottom: 2px solid var(--border);
        position: static;
        backdrop-filter: none;
    }

    ul.metadata {
        grid-template-columns: 1fr 3fr;
        background: transparent;
        border: 1px solid var(--border);
    }

    pre,
    code {
        box-shadow: none;
        border: 1px solid var(--border);
    }

    blockquote {
        break-inside: avoid;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        break-after: avoid;
    }

    table {
        break-inside: avoid;
    }
}
