/* GENERAL PAGE RULES */

/* Dark is the default theme, so it lives on :root — the page renders dark
   even before theme.js runs (no light flash) or if JS is unavailable. */
:root {
    --bg: #1f1e1d;
    --text: #f0eee6;
    --text-secondary: #b0aea5;
    --link-hover: #b0aea5;
    --border: #5e5d59;
    --card-bg: #3d3d3a;
    /* The toggle keeps the same colours in both themes. */
    --switch-track: #faf9f5;
    --switch-knob: #1f1e1d;
}

[data-theme="light"] {
    --bg: #f0eee6;
    --text: #1f1e1d;
    --text-secondary: #5e5d59;
    --link-hover: #5e5d59;
    --border: #d1cfc5;
    --card-bg: #faf9f5;
}

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

body {
    font-family: "Newsreader", "Times New Roman", serif;
    font-optical-sizing: auto;
    font-size: 1.25rem;
    line-height: 1.6;
    font-weight: 400;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    transition: background-color 0.2s linear, color 0.2s linear;
}

p {
    margin-top: 0;
    margin-bottom: 1em;
}

h1 {
    font-size: 1.44em;
    line-height: 1;
    font-weight: 600;
    margin: 0;
    text-align: left;
}

#holder {
    display: flex;
    justify-content: center;
    padding-top: clamp(32px, 8vh, 110px);
    padding-bottom: 60px;
    padding-left: 24px;
    padding-right: 24px;
    box-sizing: border-box;
}

#middle {
    max-width: 31em;
    width: 100%;
    text-align: left;
}

#name-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1em;
    margin-bottom: 1.3em;
}

a {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 0.1em;
    text-decoration-thickness: 0.08em;
    transition: color 0.2s linear;
}

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

/* TABLE OF CONTENTS */

/* Only shown when there is room left of the centered 620px column. */
#toc {
    display: none;
    position: fixed;
    top: clamp(32px, 8vh, 110px);
    left: calc(50% - 530px);
    width: 170px;
    font-size: 0.8em;
    line-height: 1.5;
}

@media (min-width: 1180px) {
    #toc {
        display: block;
    }
}

.toc-label {
    display: block;
    font-size: 0.75em;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 1em;
}

.toc-link {
    position: relative;
    display: block;
    padding-left: 1.5em;
    margin-bottom: 0.65em;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s linear;
}

.toc-link::before {
    content: "—";
    position: absolute;
    left: 0;
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toc-link:hover {
    color: var(--text);
}

.toc-link.is-active {
    color: var(--text);
}

.toc-link.is-active::before {
    opacity: 1;
    transform: none;
}

/* TYPEWRITER CARET */

.tw-cursor {
    display: inline-block;
    width: 0.08em;
    height: 1.05em;
    margin-left: 0.06em;
    background: currentColor;
    vertical-align: -0.15em;
    animation: tw-blink 1s steps(1) infinite;
}

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

/* MOBILE TOP BAR + SECTION MENU */

/* Hidden on wide viewports, where the contents rail handles navigation. */
#mobile-bar,
#mobile-menu,
#mobile-menu-backdrop {
    display: none;
}

@media (max-width: 1179px) {
    #mobile-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1em;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 230;
        padding: 0.7em clamp(16px, 5vw, 32px);
        background-color: var(--bg);
        border-bottom: 1px solid var(--border);
        transform: translateY(-100%);
        transition: transform 0.28s ease;
    }

    #mobile-bar.is-visible {
        transform: translateY(0);
    }

    #mobile-name {
        font-weight: 600;
        font-size: 1.1em;
        white-space: nowrap;
    }

    #menu-toggle {
        position: relative;
        flex-shrink: 0;
        width: 28px;
        height: 20px;
        background: none;
        border: 0;
        padding: 0;
        -webkit-appearance: none;
        appearance: none;
        cursor: pointer;
    }

    #menu-toggle span {
        position: absolute;
        left: 2px;
        right: 2px;
        height: 2px;
        background-color: var(--text);
        transition: transform 0.25s ease, opacity 0.2s ease;
    }

    #menu-toggle span:nth-child(1) { top: 2px; }
    #menu-toggle span:nth-child(2) { top: 9px; }
    #menu-toggle span:nth-child(3) { top: 16px; }

    body.menu-open #menu-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    body.menu-open #menu-toggle span:nth-child(2) { opacity: 0; }
    body.menu-open #menu-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

    #mobile-menu-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 210;
        background: rgba(0, 0, 0, 0.45);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease, visibility 0.25s;
    }

    #mobile-menu {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 220;
        background-color: var(--bg);
        border-bottom: 1px solid var(--border);
        /* Top padding clears the fixed bar so its close button stays tappable. */
        padding: 4.2em clamp(16px, 5vw, 32px) 1.5em;
        transform: translateY(-100%);
        transition: transform 0.28s ease;
    }

    body.menu-open #mobile-menu {
        transform: translateY(0);
    }

    body.menu-open #mobile-menu-backdrop {
        opacity: 1;
        visibility: visible;
    }

    .mobile-menu-label {
        display: block;
        font-size: 0.75em;
        font-weight: 500;
        letter-spacing: 0.12em;
        text-transform: uppercase;
        color: var(--text-secondary);
        margin-bottom: 1em;
    }

    #mobile-menu nav {
        display: flex;
        flex-direction: column;
        gap: 0.85em;
    }

    .mobile-menu-link {
        color: var(--text);
        text-decoration: none;
        font-size: 1.15em;
        transition: color 0.2s linear;
    }

    .mobile-menu-link:hover {
        color: var(--text-secondary);
    }

    /* Offset anchor targets so headings clear the fixed bar when jumped to. */
    h2 {
        scroll-margin-top: 72px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #mobile-bar,
    #mobile-menu,
    #mobile-menu-backdrop {
        transition: none;
    }

    .tw-cursor {
        animation: none;
    }
}

/* GLOSSARY POPOVERS */

.glossary {
    position: relative;
}

.glossary-term {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    margin: 0;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    vertical-align: baseline;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 0.15em;
    text-decoration-thickness: 0.07em;
    transition: color 0.2s linear;
}

.glossary-term:hover {
    color: var(--link-hover);
}

.glossary-card {
    position: absolute;
    top: calc(100% + 7px);
    left: 0;
    z-index: 50;
    width: max-content;
    max-width: 17em;
    padding: 0.7em 0.85em;
    background-color: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
    font-size: 0.82em;
    line-height: 1.45;
    text-align: left;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

/* Invisible bridge so the gap above the card doesn't drop hover. */
.glossary-card::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -9px;
    height: 9px;
}

.glossary.is-open .glossary-card {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.glossary-def {
    display: block;
}

.glossary-link {
    display: inline-block;
    margin-top: 0.55em;
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 0.12em;
    text-decoration-thickness: 0.06em;
}

.glossary-link:hover {
    color: var(--link-hover);
}

h2 {
    font-size: 1.2em;
    line-height: 1.2;
    font-weight: 600;
    margin-top: 1.3em;
    margin-bottom: 0.84em;
    text-align: left;
    scroll-margin-top: 24px;
}

.section-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.8em;
    text-align: left;
}

.section-list li {
    position: relative;
    padding-left: 1em;
}

.section-list li::before {
    content: "•";
    position: absolute;
    left: 0;
}

.section-list li:not(:has(a)) {
    color: var(--text-secondary);
}

/* THEME TOGGLE */

.toggle-switch {
    position: relative;
    width: 40px;
    height: 20px;
    flex-shrink: 0;
}

.toggle-checkbox {
    position: absolute;
    inset: 0;
    opacity: 0;
    margin: 0;
    cursor: pointer;
    z-index: 1;
}

.toggle-label {
    position: absolute;
    inset: 0;
    background-color: var(--switch-track);
    border: 1px solid var(--switch-knob);
    border-radius: 2rem;
    transition: background-color 0.2s linear, border-color 0.2s linear;
}

.toggle-label::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background-color: var(--switch-knob);
    transition: left 0.2s ease;
}

.toggle-checkbox:checked + .toggle-label::before {
    left: 24px;
}

/* BLOG POST PAGES */

.post-meta {
    color: var(--text-secondary);
    font-size: 0.85em;
    margin-bottom: 1.5em;
    transition: color 0.2s linear;
}

.post-body p {
    line-height: 1.6;
    margin-bottom: 1em;
}

.post-body {
    text-align: left;
}

.back-link {
    margin-top: 2em;
    display: inline-block;
    text-align: left;
}
