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

:root {
    --ctp-crust: light-dark(#dce0e8, #11111b);
    --ctp-mantle: light-dark(#e6e9ef, #181825);
    --ctp-base: light-dark(#eff1f5, #1e1e2e);
    --ctp-surface0: light-dark(#ccd0da, #313244);
    --ctp-surface1: light-dark(#bcc0cc, #45475a);
    --ctp-subtext1: light-dark(#5c5f77, #a6adc8);
    --ctp-text: light-dark(#4c4f69, #cdd6f4);
    --ctp-red: light-dark(#d20f39, #f38ba8);
    --ctp-green: light-dark(#40a02b, #a6e3a1);
    --ctp-peach: light-dark(#fe640b, #fab387);
    --ctp-yellow: light-dark(#df8e1d, #f9e2af);
    --ctp-blue: light-dark(#1e66f5, #89b4fa);
    --ctp-mauve: light-dark(#8839ef, #cba6f7);
    --ctp-punctuation: light-dark(#5c5f77, #bac2de);


    --bg: light-dark(#fff, var(--ctp-base));
    --surface: light-dark(var(--ctp-base), var(--ctp-surface0));
    --surface-raise: var(--ctp-mantle);
    --hairline: light-dark(var(--ctp-crust), var(--ctp-surface1));
    --border: light-dark(#7c7f93, #7f849c);

    --text: var(--ctp-text);
    --muted: var(--ctp-subtext1);
    --title: light-dark(#2c2f45, #e2e8ff);
    --site-title: var(--ctp-text);

    --accent: var(--ctp-blue);
    --accent-deep: light-dark(#1046b8, #a6c8ff);
    --accent-soft: light-dark(#e7edfe, #2c3b57);
    --mauve: var(--ctp-mauve);
    --mauve-soft: light-dark(#ddccfa, #40315e);
    --mauve-ink: light-dark(#5b1ba8, #d7bbfc);

    --cover-wash: light-dark(
        color-mix(in srgb, var(--accent) 12%, transparent),
        color-mix(in srgb, var(--accent) 20%, transparent)
    );

    --code-text: var(--ctp-text);
    --code-comment: light-dark(#666c80, var(--ctp-subtext1));
    --code-punctuation: var(--ctp-punctuation);
    --code-red: var(--ctp-red);
    --code-green: light-dark(#317c21, var(--ctp-green));
    --code-peach: light-dark(#bc4601, var(--ctp-peach));
    --code-yellow: light-dark(#976014, var(--ctp-yellow));
    --code-blue: light-dark(var(--accent-deep), var(--ctp-blue));
    --code-mauve: var(--ctp-mauve);

    --radius-sm: 6px;
}

html {
    color-scheme: light dark;
    scrollbar-gutter: stable;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

body {
    font-family: 'Victor Mono', monospace;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--accent);
    text-decoration: none;
    background-image: linear-gradient(currentColor, currentColor);
    background-repeat: no-repeat;
    background-position: 0 100%;
    background-size: 0 1.5px;
    transition: background-size .2s ease, color .15s ease;
}

a:hover {
    background-size: 100% 1.5px;
}

.page-content a:not(:has(img)):not(.tag-link),
.article-excerpt a:not(:has(img)):not(.tag-link),
.footer-content a:not(:has(img)):not(.tag-link) {
    background-size: 100% 1px;
}

.page-content a:not(:has(img)):not(.tag-link):hover,
.article-excerpt a:not(:has(img)):not(.tag-link):hover,
.footer-content a:not(:has(img)):not(.tag-link):hover {
    background-size: 100% 2px;
}

blockquote a {
    color: var(--accent-deep);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: 0.5rem;
    top: -100%;
    z-index: 1100;
    padding: 0.5rem 1rem;
    background: var(--bg);
    color: var(--accent-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background-image: none;
}

.skip-link:focus {
    top: 0.5rem;
}

header {
    padding: 1rem;
    background: var(--surface-raise);
    border-bottom: 1px solid var(--border);
}

header nav {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.site-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--site-title);
    background-image: none;
}

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

.nav-links {
    display: flex;
    gap: 1rem;
}

.theme-toggle {
    font: inherit;
    font-size: 0.875rem;
    color: var(--accent-deep);
    background: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.1rem 0.7rem;
    margin-top: 0.75rem;
    cursor: pointer;
    transition: background-color .15s ease;
}

.theme-toggle:hover {
    background-color: var(--accent-soft);
}

.theme-toggle:focus-visible {
    border-radius: 999px;
}

.nav-links a,
footer a {
    color: var(--accent-deep);
}

main {
    flex: 1;
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
    width: 100%;
}

h1, h2, h3, h4, h5, h6 {
    line-height: 1.3;
    margin: 1.5rem 0 0.75rem;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

h1:first-child,
h2:first-child,
h3:first-child {
    margin-top: 0;
}

p {
    margin: 1rem 0;
}

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

.article-list {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

.article-preview {
    position: relative;
    border-bottom: 1px solid var(--hairline);
    padding-bottom: 1.75rem;
}

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

.article-preview h2 {
    margin-top: 0;
    margin-bottom: 0.25rem;
}

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

.article-preview h2 a::after {
    content: "";
    position: absolute;
    inset: 0;
}

.article-excerpt a {
    position: relative;
}

.article-preview time {
    display: block;
    color: var(--muted);
    font-size: 0.875rem;
    font-style: italic;
    margin-bottom: 0.5rem;
}

.article-preview p {
    color: var(--muted);
    margin-bottom: 0;
}

.article-list-item {
    padding: 0.35rem 0;
    margin: 0;
}

.article-list-item time {
    color: var(--muted);
    font-size: 0.875rem;
}

.page-title {
    color: var(--title);
}

.page-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--hairline);
}

.tag-link {
    color: var(--accent-deep);
    font-size: 0.8125rem;
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    background-color: var(--accent-soft);
    background-image: linear-gradient(var(--mauve-soft), var(--mauve-soft));
    background-repeat: no-repeat;
    background-position: 0 50%;
    background-size: 0 100%;
    transition: background-size .25s ease, color .15s ease;
}

.tag-link:hover {
    background-size: 100% 100%;
    color: var(--mauve-ink);
}

.tag-link:focus-visible {
    border-radius: 999px;
}

.page-date {
    display: block;
    color: var(--muted);
    font-size: 0.875rem;
    font-style: italic;
    margin-bottom: 1rem;
}

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.pagination span {
    color: var(--muted);
}

footer {
    padding: 2rem 1rem;
    background: var(--surface-raise);
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--muted);
    font-size: 0.875rem;
}

.footer-content {
    max-width: 800px;
    margin: 0 auto;
}

.footer-content p {
    margin: 0.25rem 0;
}

pre {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
    border-radius: var(--radius-sm);
}

code {
    font-family: Consolas, Monaco, "Courier New", monospace;
    font-size: 0.9em;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.075rem 0.3rem;
    border-radius: 4px;
}

pre code {
    background: none;
    border: none;
    padding: 0;
}

blockquote {
    border-left: 4px solid var(--accent);
    background: var(--surface);
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    color: var(--muted);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

blockquote :first-child { margin-top: 0; }
blockquote :last-child { margin-bottom: 0; }

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

li {
    margin: 0.25rem 0;
}

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

img {
    max-width: 100%;
    height: auto;
}

.mermaid {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin: 1rem 0;
    text-align: center;
    overflow-x: auto;
}

.mermaid svg {
    max-width: 100%;
    height: auto;
}

span.you-are-here {
    font-size: 0.75rem;
    color: var(--accent-deep);
    background: var(--accent-soft);
    padding: 0.05rem 0.5rem;
    border-radius: 999px;
    margin-left: 0.5rem;
    font-weight: bold;
}

code[class*="language-"],
pre[class*="language-"] {
    color: var(--code-text);
    background: var(--surface);
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: var(--code-comment);
}
.token.punctuation {
    color: var(--code-punctuation);
}
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol {
    color: var(--code-red);
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin {
    color: var(--code-green);
}
.token.operator,
.token.entity,
.token.url,
.language-css .token.string {
    color: var(--code-peach);
}
.token.atrule,
.token.attr-value,
.token.keyword {
    color: var(--code-blue);
}
.token.function,
.token.class-name {
    color: var(--code-mauve);
}
.token.regex,
.token.important,
.token.variable {
    color: var(--code-yellow);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }

    a:hover {
        background-size: 100% 1.5px;
    }
}

@media (max-width: 600px) {
    header nav {
        flex-direction: column;
        text-align: center;
    }

    .nav-links {
        flex-wrap: wrap;
        justify-content: center;
    }

    main {
        padding: 1rem;
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
}

.page-cover {
    display: block;
    width: 100%;
    aspect-ratio: 2.76 / 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
}

.preview-cover {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    pointer-events: none;
}

.preview-cover img {
    display: block;
    width: 100%;
    aspect-ratio: 2.76 / 1;
    object-fit: cover;
    transition: transform .55s cubic-bezier(.16, 1, .3, 1);
}

@media (hover: hover) {
    .preview-cover::after {
        content: "";
        position: absolute;
        inset: 0;
        background-image: linear-gradient(var(--cover-wash), var(--cover-wash));
        background-repeat: no-repeat;
        background-position: right;
        background-size: 100% 100%;
        transition: background-size .35s ease;
    }

    .article-preview:hover .preview-cover::after,
    .article-preview:has(a:focus-visible) .preview-cover::after {
        background-size: 0 100%;
    }
}

.article-preview:hover .preview-cover img,
.article-preview:has(a:focus-visible) .preview-cover img {
    transform: scale(1.08);
}

p:has(> a > img) {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

p:has(> a > img) img {
    display: block;
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 4px;
    transition: opacity 0.2s;
}

p:has(> a > img) a:hover img {
    opacity: 0.8;
}

p:has(> a:only-child > img) {
    display: block;
}

p:has(> a:only-child > img) img {
    height: auto;
}

p:has(> a > img) > a[data-alt] {
    position: relative;
    display: block;
}

p:has(> a > img) > a[data-alt]::after {
    content: attr(data-alt);
    position: absolute;
    right: 0.5rem;
    bottom: 0.5rem;
    max-width: calc(100% - 3rem);
    background: var(--bg);
    color: var(--text);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    line-height: 1.3;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    text-align: right;
}

.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    cursor: pointer;
}

.lightbox-overlay.active {
    display: flex;
}

.lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 90vh;
    display: block;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.lightbox-btn {
    position: absolute;
    background: rgba(255, 255, 255, 0.35);
    color: white;
    border: none;
    padding: 1rem;
    cursor: pointer;
    font-size: 1.5rem;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    user-select: none;
}

.lightbox-btn:hover {
    background: rgba(255, 255, 255, 0.55);
}

.lightbox-btn.close { top: -60px; right: 0; }
.lightbox-btn.prev { left: -70px; top: 50%; transform: translateY(-50%); }
.lightbox-btn.next { right: -70px; top: 50%; transform: translateY(-50%); }

@media (max-width: 800px) {
    .lightbox-btn.prev { left: 10px; }
    .lightbox-btn.next { right: 10px; }
}

.lightbox-caption {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--bg);
    color: var(--text);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.9rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    z-index: 1010;
    pointer-events: none;
    display: none;
}

.lightbox-viewer {
    display: none;
    width: 80vw;
    height: 70vh;
    max-width: 1200px;
    max-height: 80vh;
    background: #000;
}

.lightbox-content:has(.lightbox-viewer) {
    width: auto;
    height: auto;
}

.youtube-embed {
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    margin: 1.5rem 0;
}
