/* Comfortable controls and dialogs at phone, tablet and desktop sizes. */
/* Reserve the email label's actual height, including when it wraps. Keep the
 * email/CV pair between matching outer gaps and a smaller internal gap. */
.sidebar {
    --sidebar-actions-gap: 1.25rem;
}

.sidebar .contact-details,
.sidebar .contact-details p:last-of-type {
    margin-bottom: 0;
}

.sidebar .email-wrapper {
    display: grid;
    margin: var(--sidebar-actions-gap) 0 0.5rem;
}

.sidebar .email-text,
.sidebar .human-check-overlay {
    grid-area: 1 / 1;
    align-self: center;
    min-width: 0;
}

.sidebar .human-check-overlay {
    position: relative;
    inset: auto;
    height: auto;
    min-height: 44px;
}

body :is(.human-checkbox-label, .cv-download-link, .copy-btn) {
    min-height: 44px;
}

/* Reflow when enlarged text needs more room than the usual footer row. */
.sidebar .bottom-controls {
    flex-wrap: wrap;
    row-gap: 0.5rem;
}

.main-content .entry-desc a {
    overflow-wrap: anywhere;
}

.page-wrapper > .main-content {
    min-width: 0;
}

.main-content :is(h2, h3),
.sidebar .orbit-name-text {
    overflow-wrap: anywhere;
}

#page-teaching .teaching-current-code {
    white-space: normal;
}

/* Let grouped paper actions wrap with the same height and gap on every row. */
.entry-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.entry-actions > :is(.abstract-toggle, .bibtex-toggle, .arxiv-tab) {
    margin: 0;
    min-height: 44px;
    max-width: 100%;
    white-space: normal;
}

@media (min-width: 701px) {
    .sidebar .cv-download-link {
        margin-bottom: var(--sidebar-actions-gap);
    }
}

body .mobile-sticky-nav .nav-link,
body .nav-menu .nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

body .sidebar .nav-menu .nav-link {
    display: flex;
}

body :is(.close-modal, .name-orbit-close) {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

body .close-modal {
    top: 0.4rem;
    right: 0.4rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--secondary-text);
}

body :is(.erdos-modal-content, .bibtex-modal-content) {
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-top: 3rem;
}

body :is(.erdos-modal-content, .bibtex-modal-content) > h3 {
    margin-top: 0;
}

body .name-orbit-panel {
    max-width: calc(100% - 1rem);
    max-height: min(820px, calc(100vh - 2rem));
    max-height: min(820px, calc(100dvh - 2rem));
    overscroll-behavior: contain;
}

@media screen and (max-width: 480px) {
    body :is(.erdos-modal-content, .bibtex-modal-content) {
        padding-inline: 1rem;
        padding-bottom: 1rem;
    }

    #page-teaching .teaching-current {
        padding-inline: min(1.1rem, 5vw);
    }
}

/* The tablet header uses one separator between the menu and footer controls. */
@media screen and (min-width: 701px) and (max-width: 900px) {
    .sidebar .nav-menu {
        border-top: 0;
        padding-top: 0;
        padding-bottom: var(--sidebar-actions-gap);
    }

    .sidebar .sidebar-bottom {
        margin-top: 0;
        border-top: 0;
        padding-top: var(--sidebar-actions-gap);
    }
}

body.site-dialog-open {
    overflow: hidden;
}

body .bibtex-code {
    overflow-wrap: anywhere;
}

/* Use labelled rows whenever four table columns would crowd the content area. */
@media screen and (max-width: 700px), screen and (min-width: 901px) and (max-width: 1180px) {
    .main-content .teaching-table,
    .main-content .teaching-table tbody,
    .main-content .teaching-table tr {
        display: block;
        width: 100%;
    }

    .main-content .teaching-table thead {
        display: none;
    }

    .main-content .teaching-table tr {
        padding: 0.85rem 0.95rem;
        border-bottom: 1px solid var(--border-color);
    }

    .main-content .teaching-table tbody tr:last-child {
        border-bottom: 0;
    }

    .main-content .teaching-table td {
        display: grid;
        align-items: first baseline;
        grid-template-columns: minmax(6.6rem, 25%) minmax(0, 1fr);
        gap: 0.65rem;
        width: 100%;
        padding: 0.35rem 0;
        border-bottom: 0;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .main-content .teaching-table td::before {
        content: attr(data-label);
        font-size: 0.78rem;
        line-height: 1.5;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: var(--secondary-text);
        font-weight: 600;
    }
}

@media screen and (max-width: 480px) {
    .main-content .teaching-table td {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.15rem;
        padding: 0.45rem 0;
    }
}

/* A fixed sidebar also reduces the space available to narrow laptop windows. */
@media screen and (min-width: 901px) and (max-width: 1180px) {
    .main-content .entry:has(.entry-meta) {
        grid-template-columns: minmax(0, 1fr);
        row-gap: 0.25rem;
    }

    .main-content .entry .entry-meta {
        grid-column: 1;
        justify-self: start;
        width: auto;
        text-align: left;
    }
}

/* Container widths in rem also respond to a reader's enlarged text settings. */
@media screen {
    .main-content .teaching-table-wrap {
        container: teaching-table / inline-size;
    }

    @container teaching-table (max-width: 40rem) {
        .main-content .teaching-table,
        .main-content .teaching-table tbody,
        .main-content .teaching-table tr {
            display: block;
            width: 100%;
        }

        .main-content .teaching-table thead {
            display: none;
        }

        .main-content .teaching-table tr {
            padding: 0.85rem min(0.95rem, 4cqw);
            border-bottom: 1px solid var(--border-color);
        }

        .main-content .teaching-table tbody tr:last-child {
            border-bottom: 0;
        }

        .main-content .teaching-table td {
            display: grid;
            grid-template-columns: minmax(6.6rem, 25%) minmax(0, 1fr);
            align-items: first baseline;
            gap: 0.65rem;
            width: 100%;
            padding: 0.35rem 0;
            border-bottom: 0;
            white-space: normal;
            overflow-wrap: anywhere;
        }

        .main-content .teaching-table td::before {
            content: attr(data-label);
            font-size: 0.78rem;
            line-height: 1.5;
            letter-spacing: 0.04em;
            text-transform: uppercase;
            color: var(--secondary-text);
            font-weight: 600;
        }
    }

    @container teaching-table (max-width: 26rem) {
        .main-content .teaching-table td {
            grid-template-columns: minmax(0, 1fr);
            gap: 0.15rem;
            padding: 0.45rem 0;
        }
    }
}

@media (pointer: coarse) {
    body :is(.abstract-toggle, .bibtex-toggle, .arxiv-tab, .copy-btn, .cv-download-link) {
        min-height: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .page-section {
        animation: none;
    }

    body,
    .nav-link,
    .name-orbit-panel,
    .erdos-modal,
    .bibtex-modal {
        transition: none;
        animation: none;
    }
}
