@font-face {
    font-family: AndaleMono;
    src: local(Andale Mono),
        url(/static/fonts/AndaleMono.woff2) format('woff2'),
        url(/static/fonts/AndaleMono.woff) format('woff');
}

@font-face {
    font-family: Helvetica;
    src: local(Helvetica),
        url(/static/fonts/Helvetica.woff2) format('woff2'),
        url(/static/fonts/Helvetica.woff) format('woff');
}

@font-face {
    font-family: Helvetica-Bold;
    src: local(Helvetica-Bold),
        url(/static/fonts/Helvetica-Bold.woff2) format('woff2'),
        url(/static/fonts/Helvetica-Bold.woff) format('woff');
}

* {
    box-sizing: border-box;
}

p.tips {
    color: var(--muted);
    font-size: 13px;
    line-height: 25px;
}

p.tips a {
    color: inherit;
    text-decoration: none;
}

p.tips a:hover {
    color: var(--primary);
}

.disabled {
    cursor: not-allowed !important;
    opacity: .6;
}

.hidden {
    display: none !important;
}

div.unread-badge {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 2px 5px #00000026;
    z-index: 10;
}

figure {
    margin: 15px 0;
    text-align: center;
}

figcaption {
    margin-top: 8px;
    font-size: 13px;
    font-style: italic;
    text-align: center;
}

.katex {
    font-size: 1em;
}

p.katex-block {
    overflow-x: auto;
}

body {
    display: flex;
    flex-direction: column;
    margin: 0;
    overflow: hidden;
    height: 100vh;
}

/******************************* navbar *******************************/

nav.navbar {
    position: sticky;
    top: 0;
    width: 100%;
    height: 80px;
    flex-shrink: 0;
    background: var(--primary);
    box-shadow: 0 2px 10px #0000001a;
    z-index: 1000;
    display: flex;
    align-items: center;
}

ul.navbar-items {
    list-style: none;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 3px;
    margin: 0;
    padding: 0 6px 0 0;
    width: 100%;
}

ul.navbar-items li {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

ul.navbar-items li.logo {
    width: 80px;
    height: 100%;
    color: white;
    font-size: 13px;
    font-family: Helvetica-Bold;
    text-align: center;
    margin: 0 8px 0 0;
}

ul.navbar-items li.logo img {
    width: 45px;
    height: 45px;
    margin-bottom: -10px;
}

ul.navbar-items li.logo a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: inherit;
    width: 80px;
    height: 100%;
    transition: transform .6s ease, box-shadow .6s ease;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

ul.navbar-items li.logo a::before {
    content: "";
    width: 80px;
    position: absolute;
    inset: 0;
    background: #ffffff0f;
    transform: translateY(100%);
    transition: transform .6s cubic-bezier(.2, .9, .2, 1);
    z-index: 0;
    pointer-events: none;
}

ul.navbar-items li.logo a:hover::before,
ul.navbar-items li.logo:focus-within a::before {
    transform: translateY(0);
}

ul.navbar-items li.logo:hover,
ul.navbar-items li.logo:focus-within {
    cursor: pointer;
    box-shadow: 0 6px 14px #00000020;
    transition: box-shadow .6s ease;
}

ul.navbar-items li.logo:active {
    box-shadow: none;
}

ul.navbar-items li.navbar-title {
    font-family: Helvetica-Bold;
    font-size: 28px;
    font-weight: bold;
    color: white;
    flex-direction: row;
    align-items: center;
    height: 100%;
    line-height: 27px;
    margin-right: auto;
    /* limit title width and allow wrapping when it overflows */
    max-width: 60%;
    white-space: normal;
    overflow-wrap: anywhere;
}

ul.navbar-items li.navbar-title img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    margin-right: 10px;
    object-fit: cover;
}

ul.navbar-items li.navbar-title i {
    font-size: 32px;
    color: white;
}

ul.navbar-items li.navbar-title i.gender {
    font-size: 20px;
    margin: 30px 10px 0 -20px;
    -webkit-text-stroke: 1px white;
}

ul.navbar-items li.navbar-title i.admin {
    font-size: 24px;
    margin-right: 4px;
}

ul.navbar-items li.navbar-item {
    position: relative;
    width: 64px;
    color: white;
    line-height: 15px;
    font-family: Helvetica-Bold;
    font-size: 15px;
    font-weight: bold;
    text-align: center;
    border-radius: 8px;
    transition: all .2s ease;
    padding: 4px 1px;
    margin: 0 1px;
}

ul.navbar-items .sidebar-toggle-btn,
ul.navbar-items .nav-more-toggle,
nav.navbar div.nav-more-panel {
    display: none;
}

ul.navbar-items li.navbar-item label {
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

ul.navbar-items li.navbar-item label:focus,
ul.navbar-items li.navbar-item label:active {
    outline: none;
    text-decoration: none;
}

ul.navbar-items li.navbar-item i,
ul.navbar-items li.navbar-item img {
    font-size: 30px;
    width: 36px;
    height: 36px;
    margin: 3px 0 -5px 0;
}

ul.navbar-items li.navbar-item img {
    border-radius: 50%;
}

ul.navbar-items li.navbar-item:hover {
    background: #ffffff2e;
}

ul.navbar-items a {
    text-decoration: none !important;
    color: inherit !important;
}

main {
    display: flex;
    flex-grow: 1;
    width: 100%;
    min-height: 0;
}

/******************************* sidebar *******************************/

aside {
    width: 220px;
    flex-shrink: 0;
    background: var(--surface-strong);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    font-family: Helvetica;
    padding: 15px 0;
    box-shadow: 2px 0 8px #0000000a;
    margin-right: 18px;
}

aside h3 {
    color: var(--accent);
    text-align: right;
    margin: 18px 18px 12px 0;
    font-size: 14px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: .5px;
}

div.sidebar-item {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: 40px;
    color: var(--text);
    margin: 7px 8px 7px 0;
    padding-right: 16px;
    background: var(--surface-soft);
    border-radius: 0 8px 8px 0;
    border-right: 3px solid transparent;
    transition: all .25s ease;
}

div.sidebar-item i,
div.sidebar-item img {
    margin-right: 10px !important;
    width: 18px;
    height: 18px;
    font-size: 16px;
    color: var(--accent);
}

div.sidebar-item img.avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    margin-right: 6px;
}

div.sidebar-item:not(.disabled):hover {
    background: var(--primary);
    color: white;
    border-right: 3px solid var(--primary-soft);
    cursor: pointer;
}

div.sidebar-item:not(.disabled):hover i {
    color: white;
}

div.sidebar-item.disabled {
    color: var(--muted);
    background: var(--surface-strong);
}

a.sidebar-link {
    text-decoration: none;
    color: inherit;
}

/******************************* blocks *******************************/

div.article-container {
    display: flex;
    overflow-y: auto;
    flex-grow: 1;
}

article {
    scroll-behavior: smooth;
}

article.height-fixed-article {
    position: sticky;
    top: 0;
    height: inherit !important;
    overflow-y: auto;
}

article.main-article,
article.body-article,
article.right-side-article,
article.toc-container,
article.content-container {
    margin: 15px 18px 15px 0;
    padding: 18px;
    height: fit-content;
    flex-grow: 1;
    border-radius: 12px;
    box-shadow: var(--shadow);
    background: var(--surface);
    font-family: Helvetica;
}

article.main-article {
    width: 80%;
}

article.body-article {
    width: 45%;
}

article.body-article img {
    width: 100%;
}

article.right-side-article {
    width: 30%;
}

article.right-side-article textarea.submit-input {
    height: 80px;
}

article.right-side-article h3 {
    clear: both;
}

article.toc-container {
    width: 25%;
    margin-left: 10px;
}

article.toc-container h3 {
    margin-bottom: 0;
}

nav.table-of-contents ul {
    padding-left: 16px;
}

nav.table-of-contents li {
    padding-top: 8px;
}

nav.table-of-contents a,
article.content-container a {
    text-decoration: none;
    color: var(--accent);
}

nav.table-of-contents a:hover,
article.content-container a:hover {
    text-decoration: underline;
}

article.content-container {
    width: 72%;
}

article#contentContainer,
article.content-container nav.table-of-contents {
    display: none;
}

/******************************* footer *******************************/

footer {
    width: 100%;
    height: 50px;
    flex-shrink: 0;
    background-color: var(--surface-soft);
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow);
    text-align: center;
    font-size: 12px;
    color: var(--text);
    padding: 5px;
}

footer p {
    margin: 2px;
}

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

footer a:hover {
    text-decoration: underline;
}

/******************************* responsive design *******************************/

/* Responsive: mobile layout adjustments */
@media (max-width: 768px) {

    body {
        height: fit-content;
        min-height: 100vh;
        overflow-y: auto;
    }

    ul.navbar-items {
        gap: 2px;
    }

    /* Hide full navbar items, keep title/avatar and toggles */
    ul.navbar-items a:has(.navbar-item),
    ul.navbar-items li.logo {
        display: none;
    }

    ul.navbar-items a:has(.navbar-item.navbar-avatar),
    ul.navbar-items .sidebar-toggle-btn,
    ul.navbar-items li.navbar-title,
    ul.navbar-items .navbar-avatar,
    ul.navbar-items .nav-more-toggle {
        display: flex;
    }

    ul.navbar-items .navbar-item.sidebar-toggle-btn,
    ul.navbar-items .navbar-item.nav-more-toggle {
        width: 48px;
        text-align: center;
        padding: 6px 4px;
    }

    ul.navbar-items li.navbar-title {
        font-size: 21px;
    }

    /* Nav-more panel: hidden by default, shown when checkbox checked (animated) */
    nav.navbar div.nav-more-panel {
        display: flex;
        position: absolute;
        right: 8px;
        top: 80px;
        background: #00000099;
        color: white;
        padding: 10px;
        border-radius: 10px;
        z-index: 1300;
        backdrop-filter: blur(6px);
        gap: 10px;
        overflow-x: auto;
        max-width: calc(100% - 20px);
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
        transition: opacity .18s ease, transform .18s ease;
        pointer-events: none;
    }

    #nav-more-toggle:checked~nav.navbar div.nav-more-panel {
        opacity: 1;
        transform: translateY(0) scale(1);
        pointer-events: auto;
    }

    .nav-more-link {
        display: inline-flex;
        gap: 8px;
        align-items: center;
        color: white;
        text-decoration: none;
        padding: 6px 8px;
        min-width: 80px;
        border-radius: 6px;
        white-space: nowrap;
    }

    .nav-more-link i {
        font-size: 20px;
    }

    .nav-more-link span {
        font-size: 14px;
        font-family: Helvetica, Arial, sans-serif;
    }

    /* Sidebar/TOC container is off-canvas by default; slide in when toggled */
    aside,
    article.toc-container {
        display: block;
        position: fixed;
        top: 80px;
        left: 0;
        height: calc(100vh - 80px);
        width: 50%;
        max-width: 320px;
        z-index: 1500;
        background: var(--surface-strong);
        border-right: 1px solid var(--border);
        box-shadow: 2px 8px 30px #00000040;
        padding-top: 12px;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform .25s cubic-bezier(.2, .9, .2, 1), visibility .25s linear;
        visibility: hidden;
    }

    article.toc-container {
        height: calc(100vh - 110px);
    }

    /* Overlay that darkens the page when sidebar is open; clickable to close */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: #00000059;
        z-index: 1400;
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }

    /* When toggled, reveal sidebar and overlay */
    #sidebar-toggle:checked~main .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    #sidebar-toggle:checked~main aside,
    #sidebar-toggle:checked~main article.toc-container {
        transform: translateX(0);
        visibility: visible;
    }

    /* Main: stack articles vertically and make full width;
        make main scrollable so navbar stays fixed */
    main {
        flex-direction: column;
        scroll-behavior: smooth;
        scrollbar-width: thin;
        scrollbar-color: #00000040 transparent;
    }

    main::-webkit-scrollbar {
        width: 12px;
    }

    main::-webkit-scrollbar-track {
        background: transparent;
    }

    main::-webkit-scrollbar-thumb {
        background: #0000002e;
        border-radius: 8px;
    }

    main::-webkit-scrollbar-thumb:hover {
        background: #00000042;
    }

    div.article-container {
        flex-direction: column;
        overflow: hidden;
    }

    article.main-article,
    article.body-article,
    article.right-side-article,
    article.content-container {
        width: calc(100% - 24px);
        margin: 10px 12px;
        overflow: visible;
    }
}