/* ------------------------------------------------------------------ *
 * Personal site — modeled on commonware.xyz: system monospace, one
 * 800px column, default-blue links, an animated ASCII-box logo, bold
 * linked titles with gray meta lines. Adds light/dark themes, a sticky
 * section nav, and a profile photo.
 * ------------------------------------------------------------------ */

:root {
    --bg:      #ffffff;
    --fg:      #000000;
    --muted:   #808080;   /* commonware's "gray" */
    --link:    #0000ee;   /* classic browser link blue */
    --border:  #dddddd;
    --code-bg: #f5f5f5;
}

:root[data-theme="dark"] {
    --bg:      #111111;
    --fg:      #e6e6e6;
    --muted:   #8f8f8f;
    --link:    #8ab4f8;
    --border:  #333333;
    --code-bg: #1d1d1d;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; }

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background-color: var(--bg);
    color: var(--fg);
    /* Exactly `monospace` (like commonware) so browsers use their default
       fixed-width font at its default 13px size. */
    font-family: monospace;
    max-width: 800px;
    margin: 0 auto;
    padding: 10px 10px 0 10px;
}

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

/* ------------------------------- logo + toggle -------------------- */

.logo-line {
    display: flex;
    font-size: 1.4em;
    white-space: pre;
}

/* logo: black in light mode, terminal green in dark mode */
.logo { color: var(--fg); }
:root[data-theme="dark"] .logo {
    color: #39ff14;
    text-shadow: 0 0 4px rgba(57, 255, 20, 0.45);
}

.theme-toggle {
    background: none;
    border: none;
    padding: 4px;
    color: var(--muted);
    cursor: pointer;
}
.theme-toggle:hover { color: var(--fg); }
.theme-toggle:focus-visible { outline: 1px dashed var(--fg); }
.theme-toggle svg { display: block; }
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* --------------------- sticky masthead (logo + nav) ---------------- */

/* One wrapping row: logo, toggle, then the links on a full line of their own.
   Once scrolled (.compact, set by JS) the links move up between the logo and
   the toggle, so the pinned bar is a single line. */
.masthead {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding-top: 6px;               /* breathing room above the logo once stuck */
    background-color: var(--bg);
    border-bottom: 1px solid transparent;
}
.masthead.stuck { border-bottom-color: var(--border); }

.masthead .logo   { order: 1; }
.theme-toggle     { order: 2; margin-left: auto; }
.nav {
    order: 3;
    flex-basis: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 2px 14px;
    padding: 8px 0;
    margin-top: 6px;
}

.masthead.compact .nav {
    order: 2;
    flex: 1 1 auto;          /* fill the space up to the toggle, so the profile links stay right */
    margin: 0 0 0 28px;
}

/* Profile links (cv, github, x) on the right of the menu row. */
.nav-links {
    margin-left: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 2px 14px;
}
.masthead.compact .nav-links { margin-right: 14px; }

/* On the writings pages the logo links back home; keep it looking like the logo. */
.logo-link { color: inherit; text-decoration: none; }
.masthead.compact .theme-toggle { order: 3; }
/* The compact bar is shorter; a matching margin keeps the page below it from
   moving up, so the text under the reader's eyes doesn't jump. */
.masthead.compact { margin-bottom: var(--compact-gap, 0px); }
.nav a.active {
    color: var(--fg);
    font-weight: bold;
    text-decoration: none;
}

/* anchored sections land just below the sticky nav (--nav-h set by JS) */
section[id] { scroll-margin-top: calc(var(--nav-h, 32px) + 8px); }

/* ------------------------------- content -------------------------- */

.content {
    flex: 1;
    padding-bottom: 100px;
}

section { display: flow-root; }   /* contain the floated photo */

h2 {
    font-size: 1.2em;
    margin-bottom: 8px;
}

h3 {
    font-size: 1em;
    margin-bottom: 6.6px;
    font-weight: bold;
}

p {
    line-height: 1.2;
    margin-bottom: 5px;
}

.meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.author {
    font-size: 0.9em;
    color: var(--muted);
    margin-bottom: 3px;
    margin-right: 15px;
}

.date {
    font-size: 0.8em;
    color: var(--muted);
    margin-bottom: 3px;
    font-style: italic;
}

.section-intro { color: var(--muted); }

/* about */
.photo-wrap {
    position: relative;
    float: right;
    margin: 4px 0 10px 16px;
    line-height: 0;
}
.profile-photo {
    display: block;
    width: 128px;
    height: 128px;
    object-fit: cover;
    object-position: center 30%;
    border: 1px solid var(--border);
    transition: filter 0.5s ease, border-color 0.5s ease;
}

/* photo_style: "phosphor" -- in dark mode, grade the photo like a green
   phosphor terminal (monochrome green, dimmed, with faint scanlines) so it
   sits with the green logo. Hover fades back to the real colours. */
:root[data-theme="dark"] .photo-phosphor .profile-photo {
    border-color: rgba(57, 255, 20, 0.35);
    filter: grayscale(1) sepia(1) hue-rotate(65deg) saturate(2.5) brightness(0.45) contrast(1.45);
}
:root[data-theme="dark"] .photo-phosphor::after {
    content: "";
    position: absolute;
    inset: 1px;
    background: repeating-linear-gradient(to bottom,
        rgba(0, 0, 0, 0.3) 0, rgba(0, 0, 0, 0.3) 1px, transparent 1px, transparent 3px);
    pointer-events: none;
    transition: opacity 0.5s ease;
}
:root[data-theme="dark"] .photo-phosphor:hover .profile-photo { filter: none; }
:root[data-theme="dark"] .photo-phosphor:hover::after { opacity: 0; }

/* photo_style: "circle" -- round with a 2px border: light blue and grayscale
   in light mode, terminal green and full colour in dark mode. */
.photo-circle .profile-photo {
    width: 176px;        /* about as tall as the about text beside it */
    height: 176px;
    border-radius: 50%;
    border: 2px solid var(--ring-light, lightblue);   /* set per photo via photo_ring_light */
    filter: grayscale(1);
}
:root[data-theme="dark"] .photo-circle .profile-photo {
    border-color: var(--ring-dark, #39ff14);   /* set per photo via photo_ring_dark */
    filter: none;
}

/* own name in author lists */
.author .me { color: var(--fg); }

/* publications: [eprint] [code] … and awards */
.links { font-size: 0.9em; margin-top: 4px; }
.award { color: var(--fg); }

/* news */
ul.news { list-style: none; padding-left: 0; }
ul.news li { line-height: 1.2; margin-bottom: 6px; }
ul.news .date { margin-right: 6px; }

ol, ul { margin: 10px 0; padding-left: 30px; }
li { line-height: 1.2; margin-bottom: 4px; }

code {
    background-color: var(--code-bg);
    padding: 2px 4px;
    font-family: monospace;
    font-size: 0.9em;
}

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

/* Scrambled contact email + its [decipher] button (looks like a link). */
.contact-line { margin-top: 12px; }
.cipher { color: var(--muted); }
.cipher.revealed { color: inherit; }
.decipher {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--link);
    cursor: pointer;
}
.decipher:hover { text-decoration: underline; }
.decipher:focus-visible { outline: 1px dashed var(--fg); }

/* ------------------------------- writings ------------------------- */

.more { margin-top: 10px; }
.back { display: inline-block; margin-top: 16px; }

/* A post: same monospace look, with a little more line height for long reads. */
.post h1 { font-size: 1.5em; margin: 14px 0 6px; }
.post h2 { font-size: 1.2em; margin: 1.6em 0 8px; }
.post h3 { font-size: 1em; margin: 1.4em 0 6px; }
.post h2[id], .post h3[id] { scroll-margin-top: calc(var(--nav-h, 32px) + 8px); }
.post p, .post li { line-height: 1.5; }
.post p { margin: 0.9em 0; }
.post > .meta { margin-bottom: 1.2em; }

.post pre {
    background-color: var(--code-bg);
    padding: 12px 14px;
    overflow-x: auto;
    line-height: 1.45;
}
.post pre code, .post pre code.hljs { background: transparent; padding: 0; font-size: 0.95em; }

.post blockquote {
    margin: 1em 0;
    padding: 0 0 0 12px;
    border-left: 3px solid var(--border);
    color: var(--muted);
}
.post img { display: block; margin: 18px 0; }
.post table { border-collapse: collapse; margin: 1em 0; }
.post th, .post td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.post hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.post .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.post .footnote { font-size: 0.9em; color: var(--muted); }

/* ------------------------------- footer --------------------------- */

.footer {
    text-align: left;
    padding: 10px 0;
    color: var(--fg);
}

/* ------------------------------- small screens -------------------- */

@media (max-width: 520px) {
    .photo-wrap { margin-left: 12px; }
    .profile-photo { width: 96px; height: 96px; }
    .photo-circle .profile-photo { width: 112px; height: 112px; }
    .logo-line { font-size: 1.2em; }
}
