/* main.css — the whole stylesheet for daweisun.me.
   A single narrow text column; Tufte-style sidenotes and margin notes float
   into the right margin on wide screens and collapse into tap-to-expand
   toggles on narrow ones. Colors are tokens on :root (dark mode below). */

/* Fonts ----------------------------------------------------------------- */
/* Source Serif 4 (variable weight, latin subset), self-hosted. OFL-1.1. */
@font-face {
    font-family: "Source Serif 4";
    src: url("../fonts/source-serif-4/source-serif-4-latin-wght-normal.woff2") format("woff2");
    font-weight: 200 900;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Source Serif 4";
    src: url("../fonts/source-serif-4/source-serif-4-latin-wght-italic.woff2") format("woff2");
    font-weight: 200 900;
    font-style: italic;
    font-display: swap;
}

/* Tokens ---------------------------------------------------------------- */
:root {
    --bg: #fcfcfa;
    --text: #1f1f1d;
    --muted: #6d6d68;
    --rule: #e4e3de;
    --accent: #1f5c99;
    --code-bg: #f4f3ef;

    --serif: "Source Serif 4", Charter, "Iowan Old Style", Georgia, serif;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

    --column: 38rem;     /* main text column */
    --gutter: 2.5rem;    /* gap between column and margin notes */
    --note: 15rem;       /* margin-note width */
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #171716;
        --text: #e4e2dc;
        --muted: #9a9892;
        --rule: #2f2e2b;
        --accent: #8db7e6;
        --code-bg: #212120;
    }
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--serif);
    font-size: 1.125rem;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    counter-reset: sidenote-counter;
}

::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* The page is wide enough for the column plus the note margin; the column
   itself stays left-aligned within it so notes have room on the right. */
.page {
    max-width: calc(var(--column) + var(--gutter) + var(--note));
    margin: 0 auto;
    padding: 0 1.25rem;
}

/* Header ---------------------------------------------------------------- */
.site-header {
    max-width: var(--column);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: 2.5rem 0 1rem;
    font-family: var(--sans);
}
.site-title {
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -0.01em;
    color: var(--text);
    text-decoration: none;
}
.site-header nav { display: flex; gap: 1.25rem; }
.site-header nav a {
    font-size: 0.9rem;
    color: var(--muted);
    text-decoration: none;
}
.site-header nav a:hover,
.site-header nav a.active { color: var(--text); }

/* Article --------------------------------------------------------------- */
article {
    max-width: var(--column);
    padding: 2rem 0 3rem;
}
article::after { content: ""; display: table; clear: both; }

h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.01em;
    margin: 2.2em 0 0.6em;
}
h1 { font-size: 2rem; margin-top: 0; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }

p, ul, ol, blockquote, figure, table, pre { margin: 0 0 1.25rem; }
ul, ol { padding-left: 1.4rem; }
li { margin-bottom: 0.35rem; }
strong { font-weight: 650; }

.meta {
    font-family: var(--sans);
    font-size: 0.85rem;
    color: var(--muted);
    margin: -0.25rem 0 2rem;
}
.meta .subtitle { display: block; font-family: var(--serif); font-size: 1.1rem; font-style: italic; margin-top: 0.25rem; }

a { color: var(--accent); }
article a {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
    text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
}
article a:hover { text-decoration-color: var(--accent); }

blockquote {
    margin-left: 0;
    padding-left: 1.1rem;
    border-left: 2px solid var(--rule);
    color: var(--muted);
}

hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

/* Display math: scroll sideways rather than overflow on narrow screens. */
mjx-container[display="true"] {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
}

/* Code ------------------------------------------------------------------ */
code, pre { font-family: var(--mono); font-size: 0.85em; }
:not(pre) > code {
    background: var(--code-bg);
    padding: 0.1em 0.3em;
    border-radius: 3px;
}
pre {
    background: var(--code-bg);
    padding: 0.9rem 1rem;
    border-radius: 6px;
    overflow-x: auto;
    line-height: 1.5;
}
.highlight pre { background: var(--code-bg); }
/* Minimal chroma palette (Hugo emits classes; noClasses = false). */
.chroma .c, .chroma .c1, .chroma .cm, .chroma .cs, .chroma .ch { color: var(--muted); font-style: italic; }
.chroma .k, .chroma .kd, .chroma .kn, .chroma .kr, .chroma .kc, .chroma .kt, .chroma .ow { color: var(--accent); }
.chroma .s, .chroma .s1, .chroma .s2, .chroma .sb, .chroma .sd, .chroma .se, .chroma .sh, .chroma .si { color: #3d7a3a; }
.chroma .m, .chroma .mi, .chroma .mf, .chroma .mh, .chroma .il { color: #a0522d; }
.chroma .nf, .chroma .fm, .chroma .nc { font-weight: 600; }
@media (prefers-color-scheme: dark) {
    .chroma .s, .chroma .s1, .chroma .s2, .chroma .sb, .chroma .sd, .chroma .se, .chroma .sh, .chroma .si { color: #9ccc8c; }
    .chroma .m, .chroma .mi, .chroma .mf, .chroma .mh, .chroma .il { color: #e0a47a; }
}

/* Figures and tables ---------------------------------------------------- */
img { max-width: 100%; height: auto; }
figure { margin-left: 0; margin-right: 0; }
figure.centered { text-align: center; margin: 2rem 0; }
figcaption {
    font-family: var(--sans);
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.5rem;
}
.figure-row { display: flex; flex-wrap: wrap; gap: 1rem; margin: 2rem 0; }
.figure-row figure { flex: 1 1 45%; margin: 0; }
.figure-row img { width: 100%; }

table {
    border-collapse: collapse;
    font-size: 0.95rem;
    margin-left: auto;
    margin-right: auto;
}
th, td { padding: 0.35rem 0.75rem; text-align: left; }
thead th { border-bottom: 1px solid var(--text); font-weight: 600; }
table { border-top: 1px solid var(--text); border-bottom: 1px solid var(--text); }

/* Sidenotes & margin notes --------------------------------------------- */
/* Markup (see CLAUDE.md):
   <label for="sn-x" class="margin-toggle sidenote-number"></label>
   <input type="checkbox" id="sn-x" class="margin-toggle"/>
   <span class="sidenote">…</span>
   Margin notes use class="marginnote" and a ⊕ label instead. */
.sidenote, .marginnote {
    float: right;
    clear: right;
    width: var(--note);
    margin-right: calc(-1 * (var(--note) + var(--gutter)));
    margin-top: 0.2rem;
    margin-bottom: 1rem;
    position: relative;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--muted);
    text-align: left;
}
.sidenote-number { counter-increment: sidenote-counter; }
.sidenote-number::after,
.sidenote::before {
    font-family: var(--sans);
    color: var(--accent);
    font-weight: 600;
}
.sidenote-number::after {
    content: counter(sidenote-counter);
    font-size: 0.7rem;
    vertical-align: super;
    line-height: 0;
    padding-left: 0.1rem;
}
.sidenote::before {
    content: counter(sidenote-counter) ". ";
    font-size: 0.8rem;
}
input.margin-toggle { display: none; }
label.margin-toggle:not(.sidenote-number) { display: none; }

/* Not enough room for the margin: notes become tap-to-expand blocks. */
@media (max-width: 62rem) {
    label.margin-toggle { cursor: pointer; }
    label.margin-toggle:not(.sidenote-number) { display: inline; color: var(--accent); }
    .sidenote, .marginnote {
        display: none;
        float: left;
        clear: both;
        width: 100%;
        margin: 0.75rem 0;
        padding: 0.6rem 0.9rem;
        background: var(--code-bg);
        border-radius: 6px;
    }
    .margin-toggle:checked + .sidenote,
    .margin-toggle:checked + .marginnote { display: block; }
}

/* Post list (home / blog index) ---------------------------------------- */
.post-list { list-style: none; padding: 0; margin: 0; }
/* Each entry is a card: a border appears on hover and the whole box is
   clickable, by stretching the title link over it (.post-title::after).
   The negative margin keeps the card's text aligned with the column. */
.post-list li {
    position: relative;
    margin: 0 -1rem 1.25rem;
    padding: 1rem;
    border: 1px solid transparent;   /* invisible until hover; keeps size stable */
    border-radius: 8px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.post-list li:hover {
    border-color: var(--muted);
    box-shadow: 0 2px 12px color-mix(in srgb, var(--text) 10%, transparent);
}
.post-list .post-title::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 8px;
}
/* Keep inner links in the preview clickable above the stretched overlay. */
.post-list .post-summary a { position: relative; z-index: 1; }
.post-list .post-date {
    display: block;
    font-family: var(--sans);
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.15rem;
}
.post-list .post-title {
    font-size: 1.3rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
    text-decoration: none;
}
.post-list li:hover .post-title { color: var(--accent); }
.post-list .post-summary {
    margin: 0.4rem 0 0;
    color: var(--muted);
    font-size: 1rem;
}

/* Footer ---------------------------------------------------------------- */
.site-footer {
    max-width: var(--column);
    border-top: 1px solid var(--rule);
    padding: 1.5rem 0 3rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-family: var(--sans);
    font-size: 0.8rem;
    color: var(--muted);
}
.footer-links { display: flex; gap: 1.1rem; list-style: none; margin: 0; padding: 0; }
.footer-links a { color: var(--muted); display: inline-flex; }
.footer-links a:hover { color: var(--text); }
.footer-links .icon { width: 1.15rem; height: 1.15rem; }
.site-footer .credits a { color: inherit; }
