/* ---------------------------------------------------------------
   Tokens
   --------------------------------------------------------------- */
:root {
    --font-body:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
        Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
    --font-mono:
        "SFMono-Regular", "Source Code Pro", Menlo, Monaco, Consolas,
        "Liberation Mono", "Courier New", monospace;

    --measure: 46rem;
    --gutter: 1.5rem;
    --radius: 6px;

    --bg: #ffffff;
    --bg-soft: #f8f9fa;
    --bg-code: #f5f6f7;
    --text: #2c3e50;
    --text-muted: #6a737d;
    --border: #e6e8ea;
    --accent: #2f7d6f;
    --accent-soft: rgba(47, 125, 111, 0.12);
    --accent-contrast: #ffffff;
    --flash: rgba(47, 125, 111, 0.22);
}

:root[data-theme="dark"] {
    --bg: #16181d;
    --bg-soft: #1d2027;
    --bg-code: #1f232b;
    --text: #d7dce4;
    --text-muted: #9099a6;
    --border: #2b3038;
    --accent: #6fc7b3;
    --accent-soft: rgba(111, 199, 179, 0.16);
    --accent-contrast: #10161a;
    --flash: rgba(111, 199, 179, 0.26);
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.72;
    transition:
        background-color 0.2s ease,
        color 0.2s ease;
}

/* Hide the article until the analogies are resolved and diagrams drawn. */
body.is-loading .reveal {
    visibility: hidden;
}

a {
    color: var(--accent);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 2px;
}

.wrap {
    width: 100%;
    max-width: var(--measure);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

/* ---------------------------------------------------------------
   Header / footer
   --------------------------------------------------------------- */
.site-header {
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.site-header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 3.75rem;
}

.site-header__title {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--text);
    margin: 0;
}
.site-header__title a {
    color: inherit;
}
.site-header__title a:hover {
    text-decoration: none;
    color: var(--accent);
}

.theme-toggle {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    border-radius: var(--radius);
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition:
        color 0.15s ease,
        border-color 0.15s ease;
}
.theme-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.site-footer {
    border-top: 1px solid var(--border);
    margin-top: 4rem;
    padding: 1.75rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ---------------------------------------------------------------
   Home
   --------------------------------------------------------------- */
.intro {
    padding: 3.25rem 0 2.25rem;
}

.intro__title {
    font-size: 2.1rem;
    line-height: 1.25;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 0.85rem;
}

.intro__lede {
    font-size: 1.08rem;
    color: var(--text-muted);
    margin: 0;
    max-width: 34rem;
}

.post-list__heading {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    font-weight: 600;
    margin: 0 0 1.25rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

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

.post-card {
    padding: 0 0 1.9rem;
}
.post-card + .post-card {
    border-top: 1px solid var(--border);
    padding-top: 1.9rem;
}

.post-card__link {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}
.post-card__link:hover {
    color: var(--accent);
    text-decoration: none;
}

.post-card__meta {
    margin: 0.35rem 0 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.post-card__description {
    margin: 0.6rem 0 0;
    color: var(--text);
}

.post-card__analogies {
    margin: 0.55rem 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.post-list__empty {
    color: var(--text-muted);
}

.tag {
    display: inline-block;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

/* ---------------------------------------------------------------
   Post
   --------------------------------------------------------------- */
.post {
    padding: 3rem 0 1rem;
}

.post__title {
    font-size: 2.05rem;
    line-height: 1.24;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 0.75rem;
}

/* The switcher sits directly under the title, before anything else. */
.analogy-switcher {
    margin: 0 0 0.85rem;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.analogy-switcher__label {
    display: inline-flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.analogy-switcher__select {
    font: inherit;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0.15rem 0.45rem;
    cursor: pointer;
    max-width: 100%;
}
.analogy-switcher__select:hover {
    border-color: var(--accent);
}

.post__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.55rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}

#post-tags {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Swappable terms: quietly marked so readers can see what changes. */
.post.has-analogies .analogy-term {
    border-bottom: 1px dotted var(--accent);
    border-radius: 2px;
}

.analogy-term.is-swapped {
    animation: analogy-flash 0.9s ease-out;
}

@keyframes analogy-flash {
    0% {
        background-color: var(--flash);
    }
    60% {
        background-color: var(--flash);
    }
    100% {
        background-color: transparent;
    }
}

@media (prefers-reduced-motion: reduce) {
    .analogy-term.is-swapped {
        animation: none;
    }
    body,
    .theme-toggle {
        transition: none;
    }
}

/* ---------------------------------------------------------------
   Article body
   --------------------------------------------------------------- */
.post__body > *:first-child {
    margin-top: 0;
}

.post__body h2 {
    font-size: 1.5rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    margin: 2.75rem 0 1rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}

.post__body h3 {
    font-size: 1.2rem;
    font-weight: 650;
    margin: 2rem 0 0.75rem;
}

.post__body h4 {
    font-size: 1.02rem;
    margin: 1.6rem 0 0.6rem;
}

.post__body p {
    margin: 0 0 1.15rem;
}

.post__body ul,
.post__body ol {
    margin: 0 0 1.15rem;
    padding-left: 1.35rem;
}
.post__body li {
    margin-bottom: 0.4rem;
}

.post__body blockquote {
    margin: 1.5rem 0;
    padding: 0.15rem 0 0.15rem 1.1rem;
    border-left: 3px solid var(--accent);
    color: var(--text-muted);
}
.post__body blockquote p:last-child {
    margin-bottom: 0;
}

.post__body img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1.75rem auto;
    border-radius: var(--radius);
}

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

.post__body code {
    font-family: var(--font-mono);
    font-size: 0.87em;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.1em 0.35em;
}

.post__body pre {
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    overflow-x: auto;
    margin: 0 0 1.5rem;
    line-height: 1.55;
}
.post__body pre code {
    background: none;
    border: 0;
    padding: 0;
    font-size: 0.86rem;
}

.post__body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 1.5rem;
    font-size: 0.94rem;
    display: block;
    overflow-x: auto;
}
.post__body th,
.post__body td {
    border: 1px solid var(--border);
    padding: 0.5rem 0.7rem;
    text-align: left;
}
.post__body th {
    background: var(--bg-soft);
    font-weight: 600;
}

/* Mermaid */
.mermaid-figure {
    margin: 1.75rem 0;
    padding: 1rem;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}
pre.mermaid {
    background: none;
    border: 0;
    margin: 0;
    padding: 0;
    text-align: center;
    font-family: var(--font-body);
}
pre.mermaid svg {
    max-width: 100%;
    height: auto;
}

/* Error state */
.post-status {
    padding: 3rem 0;
}
body:not(.has-error) .post-status {
    display: none;
}
body.has-error .post {
    display: none;
}

/* ---------------------------------------------------------------
   Small screens
   --------------------------------------------------------------- */
@media (max-width: 40rem) {
    body {
        font-size: 16px;
    }
    .intro {
        padding: 2.25rem 0 1.5rem;
    }
    .intro__title {
        font-size: 1.75rem;
    }
    .post {
        padding: 2rem 0 1rem;
    }
    .post__title {
        font-size: 1.65rem;
    }
    .post__body h2 {
        font-size: 1.3rem;
    }
}
