:root {
    --bg: #ffffff;
    --ink: #000000;
    --ink-soft: #1c1c1c;
    --ink-muted: #6b6b6b;
    --ink-faint: #9a9a9a;
    --rule: #e6e6e6;
    --serif: "Libertinus Serif Display", "Cormorant Garamond", "Times New Roman", Georgia, serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Code", "Fira Code", Consolas, "Courier New", monospace;
    --sans: "Space Grotesk", system-ui, -apple-system, sans-serif;
    --body-font: var(--serif);
    --sidebar-width: 17rem;
    --gutter: 3.5rem;
    --measure: 44rem;
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink-soft);
    font-family: var(--body-font);
    font-size: 19px;
    line-height: 1.55;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid currentColor;
    transition: opacity 150ms ease;
}

a:hover {
    opacity: 0.5;
}

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

/* ---------- Layout shell ---------- */
.layout {
    display: block;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    padding: 2.25rem 1.75rem 2rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: var(--bg);
    z-index: 10;
}

.sidebar__top {
    display: flex;
    flex-direction: column;
    gap: 7rem;
}

.site-title {
    font-family: var(--mono);
    font-size: 1.05rem;
    line-height: 1.3;
    color: var(--ink);
    border-bottom: none;
    letter-spacing: -0.02em;
    font-weight: 500;
}

.site-title::after {
    content: '_';
    animation: cursor-blink 1.1s step-end infinite;
    font-weight: 300;
}

@keyframes cursor-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

.site-title:hover {
    opacity: 0.55;
}

.site-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 1.05rem;
}

.site-nav a {
    border-bottom: none;
    color: var(--ink-soft);
    width: max-content;
}

.site-nav a:hover {
    color: var(--ink);
    opacity: 1;
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
}

.site-nav a.is-active {
    color: var(--ink);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
}

.sidebar__bottom {
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--ink-muted);
}

.sidebar__bottom p {
    margin: 0;
}

.sidebar__bottom p + p {
    margin-top: 0.4rem;
}

/* ---------- Main column ---------- */
.main {
    margin-left: var(--sidebar-width);
    padding: 5.5rem var(--gutter) 5rem;
    min-height: 100vh;
}

/* ---------- Page ---------- */
.page {
    max-width: var(--measure);
}

.page__header {
    margin-bottom: 2rem;
}

.page__header h1 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: clamp(2.4rem, 5vw, 3.4rem);
    line-height: 1.02;
    margin: 0;
    color: var(--ink);
    letter-spacing: -0.015em;
}

.page__lede {
    font-size: 1.2rem;
    color: var(--ink-muted);
    font-style: italic;
    line-height: 1.45;
    margin: 0.85rem 0 0;
    max-width: 34rem;
}

.page__intro {
    font-size: 1.15rem;
    line-height: 1.45;
    color: var(--ink-muted);
    margin: 0 0 2.5rem;
    animation: fade-up 0.6s ease-out 0.1s both;
}

/* ---------- Page loader ---------- */
#page-loader {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    pointer-events: none;
    animation: loader-fade 0.3s ease forwards 1.35s;
}

#loader-dialog {
    background: var(--bg);
    border: 1.5px solid var(--ink);
    box-shadow: 4px 4px 0 var(--ink);
    width: 280px;
}

#loader-titlebar {
    height: 20px;
    border-bottom: 1.5px solid var(--ink);
    background: repeating-linear-gradient(
        to bottom,
        var(--bg)  0px, var(--bg)  1px,
        var(--ink) 1px, var(--ink) 2px
    );
    display: flex;
    align-items: center;
    padding: 0 6px;
}

#loader-closebox {
    display: inline-block;
    width: 11px;
    height: 11px;
    border: 1.5px solid var(--ink);
    background: var(--bg);
    flex-shrink: 0;
}

#loader-body {
    padding: 14px 16px 16px;
}

#loader-label {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    color: var(--ink);
    margin: 0 0 10px;
}

#loader-track {
    height: 16px;
    border: 1.5px solid var(--ink);
    background: var(--bg);
    overflow: hidden;
}

#load-bar {
    height: 100%;
    width: 0;
    background: repeating-linear-gradient(
        to right,
        var(--ink) 0px, var(--ink) 8px,
        var(--bg)  8px, var(--bg)  16px
    );
    animation: load-progress 1.3s cubic-bezier(0.05, 0.6, 0.4, 1) forwards;
}

@keyframes load-progress {
    from { width: 0; }
    to   { width: 100%; }
}

@keyframes loader-fade {
    to { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    #page-loader { display: none; }
}

.no-loader #page-loader { display: none; }

/* ---------- About / bio ---------- */
.bio {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    align-items: start;
}

@media (min-width: 720px) {
    .bio {
        grid-template-columns: 22.5rem 20rem;
        gap: 5rem;
        justify-content: space-between;
        max-width: 52rem;
    }
}

.bio__portrait {
    margin: 0;
}

.bio__portrait img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    filter: grayscale(100%);
}

.bio__portrait canvas {
    background: var(--bg);
}

.bio__text p {
    margin: 0 0 1em;
    color: var(--ink-soft);
    animation: fade-up 0.6s ease-out both;
}

.bio__text p:last-child {
    margin-bottom: 0;
}

.bio__text p:nth-child(1) { animation-delay: 1.5s; }
.bio__text p:nth-child(2) { animation-delay: 1.9s; }
.bio__text p:nth-child(3) { animation-delay: 2.3s; }
.bio__text p:nth-child(4) { animation-delay: 2.7s; }

@keyframes fade-up {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.lede {
    font-size: 1.4rem;
    line-height: 1.35;
    color: var(--ink);
}

/* ---------- Writing list ---------- */
.writing-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.writing-list__item {
    padding: 1.75rem 0;
    border-top: 1px solid var(--rule);
}

.writing-list__item:last-child {
    border-bottom: 1px solid var(--rule);
}

.writing-list__meta {
    font-size: 0.85rem;
    color: var(--ink-muted);
    margin: 0 0 0.5rem;
    letter-spacing: 0.02em;
}

.writing-list__title {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 1.75rem;
    line-height: 1.1;
    letter-spacing: -0.01em;
    margin: 0 0 0.4rem;
    color: var(--ink);
}

.writing-list__title a {
    border-bottom: none;
}

.writing-list__title a:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    opacity: 1;
}

.writing-list__publication {
    margin: 0 0 0.6rem;
    color: var(--ink-muted);
    font-style: italic;
}

.writing-list__excerpt {
    margin: 0;
    max-width: 32rem;
    color: var(--ink-soft);
}

/* ---------- Academic ---------- */
.academic-block {
    padding: 2rem 0;
    border-top: 1px solid var(--rule);
    animation: fade-up 0.6s ease-out both;
}

.page .academic-block:nth-child(2) { animation-delay: 0.45s; }

.academic-block:not(.academic-block--doctoral) {
    animation: fade-up 0.6s ease-out both;
    animation-play-state: paused;
}

.academic-block:not(.academic-block--doctoral).in-view {
    animation-play-state: running;
}

.academic-block--doctoral {
    animation: none;
    opacity: 1;
}

.academic-block--doctoral > * {
    animation: fade-up 0.6s ease-out both;
}

.academic-block--doctoral > *:nth-child(1) { animation-delay: 0.45s; }
.academic-block--doctoral > *:nth-child(2) { animation-delay: 0.8s; }
.academic-block--doctoral > *:nth-child(3) { animation-delay: 1.15s; }
.academic-block--doctoral > *:nth-child(4) { animation-delay: 1.5s; }
.academic-block--doctoral > *:nth-child(5) { animation-delay: 1.85s; }
.academic-block--doctoral > *:nth-child(6) { animation-delay: 2.2s; }

.academic-block:last-of-type {
    border-bottom: 1px solid var(--rule);
}

.academic-block__heading {
    font-size: 0.85rem;
    color: var(--ink-muted);
    letter-spacing: 0.02em;
    margin: 0 0 1.2rem;
}

.academic-block__project-title {
    font-size: 1.25rem;
    line-height: 1.25;
    color: var(--ink);
    margin: 0 0 1.2rem;
}

.academic-block p {
    margin: 0 0 1em;
    color: var(--ink-soft);
}

.academic-block__meta {
    margin-top: 1.2em !important;
    color: var(--ink-muted);
    font-size: 0.95rem;
}

.academic-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.academic-list li {
    padding: 0.75rem 0;
    border-top: 1px solid var(--rule);
    color: var(--ink-soft);
}

.academic-list li:first-child {
    border-top: none;
    padding-top: 0;
}

.page--narrow {
    max-width: 32rem;
}

/* ---------- Contact ---------- */
.contact-list {
    margin: 0 0 2.5rem;
}

.contact-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.3rem 1.5rem;
    margin-bottom: 1.2rem;
    animation: fade-up 0.6s ease-out both;
}

@media (min-width: 540px) {
    .contact-row {
        grid-template-columns: 7rem 1fr;
    }
}

.contact-row:nth-child(1) { animation-delay: 0.1s; }
.contact-row:nth-child(2) { animation-delay: 0.45s; }
.contact-row:nth-child(3) { animation-delay: 0.8s; }

.contact-list dt {
    font-size: 0.85rem;
    color: var(--ink-muted);
    letter-spacing: 0.02em;
    padding-top: 0.3rem;
}

.contact-list dd {
    margin: 0;
    line-height: 1.55;
    color: var(--ink-soft);
}

.contact-note {
    color: var(--ink-muted);
    font-style: italic;
    border-top: 1px solid var(--rule);
    padding-top: 1.5rem;
    max-width: 28rem;
    animation: fade-up 0.6s ease-out 1.15s both;
}

/* ---------- Theme switcher ---------- */
.theme-switcher {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.9rem;
}

.theme-btn {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: none;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0.55;
    transition: opacity 120ms ease, outline-offset 120ms ease;
}

.theme-btn:hover { opacity: 0.85; }

.theme-btn.is-active {
    opacity: 1;
    outline: 1.5px solid var(--ink-muted);
    outline-offset: 2px;
}

.theme-btn[data-theme=""]         { background: #1a1a1a; }
[data-theme="tech"] .theme-btn[data-theme=""] { background: #ffffff; }
.theme-btn[data-theme="tech"] { background: #4dff84; }
.theme-btn[data-theme="dotmatrix"] { background: #93c5fd; }
.theme-btn[data-theme="thermal"]  { background: #e8d9bf; }


/* ---------- 80s theme ---------- */
[data-theme="tech"] {
    --bg:        #0c0d0e;
    --ink:       #4dff84;
    --ink-soft:  #3dcc6a;
    --ink-muted: #1f8040;
    --ink-faint: #0d4020;
    --rule:      #0a2818;
    --body-font: var(--mono);
}

[data-theme="tech"] .page__header h1,
[data-theme="tech"] .writing-list__title,
[data-theme="tech"] .lede {
    font-family: var(--mono);
}

[data-theme="tech"] .site-title {
    color: var(--ink);
}

[data-theme="tech"] .bio__portrait img,
[data-theme="tech"] .bio__portrait canvas {
    filter: grayscale(100%) sepia(100%) hue-rotate(100deg) saturate(250%) brightness(0.85) !important;
}

[data-theme="tech"] .layout::after {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 3px,
        rgba(0, 0, 0, 0.07) 3px,
        rgba(0, 0, 0, 0.07) 4px
    );
    pointer-events: none;
    z-index: 999;
}

/* ---------- Dot-matrix theme ---------- */
[data-theme="dotmatrix"] {
    --bg:        #ffffff;
    --ink:       #111111;
    --ink-soft:  #222222;
    --ink-muted: #555555;
    --ink-faint: #999999;
    --rule:      #bfdbfe;
    --body-font: 'VT323', var(--mono);
}

[data-theme="dotmatrix"] body {
    font-size: 20px;
    line-height: 1.45;
}

/* Tractor-feed blue horizontal stripe background */
[data-theme="dotmatrix"] .layout {
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 44px,
        rgba(147, 197, 253, 0.2) 44px,
        rgba(147, 197, 253, 0.2) 79px
    );
}

[data-theme="dotmatrix"] .sidebar {
    background: transparent;
}

[data-theme="dotmatrix"] .site-title {
    font-family: 'VT323', var(--mono);
    font-size: 1.2rem;
    letter-spacing: 0.05em;
}

[data-theme="dotmatrix"] .site-title::after {
    display: none;
}

[data-theme="dotmatrix"] .bio__portrait img {
    display: none;
}

[data-theme="dotmatrix"] .bio__portrait canvas {
    display: none;
}

/* ASCII portrait */
#ascii-portrait {
    display: none;
    font-family: var(--mono);
    font-size: 8.1px;
    line-height: 1;
    letter-spacing: 0.12em;
    white-space: pre;
    color: var(--ink);
    margin: 0;
    user-select: none;
    pointer-events: none;
    width: 100%;
    overflow: hidden;
}

[data-theme="dotmatrix"] #ascii-portrait {
    display: block;
}

/* ---------- Thermal printer theme ---------- */
[data-theme="thermal"] {
    --bg:        #faf5ec;
    --ink:       #1c1108;
    --ink-soft:  #2e1e0c;
    --ink-muted: #7a6345;
    --ink-faint: #c4ac88;
    --rule:      #e2d4b8;
    --body-font: var(--mono);
}

[data-theme="thermal"] body {
    font-size: 15px;
    line-height: 1.6;
    letter-spacing: 0.01em;
}

[data-theme="thermal"] .site-title {
    font-family: var(--mono);
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    font-weight: 500;
    text-transform: uppercase;
}

[data-theme="thermal"] .site-title::after {
    display: none;
}

[data-theme="thermal"] .page__header h1 {
    font-family: var(--mono);
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    letter-spacing: -0.01em;
}

[data-theme="thermal"] .lede,
[data-theme="thermal"] .writing-list__title {
    font-family: var(--mono);
}

[data-theme="thermal"] .bio__portrait img,
[data-theme="thermal"] .bio__portrait canvas {
    filter: grayscale(100%) contrast(1.9) brightness(1.05) !important;
}


/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .bio__text p,
    .page__intro,
    .academic-block,
    .academic-block:not(.academic-block--doctoral),
    .academic-block--doctoral > *,
    .contact-row,
    .contact-note {
        opacity: 1;
        animation: none;
        animation-play-state: running;
    }
}


/* ---------- Small screens ---------- */
@media (max-width: 720px) {
    :root {
        --sidebar-width: 0;
        --gutter: 1.5rem;
    }

    body {
        font-size: 17px;
    }

    .sidebar {
        position: static;
        width: 100%;
        padding: 1.5rem var(--gutter) 1rem;
    }

    .sidebar__top {
        flex-direction: column;
        gap: 1.25rem;
    }

    .site-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.25rem 1.25rem;
    }

    .sidebar__bottom {
        display: none;
    }

    .main {
        margin-left: 0;
        padding: 3rem var(--gutter) 3rem;
    }
}
