/*
  Mobile-first, accessible, and themeable design system.
  Light is default; respects prefers-color-scheme with an optional user override via [data-theme].
*/

:root {
    color-scheme: light dark;
    /* Typography */
    --font-sans: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --lh-base: 1.6;
    --radius-s: 0.375rem;
    --radius-m: 0.5rem;
    --container-max: 72rem;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-12: 3rem;

    /* Color (light) */
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #0f172a;
    --text-muted: #475569;
    --accent: #2563eb;
    --border: #e2e8f0;
    --code-surface: #f6f8fa;
    /* subtle light */
    --code-fg: #1f2328;
    /* readable fg */
    --code-border: #d0d7de;
    --code-accent: var(--accent);
}

/* Respect system colors if no user override */
@media (prefers-color-scheme: light) {

    :root:not([data-theme-mode]),
    :root[data-theme-mode="system"] {
        color-scheme: light;
    }
}

@media (prefers-color-scheme: dark) {

    :root:not([data-theme-mode]),
    :root[data-theme-mode="system"] {
        color-scheme: dark;
    }
}

/* Modern base reset for evergreen browsers */
*,
*::before,
*::after {
    box-sizing: border-box;
}

:where(body, h1, h2, h3, h4, p, figure, blockquote, dl, dd) {
    margin: 0;
}

img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
}

input,
button,
textarea,
select {
    font: inherit;
    color: inherit;
}

a {
    text-decoration-skip-ink: auto;
}

@media (prefers-color-scheme: dark) {
    :root {
        --surface: #0f172a;
        --surface-muted: #0b1220;
        --text: #e5e7eb;
        --text-muted: #94a3b8;
        --accent: #60a5fa;
        --border: #334155;
        --code-surface: #0d1117;
        /* subtle dark */
        --code-fg: #c9d1d9;
        --code-border: #30363d;
        --code-accent: var(--accent);
    }
}

/* User overrides via [data-theme] */
html[data-theme="light"] {
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #0f172a;
    --text-muted: #475569;
    --accent: #2563eb;
    --border: #e2e8f0;
    --code-surface: #f6f8fa;
    --code-fg: #1f2328;
    --code-border: #d0d7de;
    --code-accent: var(--accent);
}

html[data-theme="dark"] {
    --surface: #0f172a;
    --surface-muted: #0b1220;
    --text: #e5e7eb;
    --text-muted: #94a3b8;
    --accent: #60a5fa;
    --border: #334155;
    --code-surface: #0d1117;
    --code-fg: #c9d1d9;
    --code-border: #30363d;
    --code-accent: var(--accent);
}

/* Subtle, theme-adaptive code surface and accent when supported */
@supports (background: color-mix(in oklab, white, black)) {
    :root {
        --code-surface: color-mix(in oklab, var(--surface) 88%, var(--surface-muted));
        --code-accent: color-mix(in oklab, var(--accent) 72%, var(--code-surface));
    }

    @media (prefers-color-scheme: dark) {
        :root {
            --code-surface: color-mix(in oklab, var(--surface) 80%, var(--surface-muted));
            --code-accent: color-mix(in oklab, var(--accent) 78%, var(--code-surface));
        }
    }

    html[data-theme="light"] {
        --code-surface: color-mix(in oklab, var(--surface) 88%, var(--surface-muted));
        --code-accent: color-mix(in oklab, var(--accent) 72%, var(--code-surface));
    }

    html[data-theme="dark"] {
        --code-surface: color-mix(in oklab, var(--surface) 80%, var(--surface-muted));
        --code-accent: color-mix(in oklab, var(--accent) 78%, var(--code-surface));
    }
}

/* Fluid type scales */
h1 {
    font-size: clamp(1.875rem, 1.2rem + 1.5vw, 2.75rem);
    line-height: 1.2;
}

h2 {
    font-size: clamp(1.25rem, 1rem + 0.8vw, 1.75rem);
    line-height: 1.3;
    margin: 0 0 var(--space-2);
}

h3 {
    font-size: clamp(1.125rem, 0.9rem + 0.6vw, 1.5rem);
    line-height: 1.35;
}

html {
    font-family: var(--font-sans);
    font-size: 16px;
    text-rendering: optimizeLegibility;
    -webkit-text-size-adjust: 100%;
    font-kerning: normal;
}

@media (min-width: 720px) {
    html {
        font-size: 18px;
    }
}

body {
    margin: 0;
    background: var(--surface);
    color: var(--text);
    line-height: var(--lh-base);
    font-weight: 400;
    font-synthesis: none;
    /* Prevent FOUT/CLS from font loading; system fonts are default
       and webfonts only enhance when ready. */
}

/* Links */
a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 0.2em;
    text-decoration-thickness: 1px;
}

a:hover,
a:focus-visible {
    text-decoration-thickness: 2px;
}

/* Layout */
.container {
    max-width: var(--container-max);
    margin-inline: auto;
    padding: var(--space-4) var(--space-6);
}

.topbar {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    min-height: 64px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.site-title {
    margin: 0;
    font-weight: 600;
}

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

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

.site-menu ul {
    list-style: none;
    display: flex;
    gap: var(--space-4);
    padding: 0;
    margin: 0;
}

.site-menu a {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}

.site-menu a:hover,
.site-menu a:focus-visible {
    text-decoration: underline;
    text-underline-offset: 6px;
    text-decoration-thickness: 2px;
}

.theme-toggle {
    margin-left: auto;
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.theme-toggle svg {
    width: 1.1rem;
    height: 1.1rem;
    display: none;
    fill: currentColor;
}

.theme-toggle[data-state="system"] svg[data-icon="system"] {
    display: block;
}

.theme-toggle[data-state="light"] svg[data-icon="light"] {
    display: block;
}

.theme-toggle[data-state="dark"] svg[data-icon="dark"] {
    display: block;
}

/* Theme menu popover */
.theme-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: var(--space-2);
    min-width: 12rem;
    z-index: 1000;
}

.theme-menu [role="menuitemradio"] {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    appearance: none;
    background: transparent;
    border: 0;
    color: inherit;
    text-align: left;
    padding: var(--space-3);
    border-radius: var(--radius-s);
    cursor: pointer;
    font: inherit;
}

.theme-menu [role="menuitemradio"]:hover,
.theme-menu [role="menuitemradio"]:focus-visible {
    background: color-mix(in oklab, var(--surface-muted) 70%, var(--surface));
}

.theme-menu [role="menuitemradio"][aria-checked="true"] {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.theme-menu .option-icon {
    width: 1rem;
    height: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-menu .check {
    margin-left: auto;
    color: var(--accent);
    opacity: 0;
}

.theme-menu [role="menuitemradio"][aria-checked="true"] .check {
    opacity: 1;
}

.hero {
    padding-block: var(--space-12) var(--space-8);
}

.hero .eyebrow {
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.85rem;
    margin: 0 0 var(--space-2);
}

.hero .lead {
    font-size: 1.125rem;
    color: var(--text-muted);
    max-width: 65ch;
}

.button {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-s);
    font-weight: 600;
}

.button:hover,
.button:focus-visible {
    opacity: 0.95;
}

/* Article list */
.article-list {
    margin-top: var(--space-8);
}

.article-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-6);
    list-style: none;
    padding: 0;
}

.article-list-grid li {
    margin: 0;
}

.article-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    background: color-mix(in oklab, var(--surface) 96%, var(--surface-muted));
    transition: border-color 120ms ease-in-out, transform 120ms ease-in-out;
}

.article-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.article-card h2 {
    margin: 0;
}

.article-card h2 a {
    color: var(--text);
    text-decoration: none;
}

.article-card h2 a:hover,
.article-card h2 a:focus-visible {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 4px;
}

.article-card p {
    margin: 0;
    color: var(--text-muted);
}

.date {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.95rem;
    margin: 0;
}

/* Prose */
.prose,
.text-content {
    max-width: 70ch;
    margin-inline: auto;
    padding-block: var(--space-8);
}

.prose p,
.text-content p {
    margin: 0 0 var(--space-3);
    font-size: 1.05rem;
    line-height: 1.7;
    font-weight: 400;
}

.prose a,
.text-content a {
    font-weight: 500;
}

.prose ul,
.prose ol {
    padding-left: 1.1rem;
}

/* Code blocks */
pre {
    position: relative;
    border: 1px solid var(--code-border);
    border-radius: var(--radius-m);
    overflow: auto;
    padding: calc(var(--space-4) + 0.5rem) var(--space-4) var(--space-4);
    /* extra top padding for copy button / language label */
    background-color: var(--code-surface);
    color: var(--code-fg);
    margin-block: var(--space-6);
    border-left-width: 4px;
    border-left-color: var(--code-accent);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.08);
    tab-size: 2;
    -moz-tab-size: 2;
}

.shiki {
    position: relative;
    padding: calc(var(--space-4) + 0.5rem) var(--space-4) var(--space-4);
    background-color: var(--code-surface) !important;
    /* Let Shiki keep token colors; only adjust container aesthetics */
    font-size: clamp(0.875rem, 0.84rem + 0.24vw, 0.98rem);
}

.line {
    line-height: 1.55;
}

code {
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

/* Inline code (not inside pre) */
:not(pre)>code {
    background: var(--code-surface);
    color: var(--code-fg);
    border: 1px solid var(--code-border);
    border-radius: var(--radius-s);
    padding: 0.1em 0.35em;
}

/* Keyboard input styling */
kbd {
    font-family: var(--font-mono);
    font-size: 0.85em;
    border: 1px solid var(--code-border);
    border-bottom-width: 2px;
    border-radius: 0.3rem;
    padding: 0.1em 0.45em;
    background: var(--code-surface);
}

pre[data-shiki-pending] code {
    visibility: hidden;
}

/* Optional language label injected via data attribute */
.shiki[data-lang]::before {
    content: attr(data-lang);
    position: absolute;
    top: 0.35rem;
    left: 0.6rem;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Compact single-line code blocks */
.shiki[data-single-line="true"],
pre[data-lines="1"] {
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
    padding-left: var(--space-3);
    padding-right: calc(var(--space-3) + 2.25em);
    margin-block: var(--space-3);
}

/* Hide language label on single-line for brevity */
.shiki[data-single-line="true"][data-lang]::before {
    display: none;
}

/* Improve selection contrast inside code blocks */
.shiki ::selection,
pre ::selection {
    background: color-mix(in oklab, var(--accent) 24%, transparent);
}

/* Utilities */
.sr-only,
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.skip-link {
    position: fixed;
    left: 50%;
    top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
    transform: translate(-50%, -200%);
    background: var(--surface);
    color: var(--text);
    padding: 0.55rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-s);
    z-index: 10000;
    transition: transform 0.2s ease-in-out;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    width: max-content;
}

.skip-link:focus,
.skip-link:focus-visible {
    transform: translate(-50%, 0);
}

.socials-list {
    list-style: circle;
    padding-left: 1.25rem;
}

.socials-list li {
    padding: 0.35em 0;
}

/* footer removed */

/* Attribute classes */
.code_clippy {
    position: absolute;
    top: 0;
    right: 0;
    height: 2.25em;
    width: 2.25em;
    padding: 0.5em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0.75;
}

.code_clippy:hover,
.code_clippy:focus-visible {
    opacity: 1;
    color: var(--accent);
}

.code_clippy svg {
    height: 100%;
    width: 100%;
    fill: currentColor;
    transition: color 0.25s ease-in-out, fill 0.25s ease-in-out;
}

svg.icon_action_success {
    fill: #22c55e;
}

/* Focus */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}