:root {
    color-scheme: light;
    --bg: #ffffff;
    --bg-secondary: #f7f7f7;
    --text: #1a1a1a;
    --text-secondary: #5c5c5c;
    --text-tertiary: #888888;
    --accent: #c41230;
    --accent-hover: #a00f28;
    --border: #e0e0e0;
    --border-strong: #1a1a1a;
    --inline-code-bg: #f5f5f5;
    /* Code block colors (base16-ocean, fixed dark theme) */
    --code-bg: #2b303b;
    --code-header-bg: #343d46;
    --code-border: #3d4452;
    --code-text: #c0c5ce;
    --code-text-muted: #8fa1b3;
    --code-line-numbers: #65737e;
    --code-copied: #a3be8c;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #1e2228;
    --bg-secondary: #262b33;
    --text: #c0c5ce;
    --text-secondary: #a7adba;
    --text-tertiary: #65737e;
    --accent: #bf616a;
    --accent-hover: #d08770;
    --border: #3d4452;
    --border-strong: #dfe1e8;
    --inline-code-bg: #2b303b;  /* For inline `code` only */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Merriweather', Georgia, "Times New Roman", serif;
    font-size: 18px;
    line-height: 1.8;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Header */
header {
    padding: 2rem 0;
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.site-title {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.site-title a {
    color: var(--text);
    text-decoration: none;
    transition: color 0.15s;
}

.site-title a:hover {
    color: var(--accent);
}

.site-title a:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.site-title a:focus:not(:focus-visible) {
    outline: none;
}

nav {
    display: flex;
    gap: 2rem;
}

nav a {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s;
}

nav a:hover,
nav a:focus,
nav a[aria-current="page"] {
    color: var(--accent);
}

nav a:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

nav a:focus:not(:focus-visible) {
    outline: none;
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--text-secondary);
    transition: color 0.15s;
    display: flex;
    align-items: center;
}

.theme-toggle:hover,
.theme-toggle:focus {
    color: var(--accent);
}

.theme-toggle:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.theme-toggle:focus:not(:focus-visible) {
    outline: none;
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    transition: opacity 0.15s, transform 0.15s;
}

/* Light theme: show moon (to switch to dark) */
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

/* Dark theme: show sun (to switch to light) */
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* Main content */
main {
    padding: 3rem 0;
    min-height: calc(100vh - 200px);
}

/* Footer */
footer {
    padding: 2rem 0;
    border-top: 1px solid var(--border);
}

footer p {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.8rem;
    color: var(--text-tertiary);
    letter-spacing: 0.02em;
    margin: 0;
    line-height: 1;
}

.footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.footer-links a {
    display: flex;
    align-items: center;
    color: var(--text-tertiary);
    transition: color 0.15s;
    line-height: 1;
}

.footer-links a svg {
    display: block;
}

.footer-links a:hover,
.footer-links a:focus {
    color: var(--accent);
}

.footer-links a:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.footer-links a:focus:not(:focus-visible) {
    outline: none;
}

/* Typography */
h1 {
    font-size: clamp(1.75rem, 3vw + 0.5rem, 2.5rem);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
}

h2 {
    font-size: clamp(1.4rem, 2vw + 0.5rem, 1.75rem);
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.01em;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
}

h3 {
    font-size: clamp(1.15rem, 1.5vw + 0.25rem, 1.4rem);
    font-weight: 700;
    line-height: 1.3;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
}

h4 {
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.35;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

p {
    margin-bottom: 1rem;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s;
}

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

/* Article content */
.article-content {
    font-size: 1.15rem;
    line-height: 1.85;
}

.article-content h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.article-content h3 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-top: 2rem;
}

/* Heading anchor links */
.article-content h2,
.article-content h3,
.article-content h4,
.article-content h5,
.article-content h6 {
    position: relative;
}

.heading-anchor {
    position: absolute;
    left: -1.5em;
    top: 0;
    height: 1lh;
    width: 1.5em;
    opacity: 0;
    text-decoration: none;
    color: var(--text-tertiary);
    transition: opacity 0.15s, color 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* h2 has padding-top for border, offset the anchor */
.article-content h2 .heading-anchor {
    top: 1.5rem;
}

.heading-anchor svg {
    width: 0.7em;
    height: 0.7em;
}

.heading-anchor:hover {
    color: var(--accent);
}

.article-content h2:hover .heading-anchor,
.article-content h3:hover .heading-anchor,
.article-content h4:hover .heading-anchor,
.article-content h5:hover .heading-anchor,
.article-content h6:hover .heading-anchor,
.heading-anchor:focus {
    opacity: 1;
}

.heading-anchor:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.heading-anchor:focus:not(:focus-visible) {
    outline: none;
}

.heading-anchor-tooltip {
    position: absolute;
    left: -1.5em;
    top: -2em;
    background: var(--text);
    color: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.3em 0.6em;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.15s, transform 0.15s;
    pointer-events: none;
    z-index: 10;
}

.heading-anchor-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

.article-content > p:first-of-type {
    font-size: 1.25rem;
    line-height: 1.75;
    color: var(--text-secondary);
}

.article-content img {
    width: 100%;
    height: auto;
    margin: 2rem 0;
}

.article-content .code-block {
    position: relative;
    margin: 1.5rem 0;
    border-radius: 8px;
    overflow: hidden;
    background: var(--code-bg);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--code-header-bg);
    border-bottom: 1px solid var(--code-border);
}

.code-lang {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--code-text-muted);
}

.article-content pre {
    margin: 0;
    padding: 1rem;
    padding-left: 3.5rem;
    overflow-x: auto;
    position: relative;
    font-family: "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    background: var(--code-bg);
}

.article-content pre code {
    font: inherit;
    color: var(--code-text);
    background: transparent;
}

/* Code block scrollbar styling */
.article-content pre::-webkit-scrollbar {
    height: 8px;
}

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

.article-content pre::-webkit-scrollbar-thumb {
    background: var(--code-border);
    border-radius: 4px;
}

.article-content pre::-webkit-scrollbar-thumb:hover {
    background: var(--code-text-muted);
}

/* Firefox scrollbar */
.article-content pre {
    scrollbar-width: thin;
    scrollbar-color: var(--code-border) var(--code-bg);
}

.article-content :not(pre) > code {
    font-family: "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
    background: var(--inline-code-bg);
    padding: 0.2em 0.45em;
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--accent);
}

.line-numbers {
    position: absolute;
    left: 0;
    top: 1rem;
    width: 2.5rem;
    text-align: right;
    padding-right: 0.75rem;
    font-family: "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--code-line-numbers);
    user-select: none;
    border-right: 1px solid var(--code-border);
}

.line-numbers span {
    display: block;
}

.copy-btn {
    padding: 0.3rem 0.6rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--code-text-muted);
    background: transparent;
    border: 1px solid var(--code-border);
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.copy-btn:hover,
.copy-btn:focus {
    color: var(--code-text);
    border-color: var(--code-text-muted);
}

.copy-btn:focus {
    outline: 2px solid var(--code-text-muted);
    outline-offset: 2px;
}

.copy-btn:focus:not(:focus-visible) {
    outline: none;
}

.copy-btn.copied {
    color: var(--code-copied);
    border-color: var(--code-copied);
}

.copy-btn-status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Code blocks stay dark in both themes for consistent syntax highlighting */

.article-content ul, .article-content ol {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.article-content li {
    margin-bottom: 0.5rem;
}

.article-content blockquote {
    border-left: 3px solid var(--accent);
    margin: 1.5rem 0;
    padding: 0.5rem 0 0.5rem 1.5rem;
    font-style: italic;
    color: var(--text-secondary);
}

.article-content blockquote p {
    margin: 0;
}

.article-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.95rem;
}

.article-content th, .article-content td {
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    text-align: left;
}

.article-content th {
    font-weight: 700;
    border-bottom: 2px solid var(--border-strong);
}

/* Utility classes */
.label {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.label-accent {
    color: var(--accent);
}

.draft-badge {
    display: inline-block;
    background: var(--accent);
    color: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 0.2em 0.5em;
    border-radius: 3px;
    margin-left: 0.5rem;
    vertical-align: middle;
}

.meta {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.95rem;
    color: var(--text-tertiary);
}

.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

/* Article listings */
.article-card {
    margin-bottom: 2.5rem;
    padding-bottom: 2.5rem;
    border-bottom: 1px solid var(--border);
}

.article-card:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.article-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.75rem 0;
    line-height: 1.3;
}

.article-card h2 a {
    text-decoration: none;
    color: inherit;
}

.article-card h2 a:hover {
    color: var(--accent);
}

.article-card .description {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.article-card .description:last-child {
    margin-bottom: 0;
}

/* Page headers */
.page-header {
    margin-bottom: 3rem;
}

.page-header .label {
    margin-bottom: 1rem;
}

.page-header .subtitle {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin-top: 1rem;
    margin-bottom: 0;
}

/* Hero section (homepage) */
.hero {
    margin-bottom: 3rem;
    padding-bottom: 3rem;
    border-bottom: 1px solid var(--border);
}

.hero h1 {
    font-size: clamp(1.75rem, 4vw + 0.5rem, 2.5rem);
    font-weight: 700;
    margin-bottom: 1.25rem;
}

.hero .subtitle {
    font-size: 1.125rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 0;
}

/* Article page */
.article-back {
    margin-bottom: 2rem;
}

.article-header {
    margin-bottom: 2.5rem;
}

.article-header .label {
    margin-bottom: 1rem;
}

.article-header .meta {
    margin-top: 0;
    margin-bottom: 0;
}

.article-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.25rem;
    gap: 1rem;
}

.copy-markdown-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.7rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.copy-markdown-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.copy-markdown-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.copy-markdown-btn:focus:not(:focus-visible) {
    outline: none;
}

.copy-markdown-btn.copied {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--bg-secondary);
}

.copy-markdown-btn svg {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
}

.article-nav {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

/* Section headers */
.section-label {
    margin-bottom: 1.5rem;
}

.all-articles-link {
    margin-top: 2rem;
}

/* Horizontal rules */
hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

/* Footnotes */
.footnote-ref a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.footnote-ref a:hover {
    text-decoration: underline;
}

.footnote {
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 0.75rem 0;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

.footnote-label {
    font-weight: 600;
    color: var(--accent);
}

.footnote-backref {
    text-decoration: none;
    margin-left: 0.25rem;
}

.footnote-backref:hover {
    text-decoration: underline;
}

/* Math fallback styling */
.math {
    font-family: "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

.math-display {
    display: block;
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--inline-code-bg);
    border-radius: 4px;
    overflow-x: auto;
}

.math-display code {
    background: transparent;
    padding: 0;
}

/* Task lists */
.article-content input[type="checkbox"] {
    margin-right: 0.5rem;
    accent-color: var(--accent);
    /* Ensure disabled checkboxes still show accent color */
    opacity: 1;
}

.article-content input[type="checkbox"]:disabled {
    cursor: default;
}

.article-content li:has(input[type="checkbox"]) {
    list-style: none;
    margin-left: -1.25rem;
}

/* Definition lists */
.article-content dl {
    margin: 1.5rem 0;
}

.article-content dt {
    font-weight: 700;
    margin-top: 1rem;
}

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

.article-content dd {
    margin-left: 1.25rem;
    color: var(--text-secondary);
}

/* Audio overview */
.audio-overview {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 2rem;
}

.audio-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.audio-label svg {
    color: var(--accent);
}

.audio-overview audio {
    width: 100%;
    height: 44px;
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    .container {
        padding: 0 1rem;
    }

    nav {
        gap: 1rem;
    }

    .header-inner {
        gap: 0.75rem;
    }

    .article-meta-row {
        flex-wrap: wrap;
    }
}
