/* Strange Frontiers header bar (php/rpg/top-bar.php; php/head-loads.php loads
   this last). The logomark and the page nav run in a row on the left; the
   search sits on the right. (The component library link is in the footer.)

   At the top of the page the bar sits over the hero with nothing behind it. Once
   it has scrolled out of view the script in top-bar.php adds .is-stuck: the bar
   is pinned to the window, compact and dark, and unfolds down from the top. Back
   near the top it folds away (.is-folding) and returns to its place. */

/* How far sticky parts of the page keep below the window's top: the pinned
   bar's height while it shows, 0 otherwise (set by php/rpg/top-bar.php, read
   by the creator apps' character box and d20 column). Registered so it can
   glide with the bar's unfold and fold. */
@property --sf-topbar-clear {
    syntax: "<length>";
    inherits: true;
    initial-value: 0px;
}

:root {
    transition: --sf-topbar-clear 320ms cubic-bezier(.2, .8, .2, 1);
}

@media (prefers-reduced-motion: reduce) {
    :root {
        transition: none;
    }
}

.sf-topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 60;
    padding: 32px 60px 0;
    /* It stays put while the pages slide (css/page-slide.css) */
    view-transition-name: sf-topbar;
}

.sf-topbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 40px;
    min-height: 35px;
}

/* The logomark: the star and SF, in white, the caps 32px tall */
.sf-topbar-mark {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 8px;
    color: var(--portfolio-white);
    font-family: 'bebas_neueregular';
    font-size: 45px;
    line-height: 1;
    letter-spacing: 1px;
    text-decoration: none;

    svg {
        width: 20px;
        height: 20px;
        fill: currentColor;
    }

    span {
        /* Bebas Neue's caps sit high in the line */
        margin-top: .08em;
    }

    &:hover,
    &:focus-visible {
        color: var(--portfolio-white);
        text-decoration: none;
    }
}

/* The nav and the tools; on phones they fold into a menu (below) */
.sf-topbar-menu {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: space-between;
    gap: 40px;
    min-width: 0;
}

.sf-topbar-menu-btn {
    display: none;
}

/* Wider than phones: the logomark, then the nav, on the left; the search on
   the right. The nav keeps to one line and the search gives way (320px down
   to 160px) to make room for it. (These selectors are longer than the base
   rules further down so they win over them.) */
@media only screen and (min-width: 768px) {
    .sf-topbar .sf-topbar-row .section-scroll-links.personal-page-nav {
        flex: none;
        flex-wrap: nowrap;
        white-space: nowrap;
    }

    .sf-topbar .sf-topbar-row .sf-topbar-tools {
        flex: 0 1 auto;
        min-width: 0;
    }

    html body .sf-topbar .rpg-search {
        flex: 0 1 auto;
        width: 320px;
        min-width: 160px;
    }
}

/* Tighter below 1200px, so the nav keeps to one row */
@media only screen and (min-width: 768px) and (max-width: 1199px) {
    .sf-topbar-row,
    .sf-topbar-menu {
        column-gap: 24px;
    }

    .sf-topbar .section-scroll-links.personal-page-nav {
        column-gap: 28px;
    }
}

/* Tablets (768px to 991px): a little smaller still, so it all fits in a row
   with no search beside it */
@media only screen and (min-width: 768px) and (max-width: 991px) {
    .sf-topbar .sf-topbar-row .section-scroll-links.personal-page-nav {
        column-gap: 22px;
        font-size: 1.15rem;
    }
}

/* ---- The nav, in a row (php/personal/page-nav.php) ---- */
.sf-topbar .section-scroll-links.personal-page-nav {
    position: static;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 44px;
    min-width: 0;
    line-height: 35px;

    /* The old column nudged each link in on hover; in a row that jostles its
       neighbours */
    div,
    div:hover {
        padding-left: 0;
    }

    /* The current page's dot, just after its link */
    .nav-bullet {
        right: -0.5rem;
    }
}

/* ---- The search ---- */
.sf-topbar-tools {
    display: flex;
    flex: none;
    align-items: center;
    gap: 20px;
}

.sf-topbar .rpg-search {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: 320px;
    transform: none;
}

/* The Discord link, left of the search: its logo, light gray, green on hover */
.sf-topbar-social {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    /* Purple 400, a shade deeper than the logo star's 500 */
    color: var(--sf-purple-400);

    svg {
        width: 24px;
        height: 24px;
        fill: currentColor;
    }

    &:hover,
    &:focus-visible {
        color: var(--frontiers-green);
    }

    &:focus-visible {
        outline: 2px solid var(--frontiers-green);
        outline-offset: 2px;
    }
}

.sf-topbar.is-stuck .sf-topbar-social svg {
    width: 20px;
    height: 20px;
}

/* Its results are wider than the box, so they line up with its right edge
   rather than centering under it and running off the window */
.sf-topbar .rpg-search-results {
    left: auto;
    right: 0;
    transform: none;
}


/* ---- Pinned: compact, dark, unfolding from the top ---- */
.sf-topbar.is-stuck {
    position: fixed;
    background-color: var(--sf-gray-800);
    box-shadow: 0 1px 0 var(--sf-gray-600), 0 8px 24px rgb(0 0 0 / 35%);
    animation: sf-topbar-unfold 320ms cubic-bezier(.2, .8, .2, 1);
}

/* Compact while pinned: everything a size down, about 46px tall in all */
.sf-topbar.is-stuck {
    padding-top: 7px;
    padding-bottom: 7px;

    .sf-topbar-row,
    .sf-topbar .section-scroll-links.personal-page-nav {
        min-height: 32px;
    }

    .sf-topbar-mark {
        gap: 6px;
        font-size: 30px;

        svg {
            width: 13px;
            height: 13px;
        }
    }

    .section-scroll-links.personal-page-nav {
        font-size: 1.25rem;
        line-height: 32px;
    }

    .rpg-search-input {
        height: 30px;
    }

}

.sf-topbar.is-stuck.is-folding {
    animation: sf-topbar-fold 200ms ease-in forwards;
}

@keyframes sf-topbar-unfold {
    from { transform: translateY(-100%); }
    to { transform: none; }
}

@keyframes sf-topbar-fold {
    from { transform: none; }
    to { transform: translateY(-100%); }
}

@media (prefers-reduced-motion: reduce) {
    .sf-topbar.is-stuck,
    .sf-topbar.is-stuck.is-folding {
        animation: none;
    }
}

/* ---- Narrower windows ---- */
@media only screen and (max-width: 1399px) {
    .sf-topbar {
        padding-left: 30px;
        padding-right: 30px;
    }

}

/* ---- Phones: everything folds into a menu behind a button on the right ---- */
@media only screen and (max-width: 767px) {
    .sf-topbar {
        padding: 16px 20px 0;
    }

    .sf-topbar.is-stuck {
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .sf-topbar.is-open {
        background-color: var(--sf-gray-800);
    }

    .sf-topbar-row {
        justify-content: space-between;
    }

    .sf-topbar-mark {
        gap: 6px;
        font-size: 36px;

        svg {
            width: 16px;
            height: 16px;
        }
    }

    .sf-topbar-menu-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        margin-right: -8px;
        padding: 0;
        border: 0;
        border-radius: 8px;
        background: none;
        color: var(--portfolio-white);
        cursor: pointer;

        svg {
            width: 22px;
            height: 22px;
            fill: currentColor;
        }

        &:focus-visible {
            outline: 2px solid var(--frontiers-green);
            outline-offset: 2px;
        }
    }

    .sf-topbar-menu-close,
    .sf-topbar.is-open .sf-topbar-menu-open {
        display: none;
    }

    .sf-topbar.is-open .sf-topbar-menu-close {
        display: block;
    }

    /* The menu: a panel dropping from the bar */
    .sf-topbar-menu {
        display: none;
    }

    .sf-topbar.is-open .sf-topbar-menu {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 20px;
        padding: 8px 20px 24px;
        background-color: var(--sf-gray-800);
        box-shadow: 0 1px 0 var(--sf-gray-600), 0 12px 24px rgb(0 0 0 / 35%);
    }

    /* The nav, one link to a line */
    .sf-topbar .section-scroll-links.personal-page-nav {
        flex-direction: column;
        align-items: flex-start;
        row-gap: 4px;
        font-size: 1.5rem;
        line-height: 1.5;
    }

    /* The search takes its own line. It shows
       here though the search is hidden below 992px elsewhere; that rule is
       specific (css/rpg.css, body:has(...)), hence the long selector */
    .sf-topbar-tools {
        gap: 16px;
    }

    html body .sf-topbar.sf-topbar .sf-topbar-menu .rpg-search {
        display: block;
        flex: 1;
        width: auto;
    }

    .sf-topbar .rpg-search-results {
        left: 0;
        width: auto;
        max-width: none;
    }
}

/* The creator pages' heroes (read by the creator's .builder-hero): they start
   below this bar (--sf-creator-top: the bar's height at the top of the page,
   --sf-topbar-home, measured by php/rpg/top-bar.php), so their titles center
   between the bar and the content. They kept clear of the old column of links
   on the left (--sf-creator-left); the nav is a row now, so they just center. */
.creator-shell {
    --sf-creator-top: var(--sf-topbar-home, 81px);
    --sf-creator-left: 0px;
}

/* ---- The character avatar and its menu (php/rpg/user-menu.php) ---- */
.sf-user {
    position: relative;
    /* A flex box, not a line of text, so the avatar isn't sat on a text
       baseline with room for descenders under it, which put it 2px high */
    display: flex;
    align-items: center;
    flex: none;
}

.sf-user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    overflow: hidden;
    border: 2px solid var(--sf-gray-500);
    border-radius: 50%;
    background-color: var(--sf-gray-700);
    color: var(--sf-gray-200);
    cursor: pointer;
    transition: border-color 150ms ease;

    &:hover,
    .sf-user.is-open & {
        border-color: var(--frontiers-green);
    }

    &:focus-visible {
        outline: 2px solid var(--frontiers-green);
        outline-offset: 2px;
    }
}

.sf-user-portrait {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sf-user-none {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.sf-user-portrait[hidden],
.sf-user-none[hidden] {
    display: none;
}

.sf-user-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 2;
    width: 220px;
    padding: 8px 0;
    border: 1px solid var(--sf-gray-600);
    border-radius: var(--portfolio-radius);
    background-color: var(--sf-gray-800);
    box-shadow: 0 12px 24px rgb(0 0 0 / 35%);

    &[hidden] {
        display: none;
    }
}

.sf-user-name {
    margin: 0;
    padding: 6px 16px 10px;
    overflow: hidden;
    color: var(--sf-gray-200);
    font-size: .875rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sf-user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 9px 16px;
    border: 0;
    background: none;
    color: var(--sf-gray-100);
    font: inherit;
    font-size: 1rem;
    text-align: left;
    cursor: pointer;

    svg {
        flex: none;
        width: 15px;
        height: 15px;
        fill: currentColor;
    }

    &:hover,
    &:focus-visible {
        background-color: var(--sf-gray-700);
        color: var(--portfolio-white);
        outline: none;
    }

    &[aria-disabled="true"] {
        color: var(--sf-gray-400);
        background: none;
        cursor: default;
    }
}

.sf-user-error {
    margin: 4px 16px;
    color: var(--sf-crimson-300);
    font-size: .875rem;

    &[hidden] {
        display: none;
    }
}

.sf-user-rule {
    margin: 8px 0;
    border: 0;
    border-top: 1px solid var(--sf-gray-600);
}

.sf-topbar.is-stuck .sf-user-avatar {
    width: 32px;
    height: 32px;
}

/* Phones: the avatar stays in the bar, just left of the menu button */
@media only screen and (max-width: 767px) {
    .sf-topbar-row {
        gap: 12px;
    }

    .sf-user {
        order: 1;
        margin-left: auto;
    }

    .sf-topbar-menu-btn {
        order: 2;
    }
}
