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

:root {
    color-scheme: light dark;
    height: 100%;
    --page-background: #f7f3ec;
    --page-text: #423c34;
    --heading-color: #2c2823;
    --nav-color: #4f4a3f;
    --link-color: #4f5b36;
    --link-hover-opacity: 0.97;
    --work-meta-color: #60594d;
    --grid-line: rgba(118, 107, 85, 0.09);
    --grid-subdivision: rgba(118, 107, 85, 0.035);
}

:root.poetry-theme {
    --page-background: #f5eaf0;
    --page-text: #54354e;
    --heading-color: #392039;
    --nav-color: #753360;
    --link-color: #753360;
    --link-hover-opacity: 1;
    --grid-line: rgba(153, 88, 133, 0.13);
    --grid-subdivision: rgba(153, 88, 133, 0.055);
}

@media (prefers-color-scheme: dark) {
    :root {
        --page-background: #071528;
        --page-text: #a8d0f0;
        --heading-color: #ffffff;
        --nav-color: #6aaee0;
        --link-color: #6aaee0;
        --link-hover-opacity: 0.6;
        --work-meta-color: #829fb9;
        --grid-line: rgba(80, 160, 240, 0.055);
        --grid-subdivision: rgba(80, 160, 240, 0.022);
    }

    :root.poetry-theme {
        --page-background: #221423;
        --page-text: #e6c9db;
        --heading-color: #fff0fa;
        --nav-color: #e3add4;
        --link-color: #e3add4;
        --link-hover-opacity: 1;
        --grid-line: rgba(213, 139, 184, 0.12);
        --grid-subdivision: rgba(213, 139, 184, 0.05);
    }
}

body, html {
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    background-color: var(--page-background);
    color: var(--page-text);
    line-height: 1.6;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
        linear-gradient(var(--grid-subdivision) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-subdivision) 1px, transparent 1px);
    background-size: 80px 80px, 80px 80px, 16px 16px, 16px 16px;
    background-position: -1px -1px, -1px -1px, -1px -1px, -1px -1px;
}

.container {
    max-width: 650px;
    padding: 60px 20px;
    margin-inline-start: clamp(0px, calc(8vw - 64px), 60px);
}

footer {
    margin-top: auto;
    padding: 0 20px 24px;
}

.nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    font-size: 12px;
    letter-spacing: -0.015rem;
}

.primary-nav {
    margin-bottom: 36px;
}

footer .nav-links {
    justify-content: center;
    column-gap: clamp(14px, 4vw, 24px);
    row-gap: 10px;
}

.nav-links a {
    padding: 4px 0;
    color: var(--nav-color);
    text-decoration: none;
    transition: opacity 0.2s;
}

.nav-links a:hover,
.content a:hover {
    opacity: var(--link-hover-opacity);
}

.nav-links a[aria-current="page"],
.nav-links a[aria-current="location"] {
    text-decoration: underline;
    text-underline-offset: 4px;
}

h1 {
    font-size: 40px;
    font-weight: 400;
    line-height: 1;
    letter-spacing: -0.16rem;
    margin-bottom: 32px;
}

h1,
.education > h2 {
    color: var(--heading-color);
}

.content {
    max-width: 600px;
}

.essay-page .content {
    max-width: 720px;
}

.content p {
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: -0.0175rem;
    margin-bottom: 16px;
}

.post h1 {
    line-height: 1.15;
    margin-bottom: 8px;
}

.post p {
    font-size: 16px;
    line-height: 1.7;
}

.post :is(ul, ol) {
    margin: 0 0 16px;
    padding-inline-start: 1.5em;
}

.post li {
    font-size: 16px;
    line-height: 1.7;
}

.post li + li {
    margin-top: 8px;
}

.post-date {
    display: block;
    font-size: 13px;
}

.post .post-date,
.poem .post-date {
    margin-bottom: 24px;
}

.essay-page .primary-nav {
    max-width: 720px;
}

@media (prefers-color-scheme: dark) {
    :root.reading-mode {
        --page-text: #c9d2dc;
        --link-color: #b3cee7;
    }
}

.reading-mode .container.essay-page {
    width: 100%;
    max-width: 800px;
    margin-inline: auto;
    padding: 60px 40px 80px;
}

.reading-mode .primary-nav {
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
}

.reading-mode .primary-nav a:not([aria-current]) {
    display: none;
}

.reading-mode .primary-nav a[aria-current] {
    text-decoration: none;
}

.reading-mode .essay-page .post {
    font-size: 19px;
    line-height: 1.7;
}

@media (max-width: 768px) {
    .reading-mode .container.essay-page {
        padding: 40px 20px 60px;
    }

    .reading-mode .primary-nav {
        margin-bottom: 24px;
    }

    .reading-mode .essay-page .post {
        font-size: 17px;
    }
}

.essay-page .post {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.essay-page .post h1 {
    font-size: clamp(32px, 4vw, 44px);
    font-weight: 650;
    line-height: 1.12;
    letter-spacing: -0.03em;
    text-wrap: balance;
    margin-bottom: 14px;
}

.essay-page .post-date {
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    color: var(--nav-color);
    margin-bottom: 36px;
}

.essay-page .post h2 {
    font-size: 24px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.02em;
    color: var(--heading-color);
    margin: 40px 0 16px;
}

.essay-page .post p,
.essay-page .post li {
    font-size: inherit;
    line-height: inherit;
    letter-spacing: normal;
}

.essay-page .post p,
.essay-page .post :is(ul, ol) {
    margin-bottom: 22px;
}

.essay-page .post li + li {
    margin-top: 10px;
}

.essay-page .post figure {
    margin: 32px 0;
}

.essay-page .post figure img {
    display: block;
    width: 100%;
    height: auto;
}

.content strong,
.work-entry :is(h2, h3) {
    font-weight: 600;
    color: var(--heading-color);
}

.content a {
    color: var(--link-color);
    text-decoration: underline;
    transition: opacity 0.2s;
}

.work-entry + .work-entry {
    margin-top: 32px;
}

.work-entry :is(h2, h3) {
    font-size: 16px;
    margin-bottom: 3px;
}

.work-entry .work-meta {
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--work-meta-color);
}

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

.education {
    margin-top: 36px;
}

.education > h2 {
    font-size: 24px;
    font-weight: 400;
    line-height: 1.2;
    letter-spacing: -0.055rem;
    margin-bottom: 18px;
}

.poem-index ul {
    list-style: none;
}

.poem-index li + li {
    margin-top: 12px;
}

.poem h1 {
    margin-bottom: 8px;
}

.poem .poem-dedication {
    font-size: 13px;
    font-style: italic;
}

.poetry-theme .nav-links a:hover,
.poetry-theme .content a:hover {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

@media (prefers-reduced-motion: no-preference) {
    @view-transition {
        navigation: auto;
    }
}

::view-transition-group(root),
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
}

:root:active-view-transition-type(poetry-enter, poetry-exit)::view-transition-old(root) {
    mix-blend-mode: normal;
}

:root:active-view-transition-type(poetry-enter, poetry-exit)::view-transition-new(root) {
    animation: poetry-sweep 250ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
    mask-image: linear-gradient(
        var(--poetry-sweep-direction),
        #000 calc(50% - clamp(12px, 4vw, 36px)),
        transparent calc(50% + clamp(12px, 4vw, 36px))
    );
    mask-size: 240% 100%;
    mask-repeat: no-repeat;
    mix-blend-mode: normal;
}

:root:active-view-transition-type(poetry-enter)::view-transition-new(root) {
    --poetry-sweep-direction: to left;
    --poetry-sweep-start: 0% 0;
    --poetry-sweep-end: 100% 0;
}

:root:active-view-transition-type(poetry-exit)::view-transition-new(root) {
    --poetry-sweep-direction: to right;
    --poetry-sweep-start: 100% 0;
    --poetry-sweep-end: 0% 0;
}

@keyframes poetry-sweep {
    from {
        mask-position: var(--poetry-sweep-start);
    }
    to {
        mask-position: var(--poetry-sweep-end);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 40px 20px;
    }

    h1 {
        font-size: 28px;
        letter-spacing: -0.1rem;
        margin-bottom: 24px;
    }
}
