/* ---------------------------------------------------------------------------
   The Last Enemy — writing site
   Light, cream, serif. One column of text on the left, art on the right.
--------------------------------------------------------------------------- */

:root {
    /* LessWrong uses Warnock Pro (paid). Crimson Pro is the closest free match;
       Inter stands in for the sans-serif they use on dates and small text. */
    --font-serif: "Crimson Pro", "Palatino Linotype", Palatino, Georgia, serif;
    --font-sans: Inter, Calibri, system-ui, -apple-system, "Segoe UI", sans-serif;

    --bg: #f7f3ec;
    --text: #2a2622;
    --heading: #1f1b17;
    --muted: #7d766b;
    --border: #e4dccf;
    --code-bg: #efe9df;
    --link: #2f6f5e;
    --link-hover: #1e5446;

    --measure: 680px;                       /* width of the text column */
    --gutter: clamp(20px, 7vw, 110px);      /* space to the left of it */
}

* { box-sizing: border-box; }

/* Always show the scrollbar so the layout never shifts between pages. */
html { -webkit-text-size-adjust: 100%; overflow-y: scroll; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-serif);
    font-size: 20px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; text-underline-offset: 3px; }

/* The text column ---------------------------------------------------------- */
.content {
    position: relative;
    z-index: 1;
    flex: 1;
    width: 100%;
    max-width: calc(var(--measure) + 40px);
    margin-left: var(--gutter);
    padding: 0 20px 72px;
}

@media (max-width: 720px) {
    .content { margin-left: auto; margin-right: auto; }
}

/* Side art ----------------------------------------------------------------- */
.side-art { display: none; }

@media (min-width: 1150px) {
    .side-art {
        display: block;
        position: fixed;
        top: 0;
        right: 0;
        width: 50vw;
        height: 100vh;
        z-index: 0;
        pointer-events: none;
        /* Oversized and pushed past the right edge, so the artwork runs off the
           screen instead of ending inside it; the left side fades into the page. */
        background-position: right -12vw center;
        background-size: auto 125vh;
        background-repeat: no-repeat;
        opacity: 0.92;
        -webkit-mask-image: linear-gradient(to right, transparent 0%, #000 45%);
                mask-image: linear-gradient(to right, transparent 0%, #000 45%);
    }
}

/* Header: full width, sticks to the top, slightly see-through --------------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    width: 100%;
    height: 60px;                      /* fixed, so opening search never changes it */
    padding: 0 24px 0 calc(var(--gutter) + 20px);
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: blur(12px);
            backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

@media (max-width: 720px) {
    .site-header { padding-left: 20px; padding-right: 20px; }
}

.site-name {
    color: var(--heading);
    font-size: 1.3rem;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}
.site-name:hover { text-decoration: none; color: var(--link); }

/* Search box in the header ------------------------------------------------- */
/* Only the magnifier shows. Clicking it reveals a bare underlined field to its
   left and the icon becomes an X that closes it again. */
.site-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.search-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #4a443c;
    cursor: pointer;
}
.search-toggle:hover { background: rgba(0, 0, 0, 0.06); color: var(--heading); }
.search-toggle .icon-close { display: none; }
.site-search.is-open .icon-search { display: none; }
.site-search.is-open .icon-close { display: block; }

#search-input {
    display: none;
    width: 240px;
    padding: 4px 2px 5px;
    border: 0;
    border-bottom: 1px solid #cfc8bb;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    outline: none;
    box-shadow: none;
}
.site-search.is-open #search-input { display: block; }
#search-input::placeholder { color: #b5ad9f; }
#search-input:focus { border-bottom-color: #8f8574; }
#search-input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search-results {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 400px;
    max-width: calc(100vw - 40px);
    max-height: 70vh;
    overflow-y: auto;
    margin: 0;
    padding: 6px;
    list-style: none;
    background: #fff;
    border: 1px solid #d9d3c8;
    border-radius: 4px;
    box-shadow: 0 10px 30px rgba(60, 50, 35, 0.12);
}
.search-results li a {
    display: block;
    padding: 10px 12px;
    border-radius: 5px;
    color: inherit;
}
.search-results li a:hover { background: #f1efeb; text-decoration: none; }
.search-title { display: block; color: var(--heading); font-size: 1.1rem; font-weight: 500; line-height: 1.25; }
.search-date { display: block; color: var(--muted); font-family: var(--font-sans); font-size: 0.75rem; margin-top: 2px; }
.search-snippet { display: block; color: var(--muted); font-family: var(--font-sans); font-size: 0.8rem; line-height: 1.4; margin-top: 4px; }
.search-snippet mark { background: #f3e3b0; color: inherit; padding: 0 1px; border-radius: 2px; }
.search-empty { padding: 10px 12px; color: var(--muted); font-size: 0.95rem; }

@media (max-width: 520px) {
    #search-input { width: 180px; }
}

/* Home: list of posts ------------------------------------------------------ */
/* The list has no visible heading; this one is only for screen readers. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* The list runs wider than the essay column. */
body.home .content { max-width: 760px; }

.post-list { list-style: none; margin: 40px 0 0; padding: 0; }

.post-item { margin: 0; }
.post-item + .post-item { margin-top: 2px; }

/* Posts stack flush, one white block on top of the next; each greys on hover. */
.post-card {
    display: grid;
    grid-template-columns: 1fr auto;
    column-gap: 24px;
    align-items: baseline;
    padding: 11px 16px 12px;
    background: #fff;
    border: 1px solid var(--border);
    color: inherit;
    transition: background-color 0.12s ease;
}
.post-card:hover {
    background: #efece7;
    text-decoration: none;
}

.post-title {
    color: #2b2825;
    font-size: 1.05rem;        /* ~21px, matching LessWrong's list titles */
    font-weight: 400;
    line-height: 1.3;
}

.post-date {
    flex: none;
    color: var(--muted);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 520px) {
    .post-card { grid-template-columns: 1fr; row-gap: 2px; }
}

/* Post / page -------------------------------------------------------------- */
/* Reading view: no side art, the column sits in the middle of the page. */
body.post .side-art,
body.page .side-art { display: none; }

body.post .content,
body.page .content { margin-left: auto; margin-right: auto; }

.post-header { margin: 120px 0 72px; }

.post-header h1 {
    margin: 0 0 22px;
    color: var(--heading);
    font-size: 3.4rem;
    font-weight: 400;
    line-height: 1.08;
    letter-spacing: -0.01em;
}

.post-meta { margin: 0; color: #6f685d; font-family: var(--font-sans); font-size: 0.9rem; }

@media (max-width: 720px) {
    .post-header { margin: 56px 0 40px; }
    .post-header h1 { font-size: 2.4rem; }
}

/* Post pages are white like the header; the header's bottom line separates them. */
body.post { background: #fff; }
body.post .site-header { border-bottom-color: rgba(0, 0, 0, 0.1); }

/* Reading progress down the left edge of post pages (added by progress.js):
   a faint track and a short marker that slides down it as you read. */
.read-progress {
    position: fixed;
    left: 22px;
    top: 84px;
    bottom: 28px;
    width: 2px;
    background: rgba(0, 0, 0, 0.05);
    z-index: 3;
    pointer-events: none;
}
.read-progress-thumb {
    width: 2px;
    height: 24px;              /* progress.js sets the real height per article */
    background: #2a2622;
    will-change: transform;
}
@media (max-width: 900px) {
    .read-progress { display: none; }
}

.prose { font-size: 1.15rem; line-height: 1.6; }

.prose > :first-child { margin-top: 0; }

/* Links inside essays are always underlined. */
.prose a {
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    text-decoration-color: rgba(47, 111, 94, 0.5);
}
.prose a:hover { text-decoration-color: currentColor; }
.prose p { margin: 0 0 1.25em; }

.prose h2, .prose h3, .prose h4 {
    color: var(--heading);
    font-weight: 500;
    line-height: 1.2;
    margin: 2em 0 0.6em;
}
.prose h2 { font-size: 1.6rem; }
.prose h3 { font-size: 1.3rem; }
.prose h4 { font-size: 1.1rem; font-style: italic; }

.prose blockquote {
    margin: 1.5em 0;
    padding: 0 0 0 1.1em;
    border-left: 3px solid var(--border);
    color: #5a5349;
    font-style: italic;
}
.prose blockquote p:last-child { margin-bottom: 0; }

.prose ul, .prose ol { margin: 0 0 1.25em; padding-left: 1.5em; }
.prose li { margin: 0.3em 0; }

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

.prose figure { margin: 2em 0; }
.prose figure img { display: block; width: 100%; border-radius: 4px; }
.prose figcaption {
    margin-top: 0.7em;
    color: var(--muted);
    font-size: 0.92rem;
    text-align: center;
}

.prose hr { margin: 2.5em 0; border: 0; border-top: 1px solid var(--border); }

.prose code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.82em;
    background: var(--code-bg);
    padding: 0.1em 0.4em;
    border-radius: 3px;
}
.prose pre {
    margin: 1.5em 0;
    padding: 14px 18px;
    overflow-x: auto;
    background: var(--code-bg);
    border-radius: 6px;
    font-size: 0.85rem;
    line-height: 1.5;
}
.prose pre code { background: none; padding: 0; font-size: inherit; }

.prose table { border-collapse: collapse; margin: 1.5em 0; font-size: 0.95em; }
.prose th, .prose td { padding: 6px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.prose th { color: var(--heading); font-weight: 500; }

.prose sup { line-height: 0; }
.prose .footnote { margin-top: 3em; color: var(--muted); font-size: 0.95rem; }
.prose .footnote hr { margin: 0 0 1em; }
.prose .footnote ol { padding-left: 1.3em; }
.prose .footnote p { margin: 0; }

