@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;700&display=swap");

:root {
    color-scheme: light;

    /* Colors */
    --bg: #ffffff;
    --paper: #ffffff;
    --text: #0d1117;
    --muted: #3b4657;
    --line: #e5e7eb;
    --line-strong: #0d1117;

    --link: #0a45d1;
    --link-hover: #0533a8;
    --link-visited: #5b2cbf;
    --focus: #0a45d1;

    --surface: #f1f5ff;
    --surface-strong: #dfe8ff;

    /* Layout */
    --frame-width: min(760px, 92vw);
    --frame-padding: clamp(0.9rem, 2vw, 1.4rem);

    /* Type */
    --font-sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;

    --measure: 68ch;                 /* comfortable line length for prose */
    --text-size: 1.0625rem;          /* 17px */
    --small-size: 0.9375rem;         /* 15px */
    --leading: 1.65;
    --leading-tight: 1.2;

    --underline-thickness: 0.12em;
    --underline-offset: 0.16em;

    /* Spacing scale */
    --space-1: 0.5rem;
    --space-2: 0.75rem;
    --space-3: 1rem;
    --space-4: 1.5rem;
    --space-5: 2rem;

    /* Lines */
    --line-thickness: 1px;
    --line-thickness-thin: calc(var(--line-thickness) / 2);
    --line-thickness-heavy: calc(var(--line-thickness) * 2);

    --radius-1: 2px;
    --radius-2: 6px;
}

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

html,
body {
    margin: 0;
    min-height: 100%;
}

html {
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--text-size);
    line-height: var(--leading);
    font-kerning: normal;
    font-variant-numeric: tabular-nums;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;

    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0.75rem, 1fr) var(--frame-width) minmax(0.75rem, 1fr);
    grid-template-rows: auto 1fr auto;
}

/* ===== Frame sections ===== */

.site-header,
.content,
.site-footer {
    grid-column: 2;
    width: 100%;
    margin: 0;
    background: var(--paper);
    padding-inline: var(--frame-padding);
    border-left: var(--line-thickness) solid var(--line);
    border-right: var(--line-thickness) solid var(--line);
}

.site-header {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-block: 1.25rem;
}

.site-header::after,
.content::after {
    content: "";
    position: absolute;
    left: 50%;
    width: 100vw;
    transform: translateX(-50%);
    border-top: var(--line-thickness) solid var(--line);
    pointer-events: none;
}

.site-header::after {
    bottom: 0;
}

.site-header::before {
    content: "";
    position: absolute;
    left: 50%;
    width: 100vw;
    transform: translateX(-50%);

    pointer-events: none;
    top: 0;
}

.content {
    position: relative;
    padding-block: var(--space-5) calc(var(--space-5) + var(--space-3));
}

.content::after {
    bottom: 0;
}

.site-footer {
    color: var(--muted);
    padding-block: var(--space-3) var(--space-4);
    font-size: var(--small-size);
}

/* ===== Header / Nav ===== */

.brand {
    color: var(--text);
    font-weight: 700;
    letter-spacing: 0.01em;
    text-decoration: none;
}

.brand:hover,
.brand:visited,
.brand:focus-visible {
    color: var(--text);
}

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

.site-nav a {
    color: var(--text);
    font-weight: 500;
    text-decoration: none;
    text-decoration-thickness: var(--underline-thickness);
    text-underline-offset: var(--underline-offset);
}

.site-nav a:visited {
    color: var(--text);
}

.site-nav a:hover,
.site-nav a:focus-visible {
    color: var(--text);
    text-decoration: underline;
}

/* ===== Typography defaults ===== */

::selection {
    background: color-mix(in srgb, var(--surface-strong) 70%, white);
    color: var(--text);
}

h1,
h2,
h3,
h4 {
    margin: 0 0 var(--space-2);
    line-height: var(--leading-tight);
    letter-spacing: -0.01em;
    text-wrap: balance;
    overflow-wrap: anywhere;
}

h1 {
    margin-bottom: var(--space-3);
    font-size: clamp(2rem, 5vw, 2.7rem);
}

h2 {
    margin-top: var(--space-5);
    font-size: clamp(1.45rem, 3.7vw, 1.95rem);
}

h3 {
    margin-top: var(--space-4);
    font-size: clamp(1.15rem, 3.2vw, 1.45rem);
}

p {
    margin: 0 0 var(--space-3);
    color: var(--text);
    hanging-punctuation: first last;
}

.lede {
    font-size: 1.125em;
    color: var(--muted);
}

small,
.text-small {
    font-size: var(--small-size);
    color: var(--muted);
}

/* Comfortable measure for prose */
.post,
.post-body,
.prose {
    max-width: var(--measure);
}

/* ===== Links & focus ===== */

a {
    color: var(--link);
    text-decoration-thickness: var(--underline-thickness);
    text-underline-offset: var(--underline-offset);
    text-decoration-skip-ink: auto;
}

a:visited {
    color: var(--link-visited);
}

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

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 3px;
}

/* ===== Inline code & blocks ===== */

code,
pre,
kbd,
samp {
    font-family: var(--font-mono);
}

code {
    background: var(--surface);
    border: var(--line-thickness-thin) solid var(--line);
    border-radius: var(--radius-1);
    padding: 0.08rem 0.28rem;
    color: #132038;
}

pre[class*="language-"] {
    margin: var(--space-4) 0 var(--space-4);
    padding: 1rem 1.05rem;
    border: var(--line-thickness) solid var(--line);
    border-radius: var(--radius-1);
    background: linear-gradient(180deg, #f8faff 0%, #eef2ff 100%);
    box-shadow: none;
    font-size: 0.92rem;
    line-height: 1.5;
    overflow: auto;
    tab-size: 4;
}

pre[class*="language-"] > code[class*="language-"] {
    background: none;
    border: 0;
    border-radius: 0;
    padding: 0;
    font-size: inherit;
    color: #122033;
}

/* Prism-ish token colors (keep if you use Prism) */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: #5a6373;
}

.token.punctuation {
    color: #1f2938;
}

.token.property,
.token.tag,
.token.constant,
.token.symbol,
.token.deleted {
    color: #b42318;
}

.token.boolean,
.token.number {
    color: #0f5ac6;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
    color: #1f6f2f;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
    color: #7e3c00;
}

.token.atrule,
.token.attr-value,
.token.keyword {
    color: #5e35b1;
}

.token.function,
.token.class-name {
    color: #0f6d85;
}

.token.regex,
.token.important,
.token.variable {
    color: #984c00;
}

.token.important,
.token.bold {
    font-weight: 700;
}

.token.italic {
    font-style: italic;
}

/* ===== Prose elements ===== */

.post :where(p, ul, ol, blockquote, pre, table, hr) {
    margin-block: 0 var(--space-3);
}

.post ul,
.post ol {
    margin: 0 0 var(--space-3) 1.25rem;
    padding: 0;
}

.post li {
    margin: 0.35rem 0;
    color: var(--text);
}

.post hr {
    border: 0;
    border-top: var(--line-thickness) solid var(--line);
    margin: var(--space-5) 0;
}

.post blockquote {
    margin: var(--space-4) 0;
    padding: 0.85rem 1rem;
    border-left: 4px solid var(--line-strong);
    background: #f2f6ff;
    color: #1f2e43;
    border-radius: 0 var(--radius-1) var(--radius-1) 0;
}

/* Horizontal scroll wrapper for tables */
.post .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: var(--space-4) 0;
}

/* Optional: subtle hint that it can scroll */
.post .table-wrap:focus {
    outline: 2px solid var(--line);
    outline-offset: 2px;
}

/* Table styling */
.post table.post-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.98em;

    /* Important for horizontal scrolling:
       allow table to be wider than the container when needed */
    min-width: max-content;
}

.post table.post-table th,
.post table.post-table td {
    border: var(--line-thickness-thin) solid var(--line);
    padding: 0.5rem 0.65rem;
    text-align: left;
    vertical-align: top;
    white-space: nowrap; /* key for making wide tables scroll instead of wrapping */
}

.post table.post-table th {
    background: #eff4ff;
    color: #13243d;
}

/* ===== Lists / index pages ===== */

.post-list {
    list-style: none;
    margin: 0 0 var(--space-4);
    padding: 0;
    border-top: var(--line-thickness) solid var(--line);
}

.post-list li {
    padding: 0.95rem 0;
    border-bottom: var(--line-thickness) solid var(--line);
}

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

.post-list a:hover,
.post-list a:focus-visible {
    text-decoration: underline;
}

.post-list time {
    color: var(--muted);
    font-size: var(--small-size);
}

.post-title-link {
    display: inline-block;
}

.post-preview-meta {
    margin: 0.35rem 0 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    color: var(--muted);
    font-size: var(--small-size);
    white-space: nowrap;
}

.post-preview-meta time {
    color: inherit;
    font-size: inherit;
}

.post-preview-tags {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

/* ===== Tags ===== */

.topic-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
}

.topic-pill {
    display: inline-block;
    border: var(--line-thickness) solid var(--line);
    border-radius: 999px;
    padding: 0.12rem 0.63rem;
    color: var(--text);
    background: var(--surface);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
}

.topic-pill:visited {
    color: var(--text);
}

.topic-pill:hover,
.topic-pill:focus-visible {
    color: var(--text);
    border-color: var(--line);
    background: var(--surface-strong);
}

.post-tags {
    margin: 0.6rem 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

/* ===== Post header/meta ===== */

.post-header {
    margin-bottom: var(--space-4);
}

.post-meta {
    margin: 0;
    font-size: var(--small-size);
    color: var(--muted);
}

/* ===== Sidenotes ===== */

.post-body .sidenote-ref {
    font-size: 0.75em;
    line-height: 0;
    vertical-align: super;
}

.post-body .sidenote-ref a {
    color: var(--link);
    text-decoration: none;
}

.post-body .sidenote-ref a:hover,
.post-body .sidenote-ref a:focus-visible {
    text-decoration: underline;
}

.post-body .sidenote {
    display: block;
    margin: var(--space-2) 0 var(--space-3);
    padding: 0.65rem 0.85rem;
    border-left: 4px solid var(--line-strong);
    background: #eff4ff;
    color: #243448;
    font-size: 0.95rem;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    border-radius: 0 var(--radius-1) var(--radius-1) 0;
}

.post-body .sidenote-content {
    display: inline;
}

.post-body .sidenote-backref {
    color: var(--link);
    margin-left: 0.4rem;
    font-size: 0.9em;
}

.post-body .sidenote-backref:hover,
.post-body .sidenote-backref:focus-visible {
    text-decoration: underline;
}

/* ===== Responsive ===== */

@media (max-width: 640px) {
    .site-header {
        gap: 0.8rem;
        flex-direction: column;
        align-items: flex-start;
        padding-block: 1rem;
    }

    .site-nav {
        flex-wrap: wrap;
    }

    body {
        font-size: 1rem; /* 16px for small screens */
    }
}

/* Wide screens: float sidenotes */
@media (min-width: 1280px) {
    .post-body .sidenote {
        float: right;
        clear: right;
        width: 15rem;
        margin: 0.2rem -16rem 1rem 1rem;
        padding: 0.5rem 0.65rem;
        border: var(--line-thickness-thin) solid var(--line);
        border-left: 4px solid var(--line-strong);
        background: #f4f7ff;
        box-shadow: 2px 2px 0 var(--surface-strong);
    }
}

/* ===== Reduced motion ===== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition: none !important;
        animation: none !important;
    }
}
